@copilotkit/react-core 2.0.0-rc.61 → 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.umd.js CHANGED
@@ -1377,7 +1377,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
1377
1377
 
1378
1378
  //#endregion
1379
1379
  //#region package.json
1380
- var version$1 = "2.0.0-rc.61";
1380
+ var version$1 = "2.0.0-rc.62";
1381
1381
 
1382
1382
  //#endregion
1383
1383
  //#region src/components/CopilotKitInspector.tsx
@@ -1492,15 +1492,22 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
1492
1492
  * protocol session (`bindMcpApp`, loaded lazily); this component only draws
1493
1493
  * the state around it.
1494
1494
  */
1495
- const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent, allowSameOriginFallback }) {
1495
+ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent, allowSameOriginFallback, modelContext }) {
1496
1496
  const { copilotkit } = useCopilotKit();
1497
1497
  const containerRef = (0, react.useRef)(null);
1498
1498
  const messageId = message?.id;
1499
1499
  const app = (0, react.useMemo)(() => new _copilotkit_mcp_apps_renderer_activity.ɵMcpAppHost({
1500
1500
  host: copilotkit,
1501
- sessionOptions: { allowSameOriginFallback },
1501
+ sessionOptions: {
1502
+ allowSameOriginFallback,
1503
+ modelContext
1504
+ },
1502
1505
  importRenderer: () => import("@copilotkit/mcp-apps-renderer")
1503
- }), [copilotkit, allowSameOriginFallback]);
1506
+ }), [
1507
+ copilotkit,
1508
+ allowSameOriginFallback,
1509
+ modelContext
1510
+ ]);
1504
1511
  const state = (0, react.useSyncExternalStore)(app.subscribe, app.getState, app.getState);
1505
1512
  (0, react.useEffect)(() => {
1506
1513
  app.setAgent(agent);
@@ -9228,11 +9235,6 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
9228
9235
  const EMPTY_HEADERS = Object.freeze({});
9229
9236
  const EMPTY_PROPERTIES = Object.freeze({});
9230
9237
  const EMPTY_AGENTS = Object.freeze({});
9231
- /** The MCP Apps renderer with `mcpApps.allowSameOriginFallback` applied. */
9232
- const SameOriginMCPAppsActivityRenderer = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MCPAppsActivityRenderer, {
9233
- ...props,
9234
- allowSameOriginFallback: true
9235
- });
9236
9238
  /**
9237
9239
  * The `generativeUI` prop with the options of the deprecated `a2ui` prop:
9238
9240
  * `a2ui.catalog` is the `ui` and `a2ui.theme` the `theme`, unless
@@ -9307,13 +9309,19 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
9307
9309
  const renderActivityMessagesList = useStableArrayProp(renderActivityMessages, "renderActivityMessages");
9308
9310
  const copilotkitRef = (0, react.useRef)(null);
9309
9311
  const mcpAppsAllowSameOrigin = mcpApps?.allowSameOriginFallback === true;
9312
+ const mcpAppsModelContext = mcpApps?.modelContext === true;
9313
+ const mcpAppsRenderer = (0, react.useMemo)(() => mcpAppsAllowSameOrigin || mcpAppsModelContext ? (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MCPAppsActivityRenderer, {
9314
+ ...props,
9315
+ allowSameOriginFallback: mcpAppsAllowSameOrigin,
9316
+ modelContext: mcpAppsModelContext
9317
+ }) : MCPAppsActivityRenderer, [mcpAppsAllowSameOrigin, mcpAppsModelContext]);
9310
9318
  const allActivityRenderers = (0, react.useMemo)(() => (0, _copilotkit_core.ɵassembleActivityRenderers)({
9311
9319
  app: renderActivityMessagesList,
9312
9320
  builtIns: [
9313
9321
  {
9314
9322
  activityType: _copilotkit_mcp_apps_renderer_activity.MCPAppsActivityType,
9315
9323
  content: _copilotkit_mcp_apps_renderer_activity.MCPAppsActivityContentSchema,
9316
- render: mcpAppsAllowSameOrigin ? SameOriginMCPAppsActivityRenderer : MCPAppsActivityRenderer
9324
+ render: mcpAppsRenderer
9317
9325
  },
9318
9326
  openGenUIActive && {
9319
9327
  activityType: OpenGenerativeUIActivityType,
@@ -9327,7 +9335,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
9327
9335
  renderActivityMessagesList,
9328
9336
  openGenUIActive,
9329
9337
  generativeUIActive,
9330
- mcpAppsAllowSameOrigin
9338
+ mcpAppsRenderer
9331
9339
  ]);
9332
9340
  const resolvedConfig = (0, react.useMemo)(() => (0, _copilotkit_core.ɵresolveProviderConfig)({
9333
9341
  runtimeUrl,
@@ -10517,6 +10525,11 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
10517
10525
  UseAgentUpdate.OnStateChanged,
10518
10526
  UseAgentUpdate.OnRunStatusChanged
10519
10527
  ];
10528
+ /**
10529
+ * Returns the selected agent and its readiness, subscribing to agent updates.
10530
+ * Uses a shared agent by default, or a private proxy when `agentId`,
10531
+ * `runtimeAgentId`, and `threadId` are supplied together.
10532
+ */
10520
10533
  function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {}) {
10521
10534
  (0, _copilotkit_core.ɵvalidateAgentBinding)({
10522
10535
  agentId,
@@ -12537,7 +12550,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
12537
12550
  ...headerProps,
12538
12551
  children: [
12539
12552
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
12540
- className: "cpk-reasoning-message-label",
12553
+ className: (0, _copilotkit_core.ɵcn)("cpk-reasoning-message-label", isStreaming && "cpk-shimmer"),
12541
12554
  children: label
12542
12555
  }),
12543
12556
  isStreaming && !hasContent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -13194,6 +13207,8 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13194
13207
  if (JSON.stringify(prevProps.stateSnapshot) !== JSON.stringify(nextProps.stateSnapshot)) return false;
13195
13208
  return true;
13196
13209
  });
