@copilotkit/react-core 1.60.1 → 1.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/{copilotkit-CV519nFv.mjs → copilotkit-BCxdKlMw.mjs} +60 -153
  2. package/dist/copilotkit-BCxdKlMw.mjs.map +1 -0
  3. package/dist/{copilotkit-C9ptuh-b.d.cts → copilotkit-CEdu_aie.d.cts} +29 -7
  4. package/dist/{copilotkit-DvbI8G0d.d.mts.map → copilotkit-CEdu_aie.d.cts.map} +1 -1
  5. package/dist/{copilotkit-BTHcCAVQ.cjs → copilotkit-DtPCrXXd.cjs} +60 -153
  6. package/dist/copilotkit-DtPCrXXd.cjs.map +1 -0
  7. package/dist/{copilotkit-DvbI8G0d.d.mts → copilotkit-M1FiciGd.d.mts} +29 -7
  8. package/dist/{copilotkit-C9ptuh-b.d.cts.map → copilotkit-M1FiciGd.d.mts.map} +1 -1
  9. package/dist/index.cjs +6 -6
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +3 -3
  12. package/dist/index.d.mts +3 -3
  13. package/dist/index.mjs +6 -6
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/index.umd.js +61 -149
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/v2/context.cjs +8 -3
  18. package/dist/v2/context.cjs.map +1 -1
  19. package/dist/v2/context.d.cts.map +1 -1
  20. package/dist/v2/context.d.mts.map +1 -1
  21. package/dist/v2/context.mjs +8 -3
  22. package/dist/v2/context.mjs.map +1 -1
  23. package/dist/v2/headless.cjs +23 -12
  24. package/dist/v2/headless.cjs.map +1 -1
  25. package/dist/v2/headless.d.cts +25 -3
  26. package/dist/v2/headless.d.cts.map +1 -1
  27. package/dist/v2/headless.d.mts +25 -3
  28. package/dist/v2/headless.d.mts.map +1 -1
  29. package/dist/v2/headless.mjs +24 -13
  30. package/dist/v2/headless.mjs.map +1 -1
  31. package/dist/v2/index.cjs +1 -1
  32. package/dist/v2/index.css +1 -1
  33. package/dist/v2/index.d.cts +1 -1
  34. package/dist/v2/index.d.mts +1 -1
  35. package/dist/v2/index.mjs +1 -1
  36. package/dist/v2/index.umd.js +59 -152
  37. package/dist/v2/index.umd.js.map +1 -1
  38. package/package.json +6 -6
  39. package/dist/copilotkit-BTHcCAVQ.cjs.map +0 -1
  40. package/dist/copilotkit-CV519nFv.mjs.map +0 -1
