@copilotkit/react-core 1.87.1 → 1.89.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.
Files changed (38) hide show
  1. package/dist/{copilotkit-BNPEXnEE.d.mts → copilotkit-CfnudBCL.d.mts} +25 -5
  2. package/dist/copilotkit-CfnudBCL.d.mts.map +1 -0
  3. package/dist/{copilotkit-DFxtDD2N.cjs → copilotkit-DHJJxCeI.cjs} +330 -73
  4. package/dist/copilotkit-DHJJxCeI.cjs.map +1 -0
  5. package/dist/{copilotkit-BJ-6BoJ_.mjs → copilotkit-GWoyxfzS.mjs} +334 -77
  6. package/dist/copilotkit-GWoyxfzS.mjs.map +1 -0
  7. package/dist/{copilotkit-Bop-sY6y.d.cts → copilotkit-XLp7jKQk.d.cts} +25 -5
  8. package/dist/copilotkit-XLp7jKQk.d.cts.map +1 -0
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.d.cts +1 -1
  11. package/dist/index.d.mts +1 -1
  12. package/dist/index.mjs +1 -1
  13. package/dist/index.umd.js +22 -12
  14. package/dist/index.umd.js.map +1 -1
  15. package/dist/v2/generative-ui.d.cts +116 -116
  16. package/dist/v2/generative-ui.d.cts.map +1 -1
  17. package/dist/v2/generative-ui.d.mts +116 -116
  18. package/dist/v2/generative-ui.d.mts.map +1 -1
  19. package/dist/v2/headless.cjs +7 -2
  20. package/dist/v2/headless.cjs.map +1 -1
  21. package/dist/v2/headless.d.cts +5 -0
  22. package/dist/v2/headless.d.cts.map +1 -1
  23. package/dist/v2/headless.d.mts +5 -0
  24. package/dist/v2/headless.d.mts.map +1 -1
  25. package/dist/v2/headless.mjs +7 -2
  26. package/dist/v2/headless.mjs.map +1 -1
  27. package/dist/v2/index.cjs +19 -1
  28. package/dist/v2/index.css +1 -1
  29. package/dist/v2/index.d.cts +2 -2
  30. package/dist/v2/index.d.mts +2 -2
  31. package/dist/v2/index.mjs +2 -2
  32. package/dist/v2/index.umd.js +347 -72
  33. package/dist/v2/index.umd.js.map +1 -1
  34. package/package.json +10 -10
  35. package/dist/copilotkit-BJ-6BoJ_.mjs.map +0 -1
  36. package/dist/copilotkit-BNPEXnEE.d.mts.map +0 -1
  37. package/dist/copilotkit-Bop-sY6y.d.cts.map +0 -1
  38. package/dist/copilotkit-DFxtDD2N.cjs.map +0 -1
@@ -1825,7 +1825,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
1825
1825
 
1826
1826
  //#endregion
1827
1827
  //#region package.json
1828
- var version = "1.87.1";
1828
+ var version = "1.89.0";
1829
1829
 
1830
1830
  //#endregion
1831
1831
  //#region src/v2/components/CopilotKitInspector.tsx
@@ -2061,7 +2061,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
2061
2061
  * Fetches resource content on-demand via proxied MCP requests. The React shell
2062
2062
  * owns the iframe; `bindMcpApp` owns the protocol.
2063
2063
  */
