@copilotkit/react-core 1.63.2 → 1.64.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.
@@ -22,7 +22,7 @@ import { StickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
22
22
  import { COPILOTKIT_THREADS_DRAWER_TAG, defineCopilotKitThreadsDrawer } from "@copilotkit/web-components/threads-drawer";
23
23
  import ReactMarkdown from "react-markdown";
24
24
 
25
- //#region src/v2/lib/slots.tsx
25
+ //#region src/v2/lib/shallow-stable-ref.ts
26
26
  /**
27
27
  * Shallow equality comparison for objects.
28
28
  */
@@ -62,64 +62,6 @@ function useShallowStableRef(value) {
62
62
  ref.current = value;
63
63
  return ref.current;
64
64
  }
65
- /**
66
- * Check if a value is a React component type (function, class, forwardRef, memo, etc.)
67
- */
68
- function isReactComponentType(value) {
69
- if (typeof value === "function") return true;
70
- if (value && typeof value === "object" && "$$typeof" in value && !React.isValidElement(value)) return true;
71
- return false;
72
- }
73
- /**
74
- * Internal function to render a slot value as a React element (non-memoized).
75
- */
76
- function renderSlotElement(slot, DefaultComponent, props) {
77
- if (typeof slot === "string") {
78
- const existingClassName = props.className;
79
- return React.createElement(DefaultComponent, {
80
- ...props,
81
- className: twMerge(existingClassName, slot)
82
- });
83
- }
84
- if (isReactComponentType(slot)) return React.createElement(slot, props);
85
- if (slot && typeof slot === "object" && !React.isValidElement(slot)) return React.createElement(DefaultComponent, {
86
- ...props,
87
- ...slot
88
- });
89
- return React.createElement(DefaultComponent, props);
90
- }
91
- /**
92
- * Internal memoized wrapper component for renderSlot.
93
- * Uses forwardRef to support ref forwarding.
94
- */
95
- const MemoizedSlotWrapper = React.memo(React.forwardRef(function MemoizedSlotWrapper(props, ref) {
96
- const { $slot, $component, ...rest } = props;
97
- return renderSlotElement($slot, $component, ref !== null ? {
98
- ...rest,
99
- ref
100
- } : rest);
101
- }), (prev, next) => {
102
- if (prev.$slot !== next.$slot) return false;
103
- if (prev.$component !== next.$component) return false;
104
- const { $slot: _ps, $component: _pc, ...prevRest } = prev;
105
- const { $slot: _ns, $component: _nc, ...nextRest } = next;
106
- return shallowEqual(prevRest, nextRest);
107
- });
108
- /**
109
- * Renders a slot value as a memoized React element.
110
- * Automatically prevents unnecessary re-renders using shallow prop comparison.
111
- * Supports ref forwarding.
112
- *
113
- * @example
114
- * renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
115
- */
116
- function renderSlot(slot, DefaultComponent, props) {
117
- return React.createElement(MemoizedSlotWrapper, {
118
- ...props,
119
- $slot: slot,
120
- $component: DefaultComponent
121
- });
122
- }
123
65
 
124
66
  //#endregion
125
67
  //#region src/v2/providers/CopilotChatConfigurationProvider.tsx
@@ -423,12 +365,13 @@ function Tooltip({ ...props }) {
423
365
  ...props
424
366
  }) });
425
367
  }
426
- function TooltipTrigger({ ...props }) {
368
+ const TooltipTrigger = React$1.forwardRef(function TooltipTrigger({ ...props }, ref) {
427
369
  return /* @__PURE__ */ jsx(TooltipPrimitive.Trigger, {
370
+ ref,
428
371
  "data-slot": "tooltip-trigger",
429
372
  ...props
430
373
  });
431
- }
374
+ });
432
375
  function TooltipContent({ className, sideOffset = 0, children, ...props }) {
433
376
  return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(TooltipPrimitive.Content, {
434
377
  "data-copilotkit": true,
@@ -448,12 +391,13 @@ function DropdownMenu({ ...props }) {
448
391
  ...props
449
392
  });
450
393
  }
451
- function DropdownMenuTrigger({ ...props }) {
394
+ const DropdownMenuTrigger = React$1.forwardRef(function DropdownMenuTrigger({ ...props }, ref) {
452
395
  return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Trigger, {
396
+ ref,
453
397
  "data-slot": "dropdown-menu-trigger",
454
398
  ...props
455
399
  });
456
- }
400
+ });
457
401
  function DropdownMenuContent({ className, sideOffset = 4, ...props }) {
458
402
  return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ jsx(DropdownMenuPrimitive.Content, {
459
403
  "data-copilotkit": true,
@@ -702,6 +646,67 @@ const CopilotChatAudioRecorder = forwardRef((props, ref) => {
702
646
  });
703
647
  CopilotChatAudioRecorder.displayName = "CopilotChatAudioRecorder";
704
648
 
649
+ //#endregion
650
+ //#region src/v2/lib/slots.tsx
651
+ /**
652
+ * Check if a value is a React component type (function, class, forwardRef, memo, etc.)
653
+ */
654
+ function isReactComponentType(value) {
655
+ if (typeof value === "function") return true;
656
+ if (value && typeof value === "object" && "$$typeof" in value && !React.isValidElement(value)) return true;
657
+ return false;
658
+ }
659
+ /**
660
+ * Internal function to render a slot value as a React element (non-memoized).
661
+ */
662
+ function renderSlotElement(slot, DefaultComponent, props) {
663
+ if (typeof slot === "string") {
664
+ const existingClassName = props.className;
665
+ return React.createElement(DefaultComponent, {
666
+ ...props,
667
+ className: twMerge(existingClassName, slot)
668
+ });
669
+ }
670
+ if (isReactComponentType(slot)) return React.createElement(slot, props);
671
+ if (slot && typeof slot === "object" && !React.isValidElement(slot)) return React.createElement(DefaultComponent, {
672
+ ...props,
673
+ ...slot
674
+ });
675
+ return React.createElement(DefaultComponent, props);
676
+ }
677
+ /**
678
+ * Internal memoized wrapper component for renderSlot.
679
+ * Uses forwardRef to support ref forwarding.
680
+ */
681
+ const MemoizedSlotWrapper = React.memo(React.forwardRef(function MemoizedSlotWrapper(props, ref) {
682
+ const { $slot, $component, ...rest } = props;
683
+ return renderSlotElement($slot, $component, ref !== null ? {
684
+ ...rest,
685
+ ref
686
+ } : rest);
687
+ }), (prev, next) => {
688
+ if (prev.$slot !== next.$slot) return false;
689
+ if (prev.$component !== next.$component) return false;
690
+ const { $slot: _ps, $component: _pc, ...prevRest } = prev;
691
+ const { $slot: _ns, $component: _nc, ...nextRest } = next;
692
+ return shallowEqual(prevRest, nextRest);
693
+ });
694
+ /**
695
+ * Renders a slot value as a memoized React element.
696
+ * Automatically prevents unnecessary re-renders using shallow prop comparison.
697
+ * Supports ref forwarding.
698
+ *
699
+ * @example
700
+ * renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
701
+ */
702
+ function renderSlot(slot, DefaultComponent, props) {
703
+ return React.createElement(MemoizedSlotWrapper, {
704
+ ...props,
705
+ $slot: slot,
706
+ $component: DefaultComponent
707
+ });
708
+ }
709
+
705
710
  //#endregion
706
711
  //#region src/v2/components/chat/CopilotChatInput.tsx
707
712
  const SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
@@ -1055,7 +1060,6 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
1055
1060
  }
1056
1061
  if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
1057
1062
  if (window.matchMedia("(max-width: 767px)").matches) {
1058
- ensureMeasurements();
1059
1063
  adjustTextareaHeight();
1060
1064
  updateLayout("expanded");
1061
1065
  return;
@@ -4409,17 +4413,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4409
4413
  const status = copilotkit.runtimeConnectionStatus;
4410
4414
  if (isRuntimeConfigured && (status === CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
4411
4415
  const cached = provisionalAgentCache.current.get(resolvedAgentId);
4412
- if (cached) {
4413
- copilotkit.applyHeadersToAgent(cached);
4414
- return {
4415
- agent: cached,
4416
- isReady: false
4417
- };
4418
- }
4416
+ if (cached) return {
4417
+ agent: cached,
4418
+ isReady: false
4419
+ };
4419
4420
  const provisional = new ProxiedCopilotRuntimeAgent({
4420
4421
  runtimeUrl: copilotkit.runtimeUrl,
4421
4422
  agentId: resolvedAgentId,
4422
4423
  transport: copilotkit.runtimeTransport,
4424
+ credentials: copilotkit.credentials,
4423
4425
  runtimeMode: "pending"
4424
4426
  });
4425
4427
  copilotkit.applyHeadersToAgent(provisional);
@@ -4431,17 +4433,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4431
4433
  }
4432
4434
  if (isRuntimeConfigured && status === CopilotKitCoreRuntimeConnectionStatus.Error) {
4433
4435
  const cached = provisionalAgentCache.current.get(resolvedAgentId);
4434
- if (cached) {
4435
- copilotkit.applyHeadersToAgent(cached);
4436
- return {
4437
- agent: cached,
4438
- isReady: false
4439
- };
4440
- }
4436
+ if (cached) return {
4437
+ agent: cached,
4438
+ isReady: false
4439
+ };
4441
4440
  const provisional = new ProxiedCopilotRuntimeAgent({
4442
4441
  runtimeUrl: copilotkit.runtimeUrl,
4443
4442
  agentId: resolvedAgentId,
4444
4443
  transport: copilotkit.runtimeTransport,
4444
+ credentials: copilotkit.credentials,
4445
4445
  runtimeMode: "pending"
4446
4446
  });
4447
4447
  copilotkit.applyHeadersToAgent(provisional);
@@ -4460,6 +4460,7 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4460
4460
  copilotkit.runtimeConnectionStatus,
4461
4461
  copilotkit.runtimeUrl,
4462
4462
  copilotkit.runtimeTransport,
4463
+ copilotkit.credentials,
4463
4464
  JSON.stringify(copilotkit.headers)
4464
4465
  ]);
4465
4466
  useEffect(() => {
@@ -4499,7 +4500,12 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4499
4500
  ]);
4500
4501
  useEffect(() => {
4501
4502
  if (agent instanceof HttpAgent) copilotkit.applyHeadersToAgent(agent);
4502
- }, [agent, JSON.stringify(copilotkit.headers)]);
4503
+ if (agent instanceof ProxiedCopilotRuntimeAgent) agent.credentials = copilotkit.credentials;
4504
+ }, [
4505
+ agent,
4506
+ JSON.stringify(copilotkit.headers),
4507
+ copilotkit.credentials
4508
+ ]);
4503
4509
  const configThreadId = chatConfig?.threadId;
4504
4510
  const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
4505
4511
  useEffect(() => {
@@ -9062,27 +9068,35 @@ CopilotSidebar.displayName = "CopilotSidebar";
9062
9068
 
9063
9069
  //#endregion
9064
9070
  //#region src/v2/components/chat/CopilotPopup.tsx
9071
+ const PopupShellPropsContext = React.createContext({});
9072
+ const PopupViewOverride = (viewProps) => {
9073
+ const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, height: viewHeight, clickOutsideToClose: viewClickOutsideToClose, defaultOpen: viewDefaultOpen, ...restProps } = viewProps;
9074
+ const shell = useContext(PopupShellPropsContext);
9075
+ return /* @__PURE__ */ jsx(CopilotPopupView_default, {
9076
+ ...restProps,
9077
+ header: shell.header ?? viewHeader,
9078
+ toggleButton: shell.toggleButton ?? viewToggleButton,
9079
+ width: shell.width ?? viewWidth,
9080
+ height: shell.height ?? viewHeight,
9081
+ clickOutsideToClose: shell.clickOutsideToClose ?? viewClickOutsideToClose,
9082
+ defaultOpen: shell.defaultOpen ?? viewDefaultOpen
9083
+ });
9084
+ };
9085
+ const PopupViewOverrideWithStatics = Object.assign(PopupViewOverride, CopilotChatView_default);
9065
9086
  function CopilotPopup({ header, toggleButton, defaultOpen, width, height, clickOutsideToClose, ...chatProps }) {
9066
9087
  const { checkFeature } = useLicenseContext();
9067
9088
  const isPopupLicensed = checkFeature("popup");
9068
9089
  useEffect(() => {
9069
9090
  if (!isPopupLicensed) console.warn("[CopilotKit] Warning: \"popup\" feature is not licensed. Visit copilotkit.ai/pricing");
9070
9091
  }, [isPopupLicensed]);
9071
- const PopupViewOverride = useMemo(() => {
9072
- const Component = (viewProps) => {
9073
- const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, height: viewHeight, clickOutsideToClose: viewClickOutsideToClose, defaultOpen: viewDefaultOpen, ...restProps } = viewProps;
9074
- return /* @__PURE__ */ jsx(CopilotPopupView_default, {
9075
- ...restProps,
9076
- header: header ?? viewHeader,
9077
- toggleButton: toggleButton ?? viewToggleButton,
9078
- width: width ?? viewWidth,
9079
- height: height ?? viewHeight,
9080
- clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose,
9081
- defaultOpen: defaultOpen ?? viewDefaultOpen
9082
- });
9083
- };
9084
- return Object.assign(Component, CopilotChatView_default);
9085
- }, [
9092
+ const shellProps = useMemo(() => ({
9093
+ header,
9094
+ toggleButton,
9095
+ width,
9096
+ height,
9097
+ clickOutsideToClose,
9098
+ defaultOpen
9099
+ }), [
9086
9100
  clickOutsideToClose,
9087
9101
  header,
9088
9102
  toggleButton,
@@ -9090,11 +9104,14 @@ function CopilotPopup({ header, toggleButton, defaultOpen, width, height, clickO
9090
9104
  width,
9091
9105
  defaultOpen
9092
9106
  ]);
9093
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [!isPopupLicensed && /* @__PURE__ */ jsx(InlineFeatureWarning, { featureName: "Popup" }), /* @__PURE__ */ jsx(CopilotChat, {
9094
- welcomeScreen: CopilotPopupView_default.WelcomeScreen,
9095
- ...chatProps,
9096
- isModalDefaultOpen: defaultOpen,
9097
- chatView: PopupViewOverride
9107
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [!isPopupLicensed && /* @__PURE__ */ jsx(InlineFeatureWarning, { featureName: "Popup" }), /* @__PURE__ */ jsx(PopupShellPropsContext.Provider, {
9108
+ value: shellProps,
9109
+ children: /* @__PURE__ */ jsx(CopilotChat, {
9110
+ welcomeScreen: CopilotPopupView_default.WelcomeScreen,
9111
+ ...chatProps,
9112
+ isModalDefaultOpen: defaultOpen,
9113
+ chatView: PopupViewOverrideWithStatics
9114
+ })
9098
9115
  })] });
9099
9116
  }
9100
9117
  CopilotPopup.displayName = "CopilotPopup";
@@ -11627,4 +11644,4 @@ function validateProps(props) {
11627
11644
 
11628
11645
  //#endregion
11629
11646
  export { useCapabilities as $, CopilotChatMessageView as A, CopilotChatConfigurationProvider as At, CopilotChatAssistantMessage_default as B, CopilotModalHeader as C, CopilotKitInspector as Ct, CopilotChat as D, CopilotChatInput_default as Dt, DefaultOpenIcon as E, CopilotKitCoreReact as Et, CopilotChatSuggestionView as F, useLearnFromUserActionInCurrentThread as G, useLearningContainersInCurrentThread as H, CopilotChatSuggestionPill as I, useThreads$1 as J, useLearnFromUserAction as K, CopilotChatReasoningMessage_default as L, IntelligenceIndicator as M, getIntelligenceTurnAnchors as N, CopilotChatView_default as O, AudioRecorderError as Ot, IntelligenceIndicatorView as P, useAgentContext as Q, CopilotChatUserMessage_default as R, CopilotSidebarView as S, ɵrunMcpFollowUp as St, DefaultCloseIcon as T, useCopilotKit as Tt, useLearningContainers as U, CopilotChatToolCallsView as V, useAttachments as W, useConfigureSuggestions as X, useInterrupt as Y, useSuggestions as Z, WildcardToolCallRender as _, SandboxFunctionsContext as _t, ThreadsProvider as a, useComponent as at, CopilotSidebar as b, MCPAppsActivityRenderer as bt, CoAgentStateRendersProvider as c, useRenderCustomMessages as ct, shouldShowDevConsole as d, createA2UIMessageRenderer as dt, UseAgentUpdate as et, useToast as f, GenerateSandboxedUiArgsSchema as ft, useCopilotContext as g, OpenGenerativeUIToolRenderer as gt, CopilotContext as h, OpenGenerativeUIContentSchema as ht, ThreadsContext as i, useRenderTool as it, INTELLIGENCE_TURN_HEAD as j, useCopilotChatConfiguration as jt, CopilotChatAttachmentQueue as k, CopilotChatAudioRecorder as kt, useCoAgentStateRenders as l, CopilotKitProvider as lt, useCopilotMessagesContext as m, OpenGenerativeUIActivityType as mt, defaultCopilotContextCategories as n, useHumanInTheLoop as nt, useThreads as o, useFrontendTool as ot, CopilotMessagesContext as p, OpenGenerativeUIActivityRenderer as pt, useMemories as q, CoAgentStateRenderBridge as r, useDefaultRenderTool as rt, CoAgentStateRendersContext as s, useRenderActivityMessage as st, CopilotKit as t, useAgent as tt, useAsyncCallback as u, defineToolCallRenderer as ut, CopilotThreadsDrawer as v, useSandboxFunctions as vt, CopilotChatToggleButton as w, useRenderToolCall as wt, CopilotPopupView as x, MCPAppsActivityType as xt, CopilotPopup as y, MCPAppsActivityContentSchema as yt, CopilotChatAttachmentRenderer as z };
11630
- //# sourceMappingURL=copilotkit-CN2JVeH3.mjs.map
11647
+ //# sourceMappingURL=copilotkit-D_Ao1X-u.mjs.map