@copilotkit/react-core 1.62.2 → 1.63.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.
@@ -1,6 +1,6 @@
1
1
  import * as React$1 from "react";
2
2
  import React, { createContext, forwardRef, memo, useCallback, useContext, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
3
- import { CopilotKitCore, CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, isRunCompletionAware, ɵcreateThreadStore, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
3
+ import { CopilotKitCore, CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, ToolCallStatus, isRunCompletionAware, ɵcreateThreadStore, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading } from "@copilotkit/core";
4
4
  import { HttpAgent, buildResumeArray, isInterruptExpired, randomUUID } from "@ag-ui/client";
5
5
  import { extendTailwindMerge, twMerge } from "tailwind-merge";
6
6
  import { ArrowUp, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronRightIcon, Copy, Edit, Loader2, MessageCircle, Mic, PanelLeftOpen, Play, Plus, RefreshCw, Square, ThumbsDown, ThumbsUp, Upload, Volume2, X } from "lucide-react";
@@ -1800,6 +1800,34 @@ function InlineFeatureWarning({ featureName }) {
1800
1800
 
1801
1801
  //#endregion
1802
1802
  //#region src/v2/components/MCPAppsActivityRenderer.tsx
1803
+ /**
1804
+ * Run an MCP app `ui/message` follow-up, scoped to the thread it was enqueued
1805
+ * for (issue #5819).
1806
+ *
1807
+ * The MCP request queue delays follow-up work until the agent is idle. There is
1808
+ * a single shared registry agent per id, and switching threads overwrites its
1809
+ * `threadId`/`messages` in place. So if the host switches threads while a
1810
+ * follow-up is queued, running it now would execute against — and stream into —
1811
+ * the now-foreground thread.
1812
+ *
1813
+ * - **Same thread** (the common case): run on the shared agent, unchanged.
1814
+ * - **Thread changed**: the shared agent has moved on, so the follow-up can no
1815
+ * longer run in its originating thread's context. Drop it rather than leak it
1816
+ * into the current thread. (The MCP app already received its `ui/message` ack
1817
+ * at enqueue time; only the optional agent turn is skipped.)
1818
+ *
1819
+ * @internal exported for testing.
1820
+ */
1821
+ async function ɵrunMcpFollowUp({ host, agent, capturedThreadId }) {
1822
+ const currentThreadId = agent.threadId || "default";
1823
+ const originThreadId = capturedThreadId || "default";
1824
+ if (currentThreadId === originThreadId) return host.runAgent({ agent });
1825
+ console.warn(`[MCPAppsRenderer] ui/message follow-up dropped: the thread changed (${originThreadId} → ${currentThreadId}) between enqueue and execution, so running it would leak into the now-foreground thread.`);
1826
+ return {
1827
+ result: void 0,
1828
+ newMessages: []
1829
+ };
1830
+ }
1803
1831
  const PROTOCOL_VERSION = "2025-06-18";
1804
1832
  function buildSandboxHTML(extraCspDomains) {
1805
1833
  const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
@@ -2122,7 +2150,14 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
2122
2150
  content: textContent
2123
2151
  });
2124
2152
  sendResponse(msg.id, { isError: false });
2125
- if ((params.followUp ?? role === "user") && textContent) mcpAppsRequestQueue.enqueue(currentAgent, () => copilotkit.runAgent({ agent: currentAgent })).catch((err) => console.error("[MCPAppsRenderer] ui/message agent run failed:", err));
2153
+ if ((params.followUp ?? role === "user") && textContent) {
2154
+ const capturedThreadId = currentAgent.threadId || "default";
2155
+ mcpAppsRequestQueue.enqueue(currentAgent, () => ɵrunMcpFollowUp({
2156
+ host: copilotkit,
2157
+ agent: currentAgent,
2158
+ capturedThreadId
2159
+ })).catch((err) => console.error("[MCPAppsRenderer] ui/message agent run failed:", err));
2160
+ }
2126
2161
  } catch (err) {
2127
2162
  console.error("[MCPAppsRenderer] ui/message error:", err);
2128
2163
  sendResponse(msg.id, { isError: true });
@@ -3605,6 +3640,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3605
3640
  if (copilotkitRef.current === null) {
3606
3641
  copilotkitRef.current = new CopilotKitCoreReact({
3607
3642
  runtimeUrl: chatApiEndpoint,
3643
+ deferInitialConnection: true,
3608
3644
  runtimeTransport: useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto",
3609
3645
  headers: mergedHeaders,
3610
3646
  credentials,
@@ -3688,6 +3724,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3688
3724
  } : properties);
3689
3725
  copilotkit.setAgents__unsafe_dev_only(mergedAgents);
3690
3726
  copilotkit.setDebug(debug);
3727
+ copilotkit.connect();
3691
3728
  }, [
3692
3729
  copilotkit,
3693
3730
  chatApiEndpoint,
@@ -4352,57 +4389,58 @@ const ALL_UPDATES = [
4352
4389
  UseAgentUpdate.OnRunStatusChanged
4353
4390
  ];
4354
4391
  function useAgent({ agentId, updates, throttleMs } = {}) {
4355
- agentId ??= DEFAULT_AGENT_ID;
4392
+ const chatConfig = useCopilotChatConfiguration();
4393
+ const resolvedAgentId = agentId ?? chatConfig?.agentId ?? DEFAULT_AGENT_ID;
4356
4394
  const { copilotkit } = useCopilotKit();
4357
4395
  const providerThrottleMs = copilotkit.defaultThrottleMs;
4358
4396
  const [, forceUpdate] = useReducer((x) => x + 1, 0);
4359
4397
  const updateFlags = useMemo(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
4360
4398
  const provisionalAgentCache = useRef(/* @__PURE__ */ new Map());
4361
4399
  const agent = useMemo(() => {
4362
- const existing = copilotkit.getAgent(agentId);
4400
+ const existing = copilotkit.getAgent(resolvedAgentId);
4363
4401
  if (existing) {
4364
- provisionalAgentCache.current.delete(agentId);
4402
+ provisionalAgentCache.current.delete(resolvedAgentId);
4365
4403
  return existing;
4366
4404
  }
4367
4405
  const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
4368
4406
  const status = copilotkit.runtimeConnectionStatus;
4369
4407
  if (isRuntimeConfigured && (status === CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
4370
- const cached = provisionalAgentCache.current.get(agentId);
4408
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
4371
4409
  if (cached) {
4372
4410
  copilotkit.applyHeadersToAgent(cached);
4373
4411
  return cached;
4374
4412
  }
4375
4413
  const provisional = new ProxiedCopilotRuntimeAgent({
4376
4414
  runtimeUrl: copilotkit.runtimeUrl,
4377
- agentId,
4415
+ agentId: resolvedAgentId,
4378
4416
  transport: copilotkit.runtimeTransport,
4379
4417
  runtimeMode: "pending"
4380
4418
  });
4381
4419
  copilotkit.applyHeadersToAgent(provisional);
4382
- provisionalAgentCache.current.set(agentId, provisional);
4420
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
4383
4421
  return provisional;
4384
4422
  }
4385
4423
  if (isRuntimeConfigured && status === CopilotKitCoreRuntimeConnectionStatus.Error) {
4386
- const cached = provisionalAgentCache.current.get(agentId);
4424
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
4387
4425
  if (cached) {
4388
4426
  copilotkit.applyHeadersToAgent(cached);
4389
4427
  return cached;
4390
4428
  }
4391
4429
  const provisional = new ProxiedCopilotRuntimeAgent({
4392
4430
  runtimeUrl: copilotkit.runtimeUrl,
4393
- agentId,
4431
+ agentId: resolvedAgentId,
4394
4432
  transport: copilotkit.runtimeTransport,
4395
4433
  runtimeMode: "pending"
4396
4434
  });
4397
4435
  copilotkit.applyHeadersToAgent(provisional);
4398
- provisionalAgentCache.current.set(agentId, provisional);
4436
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
4399
4437
  return provisional;
4400
4438
  }
4401
4439
  const knownAgents = Object.keys(copilotkit.agents ?? {});
4402
4440
  const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
4403
- throw new Error(`useAgent: Agent '${agentId}' 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.");
4441
+ 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.");
4404
4442
  }, [
4405
- agentId,
4443
+ resolvedAgentId,
4406
4444
  copilotkit.agents,
4407
4445
  copilotkit.runtimeConnectionStatus,
4408
4446
  copilotkit.runtimeUrl,
@@ -4447,7 +4485,6 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4447
4485
  useEffect(() => {
4448
4486
  if (agent instanceof HttpAgent) copilotkit.applyHeadersToAgent(agent);
4449
4487
  }, [agent, JSON.stringify(copilotkit.headers)]);
4450
- const chatConfig = useCopilotChatConfiguration();
4451
4488
  const configThreadId = chatConfig?.threadId;
4452
4489
  const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
4453
4490
  useEffect(() => {
@@ -4464,13 +4501,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4464
4501
  //#endregion
4465
4502
  //#region src/v2/hooks/use-capabilities.tsx
4466
4503
  /**
4467
- * Returns the capabilities declared by the given agent (or the default agent).
4504
+ * Returns the capabilities declared by the given agent (or the agent resolved
4505
+ * from the surrounding chat configuration, falling back to the default agent).
4468
4506
  * Capabilities are populated from the runtime `/info` response at connection
4469
4507
  * time. The hook reads them synchronously from the agent instance — there is
4470
4508
  * no separate loading state, but the value will be `undefined` until the
4471
4509
  * runtime handshake completes.
4472
4510
  *
4473
- * @param agentId - Optional agent ID. If omitted, uses the default agent.
4511
+ * @param agentId - Optional agent ID. If omitted, inherits the surrounding
4512
+ * chat configuration's agent, falling back to the default agent.
4474
4513
  * @returns The agent's capabilities, or `undefined` if the agent doesn't
4475
4514
  * declare capabilities.
4476
4515
  */
@@ -5043,6 +5082,7 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5043
5082
  })), [coreThreads]);
5044
5083
  const storeIsLoading = useThreadStoreSelector(store, ɵselectThreadsIsLoading);
5045
5084
  const storeError = useThreadStoreSelector(store, ɵselectThreadsError);
5085
+ const fetchMoreError = useThreadStoreSelector(store, ɵselectFetchMoreError);
5046
5086
  const hasMoreThreads = useThreadStoreSelector(store, ɵselectHasNextPage);
5047
5087
  const isFetchingMoreThreads = useThreadStoreSelector(store, ɵselectIsFetchingNextPage);
5048
5088
  const isMutating = useThreadStoreSelector(store, ɵselectIsMutating);
@@ -5148,6 +5188,7 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5148
5188
  isLoading,
5149
5189
  error,
5150
5190
  listError,
5191
+ fetchMoreError,
5151
5192
  hasMoreThreads,
5152
5193
  isFetchingMoreThreads,
5153
5194
  isMutating,
@@ -5164,6 +5205,70 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5164
5205
  };
5165
5206
  }
5166
5207
 
5208
+ //#endregion
5209
+ //#region src/v2/hooks/use-memories.tsx
5210
+ function useMemoryStoreSelector(store, selector) {
5211
+ return useSyncExternalStore(useCallback((onStoreChange) => {
5212
+ const subscription = store.select(selector).subscribe(onStoreChange);
5213
+ return () => subscription.unsubscribe();
5214
+ }, [store, selector]), () => selector(store.getState()), () => selector(store.getServerState()));
5215
+ }
5216
+ /**
5217
+ * React hook for listing and managing platform memories.
5218
+ *
5219
+ * Reads the memory store owned and wired by `CopilotKitCore`. On mount the
5220
+ * hook exposes the live list plus stable `addMemory` / `updateMemory` /
5221
+ * `removeMemory` / `refresh` callbacks. Mutations are server-authoritative:
5222
+ * each resolves once the platform confirms the operation and rejects with an
5223
+ * `Error` on failure.
5224
+ *
5225
+ * Realtime updates are automatic: the core's memory store opens its own
5226
+ * `user_meta:memories:<joinCode>` channel and applies `memory_metadata` deltas
5227
+ * to the list. You can still call `refresh()` to re-pull the REST snapshot on
5228
+ * demand.
5229
+ *
5230
+ * @returns Memory list state and stable mutation callbacks.
5231
+ *
5232
+ * @example
5233
+ * ```tsx
5234
+ * import { useMemories } from "@copilotkit/react-core";
5235
+ *
5236
+ * function MemoryList() {
5237
+ * const { memories, isLoading, isAvailable, addMemory, removeMemory } =
5238
+ * useMemories();
5239
+ *
5240
+ * if (!isAvailable) return null;
5241
+ * if (isLoading) return <p>Loading…</p>;
5242
+ *
5243
+ * return (
5244
+ * <ul>
5245
+ * {memories.map((m) => (
5246
+ * <li key={m.id}>
5247
+ * {m.content}
5248
+ * <button onClick={() => removeMemory(m.id)}>Delete</button>
5249
+ * </li>
5250
+ * ))}
5251
+ * </ul>
5252
+ * );
5253
+ * }
5254
+ * ```
5255
+ */
5256
+ function useMemories() {
5257
+ const { copilotkit } = useCopilotKit();
5258
+ const store = copilotkit.getMemoryStore();
5259
+ return {
5260
+ memories: useMemoryStoreSelector(store, ɵselectMemories),
5261
+ isLoading: useMemoryStoreSelector(store, ɵselectMemoriesIsLoading),
5262
+ error: useMemoryStoreSelector(store, ɵselectMemoriesError),
5263
+ isAvailable: useMemoryStoreSelector(store, ɵselectMemoriesAvailable),
5264
+ realtimeStatus: useMemoryStoreSelector(store, ɵselectMemoriesRealtimeStatus),
5265
+ refresh: useCallback(() => store.refresh(), [store]),
5266
+ addMemory: useCallback((input) => store.addMemory(input), [store]),
5267
+ updateMemory: useCallback((id, changes) => store.updateMemory(id, changes), [store]),
5268
+ removeMemory: useCallback((id) => store.removeMemory(id), [store])
5269
+ };
5270
+ }
5271
+
5167
5272
  //#endregion
5168
5273
  //#region src/v2/lib/record-annotation.ts
5169
5274
  /**
@@ -9025,7 +9130,7 @@ function findChatInput(origin) {
9025
9130
  * during prerender to avoid hydration mismatch).
9026
9131
  * - Feeds the element domain data: `threads`, `loading`, `error`,
9027
9132
  * `activeThreadId`, `licensed`, fetch-more state.
9028
- * - Routes the element's nine outbound events to core thread operations
9133
+ * - Routes the element's outbound events to core thread operations
9029
9134
  * ({@link useThreads}) and chat-configuration changes.
9030
9135
  * - Registers with the surrounding chat configuration so the header
9031
9136
  * thread-list launcher appears, and binds the element `open` state to the
@@ -9052,16 +9157,16 @@ function findChatInput(origin) {
9052
9157
  * </CopilotKitProvider>
9053
9158
  * ```
9054
9159
  */
9055
- function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed, licenseUrl, renderRow, label, limit, "data-testid": dataTestId = "copilot-threads-drawer" }) {
9160
+ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed, licenseUrl, renderRow, label, recentLabel, collapsible, onCollapseChange, limit, "data-testid": dataTestId = "copilot-threads-drawer" }) {
9056
9161
  const configuration = useCopilotChatConfiguration();
9057
9162
  const { status, checkFeature } = useLicenseContext();
9058
9163
  const licensePresent = status === "valid" || status === "expiring";
9059
9164
  const featureLicensed = checkFeature("threads");
9060
9165
  const licensed = licensePresent && featureLicensed;
9061
9166
  const licensePending = status === null;
9062
- const resolvedAgentId = agentId ?? configuration?.agentId ?? "default";
9167
+ const resolvedAgentId = agentId ?? configuration?.agentId ?? DEFAULT_AGENT_ID;
9063
9168
  const activeThreadId = configuration?.threadId ?? null;
9064
- const { threads, isLoading, listError, hasMoreThreads, isFetchingMoreThreads, archiveThread, unarchiveThread, deleteThread, fetchMoreThreads, refetchThreads, startNewThread } = useThreads$1({
9169
+ const { threads, isLoading, listError, fetchMoreError, hasMoreThreads, isFetchingMoreThreads, archiveThread, unarchiveThread, deleteThread, fetchMoreThreads, refetchThreads, startNewThread } = useThreads$1({
9065
9170
  agentId: resolvedAgentId,
9066
9171
  includeArchived: true,
9067
9172
  enabled: licensed,
@@ -9142,6 +9247,9 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9142
9247
  const handleLoadMore = useCallback(() => {
9143
9248
  fetchMoreThreads();
9144
9249
  }, [fetchMoreThreads]);
9250
+ const handleCollapseChange = useCallback((collapsed) => {
9251
+ onCollapseChange?.(collapsed);
9252
+ }, [onCollapseChange]);
9145
9253
  const handlersRef = useRef({
9146
9254
  handleThreadSelected,
9147
9255
  handleNewThread,
@@ -9152,7 +9260,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9152
9260
  handleRetry,
9153
9261
  handleOpenChange,
9154
9262
  handleLicensed,
9155
- handleLoadMore
9263
+ handleLoadMore,
9264
+ handleCollapseChange
9156
9265
  });
9157
9266
  handlersRef.current = {
9158
9267
  handleThreadSelected,
@@ -9164,7 +9273,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9164
9273
  handleRetry,
9165
9274
  handleOpenChange,
9166
9275
  handleLicensed,
9167
- handleLoadMore
9276
+ handleLoadMore,
9277
+ handleCollapseChange
9168
9278
  };
9169
9279
  useEffect(() => {
9170
9280
  const el = elementRef.current;
@@ -9199,6 +9309,10 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9199
9309
  };
9200
9310
  const onLicensedEvent = () => handlersRef.current.handleLicensed();
9201
9311
  const onLoadMore = () => handlersRef.current.handleLoadMore();
9312
+ const onCollapseChangeEvent = (event) => {
9313
+ const detail = event.detail;
9314
+ handlersRef.current.handleCollapseChange(detail.collapsed);
9315
+ };
9202
9316
  el.addEventListener("thread-selected", onThreadSelected);
9203
9317
  el.addEventListener("new-thread", onNewThreadEvent);
9204
9318
  el.addEventListener("archive", onArchive);
@@ -9209,6 +9323,7 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9209
9323
  el.addEventListener("retry", onRetry);
9210
9324
  el.addEventListener("licensed", onLicensedEvent);
9211
9325
  el.addEventListener("load-more", onLoadMore);
9326
+ el.addEventListener("collapse-change", onCollapseChangeEvent);
9212
9327
  return () => {
9213
9328
  el.removeEventListener("thread-selected", onThreadSelected);
9214
9329
  el.removeEventListener("new-thread", onNewThreadEvent);
@@ -9220,6 +9335,7 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9220
9335
  el.removeEventListener("retry", onRetry);
9221
9336
  el.removeEventListener("licensed", onLicensedEvent);
9222
9337
  el.removeEventListener("load-more", onLoadMore);
9338
+ el.removeEventListener("collapse-change", onCollapseChangeEvent);
9223
9339
  };
9224
9340
  }, [mounted]);
9225
9341
  useEffect(() => {
@@ -9236,9 +9352,11 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9236
9352
  el.licensed = licensed || licensePending;
9237
9353
  el.hasMore = hasMoreThreads;
9238
9354
  el.fetchingMore = isFetchingMoreThreads;
9355
+ el.fetchMoreError = fetchMoreError ? fetchMoreError.message : null;
9239
9356
  }, [
9240
9357
  isLoading,
9241
9358
  listError,
9359
+ fetchMoreError,
9242
9360
  activeThreadId,
9243
9361
  licensed,
9244
9362
  licensePending,
@@ -9261,6 +9379,11 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9261
9379
  if (!el) return;
9262
9380
  if (licenseUrl !== void 0) el.licenseUrl = licenseUrl;
9263
9381
  }, [licenseUrl, mounted]);
9382
+ useEffect(() => {
9383
+ const el = elementRef.current;
9384
+ if (!el) return;
9385
+ if (collapsible !== void 0) el.collapsible = collapsible;
9386
+ }, [collapsible, mounted]);
9264
9387
  const rowChildren = useMemo(() => {
9265
9388
  if (!renderRow) return null;
9266
9389
  return drawerThreads.map((drawerThread) => {
@@ -9281,7 +9404,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9281
9404
  if (!mounted) return null;
9282
9405
  return React.createElement(COPILOTKIT_THREADS_DRAWER_TAG, {
9283
9406
  ref: elementRef,
9284
- "data-testid": dataTestId
9407
+ "data-testid": dataTestId,
9408
+ ...recentLabel !== void 0 ? { "recent-label": recentLabel } : {}
9285
9409
  }, rowChildren);
9286
9410
  }
9287
9411
  CopilotThreadsDrawer.displayName = "CopilotThreadsDrawer";
@@ -10934,8 +11058,18 @@ const usePredictStateSubscription = (agent) => {
10934
11058
  }, [agent, getSubscriber]);
10935
11059
  };
10936
11060
  function CopilotListenersAgentSubscription() {
10937
- const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
10938
- const { agent } = useAgent({ agentId: resolvedAgentId });
11061
+ const { copilotkit } = useCopilotKit();
11062
+ const configAgentId = useCopilotChatConfiguration()?.agentId;
11063
+ const { agent } = useAgent({ agentId: useMemo(() => {
11064
+ const requested = configAgentId ?? DEFAULT_AGENT_ID;
11065
+ const registered = copilotkit.agents ?? {};
11066
+ if (registered[requested]) return requested;
11067
+ if (requested === DEFAULT_AGENT_ID) {
11068
+ const firstRegistered = Object.keys(registered)[0];
11069
+ if (firstRegistered) return firstRegistered;
11070
+ }
11071
+ return requested;
11072
+ }, [configAgentId, copilotkit.agents]) });
10939
11073
  usePredictStateSubscription(agent);
10940
11074
  return null;
10941
11075
  }
@@ -11468,5 +11602,5 @@ function validateProps(props) {
11468
11602
  }
11469
11603
 
11470
11604
  //#endregion
11471
- export { UseAgentUpdate as $, CopilotChatMessageView as A, CopilotChatAssistantMessage_default as B, CopilotModalHeader as C, CopilotChatConfigurationProvider as Ct, CopilotChat as D, DefaultOpenIcon as E, CopilotChatSuggestionView as F, useLearnFromUserActionInCurrentThread as G, useLearningContainersInCurrentThread as H, CopilotChatSuggestionPill as I, useInterrupt as J, useLearnFromUserAction as K, CopilotChatReasoningMessage_default as L, IntelligenceIndicator as M, getIntelligenceTurnAnchors as N, CopilotChatView_default as O, IntelligenceIndicatorView as P, useCapabilities as Q, CopilotChatUserMessage_default as R, CopilotSidebarView as S, CopilotChatAudioRecorder as St, DefaultCloseIcon as T, useLearningContainers as U, CopilotChatToolCallsView as V, useAttachments as W, useSuggestions as X, useConfigureSuggestions as Y, useAgentContext as Z, WildcardToolCallRender as _, useRenderToolCall as _t, ThreadsProvider as a, useFrontendTool as at, CopilotSidebar as b, CopilotChatInput_default as bt, CoAgentStateRendersProvider as c, CopilotKitProvider as ct, shouldShowDevConsole as d, SandboxFunctionsContext as dt, useAgent as et, useToast as f, useSandboxFunctions as ft, useCopilotContext as g, CopilotKitInspector as gt, CopilotContext as h, MCPAppsActivityType as ht, ThreadsContext as i, useComponent as it, INTELLIGENCE_TURN_HEAD as j, CopilotChatAttachmentQueue as k, useCoAgentStateRenders as l, defineToolCallRenderer as lt, useCopilotMessagesContext as m, MCPAppsActivityRenderer as mt, defaultCopilotContextCategories as n, useDefaultRenderTool as nt, useThreads as o, useRenderActivityMessage as ot, CopilotMessagesContext as p, MCPAppsActivityContentSchema as pt, useThreads$1 as q, CoAgentStateRenderBridge as r, useRenderTool as rt, CoAgentStateRendersContext as s, useRenderCustomMessages as st, CopilotKit as t, useHumanInTheLoop as tt, useAsyncCallback as u, createA2UIMessageRenderer as ut, CopilotThreadsDrawer as v, useCopilotKit as vt, CopilotChatToggleButton as w, useCopilotChatConfiguration as wt, CopilotPopupView as x, AudioRecorderError as xt, CopilotPopup as y, CopilotKitCoreReact as yt, CopilotChatAttachmentRenderer as z };
11472
- //# sourceMappingURL=copilotkit-CmcMFc8o.mjs.map
11605
+ export { useCapabilities as $, CopilotChatMessageView as A, CopilotChatConfigurationProvider as At, CopilotChatAssistantMessage_default as B, CopilotModalHeader as C, CopilotKitInspector as Ct, CopilotChat as D, CopilotChatInput_default as Dt, DefaultOpenIcon as E, CopilotKitCoreReact as Et, CopilotChatSuggestionView as F, useLearnFromUserActionInCurrentThread as G, useLearningContainersInCurrentThread as H, CopilotChatSuggestionPill as I, useThreads$1 as J, useLearnFromUserAction as K, CopilotChatReasoningMessage_default as L, IntelligenceIndicator as M, getIntelligenceTurnAnchors as N, CopilotChatView_default as O, AudioRecorderError as Ot, IntelligenceIndicatorView as P, useAgentContext as Q, CopilotChatUserMessage_default as R, CopilotSidebarView as S, ɵrunMcpFollowUp as St, DefaultCloseIcon as T, useCopilotKit as Tt, useLearningContainers as U, CopilotChatToolCallsView as V, useAttachments as W, useConfigureSuggestions as X, useInterrupt as Y, useSuggestions as Z, WildcardToolCallRender as _, SandboxFunctionsContext as _t, ThreadsProvider as a, useComponent as at, CopilotSidebar as b, MCPAppsActivityRenderer as bt, CoAgentStateRendersProvider as c, useRenderCustomMessages as ct, shouldShowDevConsole as d, createA2UIMessageRenderer as dt, UseAgentUpdate as et, useToast as f, GenerateSandboxedUiArgsSchema as ft, useCopilotContext as g, OpenGenerativeUIToolRenderer as gt, CopilotContext as h, OpenGenerativeUIContentSchema as ht, ThreadsContext as i, useRenderTool as it, INTELLIGENCE_TURN_HEAD as j, useCopilotChatConfiguration as jt, CopilotChatAttachmentQueue as k, CopilotChatAudioRecorder as kt, useCoAgentStateRenders as l, CopilotKitProvider as lt, useCopilotMessagesContext as m, OpenGenerativeUIActivityType as mt, defaultCopilotContextCategories as n, useHumanInTheLoop as nt, useThreads as o, useFrontendTool as ot, CopilotMessagesContext as p, OpenGenerativeUIActivityRenderer as pt, useMemories as q, CoAgentStateRenderBridge as r, useDefaultRenderTool as rt, CoAgentStateRendersContext as s, useRenderActivityMessage as st, CopilotKit as t, useAgent as tt, useAsyncCallback as u, defineToolCallRenderer as ut, CopilotThreadsDrawer as v, useSandboxFunctions as vt, CopilotChatToggleButton as w, useRenderToolCall as wt, CopilotPopupView as x, MCPAppsActivityType as xt, CopilotPopup as y, MCPAppsActivityContentSchema as yt, CopilotChatAttachmentRenderer as z };
11606
+ //# sourceMappingURL=copilotkit-BLh58_Tt.mjs.map