2064
- const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent, allowSameOriginFallback }) {
2064
+ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent, allowSameOriginFallback, modelContext }) {
2065
2065
  const { copilotkit } = useCopilotKit();
2066
2066
  const messageId = message?.id;
2067
2067
  const containerRef = (0, react.useRef)(null);
@@ -2111,7 +2111,10 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
2111
2111
  getAgent: () => agentRef.current,
2112
2112
  host: copilotkit,
2113
2113
  messageId,
2114
- options: { allowSameOriginFallback },
2114
+ options: {
2115
+ allowSameOriginFallback,
2116
+ modelContext
2117
+ },
2115
2118
  hooks: {
2116
2119
  onResource: (resource) => {
2117
2120
  if (!mounted) return;
@@ -2154,6 +2157,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
2154
2157
  copilotkit,
2155
2158
  messageId,
2156
2159
  allowSameOriginFallback,
2160
+ modelContext,
2157
2161
  content.resourceUri,
2158
2162
  content.serverHash,
2159
2163
  content.serverId
@@ -5251,11 +5255,6 @@ surface to use a different protocol.`;
5251
5255
  - Use CSS Grid or Flexbox for layout. Ensure the UI looks good at any width.
5252
5256
  - Minimal transitions (150ms) for hover/focus states only. No decorative animations.
5253
5257
  - Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
5254
- /** The MCP Apps renderer with `mcpApps.allowSameOriginFallback` applied. */
5255
- const SameOriginMCPAppsActivityRenderer = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MCPAppsActivityRenderer, {
5256
- ...props,
5257
- allowSameOriginFallback: true
5258
- });
5259
5258
  const DEFAULT_LEARNING = Object.freeze({});
5260
5259
  function toLearningConfig(learning) {
5261
5260
  if (learning === true) return DEFAULT_LEARNING;
@@ -5332,11 +5331,17 @@ surface to use a different protocol.`;
5332
5331
  return (0, _copilotkit_a2ui_renderer.filterCatalog)(rawCatalog, (name) => core ? core.isCatalogComponentEnabled(name) : true);
5333
5332
  }, [rawCatalog, catalogToggleVersion]);
5334
5333
  const mcpAppsAllowSameOrigin = mcpApps?.allowSameOriginFallback === true;
5334
+ const mcpAppsModelContext = mcpApps?.modelContext === true;
5335
+ const mcpAppsRenderer = (0, react.useMemo)(() => mcpAppsAllowSameOrigin || mcpAppsModelContext ? (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MCPAppsActivityRenderer, {
5336
+ ...props,
5337
+ allowSameOriginFallback: mcpAppsAllowSameOrigin,
5338
+ modelContext: mcpAppsModelContext
5339
+ }) : MCPAppsActivityRenderer, [mcpAppsAllowSameOrigin, mcpAppsModelContext]);
5335
5340
  const builtInActivityRenderers = (0, react.useMemo)(() => {
5336
5341
  const renderers = [{
5337
5342
  activityType: _copilotkit_mcp_apps_renderer_activity.MCPAppsActivityType,
5338
5343
  content: _copilotkit_mcp_apps_renderer_activity.MCPAppsActivityContentSchema,
5339
- render: mcpAppsAllowSameOrigin ? SameOriginMCPAppsActivityRenderer : MCPAppsActivityRenderer
5344
+ render: mcpAppsRenderer
5340
5345
  }];
5341
5346
  if (openGenUIActive) renderers.push({
5342
5347
  activityType: OpenGenerativeUIActivityType,
@@ -5357,7 +5362,7 @@ surface to use a different protocol.`;
5357
5362
  generativeUIActive,
5358
5363
  a2ui,
5359
5364
  filteredCatalog,
5360
- mcpAppsAllowSameOrigin
5365
+ mcpAppsRenderer
5361
5366
  ]);
5362
5367
  const allActivityRenderers = (0, react.useMemo)(() => {
5363
5368
  return [...renderActivityMessagesList, ...builtInActivityRenderers];
@@ -6935,6 +6940,11 @@ surface to use a different protocol.`;
6935
6940
  UseAgentUpdate.OnStateChanged,
6936
6941
  UseAgentUpdate.OnRunStatusChanged
6937
6942
  ];
6943
+ /**
6944
+ * Returns the selected agent and its readiness, subscribing to agent updates.
6945
+ * Uses a shared agent by default, or a private proxy when `agentId`,
6946
+ * `runtimeAgentId`, and `threadId` are supplied together.
6947
+ */
6938
6948
  function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {}) {
6939
6949
  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 }).`);
6940
6950
  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}" }).`);
@@ -7061,7 +7071,7 @@ surface to use a different protocol.`;
7061
7071
  copilotkit.runtimeUrl,
7062
7072
  copilotkit.runtimeTransport,
7063
7073
  copilotkit.credentials,
7064
- JSON.stringify(copilotkit.headers)
7074
+ copilotkit.ɵheadersGeneration
7065
7075
  ]);
7066
7076
  (0, react.useEffect)(() => {
7067
7077
  if (updateFlags.length === 0) return;
@@ -7104,7 +7114,7 @@ surface to use a different protocol.`;
7104
7114
  if (agent instanceof _copilotkit_core.ProxiedCopilotRuntimeAgent) agent.credentials = copilotkit.credentials;
7105
7115
  }, [
7106
7116
  agent,
7107
- JSON.stringify(copilotkit.headers),
7117
+ copilotkit.ɵheadersGeneration,
7108
7118
  copilotkit.credentials
7109
7119
  ]);
7110
7120
  const configThreadId = chatConfig?.threadId;
@@ -8551,9 +8561,14 @@ surface to use a different protocol.`;
8551
8561
  }
8552
8562
  /**
8553
8563
  * Finds the working phase of every reply in `rendered`: its messages up to the
8554
- * last one that calls a tool. Text in there was narration; what follows is the
8564
+ * last one that calls a tool, plus the thinking and the silent messages that
8565
+ * trail it. Text in there was narration; the first text after the work is the
8555
8566
  * reply itself. Replies that called no tools are omitted, except the latest,
8556
8567
  * which may be about to.
8568
+ *
8569
+ * The trailing part matters: an agent that thinks once more after its last
8570
+ * tool call would otherwise leave those "Thought for 2 seconds" lines outside
8571
+ * the work, where nothing ever folds them away.
8557
8572
  */
8558
8573
  function getTurnWork(rendered, layouts) {
8559
8574
  const turns = /* @__PURE__ */ new Map();
@@ -8572,6 +8587,13 @@ surface to use a different protocol.`;
8572
8587
  visible.forEach((message, index) => {
8573
8588
  if (message.role === "assistant" && message.toolCalls?.some((call) => shown.has(call.id))) lastWork = index;
8574
8589
  });
8590
+ let workEnd = lastWork;
8591
+ for (let index = lastWork + 1; lastWork >= 0 && index < visible.length; index++) {
8592
+ const message = visible[index];
8593
+ const content = message.content;
8594
+ if (message.role === "assistant" && typeof content === "string" && content.trim()) break;
8595
+ workEnd = index;
8596
+ }
8575
8597
  const first = visible[0];
8576
8598
  if (first && (calls.length > 0 || isLatest)) {
8577
8599
  let lastAssistant = -1;
@@ -8579,11 +8601,13 @@ surface to use a different protocol.`;
8579
8601
  if (message.role === "assistant") lastAssistant = index;
8580
8602
  });
8581
8603
  const replyText = visible[lastAssistant]?.content;
8582
- const endsWithWork = lastAssistant >= 0 && lastAssistant <= lastWork && typeof replyText === "string" && replyText.trim().length > 0;
8604
+ const endsWithWork = lastAssistant >= 0 && lastAssistant <= workEnd && typeof replyText === "string" && replyText.trim().length > 0;
8605
+ const work = visible.slice(0, workEnd + 1);
8583
8606
  turns.set(key, {
8584
8607
  key,
8585
8608
  firstMessageId: first.id,
8586
- workMessageIds: new Set(visible.slice(0, lastWork + 1).map((message) => message.id)),
8609
+ workMessageIds: new Set(work.map((message) => message.id)),
8610
+ reasoningIds: work.filter((message) => message.role === "reasoning").map((message) => message.id),
8587
8611
  replyTextMessageId: endsWithWork ? visible[lastAssistant].id : void 0,
8588
8612
  calls,
8589
8613
  isLatest
@@ -9584,9 +9608,12 @@ surface to use a different protocol.`;
9584
9608
  }
