File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed
ui/desktop/src/ai-sdk-fork Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ paste = "1.0"
5959serde_yaml = " 0.9.34"
6060once_cell = " 1.20.2"
6161dirs = " 6.0.0"
62+ rand = " 0.8.5"
6263
6364[dev-dependencies ]
6465criterion = " 0.5"
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use anyhow::Result;
66use mcp_core:: content:: Content ;
77use mcp_core:: role:: Role ;
88use mcp_core:: tool:: { Tool , ToolCall } ;
9+ use rand:: { distributions:: Alphanumeric , Rng } ;
910use 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 ( )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments