@copilotkit/react-core 1.73.3 → 1.74.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.
@@ -1633,6 +1633,10 @@ function useRenderToolCall() {
1633
1633
  return renderToolCall;
1634
1634
  }
1635
1635
 
1636
+ //#endregion
1637
+ //#region package.json
1638
+ var version = "1.74.0";
1639
+
1636
1640
  //#endregion
1637
1641
  //#region src/v2/components/CopilotKitInspector.tsx
1638
1642
  const CopilotKitInspector = ({ core, openRequest, onVisibilityChange }) => {
@@ -1655,7 +1659,11 @@ const CopilotKitInspector = ({ core, openRequest, onVisibilityChange }) => {
1655
1659
  if (!mounted || !mountRef.current) return;
1656
1660
  mod.defineWebInspector?.();
1657
1661
  inspector = mountRef.current.ownerDocument.createElement(mod.WEB_INSPECTOR_TAG);
1658
- mod.configureWebInspectorElement(inspector, latestCoreRef.current);
1662
+ mod.configureWebInspectorElement(inspector, latestCoreRef.current, {
1663
+ development: process.env.NODE_ENV === "development",
1664
+ framework: "react",
1665
+ sdkVersion: version
1666
+ });
1659
1667
  inspector.addEventListener("cpk-inspector-visibility-change", handleVisibilityChange);
1660
1668
  mountRef.current.appendChild(inspector);
1661
1669
  inspectorRef.current = inspector;
@@ -3860,8 +3868,8 @@ function useRenderCustomMessages() {
3860
3868
  if (aHasAgent === (b.agentId !== void 0)) return 0;
3861
3869
  return aHasAgent ? -1 : 1;
3862
3870
  });
3871
+ if (!customMessageRenderers.length) return null;
3863
3872
  return function(params) {
3864
- if (!customMessageRenderers.length) return null;
3865
3873
  const { message, position } = params;
3866
3874
  const resolvedRunId = copilotkit.getRunIdForMessage(agentId, threadId, message.id) ?? copilotkit.getRunIdsForThread(agentId, threadId).slice(-1)[0];
3867
3875
  const runId = resolvedRunId ?? `missing-run-id:${message.id}`;
@@ -7132,6 +7140,32 @@ CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
7132
7140
  */
7133
7141
  const ScrollElementContext = react.default.createContext(null);
7134
7142
 
7143
+ //#endregion
7144
+ //#region src/v2/components/chat/scroll-pinned-context.ts
7145
+ /**
7146
+ * True while the pin-to-bottom behaviour is actively following the bottom of
7147
+ * the thread — i.e. `use-stick-to-bottom` will animate the scroll position to
7148
+ * the bottom the next time the content grows.
7149
+ *
7150
+ * Only CopilotChatView's pin-to-bottom branch provides this. The other scroll
7151
+ * modes leave it `false`, which is correct: nothing else writes the scroll
7152
+ * position on its own, so no one is competing with the virtualizer.
7153
+ *
7154
+ * Why this exists: the virtualizer and `use-stick-to-bottom` both write
7155
+ * `scrollTop` on the same element. The virtualizer writes it to compensate
7156
+ * when a row above the viewport turns out taller than its estimate, so that
7157
+ * what the reader is looking at does not shift. That compensation is essential
7158
+ * while the reader is scrolled up — and pointless while pinned to the bottom,
7159
+ * because the pin is about to move the scroll position anyway. Worse than
7160
+ * pointless: the compensation changes the virtual container's height, the pin
7161
+ * reads that as content growth and animates, the animation brings unmeasured
7162
+ * rows into view, they measure, and the two keep shoving each other.
7163
+ *
7164
+ * Consumed by CopilotChatMessageView to stand the virtualizer down while the
7165
+ * pin owns the scroll position.
7166
+ */
7167
+ const ScrollPinnedContext = react.default.createContext(false);
7168
+
7135
7169
  //#endregion
7136
7170
  //#region src/v2/components/intelligence-indicator/IntelligenceIndicatorView.tsx
7137
7171
  /**
@@ -7597,6 +7631,7 @@ function deduplicateMessages(messages) {
7597
7631
  }
7598
7632
  const VIRTUALIZE_THRESHOLD = 50;
7599
7633
  function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, isRunning = false, children, className, ...props }) {
7634
+ const isPinnedToBottom = (0, react.useContext)(ScrollPinnedContext);
7600
7635
  const renderCustomMessage = useRenderCustomMessages();
7601
7636
  const { renderActivityMessage } = useRenderActivityMessage();
7602
7637
  const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
@@ -7669,18 +7704,52 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7669
7704
  if (process.env.NODE_ENV !== "production" && scrollElementFromCtx && scrollElementFromCtx.clientHeight === 0) console.warn("[CopilotKit] Chat scroll container has clientHeight=0 — virtualization disabled. Ensure the chat is rendered in a visible container with a non-zero height.");
7670
7705
  }, [scrollElementFromCtx]);
7671
7706
  const shouldVirtualize = !!scrollElement && !children && deduplicatedMessages.length > VIRTUALIZE_THRESHOLD;
7707
+ const measuredRef = react.default.useRef({
7708
+ total: 0,
7709
+ sizes: /* @__PURE__ */ new Map()
7710
+ });
7711
+ const firstMessageId = deduplicatedMessages[0]?.id;
7712
+ const measuredThreadRef = react.default.useRef(firstMessageId);
7713
+ if (measuredThreadRef.current !== firstMessageId) {
7714
+ measuredThreadRef.current = firstMessageId;
7715
+ measuredRef.current = {
7716
+ total: 0,
7717
+ sizes: /* @__PURE__ */ new Map()
7718
+ };
7719
+ }
7720
+ const estimateRowSize = react.default.useCallback(() => {
7721
+ const { total, sizes } = measuredRef.current;
7722
+ return sizes.size > 0 ? Math.max(1, Math.round(total / sizes.size)) : 100;
7723
+ }, []);
7724
+ const measureRowElement = react.default.useCallback((el) => {
7725
+ const height = el?.getBoundingClientRect().height ?? 0;
7726
+ const index = Number(el?.dataset?.index);
7727
+ if (height > 0 && Number.isInteger(index)) {
7728
+ const { total, sizes } = measuredRef.current;
7729
+ measuredRef.current.total = total - (sizes.get(index) ?? 0) + height;
7730
+ sizes.set(index, height);
7731
+ }
7732
+ return height;
7733
+ }, []);
7734
+ const isPinnedToBottomRef = react.default.useRef(isPinnedToBottom);
7735
+ const shouldAdjustScrollOnResize = react.default.useCallback((item, _delta, instance) => {
7736
+ if (isPinnedToBottomRef.current) return false;
7737
+ const scrollAdjustments = instance.scrollAdjustments ?? 0;
7738
+ return item.start < (instance.scrollOffset ?? 0) + scrollAdjustments;
7739
+ }, []);
7672
7740
  const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
