@copilotkit/react-core 1.75.2 → 1.77.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 (43) hide show
  1. package/dist/{copilotkit-Beiw32bn.cjs → copilotkit-CFPkj9B9.cjs} +155 -54
  2. package/dist/copilotkit-CFPkj9B9.cjs.map +1 -0
  3. package/dist/{copilotkit-D9iy3p2l.mjs → copilotkit-CP9qPAqV.mjs} +159 -57
  4. package/dist/copilotkit-CP9qPAqV.mjs.map +1 -0
  5. package/dist/{copilotkit-CGlSOKHM.d.mts → copilotkit-Cqa0TfEo.d.mts} +43 -17
  6. package/dist/copilotkit-Cqa0TfEo.d.mts.map +1 -0
  7. package/dist/{copilotkit-Cjj9wDI8.d.cts → copilotkit-DGc2YiW9.d.cts} +35 -4
  8. package/dist/copilotkit-DGc2YiW9.d.cts.map +1 -0
  9. package/dist/index.cjs +2 -2
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.cts.map +1 -1
  13. package/dist/index.d.mts +1 -1
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +4 -4
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/index.umd.js +90 -44
  18. package/dist/index.umd.js.map +1 -1
  19. package/dist/v2/context.cjs.map +1 -1
  20. package/dist/v2/context.d.cts +5 -0
  21. package/dist/v2/context.d.cts.map +1 -1
  22. package/dist/v2/context.d.mts +5 -0
  23. package/dist/v2/context.d.mts.map +1 -1
  24. package/dist/v2/context.mjs.map +1 -1
  25. package/dist/v2/headless.cjs +36 -24
  26. package/dist/v2/headless.cjs.map +1 -1
  27. package/dist/v2/headless.d.cts +5 -0
  28. package/dist/v2/headless.d.cts.map +1 -1
  29. package/dist/v2/headless.d.mts +2 -2
  30. package/dist/v2/headless.d.mts.map +1 -1
  31. package/dist/v2/headless.mjs +38 -26
  32. package/dist/v2/headless.mjs.map +1 -1
  33. package/dist/v2/index.cjs +302 -121
  34. package/dist/v2/index.d.cts +2 -2
  35. package/dist/v2/index.d.mts +2 -2
  36. package/dist/v2/index.mjs +2 -2
  37. package/dist/v2/index.umd.js +457 -177
  38. package/dist/v2/index.umd.js.map +1 -1
  39. package/package.json +10 -10
  40. package/dist/copilotkit-Beiw32bn.cjs.map +0 -1
  41. package/dist/copilotkit-CGlSOKHM.d.mts.map +0 -1
  42. package/dist/copilotkit-Cjj9wDI8.d.cts.map +0 -1
  43. package/dist/copilotkit-D9iy3p2l.mjs.map +0 -1
