@copilotkit/react-core 1.55.3 → 1.56.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 (53) hide show
  1. package/dist/{copilotkit-dwDWYpya.d.cts → copilotkit-BtP7w7cT.d.cts} +56 -10
  2. package/dist/copilotkit-BtP7w7cT.d.cts.map +1 -0
  3. package/dist/{copilotkit-BuhSUZHb.d.mts → copilotkit-CCbxm6JM.d.mts} +56 -10
  4. package/dist/copilotkit-CCbxm6JM.d.mts.map +1 -0
  5. package/dist/{copilotkit-Dgdpbqjt.cjs → copilotkit-CSJw5BG8.cjs} +129 -58
  6. package/dist/copilotkit-CSJw5BG8.cjs.map +1 -0
  7. package/dist/{copilotkit-Cd-NrDyp.mjs → copilotkit-Cj2ZIxVr.mjs} +125 -60
  8. package/dist/copilotkit-Cj2ZIxVr.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 +55 -23
  14. package/dist/index.umd.js.map +1 -1
  15. package/dist/v2/index.cjs +2 -1
  16. package/dist/v2/index.d.cts +2 -2
  17. package/dist/v2/index.d.mts +2 -2
  18. package/dist/v2/index.mjs +2 -2
  19. package/dist/v2/index.umd.js +124 -59
  20. package/dist/v2/index.umd.js.map +1 -1
  21. package/package.json +6 -6
  22. package/src/components/CopilotListeners.tsx +15 -4
  23. package/src/components/__tests__/CopilotListeners.test.tsx +38 -0
  24. package/src/components/copilot-provider/__tests__/error-visibility-prod.test.tsx +70 -0
  25. package/src/components/copilot-provider/copilot-messages.tsx +39 -24
  26. package/src/components/copilot-provider/copilotkit-props.tsx +26 -6
  27. package/src/components/copilot-provider/copilotkit.tsx +4 -1
  28. package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +22 -19
  29. package/src/v2/components/chat/CopilotChatInput.tsx +21 -2
  30. package/src/v2/components/chat/CopilotChatReasoningMessage.tsx +17 -4
  31. package/src/v2/components/chat/CopilotChatUserMessage.tsx +13 -10
  32. package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.tsx +131 -5
  33. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.test.tsx +1 -1
  34. package/src/v2/components/chat/__tests__/CopilotChatAssistantMessage.thumbs.test.tsx +72 -0
  35. package/src/v2/components/chat/__tests__/CopilotChatCopyButton.clipboard.test.tsx +241 -0
  36. package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +38 -0
  37. package/src/v2/components/ui/button.tsx +12 -11
  38. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +10 -10
  39. package/src/v2/hooks/__tests__/use-capabilities.test.tsx +76 -0
  40. package/src/v2/hooks/__tests__/use-render-custom-messages.test.tsx +55 -0
  41. package/src/v2/hooks/index.ts +1 -0
  42. package/src/v2/hooks/use-agent.tsx +23 -4
  43. package/src/v2/hooks/use-capabilities.tsx +25 -0
  44. package/src/v2/hooks/use-render-custom-messages.tsx +1 -1
  45. package/src/v2/hooks/use-render-tool-call.tsx +3 -0
  46. package/src/v2/hooks/use-render-tool.tsx +3 -0
  47. package/src/v2/providers/CopilotKitProvider.tsx +15 -2
  48. package/src/v2/types/defineToolCallRenderer.ts +3 -0
  49. package/src/v2/types/react-tool-call-renderer.ts +3 -0
  50. package/dist/copilotkit-BuhSUZHb.d.mts.map +0 -1
  51. package/dist/copilotkit-Cd-NrDyp.mjs.map +0 -1
  52. package/dist/copilotkit-Dgdpbqjt.cjs.map +0 -1
  53. package/dist/copilotkit-dwDWYpya.d.cts.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_copilotkit = require('./copilotkit-Dgdpbqjt.cjs');
