@copilotkit/react-core 1.69.2 → 1.69.3

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 (33) hide show
  1. package/dist/{copilotkit-Ba7qwYt3.cjs → copilotkit-BPeh62mW.cjs} +73 -56
  2. package/dist/copilotkit-BPeh62mW.cjs.map +1 -0
  3. package/dist/{copilotkit-CF1Pm2VG.d.cts → copilotkit-CrNUgJiq.d.cts} +17 -15
  4. package/dist/{copilotkit-CF1Pm2VG.d.cts.map → copilotkit-CrNUgJiq.d.cts.map} +1 -1
  5. package/dist/{copilotkit-TdM-5onZ.d.mts → copilotkit-DgO31tBq.d.mts} +17 -15
  6. package/dist/{copilotkit-TdM-5onZ.d.mts.map → copilotkit-DgO31tBq.d.mts.map} +1 -1
  7. package/dist/{copilotkit-BmW2sFH6.mjs → copilotkit-JdHy0xdu.mjs} +74 -57
  8. package/dist/copilotkit-JdHy0xdu.mjs.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.d.cts +1 -1
  11. package/dist/index.d.mts +1 -1
  12. package/dist/index.mjs +1 -1
  13. package/dist/index.umd.js +73 -55
  14. package/dist/index.umd.js.map +1 -1
  15. package/dist/v2/headless.cjs +1 -1
  16. package/dist/v2/headless.cjs.map +1 -1
  17. package/dist/v2/headless.mjs +1 -1
  18. package/dist/v2/headless.mjs.map +1 -1
  19. package/dist/v2/index.cjs +1 -1
  20. package/dist/v2/index.d.cts +1 -1
  21. package/dist/v2/index.d.mts +1 -1
  22. package/dist/v2/index.mjs +1 -1
  23. package/dist/v2/index.umd.js +76 -58
  24. package/dist/v2/index.umd.js.map +1 -1
  25. package/package.json +7 -8
  26. package/skills/react-core/SKILL.md +5 -3
  27. package/skills/react-core/references/agent-access.md +68 -1
  28. package/skills/react-core/references/debug-mode.md +21 -34
  29. package/skills/react-core/references/switching-agents-recipes.md +1 -0
  30. package/skills/react-core/references/switching-agents.md +9 -0
  31. package/skills/react-core/references/threads.md +65 -0
  32. package/dist/copilotkit-Ba7qwYt3.cjs.map +0 -1
  33. package/dist/copilotkit-BmW2sFH6.mjs.map +0 -1
@@ -43,7 +43,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
43
43
  let streamdown = require("streamdown");
44
44
  let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
45
45
  let zod = require("zod");
46
- let _lit_labs_react = require("@lit-labs/react");
47
46
  let _copilotkit_a2ui_renderer = require("@copilotkit/a2ui-renderer");
48
47
  let zod_to_json_schema = require("zod-to-json-schema");
49
48
  let react_dom = require("react-dom");
