@@ -581,60 +581,22 @@ function emptyAssistantContent(provider: OcxProviderConfig): string | { type: "t
581581}
582582
583583/**
584- * Deep-recursive schema fix: replaces `type:null` (JS null, JSON-Schema
585- * "null" string type, or missing type) at every level of the schema tree.
584+ * Providers like Kimi and DeepSeek reject function parameter schemas whose root
585+ * `type` is missing or `null` — JSON Schema requires `"object"` at the root of
586+ * function parameters. Add `type: "object"` at the root while preserving
587+ * `oneOf`, `$defs`, and every other schema key.
586588 *
587- * Several providers (Kimi, DeepSeek) reject JSON Schema `type:"null"` even
588- * inside `anyOf`/`oneOf` composition arrays. Codex tools like
589- * `codex_app__automation_update` ship nullable fields such as
590- * `localEnvironmentConfigPath: {anyOf:[{type:"string"},{type:"null"}]}`,
591- * causing 400 errors at the provider.
592- *
593- * This function recursively removes every `{type:"null"}` from arrays and
594- * replaces standalone `type:null` with `type:"string"`, mirroring
595- * `normalizeToolSchemas` in openai-responses.ts (but at all depths).
589+ * This mirrors `normalizeFunctionToolSchema` in openai-responses.ts, which
590+ * applies the same root-only normalization unconditionally on the responses
591+ * path. Nested schema content is intentionally left untouched.
596592 */
597- function fixNullTypes ( obj : Record < string , unknown > ) : Record < string , unknown > {
598- const out : Record < string , unknown > = { } ;
599- for ( const [ key , value ] of Object . entries ( obj ) ) {
600- if ( key === "type" && ( value === null || value === undefined || value === "null" ) ) {
601- // DeepSeek rejects `type:null` (JS null and the JSON-Schema `"null"` type)
602- // at any level. Replace with `"string"` — safe for all LLM tool-call schemas.
603- out [ key ] = value === "null" ? "string" : "object" ;
604- } else if ( value !== null && typeof value === "object" && ! Array . isArray ( value ) ) {
605- out [ key ] = fixNullTypes ( value as Record < string , unknown > ) ;
606- } else if ( Array . isArray ( value ) ) {
607- // Filter out `{type:"null"}` entries from anyOf/oneOf/allOf arrays — nullable
608- // is fine for JSON Schema but not for DeepSeek's stricter validator.
609- const filtered = value . filter ( v => {
610- if ( v !== null && typeof v === "object" && ! Array . isArray ( v ) ) {
611- const t = ( v as Record < string , unknown > ) . type ;
612- return t !== "null" ;
613- }
614- return true ;
615- } ) ;
616- out [ key ] = filtered . map ( v =>
617- v !== null && typeof v === "object" && ! Array . isArray ( v )
618- ? fixNullTypes ( v as Record < string , unknown > )
619- : v
620- ) ;
621- } else {
622- out [ key ] = value ;
623- }
624- }
625- return out ;
626- }
627-
628593function ensureRootObjectType ( parameters : unknown ) : Record < string , unknown > {
629594 if ( ! parameters || typeof parameters !== "object" || Array . isArray ( parameters ) ) {
630595 return { type : "object" , properties : { } } ;
631596 }
632597 const obj = parameters as Record < string , unknown > ;
633- if ( obj . type === "object" ) {
634- // Deep-fix: even if root type is correct, nested null types break DeepSeek
635- return fixNullTypes ( obj ) as Record < string , unknown > ;
636- }
637- return fixNullTypes ( { ...obj , type : "object" } ) as Record < string , unknown > ;
598+ if ( obj . type === "object" ) return obj ;
599+ return { ...obj , type : "object" } ;
638600}
639601
640602function expandXaiRootObjectSchemas ( schema : unknown ) : Record < string , unknown > [ ] | undefined {
0 commit comments