@@ -188,6 +188,7 @@ export type AnswerCommitInput = z.input<typeof parameters>
188188// JSON and let the schema validate the result as usual; anything else is left for the normal error.
189189const JSON_SHAPED_KEYS = [ "fields" , "asked" , "rows" , "unresolved" , "readings" ] as const
190190
191+ /** Parse a string that looks like a JSON array or object; return any other value, or invalid JSON, unchanged. */
191192function decodeJsonShaped ( value : unknown ) : unknown {
192193 if ( typeof value !== "string" || ! / ^ \s * [ [ { ] / . test ( value ) ) return value
193194 try {
@@ -199,6 +200,10 @@ function decodeJsonShaped(value: unknown): unknown {
199200// altimate_change end
200201
201202// altimate_change start — #1700: exported so raw-argument readers (MCP adapter/server) see the same decoded shape
203+ /**
204+ * Normalize raw answer_commit arguments before validation: decode JSON-string list/object inputs
205+ * and coerce string or numeric `answer_only` flags. Non-object input is returned unchanged.
206+ */
202207export function normalizeAnswerArgs ( input : unknown ) : unknown {
203208 if ( ! input || typeof input !== "object" || Array . isArray ( input ) ) return input
204209 const next : Record < string , unknown > = { ...input }
@@ -207,8 +212,11 @@ export function normalizeAnswerArgs(input: unknown): unknown {
207212 }
208213 if ( ! ( "answer_only" in next ) ) return next
209214 const value = typeof next . answer_only === "string" ? next . answer_only . toLowerCase ( ) : next . answer_only
210- next . answer_only =
211- value === "true" || value === 1 ? true : value === "false" || value === 0 ? false : next . answer_only
215+ if ( value === "true" || value === 1 ) {
216+ next . answer_only = true
217+ } else if ( value === "false" || value === 0 ) {
218+ next . answer_only = false
219+ }
212220 return next
213221}
214222
0 commit comments