@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.
@@ -52,7 +52,7 @@ let _copilotkit_web_components_threads_drawer = require("@copilotkit/web-compone
52
52
  let react_markdown = require("react-markdown");
53
53
  react_markdown = __toESM(react_markdown);
54
54
 
55
- //#region src/v2/lib/slots.tsx
55
+ //#region src/v2/lib/shallow-stable-ref.ts
56
56
  /**
57
57
  * Shallow equality comparison for objects.
58
58
  */
@@ -92,64 +92,6 @@ function useShallowStableRef(value) {
92
92
  ref.current = value;
93
93
  return ref.current;
94
94
  }
95
- /**
96
- * Check if a value is a React component type (function, class, forwardRef, memo, etc.)
97
- */
98
- function isReactComponentType(value) {
99
- if (typeof value === "function") return true;
100
- if (value && typeof value === "object" && "$$typeof" in value && !react.default.isValidElement(value)) return true;
101
- return false;
102
- }
103
- /**
104
- * Internal function to render a slot value as a React element (non-memoized).
105
- */
106
- function renderSlotElement(slot, DefaultComponent, props) {
107
- if (typeof slot === "string") {
108
- const existingClassName = props.className;
109
- return react.default.createElement(DefaultComponent, {
110
- ...props,
111
- className: (0, tailwind_merge.twMerge)(existingClassName, slot)
112
- });
113
- }
114
- if (isReactComponentType(slot)) return react.default.createElement(slot, props);
115
- if (slot && typeof slot === "object" && !react.default.isValidElement(slot)) return react.default.createElement(DefaultComponent, {
116
- ...props,
117
- ...slot
118
- });
119
- return react.default.createElement(DefaultComponent, props);
120
- }
121
- /**
122
- * Internal memoized wrapper component for renderSlot.
123
- * Uses forwardRef to support ref forwarding.
124
- */
125
- const MemoizedSlotWrapper = react.default.memo(react.default.forwardRef(function MemoizedSlotWrapper(props, ref) {
126
- const { $slot, $component, ...rest } = props;
127
- return renderSlotElement($slot, $component, ref !== null ? {
128
- ...rest,
129
- ref
130
- } : rest);
131
- }), (prev, next) => {
132
- if (prev.$slot !== next.$slot) return false;
133
- if (prev.$component !== next.$component) return false;
134
- const { $slot: _ps, $component: _pc, ...prevRest } = prev;
135
- const { $slot: _ns, $component: _nc, ...nextRest } = next;
136
- return shallowEqual(prevRest, nextRest);
137
- });
138
- /**
139
- * Renders a slot value as a memoized React element.
140
- * Automatically prevents unnecessary re-renders using shallow prop comparison.
141
- * Supports ref forwarding.
142
- *
143
- * @example
144
- * renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
145
- */
146
- function renderSlot(slot, DefaultComponent, props) {
147
- return react.default.createElement(MemoizedSlotWrapper, {
148
- ...props,
149
- $slot: slot,
150
- $component: DefaultComponent
151
- });
152
- }
153
95
 
154
96
  //#endregion
155
97
  //#region src/v2/providers/CopilotChatConfigurationProvider.tsx
@@ -357,9 +299,9 @@ const useCopilotChatConfiguration = () => {
357
299
 
358
300
  //#endregion
359
301
  //#region src/v2/lib/utils.ts
360
- const twMerge$8 = (0, tailwind_merge.extendTailwindMerge)({ prefix: "cpk" });
302
+ const twMerge$9 = (0, tailwind_merge.extendTailwindMerge)({ prefix: "cpk" });
361
303
  function cn(...inputs) {
362
- return twMerge$8((0, clsx.clsx)(inputs));
304
+ return twMerge$9((0, clsx.clsx)(inputs));
363
305
  }
364
306
 
365
307
  //#endregion
@@ -453,12 +395,13 @@ function Tooltip({ ...props }) {
453
395
  ...props
454
396
  }) });
455
397
  }
