fix(pi,omp): treat null optional tool arguments as omitted (#9506)
Models commonly send null for optional tool arguments, such as read offset/limit (captured in #7011) and bash timeout. Pi and OMP treat null as omitted, but the Paseo mappers rejected it, so these calls fell back to unknown tool cards that show raw JSON input and output instead of Read/Shell cards.
This commit is contained in:
1 parent
8b3b2a9ea3
commit
70aeb7b45b
4 files changed
+31
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import type { ToolCallDetail } from "../../agent-sdk-types.js";
|
||||
import { omitNullArgs } from "../tool-call-args.js";
|
||||
|
||||
interface BashToolInput {
|
||||
command: string;
|
||||
@@ -324,7 +325,7 @@ export function parseToolArgs(toolName: string, rawArgs: unknown): OmpTrackedToo
|
||||
}
|
||||
const schema = SIMPLE_TOOL_SCHEMAS[toolName as SimpleToolKind];
|
||||
if (schema) {
|
||||
const parsed = schema.safeParse(rawArgs);
|
||||
const parsed = schema.safeParse(omitNullArgs(rawArgs));
|
||||
if (parsed.success) {
|
||||
return {
|
||||
kind: toolName as SimpleToolKind,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { z } from "zod";
|
||||
|
||||
import type { ToolCallDetail } from "../../agent-sdk-types.js";
|
||||
import type { ProviderImageOutput } from "../provider-image-output.js";
|
||||
import { omitNullArgs } from "../tool-call-args.js";
|
||||
|
||||
interface BashToolInput {
|
||||
command: string;
|
||||
@@ -331,7 +332,7 @@ export function parseToolArgs(toolName: string, rawArgs: unknown): PiTrackedTool
|
||||
}
|
||||
const schema = SIMPLE_TOOL_SCHEMAS[toolName as SimpleToolKind];
|
||||
if (schema) {
|
||||
const parsed = schema.safeParse(rawArgs);
|
||||
const parsed = schema.safeParse(omitNullArgs(rawArgs));
|
||||
if (parsed.success) {
|
||||
return { kind: toolName as SimpleToolKind, toolName, args: parsed.data } as PiTrackedToolCall;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { parseToolArgs as parseOmpToolArgs } from "./omp/tool-call-detail.js";
|
||||
import { parseToolArgs as parsePiToolArgs } from "./pi/tool-call-mapper.js";
|
||||
|
||||
// Models send `null` for optional arguments (captured in #7011: read offset/limit), which the
|
||||
// runtimes treat as omitted. Rejecting them turned every such call into an unknown card.
|
||||
describe.each([
|
||||
["Pi", parsePiToolArgs],
|
||||
["OMP", parseOmpToolArgs],
|
||||
])("%s tool args with null optional values", (_provider, parseToolArgs) => {
|
||||
test.each([
|
||||
["read", { path: "./preview.png", offset: null, limit: null }, { path: "./preview.png" }],
|
||||
["bash", { command: "ls", timeout: null }, { command: "ls" }],
|
||||
])("parses %s as its own tool kind", (toolName, rawArgs, args) => {
|
||||
expect(parseToolArgs(toolName, rawArgs)).toEqual({ kind: toolName, toolName, args });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
// Models routinely send `null` for optional tool arguments (e.g. read offset/limit); the
|
||||
// runtimes treat that as omitted, so the mappers must too or the call degrades to an
|
||||
// unknown card that carries the raw result.
|
||||
export function omitNullArgs(rawArgs: unknown): unknown {
|
||||
if (!rawArgs || typeof rawArgs !== "object" || Array.isArray(rawArgs)) {
|
||||
return rawArgs;
|
||||
}
|
||||
return Object.fromEntries(Object.entries(rawArgs).filter(([, value]) => value !== null));
|
||||
}
|
||||
Reference in new issue
Block a user