@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
|
@@ -136,7 +136,7 @@ var emptyCopilotContext = {
|
|
|
136
136
|
},
|
|
137
137
|
removeChatSuggestionConfiguration: () => {
|
|
138
138
|
},
|
|
139
|
-
showDevConsole:
|
|
139
|
+
showDevConsole: false,
|
|
140
140
|
coagentStates: {},
|
|
141
141
|
setCoagentStates: () => {
|
|
142
142
|
},
|
|
@@ -311,7 +311,7 @@ function setsHaveIntersection(setA, setB) {
|
|
|
311
311
|
|
|
312
312
|
// src/components/copilot-provider/copilotkit.tsx
|
|
313
313
|
var import_react_dom = require("react-dom");
|
|
314
|
-
var
|
|
314
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
315
315
|
|
|
316
316
|
// src/hooks/use-flat-category-store.ts
|
|
317
317
|
var import_react3 = require("react");
|
|
@@ -380,7 +380,7 @@ function setsHaveIntersection2(setA, setB) {
|
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
// src/components/copilot-provider/copilot-messages.tsx
|
|
383
|
-
var
|
|
383
|
+
var import_react6 = require("react");
|
|
384
384
|
|
|
385
385
|
// src/context/copilot-messages-context.tsx
|
|
386
386
|
var import_react4 = __toESM(require("react"));
|
|
@@ -392,163 +392,58 @@ var CopilotMessagesContext = import_react4.default.createContext(emptyCopilotCon
|
|
|
392
392
|
|
|
393
393
|
// src/components/copilot-provider/copilot-messages.tsx
|
|
394
394
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
395
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
396
|
-
function CopilotMessages({ children }) {
|
|
397
|
-
const [messages, setMessages] = (0, import_react5.useState)([]);
|
|
398
|
-
const lastLoadedThreadId = (0, import_react5.useRef)();
|
|
399
|
-
const lastLoadedAgentName = (0, import_react5.useRef)();
|
|
400
|
-
const lastLoadedMessages = (0, import_react5.useRef)();
|
|
401
|
-
const { threadId, agentSession, runtimeClient } = useCopilotContext();
|
|
402
|
-
(0, import_react5.useEffect)(() => {
|
|
403
|
-
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
404
|
-
return;
|
|
405
|
-
if (threadId === lastLoadedThreadId.current && (agentSession == null ? void 0 : agentSession.agentName) === lastLoadedAgentName.current) {
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
const fetchMessages = () => __async(this, null, function* () {
|
|
409
|
-
var _a, _b, _c, _d;
|
|
410
|
-
if (!(agentSession == null ? void 0 : agentSession.agentName))
|
|
411
|
-
return;
|
|
412
|
-
const result = yield runtimeClient.loadAgentState({
|
|
413
|
-
threadId,
|
|
414
|
-
agentName: agentSession == null ? void 0 : agentSession.agentName
|
|
415
|
-
});
|
|
416
|
-
const newMessages = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.messages;
|
|
417
|
-
if (newMessages === lastLoadedMessages.current)
|
|
418
|
-
return;
|
|
419
|
-
if ((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) {
|
|
420
|
-
lastLoadedMessages.current = newMessages;
|
|
421
|
-
lastLoadedThreadId.current = threadId;
|
|
422
|
-
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
423
|
-
const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(JSON.parse(newMessages || "[]"));
|
|
424
|
-
setMessages(messages2);
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
void fetchMessages();
|
|
428
|
-
}, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
|
|
429
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
430
|
-
CopilotMessagesContext.Provider,
|
|
431
|
-
{
|
|
432
|
-
value: {
|
|
433
|
-
messages,
|
|
434
|
-
setMessages
|
|
435
|
-
},
|
|
436
|
-
children
|
|
437
|
-
}
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
395
|
|
|
441
396
|
// src/components/toast/toast-provider.tsx
|
|
442
|
-
var
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
var
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
height: "24",
|
|
458
|
-
viewBox: "0 0 24 24",
|
|
459
|
-
fill: "none",
|
|
460
|
-
stroke: "currentColor",
|
|
461
|
-
strokeWidth: "2",
|
|
462
|
-
strokeLinecap: "round",
|
|
463
|
-
strokeLinejoin: "round",
|
|
464
|
-
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
465
|
-
style,
|
|
466
|
-
children: [
|
|
467
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
468
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
469
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
470
|
-
]
|
|
471
|
-
}
|
|
472
|
-
);
|
|
473
|
-
|
|
474
|
-
// src/components/error-boundary/error-utils.tsx
|
|
475
|
-
var import_react_markdown = __toESM(require("react-markdown"));
|
|
476
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
477
|
-
function ErrorToast({ errors }) {
|
|
478
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
479
|
-
var _a, _b, _c;
|
|
480
|
-
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
481
|
-
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
482
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
483
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
484
|
-
"div",
|
|
485
|
-
{
|
|
486
|
-
style: {
|
|
487
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
488
|
-
marginBottom: 14
|
|
489
|
-
},
|
|
490
|
-
children: [
|
|
491
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
492
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
493
|
-
"div",
|
|
494
|
-
{
|
|
495
|
-
style: {
|
|
496
|
-
fontWeight: "600",
|
|
497
|
-
marginBottom: 4
|
|
498
|
-
},
|
|
499
|
-
children: [
|
|
500
|
-
"Copilot Cloud Error:",
|
|
501
|
-
" ",
|
|
502
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
503
|
-
]
|
|
504
|
-
}
|
|
505
|
-
),
|
|
506
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
507
|
-
]
|
|
508
|
-
},
|
|
509
|
-
idx
|
|
510
|
-
);
|
|
511
|
-
});
|
|
512
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
513
|
-
"div",
|
|
514
|
-
{
|
|
515
|
-
style: {
|
|
516
|
-
fontSize: "13px",
|
|
517
|
-
maxWidth: "600px"
|
|
518
|
-
},
|
|
519
|
-
children: [
|
|
520
|
-
errorsToRender,
|
|
521
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
522
|
-
]
|
|
397
|
+
var import_react5 = require("react");
|
|
398
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
399
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
400
|
+
var ToastContext = (0, import_react5.createContext)(void 0);
|
|
401
|
+
function getErrorSeverity(error) {
|
|
402
|
+
if (error.severity) {
|
|
403
|
+
switch (error.severity) {
|
|
404
|
+
case import_shared3.Severity.CRITICAL:
|
|
405
|
+
return "critical";
|
|
406
|
+
case import_shared3.Severity.WARNING:
|
|
407
|
+
return "warning";
|
|
408
|
+
case import_shared3.Severity.INFO:
|
|
409
|
+
return "info";
|
|
410
|
+
default:
|
|
411
|
+
return "info";
|
|
523
412
|
}
|
|
524
|
-
|
|
413
|
+
}
|
|
414
|
+
const message = error.message.toLowerCase();
|
|
415
|
+
if (message.includes("api key") || message.includes("401") || message.includes("unauthorized") || message.includes("authentication") || message.includes("incorrect api key")) {
|
|
416
|
+
return "critical";
|
|
417
|
+
}
|
|
418
|
+
return "info";
|
|
525
419
|
}
|
|
526
|
-
function
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
420
|
+
function getErrorColors(severity) {
|
|
421
|
+
switch (severity) {
|
|
422
|
+
case "critical":
|
|
423
|
+
return {
|
|
424
|
+
background: "#fee2e2",
|
|
425
|
+
border: "#dc2626",
|
|
426
|
+
text: "#7f1d1d",
|
|
427
|
+
icon: "#dc2626"
|
|
428
|
+
};
|
|
429
|
+
case "warning":
|
|
430
|
+
return {
|
|
431
|
+
background: "#fef3c7",
|
|
432
|
+
border: "#d97706",
|
|
433
|
+
text: "#78350f",
|
|
434
|
+
icon: "#d97706"
|
|
435
|
+
};
|
|
436
|
+
case "info":
|
|
437
|
+
return {
|
|
438
|
+
background: "#dbeafe",
|
|
439
|
+
border: "#2563eb",
|
|
440
|
+
text: "#1e3a8a",
|
|
441
|
+
icon: "#2563eb"
|
|
442
|
+
};
|
|
443
|
+
}
|
|
545
444
|
}
|
|
546
|
-
|
|
547
|
-
// src/components/toast/toast-provider.tsx
|
|
548
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
549
|
-
var ToastContext = (0, import_react7.createContext)(void 0);
|
|
550
445
|
function useToast() {
|
|
551
|
-
const context = (0,
|
|
446
|
+
const context = (0, import_react5.useContext)(ToastContext);
|
|
552
447
|
if (!context) {
|
|
553
448
|
throw new Error("useToast must be used within a ToastProvider");
|
|
554
449
|
}
|
|
@@ -558,8 +453,12 @@ function ToastProvider({
|
|
|
558
453
|
enabled,
|
|
559
454
|
children
|
|
560
455
|
}) {
|
|
561
|
-
const [toasts, setToasts] = (0,
|
|
562
|
-
const
|
|
456
|
+
const [toasts, setToasts] = (0, import_react5.useState)([]);
|
|
457
|
+
const [bannerError, setBannerErrorState] = (0, import_react5.useState)(null);
|
|
458
|
+
const removeToast = (0, import_react5.useCallback)((id) => {
|
|
459
|
+
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
460
|
+
}, []);
|
|
461
|
+
const addToast = (0, import_react5.useCallback)(
|
|
563
462
|
(toast) => {
|
|
564
463
|
var _a;
|
|
565
464
|
if (!enabled) {
|
|
@@ -577,162 +476,417 @@ function ToastProvider({
|
|
|
577
476
|
}, toast.duration);
|
|
578
477
|
}
|
|
579
478
|
},
|
|
479
|
+
[enabled, removeToast]
|
|
480
|
+
);
|
|
481
|
+
const setBannerError = (0, import_react5.useCallback)(
|
|
482
|
+
(error) => {
|
|
483
|
+
if (!enabled && error !== null) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
setBannerErrorState(error);
|
|
487
|
+
},
|
|
580
488
|
[enabled]
|
|
581
489
|
);
|
|
582
|
-
const addGraphQLErrorsToast = (0,
|
|
583
|
-
|
|
584
|
-
type: "error",
|
|
585
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorToast, { errors })
|
|
586
|
-
});
|
|
587
|
-
}, []);
|
|
588
|
-
const removeToast = (0, import_react7.useCallback)((id) => {
|
|
589
|
-
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
490
|
+
const addGraphQLErrorsToast = (0, import_react5.useCallback)((errors) => {
|
|
491
|
+
console.warn("addGraphQLErrorsToast is deprecated. All errors now show as banners.");
|
|
590
492
|
}, []);
|
|
591
493
|
const value = {
|
|
592
494
|
toasts,
|
|
593
495
|
addToast,
|
|
594
496
|
addGraphQLErrorsToast,
|
|
595
497
|
removeToast,
|
|
596
|
-
enabled
|
|
498
|
+
enabled,
|
|
499
|
+
bannerError,
|
|
500
|
+
setBannerError
|
|
597
501
|
};
|
|
598
|
-
return /* @__PURE__ */ (0,
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
"
|
|
502
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ToastContext.Provider, { value, children: [
|
|
503
|
+
bannerError && (() => {
|
|
504
|
+
const severity = getErrorSeverity(bannerError);
|
|
505
|
+
const colors = getErrorColors(severity);
|
|
506
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
507
|
+
"div",
|
|
508
|
+
{
|
|
509
|
+
style: {
|
|
510
|
+
position: "fixed",
|
|
511
|
+
bottom: "20px",
|
|
512
|
+
left: "50%",
|
|
513
|
+
transform: "translateX(-50%)",
|
|
514
|
+
zIndex: 9999,
|
|
515
|
+
backgroundColor: colors.background,
|
|
516
|
+
border: `1px solid ${colors.border}`,
|
|
517
|
+
borderLeft: `4px solid ${colors.border}`,
|
|
518
|
+
borderRadius: "8px",
|
|
519
|
+
padding: "10px 14px",
|
|
520
|
+
fontSize: "13px",
|
|
521
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
522
|
+
backdropFilter: "blur(8px)",
|
|
523
|
+
maxWidth: "500px",
|
|
524
|
+
minWidth: "350px"
|
|
525
|
+
},
|
|
526
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
527
|
+
"div",
|
|
615
528
|
{
|
|
616
|
-
onClick: () => setToasts([]),
|
|
617
529
|
style: {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
border: "1px solid rgba(0,0,0,0.2)",
|
|
623
|
-
borderRadius: "4px"
|
|
530
|
+
display: "flex",
|
|
531
|
+
justifyContent: "space-between",
|
|
532
|
+
alignItems: "center",
|
|
533
|
+
gap: "10px"
|
|
624
534
|
},
|
|
625
|
-
children:
|
|
535
|
+
children: [
|
|
536
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", flex: 1 }, children: [
|
|
537
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
538
|
+
"div",
|
|
539
|
+
{
|
|
540
|
+
style: {
|
|
541
|
+
width: "12px",
|
|
542
|
+
height: "12px",
|
|
543
|
+
borderRadius: "50%",
|
|
544
|
+
backgroundColor: colors.border,
|
|
545
|
+
flexShrink: 0
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
),
|
|
549
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "10px", flex: 1 }, children: [
|
|
550
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
551
|
+
"div",
|
|
552
|
+
{
|
|
553
|
+
style: {
|
|
554
|
+
color: colors.text,
|
|
555
|
+
lineHeight: "1.4",
|
|
556
|
+
fontWeight: "400",
|
|
557
|
+
fontSize: "13px",
|
|
558
|
+
flex: 1,
|
|
559
|
+
wordWrap: "break-word",
|
|
560
|
+
overflowWrap: "break-word",
|
|
561
|
+
hyphens: "auto"
|
|
562
|
+
},
|
|
563
|
+
children: (() => {
|
|
564
|
+
const message = bannerError.message;
|
|
565
|
+
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
566
|
+
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
567
|
+
let cleanMessage = message.replace(markdownLinkRegex, "").replace(plainUrlRegex, "").replace(/See more:\s*/g, "").replace(/\s+/g, " ").trim();
|
|
568
|
+
if (cleanMessage.length > 120) {
|
|
569
|
+
cleanMessage = cleanMessage.substring(0, 117) + "...";
|
|
570
|
+
}
|
|
571
|
+
return cleanMessage;
|
|
572
|
+
})()
|
|
573
|
+
}
|
|
574
|
+
),
|
|
575
|
+
(() => {
|
|
576
|
+
const message = bannerError.message;
|
|
577
|
+
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
578
|
+
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
579
|
+
let url = null;
|
|
580
|
+
let buttonText = "See More";
|
|
581
|
+
const markdownMatch = markdownLinkRegex.exec(message);
|
|
582
|
+
if (markdownMatch) {
|
|
583
|
+
url = markdownMatch[2];
|
|
584
|
+
buttonText = "See More";
|
|
585
|
+
} else {
|
|
586
|
+
const urlMatch = plainUrlRegex.exec(message);
|
|
587
|
+
if (urlMatch) {
|
|
588
|
+
url = urlMatch[0];
|
|
589
|
+
buttonText = "See More";
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (!url)
|
|
593
|
+
return null;
|
|
594
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
595
|
+
"button",
|
|
596
|
+
{
|
|
597
|
+
onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
|
|
598
|
+
style: {
|
|
599
|
+
background: colors.border,
|
|
600
|
+
color: "white",
|
|
601
|
+
border: "none",
|
|
602
|
+
borderRadius: "5px",
|
|
603
|
+
padding: "4px 10px",
|
|
604
|
+
fontSize: "11px",
|
|
605
|
+
fontWeight: "500",
|
|
606
|
+
cursor: "pointer",
|
|
607
|
+
transition: "all 0.2s ease",
|
|
608
|
+
flexShrink: 0
|
|
609
|
+
},
|
|
610
|
+
onMouseEnter: (e) => {
|
|
611
|
+
e.currentTarget.style.opacity = "0.9";
|
|
612
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
613
|
+
},
|
|
614
|
+
onMouseLeave: (e) => {
|
|
615
|
+
e.currentTarget.style.opacity = "1";
|
|
616
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
617
|
+
},
|
|
618
|
+
children: buttonText
|
|
619
|
+
}
|
|
620
|
+
);
|
|
621
|
+
})()
|
|
622
|
+
] })
|
|
623
|
+
] }),
|
|
624
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
625
|
+
"button",
|
|
626
|
+
{
|
|
627
|
+
onClick: () => setBannerError(null),
|
|
628
|
+
style: {
|
|
629
|
+
background: "transparent",
|
|
630
|
+
border: "none",
|
|
631
|
+
color: colors.text,
|
|
632
|
+
cursor: "pointer",
|
|
633
|
+
padding: "2px",
|
|
634
|
+
borderRadius: "3px",
|
|
635
|
+
fontSize: "14px",
|
|
636
|
+
lineHeight: "1",
|
|
637
|
+
opacity: 0.6,
|
|
638
|
+
transition: "all 0.2s ease",
|
|
639
|
+
flexShrink: 0
|
|
640
|
+
},
|
|
641
|
+
title: "Dismiss",
|
|
642
|
+
onMouseEnter: (e) => {
|
|
643
|
+
e.currentTarget.style.opacity = "1";
|
|
644
|
+
e.currentTarget.style.background = "rgba(0, 0, 0, 0.05)";
|
|
645
|
+
},
|
|
646
|
+
onMouseLeave: (e) => {
|
|
647
|
+
e.currentTarget.style.opacity = "0.6";
|
|
648
|
+
e.currentTarget.style.background = "transparent";
|
|
649
|
+
},
|
|
650
|
+
children: "\xD7"
|
|
651
|
+
}
|
|
652
|
+
)
|
|
653
|
+
]
|
|
626
654
|
}
|
|
627
|
-
)
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
message: toast.message,
|
|
632
|
-
type: toast.type,
|
|
633
|
-
onClose: () => removeToast(toast.id)
|
|
634
|
-
},
|
|
635
|
-
toast.id
|
|
636
|
-
))
|
|
637
|
-
]
|
|
638
|
-
}
|
|
639
|
-
),
|
|
655
|
+
)
|
|
656
|
+
}
|
|
657
|
+
);
|
|
658
|
+
})(),
|
|
640
659
|
children
|
|
641
660
|
] });
|
|
642
661
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
662
|
+
|
|
663
|
+
// src/utils/dev-console.ts
|
|
664
|
+
function shouldShowDevConsole(showDevConsole) {
|
|
665
|
+
return showDevConsole;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// src/components/copilot-provider/copilot-messages.tsx
|
|
669
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
670
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
671
|
+
function CopilotMessages({ children }) {
|
|
672
|
+
const [messages, setMessages] = (0, import_react6.useState)([]);
|
|
673
|
+
const lastLoadedThreadId = (0, import_react6.useRef)();
|
|
674
|
+
const lastLoadedAgentName = (0, import_react6.useRef)();
|
|
675
|
+
const lastLoadedMessages = (0, import_react6.useRef)();
|
|
676
|
+
const { threadId, agentSession, runtimeClient, showDevConsole } = useCopilotContext();
|
|
677
|
+
const { setBannerError } = useToast();
|
|
678
|
+
const createStructuredError2 = (gqlError) => {
|
|
679
|
+
const extensions = gqlError.extensions;
|
|
680
|
+
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
681
|
+
if (originalError == null ? void 0 : originalError.stack) {
|
|
682
|
+
if (originalError.stack.includes("CopilotApiDiscoveryError")) {
|
|
683
|
+
return new import_shared4.CopilotKitApiDiscoveryError({ message: originalError.message });
|
|
684
|
+
}
|
|
685
|
+
if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
686
|
+
return new import_shared4.CopilotKitRemoteEndpointDiscoveryError({ message: originalError.message });
|
|
687
|
+
}
|
|
688
|
+
if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) {
|
|
689
|
+
return new import_shared4.CopilotKitAgentDiscoveryError({
|
|
690
|
+
agentName: "",
|
|
691
|
+
availableAgents: []
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
696
|
+
const code = extensions == null ? void 0 : extensions.code;
|
|
697
|
+
if (code) {
|
|
698
|
+
return new import_shared4.CopilotKitError({ message, code });
|
|
699
|
+
}
|
|
700
|
+
return null;
|
|
653
701
|
};
|
|
654
|
-
|
|
655
|
-
|
|
702
|
+
const handleGraphQLErrors = (0, import_react6.useCallback)(
|
|
703
|
+
(error) => {
|
|
704
|
+
var _a;
|
|
705
|
+
if ((_a = error.graphQLErrors) == null ? void 0 : _a.length) {
|
|
706
|
+
const graphQLErrors = error.graphQLErrors;
|
|
707
|
+
const routeError = (gqlError) => {
|
|
708
|
+
const extensions = gqlError.extensions;
|
|
709
|
+
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
710
|
+
const isDev = shouldShowDevConsole(showDevConsole);
|
|
711
|
+
if (!isDev) {
|
|
712
|
+
console.error("CopilotKit Error (hidden in production):", gqlError.message);
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
if (visibility === import_shared4.ErrorVisibility.SILENT) {
|
|
716
|
+
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const ckError = createStructuredError2(gqlError);
|
|
720
|
+
if (ckError) {
|
|
721
|
+
setBannerError(ckError);
|
|
722
|
+
} else {
|
|
723
|
+
const fallbackError = new import_shared4.CopilotKitError({
|
|
724
|
+
message: gqlError.message,
|
|
725
|
+
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
726
|
+
});
|
|
727
|
+
setBannerError(fallbackError);
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
graphQLErrors.forEach(routeError);
|
|
731
|
+
} else {
|
|
732
|
+
const isDev = shouldShowDevConsole(showDevConsole);
|
|
733
|
+
if (!isDev) {
|
|
734
|
+
console.error("CopilotKit Error (hidden in production):", error);
|
|
735
|
+
} else {
|
|
736
|
+
const fallbackError = new import_shared4.CopilotKitError({
|
|
737
|
+
message: (error == null ? void 0 : error.message) || String(error),
|
|
738
|
+
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
739
|
+
});
|
|
740
|
+
setBannerError(fallbackError);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
[setBannerError, showDevConsole]
|
|
745
|
+
);
|
|
746
|
+
(0, import_react6.useEffect)(() => {
|
|
747
|
+
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
748
|
+
return;
|
|
749
|
+
if (threadId === lastLoadedThreadId.current && (agentSession == null ? void 0 : agentSession.agentName) === lastLoadedAgentName.current) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
const fetchMessages = () => __async(this, null, function* () {
|
|
753
|
+
var _a, _b, _c, _d;
|
|
754
|
+
if (!(agentSession == null ? void 0 : agentSession.agentName))
|
|
755
|
+
return;
|
|
756
|
+
const result = yield runtimeClient.loadAgentState({
|
|
757
|
+
threadId,
|
|
758
|
+
agentName: agentSession == null ? void 0 : agentSession.agentName
|
|
759
|
+
});
|
|
760
|
+
if (result.error) {
|
|
761
|
+
lastLoadedThreadId.current = threadId;
|
|
762
|
+
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
763
|
+
handleGraphQLErrors(result.error);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
const newMessages = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.messages;
|
|
767
|
+
if (newMessages === lastLoadedMessages.current)
|
|
768
|
+
return;
|
|
769
|
+
if ((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) {
|
|
770
|
+
lastLoadedMessages.current = newMessages;
|
|
771
|
+
lastLoadedThreadId.current = threadId;
|
|
772
|
+
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
773
|
+
const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(JSON.parse(newMessages || "[]"));
|
|
774
|
+
setMessages(messages2);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
void fetchMessages();
|
|
778
|
+
}, [threadId, agentSession == null ? void 0 : agentSession.agentName, runtimeClient]);
|
|
779
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
780
|
+
CopilotMessagesContext.Provider,
|
|
656
781
|
{
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
padding: "0.5rem 1.5rem",
|
|
661
|
-
borderRadius: "0.25rem",
|
|
662
|
-
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
663
|
-
position: "relative",
|
|
664
|
-
minWidth: "200px"
|
|
782
|
+
value: {
|
|
783
|
+
messages,
|
|
784
|
+
setMessages
|
|
665
785
|
},
|
|
666
|
-
children
|
|
667
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: message }),
|
|
668
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
669
|
-
"button",
|
|
670
|
-
{
|
|
671
|
-
onClick: onClose,
|
|
672
|
-
style: {
|
|
673
|
-
position: "absolute",
|
|
674
|
-
top: "0",
|
|
675
|
-
right: "0",
|
|
676
|
-
background: "none",
|
|
677
|
-
border: "none",
|
|
678
|
-
color: "white",
|
|
679
|
-
cursor: "pointer",
|
|
680
|
-
padding: "0.5rem",
|
|
681
|
-
fontSize: "1rem"
|
|
682
|
-
},
|
|
683
|
-
children: "\u2715"
|
|
684
|
-
}
|
|
685
|
-
)
|
|
686
|
-
]
|
|
786
|
+
children
|
|
687
787
|
}
|
|
688
788
|
);
|
|
689
789
|
}
|
|
690
790
|
|
|
691
791
|
// src/hooks/use-copilot-runtime-client.ts
|
|
692
792
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
693
|
-
var
|
|
793
|
+
var import_react7 = require("react");
|
|
794
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
694
795
|
var useCopilotRuntimeClient = (options) => {
|
|
695
|
-
const {
|
|
696
|
-
const
|
|
697
|
-
const
|
|
698
|
-
const runtimeClient = (0,
|
|
699
|
-
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({},
|
|
796
|
+
const { setBannerError } = useToast();
|
|
797
|
+
const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
|
|
798
|
+
const lastStructuredErrorRef = (0, import_react7.useRef)(null);
|
|
799
|
+
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
800
|
+
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
700
801
|
handleGQLErrors: (error) => {
|
|
701
|
-
|
|
702
|
-
|
|
802
|
+
var _a2;
|
|
803
|
+
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
804
|
+
const graphQLErrors = error.graphQLErrors;
|
|
805
|
+
const routeError = (gqlError) => {
|
|
806
|
+
const extensions = gqlError.extensions;
|
|
807
|
+
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
808
|
+
const isDev = shouldShowDevConsole(showDevConsole != null ? showDevConsole : false);
|
|
809
|
+
if (visibility === import_shared5.ErrorVisibility.SILENT) {
|
|
810
|
+
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
if (!isDev) {
|
|
814
|
+
console.error("CopilotKit Error (hidden in production):", gqlError.message);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
const now = Date.now();
|
|
818
|
+
const errorMessage = gqlError.message;
|
|
819
|
+
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };
|
|
823
|
+
const ckError = createStructuredError(gqlError);
|
|
824
|
+
if (ckError) {
|
|
825
|
+
setBannerError(ckError);
|
|
826
|
+
} else {
|
|
827
|
+
const fallbackError = new import_shared5.CopilotKitError({
|
|
828
|
+
message: gqlError.message,
|
|
829
|
+
code: import_shared5.CopilotKitErrorCode.UNKNOWN
|
|
830
|
+
});
|
|
831
|
+
setBannerError(fallbackError);
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
graphQLErrors.forEach(routeError);
|
|
703
835
|
} else {
|
|
704
|
-
|
|
836
|
+
const isDev = shouldShowDevConsole(showDevConsole != null ? showDevConsole : false);
|
|
837
|
+
if (!isDev) {
|
|
838
|
+
console.error("CopilotKit Error (hidden in production):", error);
|
|
839
|
+
} else {
|
|
840
|
+
const fallbackError = new import_shared5.CopilotKitError({
|
|
841
|
+
message: (error == null ? void 0 : error.message) || String(error),
|
|
842
|
+
code: import_shared5.CopilotKitErrorCode.UNKNOWN
|
|
843
|
+
});
|
|
844
|
+
setBannerError(fallbackError);
|
|
845
|
+
}
|
|
705
846
|
}
|
|
706
847
|
},
|
|
707
848
|
handleGQLWarning: (message) => {
|
|
708
849
|
console.warn(message);
|
|
709
|
-
|
|
850
|
+
const warningError = new import_shared5.CopilotKitError({
|
|
851
|
+
message,
|
|
852
|
+
code: import_shared5.CopilotKitErrorCode.UNKNOWN
|
|
853
|
+
});
|
|
854
|
+
setBannerError(warningError);
|
|
710
855
|
}
|
|
711
856
|
}));
|
|
712
|
-
}, [
|
|
857
|
+
}, [runtimeOptions, setBannerError, showDevConsole]);
|
|
713
858
|
return runtimeClient;
|
|
714
859
|
};
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
860
|
+
function createStructuredError(gqlError) {
|
|
861
|
+
var _a, _b, _c;
|
|
862
|
+
const extensions = gqlError.extensions;
|
|
863
|
+
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
864
|
+
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
865
|
+
const code = extensions == null ? void 0 : extensions.code;
|
|
866
|
+
if (code) {
|
|
867
|
+
return new import_shared5.CopilotKitError({ message, code });
|
|
720
868
|
}
|
|
721
|
-
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
if (
|
|
725
|
-
return
|
|
869
|
+
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
870
|
+
return new import_shared5.CopilotKitApiDiscoveryError({ message });
|
|
871
|
+
}
|
|
872
|
+
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
873
|
+
return new import_shared5.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
726
874
|
}
|
|
727
|
-
|
|
875
|
+
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
876
|
+
return new import_shared5.CopilotKitAgentDiscoveryError({
|
|
877
|
+
agentName: "",
|
|
878
|
+
availableAgents: []
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
return null;
|
|
728
882
|
}
|
|
729
883
|
|
|
730
884
|
// src/components/error-boundary/error-boundary.tsx
|
|
731
885
|
var import_react9 = __toESM(require("react"));
|
|
732
|
-
var
|
|
886
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
733
887
|
|
|
734
888
|
// src/lib/status-checker.ts
|
|
735
|
-
var
|
|
889
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
736
890
|
var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
|
|
737
891
|
var StatusChecker = class {
|
|
738
892
|
constructor() {
|
|
@@ -750,10 +904,10 @@ var StatusChecker = class {
|
|
|
750
904
|
clearInterval(this.intervalId);
|
|
751
905
|
const checkStatus = () => __async(this, null, function* () {
|
|
752
906
|
try {
|
|
753
|
-
const response = yield fetch(`${
|
|
907
|
+
const response = yield fetch(`${import_shared6.COPILOT_CLOUD_API_URL}/ciu`, {
|
|
754
908
|
method: "GET",
|
|
755
909
|
headers: {
|
|
756
|
-
[
|
|
910
|
+
[import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
|
|
757
911
|
}
|
|
758
912
|
}).then((response2) => response2.json());
|
|
759
913
|
this.lastResponse = response;
|
|
@@ -786,203 +940,463 @@ var StatusChecker = class {
|
|
|
786
940
|
};
|
|
787
941
|
|
|
788
942
|
// src/components/usage-banner.tsx
|
|
789
|
-
var
|
|
790
|
-
var
|
|
943
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
944
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
791
945
|
var defaultIcons = {
|
|
792
|
-
[
|
|
946
|
+
[import_shared7.Severity.CRITICAL]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
947
|
+
"svg",
|
|
948
|
+
{
|
|
949
|
+
viewBox: "0 0 24 24",
|
|
950
|
+
width: "18",
|
|
951
|
+
height: "18",
|
|
952
|
+
stroke: "currentColor",
|
|
953
|
+
strokeWidth: "2.5",
|
|
954
|
+
fill: "none",
|
|
955
|
+
strokeLinecap: "round",
|
|
956
|
+
strokeLinejoin: "round",
|
|
957
|
+
children: [
|
|
958
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
959
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "15", y1: "9", x2: "9", y2: "15" }),
|
|
960
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
|
|
961
|
+
]
|
|
962
|
+
}
|
|
963
|
+
),
|
|
964
|
+
[import_shared7.Severity.WARNING]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
793
965
|
"svg",
|
|
794
966
|
{
|
|
795
967
|
viewBox: "0 0 24 24",
|
|
796
|
-
width: "
|
|
797
|
-
height: "
|
|
968
|
+
width: "18",
|
|
969
|
+
height: "18",
|
|
798
970
|
stroke: "currentColor",
|
|
799
|
-
strokeWidth: "2",
|
|
971
|
+
strokeWidth: "2.5",
|
|
800
972
|
fill: "none",
|
|
801
973
|
strokeLinecap: "round",
|
|
802
974
|
strokeLinejoin: "round",
|
|
803
975
|
children: [
|
|
804
|
-
/* @__PURE__ */ (0,
|
|
805
|
-
/* @__PURE__ */ (0,
|
|
806
|
-
/* @__PURE__ */ (0,
|
|
976
|
+
/* @__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" }),
|
|
977
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "12", y1: "9", x2: "12", y2: "13" }),
|
|
978
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "12", y1: "17", x2: "12.01", y2: "17" })
|
|
979
|
+
]
|
|
980
|
+
}
|
|
981
|
+
),
|
|
982
|
+
[import_shared7.Severity.INFO]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
983
|
+
"svg",
|
|
984
|
+
{
|
|
985
|
+
viewBox: "0 0 24 24",
|
|
986
|
+
width: "18",
|
|
987
|
+
height: "18",
|
|
988
|
+
stroke: "currentColor",
|
|
989
|
+
strokeWidth: "2.5",
|
|
990
|
+
fill: "none",
|
|
991
|
+
strokeLinecap: "round",
|
|
992
|
+
strokeLinejoin: "round",
|
|
993
|
+
children: [
|
|
994
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
995
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "12", y1: "16", x2: "12", y2: "12" }),
|
|
996
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "12", y1: "8", x2: "12.01", y2: "8" })
|
|
807
997
|
]
|
|
808
998
|
}
|
|
809
999
|
)
|
|
810
1000
|
};
|
|
811
1001
|
function UsageBanner({
|
|
812
|
-
severity =
|
|
1002
|
+
severity = import_shared7.Severity.CRITICAL,
|
|
813
1003
|
message = "",
|
|
814
1004
|
icon,
|
|
1005
|
+
onClose,
|
|
815
1006
|
actions
|
|
816
1007
|
}) {
|
|
817
1008
|
if (!message || !severity) {
|
|
818
1009
|
return null;
|
|
819
1010
|
}
|
|
1011
|
+
const parseMessage = (rawMessage) => {
|
|
1012
|
+
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
1013
|
+
const matches = Array.from(rawMessage.matchAll(linkRegex));
|
|
1014
|
+
if (matches.length > 0) {
|
|
1015
|
+
let cleanMessage2 = rawMessage.replace(/\.\s*See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, ".").replace(/See more:\s*\[([^\]]+)\]\(([^)]+)\)/g, "").trim();
|
|
1016
|
+
return cleanMessage2;
|
|
1017
|
+
}
|
|
1018
|
+
return rawMessage;
|
|
1019
|
+
};
|
|
1020
|
+
const cleanMessage = parseMessage(message);
|
|
820
1021
|
const Icon = icon || defaultIcons[severity];
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
1022
|
+
const themeConfigs = {
|
|
1023
|
+
[import_shared7.Severity.INFO]: {
|
|
1024
|
+
bg: "linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%)",
|
|
1025
|
+
border: "#93c5fd",
|
|
1026
|
+
text: "#1e40af",
|
|
1027
|
+
icon: "#3b82f6",
|
|
1028
|
+
primaryBtn: "#3b82f6",
|
|
1029
|
+
primaryBtnHover: "#2563eb"
|
|
1030
|
+
},
|
|
1031
|
+
[import_shared7.Severity.WARNING]: {
|
|
1032
|
+
bg: "linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%)",
|
|
1033
|
+
border: "#fbbf24",
|
|
1034
|
+
text: "#92400e",
|
|
1035
|
+
icon: "#f59e0b",
|
|
1036
|
+
primaryBtn: "#f59e0b",
|
|
1037
|
+
primaryBtnHover: "#d97706"
|
|
1038
|
+
},
|
|
1039
|
+
[import_shared7.Severity.CRITICAL]: {
|
|
1040
|
+
bg: "linear-gradient(135deg, #fef2f2 0%, #fecaca 100%)",
|
|
1041
|
+
border: "#f87171",
|
|
1042
|
+
text: "#991b1b",
|
|
1043
|
+
icon: "#ef4444",
|
|
1044
|
+
primaryBtn: "#ef4444",
|
|
1045
|
+
primaryBtnHover: "#dc2626"
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
const themeConfig = themeConfigs[severity] || themeConfigs[import_shared7.Severity.CRITICAL];
|
|
1049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
847
1050
|
"div",
|
|
848
1051
|
{
|
|
849
1052
|
style: {
|
|
850
1053
|
position: "fixed",
|
|
851
|
-
bottom: "
|
|
1054
|
+
bottom: "20px",
|
|
852
1055
|
left: "50%",
|
|
853
1056
|
transform: "translateX(-50%)",
|
|
854
|
-
maxWidth: "
|
|
855
|
-
|
|
1057
|
+
maxWidth: "min(95vw, 680px)",
|
|
1058
|
+
width: "100%",
|
|
1059
|
+
zIndex: 1e4,
|
|
1060
|
+
animation: "bannerSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1)"
|
|
856
1061
|
},
|
|
857
|
-
children:
|
|
858
|
-
"
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
"
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1062
|
+
children: [
|
|
1063
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
|
|
1064
|
+
@keyframes bannerSlideIn {
|
|
1065
|
+
from {
|
|
1066
|
+
opacity: 0;
|
|
1067
|
+
transform: translateX(-50%) translateY(10px);
|
|
1068
|
+
}
|
|
1069
|
+
to {
|
|
1070
|
+
opacity: 1;
|
|
1071
|
+
transform: translateX(-50%) translateY(0);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
` }),
|
|
1075
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1076
|
+
"div",
|
|
1077
|
+
{
|
|
1078
|
+
style: {
|
|
1079
|
+
display: "flex",
|
|
1080
|
+
alignItems: "flex-start",
|
|
1081
|
+
gap: "14px",
|
|
1082
|
+
borderRadius: "16px",
|
|
1083
|
+
border: `1px solid ${themeConfig.border}`,
|
|
1084
|
+
background: themeConfig.bg,
|
|
1085
|
+
padding: "18px 20px",
|
|
1086
|
+
boxShadow: "0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1)",
|
|
1087
|
+
position: "relative",
|
|
1088
|
+
backdropFilter: "blur(10px)",
|
|
1089
|
+
WebkitBackdropFilter: "blur(10px)"
|
|
1090
|
+
},
|
|
1091
|
+
children: [
|
|
1092
|
+
onClose && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1093
|
+
"button",
|
|
1094
|
+
{
|
|
1095
|
+
onClick: onClose,
|
|
1096
|
+
style: {
|
|
1097
|
+
position: "absolute",
|
|
1098
|
+
top: "12px",
|
|
1099
|
+
right: "12px",
|
|
1100
|
+
background: "rgba(255, 255, 255, 0.8)",
|
|
1101
|
+
border: "none",
|
|
1102
|
+
color: themeConfig.text,
|
|
1103
|
+
cursor: "pointer",
|
|
1104
|
+
fontSize: "18px",
|
|
1105
|
+
lineHeight: "1",
|
|
1106
|
+
padding: "6px",
|
|
1107
|
+
borderRadius: "8px",
|
|
1108
|
+
opacity: 0.7,
|
|
1109
|
+
transition: "all 0.2s ease",
|
|
1110
|
+
display: "flex",
|
|
1111
|
+
alignItems: "center",
|
|
1112
|
+
justifyContent: "center",
|
|
1113
|
+
width: "28px",
|
|
1114
|
+
height: "28px"
|
|
1115
|
+
},
|
|
1116
|
+
title: "Close",
|
|
1117
|
+
onMouseOver: (e) => {
|
|
1118
|
+
e.currentTarget.style.opacity = "1";
|
|
1119
|
+
e.currentTarget.style.background = "rgba(255, 255, 255, 1)";
|
|
1120
|
+
e.currentTarget.style.transform = "scale(1.05)";
|
|
1121
|
+
},
|
|
1122
|
+
onMouseOut: (e) => {
|
|
1123
|
+
e.currentTarget.style.opacity = "0.7";
|
|
1124
|
+
e.currentTarget.style.background = "rgba(255, 255, 255, 0.8)";
|
|
1125
|
+
e.currentTarget.style.transform = "scale(1)";
|
|
1126
|
+
},
|
|
1127
|
+
children: "\xD7"
|
|
1128
|
+
}
|
|
1129
|
+
),
|
|
1130
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1131
|
+
"div",
|
|
1132
|
+
{
|
|
1133
|
+
style: {
|
|
1134
|
+
color: themeConfig.icon,
|
|
1135
|
+
flexShrink: 0,
|
|
1136
|
+
marginTop: "1px",
|
|
1137
|
+
padding: "6px",
|
|
1138
|
+
borderRadius: "10px",
|
|
1139
|
+
background: "rgba(255, 255, 255, 0.7)",
|
|
1140
|
+
display: "flex",
|
|
1141
|
+
alignItems: "center",
|
|
1142
|
+
justifyContent: "center"
|
|
1143
|
+
},
|
|
1144
|
+
children: Icon
|
|
1145
|
+
}
|
|
1146
|
+
),
|
|
1147
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { flex: 1, paddingRight: onClose ? "40px" : "0" }, children: [
|
|
1148
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1149
|
+
"div",
|
|
1150
|
+
{
|
|
1151
|
+
style: {
|
|
1152
|
+
fontSize: "15px",
|
|
1153
|
+
fontWeight: 600,
|
|
1154
|
+
color: themeConfig.text,
|
|
1155
|
+
lineHeight: "1.5",
|
|
1156
|
+
marginBottom: actions ? "12px" : "0",
|
|
1157
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1158
|
+
},
|
|
1159
|
+
children: cleanMessage
|
|
1160
|
+
}
|
|
1161
|
+
),
|
|
1162
|
+
actions && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1163
|
+
"div",
|
|
1164
|
+
{
|
|
1165
|
+
style: {
|
|
1166
|
+
display: "flex",
|
|
1167
|
+
gap: "10px",
|
|
1168
|
+
flexWrap: "wrap"
|
|
1169
|
+
},
|
|
1170
|
+
children: [
|
|
1171
|
+
actions.secondary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1172
|
+
"button",
|
|
1173
|
+
{
|
|
1174
|
+
onClick: actions.secondary.onClick,
|
|
1175
|
+
style: {
|
|
1176
|
+
borderRadius: "10px",
|
|
1177
|
+
padding: "8px 16px",
|
|
1178
|
+
fontSize: "14px",
|
|
1179
|
+
fontWeight: 500,
|
|
1180
|
+
color: themeConfig.text,
|
|
1181
|
+
backgroundColor: "rgba(255, 255, 255, 0.8)",
|
|
1182
|
+
border: `1.5px solid ${themeConfig.border}`,
|
|
1183
|
+
cursor: "pointer",
|
|
1184
|
+
transition: "all 0.2s ease",
|
|
1185
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1186
|
+
},
|
|
1187
|
+
onMouseOver: (e) => {
|
|
1188
|
+
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 1)";
|
|
1189
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
1190
|
+
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
|
|
1191
|
+
},
|
|
1192
|
+
onMouseOut: (e) => {
|
|
1193
|
+
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
|
|
1194
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
1195
|
+
e.currentTarget.style.boxShadow = "none";
|
|
1196
|
+
},
|
|
1197
|
+
children: actions.secondary.label
|
|
1198
|
+
}
|
|
1199
|
+
),
|
|
1200
|
+
actions.primary && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1201
|
+
"button",
|
|
1202
|
+
{
|
|
1203
|
+
onClick: actions.primary.onClick,
|
|
1204
|
+
style: {
|
|
1205
|
+
borderRadius: "10px",
|
|
1206
|
+
padding: "8px 16px",
|
|
1207
|
+
fontSize: "14px",
|
|
1208
|
+
fontWeight: 600,
|
|
1209
|
+
color: "#fff",
|
|
1210
|
+
backgroundColor: themeConfig.primaryBtn,
|
|
1211
|
+
border: "none",
|
|
1212
|
+
cursor: "pointer",
|
|
1213
|
+
transition: "all 0.2s ease",
|
|
1214
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
1215
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
|
|
1216
|
+
},
|
|
1217
|
+
onMouseOver: (e) => {
|
|
1218
|
+
e.currentTarget.style.backgroundColor = themeConfig.primaryBtnHover;
|
|
1219
|
+
e.currentTarget.style.transform = "translateY(-1px)";
|
|
1220
|
+
e.currentTarget.style.boxShadow = "0 6px 16px rgba(0, 0, 0, 0.2)";
|
|
1221
|
+
},
|
|
1222
|
+
onMouseOut: (e) => {
|
|
1223
|
+
e.currentTarget.style.backgroundColor = themeConfig.primaryBtn;
|
|
1224
|
+
e.currentTarget.style.transform = "translateY(0)";
|
|
1225
|
+
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
|
|
1226
|
+
},
|
|
1227
|
+
children: actions.primary.label
|
|
1228
|
+
}
|
|
1229
|
+
)
|
|
1230
|
+
]
|
|
1231
|
+
}
|
|
1232
|
+
)
|
|
1233
|
+
] })
|
|
1234
|
+
]
|
|
1235
|
+
}
|
|
1236
|
+
)
|
|
1237
|
+
]
|
|
942
1238
|
}
|
|
943
1239
|
);
|
|
944
1240
|
}
|
|
945
|
-
function renderCopilotKitUsage(error) {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
}
|
|
1241
|
+
function renderCopilotKitUsage(error, onClose) {
|
|
1242
|
+
if (error.visibility !== import_shared7.ErrorVisibility.BANNER) {
|
|
1243
|
+
return null;
|
|
1244
|
+
}
|
|
1245
|
+
const extractUrlFromMessage = (message) => {
|
|
1246
|
+
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
1247
|
+
const match = linkRegex.exec(message);
|
|
1248
|
+
return match ? match[2] : null;
|
|
1249
|
+
};
|
|
1250
|
+
const getErrorActions = (error2) => {
|
|
1251
|
+
switch (error2.name) {
|
|
1252
|
+
case import_shared7.ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR:
|
|
1253
|
+
return {
|
|
1254
|
+
primary: {
|
|
1255
|
+
label: "Sign In",
|
|
1256
|
+
onClick: () => window.location.href = "https://cloud.copilotkit.ai"
|
|
962
1257
|
}
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1258
|
+
};
|
|
1259
|
+
case import_shared7.ERROR_NAMES.UPGRADE_REQUIRED_ERROR:
|
|
1260
|
+
return {
|
|
1261
|
+
primary: {
|
|
1262
|
+
label: "Upgrade",
|
|
1263
|
+
onClick: () => window.location.href = "https://copilotkit.ai/"
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
case import_shared7.ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR:
|
|
1267
|
+
case import_shared7.ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR:
|
|
1268
|
+
case import_shared7.ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR:
|
|
1269
|
+
return {
|
|
1270
|
+
primary: {
|
|
1271
|
+
label: "View Docs",
|
|
1272
|
+
onClick: () => {
|
|
1273
|
+
var _a;
|
|
1274
|
+
const urlFromMessage = extractUrlFromMessage(error2.message);
|
|
1275
|
+
const urlFromExtensions = (_a = error2.extensions) == null ? void 0 : _a.troubleshootingUrl;
|
|
1276
|
+
const url = urlFromMessage || urlFromExtensions || "https://docs.copilotkit.ai/troubleshooting/common-issues";
|
|
1277
|
+
window.open(url, "_blank");
|
|
977
1278
|
}
|
|
978
1279
|
}
|
|
979
|
-
}
|
|
980
|
-
|
|
1280
|
+
};
|
|
1281
|
+
default:
|
|
1282
|
+
return void 0;
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1286
|
+
UsageBanner,
|
|
1287
|
+
{
|
|
1288
|
+
severity: error.severity || import_shared7.Severity.CRITICAL,
|
|
1289
|
+
message: error.message,
|
|
1290
|
+
onClose,
|
|
1291
|
+
actions: getErrorActions(error)
|
|
1292
|
+
}
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// src/components/error-boundary/error-utils.tsx
|
|
1297
|
+
var import_react8 = require("react");
|
|
1298
|
+
|
|
1299
|
+
// src/components/toast/exclamation-mark-icon.tsx
|
|
1300
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1301
|
+
var ExclamationMarkIcon = ({
|
|
1302
|
+
className,
|
|
1303
|
+
style
|
|
1304
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1305
|
+
"svg",
|
|
1306
|
+
{
|
|
1307
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1308
|
+
width: "24",
|
|
1309
|
+
height: "24",
|
|
1310
|
+
viewBox: "0 0 24 24",
|
|
1311
|
+
fill: "none",
|
|
1312
|
+
stroke: "currentColor",
|
|
1313
|
+
strokeWidth: "2",
|
|
1314
|
+
strokeLinecap: "round",
|
|
1315
|
+
strokeLinejoin: "round",
|
|
1316
|
+
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
1317
|
+
style,
|
|
1318
|
+
children: [
|
|
1319
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1320
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
1321
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
1322
|
+
]
|
|
981
1323
|
}
|
|
1324
|
+
);
|
|
1325
|
+
|
|
1326
|
+
// src/components/error-boundary/error-utils.tsx
|
|
1327
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1328
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1329
|
+
function ErrorToast({ errors }) {
|
|
1330
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
1331
|
+
var _a, _b, _c;
|
|
1332
|
+
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
1333
|
+
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
1334
|
+
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
1335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1336
|
+
"div",
|
|
1337
|
+
{
|
|
1338
|
+
style: {
|
|
1339
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
1340
|
+
marginBottom: 14
|
|
1341
|
+
},
|
|
1342
|
+
children: [
|
|
1343
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
1344
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1345
|
+
"div",
|
|
1346
|
+
{
|
|
1347
|
+
style: {
|
|
1348
|
+
fontWeight: "600",
|
|
1349
|
+
marginBottom: 4
|
|
1350
|
+
},
|
|
1351
|
+
children: [
|
|
1352
|
+
"Copilot Runtime Error:",
|
|
1353
|
+
" ",
|
|
1354
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
1355
|
+
]
|
|
1356
|
+
}
|
|
1357
|
+
),
|
|
1358
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_markdown.default, { children: message })
|
|
1359
|
+
]
|
|
1360
|
+
},
|
|
1361
|
+
idx
|
|
1362
|
+
);
|
|
1363
|
+
});
|
|
1364
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1365
|
+
"div",
|
|
1366
|
+
{
|
|
1367
|
+
style: {
|
|
1368
|
+
fontSize: "13px",
|
|
1369
|
+
maxWidth: "600px"
|
|
1370
|
+
},
|
|
1371
|
+
children: [
|
|
1372
|
+
errorsToRender,
|
|
1373
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
1374
|
+
]
|
|
1375
|
+
}
|
|
1376
|
+
);
|
|
1377
|
+
}
|
|
1378
|
+
function useErrorToast() {
|
|
1379
|
+
const { addToast } = useToast();
|
|
1380
|
+
return (0, import_react8.useCallback)(
|
|
1381
|
+
(error) => {
|
|
1382
|
+
const errorId = error.map((err) => {
|
|
1383
|
+
var _a, _b;
|
|
1384
|
+
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
1385
|
+
const stack = err.stack || "";
|
|
1386
|
+
return btoa(message + stack).slice(0, 32);
|
|
1387
|
+
}).join("|");
|
|
1388
|
+
addToast({
|
|
1389
|
+
type: "error",
|
|
1390
|
+
id: errorId,
|
|
1391
|
+
// Toast libraries typically dedupe by id
|
|
1392
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast, { errors: error })
|
|
1393
|
+
});
|
|
1394
|
+
},
|
|
1395
|
+
[addToast]
|
|
1396
|
+
);
|
|
982
1397
|
}
|
|
983
1398
|
|
|
984
1399
|
// src/components/error-boundary/error-boundary.tsx
|
|
985
|
-
var import_shared6 = require("@copilotkit/shared");
|
|
986
1400
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
987
1401
|
var statusChecker = new StatusChecker();
|
|
988
1402
|
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
@@ -1017,9 +1431,12 @@ var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
|
1017
1431
|
render() {
|
|
1018
1432
|
var _a, _b;
|
|
1019
1433
|
if (this.state.hasError) {
|
|
1020
|
-
if (this.state.error instanceof
|
|
1021
|
-
if (
|
|
1022
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: renderCopilotKitUsage(
|
|
1434
|
+
if (this.state.error instanceof import_shared8.CopilotKitError) {
|
|
1435
|
+
if (this.state.error.visibility === import_shared8.ErrorVisibility.BANNER) {
|
|
1436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: renderCopilotKitUsage(
|
|
1437
|
+
this.state.error,
|
|
1438
|
+
() => this.setState({ hasError: false, error: void 0 })
|
|
1439
|
+
) });
|
|
1023
1440
|
}
|
|
1024
1441
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1025
1442
|
this.props.children,
|
|
@@ -1053,14 +1470,16 @@ function ErrorToast2({ error, children }) {
|
|
|
1053
1470
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1054
1471
|
function CopilotKit(_a) {
|
|
1055
1472
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
1056
|
-
|
|
1473
|
+
var _a2;
|
|
1474
|
+
const showDevConsole = (_a2 = props.showDevConsole) != null ? _a2 : false;
|
|
1057
1475
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
1058
1476
|
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 })) }) });
|
|
1059
1477
|
}
|
|
1060
1478
|
function CopilotKitInternal(cpkProps) {
|
|
1479
|
+
var _b, _c;
|
|
1061
1480
|
const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
|
|
1062
1481
|
validateProps(cpkProps);
|
|
1063
|
-
const chatApiEndpoint = props.runtimeUrl ||
|
|
1482
|
+
const chatApiEndpoint = props.runtimeUrl || import_shared9.COPILOT_CLOUD_CHAT_URL;
|
|
1064
1483
|
const [actions, setActions] = (0, import_react10.useState)({});
|
|
1065
1484
|
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
|
|
1066
1485
|
const chatComponentsCache = (0, import_react10.useRef)({
|
|
@@ -1078,6 +1497,8 @@ function CopilotKitInternal(cpkProps) {
|
|
|
1078
1497
|
removeElement: removeDocument,
|
|
1079
1498
|
allElements: allDocuments
|
|
1080
1499
|
} = use_flat_category_store_default();
|
|
1500
|
+
const statusChecker2 = (0, import_react10.useMemo)(() => new StatusChecker(), []);
|
|
1501
|
+
const [usageBannerStatus, setUsageBannerStatus] = (0, import_react10.useState)(null);
|
|
1081
1502
|
const setAction = (0, import_react10.useCallback)((id, action) => {
|
|
1082
1503
|
setActions((prevPoints) => {
|
|
1083
1504
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
@@ -1159,7 +1580,7 @@ ${nonDocumentStrings}`;
|
|
|
1159
1580
|
[removeDocument]
|
|
1160
1581
|
);
|
|
1161
1582
|
const copilotApiConfig = (0, import_react10.useMemo)(() => {
|
|
1162
|
-
var _a2,
|
|
1583
|
+
var _a2, _b2;
|
|
1163
1584
|
let cloud = void 0;
|
|
1164
1585
|
if (props.publicApiKey) {
|
|
1165
1586
|
cloud = {
|
|
@@ -1168,7 +1589,7 @@ ${nonDocumentStrings}`;
|
|
|
1168
1589
|
restrictToTopic: {
|
|
1169
1590
|
enabled: Boolean(props.guardrails_c),
|
|
1170
1591
|
validTopics: ((_a2 = props.guardrails_c) == null ? void 0 : _a2.validTopics) || [],
|
|
1171
|
-
invalidTopics: ((
|
|
1592
|
+
invalidTopics: ((_b2 = props.guardrails_c) == null ? void 0 : _b2.invalidTopics) || []
|
|
1172
1593
|
}
|
|
1173
1594
|
}
|
|
1174
1595
|
}
|
|
@@ -1206,13 +1627,14 @@ ${nonDocumentStrings}`;
|
|
|
1206
1627
|
}
|
|
1207
1628
|
return acc;
|
|
1208
1629
|
}, {});
|
|
1209
|
-
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [
|
|
1630
|
+
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared9.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
|
|
1210
1631
|
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
1211
1632
|
const runtimeClient = useCopilotRuntimeClient({
|
|
1212
1633
|
url: copilotApiConfig.chatApiEndpoint,
|
|
1213
1634
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
1214
1635
|
headers,
|
|
1215
|
-
credentials: copilotApiConfig.credentials
|
|
1636
|
+
credentials: copilotApiConfig.credentials,
|
|
1637
|
+
showDevConsole: (_b = props.showDevConsole) != null ? _b : false
|
|
1216
1638
|
});
|
|
1217
1639
|
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
1218
1640
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
@@ -1267,7 +1689,7 @@ ${nonDocumentStrings}`;
|
|
|
1267
1689
|
setAgentSession(null);
|
|
1268
1690
|
}
|
|
1269
1691
|
}, [props.agent]);
|
|
1270
|
-
const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0,
|
|
1692
|
+
const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared9.randomUUID)());
|
|
1271
1693
|
const setThreadId = (0, import_react10.useCallback)(
|
|
1272
1694
|
(value) => {
|
|
1273
1695
|
if (props.threadId) {
|
|
@@ -1284,7 +1706,7 @@ ${nonDocumentStrings}`;
|
|
|
1284
1706
|
}, [props.threadId]);
|
|
1285
1707
|
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
1286
1708
|
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
1287
|
-
const showDevConsole = props.showDevConsole
|
|
1709
|
+
const showDevConsole = (_c = props.showDevConsole) != null ? _c : false;
|
|
1288
1710
|
const [langGraphInterruptAction, _setLangGraphInterruptAction] = (0, import_react10.useState)(null);
|
|
1289
1711
|
const setLangGraphInterruptAction = (0, import_react10.useCallback)((action) => {
|
|
1290
1712
|
_setLangGraphInterruptAction((prev) => {
|
|
@@ -1392,10 +1814,10 @@ function formatFeatureName(featureName) {
|
|
|
1392
1814
|
function validateProps(props) {
|
|
1393
1815
|
const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
|
|
1394
1816
|
if (!props.runtimeUrl && !props.publicApiKey) {
|
|
1395
|
-
throw new
|
|
1817
|
+
throw new import_shared9.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey'");
|
|
1396
1818
|
}
|
|
1397
1819
|
if (cloudFeatures.length > 0 && !props.publicApiKey) {
|
|
1398
|
-
throw new
|
|
1820
|
+
throw new import_shared9.MissingPublicApiKeyError(
|
|
1399
1821
|
`Missing required prop: 'publicApiKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
|
|
1400
1822
|
);
|
|
1401
1823
|
}
|