package/dist/index.umd.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  (function(global, factory) {
4
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@copilotkit/core'), require('@ag-ui/client'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('zod'), require('@copilotkit/mcp-apps-renderer/activity'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('react-markdown'), require('@copilotkit/runtime-client-gql')) :
5
- typeof define === 'function' && define.amd ? define(['exports', 'react', '@copilotkit/core', '@ag-ui/client', '@copilotkit/shared', 'react/jsx-runtime', 'zod', '@copilotkit/mcp-apps-renderer/activity', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', 'react-markdown', '@copilotkit/runtime-client-gql'], factory) :
6
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCore = {}), global.React,global.CopilotKitCore,global.AgUIClient,global.CopilotKitShared,global.ReactJsxRuntime,global.Zod,global.CopilotKitMcpAppsRendererActivity,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global.ReactMarkdown,global.CopilotKitRuntimeClientGQL));
7
- })(this, function(exports, react, _copilotkit_core, _ag_ui_client, _copilotkit_shared, react_jsx_runtime, zod, _copilotkit_mcp_apps_renderer_activity, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, react_markdown, _copilotkit_runtime_client_gql) {
4
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@copilotkit/core'), require('@ag-ui/client'), require('@copilotkit/shared'), require('react/jsx-runtime'), require('@ag-ui/core'), require('zod'), require('@copilotkit/mcp-apps-renderer/activity'), require('@copilotkit/a2ui-renderer'), require('zod-to-json-schema'), require('react-dom'), require('react-markdown'), require('@copilotkit/runtime-client-gql')) :
5
+ typeof define === 'function' && define.amd ? define(['exports', 'react', '@copilotkit/core', '@ag-ui/client', '@copilotkit/shared', 'react/jsx-runtime', '@ag-ui/core', 'zod', '@copilotkit/mcp-apps-renderer/activity', '@copilotkit/a2ui-renderer', 'zod-to-json-schema', 'react-dom', 'react-markdown', '@copilotkit/runtime-client-gql'], factory) :
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitReactCore = {}), global.React,global.CopilotKitCore,global.AgUIClient,global.CopilotKitShared,global.ReactJsxRuntime,global._ag_ui_core,global.Zod,global.CopilotKitMcpAppsRendererActivity,global.CopilotKitA2UIRenderer,global.zod_to_json_schema,global.ReactDOM,global.ReactMarkdown,global.CopilotKitRuntimeClientGQL));
7
+ })(this, function(exports, react, _copilotkit_core, _ag_ui_client, _copilotkit_shared, react_jsx_runtime, _ag_ui_core, zod, _copilotkit_mcp_apps_renderer_activity, _copilotkit_a2ui_renderer, zod_to_json_schema, react_dom, react_markdown, _copilotkit_runtime_client_gql) {
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
9
9
  //#region \0rolldown/runtime.js
10
10
  var __create = Object.create;
@@ -280,6 +280,25 @@ react_markdown = __toESM(react_markdown);
280
280
  parentConfig?.threadId,
281
281
  activeThreadOverride
282
282
  ]);
283
+ const copilotkit = (0, react.useContext)(CopilotKitContext)?.copilotkit;
284
+ const openThreadRef = (0, react.useRef)(null);
285
+ const latestThreadIdRef = (0, react.useRef)(resolvedThreadId);
286
+ latestThreadIdRef.current = resolvedThreadId;
287
+ (0, react.useEffect)(() => {
288
+ if (copilotkit === void 0) return;
289
+ const registration = copilotkit.registerOpenThread({
290
+ agentId: resolvedAgentId,
291
+ threadId: latestThreadIdRef.current
292
+ });
293
+ openThreadRef.current = registration;
294
+ return () => {
295
+ registration.unregister();
296
+ openThreadRef.current = null;
297
+ };
298
+ }, [copilotkit, resolvedAgentId]);
299
+ (0, react.useEffect)(() => {
300
+ openThreadRef.current?.update(resolvedThreadId);
301
+ }, [resolvedThreadId]);
283
302
  const resolvedHasExplicitThreadId = (threadIdPropIsAuthoritative ? true : activeThreadOverride?.explicit ?? hasExplicitThreadId ?? false) || !!parentConfig?.hasExplicitThreadId;
284
303
  const [internalModalOpen, setInternalModalOpen] = (0, react.useState)(isModalDefaultOpen ?? true);
285
304
  const hasExplicitDefault = isModalDefaultOpen !== void 0;
@@ -487,7 +506,7 @@ react_markdown = __toESM(react_markdown);
487
506
  toolCallId: toolCall.id,
488
507
  args,
489
508
  status: _copilotkit_core.ToolCallStatus.Complete,
490
- result: toolMessage.content
509
+ result: (0, _ag_ui_core.contentToText)(toolMessage.content)
491
510
  });