9585
9609
  };
9586
9610
  };
9611
+ const isLatestAssistantMessage = message.role === "assistant" && (isLatest ?? messages?.[messages.length - 1]?.id === message.id);
9612
+ const isStreaming = !!isRunning && (isLatest === void 0 && messages === void 0 ? true : isLatestAssistantMessage);
9587
9613
  const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, {
9588
9614
  content: message.content || "",
9589
- messageId: message.id
9615
+ messageId: message.id,
9616
+ mode: isStreaming ? "streaming" : "static"
9590
9617
  });
9591
9618
  const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
9592
9619
  if (message.content) return await (0, _copilotkit_shared.copyToClipboard)(message.content);
@@ -9628,7 +9655,6 @@ surface to use a different protocol.`;
9628
9655
  messages
9629
9656
  });
9630
9657
  const hasContent = !!(message.content && message.content.trim().length > 0);
9631
- const isLatestAssistantMessage = message.role === "assistant" && (isLatest ?? messages?.[messages.length - 1]?.id === message.id);
9632
9658
  const shouldShowToolbar = toolbarVisible && (hasContent || showInspectorShortcut) && !(isRunning && isLatestAssistantMessage);
9633
9659
  const { open: commentOpen, close: closeComment } = comment;
9634
9660
  (0, react.useEffect)(() => {
@@ -10318,7 +10344,7 @@ surface to use a different protocol.`;
10318
10344
  ...headerProps,
10319
10345
  children: [
10320
10346
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
10321
- className: "cpk:font-medium",
10347
+ className: (0, tailwind_merge.twMerge)("cpk:font-medium", isStreaming && "cpk-shimmer"),
10322
10348
  children: label
10323
10349
  }),
10324
10350
  isStreaming && !hasContent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -10968,25 +10994,14 @@ surface to use a different protocol.`;
10968
10994
  return true;
10969
10995
  });
10970
10996
  /**
10971
- * Deduplicates messages by ID. For assistant messages, merges occurrences:
10972
- * recovers non-empty content from any earlier occurrence if the latest wiped it
10973
- * (empty string means the streaming update cleared the field, not blank text),
10974
- * and similarly recovers toolCalls from earlier occurrences if the latest is
10975
- * undefined (an empty array [] is treated as intentional and kept as-is).
10976
- * For all other roles, keeps the last entry.
10977
- *
10978
- * @internal Exported for unit testing only — not part of the public API.
10979
- */
10980
- /**
10981
10997
  * Collapse tool calls that share an id, keeping first-seen order.
10982
10998
  *
10983
- * AG-UI's TOOL_CALL_START handler appends to the parent message's `toolCalls`
10984
- * without checking whether that id is already present. So whenever a start
10985
- * event is applied twice — which the human-in-the-loop flow triggers when the
10986
- * run syncs after `respond()` — the message ends up carrying the same call
10987
- * twice. The second copy has EMPTY `arguments`, because a start event carries
10988
- * none; the args arrive later as TOOL_CALL_ARGS deltas addressed to the first
10989
- * copy.
10999
+ * Older AG-UI clients appended to the parent message's `toolCalls` without
11000
+ * checking whether that id was already present. So whenever a start event was
11001
+ * applied twice — which the human-in-the-loop flow triggers when the run syncs
11002
+ * after `respond()` — the message ended up carrying the same call twice. The
11003
+ * second copy has EMPTY `arguments`, because a start event carries none; the
11004
+ * args arrive later as TOOL_CALL_ARGS deltas addressed to the first copy.
10990
11005
  *
10991
11006
  * Left alone that renders the same tool call twice: once populated and once
10992
11007
  * blank (an approval card with no transaction id, offering live buttons for an
@@ -11008,13 +11023,42 @@ surface to use a different protocol.`;
11008
11023
  }
11009
11024
  return byId.size === toolCalls.length ? toolCalls : [...byId.values()];
11010
11025
  }
