reactbridge-sdk 0.2.12 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"useReactBridge.d.ts","sourceRoot":"","sources":["../../src/hooks/useReactBridge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,qBAAqB,EACrB,oBAAoB,EAIrB,MAAM,UAAU,CAAC;AAElB,wBAAgB,cAAc,CAAC,EAC7B,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,aAAa,EACb,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,EAAE,qBAAqB,GAAG,oBAAoB,CAuP9C"}
1
+ {"version":3,"file":"useReactBridge.d.ts","sourceRoot":"","sources":["../../src/hooks/useReactBridge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,qBAAqB,EACrB,oBAAoB,EAIrB,MAAM,UAAU,CAAC;AAElB,wBAAgB,cAAc,CAAC,EAC7B,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,aAAa,EACb,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,EAAE,qBAAqB,GAAG,oBAAoB,CAmR9C"}
package/dist/index.esm.js CHANGED
@@ -514,26 +514,52 @@ function useReactBridge({ onIntentDetected, currentContext, onError, onSpeechSta
514
514
  // Step 2: If there's a tool call, execute it
515
515
  if (response.toolCall && onIntentDetected) {
516
516
  try {
517
- const toolResult = yield onIntentDetected(response.toolCall);
518
- // Step 3: Send tool result back to orchestrator
519
- if (lastRequestRef.current && response.sessionId) {
520
- const resultResponse = yield api.sendToolResult(response.sessionId, toolResult, lastRequestRef.current);
521
- // Add final assistant message with tool result context
522
- const finalMessage = {
523
- id: `assistant-final-${Date.now()}`,
524
- role: "assistant",
525
- content: resultResponse.message,
526
- timestamp: new Date(),
527
- };
528
- setMessages((prev) => [...prev, finalMessage]);
529
- // Trigger TTS for final response only if input came from voice
530
- if (fromVoiceInput) {
531
- ttsProvider.speak(resultResponse.message);
517
+ // Process tool calls in a loop to support chained/sequential tool execution
518
+ let currentToolCall = response.toolCall;
519
+ let currentResponse = response;
520
+ let toolCallCount = 0;
521
+ const maxToolCalls = 50; // Prevent infinite loops
522
+ while (currentToolCall && toolCallCount < maxToolCalls) {
523
+ toolCallCount++;
524
+ // Execute the current tool
525
+ const toolResult = yield onIntentDetected(currentToolCall);
526
+ // Step 3: Send tool result back to orchestrator
527
+ if (lastRequestRef.current && currentResponse.sessionId) {
528
+ const resultResponse = yield api.sendToolResult(currentResponse.sessionId, toolResult, lastRequestRef.current);
529
+ // Add assistant message with tool result context
530
+ const finalMessage = {
531
+ id: `assistant-final-${Date.now()}-${toolCallCount}`,
532
+ role: "assistant",
533
+ content: resultResponse.message,
534
+ timestamp: new Date(),
535
+ toolCall: resultResponse.toolCall,
536
+ };
537
+ setMessages((prev) => [...prev, finalMessage]);
538
+ // Trigger TTS for final response only if input came from voice (first iteration only)
539
+ if (fromVoiceInput && toolCallCount === 1) {
540
+ ttsProvider.speak(resultResponse.message);
541
+ }
542
+ if (onAgentResponse && toolCallCount === 1) {
543
+ onAgentResponse(resultResponse.message);
544
+ }
545
+ // Check if there's another tool call in the response (chained execution)
546
+ if (resultResponse.toolCall) {
547
+ currentToolCall = resultResponse.toolCall;
548
+ currentResponse = resultResponse;
549
+ }
550
+ else {
551
+ // No more tool calls, exit loop
552
+ currentToolCall = null;
553
+ }
532
554
  }
533
- if (onAgentResponse) {
534
- onAgentResponse(resultResponse.message);
555
+ else {
556
+ // Cannot send result, exit loop
557
+ currentToolCall = null;
535
558
  }
536
559
  }
560
+ if (toolCallCount >= maxToolCalls) {
561
+ console.warn("Tool call loop exceeded maximum iterations. Possible infinite loop detected.");
562
+ }
537
563
  }
538
564
  catch (toolError) {
539
565
  const errorMessage = toolError instanceof Error