reactbridge-sdk 0.2.11 → 0.2.13

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
@@ -129,7 +129,10 @@ class ReactBridgeAPI {
129
129
  sendToolResult(sessionId, toolResult, originalRequest) {
130
130
  return __awaiter(this, void 0, void 0, function* () {
131
131
  // Second API call with tool result
132
- const request = Object.assign(Object.assign({}, originalRequest), { sessionId, query: `[Tool Result] ${toolResult.summary}` });
132
+ // Pass the FULL ToolResult object to the orchestrator, not just the summary
133
+ // The orchestrator needs: status, result_items, and detailed_data for sequential execution
134
+ const toolResultJson = JSON.stringify(toolResult, null, 2);
135
+ const request = Object.assign(Object.assign({}, originalRequest), { sessionId, query: `[Tool Result] ${toolResultJson}` });
133
136
  return this.sendMessage(request);
134
137
  });
135
138
  }
@@ -513,26 +516,52 @@ function useReactBridge({ onIntentDetected, currentContext, onError, onSpeechSta
513
516
  // Step 2: If there's a tool call, execute it
514
517
  if (response.toolCall && onIntentDetected) {
515
518
  try {
516
- const toolResult = yield onIntentDetected(response.toolCall);
517
- // Step 3: Send tool result back to orchestrator
518
- if (lastRequestRef.current && response.sessionId) {
519
- const resultResponse = yield api.sendToolResult(response.sessionId, toolResult, lastRequestRef.current);
520
- // Add final assistant message with tool result context
521
- const finalMessage = {
522
- id: `assistant-final-${Date.now()}`,
523
- role: "assistant",
524
- content: resultResponse.message,
525
- timestamp: new Date(),
526
- };
527
- setMessages((prev) => [...prev, finalMessage]);
528
- // Trigger TTS for final response only if input came from voice
529
- if (fromVoiceInput) {
530
- ttsProvider.speak(resultResponse.message);
519
+ // Process tool calls in a loop to support chained/sequential tool execution
520
+ let currentToolCall = response.toolCall;
521
+ let currentResponse = response;
522
+ let toolCallCount = 0;
523
+ const maxToolCalls = 50; // Prevent infinite loops
524
+ while (currentToolCall && toolCallCount < maxToolCalls) {
525
+ toolCallCount++;
526
+ // Execute the current tool
527
+ const toolResult = yield onIntentDetected(currentToolCall);
528
+ // Step 3: Send tool result back to orchestrator
529
+ if (lastRequestRef.current && currentResponse.sessionId) {
530
+ const resultResponse = yield api.sendToolResult(currentResponse.sessionId, toolResult, lastRequestRef.current);
531
+ // Add assistant message with tool result context
532
+ const finalMessage = {
533
+ id: `assistant-final-${Date.now()}-${toolCallCount}`,
534
+ role: "assistant",
535
+ content: resultResponse.message,
536
+ timestamp: new Date(),
537
+ toolCall: resultResponse.toolCall,
538
+ };
539
+ setMessages((prev) => [...prev, finalMessage]);
540
+ // Trigger TTS for final response only if input came from voice (first iteration only)
541
+ if (fromVoiceInput && toolCallCount === 1) {
542
+ ttsProvider.speak(resultResponse.message);
543
+ }
544
+ if (onAgentResponse && toolCallCount === 1) {
545
+ onAgentResponse(resultResponse.message);
546
+ }
547
+ // Check if there's another tool call in the response (chained execution)
548
+ if (resultResponse.toolCall) {
549
+ currentToolCall = resultResponse.toolCall;
550
+ currentResponse = resultResponse;
551
+ }
552
+ else {
553
+ // No more tool calls, exit loop
554
+ currentToolCall = null;
555
+ }
531
556
  }
532
- if (onAgentResponse) {
533
- onAgentResponse(resultResponse.message);
557
+ else {
558
+ // Cannot send result, exit loop
559
+ currentToolCall = null;
534
560
  }
535
561
  }
562
+ if (toolCallCount >= maxToolCalls) {
563
+ console.warn("Tool call loop exceeded maximum iterations. Possible infinite loop detected.");
564
+ }
536
565
  }
537
566
  catch (toolError) {
538
567
  const errorMessage = toolError instanceof Error