-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdatabase-tools.ts
More file actions
116 lines (107 loc) · 3.46 KB
/
database-tools.ts
File metadata and controls
116 lines (107 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { AIToolDefinition } from '../interfaces/ai-provider.interface.js';
export function createDatabaseTools(isMongoDB: boolean): AIToolDefinition[] {
const getTableStructureTool: AIToolDefinition = {
name: 'getTableStructure',
description:
'Returns the structure of the specified table and related information including foreign keys and referenced tables.',
parameters: {
type: 'object',
properties: {
tableName: {
type: 'string',
description: 'The name of the table to get the structure for.',
},
},
required: ['tableName'],
additionalProperties: false,
},
};
const executeRawSqlTool: AIToolDefinition = {
name: 'executeRawSql',
description:
'Executes a raw SQL query and returns the results. Only SELECT queries are allowed. Do not drop the database or any data from the database.',
parameters: {
type: 'object',
properties: {
query: {
type: 'string',
description:
'The SQL query to execute. Table and column names should be properly escaped. Only SELECT statements are allowed.',
},
},
required: ['query'],
additionalProperties: false,
},
};
const executeAggregationPipelineTool: AIToolDefinition = {
name: 'executeAggregationPipeline',
description:
'Executes a MongoDB aggregation pipeline and returns the results. Do not drop the database or any data from the database.',
parameters: {
type: 'object',
properties: {
pipeline: {
type: 'string',
description: 'The MongoDB aggregation pipeline to execute as a JSON string.',
},
},
required: ['pipeline'],
additionalProperties: false,
},
};
const searchDocumentationTool: AIToolDefinition = {
name: 'searchDocumentation',
description:
'Searches the official Rocketadmin documentation at https://docs.rocketadmin.com and returns the most relevant pages with their titles, URLs, and content snippets. Use this when the user asks how to use Rocketadmin features (connections, dashboards, permissions, groups, master password, widgets, integrations, settings, SSO, secrets, etc.) or when a question is about the product rather than the data in the connected database.',
parameters: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'A short search query describing what to look up in the Rocketadmin documentation.',
},
},
required: ['query'],
additionalProperties: false,
},
};
const tools: AIToolDefinition[] = [getTableStructureTool];
if (isMongoDB) {
tools.push(executeAggregationPipelineTool);
} else {
tools.push(executeRawSqlTool);
}
tools.push(searchDocumentationTool);
return tools;
}
export function createDashboardGenerationTools(): AIToolDefinition[] {
return [
{
name: 'getTablesList',
description:
'Returns the list of all tables and views available in the database. Use this to discover what tables exist before requesting their structure.',
parameters: {
type: 'object',
properties: {},
required: [],
additionalProperties: false,
},
},
{
name: 'getTableStructure',
description:
'Returns the structure of the specified table including column names, data types, and nullability. Use this to inspect tables before generating dashboard panels.',
parameters: {
type: 'object',
properties: {
tableName: {
type: 'string',
description: 'The name of the table to get the structure for.',
},
},
required: ['tableName'],
additionalProperties: false,
},
},
];
}