@copilotkit/react-core 1.64.1 → 1.64.2-canary.rc-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.
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-DiLTL1ZM.cjs');
4
+ const require_copilotkit = require('./copilotkit-2v7ami2b.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 { $n as LangGraphInterruptRender, Gn as CopilotApiConfig, Jn as useCopilotContext, Kn as CopilotContext, Qn as LangGraphInterruptActionSetterArgs, Sr as RenderFunctionStatus, Wn as CoagentInChatRenderFunction, Xn as LangGraphInterruptAction, Y as useAgent, Yn as CoAgentStateRender, Zn as LangGraphInterruptActionSetter, _r as ActionRenderPropsWait, ar as CrewsResponseStatus, br as FrontendAction, cr as CrewsToolStateItem, dr as DocumentPointer, er as LangGraphInterruptRenderHandlerProps, fr as Tree, gr as ActionRenderPropsNoArgsWait, hr as ActionRenderPropsNoArgs, ir as CrewsResponse, lr as CopilotChatSuggestionConfiguration, mr as ActionRenderProps, n as defaultCopilotContextCategories, nr as QueuedInterruptEvent, or as CrewsStateItem, pr as TreeNode, qn as CopilotContextParams, r as CopilotKitProps, rr as CrewsAgentState, sr as CrewsTaskStateItem, t as CopilotKit, tr as LangGraphInterruptRenderProps, ur as SystemMessageFunction, vr as CatchAllActionRenderProps, vt as useRenderToolCall$1, xr as FrontendActionAvailability, yr as CatchAllFrontendAction } from "./copilotkit-CXvuYw_F.cjs";
1
+ import { $n as LangGraphInterruptRender, Gn as CopilotApiConfig, Jn as useCopilotContext, Kn as CopilotContext, Qn as LangGraphInterruptActionSetterArgs, Sr as RenderFunctionStatus, Wn as CoagentInChatRenderFunction, Xn as LangGraphInterruptAction, Y as useAgent, Yn as CoAgentStateRender, Zn as LangGraphInterruptActionSetter, _r as ActionRenderPropsWait, ar as CrewsResponseStatus, br as FrontendAction, cr as CrewsToolStateItem, dr as DocumentPointer, er as LangGraphInterruptRenderHandlerProps, fr as Tree, gr as ActionRenderPropsNoArgsWait, hr as ActionRenderPropsNoArgs, ir as CrewsResponse, lr as CopilotChatSuggestionConfiguration, mr as ActionRenderProps, n as defaultCopilotContextCategories, nr as QueuedInterruptEvent, or as CrewsStateItem, pr as TreeNode, qn as CopilotContextParams, r as CopilotKitProps, rr as CrewsAgentState, sr as CrewsTaskStateItem, t as CopilotKit, tr as LangGraphInterruptRenderProps, ur as SystemMessageFunction, vr as CatchAllActionRenderProps, vt as useRenderToolCall$1, xr as FrontendActionAvailability, yr as CatchAllFrontendAction } from "./copilotkit-CBCT7BlL.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 { $n as LangGraphInterruptRender, Gn as CopilotApiConfig, Jn as useCopilotContext, Kn as CopilotContext, Qn as LangGraphInterruptActionSetterArgs, Sr as RenderFunctionStatus, Wn as CoagentInChatRenderFunction, Xn as LangGraphInterruptAction, Y as useAgent, Yn as CoAgentStateRender, Zn as LangGraphInterruptActionSetter, _r as ActionRenderPropsWait, ar as CrewsResponseStatus, br as FrontendAction, cr as CrewsToolStateItem, dr as DocumentPointer, er as LangGraphInterruptRenderHandlerProps, fr as Tree, gr as ActionRenderPropsNoArgsWait, hr as ActionRenderPropsNoArgs, ir as CrewsResponse, lr as CopilotChatSuggestionConfiguration, mr as ActionRenderProps, n as defaultCopilotContextCategories, nr as QueuedInterruptEvent, or as CrewsStateItem, pr as TreeNode, qn as CopilotContextParams, r as CopilotKitProps, rr as CrewsAgentState, sr as CrewsTaskStateItem, t as CopilotKit, tr as LangGraphInterruptRenderProps, ur as SystemMessageFunction, vr as CatchAllActionRenderProps, vt as useRenderToolCall$1, xr as FrontendActionAvailability, yr as CatchAllFrontendAction } from "./copilotkit-BE1n5tSI.mjs";
1
+ import { $n as LangGraphInterruptRender, Gn as CopilotApiConfig, Jn as useCopilotContext, Kn as CopilotContext, Qn as LangGraphInterruptActionSetterArgs, Sr as RenderFunctionStatus, Wn as CoagentInChatRenderFunction, Xn as LangGraphInterruptAction, Y as useAgent, Yn as CoAgentStateRender, Zn as LangGraphInterruptActionSetter, _r as ActionRenderPropsWait, ar as CrewsResponseStatus, br as FrontendAction, cr as CrewsToolStateItem, dr as DocumentPointer, er as LangGraphInterruptRenderHandlerProps, fr as Tree, gr as ActionRenderPropsNoArgsWait, hr as ActionRenderPropsNoArgs, ir as CrewsResponse, lr as CopilotChatSuggestionConfiguration, mr as ActionRenderProps, n as defaultCopilotContextCategories, nr as QueuedInterruptEvent, or as CrewsStateItem, pr as TreeNode, qn as CopilotContextParams, r as CopilotKitProps, rr as CrewsAgentState, sr as CrewsTaskStateItem, t as CopilotKit, tr as LangGraphInterruptRenderProps, ur as SystemMessageFunction, vr as CatchAllActionRenderProps, vt as useRenderToolCall$1, xr as FrontendActionAvailability, yr as CatchAllFrontendAction } from "./copilotkit-D0aAnD3i.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 { Tt as useCopilotKit, X as useConfigureSuggestions, Y as useInterrupt, Z as useSuggestions, a as ThreadsProvider, c as CoAgentStateRendersProvider, ct as useRenderCustomMessages, d as shouldShowDevConsole, f as useToast, g as useCopilotContext, h as CopilotContext, i as ThreadsContext, jt as useCopilotChatConfiguration, l as useCoAgentStateRenders, m as useCopilotMessagesContext, n as defaultCopilotContextCategories, nt as useHumanInTheLoop$1, o as useThreads, ot as useFrontendTool$1, p as CopilotMessagesContext, r as CoAgentStateRenderBridge, s as CoAgentStateRendersContext, t as CopilotKit, tt as useAgent, u as useAsyncCallback, ut as defineToolCallRenderer, wt as useRenderToolCall$1 } from "./copilotkit-D_Ao1X-u.mjs";
3
+ import { Tt as useCopilotKit, X as useConfigureSuggestions, Y as useInterrupt, Z as useSuggestions, a as ThreadsProvider, c as CoAgentStateRendersProvider, ct as useRenderCustomMessages, d as shouldShowDevConsole, f as useToast, g as useCopilotContext, h as CopilotContext, i as ThreadsContext, jt as useCopilotChatConfiguration, l as useCoAgentStateRenders, m as useCopilotMessagesContext, n as defaultCopilotContextCategories, nt as useHumanInTheLoop$1, o as useThreads, ot as useFrontendTool$1, p as CopilotMessagesContext, r as CoAgentStateRenderBridge, s as CoAgentStateRendersContext, t as CopilotKit, tt as useAgent, u as useAsyncCallback, ut as defineToolCallRenderer, wt as useRenderToolCall$1 } from "./copilotkit-DnlgZWST.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
@@ -916,6 +916,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
916
916
  iframe.style.backgroundColor = "transparent";
917
917
  iframe.style.display = "block";
918
918
  iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
919
+ iframe.setAttribute("data-testid", "mcp-app-iframe");
920
+ iframe.setAttribute("title", "Interactive MCP application");
919
921
  const sandboxReady = new Promise((resolve) => {
920
922
  initialListener = (event) => {
921
923
  if (event.source === iframe.contentWindow) {
@@ -2322,6 +2324,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2322
2324
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
2323
2325
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
2324
2326
  const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
2327
+ const [catalogToggleVersion, setCatalogToggleVersion] = (0, react.useState)(0);
2325
2328
  const openGenUIActive = runtimeOpenGenUIEnabled || !!openGenerativeUI;
2326
2329
  const a2uiCatalogProvided = !!a2ui?.catalog;
2327
2330
  const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
@@ -2344,6 +2347,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2344
2347
  });
2345
2348
  const renderCustomMessagesList = useStableArrayProp(renderCustomMessages, "renderCustomMessages must be a stable array.");
2346
2349
  const renderActivityMessagesList = useStableArrayProp(renderActivityMessages, "renderActivityMessages must be a stable array.");
2350
+ const copilotkitRef = (0, react.useRef)(null);
2351
+ const rawCatalog = a2ui?.catalog;
2352
+ const filteredCatalog = (0, react.useMemo)(() => {
2353
+ if (!rawCatalog) return rawCatalog;
2354
+ if (!(rawCatalog instanceof _copilotkit_a2ui_renderer.Catalog)) return rawCatalog;
2355
+ const core = copilotkitRef.current;
2356
+ return (0, _copilotkit_a2ui_renderer.filterCatalog)(rawCatalog, (name) => core ? core.isCatalogComponentEnabled(name) : true);
2357
+ }, [rawCatalog, catalogToggleVersion]);
2347
2358
  const builtInActivityRenderers = (0, react.useMemo)(() => {
2348
2359
  const renderers = [{
2349
2360
  activityType: MCPAppsActivityType,
@@ -2357,7 +2368,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2357
2368
  });
2358
2369
  if (a2uiActive) renderers.unshift(createA2UIMessageRenderer({
2359
2370
  theme: a2ui?.theme ?? _copilotkit_a2ui_renderer.viewerTheme,
2360
- catalog: a2ui?.catalog,
2371
+ catalog: filteredCatalog,
2361
2372
  loadingComponent: a2ui?.loadingComponent,
2362
2373
  recovery: a2ui?.recovery
2363
2374
  }));
@@ -2365,7 +2376,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2365
2376
  }, [
2366
2377
  a2uiActive,
2367
2378
  openGenUIActive,
2368
- a2ui
2379
+ a2ui,
2380
+ filteredCatalog
2369
2381
  ]);
2370
2382
  const allActivityRenderers = (0, react.useMemo)(() => {
2371
2383
  return [...renderActivityMessagesList, ...builtInActivityRenderers];
@@ -2470,7 +2482,6 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2470
2482
  builtInFrontendTools,
2471
2483
  processedHumanInTheLoopTools
2472
2484
  ]);
2473
- const copilotkitRef = (0, react.useRef)(null);
2474
2485
  if (copilotkitRef.current === null) {
2475
2486
  copilotkitRef.current = new CopilotKitCoreReact({
2476
2487
  runtimeUrl: chatApiEndpoint,
@@ -2489,6 +2500,20 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2489
2500
  if (defaultThrottleMs !== void 0) copilotkitRef.current.setDefaultThrottleMs(defaultThrottleMs);
2490
2501
  }
2491
2502
  const copilotkit = copilotkitRef.current;
2503
+ (0, react.useEffect)(() => {
2504
+ if (!rawCatalog) return;
2505
+ if (!(rawCatalog instanceof _copilotkit_a2ui_renderer.Catalog)) return;
2506
+ const components = Array.from(rawCatalog.components.values()).map((comp) => ({
2507
+ name: comp.name,
2508
+ description: void 0,
2509
+ schema: comp.schema
2510
+ }));
2511
+ copilotkit.setCatalogComponents(components);
2512
+ const subscription = copilotkit.subscribe({ onCatalogComponentsChanged: () => {
2513
+ setCatalogToggleVersion((v) => v + 1);
2514
+ } });
2515
+ return () => subscription.unsubscribe();
2516
+ }, [copilotkit, rawCatalog]);
2492
2517
  (0, react.useEffect)(() => {
2493
2518
  const syncRuntimeInfo = () => {
2494
2519
  setRuntimeA2UIEnabled(copilotkit.a2uiEnabled);
@@ -2644,7 +2669,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2644
2669
  children: [
2645
2670
  a2uiActive && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
2646
2671
  a2uiActive && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
2647
- catalog: a2ui?.catalog,
2672
+ catalog: filteredCatalog,
2648
2673
  includeSchema: a2ui?.includeSchema
2649
2674
  }),
2650
2675
  children,
@@ -2842,7 +2867,10 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2842
2867
  UseAgentUpdate.OnStateChanged,
2843
2868
  UseAgentUpdate.OnRunStatusChanged
2844
2869
  ];
2845
- function useAgent({ agentId, updates, throttleMs } = {}) {
2870
+ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {}) {
2871
+ if (threadId != null && runtimeAgentId == null) throw new Error(`useAgent: \`threadId\` requires \`runtimeAgentId\`. A threadId is written onto a single agent, but an agent resolved by agentId alone is shared, so scoping a thread to it would clobber other useAgent callers. Pass a distinct local \`agentId\` and the runtime agent to route to, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "${agentId ?? "default"}", threadId }).`);
2872
+ if (runtimeAgentId != null && threadId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires \`threadId\`. A proxied agent exists to scope a thread to a private instance; without a threadId it behaves like the shared agent while adding a registration and a local agentId to keep unique. Either pass the thread, e.g. useAgent({ agentId: "${agentId ?? "chat-1"}", runtimeAgentId: "${runtimeAgentId}", threadId }), or bind to the agent directly with useAgent({ agentId: "${runtimeAgentId}" }).`);
2873
+ if (runtimeAgentId != null && agentId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires an explicit \`agentId\`. The proxied agent is registered under \`agentId\`, and the usual fallbacks (chat configuration, then "${_copilotkit_shared.DEFAULT_AGENT_ID}") name agents that already exist — registering over one throws or shadows it. Pick a local id for this hook, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "${runtimeAgentId}", threadId }).`);
2846
2874
  const chatConfig = useCopilotChatConfiguration();
2847
2875
  const resolvedAgentId = agentId ?? chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
2848
2876
  const { copilotkit } = useCopilotKit();
@@ -2850,7 +2878,58 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2850
2878
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
2851
2879
  const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
2852
2880
  const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
2881
+ const [registeredProxyAgent, setRegisteredProxyAgent] = (0, react.useState)(null);
2882
+ (0, react.useEffect)(() => {
2883
+ if (runtimeAgentId == null) {
2884
+ setRegisteredProxyAgent(null);
2885
+ return;
2886
+ }
2887
+ const { agent: proxy, unregister } = copilotkit.registerProxiedAgent({
2888
+ agentId: resolvedAgentId,
2889
+ runtimeAgentId
2890
+ });
2891
+ provisionalAgentCache.current.delete(resolvedAgentId);
2892
+ setRegisteredProxyAgent(proxy);
2893
+ return () => {
2894
+ unregister();
2895
+ setRegisteredProxyAgent(null);
2896
+ };
2897
+ }, [
2898
+ copilotkit,
2899
+ resolvedAgentId,
2900
+ runtimeAgentId
2901
+ ]);
2853
2902
  const { agent, isReady } = (0, react.useMemo)(() => {
2903
+ if (runtimeAgentId != null) {
2904
+ if (registeredProxyAgent) {
2905
+ provisionalAgentCache.current.delete(resolvedAgentId);
2906
+ return {
2907
+ agent: registeredProxyAgent,
2908
+ isReady: true
2909
+ };
2910
+ }
2911
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
2912
+ if (cached) {
2913
+ copilotkit.applyHeadersToAgent(cached);
2914
+ return {
2915
+ agent: cached,
2916
+ isReady: false
2917
+ };
2918
+ }
2919
+ const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
2920
+ runtimeUrl: copilotkit.runtimeUrl,
2921
+ agentId: resolvedAgentId,
2922
+ runtimeAgentId,
2923
+ transport: copilotkit.runtimeTransport,
2924
+ runtimeMode: "pending"
2925
+ });
2926
+ copilotkit.applyHeadersToAgent(provisional);
2927
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
2928
+ return {
2929
+ agent: provisional,
2930
+ isReady: false
2931
+ };
2932
+ }
2854
2933
  const existing = copilotkit.getAgent(resolvedAgentId);
2855
2934
  if (existing) {
2856
2935
  provisionalAgentCache.current.delete(resolvedAgentId);
@@ -2906,6 +2985,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2906
2985
  throw new Error(`useAgent: Agent '${resolvedAgentId}' not found after runtime sync (${runtimePart}). ` + (knownAgents.length ? `Known agents: [${knownAgents.join(", ")}]` : "No agents registered.") + " Verify your runtime /info and/or agents__unsafe_dev_only.");
2907
2986
  }, [
2908
2987
  resolvedAgentId,
2988
+ runtimeAgentId,
2989
+ registeredProxyAgent,
2909
2990
  copilotkit.agents,
2910
2991
  copilotkit.runtimeConnectionStatus,
2911
2992
  copilotkit.runtimeUrl,
@@ -2958,14 +3039,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2958
3039
  ]);
2959
3040
  const configThreadId = chatConfig?.threadId;
2960
3041
  const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
3042
+ const resolvedThreadId = threadId ?? (configHasExplicitThreadId ? configThreadId : void 0);
2961
3043
  (0, react.useEffect)(() => {
2962
- if (!configHasExplicitThreadId || !configThreadId) return;
2963
- agent.threadId = configThreadId;
2964
- }, [
2965
- agent,
2966
- configThreadId,
2967
- configHasExplicitThreadId
2968
- ]);
3044
+ if (!resolvedThreadId) return;
3045
+ agent.threadId = resolvedThreadId;
3046
+ }, [agent, resolvedThreadId]);
2969
3047
  return {
2970
3048
  agent,
2971
3049
  isReady