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.
- package/dist/hooks/useReactBridge.d.ts.map +1 -1
- package/dist/index.esm.js +43 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +43 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -516,26 +516,52 @@ function useReactBridge({ onIntentDetected, currentContext, onError, onSpeechSta
|
|
|
516
516
|
// Step 2: If there's a tool call, execute it
|
|
517
517
|
if (response.toolCall && onIntentDetected) {
|
|
518
518
|
try {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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
|
+
}
|
|
534
556
|
}
|
|
535
|
-
|
|
536
|
-
|
|
557
|
+
else {
|
|
558
|
+
// Cannot send result, exit loop
|
|
559
|
+
currentToolCall = null;
|
|
537
560
|
}
|
|
538
561
|
}
|
|
562
|
+
if (toolCallCount >= maxToolCalls) {
|
|
563
|
+
console.warn("Tool call loop exceeded maximum iterations. Possible infinite loop detected.");
|
|
564
|
+
}
|
|
539
565
|
}
|
|
540
566
|
catch (toolError) {
|
|
541
567
|
const errorMessage = toolError instanceof Error
|