456
- function TooltipTrigger({ ...props }) {
398
+ const TooltipTrigger = react.forwardRef(function TooltipTrigger({ ...props }, ref) {
457
399
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_tooltip.Trigger, {
400
+ ref,
458
401
  "data-slot": "tooltip-trigger",
459
402
  ...props
460
403
  });
461
- }
404
+ });
462
405
  function TooltipContent({ className, sideOffset = 0, children, ...props }) {
463
406
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_tooltip.Portal, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_radix_ui_react_tooltip.Content, {
464
407
  "data-copilotkit": true,
@@ -478,12 +421,13 @@ function DropdownMenu({ ...props }) {
478
421
  ...props
479
422
  });
480
423
  }
481
- function DropdownMenuTrigger({ ...props }) {
424
+ const DropdownMenuTrigger = react.forwardRef(function DropdownMenuTrigger({ ...props }, ref) {
482
425
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Trigger, {
426
+ ref,
483
427
  "data-slot": "dropdown-menu-trigger",
484
428
  ...props
485
429
  });
486
- }
430
+ });
487
431
  function DropdownMenuContent({ className, sideOffset = 4, ...props }) {
488
432
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Portal, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_dropdown_menu.Content, {
489
433
  "data-copilotkit": true,
@@ -732,6 +676,67 @@ const CopilotChatAudioRecorder = (0, react.forwardRef)((props, ref) => {
732
676
  });
733
677
  CopilotChatAudioRecorder.displayName = "CopilotChatAudioRecorder";
734
678
 
679
+ //#endregion
680
+ //#region src/v2/lib/slots.tsx
681
+ /**
682
+ * Check if a value is a React component type (function, class, forwardRef, memo, etc.)
683
+ */
684
+ function isReactComponentType(value) {
685
+ if (typeof value === "function") return true;
686
+ if (value && typeof value === "object" && "$$typeof" in value && !react.default.isValidElement(value)) return true;
687
+ return false;
688
+ }
689
+ /**
690
+ * Internal function to render a slot value as a React element (non-memoized).
691
+ */
692
+ function renderSlotElement(slot, DefaultComponent, props) {
693
+ if (typeof slot === "string") {
694
+ const existingClassName = props.className;
695
+ return react.default.createElement(DefaultComponent, {
696
+ ...props,
697
+ className: (0, tailwind_merge.twMerge)(existingClassName, slot)
698
+ });
699
+ }
700
+ if (isReactComponentType(slot)) return react.default.createElement(slot, props);
701
+ if (slot && typeof slot === "object" && !react.default.isValidElement(slot)) return react.default.createElement(DefaultComponent, {
702
+ ...props,
703
+ ...slot
704
+ });
705
+ return react.default.createElement(DefaultComponent, props);
706
+ }
707
+ /**
708
+ * Internal memoized wrapper component for renderSlot.
709
+ * Uses forwardRef to support ref forwarding.
710
+ */
711
+ const MemoizedSlotWrapper = react.default.memo(react.default.forwardRef(function MemoizedSlotWrapper(props, ref) {
712
+ const { $slot, $component, ...rest } = props;
713
+ return renderSlotElement($slot, $component, ref !== null ? {
714
+ ...rest,
715
+ ref
716
+ } : rest);
717
+ }), (prev, next) => {
718
+ if (prev.$slot !== next.$slot) return false;
719
+ if (prev.$component !== next.$component) return false;
720
+ const { $slot: _ps, $component: _pc, ...prevRest } = prev;
721
+ const { $slot: _ns, $component: _nc, ...nextRest } = next;
722
+ return shallowEqual(prevRest, nextRest);
723
+ });
724
+ /**
725
+ * Renders a slot value as a memoized React element.
726
+ * Automatically prevents unnecessary re-renders using shallow prop comparison.
727
+ * Supports ref forwarding.
728
+ *
729
+ * @example
730
+ * renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
731
+ */
732
+ function renderSlot(slot, DefaultComponent, props) {
733
+ return react.default.createElement(MemoizedSlotWrapper, {
734
+ ...props,
735
+ $slot: slot,
736
+ $component: DefaultComponent
737
+ });
738
+ }
739
+
735
740
  //#endregion
736
741
  //#region src/v2/components/chat/CopilotChatInput.tsx
737
742
  const SLASH_MENU_MAX_VISIBLE_ITEMS = 5;
@@ -1085,7 +1090,6 @@ function CopilotChatInput({ mode = "input", onSubmitMessage, onStop, isRunning =
1085
1090
  }
1086
1091
  if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
1087
1092
  if (window.matchMedia("(max-width: 767px)").matches) {
1088
- ensureMeasurements();
1089
1093
  adjustTextareaHeight();
1090
1094
  updateLayout("expanded");
1091
1095
  return;
@@ -4439,17 +4443,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4439
4443
  const status = copilotkit.runtimeConnectionStatus;
4440
4444
  if (isRuntimeConfigured && (status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Disconnected || status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Connecting)) {
4441
4445
  const cached = provisionalAgentCache.current.get(resolvedAgentId);
4442
- if (cached) {
4443
- copilotkit.applyHeadersToAgent(cached);
4444
- return {
4445
- agent: cached,
4446
- isReady: false
4447
- };
4448
- }
4446
+ if (cached) return {
4447
+ agent: cached,
4448
+ isReady: false
4449
+ };
4449
4450
  const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4450
4451
  runtimeUrl: copilotkit.runtimeUrl,
4451
4452
  agentId: resolvedAgentId,
4452
4453
  transport: copilotkit.runtimeTransport,
4454
+ credentials: copilotkit.credentials,
4453
4455
  runtimeMode: "pending"
4454
4456
  });
4455
4457
  copilotkit.applyHeadersToAgent(provisional);
@@ -4461,17 +4463,15 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4461
4463
  }
4462
4464
  if (isRuntimeConfigured && status === _copilotkit_core.CopilotKitCoreRuntimeConnectionStatus.Error) {
4463
4465
  const cached = provisionalAgentCache.current.get(resolvedAgentId);
4464
- if (cached) {
4465
- copilotkit.applyHeadersToAgent(cached);
4466
- return {
4467
- agent: cached,
4468
- isReady: false
4469
- };
4470
- }
4466
+ if (cached) return {
4467
+ agent: cached,
4468
+ isReady: false
4469
+ };
4471
4470
  const provisional = new _copilotkit_core.ProxiedCopilotRuntimeAgent({
4472
4471
  runtimeUrl: copilotkit.runtimeUrl,
4473
4472
  agentId: resolvedAgentId,
4474
4473
  transport: copilotkit.runtimeTransport,
4474
+ credentials: copilotkit.credentials,
4475
4475
  runtimeMode: "pending"
4476
4476
  });
4477
4477
  copilotkit.applyHeadersToAgent(provisional);
@@ -4490,6 +4490,7 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4490
4490
  copilotkit.runtimeConnectionStatus,
4491
4491
  copilotkit.runtimeUrl,
4492
4492
  copilotkit.runtimeTransport,
4493
+ copilotkit.credentials,
4493
4494
  JSON.stringify(copilotkit.headers)
4494
4495
  ]);
4495
4496
  (0, react.useEffect)(() => {
@@ -4529,7 +4530,12 @@ function useAgent({ agentId, updates, throttleMs } = {}) {
4529
4530
  ]);
4530
4531
  (0, react.useEffect)(() => {
4531
4532
  if (agent instanceof _ag_ui_client.HttpAgent) copilotkit.applyHeadersToAgent(agent);
4532
- }, [agent, JSON.stringify(copilotkit.headers)]);
4533
+ if (agent instanceof _copilotkit_core.ProxiedCopilotRuntimeAgent) agent.credentials = copilotkit.credentials;
4534
+ }, [
4535
+ agent,
4536
+ JSON.stringify(copilotkit.headers),
4537
+ copilotkit.credentials
4538
+ ]);
4533
4539
  const configThreadId = chatConfig?.threadId;