@@ -1428,9 +1428,14 @@ const useCopilotKit = () => {
1428
1428
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
1429
1429
  if (!context) throw new Error("useCopilotKit must be used within CopilotKitProvider");
1430
1430
  (0, react.useEffect)(() => {
1431
- const subscription = context.copilotkit.subscribe({ onRuntimeConnectionStatusChanged: () => {
1432
- forceUpdate();
1433
- } });
1431
+ const subscription = context.copilotkit.subscribe({
1432
+ onRuntimeConnectionStatusChanged: () => {
1433
+ forceUpdate();
1434
+ },
1435
+ onHeadersChanged: () => {
1436
+ forceUpdate();
1437
+ }
1438
+ });
1434
1439
  return () => {
1435
1440
  subscription.unsubscribe();
1436
1441
  };
@@ -1637,9 +1642,8 @@ function DefaultToolCallRenderer({ name, toolCallId, parameters, status, result
1637
1642
  const isActive = status === "inProgress" || status === "executing";
1638
1643
  const isComplete = status === "complete";
1639
1644
  const statusLabel = isActive ? "Running" : isComplete ? "Done" : status;
1640
- const dotColor = isActive ? "#f59e0b" : isComplete ? "#10b981" : "#a1a1aa";
1641
- const badgeBg = isActive ? "#fef3c7" : isComplete ? "#d1fae5" : "#f4f4f5";
1642
- const badgeColor = isActive ? "#92400e" : isComplete ? "#065f46" : "#3f3f46";
1645
+ const dotClassName = isActive ? "cpk:bg-amber-500" : isComplete ? "cpk:bg-emerald-500" : "cpk:bg-zinc-400";
1646
+ const badgeClassName = isActive ? "cpk:bg-amber-100 cpk:text-amber-800 cpk:dark:bg-amber-500/15 cpk:dark:text-amber-400" : isComplete ? "cpk:bg-emerald-100 cpk:text-emerald-800 cpk:dark:bg-emerald-500/15 cpk:dark:text-emerald-400" : "cpk:bg-zinc-100 cpk:text-zinc-800 cpk:dark:bg-zinc-700/40 cpk:dark:text-zinc-300";
1643
1647
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1644
1648
  "data-testid": "copilot-tool-render",
1645
1649
  "data-tool-name": name,
@@ -1647,54 +1651,20 @@ function DefaultToolCallRenderer({ name, toolCallId, parameters, status, result
1647
1651
  "data-status": status,
1648
1652
  "data-args": safeStringifyForAttr(parameters),
1649
1653
  "data-result": safeStringifyForAttr(result),
1650
- style: {
1651
- marginTop: "8px",
1652
- paddingBottom: "8px"
1653
- },
1654
+ className: "cpk:mt-2 cpk:pb-2",
1654
1655
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1655
- style: {
1656
- borderRadius: "12px",
1657
- border: "1px solid #e4e4e7",
1658
- backgroundColor: "#fafafa",
1659
- padding: "14px 16px"
1660
- },
1656
+ className: "cpk:rounded-xl cpk:border cpk:border-zinc-200/60 cpk:bg-white/70 cpk:p-4 cpk:shadow-sm cpk:backdrop-blur cpk:dark:border-zinc-800/60 cpk:dark:bg-zinc-900/50",
1661
1657
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1662
1658
  type: "button",
1663
1659
  "aria-expanded": isExpanded,
1664
1660
  onClick: () => setIsExpanded(!isExpanded),
1665
- style: {
1666
- display: "flex",
1667
- alignItems: "center",
1668
- justifyContent: "space-between",
1669
- gap: "10px",
1670
- cursor: "pointer",
1671
- userSelect: "none",
1672
- width: "100%",
1673
- border: "none",
1674
- padding: 0,
1675
- margin: 0,
1676
- background: "transparent",
1677
- textAlign: "left",
1678
- font: "inherit",
1679
- color: "inherit"
1680
- },
1661
+ className: "cpk:flex cpk:w-full cpk:cursor-pointer cpk:select-none cpk:items-center cpk:justify-between cpk:gap-2.5 cpk:border-none cpk:bg-transparent cpk:p-0 cpk:m-0 cpk:text-left cpk:text-inherit",
1662
+ style: { font: "inherit" },
1681
1663
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1682
- style: {
1683
- display: "flex",
1684
- alignItems: "center",
1685
- gap: "8px",
1686
- minWidth: 0
1687
- },
1664
+ className: "cpk:flex cpk:min-w-0 cpk:items-center cpk:gap-2",
1688
1665
  children: [
1689
1666
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1690
- style: {
1691
- height: "14px",
1692
- width: "14px",
1693
- color: "#71717a",
1694
- transition: "transform 0.15s",
1695
- transform: isExpanded ? "rotate(90deg)" : "rotate(0deg)",
1696
- flexShrink: 0
1697
- },
1667
+ className: `cpk:h-3.5 cpk:w-3.5 cpk:flex-shrink-0 cpk:text-zinc-500 cpk:transition-transform cpk:dark:text-zinc-400 ${isExpanded ? "cpk:rotate-90" : ""}`,
1698
1668
  fill: "none",
1699
1669
  viewBox: "0 0 24 24",
1700
1670
  strokeWidth: 2,
@@ -1705,93 +1675,31 @@ function DefaultToolCallRenderer({ name, toolCallId, parameters, status, result
1705
1675
  d: "M8.25 4.5l7.5 7.5-7.5 7.5"
1706
1676
  })
1707
1677
  }),
1708
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: {
1709
- display: "inline-block",
1710
- height: "8px",
1711
- width: "8px",
1712
- borderRadius: "50%",
1713
- backgroundColor: dotColor,
1714
- flexShrink: 0
1715
- } }),
1678
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: `cpk:inline-block cpk:h-2 cpk:w-2 cpk:flex-shrink-0 cpk:rounded-full ${dotClassName}` }),
1716
1679
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1717
1680
  "data-testid": "copilot-tool-render-name",
1718
- style: {
1719
- fontSize: "13px",
1720
- fontWeight: 600,
1721
- color: "#18181b",
1722
- overflow: "hidden",
1723
- textOverflow: "ellipsis",
1724
- whiteSpace: "nowrap"
1725
- },
1681
+ className: "cpk:truncate cpk:text-[13px] cpk:font-semibold cpk:text-zinc-900 cpk:dark:text-zinc-100",
1726
1682
  children: name
1727
1683
  })
1728
1684
  ]
