@copilotkit/react-core 2.0.0-rc.60 → 2.0.0-rc.62

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.
package/dist/index.cjs CHANGED
@@ -805,7 +805,7 @@ function ɵuseOwnedCore(ref, create) {
805
805
 
806
806
  //#endregion
807
807
  //#region package.json
808
- var version$1 = "2.0.0-rc.60";
808
+ var version$1 = "2.0.0-rc.62";
809
809
 
810
810
  //#endregion
811
811
  //#region src/components/CopilotKitInspector.tsx
@@ -920,15 +920,22 @@ function InlineFeatureWarning({ featureName }) {
920
920
  * protocol session (`bindMcpApp`, loaded lazily); this component only draws
921
921
  * the state around it.
922
922
  */
923
- const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent, allowSameOriginFallback }) {
923
+ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent, allowSameOriginFallback, modelContext }) {
924
924
  const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
925
925
  const containerRef = (0, react.useRef)(null);
926
926
  const messageId = message?.id;
927
927
  const app = (0, react.useMemo)(() => new _copilotkit_mcp_apps_renderer_activity.ɵMcpAppHost({
928
928
  host: copilotkit,
929
- sessionOptions: { allowSameOriginFallback },
929
+ sessionOptions: {
930
+ allowSameOriginFallback,
931
+ modelContext
932
+ },
930
933
  importRenderer: () => import("@copilotkit/mcp-apps-renderer")
931
- }), [copilotkit, allowSameOriginFallback]);
934
+ }), [
935
+ copilotkit,
936
+ allowSameOriginFallback,
937
+ modelContext
938
+ ]);
932
939
  const state = (0, react.useSyncExternalStore)(app.subscribe, app.getState, app.getState);
