reactbridge-sdk 0.2.16 → 0.2.18
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/components/ReactBridgeChatbox.d.ts.map +1 -1
- package/dist/components/ReactBridgeSearch.d.ts.map +1 -1
- package/dist/hooks/useReactBridge.d.ts.map +1 -1
- package/dist/index.esm.js +95 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +95 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactBridgeChatbox.d.ts","sourceRoot":"","sources":["../../src/components/ReactBridgeChatbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAIxE,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,KAAK,EACL,cAAc,EACf,MAAM,UAAU,CAAC;AA2MlB,MAAM,WAAW,uBAAuB;IAEtC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,KAAK,CAAC,SAAS,CAAC;IAC1D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAGjC,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAG7C,UAAU,CAAC,EAAE,UAAU,GAAG,OAA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AuB,qBA06BzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactBridgeSearch.d.ts","sourceRoot":"","sources":["../../src/components/ReactBridgeSearch.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ReactBridgeSearch.d.ts","sourceRoot":"","sources":["../../src/components/ReactBridgeSearch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAGxE,OAAO,KAAK,EACV,gBAAgB,EAEhB,KAAK,EACL,cAAc,EACf,MAAM,UAAU,CAAC;AAoFlB,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C;AAED,wBAAgB,iBAAiB,CAAC,EAChC,gBAAgB,EAChB,cAAc,EACd,WAAyB,EACzB,KAAc,EACd,UAAc,EACd,KAAK,EAAE,aAAa,EACpB,OAAO,EACP,aAAa,EACb,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,EAAE,sBAAsB,qBAwdxB"}
|
|
@@ -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,CA6R9C"}
|
package/dist/index.esm.js
CHANGED
|
@@ -523,6 +523,7 @@ function useReactBridge({ onIntentDetected, currentContext, onError, onSpeechSta
|
|
|
523
523
|
let currentResponse = response;
|
|
524
524
|
let toolCallCount = 0;
|
|
525
525
|
const maxToolCalls = 50; // Prevent infinite loops
|
|
526
|
+
let previousResultResponse = null;
|
|
526
527
|
while (currentToolCall && toolCallCount < maxToolCalls) {
|
|
527
528
|
toolCallCount++;
|
|
528
529
|
// Execute the current tool
|
|
@@ -530,6 +531,14 @@ function useReactBridge({ onIntentDetected, currentContext, onError, onSpeechSta
|
|
|
530
531
|
// Step 3: Send tool result back to orchestrator
|
|
531
532
|
if (lastRequestRef.current && currentResponse.sessionId) {
|
|
532
533
|
const resultResponse = yield api.sendToolResult(currentResponse.sessionId, toolResult, lastRequestRef.current);
|
|
534
|
+
// Check if result is identical to previous one (prevent infinite loops on duplicate responses)
|
|
535
|
+
const currentResultString = JSON.stringify(resultResponse);
|
|
536
|
+
if (previousResultResponse === currentResultString) {
|
|
537
|
+
console.warn("Identical tool response detected. Exiting loop to prevent infinite loop.");
|
|
538
|
+
currentToolCall = null;
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
previousResultResponse = currentResultString;
|
|
533
542
|
// Add assistant message with tool result context
|
|
534
543
|
const finalMessage = {
|
|
535
544
|
id: `assistant-final-${Date.now()}-${toolCallCount}`,
|
|
@@ -879,6 +888,42 @@ toggleButtonClass = defaultToggleButtonClass, toggleButtonTitle = "Open chat ass
|
|
|
879
888
|
document.addEventListener("mousedown", handleClickOutside);
|
|
880
889
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
881
890
|
}, [isUploadMenuOpen, isOpen, renderMode]);
|
|
891
|
+
// Add scrollbar styling for textareas
|
|
892
|
+
useEffect(() => {
|
|
893
|
+
const styleId = "react-bridge-textarea-styles";
|
|
894
|
+
// Check if styles are already injected
|
|
895
|
+
if (!document.getElementById(styleId)) {
|
|
896
|
+
const style = document.createElement("style");
|
|
897
|
+
style.id = styleId;
|
|
898
|
+
style.textContent = `
|
|
899
|
+
.react-bridge-textarea {
|
|
900
|
+
scrollbar-width: thin;
|
|
901
|
+
scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
.react-bridge-textarea::-webkit-scrollbar {
|
|
905
|
+
width: 6px;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
.react-bridge-textarea::-webkit-scrollbar-track {
|
|
909
|
+
background: transparent;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
.react-bridge-textarea::-webkit-scrollbar-thumb {
|
|
913
|
+
background: rgba(0, 0, 0, 0.3);
|
|
914
|
+
border-radius: 3px;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
.react-bridge-textarea::-webkit-scrollbar-thumb:hover {
|
|
918
|
+
background: rgba(0, 0, 0, 0.5);
|
|
919
|
+
}
|
|
920
|
+
`;
|
|
921
|
+
document.head.appendChild(style);
|
|
922
|
+
}
|
|
923
|
+
return () => {
|
|
924
|
+
// Optional: cleanup if needed
|
|
925
|
+
};
|
|
926
|
+
}, []);
|
|
882
927
|
const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
883
928
|
e.preventDefault();
|
|
884
929
|
if ((!inputValue.trim() && !selectedFile) || isLoading)
|
|
@@ -1004,7 +1049,7 @@ toggleButtonClass = defaultToggleButtonClass, toggleButtonTitle = "Open chat ass
|
|
|
1004
1049
|
gap: theme.spacing.sm,
|
|
1005
1050
|
alignItems: "flex-end",
|
|
1006
1051
|
} },
|
|
1007
|
-
React.createElement("textarea", { ref: textareaRef, value: inputValue, onChange: handleTextareaChange, onKeyDown: handleKeyDown, placeholder: placeholder, disabled: isLoading, style: {
|
|
1052
|
+
React.createElement("textarea", { ref: textareaRef, value: inputValue, onChange: handleTextareaChange, onKeyDown: handleKeyDown, placeholder: placeholder, disabled: isLoading, className: "react-bridge-textarea", style: {
|
|
1008
1053
|
flex: 1,
|
|
1009
1054
|
padding: theme.spacing.sm,
|
|
1010
1055
|
fontSize: theme.fontSizes.md,
|
|
@@ -1018,6 +1063,7 @@ toggleButtonClass = defaultToggleButtonClass, toggleButtonTitle = "Open chat ass
|
|
|
1018
1063
|
minHeight: "40px",
|
|
1019
1064
|
maxHeight: "120px",
|
|
1020
1065
|
height: `${textareaHeight}px`,
|
|
1066
|
+
scrollbarWidth: "thin",
|
|
1021
1067
|
} }),
|
|
1022
1068
|
React.createElement("button", { type: "button", onClick: () => setIsUploadMenuOpen(!isUploadMenuOpen), disabled: isLoading, title: "Attach file", style: {
|
|
1023
1069
|
padding: theme.spacing.sm,
|
|
@@ -1210,7 +1256,7 @@ toggleButtonClass = defaultToggleButtonClass, toggleButtonTitle = "Open chat ass
|
|
|
1210
1256
|
gap: theme.spacing.sm,
|
|
1211
1257
|
alignItems: "flex-end",
|
|
1212
1258
|
} },
|
|
1213
|
-
React.createElement("textarea", { ref: textareaRef, value: inputValue, onChange: handleTextareaChange, onKeyDown: handleKeyDown, placeholder: placeholder, disabled: isLoading, style: {
|
|
1259
|
+
React.createElement("textarea", { ref: textareaRef, value: inputValue, onChange: handleTextareaChange, onKeyDown: handleKeyDown, placeholder: placeholder, disabled: isLoading, className: "react-bridge-textarea", style: {
|
|
1214
1260
|
flex: 1,
|
|
1215
1261
|
padding: theme.spacing.sm,
|
|
1216
1262
|
fontSize: theme.fontSizes.md,
|
|
@@ -1224,6 +1270,7 @@ toggleButtonClass = defaultToggleButtonClass, toggleButtonTitle = "Open chat ass
|
|
|
1224
1270
|
minHeight: "40px",
|
|
1225
1271
|
maxHeight: "120px",
|
|
1226
1272
|
height: `${textareaHeight}px`,
|
|
1273
|
+
scrollbarWidth: "thin",
|
|
1227
1274
|
} }),
|
|
1228
1275
|
React.createElement("button", { type: "button", onClick: () => setIsUploadMenuOpen(!isUploadMenuOpen), disabled: isLoading, title: "Attach file", style: {
|
|
1229
1276
|
padding: theme.spacing.sm,
|
|
@@ -1357,6 +1404,34 @@ const MIC_ICON_SVG = (React.createElement("svg", { xmlns: "http://www.w3.org/200
|
|
|
1357
1404
|
// Plus Icon SVG
|
|
1358
1405
|
const PLUS_ICON_SVG = (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: "1em", height: "1em", fill: "currentColor" },
|
|
1359
1406
|
React.createElement("path", { d: "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" })));
|
|
1407
|
+
// Expandable Message Component for Search Results
|
|
1408
|
+
const SearchResultItem = ({ content, theme, isExpanded, onToggleExpand, }) => {
|
|
1409
|
+
const characterLimit = 300;
|
|
1410
|
+
const isLongMessage = content.length > characterLimit;
|
|
1411
|
+
const displayText = isExpanded ? content : content.substring(0, characterLimit);
|
|
1412
|
+
return (React.createElement("div", { style: {
|
|
1413
|
+
display: "flex",
|
|
1414
|
+
flexDirection: "column",
|
|
1415
|
+
gap: "8px",
|
|
1416
|
+
} },
|
|
1417
|
+
React.createElement("div", { style: {
|
|
1418
|
+
whiteSpace: "pre-wrap",
|
|
1419
|
+
wordWrap: "break-word",
|
|
1420
|
+
overflowWrap: "break-word",
|
|
1421
|
+
color: theme.colors.text,
|
|
1422
|
+
} }, displayText),
|
|
1423
|
+
isLongMessage && (React.createElement("button", { onClick: onToggleExpand, style: {
|
|
1424
|
+
background: "none",
|
|
1425
|
+
border: "none",
|
|
1426
|
+
color: theme.colors.primary,
|
|
1427
|
+
cursor: "pointer",
|
|
1428
|
+
textDecoration: "underline",
|
|
1429
|
+
padding: "0",
|
|
1430
|
+
textAlign: "left",
|
|
1431
|
+
fontSize: theme.fontSizes.sm,
|
|
1432
|
+
fontWeight: "bold",
|
|
1433
|
+
} }, isExpanded ? "Show less" : "Show more..."))));
|
|
1434
|
+
};
|
|
1360
1435
|
function ReactBridgeSearch({ onIntentDetected, currentContext, placeholder = "Search...", width = "100%", maxResults = 5, theme: themeOverride, onError, onSpeechStart, onSpeechEnd, onTranscript, onAgentResponse, }) {
|
|
1361
1436
|
const { theme: contextTheme } = useReactBridgeContext();
|
|
1362
1437
|
const theme = Object.assign(Object.assign({}, contextTheme), themeOverride);
|
|
@@ -1374,6 +1449,7 @@ function ReactBridgeSearch({ onIntentDetected, currentContext, placeholder = "Se
|
|
|
1374
1449
|
const [isUploadMenuOpen, setIsUploadMenuOpen] = useState(false);
|
|
1375
1450
|
const [selectedFile, setSelectedFile] = useState(null);
|
|
1376
1451
|
const [filePreview, setFilePreview] = useState(null);
|
|
1452
|
+
const [expandedMessages, setExpandedMessages] = useState(new Set());
|
|
1377
1453
|
const containerRef = useRef(null);
|
|
1378
1454
|
const fileInputRef = useRef(null);
|
|
1379
1455
|
// Close dropdown and upload menu when clicking outside
|
|
@@ -1456,6 +1532,19 @@ function ReactBridgeSearch({ onIntentDetected, currentContext, placeholder = "Se
|
|
|
1456
1532
|
fileInputRef.current.value = "";
|
|
1457
1533
|
}
|
|
1458
1534
|
};
|
|
1535
|
+
// Toggle message expansion
|
|
1536
|
+
const toggleMessageExpansion = useCallback((messageId) => {
|
|
1537
|
+
setExpandedMessages((prev) => {
|
|
1538
|
+
const newSet = new Set(prev);
|
|
1539
|
+
if (newSet.has(messageId)) {
|
|
1540
|
+
newSet.delete(messageId);
|
|
1541
|
+
}
|
|
1542
|
+
else {
|
|
1543
|
+
newSet.add(messageId);
|
|
1544
|
+
}
|
|
1545
|
+
return newSet;
|
|
1546
|
+
});
|
|
1547
|
+
}, []);
|
|
1459
1548
|
const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
1460
1549
|
e.preventDefault();
|
|
1461
1550
|
if ((!inputValue.trim() && !selectedFile) || isLoading)
|
|
@@ -1482,7 +1571,8 @@ function ReactBridgeSearch({ onIntentDetected, currentContext, placeholder = "Se
|
|
|
1482
1571
|
// Get only assistant messages (not system messages)
|
|
1483
1572
|
const displayMessages = messages
|
|
1484
1573
|
.filter((msg) => msg.role === "assistant")
|
|
1485
|
-
.slice(-maxResults)
|
|
1574
|
+
.slice(-maxResults)
|
|
1575
|
+
.reverse();
|
|
1486
1576
|
return (React.createElement("div", { ref: containerRef, style: {
|
|
1487
1577
|
position: "relative",
|
|
1488
1578
|
width,
|
|
@@ -1654,12 +1744,12 @@ function ReactBridgeSearch({ onIntentDetected, currentContext, placeholder = "Se
|
|
|
1654
1744
|
borderBottom: `1px solid ${theme.colors.border}`,
|
|
1655
1745
|
fontSize: theme.fontSizes.sm,
|
|
1656
1746
|
color: theme.colors.text,
|
|
1657
|
-
cursor: "pointer",
|
|
1658
1747
|
}, onMouseEnter: (e) => {
|
|
1659
1748
|
e.currentTarget.style.backgroundColor = theme.colors.surface;
|
|
1660
1749
|
}, onMouseLeave: (e) => {
|
|
1661
1750
|
e.currentTarget.style.backgroundColor = theme.colors.background;
|
|
1662
|
-
} },
|
|
1751
|
+
} },
|
|
1752
|
+
React.createElement(SearchResultItem, { content: message.content, theme: theme, isExpanded: expandedMessages.has(message.id), onToggleExpand: () => toggleMessageExpansion(message.id) }))))))));
|
|
1663
1753
|
}
|
|
1664
1754
|
|
|
1665
1755
|
const darkTheme = {
|