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/hooks/useReactBridge.d.ts.map +1 -1
- package/dist/index.esm.js +47 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +47 -18
- package/dist/index.js.map +1 -1
- package/dist/utils/api.d.ts.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
|
@@ -127,7 +127,10 @@ class ReactBridgeAPI {
|
|
|
127
127
|
sendToolResult(sessionId, toolResult, originalRequest) {
|
|
128
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
129
|
// Second API call with tool result
|
|
130
|
-
|
|
130
|
+
// Pass the FULL ToolResult object to the orchestrator, not just the summary
|
|
131
|
+
// The orchestrator needs: status, result_items, and detailed_data for sequential execution
|
|
132
|
+
const toolResultJson = JSON.stringify(toolResult, null, 2);
|
|
133
|
+
const request = Object.assign(Object.assign({}, originalRequest), { sessionId, query: `[Tool Result] ${toolResultJson}` });
|
|
131
134
|
return this.sendMessage(request);
|
|
132
135
|
});
|
|
133
136
|
}
|
|
@@ -511,26 +514,52 @@ function useReactBridge({ onIntentDetected, currentContext, onError, onSpeechSta
|
|
|
511
514
|
// Step 2: If there's a tool call, execute it
|
|
512
515
|
if (response.toolCall && onIntentDetected) {
|
|
513
516
|
try {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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
|
+
}
|
|
529
554
|
}
|
|
530
|
-
|
|
531
|
-
|
|
555
|
+
else {
|
|
556
|
+
// Cannot send result, exit loop
|
|
557
|
+
currentToolCall = null;
|
|
532
558
|
}
|
|
533
559
|
}
|
|
560
|
+
if (toolCallCount >= maxToolCalls) {
|
|
561
|
+
console.warn("Tool call loop exceeded maximum iterations. Possible infinite loop detected.");
|
|
562
|
+
}
|
|
534
563
|
}
|
|
535
564
|
catch (toolError) {
|
|
536
565
|
const errorMessage = toolError instanceof Error
|