type union

pull/7239/head
Aiden Cline 2026-01-07 17:11:57 -06:00
parent 68219475c0
commit eb8c34735f
5 changed files with 12 additions and 14 deletions

View File

@ -69,7 +69,7 @@ export namespace ToolRegistry {
return {
title: "",
output: out.truncated ? out.content : result,
metadata: { truncated: out.truncated, outputPath: out.outputPath },
metadata: { truncated: out.truncated, outputPath: out.truncated ? out.outputPath : undefined },
}
},
}),

View File

@ -77,7 +77,7 @@ export namespace Tool {
metadata: {
...result.metadata,
truncated: truncated.truncated,
outputPath: truncated.outputPath,
...(truncated.truncated && { outputPath: truncated.outputPath }),
},
}
}

View File

@ -12,11 +12,7 @@ export namespace Truncate {
export const DIR = path.join(Global.Path.data, "tool-output")
const RETENTION_MS = 7 * 24 * 60 * 60 * 1000 // 7 days
export interface Result {
content: string
truncated: boolean
outputPath?: string
}
export type Result = { content: string; truncated: false } | { content: string; truncated: true; outputPath: string }
export interface Options {
maxLines?: number

View File

@ -248,7 +248,7 @@ describe("tool.bash truncation", () => {
)
expect((result.metadata as any).truncated).toBe(true)
expect(result.output).toContain("truncated")
expect(result.output).toContain("The tool output was too large")
expect(result.output).toContain("The tool call succeeded but the output was truncated")
},
})
})
@ -268,7 +268,7 @@ describe("tool.bash truncation", () => {
)
expect((result.metadata as any).truncated).toBe(true)
expect(result.output).toContain("truncated")
expect(result.output).toContain("The tool output was too large")
expect(result.output).toContain("The tool call succeeded but the output was truncated")
},
})
})

View File

@ -14,7 +14,7 @@ describe("Truncate", () => {
expect(result.truncated).toBe(true)
expect(result.content).toContain("truncated...")
expect(result.outputPath).toBeDefined()
if (result.truncated) expect(result.outputPath).toBeDefined()
})
test("returns content unchanged when under limits", async () => {
@ -82,12 +82,13 @@ describe("Truncate", () => {
const result = await Truncate.output(lines, { maxLines: 10 })
expect(result.truncated).toBe(true)
expect(result.content).toContain("The tool call succeeded but the output was truncated")
expect(result.content).toContain("Grep")
if (!result.truncated) throw new Error("expected truncated")
expect(result.outputPath).toBeDefined()
expect(result.outputPath).toContain("tool_")
expect(result.content).toContain("The tool output was too large")
expect(result.content).toContain("Grep")
const written = await Bun.file(result.outputPath!).text()
const written = await Bun.file(result.outputPath).text()
expect(written).toBe(lines)
})
@ -116,7 +117,8 @@ describe("Truncate", () => {
const result = await Truncate.output(content)
expect(result.truncated).toBe(false)
expect(result.outputPath).toBeUndefined()
if (result.truncated) throw new Error("expected not truncated")
expect("outputPath" in result).toBe(false)
})
})