Skip to content

Commit 62940dd

Browse files
committed
Allow text-only native Tzafon tool-result replay
1 parent f588ba4 commit 62940dd

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎packages/ai/src/providers/tzafon/provider.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,12 @@ function convertMessages(messages: readonly Message[], nativeComputerName?: stri
344344
.trim();
345345
const image = [...message.content].reverse().find((part): part is ImageContent => part.type === "image");
346346
if (nativeComputerName && message.toolName === nativeComputerName) {
347-
if (!image) {
348-
throw new Error(
349-
"Tzafon native computer action loops require image tool results; text-only results are unsupported because CUA does not capture post-action screenshots automatically.",
350-
);
351-
}
352347
items.push({
353348
type: "computer_call_output",
354349
call_id: message.toolCallId,
355-
output: { type: "computer_screenshot", image_url: `data:${image.mimeType};base64,${image.data}` },
350+
output: image
351+
? { type: "computer_screenshot", image_url: `data:${image.mimeType};base64,${image.data}` }
352+
: { type: "computer_screenshot", error: message.isError ? text || "tool execution failed" : text || "no screenshot" },
356353
});
357354
continue;
358355
}

‎packages/ai/test/tzafon-provider.test.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ describe("streamTzafonResponses", () => {
9999
expect(toolCalls(message.content)).toEqual([]);
100100
});
101101

102-
it("rejects text-only native computer results before sending a request", () => {
103-
expect(() => tzafon.buildTzafonRequestInput(model, {
102+
it("serializes text-only native computer results as computer_screenshot errors", () => {
103+
const payload = tzafon.buildTzafonRequestInput(model, {
104104
messages: [
105105
{
106106
role: "assistant",
@@ -125,7 +125,19 @@ describe("streamTzafonResponses", () => {
125125
}, {
126126
disableResponseThreading: true,
127127
cuaIncomingToolPlan: { tzafonComputerName: "computer", yutoriNames: {}, googleNames: {}, googleExcludedNames: [], nativeToolNames: ["computer"] },
128-
})).toThrow("text-only results are unsupported");
128+
});
129+
130+
expect(payload.input).toEqual(expect.arrayContaining([
131+
expect.objectContaining({ type: "computer_call", call_id: "call_click" }),
132+
expect.objectContaining({
133+
type: "computer_call_output",
134+
call_id: "call_click",
135+
output: {
136+
type: "computer_screenshot",
137+
error: "Actions executed successfully.",
138+
},
139+
}),
140+
]));
129141
});
130142

131143
it("degrades malformed function-call arguments to empty args instead of failing the turn", async () => {

0 commit comments

Comments
 (0)