@copilotkit/react-core 1.9.1 → 1.9.2-next.0
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/CHANGELOG.md +9 -0
- package/dist/{chunk-B5UA5G3E.mjs → chunk-2FW7HH6W.mjs} +12 -8
- package/dist/chunk-2FW7HH6W.mjs.map +1 -0
- package/dist/{chunk-ERFA53MG.mjs → chunk-6KGEF242.mjs} +2 -2
- package/dist/chunk-6KGEF242.mjs.map +1 -0
- package/dist/{chunk-2J3SMMGW.mjs → chunk-C6F6EQNA.mjs} +2 -2
- package/dist/chunk-CCESTGAM.mjs +102 -0
- package/dist/chunk-CCESTGAM.mjs.map +1 -0
- package/dist/chunk-GFJW4RIM.mjs +9 -0
- package/dist/chunk-GFJW4RIM.mjs.map +1 -0
- package/dist/chunk-HD2GE3DK.mjs +359 -0
- package/dist/chunk-HD2GE3DK.mjs.map +1 -0
- package/dist/{chunk-74AJEJTV.mjs → chunk-HJP2RX5R.mjs} +11 -6
- package/dist/chunk-HJP2RX5R.mjs.map +1 -0
- package/dist/{chunk-EQ4XLLT4.mjs → chunk-LDACFA2B.mjs} +3 -3
- package/dist/{chunk-FGBRHBRR.mjs → chunk-LZDDYZEY.mjs} +2 -2
- package/dist/chunk-NNSXCFQO.mjs +154 -0
- package/dist/chunk-NNSXCFQO.mjs.map +1 -0
- package/dist/{chunk-WZAEVHLK.mjs → chunk-Q5D5XQFA.mjs} +2 -2
- package/dist/{chunk-534J55RX.mjs → chunk-QQZLIEXK.mjs} +9 -7
- package/dist/chunk-QQZLIEXK.mjs.map +1 -0
- package/dist/chunk-RUY6MLHA.mjs +119 -0
- package/dist/chunk-RUY6MLHA.mjs.map +1 -0
- package/dist/{chunk-MDIIRGJD.mjs → chunk-SGLWMQ2J.mjs} +25 -17
- package/dist/chunk-SGLWMQ2J.mjs.map +1 -0
- package/dist/{chunk-G27C5EFO.mjs → chunk-T42PN5VN.mjs} +7 -5
- package/dist/{chunk-G27C5EFO.mjs.map → chunk-T42PN5VN.mjs.map} +1 -1
- package/dist/{chunk-VQ3VTO26.mjs → chunk-UHQMV2CE.mjs} +2 -2
- package/dist/{chunk-4DVPRMVH.mjs → chunk-UIT6QMUJ.mjs} +7 -7
- package/dist/chunk-VRXANACV.mjs +277 -0
- package/dist/chunk-VRXANACV.mjs.map +1 -0
- package/dist/{chunk-2FLZLANO.mjs → chunk-XY5BN4HZ.mjs} +19 -12
- package/dist/chunk-XY5BN4HZ.mjs.map +1 -0
- package/dist/{chunk-7HDYPEWS.mjs → chunk-YDENFEKA.mjs} +2 -2
- package/dist/{chunk-4VWM6JNK.mjs → chunk-YZDRMIOM.mjs} +6 -6
- package/dist/components/copilot-provider/copilot-messages.js +105 -11
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +4 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +4 -3
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +863 -441
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +10 -9
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +863 -441
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +10 -9
- package/dist/components/error-boundary/error-boundary.js +320 -159
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -3
- package/dist/components/error-boundary/error-utils.js +2 -1
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +2 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +863 -441
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -9
- package/dist/components/toast/toast-provider.d.ts +9 -12
- package/dist/components/toast/toast-provider.js +218 -191
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -2
- package/dist/components/usage-banner.d.ts +3 -2
- package/dist/components/usage-banner.js +311 -153
- package/dist/components/usage-banner.js.map +1 -1
- package/dist/components/usage-banner.mjs +1 -1
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +1 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-309906bb.d.ts → copilot-context-f9b2b4c3.d.ts} +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +160 -75
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +33 -32
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +243 -68
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +6 -3
- package/dist/hooks/use-coagent-state-render.js +10 -5
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -4
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +148 -67
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -13
- package/dist/hooks/use-copilot-action.js +5 -4
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -3
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +5 -4
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +5 -4
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +138 -62
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -12
- package/dist/hooks/use-copilot-readable.js +1 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.d.ts +5 -2
- package/dist/hooks/use-copilot-runtime-client.js +101 -128
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +3 -3
- package/dist/hooks/use-langgraph-interrupt-render.js +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +140 -64
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +14 -13
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +913 -480
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -34
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -10
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -10
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/utils/dev-console.d.ts +1 -1
- package/dist/utils/dev-console.js +1 -10
- package/dist/utils/dev-console.js.map +1 -1
- package/dist/utils/dev-console.mjs +1 -1
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +10 -9
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +7 -14
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +12 -11
- package/package.json +3 -3
- package/src/components/copilot-provider/copilot-messages.tsx +163 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +3 -2
- package/src/components/copilot-provider/copilotkit.tsx +8 -2
- package/src/components/error-boundary/error-boundary.tsx +6 -5
- package/src/components/error-boundary/error-utils.tsx +1 -1
- package/src/components/toast/toast-provider.tsx +260 -93
- package/src/components/usage-banner.tsx +311 -131
- package/src/context/copilot-context.tsx +2 -2
- package/src/hooks/use-chat.ts +4 -0
- package/src/hooks/use-coagent-state-render.ts +9 -3
- package/src/hooks/use-coagent.ts +10 -3
- package/src/hooks/use-copilot-runtime-client.ts +153 -12
- package/src/utils/dev-console.ts +2 -17
- package/dist/chunk-22ENANUU.mjs +0 -250
- package/dist/chunk-22ENANUU.mjs.map +0 -1
- package/dist/chunk-2FLZLANO.mjs.map +0 -1
- package/dist/chunk-534J55RX.mjs.map +0 -1
- package/dist/chunk-6PK72HMH.mjs +0 -63
- package/dist/chunk-6PK72HMH.mjs.map +0 -1
- package/dist/chunk-74AJEJTV.mjs.map +0 -1
- package/dist/chunk-B5UA5G3E.mjs.map +0 -1
- package/dist/chunk-BKTARDXX.mjs +0 -40
- package/dist/chunk-BKTARDXX.mjs.map +0 -1
- package/dist/chunk-D34OH4VN.mjs +0 -201
- package/dist/chunk-D34OH4VN.mjs.map +0 -1
- package/dist/chunk-ERFA53MG.mjs.map +0 -1
- package/dist/chunk-MDIIRGJD.mjs.map +0 -1
- package/dist/chunk-MLAS4QUR.mjs +0 -18
- package/dist/chunk-MLAS4QUR.mjs.map +0 -1
- /package/dist/{chunk-2J3SMMGW.mjs.map → chunk-C6F6EQNA.mjs.map} +0 -0
- /package/dist/{chunk-EQ4XLLT4.mjs.map → chunk-LDACFA2B.mjs.map} +0 -0
- /package/dist/{chunk-FGBRHBRR.mjs.map → chunk-LZDDYZEY.mjs.map} +0 -0
- /package/dist/{chunk-WZAEVHLK.mjs.map → chunk-Q5D5XQFA.mjs.map} +0 -0
- /package/dist/{chunk-VQ3VTO26.mjs.map → chunk-UHQMV2CE.mjs.map} +0 -0
- /package/dist/{chunk-4DVPRMVH.mjs.map → chunk-UIT6QMUJ.mjs.map} +0 -0
- /package/dist/{chunk-7HDYPEWS.mjs.map → chunk-YDENFEKA.mjs.map} +0 -0
- /package/dist/{chunk-4VWM6JNK.mjs.map → chunk-YZDRMIOM.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -158,7 +158,7 @@ var emptyCopilotContext = {
|
|
|
158
158
|
},
|
|
159
159
|
removeChatSuggestionConfiguration: () => {
|
|
160
160
|
},
|
|
161
|
-
showDevConsole:
|
|
161
|
+
showDevConsole: false,
|
|
162
162
|
coagentStates: {},
|
|
163
163
|
setCoagentStates: () => {
|
|
164
164
|
},
|
|
@@ -333,7 +333,7 @@ function setsHaveIntersection(setA, setB) {
|
|
|
333
333
|
|
|
334
334
|
// src/components/copilot-provider/copilotkit.tsx
|
|
335
335
|
var import_react_dom = require("react-dom");
|
|
336
|
-
var
|
|
336
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
337
337
|
|
|
338
338
|
// src/hooks/use-flat-category-store.ts
|
|
339
339
|
var import_react3 = require("react");
|
|
@@ -402,7 +402,7 @@ function setsHaveIntersection2(setA, setB) {
|
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
// src/components/copilot-provider/copilot-messages.tsx
|
|
405
|
-
var
|
|
405
|
+
var import_react6 = require("react");
|
|
406
406
|
|
|
407
407
|
// src/context/copilot-messages-context.tsx
|
|
408
408
|
var import_react4 = __toESM(require("react"));
|
|
@@ -423,175 +423,58 @@ function useCopilotMessagesContext() {
|
|
|
423
423
|
|
|
424
424
|
// src/components/copilot-provider/copilot-messages.tsx
|
|
425
425
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
426
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
427
|
-
function CopilotMessages({ children }) {
|
|
428
|
-
const [messages, setMessages] = (0, import_react5.useState)([]);
|
|
429
|
-
const lastLoadedThreadId = (0, import_react5.useRef)();
|
|
430
|
-
const lastLoadedAgentName = (0, import_react5.useRef)();
|
|
431
|
-
const lastLoadedMessages = (0, import_react5.useRef)();
|
|
432
|
-
const { threadId, agentSession, runtimeClient } = useCopilotContext();
|
|
433
|
-
(0, import_react5.useEffect)(() => {
|
|
434
|
-
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
435
|
-
return;
|
|
436
|
-
if (threadId === lastLoadedThreadId.current && (agentSession == null ? void 0 : agentSession.agentName) === lastLoadedAgentName.current) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
const fetchMessages = () => __async(this, null, function* () {
|
|
440
|
-
var _a, _b, _c, _d;
|
|
441
|
-
if (!(agentSession == null ? void 0 : agentSession.agentName))
|
|
442
|
-
return;
|
|
443
|
-
const result = yield runtimeClient.loadAgentState({
|
|
444
|
-
threadId,
|
|
445
|
-
agentName: agentSession == null ? void 0 : agentSession.agentName
|
|
446
|
-
});
|
|
447
|
-
const newMessages = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.messages;
|
|
448
|
-
if (newMessages === lastLoadedMessages.current)
|
|
449
|
-
return;
|
|
450
|
-
if ((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) {
|
|
451
|
-
lastLoadedMessages.current = newMessages;
|
|
452
|
-
lastLoadedThreadId.current = threadId;
|
|
453
|
-
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
454
|
-
const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(JSON.parse(newMessages || "[]"));
|
|
455
|
-
setMessages(messages2);
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
void fetchMessages();
|
|
459
|
-
}, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
|
|
460
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
461
|
-
CopilotMessagesContext.Provider,
|
|
462
|
-
{
|
|
463
|
-
value: {
|
|
464
|
-
messages,
|
|
465
|
-
setMessages
|
|
466
|
-
},
|
|
467
|
-
children
|
|
468
|
-
}
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
426
|
|
|
472
427
|
// src/components/toast/toast-provider.tsx
|
|
473
|
-
var
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
var
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
height: "24",
|
|
489
|
-
viewBox: "0 0 24 24",
|
|
490
|
-
fill: "none",
|
|
491
|
-
stroke: "currentColor",
|
|
492
|
-
strokeWidth: "2",
|
|
493
|
-
strokeLinecap: "round",
|
|
494
|
-
strokeLinejoin: "round",
|
|
495
|
-
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
496
|
-
style,
|
|
497
|
-
children: [
|
|
498
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
499
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
500
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
501
|
-
]
|
|
502
|
-
}
|
|
503
|
-
);
|
|
504
|
-
|
|
505
|
-
// src/components/error-boundary/error-utils.tsx
|
|
506
|
-
var import_react_markdown = __toESM(require("react-markdown"));
|
|
507
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
508
|
-
function ErrorToast({ errors }) {
|
|
509
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
510
|
-
var _a, _b, _c;
|
|
511
|
-
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
512
|
-
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
513
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
514
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
515
|
-
"div",
|
|
516
|
-
{
|
|
517
|
-
style: {
|
|
518
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
519
|
-
marginBottom: 14
|
|
520
|
-
},
|
|
521
|
-
children: [
|
|
522
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
523
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
524
|
-
"div",
|
|
525
|
-
{
|
|
526
|
-
style: {
|
|
527
|
-
fontWeight: "600",
|
|
528
|
-
marginBottom: 4
|
|
529
|
-
},
|
|
530
|
-
children: [
|
|
531
|
-
"Copilot Cloud Error:",
|
|
532
|
-
" ",
|
|
533
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
534
|
-
]
|
|
535
|
-
}
|
|
536
|
-
),
|
|
537
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
538
|
-
]
|
|
539
|
-
},
|
|
540
|
-
idx
|
|
541
|
-
);
|
|
542
|
-
});
|
|
543
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
544
|
-
"div",
|
|
545
|
-
{
|
|
546
|
-
style: {
|
|
547
|
-
fontSize: "13px",
|
|
548
|
-
maxWidth: "600px"
|
|
549
|
-
},
|
|
550
|
-
children: [
|
|
551
|
-
errorsToRender,
|
|
552
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
553
|
-
]
|
|
428
|
+
var import_react5 = require("react");
|
|
429
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
430
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
431
|
+
var ToastContext = (0, import_react5.createContext)(void 0);
|
|
432
|
+
function getErrorSeverity(error) {
|
|
433
|
+
if (error.severity) {
|
|
434
|
+
switch (error.severity) {
|
|
435
|
+
case import_shared3.Severity.CRITICAL:
|
|
436
|
+
return "critical";
|
|
437
|
+
case import_shared3.Severity.WARNING:
|
|
438
|
+
return "warning";
|
|
439
|
+
case import_shared3.Severity.INFO:
|
|
440
|
+
return "info";
|
|
441
|
+
default:
|
|
442
|
+
return "info";
|
|
554
443
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
const errorId = error.map((err) => {
|
|
562
|
-
var _a, _b;
|
|
563
|
-
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
564
|
-
const stack = err.stack || "";
|
|
565
|
-
return btoa(message + stack).slice(0, 32);
|
|
566
|
-
}).join("|");
|
|
567
|
-
addToast({
|
|
568
|
-
type: "error",
|
|
569
|
-
id: errorId,
|
|
570
|
-
// Toast libraries typically dedupe by id
|
|
571
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
572
|
-
});
|
|
573
|
-
},
|
|
574
|
-
[addToast]
|
|
575
|
-
);
|
|
444
|
+
}
|
|
445
|
+
const message = error.message.toLowerCase();
|
|
446
|
+
if (message.includes("api key") || message.includes("401") || message.includes("unauthorized") || message.includes("authentication") || message.includes("incorrect api key")) {
|
|
447
|
+
return "critical";
|
|
448
|
+
}
|
|
449
|
+
return "info";
|
|
576
450
|
}
|
|
577
|
-
function
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
451
|
+
function getErrorColors(severity) {
|
|
452
|
+
switch (severity) {
|
|
453
|
+
case "critical":
|
|
454
|
+
return {
|
|
455
|
+
background: "#fee2e2",
|
|
456
|
+
border: "#dc2626",
|
|
457
|
+
text: "#7f1d1d",
|
|
458
|
+
icon: "#dc2626"
|
|
459
|
+
};
|
|
460
|
+
case "warning":
|
|
461
|
+
return {
|
|
462
|
+
background: "#fef3c7",
|
|
463
|
+
border: "#d97706",
|
|
464
|
+
text: "#78350f",
|
|
465
|
+
icon: "#d97706"
|
|
466
|
+
};
|
|
467
|
+
case "info":
|
|
468
|
+
return {
|
|
469
|
+
background: "#dbeafe",
|
|
470
|
+
border: "#2563eb",
|
|
471
|
+
text: "#1e3a8a",
|
|
472
|
+
icon: "#2563eb"
|
|
473
|
+
};
|
|
474
|
+
}
|
|
588
475
|
}
|
|
589
|
-
|
|
590
|
-
// src/components/toast/toast-provider.tsx
|
|
591
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
592
|
-
var ToastContext = (0, import_react7.createContext)(void 0);
|
|
593
476
|
function useToast() {
|
|
594
|
-
const context = (0,
|
|
477
|
+
const context = (0, import_react5.useContext)(ToastContext);
|
|
595
478
|
if (!context) {
|
|
596
479
|
throw new Error("useToast must be used within a ToastProvider");
|
|
597
480
|
}
|
|
@@ -601,8 +484,12 @@ function ToastProvider({
|
|
|
601
484
|
enabled,
|
|
602
485
|
children
|
|
603
486
|
}) {
|
|
604
|
-
const [toasts, setToasts] = (0,
|
|
605
|
-
const
|
|
487
|
+
const [toasts, setToasts] = (0, import_react5.useState)([]);
|
|
488
|
+
const [bannerError, setBannerErrorState] = (0, import_react5.useState)(null);
|
|
489
|
+
const removeToast = (0, import_react5.useCallback)((id) => {
|
|
490
|
+
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
491
|
+
}, []);
|
|
492
|
+
const addToast = (0, import_react5.useCallback)(
|
|
606
493
|
(toast) => {
|
|
607
494
|
var _a;
|
|
608
495
|
if (!enabled) {
|
|
@@ -620,144 +507,413 @@ function ToastProvider({
|
|
|
620
507
|
}, toast.duration);
|
|
621
508
|
}
|
|
622
509
|
},
|
|
510
|
+
[enabled, removeToast]
|
|
511
|
+
);
|
|
512
|
+
const setBannerError = (0, import_react5.useCallback)(
|
|
513
|
+
(error) => {
|
|
514
|
+
if (!enabled && error !== null) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
setBannerErrorState(error);
|
|
518
|
+
},
|
|
623
519
|
[enabled]
|
|
624
520
|
);
|
|
625
|
-
const addGraphQLErrorsToast = (0,
|
|
626
|
-
|
|
627
|
-
type: "error",
|
|
628
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorToast, { errors })
|
|
629
|
-
});
|
|
630
|
-
}, []);
|
|
631
|
-
const removeToast = (0, import_react7.useCallback)((id) => {
|
|
632
|
-
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
521
|
+
const addGraphQLErrorsToast = (0, import_react5.useCallback)((errors) => {
|
|
522
|
+
console.warn("addGraphQLErrorsToast is deprecated. All errors now show as banners.");
|
|
633
523
|
}, []);
|
|
634
524
|
const value = {
|
|
635
525
|
toasts,
|
|
636
526
|
addToast,
|
|
637
527
|
addGraphQLErrorsToast,
|
|
638
528
|
removeToast,
|
|
639
|
-
enabled
|
|
529
|
+
enabled,
|
|
530
|
+
bannerError,
|
|
531
|
+
setBannerError
|
|
640
532
|
};
|
|
641
|
-
return /* @__PURE__ */ (0,
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
"
|
|
533
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ToastContext.Provider, { value, children: [
|
|
534
|
+
bannerError && (() => {
|
|
535
|
+
const severity = getErrorSeverity(bannerError);
|
|
536
|
+
const colors = getErrorColors(severity);
|
|
537
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
538
|
+
"div",
|
|
539
|
+
{
|
|
540
|
+
style: {
|
|
541
|
+
position: "fixed",
|
|
542
|
+
bottom: "20px",
|
|
543
|
+
left: "50%",
|
|
544
|
+
transform: "translateX(-50%)",
|
|
545
|
+
zIndex: 9999,
|
|
546
|
+
backgroundColor: colors.background,
|
|
547
|
+
border: `1px solid ${colors.border}`,
|
|
548
|
+
borderLeft: `4px solid ${colors.border}`,
|
|
549
|
+
borderRadius: "8px",
|
|
550
|
+
padding: "10px 14px",
|
|
551
|
+
fontSize: "13px",
|
|
552
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
553
|
+
backdropFilter: "blur(8px)",
|
|
554
|
+
maxWidth: "500px",
|
|
555
|
+
minWidth: "350px"
|
|
556
|
+
},
|
|
557
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
558
|
+
"div",
|
|
658
559
|
{
|
|
659
|
-
onClick: () => setToasts([]),
|
|
660
560
|
style: {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
border: "1px solid rgba(0,0,0,0.2)",
|
|
666
|
-
borderRadius: "4px"
|
|
561
|
+
display: "flex",
|
|
562
|
+
justifyContent: "space-between",
|
|
563
|
+
alignItems: "center",
|
|
564
|
+
gap: "10px"
|
|
667
565
|
},
|
|
668
|
-
children:
|
|
566
|
+
children: [
|
|
567
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", flex: 1 }, children: [
|
|
568
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
569
|
+
"div",
|
|
570
|
+
{
|
|
571
|
+
style: {
|
|
572
|
+
width: "12px",
|
|
573
|
+
height: "12px",
|
|
574
|
+
borderRadius: "50%",
|
|
575
|
+
backgroundColor: colors.border,
|
|
576
|
+
flexShrink: 0
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
),
|
|
580
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "10px", flex: 1 }, children: [
|
|
581
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
582
|
+
"div",
|
|
583
|
+
{
|
|
584
|
+
style: {
|
|
585
|
+
color: colors.text,
|
|
586
|
+
lineHeight: "1.4",
|
|
587
|
+
fontWeight: "400",
|
|
588
|
+
fontSize: "13px",
|
|
589
|
+
flex: 1,
|
|
590
|
+
wordWrap: "break-word",
|
|
591
|
+
overflowWrap: "break-word",
|
|
592
|
+
hyphens: "auto"
|
|
593
|
+
},
|
|
594
|
+
children: (() => {
|
|
595
|
+
const message = bannerError.message;
|
|
596
|
+
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
597
|
+
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
598
|
+
let cleanMessage = message.replace(markdownLinkRegex, "").replace(plainUrlRegex, "").replace(/See more:\s*/g, "").replace(/\s+/g, " ").trim();
|
|
599
|
+
if (cleanMessage.length > 120) {
|
|
600
|
+
cleanMessage = cleanMessage.substring(0, 117) + "...";
|
|
601
|
+
}
|
|
602
|
+
return cleanMessage;
|
|
603
|
+
})()
|
|
604
|
+
}
|
|
605
|
+
),
|
|
606
|
+
(() => {
|
|
607
|
+
const message = bannerError.message;
|
|
608
|
+
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
609
|
+
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
610
|
+
let url = null;
|
|
611
|
+
let buttonText = "See More";
|
|
612
|
+
const markdownMatch = markdownLinkRegex.exec(message);
|
|
613
|
+
if (markdownMatch) {
|
|
614
|
+
url = markdownMatch[2];
|
|
615
|
+
buttonText = "See More";
|
|
616
|
+
} else {
|
|
617
|
+
const urlMatch = plainUrlRegex.exec(message);
|
|
618
|
+
if (urlMatch) {
|
|
619
|
+
url = urlMatch[0];
|
|
620
|
+
buttonText = "See More";
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (!url)
|
|
624
|
+
return null;
|
|
625
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
626
|
+
"button",
|
|
627
|
+
{
|
|
628
|
+
onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
|
|
629
|
+
style: {
|
|
630
|
+
background: colors.border,
|
|
631
|
+
color: "white",
|
|
632
|
+
border: "none",
|
|
633
|
+
borderRadius: "5px",
|
|
634
|
+
padding: "4px 10px",
|
|
635
|
+
fontSize: "11px",
|
|
636
|
+
fontWeight: "500",
|
|
637
|
+
cursor: "pointer",
|
|
638
|
+
transition: "all 0.2s ease",
|
|
639
|
+
flexShrink: 0
|
|
640
|
+
},
|
|
641
|
+
onMouseEnter: (e) => {
|
|
642
|
+
e.currentTarget.style.opacity = "0.9";
|
|
643
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
644
|
+
},
|
|
645
|
+
onMouseLeave: (e) => {
|
|
646
|
+
e.currentTarget.style.opacity = "1";
|
|
647
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
648
|
+
},
|
|
649
|
+
children: buttonText
|
|
650
|
+
}
|
|
651
|
+
);
|
|
652
|
+
})()
|
|
653
|
+
] })
|
|
654
|
+
] }),
|
|
655
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
656
|
+
"button",
|
|
657
|
+
{
|
|
658
|
+
onClick: () => setBannerError(null),
|
|
659
|
+
style: {
|
|
660
|
+
background: "transparent",
|
|
661
|
+
border: "none",
|
|
662
|
+
color: colors.text,
|
|
663
|
+
cursor: "pointer",
|
|
664
|
+
padding: "2px",
|
|
665
|
+
borderRadius: "3px",
|
|
666
|
+
fontSize: "14px",
|
|
667
|
+
lineHeight: "1",
|
|
668
|
+
opacity: 0.6,
|
|
669
|
+
transition: "all 0.2s ease",
|
|
670
|
+
flexShrink: 0
|
|
671
|
+
},
|
|
672
|
+
title: "Dismiss",
|
|
673
|
+
onMouseEnter: (e) => {
|
|
674
|
+
e.currentTarget.style.opacity = "1";
|
|
675
|
+
e.currentTarget.style.background = "rgba(0, 0, 0, 0.05)";
|
|
676
|
+
},
|
|
677
|
+
onMouseLeave: (e) => {
|
|
678
|
+
e.currentTarget.style.opacity = "0.6";
|
|
679
|
+
e.currentTarget.style.background = "transparent";
|
|
680
|
+
},
|
|
681
|
+
children: "\xD7"
|
|
682
|
+
}
|
|
683
|
+
)
|
|
684
|
+
]
|
|
669
685
|
}
|
|
670
|
-
)
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
message: toast.message,
|
|
675
|
-
type: toast.type,
|
|
676
|
-
onClose: () => removeToast(toast.id)
|
|
677
|
-
},
|
|
678
|
-
toast.id
|
|
679
|
-
))
|
|
680
|
-
]
|
|
681
|
-
}
|
|
682
|
-
),
|
|
686
|
+
)
|
|
687
|
+
}
|
|
688
|
+
);
|
|
689
|
+
})(),
|
|
683
690
|
children
|
|
684
691
|
] });
|
|
685
692
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
693
|
+
|
|
694
|
+
// src/utils/dev-console.ts
|
|
695
|
+
function shouldShowDevConsole(showDevConsole) {
|
|
696
|
+
return showDevConsole;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// src/components/copilot-provider/copilot-messages.tsx
|
|
700
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
701
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
702
|
+
function CopilotMessages({ children }) {
|
|
703
|
+
const [messages, setMessages] = (0, import_react6.useState)([]);
|
|
704
|
+
const lastLoadedThreadId = (0, import_react6.useRef)();
|
|
705
|
+
const lastLoadedAgentName = (0, import_react6.useRef)();
|
|
706
|
+
const lastLoadedMessages = (0, import_react6.useRef)();
|
|
707
|
+
const { threadId, agentSession, runtimeClient, showDevConsole } = useCopilotContext();
|
|
708
|
+
const { setBannerError } = useToast();
|
|
709
|
+
const createStructuredError2 = (gqlError) => {
|
|
710
|
+
const extensions = gqlError.extensions;
|
|
711
|
+
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
712
|
+
if (originalError == null ? void 0 : originalError.stack) {
|
|
713
|
+
if (originalError.stack.includes("CopilotApiDiscoveryError")) {
|
|
714
|
+
return new import_shared4.CopilotKitApiDiscoveryError({ message: originalError.message });
|
|
715
|
+
}
|
|
716
|
+
if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
717
|
+
return new import_shared4.CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });
|
|
718
|
+
}
|
|
719
|
+
if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) {
|
|
720
|
+
return new import_shared4.CopilotKitAgentDiscoveryError({
|
|
721
|
+
agentName: "",
|
|
722
|
+
availableAgents: []
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
727
|
+
const code = extensions == null ? void 0 : extensions.code;
|
|
728
|
+
if (code) {
|
|
729
|
+
return new import_shared4.CopilotKitError({ message, code });
|
|
730
|
+
}
|
|
731
|
+
return null;
|
|
696
732
|
};
|
|
697
|
-
|
|
698
|
-
|
|
733
|
+
const handleGraphQLErrors = (0, import_react6.useCallback)(
|
|
734
|
+
(error) => {
|
|
735
|
+
var _a;
|
|
736
|
+
if ((_a = error.graphQLErrors) == null ? void 0 : _a.length) {
|
|
737
|
+
const graphQLErrors = error.graphQLErrors;
|
|
738
|
+
const routeError = (gqlError) => {
|
|
739
|
+
const extensions = gqlError.extensions;
|
|
740
|
+
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
741
|
+
const isDev = shouldShowDevConsole(showDevConsole);
|
|
742
|
+
if (!isDev) {
|
|
743
|
+
console.error("CopilotKit Error (hidden in production):", gqlError.message);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (visibility === import_shared4.ErrorVisibility.SILENT) {
|
|
747
|
+
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const ckError = createStructuredError2(gqlError);
|
|
751
|
+
if (ckError) {
|
|
752
|
+
setBannerError(ckError);
|
|
753
|
+
} else {
|
|
754
|
+
const fallbackError = new import_shared4.CopilotKitError({
|
|
755
|
+
message: gqlError.message,
|
|
756
|
+
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
757
|
+
});
|
|
758
|
+
setBannerError(fallbackError);
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
graphQLErrors.forEach(routeError);
|
|
762
|
+
} else {
|
|
763
|
+
const isDev = shouldShowDevConsole(showDevConsole);
|
|
764
|
+
if (!isDev) {
|
|
765
|
+
console.error("CopilotKit Error (hidden in production):", error);
|
|
766
|
+
} else {
|
|
767
|
+
const fallbackError = new import_shared4.CopilotKitError({
|
|
768
|
+
message: (error == null ? void 0 : error.message) || String(error),
|
|
769
|
+
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
770
|
+
});
|
|
771
|
+
setBannerError(fallbackError);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
[setBannerError, showDevConsole]
|
|
776
|
+
);
|
|
777
|
+
(0, import_react6.useEffect)(() => {
|
|
778
|
+
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
779
|
+
return;
|
|
780
|
+
if (threadId === lastLoadedThreadId.current && (agentSession == null ? void 0 : agentSession.agentName) === lastLoadedAgentName.current) {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const fetchMessages = () => __async(this, null, function* () {
|
|
784
|
+
var _a, _b, _c, _d;
|
|
785
|
+
if (!(agentSession == null ? void 0 : agentSession.agentName))
|
|
786
|
+
return;
|
|
787
|
+
const result = yield runtimeClient.loadAgentState({
|
|
788
|
+
threadId,
|
|
789
|
+
agentName: agentSession == null ? void 0 : agentSession.agentName
|
|
790
|
+
});
|
|
791
|
+
if (result.error) {
|
|
792
|
+
lastLoadedThreadId.current = threadId;
|
|
793
|
+
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
794
|
+
handleGraphQLErrors(result.error);
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const newMessages = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.messages;
|
|
798
|
+
if (newMessages === lastLoadedMessages.current)
|
|
799
|
+
return;
|
|
800
|
+
if ((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) {
|
|
801
|
+
lastLoadedMessages.current = newMessages;
|
|
802
|
+
lastLoadedThreadId.current = threadId;
|
|
803
|
+
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
804
|
+
const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(JSON.parse(newMessages || "[]"));
|
|
805
|
+
setMessages(messages2);
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
void fetchMessages();
|
|
809
|
+
}, [threadId, agentSession == null ? void 0 : agentSession.agentName, runtimeClient]);
|
|
810
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
811
|
+
CopilotMessagesContext.Provider,
|
|
699
812
|
{
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
padding: "0.5rem 1.5rem",
|
|
704
|
-
borderRadius: "0.25rem",
|
|
705
|
-
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
706
|
-
position: "relative",
|
|
707
|
-
minWidth: "200px"
|
|
813
|
+
value: {
|
|
814
|
+
messages,
|
|
815
|
+
setMessages
|
|
708
816
|
},
|
|
709
|
-
children
|
|
710
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: message }),
|
|
711
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
712
|
-
"button",
|
|
713
|
-
{
|
|
714
|
-
onClick: onClose,
|
|
715
|
-
style: {
|
|
716
|
-
position: "absolute",
|
|
717
|
-
top: "0",
|
|
718
|
-
right: "0",
|
|
719
|
-
background: "none",
|
|
720
|
-
border: "none",
|
|
721
|
-
color: "white",
|
|
722
|
-
cursor: "pointer",
|
|
723
|
-
padding: "0.5rem",
|
|
724
|
-
fontSize: "1rem"
|
|
725
|
-
},
|
|
726
|
-
children: "\u2715"
|
|
727
|
-
}
|
|
728
|
-
)
|
|
729
|
-
]
|
|
817
|
+
children
|
|
730
818
|
}
|
|
731
819
|
);
|
|
732
820
|
}
|
|
733
821
|
|
|
734
822
|
// src/hooks/use-copilot-runtime-client.ts
|
|
735
823
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
736
|
-
var
|
|
824
|
+
var import_react7 = require("react");
|
|
825
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
737
826
|
var useCopilotRuntimeClient = (options) => {
|
|
738
|
-
const {
|
|
739
|
-
const
|
|
740
|
-
const
|
|
741
|
-
const runtimeClient = (0,
|
|
742
|
-
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({},
|
|
827
|
+
const { setBannerError } = useToast();
|
|
828
|
+
const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
|
|
829
|
+
const lastStructuredErrorRef = (0, import_react7.useRef)(null);
|
|
830
|
+
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
831
|
+
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
743
832
|
handleGQLErrors: (error) => {
|
|
744
|
-
|
|
745
|
-
|
|
833
|
+
var _a2;
|
|
834
|
+
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
835
|
+
const graphQLErrors = error.graphQLErrors;
|
|
836
|
+
const routeError = (gqlError) => {
|
|
837
|
+
const extensions = gqlError.extensions;
|
|
838
|
+
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
839
|
+
const isDev = shouldShowDevConsole(showDevConsole != null ? showDevConsole : false);
|
|
840
|
+
if (visibility === import_shared5.ErrorVisibility.SILENT) {
|
|
841
|
+
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
if (!isDev) {
|
|
845
|
+
console.error("CopilotKit Error (hidden in production):", gqlError.message);
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
const now = Date.now();
|
|
849
|
+
const errorMessage = gqlError.message;
|
|
850
|
+
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
|
|
854
|
+
const ckError = createStructuredError(gqlError);
|
|
855
|
+
if (ckError) {
|
|
856
|
+
setBannerError(ckError);
|
|
857
|
+
} else {
|
|
858
|
+
const fallbackError = new import_shared5.CopilotKitError({
|
|
859
|
+
message: gqlError.message,
|
|
860
|
+
code: import_shared5.CopilotKitErrorCode.UNKNOWN
|
|
861
|
+
});
|
|
862
|
+
setBannerError(fallbackError);
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
graphQLErrors.forEach(routeError);
|
|
746
866
|
} else {
|
|
747
|
-
|
|
867
|
+
const isDev = shouldShowDevConsole(showDevConsole != null ? showDevConsole : false);
|
|
868
|
+
if (!isDev) {
|
|
869
|
+
console.error("CopilotKit Error (hidden in production):", error);
|
|
870
|
+
} else {
|
|
871
|
+
const fallbackError = new import_shared5.CopilotKitError({
|
|
872
|
+
message: (error == null ? void 0 : error.message) || String(error),
|
|
873
|
+
code: import_shared5.CopilotKitErrorCode.UNKNOWN
|
|
874
|
+
});
|
|
875
|
+
setBannerError(fallbackError);
|
|
876
|
+
}
|
|
748
877
|
}
|
|
749
878
|
},
|
|
750
879
|
handleGQLWarning: (message) => {
|
|
751
880
|
console.warn(message);
|
|
752
|
-
|
|
881
|
+
const warningError = new import_shared5.CopilotKitError({
|
|
882
|
+
message,
|
|
883
|
+
code: import_shared5.CopilotKitErrorCode.UNKNOWN
|
|
884
|
+
});
|
|
885
|
+
setBannerError(warningError);
|
|
753
886
|
}
|
|
754
887
|
}));
|
|
755
|
-
}, [
|
|
888
|
+
}, [runtimeOptions, setBannerError, showDevConsole]);
|
|
756
889
|
return runtimeClient;
|
|
757
890
|
};
|
|
891
|
+
function createStructuredError(gqlError) {
|
|
892
|
+
var _a, _b, _c;
|
|
893
|
+
const extensions = gqlError.extensions;
|
|
894
|
+
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
895
|
+
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
896
|
+
const code = extensions == null ? void 0 : extensions.code;
|
|
897
|
+
if (code) {
|
|
898
|
+
return new import_shared5.CopilotKitError({ message, code });
|
|
899
|
+
}
|
|
900
|
+
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
901
|
+
return new import_shared5.CopilotKitApiDiscoveryError({ message });
|
|
902
|
+
}
|
|
903
|
+
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
904
|
+
return new import_shared5.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
905
|
+
}
|
|
906
|
+
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
907
|
+
return new import_shared5.CopilotKitAgentDiscoveryError({
|
|
908
|
+
agentName: "",
|
|
909
|
+
availableAgents: []
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
758
914
|
|
|
759
915
|
// src/utils/extract.ts
|
|
760
|
-
var
|
|
916
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
761
917
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
762
918
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
763
919
|
function extract(_0) {
|
|
@@ -806,7 +962,7 @@ function extract(_0) {
|
|
|
806
962
|
{
|
|
807
963
|
name: action.name,
|
|
808
964
|
description: action.description || "",
|
|
809
|
-
jsonSchema: JSON.stringify((0,
|
|
965
|
+
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters || []))
|
|
810
966
|
}
|
|
811
967
|
],
|
|
812
968
|
url: window.location.href
|
|
@@ -890,26 +1046,12 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
890
1046
|
`;
|
|
891
1047
|
}
|
|
892
1048
|
|
|
893
|
-
// src/utils/dev-console.ts
|
|
894
|
-
function shouldShowDevConsole(showDevConsole) {
|
|
895
|
-
if (typeof showDevConsole === "boolean") {
|
|
896
|
-
return showDevConsole;
|
|
897
|
-
}
|
|
898
|
-
return getHostname() === "localhost" || getHostname() === "127.0.0.1" || getHostname() === "0.0.0.0" || getHostname() === "::1";
|
|
899
|
-
}
|
|
900
|
-
function getHostname() {
|
|
901
|
-
if (typeof window !== "undefined" && window.location) {
|
|
902
|
-
return window.location.hostname;
|
|
903
|
-
}
|
|
904
|
-
return "";
|
|
905
|
-
}
|
|
906
|
-
|
|
907
1049
|
// src/components/error-boundary/error-boundary.tsx
|
|
908
1050
|
var import_react9 = __toESM(require("react"));
|
|
909
|
-
var
|
|
1051
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
910
1052
|
|
|
911
1053
|
// src/lib/status-checker.ts
|
|
912
|
-
var
|
|
1054
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
913
1055
|
var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
|
|
914
1056
|
var StatusChecker = class {
|
|
915
1057
|
constructor() {
|
|
@@ -927,10 +1069,10 @@ var StatusChecker = class {
|
|
|
927
1069
|
clearInterval(this.intervalId);
|
|
928
1070
|
const checkStatus = () => __async(this, null, function* () {
|
|
929
1071
|
try {
|
|
930
|
-
const response = yield fetch(`${
|
|
1072
|
+
const response = yield fetch(`${import_shared7.COPILOT_CLOUD_API_URL}/ciu`, {
|
|
931
1073
|
method: "GET",
|
|
932
1074
|
headers: {
|
|
933
|
-
[
|
|
1075
|
+
[import_shared7.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
|
|
934
1076
|
}
|
|
935
1077
|
}).then((response2) => response2.json());
|
|
936
1078
|
this.lastResponse = response;
|
|
@@ -963,203 +1105,475 @@ var StatusChecker = class {
|
|
|
963
1105
|
};
|
|
964
1106
|
|
|
965
1107
|
// src/components/usage-banner.tsx
|
|
966
|
-
var
|
|
967
|
-
var
|
|
1108
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1109
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
968
1110
|
var defaultIcons = {
|
|
969
|
-
[
|
|
1111
|
+
[import_shared8.Severity.CRITICAL]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
970
1112
|
"svg",
|
|
971
1113
|
{
|
|
972
1114
|
viewBox: "0 0 24 24",
|
|
973
|
-
width: "
|
|
974
|
-
height: "
|
|
1115
|
+
width: "18",
|
|
1116
|
+
height: "18",
|
|
975
1117
|
stroke: "currentColor",
|
|
976
|
-
strokeWidth: "2",
|
|
1118
|
+
strokeWidth: "2.5",
|
|
977
1119
|
fill: "none",
|
|
978
1120
|
strokeLinecap: "round",
|
|
979
1121
|
strokeLinejoin: "round",
|
|
980
1122
|
children: [
|
|
981
|
-
/* @__PURE__ */ (0,
|
|
982
|
-
/* @__PURE__ */ (0,
|
|
983
|
-
/* @__PURE__ */ (0,
|
|
1123
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1124
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "15", y1: "9", x2: "9", y2: "15" }),
|
|
1125
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
|
|
1126
|
+
]
|
|
1127
|
+
}
|
|
1128
|
+
),
|
|
1129
|
+
[import_shared8.Severity.WARNING]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1130
|
+
"svg",
|
|
1131
|
+
{
|
|
1132
|
+
viewBox: "0 0 24 24",
|
|
1133
|
+
width: "18",
|
|
1134
|
+
height: "18",
|
|
1135
|
+
stroke: "currentColor",
|
|
1136
|
+
strokeWidth: "2.5",
|
|
1137
|
+
fill: "none",
|
|
1138
|
+
strokeLinecap: "round",
|
|
1139
|
+
strokeLinejoin: "round",
|
|
1140
|
+
children: [
|
|
1141
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z" }),
|
|
1142
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "12", y1: "9", x2: "12", y2: "13" }),
|
|
1143
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "12", y1: "17", x2: "12.01", y2: "17" })
|
|
1144
|
+
]
|
|
1145
|
+
}
|
|
1146
|
+
),
|
|
1147
|
+
[import_shared8.Severity.INFO]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1148
|
+
"svg",
|
|
1149
|
+
{
|
|
1150
|
+
viewBox: "0 0 24 24",
|
|
1151
|
+
width: "18",
|
|
1152
|
+
height: "18",
|
|
1153
|
+
stroke: "currentColor",
|
|
1154
|
+
strokeWidth: "2.5",
|
|
1155
|
+
fill: "none",
|
|
1156
|
+
strokeLinecap: "round",
|
|
1157
|
+
strokeLinejoin: "round",
|
|
1158
|
+
children: [
|
|
1159
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1160
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "12", y1: "16", x2: "12", y2: "12" }),
|
|
1161
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "12", y1: "8", x2: "12.01", y2: "8" })
|
|
984
1162
|
]
|
|
985
1163
|
}
|
|
986
1164
|
)
|
|
987
1165
|
};
|
|
988
1166
|
function UsageBanner({
|
|
989
|
-
severity =
|
|
1167
|
+
severity = import_shared8.Severity.CRITICAL,
|
|
990
1168
|
message = "",
|
|
991
1169
|
icon,
|
|
1170
|
+
onClose,
|
|
992
1171
|
actions
|
|
993
1172
|
}) {
|
|
994
1173
|
if (!message || !severity) {
|
|
995
1174
|
return null;
|
|
996
1175
|
}
|
|
1176
|
+
const parseMessage = (rawMessage) => {
|
|
1177
|
+
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
1178
|
+
const matches = Array.from(rawMessage.matchAll(linkRegex));
|
|
1179
|
+
if (matches.length > 0) {
|
|
1180
|
+
let cleanMessage2 = rawMessage.replace(/\.\s*See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, ".").replace(/See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, "").trim();
|
|
1181
|
+
return cleanMessage2;
|
|
1182
|
+
}
|
|
1183
|
+
return rawMessage;
|
|
1184
|
+
};
|
|
1185
|
+
const cleanMessage = parseMessage(message);
|
|
997
1186
|
const Icon = icon || defaultIcons[severity];
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1187
|
+
const themeConfigs = {
|
|
1188
|
+
[import_shared8.Severity.INFO]: {
|
|
1189
|
+
bg: "linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%)",
|
|
1190
|
+
border: "#93c5fd",
|
|
1191
|
+
text: "#1e40af",
|
|
1192
|
+
icon: "#3b82f6",
|
|
1193
|
+
primaryBtn: "#3b82f6",
|
|
1194
|
+
primaryBtnHover: "#2563eb"
|
|
1195
|
+
},
|
|
1196
|
+
[import_shared8.Severity.WARNING]: {
|
|
1197
|
+
bg: "linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%)",
|
|
1198
|
+
border: "#fbbf24",
|
|
1199
|
+
text: "#92400e",
|
|
1200
|
+
icon: "#f59e0b",
|
|
1201
|
+
primaryBtn: "#f59e0b",
|
|
1202
|
+
primaryBtnHover: "#d97706"
|
|
1203
|
+
},
|
|
1204
|
+
[import_shared8.Severity.CRITICAL]: {
|
|
1205
|
+
bg: "linear-gradient(135deg, #fef2f2 0%, #fecaca 100%)",
|
|
1206
|
+
border: "#f87171",
|
|
1207
|
+
text: "#991b1b",
|
|
1208
|
+
icon: "#ef4444",
|
|
1209
|
+
primaryBtn: "#ef4444",
|
|
1210
|
+
primaryBtnHover: "#dc2626"
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
const themeConfig = themeConfigs[severity] || themeConfigs[import_shared8.Severity.CRITICAL];
|
|
1214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1024
1215
|
"div",
|
|
1025
1216
|
{
|
|
1026
1217
|
style: {
|
|
1027
1218
|
position: "fixed",
|
|
1028
|
-
bottom: "
|
|
1219
|
+
bottom: "20px",
|
|
1029
1220
|
left: "50%",
|
|
1030
1221
|
transform: "translateX(-50%)",
|
|
1031
|
-
maxWidth: "
|
|
1032
|
-
|
|
1222
|
+
maxWidth: "min(95vw, 680px)",
|
|
1223
|
+
width: "100%",
|
|
1224
|
+
zIndex: 1e4,
|
|
1225
|
+
animation: "bannerSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1)"
|
|
1033
1226
|
},
|
|
1034
|
-
children:
|
|
1035
|
-
"
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
"
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1227
|
+
children: [
|
|
1228
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
|
|
1229
|
+
@keyframes bannerSlideIn {
|
|
1230
|
+
from {
|
|
1231
|
+
opacity: 0;
|
|
1232
|
+
transform: translateX(-50%) translateY(10px);
|
|
1233
|
+
}
|
|
1234
|
+
to {
|
|
1235
|
+
opacity: 1;
|
|
1236
|
+
transform: translateX(-50%) translateY(0);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
` }),
|
|
1240
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1241
|
+
"div",
|
|
1242
|
+
{
|
|
1243
|
+
style: {
|
|
1244
|
+
display: "flex",
|
|
1245
|
+
alignItems: "flex-start",
|
|
1246
|
+
gap: "14px",
|
|
1247
|
+
borderRadius: "16px",
|
|
1248
|
+
border: `1px solid ${themeConfig.border}`,
|
|
1249
|
+
background: themeConfig.bg,
|
|
1250
|
+
padding: "18px 20px",
|
|
1251
|
+
boxShadow: "0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)",
|
|
1252
|
+
position: "relative",
|
|
1253
|
+
backdropFilter: "blur(10px)",
|
|
1254
|
+
WebkitBackdropFilter: "blur(10px)"
|
|
1255
|
+
},
|
|
1256
|
+
children: [
|
|
1257
|
+
onClose && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1258
|
+
"button",
|
|
1259
|
+
{
|
|
1260
|
+
onClick: onClose,
|
|
1261
|
+
style: {
|
|
1262
|
+
position: "absolute",
|
|
1263
|
+
top: "12px",
|
|
1264
|
+
right: "12px",
|
|
1265
|
+
background: "rgba(255, 255, 255, 0.8)",
|
|
1266
|
+
border: "none",
|
|
1267
|
+
color: themeConfig.text,
|
|
1268
|
+
cursor: "pointer",
|
|
1269
|
+
fontSize: "18px",
|
|
1270
|
+
lineHeight: "1",
|
|
1271
|
+
padding: "6px",
|
|
1272
|
+
borderRadius: "8px",
|
|
1273
|
+
opacity: 0.7,
|
|
1274
|
+
transition: "all 0.2s ease",
|
|
1275
|
+
display: "flex",
|
|
1276
|
+
alignItems: "center",
|
|
1277
|
+
justifyContent: "center",
|
|
1278
|
+
width: "28px",
|
|
1279
|
+
height: "28px"
|
|
1280
|
+
},
|
|
1281
|
+
title: "Close",
|
|
1282
|
+
onMouseOver: (e) => {
|
|
1283
|
+
e.currentTarget.style.opacity = "1";
|
|
1284
|
+
e.currentTarget.style.background = "rgba(255, 255, 255, 1)";
|
|
1285
|
+
e.currentTarget.style.transform = "scale(1.05)";
|
|
1286
|
+
},
|
|
1287
|
+
onMouseOut: (e) => {
|
|
1288
|
+
e.currentTarget.style.opacity = "0.7";
|
|
1289
|
+
e.currentTarget.style.background = "rgba(255, 255, 255, 0.8)";
|
|
1290
|
+
e.currentTarget.style.transform = "scale(1)";
|
|
1291
|
+
},
|
|
1292
|
+
children: "\xD7"
|
|
1293
|
+
}
|
|
1294
|
+
),
|
|
1295
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1296
|
+
"div",
|
|
1297
|
+
{
|
|
1298
|
+
style: {
|
|
1299
|
+
color: themeConfig.icon,
|
|
1300
|
+
flexShrink: 0,
|
|
1301
|
+
marginTop: "1px",
|
|
1302
|
+
padding: "6px",
|
|
1303
|
+
borderRadius: "10px",
|
|
1304
|
+
background: "rgba(255, 255, 255, 0.7)",
|
|
1305
|
+
display: "flex",
|
|
1306
|
+
alignItems: "center",
|
|
1307
|
+
justifyContent: "center"
|
|
1308
|
+
},
|
|
1309
|
+
children: Icon
|
|
1310
|
+
}
|
|
1311
|
+
),
|
|
1312
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { flex: 1, paddingRight: onClose ? "40px" : "0" }, children: [
|
|
1313
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1314
|
+
"div",
|
|
1315
|
+
{
|
|
1316
|
+
style: {
|
|
1317
|
+
fontSize: "15px",
|
|
1318
|
+
fontWeight: 600,
|
|
1319
|
+
color: themeConfig.text,
|
|
1320
|
+
lineHeight: "1.5",
|
|
1321
|
+
marginBottom: actions ? "12px" : "0",
|
|
1322
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1323
|
+
},
|
|
1324
|
+
children: cleanMessage
|
|
1325
|
+
}
|
|
1326
|
+
),
|
|
1327
|
+
actions && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1328
|
+
"div",
|
|
1329
|
+
{
|
|
1330
|
+
style: {
|
|
1331
|
+
display: "flex",
|
|
1332
|
+
gap: "10px",
|
|
1333
|
+
flexWrap: "wrap"
|
|
1334
|
+
},
|
|
1335
|
+
children: [
|
|
1336
|
+
actions.secondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1337
|
+
"button",
|
|
1338
|
+
{
|
|
1339
|
+
onClick: actions.secondary.onClick,
|
|
1340
|
+
style: {
|
|
1341
|
+
borderRadius: "10px",
|
|
1342
|
+
padding: "8px 16px",
|
|
1343
|
+
fontSize: "14px",
|
|
1344
|
+
fontWeight: 500,
|
|
1345
|
+
color: themeConfig.text,
|
|
1346
|
+
backgroundColor: "rgba(255, 255, 255, 0.8)",
|
|
1347
|
+
border: `1.5px solid ${themeConfig.border}`,
|
|
1348
|
+
cursor: "pointer",
|
|
1349
|
+
transition: "all 0.2s ease",
|
|
1350
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1351
|
+
},
|
|
1352
|
+
onMouseOver: (e) => {
|
|
1353
|
+
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 1)";
|
|
1354
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
1355
|
+
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
|
|
1356
|
+
},
|
|
1357
|
+
onMouseOut: (e) => {
|
|
1358
|
+
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
|
|
1359
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
1360
|
+
e.currentTarget.style.boxShadow = "none";
|
|
1361
|
+
},
|
|
1362
|
+
children: actions.secondary.label
|
|
1363
|
+
}
|
|
1364
|
+
),
|
|
1365
|
+
actions.primary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1366
|
+
"button",
|
|
1367
|
+
{
|
|
1368
|
+
onClick: actions.primary.onClick,
|
|
1369
|
+
style: {
|
|
1370
|
+
borderRadius: "10px",
|
|
1371
|
+
padding: "8px 16px",
|
|
1372
|
+
fontSize: "14px",
|
|
1373
|
+
fontWeight: 600,
|
|
1374
|
+
color: "#fff",
|
|
1375
|
+
backgroundColor: themeConfig.primaryBtn,
|
|
1376
|
+
border: "none",
|
|
1377
|
+
cursor: "pointer",
|
|
1378
|
+
transition: "all 0.2s ease",
|
|
1379
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
1380
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1381
|
+
},
|
|
1382
|
+
onMouseOver: (e) => {
|
|
1383
|
+
e.currentTarget.style.backgroundColor = themeConfig.primaryBtnHover;
|
|
1384
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
1385
|
+
e.currentTarget.style.boxShadow = "0 6px 16px rgba(0, 0, 0, 0.2)";
|
|
1386
|
+
},
|
|
1387
|
+
onMouseOut: (e) => {
|
|
1388
|
+
e.currentTarget.style.backgroundColor = themeConfig.primaryBtn;
|
|
1389
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
1390
|
+
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
|
|
1391
|
+
},
|
|
1392
|
+
children: actions.primary.label
|
|
1393
|
+
}
|
|
1394
|
+
)
|
|
1395
|
+
]
|
|
1396
|
+
}
|
|
1397
|
+
)
|
|
1398
|
+
] })
|
|
1399
|
+
]
|
|
1400
|
+
}
|
|
1401
|
+
)
|
|
1402
|
+
]
|
|
1119
1403
|
}
|
|
1120
1404
|
);
|
|
1121
1405
|
}
|
|
1122
|
-
function renderCopilotKitUsage(error) {
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
}
|
|
1406
|
+
function renderCopilotKitUsage(error, onClose) {
|
|
1407
|
+
if (error.visibility !== import_shared8.ErrorVisibility.BANNER) {
|
|
1408
|
+
return null;
|
|
1409
|
+
}
|
|
1410
|
+
const extractUrlFromMessage = (message) => {
|
|
1411
|
+
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
1412
|
+
const match = linkRegex.exec(message);
|
|
1413
|
+
return match ? match[2] : null;
|
|
1414
|
+
};
|
|
1415
|
+
const getErrorActions = (error2) => {
|
|
1416
|
+
switch (error2.name) {
|
|
1417
|
+
case import_shared8.ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR:
|
|
1418
|
+
return {
|
|
1419
|
+
primary: {
|
|
1420
|
+
label: "Sign In",
|
|
1421
|
+
onClick: () => window.location.href = "https://cloud.copilotkit.ai"
|
|
1139
1422
|
}
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1423
|
+
};
|
|
1424
|
+
case import_shared8.ERROR_NAMES.UPGRADE_REQUIRED_ERROR:
|
|
1425
|
+
return {
|
|
1426
|
+
primary: {
|
|
1427
|
+
label: "Upgrade",
|
|
1428
|
+
onClick: () => window.location.href = "https://copilotkit.ai/"
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
case import_shared8.ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR:
|
|
1432
|
+
case import_shared8.ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR:
|
|
1433
|
+
case import_shared8.ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR:
|
|
1434
|
+
return {
|
|
1435
|
+
primary: {
|
|
1436
|
+
label: "View Docs",
|
|
1437
|
+
onClick: () => {
|
|
1438
|
+
var _a;
|
|
1439
|
+
const urlFromMessage = extractUrlFromMessage(error2.message);
|
|
1440
|
+
const urlFromExtensions = (_a = error2.extensions) == null ? void 0 : _a.troubleshootingUrl;
|
|
1441
|
+
const url = urlFromMessage || urlFromExtensions || "https://docs.copilotkit.ai/troubleshooting/common-issues";
|
|
1442
|
+
window.open(url, "_blank");
|
|
1154
1443
|
}
|
|
1155
1444
|
}
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1445
|
+
};
|
|
1446
|
+
default:
|
|
1447
|
+
return void 0;
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1451
|
+
UsageBanner,
|
|
1452
|
+
{
|
|
1453
|
+
severity: error.severity || import_shared8.Severity.CRITICAL,
|
|
1454
|
+
message: error.message,
|
|
1455
|
+
onClose,
|
|
1456
|
+
actions: getErrorActions(error)
|
|
1457
|
+
}
|
|
1458
|
+
);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// src/components/error-boundary/error-utils.tsx
|
|
1462
|
+
var import_react8 = require("react");
|
|
1463
|
+
|
|
1464
|
+
// src/components/toast/exclamation-mark-icon.tsx
|
|
1465
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1466
|
+
var ExclamationMarkIcon = ({
|
|
1467
|
+
className,
|
|
1468
|
+
style
|
|
1469
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1470
|
+
"svg",
|
|
1471
|
+
{
|
|
1472
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1473
|
+
width: "24",
|
|
1474
|
+
height: "24",
|
|
1475
|
+
viewBox: "0 0 24 24",
|
|
1476
|
+
fill: "none",
|
|
1477
|
+
stroke: "currentColor",
|
|
1478
|
+
strokeWidth: "2",
|
|
1479
|
+
strokeLinecap: "round",
|
|
1480
|
+
strokeLinejoin: "round",
|
|
1481
|
+
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
1482
|
+
style,
|
|
1483
|
+
children: [
|
|
1484
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1485
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
1486
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
1487
|
+
]
|
|
1158
1488
|
}
|
|
1489
|
+
);
|
|
1490
|
+
|
|
1491
|
+
// src/components/error-boundary/error-utils.tsx
|
|
1492
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1493
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1494
|
+
function ErrorToast({ errors }) {
|
|
1495
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
1496
|
+
var _a, _b, _c;
|
|
1497
|
+
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
1498
|
+
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
1499
|
+
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
1500
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1501
|
+
"div",
|
|
1502
|
+
{
|
|
1503
|
+
style: {
|
|
1504
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
1505
|
+
marginBottom: 14
|
|
1506
|
+
},
|
|
1507
|
+
children: [
|
|
1508
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
1509
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1510
|
+
"div",
|
|
1511
|
+
{
|
|
1512
|
+
style: {
|
|
1513
|
+
fontWeight: "600",
|
|
1514
|
+
marginBottom: 4
|
|
1515
|
+
},
|
|
1516
|
+
children: [
|
|
1517
|
+
"Copilot Runtime Error:",
|
|
1518
|
+
" ",
|
|
1519
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
1520
|
+
]
|
|
1521
|
+
}
|
|
1522
|
+
),
|
|
1523
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_markdown.default, { children: message })
|
|
1524
|
+
]
|
|
1525
|
+
},
|
|
1526
|
+
idx
|
|
1527
|
+
);
|
|
1528
|
+
});
|
|
1529
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1530
|
+
"div",
|
|
1531
|
+
{
|
|
1532
|
+
style: {
|
|
1533
|
+
fontSize: "13px",
|
|
1534
|
+
maxWidth: "600px"
|
|
1535
|
+
},
|
|
1536
|
+
children: [
|
|
1537
|
+
errorsToRender,
|
|
1538
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
1539
|
+
]
|
|
1540
|
+
}
|
|
1541
|
+
);
|
|
1542
|
+
}
|
|
1543
|
+
function useErrorToast() {
|
|
1544
|
+
const { addToast } = useToast();
|
|
1545
|
+
return (0, import_react8.useCallback)(
|
|
1546
|
+
(error) => {
|
|
1547
|
+
const errorId = error.map((err) => {
|
|
1548
|
+
var _a, _b;
|
|
1549
|
+
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
1550
|
+
const stack = err.stack || "";
|
|
1551
|
+
return btoa(message + stack).slice(0, 32);
|
|
1552
|
+
}).join("|");
|
|
1553
|
+
addToast({
|
|
1554
|
+
type: "error",
|
|
1555
|
+
id: errorId,
|
|
1556
|
+
// Toast libraries typically dedupe by id
|
|
1557
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast, { errors: error })
|
|
1558
|
+
});
|
|
1559
|
+
},
|
|
1560
|
+
[addToast]
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
function useAsyncCallback(callback, deps) {
|
|
1564
|
+
const addErrorToast = useErrorToast();
|
|
1565
|
+
return (0, import_react8.useCallback)((...args) => __async(this, null, function* () {
|
|
1566
|
+
try {
|
|
1567
|
+
return yield callback(...args);
|
|
1568
|
+
} catch (error) {
|
|
1569
|
+
console.error("Error in async callback:", error);
|
|
1570
|
+
addErrorToast([error]);
|
|
1571
|
+
throw error;
|
|
1572
|
+
}
|
|
1573
|
+
}), deps);
|
|
1159
1574
|
}
|
|
1160
1575
|
|
|
1161
1576
|
// src/components/error-boundary/error-boundary.tsx
|
|
1162
|
-
var import_shared7 = require("@copilotkit/shared");
|
|
1163
1577
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1164
1578
|
var statusChecker = new StatusChecker();
|
|
1165
1579
|
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
@@ -1194,9 +1608,12 @@ var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
|
1194
1608
|
render() {
|
|
1195
1609
|
var _a, _b;
|
|
1196
1610
|
if (this.state.hasError) {
|
|
1197
|
-
if (this.state.error instanceof
|
|
1198
|
-
if (
|
|
1199
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: renderCopilotKitUsage(
|
|
1611
|
+
if (this.state.error instanceof import_shared9.CopilotKitError) {
|
|
1612
|
+
if (this.state.error.visibility === import_shared9.ErrorVisibility.BANNER) {
|
|
1613
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: renderCopilotKitUsage(
|
|
1614
|
+
this.state.error,
|
|
1615
|
+
() => this.setState({ hasError: false, error: void 0 })
|
|
1616
|
+
) });
|
|
1200
1617
|
}
|
|
1201
1618
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1202
1619
|
this.props.children,
|
|
@@ -1230,14 +1647,16 @@ function ErrorToast2({ error, children }) {
|
|
|
1230
1647
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1231
1648
|
function CopilotKit(_a) {
|
|
1232
1649
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
1233
|
-
|
|
1650
|
+
var _a2;
|
|
1651
|
+
const showDevConsole = (_a2 = props.showDevConsole) != null ? _a2 : false;
|
|
1234
1652
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
1235
1653
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotErrorBoundary, { publicApiKey: props.publicApiKey, showUsageBanner: enabled, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) }) });
|
|
1236
1654
|
}
|
|
1237
1655
|
function CopilotKitInternal(cpkProps) {
|
|
1656
|
+
var _b, _c;
|
|
1238
1657
|
const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
|
|
1239
1658
|
validateProps(cpkProps);
|
|
1240
|
-
const chatApiEndpoint = props.runtimeUrl ||
|
|
1659
|
+
const chatApiEndpoint = props.runtimeUrl || import_shared10.COPILOT_CLOUD_CHAT_URL;
|
|
1241
1660
|
const [actions, setActions] = (0, import_react10.useState)({});
|
|
1242
1661
|
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
|
|
1243
1662
|
const chatComponentsCache = (0, import_react10.useRef)({
|
|
@@ -1255,6 +1674,8 @@ function CopilotKitInternal(cpkProps) {
|
|
|
1255
1674
|
removeElement: removeDocument,
|
|
1256
1675
|
allElements: allDocuments
|
|
1257
1676
|
} = use_flat_category_store_default();
|
|
1677
|
+
const statusChecker2 = (0, import_react10.useMemo)(() => new StatusChecker(), []);
|
|
1678
|
+
const [usageBannerStatus, setUsageBannerStatus] = (0, import_react10.useState)(null);
|
|
1258
1679
|
const setAction = (0, import_react10.useCallback)((id, action) => {
|
|
1259
1680
|
setActions((prevPoints) => {
|
|
1260
1681
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
@@ -1336,7 +1757,7 @@ ${nonDocumentStrings}`;
|
|
|
1336
1757
|
[removeDocument]
|
|
1337
1758
|
);
|
|
1338
1759
|
const copilotApiConfig = (0, import_react10.useMemo)(() => {
|
|
1339
|
-
var _a2,
|
|
1760
|
+
var _a2, _b2;
|
|
1340
1761
|
let cloud = void 0;
|
|
1341
1762
|
if (props.publicApiKey) {
|
|
1342
1763
|
cloud = {
|
|
@@ -1345,7 +1766,7 @@ ${nonDocumentStrings}`;
|
|
|
1345
1766
|
restrictToTopic: {
|
|
1346
1767
|
enabled: Boolean(props.guardrails_c),
|
|
1347
1768
|
validTopics: ((_a2 = props.guardrails_c) == null ? void 0 : _a2.validTopics) || [],
|
|
1348
|
-
invalidTopics: ((
|
|
1769
|
+
invalidTopics: ((_b2 = props.guardrails_c) == null ? void 0 : _b2.invalidTopics) || []
|
|
1349
1770
|
}
|
|
1350
1771
|
}
|
|
1351
1772
|
}
|
|
@@ -1383,13 +1804,14 @@ ${nonDocumentStrings}`;
|
|
|
1383
1804
|
}
|
|
1384
1805
|
return acc;
|
|
1385
1806
|
}, {});
|
|
1386
|
-
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [
|
|
1807
|
+
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared10.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
|
|
1387
1808
|
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
1388
1809
|
const runtimeClient = useCopilotRuntimeClient({
|
|
1389
1810
|
url: copilotApiConfig.chatApiEndpoint,
|
|
1390
1811
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
1391
1812
|
headers,
|
|
1392
|
-
credentials: copilotApiConfig.credentials
|
|
1813
|
+
credentials: copilotApiConfig.credentials,
|
|
1814
|
+
showDevConsole: (_b = props.showDevConsole) != null ? _b : false
|
|
1393
1815
|
});
|
|
1394
1816
|
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
1395
1817
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
@@ -1444,7 +1866,7 @@ ${nonDocumentStrings}`;
|
|
|
1444
1866
|
setAgentSession(null);
|
|
1445
1867
|
}
|
|
1446
1868
|
}, [props.agent]);
|
|
1447
|
-
const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0,
|
|
1869
|
+
const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared10.randomUUID)());
|
|
1448
1870
|
const setThreadId = (0, import_react10.useCallback)(
|
|
1449
1871
|
(value) => {
|
|
1450
1872
|
if (props.threadId) {
|
|
@@ -1461,7 +1883,7 @@ ${nonDocumentStrings}`;
|
|
|
1461
1883
|
}, [props.threadId]);
|
|
1462
1884
|
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
1463
1885
|
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
1464
|
-
const showDevConsole = props.showDevConsole
|
|
1886
|
+
const showDevConsole = (_c = props.showDevConsole) != null ? _c : false;
|
|
1465
1887
|
const [langGraphInterruptAction, _setLangGraphInterruptAction] = (0, import_react10.useState)(null);
|
|
1466
1888
|
const setLangGraphInterruptAction = (0, import_react10.useCallback)((action) => {
|
|
1467
1889
|
_setLangGraphInterruptAction((prev) => {
|
|
@@ -1569,10 +1991,10 @@ function formatFeatureName(featureName) {
|
|
|
1569
1991
|
function validateProps(props) {
|
|
1570
1992
|
const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
|
|
1571
1993
|
if (!props.runtimeUrl && !props.publicApiKey) {
|
|
1572
|
-
throw new
|
|
1994
|
+
throw new import_shared10.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey'");
|
|
1573
1995
|
}
|
|
1574
1996
|
if (cloudFeatures.length > 0 && !props.publicApiKey) {
|
|
1575
|
-
throw new
|
|
1997
|
+
throw new import_shared10.MissingPublicApiKeyError(
|
|
1576
1998
|
`Missing required prop: 'publicApiKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
|
|
1577
1999
|
);
|
|
1578
2000
|
}
|
|
@@ -1584,12 +2006,12 @@ var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
|
1584
2006
|
|
|
1585
2007
|
// src/hooks/use-chat.ts
|
|
1586
2008
|
var import_react11 = require("react");
|
|
1587
|
-
var
|
|
2009
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
1588
2010
|
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1589
2011
|
|
|
1590
2012
|
// src/types/frontend-action.ts
|
|
1591
2013
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1592
|
-
var
|
|
2014
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1593
2015
|
function processActionsForRuntimeRequest(actions) {
|
|
1594
2016
|
const filteredActions = actions.filter(
|
|
1595
2017
|
(action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
@@ -1605,7 +2027,7 @@ function processActionsForRuntimeRequest(actions) {
|
|
|
1605
2027
|
return {
|
|
1606
2028
|
name: action.name,
|
|
1607
2029
|
description: action.description || "",
|
|
1608
|
-
jsonSchema: JSON.stringify((0,
|
|
2030
|
+
jsonSchema: JSON.stringify((0, import_shared11.actionParametersToJsonSchema)(action.parameters || [])),
|
|
1609
2031
|
available
|
|
1610
2032
|
};
|
|
1611
2033
|
});
|
|
@@ -1649,12 +2071,14 @@ function useChat(options) {
|
|
|
1649
2071
|
const extensionsRef = (0, import_react11.useRef)(extensions);
|
|
1650
2072
|
extensionsRef.current = extensions;
|
|
1651
2073
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
1652
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [
|
|
2074
|
+
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared12.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
2075
|
+
const { showDevConsole } = useCopilotContext();
|
|
1653
2076
|
const runtimeClient = useCopilotRuntimeClient({
|
|
1654
2077
|
url: copilotConfig.chatApiEndpoint,
|
|
1655
2078
|
publicApiKey: copilotConfig.publicApiKey,
|
|
1656
2079
|
headers,
|
|
1657
|
-
credentials: copilotConfig.credentials
|
|
2080
|
+
credentials: copilotConfig.credentials,
|
|
2081
|
+
showDevConsole
|
|
1658
2082
|
});
|
|
1659
2083
|
const pendingAppendsRef = (0, import_react11.useRef)([]);
|
|
1660
2084
|
const runChatCompletion = useAsyncCallback(
|
|
@@ -1772,7 +2196,7 @@ function useChat(options) {
|
|
|
1772
2196
|
(metaEvents != null ? metaEvents : []).forEach((ev) => {
|
|
1773
2197
|
if (ev.name === import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent) {
|
|
1774
2198
|
let eventValue = (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev).value;
|
|
1775
|
-
eventValue = (0,
|
|
2199
|
+
eventValue = (0, import_shared12.parseJson)(eventValue, eventValue);
|
|
1776
2200
|
setLangGraphInterruptAction({
|
|
1777
2201
|
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev)), {
|
|
1778
2202
|
value: eventValue
|
|
@@ -1846,7 +2270,7 @@ function useChat(options) {
|
|
|
1846
2270
|
} else {
|
|
1847
2271
|
if (agentLock) {
|
|
1848
2272
|
setAgentSession({
|
|
1849
|
-
threadId: (0,
|
|
2273
|
+
threadId: (0, import_shared12.randomId)(),
|
|
1850
2274
|
agentName: agentLock,
|
|
1851
2275
|
nodeName: void 0
|
|
1852
2276
|
});
|
|
@@ -1907,7 +2331,7 @@ function useChat(options) {
|
|
|
1907
2331
|
if (pairedFeAction) {
|
|
1908
2332
|
const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
|
|
1909
2333
|
name: pairedFeAction.name,
|
|
1910
|
-
arguments: (0,
|
|
2334
|
+
arguments: (0, import_shared12.parseJson)(resultMessage.result, resultMessage.result),
|
|
1911
2335
|
status: message.status,
|
|
1912
2336
|
createdAt: message.createdAt,
|
|
1913
2337
|
parentMessageId: message.parentMessageId
|
|
@@ -1917,7 +2341,7 @@ function useChat(options) {
|
|
|
1917
2341
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
1918
2342
|
const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
|
|
1919
2343
|
name: currentResultMessagePairedFeAction.name,
|
|
1920
|
-
arguments: (0,
|
|
2344
|
+
arguments: (0, import_shared12.parseJson)(message.result, message.result),
|
|
1921
2345
|
status: message.status,
|
|
1922
2346
|
createdAt: message.createdAt
|
|
1923
2347
|
});
|
|
@@ -2367,11 +2791,11 @@ ${additionalInstructions}` : "");
|
|
|
2367
2791
|
}
|
|
2368
2792
|
|
|
2369
2793
|
// src/hooks/use-copilot-action.ts
|
|
2370
|
-
var
|
|
2794
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2371
2795
|
var import_react13 = require("react");
|
|
2372
2796
|
function useCopilotAction(action, dependencies) {
|
|
2373
2797
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
2374
|
-
const idRef = (0, import_react13.useRef)((0,
|
|
2798
|
+
const idRef = (0, import_react13.useRef)((0, import_shared13.randomId)());
|
|
2375
2799
|
const renderAndWaitRef = (0, import_react13.useRef)(null);
|
|
2376
2800
|
const { addToast } = useToast();
|
|
2377
2801
|
action = __spreadValues({}, action);
|
|
@@ -2473,7 +2897,7 @@ function isFrontendAction(action) {
|
|
|
2473
2897
|
|
|
2474
2898
|
// src/hooks/use-coagent-state-render.ts
|
|
2475
2899
|
var import_react14 = require("react");
|
|
2476
|
-
var
|
|
2900
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
2477
2901
|
function useCoAgentStateRender(action, dependencies) {
|
|
2478
2902
|
const {
|
|
2479
2903
|
setCoAgentStateRender,
|
|
@@ -2482,12 +2906,16 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
2482
2906
|
chatComponentsCache,
|
|
2483
2907
|
availableAgents
|
|
2484
2908
|
} = (0, import_react14.useContext)(CopilotContext);
|
|
2485
|
-
const idRef = (0, import_react14.useRef)((0,
|
|
2486
|
-
const { addToast } = useToast();
|
|
2909
|
+
const idRef = (0, import_react14.useRef)((0, import_shared14.randomId)());
|
|
2910
|
+
const { setBannerError, addToast } = useToast();
|
|
2487
2911
|
(0, import_react14.useEffect)(() => {
|
|
2488
2912
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
2489
2913
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
2490
|
-
|
|
2914
|
+
const agentError = new import_shared14.CopilotKitAgentDiscoveryError({
|
|
2915
|
+
agentName: action.name,
|
|
2916
|
+
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
2917
|
+
});
|
|
2918
|
+
setBannerError(agentError);
|
|
2491
2919
|
}
|
|
2492
2920
|
}, [availableAgents]);
|
|
2493
2921
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
@@ -2590,11 +3018,11 @@ function useCopilotReadable({
|
|
|
2590
3018
|
|
|
2591
3019
|
// src/hooks/use-coagent.ts
|
|
2592
3020
|
var import_react17 = require("react");
|
|
2593
|
-
var
|
|
3021
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
2594
3022
|
function useCoAgent(options) {
|
|
2595
3023
|
const generalContext = useCopilotContext();
|
|
2596
3024
|
const { availableAgents } = generalContext;
|
|
2597
|
-
const {
|
|
3025
|
+
const { setBannerError } = useToast();
|
|
2598
3026
|
const lastLoadedThreadId = (0, import_react17.useRef)();
|
|
2599
3027
|
const lastLoadedState = (0, import_react17.useRef)();
|
|
2600
3028
|
const { name } = options;
|
|
@@ -2602,7 +3030,11 @@ function useCoAgent(options) {
|
|
|
2602
3030
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
2603
3031
|
const message = `(useCoAgent): Agent "${name}" not found. Make sure the agent exists and is properly configured.`;
|
|
2604
3032
|
console.warn(message);
|
|
2605
|
-
|
|
3033
|
+
const agentError = new import_shared15.CopilotKitAgentDiscoveryError({
|
|
3034
|
+
agentName: name,
|
|
3035
|
+
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
3036
|
+
});
|
|
3037
|
+
setBannerError(agentError);
|
|
2606
3038
|
}
|
|
2607
3039
|
}, [availableAgents]);
|
|
2608
3040
|
const messagesContext = useCopilotMessagesContext();
|
|
@@ -2614,7 +3046,8 @@ function useCoAgent(options) {
|
|
|
2614
3046
|
url: copilotApiConfig.chatApiEndpoint,
|
|
2615
3047
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
2616
3048
|
headers,
|
|
2617
|
-
credentials: copilotApiConfig.credentials
|
|
3049
|
+
credentials: copilotApiConfig.credentials,
|
|
3050
|
+
showDevConsole: context.showDevConsole
|
|
2618
3051
|
});
|
|
2619
3052
|
const setState = (0, import_react17.useCallback)(
|
|
2620
3053
|
(newState) => {
|
|
@@ -2643,7 +3076,7 @@ function useCoAgent(options) {
|
|
|
2643
3076
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
2644
3077
|
lastLoadedState.current = newState;
|
|
2645
3078
|
lastLoadedThreadId.current = threadId;
|
|
2646
|
-
const fetchedState = (0,
|
|
3079
|
+
const fetchedState = (0, import_shared15.parseJson)(newState, {});
|
|
2647
3080
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
2648
3081
|
}
|
|
2649
3082
|
});
|
|
@@ -2808,13 +3241,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
2808
3241
|
|
|
2809
3242
|
// src/hooks/use-langgraph-interrupt.ts
|
|
2810
3243
|
var import_react20 = require("react");
|
|
2811
|
-
var
|
|
3244
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
2812
3245
|
function useLangGraphInterrupt(action, dependencies) {
|
|
2813
3246
|
var _a;
|
|
2814
3247
|
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react20.useContext)(CopilotContext);
|
|
2815
3248
|
const { runChatCompletion } = useCopilotChat();
|
|
2816
3249
|
const { addToast } = useToast();
|
|
2817
|
-
const actionId = (0,
|
|
3250
|
+
const actionId = (0, import_shared16.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
2818
3251
|
const hasAction = (0, import_react20.useMemo)(
|
|
2819
3252
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
2820
3253
|
[langGraphInterruptAction]
|