44 <q-page-container >
55 <q-page class =" row" >
66 <!-- SQL Card -->
7- <q-card class =" col" >
7+ <q-card class =" col q-ma-md " >
88 <q-card-section >
99 <div class =" text-h6" >SQL Queries</div >
1010 <div class =" text-subtitle2" >Tables in DB: {{ allTables }}</div >
2929 <div class =" text-h6 q-mb-sm" >Results</div >
3030 <pre style =" max-height : 300px ; overflow : auto " >{{ formattedResult }}</pre >
3131 </q-card-section >
32-
33- <q-card-section v-if =" errorMessage" class =" text-negative" >
34- <div class =" text-h6 q-mb-sm" >Error</div >
35- <pre >{{ errorMessage }}</pre >
36- </q-card-section >
3732 </q-card >
3833
3934 <!-- Taskyon iframe -->
4338 title =" Taskyon agent"
4439 frameborder =" 0"
4540 src =" http://localhost:9000"
46- style =" width : 100% ; height : 100% ; border : 1px solid #ccc "
41+ style =" width : 100% ; height : 100% ; border : 1px solid transparent "
4742 ></iframe >
4843 </div >
4944 </q-page >
@@ -58,10 +53,11 @@ import { asyncComputed } from 'src/modules/vueUtils'
5853
5954// Taskyon
6055import type { partialTyConfiguration } from ' src/modules/taskyon/iframeApiTypes'
61- import type { ClientTool } from ' src/modules/taskyon/tools'
62- import { createTool } from ' src/modules/taskyon/tools'
56+ import { createTool , makeTaskResult , toolCall } from ' src/modules/taskyon/tools'
6357import { initializeTaskyon } from ' src/modules/client/tyClient'
6458import { dump } from ' js-yaml'
59+ import { createChatCompletionTask } from ' src/modules/tools/chatCompletionTool'
60+ import type { JSONSchema7 } from ' json-schema'
6561
6662// Row interfaces (no `any`)
6763interface TableNameRow {
@@ -108,37 +104,11 @@ async function executeQuery() {
108104 try {
109105 const res = await db .value ?.query (sqlQuery .value )
110106 queryResult .value = res ?.rows ?? null
111- return queryResult .value
112107 } catch (err ) {
113- errorMessage .value = err instanceof Error ? err .message : String (err )
114- return { error: errorMessage .value }
108+ queryResult .value = err instanceof Error ? err .message : String (err )
115109 }
116110}
117111
118- // Taskyon tools
119- const tools: ClientTool [] = [
120- createTool ({
121- name: ' setSql' ,
122- description: ' Replace the current SQL query in the editor with the provided string.' ,
123- parameters: {
124- type: ' object' ,
125- properties: { sql: { type: ' string' , description: ' SQL to place in the editor' } },
126- required: [' sql' ],
127- additionalProperties: false ,
128- } as const ,
129- function : ({ sql }) => {
130- sqlQuery .value = sql
131- return ' ok'
132- },
133- }),
134- createTool ({
135- name: ' runSql' ,
136- description: ' Execute the SQL currently in the editor and return result rows.' ,
137- parameters: { type: ' object' , properties: {}, additionalProperties: false } as const ,
138- function : async () => executeQuery (),
139- }),
140- ]
141-
142112const sqlschemaquery = `
143113-- Postgres ≥ 9.4 (jsonb_build_object / jsonb_agg)
144114SELECT jsonb_agg(
@@ -166,37 +136,84 @@ FROM (
166136) t;
167137`
168138
169- const schema = asyncComputed <Record <string , unknown >>(async () => {
170- if (db .value ) {
171- const res = await db .value .query (sqlschemaquery )
172- return res
173- }
174- return {}
175- }, {})
176-
177- // Taskyon configuration
178- const configuration: partialTyConfiguration = {
179- llmSettings: {
180- selectedApi: ' taskyon' ,
181- enableOpenAiTools: false ,
182- enableToolChooser: true ,
183- taskChatTemplates: {
184- basePrompt: `
185- You are a SQL assistant helping users write and execute SQL queries against a PostgreSQL database.
186- You can use the tools provided to set the SQL query, run it, and describe the database schema.
139+ onMounted (async () => {
140+ db .value = await getDatabase (' taskyon' )
141+
142+ // Taskyon tools
143+ const tools = [
144+ createTool ({
145+ name: ' setSqlQuery' ,
146+ description: ' Replace the current SQL query in the editor with the provided string' ,
147+ parameters: {
148+ type: ' object' ,
149+ properties: { sql: { type: ' string' , description: ' SQL to place in the editor' } },
150+ required: [],
151+ additionalProperties: false ,
152+ } as const satisfies JSONSchema7 ,
153+ function : async ({ sql }) => {
154+ if (! sql ) {
155+ const schema = await db .value ! .query (sqlschemaquery )
156+ const toolPrompt = `
157+ You are are the taskyon SQL assistant helping users write and execute SQL queries against the local
158+ in-browser pglite PostgreSQL database.
159+
160+ You can use the tools provided to set the SQL query.
187161Always ensure that the SQL you generate is syntactically correct and safe to run.
188162
189163The database has the following tables and columns:
190164
191- ${dump (schema .value )}
192- ` ,
193- },
194- },
195- appConfiguration: { guiMode: ' default' },
196- }
165+ ${dump (schema )}
197166
198- onMounted (async () => {
199- db .value = await getDatabase (' taskyon' )
167+ The current SQL query in the editor is:
168+
169+ ${sqlQuery .value }
170+
171+ The current results of the last executed query are:
172+
173+ ${dump (queryResult .value )}
174+
175+ Only use the tool 'setSqlQuery' Tool if you think the user wants to change the SQL query.
176+ `
177+
178+ return makeTaskResult ([
179+ createChatCompletionTask ({
180+ prompts: [toolPrompt ],
181+ goal: ' ChooseTool' ,
182+ allowedTools: [' setSqlQuery' ],
183+ }),
184+ ])
185+ }
186+
187+ sqlQuery .value = sql
188+ return makeTaskResult ([
189+ {
190+ role: ' assistant' ,
191+ content: {
192+ type: ' message' ,
193+ data: ` The SQL query has been updated to:\n\`\`\` sql\n ${sql }\n\`\`\` ` ,
194+ },
195+ },
196+ {
197+ role: ' system' ,
198+ content: {
199+ type: ' return' ,
200+ data: ' OK' ,
201+ },
202+ },
203+ ])
204+ },
205+ }),
206+ ]
207+
208+ const configuration: partialTyConfiguration = {
209+ llmSettings: {
210+ selectedApi: ' taskyon' ,
211+ enableOpenAiTools: false ,
212+ enableToolChooser: true ,
213+ entryNode: toolCall ({ name: ' setSqlQuery' , arguments: {} }),
214+ },
215+ appConfiguration: { guiMode: ' default' },
216+ }
200217 void initializeTaskyon (tools , configuration )
201218})
202219
0 commit comments