feat: custom tool renderers

This commit is contained in:
Zoe
2026-09-25 19:46:00 -05:00
parent 3f81f96bda
commit bb5795e00d
18 changed files with 1294 additions and 65 deletions
+33
View File
@@ -0,0 +1,33 @@
import { expect, test } from "bun:test";
import { readStoredToolError, serializeToolError } from "../utils/tool-errors";
const validationError = "Invalid input for tool search: Type validation failed: Value: {\"query\":123}.\nError message: [{\"code\":\"custom\"}]";
test("tool Error instances persist their message, not an empty JSON object", () => {
expect(serializeToolError(new Error(validationError))).toBe(validationError);
expect(serializeToolError(validationError)).toBe(validationError);
expect(serializeToolError({ reason: "invalid input" })).toBe('{"reason":"invalid input"}');
});
test("text validation errors remain text on history replay", () => {
expect(readStoredToolError({ type: "text", value: validationError })).toEqual({
type: "error-text",
value: validationError,
});
});
test("legacy mislabeled JSON errors cannot break subsequent prompts", () => {
expect(readStoredToolError({ type: "json", value: validationError })).toEqual({
type: "error-text",
value: validationError,
});
});
test("preserves actual JSON errors and handles missing errors", () => {
expect(readStoredToolError({ type: "json", value: '{"reason":"bad input"}' })).toEqual({
type: "error-json",
value: { reason: "bad input" },
});
expect(readStoredToolError(null).type).toBe("error-text");
expect(readStoredToolError(undefined).type).toBe("error-text");
});