@@ -107,7 +106,7 @@ const CopilotChatDefaultLabels = {
107
106
  assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
108
107
  assistantMessageToolbarCopyMessageLabel: "Copy",
109
108
  assistantMessageToolbarInspectorLabel: "View in Inspector",
110
- assistantMessageToolbarInspectorLocalOnlyLabel: "Local Only",
109
+ assistantMessageToolbarInspectorLocalOnlyLabel: "Development Only",
111
110
  assistantMessageToolbarThumbsUpLabel: "Good response",
112
111
  assistantMessageToolbarThumbsDownLabel: "Bad response",
113
112
  assistantMessageToolbarReadAloudLabel: "Read aloud",
@@ -1526,32 +1525,43 @@ function useRenderToolCall() {
1526
1525
 
1527
1526
  //#endregion
1528
1527
  //#region src/v2/components/CopilotKitInspector.tsx
1529
- const CopilotKitInspector = ({ core, openRequest, ...rest }) => {
1530
- const [InspectorComponent, setInspectorComponent] = react.useState(null);
1528
+ const CopilotKitInspector = ({ core, openRequest }) => {
1529
+ const mountRef = react.useRef(null);
1531
1530
  const inspectorRef = react.useRef(null);
1531
+ const latestCoreRef = react.useRef(core ?? null);
1532
+ const latestOpenRequestRef = react.useRef(openRequest);
1533
+ latestCoreRef.current = core ?? null;
1534
+ latestOpenRequestRef.current = openRequest;
1532
1535
  react.useEffect(() => {
1533
1536
  let mounted = true;
1537
+ let inspector = null;
1534
1538
  import("@copilotkit/web-inspector").then((mod) => {
1539
+ if (!mounted || !mountRef.current) return;
1535
1540
  mod.defineWebInspector?.();
1536
- const Component = (0, _lit_labs_react.createComponent)({
1537
- tagName: mod.WEB_INSPECTOR_TAG,
1538
- elementClass: mod.WebInspectorElement,
1539
- react
1540
- });
1541
- if (mounted) setInspectorComponent(() => Component);
1541
+ inspector = mountRef.current.ownerDocument.createElement(mod.WEB_INSPECTOR_TAG);
1542
+ mod.configureWebInspectorElement(inspector, latestCoreRef.current);
1543
+ mountRef.current.appendChild(inspector);
1544
+ inspectorRef.current = inspector;
1545
+ const request = latestOpenRequestRef.current;
1546
+ if (request) inspector.openInspector("message_toolbar", request);
1547
+ }).catch((error) => {
1548
+ console.error("Failed to load CopilotKit inspector:", error);
1542
1549
  });
1543
1550
  return () => {
1544
1551
  mounted = false;
1552
+ inspector?.remove();
1553
+ if (inspectorRef.current === inspector) inspectorRef.current = null;
1545
1554
  };
1546
1555
  }, []);
1556
+ react.useEffect(() => {
1557
+ if (inspectorRef.current) inspectorRef.current.core = core ?? null;
1558
+ }, [core]);
1547
1559
  react.useEffect(() => {
1548
1560
  if (openRequest) inspectorRef.current?.openInspector("message_toolbar", openRequest);
1549
- }, [InspectorComponent, openRequest]);
1550
- if (!InspectorComponent) return null;
1551
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InspectorComponent, {
1552
- ref: inspectorRef,
1553
- ...rest,
1554
- core: core ?? null
1561
+ }, [openRequest]);
1562
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1563
+ ref: mountRef,
1564
+ style: { display: "contents" }
1555
1565
  });
1556
1566
  };
1557
1567
  CopilotKitInspector.displayName = "CopilotKitInspector";
@@ -1559,7 +1569,7 @@ CopilotKitInspector.displayName = "CopilotKitInspector";
1559
1569
  //#endregion
1560
1570
  //#region src/v2/components/CopilotKitInspectorContext.tsx
1561
1571
  const CopilotKitInspectorContext = react.createContext({
1562
- isLocalInspectorEnabled: false,
1572
+ isInspectorEnabled: false,
1563
1573
  openInspector: () => void 0
1564
1574
  });
1565
1575
  const CopilotKitInspectorContextProvider = CopilotKitInspectorContext.Provider;
@@ -3509,9 +3519,15 @@ function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
3509
3519
  }, [value, warningMessage]);
3510
3520
  return value;
3511
3521
  }
