Skip to content

Commit 954bdb4

Browse files
authored
fix: Fix google provider in app (#859)
1 parent f7a9806 commit 954bdb4

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

crates/goose/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ paste = "1.0"
5959
serde_yaml = "0.9.34"
6060
once_cell = "1.20.2"
6161
dirs = "6.0.0"
62+
rand = "0.8.5"
6263

6364
[dev-dependencies]
6465
criterion = "0.5"

crates/goose/src/providers/formats/google.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use anyhow::Result;
66
use mcp_core::content::Content;
77
use mcp_core::role::Role;
88
use mcp_core::tool::{Tool, ToolCall};
9+
use rand::{distributions::Alphanumeric, Rng};
910
use serde_json::{json, Map, Value};
1011

1112
/// Convert internal Message format to Google's API message specification
@@ -198,14 +199,16 @@ pub fn response_to_message(response: Value) -> Result<Message> {
198199
.and_then(|content| content.get("parts"))
199200
.and_then(|parts| parts.as_array())
200201
.unwrap_or(&binding);
202+
201203
for part in parts {
202204
if let Some(text) = part.get("text").and_then(|v| v.as_str()) {
203205
content.push(MessageContent::text(text.to_string()));
204206
} else if let Some(function_call) = part.get("functionCall") {
205-
let id = function_call["name"]
206-
.as_str()
207-
.unwrap_or_default()
208-
.to_string();
207+
let id: String = rand::thread_rng()
208+
.sample_iter(&Alphanumeric)
209+
.take(8)
210+
.map(char::from)
211+
.collect();
209212
let name = function_call["name"]
210213
.as_str()
211214
.unwrap_or_default()

ui/desktop/src/ai-sdk-fork/process-custom-chat-response.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,18 @@ export async function processCustomChatResponse({
8989
onTextPart(value) {
9090
// If the last event wasn't text, or we don't have a current message, create a new one
9191
if (lastEventType !== 'text' || currentMessage == null) {
92-
archiveCurrentMessage();
93-
currentMessage = createNewMessage();
92+
// Only archive if there are no tool invocations in 'call' state
93+
const hasPendingToolCalls =
94+
currentMessage?.toolInvocations?.some((invocation) => invocation.state === 'call') ??
95+
false;
96+
97+
if (!hasPendingToolCalls) {
98+
archiveCurrentMessage();
99+
}
100+
101+
if (!currentMessage) {
102+
currentMessage = createNewMessage();
103+
}
94104
currentMessage.content = value;
95105
} else {
96106
// Concatenate with the existing message

0 commit comments

Comments
 (0)