@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.
@@ -4382,57 +4382,58 @@ const ALL_UPDATES = [
4382
4382
  UseAgentUpdate.OnRunStatusChanged
4383
4383
  ];
4384
4384
  function useAgent({ agentId, updates, throttleMs } = {}) {
4385
- agentId ??= _copilotkit_shared.DEFAULT_AGENT_ID;
4385
+ const chatConfig = useCopilotChatConfiguration();
4386
+ const resolvedAgentId = agentId ?? chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
4386
4387
  const { copilotkit } = useCopilotKit();
4387
4388
  const providerThrottleMs = copilotkit.defaultThrottleMs;
4388
4389
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
4389
4390
  const updateFlags = (0, react.useMemo)(() => updates ?? ALL_UPDATES, [JSON.stringify(updates)]);
4390
4391
  const provisionalAgentCache = (0, react.useRef)(/* @__PURE__ */ new Map());
4391
4392
  const agent = (0, react.useMemo)(() => {
4392
- const existing = copilotkit.getAgent(agentId);
4393
+ const existing = copilotkit.getAgent(resolvedAgentId);
4393
4394
  if (existing) {
4394
- provisionalAgentCache.current.delete(agentId);
4395
+ provisionalAgentCache.current.delete(resolvedAgentId);
4395
4396
  return existing;
4396
4397
  }
4397
4398
  const isRuntimeConfigured = copilotkit.runtimeUrl !== void 0;
4398
4399
  const status = copilotkit.runtimeConnectionStatus;
4399
4400
  if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
4400
- const cached = provisionalAgentCache.current.get(agentId);
4401
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
4401
4402
  if (cached) {
4402
4403
  copilotkit.applyHeadersToAgent(cached);
4403
4404
  return cached;
4404
4405
  }
4405
4406
  const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4406
4407
  runtimeUrl: copilotkit.runtimeUrl,
4407
- agentId,
4408
+ agentId: resolvedAgentId,
4408
4409
  transport: copilotkit.runtimeTransport,
4409
4410
  runtimeMode: "pending"
4410
4411
  });
4411
4412
  copilotkit.applyHeadersToAgent(provisional);
4412
- provisionalAgentCache.current.set(agentId, provisional);
4413
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
4413
4414
  return provisional;
4414
4415
  }
4415
4416
  if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
4416
- const cached = provisionalAgentCache.current.get(agentId);
4417
+ const cached = provisionalAgentCache.current.get(resolvedAgentId);
4417
4418
  if (cached) {
4418
4419
  copilotkit.applyHeadersToAgent(cached);
4419
4420
  return cached;
4420
4421
  }
4421
4422
  const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4422
4423
  runtimeUrl: copilotkit.runtimeUrl,
4423
- agentId,
4424
+ agentId: resolvedAgentId,
4424
4425
  transport: copilotkit.runtimeTransport,
4425
4426
  runtimeMode: "pending"
4426
4427
  });
4427
4428
  copilotkit.applyHeadersToAgent(provisional);
4428
- provisionalAgentCache.current.set(agentId, provisional);
4429
+ provisionalAgentCache.current.set(resolvedAgentId, provisional);
4429
4430
  return provisional;
4430
4431
  }
4431
4432
  const knownAgents = Object.keys(copilotkit.agents ?? {});
4432
4433
  const runtimePart = isRuntimeConfigured ? `runtimeUrl=${copilotkit.runtimeUrl}` : "no runtimeUrl";
4433
- 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.");
4434
+ 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.");
4434
4435
  }, [
4435
- agentId,
4436
+ resolvedAgentId,
4436
4437
  copilotkit.agents,
4437
4438
  copilotkit.runtimeConnectionStatus,
4438
4439
  copilotkit.runtimeUrl,
@@ -4477,7 +4478,6 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4477
4478
  (0, react.useEffect)(() => {
4478
4479
  if (agent instanceof _ag_ui_client.HttpAgent) copilotkit.applyHeadersToAgent(agent);
4479
4480
  }, [agent, JSON.stringify(copilotkit.headers)]);
4480
- const chatConfig = useCopilotChatConfiguration();
4481
4481
  const configThreadId = chatConfig?.threadId;
4482
4482
  const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
4483
4483
  (0, react.useEffect)(() => {
@@ -4494,13 +4494,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4494
4494
  //#endregion
4495
4495
  //#region src/v2/hooks/use-capabilities.tsx
4496
4496
  /**
4497
- * Returns the capabilities declared by the given agent (or the default agent).
4497
+ * Returns the capabilities declared by the given agent (or the agent resolved
4498
+ * from the surrounding chat configuration, falling back to the default agent).
4498
4499
  * Capabilities are populated from the runtime `/info` response at connection
4499
4500
  * time. The hook reads them synchronously from the agent instance — there is
4500
4501
  * no separate loading state, but the value will be `undefined` until the
4501
4502
  * runtime handshake completes.
4502
4503
  *
4503
- * @param agentId - Optional agent ID. If omitted, uses the default agent.
4504
+ * @param agentId - Optional agent ID. If omitted, inherits the surrounding
4505
+ * chat configuration's agent, falling back to the default agent.
4504
4506
  * @returns The agent's capabilities, or `undefined` if the agent doesn't
4505
4507
  * declare capabilities.
4506
4508
  */
@@ -5073,6 +5075,7 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5073
5075
  })), [coreThreads]);