11026
+ /**
11027
+ * Unite the tool calls of two occurrences of the same assistant message,
11028
+ * keeping first-seen order. Each occurrence can hold only some of the calls,
11029
+ * so neither list may replace the other.
11030
+ *
11031
+ * For an id present in both, the later occurrence wins when it carries
11032
+ * arguments: it is the newer streaming update. A blank later copy never
11033
+ * replaces a populated one.
11034
+ */
11035
+ function mergeToolCalls(earlier, later) {
11036
+ const byId = new Map(earlier.map((toolCall) => [toolCall.id, toolCall]));
11037
+ for (const toolCall of later) {
11038
+ const existing = byId.get(toolCall.id);
11039
+ if (!existing || toolCall.function?.arguments || !existing.function?.arguments) byId.set(toolCall.id, toolCall);
11040
+ }
11041
+ return [...byId.values()];
11042
+ }
11043
+ /**
11044
+ * Deduplicates messages by ID. For assistant messages, merges occurrences:
11045
+ * recovers non-empty content from any earlier occurrence if the latest wiped it
11046
+ * (empty string means the streaming update cleared the field, not blank text).
11047
+ * Tool calls from every occurrence are kept: a copy can hold only some of the
11048
+ * calls, so when two occurrences both carry tool calls they are united by id.
11049
+ * If the latest has undefined toolCalls they are recovered from earlier
11050
+ * occurrences; an explicit empty array [] is treated as intentional and kept.
11051
+ * For all other roles, keeps the last entry.
11052
+ *
11053
+ * @internal Exported for unit testing only — not part of the public API.
11054
+ */
11011
11055
  function deduplicateMessages(messages) {
11012
11056
  const acc = /* @__PURE__ */ new Map();
11013
11057
  for (const message of messages) {
11014
11058
  const existing = acc.get(message.id);
11015
11059
  if (existing && message.role === "assistant" && existing.role === "assistant") {
11016
11060
  const content = message.content || existing.content;
11017
- const toolCalls = message.toolCalls ?? existing.toolCalls;
11061
+ const toolCalls = message.toolCalls?.length && existing.toolCalls?.length ? mergeToolCalls(dedupeToolCalls(existing.toolCalls), dedupeToolCalls(message.toolCalls)) : message.toolCalls ?? existing.toolCalls;
11018
11062
  acc.set(message.id, {
11019
11063
  ...existing,
11020
11064
  ...message,
@@ -11029,6 +11073,8 @@ surface to use a different protocol.`;
11029
11073
  }
11030
11074
  return [...acc.values()];
11031
11075
  }
11076
+ /** At most this many rows are rendered beyond the viewport on either side. */
11077
+ const MAX_OVERSCAN_ROWS = 400;
11032
11078
  /** A row holding a single message, rendered as it would be ungrouped. */
11033
11079
  function messageRow(message) {
11034
11080
  return {
@@ -11044,7 +11090,19 @@ surface to use a different protocol.`;
11044
11090
  };
11045
11091
  }
11046
11092
  const GROUP_ROW_KEY_PREFIX = "copilotkit-group:";
11093
+ const MESSAGE_ROW_KEY_PREFIX = "copilotkit-message:";
11047
11094
  const VIRTUALIZE_THRESHOLD = 50;
11095
+ /**
11096
+ * How long the scroll position must stay still, with no wheel or touch input,
11097
+ * before a correction held back during scrolling is written to `scrollTop`.
11098
+ */
11099
+ const SCROLL_SETTLE_MS = 250;
11100
+ /**
11101
+ * The most a held correction moves per frame once it is written. Safari can
11102
+ * still drop a write when a new gesture starts in the same frame; a small
11103
+ * step keeps that from showing.
11104
+ */
11105
+ const SETTLE_STEP_PX = 4;
11048
11106
  function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, workSummary, isRunning = false, transformMessages, groupMessages, messageFeedback = true, toolCallDisplay = "grouped", children, className, ...props }) {
11049
11107
  const isPinnedToBottom = (0, react.useContext)(ScrollPinnedContext);
11050
11108
  const renderCustomMessage = useRenderCustomMessages();
@@ -11148,6 +11206,17 @@ surface to use a different protocol.`;
11148
11206
  isRunning,
11149
11207
  latestTurnKey
11150
11208
  ]);
11209
+ const supersededReasoning = (0, react.useMemo)(() => {
11210
+ const ids = /* @__PURE__ */ new Set();
11211
+ if (!isRunning) return ids;
11212
+ const turn = turnWork?.get(latestTurnKey);
11213
+ for (const id of turn?.reasoningIds.slice(0, -1) ?? []) ids.add(id);
11214
+ return ids;
11215
+ }, [
11216
+ turnWork,
11217
+ latestTurnKey,
11218
+ isRunning
11219
+ ]);
11151
11220
  const toolCallDisplayContext = (0, react.useMemo)(() => ({
11152
11221
  display: toolCallDisplay,
11153
11222
  isRunning,
@@ -11217,6 +11286,14 @@ surface to use a different protocol.`;
11217
11286
  (0, _copilotkit_shared.commitRowKeyStore)(rowKeyStore, renderedMessages);
11218
11287
  }, [rowKeyStore, renderedMessages]);
11219
11288
  const stableGroupKey = (key) => rowRenderKeys.get(key) ?? key;
11289
+ const rowKey = (row) => row.type === "group" ? `${GROUP_ROW_KEY_PREFIX}${stableGroupKey(row.key)}` : `${MESSAGE_ROW_KEY_PREFIX}${rowRenderKeys.get(row.message.id) ?? row.message.id}`;
11290
+ const previousRowKeysRef = (0, react.useRef)([]);
11291
+ const rowKeys = (0, react.useMemo)(() => {
11292
+ const next = rows.map(rowKey);
11293
+ const previous = previousRowKeysRef.current;
11294
+ return next.length === previous.length && next.every((key, index) => key === previous[index]) ? previous : next;
11295
+ }, [rows, rowRenderKeys]);
11296
+ previousRowKeysRef.current = rowKeys;
11220
11297
  const groupStateRef = (0, react.useRef)(/* @__PURE__ */ new Map());
11221
11298
  const groupSettersRef = (0, react.useRef)(/* @__PURE__ */ new Map());
11222
11299
  const groupStateThreadRef = (0, react.useRef)(config?.threadId);
