style: fix formatting in session transcript repair
This commit is contained in:
parent
ccf00e10cb
commit
dc2c40468d
@ -118,9 +118,7 @@ describe("sanitizeToolUseArgs", () => {
|
||||
const input = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "toolUse", id: "1", name: "tool", input: { key: "value" } },
|
||||
],
|
||||
content: [{ type: "toolUse", id: "1", name: "tool", input: { key: "value" } }],
|
||||
},
|
||||
] as any;
|
||||
const out = sanitizeToolUseArgs(input);
|
||||
@ -132,9 +130,7 @@ describe("sanitizeToolUseArgs", () => {
|
||||
const input = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "toolUse", id: "1", name: "tool", input: '{"key": "value"}' },
|
||||
],
|
||||
content: [{ type: "toolUse", id: "1", name: "tool", input: '{"key": "value"}' }],
|
||||
},
|
||||
] as any;
|
||||
const out = sanitizeToolUseArgs(input);
|
||||
@ -146,25 +142,21 @@ describe("sanitizeToolUseArgs", () => {
|
||||
const input = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "toolUse", id: "1", name: "tool", input: '{ bad json }' },
|
||||
],
|
||||
content: [{ type: "toolUse", id: "1", name: "tool", input: "{ bad json }" }],
|
||||
},
|
||||
] as any;
|
||||
const out = sanitizeToolUseArgs(input);
|
||||
const block = out[0].content[0] as any;
|
||||
expect(block.input).toEqual({});
|
||||
expect(block._sanitized).toBe(true);
|
||||
expect(block._originalInput).toBe('{ bad json }');
|
||||
expect(block._originalInput).toBe("{ bad json }");
|
||||
});
|
||||
|
||||
it("handles 'arguments' alias", () => {
|
||||
const input = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "toolCall", id: "1", name: "tool", arguments: '{"key": "val"}' },
|
||||
],
|
||||
content: [{ type: "toolCall", id: "1", name: "tool", arguments: '{"key": "val"}' }],
|
||||
},
|
||||
] as any;
|
||||
const out = sanitizeToolUseArgs(input);
|
||||
@ -176,9 +168,7 @@ describe("sanitizeToolUseArgs", () => {
|
||||
const input = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "toolCall", id: "1", name: "tool", arguments: 'bad' },
|
||||
],
|
||||
content: [{ type: "toolCall", id: "1", name: "tool", arguments: "bad" }],
|
||||
},
|
||||
] as any;
|
||||
const out = sanitizeToolUseArgs(input);
|
||||
|
||||
@ -78,11 +78,14 @@ export function sanitizeToolUseArgs(messages: AgentMessage[]): AgentMessage[] {
|
||||
if (
|
||||
anyBlock &&
|
||||
typeof anyBlock === "object" &&
|
||||
(anyBlock.type === "toolUse" || anyBlock.type === "toolCall" || anyBlock.type === "functionCall")
|
||||
(anyBlock.type === "toolUse" ||
|
||||
anyBlock.type === "toolCall" ||
|
||||
anyBlock.type === "functionCall")
|
||||
) {
|
||||
const toolBlock = block as any;
|
||||
// Handle both 'input' and 'arguments' fields (some providers use arguments)
|
||||
const inputField = "input" in toolBlock ? "input" : "arguments" in toolBlock ? "arguments" : null;
|
||||
const inputField =
|
||||
"input" in toolBlock ? "input" : "arguments" in toolBlock ? "arguments" : null;
|
||||
|
||||
if (inputField && typeof toolBlock[inputField] === "string") {
|
||||
try {
|
||||
@ -97,7 +100,7 @@ export function sanitizeToolUseArgs(messages: AgentMessage[]): AgentMessage[] {
|
||||
// Invalid JSON found in tool args.
|
||||
// Replace with empty object to prevent downstream crashes.
|
||||
console.warn(
|
||||
`[SessionRepair] Sanitized malformed JSON in tool use '${toolBlock.name || "unknown"}'. Original: ${toolBlock[inputField]}`
|
||||
`[SessionRepair] Sanitized malformed JSON in tool use '${toolBlock.name || "unknown"}'. Original: ${toolBlock[inputField]}`,
|
||||
);
|
||||
nextContent.push({
|
||||
...toolBlock,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user