4
+ const require_copilotkit = require('./copilotkit-CSJw5BG8.cjs');
5
5
  let react = require("react");
6
6
  react = require_copilotkit.__toESM(react);
7
7
  let _copilotkit_core = require("@copilotkit/core");
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { $t as CoagentInChatRenderFunction, An as FrontendActionAvailability, Cn as ActionRenderProps, Dn as CatchAllActionRenderProps, En as ActionRenderPropsWait, M as useAgent, On as CatchAllFrontendAction, Sn as TreeNode, Tn as ActionRenderPropsNoArgsWait, Z as useRenderToolCall$1, _n as CrewsToolStateItem, an as LangGraphInterruptAction, bn as DocumentPointer, cn as LangGraphInterruptRender, dn as QueuedInterruptEvent, en as CopilotApiConfig, fn as CrewsAgentState, gn as CrewsTaskStateItem, hn as CrewsStateItem, in as CoAgentStateRender, jn as RenderFunctionStatus, kn as FrontendAction, ln as LangGraphInterruptRenderHandlerProps, mn as CrewsResponseStatus, n as defaultCopilotContextCategories, nn as CopilotContextParams, on as LangGraphInterruptActionSetter, pn as CrewsResponse, r as CopilotKitProps, rn as useCopilotContext, sn as LangGraphInterruptActionSetterArgs, t as CopilotKit, tn as CopilotContext, un as LangGraphInterruptRenderProps, vn as CopilotChatSuggestionConfiguration, wn as ActionRenderPropsNoArgs, xn as Tree, yn as SystemMessageFunction } from "./copilotkit-dwDWYpya.cjs";
1
+ import { An as FrontendAction, Cn as TreeNode, Dn as ActionRenderPropsWait, En as ActionRenderPropsNoArgsWait, Mn as RenderFunctionStatus, N as useAgent, On as CatchAllActionRenderProps, Q as useRenderToolCall$1, Sn as Tree, Tn as ActionRenderPropsNoArgs, _n as CrewsTaskStateItem, an as CoAgentStateRender, bn as SystemMessageFunction, cn as LangGraphInterruptActionSetterArgs, dn as LangGraphInterruptRenderProps, en as CoagentInChatRenderFunction, fn as QueuedInterruptEvent, gn as CrewsStateItem, hn as CrewsResponseStatus, in as useCopilotContext, jn as FrontendActionAvailability, kn as CatchAllFrontendAction, ln as LangGraphInterruptRender, mn as CrewsResponse, n as defaultCopilotContextCategories, nn as CopilotContext, on as LangGraphInterruptAction, pn as CrewsAgentState, r as CopilotKitProps, rn as CopilotContextParams, sn as LangGraphInterruptActionSetter, t as CopilotKit, tn as CopilotApiConfig, un as LangGraphInterruptRenderHandlerProps, vn as CrewsToolStateItem, wn as ActionRenderProps, xn as DocumentPointer, yn as CopilotChatSuggestionConfiguration } from "./copilotkit-BtP7w7cT.cjs";
2
2
  import "./v2/index.cjs";
3
3
  import * as react_jsx_runtime0 from "react/jsx-runtime";