492
511
  else if (isExecuting) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderComponent, {
493
512
  name: toolName,
@@ -583,7 +602,7 @@ react_markdown = __toESM(react_markdown);
583
602
 
584
603
  //#endregion
585
604
  //#region package.json
586
- var version = "1.75.2";
605
+ var version = "1.77.0";
587
606
 
588
607
  //#endregion
589
608
  //#region src/v2/components/CopilotKitInspector.tsx
@@ -787,12 +806,14 @@ react_markdown = __toESM(react_markdown);
787
806
  * Fetches resource content on-demand via proxied MCP requests. The React shell
788
807
  * owns the iframe; `bindMcpApp` owns the protocol.
789
808
  */
790
- const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agent }) {
809
+ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent }) {
791
810
  const { copilotkit } = useCopilotKit();
811
+ const messageId = message?.id;
792
812
  const containerRef = (0, react.useRef)(null);
793
813
  const iframeRef = (0, react.useRef)(null);
794
814
  const sessionRef = (0, react.useRef)(null);
795
815
  const [error, setError] = (0, react.useState)(null);
816
+ const [contentError, setContentError] = (0, react.useState)(null);
796
817
  const [isLoading, setIsLoading] = (0, react.useState)(true);
797
818
  const [iframeSize, setIframeSize] = (0, react.useState)({});
798
819
  const [fetchedResource, setFetchedResource] = (0, react.useState)(null);
@@ -811,6 +832,7 @@ react_markdown = __toESM(react_markdown);
811
832
  let mounted = true;
812
833
  setIsLoading(true);
813
834
  setError(null);
835
+ setContentError(null);
814
836
  const iframe = document.createElement("iframe");
815
837
  iframe.style.width = "100%";
816
838
  iframe.style.height = "100px";
@@ -833,6 +855,7 @@ react_markdown = __toESM(react_markdown);
833
855
  getContent: () => contentRef.current,
834
856
  getAgent: () => agentRef.current,
835
857
  host: copilotkit,
858
+ messageId,
836
859
  hooks: {
837
860
  onResource: (resource) => {
838
861
  if (!mounted) return;
@@ -842,6 +865,9 @@ react_markdown = __toESM(react_markdown);
842
865
  onSizeChanged: (size) => {
843
866
  if (mounted) setIframeSize(size);
844
867
  },
868
+ onContentError: (err) => {
869
+ if (mounted) setContentError(err);
870
+ },
845
871
  onError: (err) => {
846
872
  if (!mounted) return;
847
873
  setError(err);
@@ -850,9 +876,7 @@ react_markdown = __toESM(react_markdown);
850
876
  }
851
877
  });
852
878
  sessionRef.current = session;
853
- const current = contentRef.current;
854
- if (current.toolInput) session.sendToolInput(current.toolInput);
855
- if (current.result) session.sendToolResult(current.result);
879
+ session.syncContent(contentRef.current);
856
880
  } catch (err) {
857
881
  console.error("[MCPAppsRenderer] Setup error:", err);
858
882
  if (mounted) {
@@ -872,6 +896,7 @@ react_markdown = __toESM(react_markdown);
872
896
  }, [
873
897
  agent,
874
898
  copilotkit,
899
+ messageId,
875
900
  content.resourceUri,
876
901
  content.serverHash,
877
902
  content.serverId
@@ -886,11 +911,8 @@ react_markdown = __toESM(react_markdown);
886
911
  }
887
912
  }, [iframeSize]);
888
913
  (0, react.useEffect)(() => {
889
- if (content.toolInput) sessionRef.current?.sendToolInput(content.toolInput);
890
- }, [content.toolInput]);
891
- (0, react.useEffect)(() => {
892
- if (content.result) sessionRef.current?.sendToolResult(content.result);
893
- }, [content.result]);
914
+ sessionRef.current?.syncContent(contentRef.current);
915
+ }, [content.toolInput, content.result]);
894
916
  const borderStyle = fetchedResource?._meta?.ui?.prefersBorder === true ? {
895
917
  borderRadius: "8px",
896
918
  backgroundColor: "#f9f9f9",
@@ -912,12 +934,12 @@ react_markdown = __toESM(react_markdown);
912
934
  color: "#666"
913
935
  },
914
936
  children: "Loading..."
915
- }), error && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
937
+ }), (error ?? contentError) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
916
938
  style: {
917
939
  color: "red",
918
940
  padding: "1rem"
919
941
  },
920
- children: ["Error: ", error.message]
942
+ children: ["Error: ", (error ?? contentError).message]
921
943
  })]
922
944
  });
923
945
  };
@@ -2219,7 +2241,7 @@ react_markdown = __toESM(react_markdown);
2219
2241
  }, [value, warningMessage]);
2220
2242
  return value;
2221
2243
  }
