@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.
@@ -2116,6 +2116,8 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
2116
2116
  iframe.style.backgroundColor = "transparent";
2117
2117
  iframe.style.display = "block";
2118
2118
  iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
2119
+ iframe.setAttribute("data-testid", "mcp-app-iframe");
2120
+ iframe.setAttribute("title", "Interactive MCP application");
2119
2121
  const sandboxReady = new Promise((resolve) => {
2120
2122
  initialListener = (event) => {
2121
2123
  if (event.source === iframe.contentWindow) {
@@ -3522,6 +3524,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3522
3524
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
3523
3525
  const [runtimeA2UIEnabled, setRuntimeA2UIEnabled] = (0, react.useState)(false);
3524
3526
  const [runtimeOpenGenUIEnabled, setRuntimeOpenGenUIEnabled] = (0, react.useState)(false);
3527
+ const [catalogToggleVersion, setCatalogToggleVersion] = (0, react.useState)(0);
3525
3528
  const openGenUIActive = runtimeOpenGenUIEnabled || !!openGenerativeUI;
3526
3529
  const a2uiCatalogProvided = !!a2ui?.catalog;
3527
3530
  const a2uiActive = runtimeA2UIEnabled || a2uiCatalogProvided;
@@ -3544,6 +3547,14 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3544
3547
  });
3545
3548
  const renderCustomMessagesList = useStableArrayProp(renderCustomMessages, "renderCustomMessages must be a stable array.");
3546
3549
  const renderActivityMessagesList = useStableArrayProp(renderActivityMessages, "renderActivityMessages must be a stable array.");
3550
+ const copilotkitRef = (0, react.useRef)(null);
3551
+ const rawCatalog = a2ui?.catalog;
3552
+ const filteredCatalog = (0, react.useMemo)(() => {
3553
+ if (!rawCatalog) return rawCatalog;
3554
+ if (!(rawCatalog instanceof _copilotkit_a2ui_renderer.Catalog)) return rawCatalog;
3555
+ const core = copilotkitRef.current;
3556
+ return (0, _copilotkit_a2ui_renderer.filterCatalog)(rawCatalog, (name) => core ? core.isCatalogComponentEnabled(name) : true);
3557
+ }, [rawCatalog, catalogToggleVersion]);
3547
3558
  const builtInActivityRenderers = (0, react.useMemo)(() => {
3548
3559
  const renderers = [{
3549
3560
  activityType: MCPAppsActivityType,
@@ -3557,7 +3568,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3557
3568
  });
3558
3569
  if (a2uiActive) renderers.unshift(createA2UIMessageRenderer({
3559
3570
  theme: a2ui?.theme ?? _copilotkit_a2ui_renderer.viewerTheme,
3560
- catalog: a2ui?.catalog,
3571
+ catalog: filteredCatalog,
3561
3572
  loadingComponent: a2ui?.loadingComponent,
3562
3573
  recovery: a2ui?.recovery
3563
3574
  }));
@@ -3565,7 +3576,8 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3565
3576
  }, [
3566
3577
  a2uiActive,
3567
3578
  openGenUIActive,
3568
- a2ui
3579
+ a2ui,
3580
+ filteredCatalog
3569
3581
  ]);
3570
3582
  const allActivityRenderers = (0, react.useMemo)(() => {
3571
3583
  return [...renderActivityMessagesList, ...builtInActivityRenderers];
@@ -3670,7 +3682,6 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3670
3682
  builtInFrontendTools,
3671
3683
  processedHumanInTheLoopTools
3672
3684
  ]);
3673
- const copilotkitRef = (0, react.useRef)(null);
3674
3685
  if (copilotkitRef.current === null) {
3675
3686
  copilotkitRef.current = new CopilotKitCoreReact({
3676
3687
  runtimeUrl: chatApiEndpoint,
@@ -3689,6 +3700,20 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3689
3700
  if (defaultThrottleMs !== void 0) copilotkitRef.current.setDefaultThrottleMs(defaultThrottleMs);
3690
3701
  }
3691
3702
  const copilotkit = copilotkitRef.current;
3703
+ (0, react.useEffect)(() => {
3704
+ if (!rawCatalog) return;
3705
+ if (!(rawCatalog instanceof _copilotkit_a2ui_renderer.Catalog)) return;
3706
+ const components = Array.from(rawCatalog.components.values()).map((comp) => ({
3707
+ name: comp.name,
3708
+ description: void 0,
3709
+ schema: comp.schema
3710
+ }));
3711
+ copilotkit.setCatalogComponents(components);
3712
+ const subscription = copilotkit.subscribe({ onCatalogComponentsChanged: () => {
3713
+ setCatalogToggleVersion((v) => v + 1);
3714
+ } });
3715
+ return () => subscription.unsubscribe();
3716
+ }, [copilotkit, rawCatalog]);
3692
3717
  (0, react.useEffect)(() => {
3693
3718
  const syncRuntimeInfo = () => {
3694
3719
  setRuntimeA2UIEnabled(copilotkit.a2uiEnabled);
@@ -3844,7 +3869,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3844
3869
  children: [
3845
3870
  a2uiActive && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UIBuiltInToolCallRenderer, {}),
3846
3871
  a2uiActive && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(A2UICatalogContext, {
3847
- catalog: a2ui?.catalog,
3872
+ catalog: filteredCatalog,
3848
3873
  includeSchema: a2ui?.includeSchema
3849
3874
  }),
3850
3875
  children,
@@ -4422,7 +4447,10 @@ const ALL_UPDATES = [
4422
4447
  UseAgentUpdate.OnStateChanged,
4423
4448
  UseAgentUpdate.OnRunStatusChanged
4424
4449
  ];
4425
- function useAgent({ agentId, updates, throttleMs } = {}) {
4450
+ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {}) {
4451
+ 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 }).`);
4452
+ 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}" }).`);
4453
+ 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 }).`);
4426
4454
  const chatConfig = useCopilotChatConfiguration();
4427
4455
  const resolvedAgentId = agentId ?? chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
4428
4456
  const { copilotkit } = useCopilotKit();
@@ -4430,7 +4458,58 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4430
4458
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
4431
4459
  const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
4432
4460
  const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
4461
+ const [registeredProxyAgent, setRegisteredProxyAgent] = (0, react.useState)(null);
4462
+ (0, react.useEffect)(() => {
4463
+ if (runtimeAgentId == null) {
4464
+ setRegisteredProxyAgent(null);
4465
+ return;
4466
+ }
4467
+ const { agent: proxy, unregister } = copilotkit.registerProxiedAgent({
4468
+ agentId: resolvedAgentId,
4469
+ runtimeAgentId
4470
+ });
4471
+ provisionalAgentCache.current.delete(resolvedAgentId);
4472
+ setRegisteredProxyAgent(proxy);
4473
+ return () => {
4474
+ unregister();
4475
+ setRegisteredProxyAgent(null);
4476
+ };
4477
+ }, [
4478
+ copilotkit,
4479
+ resolvedAgentId,
4480
+ runtimeAgentId
4481
+ ]);
4433
4482
  const { agent, isReady } = (0, react.useMemo)(() => {
4483
+ if (runtimeAgentId != null) {
4484
+ if (registeredProxyAgent) {
4485
+ provisionalAgentCache.current.delete(resolvedAgentId);
4486
+ return {
4487
+ agent: registeredProxyAgent,
4488
+ isReady: true
4489
+ };
4490
+ }
4491
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
4492
+ if (cached) {
4493
+ copilotkit.applyHeadersToAgent(cached);
4494
+ return {
4495
+ agent: cached,
4496
+ isReady: false
4497
+ };
4498
+ }
4499
+ const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4500
+ runtimeUrl: copilotkit.runtimeUrl,
4501
+ agentId: resolvedAgentId,
4502
+ runtimeAgentId,
4503
+ transport: copilotkit.runtimeTransport,
4504
+ runtimeMode: "pending"
4505
+ });
4506
+ copilotkit.applyHeadersToAgent(provisional);
4507
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
4508
+ return {
4509
+ agent: provisional,
4510
+ isReady: false
4511
+ };
4512
+ }
4434
4513
  const existing = copilotkit.getAgent(resolvedAgentId);
4435
4514
  if (existing) {
4436
4515
  provisionalAgentCache.current.delete(resolvedAgentId);
@@ -4486,6 +4565,8 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4486
4565
  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.");
4487
4566
  }, [
4488
4567
  resolvedAgentId,
4568
+ runtimeAgentId,
4569
+ registeredProxyAgent,
4489
4570
  copilotkit.agents,
4490
4571
  copilotkit.runtimeConnectionStatus,
4491
4572
  copilotkit.runtimeUrl,
@@ -4538,14 +4619,11 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4538
4619
  ]);
4539
4620
  const configThreadId = chatConfig?.threadId;
4540
4621
  const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
4622
+ const resolvedThreadId = threadId ?? (configHasExplicitThreadId ? configThreadId : void 0);
4541
4623
  (0, react.useEffect)(() => {
4542
- if (!configHasExplicitThreadId || !configThreadId) return;
4543
- agent.threadId = configThreadId;
4544
- }, [
4545
- agent,
4546
- configThreadId,
4547
- configHasExplicitThreadId
4548
- ]);
4624
+ if (!resolvedThreadId) return;
4625
+ agent.threadId = resolvedThreadId;
4626
+ }, [agent, resolvedThreadId]);
4549
4627
  return {
4550
4628
  agent,
4551
4629
  isReady
@@ -12189,4 +12267,4 @@ Object.defineProperty(exports, 'ɵrunMcpFollowUp', {
12189
12267
  return ɵrunMcpFollowUp;
12190
12268
  }
12191
12269
  });
12192
- //# sourceMappingURL=copilotkit-DiLTL1ZM.cjs.map
12270
+ //# sourceMappingURL=copilotkit-2v7ami2b.cjs.map