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