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