@copilotkit/react-core 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454 → 0.0.0-feat-enable-setting-recursion-limit-20250424165940
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 +796 -3
- package/dist/{chunk-LNI2Z45S.mjs → chunk-22ENANUU.mjs} +25 -17
- package/dist/chunk-22ENANUU.mjs.map +1 -0
- package/dist/{chunk-U6JICUGO.mjs → chunk-42SVH3TY.mjs} +238 -83
- package/dist/chunk-42SVH3TY.mjs.map +1 -0
- package/dist/{chunk-XERJQUHA.mjs → chunk-4CEQJ2X6.mjs} +2 -2
- package/dist/{chunk-XERJQUHA.mjs.map → chunk-4CEQJ2X6.mjs.map} +1 -1
- package/dist/chunk-534J55RX.mjs +86 -0
- package/dist/chunk-534J55RX.mjs.map +1 -0
- package/dist/{chunk-22XKTBPF.mjs → chunk-5TVV6FJD.mjs} +27 -4
- package/dist/chunk-5TVV6FJD.mjs.map +1 -0
- package/dist/chunk-6YOKPWQ7.mjs +1 -0
- package/dist/chunk-7VCWAAWC.mjs +24 -0
- package/dist/chunk-7VCWAAWC.mjs.map +1 -0
- package/dist/{chunk-6BQVZFNO.mjs → chunk-BKTARDXX.mjs} +8 -3
- package/dist/chunk-BKTARDXX.mjs.map +1 -0
- package/dist/{chunk-2KT73RVG.mjs → chunk-CMEX33KD.mjs} +100 -38
- package/dist/chunk-CMEX33KD.mjs.map +1 -0
- package/dist/chunk-CQPYJIBH.mjs +1 -0
- package/dist/chunk-D34OH4VN.mjs +201 -0
- package/dist/chunk-D34OH4VN.mjs.map +1 -0
- package/dist/chunk-DMQB35FC.mjs +47 -0
- package/dist/chunk-DMQB35FC.mjs.map +1 -0
- package/dist/{chunk-4TDYSNUD.mjs → chunk-EI2J4CP6.mjs} +26 -13
- package/dist/chunk-EI2J4CP6.mjs.map +1 -0
- package/dist/{chunk-KSPLXKSX.mjs → chunk-FGOCUTAU.mjs} +91 -50
- package/dist/chunk-FGOCUTAU.mjs.map +1 -0
- package/dist/{chunk-LHKIIAUQ.mjs → chunk-FRRPZKXW.mjs} +10 -10
- package/dist/chunk-FRRPZKXW.mjs.map +1 -0
- package/dist/chunk-FXVXAJVG.mjs +65 -0
- package/dist/chunk-FXVXAJVG.mjs.map +1 -0
- package/dist/{chunk-FQ53HQYZ.mjs → chunk-GOK4PDQO.mjs} +13 -4
- package/dist/{chunk-FQ53HQYZ.mjs.map → chunk-GOK4PDQO.mjs.map} +1 -1
- package/dist/chunk-HGZXDC4Y.mjs +63 -0
- package/dist/chunk-HGZXDC4Y.mjs.map +1 -0
- package/dist/{chunk-EWKJMQOF.mjs → chunk-JWE4IXSG.mjs} +18 -4
- package/dist/chunk-JWE4IXSG.mjs.map +1 -0
- package/dist/{chunk-HIUT2NLX.mjs → chunk-KF5SB2VB.mjs} +2 -2
- package/dist/chunk-PMAFHQ7P.mjs +65 -0
- package/dist/chunk-PMAFHQ7P.mjs.map +1 -0
- package/dist/{chunk-XOQMISG3.mjs → chunk-TWWQG3EF.mjs} +3 -3
- package/dist/{chunk-WXREY7UP.mjs → chunk-UDUFMGWQ.mjs} +11 -3
- package/dist/chunk-UDUFMGWQ.mjs.map +1 -0
- package/dist/chunk-YPBKY4KY.mjs +1 -0
- package/dist/chunk-YPBKY4KY.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.d.ts +4 -12
- package/dist/components/copilot-provider/copilot-messages.js +143 -18
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -1
- package/dist/components/copilot-provider/copilotkit-props.d.ts +37 -2
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +2 -2
- package/dist/components/copilot-provider/copilotkit.js +470 -58
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +9 -7
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +470 -58
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +9 -7
- package/dist/components/error-boundary/error-boundary.d.ts +12 -3
- package/dist/components/error-boundary/error-boundary.js +333 -19
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -2
- package/dist/components/error-boundary/error-utils.js +14 -2
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +470 -58
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -7
- package/dist/components/toast/toast-provider.js +34 -16
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/components/usage-banner.d.ts +22 -0
- package/dist/components/usage-banner.js +226 -0
- package/dist/components/usage-banner.js.map +1 -0
- package/dist/components/usage-banner.mjs +10 -0
- package/dist/components/usage-banner.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +10 -142
- package/dist/context/copilot-context.js +10 -2
- 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 +10 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +4 -4
- package/dist/copilot-context-0e923eb1.d.ts +194 -0
- package/dist/hooks/index.d.ts +5 -2
- package/dist/hooks/index.js +513 -145
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +37 -23
- package/dist/hooks/use-chat.d.ts +16 -6
- package/dist/hooks/use-chat.js +245 -79
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -4
- package/dist/hooks/use-coagent-state-render.d.ts +2 -7
- package/dist/hooks/use-coagent-state-render.js +34 -3
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -3
- package/dist/hooks/use-coagent.d.ts +20 -14
- package/dist/hooks/use-coagent.js +346 -131
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +13 -11
- package/dist/hooks/use-copilot-action.js +27 -4
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +3 -3
- package/dist/hooks/use-copilot-additional-instructions.d.ts +26 -0
- package/dist/hooks/use-copilot-additional-instructions.js +162 -0
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -0
- package/dist/hooks/use-copilot-additional-instructions.mjs +9 -0
- package/dist/hooks/use-copilot-additional-instructions.mjs.map +1 -0
- package/dist/hooks/use-copilot-authenticated-action.d.ts +12 -2
- package/dist/hooks/use-copilot-authenticated-action.js +35 -12
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +6 -6
- package/dist/hooks/use-copilot-chat.d.ts +3 -3
- package/dist/hooks/use-copilot-chat.js +264 -87
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +12 -10
- package/dist/hooks/use-copilot-readable.d.ts +5 -1
- package/dist/hooks/use-copilot-readable.js +21 -4
- 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.js +20 -3
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.d.ts +5 -0
- package/dist/hooks/use-langgraph-interrupt-render.js +185 -0
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -0
- package/dist/hooks/use-langgraph-interrupt-render.mjs +11 -0
- package/dist/hooks/use-langgraph-interrupt-render.mjs.map +1 -0
- package/dist/hooks/use-langgraph-interrupt.d.ts +14 -0
- package/dist/hooks/use-langgraph-interrupt.js +1154 -0
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -0
- package/dist/hooks/use-langgraph-interrupt.mjs +25 -0
- package/dist/hooks/use-langgraph-interrupt.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.js +10 -2
- 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 +7 -3
- package/dist/index.js +998 -240
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -28
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -9
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -9
- package/dist/lib/status-checker.d.ts +17 -0
- package/dist/lib/status-checker.js +102 -0
- package/dist/lib/status-checker.js.map +1 -0
- package/dist/lib/status-checker.mjs +8 -0
- package/dist/lib/status-checker.mjs.map +1 -0
- package/dist/types/coagent-state.d.ts +4 -0
- package/dist/types/coagent-state.js.map +1 -1
- package/dist/types/crew.d.ts +79 -0
- package/dist/types/crew.js +19 -0
- package/dist/types/crew.js.map +1 -0
- package/dist/types/crew.mjs +2 -0
- package/dist/types/crew.mjs.map +1 -0
- package/dist/types/frontend-action.d.ts +2 -1
- package/dist/types/frontend-action.js +1 -1
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/types/frontend-action.mjs +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +2 -1
- package/dist/types/interrupt-action.d.ts +10 -0
- package/dist/types/interrupt-action.js +19 -0
- package/dist/types/interrupt-action.js.map +1 -0
- package/dist/types/interrupt-action.mjs +1 -0
- package/dist/types/interrupt-action.mjs.map +1 -0
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +9 -7
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +9 -7
- package/package.json +5 -4
- package/src/components/copilot-provider/copilot-messages.tsx +41 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +36 -1
- package/src/components/copilot-provider/copilotkit.tsx +117 -29
- package/src/components/error-boundary/error-boundary.tsx +62 -4
- package/src/components/error-boundary/error-utils.tsx +11 -6
- package/src/components/toast/toast-provider.tsx +20 -17
- package/src/components/usage-banner.tsx +205 -0
- package/src/context/copilot-context.tsx +41 -10
- package/src/hooks/index.ts +4 -1
- package/src/hooks/use-chat.ts +288 -64
- package/src/hooks/use-coagent-state-render.ts +39 -8
- package/src/hooks/use-coagent.ts +125 -67
- package/src/hooks/use-copilot-action.ts +16 -0
- package/src/hooks/use-copilot-additional-instructions.ts +85 -0
- package/src/hooks/use-copilot-authenticated-action.ts +17 -7
- package/src/hooks/use-copilot-chat.ts +19 -5
- package/src/hooks/use-copilot-readable.ts +16 -2
- package/src/hooks/use-copilot-runtime-client.ts +6 -1
- package/src/hooks/use-langgraph-interrupt-render.ts +67 -0
- package/src/hooks/use-langgraph-interrupt.ts +61 -0
- package/src/lib/status-checker.ts +64 -0
- package/src/types/coagent-state.ts +4 -0
- package/src/types/crew.ts +89 -0
- package/src/types/frontend-action.ts +5 -2
- package/src/types/index.ts +8 -0
- package/src/types/interrupt-action.ts +39 -0
- package/dist/chunk-22XKTBPF.mjs.map +0 -1
- package/dist/chunk-2KT73RVG.mjs.map +0 -1
- package/dist/chunk-4TDYSNUD.mjs.map +0 -1
- package/dist/chunk-6BQVZFNO.mjs.map +0 -1
- package/dist/chunk-EFZPSZWO.mjs +0 -1
- package/dist/chunk-EWKJMQOF.mjs.map +0 -1
- package/dist/chunk-KSPLXKSX.mjs.map +0 -1
- package/dist/chunk-LHKIIAUQ.mjs.map +0 -1
- package/dist/chunk-LNI2Z45S.mjs.map +0 -1
- package/dist/chunk-NR2BTA6Z.mjs +0 -1
- package/dist/chunk-U6JICUGO.mjs.map +0 -1
- package/dist/chunk-VNTDIJSG.mjs +0 -37
- package/dist/chunk-VNTDIJSG.mjs.map +0 -1
- package/dist/chunk-WXREY7UP.mjs.map +0 -1
- package/dist/chunk-XXR4QFAQ.mjs +0 -29
- package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
- /package/dist/{chunk-EFZPSZWO.mjs.map → chunk-6YOKPWQ7.mjs.map} +0 -0
- /package/dist/{chunk-NR2BTA6Z.mjs.map → chunk-CQPYJIBH.mjs.map} +0 -0
- /package/dist/{chunk-HIUT2NLX.mjs.map → chunk-KF5SB2VB.mjs.map} +0 -0
- /package/dist/{chunk-XOQMISG3.mjs.map → chunk-TWWQG3EF.mjs.map} +0 -0
|
@@ -111,6 +111,8 @@ var emptyCopilotContext = {
|
|
|
111
111
|
setIsLoading: () => returnAndThrowInDebug(false),
|
|
112
112
|
chatInstructions: "",
|
|
113
113
|
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
114
|
+
additionalInstructions: [],
|
|
115
|
+
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
114
116
|
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
115
117
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
116
118
|
removeDocumentContext: () => {
|
|
@@ -144,16 +146,29 @@ var emptyCopilotContext = {
|
|
|
144
146
|
},
|
|
145
147
|
forwardedParameters: {},
|
|
146
148
|
agentLock: null,
|
|
147
|
-
threadId:
|
|
149
|
+
threadId: "",
|
|
148
150
|
setThreadId: () => {
|
|
149
151
|
},
|
|
150
152
|
runId: null,
|
|
151
153
|
setRunId: () => {
|
|
152
154
|
},
|
|
153
155
|
chatAbortControllerRef: { current: null },
|
|
154
|
-
availableAgents: []
|
|
156
|
+
availableAgents: [],
|
|
157
|
+
extensions: {},
|
|
158
|
+
setExtensions: () => {
|
|
159
|
+
},
|
|
160
|
+
langGraphInterruptAction: null,
|
|
161
|
+
setLangGraphInterruptAction: () => null,
|
|
162
|
+
removeLangGraphInterruptAction: () => null
|
|
155
163
|
};
|
|
156
164
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
165
|
+
function useCopilotContext() {
|
|
166
|
+
const context = import_react.default.useContext(CopilotContext);
|
|
167
|
+
if (context === emptyCopilotContext) {
|
|
168
|
+
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
169
|
+
}
|
|
170
|
+
return context;
|
|
171
|
+
}
|
|
157
172
|
function returnAndThrowInDebug(_value) {
|
|
158
173
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
159
174
|
}
|
|
@@ -291,7 +306,7 @@ function setsHaveIntersection(setA, setB) {
|
|
|
291
306
|
|
|
292
307
|
// src/components/copilot-provider/copilotkit.tsx
|
|
293
308
|
var import_react_dom = require("react-dom");
|
|
294
|
-
var
|
|
309
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
295
310
|
|
|
296
311
|
// src/hooks/use-flat-category-store.ts
|
|
297
312
|
var import_react3 = require("react");
|
|
@@ -371,10 +386,41 @@ var emptyCopilotContext2 = {
|
|
|
371
386
|
var CopilotMessagesContext = import_react4.default.createContext(emptyCopilotContext2);
|
|
372
387
|
|
|
373
388
|
// src/components/copilot-provider/copilot-messages.tsx
|
|
389
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
374
390
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
375
|
-
function CopilotMessages(
|
|
376
|
-
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
391
|
+
function CopilotMessages({ children }) {
|
|
377
392
|
const [messages, setMessages] = (0, import_react5.useState)([]);
|
|
393
|
+
const lastLoadedThreadId = (0, import_react5.useRef)();
|
|
394
|
+
const lastLoadedAgentName = (0, import_react5.useRef)();
|
|
395
|
+
const lastLoadedMessages = (0, import_react5.useRef)();
|
|
396
|
+
const { threadId, agentSession, runtimeClient } = useCopilotContext();
|
|
397
|
+
(0, import_react5.useEffect)(() => {
|
|
398
|
+
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
399
|
+
return;
|
|
400
|
+
if (threadId === lastLoadedThreadId.current && (agentSession == null ? void 0 : agentSession.agentName) === lastLoadedAgentName.current) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const fetchMessages = () => __async(this, null, function* () {
|
|
404
|
+
var _a, _b, _c, _d;
|
|
405
|
+
if (!(agentSession == null ? void 0 : agentSession.agentName))
|
|
406
|
+
return;
|
|
407
|
+
const result = yield runtimeClient.loadAgentState({
|
|
408
|
+
threadId,
|
|
409
|
+
agentName: agentSession == null ? void 0 : agentSession.agentName
|
|
410
|
+
});
|
|
411
|
+
const newMessages = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.messages;
|
|
412
|
+
if (newMessages === lastLoadedMessages.current)
|
|
413
|
+
return;
|
|
414
|
+
if ((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) {
|
|
415
|
+
lastLoadedMessages.current = newMessages;
|
|
416
|
+
lastLoadedThreadId.current = threadId;
|
|
417
|
+
lastLoadedAgentName.current = agentSession == null ? void 0 : agentSession.agentName;
|
|
418
|
+
const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(JSON.parse(newMessages || "[]"));
|
|
419
|
+
setMessages(messages2);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
void fetchMessages();
|
|
423
|
+
}, [threadId, agentSession == null ? void 0 : agentSession.agentName]);
|
|
378
424
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
379
425
|
CopilotMessagesContext.Provider,
|
|
380
426
|
{
|
|
@@ -421,11 +467,13 @@ var ExclamationMarkIcon = ({
|
|
|
421
467
|
);
|
|
422
468
|
|
|
423
469
|
// src/components/error-boundary/error-utils.tsx
|
|
470
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
424
471
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
425
472
|
function ErrorToast({ errors }) {
|
|
426
473
|
const errorsToRender = errors.map((error, idx) => {
|
|
427
474
|
var _a, _b, _c;
|
|
428
|
-
const
|
|
475
|
+
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
476
|
+
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
429
477
|
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
430
478
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
431
479
|
"div",
|
|
@@ -450,7 +498,7 @@ function ErrorToast({ errors }) {
|
|
|
450
498
|
]
|
|
451
499
|
}
|
|
452
500
|
),
|
|
453
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
501
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
454
502
|
]
|
|
455
503
|
},
|
|
456
504
|
idx
|
|
@@ -506,20 +554,26 @@ function ToastProvider({
|
|
|
506
554
|
children
|
|
507
555
|
}) {
|
|
508
556
|
const [toasts, setToasts] = (0, import_react7.useState)([]);
|
|
509
|
-
const addToast = (0, import_react7.useCallback)(
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
|
|
557
|
+
const addToast = (0, import_react7.useCallback)(
|
|
558
|
+
(toast) => {
|
|
559
|
+
var _a;
|
|
560
|
+
if (!enabled) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
|
|
564
|
+
setToasts((currentToasts) => {
|
|
565
|
+
if (currentToasts.find((toast2) => toast2.id === id))
|
|
566
|
+
return currentToasts;
|
|
567
|
+
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
568
|
+
});
|
|
569
|
+
if (toast.duration) {
|
|
570
|
+
setTimeout(() => {
|
|
571
|
+
removeToast(id);
|
|
572
|
+
}, toast.duration);
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
[enabled]
|
|
576
|
+
);
|
|
523
577
|
const addGraphQLErrorsToast = (0, import_react7.useCallback)((errors) => {
|
|
524
578
|
addToast({
|
|
525
579
|
type: "error",
|
|
@@ -630,22 +684,27 @@ function Toast({
|
|
|
630
684
|
}
|
|
631
685
|
|
|
632
686
|
// src/hooks/use-copilot-runtime-client.ts
|
|
633
|
-
var
|
|
687
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
634
688
|
var import_react8 = require("react");
|
|
635
689
|
var useCopilotRuntimeClient = (options) => {
|
|
636
690
|
const { addGraphQLErrorsToast } = useToast();
|
|
637
691
|
const addErrorToast = useErrorToast();
|
|
692
|
+
const { addToast } = useToast();
|
|
638
693
|
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
639
|
-
return new
|
|
694
|
+
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
640
695
|
handleGQLErrors: (error) => {
|
|
641
696
|
if (error.graphQLErrors.length) {
|
|
642
697
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
643
698
|
} else {
|
|
644
699
|
addErrorToast([error]);
|
|
645
700
|
}
|
|
701
|
+
},
|
|
702
|
+
handleGQLWarning: (message) => {
|
|
703
|
+
console.warn(message);
|
|
704
|
+
addToast({ type: "warning", message });
|
|
646
705
|
}
|
|
647
706
|
}));
|
|
648
|
-
}, [options, addGraphQLErrorsToast]);
|
|
707
|
+
}, [options, addGraphQLErrorsToast, addToast]);
|
|
649
708
|
return runtimeClient;
|
|
650
709
|
};
|
|
651
710
|
|
|
@@ -665,20 +724,312 @@ function getHostname() {
|
|
|
665
724
|
|
|
666
725
|
// src/components/error-boundary/error-boundary.tsx
|
|
667
726
|
var import_react9 = __toESM(require("react"));
|
|
727
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
728
|
+
|
|
729
|
+
// src/lib/status-checker.ts
|
|
730
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
731
|
+
var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
|
|
732
|
+
var StatusChecker = class {
|
|
733
|
+
constructor() {
|
|
734
|
+
this.activeKey = null;
|
|
735
|
+
this.intervalId = null;
|
|
736
|
+
this.instanceCount = 0;
|
|
737
|
+
this.lastResponse = null;
|
|
738
|
+
}
|
|
739
|
+
start(publicApiKey, onUpdate) {
|
|
740
|
+
return __async(this, null, function* () {
|
|
741
|
+
this.instanceCount++;
|
|
742
|
+
if (this.activeKey === publicApiKey)
|
|
743
|
+
return;
|
|
744
|
+
if (this.intervalId)
|
|
745
|
+
clearInterval(this.intervalId);
|
|
746
|
+
const checkStatus = () => __async(this, null, function* () {
|
|
747
|
+
try {
|
|
748
|
+
const response = yield fetch(`${import_shared3.COPILOT_CLOUD_API_URL}/ciu`, {
|
|
749
|
+
method: "GET",
|
|
750
|
+
headers: {
|
|
751
|
+
[import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
|
|
752
|
+
}
|
|
753
|
+
}).then((response2) => response2.json());
|
|
754
|
+
this.lastResponse = response;
|
|
755
|
+
onUpdate == null ? void 0 : onUpdate(response);
|
|
756
|
+
return response;
|
|
757
|
+
} catch (error) {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
const initialResponse = yield checkStatus();
|
|
762
|
+
this.intervalId = setInterval(checkStatus, STATUS_CHECK_INTERVAL);
|
|
763
|
+
this.activeKey = publicApiKey;
|
|
764
|
+
return initialResponse;
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
getLastResponse() {
|
|
768
|
+
return this.lastResponse;
|
|
769
|
+
}
|
|
770
|
+
stop() {
|
|
771
|
+
this.instanceCount--;
|
|
772
|
+
if (this.instanceCount === 0) {
|
|
773
|
+
if (this.intervalId) {
|
|
774
|
+
clearInterval(this.intervalId);
|
|
775
|
+
this.intervalId = null;
|
|
776
|
+
this.activeKey = null;
|
|
777
|
+
this.lastResponse = null;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
// src/components/usage-banner.tsx
|
|
784
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
668
785
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
786
|
+
var defaultIcons = {
|
|
787
|
+
[import_shared4.Severity.Error]: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
788
|
+
"svg",
|
|
789
|
+
{
|
|
790
|
+
viewBox: "0 0 24 24",
|
|
791
|
+
width: "20",
|
|
792
|
+
height: "20",
|
|
793
|
+
stroke: "currentColor",
|
|
794
|
+
strokeWidth: "2",
|
|
795
|
+
fill: "none",
|
|
796
|
+
strokeLinecap: "round",
|
|
797
|
+
strokeLinejoin: "round",
|
|
798
|
+
children: [
|
|
799
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
800
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "15", y1: "9", x2: "9", y2: "15" }),
|
|
801
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
|
|
802
|
+
]
|
|
803
|
+
}
|
|
804
|
+
)
|
|
805
|
+
};
|
|
806
|
+
function UsageBanner({
|
|
807
|
+
severity = import_shared4.Severity.Error,
|
|
808
|
+
message = "",
|
|
809
|
+
icon,
|
|
810
|
+
actions
|
|
811
|
+
}) {
|
|
812
|
+
if (!message || !severity) {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
const Icon = icon || defaultIcons[severity];
|
|
816
|
+
const bgColor = {
|
|
817
|
+
info: "#dbeafe",
|
|
818
|
+
warning: "#fef3c7",
|
|
819
|
+
error: "#fee2e2"
|
|
820
|
+
}[severity];
|
|
821
|
+
const textColor = {
|
|
822
|
+
info: "#1e40af",
|
|
823
|
+
warning: "#854d0e",
|
|
824
|
+
error: "#991b1b"
|
|
825
|
+
}[severity];
|
|
826
|
+
const iconColor = {
|
|
827
|
+
info: "#3b82f6",
|
|
828
|
+
warning: "#eab308",
|
|
829
|
+
error: "#ef4444"
|
|
830
|
+
}[severity];
|
|
831
|
+
const primaryButtonColor = {
|
|
832
|
+
info: "#3b82f6",
|
|
833
|
+
warning: "#eab308",
|
|
834
|
+
error: "#ef4444"
|
|
835
|
+
}[severity];
|
|
836
|
+
const primaryButtonHoverColor = {
|
|
837
|
+
info: "#2563eb",
|
|
838
|
+
warning: "#ca8a04",
|
|
839
|
+
error: "#dc2626"
|
|
840
|
+
}[severity];
|
|
841
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
842
|
+
"div",
|
|
843
|
+
{
|
|
844
|
+
style: {
|
|
845
|
+
position: "fixed",
|
|
846
|
+
bottom: "16px",
|
|
847
|
+
left: "50%",
|
|
848
|
+
transform: "translateX(-50%)",
|
|
849
|
+
maxWidth: "90%",
|
|
850
|
+
zIndex: 9999
|
|
851
|
+
},
|
|
852
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
853
|
+
"div",
|
|
854
|
+
{
|
|
855
|
+
style: {
|
|
856
|
+
display: "flex",
|
|
857
|
+
flexWrap: "wrap",
|
|
858
|
+
alignItems: "center",
|
|
859
|
+
gap: "12px",
|
|
860
|
+
borderRadius: "9999px",
|
|
861
|
+
border: "1px solid #e5e7eb",
|
|
862
|
+
backgroundColor: bgColor,
|
|
863
|
+
padding: "8px 16px",
|
|
864
|
+
boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)"
|
|
865
|
+
},
|
|
866
|
+
children: [
|
|
867
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { color: iconColor }, children: Icon }),
|
|
868
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
869
|
+
"span",
|
|
870
|
+
{
|
|
871
|
+
style: {
|
|
872
|
+
flex: 1,
|
|
873
|
+
fontSize: "14px",
|
|
874
|
+
fontWeight: 500,
|
|
875
|
+
color: textColor,
|
|
876
|
+
whiteSpace: "normal",
|
|
877
|
+
wordBreak: "break-word"
|
|
878
|
+
},
|
|
879
|
+
children: message
|
|
880
|
+
}
|
|
881
|
+
),
|
|
882
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
883
|
+
"div",
|
|
884
|
+
{
|
|
885
|
+
style: {
|
|
886
|
+
display: "flex",
|
|
887
|
+
gap: "8px",
|
|
888
|
+
flexWrap: "wrap"
|
|
889
|
+
},
|
|
890
|
+
children: [
|
|
891
|
+
(actions == null ? void 0 : actions.secondary) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
892
|
+
"button",
|
|
893
|
+
{
|
|
894
|
+
onClick: actions.secondary.onClick,
|
|
895
|
+
style: {
|
|
896
|
+
borderRadius: "9999px",
|
|
897
|
+
padding: "4px 12px",
|
|
898
|
+
fontSize: "14px",
|
|
899
|
+
fontWeight: 500,
|
|
900
|
+
color: textColor,
|
|
901
|
+
backgroundColor: "transparent",
|
|
902
|
+
border: "none",
|
|
903
|
+
cursor: "pointer",
|
|
904
|
+
transition: "background-color 0.2s"
|
|
905
|
+
},
|
|
906
|
+
onMouseOver: (e) => e.currentTarget.style.backgroundColor = "rgba(255,255,255,0.5)",
|
|
907
|
+
onMouseOut: (e) => e.currentTarget.style.backgroundColor = "transparent",
|
|
908
|
+
children: actions.secondary.label
|
|
909
|
+
}
|
|
910
|
+
),
|
|
911
|
+
(actions == null ? void 0 : actions.primary) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
912
|
+
"button",
|
|
913
|
+
{
|
|
914
|
+
onClick: actions.primary.onClick,
|
|
915
|
+
style: {
|
|
916
|
+
borderRadius: "9999px",
|
|
917
|
+
padding: "4px 12px",
|
|
918
|
+
fontSize: "14px",
|
|
919
|
+
fontWeight: 500,
|
|
920
|
+
color: "#fff",
|
|
921
|
+
backgroundColor: primaryButtonColor,
|
|
922
|
+
border: "none",
|
|
923
|
+
cursor: "pointer",
|
|
924
|
+
transition: "background-color 0.2s"
|
|
925
|
+
},
|
|
926
|
+
onMouseOver: (e) => e.currentTarget.style.backgroundColor = primaryButtonHoverColor,
|
|
927
|
+
onMouseOut: (e) => e.currentTarget.style.backgroundColor = primaryButtonColor,
|
|
928
|
+
children: actions.primary.label
|
|
929
|
+
}
|
|
930
|
+
)
|
|
931
|
+
]
|
|
932
|
+
}
|
|
933
|
+
)
|
|
934
|
+
]
|
|
935
|
+
}
|
|
936
|
+
)
|
|
937
|
+
}
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
function renderCopilotKitUsage(error) {
|
|
941
|
+
switch (error.name) {
|
|
942
|
+
case import_shared4.ERROR_NAMES.CONFIGURATION_ERROR:
|
|
943
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(UsageBanner, { severity: error.severity, message: error.message });
|
|
944
|
+
case import_shared4.ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR:
|
|
945
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
946
|
+
UsageBanner,
|
|
947
|
+
{
|
|
948
|
+
severity: error.severity,
|
|
949
|
+
message: error.message,
|
|
950
|
+
actions: {
|
|
951
|
+
primary: {
|
|
952
|
+
label: "Sign In",
|
|
953
|
+
onClick: () => {
|
|
954
|
+
window.location.href = "https://cloud.copilotkit.ai";
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
);
|
|
960
|
+
case import_shared4.ERROR_NAMES.UPGRADE_REQUIRED_ERROR:
|
|
961
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
962
|
+
UsageBanner,
|
|
963
|
+
{
|
|
964
|
+
severity: error.severity,
|
|
965
|
+
message: error.message,
|
|
966
|
+
actions: {
|
|
967
|
+
primary: {
|
|
968
|
+
label: "Upgrade",
|
|
969
|
+
onClick: () => {
|
|
970
|
+
window.location.href = "https://copilotkit.ai/";
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// src/components/error-boundary/error-boundary.tsx
|
|
980
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
981
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
982
|
+
var statusChecker = new StatusChecker();
|
|
669
983
|
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
670
984
|
constructor(props) {
|
|
671
985
|
super(props);
|
|
672
|
-
this.state = {
|
|
986
|
+
this.state = {
|
|
987
|
+
hasError: false
|
|
988
|
+
};
|
|
673
989
|
}
|
|
674
990
|
static getDerivedStateFromError(error) {
|
|
675
991
|
return { hasError: true, error };
|
|
676
992
|
}
|
|
993
|
+
componentDidMount() {
|
|
994
|
+
if (this.props.publicApiKey) {
|
|
995
|
+
statusChecker.start(this.props.publicApiKey, (newStatus) => {
|
|
996
|
+
this.setState((prevState) => {
|
|
997
|
+
var _a;
|
|
998
|
+
if ((newStatus == null ? void 0 : newStatus.severity) !== ((_a = prevState.status) == null ? void 0 : _a.severity)) {
|
|
999
|
+
return { status: newStatus != null ? newStatus : void 0 };
|
|
1000
|
+
}
|
|
1001
|
+
return null;
|
|
1002
|
+
});
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
componentWillUnmount() {
|
|
1007
|
+
statusChecker.stop();
|
|
1008
|
+
}
|
|
677
1009
|
componentDidCatch(error, errorInfo) {
|
|
678
1010
|
console.error("CopilotKit Error:", error, errorInfo);
|
|
679
1011
|
}
|
|
680
1012
|
render() {
|
|
681
|
-
|
|
1013
|
+
var _a, _b;
|
|
1014
|
+
if (this.state.hasError) {
|
|
1015
|
+
if (this.state.error instanceof import_shared5.CopilotKitError) {
|
|
1016
|
+
if (import_shared6.COPILOT_CLOUD_ERROR_NAMES.includes(this.state.error.name)) {
|
|
1017
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: renderCopilotKitUsage(this.state.error) });
|
|
1018
|
+
}
|
|
1019
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1020
|
+
this.props.children,
|
|
1021
|
+
this.props.showUsageBanner && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1022
|
+
UsageBanner,
|
|
1023
|
+
{
|
|
1024
|
+
severity: (_a = this.state.status) == null ? void 0 : _a.severity,
|
|
1025
|
+
message: (_b = this.state.status) == null ? void 0 : _b.message
|
|
1026
|
+
}
|
|
1027
|
+
)
|
|
1028
|
+
] });
|
|
1029
|
+
}
|
|
1030
|
+
throw this.state.error;
|
|
1031
|
+
}
|
|
1032
|
+
return this.props.children;
|
|
682
1033
|
}
|
|
683
1034
|
};
|
|
684
1035
|
function ErrorToast2({ error, children }) {
|
|
@@ -688,25 +1039,23 @@ function ErrorToast2({ error, children }) {
|
|
|
688
1039
|
addErrorToast([error]);
|
|
689
1040
|
}
|
|
690
1041
|
}, [error, addErrorToast]);
|
|
1042
|
+
if (!error)
|
|
1043
|
+
throw error;
|
|
691
1044
|
return children;
|
|
692
1045
|
}
|
|
693
1046
|
|
|
694
1047
|
// src/components/copilot-provider/copilotkit.tsx
|
|
695
|
-
var
|
|
1048
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
696
1049
|
function CopilotKit(_a) {
|
|
697
1050
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
698
1051
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
699
1052
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
700
|
-
return /* @__PURE__ */ (0,
|
|
1053
|
+
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 })) }) });
|
|
701
1054
|
}
|
|
702
|
-
function CopilotKitInternal(
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
"Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component."
|
|
707
|
-
);
|
|
708
|
-
}
|
|
709
|
-
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
1055
|
+
function CopilotKitInternal(cpkProps) {
|
|
1056
|
+
const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
|
|
1057
|
+
validateProps(cpkProps);
|
|
1058
|
+
const chatApiEndpoint = props.runtimeUrl || import_shared7.COPILOT_CLOUD_CHAT_URL;
|
|
710
1059
|
const [actions, setActions] = (0, import_react10.useState)({});
|
|
711
1060
|
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
|
|
712
1061
|
const chatComponentsCache = (0, import_react10.useRef)({
|
|
@@ -717,6 +1066,8 @@ function CopilotKitInternal(_a) {
|
|
|
717
1066
|
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
718
1067
|
const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
|
|
719
1068
|
const [authStates, setAuthStates] = (0, import_react10.useState)({});
|
|
1069
|
+
const [extensions, setExtensions] = (0, import_react10.useState)({});
|
|
1070
|
+
const [additionalInstructions, setAdditionalInstructions] = (0, import_react10.useState)([]);
|
|
720
1071
|
const {
|
|
721
1072
|
addElement: addDocument,
|
|
722
1073
|
removeElement: removeDocument,
|
|
@@ -799,24 +1150,17 @@ ${nonDocumentStrings}`;
|
|
|
799
1150
|
},
|
|
800
1151
|
[removeDocument]
|
|
801
1152
|
);
|
|
802
|
-
if (!props.publicApiKey) {
|
|
803
|
-
if (props.cloudRestrictToTopic) {
|
|
804
|
-
throw new Error(
|
|
805
|
-
"To use the cloudRestrictToTopic feature, please sign up at https://copilotkit.ai and provide a publicApiKey."
|
|
806
|
-
);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
1153
|
const copilotApiConfig = (0, import_react10.useMemo)(() => {
|
|
810
|
-
var _a2,
|
|
1154
|
+
var _a2, _b;
|
|
811
1155
|
let cloud = void 0;
|
|
812
1156
|
if (props.publicApiKey) {
|
|
813
1157
|
cloud = {
|
|
814
1158
|
guardrails: {
|
|
815
1159
|
input: {
|
|
816
1160
|
restrictToTopic: {
|
|
817
|
-
enabled: props.
|
|
818
|
-
validTopics: ((_a2 = props.
|
|
819
|
-
invalidTopics: ((
|
|
1161
|
+
enabled: Boolean(props.guardrails_c),
|
|
1162
|
+
validTopics: ((_a2 = props.guardrails_c) == null ? void 0 : _a2.validTopics) || [],
|
|
1163
|
+
invalidTopics: ((_b = props.guardrails_c) == null ? void 0 : _b.invalidTopics) || []
|
|
820
1164
|
}
|
|
821
1165
|
}
|
|
822
1166
|
}
|
|
@@ -830,7 +1174,8 @@ ${nonDocumentStrings}`;
|
|
|
830
1174
|
properties: props.properties || {},
|
|
831
1175
|
transcribeAudioUrl: props.transcribeAudioUrl,
|
|
832
1176
|
textToSpeechUrl: props.textToSpeechUrl,
|
|
833
|
-
credentials: props.credentials
|
|
1177
|
+
credentials: props.credentials,
|
|
1178
|
+
mcpEndpoints: props.mcpEndpoints
|
|
834
1179
|
});
|
|
835
1180
|
}, [
|
|
836
1181
|
props.publicApiKey,
|
|
@@ -839,7 +1184,9 @@ ${nonDocumentStrings}`;
|
|
|
839
1184
|
props.transcribeAudioUrl,
|
|
840
1185
|
props.textToSpeechUrl,
|
|
841
1186
|
props.credentials,
|
|
842
|
-
props.cloudRestrictToTopic
|
|
1187
|
+
props.cloudRestrictToTopic,
|
|
1188
|
+
props.mcpEndpoints,
|
|
1189
|
+
props.guardrails_c
|
|
843
1190
|
]);
|
|
844
1191
|
const headers = (0, import_react10.useMemo)(() => {
|
|
845
1192
|
const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
|
|
@@ -853,7 +1200,7 @@ ${nonDocumentStrings}`;
|
|
|
853
1200
|
}
|
|
854
1201
|
return acc;
|
|
855
1202
|
}, {});
|
|
856
|
-
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [
|
|
1203
|
+
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared7.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
|
|
857
1204
|
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
858
1205
|
const runtimeClient = useCopilotRuntimeClient({
|
|
859
1206
|
url: copilotApiConfig.chatApiEndpoint,
|
|
@@ -884,13 +1231,17 @@ ${nonDocumentStrings}`;
|
|
|
884
1231
|
},
|
|
885
1232
|
[]
|
|
886
1233
|
);
|
|
1234
|
+
const hasLoadedAgents = (0, import_react10.useRef)(false);
|
|
887
1235
|
(0, import_react10.useEffect)(() => {
|
|
1236
|
+
if (hasLoadedAgents.current)
|
|
1237
|
+
return;
|
|
888
1238
|
const fetchData = () => __async(this, null, function* () {
|
|
889
1239
|
var _a2;
|
|
890
1240
|
const result = yield runtimeClient.availableAgents();
|
|
891
1241
|
if ((_a2 = result.data) == null ? void 0 : _a2.availableAgents) {
|
|
892
1242
|
setAvailableAgents(result.data.availableAgents.agents);
|
|
893
1243
|
}
|
|
1244
|
+
hasLoadedAgents.current = true;
|
|
894
1245
|
});
|
|
895
1246
|
void fetchData();
|
|
896
1247
|
}, []);
|
|
@@ -901,11 +1252,51 @@ ${nonDocumentStrings}`;
|
|
|
901
1252
|
};
|
|
902
1253
|
}
|
|
903
1254
|
const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
|
|
904
|
-
|
|
1255
|
+
(0, import_react10.useEffect)(() => {
|
|
1256
|
+
if (props.agent) {
|
|
1257
|
+
setAgentSession({
|
|
1258
|
+
agentName: props.agent
|
|
1259
|
+
});
|
|
1260
|
+
} else {
|
|
1261
|
+
setAgentSession(null);
|
|
1262
|
+
}
|
|
1263
|
+
}, [props.agent]);
|
|
1264
|
+
const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared7.randomUUID)());
|
|
1265
|
+
const setThreadId = (0, import_react10.useCallback)(
|
|
1266
|
+
(value) => {
|
|
1267
|
+
if (props.threadId) {
|
|
1268
|
+
throw new Error("Cannot call setThreadId() when threadId is provided via props.");
|
|
1269
|
+
}
|
|
1270
|
+
setInternalThreadId(value);
|
|
1271
|
+
},
|
|
1272
|
+
[props.threadId]
|
|
1273
|
+
);
|
|
1274
|
+
(0, import_react10.useEffect)(() => {
|
|
1275
|
+
if (props.threadId !== void 0) {
|
|
1276
|
+
setInternalThreadId(props.threadId);
|
|
1277
|
+
}
|
|
1278
|
+
}, [props.threadId]);
|
|
905
1279
|
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
906
1280
|
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
907
1281
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
908
|
-
|
|
1282
|
+
const [langGraphInterruptAction, _setLangGraphInterruptAction] = (0, import_react10.useState)(null);
|
|
1283
|
+
const setLangGraphInterruptAction = (0, import_react10.useCallback)((action) => {
|
|
1284
|
+
_setLangGraphInterruptAction((prev) => {
|
|
1285
|
+
if (prev == null)
|
|
1286
|
+
return action;
|
|
1287
|
+
if (action == null)
|
|
1288
|
+
return null;
|
|
1289
|
+
let event = prev.event;
|
|
1290
|
+
if (action.event) {
|
|
1291
|
+
event = __spreadValues(__spreadValues({}, prev.event), action.event);
|
|
1292
|
+
}
|
|
1293
|
+
return __spreadProps(__spreadValues(__spreadValues({}, prev), action), { event });
|
|
1294
|
+
});
|
|
1295
|
+
}, []);
|
|
1296
|
+
const removeLangGraphInterruptAction = (0, import_react10.useCallback)(() => {
|
|
1297
|
+
setLangGraphInterruptAction(null);
|
|
1298
|
+
}, []);
|
|
1299
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
909
1300
|
CopilotContext.Provider,
|
|
910
1301
|
{
|
|
911
1302
|
value: {
|
|
@@ -931,6 +1322,8 @@ ${nonDocumentStrings}`;
|
|
|
931
1322
|
removeChatSuggestionConfiguration,
|
|
932
1323
|
chatInstructions,
|
|
933
1324
|
setChatInstructions,
|
|
1325
|
+
additionalInstructions,
|
|
1326
|
+
setAdditionalInstructions,
|
|
934
1327
|
showDevConsole,
|
|
935
1328
|
coagentStates,
|
|
936
1329
|
setCoagentStates,
|
|
@@ -941,23 +1334,28 @@ ${nonDocumentStrings}`;
|
|
|
941
1334
|
runtimeClient,
|
|
942
1335
|
forwardedParameters: props.forwardedParameters || {},
|
|
943
1336
|
agentLock: props.agent || null,
|
|
944
|
-
threadId,
|
|
1337
|
+
threadId: internalThreadId,
|
|
945
1338
|
setThreadId,
|
|
946
1339
|
runId,
|
|
947
1340
|
setRunId,
|
|
948
1341
|
chatAbortControllerRef,
|
|
949
1342
|
availableAgents,
|
|
950
|
-
|
|
951
|
-
authStates,
|
|
952
|
-
setAuthStates
|
|
1343
|
+
authConfig_c: props.authConfig_c,
|
|
1344
|
+
authStates_c: authStates,
|
|
1345
|
+
setAuthStates_c: setAuthStates,
|
|
1346
|
+
extensions,
|
|
1347
|
+
setExtensions,
|
|
1348
|
+
langGraphInterruptAction,
|
|
1349
|
+
setLangGraphInterruptAction,
|
|
1350
|
+
removeLangGraphInterruptAction
|
|
953
1351
|
},
|
|
954
|
-
children: /* @__PURE__ */ (0,
|
|
1352
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children })
|
|
955
1353
|
}
|
|
956
1354
|
);
|
|
957
1355
|
}
|
|
958
1356
|
var defaultCopilotContextCategories = ["global"];
|
|
959
1357
|
function entryPointsToFunctionCallHandler(actions) {
|
|
960
|
-
return (_0) => __async(this, [_0], function* ({
|
|
1358
|
+
return (_0) => __async(this, [_0], function* ({ name, args }) {
|
|
961
1359
|
let actionsByFunctionName = {};
|
|
962
1360
|
for (let action2 of actions) {
|
|
963
1361
|
actionsByFunctionName[action2.name] = action2;
|
|
@@ -981,6 +1379,20 @@ function entryPointsToFunctionCallHandler(actions) {
|
|
|
981
1379
|
return result;
|
|
982
1380
|
});
|
|
983
1381
|
}
|
|
1382
|
+
function formatFeatureName(featureName) {
|
|
1383
|
+
return featureName.replace(/_c$/, "").split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
1384
|
+
}
|
|
1385
|
+
function validateProps(props) {
|
|
1386
|
+
const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
|
|
1387
|
+
if (!props.runtimeUrl && !props.publicApiKey) {
|
|
1388
|
+
throw new import_shared7.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey'");
|
|
1389
|
+
}
|
|
1390
|
+
if (cloudFeatures.length > 0 && !props.publicApiKey) {
|
|
1391
|
+
throw new import_shared7.MissingPublicApiKeyError(
|
|
1392
|
+
`Missing required prop: 'publicApiKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
984
1396
|
// Annotate the CommonJS export names for ESM import in node:
|
|
985
1397
|
0 && (module.exports = {
|
|
986
1398
|
CopilotKit,
|