7673
7741
  count: shouldVirtualize ? deduplicatedMessages.length : 0,
7674
7742
  getScrollElement: () => scrollElement,
7675
- estimateSize: () => 100,
7743
+ estimateSize: estimateRowSize,
7676
7744
  overscan: 5,
7677
- measureElement: (el) => el?.getBoundingClientRect().height ?? 0,
7745
+ measureElement: measureRowElement,
7678
7746
  initialRect: {
7679
7747
  width: 0,
7680
7748
  height: 600
7681
7749
  }
7682
7750
  });
7683
- const firstMessageId = deduplicatedMessages[0]?.id;
7751
+ isPinnedToBottomRef.current = isPinnedToBottom;
7752
+ virtualizer.shouldAdjustScrollPositionOnItemSizeChange = shouldAdjustScrollOnResize;
7684
7753
  (0, react.useLayoutEffect)(() => {
7685
7754
  if (!shouldVirtualize || !deduplicatedMessages.length) return;
7686
7755
  virtualizer.scrollToIndex(deduplicatedMessages.length - 1, { align: "end" });
@@ -7688,7 +7757,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7688
7757
  const intelligenceTurnAnchors = (0, react.useMemo)(() => getIntelligenceTurnAnchors(deduplicatedMessages), [deduplicatedMessages]);
7689
7758
  const renderMessageBlock = (message) => {
7690
7759
  const elements = [];
7691
- const stateSnapshot = getStateSnapshotForMessage(message.id);
7760
+ const stateSnapshot = renderCustomMessage ? getStateSnapshotForMessage(message.id) : void 0;
7692
7761
  const rowKey = rowRenderKeys.get(message.id) ?? message.id;
7693
7762
  if (renderCustomMessage) elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedCustomMessage, {
7694
7763
  message,
@@ -8325,7 +8394,7 @@ function CopilotChatView({ messageView, input, scrollView, suggestionView, welco
8325
8394
  }
8326
8395
  (function(_CopilotChatView) {
8327
8396
  const ScrollContent = ({ children, scrollToBottomButton, feather, inputContainerHeight, isResizing }) => {
8328
- const { isAtBottom, scrollToBottom, scrollRef } = (0, use_stick_to_bottom.useStickToBottomContext)();
8397
+ const { isAtBottom, scrollToBottom, scrollRef, state } = (0, use_stick_to_bottom.useStickToBottomContext)();
8329
8398
  const [scrollEl, setScrollEl] = (0, react.useState)(null);
8330
8399
  (0, react.useLayoutEffect)(() => {
8331
8400
  setScrollEl(scrollRef.current ?? null);
@@ -8333,25 +8402,28 @@ function CopilotChatView({ messageView, input, scrollView, suggestionView, welco
8333
8402
  const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
8334
8403
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScrollElementContext.Provider, {
8335
8404
  value: scrollEl,
8336
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
8337
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(use_stick_to_bottom.StickToBottom.Content, {
8338
- className: "cpk:overflow-y-auto cpk:overflow-x-hidden",
8339
- style: {
8340
- flex: "1 1 0%",
8341
- minHeight: 0
8342
- },
8343
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
8344
- className: "cpk:px-4 cpk:@3xl:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-6",
8345
- children
8405
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ScrollPinnedContext.Provider, {
8406
+ value: state.isAtBottom,
8407
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
8408
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(use_stick_to_bottom.StickToBottom.Content, {
8409
+ className: "cpk:overflow-y-auto cpk:overflow-x-hidden",
8410
+ style: {
8411
+ flex: "1 1 0%",
8412
+ minHeight: 0
8413
+ },
8414
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
8415
+ className: "cpk:px-4 cpk:@3xl:px-0 cpk:[div[data-sidebar-chat]_&]:px-8 cpk:[div[data-popup-chat]_&]:px-6",
8416
+ children
8417
+ })
8418
+ }),
8419
+ BoundFeather,
8420
+ !isAtBottom && !isResizing && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
8421
+ className: "cpk:absolute cpk:inset-x-0 cpk:flex cpk:justify-center cpk:z-30 cpk:pointer-events-none",
8422
+ style: { bottom: `${inputContainerHeight + SCROLL_BUTTON_OFFSET}px` },
8423
+ children: renderSlot(scrollToBottomButton, CopilotChatView.ScrollToBottomButton, { onClick: () => scrollToBottom() })
8346
8424
  })
8347
- }),
8348
- BoundFeather,
8349
- !isAtBottom && !isResizing && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
8350
- className: "cpk:absolute cpk:inset-x-0 cpk:flex cpk:justify-center cpk:z-30 cpk:pointer-events-none",
8351
- style: { bottom: `${inputContainerHeight + SCROLL_BUTTON_OFFSET}px` },
8352
- children: renderSlot(scrollToBottomButton, CopilotChatView.ScrollToBottomButton, { onClick: () => scrollToBottom() })
8353
- })
8354
- ] })
8425
+ ] })
8426
+ })
8355
8427
  });