4534
4540
  const configHasExplicitThreadId = chatConfig?.hasExplicitThreadId;
4535
4541
  (0, react.useEffect)(() => {
@@ -9092,27 +9098,35 @@ CopilotSidebar.displayName = "CopilotSidebar";
9092
9098
 
9093
9099
  //#endregion
9094
9100
  //#region src/v2/components/chat/CopilotPopup.tsx
9101
+ const PopupShellPropsContext = react.default.createContext({});
9102
+ const PopupViewOverride = (viewProps) => {
9103
+ const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, height: viewHeight, clickOutsideToClose: viewClickOutsideToClose, defaultOpen: viewDefaultOpen, ...restProps } = viewProps;
9104
+ const shell = (0, react.useContext)(PopupShellPropsContext);
9105
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotPopupView_default, {
9106
+ ...restProps,
9107
+ header: shell.header ?? viewHeader,
9108
+ toggleButton: shell.toggleButton ?? viewToggleButton,
9109
+ width: shell.width ?? viewWidth,
9110
+ height: shell.height ?? viewHeight,
9111
+ clickOutsideToClose: shell.clickOutsideToClose ?? viewClickOutsideToClose,
9112
+ defaultOpen: shell.defaultOpen ?? viewDefaultOpen
9113
+ });
9114
+ };
9115
+ const PopupViewOverrideWithStatics = Object.assign(PopupViewOverride, CopilotChatView_default);
9095
9116
  function CopilotPopup({ header, toggleButton, defaultOpen, width, height, clickOutsideToClose, ...chatProps }) {
9096
9117
  const { checkFeature } = useLicenseContext();
9097
9118
  const isPopupLicensed = checkFeature("popup");
9098
9119
  (0, react.useEffect)(() => {
9099
9120
  if (!isPopupLicensed) console.warn("[CopilotKit] Warning: \"popup\" feature is not licensed. Visit copilotkit.ai/pricing");
9100
9121
  }, [isPopupLicensed]);
9101
- const PopupViewOverride = (0, react.useMemo)(() => {
9102
- const Component = (viewProps) => {
9103
- const { header: viewHeader, toggleButton: viewToggleButton, width: viewWidth, height: viewHeight, clickOutsideToClose: viewClickOutsideToClose, defaultOpen: viewDefaultOpen, ...restProps } = viewProps;
9104
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotPopupView_default, {
9105
- ...restProps,
9106
- header: header ?? viewHeader,
9107
- toggleButton: toggleButton ?? viewToggleButton,
9108
- width: width ?? viewWidth,
9109
- height: height ?? viewHeight,
9110
- clickOutsideToClose: clickOutsideToClose ?? viewClickOutsideToClose,
9111
- defaultOpen: defaultOpen ?? viewDefaultOpen
9112
- });
9113
- };
9114
- return Object.assign(Component, CopilotChatView_default);
9115
- }, [
9122
+ const shellProps = (0, react.useMemo)(() => ({
9123
+ header,
9124
+ toggleButton,
9125
+ width,
9126
+ height,
9127
+ clickOutsideToClose,
9128
+ defaultOpen
9129
+ }), [
9116
9130
  clickOutsideToClose,
9117
9131
  header,
9118
9132
  toggleButton,
@@ -9120,11 +9134,14 @@ function CopilotPopup({ header, toggleButton, defaultOpen, width, height, clickO
9120
9134
  width,
9121
9135
  defaultOpen
9122
9136
  ]);
9123
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [!isPopupLicensed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InlineFeatureWarning, { featureName: "Popup" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChat, {
9124
- welcomeScreen: CopilotPopupView_default.WelcomeScreen,
9125
- ...chatProps,
9126
- isModalDefaultOpen: defaultOpen,
9127
- chatView: PopupViewOverride
9137
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [!isPopupLicensed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InlineFeatureWarning, { featureName: "Popup" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PopupShellPropsContext.Provider, {
9138
+ value: shellProps,
9139
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChat, {
9140
+ welcomeScreen: CopilotPopupView_default.WelcomeScreen,
9141
+ ...chatProps,
9142
+ isModalDefaultOpen: defaultOpen,
9143
+ chatView: PopupViewOverrideWithStatics
9144
+ })
9128
9145
  })] });
9129
9146
  }
9130
9147
  CopilotPopup.displayName = "CopilotPopup";
@@ -12172,4 +12189,4 @@ Object.defineProperty(exports, 'ɵrunMcpFollowUp', {
12172
12189
  return ɵrunMcpFollowUp;
12173
12190
  }
12174
12191
  });
12175
- //# sourceMappingURL=copilotkit-DDVfoiRM.cjs.map
12192
+ //# sourceMappingURL=copilotkit-DiLTL1ZM.cjs.map