Skip to content

Commit 5f4df15

Browse files
hackertronclaude
andcommitted
fix: avoid Gemini SDK warning when response contains FunctionCall parts
Replace result.Text() with geminiTextParts() that extracts text directly from candidate parts, skipping FunctionCall/FunctionResponse parts. The SDK's Text() method emits "Warning: non-text parts FunctionCall" which leaked into streamed content and caused the TUI to appear stuck. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b6f0b05 commit 5f4df15

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

internal/provider/gemini.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (p *GeminiProvider) Stream(ctx context.Context, c *types.Context) <-chan ty
7070
return
7171
}
7272

73-
if text := result.Text(); text != "" {
73+
if text := geminiTextParts(result); text != "" {
7474
ch <- types.StreamItem{Type: types.StreamText, Text: text}
7575
}
7676

@@ -119,11 +119,32 @@ func (p *GeminiProvider) buildRequest(c *types.Context) ([]*genai.Content, *gena
119119
return contents, config
120120
}
121121

122+
// geminiTextParts extracts text from candidate parts directly, skipping
123+
// FunctionCall/FunctionResponse parts. This avoids the SDK's result.Text()
124+
// which emits a warning string when non-text parts are present.
125+
func geminiTextParts(result *genai.GenerateContentResponse) string {
126+
var texts []string
127+
if result.Candidates == nil {
128+
return ""
129+
}
130+
for _, cand := range result.Candidates {
131+
if cand.Content == nil {
132+
continue
133+
}
134+
for _, part := range cand.Content.Parts {
135+
if part.Text != "" && part.FunctionCall == nil && part.FunctionResponse == nil {
136+
texts = append(texts, part.Text)
137+
}
138+
}
139+
}
140+
return strings.Join(texts, "")
141+
}
142+
122143
func geminiResultToResponse(result *genai.GenerateContentResponse) *types.Response {
123144
resp := &types.Response{
124145
Message: types.Message{
125146
Role: types.RoleAssistant,
126-
Content: result.Text(),
147+
Content: geminiTextParts(result),
127148
},
128149
}
129150

0 commit comments

Comments
 (0)