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