@kite-copilot/chat-panel 0.2.48 → 0.2.49
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/README.md +30 -0
- package/dist/auto.cjs +92 -9
- package/dist/auto.js +1 -1
- package/dist/{chunk-LOTJ3U5L.js → chunk-YZXB3LLU.js} +84 -1
- package/dist/embed.global.js +58 -23
- package/dist/index.cjs +92 -9
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -66,7 +66,7 @@ __export(src_exports, {
|
|
|
66
66
|
module.exports = __toCommonJS(src_exports);
|
|
67
67
|
|
|
68
68
|
// src/createKiteChat.tsx
|
|
69
|
-
var
|
|
69
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
70
70
|
var import_client = require("react-dom/client");
|
|
71
71
|
|
|
72
72
|
// src/ChatPanel.tsx
|
|
@@ -478,6 +478,78 @@ function useOrgConfig({ agentUrl, orgId }) {
|
|
|
478
478
|
return state;
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
+
// src/hooks/useFrontendToolExecutor.ts
|
|
482
|
+
var import_react = require("react");
|
|
483
|
+
function useFrontendToolExecutor({
|
|
484
|
+
productBackendUrl,
|
|
485
|
+
agentUrl,
|
|
486
|
+
sessionId
|
|
487
|
+
}) {
|
|
488
|
+
const sendToolResult = (0, import_react.useCallback)(async (payload) => {
|
|
489
|
+
try {
|
|
490
|
+
await fetch(`${agentUrl}/chat/tool-result`, {
|
|
491
|
+
method: "POST",
|
|
492
|
+
headers: {
|
|
493
|
+
"Content-Type": "application/json"
|
|
494
|
+
},
|
|
495
|
+
body: JSON.stringify(payload)
|
|
496
|
+
});
|
|
497
|
+
} catch (error) {
|
|
498
|
+
console.error("[FrontendToolExecutor] Failed to send tool result:", error);
|
|
499
|
+
}
|
|
500
|
+
}, [agentUrl]);
|
|
501
|
+
const executeToolRequest = (0, import_react.useCallback)(async (toolRequest) => {
|
|
502
|
+
const { call_id, tool_name, arguments: args, endpoint, method, path_params } = toolRequest;
|
|
503
|
+
console.log("[FrontendToolExecutor] Executing tool:", tool_name, "with args:", args);
|
|
504
|
+
try {
|
|
505
|
+
let url = endpoint;
|
|
506
|
+
for (const param of path_params) {
|
|
507
|
+
if (args[param]) {
|
|
508
|
+
url = url.replace(`{${param}}`, encodeURIComponent(args[param]));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const queryParams = new URLSearchParams();
|
|
512
|
+
for (const [key, value] of Object.entries(args)) {
|
|
513
|
+
if (!path_params.includes(key) && value !== void 0 && value !== null) {
|
|
514
|
+
queryParams.append(key, String(value));
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
const queryString = queryParams.toString();
|
|
518
|
+
const fullUrl = `${productBackendUrl}${url}${queryString ? "?" + queryString : ""}`;
|
|
519
|
+
console.log("[FrontendToolExecutor] Fetching:", fullUrl);
|
|
520
|
+
const response = await fetch(fullUrl, {
|
|
521
|
+
method,
|
|
522
|
+
credentials: "include",
|
|
523
|
+
headers: {
|
|
524
|
+
"Accept": "application/json",
|
|
525
|
+
"Content-Type": "application/json"
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
let result;
|
|
529
|
+
if (response.ok) {
|
|
530
|
+
result = await response.json();
|
|
531
|
+
console.log("[FrontendToolExecutor] Tool result:", result);
|
|
532
|
+
} else {
|
|
533
|
+
const errorText = await response.text();
|
|
534
|
+
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
535
|
+
}
|
|
536
|
+
await sendToolResult({
|
|
537
|
+
session_id: sessionId,
|
|
538
|
+
call_id,
|
|
539
|
+
result
|
|
540
|
+
});
|
|
541
|
+
} catch (error) {
|
|
542
|
+
console.error("[FrontendToolExecutor] Tool execution failed:", error);
|
|
543
|
+
await sendToolResult({
|
|
544
|
+
session_id: sessionId,
|
|
545
|
+
call_id,
|
|
546
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
}, [productBackendUrl, sessionId, sendToolResult]);
|
|
550
|
+
return { executeToolRequest };
|
|
551
|
+
}
|
|
552
|
+
|
|
481
553
|
// src/components/ui/card.tsx
|
|
482
554
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
483
555
|
function Card({ className, ...props }) {
|
|
@@ -1078,7 +1150,7 @@ function TypingIndicator({ className = "" }) {
|
|
|
1078
1150
|
|
|
1079
1151
|
// src/ChatPanel.tsx
|
|
1080
1152
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1081
|
-
var CHAT_PANEL_VERSION = true ? "0.2.
|
|
1153
|
+
var CHAT_PANEL_VERSION = true ? "0.2.49" : "dev";
|
|
1082
1154
|
var DEFAULT_AGENT_URL = "http://localhost:5002";
|
|
1083
1155
|
var PANEL_WIDTH = 400;
|
|
1084
1156
|
var PANEL_HEIGHT = 600;
|
|
@@ -1570,6 +1642,11 @@ function ChatPanel({
|
|
|
1570
1642
|
enabled: !!effectiveProductBackendUrl && orgConfigState.status === "success"
|
|
1571
1643
|
// Only enable after config is fetched
|
|
1572
1644
|
});
|
|
1645
|
+
const { executeToolRequest } = useFrontendToolExecutor({
|
|
1646
|
+
productBackendUrl: effectiveProductBackendUrl || "",
|
|
1647
|
+
agentUrl,
|
|
1648
|
+
sessionId
|
|
1649
|
+
});
|
|
1573
1650
|
React6.useEffect(() => {
|
|
1574
1651
|
if (!effectiveProductBackendUrl || orgConfigState.status !== "success") {
|
|
1575
1652
|
return;
|
|
@@ -2584,6 +2661,12 @@ function ChatPanel({
|
|
|
2584
2661
|
content: data.message || "You've been connected to our support queue. An agent will be with you shortly."
|
|
2585
2662
|
};
|
|
2586
2663
|
setMessages((prev) => [...prev, escalationMessage]);
|
|
2664
|
+
} else if (eventType === "tool_request") {
|
|
2665
|
+
const toolRequest = data;
|
|
2666
|
+
console.log("[KiteChat] Received tool_request:", toolRequest);
|
|
2667
|
+
executeToolRequest(toolRequest).catch((err) => {
|
|
2668
|
+
console.error("[KiteChat] Tool execution failed:", err);
|
|
2669
|
+
});
|
|
2587
2670
|
} else if (eventType === "token") {
|
|
2588
2671
|
}
|
|
2589
2672
|
} catch (parseError) {
|
|
@@ -4848,14 +4931,14 @@ function KiteChatWrapper({
|
|
|
4848
4931
|
onConfigUpdate,
|
|
4849
4932
|
onStateUpdate
|
|
4850
4933
|
}) {
|
|
4851
|
-
const [config, setConfig] =
|
|
4852
|
-
const [currentPage, setCurrentPage] =
|
|
4853
|
-
const [isOpen, setIsOpen] =
|
|
4854
|
-
const isOpenRef =
|
|
4855
|
-
|
|
4934
|
+
const [config, setConfig] = import_react2.default.useState(initialConfig);
|
|
4935
|
+
const [currentPage, setCurrentPage] = import_react2.default.useState(initialConfig.currentPage || "dashboard");
|
|
4936
|
+
const [isOpen, setIsOpen] = import_react2.default.useState(false);
|
|
4937
|
+
const isOpenRef = import_react2.default.useRef(false);
|
|
4938
|
+
import_react2.default.useEffect(() => {
|
|
4856
4939
|
isOpenRef.current = isOpen;
|
|
4857
4940
|
}, [isOpen]);
|
|
4858
|
-
|
|
4941
|
+
import_react2.default.useEffect(() => {
|
|
4859
4942
|
onConfigUpdate((newConfig) => {
|
|
4860
4943
|
if (newConfig.currentPage !== void 0) {
|
|
4861
4944
|
setCurrentPage(newConfig.currentPage);
|
|
@@ -4867,7 +4950,7 @@ function KiteChatWrapper({
|
|
|
4867
4950
|
getIsOpen: () => isOpenRef.current
|
|
4868
4951
|
});
|
|
4869
4952
|
}, [onConfigUpdate, onStateUpdate]);
|
|
4870
|
-
|
|
4953
|
+
import_react2.default.useEffect(() => {
|
|
4871
4954
|
const container = document.getElementById("kite-chat-root");
|
|
4872
4955
|
if (!container) return;
|
|
4873
4956
|
if (config.theme === "dark") {
|
package/dist/index.js
CHANGED