4
4
  import { CopilotRuntimeClient, CopilotRuntimeClientOptions, ForwardedParametersInput, Message } from "@copilotkit/runtime-client-gql";
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $t as CoagentInChatRenderFunction, An as FrontendActionAvailability, Cn as ActionRenderProps, Dn as CatchAllActionRenderProps, En as ActionRenderPropsWait, M as useAgent, On as CatchAllFrontendAction, Sn as TreeNode, Tn as ActionRenderPropsNoArgsWait, Z as useRenderToolCall$1, _n as CrewsToolStateItem, an as LangGraphInterruptAction, bn as DocumentPointer, cn as LangGraphInterruptRender, dn as QueuedInterruptEvent, en as CopilotApiConfig, fn as CrewsAgentState, gn as CrewsTaskStateItem, hn as CrewsStateItem, in as CoAgentStateRender, jn as RenderFunctionStatus, kn as FrontendAction, ln as LangGraphInterruptRenderHandlerProps, mn as CrewsResponseStatus, n as defaultCopilotContextCategories, nn as CopilotContextParams, on as LangGraphInterruptActionSetter, pn as CrewsResponse, r as CopilotKitProps, rn as useCopilotContext, sn as LangGraphInterruptActionSetterArgs, t as CopilotKit, tn as CopilotContext, un as LangGraphInterruptRenderProps, vn as CopilotChatSuggestionConfiguration, wn as ActionRenderPropsNoArgs, xn as Tree, yn as SystemMessageFunction } from "./copilotkit-BuhSUZHb.mjs";
1
+ import { An as FrontendAction, Cn as TreeNode, Dn as ActionRenderPropsWait, En as ActionRenderPropsNoArgsWait, Mn as RenderFunctionStatus, N as useAgent, On as CatchAllActionRenderProps, Q as useRenderToolCall$1, Sn as Tree, Tn as ActionRenderPropsNoArgs, _n as CrewsTaskStateItem, an as CoAgentStateRender, bn as SystemMessageFunction, cn as LangGraphInterruptActionSetterArgs, dn as LangGraphInterruptRenderProps, en as CoagentInChatRenderFunction, fn as QueuedInterruptEvent, gn as CrewsStateItem, hn as CrewsResponseStatus, in as useCopilotContext, jn as FrontendActionAvailability, kn as CatchAllFrontendAction, ln as LangGraphInterruptRender, mn as CrewsResponse, n as defaultCopilotContextCategories, nn as CopilotContext, on as LangGraphInterruptAction, pn as CrewsAgentState, r as CopilotKitProps, rn as CopilotContextParams, sn as LangGraphInterruptActionSetter, t as CopilotKit, tn as CopilotApiConfig, un as LangGraphInterruptRenderHandlerProps, vn as CrewsToolStateItem, wn as ActionRenderProps, xn as DocumentPointer, yn as CopilotChatSuggestionConfiguration } from "./copilotkit-CCbxm6JM.mjs";
2
2
  import "./v2/index.mjs";
3
3
  import React, { ReactNode, RefObject, SetStateAction } from "react";
4
4
  import { StaticSuggestionsConfig, Suggestion } from "@copilotkit/core";
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { $ as useCopilotKit, B as useConfigureSuggestions, H as useHumanInTheLoop$1, J as useRenderCustomMessages, K as useFrontendTool$1, V as useSuggestions, X as useAgent, Z as useRenderToolCall$1, a as ThreadsProvider, c as CoAgentStateRendersProvider, d as shouldShowDevConsole, f as useToast, g as useCopilotContext, h as CopilotContext, i as ThreadsContext, l as useCoAgentStateRenders, m as useCopilotMessagesContext, mt as useCopilotChatConfiguration, n as defaultCopilotContextCategories, nt as defineToolCallRenderer, o as useThreads, p as CopilotMessagesContext, r as CoAgentStateRenderBridge, s as CoAgentStateRendersContext, t as CopilotKit, u as useAsyncCallback, z as useInterrupt } from "./copilotkit-Cd-NrDyp.mjs";
3
+ import { B as useConfigureSuggestions, Q as useRenderToolCall$1, U as useHumanInTheLoop$1, V as useSuggestions, Y as useRenderCustomMessages, Z as useAgent, a as ThreadsProvider, c as CoAgentStateRendersProvider, d as shouldShowDevConsole, et as useCopilotKit, f as useToast, g as useCopilotContext, h as CopilotContext, ht as useCopilotChatConfiguration, i as ThreadsContext, l as useCoAgentStateRenders, m as useCopilotMessagesContext, n as defaultCopilotContextCategories, o as useThreads, p as CopilotMessagesContext, q as useFrontendTool$1, r as CoAgentStateRenderBridge, rt as defineToolCallRenderer, s as CoAgentStateRendersContext, t as CopilotKit, u as useAsyncCallback, z as useInterrupt } from "./copilotkit-Cj2ZIxVr.mjs";
4
4
  import React, { Fragment, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
5
5
  import { CopilotKitCoreRuntimeConnectionStatus, ToolCallStatus } from "@copilotkit/core";
6
6
  import { AGUIConnectNotImplementedError, HttpAgent } from "@ag-ui/client";
package/dist/index.umd.js CHANGED
@@ -1954,7 +1954,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
1954
1954
  }, [value, warningMessage]);
