fix(gemini): guard terminal model turns and unresponded functionCalls in normalizeGeminiContents
This commit is contained in:
@@ -432,7 +432,7 @@ export function cleanJSONSchemaForAntigravity(schema) {
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
// Merge adjacent same-role messages, strip empty parts, ensure initial user turn
|
||||
// Merge adjacent same-role messages, strip empty parts, ensure initial and terminal user turns
|
||||
export function normalizeGeminiContents(contents) {
|
||||
const out = [];
|
||||
for (const c of contents || []) {
|
||||
@@ -446,6 +446,23 @@ export function normalizeGeminiContents(contents) {
|
||||
if (out.length > 0 && out[0].role !== "user") {
|
||||
out.unshift({ role: "user", parts: [{ text: "..." }] });
|
||||
}
|
||||
if (out.length > 0 && out.at(-1).role === "model") {
|
||||
const fnCalls = (out.at(-1).parts || []).filter(p => p && p.functionCall);
|
||||
if (fnCalls.length > 0) {
|
||||
const responses = fnCalls.map(p => {
|
||||
const call = p.functionCall || {};
|
||||
const fr = {
|
||||
name: call.name || "tool",
|
||||
response: { result: "Continue." }
|
||||
};
|
||||
if (call.id) fr.id = call.id;
|
||||
return { functionResponse: fr };
|
||||
});
|
||||
out.push({ role: "user", parts: responses });
|
||||
} else {
|
||||
out.push({ role: "user", parts: [{ text: "Continue." }] });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user