@copilotkit/react-core 1.5.18 → 1.5.19-next.1

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-MIUILUVX.mjs → chunk-2F6RYBYS.mjs} +2 -2
  3. package/dist/{chunk-5K2FUI34.mjs → chunk-534J55RX.mjs} +19 -13
  4. package/dist/chunk-534J55RX.mjs.map +1 -0
  5. package/dist/{chunk-24PU4QRT.mjs → chunk-6C6ZNKSS.mjs} +2 -2
  6. package/dist/{chunk-DB25UMNI.mjs → chunk-7YXUCWXF.mjs} +2 -2
  7. package/dist/{chunk-CUMF2APV.mjs → chunk-DFNQGERN.mjs} +2 -2
  8. package/dist/{chunk-WSOA4BGM.mjs → chunk-JFCNSGNU.mjs} +2 -2
  9. package/dist/{chunk-HJWT7WXD.mjs → chunk-MNYMDFWD.mjs} +9 -1
  10. package/dist/chunk-MNYMDFWD.mjs.map +1 -0
  11. package/dist/{chunk-2RDVL7EU.mjs → chunk-OBGDZ7BM.mjs} +3 -3
  12. package/dist/{chunk-2VIL3F36.mjs → chunk-PR5R5TTF.mjs} +25 -2
  13. package/dist/chunk-PR5R5TTF.mjs.map +1 -0
  14. package/dist/{chunk-CUSSPNG5.mjs → chunk-T2EFA3D5.mjs} +16 -2
  15. package/dist/chunk-T2EFA3D5.mjs.map +1 -0
  16. package/dist/components/copilot-provider/copilotkit.js +24 -18
  17. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  18. package/dist/components/copilot-provider/copilotkit.mjs +2 -2
  19. package/dist/components/copilot-provider/index.js +24 -18
  20. package/dist/components/copilot-provider/index.js.map +1 -1
  21. package/dist/components/copilot-provider/index.mjs +2 -2
  22. package/dist/components/error-boundary/error-boundary.d.ts +1 -1
  23. package/dist/components/error-boundary/error-boundary.js +18 -12
  24. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  25. package/dist/components/error-boundary/error-boundary.mjs +1 -1
  26. package/dist/components/index.js +24 -18
  27. package/dist/components/index.js.map +1 -1
  28. package/dist/components/index.mjs +2 -2
  29. package/dist/hooks/index.js +45 -1
  30. package/dist/hooks/index.js.map +1 -1
  31. package/dist/hooks/index.mjs +9 -9
  32. package/dist/hooks/use-chat.js +8 -0
  33. package/dist/hooks/use-chat.js.map +1 -1
  34. package/dist/hooks/use-chat.mjs +1 -1
  35. package/dist/hooks/use-coagent-state-render.js +24 -1
  36. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  37. package/dist/hooks/use-coagent-state-render.mjs +1 -1
  38. package/dist/hooks/use-coagent.js +8 -0
  39. package/dist/hooks/use-coagent.js.map +1 -1
  40. package/dist/hooks/use-coagent.mjs +5 -5
  41. package/dist/hooks/use-copilot-action.js +13 -0
  42. package/dist/hooks/use-copilot-action.js.map +1 -1
  43. package/dist/hooks/use-copilot-action.mjs +1 -1
  44. package/dist/hooks/use-copilot-authenticated-action.js +13 -0
  45. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  46. package/dist/hooks/use-copilot-authenticated-action.mjs +2 -2
  47. package/dist/hooks/use-copilot-chat.js +8 -0
  48. package/dist/hooks/use-copilot-chat.js.map +1 -1
  49. package/dist/hooks/use-copilot-chat.mjs +4 -4
  50. package/dist/hooks/use-langgraph-interrupt.js +8 -0
  51. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  52. package/dist/hooks/use-langgraph-interrupt.mjs +5 -5
  53. package/dist/index.js +82 -32
  54. package/dist/index.js.map +1 -1
  55. package/dist/index.mjs +10 -10
  56. package/dist/lib/copilot-task.mjs +3 -3
  57. package/dist/lib/index.mjs +3 -3
  58. package/dist/utils/extract.mjs +2 -2
  59. package/dist/utils/index.mjs +2 -2
  60. package/package.json +3 -3
  61. package/src/components/error-boundary/error-boundary.tsx +24 -13
  62. package/src/hooks/use-chat.ts +14 -0
  63. package/src/hooks/use-coagent-state-render.ts +37 -1
  64. package/src/hooks/use-copilot-action.ts +16 -0
  65. package/dist/chunk-2VIL3F36.mjs.map +0 -1
  66. package/dist/chunk-5K2FUI34.mjs.map +0 -1
  67. package/dist/chunk-CUSSPNG5.mjs.map +0 -1
  68. package/dist/chunk-HJWT7WXD.mjs.map +0 -1
  69. /package/dist/{chunk-MIUILUVX.mjs.map → chunk-2F6RYBYS.mjs.map} +0 -0
  70. /package/dist/{chunk-24PU4QRT.mjs.map → chunk-6C6ZNKSS.mjs.map} +0 -0
  71. /package/dist/{chunk-DB25UMNI.mjs.map → chunk-7YXUCWXF.mjs.map} +0 -0
  72. /package/dist/{chunk-CUMF2APV.mjs.map → chunk-DFNQGERN.mjs.map} +0 -0
  73. /package/dist/{chunk-WSOA4BGM.mjs.map → chunk-JFCNSGNU.mjs.map} +0 -0
  74. /package/dist/{chunk-2RDVL7EU.mjs.map → chunk-OBGDZ7BM.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -326,7 +326,7 @@ function setsHaveIntersection(setA, setB) {
326
326
 
327
327
  // src/components/copilot-provider/copilotkit.tsx
328
328
  var import_react_dom = require("react-dom");
329
- var import_shared7 = require("@copilotkit/shared");
329
+ var import_shared8 = require("@copilotkit/shared");
330
330
 
331
331
  // src/hooks/use-flat-category-store.ts
332
332
  var import_react3 = require("react");
@@ -1152,6 +1152,7 @@ function renderCopilotKitUsage(error) {
1152
1152
  }
1153
1153
 
1154
1154
  // src/components/error-boundary/error-boundary.tsx
1155
+ var import_shared7 = require("@copilotkit/shared");
1155
1156
  var import_jsx_runtime6 = require("react/jsx-runtime");
1156
1157
  var statusChecker = new StatusChecker();
1157
1158
  var CopilotErrorBoundary = class extends import_react9.default.Component {
@@ -1187,20 +1188,23 @@ var CopilotErrorBoundary = class extends import_react9.default.Component {
1187
1188
  var _a, _b;
1188
1189
  if (this.state.hasError) {
1189
1190
  if (this.state.error instanceof import_shared6.CopilotKitError) {
1190
- return renderCopilotKitUsage(this.state.error);
1191
+ if (import_shared7.COPILOT_CLOUD_ERROR_NAMES.includes(this.state.error.name)) {
1192
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: renderCopilotKitUsage(this.state.error) });
1193
+ }
1194
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1195
+ this.props.children,
1196
+ this.props.showUsageBanner && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1197
+ UsageBanner,
1198
+ {
1199
+ severity: (_a = this.state.status) == null ? void 0 : _a.severity,
1200
+ message: (_b = this.state.status) == null ? void 0 : _b.message
1201
+ }
1202
+ )
1203
+ ] });
1191
1204
  }