1729
1685
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1730
1686
  "data-testid": "copilot-tool-render-status",
1731
- style: {
1732
- display: "inline-flex",
1733
- alignItems: "center",
1734
- borderRadius: "9999px",
1735
- padding: "2px 8px",
1736
- fontSize: "11px",
1737
- fontWeight: 500,
1738
- backgroundColor: badgeBg,
1739
- color: badgeColor,
1740
- flexShrink: 0
1741
- },
1687
+ className: `cpk:inline-flex cpk:flex-shrink-0 cpk:items-center cpk:rounded-full cpk:px-2 cpk:py-0.5 cpk:text-[11px] cpk:font-medium ${badgeClassName}`,
1742
1688
  children: statusLabel
1743
1689
  })]
1744
1690
  }), isExpanded && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1745
- style: {
1746
- marginTop: "12px",
1747
- display: "grid",
1748
- gap: "12px"
1749
- },
1691
+ className: "cpk:mt-3 cpk:grid cpk:gap-3",
1750
1692
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1751
- style: {
1752
- fontSize: "10px",
1753
- textTransform: "uppercase",
1754
- letterSpacing: "0.05em",
1755
- color: "#71717a"
1756
- },
1693
+ className: "cpk:text-[10px] cpk:uppercase cpk:text-zinc-500 cpk:dark:text-zinc-400",
1757
1694
  children: "Arguments"
1758
1695
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
1759
- style: {
1760
- marginTop: "6px",
1761
- maxHeight: "200px",
1762
- overflow: "auto",
1763
- borderRadius: "6px",
1764
- backgroundColor: "#f4f4f5",
1765
- padding: "10px",
1766
- fontSize: "11px",
1767
- lineHeight: 1.6,
1768
- color: "#27272a",
1769
- whiteSpace: "pre-wrap",
1770
- wordBreak: "break-word"
1771
- },
1696
+ className: "cpk:mt-1.5 cpk:max-h-[200px] cpk:overflow-auto cpk:rounded-md cpk:bg-zinc-100 cpk:p-2.5 cpk:text-[11px] cpk:leading-relaxed cpk:text-zinc-800 cpk:whitespace-pre-wrap cpk:break-words cpk:dark:bg-zinc-800/60 cpk:dark:text-zinc-200",
1772
1697
  children: safeStringifyForPre(parameters ?? {})
1773
1698
  })] }), result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1774
- style: {
1775
- fontSize: "10px",
1776
- textTransform: "uppercase",
1777
- letterSpacing: "0.05em",
1778
- color: "#71717a"
1779
- },
1699
+ className: "cpk:text-[10px] cpk:uppercase cpk:text-zinc-500 cpk:dark:text-zinc-400",
1780
1700
  children: "Result"
1781
1701
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
1782
- style: {
1783
- marginTop: "6px",
1784
- maxHeight: "200px",
1785
- overflow: "auto",
1786
- borderRadius: "6px",
1787
- backgroundColor: "#f4f4f5",
1788
- padding: "10px",
1789
- fontSize: "11px",
1790
- lineHeight: 1.6,
1791
- color: "#27272a",
1792
- whiteSpace: "pre-wrap",
1793
- wordBreak: "break-word"
1794
- },
1702
+ className: "cpk:mt-1.5 cpk:max-h-[200px] cpk:overflow-auto cpk:rounded-md cpk:bg-zinc-100 cpk:p-2.5 cpk:text-[11px] cpk:leading-relaxed cpk:text-zinc-800 cpk:whitespace-pre-wrap cpk:break-words cpk:dark:bg-zinc-800/60 cpk:dark:text-zinc-200",
1795
1703
  children: typeof result === "string" ? result : safeStringifyForPre(result)
1796
1704
  })] })]
1797
1705
  })]
@@ -3734,6 +3642,10 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3734
3642
  ...selfManagedAgents
3735
3643
  }), [agents, selfManagedAgents]);
3736
3644
  const hasLocalAgents = mergedAgents && Object.keys(mergedAgents).length > 0;
3645
+ const hasSelfManagedAgents = Object.keys(selfManagedAgents).length > 0;
3646
+ (0, react.useEffect)(() => {
3647
+ if (hasSelfManagedAgents && !resolvedPublicKey) console.warn("[CopilotKit] `selfManagedAgents` is part of CopilotKit's Enterprise Intelligence offering. Provide a `publicLicenseKey` for production use — contact the CopilotKit team about licensing.");
3648
+ }, [hasSelfManagedAgents, resolvedPublicKey]);
3737
3649
  const headers = typeof headersProp === "function" ? headersProp() : headersProp;