5074
5076
  const storeIsLoading = useThreadStoreSelector(store, _copilotkit_core.ɵselectThreadsIsLoading);
5075
5077
  const storeError = useThreadStoreSelector(store, _copilotkit_core.ɵselectThreadsError);
5078
+ const fetchMoreError = useThreadStoreSelector(store, _copilotkit_core.ɵselectFetchMoreError);
5076
5079
  const hasMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectHasNextPage);
5077
5080
  const isFetchingMoreThreads = useThreadStoreSelector(store, _copilotkit_core.ɵselectIsFetchingNextPage);
5078
5081
  const isMutating = useThreadStoreSelector(store, _copilotkit_core.ɵselectIsMutating);
@@ -5178,6 +5181,7 @@ function useThreads$1({ agentId, includeArchived, limit, enabled = true }) {
5178
5181
  isLoading,
5179
5182
  error,
5180
5183
  listError,
5184
+ fetchMoreError,
5181
5185
  hasMoreThreads,
5182
5186
  isFetchingMoreThreads,
5183
5187
  isMutating,
@@ -9119,7 +9123,7 @@ function findChatInput(origin) {
9119
9123
  * during prerender to avoid hydration mismatch).
9120
9124
  * - Feeds the element domain data: `threads`, `loading`, `error`,
9121
9125
  * `activeThreadId`, `licensed`, fetch-more state.
9122
- * - Routes the element's nine outbound events to core thread operations
9126
+ * - Routes the element's outbound events to core thread operations
9123
9127
  * ({@link useThreads}) and chat-configuration changes.
9124
9128
  * - Registers with the surrounding chat configuration so the header
9125
9129
  * thread-list launcher appears, and binds the element `open` state to the
@@ -9146,16 +9150,16 @@ function findChatInput(origin) {
9146
9150
  * </CopilotKitProvider>
9147
9151
  * ```
9148
9152
  */
9149
- function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed, licenseUrl, renderRow, label, limit, "data-testid": dataTestId = "copilot-threads-drawer" }) {
9153
+ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed, licenseUrl, renderRow, label, recentLabel, collapsible, onCollapseChange, limit, "data-testid": dataTestId = "copilot-threads-drawer" }) {
9150
9154
  const configuration = useCopilotChatConfiguration();
9151
9155
  const { status, checkFeature } = useLicenseContext();
9152
9156
  const licensePresent = status === "valid" || status === "expiring";
9153
9157
  const featureLicensed = checkFeature("threads");
9154
9158
  const licensed = licensePresent && featureLicensed;
9155
9159
  const licensePending = status === null;
9156
- const resolvedAgentId = agentId ?? configuration?.agentId ?? "default";
9160
+ const resolvedAgentId = agentId ?? configuration?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
9157
9161
  const activeThreadId = configuration?.threadId ?? null;
9158
- const { threads, isLoading, listError, hasMoreThreads, isFetchingMoreThreads, archiveThread, unarchiveThread, deleteThread, fetchMoreThreads, refetchThreads, startNewThread } = useThreads$1({
9162
+ const { threads, isLoading, listError, fetchMoreError, hasMoreThreads, isFetchingMoreThreads, archiveThread, unarchiveThread, deleteThread, fetchMoreThreads, refetchThreads, startNewThread } = useThreads$1({
9159
9163
  agentId: resolvedAgentId,
9160
9164
  includeArchived: true,
9161
9165
  enabled: licensed,
@@ -9236,6 +9240,9 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9236
9240
  const handleLoadMore = (0, react.useCallback)(() => {
9237
9241
  fetchMoreThreads();
9238
9242
  }, [fetchMoreThreads]);
9243
+ const handleCollapseChange = (0, react.useCallback)((collapsed) => {
9244
+ onCollapseChange?.(collapsed);
9245
+ }, [onCollapseChange]);
9239
9246
  const handlersRef = (0, react.useRef)({
9240
9247
  handleThreadSelected,
9241
9248
  handleNewThread,
@@ -9246,7 +9253,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9246
9253
  handleRetry,
9247
9254
  handleOpenChange,
9248
9255
  handleLicensed,
9249
- handleLoadMore
9256
+ handleLoadMore,
9257
+ handleCollapseChange
9250
9258
  });
9251
9259
  handlersRef.current = {
9252
9260
  handleThreadSelected,
@@ -9258,7 +9266,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9258
9266
  handleRetry,
9259
9267
  handleOpenChange,
9260
9268
  handleLicensed,
9261
- handleLoadMore
9269
+ handleLoadMore,
9270
+ handleCollapseChange
9262
9271
  };
9263
9272
  (0, react.useEffect)(() => {
9264
9273
  const el = elementRef.current;
@@ -9293,6 +9302,10 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9293
9302
  };
9294
9303
  const onLicensedEvent = () => handlersRef.current.handleLicensed();
9295
9304
  const onLoadMore = () => handlersRef.current.handleLoadMore();
9305
+ const onCollapseChangeEvent = (event) => {
9306
+ const detail = event.detail;
9307
+ handlersRef.current.handleCollapseChange(detail.collapsed);
9308
+ };
9296
9309
  el.addEventListener("thread-selected", onThreadSelected);
9297
9310
  el.addEventListener("new-thread", onNewThreadEvent);
9298
9311
  el.addEventListener("archive", onArchive);
@@ -9303,6 +9316,7 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9303
9316
  el.addEventListener("retry", onRetry);
9304
9317
  el.addEventListener("licensed", onLicensedEvent);
9305
9318
  el.addEventListener("load-more", onLoadMore);
9319
+ el.addEventListener("collapse-change", onCollapseChangeEvent);
9306
9320
  return () => {
9307
9321
  el.removeEventListener("thread-selected", onThreadSelected);
9308
9322
  el.removeEventListener("new-thread", onNewThreadEvent);
@@ -9314,6 +9328,7 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9314
9328
  el.removeEventListener("retry", onRetry);
9315
9329
  el.removeEventListener("licensed", onLicensedEvent);
9316
9330
  el.removeEventListener("load-more", onLoadMore);
9331
+ el.removeEventListener("collapse-change", onCollapseChangeEvent);
9317
9332
  };
9318
9333
  }, [mounted]);
9319
9334
  (0, react.useEffect)(() => {
@@ -9330,9 +9345,11 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9330
9345
  el.licensed = licensed || licensePending;
9331
9346
  el.hasMore = hasMoreThreads;
9332
9347
  el.fetchingMore = isFetchingMoreThreads;
9348
+ el.fetchMoreError = fetchMoreError ? fetchMoreError.message : null;
9333
9349
  }, [
9334
9350
  isLoading,
9335
9351
  listError,
9352
+ fetchMoreError,
9336
9353
  activeThreadId,
9337
9354
  licensed,
9338
9355
  licensePending,
@@ -9355,6 +9372,11 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9355
9372
  if (!el) return;
9356
9373
  if (licenseUrl !== void 0) el.licenseUrl = licenseUrl;
9357
9374
  }, [licenseUrl, mounted]);
9375
+ (0, react.useEffect)(() => {
9376
+ const el = elementRef.current;
9377
+ if (!el) return;
9378
+ if (collapsible !== void 0) el.collapsible = collapsible;
9379
+ }, [collapsible, mounted]);
9358
9380
  const rowChildren = (0, react.useMemo)(() => {
9359
9381
  if (!renderRow) return null;
9360
9382
  return drawerThreads.map((drawerThread) => {
@@ -9375,7 +9397,8 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
9375
9397
  if (!mounted) return null;
9376
9398
  return react.default.createElement(_copilotkit_web_components_threads_drawer.COPILOTKIT_THREADS_DRAWER_TAG, {
9377
9399
  ref: elementRef,
9378
- "data-testid": dataTestId
9400
+ "data-testid": dataTestId,
9401
+ ...recentLabel !== void 0 ? { "recent-label": recentLabel } : {}
9379
9402
  }, rowChildren);
9380
9403
  }
9381
9404
  CopilotThreadsDrawer.displayName = "CopilotThreadsDrawer";
@@ -11028,8 +11051,18 @@ const usePredictStateSubscription = (agent) => {
11028
11051
  }, [agent, getSubscriber]);
11029
11052
  };
11030
11053
  function CopilotListenersAgentSubscription() {
11031
- const resolvedAgentId = useCopilotChatConfiguration()?.agentId;
11032
- const { agent } = useAgent({ agentId: resolvedAgentId });
11054
+ const { copilotkit } = useCopilotKit();
11055
+ const configAgentId = useCopilotChatConfiguration()?.agentId;
11056
+ const { agent } = useAgent({ agentId: (0, react.useMemo)(() => {
11057
+ const requested = configAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
11058
+ const registered = copilotkit.agents ?? {};
11059
+ if (registered[requested]) return requested;
11060
+ if (requested === _copilotkit_shared.DEFAULT_AGENT_ID) {
11061
+ const firstRegistered = Object.keys(registered)[0];
11062
+ if (firstRegistered) return firstRegistered;
11063
+ }
11064
+ return requested;
11065
+ }, [configAgentId, copilotkit.agents]) });
11033
11066
  usePredictStateSubscription(agent);
11034
11067
  return null;
11035
11068
  }
@@ -12042,4 +12075,4 @@ Object.defineProperty(exports, 'useToast', {
12042
12075
  return useToast;
12043
12076
  }
12044
12077
  });
12045
- //# sourceMappingURL=copilotkit-Ces-OkSR.cjs.map
12078
+ //# sourceMappingURL=copilotkit-5MptLWNR.cjs.map