@@ -58,6 +58,7 @@ export interface Def<
5858 description : string
5959 parameters : Parameters
6060 jsonSchema ?: JSONSchema7
61+ normalizeArguments ?( args : unknown ) : unknown
6162 execute ( args : Schema . Schema . Type < Parameters > , ctx : Context ) : Effect . Effect < ExecuteResult < M > >
6263 formatValidationError ?( error : unknown ) : string
6364}
@@ -94,6 +95,21 @@ export type InferDef<T> =
9495 ? Def < P , M >
9596 : never
9697
98+ export function normalizeAliases ( input : unknown , aliases : Record < string , string [ ] > ) : unknown {
99+ if ( ! isRecord ( input ) ) return input
100+ const output = { ...input }
101+ for ( const [ key , names ] of Object . entries ( aliases ) ) {
102+ if ( output [ key ] !== undefined ) continue
103+ const name = names . find ( ( alias ) => input [ alias ] !== undefined )
104+ if ( name ) output [ key ] = input [ name ]
105+ }
106+ return output
107+ }
108+
109+ function isRecord ( input : unknown ) : input is Record < string , unknown > {
110+ return typeof input === "object" && input !== null && ! Array . isArray ( input )
111+ }
112+
97113function wrap < Parameters extends Schema . Decoder < unknown > , Result extends Metadata > (
98114 id : string ,
99115 init : Init < Parameters , Result > ,
@@ -116,7 +132,7 @@ function wrap<Parameters extends Schema.Decoder<unknown>, Result extends Metadat
116132 ...( ctx . callID ? { "tool.call_id" : ctx . callID } : { } ) ,
117133 }
118134 return Effect . gen ( function * ( ) {
119- const decoded = yield * decode ( args ) . pipe (
135+ const decoded = yield * decode ( toolInfo . normalizeArguments ? toolInfo . normalizeArguments ( args ) : args ) . pipe (
120136 Effect . mapError (
121137 ( error ) =>
122138 new InvalidArgumentsError ( {
0 commit comments