1192
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
1205
+ throw this.state.error;
1193
1206
  }
1194
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1195
- this.props.children,
1196
- this.props.showUsageBanner ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1197
- UsageBanner,
1198
- {
1199
- severity: (_a = this.state.status) == null ? void 0 : _a.severity,
1200
- message: (_b = this.state.status) == null ? void 0 : _b.message
1201
- }
1202
- ) : null
1203
- ] });
1207
+ return this.props.children;
1204
1208
  }
1205
1209
  };
1206
1210
  function ErrorToast2({ error, children }) {
@@ -1210,6 +1214,8 @@ function ErrorToast2({ error, children }) {
1210
1214
  addErrorToast([error]);
1211
1215
  }
1212
1216
  }, [error, addErrorToast]);
1217
+ if (!error)
1218
+ throw error;
1213
1219
  return children;
1214
1220
  }
1215
1221
 
@@ -1224,7 +1230,7 @@ function CopilotKit(_a) {
1224
1230
  function CopilotKitInternal(cpkProps) {
1225
1231
  const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
1226
1232
  validateProps(cpkProps);
1227
- const chatApiEndpoint = props.runtimeUrl || import_shared7.COPILOT_CLOUD_CHAT_URL;
1233
+ const chatApiEndpoint = props.runtimeUrl || import_shared8.COPILOT_CLOUD_CHAT_URL;
1228
1234
  const [actions, setActions] = (0, import_react10.useState)({});
1229
1235
  const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
1230
1236
  const chatComponentsCache = (0, import_react10.useRef)({
@@ -1366,7 +1372,7 @@ ${nonDocumentStrings}`;
1366
1372
  }
1367
1373
  return acc;
1368
1374
  }, {});
1369
- return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared7.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
1375
+ return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared8.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
1370
1376
  }, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
1371
1377
  const runtimeClient = useCopilotRuntimeClient({
1372
1378
  url: copilotApiConfig.chatApiEndpoint,
@@ -1418,7 +1424,7 @@ ${nonDocumentStrings}`;
1418
1424
  };
1419
1425
  }
1420
1426
  const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
1421
- const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared7.randomUUID)());
1427
+ const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared8.randomUUID)());
1422
1428
  const setThreadId = (0, import_react10.useCallback)(
1423
1429
  (value) => {
1424
1430
  if (props.threadId) {
@@ -1540,10 +1546,10 @@ function formatFeatureName(featureName) {
1540
1546
  function validateProps(props) {
1541
1547
  const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
1542
1548
  if (!props.runtimeUrl && !props.publicApiKey) {
1543
- throw new import_shared7.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey'");
1549
+ throw new import_shared8.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey'");
1544
1550
  }
1545
1551
  if (cloudFeatures.length > 0 && !props.publicApiKey) {
1546
- throw new import_shared7.MissingPublicApiKeyError(
1552
+ throw new import_shared8.MissingPublicApiKeyError(
1547
1553
  `Missing required prop: 'publicApiKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
1548
1554
  );
1549
1555
  }
@@ -1555,12 +1561,12 @@ var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
1555
1561
 
1556
1562
  // src/hooks/use-chat.ts
1557
1563
  var import_react11 = require("react");
1558
- var import_shared9 = require("@copilotkit/shared");
1564
+ var import_shared10 = require("@copilotkit/shared");
1559
1565
  var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
1560
1566
 
1561
1567
  // src/types/frontend-action.ts
1562
1568
  var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
1563
- var import_shared8 = require("@copilotkit/shared");
1569
+ var import_shared9 = require("@copilotkit/shared");
1564
1570
  function processActionsForRuntimeRequest(actions) {
1565
1571
  const filteredActions = actions.filter(
1566
1572
  (action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
@@ -1576,7 +1582,7 @@ function processActionsForRuntimeRequest(actions) {
1576
1582
  return {
1577
1583
  name: action.name,
1578
1584
  description: action.description || "",
1579
- jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters || [])),
1585
+ jsonSchema: JSON.stringify((0, import_shared9.actionParametersToJsonSchema)(action.parameters || [])),
1580
1586
  available
1581
1587
  };
1582
1588
  });
@@ -1621,7 +1627,7 @@ function useChat(options) {
1621
1627
  const extensionsRef = (0, import_react11.useRef)(extensions);
1622
1628
  extensionsRef.current = extensions;
1623
1629
  const publicApiKey = copilotConfig.publicApiKey;
1624
- const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared9.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1630
+ const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared10.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1625
1631
  const runtimeClient = useCopilotRuntimeClient({
1626
1632
  url: copilotConfig.chatApiEndpoint,
1627
1633
  publicApiKey: copilotConfig.publicApiKey,
@@ -1632,6 +1638,14 @@ function useChat(options) {
1632
1638
  (previousMessages) => __async(this, null, function* () {
1633
1639
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1634
1640
  setIsLoading(true);
1641
+ const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
1642
+ if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
1643
+ addErrorToast([
1644
+ new Error(
1645
+ "A message was sent while interrupt is active. This will cause failure on the agent side"
1646
+ )
1647
+ ]);
1648
+ }
1635
1649
  let newMessages = [
1636
1650
  new import_runtime_client_gql6.TextMessage({
1637
1651
  content: "",
@@ -1794,7 +1808,7 @@ function useChat(options) {
1794
1808
  } else {
1795
1809
  if (agentLock) {
1796
1810
  setAgentSession({
1797
- threadId: (0, import_shared9.randomId)(),
1811
+ threadId: (0, import_shared10.randomId)(),
1798
1812
  agentName: agentLock,
1799
1813
  nodeName: void 0
1800
1814
  });
@@ -2223,12 +2237,13 @@ ${additionalInstructions}` : "");
2223
2237
  }
2224
2238
 
2225
2239
  // src/hooks/use-copilot-action.ts
2226
- var import_shared10 = require("@copilotkit/shared");
2240
+ var import_shared11 = require("@copilotkit/shared");
2227
2241
  var import_react13 = require("react");
2228
2242
  function useCopilotAction(action, dependencies) {
2229
2243
  const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
2230
- const idRef = (0, import_react13.useRef)((0, import_shared10.randomId)());
2244
+ const idRef = (0, import_react13.useRef)((0, import_shared11.randomId)());
2231
2245
  const renderAndWaitRef = (0, import_react13.useRef)(null);
2246
+ const { addToast } = useToast();
2232
2247
  action = __spreadValues({}, action);
2233
2248
  if (
2234
2249
  // renderAndWaitForResponse is not available for catch all actions
@@ -2286,6 +2301,18 @@ function useCopilotAction(action, dependencies) {
2286
2301
  }
2287
2302
  }
2288
2303
  }
2304
+ (0, import_react13.useEffect)(() => {
2305
+ const hasDuplicate = Object.values(actions).some(
2306
+ (otherAction) => otherAction.name === action.name && otherAction !== actions[idRef.current]
2307
+ );
2308
+ if (hasDuplicate) {
2309
+ addToast({
2310
+ type: "warning",
2311
+ message: `Found an already registered action with name ${action.name}.`,
2312
+ id: `dup-action-${action.name}`
2313
+ });
2314
+ }
2315
+ }, [actions]);
2289
2316
  (0, import_react13.useEffect)(() => {
2290
2317
  setAction(idRef.current, action);
2291
2318
  if (chatComponentsCache.current !== null && action.render !== void 0) {
@@ -2316,7 +2343,7 @@ function isFrontendAction(action) {
2316
2343
 
2317
2344
  // src/hooks/use-coagent-state-render.ts
2318
2345
  var import_react14 = require("react");
2319
- var import_shared11 = require("@copilotkit/shared");
2346
+ var import_shared12 = require("@copilotkit/shared");
2320
2347
  function useCoAgentStateRender(action, dependencies) {
2321
2348
  const {
2322
2349
  setCoAgentStateRender,
@@ -2325,12 +2352,11 @@ function useCoAgentStateRender(action, dependencies) {
2325
2352
  chatComponentsCache,
2326
2353
  availableAgents
2327
2354
  } = (0, import_react14.useContext)(CopilotContext);
2328
- const idRef = (0, import_react14.useRef)((0, import_shared11.randomId)());
2355
+ const idRef = (0, import_react14.useRef)((0, import_shared12.randomId)());
2329
2356
  const { addToast } = useToast();
2330
2357
  (0, import_react14.useEffect)(() => {
2331
2358
  if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
2332
2359
  const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
2333
- console.warn(message);
2334
2360
  addToast({ type: "warning", message });
2335
2361
  }
2336
2362
  }, [availableAgents]);
@@ -2345,6 +2371,30 @@ function useCoAgentStateRender(action, dependencies) {
2345
2371
  }
2346
2372
  }
2347
2373
  }
2374
+ (0, import_react14.useEffect)(() => {
2375
+ const currentId = idRef.current;
2376
+ const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
2377
+ if (id === currentId)
2378
+ return false;
2379
+ if (otherAction.name !== action.name)
2380
+ return false;
2381
+ const hasNodeName = !!action.nodeName;
2382
+ const hasOtherNodeName = !!otherAction.nodeName;
2383
+ if (!hasNodeName && !hasOtherNodeName)
2384
+ return true;
2385
+ if (hasNodeName !== hasOtherNodeName)
2386
+ return false;
2387
+ return action.nodeName === otherAction.nodeName;
2388
+ });
2389
+ if (hasDuplicate) {
2390
+ const message = action.nodeName ? `Found multiple state renders for agent ${action.name} and node ${action.nodeName}. State renders might get overridden` : `Found multiple state renders for agent ${action.name}. State renders might get overridden`;
2391
+ addToast({
2392
+ type: "warning",
2393
+ message,
2394
+ id: `dup-action-${action.name}`
2395
+ });
2396
+ }
2397
+ }, [coAgentStateRenders]);
2348
2398
  (0, import_react14.useEffect)(() => {
2349
2399
  setCoAgentStateRender(idRef.current, action);
2350
2400
  if (chatComponentsCache.current !== null && action.render !== void 0) {
@@ -2606,13 +2656,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2606
2656
 
2607
2657
  // src/hooks/use-langgraph-interrupt.ts
2608
2658
  var import_react20 = require("react");
2609
- var import_shared12 = require("@copilotkit/shared");
2659
+ var import_shared13 = require("@copilotkit/shared");
2610
2660
  function useLangGraphInterrupt(action, dependencies) {
2611
2661
  var _a;
2612
2662
  const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react20.useContext)(CopilotContext);
2613
2663
  const { runChatCompletion } = useCopilotChat();
2614
2664
  const { addToast } = useToast();
2615
- const actionId = (0, import_shared12.dataToUUID)(JSON.stringify(action), "lgAction");
2665
+ const actionId = (0, import_shared13.dataToUUID)(JSON.stringify(action), "lgAction");
2616
2666
  const hasAction = (0, import_react20.useMemo)(
2617
2667
  () => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
2618
2668
  [langGraphInterruptAction]
@@ -2654,7 +2704,7 @@ function useLangGraphInterrupt(action, dependencies) {
2654
2704
 
2655
2705
  // src/hooks/use-langgraph-interrupt-render.ts
2656
2706
  var import_react21 = __toESM(require("react"));
2657
- var import_shared13 = require("@copilotkit/shared");
2707
+ var import_shared14 = require("@copilotkit/shared");
2658
2708
  var InterruptRenderer = ({ event, result, render, resolve }) => {
2659
2709
  return render({ event, result, resolve });
2660
2710
  };
@@ -2673,7 +2723,7 @@ function useLangGraphInterruptRender() {
2673
2723
  if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
2674
2724
  return null;
2675
2725
  const { render, handler, event, conditions } = langGraphInterruptAction;
2676
- const conditionsMet = (0, import_shared13.executeConditions)({ conditions, value: event.value });
2726
+ const conditionsMet = (0, import_shared14.executeConditions)({ conditions, value: event.value });
2677
2727
  if (!conditionsMet) {
2678
2728
  return null;
2679
2729
  }