@@ -87,9 +87,15 @@ export function repairToolCallMessage(message: Record<string, unknown>) {
8787 return { message : { ...message , params : { ...call , arguments : args } } , repairs : [ ...repairs ] }
8888}
8989
90+ /** Unrecognized field names a rejection records, each cut short, so a log line stays bounded. */
91+ const MAX_LOGGED_KEYS = 5
92+ const MAX_LOGGED_KEY_CHARACTERS = 64
93+
9094/**
9195 * Where a tool call's arguments fail its input schema, as field paths and issue codes without
92- * values. The SDK rejects such a call before the tool runs, so nothing else records it.
96+ * values, plus the names of fields the schema does not know, so a repeated client mistake can be
97+ * told apart from a new one. The SDK rejects such a call before the tool runs, so nothing else
98+ * records it.
9399 */
94100export function toolCallInputIssues ( message : Record < string , unknown > ) {
95101 const call = readToolCall ( message )
@@ -99,6 +105,14 @@ export function toolCallInputIssues(message: Record<string, unknown>) {
99105 if ( parsed . success ) return undefined
100106 return {
101107 toolName : call . name ,
102- issues : parsed . error . issues . map ( ( { code, path } ) => ( { code, path : path . join ( '.' ) } ) ) ,
108+ issues : parsed . error . issues . map ( ( issue ) => ( {
109+ code : issue . code ,
110+ path : issue . path . join ( '.' ) ,
111+ ...( issue . code === 'unrecognized_keys' && {
112+ keys : issue . keys
113+ . slice ( 0 , MAX_LOGGED_KEYS )
114+ . map ( ( key ) => key . slice ( 0 , MAX_LOGGED_KEY_CHARACTERS ) ) ,
115+ } ) ,
116+ } ) ) ,
103117 }
104118}
0 commit comments