933
940
  (0, react.useEffect)(() => {
934
941
  app.setAgent(agent);
@@ -1304,11 +1311,6 @@ function CopilotKitStyles() {
1304
1311
  const EMPTY_HEADERS = Object.freeze({});
1305
1312
  const EMPTY_PROPERTIES = Object.freeze({});
1306
1313
  const EMPTY_AGENTS = Object.freeze({});
1307
- /** The MCP Apps renderer with `mcpApps.allowSameOriginFallback` applied. */
1308
- const SameOriginMCPAppsActivityRenderer = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MCPAppsActivityRenderer, {
1309
- ...props,
1310
- allowSameOriginFallback: true
1311
- });
1312
1314
  /**
1313
1315
  * The `generativeUI` prop with the options of the deprecated `a2ui` prop:
1314
1316
  * `a2ui.catalog` is the `ui` and `a2ui.theme` the `theme`, unless
@@ -1383,13 +1385,19 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
1383
1385
  const renderActivityMessagesList = useStableArrayProp(renderActivityMessages, "renderActivityMessages");
1384
1386
  const copilotkitRef = (0, react.useRef)(null);
1385
1387
  const mcpAppsAllowSameOrigin = mcpApps?.allowSameOriginFallback === true;
1388
+ const mcpAppsModelContext = mcpApps?.modelContext === true;
1389
+ const mcpAppsRenderer = (0, react.useMemo)(() => mcpAppsAllowSameOrigin || mcpAppsModelContext ? (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MCPAppsActivityRenderer, {
1390
+ ...props,
1391
+ allowSameOriginFallback: mcpAppsAllowSameOrigin,
1392
+ modelContext: mcpAppsModelContext
1393
+ }) : MCPAppsActivityRenderer, [mcpAppsAllowSameOrigin, mcpAppsModelContext]);
1386
1394
  const allActivityRenderers = (0, react.useMemo)(() => (0, _copilotkit_core.ɵassembleActivityRenderers)({
1387
1395
  app: renderActivityMessagesList,
1388
1396
  builtIns: [
1389
1397
  {
1390
1398
  activityType: _copilotkit_mcp_apps_renderer_activity.MCPAppsActivityType,
1391
1399
  content: _copilotkit_mcp_apps_renderer_activity.MCPAppsActivityContentSchema,
1392
- render: mcpAppsAllowSameOrigin ? SameOriginMCPAppsActivityRenderer : MCPAppsActivityRenderer
1400
+ render: mcpAppsRenderer
1393
1401
  },
1394
1402
  openGenUIActive && {
1395
1403
  activityType: OpenGenerativeUIActivityType,
@@ -1403,7 +1411,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
1403
1411
  renderActivityMessagesList,
1404
1412
  openGenUIActive,
1405
1413
  generativeUIActive,
1406
- mcpAppsAllowSameOrigin
1414
+ mcpAppsRenderer
1407
1415
  ]);
1408
1416
  const resolvedConfig = (0, react.useMemo)(() => (0, _copilotkit_core.ɵresolveProviderConfig)({
1409
1417
  runtimeUrl,
@@ -2590,6 +2598,11 @@ const ALL_UPDATES = [
2590
2598
  UseAgentUpdate.OnStateChanged,
2591
2599
  UseAgentUpdate.OnRunStatusChanged
2592
2600
  ];
2601
+ /**
2602
+ * Returns the selected agent and its readiness, subscribing to agent updates.
2603
+ * Uses a shared agent by default, or a private proxy when `agentId`,
2604
+ * `runtimeAgentId`, and `threadId` are supplied together.
2605
+ */
2593
2606
  function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {}) {
2594
2607
  (0, _copilotkit_core.ɵvalidateAgentBinding)({
2595
2608
  agentId,
@@ -4465,7 +4478,7 @@ function CopilotChatReasoningMessage({ message, messages, isRunning, isLatest: i
4465
4478
  ...headerProps,
4466
4479
  children: [
4467
4480
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4468
- className: "cpk-reasoning-message-label",
4481
+ className: (0, _copilotkit_core.ɵcn)("cpk-reasoning-message-label", isStreaming && "cpk-shimmer"),
4469
4482
  children: label
4470
4483
  }),
4471
4484
  isStreaming && !hasContent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -5113,6 +5126,8 @@ const MemoizedCustomMessage = react.default.memo(function MemoizedCustomMessage(
5113
5126
  if (JSON.stringify(prevProps.stateSnapshot) !== JSON.stringify(nextProps.stateSnapshot)) return false;
5114
5127
  return true;
5115
5128
  });
5129
+ /** At most this many rows are rendered beyond the viewport on either side. */
5130
+ const MAX_OVERSCAN_ROWS = 400;
5116
5131
  /** A row holding a single message, rendered as it would be ungrouped. */
5117
5132
  function messageRow(message) {
5118
5133
  return {
@@ -5128,7 +5143,19 @@ function messageGroup(group) {
5128
5143
  };
5129
5144
  }
5130
5145
  const GROUP_ROW_KEY_PREFIX = "copilotkit-group:";
5146
+ const MESSAGE_ROW_KEY_PREFIX = "copilotkit-message:";
5131
5147
  const VIRTUALIZE_THRESHOLD = 50;
5148
+ /**
5149
+ * How long the scroll position must stay still, with no wheel or touch input,
5150
+ * before a correction held back during scrolling is written to `scrollTop`.
5151
+ */
5152
+ const SCROLL_SETTLE_MS = 250;
5153
+ /**
5154
+ * The most a held correction moves per frame once it is written. Safari can
5155
+ * still drop a write when a new gesture starts in the same frame; a small
5156
+ * step keeps that from showing.
5157
+ */
5158
+ const SETTLE_STEP_PX = 4;
5132
5159
  function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, workSummary, isRunning = false, transformMessages, groupMessages, messageFeedback = true, toolCallDisplay = "grouped", children, className, ...props }) {
5133
5160
  const isPinnedToBottom = (0, react.useContext)(ScrollPinnedContext);
5134
5161
  const renderCustomMessage = useRenderCustomMessages();
@@ -5173,7 +5200,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5173
5200
  const rendererNames = useToolCallRendererNames();
5174
5201
  const [viewModel] = (0, react.useState)(_copilotkit_core.ɵcreateMessageViewModel);
5175
5202
  (0, react.useSyncExternalStore)((0, react.useCallback)((onChange) => viewModel.subscribe(onChange), [viewModel]), () => viewModel.getSnapshot(), () => viewModel.getSnapshot());
5176
- const { layouts: toolCallLayouts, turnByFirstMessage, latestTurnKey, workOpen, workTextOpen, showCursor, pendingWorkSummary } = viewModel.update({
5203
+ const { layouts: toolCallLayouts, turnByFirstMessage, latestTurnKey, workOpen, workTextOpen, reasoningOpen, showCursor, pendingWorkSummary } = viewModel.update({
5177
5204
  display: toolCallDisplay,
5178
5205
  messages,
5179
5206
  rendered: renderedMessages,
@@ -5250,11 +5277,14 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5250
5277
  (0, _copilotkit_shared.commitRowKeyStore)(rowKeyStore, renderedMessages);
5251
5278
  }, [rowKeyStore, renderedMessages]);
5252
5279
  const stableGroupKey = (key) => rowRenderKeys.get(key) ?? key;
5253
- const rowKey = (row) => row.type === "group" ? `${GROUP_ROW_KEY_PREFIX}${stableGroupKey(row.key)}` : rowRenderKeys.get(row.message.id) ?? row.message.id;
5254
- const rowKeysRef = (0, react.useRef)([]);
5255
- const nextRowKeys = rows.map(rowKey);
5256
- if (nextRowKeys.length !== rowKeysRef.current.length || nextRowKeys.some((key, index) => key !== rowKeysRef.current[index])) rowKeysRef.current = nextRowKeys;
5257
- const rowKeys = rowKeysRef.current;
5280
+ 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}`;
5281
+ const previousRowKeysRef = (0, react.useRef)([]);
5282
+ const rowKeys = (0, react.useMemo)(() => {
5283
+ const next = rows.map(rowKey);
5284
+ const previous = previousRowKeysRef.current;
5285
+ return next.length === previous.length && next.every((key, index) => key === previous[index]) ? previous : next;
5286
+ }, [rows, rowRenderKeys]);
5287
+ previousRowKeysRef.current = rowKeys;
5258
5288
  const groupStateRef = (0, react.useRef)(/* @__PURE__ */ new Map());
5259
5289
  const groupSettersRef = (0, react.useRef)(/* @__PURE__ */ new Map());
5260
5290
  const groupStateThreadRef = (0, react.useRef)(config?.threadId);
@@ -5341,12 +5371,41 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5341
5371
  ]);
5342
5372
  const measuredRef = react.default.useRef({
5343
5373
  total: 0,
5344
- sizes: /* @__PURE__ */ new Map()
5374
+ sizes: /* @__PURE__ */ new Map(),
5375
+ estimates: /* @__PURE__ */ new Map()
5345
5376
  });
5377
+ const rowKeysRef = react.default.useRef(rowKeys);
5378
+ rowKeysRef.current = rowKeys;
5346
5379
  const resizeAnchorRef = react.default.useRef(null);
5347
5380
  const restoringVisibilityRef = react.default.useRef(false);
5348
5381
  const isPinnedToBottomRef = react.default.useRef(isPinnedToBottom);
5349
5382
  const virtualizerRef = react.default.useRef(null);
5383
+ const heldOffsetRef = react.default.useRef(0);
5384
+ const spacerRef = react.default.useRef(null);
5385
+ const shiftedRowsRef = react.default.useRef(null);
5386
+ const lastMeasuredRef = react.default.useRef(null);
5387
+ const userScrollingRef = react.default.useRef(false);
5388
+ const ownScrollWriteRef = react.default.useRef(null);
5389
+ const renderedTotalRef = (0, react.useRef)(0);
5390
+ const applyHeldOffset = react.default.useCallback(() => {
5391
+ const held = heldOffsetRef.current;
5392
+ if (spacerRef.current) spacerRef.current.style.height = `${renderedTotalRef.current - held}px`;
5393
+ if (shiftedRowsRef.current) shiftedRowsRef.current.style.transform = held ? `translateY(${-held}px)` : "";
5394
+ }, []);
5395
+ const keepListTopInView = react.default.useCallback((scrollTop) => {
5396
+ if (heldOffsetRef.current >= 0 || scrollTop + heldOffsetRef.current >= 0) return false;
5397
+ heldOffsetRef.current = scrollTop > 0 ? -scrollTop : 0;
5398
+ return true;
5399
+ }, []);
5400
+ const releaseHeldOffset = react.default.useCallback((element, amount) => {
5401
+ if (amount === 0) return;
5402
+ const scrollTop = element.scrollTop;
5403
+ heldOffsetRef.current -= amount;
5404
+ applyHeldOffset();
5405
+ const target = Math.max(0, scrollTop + amount);
5406
+ ownScrollWriteRef.current = target;
5407
+ element.scrollTop = target;
5408
+ }, [applyHeldOffset]);
5350
5409
  const history = react.default.useRef({
5351
5410
  messages: deduplicatedMessages,
5352
5411
  threadId,
@@ -5359,9 +5418,11 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5359
5418
  else {
5360
5419
  history.generation += 1;
5361
5420
  resizeAnchorRef.current = null;
5421
+ heldOffsetRef.current = 0;
5362
5422
  measuredRef.current = {
5363
5423
  total: 0,
5364
- sizes: /* @__PURE__ */ new Map()
5424
+ sizes: /* @__PURE__ */ new Map(),
5425
+ estimates: /* @__PURE__ */ new Map()
5365
5426
  };
5366
5427
  }
5367
5428
  }
@@ -5373,7 +5434,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5373
5434
  const instance = virtualizerRef.current;
5374
5435
  const element = instance?.scrollElement;
5375
5436
  if (!instance || !element || instance.options.count === 0 || element.clientHeight === 0 || isPinnedToBottomRef.current || restoringVisibilityRef.current) return;
5376
- const offset = element.scrollTop;
5437
+ const offset = element.scrollTop + heldOffsetRef.current;
5377
5438
  const item = instance.getVirtualItemForOffset(offset);
5378
5439
  const index = item ? rowKeys.indexOf(String(item.key)) : -1;
5379
5440
  resizeAnchorRef.current = item && index >= 0 ? {
@@ -5382,9 +5443,28 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5382
5443
  ready: true
5383
5444
  } : null;
5384
5445
  }
5385
- const estimateRowSize = react.default.useCallback(() => {
5386
- const { total, sizes } = measuredRef.current;
5387
- return sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
5446
+ const measuredKeysRef = react.default.useRef(rowKeys);
5447
+ if (measuredKeysRef.current !== rowKeys) {
5448
+ measuredKeysRef.current = rowKeys;
5449
+ const live = new Set(rowKeys);
5450
+ const measured = measuredRef.current;
5451
+ for (const [key, height] of measured.sizes) if (!live.has(key)) {
5452
+ measured.sizes.delete(key);
5453
+ measured.total -= height;
5454
+ }
5455
+ for (const key of measured.estimates.keys()) if (!live.has(key)) measured.estimates.delete(key);
5456
+ }
5457
+ const estimateRowSize = react.default.useCallback((index) => {
5458
+ const { total, sizes, estimates } = measuredRef.current;
5459
+ const mean = sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
5460
+ const key = rowKeysRef.current[index];
5461
+ if (key === void 0) return mean;
5462
+ let estimate = estimates.get(key);
5463
+ if (estimate === void 0) {
5464
+ estimate = mean;
5465
+ estimates.set(key, estimate);
5466
+ }
5467
+ return estimate;
5388
5468
  }, []);
5389
5469
  const measuredWidthRef = react.default.useRef(null);
5390
5470
  const captureResizeAnchor = react.default.useCallback((instance) => {
@@ -5397,7 +5477,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5397
5477
  };
5398
5478
  return;
5399
5479
  }
5400
- const offset = instance.scrollElement?.scrollTop ?? 0;
5480
+ const offset = (instance.scrollElement?.scrollTop ?? 0) + heldOffsetRef.current;
5401
5481
  const anchor = instance.getVirtualItemForOffset(offset);
5402
5482
  if (anchor) resizeAnchorRef.current = {
5403
5483
  index: anchor.index,
@@ -5407,20 +5487,48 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5407
5487
  }, []);
5408
5488
  const measureRowElement = react.default.useCallback((el, _entry, instance) => {
5409
5489
  captureResizeAnchor(instance);
5410
- const height = el?.getBoundingClientRect().height ?? 0;
5490
+ const rect = el.getBoundingClientRect();
5491
+ const measuredHeight = rect.height;
5492
+ const height = typeof measuredHeight === "number" ? measuredHeight : 0;
5411
5493
  const index = Number(el?.dataset?.index);
5412
- const key = Number.isInteger(index) ? instance.options.getItemKey(index) : void 0;
5413
- if (height > 0 && key !== void 0) {
5494
+ const key = Number.isInteger(index) ? rowKeysRef.current[index] : void 0;
5495
+ const rowTop = rect.top;
5496
+ const viewportTop = typeof rowTop === "number" ? instance.scrollElement?.getBoundingClientRect().top : void 0;
5497
+ lastMeasuredRef.current = Number.isInteger(index) && typeof rowTop === "number" && typeof viewportTop === "number" ? {
5498
+ index,
5499
+ above: rowTop < viewportTop
5500
+ } : null;
5501
+ const hidden = !el.isConnected || !instance.scrollElement?.clientHeight;
5502
+ if ((height > 0 || !hidden) && key !== void 0) {
5414
5503
  const { total, sizes } = measuredRef.current;
5415
5504
  measuredRef.current.total = total - (sizes.get(key) ?? 0) + height;
5416
5505
  sizes.set(key, height);
5417
5506
  }
5418
- return height > 0 ? height : key !== void 0 && measuredRef.current.sizes.get(key) || 100;
5507
+ return height > 0 || !hidden ? height : (key === void 0 ? void 0 : measuredRef.current.sizes.get(key)) ?? 100;
5419
5508
  }, [captureResizeAnchor]);
5420
- const shouldAdjustScrollOnResize = react.default.useCallback((item, _delta, instance) => {
5509
+ const shouldAdjustScrollOnResize = react.default.useCallback((item, delta, instance) => {
5510
+ const measured = lastMeasuredRef.current;
5511
+ lastMeasuredRef.current = null;
5421
5512
  if (isPinnedToBottomRef.current || resizeAnchorRef.current || restoringVisibilityRef.current) return false;
5422
5513
  const scrollAdjustments = instance.scrollAdjustments ?? 0;
5423
- return item.start < (instance.scrollOffset ?? 0) + scrollAdjustments;
5514
+ if (!(measured?.index === item.index ? measured.above : item.start < (instance.scrollOffset ?? 0) + scrollAdjustments)) return false;
5515
+ if (userScrollingRef.current || heldOffsetRef.current !== 0) {
5516
+ const held = heldOffsetRef.current;
5517
+ heldOffsetRef.current += delta;
5518
+ keepListTopInView(instance.scrollElement?.scrollTop ?? 0);
5519
+ instance.scrollOffset = (instance.scrollOffset ?? 0) + heldOffsetRef.current - held;
5520
+ return false;
5521
+ }
5522
+ return true;
5523
+ }, [keepListTopInView]);
5524
+ const observeListOffset = react.default.useCallback((instance, notify) => (0, _tanstack_react_virtual.observeElementOffset)(instance, (offset, isScrolling) => {
5525
+ if (keepListTopInView(offset)) applyHeldOffset();
5526
+ notify(offset + heldOffsetRef.current, isScrolling);
5527
+ }), [keepListTopInView, applyHeldOffset]);
5528
+ const scrollToListOffset = react.default.useCallback((offset, options, instance) => {
5529
+ const elementOffset = offset - heldOffsetRef.current;
5530
+ ownScrollWriteRef.current = elementOffset + (options.adjustments ?? 0);
5531
+ (0, _tanstack_react_virtual.elementScroll)(elementOffset, options, instance);
5424
5532
  }, []);
5425
5533
  const observeScrollRect = react.default.useCallback((instance, notify) => {
5426
5534
  let frame;
@@ -5451,7 +5559,8 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5451
5559
  instance.getTotalSize();
5452
5560
  measuredRef.current = {
5453
5561
  total: 0,
5454
- sizes: /* @__PURE__ */ new Map()
5562
+ sizes: /* @__PURE__ */ new Map(),
5563
+ estimates: /* @__PURE__ */ new Map()
5455
5564
  };
5456
5565
  instance.elementsCache.forEach((element) => {
5457
5566
  measureRowElement(element, void 0, instance);
@@ -5477,13 +5586,35 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5477
5586
  };
5478
5587
  }, [captureResizeAnchor, measureRowElement]);
5479
5588
  const getItemKey = react.default.useCallback((index) => rowKeys[index] ?? index, [rowKeys]);
5589
+ const rangeExtractor = react.default.useCallback((range) => {
5590
+ const instance = virtualizerRef.current;
5591
+ const items = instance?.measurementsCache;
5592
+ const reach = instance?.scrollRect?.height ?? 0;
5593
+ if (!items || items.length !== range.count || reach <= 0) return (0, _tanstack_react_virtual.defaultRangeExtractor)(range);
5594
+ let start = range.startIndex;
5595
+ for (let above = 0; start > 0 && range.startIndex - start < MAX_OVERSCAN_ROWS && (range.startIndex - start < range.overscan || above < reach);) {
5596
+ start -= 1;
5597
+ above += items[start].size;
5598
+ }
5599
+ let end = range.endIndex;
5600
+ for (let below = 0; end < range.count - 1 && end - range.endIndex < MAX_OVERSCAN_ROWS && (end - range.endIndex < range.overscan || below < reach);) {
5601
+ end += 1;
5602
+ below += items[end].size;
5603
+ }
5604
+ const indexes = [];
5605
+ for (let index = start; index <= end; index++) indexes.push(index);
5606
+ return indexes;
5607
+ }, []);
5480
5608
  const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
5481
5609
  count: shouldVirtualize ? rows.length : 0,
5482
5610
  getItemKey,
5483
5611
  getScrollElement: () => shouldVirtualize ? scrollElement : null,
5484
5612
  observeElementRect: observeScrollRect,
5613
+ observeElementOffset: observeListOffset,
5614
+ scrollToFn: scrollToListOffset,
5485
5615
  estimateSize: estimateRowSize,
5486
5616
  overscan: 5,
5617
+ rangeExtractor,
5487
5618
  measureElement: measureRowElement,
5488
5619
  initialRect: {
5489
5620
  width: 0,
@@ -5491,15 +5622,83 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5491
5622
  }
5492
5623
  });
5493
5624
  virtualizerRef.current = virtualizer;
5625
+ renderedTotalRef.current = virtualizer.getTotalSize();
5626
+ (0, react.useLayoutEffect)(applyHeldOffset);
5627
+ (0, react.useEffect)(() => {
5628
+ const element = shouldVirtualize ? scrollElement : null;
5629
+ if (!element) return;
5630
+ let settleTimer;
5631
+ let settleFrame;
5632
+ let touching = false;
5633
+ const settleStep = () => {
5634
+ settleFrame = void 0;
5635
+ const held = heldOffsetRef.current;
5636
+ if (userScrollingRef.current || touching || held === 0) return;
5637
+ releaseHeldOffset(element, Math.sign(held) * Math.min(Math.abs(held), SETTLE_STEP_PX));
5638
+ if (heldOffsetRef.current !== 0) settleFrame = requestAnimationFrame(settleStep);
5639
+ };
5640
+ const settle = () => {
5641
+ settleTimer = void 0;
5642
+ if (touching) return;
5643
+ userScrollingRef.current = false;
5644
+ if (heldOffsetRef.current !== 0 && settleFrame === void 0) settleFrame = requestAnimationFrame(settleStep);
5645
+ };
5646
+ const scrolling = () => {
5647
+ userScrollingRef.current = true;
5648
+ if (settleFrame !== void 0) {
5649
+ cancelAnimationFrame(settleFrame);
5650
+ settleFrame = void 0;
5651
+ }
5652
+ if (settleTimer !== void 0) clearTimeout(settleTimer);
5653
+ settleTimer = setTimeout(settle, SCROLL_SETTLE_MS);
5654
+ };
5655
+ const onScroll = () => {
5656
+ const own = ownScrollWriteRef.current;
5657
+ if (own !== null && Math.abs(element.scrollTop - own) < 1) {
5658
+ ownScrollWriteRef.current = null;
5659
+ return;
5660
+ }
5661
+ scrolling();
5662
+ };
5663
+ const onTouchStart = () => {
5664
+ touching = true;
5665
+ scrolling();
5666
+ };
5667
+ const onTouchEnd = () => {
5668
+ touching = false;
5669
+ scrolling();
5670
+ };
5671
+ element.addEventListener("scroll", onScroll, { passive: true });
5672
+ element.addEventListener("wheel", scrolling, { passive: true });
5673
+ element.addEventListener("touchstart", onTouchStart, { passive: true });
5674
+ element.addEventListener("touchend", onTouchEnd, { passive: true });
5675
+ element.addEventListener("touchcancel", onTouchEnd, { passive: true });
5676
+ return () => {
5677
+ if (settleTimer !== void 0) clearTimeout(settleTimer);
5678
+ if (settleFrame !== void 0) cancelAnimationFrame(settleFrame);
5679
+ userScrollingRef.current = false;
5680
+ element.removeEventListener("scroll", onScroll);
5681
+ element.removeEventListener("wheel", scrolling);
5682
+ element.removeEventListener("touchstart", onTouchStart);
5683
+ element.removeEventListener("touchend", onTouchEnd);
5684
+ element.removeEventListener("touchcancel", onTouchEnd);
5685
+ };
5686
+ }, [
5687
+ shouldVirtualize,
5688
+ scrollElement,
5689
+ releaseHeldOffset
5690
+ ]);
5494
5691
  isPinnedToBottomRef.current = isPinnedToBottom;
5495
5692
  virtualizer.shouldAdjustScrollPositionOnItemSizeChange = shouldAdjustScrollOnResize;
5496
5693
  (0, react.useLayoutEffect)(() => {
5497
5694
  const anchor = resizeAnchorRef.current;
5498
5695
  if (!anchor?.ready || restoringVisibilityRef.current) return;
5696
+ if (scrollElement) releaseHeldOffset(scrollElement, heldOffsetRef.current);
5499
5697
  const position = virtualizer.getOffsetForIndex(anchor.index, "start");
5500
5698
  if (position && !isPinnedToBottomRef.current) {
5501
5699
  const target = position[0] + anchor.offset;
5502
- if (Math.abs((scrollElement?.scrollTop ?? 0) - target) > .5) virtualizer.scrollToOffset(target);
5700
+ const listOffset = (scrollElement?.scrollTop ?? 0) + heldOffsetRef.current;
5701
+ if (Math.abs(listOffset - target) > .5) virtualizer.scrollToOffset(target);
5503
5702
  }
5504
5703
  const frame = requestAnimationFrame(() => {
5505
5704
  if (resizeAnchorRef.current === anchor) resizeAnchorRef.current = null;
@@ -5553,7 +5752,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5553
5752
  slotProps: reasoningSlotProps
5554
5753
  }, messageKey);
5555
5754
  elements.push(toolCallDisplay === "turn" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Collapsible, {
5556
- open: workOpen.get(message.id) ?? true,
5755
+ open: reasoningOpen.get(message.id) ?? true,
5557
5756
  children: reasoning
5558
5757
  }, messageKey) : reasoning);
5559
5758
  }
@@ -5717,26 +5916,37 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
5717
5916
  ...props,
5718
5917
  children: [
5719
5918
  shouldVirtualize ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5919
+ ref: spacerRef,
5720
5920
  style: {
5721
- height: virtualizer.getTotalSize(),
5921
+ height: renderedTotalRef.current - heldOffsetRef.current,
5722
5922
  position: "relative",
5723
5923
  overflowAnchor: "none"
5724
5924
  },
5725
- children: virtualizer.getVirtualItems().map((virtualItem) => {
5726
- const row = rows[virtualItem.index];
5727
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5728
- "data-index": virtualItem.index,
5729
- "data-scroll-anchor": rowKey(row),
5730
- ref: virtualizer.measureElement,
5731
- style: {
5732
- position: "absolute",
5733
- top: 0,
5734
- left: 0,
5735
- width: "100%",
5736
- transform: `translateY(${virtualItem.start}px)`
5737
- },
5738
- children: renderRow(row)
5739
- }, rowKey(row));
5925
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5926
+ ref: shiftedRowsRef,
5927
+ style: {
5928
+ position: "absolute",
5929
+ top: 0,
5930
+ left: 0,
5931
+ width: "100%",
5932
+ transform: heldOffsetRef.current ? `translateY(${-heldOffsetRef.current}px)` : void 0
5933
+ },
5934
+ children: virtualizer.getVirtualItems().map((virtualItem) => {
5935
+ const row = rows[virtualItem.index];
5936
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
5937
+ "data-index": virtualItem.index,
5938
+ "data-scroll-anchor": rowKey(row),
5939
+ ref: virtualizer.measureElement,
5940
+ style: {
5941
+ position: "absolute",
5942
+ top: 0,
5943
+ left: 0,
5944
+ width: "100%",
5945
+ transform: `translateY(${virtualItem.start}px)`
5946
+ },
5947
+ children: renderRow(row)
5948
+ }, rowKey(row));
5949
+ })
5740
5950
  })
5741
5951
  }) : messageElements,
5742
5952
  interruptElement,
@@ -8366,6 +8576,12 @@ Object.defineProperty(exports, 'IntelligenceAgent', {
8366
8576
  });
8367
8577
  exports.IntelligenceIndicator = IntelligenceIndicator;
8368
8578
  exports.IntelligenceIndicatorView = IntelligenceIndicatorView;
8579
+ Object.defineProperty(exports, 'IntelligenceReplayFailedError', {
8580
+ enumerable: true,
8581
+ get: function () {
8582
+ return _copilotkit_core.IntelligenceReplayFailedError;
8583
+ }
8584
+ });
8369
8585
  Object.defineProperty(exports, 'InterruptSchema', {
8370
8586
  enumerable: true,
8371
8587
  get: function () {