Skip to content

Commit bb5fe27

Browse files
author
Peter Steinberger
committed
fix(google): preserve signed empty SDK response parts
1 parent 146f5a8 commit bb5fe27

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎packages/ai/src/providers/google-shared.convert.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ describe("google-shared convertMessages", () => {
201201
]);
202202
});
203203

204+
it.each([
205+
{
206+
label: "text",
207+
block: { type: "text", text: "", textSignature: "c2lnbmVk" },
208+
part: { text: "", thoughtSignature: "c2lnbmVk" },
209+
},
210+
{
211+
label: "thinking",
212+
block: { type: "thinking", thinking: "", thinkingSignature: "c2lnbmVk" },
213+
part: { thought: true, text: "", thoughtSignature: "c2lnbmVk" },
214+
},
215+
])("preserves the empty content field of a signed $label part", ({ block, part }) => {
216+
const model = makeModel("gemini-3-flash");
217+
218+
const contents = convertMessagesForTest(model, {
219+
messages: [makeGoogleAssistantMessage(model.id, [block])],
220+
} as Context);
221+
222+
expect(contents).toEqual([{ role: "model", parts: [part] }]);
223+
});
224+
204225
it("supplies the documented Gemini 3 thought-signature placeholder for unsigned calls", () => {
205226
const model = makeModel("gemini-3-flash");
206227
const contents = convertMessagesForTest(model, {

‎packages/ai/src/providers/google-shared.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,14 @@ describe("consumeGoogleGenerateContentStream", () => {
500500

501501
expect(output.content).toEqual(content);
502502
expect(events).toContainEqual(expect.objectContaining({ type: "text_delta", delta: "" }));
503-
expect(convertMessages(model, { messages: [output] })).toEqual([{ role: "model", parts }]);
503+
expect(convertMessages(model, { messages: [output] })).toEqual([
504+
{
505+
role: "model",
506+
parts: parts.map((part) =>
507+
"thoughtSignature" in part && !("text" in part) ? { ...part, text: "" } : part,
508+
),
509+
},
510+
]);
504511
});
505512

506513
it("keeps an explicit signature-only thought separate from the preceding tool call", async () => {

‎packages/ai/src/providers/google-shared.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export function convertMessages<T extends GoogleApiType>(
237237
continue;
238238
}
239239
parts.push({
240-
...(block.text && { text: sanitizeSurrogates(block.text) }),
240+
text: sanitizeSurrogates(block.text),
241241
...(thoughtSignature && { thoughtSignature }),
242242
});
243243
} else if (block.type === "thinking") {
@@ -253,7 +253,7 @@ export function convertMessages<T extends GoogleApiType>(
253253
if (isSameProviderAndModel) {
254254
parts.push({
255255
thought: true,
256-
...(block.thinking && { text: sanitizeSurrogates(block.thinking) }),
256+
text: sanitizeSurrogates(block.thinking),
257257
...(thoughtSignature && { thoughtSignature }),
258258
});
259259
} else {

0 commit comments

Comments
 (0)