2222
- const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, messageFilter, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, agentId, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug }) => {
2244
+ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, messageFilter, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, agentId, showIntelligenceIndicator = true, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug, learning }) => {
2223
2245
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
2224
2246
  const [inspectorVisible, setInspectorVisible] = (0, react.useState)(false);
2225
2247
  (0, react.useEffect)(() => {
@@ -2454,7 +2476,8 @@ react_markdown = __toESM(react_markdown);
2454
2476
  renderToolCalls: allRenderToolCalls,
2455
2477
  renderActivityMessages: allActivityRenderers,
2456
2478
  renderCustomMessages: renderCustomMessagesList,
2457
- debug
2479
+ debug,
2480
+ learning
2458
2481
  });
2459
2482
  if (defaultThrottleMs !== void 0) copilotkitRef.current.setDefaultThrottleMs(defaultThrottleMs);
2460
2483
  }
@@ -2559,6 +2582,32 @@ react_markdown = __toESM(react_markdown);
2559
2582
  useSingleEndpoint,
2560
2583
  debug
2561
2584
  ]);
2585
+ const learningEnabled = learning !== void 0;
2586
+ const trajectoryId = learning?.trajectoryId;
2587
+ const learningContainerIdsRef = (0, react.useRef)(learning?.learningContainerIds);
2588
+ (0, react.useEffect)(() => {
2589
+ copilotkit.setLearningConfig(learning);
2590
+ learningContainerIdsRef.current = learning?.learningContainerIds;
2591
+ if (learning?.sink === void 0 && learning?.trajectoryId === void 0 && learning?.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture does not assign Learning Containers; remove learningContainerIds from the capture options.");
2592
+ }, [copilotkit, learning]);
2593
+ (0, react.useEffect)(() => {
2594
+ if (!learningEnabled) return;
2595
+ let disposed = false;
2596
+ if (trajectoryId !== void 0) copilotkit.startTrajectory({
2597
+ trajectoryId,
2598
+ learningContainerIds: learningContainerIdsRef.current
2599
+ }).catch(() => {
2600
+ if (!disposed) console.warn("[CopilotKit] Failed to start interaction capture.");
2601
+ });
2602
+ return () => {
2603
+ disposed = true;
2604
+ copilotkit.stopTrajectory();
2605
+ };
2606
+ }, [
2607
+ copilotkit,
2608
+ learningEnabled,
2609
+ trajectoryId
2610
+ ]);
2562
2611
  const didMountRef = (0, react.useRef)(false);
2563
2612
  (0, react.useEffect)(() => {
2564
2613
  if (!didMountRef.current) return;
@@ -2621,8 +2670,13 @@ react_markdown = __toESM(react_markdown);
2621
2670
  ]);
2622
2671
  const contextValue = (0, react.useMemo)(() => ({
2623
2672
  copilotkit,
2624
- executingToolCallIds
2625
- }), [copilotkit, executingToolCallIds]);
2673
+ executingToolCallIds,
2674
+ showIntelligenceIndicator
2675
+ }), [
2676
+ copilotkit,
2677
+ executingToolCallIds,
2678
+ showIntelligenceIndicator
2679
+ ]);
2626
2680
  const retryableRuntimeEntitlementFailure = runtimeEntitlements?.status !== "ready" && runtimeEntitlements?.error.retryable === true;
2627
2681
  const hasNonReadyRuntimeEntitlement = runtimeEntitlements !== void 0 && runtimeEntitlements.status !== "ready";
2628
2682
  const hasLegacyRuntimeEntitlementFallback = runtimeLicenseStatus === "valid" || runtimeLicenseStatus === "expiring";
@@ -3026,7 +3080,7 @@ react_markdown = __toESM(react_markdown);
3026
3080
  updateFlags
3027
3081
  ]);
