@copilotkit/react-core 1.55.2 → 1.55.3-canary.1776215089

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-Dgdpbqjt.cjs → copilotkit-BZuXjQLc.cjs} +43 -7
  2. package/dist/copilotkit-BZuXjQLc.cjs.map +1 -0
  3. package/dist/{copilotkit-Cd-NrDyp.mjs → copilotkit-BzVUuD95.mjs} +38 -8
  4. package/dist/copilotkit-BzVUuD95.mjs.map +1 -0
  5. package/dist/{copilotkit-dwDWYpya.d.cts → copilotkit-EfopO2gn.d.cts} +27 -9
  6. package/dist/copilotkit-EfopO2gn.d.cts.map +1 -0
  7. package/dist/{copilotkit-BuhSUZHb.d.mts → copilotkit-opur-20s.d.mts} +27 -9
  8. package/dist/copilotkit-opur-20s.d.mts.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 +18 -6
  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 +37 -6
  20. package/dist/v2/index.umd.js.map +1 -1
  21. package/package.json +6 -6
  22. package/src/components/copilot-provider/copilotkit-props.tsx +9 -5
  23. package/src/components/copilot-provider/copilotkit.tsx +4 -1
  24. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +10 -10
  25. package/src/v2/hooks/__tests__/use-capabilities.test.tsx +76 -0
  26. package/src/v2/hooks/index.ts +1 -0
  27. package/src/v2/hooks/use-agent.tsx +23 -4
  28. package/src/v2/hooks/use-capabilities.tsx +25 -0
  29. package/src/v2/providers/CopilotKitProvider.tsx +6 -2
  30. package/dist/copilotkit-BuhSUZHb.d.mts.map +0 -1
  31. package/dist/copilotkit-Cd-NrDyp.mjs.map +0 -1
  32. package/dist/copilotkit-Dgdpbqjt.cjs.map +0 -1
  33. package/dist/copilotkit-dwDWYpya.d.cts.map +0 -1
@@ -3072,7 +3072,7 @@ function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
3072
3072
  }, [value, warningMessage]);
3073
3073
  return value;
3074
3074
  }
3075
- 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 }) => {
3075
+ 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 }) => {
3076
3076
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
3077
3077
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
3078
3078
  const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
@@ -3127,6 +3127,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers = {}, credentials, p
3127
3127
  ...selfManagedAgents
3128
3128
  }), [agents, selfManagedAgents]);
3129
3129
  const hasLocalAgents = mergedAgents && Object.keys(mergedAgents).length > 0;
3130
+ const headers = typeof headersProp === "function" ? headersProp() : headersProp;
3130
3131
  const mergedHeaders = (0, react.useMemo)(() => {
3131
3132
  if (!resolvedPublicKey) return headers;
3132
3133
  if (headers[HEADER_NAME]) return headers;
@@ -3619,6 +3620,17 @@ function useAgent({ agentId, threadId, updates, throttleMs } = {}) {
3619
3620
  const handlers = {};
3620
3621
  let timerId = null;
3621
3622
  let active = true;
3623
+ let batchScheduled = false;
3624
+ const batchedForceUpdate = () => {
3625
+ if (!active) return;
3626
+ if (!batchScheduled) {
3627
+ batchScheduled = true;
3628
+ queueMicrotask(() => {
3629
+ batchScheduled = false;
3630
+ if (active) forceUpdate();
3631
+ });
3632
+ }
3633
+ };
3622
3634
  if (updateFlags.includes(UseAgentUpdate.OnMessagesChanged)) {
3623
3635
  const ms = effectiveThrottleMs;
3624
3636
  if (ms > 0) {
@@ -3643,11 +3655,11 @@ function useAgent({ agentId, threadId, updates, throttleMs } = {}) {
3643
3655
  handlers.onMessagesChanged = throttledNotify;
3644
3656
  } else handlers.onMessagesChanged = forceUpdate;
3645
3657
  }
3646
- if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = forceUpdate;
3658
+ if (updateFlags.includes(UseAgentUpdate.OnStateChanged)) handlers.onStateChanged = batchedForceUpdate;
3647
3659
  if (updateFlags.includes(UseAgentUpdate.OnRunStatusChanged)) {
3648
- handlers.onRunInitialized = forceUpdate;
3649
- handlers.onRunFinalized = forceUpdate;
3650
- handlers.onRunFailed = forceUpdate;
3660
+ handlers.onRunInitialized = batchedForceUpdate;
3661
+ handlers.onRunFinalized = batchedForceUpdate;
3662
+ handlers.onRunFailed = batchedForceUpdate;
3651
3663
  }
3652
3664
  const subscription = agent.subscribe(handlers);
3653
3665
  return () => {
@@ -4184,6 +4196,24 @@ function useHumanInTheLoop(tool, deps) {
4184
4196
  ]);
4185
4197
  }
4186
4198
 
4199
+ //#endregion
4200
+ //#region src/v2/hooks/use-capabilities.tsx
4201
+ /**
4202
+ * Returns the capabilities declared by the given agent (or the default agent).
4203
+ * Capabilities are populated from the runtime `/info` response at connection
4204
+ * time. The hook reads them synchronously from the agent instance — there is
4205
+ * no separate loading state, but the value will be `undefined` until the
4206
+ * runtime handshake completes.
4207
+ *
4208
+ * @param agentId - Optional agent ID. If omitted, uses the default agent.
4209
+ * @returns The agent's capabilities, or `undefined` if the agent doesn't
4210
+ * declare capabilities.
4211
+ */
4212
+ function useCapabilities(agentId) {
4213
+ const { agent } = useAgent({ agentId });
4214
+ if (agent && "capabilities" in agent) return agent.capabilities;
4215
+ }
4216
+
4187
4217
  //#endregion
4188
4218
  //#region src/v2/hooks/use-suggestions.tsx
4189
4219
  function useSuggestions({ agentId } = {}) {
@@ -9186,7 +9216,7 @@ function CopilotKitInternal(cpkProps) {
9186
9216
  publicApiKey,
9187
9217
  ...cloud ? { cloud } : {},
9188
9218
  chatApiEndpoint,
9189
- headers: props.headers || {},
9219
+ headers: typeof props.headers === "function" ? props.headers() : props.headers || {},
9190
9220
  properties: props.properties || {},
9191
9221
  transcribeAudioUrl: props.transcribeAudioUrl,
9192
9222
  textToSpeechUrl: props.textToSpeechUrl,
@@ -9826,6 +9856,12 @@ Object.defineProperty(exports, 'useAttachments', {
9826
9856
  return useAttachments;
9827
9857
  }
9828
9858
  });
9859
+ Object.defineProperty(exports, 'useCapabilities', {
9860
+ enumerable: true,
9861
+ get: function () {
9862
+ return useCapabilities;
9863
+ }
9864
+ });
9829
9865
  Object.defineProperty(exports, 'useCoAgentStateRenders', {
9830
9866
  enumerable: true,
9831
9867
  get: function () {
@@ -9946,4 +9982,4 @@ Object.defineProperty(exports, 'useToast', {
9946
9982
  return useToast;
9947
9983
  }
9948
9984
  });
9949
- //# sourceMappingURL=copilotkit-Dgdpbqjt.cjs.map
9985
+ //# sourceMappingURL=copilotkit-BZuXjQLc.cjs.map