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
|
@@ -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,
|
|
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
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
-
|
|
534
|
-
|
|
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
|