8356
8428
  };
8357
8429
  const PinToSendScrollContainer = ({ children, scrollRef, contentRef, scrollToBottom, scrollToBottomButton, feather, inputContainerHeight, isResizing, nonAutoScrollEl, nonAutoScrollRefCallback, showScrollButton, className, ...props }) => {
@@ -10039,7 +10111,7 @@ function CopilotThreadsDrawer({ agentId, onThreadSelect, onNewThread, onLicensed
10039
10111
  const { status, checkFeature } = (0, _copilotkit_react_core_v2_context.useLicenseContext)();
10040
10112
  const licensePresent = status === "valid" || status === "expiring";
10041
10113
  const featureLicensed = checkFeature("threads");
10042
- const licensed = licensePresent && featureLicensed;
10114
+ const licensed = status === "unknown" || licensePresent && featureLicensed;
10043
10115
  const licensePending = status === null;
10044
10116
  const providerAgentId = (0, _copilotkit_react_core_v2_context.useDefaultAgentId)();
10045
10117
  const resolvedAgentId = agentId ?? configuration?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
@@ -13009,4 +13081,4 @@ Object.defineProperty(exports, 'useToast', {
13009
13081
  return useToast;
13010
13082
  }
13011
13083
  });
13012
- //# sourceMappingURL=copilotkit-D_c2dJ9t.cjs.map
13084
+ //# sourceMappingURL=copilotkit-C5FS3iDK.cjs.map