@@ -11300,24 +11377,75 @@ surface to use a different protocol.`;
11300
11377
  ]);
11301
11378
  const measuredRef = react.default.useRef({
11302
11379
  total: 0,
11303
- sizes: /* @__PURE__ */ new Map()
11380
+ sizes: /* @__PURE__ */ new Map(),
11381
+ estimates: /* @__PURE__ */ new Map()
11304
11382
  });
11383
+ const rowKeysRef = react.default.useRef(rowKeys);
11384
+ rowKeysRef.current = rowKeys;
11305
11385
  const resizeAnchorRef = react.default.useRef(null);
11306
11386
  const restoringVisibilityRef = react.default.useRef(false);
11387
+ const heldOffsetRef = react.default.useRef(0);
11388
+ const spacerRef = react.default.useRef(null);
11389
+ const shiftedRowsRef = react.default.useRef(null);
11390
+ const lastMeasuredRef = react.default.useRef(null);
11391
+ const userScrollingRef = react.default.useRef(false);
11392
+ const ownScrollWriteRef = react.default.useRef(null);
11393
+ const renderedTotalRef = (0, react.useRef)(0);
11394
+ const applyHeldOffset = react.default.useCallback(() => {
11395
+ const held = heldOffsetRef.current;
11396
+ if (spacerRef.current) spacerRef.current.style.height = `${renderedTotalRef.current - held}px`;
11397
+ if (shiftedRowsRef.current) shiftedRowsRef.current.style.transform = held ? `translateY(${-held}px)` : "";
11398
+ }, []);
11399
+ const keepListTopInView = react.default.useCallback((scrollTop) => {
11400
+ if (heldOffsetRef.current >= 0 || scrollTop + heldOffsetRef.current >= 0) return false;
11401
+ heldOffsetRef.current = scrollTop > 0 ? -scrollTop : 0;
11402
+ return true;
11403
+ }, []);
11404
+ const releaseHeldOffset = react.default.useCallback((element, amount) => {
11405
+ if (amount === 0) return;
11406
+ const scrollTop = element.scrollTop;
11407
+ heldOffsetRef.current -= amount;
11408
+ applyHeldOffset();
11409
+ const target = Math.max(0, scrollTop + amount);
11410
+ ownScrollWriteRef.current = target;
11411
+ element.scrollTop = target;
11412
+ }, [applyHeldOffset]);
11307
11413
  const firstMessageId = deduplicatedMessages[0]?.id;
11308
11414
  const measuredThreadRef = react.default.useRef(firstMessageId);
11309
11415
  if (measuredThreadRef.current !== firstMessageId) {
11310
11416
  measuredThreadRef.current = firstMessageId;
11311
11417
  resizeAnchorRef.current = null;
11418
+ heldOffsetRef.current = 0;
11312
11419
  measuredRef.current = {
11313
11420
  total: 0,
11314
- sizes: /* @__PURE__ */ new Map()
11421
+ sizes: /* @__PURE__ */ new Map(),
11422
+ estimates: /* @__PURE__ */ new Map()
11315
11423
  };
11316
11424
  }
11317
- const estimateRowSize = react.default.useCallback(() => {
11318
- const { total, sizes } = measuredRef.current;
11319
- return sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
11425
+ const measuredKeysRef = react.default.useRef(rowKeys);
11426
+ if (measuredKeysRef.current !== rowKeys) {
11427
+ measuredKeysRef.current = rowKeys;
11428
+ const live = new Set(rowKeys);
11429
+ const measured = measuredRef.current;
11430
+ for (const [key, height] of measured.sizes) if (!live.has(key)) {
11431
+ measured.sizes.delete(key);
11432
+ measured.total -= height;
11433
+ }
11434
+ for (const key of measured.estimates.keys()) if (!live.has(key)) measured.estimates.delete(key);
11435
+ }
11436
+ const estimateRowSize = react.default.useCallback((index) => {
11437
+ const { total, sizes, estimates } = measuredRef.current;
11438
+ const mean = sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
11439
+ const key = rowKeysRef.current[index];
11440
+ if (key === void 0) return mean;
11441
+ let estimate = estimates.get(key);
11442
+ if (estimate === void 0) {
11443
+ estimate = mean;
11444
+ estimates.set(key, estimate);
11445
+ }
11446
+ return estimate;
11320
11447
  }, []);
11448
+ const getRowKey = react.default.useCallback((index) => rowKeys[index] ?? index, [rowKeys]);
11321
11449
  const isPinnedToBottomRef = react.default.useRef(isPinnedToBottom);
11322
11450
  const measuredWidthRef = react.default.useRef(null);
11323
11451
  const captureResizeAnchor = react.default.useCallback((instance) => {
@@ -11330,7 +11458,7 @@ surface to use a different protocol.`;
11330
11458
  };
11331
11459
  return;
11332
11460
  }
11333
- const offset = instance.scrollElement?.scrollTop ?? 0;
11461
+ const offset = (instance.scrollElement?.scrollTop ?? 0) + heldOffsetRef.current;
11334
11462
  const anchor = instance.getVirtualItemForOffset(offset);