3512
- const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, showDevConsole = false, useSingleEndpoint, onError, a2ui, defaultThrottleMs, inspectorDefaultAnchor, debug }) => {
3522
+ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug }) => {
3513
3523
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
3514
- const [isLocalInspectorEnabled, setIsLocalInspectorEnabled] = (0, react.useState)(false);
3524
+ (0, react.useEffect)(() => {
3525
+ setShouldRenderInspector((0, _copilotkit_shared.shouldEnableInspector)({
3526
+ enableInspector,
3527
+ isBrowser: true,
3528
+ isDevelopment: process.env.NODE_ENV === "development"
3529
+ }));
3530
+ }, [enableInspector]);
3515
3531
  const [inspectorOpenRequest, setInspectorOpenRequest] = (0, react.useState)(null);
3516
3532
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
3517
3533
  const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
@@ -3520,32 +3536,13 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3520
3536
  const a2uiCatalogProvided = !!a2ui?.catalog;
3521
3537
  const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
3522
3538
  const [runtimeLicenseStatus, setRuntimeLicenseStatus] = (0, react.useState)(void 0);
3523
- (0, react.useEffect)(() => {
3524
- if (typeof window === "undefined") return;
3525
- const isLocalhost = new Set(["localhost", "127.0.0.1"]).has(window.location?.hostname ?? "");
3526
- const canShowLocalInspectorAction = process.env.NODE_ENV === "development" && isLocalhost;
3527
- if (showDevConsole === true) {
3528
- setShouldRenderInspector(true);
3529
- setIsLocalInspectorEnabled(canShowLocalInspectorAction);
3530
- } else if (showDevConsole === "auto") if (isLocalhost) {
3531
- setShouldRenderInspector(true);
3532
- setIsLocalInspectorEnabled(canShowLocalInspectorAction);
3533
- } else {
3534
- setShouldRenderInspector(false);
3535
- setIsLocalInspectorEnabled(false);
3536
- }
3537
- else {
3538
- setShouldRenderInspector(false);
3539
- setIsLocalInspectorEnabled(false);
3540
- }
3541
- }, [showDevConsole]);
3542
3539
  const requestInspectorOpen = (0, react.useCallback)((request) => {
3543
3540
  setInspectorOpenRequest({ ...request });
3544
3541
  }, []);
3545
3542
  const inspectorContextValue = (0, react.useMemo)(() => ({
3546
- isLocalInspectorEnabled,
3543
+ isInspectorEnabled: shouldRenderInspector,
3547
3544
  openInspector: requestInspectorOpen
3548
- }), [isLocalInspectorEnabled, requestInspectorOpen]);
3545
+ }), [shouldRenderInspector, requestInspectorOpen]);
3549
3546
  const renderToolCallsList = useStableArrayProp(renderToolCalls, "renderToolCalls must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead.", (initial, next) => {
3550
3547
  const key = (rc) => `${rc?.agentId ?? ""}:${rc?.name ?? ""}`;
3551
3548
  const setFrom = (arr) => new Set(arr.map(key));
@@ -3886,7 +3883,6 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3886
3883
  value: inspectorContextValue,
3887
3884
  children: [children, shouldRenderInspector ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInspector, {
3888
3885
  core: copilotkit,
3889
- defaultAnchor: inspectorDefaultAnchor,
3890
3886
  openRequest: inspectorOpenRequest
3891
3887
  }) : null]
3892
3888
  }),
