@@ -190,6 +190,9 @@ export function createToolDef(
190
190
name,
191
191
target : 'openAi'
192
192
} )
193
+ if ( name === 'test_run_step' ) {
194
+ console . log ( 'schema' , schema )
195
+ }
193
196
let parameters = schema . definitions ! [ name ] as FunctionParameters
194
197
parameters = {
195
198
...parameters ,
@@ -253,19 +256,29 @@ export const createSearchHubScriptsTool = (withContent: boolean = false) => ({
253
256
}
254
257
} )
255
258
256
- export async function buildSchemaForTool ( toolDef : ChatCompletionTool , schemaBuilder : ( ) => Promise < FunctionParameters > ) : Promise < void > {
259
+ export async function buildSchemaForTool ( toolDef : ChatCompletionTool , schemaBuilder : ( ) => Promise < FunctionParameters > ) : Promise < boolean > {
257
260
try {
258
261
const schema = await schemaBuilder ( )
262
+
263
+ // if schema properties contains values different from '^[a-zA-Z0-9_.-]{1,64}$'
264
+ const invalidProperties = Object . keys ( schema . properties ?? { } ) . filter ( ( key ) => ! / ^ [ a - z A - Z 0 - 9 _ . - ] { 1 , 64 } $ / . test ( key ) )
265
+ if ( invalidProperties . length > 0 ) {
266
+ console . warn ( `Invalid flow inputs schema: ${ invalidProperties . join ( ', ' ) } ` )
267
+ throw new Error ( `Invalid flow inputs schema: ${ invalidProperties . join ( ', ' ) } ` )
268
+ }
269
+
259
270
toolDef . function . parameters = { ...schema , additionalProperties : false }
260
271
// OPEN AI models don't support strict mode well with schema with complex properties, so we disable it
261
272
const model = get ( copilotSessionModel ) ?. provider
262
273
if ( model === 'openai' || model === 'azure_openai' ) {
263
274
toolDef . function . strict = false
264
275
}
276
+ return true
265
277
} catch ( error ) {
266
278
console . error ( 'Error building schema for tool' , error )
267
279
// fallback to schema with any properties
268
- toolDef . function . parameters = { type : 'object' , properties : { } , additionalProperties : true , strict : false }
280
+ toolDef . function . parameters = { type : 'object' , properties : { args : { type : 'string' , description : 'JSON string containing the arguments for the tool' } } , additionalProperties : false , strict : false , required : [ 'args' ] }
281
+ return false
269
282
}
270
283
}
271
284
@@ -378,6 +391,20 @@ function getErrorMessage(result: unknown): string {
378
391
return 'Unknown error'
379
392
}
380
393
394
+ // Build test run args based on the tool definition, if it contains a fallback schema
395
+ export async function buildTestRunArgs ( args : any , toolDef : ChatCompletionTool ) : Promise < any > {
396
+ let parsedArgs = args
397
+ // if the schema is the fallback schema, parse the args as a JSON string
398
+ if ( ( toolDef . function . parameters as any ) . properties ?. args ?. description === 'JSON string containing the arguments for the tool' ) {
399
+ try {
400
+ parsedArgs = JSON . parse ( args . args )
401
+ } catch ( error ) {
402
+ console . error ( 'Error parsing arguments for tool' , error )
403
+ }
404
+ }
405
+ return parsedArgs
406
+ }
407
+
381
408
// Main execution function for test runs
382
409
export async function executeTestRun ( config : TestRunConfig ) : Promise < string > {
383
410
try {
0 commit comments