1955
1955
  return value;
1956
1956
  }
1957
- const CopilotKitProvider = ({ children, runtimeUrl, headers = {}, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = {}, agents__unsafe_dev_only: agents = {}, selfManagedAgents = {}, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, showDevConsole = false, useSingleEndpoint, onError, a2ui, defaultThrottleMs, inspectorDefaultAnchor }) => {
1957
+ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = {}, credentials, publicApiKey, publicLicenseKey, licenseToken, properties = {}, agents__unsafe_dev_only: agents = {}, selfManagedAgents = {}, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, showDevConsole = false, useSingleEndpoint, onError, a2ui, defaultThrottleMs, inspectorDefaultAnchor, debug }) => {
1958
1958
  var _openGenerativeUI$des;
1959
1959
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
1960
1960
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
@@ -2016,6 +2016,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2016
2016
  ...selfManagedAgents
2017
2017
  }), [agents, selfManagedAgents]);
2018
2018
  const hasLocalAgents = mergedAgents && Object.keys(mergedAgents).length > 0;
2019
+ const headers = typeof headersProp === "function" ? headersProp() : headersProp;
2019
2020
  const mergedHeaders = (0, react.useMemo)(() => {
2020
2021
  if (!resolvedPublicKey) return headers;
2021
2022
  if (headers[HEADER_NAME]) return headers;
@@ -2117,7 +2118,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2117
2118
  tools: allTools,
2118
2119
  renderToolCalls: allRenderToolCalls,
2119
2120
  renderActivityMessages: allActivityRenderers,
2120
- renderCustomMessages: renderCustomMessagesList
2121
+ renderCustomMessages: renderCustomMessagesList,
2122
+ debug
2121
2123
  });
2122
2124
  if (defaultThrottleMs !== void 0) copilotkitRef.current.setDefaultThrottleMs(defaultThrottleMs);
2123
2125
  }
@@ -2191,6 +2193,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2191
2193
  copilotkit.setCredentials(credentials);
2192
2194
  copilotkit.setProperties(properties);
2193
2195
  copilotkit.setAgents__unsafe_dev_only(mergedAgents);
2196
+ copilotkit.setDebug(debug);
2194
2197
  }, [
2195
2198
  copilotkit,
2196
2199
  chatApiEndpoint,
@@ -2198,7 +2201,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2198
2201
  credentials,
2199
2202
  properties,
2200
2203
  mergedAgents,
2201
- useSingleEndpoint
2204
+ useSingleEndpoint,
2205
+ debug
2202
2206
  ]);
2203
2207
  const didMountRef = (0, react.useRef)(false);
2204
2208
  (0, react.useEffect)(() => {
@@ -2319,18 +2323,21 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2319
2323
  const toolName = toolCall.function.name;
2320
2324
  if (toolMessage) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
2321
2325
  name: toolName,
2326
+ toolCallId: toolCall.id,
2322
2327
  args,
2323
2328
  status: _copilotkit_core.ToolCallStatus.Complete,
2324
2329
  result: toolMessage.content
2325
2330
  });
2326
2331
  else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
2327
2332
  name: toolName,
2333
+ toolCallId: toolCall.id,
2328
2334
  args,
2329
2335
  status: _copilotkit_core.ToolCallStatus.Executing,
2330
2336
  result: void 0
2331
2337
  });