11335
11463
  if (anchor) resizeAnchorRef.current = {
11336
11464
  index: anchor.index,
@@ -11340,19 +11468,46 @@ surface to use a different protocol.`;
11340
11468
  }, []);
11341
11469
  const measureRowElement = react.default.useCallback((el, _entry, instance) => {
11342
11470
  captureResizeAnchor(instance);
11343
- const height = el?.getBoundingClientRect().height ?? 0;
11471
+ const rect = el?.getBoundingClientRect();
11472
+ const height = rect?.height ?? 0;
11344
11473
  const index = Number(el?.dataset?.index);
11345
- if (height > 0 && Number.isInteger(index)) {
11474
+ const key = Number.isInteger(index) ? rowKeysRef.current[index] : void 0;
11475
+ const viewportTop = typeof rect?.top === "number" ? instance.scrollElement?.getBoundingClientRect().top : void 0;
11476
+ lastMeasuredRef.current = Number.isInteger(index) && typeof rect?.top === "number" && typeof viewportTop === "number" ? {
11477
+ index,
11478
+ above: rect.top < viewportTop
11479
+ } : null;
11480
+ const hidden = !el?.isConnected || !instance.scrollElement?.clientHeight;
11481
+ if ((height > 0 || !hidden) && key !== void 0) {
11346
11482
  const { total, sizes } = measuredRef.current;
11347
- measuredRef.current.total = total - (sizes.get(index) ?? 0) + height;
11348
- sizes.set(index, height);
11483
+ measuredRef.current.total = total - (sizes.get(key) ?? 0) + height;
11484
+ sizes.set(key, height);
11349
11485
  }
11350
- return height > 0 ? height : measuredRef.current.sizes.get(index) ?? 100;
11486
+ return height > 0 || !hidden ? height : (key === void 0 ? void 0 : measuredRef.current.sizes.get(key)) ?? 100;
11351
11487
  }, [captureResizeAnchor]);
11352
- const shouldAdjustScrollOnResize = react.default.useCallback((item, _delta, instance) => {
11488
+ const shouldAdjustScrollOnResize = react.default.useCallback((item, delta, instance) => {
11489
+ const measured = lastMeasuredRef.current;
11490
+ lastMeasuredRef.current = null;
11353
11491
  if (isPinnedToBottomRef.current || resizeAnchorRef.current || restoringVisibilityRef.current) return false;
11354
11492
  const scrollAdjustments = instance.scrollAdjustments ?? 0;
11355
- return item.start < (instance.scrollOffset ?? 0) + scrollAdjustments;
11493
+ if (!(measured?.index === item.index ? measured.above : item.start < (instance.scrollOffset ?? 0) + scrollAdjustments)) return false;
11494
+ if (userScrollingRef.current || heldOffsetRef.current !== 0) {
11495
+ const held = heldOffsetRef.current;
11496
+ heldOffsetRef.current += delta;
11497
+ keepListTopInView(instance.scrollElement?.scrollTop ?? 0);
11498
+ instance.scrollOffset = (instance.scrollOffset ?? 0) + heldOffsetRef.current - held;
11499
+ return false;
11500
+ }
11501
+ return true;
11502
+ }, [keepListTopInView]);
11503
+ const observeListOffset = react.default.useCallback((instance, notify) => (0, _tanstack_react_virtual.observeElementOffset)(instance, (offset, isScrolling) => {
11504
+ if (keepListTopInView(offset)) applyHeldOffset();
11505
+ notify(offset + heldOffsetRef.current, isScrolling);
11506
+ }), [keepListTopInView, applyHeldOffset]);
11507
+ const scrollToListOffset = react.default.useCallback((offset, options, instance) => {
11508
+ const elementOffset = offset - heldOffsetRef.current;
11509
+ ownScrollWriteRef.current = elementOffset + (options.adjustments ?? 0);
11510
+ (0, _tanstack_react_virtual.elementScroll)(elementOffset, options, instance);
11356
11511
  }, []);
11357
11512
  const observeScrollRect = react.default.useCallback((instance, notify) => {
11358
11513
  let frame;
@@ -11383,7 +11538,8 @@ surface to use a different protocol.`;
11383
11538
  instance.getTotalSize();
11384
11539
  measuredRef.current = {
11385
11540
  total: 0,
11386
- sizes: /* @__PURE__ */ new Map()
11541
+ sizes: /* @__PURE__ */ new Map(),
11542
+ estimates: /* @__PURE__ */ new Map()
11387
11543
  };
11388
11544
  instance.elementsCache.forEach((element) => {
11389
11545
  measureRowElement(element, void 0, instance);
@@ -11408,27 +11564,120 @@ surface to use a different protocol.`;
11408
11564
  resizeAnchorRef.current = null;
11409
11565
  };
11410
11566
  }, [captureResizeAnchor, measureRowElement]);
11567
+ const virtualizerRef = (0, react.useRef)(null);
11568
+ const rangeExtractor = react.default.useCallback((range) => {
11569
+ const instance = virtualizerRef.current;
11570
+ const items = instance?.measurementsCache;
11571
+ const reach = instance?.scrollRect?.height ?? 0;
11572
+ if (!items || items.length !== range.count || reach <= 0) return (0, _tanstack_react_virtual.defaultRangeExtractor)(range);
11573
+ let start = range.startIndex;
11574
+ for (let above = 0; start > 0 && range.startIndex - start < MAX_OVERSCAN_ROWS && (range.startIndex - start < range.overscan || above < reach);) {
11575
+ start -= 1;
11576
+ above += items[start].size;
11577
+ }
11578
+ let end = range.endIndex;
11579
+ for (let below = 0; end < range.count - 1 && end - range.endIndex < MAX_OVERSCAN_ROWS && (end - range.endIndex < range.overscan || below < reach);) {
11580
+ end += 1;
11581
+ below += items[end].size;
11582
+ }
11583
+ const indexes = [];
11584
+ for (let index = start; index <= end; index++) indexes.push(index);
11585
+ return indexes;
11586
+ }, []);
11411
11587
  const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
11412
11588
  count: shouldVirtualize ? rows.length : 0,
11413
11589
  getScrollElement: () => shouldVirtualize ? scrollElement : null,
11414
11590
  observeElementRect: observeScrollRect,
11591
+ observeElementOffset: observeListOffset,
11592
+ scrollToFn: scrollToListOffset,
11415
11593
  estimateSize: estimateRowSize,
11594
+ getItemKey: getRowKey,
11416
11595
  overscan: 5,
11596
+ rangeExtractor,
11417
11597
  measureElement: measureRowElement,
11418
11598
  initialRect: {
11419
11599
  width: 0,
11420
11600
  height: 600
11421
11601
  }
11422
11602
  });
11603
+ virtualizerRef.current = virtualizer;
11604
+ renderedTotalRef.current = virtualizer.getTotalSize();
11605
+ (0, react.useLayoutEffect)(applyHeldOffset);
11606
+ (0, react.useEffect)(() => {
11607
+ const element = shouldVirtualize ? scrollElement : null;
11608
+ if (!element) return;
11609
+ let settleTimer;
11610
+ let settleFrame;
11611
+ let touching = false;
11612
+ const settleStep = () => {
11613
+ settleFrame = void 0;
11614
+ const held = heldOffsetRef.current;
11615
+ if (userScrollingRef.current || touching || held === 0) return;
11616
+ releaseHeldOffset(element, Math.sign(held) * Math.min(Math.abs(held), SETTLE_STEP_PX));
11617
+ if (heldOffsetRef.current !== 0) settleFrame = requestAnimationFrame(settleStep);
11618
+ };
11619
+ const settle = () => {
11620
+ settleTimer = void 0;
11621
+ if (touching) return;
11622
+ userScrollingRef.current = false;
11623
+ if (heldOffsetRef.current !== 0 && settleFrame === void 0) settleFrame = requestAnimationFrame(settleStep);
11624
+ };
11625
+ const scrolling = () => {
11626
+ userScrollingRef.current = true;
11627
+ if (settleFrame !== void 0) {
11628
+ cancelAnimationFrame(settleFrame);
11629
+ settleFrame = void 0;
11630
+ }
11631
+ if (settleTimer !== void 0) clearTimeout(settleTimer);
11632
+ settleTimer = setTimeout(settle, SCROLL_SETTLE_MS);
11633
+ };
11634
+ const onScroll = () => {
11635
+ const own = ownScrollWriteRef.current;
11636
+ if (own !== null && Math.abs(element.scrollTop - own) < 1) {
11637
+ ownScrollWriteRef.current = null;
11638
+ return;
11639
+ }
11640
+ scrolling();
11641
+ };
11642
+ const onTouchStart = () => {
11643
+ touching = true;
11644
+ scrolling();
11645
+ };
11646
+ const onTouchEnd = () => {
11647
+ touching = false;
11648
+ scrolling();
11649
+ };
11650
+ element.addEventListener("scroll", onScroll, { passive: true });
11651
+ element.addEventListener("wheel", scrolling, { passive: true });
11652
+ element.addEventListener("touchstart", onTouchStart, { passive: true });
11653
+ element.addEventListener("touchend", onTouchEnd, { passive: true });
11654
+ element.addEventListener("touchcancel", onTouchEnd, { passive: true });
11655
+ return () => {
11656
+ if (settleTimer !== void 0) clearTimeout(settleTimer);
11657
+ if (settleFrame !== void 0) cancelAnimationFrame(settleFrame);
11658
+ userScrollingRef.current = false;
11659
+ element.removeEventListener("scroll", onScroll);
11660
+ element.removeEventListener("wheel", scrolling);
11661
+ element.removeEventListener("touchstart", onTouchStart);
11662
+ element.removeEventListener("touchend", onTouchEnd);
11663
+ element.removeEventListener("touchcancel", onTouchEnd);
11664
+ };
11665
+ }, [
11666
+ shouldVirtualize,
11667
+ scrollElement,
11668
+ releaseHeldOffset
11669
+ ]);
11423
11670
  isPinnedToBottomRef.current = isPinnedToBottom;
11424
11671
  virtualizer.shouldAdjustScrollPositionOnItemSizeChange = shouldAdjustScrollOnResize;
11425
11672
  (0, react.useLayoutEffect)(() => {
11426
11673
  const anchor = resizeAnchorRef.current;
11427
11674
  if (!anchor?.ready || restoringVisibilityRef.current) return;
11675
+ if (scrollElement) releaseHeldOffset(scrollElement, heldOffsetRef.current);
11428
11676
  const position = virtualizer.getOffsetForIndex(anchor.index, "start");
11429
11677
  if (position && !isPinnedToBottomRef.current) {
11430
11678
  const target = position[0] + anchor.offset;
11431
- if (Math.abs((scrollElement?.scrollTop ?? 0) - target) > .5) virtualizer.scrollToOffset(target);
11679
+ const listOffset = (scrollElement?.scrollTop ?? 0) + heldOffsetRef.current;
11680
+ if (Math.abs(listOffset - target) > .5) virtualizer.scrollToOffset(target);
11432
11681
  }
11433
11682
  const frame = requestAnimationFrame(() => {
11434
11683
  if (resizeAnchorRef.current === anchor) resizeAnchorRef.current = null;
@@ -11482,7 +11731,7 @@ surface to use a different protocol.`;
11482
11731
  slotProps: reasoningSlotProps
11483
11732
  }, rowKey);
11484
11733
  elements.push(toolCallDisplay === "turn" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Collapsible, {
11485
- open: workOpen.get(message.id) ?? true,
11734
+ open: (workOpen.get(message.id) ?? true) && !supersededReasoning.has(message.id),
11486
11735
  children: reasoning
11487
11736
  }, rowKey) : reasoning);