@@ -5940,7 +5936,7 @@ function CopilotChatToolCallsView({ message, messages = [] }) {
5940
5936
  //#region src/v2/components/chat/CopilotChatAssistantMessage.tsx
5941
5937
  function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, inspectorButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
5942
5938
  useKatexStyles();
5943
- const { isLocalInspectorEnabled, openInspector } = useCopilotKitInspector();
5939
+ const { isInspectorEnabled, openInspector } = useCopilotKitInspector();
5944
5940
  const chatConfiguration = useCopilotChatConfiguration();
5945
5941
  const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
5946
5942
  const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
@@ -5960,7 +5956,7 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
5960
5956
  className: "cpk:flex cpk:items-center cpk:gap-1",
5961
5957
  children: [
5962
5958
  boundCopyButton,
5963
- isLocalInspectorEnabled && boundInspectorButton,
5959
+ isInspectorEnabled && boundInspectorButton,
5964
5960
  (onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
5965
5961
  (onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
5966
5962
  (onReadAloud || readAloudButton) && boundReadAloudButton,
@@ -5974,7 +5970,7 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
5974
5970
  });
5975
5971
  const hasContent = !!(message.content && message.content.trim().length > 0);
5976
5972
  const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
5977
- const shouldShowToolbar = toolbarVisible && (hasContent || isLocalInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
5973
+ const shouldShowToolbar = toolbarVisible && (hasContent || isInspectorEnabled) && !(isRunning && isLatestAssistantMessage);
5978
5974
  if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5979
5975
  "data-copilotkit": true,
5980
5976
  style: { display: "contents" },
@@ -11545,20 +11541,42 @@ function CoAgentStateRenderBridge(props) {
11545
11541
 
11546
11542
  //#endregion
11547
11543
  //#region src/v1-deprecated/components/CopilotListeners.tsx
11548
- const usePredictStateSubscription = (agent) => {
11549
- const predictStateToolsRef = (0, react.useRef)([]);
11550
- const getSubscriber = (0, react.useCallback)((agent) => ({
11544
+ function isPredictStateTool(value) {
11545
+ if (value === null || typeof value !== "object") return false;
11546
+ const config = value;
11547
+ return typeof config.tool === "string" && typeof config.state_key === "string" && (config.tool_argument === void 0 || typeof config.tool_argument === "string");
11548
+ }
11549
+ function getPredictStateUpdate(config, toolCallName, partialToolCallArgs) {
11550
+ if (config.tool !== toolCallName) return void 0;
11551
+ const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.partialJSONParse)(partialToolCallArgs) : partialToolCallArgs;
11552
+ if (emittedState === null || typeof emittedState !== "object") return;
11553
+ if (config.tool_argument) {
11554
+ if (!(config.tool_argument in emittedState)) return void 0;
11555
+ return { [config.state_key]: emittedState[config.tool_argument] };
11556
+ }
11557
+ return { [config.state_key]: emittedState };
11558
+ }
11559
+ function createPredictStateSubscriber(agent, predictStateToolsRef) {
11560
+ return {
11551
11561
  onCustomEvent: ({ event }) => {
11552
- if (event.name === "PredictState") predictStateToolsRef.current = event.value;
11562
+ if (event.name === "PredictState") predictStateToolsRef.current = Array.isArray(event.value) ? event.value.filter(isPredictStateTool) : [];
11553
11563
  },
11554
11564
  onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
11555
- predictStateToolsRef.current.forEach((t) => {
11556
- if (t?.tool !== toolCallName) return;
11557
- const emittedState = typeof partialToolCallArgs === "string" ? (0, _copilotkit_shared.parseJson)(partialToolCallArgs, partialToolCallArgs) : partialToolCallArgs;
11558
- agent.setState({ [t.state_key]: emittedState[t.state_key] });
11565
+ const updates = {};
11566
+ predictStateToolsRef.current.forEach((config) => {
11567
+ const update = getPredictStateUpdate(config, toolCallName, partialToolCallArgs);
11568
+ if (update) Object.assign(updates, update);
11569
+ });
11570
+ if (Object.keys(updates).length > 0) agent.setState({
11571
+ ...agent.state,
11572
+ ...updates
11559
11573
  });
11560
11574
  }
11561
- }), []);
11575
+ };
11576
+ }
11577
+ const usePredictStateSubscription = (agent) => {
11578
+ const predictStateToolsRef = (0, react.useRef)([]);
11579
+ const getSubscriber = (0, react.useCallback)((subscriptionAgent) => createPredictStateSubscriber(subscriptionAgent, predictStateToolsRef), []);
11562
11580
  (0, react.useEffect)(() => {
11563
11581
  if (!agent) return;
11564
11582
  const subscriber = getSubscriber(agent);
@@ -11617,7 +11635,6 @@ function CopilotListeners() {
11617
11635
  //#region src/v1-deprecated/components/copilot-provider/copilotkit.tsx
11618
11636
  function CopilotKit({ children, ...props }) {
11619
11637
  const enabled = shouldShowDevConsole(props.showDevConsole);
11620
- const showInspector = shouldShowDevConsole(props.enableInspector);
11621
11638
  const publicApiKey = props.publicApiKey || props.publicLicenseKey;
11622
11639
  const renderArr = (0, react.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
11623
11640
  const { onError: _onError, ...v2Props } = props;
@@ -11630,7 +11647,7 @@ function CopilotKit({ children, ...props }) {
11630
11647
  threadId: props.threadId,
11631
11648
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitProvider, {
11632
11649
  ...v2Props,
11633
- showDevConsole: showInspector,
11650
+ enableInspector: props.enableInspector,
11634
11651
  renderCustomMessages: renderArr,
11635
11652
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotKitInternal, {
11636
11653
  ...props,
@@ -12622,4 +12639,4 @@ Object.defineProperty(exports, 'ɵrunMcpFollowUp', {
12622
12639
  return ɵrunMcpFollowUp;
12623
12640
  }
12624
12641
  });
12625
- //# sourceMappingURL=copilotkit-Ba7qwYt3.cjs.map
12642
+ //# sourceMappingURL=copilotkit-BPeh62mW.cjs.map