Skip to content

Commit a916f84

Browse files
committed
fix: prefer content over parts in Gemini Interactions Turn parsing
1 parent 7e51970 commit a916f84

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/gemini-interactions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ interface InteractionsContentBlock {
5050

5151
interface InteractionsTurn {
5252
role: string;
53+
content?: InteractionsContentBlock[];
5354
parts?: InteractionsContentBlock[];
5455
}
5556

@@ -100,17 +101,18 @@ export function geminiInteractionsToCompletionRequest(
100101
// Turn[] format
101102
for (const turn of req.input as InteractionsTurn[]) {
102103
const role = turn.role === "model" ? "assistant" : turn.role;
103-
if (!turn.parts || turn.parts.length === 0) {
104+
const blocks = turn.content ?? turn.parts;
105+
if (!blocks || blocks.length === 0) {
104106
if (role === "user" || role === "assistant") {
105107
messages.push({ role: role as "user" | "assistant", content: "" });
106108
}
107109
continue;
108110
}
109111

110112
// Check for function_call or function_result parts
111-
const funcCallParts = turn.parts.filter((p) => p.type === "function_call");
112-
const funcResultParts = turn.parts.filter((p) => p.type === "function_result");
113-
const textParts = turn.parts.filter((p) => p.type === "text");
113+
const funcCallParts = blocks.filter((p) => p.type === "function_call");
114+
const funcResultParts = blocks.filter((p) => p.type === "function_result");
115+
const textParts = blocks.filter((p) => p.type === "text");
114116

115117
if (funcCallParts.length > 0) {
116118
// Assistant tool call message

0 commit comments

Comments
 (0)