11488
11737
  }
@@ -11500,7 +11749,6 @@ surface to use a different protocol.`;
11500
11749
  }, `intelligence-${intelligenceTurnId}`));
11501
11750
  return elements.filter(Boolean);
11502
11751
  };
11503
- const rowKey = (row) => row.type === "group" ? `${GROUP_ROW_KEY_PREFIX}${stableGroupKey(row.key)}` : rowRenderKeys.get(row.message.id) ?? row.message.id;
11504
11752
  const renderRow = (row) => {
11505
11753
  if (row.type === "message") return renderMessageBlock(row.message);
11506
11754
  const Wrapper = row.wrapper;
@@ -11513,8 +11761,6 @@ surface to use a different protocol.`;
11513
11761
  children: row.messages.flatMap(renderMessageBlock)
11514
11762
  }, rowKey(row))];
11515
11763
  };
11516
- const rowKeysRef = (0, react.useRef)([]);
11517
- rowKeysRef.current = rows.map(rowKey);
11518
11764
  const virtualModeRef = (0, react.useRef)(shouldVirtualize);
11519
11765
  virtualModeRef.current = shouldVirtualize;
11520
11766
  (0, react.useEffect)(() => {
@@ -11649,26 +11895,37 @@ surface to use a different protocol.`;
11649
11895
  ...props,
11650
11896
  children: [
11651
11897
  shouldVirtualize ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11898
+ ref: spacerRef,
11652
11899
  style: {
11653
- height: virtualizer.getTotalSize(),
11900
+ height: renderedTotalRef.current - heldOffsetRef.current,
11654
11901
  position: "relative",
11655
11902
  overflowAnchor: "none"
11656
11903
  },
11657
- children: virtualizer.getVirtualItems().map((virtualItem) => {
11658
- const row = rows[virtualItem.index];
11659
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11660
- "data-index": virtualItem.index,
11661
- "data-scroll-anchor": rowKey(row),
11662
- ref: virtualizer.measureElement,
11663
- style: {
11664
- position: "absolute",
11665
- top: 0,
11666
- left: 0,
11667
- width: "100%",
11668
- transform: `translateY(${virtualItem.start}px)`
11669
- },
11670
- children: renderRow(row)
11671
- }, rowKey(row));
11904
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11905
+ ref: shiftedRowsRef,
11906
+ style: {
11907
+ position: "absolute",
11908
+ top: 0,
11909
+ left: 0,
11910
+ width: "100%",
11911
+ transform: heldOffsetRef.current ? `translateY(${-heldOffsetRef.current}px)` : void 0
11912
+ },
11913
+ children: virtualizer.getVirtualItems().map((virtualItem) => {
11914
+ const row = rows[virtualItem.index];
11915
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11916
+ "data-index": virtualItem.index,
11917
+ "data-scroll-anchor": rowKey(row),
11918
+ ref: virtualizer.measureElement,
11919
+ style: {
11920
+ position: "absolute",
11921
+ top: 0,
11922
+ left: 0,
11923
+ width: "100%",
11924
+ transform: `translateY(${virtualItem.start}px)`
11925
+ },
11926
+ children: renderRow(row)
11927
+ }, rowKey(row));
11928
+ })
11672
11929
  })
11673
11930
  }) : messageElements,
11674
11931
  interruptElement,
@@ -12549,7 +12806,7 @@ surface to use a different protocol.`;
12549
12806
  ...props,
12550
12807
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, {
12551
12808
  "aria-hidden": "true",
12552
- className: "cpk:size-6 cpk:animate-spin cpk:text-muted-foreground"
12809
+ className: "cpk:size-6 cpk:text-muted-foreground cpk:*:origin-center cpk:*:animate-spin"
12553
12810
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
12554
12811
  className: "cpk:sr-only",
12555
12812
  children: labels.chatConnectingLabel
@@ -16566,6 +16823,12 @@ Object.defineProperty(exports, 'AGUIConnectNotImplementedError', {
16566
16823
  return _ag_ui_client.AGUIConnectNotImplementedError;
16567
16824
  }
16568
16825
  });
16826
+ Object.defineProperty(exports, 'AGUIEnforcementLimitError', {
16827
+ enumerable: true,
16828
+ get: function () {
16829
+ return _ag_ui_client.AGUIEnforcementLimitError;
16830
+ }
16831
+ });
16569
16832
  Object.defineProperty(exports, 'AGUIError', {
16570
16833
  enumerable: true,
16571
16834
  get: function () {
@@ -16796,6 +17059,12 @@ Object.defineProperty(exports, 'CustomEventSchema', {
16796
17059
  return _ag_ui_core_schemas.CustomEventSchema;
16797
17060
  }
16798
17061
  });
17062
+ Object.defineProperty(exports, 'DEFAULT_MAX_ENFORCED_ENTRIES', {
17063
+ enumerable: true,
17064
+ get: function () {
17065
+ return _ag_ui_client.DEFAULT_MAX_ENFORCED_ENTRIES;
17066
+ }
17067
+ });
16799
17068
  Object.defineProperty(exports, 'DataSourceSchema', {
16800
17069
  enumerable: true,
16801
17070
  get: function () {
@@ -16963,6 +17232,12 @@ Object.defineProperty(exports, 'IntelligenceAgent', {
16963
17232
  });
16964
17233
  exports.IntelligenceIndicator = IntelligenceIndicator;
16965
17234
  exports.IntelligenceIndicatorView = IntelligenceIndicatorView;
17235
+ Object.defineProperty(exports, 'IntelligenceReplayFailedError', {
17236
+ enumerable: true,
17237
+ get: function () {
17238
+ return _copilotkit_core.IntelligenceReplayFailedError;
17239
+ }
17240
+ });
16966
17241
  Object.defineProperty(exports, 'InterruptSchema', {
16967
17242
  enumerable: true,
16968
17243
  get: function () {