2332
2338
  else return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
2333
2339
  name: toolName,
2340
+ toolCallId: toolCall.id,
2334
2341
  args,
2335
2342
  status: _copilotkit_core.ToolCallStatus.InProgress,
2336
2343
  result: void 0
@@ -2516,6 +2523,17 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2516
2523
  const handlers = {};
2517
2524
  let timerId = null;
2518
2525
  let active = true;
2526
+ let batchScheduled = false;
2527
+ const batchedForceUpdate = () => {
2528
+ if (!active) return;
2529
+ if (!batchScheduled) {
2530
+ batchScheduled = true;
2531
+ queueMicrotask(() => {
2532
+ batchScheduled = false;
2533
+ if (active) forceUpdate();
2534
+ });
2535
+ }
2536
+ };
2519
2537
  if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) {
2520
2538
  const ms = effectiveThrottleMs;
2521
2539
  if (ms > 0) {
@@ -2540,11 +2558,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2540
2558
  handlers.onMessagesChanged = throttledNotify;
2541
2559
  } else handlers.onMessagesChanged = forceUpdate;
2542
2560
  }
2543
- if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = forceUpdate;
2561
+ if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
2544
2562
  if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
2545
- handlers.onRunInitialized = forceUpdate;
2546
- handlers.onRunFinalized = forceUpdate;
2547
- handlers.onRunFailed = forceUpdate;
2563
+ handlers.onRunInitialized = batchedForceUpdate;
2564
+ handlers.onRunFinalized = batchedForceUpdate;
2565
+ handlers.onRunFailed = batchedForceUpdate;
2548
2566
  }
2549
2567
  const subscription = agent.subscribe(handlers);
2550
2568
  return () => {
@@ -2584,7 +2602,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2584
2602
  const runId = resolvedRunId !== null && resolvedRunId !== void 0 ? resolvedRunId : `missing-run-id:${message.id}`;
2585
2603
  const registryAgent = copilotkit.getAgent(agentId);
2586
2604
  const agent = (_getThreadClone = getThreadClone(registryAgent, threadId)) !== null && _getThreadClone !== void 0 ? _getThreadClone : registryAgent;
2587
- if (!agent) throw new Error("Agent not found");
2605
+ if (!agent) return null;
2588
2606
  const messagesIdsInRun = resolvedRunId ? agent.messages.filter((msg) => copilotkit.getRunIdForMessage(agentId, threadId, msg.id) === resolvedRunId).map((msg) => msg.id) : [message.id];
2589
2607
  const rawMessageIndex = agent.messages.findIndex((msg) => msg.id === message.id);
2590
2608
  const messageIndex = rawMessageIndex >= 0 ? rawMessageIndex : 0;
@@ -3668,6 +3686,20 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3668
3686
  /**
3669
3687
  * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context
3670
3688
  */
3689
+ /**
3690
+ * Determine whether a GraphQL error should be suppressed based on its visibility
3691
+ * and whether the dev console is active.
3692
+ *
3693
+ * Returns `null` when the error should be surfaced to the UI, or a log prefix
3694
+ * string when the error should be suppressed (logged to console only).
3695
+ *
3696
+ * Exported for unit testing.
3697
+ */
3698
+ function getErrorSuppression(visibility, isDev) {
3699
+ if (visibility === _copilotkit_shared.ErrorVisibility.SILENT) return "CopilotKit Silent Error:";
3700
+ if (!isDev && visibility === _copilotkit_shared.ErrorVisibility.DEV_ONLY) return "CopilotKit Error (hidden in production):";
3701
+ return null;
3702
+ }
3671
3703
  const MessagesTapContext = (0, react.createContext)(null);
3672
3704
  function useMessagesTap() {
3673
3705
  const tap = (0, react.useContext)(MessagesTapContext);
@@ -3752,13 +3784,9 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3752
3784
  const graphQLErrors = error.graphQLErrors;
3753
3785
  const routeError = (gqlError) => {
3754
3786
  const extensions = gqlError.extensions;
3755
- const visibility = extensions === null || extensions === void 0 ? void 0 : extensions.visibility;
3756
- if (!shouldShowDevConsole(showDevConsole)) {
3757
- console.error("CopilotKit Error (hidden in production):", gqlError.message);
3758
- return;
3759
- }
3760
- if (visibility === _copilotkit_shared.ErrorVisibility.SILENT) {
3761
- console.error("CopilotKit Silent Error:", gqlError.message);
3787
+ const suppression = getErrorSuppression(extensions === null || extensions === void 0 ? void 0 : extensions.visibility, shouldShowDevConsole(showDevConsole));
3788
+ if (suppression) {
3789
+ console.error(suppression, gqlError.message);
3762
3790
  return;
3763
3791
  }
3764
3792
  const ckError = createStructuredError(gqlError);
@@ -3775,8 +3803,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3775
3803
  }
3776
3804
  };
3777
3805
  graphQLErrors.forEach(routeError);
3778
- } else if (!shouldShowDevConsole(showDevConsole)) console.error("CopilotKit Error (hidden in production):", error);
3779
- else {
3806
+ } else {
3780
3807
  const fallbackError = new _copilotkit_shared.CopilotKitError({
3781
3808
  message: (error === null || error === void 0 ? void 0 : error.message) || String(error),
3782
3809
  code: _copilotkit_shared.CopilotKitErrorCode.UNKNOWN
@@ -4679,13 +4706,18 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4679
4706
  };
4680
4707
  }, [agent, getSubscriber]);
4681
4708
  };
