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