13210
+ /** At most this many rows are rendered beyond the viewport on either side. */
13211
+ const MAX_OVERSCAN_ROWS = 400;
13197
13212
  /** A row holding a single message, rendered as it would be ungrouped. */
13198
13213
  function messageRow(message) {
13199
13214
  return {
@@ -13209,7 +13224,19 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13209
13224
  };
13210
13225
  }
13211
13226
  const GROUP_ROW_KEY_PREFIX = "copilotkit-group:";
13227
+ const MESSAGE_ROW_KEY_PREFIX = "copilotkit-message:";
13212
13228
  const VIRTUALIZE_THRESHOLD = 50;
13229
+ /**
13230
+ * How long the scroll position must stay still, with no wheel or touch input,
13231
+ * before a correction held back during scrolling is written to `scrollTop`.
13232
+ */
13233
+ const SCROLL_SETTLE_MS = 250;
13234
+ /**
13235
+ * The most a held correction moves per frame once it is written. Safari can
13236
+ * still drop a write when a new gesture starts in the same frame; a small
13237
+ * step keeps that from showing.
13238
+ */
13239
+ const SETTLE_STEP_PX = 4;
13213
13240
  function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, workSummary, isRunning = false, transformMessages, groupMessages, messageFeedback = true, toolCallDisplay = "grouped", children, className, ...props }) {
13214
13241
  const isPinnedToBottom = (0, react.useContext)(ScrollPinnedContext);
13215
13242
  const renderCustomMessage = useRenderCustomMessages();
@@ -13254,7 +13281,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13254
13281
  const rendererNames = useToolCallRendererNames();
13255
13282
  const [viewModel] = (0, react.useState)(_copilotkit_core.ɵcreateMessageViewModel);
13256
13283
  (0, react.useSyncExternalStore)((0, react.useCallback)((onChange) => viewModel.subscribe(onChange), [viewModel]), () => viewModel.getSnapshot(), () => viewModel.getSnapshot());
13257
- const { layouts: toolCallLayouts, turnByFirstMessage, latestTurnKey, workOpen, workTextOpen, showCursor, pendingWorkSummary } = viewModel.update({
13284
+ const { layouts: toolCallLayouts, turnByFirstMessage, latestTurnKey, workOpen, workTextOpen, reasoningOpen, showCursor, pendingWorkSummary } = viewModel.update({
13258
13285
  display: toolCallDisplay,
13259
13286
  messages,
13260
13287
  rendered: renderedMessages,
@@ -13331,11 +13358,14 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13331
13358
  (0, _copilotkit_shared.commitRowKeyStore)(rowKeyStore, renderedMessages);
13332
13359
  }, [rowKeyStore, renderedMessages]);
13333
13360
  const stableGroupKey = (key) => rowRenderKeys.get(key) ?? key;
13334
- const rowKey = (row) => row.type === "group" ? `${GROUP_ROW_KEY_PREFIX}${stableGroupKey(row.key)}` : rowRenderKeys.get(row.message.id) ?? row.message.id;
13335
- const rowKeysRef = (0, react.useRef)([]);
13336
- const nextRowKeys = rows.map(rowKey);
13337
- if (nextRowKeys.length !== rowKeysRef.current.length || nextRowKeys.some((key, index) => key !== rowKeysRef.current[index])) rowKeysRef.current = nextRowKeys;
13338
- const rowKeys = rowKeysRef.current;
13361
+ 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}`;
13362
+ const previousRowKeysRef = (0, react.useRef)([]);
13363
+ const rowKeys = (0, react.useMemo)(() => {
13364
+ const next = rows.map(rowKey);
13365
+ const previous = previousRowKeysRef.current;
13366
+ return next.length === previous.length && next.every((key, index) => key === previous[index]) ? previous : next;
13367
+ }, [rows, rowRenderKeys]);
13368
+ previousRowKeysRef.current = rowKeys;
13339
13369
  const groupStateRef = (0, react.useRef)(/* @__PURE__ */ new Map());
13340
13370
  const groupSettersRef = (0, react.useRef)(/* @__PURE__ */ new Map());
13341
13371
  const groupStateThreadRef = (0, react.useRef)(config?.threadId);
@@ -13422,12 +13452,41 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13422
13452
  ]);
13423
13453
  const measuredRef = react.default.useRef({
13424
13454
  total: 0,
13425
- sizes: /* @__PURE__ */ new Map()
13455
+ sizes: /* @__PURE__ */ new Map(),
13456
+ estimates: /* @__PURE__ */ new Map()
13426
13457
  });
13458
+ const rowKeysRef = react.default.useRef(rowKeys);
13459
+ rowKeysRef.current = rowKeys;
13427
13460
  const resizeAnchorRef = react.default.useRef(null);
13428
13461
  const restoringVisibilityRef = react.default.useRef(false);
13429
13462
  const isPinnedToBottomRef = react.default.useRef(isPinnedToBottom);
13430
13463
  const virtualizerRef = react.default.useRef(null);
13464
+ const heldOffsetRef = react.default.useRef(0);
13465
+ const spacerRef = react.default.useRef(null);
13466
+ const shiftedRowsRef = react.default.useRef(null);
13467
+ const lastMeasuredRef = react.default.useRef(null);
13468
+ const userScrollingRef = react.default.useRef(false);
13469
+ const ownScrollWriteRef = react.default.useRef(null);
13470
+ const renderedTotalRef = (0, react.useRef)(0);
13471
+ const applyHeldOffset = react.default.useCallback(() => {
13472
+ const held = heldOffsetRef.current;
13473
+ if (spacerRef.current) spacerRef.current.style.height = `${renderedTotalRef.current - held}px`;
13474
+ if (shiftedRowsRef.current) shiftedRowsRef.current.style.transform = held ? `translateY(${-held}px)` : "";
13475
+ }, []);
13476
+ const keepListTopInView = react.default.useCallback((scrollTop) => {
13477
+ if (heldOffsetRef.current >= 0 || scrollTop + heldOffsetRef.current >= 0) return false;
13478
+ heldOffsetRef.current = scrollTop > 0 ? -scrollTop : 0;
13479
+ return true;
13480
+ }, []);
13481
+ const releaseHeldOffset = react.default.useCallback((element, amount) => {
13482
+ if (amount === 0) return;
13483
+ const scrollTop = element.scrollTop;
13484
+ heldOffsetRef.current -= amount;
13485
+ applyHeldOffset();
13486
+ const target = Math.max(0, scrollTop + amount);
13487
+ ownScrollWriteRef.current = target;
13488
+ element.scrollTop = target;
13489
+ }, [applyHeldOffset]);
13431
13490
  const history = react.default.useRef({
13432
13491
  messages: deduplicatedMessages,
13433
13492
  threadId,
@@ -13440,9 +13499,11 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13440
13499
  else {
13441
13500
  history.generation += 1;
13442
13501
  resizeAnchorRef.current = null;
13502
+ heldOffsetRef.current = 0;
13443
13503
  measuredRef.current = {
13444
13504
  total: 0,
13445
- sizes: /* @__PURE__ */ new Map()
13505
+ sizes: /* @__PURE__ */ new Map(),
13506
+ estimates: /* @__PURE__ */ new Map()
13446
13507
  };
13447
13508
  }
13448
13509
  }
@@ -13454,7 +13515,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13454
13515
  const instance = virtualizerRef.current;
13455
13516
  const element = instance?.scrollElement;
13456
13517
  if (!instance || !element || instance.options.count === 0 || element.clientHeight === 0 || isPinnedToBottomRef.current || restoringVisibilityRef.current) return;
13457
- const offset = element.scrollTop;
13518
+ const offset = element.scrollTop + heldOffsetRef.current;
13458
13519
  const item = instance.getVirtualItemForOffset(offset);
13459
13520
  const index = item ? rowKeys.indexOf(String(item.key)) : -1;
13460
13521
  resizeAnchorRef.current = item && index >= 0 ? {
@@ -13463,9 +13524,28 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13463
13524
  ready: true
13464
13525
  } : null;
13465
13526
  }
13466
- const estimateRowSize = react.default.useCallback(() => {
13467
- const { total, sizes } = measuredRef.current;
13468
- return sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
13527
+ const measuredKeysRef = react.default.useRef(rowKeys);
13528
+ if (measuredKeysRef.current !== rowKeys) {
13529
+ measuredKeysRef.current = rowKeys;
13530
+ const live = new Set(rowKeys);
13531
+ const measured = measuredRef.current;
13532
+ for (const [key, height] of measured.sizes) if (!live.has(key)) {
13533
+ measured.sizes.delete(key);
13534
+ measured.total -= height;
13535
+ }
13536
+ for (const key of measured.estimates.keys()) if (!live.has(key)) measured.estimates.delete(key);
13537
+ }
13538
+ const estimateRowSize = react.default.useCallback((index) => {
13539
+ const { total, sizes, estimates } = measuredRef.current;
13540
+ const mean = sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
13541
+ const key = rowKeysRef.current[index];
13542
+ if (key === void 0) return mean;
13543
+ let estimate = estimates.get(key);
13544
+ if (estimate === void 0) {
13545
+ estimate = mean;
13546
+ estimates.set(key, estimate);
13547
+ }
13548
+ return estimate;
13469
13549
  }, []);
13470
13550
  const measuredWidthRef = react.default.useRef(null);
13471
13551
  const captureResizeAnchor = react.default.useCallback((instance) => {
@@ -13478,7 +13558,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13478
13558
  };
13479
13559
  return;
13480
13560
  }
13481
- const offset = instance.scrollElement?.scrollTop ?? 0;
13561
+ const offset = (instance.scrollElement?.scrollTop ?? 0) + heldOffsetRef.current;
13482
13562
  const anchor = instance.getVirtualItemForOffset(offset);
13483
13563
  if (anchor) resizeAnchorRef.current = {
13484
13564
  index: anchor.index,
@@ -13488,20 +13568,48 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13488
13568
  }, []);
13489
13569
  const measureRowElement = react.default.useCallback((el, _entry, instance) => {
13490
13570
  captureResizeAnchor(instance);
13491
- const height = el?.getBoundingClientRect().height ?? 0;
13571
+ const rect = el.getBoundingClientRect();
13572
+ const measuredHeight = rect.height;
13573
+ const height = typeof measuredHeight === "number" ? measuredHeight : 0;
13492
13574
  const index = Number(el?.dataset?.index);
13493
- const key = Number.isInteger(index) ? instance.options.getItemKey(index) : void 0;
13494
- if (height > 0 && key !== void 0) {
13575
+ const key = Number.isInteger(index) ? rowKeysRef.current[index] : void 0;
13576
+ const rowTop = rect.top;
13577
+ const viewportTop = typeof rowTop === "number" ? instance.scrollElement?.getBoundingClientRect().top : void 0;
13578
+ lastMeasuredRef.current = Number.isInteger(index) && typeof rowTop === "number" && typeof viewportTop === "number" ? {
13579
+ index,
13580
+ above: rowTop < viewportTop
13581
+ } : null;
13582
+ const hidden = !el.isConnected || !instance.scrollElement?.clientHeight;
13583
+ if ((height > 0 || !hidden) && key !== void 0) {
13495
13584
  const { total, sizes } = measuredRef.current;
13496
13585
  measuredRef.current.total = total - (sizes.get(key) ?? 0) + height;
13497
13586
  sizes.set(key, height);
13498
13587
  }
13499
- return height > 0 ? height : key !== void 0 && measuredRef.current.sizes.get(key) || 100;
13588
+ return height > 0 || !hidden ? height : (key === void 0 ? void 0 : measuredRef.current.sizes.get(key)) ?? 100;
13500
13589
  }, [captureResizeAnchor]);
13501
- const shouldAdjustScrollOnResize = react.default.useCallback((item, _delta, instance) => {
13590
+ const shouldAdjustScrollOnResize = react.default.useCallback((item, delta, instance) => {
13591
+ const measured = lastMeasuredRef.current;
13592
+ lastMeasuredRef.current = null;
13502
13593
  if (isPinnedToBottomRef.current || resizeAnchorRef.current || restoringVisibilityRef.current) return false;
13503
13594
  const scrollAdjustments = instance.scrollAdjustments ?? 0;
13504
- return item.start < (instance.scrollOffset ?? 0) + scrollAdjustments;
13595
+ if (!(measured?.index === item.index ? measured.above : item.start < (instance.scrollOffset ?? 0) + scrollAdjustments)) return false;
13596
+ if (userScrollingRef.current || heldOffsetRef.current !== 0) {
13597
+ const held = heldOffsetRef.current;
13598
+ heldOffsetRef.current += delta;
13599
+ keepListTopInView(instance.scrollElement?.scrollTop ?? 0);
13600
+ instance.scrollOffset = (instance.scrollOffset ?? 0) + heldOffsetRef.current - held;
13601
+ return false;
13602
+ }
13603
+ return true;
13604
+ }, [keepListTopInView]);
13605
+ const observeListOffset = react.default.useCallback((instance, notify) => (0, _tanstack_react_virtual.observeElementOffset)(instance, (offset, isScrolling) => {
13606
+ if (keepListTopInView(offset)) applyHeldOffset();
13607
+ notify(offset + heldOffsetRef.current, isScrolling);
13608
+ }), [keepListTopInView, applyHeldOffset]);
13609
+ const scrollToListOffset = react.default.useCallback((offset, options, instance) => {
13610
+ const elementOffset = offset - heldOffsetRef.current;
13611
+ ownScrollWriteRef.current = elementOffset + (options.adjustments ?? 0);
13612
+ (0, _tanstack_react_virtual.elementScroll)(elementOffset, options, instance);
13505
13613
  }, []);
13506
13614
  const observeScrollRect = react.default.useCallback((instance, notify) => {
13507
13615
  let frame;
@@ -13532,7 +13640,8 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13532
13640
  instance.getTotalSize();
13533
13641
  measuredRef.current = {
13534
13642
  total: 0,
13535
- sizes: /* @__PURE__ */ new Map()
13643
+ sizes: /* @__PURE__ */ new Map(),
13644
+ estimates: /* @__PURE__ */ new Map()
13536
13645
  };
13537
13646
  instance.elementsCache.forEach((element) => {
13538
13647
  measureRowElement(element, void 0, instance);
@@ -13558,13 +13667,35 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13558
13667
  };
13559
13668
  }, [captureResizeAnchor, measureRowElement]);
13560
13669
  const getItemKey = react.default.useCallback((index) => rowKeys[index] ?? index, [rowKeys]);
13670
+ const rangeExtractor = react.default.useCallback((range) => {
13671
+ const instance = virtualizerRef.current;
13672
+ const items = instance?.measurementsCache;
13673
+ const reach = instance?.scrollRect?.height ?? 0;
13674
+ if (!items || items.length !== range.count || reach <= 0) return (0, _tanstack_react_virtual.defaultRangeExtractor)(range);
13675
+ let start = range.startIndex;
13676
+ for (let above = 0; start > 0 && range.startIndex - start < MAX_OVERSCAN_ROWS && (range.startIndex - start < range.overscan || above < reach);) {
13677
+ start -= 1;
13678
+ above += items[start].size;
13679
+ }
13680
+ let end = range.endIndex;
13681
+ for (let below = 0; end < range.count - 1 && end - range.endIndex < MAX_OVERSCAN_ROWS && (end - range.endIndex < range.overscan || below < reach);) {
13682
+ end += 1;
13683
+ below += items[end].size;
13684
+ }
13685
+ const indexes = [];
13686
+ for (let index = start; index <= end; index++) indexes.push(index);
13687
+ return indexes;
13688
+ }, []);
13561
13689
  const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
13562
13690
  count: shouldVirtualize ? rows.length : 0,
13563
13691
  getItemKey,
13564
13692
  getScrollElement: () => shouldVirtualize ? scrollElement : null,
13565
13693
  observeElementRect: observeScrollRect,
13694
+ observeElementOffset: observeListOffset,
13695
+ scrollToFn: scrollToListOffset,
13566
13696
  estimateSize: estimateRowSize,
13567
13697
  overscan: 5,
13698
+ rangeExtractor,
13568
13699
  measureElement: measureRowElement,
13569
13700
  initialRect: {
13570
13701
  width: 0,
@@ -13572,15 +13703,83 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13572
13703
  }
13573
13704
  });
13574
13705
  virtualizerRef.current = virtualizer;
13706
+ renderedTotalRef.current = virtualizer.getTotalSize();
13707
+ (0, react.useLayoutEffect)(applyHeldOffset);
13708
+ (0, react.useEffect)(() => {
13709
+ const element = shouldVirtualize ? scrollElement : null;
13710
+ if (!element) return;
13711
+ let settleTimer;
13712
+ let settleFrame;
13713
+ let touching = false;
13714
+ const settleStep = () => {
13715
+ settleFrame = void 0;
13716
+ const held = heldOffsetRef.current;
13717
+ if (userScrollingRef.current || touching || held === 0) return;
13718
+ releaseHeldOffset(element, Math.sign(held) * Math.min(Math.abs(held), SETTLE_STEP_PX));
13719
+ if (heldOffsetRef.current !== 0) settleFrame = requestAnimationFrame(settleStep);
13720
+ };
13721
+ const settle = () => {
13722
+ settleTimer = void 0;
13723
+ if (touching) return;
13724
+ userScrollingRef.current = false;
13725
+ if (heldOffsetRef.current !== 0 && settleFrame === void 0) settleFrame = requestAnimationFrame(settleStep);
13726
+ };
13727
+ const scrolling = () => {
13728
+ userScrollingRef.current = true;
13729
+ if (settleFrame !== void 0) {
13730
+ cancelAnimationFrame(settleFrame);
13731
+ settleFrame = void 0;
13732
+ }
13733
+ if (settleTimer !== void 0) clearTimeout(settleTimer);
13734
+ settleTimer = setTimeout(settle, SCROLL_SETTLE_MS);
13735
+ };
13736
+ const onScroll = () => {
13737
+ const own = ownScrollWriteRef.current;
13738
+ if (own !== null && Math.abs(element.scrollTop - own) < 1) {
13739
+ ownScrollWriteRef.current = null;
13740
+ return;
13741
+ }
13742
+ scrolling();
13743
+ };
13744
+ const onTouchStart = () => {
13745
+ touching = true;
13746
+ scrolling();
13747
+ };
13748
+ const onTouchEnd = () => {
13749
+ touching = false;
13750
+ scrolling();
13751
+ };
13752
+ element.addEventListener("scroll", onScroll, { passive: true });
13753
+ element.addEventListener("wheel", scrolling, { passive: true });
13754
+ element.addEventListener("touchstart", onTouchStart, { passive: true });
13755
+ element.addEventListener("touchend", onTouchEnd, { passive: true });
13756
+ element.addEventListener("touchcancel", onTouchEnd, { passive: true });
13757
+ return () => {
13758
+ if (settleTimer !== void 0) clearTimeout(settleTimer);
13759
+ if (settleFrame !== void 0) cancelAnimationFrame(settleFrame);
13760
+ userScrollingRef.current = false;
13761
+ element.removeEventListener("scroll", onScroll);
13762
+ element.removeEventListener("wheel", scrolling);
13763
+ element.removeEventListener("touchstart", onTouchStart);
13764
+ element.removeEventListener("touchend", onTouchEnd);
13765
+ element.removeEventListener("touchcancel", onTouchEnd);
13766
+ };
13767
+ }, [
13768
+ shouldVirtualize,
13769
+ scrollElement,
13770
+ releaseHeldOffset
13771
+ ]);
13575
13772
  isPinnedToBottomRef.current = isPinnedToBottom;
13576
13773
  virtualizer.shouldAdjustScrollPositionOnItemSizeChange = shouldAdjustScrollOnResize;
13577
13774
  (0, react.useLayoutEffect)(() => {
13578
13775
  const anchor = resizeAnchorRef.current;
13579
13776
  if (!anchor?.ready || restoringVisibilityRef.current) return;
13777
+ if (scrollElement) releaseHeldOffset(scrollElement, heldOffsetRef.current);
13580
13778
  const position = virtualizer.getOffsetForIndex(anchor.index, "start");
13581
13779
  if (position && !isPinnedToBottomRef.current) {
13582
13780
  const target = position[0] + anchor.offset;
13583
- if (Math.abs((scrollElement?.scrollTop ?? 0) - target) > .5) virtualizer.scrollToOffset(target);
13781
+ const listOffset = (scrollElement?.scrollTop ?? 0) + heldOffsetRef.current;
13782
+ if (Math.abs(listOffset - target) > .5) virtualizer.scrollToOffset(target);
13584
13783
  }
13585
13784
  const frame = requestAnimationFrame(() => {
13586
13785
  if (resizeAnchorRef.current === anchor) resizeAnchorRef.current = null;
@@ -13634,7 +13833,7 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13634
13833
  slotProps: reasoningSlotProps
13635
13834
  }, messageKey);
13636
13835
  elements.push(toolCallDisplay === "turn" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Collapsible, {
13637
- open: workOpen.get(message.id) ?? true,
13836
+ open: reasoningOpen.get(message.id) ?? true,
13638
13837
  children: reasoning
13639
13838
  }, messageKey) : reasoning);
13640
13839
  }
@@ -13798,26 +13997,37 @@ _radix_ui_react_popover = __toESM(_radix_ui_react_popover);
13798
13997
  ...props,
13799
13998
  children: [
13800
13999
  shouldVirtualize ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14000
+ ref: spacerRef,
13801
14001
  style: {
13802
- height: virtualizer.getTotalSize(),
14002
+ height: renderedTotalRef.current - heldOffsetRef.current,
13803
14003
  position: "relative",
13804
14004
  overflowAnchor: "none"
13805
14005
  },
13806
- children: virtualizer.getVirtualItems().map((virtualItem) => {
13807
- const row = rows[virtualItem.index];
13808
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
13809
- "data-index": virtualItem.index,
13810
- "data-scroll-anchor": rowKey(row),
13811
- ref: virtualizer.measureElement,
13812
- style: {
13813
- position: "absolute",
13814
- top: 0,
13815
- left: 0,
13816
- width: "100%",
13817
- transform: `translateY(${virtualItem.start}px)`
13818
- },
13819
- children: renderRow(row)
13820
- }, rowKey(row));
14006
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14007
+ ref: shiftedRowsRef,
14008
+ style: {
14009
+ position: "absolute",
14010
+ top: 0,
14011
+ left: 0,
14012
+ width: "100%",
14013
+ transform: heldOffsetRef.current ? `translateY(${-heldOffsetRef.current}px)` : void 0
14014
+ },
14015
+ children: virtualizer.getVirtualItems().map((virtualItem) => {
14016
+ const row = rows[virtualItem.index];
14017
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
14018
+ "data-index": virtualItem.index,
14019
+ "data-scroll-anchor": rowKey(row),
14020
+ ref: virtualizer.measureElement,
14021
+ style: {
14022
+ position: "absolute",
14023
+ top: 0,
14024
+ left: 0,
14025
+ width: "100%",
14026
+ transform: `translateY(${virtualItem.start}px)`
14027
+ },
14028
+ children: renderRow(row)
14029
+ }, rowKey(row));
14030
+ })
13821
14031
  })
13822
14032
  }) : messageElements,
13823
14033
  interruptElement,
@@ -16463,6 +16673,12 @@ Object.defineProperty(exports, 'IntelligenceAgent', {
16463
16673
  });
16464
16674
  exports.IntelligenceIndicator = IntelligenceIndicator;
16465
16675
  exports.IntelligenceIndicatorView = IntelligenceIndicatorView;
16676
+ Object.defineProperty(exports, 'IntelligenceReplayFailedError', {
16677
+ enumerable: true,
16678
+ get: function () {
16679
+ return _copilotkit_core.IntelligenceReplayFailedError;
16680
+ }
16681
+ });
16466
16682
  Object.defineProperty(exports, 'InterruptSchema', {
16467
16683
  enumerable: true,
16468
16684
  get: function () {