@@ -557,8 +557,7 @@ describe("getMessageDiagnostics", () => {
557557 });
558558
559559 describe("compactToolResultPayloads", () => {
560- test("compacts oversized tool payloads with truncation metadata", () => {
561- const largePayload = "x".repeat(10_000);
560+ function expectCompactedJsonOutput(output: unknown): void {
562561 const messages: CoreMessage[] = [
563562 {
564563 role: "tool",
@@ -567,7 +566,7 @@ describe("compactToolResultPayloads", () => {
567566 type: "tool-result",
568567 toolCallId: "1",
569568 toolName: "read",
570- output: { blob: largePayload },
569+ output,
571570 },
572571 ],
573572 } as unknown as CoreMessage,
@@ -577,8 +576,26 @@ describe("compactToolResultPayloads", () => {
577576 const part = (compacted[0] as { content: Array<Record<string, unknown>> })
578577 .content[0];
579578 expect(part?.output).toMatchObject({
580- truncated: true,
581- strategy: "head-tail",
579+ type: "json",
580+ value: {
581+ truncated: true,
582+ strategy: "head-tail",
583+ },
582584 });
585+ }
586+
587+ test("compacts oversized tool payloads without breaking output schema", () => {
588+ const largePayload = "x".repeat(10_000);
589+ expectCompactedJsonOutput({ type: "json", value: { blob: largePayload } });
590+ });
591+
592+ test("wraps compacted legacy raw output into json output schema", () => {
593+ const largePayload = "x".repeat(10_000);
594+ expectCompactedJsonOutput({ blob: largePayload });
595+ });
596+
597+ test("rewraps compacted typed text output into json schema", () => {
598+ const largePayload = "x".repeat(10_000);
599+ expectCompactedJsonOutput({ type: "text", value: largePayload });
583600 });
584601 });