fix(gemini): normalize contents and handle intermediate tool responses in Antigravity

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
decolua
2026-09-09 09:45:18 +07:00
parent eb712ca821
commit e7b5f09d50
3 changed files with 33 additions and 26 deletions

View File

@@ -432,3 +432,21 @@ export function cleanJSONSchemaForAntigravity(schema) {
return cleaned;
}
// Merge adjacent same-role messages, strip empty parts, ensure initial user turn
export function normalizeGeminiContents(contents) {
const out = [];
for (const c of contents || []) {
if (!c?.role || !Array.isArray(c.parts)) continue;
const parts = c.parts.filter(p => p && Object.keys(p).length > 0);
if (parts.length === 0) continue;
const last = out.at(-1);
if (last?.role === c.role) last.parts.push(...parts);
else out.push({ ...c, parts: [...parts] });
}
if (out.length > 0 && out[0].role !== "user") {
out.unshift({ role: "user", parts: [{ text: "..." }] });
}
return out;
}