-
Notifications
You must be signed in to change notification settings - Fork 514
fix: normalize tool function schemas to always have root type: "object" #745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,11 +137,24 @@ function allowedToolName(tool: unknown): string | undefined { | |
| function buildTools(tools: unknown[] | undefined): OcxTool[] | undefined { | ||
| if (!tools) return undefined; | ||
| const out: OcxTool[] = []; | ||
| // Some tool definitions (e.g. Codex `codex_app__automation_update`) arrive | ||
| // without a `parameters` field or with `parameters: null`. When serialized, | ||
| // that produces a JSON Schema whose root `type` is `null` (or missing). | ||
| // Strict validators reject such schemas with HTTP 400 | ||
| // ("schema must be a JSON Schema of 'type: \"object\"', got 'type: null'"). | ||
| // Coerce every function tool's `parameters` to a valid object-schema root | ||
| // so all downstream adapters pass through cleanly. | ||
| const normalizeParameters = (raw: unknown): Record<string, unknown> => { | ||
| const p = isObj(raw) ? { ...raw } : {}; | ||
| if (p.type !== "object") p.type = "object"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For routed xAI requests where the client supplies an unsafe function schema such as Useful? React with 👍 / 👎. |
||
| if (!isObj(p.properties)) p.properties = {}; | ||
| return p; | ||
| }; | ||
| const pushFn = (t: Record<string, unknown>, namespace?: string) => { | ||
| const tool: OcxTool = { | ||
| name: t.name as string, | ||
| description: (t.description as string) ?? "", | ||
| parameters: (t.parameters ?? {}) as Record<string, unknown>, | ||
| parameters: normalizeParameters(t.parameters), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This changes the request/tool schema behavior in AGENTS.md reference: AGENTS.md:L149-L151 Useful? React with 👍 / 👎. |
||
| }; | ||
| if (t.strict !== undefined) tool.strict = t.strict as boolean; | ||
| if (namespace) tool.namespace = namespace; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a Responses passthrough request carries MCP tools grouped as
{type: "namespace", tools: [{type: "function", parameters: null}]}and the target is not the Spark path that flattens namespaces first, this guard returns the namespace unchanged, so the inner function still reaches strict Responses gateways with the same missing/null root schema that this patch is meant to prevent. Please recurse into namespacetoolsfor both top-level tools andadditional_toolscontainers, or flatten before normalizing.AGENTS.md reference: src/AGENTS.md:L19-L19
Useful? React with 👍 / 👎.