3738
3650
  const mergedHeaders = (0, react.useMemo)(() => {
3739
3651
  if (!resolvedPublicKey) return headers;
@@ -4211,36 +4123,40 @@ function useHumanInTheLoop(tool, deps) {
4211
4123
  }, []);
4212
4124
  const RenderComponent = (0, react.useCallback)((props) => {
4213
4125
  const ToolComponent = tool.render;
4214
- if (props.status === "inProgress") {
4126
+ if (props.status === _copilotkit_core.ToolCallStatus.InProgress) {
4215
4127
  const enhancedProps = {
4216
4128
  ...props,
4217
4129
  name: tool.name,
4218
4130
  description: tool.description || "",
4131
+ agentId: tool.agentId,
4219
4132
  respond: void 0
4220
4133
  };
4221
4134
  return react.default.createElement(ToolComponent, enhancedProps);
4222
- } else if (props.status === "executing") {
4135
+ } else if (props.status === _copilotkit_core.ToolCallStatus.Executing) {
4223
4136
  const enhancedProps = {
4224
4137
  ...props,
4225
4138
  name: tool.name,
4226
4139
  description: tool.description || "",
4140
+ agentId: tool.agentId,
4227
4141
  respond
4228
4142
  };
4229
4143
  return react.default.createElement(ToolComponent, enhancedProps);
4230
- } else if (props.status === "complete") {
4144
+ } else if (props.status === _copilotkit_core.ToolCallStatus.Complete) {
4231
4145
  const enhancedProps = {
4232
4146
  ...props,
4233
4147
  name: tool.name,
4234
4148
  description: tool.description || "",
4149
+ agentId: tool.agentId,
4235
4150
  respond: void 0
4236
4151
  };
4237
4152
  return react.default.createElement(ToolComponent, enhancedProps);
4238
4153
  }
4239
- return react.default.createElement(ToolComponent, props);
4154
+ return props;
4240
4155
  }, [
4241
4156
  tool.render,
4242
4157
  tool.name,
4243
4158
  tool.description,
4159
+ tool.agentId,
4244
4160
  respond
4245
4161
  ]);
4246
4162
  useFrontendTool({
@@ -4731,18 +4647,25 @@ function useInterrupt(config) {
4731
4647
  },
4732
4648
  onRunFailed: () => {
4733
4649
  localInterrupt = null;
4650
+ setPendingEvent(null);
4734
4651
  }
4735
4652
  });
4736
4653
  return () => subscription.unsubscribe();
4737
4654
  }, [agent]);
