reactbridge-sdk 0.2.12 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -132,7 +132,11 @@ class ReactBridgeAPI {
132
132
  // Pass the FULL ToolResult object to the orchestrator, not just the summary
133
133
  // The orchestrator needs: status, result_items, and detailed_data for sequential execution
134
134
  const toolResultJson = JSON.stringify(toolResult, null, 2);
135
- const request = Object.assign(Object.assign({}, originalRequest), { sessionId, query: `[Tool Result] ${toolResultJson}` });
135
+ const request = Object.assign(Object.assign({}, originalRequest), { sessionId, query: `[Tool Result] ${toolResultJson}`,
136
+ // CRITICAL: Remove document/image from subsequent requests
137
+ // If we keep them, the orchestrator will reprocess the PDF on every tool result
138
+ // This causes sequential execution to restart instead of continuing
139
+ document: undefined, image: undefined, modalityHint: undefined });
136
140
  return this.sendMessage(request);
137
141
  });
138
142
  }
@@ -516,26 +520,52 @@ function useReactBridge({ onIntentDetected, currentContext, onError, onSpeechSta
516
520
  // Step 2: If there's a tool call, execute it
517
521
  if (response.toolCall && onIntentDetected) {
518
522
  try {
519
- const toolResult = yield onIntentDetected(response.toolCall);
520
- // Step 3: Send tool result back to orchestrator
521
- if (lastRequestRef.current && response.sessionId) {
522
- const resultResponse = yield api.sendToolResult(response.sessionId, toolResult, lastRequestRef.current);
523
- // Add final assistant message with tool result context
524
- const finalMessage = {
525
- id: `assistant-final-${Date.now()}`,
526
- role: "assistant",
527
- content: resultResponse.message,
528
- timestamp: new Date(),
529
- };
530
- setMessages((prev) => [...prev, finalMessage]);
531
- // Trigger TTS for final response only if input came from voice
532
- if (fromVoiceInput) {
533
- ttsProvider.speak(resultResponse.message);
523
+ // Process tool calls in a loop to support chained/sequential tool execution
524
+ let currentToolCall = response.toolCall;
525
+ let currentResponse = response;
526
+ let toolCallCount = 0;
527
+ const maxToolCalls = 50; // Prevent infinite loops
528
+ while (currentToolCall && toolCallCount < maxToolCalls) {
529
+ toolCallCount++;
530
+ // Execute the current tool
531
+ const toolResult = yield onIntentDetected(currentToolCall);
532
+ // Step 3: Send tool result back to orchestrator
533
+ if (lastRequestRef.current && currentResponse.sessionId) {
534
+ const resultResponse = yield api.sendToolResult(currentResponse.sessionId, toolResult, lastRequestRef.current);
535
+ // Add assistant message with tool result context
536
+ const finalMessage = {
537
+ id: `assistant-final-${Date.now()}-${toolCallCount}`,
538
+ role: "assistant",
539
+ content: resultResponse.message,
540
+ timestamp: new Date(),
541
+ toolCall: resultResponse.toolCall,
542
+ };
543
+ setMessages((prev) => [...prev, finalMessage]);
544
+ // Trigger TTS for final response only if input came from voice (first iteration only)
545
+ if (fromVoiceInput && toolCallCount === 1) {
546
+ ttsProvider.speak(resultResponse.message);
547
+ }
548
+ if (onAgentResponse && toolCallCount === 1) {
549
+ onAgentResponse(resultResponse.message);
550
+ }
551
+ // Check if there's another tool call in the response (chained execution)
552
+ if (resultResponse.toolCall) {
553
+ currentToolCall = resultResponse.toolCall;
554
+ currentResponse = resultResponse;
555
+ }
556
+ else {
557
+ // No more tool calls, exit loop
558
+ currentToolCall = null;
559
+ }
534
560
  }
535
- if (onAgentResponse) {
536
- onAgentResponse(resultResponse.message);
561
+ else {
562
+ // Cannot send result, exit loop
563
+ currentToolCall = null;
537
564
  }
538
565
  }
566
+ if (toolCallCount >= maxToolCalls) {
567
+ console.warn("Tool call loop exceeded maximum iterations. Possible infinite loop detected.");
568
+ }
539
569
  }
540
570
  catch (toolError) {
541
571
  const errorMessage = toolError instanceof Error