@copilotkit/react-core 1.62.2-canary.1783457132 → 1.62.3

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, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesRealtimeStatus, ɵ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";
@@ -4352,57 +4352,58 @@ const ALL_UPDATES = [
4352
4352
  UseAgentUpdate.OnRunStatusChanged
4353
4353
  ];
4354
4354
  function useAgent({ agentId, updates, throttleMs } = {}) {
4355
- agentId ??= DEFAULT_AGENT_ID;
4355
+ const chatConfig = useCopilotChatConfiguration();
4356
+ const resolvedAgentId = agentId ?? chatConfig?.agentId ?? DEFAULT_AGENT_ID;
4356
4357
  const { copilotkit } = useCopilotKit();
4357
4358
  const providerThrottleMs = copilotkit.defaultThrottleMs;
4358
4359
  const [, forceUpdate] = useReducer((x) => x + 1, 0);
4359
4360
  const updateFlags = useMemo(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
4360
4361
  const provisionalAgentCache = useRef(/* @__PURE__ */ new Map());
4361
4362
  const agent = useMemo(() => {
4362
- const existing = copilotkit.getAgent(agentId);
4363
+ const existing = copilotkit.getAgent(resolvedAgentId);
4363
4364
  if (existing) {
4364
- provisionalAgentCache.current.delete(agentId);
4365
+ provisionalAgentCache.current.delete(resolvedAgentId);
4365
4366
  return existing;
4366
4367
  }
4367
4368
  const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
4368
4369
  const status = copilotkit.runtimeConnectionStatus;
4369
4370
  if (isRuntimeConfigured && (status === CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
4370
- const cached = provisionalAgentCache.current.get(agentId);
4371
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
4371
4372
  if (cached) {
4372
4373
  copilotkit.applyHeadersToAgent(cached);
4373
4374
  return cached;
4374
4375
  }
4375
4376
  const provisional = new ProxiedCopilotRuntimeAgent({
4376
4377
  runtimeUrl: copilotkit.runtimeUrl,
4377
- agentId,
4378
+ agentId: resolvedAgentId,
4378
4379
  transport: copilotkit.runtimeTransport,
4379
4380
  runtimeMode: "pending"
4380
4381
  });
4381
4382
  copilotkit.applyHeadersToAgent(provisional);
4382
- provisionalAgentCache.current.set(agentId, provisional);
4383
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
4383
4384
  return provisional;
4384
4385
  }
4385
4386
  if (isRuntimeConfigured && status === CopilotKitCoreRuntimeConnectionStatus.Error) {
4386
- const cached = provisionalAgentCache.current.get(agentId);
4387
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
4387
4388
  if (cached) {
4388
4389
  copilotkit.applyHeadersToAgent(cached);
4389
4390
  return cached;
4390
4391
  }
4391
4392
  const provisional = new ProxiedCopilotRuntimeAgent({
4392
4393
  runtimeUrl: copilotkit.runtimeUrl,
4393
- agentId,
4394
+ agentId: resolvedAgentId,
4394
4395
  transport: copilotkit.runtimeTransport,
4395
4396
  runtimeMode: "pending"
4396
4397
  });
4397
4398
  copilotkit.applyHeadersToAgent(provisional);
4398
- provisionalAgentCache.current.set(agentId, provisional);
4399
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
4399
4400
  return provisional;
4400
4401
  }
4401
4402
  const knownAgents = Object.keys(copilotkit.agents ?? {});
4402
4403
  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.");
4404
+ 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
4405
  }, [
4405
- agentId,
4406
+ resolvedAgentId,
4406
4407
  copilotkit.agents,
4407
4408
  copilotkit.runtimeConnectionStatus,
4408
4409
  copilotkit.runtimeUrl,
@@ -4447,7 +4448,6 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4447
4448
  useEffect(() => {
4448
4449
  if (agent instanceof HttpAgent) copilotkit.applyHeadersToAgent(agent);
4449
4450
  }, [agent, JSON.stringify(copilotkit.headers)]);
4450
- const chatConfig = useCopilotChatConfiguration();
4451
4451
  const configThreadId = chatConfig?.threadId;
4452
4452
  const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
4453
4453
  useEffect(() => {
@@ -4464,13 +4464,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4464
4464
  //#endregion
4465
4465
  //#region src/v2/hooks/use-capabilities.tsx
4466
4466
  /**
4467
- * Returns the capabilities declared by the given agent (or the default agent).
4467
+ * Returns the capabilities declared by the given agent (or the agent resolved
4468
+ * from the surrounding chat configuration, falling back to the default agent).
4468
4469
  * Capabilities are populated from the runtime `/info` response at connection
4469
4470
  * time. The hook reads them synchronously from the agent instance — there is
4470
4471
  * no separate loading state, but the value will be `undefined` until the
4471
4472
  * runtime handshake completes.
4472
4473
  *
4473
- * @param agentId - Optional agent ID. If omitted, uses the default agent.
4474
+ * @param agentId - Optional agent ID. If omitted, inherits the surrounding
4475
+ * chat configuration's agent, falling back to the default agent.
4474
4476
  * @returns The agent's capabilities, or `undefined` if the agent doesn't
4475
4477
  * declare capabilities.
4476
4478
  */
@@ -5043,6 +5045,7 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5043
5045
  })), [coreThreads]);
5044
5046
  const storeIsLoading = useThreadStoreSelector(store, ɵselectThreadsIsLoading);
5045
5047
  const storeError = useThreadStoreSelector(store, ɵselectThreadsError);
5048
+ const fetchMoreError = useThreadStoreSelector(store, ɵselectFetchMoreError);
5046
5049
  const hasMoreThreads = useThreadStoreSelector(store, ɵselectHasNextPage);
5047
5050
  const isFetchingMoreThreads = useThreadStoreSelector(store, ɵselectIsFetchingNextPage);
5048
5051
  const isMutating = useThreadStoreSelector(store, ɵselectIsMutating);
@@ -5148,6 +5151,7 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5148
5151
  isLoading,
5149
5152
  error,
5150
5153
  listError,
5154
+ fetchMoreError,
5151
5155
  hasMoreThreads,
5152
5156
  isFetchingMoreThreads,
5153
5157
  isMutating,
@@ -9089,7 +9093,7 @@ function findChatInput(origin) {
9089
9093
  * during prerender to avoid hydration mismatch).
9090
9094
  * - Feeds the element domain data: `threads`, `loading`, `error`,
9091
9095
  * `activeThreadId`, `licensed`, fetch-more state.
9092
- * - Routes the element's nine outbound events to core thread operations
9096
+ * - Routes the element's outbound events to core thread operations
9093
9097
  * ({@link useThreads}) and chat-configuration changes.
9094
9098
  * - Registers with the surrounding chat configuration so the header
9095
9099
  * thread-list launcher appears, and binds the element `open` state to the
@@ -9116,16 +9120,16 @@ function findChatInput(origin) {
9116
9120
  * </CopilotKitProvider>
9117
9121
  * ```
9118
9122
  */
9119
- function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed, licenseUrl, renderRow, label, limit, "data-testid": dataTestId = "copilot-threads-drawer" }) {
9123
+ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed, licenseUrl, renderRow, label, recentLabel, collapsible, onCollapseChange, limit, "data-testid": dataTestId = "copilot-threads-drawer" }) {
9120
9124
  const configuration = useCopilotChatConfiguration();
9121
9125
  const { status, checkFeature } = useLicenseContext();
9122
9126
  const licensePresent = status === "valid" || status === "expiring";
9123
9127
  const featureLicensed = checkFeature("threads");
9124
9128
  const licensed = licensePresent && featureLicensed;
9125
9129
  const licensePending = status === null;
9126
- const resolvedAgentId = agentId ?? configuration?.agentId ?? "default";
9130
+ const resolvedAgentId = agentId ?? configuration?.agentId ?? DEFAULT_AGENT_ID;
9127
9131
  const activeThreadId = configuration?.threadId ?? null;
9128
- const { threads, isLoading, listError, hasMoreThreads, isFetchingMoreThreads, archiveThread, unarchiveThread, deleteThread, fetchMoreThreads, refetchThreads, startNewThread } = useThreads$1({
9132
+ const { threads, isLoading, listError, fetchMoreError, hasMoreThreads, isFetchingMoreThreads, archiveThread, unarchiveThread, deleteThread, fetchMoreThreads, refetchThreads, startNewThread } = useThreads$1({
9129
9133
  agentId: resolvedAgentId,
9130
9134
  includeArchived: true,
9131
9135
  enabled: licensed,
@@ -9206,6 +9210,9 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9206
9210
  const handleLoadMore = useCallback(() => {
9207
9211
  fetchMoreThreads();
9208
9212
  }, [fetchMoreThreads]);
9213
+ const handleCollapseChange = useCallback((collapsed) => {
9214
+ onCollapseChange?.(collapsed);
9215
+ }, [onCollapseChange]);
9209
9216
  const handlersRef = useRef({
9210
9217
  handleThreadSelected,
9211
9218
  handleNewThread,
@@ -9216,7 +9223,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9216
9223
  handleRetry,
9217
9224
  handleOpenChange,
9218
9225
  handleLicensed,
9219
- handleLoadMore
9226
+ handleLoadMore,
9227
+ handleCollapseChange
9220
9228
  });
9221
9229
  handlersRef.current = {
9222
9230
  handleThreadSelected,
@@ -9228,7 +9236,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9228
9236
  handleRetry,
9229
9237
  handleOpenChange,
9230
9238
  handleLicensed,
9231
- handleLoadMore
9239
+ handleLoadMore,
9240
+ handleCollapseChange
9232
9241
  };
9233
9242
  useEffect(() => {
9234
9243
  const el = elementRef.current;
@@ -9263,6 +9272,10 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9263
9272
  };
9264
9273
  const onLicensedEvent = () => handlersRef.current.handleLicensed();
9265
9274
  const onLoadMore = () => handlersRef.current.handleLoadMore();
9275
+ const onCollapseChangeEvent = (event) => {
9276
+ const detail = event.detail;
9277
+ handlersRef.current.handleCollapseChange(detail.collapsed);
9278
+ };
9266
9279
  el.addEventListener("thread-selected", onThreadSelected);
9267
9280
  el.addEventListener("new-thread", onNewThreadEvent);
9268
9281
  el.addEventListener("archive", onArchive);
@@ -9273,6 +9286,7 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9273
9286
  el.addEventListener("retry", onRetry);
9274
9287
  el.addEventListener("licensed", onLicensedEvent);
9275
9288
  el.addEventListener("load-more", onLoadMore);
9289
+ el.addEventListener("collapse-change", onCollapseChangeEvent);
9276
9290
  return () => {
9277
9291
  el.removeEventListener("thread-selected", onThreadSelected);
9278
9292
  el.removeEventListener("new-thread", onNewThreadEvent);
@@ -9284,6 +9298,7 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9284
9298
  el.removeEventListener("retry", onRetry);
9285
9299
  el.removeEventListener("licensed", onLicensedEvent);
9286
9300
  el.removeEventListener("load-more", onLoadMore);
9301
+ el.removeEventListener("collapse-change", onCollapseChangeEvent);
9287
9302
  };
9288
9303
  }, [mounted]);
9289
9304
  useEffect(() => {
@@ -9300,9 +9315,11 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9300
9315
  el.licensed = licensed || licensePending;
9301
9316
  el.hasMore = hasMoreThreads;
9302
9317
  el.fetchingMore = isFetchingMoreThreads;
9318
+ el.fetchMoreError = fetchMoreError ? fetchMoreError.message : null;
9303
9319
  }, [
9304
9320
  isLoading,
9305
9321
  listError,
9322
+ fetchMoreError,
9306
9323
  activeThreadId,
9307
9324
  licensed,
9308
9325
  licensePending,
@@ -9325,6 +9342,11 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9325
9342
  if (!el) return;
9326
9343
  if (licenseUrl !== void 0) el.licenseUrl = licenseUrl;
9327
9344
  }, [licenseUrl, mounted]);
9345
+ useEffect(() => {
9346
+ const el = elementRef.current;
9347
+ if (!el) return;
9348
+ if (collapsible !== void 0) el.collapsible = collapsible;
9349
+ }, [collapsible, mounted]);
9328
9350
  const rowChildren = useMemo(() => {
9329
9351
  if (!renderRow) return null;
9330
9352
  return drawerThreads.map((drawerThread) => {
@@ -9345,7 +9367,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9345
9367
  if (!mounted) return null;
9346
9368
  return React.createElement(COPILOTKIT_THREADS_DRAWER_TAG, {
9347
9369
  ref: elementRef,
9348
- "data-testid": dataTestId
9370
+ "data-testid": dataTestId,
9371
+ ...recentLabel !== void 0 ? { "recent-label": recentLabel } : {}
9349
9372
  }, rowChildren);
9350
9373
  }
9351
9374
  CopilotThreadsDrawer.displayName = "CopilotThreadsDrawer";
@@ -10998,8 +11021,18 @@ const usePredictStateSubscription = (agent) => {
10998
11021
  }, [agent, getSubscriber]);
10999
11022
  };
11000
11023
  function CopilotListenersAgentSubscription() {
11001
- const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
11002
- const { agent } = useAgent({ agentId: resolvedAgentId });
11024
+ const { copilotkit } = useCopilotKit();
11025
+ const configAgentId = useCopilotChatConfiguration()?.agentId;
11026
+ const { agent } = useAgent({ agentId: useMemo(() => {
11027
+ const requested = configAgentId ?? DEFAULT_AGENT_ID;
11028
+ const registered = copilotkit.agents ?? {};
11029
+ if (registered[requested]) return requested;
11030
+ if (requested === DEFAULT_AGENT_ID) {
11031
+ const firstRegistered = Object.keys(registered)[0];
11032
+ if (firstRegistered) return firstRegistered;
11033
+ }
11034
+ return requested;
11035
+ }, [configAgentId, copilotkit.agents]) });
11003
11036
  usePredictStateSubscription(agent);
11004
11037
  return null;
11005
11038
  }
@@ -11533,4 +11566,4 @@ function validateProps(props) {
11533
11566
 
11534
11567
  //#endregion
11535
11568
  export { useCapabilities as $, CopilotChatMessageView as A, CopilotChatAssistantMessage_default as B, CopilotModalHeader as C, CopilotChatAudioRecorder as Ct, CopilotChat as D, DefaultOpenIcon as E, 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, IntelligenceIndicatorView as P, useAgentContext as Q, CopilotChatUserMessage_default as R, CopilotSidebarView as S, AudioRecorderError as St, DefaultCloseIcon as T, useCopilotChatConfiguration as Tt, useLearningContainers as U, CopilotChatToolCallsView as V, useAttachments as W, useConfigureSuggestions as X, useInterrupt as Y, useSuggestions as Z, WildcardToolCallRender as _, CopilotKitInspector as _t, ThreadsProvider as a, useComponent as at, CopilotSidebar as b, CopilotKitCoreReact as bt, CoAgentStateRendersProvider as c, useRenderCustomMessages as ct, shouldShowDevConsole as d, createA2UIMessageRenderer as dt, UseAgentUpdate as et, useToast as f, SandboxFunctionsContext as ft, useCopilotContext as g, MCPAppsActivityType as gt, CopilotContext as h, MCPAppsActivityRenderer as ht, ThreadsContext as i, useRenderTool as it, INTELLIGENCE_TURN_HEAD as j, CopilotChatAttachmentQueue as k, useCoAgentStateRenders as l, CopilotKitProvider as lt, useCopilotMessagesContext as m, MCPAppsActivityContentSchema as mt, defaultCopilotContextCategories as n, useHumanInTheLoop as nt, useThreads as o, useFrontendTool as ot, CopilotMessagesContext as p, useSandboxFunctions 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, useRenderToolCall as vt, CopilotChatToggleButton as w, CopilotChatConfigurationProvider as wt, CopilotPopupView as x, CopilotChatInput_default as xt, CopilotPopup as y, useCopilotKit as yt, CopilotChatAttachmentRenderer as z };
11536
- //# sourceMappingURL=copilotkit-BQT2ngSh.mjs.map
11569
+ //# sourceMappingURL=copilotkit-ympAovXs.mjs.map