4709
+ function CopilotListenersAgentSubscription() {
4710
+ const existingConfig = useCopilotChatConfiguration();
4711
+ const { agent } = useAgent({ agentId: existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.agentId });
4712
+ usePredictStateSubscription(agent);
4713
+ return null;
4714
+ }
4682
4715
  function CopilotListeners() {
4716
+ var _copilotkit$agents;
4683
4717
  const { copilotkit } = useCopilotKit();
4684
- const existingConfig = useCopilotChatConfiguration();
4685
- const resolvedAgentId = existingConfig === null || existingConfig === void 0 ? void 0 : existingConfig.agentId;
4686
4718
  const { setBannerError } = useToast();
4687
- const { agent } = useAgent({ agentId: resolvedAgentId });
4688
- usePredictStateSubscription(agent);
4719
+ const hasAgents = Object.keys((_copilotkit$agents = copilotkit.agents) !== null && _copilotkit$agents !== void 0 ? _copilotkit$agents : {}).length > 0;
4720
+ const hasRuntime = copilotkit.runtimeUrl !== void 0;
4689
4721
  (0, react.useEffect)(() => {
4690
4722
  const subscription = copilotkit.subscribe({ onError: ({ error, code, context }) => {
4691
4723
  if (error.name === "AbortError" || error.message === "Fetch is aborted" || error.message === "signal is aborted without reason" || error.message === "component unmounted" || !error.message) return;
@@ -4707,7 +4739,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4707
4739
  subscription.unsubscribe();
4708
4740
  };
4709
4741
  }, [copilotkit === null || copilotkit === void 0 ? void 0 : copilotkit.subscribe]);
4710
- return null;
4742
+ return hasAgents || hasRuntime ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotListenersAgentSubscription, {}) : null;
4711
4743
  }
4712
4744
 
4713
4745
  //#endregion
@@ -4878,7 +4910,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
4878
4910
  publicApiKey,
4879
4911
  ...cloud ? { cloud } : {},
4880
4912
  chatApiEndpoint,
4881
- headers: props.headers || {},
4913
+ headers: typeof props.headers === "function" ? props.headers() : props.headers || {},
4882
4914
  properties: props.properties || {},
4883
4915
  transcribeAudioUrl: props.transcribeAudioUrl,
4884
4916
  textToSpeechUrl: props.textToSpeechUrl,