4738
- const resolve = (0, react.useCallback)((response) => {
4739
- copilotkit.runAgent({
4740
- agent,
4741
- forwardedProps: { command: {
4742
- resume: response,
4743
- interruptEvent: pendingEventRef.current?.value
4744
- } }
4745
- });
4655
+ const resolve = (0, react.useCallback)(async (response) => {
4656
+ try {
4657
+ return await copilotkit.runAgent({
4658
+ agent,
4659
+ forwardedProps: { command: {
4660
+ resume: response,
4661
+ interruptEvent: pendingEventRef.current?.value
4662
+ } }
4663
+ });
4664
+ } catch (err) {
4665
+ console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
4666
+ setPendingEvent(null);
4667
+ throw err;
4668
+ }
4746
4669
  }, [agent, copilotkit]);
4747
4670
  const renderRef = (0, react.useRef)(config.render);
4748
4671
  renderRef.current = config.render;
@@ -7111,7 +7034,6 @@ const LastUserMessageContext = react.default.createContext({
7111
7034
  function usePinToSend({ scrollRef, contentRef, spacerRef, topOffset = 16 }) {
7112
7035
  const { id, sendNonce } = (0, react.useContext)(LastUserMessageContext);
7113
7036
  const lastNonceRef = (0, react.useRef)(-1);
7114
- const currentSpacerHeightRef = (0, react.useRef)(0);
7115
7037
  (0, react.useEffect)(() => {
7116
7038
  if (sendNonce === lastNonceRef.current) return;
7117
7039
  lastNonceRef.current = sendNonce;
@@ -7129,7 +7051,6 @@ function usePinToSend({ scrollRef, contentRef, spacerRef, topOffset = 16 }) {
7129
7051
  const bubbleHeight = Math.max(0, userMessageHeight - paddingTop);
7130
7052
  const spacerHeight = Math.max(0, viewportHeight - bubbleHeight - topOffset);
7131
7053
  spacerEl.style.height = `${spacerHeight}px`;
7132
- currentSpacerHeightRef.current = spacerHeight;
7133
7054
  const raf = requestAnimationFrame(() => {
7134
7055
  const targetTop = computeOffsetTop(targetEl, scrollEl) + paddingTop - topOffset;
7135
7056
  scrollEl.scrollTo({
@@ -7141,10 +7062,7 @@ function usePinToSend({ scrollRef, contentRef, spacerRef, topOffset = 16 }) {
7141
7062
  if (!contentEl || !spacerEl || !scrollEl) return;
7142
7063
  const consumedBelow = contentEl.getBoundingClientRect().height - computeOffsetTop(targetEl, contentEl) - userMessageHeight;
7143
7064
  const remaining = Math.max(0, spacerHeight - consumedBelow);
7144
- if (remaining < currentSpacerHeightRef.current) {
7145
- spacerEl.style.height = `${remaining}px`;
7146
- currentSpacerHeightRef.current = remaining;
7147
- }
7065
+ spacerEl.style.height = `${remaining}px`;
7148
7066
  });
7149
7067
  ro.observe(contentEl);
7150
7068
  return () => {
@@ -7438,7 +7356,7 @@ function CopilotChatView({ messageView, input, scrollView, suggestionView, welco
7438
7356
  }, []);
7439
7357
  (0, react.useEffect)(() => {
7440
7358
  if (mode === "pin-to-bottom") return;
7441
- const scrollElement = scrollRef.current;
7359
+ const scrollElement = nonAutoScrollEl;
7442
7360
  if (!scrollElement) return;
7443
7361
  const checkScroll = () => {
7444
7362
  setShowScrollButton(!(scrollElement.scrollHeight - scrollElement.scrollTop - scrollElement.clientHeight < 10));
@@ -7451,7 +7369,7 @@ function CopilotChatView({ messageView, input, scrollView, suggestionView, welco
7451
7369
  scrollElement.removeEventListener("scroll", checkScroll);
7452
7370
  resizeObserver.disconnect();
7453
7371
  };
7454
- }, [scrollRef, mode]);
7372
+ }, [nonAutoScrollEl, mode]);
7455
7373
  if (!hasMounted) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
7456
7374
  className: "cpk:h-full cpk:max-h-full cpk:flex cpk:flex-col cpk:min-h-0 cpk:overflow-y-auto cpk:overflow-x-hidden",
7457
7375
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -10200,21 +10118,6 @@ function CopilotListeners() {
10200
10118
 
10201
10119
  //#endregion
10202
10120
  //#region src/components/copilot-provider/copilotkit.tsx
10203
- /**
10204
- * This component will typically wrap your entire application (or a sub-tree of your application where you want to have a copilot). It provides the copilot context to all other components and hooks.
10205
- *
10206
- * ## Example
10207
- *
10208
- * You can find more information about self-hosting CopilotKit [here](/guides/self-hosting).
10209
- *
10210
- * ```tsx
10211
- * import { CopilotKit } from "@copilotkit/react-core";
10212
- *
10213
- * <CopilotKit runtimeUrl="<your-runtime-url>">
10214
- * // ... your app ...
10215
- * </CopilotKit>
10216
- * ```
10217
- */
10218
10121
  function CopilotKit({ children, ...props }) {
10219
10122
  const enabled = shouldShowDevConsole(props.showDevConsole);
10220
10123
  const showInspector = shouldShowDevConsole(props.enableInspector);
@@ -10703,7 +10606,11 @@ function formatFeatureName(featureName) {
10703
10606
  function validateProps(props) {
10704
10607
  const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
10705
10608
  const hasApiKey = props.publicApiKey || props.publicLicenseKey;
10706
- if (!props.runtimeUrl && !hasApiKey) throw new _copilotkit_shared.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'");
10609
+ const hasLocalAgents = Object.keys({
10610
+ ...props.agents__unsafe_dev_only,
10611
+ ...props.selfManagedAgents
10612
+ }).length > 0;
10613
+ if (!props.runtimeUrl && !hasApiKey && !hasLocalAgents) throw new _copilotkit_shared.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'");
10707
10614
  if (cloudFeatures.length > 0 && !hasApiKey) throw new _copilotkit_shared.MissingPublicApiKeyError(`Missing required prop: 'publicApiKey' or 'publicLicenseKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`);
10708
10615
  }
10709
10616
 
@@ -11176,4 +11083,4 @@ Object.defineProperty(exports, 'useToast', {
11176
11083
  return useToast;
11177
11084
  }
11178
11085
  });
11179
- //# sourceMappingURL=copilotkit-BTHcCAVQ.cjs.map
11086
+ //# sourceMappingURL=copilotkit-DtPCrXXd.cjs.map