88
99import process from 'node:process' ;
1010import { openai } from '@ai-sdk/openai' ;
11- import { StackOneToolSet , Tools } from '@stackone/ai' ;
11+ import { type JsonObject , StackOneToolSet , Tools } from '@stackone/ai' ;
1212import { generateText , stepCountIs } from 'ai' ;
1313
1414const apiKey = process . env . STACKONE_API_KEY ;
@@ -160,7 +160,7 @@ const directMetaToolUsage = async (): Promise<void> => {
160160
161161 try {
162162 // Prepare parameters based on the tool's schema
163- let params : Record < string , unknown > = { } ;
163+ let params = { } satisfies JsonObject ;
164164 if ( firstTool . name === 'bamboohr_list_employees' ) {
165165 params = { limit : 5 } ;
166166 } else if ( firstTool . name === 'bamboohr_create_employee' ) {
@@ -173,7 +173,7 @@ const directMetaToolUsage = async (): Promise<void> => {
173173
174174 const result = await executeTool . execute ( {
175175 toolName : firstTool . name ,
176- params : params ,
176+ params,
177177 } ) ;
178178
179179 console . log ( 'Execution result:' , JSON . stringify ( result , null , 2 ) ) ;
@@ -209,7 +209,7 @@ const dynamicToolRouter = async (): Promise<void> => {
209209 const metaTools = await combinedTools . metaTools ( ) ;
210210
211211 // Create a router function that finds and executes tools based on intent
212- const routeAndExecute = async ( intent : string , params : Record < string , unknown > = { } ) => {
212+ const routeAndExecute = async ( intent : string , params : JsonObject = { } ) => {
213213 const filterTool = metaTools . getTool ( 'meta_search_tools' ) ;
214214 const executeTool = metaTools . getTool ( 'meta_execute_tool' ) ;
215215 if ( ! filterTool || ! executeTool ) throw new Error ( 'Meta tools not found' ) ;
@@ -221,18 +221,18 @@ const dynamicToolRouter = async (): Promise<void> => {
221221 minScore : 0.5 ,
222222 } ) ;
223223
224- const tools = searchResult . tools as Array < { name : string ; score : number } > ;
225- if ( tools . length === 0 ) {
224+ const tools = searchResult . tools ;
225+ if ( ! Array . isArray ( tools ) || tools . length === 0 ) {
226226 return { error : 'No relevant tools found for the given intent' } ;
227227 }
228228
229- const selectedTool = tools [ 0 ] ;
229+ const selectedTool = tools [ 0 ] as { name : string ; score : number } ;
230230 console . log ( `Routing to: ${ selectedTool . name } (score: ${ selectedTool . score . toFixed ( 2 ) } )` ) ;
231231
232232 // Execute the selected tool
233233 return await executeTool . execute ( {
234234 toolName : selectedTool . name ,
235- params : params ,
235+ params,
236236 } ) ;
237237 } ;
238238
@@ -244,7 +244,7 @@ const dynamicToolRouter = async (): Promise<void> => {
244244 params : { name : 'Jane Smith' , email : 'jane@example.com' } ,
245245 } ,
246246 { intent : 'Find recruitment candidates' , params : { status : 'active' } } ,
247- ] ;
247+ ] as const satisfies Array < { intent : string ; params : JsonObject } > ;
248248
249249 for ( const { intent, params } of intents ) {
250250 console . log ( `\nIntent: "${ intent } "` ) ;
0 commit comments