3028
3082
  (0, react.useEffect)(() => {
3029
- if (agent instanceof _ag_ui_client.HttpAgent) copilotkit.applyHeadersToAgent(agent);
3083
+ if ((0, _copilotkit_core.ɵisHttpAgent)(agent)) copilotkit.applyHeadersToAgent(agent);
3030
3084
  if (agent instanceof _copilotkit_core.ProxiedCopilotRuntimeAgent) agent.credentials = copilotkit.credentials;
3031
3085
  }, [
3032
3086
  agent,
@@ -3319,7 +3373,6 @@ react_markdown = __toESM(react_markdown);
3319
3373
  pendingRef.current = pending;
3320
3374
  const [handlerResult, setHandlerResult] = (0, react.useState)(null);
3321
3375
  const interruptStateRef = (0, react.useRef)(new _copilotkit_core.ɵInterruptState());
3322
- const legacyRunIdRef = (0, react.useRef)(void 0);
3323
3376
  (0, react.useEffect)(() => {
3324
3377
  const interruptState = interruptStateRef.current;
3325
3378
  let localLegacy = null;
@@ -3337,16 +3390,14 @@ react_markdown = __toESM(react_markdown);
3337
3390
  onRunStartedEvent: () => {
3338
3391
  localLegacy = null;
3339
3392
  localStandard = null;
3340
- legacyRunIdRef.current = void 0;
3341
3393
  interruptState.clear();
3342
3394
  setPending(null);
3343
3395
  },
3344
- onRunFinalized: (params) => {
3396
+ onRunFinalized: () => {
3345
3397
  if (localStandard && localStandard.length > 0) {
3346
3398
  interruptState.setStandard(localStandard);
3347
3399
  setPending(interruptState.pending);
3348
3400
  } else if (localLegacy) {
3349
- legacyRunIdRef.current = params.input.runId;
3350
3401
  interruptState.setLegacy(localLegacy);
3351
3402
  setPending(interruptState.pending);
3352
3403
  }
@@ -3356,7 +3407,6 @@ react_markdown = __toESM(react_markdown);
3356
3407
  onRunFailed: () => {
3357
3408
  localLegacy = null;
3358
3409
  localStandard = null;
3359
- legacyRunIdRef.current = void 0;
3360
3410
  interruptState.clear();
3361
3411
  setPending(null);
3362
3412
  }
@@ -3371,22 +3421,18 @@ react_markdown = __toESM(react_markdown);
3371
3421
  if (!current) return;
3372
3422
  if (current.kind === "standard" && current.interrupts.length > 1 && interruptId === void 0) console.warn(`[CopilotKit] useInterrupt: resolve()/cancel() called without an interruptId while ${current.interrupts.length} interrupts are open; defaulting to the first. Pass an interruptId to address a specific interrupt.`);
3373
3423
  const decision = interruptStateRef.current.resolve(payload, interruptId);
3374
- if (decision.kind === "legacy-resume") {
3375
- const runId = legacyRunIdRef.current;
3376
- try {
3377
- return await copilotkit.runAgent({
3378
- agent,
3379
- ...runId !== void 0 ? { runId } : {},
3380
- forwardedProps: { command: {
3381
- resume: decision.payload,
3382
- interruptEvent: decision.interruptValue
3383
- } }
3384
- });
3385
- } catch (err) {
3386
- console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
3387
- setPending(null);
3388
- throw err;
3389
- }
3424
+ if (decision.kind === "legacy-resume") try {
3425
+ return await copilotkit.runAgent({
3426
+ agent,
3427
+ forwardedProps: { command: {
3428
+ resume: decision.payload,
3429
+ interruptEvent: decision.interruptValue
3430
+ } }
3431
+ });
3432
+ } catch (err) {
3433
+ console.error("[CopilotKit] useInterrupt resolve: runAgent rejected; clearing pending + rethrowing", err);
3434
+ setPending(null);
3435
+ throw err;
3390
3436
  }
3391
3437
  if (decision.kind === "expired") {
3392
3438
  console.error(`[CopilotKit] useInterrupt: interrupt ${decision.interrupt.id} expired at ${decision.interrupt.expiresAt}; not resuming.`);
@@ -5747,7 +5793,7 @@ react_markdown = __toESM(react_markdown);
5747
5793
  (0, react.useEffect)(() => {
5748
5794
  let detached = false;
5749
5795
  const connectAbortController = new AbortController();
5750
- if (agent instanceof _ag_ui_client.HttpAgent) agent.abortController = connectAbortController;
5796
+ if ((0, _copilotkit_core.ɵisHttpAgent)(agent)) agent.abortController = connectAbortController;
5751
5797
  const connect = async (agent) => {
5752
5798
  setAgentAvailable(false);
5753
5799
  try {