File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,21 @@ describe('Agent Tools', () => {
1717 required : [ 'test' ] ,
1818 } ,
1919 } as const
20+
21+ const SOME_TOOL_SPEC_WITH_EXTENSIONS = {
22+ name : 'test' ,
23+ description : 'test' ,
24+ inputSchema : {
25+ type : 'object' ,
26+ properties : {
27+ test : {
28+ type : 'string' ,
29+ } ,
30+ } ,
31+ required : [ 'test' ] ,
32+ someExtension : true ,
33+ } ,
34+ } as const
2035 const SOME_TOOL_HANDLER = async ( _ : { test : string } ) => true
2136
2237 beforeEach ( ( ) => {
@@ -91,4 +106,13 @@ describe('Agent Tools', () => {
91106 assert . equal ( tools [ 0 ] . description , SOME_TOOL_SPEC . description )
92107 assert . equal ( tools [ 0 ] . inputSchema , SOME_TOOL_SPEC . inputSchema )
93108 } )
109+
110+ it ( 'should support JSON Schema extension keywords' , ( ) => {
111+ AGENT . addTool ( SOME_TOOL_SPEC_WITH_EXTENSIONS , SOME_TOOL_HANDLER )
112+ const tools = AGENT . getTools ( { format : 'bedrock' } )
113+ assert . equal (
114+ tools [ 0 ] . toolSpecification . inputSchema . json [ 'someExtension' ] ,
115+ SOME_TOOL_SPEC_WITH_EXTENSIONS . inputSchema . someExtension
116+ )
117+ } )
94118} )
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ type Tool<T, R> = {
1111
1212export const newAgent = ( ) : Agent => {
1313 const tools : Record < string , Tool < any , any > > = { }
14- const ajv = new Ajv ( )
14+ const ajv = new Ajv ( { strictSchema : false } )
1515
1616 return {
1717 addTool : < T extends InferSchema < S [ 'inputSchema' ] > , S extends ToolSpec > (
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ interface BaseSchema {
66 $id ?: string
77 $schema ?: string
88 definitions ?: Record < string , JSONSchema >
9+ [ extensionKeywords : string ] : any
910}
1011
1112interface StringSchema extends BaseSchema {
@@ -74,9 +75,17 @@ type InferArray<T extends { type: 'array'; items: any }> = T['items'] extends {
7475 ? InferSchema < T [ 'items' ] > [ ]
7576 : never
7677
77- type InferObject < T extends { type : 'object' ; properties : Record < string , any > } > = {
78- [ K in keyof T [ 'properties' ] ] ?: InferSchema < T [ 'properties' ] [ K ] >
79- } & ( T extends { required : string [ ] } ? { [ K in T [ 'required' ] [ number ] ] : InferSchema < T [ 'properties' ] [ K ] > } : unknown )
78+ type InferObject < T extends { type : 'object' ; properties : Record < string , any > } > = T extends {
79+ required : readonly string [ ]
80+ }
81+ ? {
82+ [ K in keyof T [ 'properties' ] as K extends T [ 'required' ] [ number ] ? K : never ] : InferSchema < T [ 'properties' ] [ K ] >
83+ } & {
84+ [ K in keyof T [ 'properties' ] as K extends T [ 'required' ] [ number ] ? never : K ] ?: InferSchema < T [ 'properties' ] [ K ] >
85+ }
86+ : {
87+ [ K in keyof T [ 'properties' ] ] ?: InferSchema < T [ 'properties' ] [ K ] >
88+ }
8089
8190export type InferSchema < T > = T extends { type : 'array' ; items : any }
8291 ? InferArray < T >
You can’t perform that action at this time.
0 commit comments