11import { z } from "zod" ;
2- import * as handlers from "./handlers" ;
3- import { tool } from "@langchain/core/tools" ;
4- import { overArgs } from "lodash" ;
2+ import { DynamicTool , tool } from "@langchain/core/tools" ;
3+ import { request } from "../vendor/@beekeeperstudio/plugin/comms" ;
54
6- export const getActiveTabTool = tool ( handlers . getActiveTab , {
5+ export const getActiveTabTool = new DynamicTool ( {
76 name : "getActiveTab" ,
87 description :
98 "Get information about the user's currently active tab in Beekeeper Studio" ,
9+ func : async ( ) => {
10+ const result = await request ( "getActiveTab" ) ;
11+ return JSON . stringify ( result ) ;
12+ } ,
1013} ) ;
1114
12- export const updateQueryTextTool = tool ( handlers . updateQueryText , {
13- name : "updateQueryText" ,
14- description : "Update the SQL query text in a specific tab" ,
15- schema : z . object ( {
16- tabId : z . number ( ) . describe ( "The ID of the tab containing the query to update" ) ,
17- query : z . string ( ) . describe ( "The new SQL query text" ) ,
18- } ) ,
19- tags : [ "write" ]
20- } )
21-
22- export const getConnectionInfoTool = tool ( handlers . getConnectionInfo , {
15+ export const getConnectionInfoTool = new DynamicTool ( {
2316 name : "getConnectionInfo" ,
2417 description :
2518 "Get information about the current database connection including type, default database, and read-only status" ,
19+ func : async ( ) => {
20+ const result = await request ( "getConnectionInfo" ) ;
21+ return JSON . stringify ( result ) ;
22+ } ,
2623} ) ;
2724
28- export const getTablesTool = tool ( handlers . getTables , {
29- name : "getTables" ,
30- description : "Get a list of all tables in the current database" ,
31- } )
25+ export const getTablesTool = tool (
26+ async ( params : { schema ?: string } ) => {
27+ const result = await request ( "getTables" , { schema : params . schema } ) ;
28+ return JSON . stringify ( result ) ;
29+ } ,
30+ {
31+ name : "getTables" ,
32+ description : "Get a list of all tables in the current database" ,
33+ schema : z . object ( {
34+ schema : z
35+ . string ( )
36+ . optional ( )
37+ . describe ( "The name of the schema to get tables for" ) ,
38+ } ) ,
39+ } ,
40+ ) ;
3241
33- export const getTableColumnsTool = tool ( handlers . getTableColumns , {
34- name : "getTableColumns" ,
35- description : "Get all columns for a specific table including name and data type" ,
36- schema : z . object ( {
37- table : z . string ( ) . describe ( "The name of the table to get columns for" ) ,
38- } ) ,
39- } )
42+ export const getTableColumnsTool = tool (
43+ async ( params : { table : string } ) => {
44+ const result = await request ( "getColumns" , { table : params . table } ) ;
45+ return JSON . stringify ( result ) ;
46+ } ,
47+ {
48+ name : "getTableColumns" ,
49+ description :
50+ "Get all columns for a specific table including name and data type" ,
51+ schema : z . object ( {
52+ table : z . string ( ) . describe ( "The name of the table to get columns for" ) ,
53+ } ) ,
54+ } ,
55+ ) ;
56+
57+ export const getAllTabsTool = new DynamicTool ( {
58+ name : "getAllTabs" ,
59+ description : "Get a list of all open query tabs in Beekeeper Studio" ,
60+ func : async ( ) => {
61+ const result = await request ( "getAllTabs" ) ;
62+ return JSON . stringify ( result ) ;
63+ } ,
64+ } ) ;
65+
66+ export const createQueryTabTool = tool (
67+ async ( params : { query : string ; title : string } ) => {
68+ const result = await request ( "createQueryTab" , {
69+ query : params . query ,
70+ title : params . title ,
71+ } ) ;
72+ return JSON . stringify ( result ) ;
73+ } ,
74+ {
75+ name : "createQueryTab" ,
76+ description : "Create a new query tab with specified content" ,
77+ schema : z . object ( {
78+ query : z . string ( ) . describe ( "The SQL query text for the new tab" ) ,
79+ title : z . string ( ) . describe ( "The title for the new tab" ) ,
80+ } ) ,
81+ tags : [ "write" ] ,
82+ } ,
83+ ) ;
84+
85+ export const updateQueryTextTool = tool (
86+ async ( params : { tabId : number ; query : string } ) => {
87+ await request ( "updateQueryText" , {
88+ tabId : params . tabId ,
89+ query : params . query ,
90+ } ) ;
91+ return JSON . stringify ( {
92+ success : true ,
93+ message : "Query text updated successfully" ,
94+ tabId : params . tabId ,
95+ } ) ;
96+ } ,
97+ {
98+ name : "updateQueryText" ,
99+ description : "Update the SQL query text in a specific tab" ,
100+ schema : z . object ( {
101+ tabId : z
102+ . number ( )
103+ . describe ( "The ID of the tab containing the query to update" ) ,
104+ query : z . string ( ) . describe ( "The new SQL query text" ) ,
105+ } ) ,
106+ tags : [ "write" ] ,
107+ } ,
108+ ) ;
109+
110+ export const runQueryTool = tool (
111+ async ( params : { query : string } ) => {
112+ const result = await request ( "runQuery" , { query : params . query } ) ;
113+ return JSON . stringify ( result ) ;
114+ } ,
115+ {
116+ name : "runQuery" ,
117+ description : "Run a SQL query and get the results" ,
118+ schema : z . object ( {
119+ query : z . string ( ) . describe ( "The SQL query to execute" ) ,
120+ } ) ,
121+ tags : [ "write" ] ,
122+ } ,
123+ ) ;
124+
125+ export const runQueryTabTool = tool (
126+ async ( params : { tabId : number } ) => {
127+ const result = await request ( "runQueryTab" , { tabId : params . tabId } ) ;
128+ return JSON . stringify ( result ) ;
129+ } ,
130+ {
131+ name : "runQueryTab" ,
132+ description : "Run the query in a specific tab" ,
133+ schema : z . object ( {
134+ tabId : z
135+ . number ( )
136+ . describe ( "The ID of the tab containing the query to run" ) ,
137+ } ) ,
138+ tags : [ "write" ] ,
139+ } ,
140+ ) ;
141+
142+ // export const runQueryTabPartiallyTool = new DynamicStructuredTool({
143+ // name: "runQueryTabPartially",
144+ // description: "Run a portion of the query in a specific tab",
145+ // func: handlers.runQueryTabPartially,
146+ // schema: z.object({
147+ // tabId: z.number().describe("The ID of the tab containing the query"),
148+ // from: z.number().describe("The starting line number (1-based)"),
149+ // to: z.number().describe("The ending line number (1-based)"),
150+ // }),
151+ // tags: ["write"]
152+ // });
153+
154+ // export const insertSuggestionTool = new DynamicStructuredTool({
155+ // name: "insertSuggestion",
156+ // description: "Insert a suggestion into a specific range in a query tab",
157+ // func: handlers.insertSuggestion,
158+ // schema: z.object({
159+ // tabId: z.number().describe("The ID of the tab to insert the suggestion into"),
160+ // suggestion: z.string().describe("The text to insert"),
161+ // from: z.number().describe("The starting line number (1-based)"),
162+ // to: z.number().describe("The ending line number (1-based)"),
163+ // }),
164+ // tags: ["write"]
165+ // });
40166
41167export const tools = [
42168 getActiveTabTool ,
43- updateQueryTextTool ,
44169 getConnectionInfoTool ,
45170 getTablesTool ,
46171 getTableColumnsTool ,
47- ] ;
172+ getAllTabsTool ,
173+ createQueryTabTool ,
174+ updateQueryTextTool ,
175+ runQueryTool ,
176+ runQueryTabTool ,
177+ // TODO: These are not supported by Beekeeper Studio yet
178+ // runQueryTabPartiallyTool,
179+ // insertSuggestionTool,
180+ ] ;
0 commit comments