@copilotkitnext/react 0.0.22 → 0.0.23

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.js CHANGED
@@ -544,7 +544,16 @@ CopilotChatAudioRecorder.displayName = "WebAudioRecorder";
544
544
 
545
545
  // src/lib/slots.tsx
546
546
  var import_react3 = __toESM(require("react"));
547
- function renderSlot(slot, DefaultComponent, props) {
547
+ function shallowEqual(obj1, obj2) {
548
+ const keys1 = Object.keys(obj1);
549
+ const keys2 = Object.keys(obj2);
550
+ if (keys1.length !== keys2.length) return false;
551
+ for (const key of keys1) {
552
+ if (obj1[key] !== obj2[key]) return false;
553
+ }
554
+ return true;
555
+ }
556
+ function renderSlotElement(slot, DefaultComponent, props) {
548
557
  if (typeof slot === "string") {
549
558
  return import_react3.default.createElement(DefaultComponent, {
550
559
  ...props,
@@ -552,8 +561,7 @@ function renderSlot(slot, DefaultComponent, props) {
552
561
  });
553
562
  }
554
563
  if (typeof slot === "function") {
555
- const Comp = slot;
556
- return import_react3.default.createElement(Comp, props);
564
+ return import_react3.default.createElement(slot, props);
557
565
  }
558
566
  if (slot && typeof slot === "object" && !import_react3.default.isValidElement(slot)) {
559
567
  return import_react3.default.createElement(DefaultComponent, {
@@ -563,6 +571,30 @@ function renderSlot(slot, DefaultComponent, props) {
563
571
  }
564
572
  return import_react3.default.createElement(DefaultComponent, props);
565
573
  }
574
+ var MemoizedSlotWrapper = import_react3.default.memo(
575
+ import_react3.default.forwardRef(function MemoizedSlotWrapper2(props, ref) {
576
+ const { $slot, $component, ...rest } = props;
577
+ const propsWithRef = ref !== null ? { ...rest, ref } : rest;
578
+ return renderSlotElement($slot, $component, propsWithRef);
579
+ }),
580
+ (prev, next) => {
581
+ if (prev.$slot !== next.$slot) return false;
582
+ if (prev.$component !== next.$component) return false;
583
+ const { $slot: _ps, $component: _pc, ...prevRest } = prev;
584
+ const { $slot: _ns, $component: _nc, ...nextRest } = next;
585
+ return shallowEqual(
586
+ prevRest,
587
+ nextRest
588
+ );
589
+ }
590
+ );
591
+ function renderSlot(slot, DefaultComponent, props) {
592
+ return import_react3.default.createElement(MemoizedSlotWrapper, {
593
+ ...props,
594
+ $slot: slot,
595
+ $component: DefaultComponent
596
+ });
597
+ }
566
598
 
567
599
  // src/components/chat/CopilotChatInput.tsx
568
600
  var import_jsx_runtime6 = require("react/jsx-runtime");
@@ -1399,7 +1431,7 @@ var import_katex_min = require("katex/dist/katex.min.css");
1399
1431
  var import_streamdown = require("streamdown");
1400
1432
 
1401
1433
  // src/hooks/use-render-tool-call.tsx
1402
- var import_react7 = require("react");
1434
+ var import_react7 = __toESM(require("react"));
1403
1435
  var import_core2 = require("@copilotkitnext/core");
1404
1436
 
1405
1437
  // src/providers/CopilotKitProvider.tsx
@@ -1676,6 +1708,63 @@ var useCopilotKit = () => {
1676
1708
  var import_shared2 = require("@copilotkitnext/shared");
1677
1709
  var import_shared3 = require("@copilotkitnext/shared");
1678
1710
  var import_jsx_runtime9 = require("react/jsx-runtime");
1711
+ var ToolCallRenderer = import_react7.default.memo(
1712
+ function ToolCallRenderer2({
1713
+ toolCall,
1714
+ toolMessage,
1715
+ RenderComponent,
1716
+ isExecuting
1717
+ }) {
1718
+ const args = (0, import_react7.useMemo)(
1719
+ () => (0, import_shared3.partialJSONParse)(toolCall.function.arguments),
1720
+ [toolCall.function.arguments]
1721
+ );
1722
+ const toolName = toolCall.function.name;
1723
+ if (toolMessage) {
1724
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1725
+ RenderComponent,
1726
+ {
1727
+ name: toolName,
1728
+ args,
1729
+ status: import_core2.ToolCallStatus.Complete,
1730
+ result: toolMessage.content
1731
+ }
1732
+ );
1733
+ } else if (isExecuting) {
1734
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1735
+ RenderComponent,
1736
+ {
1737
+ name: toolName,
1738
+ args,
1739
+ status: import_core2.ToolCallStatus.Executing,
1740
+ result: void 0
1741
+ }
1742
+ );
1743
+ } else {
1744
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1745
+ RenderComponent,
1746
+ {
1747
+ name: toolName,
1748
+ args,
1749
+ status: import_core2.ToolCallStatus.InProgress,
1750
+ result: void 0
1751
+ }
1752
+ );
1753
+ }
1754
+ },
1755
+ // Custom comparison function to prevent re-renders when tool call data hasn't changed
1756
+ (prevProps, nextProps) => {
1757
+ if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
1758
+ if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
1759
+ if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
1760
+ const prevResult = prevProps.toolMessage?.content;
1761
+ const nextResult = nextProps.toolMessage?.content;
1762
+ if (prevResult !== nextResult) return false;
1763
+ if (prevProps.isExecuting !== nextProps.isExecuting) return false;
1764
+ if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
1765
+ return true;
1766
+ }
1767
+ );
1679
1768
  function useRenderToolCall() {
1680
1769
  const { copilotkit } = useCopilotKit();
1681
1770
  const config = useCopilotChatConfiguration();
@@ -1724,42 +1813,17 @@ function useRenderToolCall() {
1724
1813
  return null;
1725
1814
  }
1726
1815
  const RenderComponent = renderConfig.render;
1727
- const args = (0, import_shared3.partialJSONParse)(toolCall.function.arguments);
1728
- const toolName = toolCall.function.name;
1729
- if (toolMessage) {
1730
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1731
- RenderComponent,
1732
- {
1733
- name: toolName,
1734
- args,
1735
- status: import_core2.ToolCallStatus.Complete,
1736
- result: toolMessage.content
1737
- },
1738
- toolCall.id
1739
- );
1740
- } else if (executingToolCallIds.has(toolCall.id)) {
1741
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1742
- RenderComponent,
1743
- {
1744
- name: toolName,
1745
- args,
1746
- status: import_core2.ToolCallStatus.Executing,
1747
- result: void 0
1748
- },
1749
- toolCall.id
1750
- );
1751
- } else {
1752
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1816
+ const isExecuting = executingToolCallIds.has(toolCall.id);
1817
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1818
+ ToolCallRenderer,
1819
+ {
1820
+ toolCall,
1821
+ toolMessage,
1753
1822
  RenderComponent,
1754
- {
1755
- name: toolName,
1756
- args,
1757
- status: import_core2.ToolCallStatus.InProgress,
1758
- result: void 0
1759
- },
1760
- toolCall.id
1761
- );
1762
- }
1823
+ isExecuting
1824
+ },
1825
+ toolCall.id
1826
+ );
1763
1827
  },
1764
1828
  [renderToolCalls, executingToolCallIds, agentId]
1765
1829
  );
@@ -1872,8 +1936,10 @@ function useRenderActivityMessage() {
1872
1936
 
1873
1937
  // src/hooks/use-frontend-tool.tsx
1874
1938
  var import_react9 = require("react");
1875
- function useFrontendTool(tool) {
1939
+ var EMPTY_DEPS = [];
1940
+ function useFrontendTool(tool, deps) {
1876
1941
  const { copilotkit } = useCopilotKit();
1942
+ const extraDeps = deps ?? EMPTY_DEPS;
1877
1943
  (0, import_react9.useEffect)(() => {
1878
1944
  const name = tool.name;
1879
1945
  if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
@@ -1902,13 +1968,13 @@ function useFrontendTool(tool) {
1902
1968
  return () => {
1903
1969
  copilotkit.removeTool(name, tool.agentId);
1904
1970
  };
1905
- }, [tool.name, copilotkit]);
1971
+ }, [tool.name, copilotkit, extraDeps.length, ...extraDeps]);
1906
1972
  }
1907
1973
 
1908
1974
  // src/hooks/use-human-in-the-loop.tsx
1909
1975
  var import_react10 = require("react");
1910
1976
  var import_react11 = __toESM(require("react"));
1911
- function useHumanInTheLoop(tool) {
1977
+ function useHumanInTheLoop(tool, deps) {
1912
1978
  const { copilotkit } = useCopilotKit();
1913
1979
  const resolvePromiseRef = (0, import_react10.useRef)(null);
1914
1980
  const respond = (0, import_react10.useCallback)(async (result) => {
@@ -1959,7 +2025,7 @@ function useHumanInTheLoop(tool) {
1959
2025
  handler,
1960
2026
  render: RenderComponent
1961
2027
  };
1962
- useFrontendTool(frontendTool);
2028
+ useFrontendTool(frontendTool, deps);
1963
2029
  (0, import_react10.useEffect)(() => {
1964
2030
  return () => {
1965
2031
  const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
@@ -2134,11 +2200,10 @@ function useSuggestions({ agentId } = {}) {
2134
2200
  // src/hooks/use-configure-suggestions.tsx
2135
2201
  var import_react15 = require("react");
2136
2202
  var import_shared7 = require("@copilotkitnext/shared");
2137
- var EMPTY_DEPS = [];
2138
- function useConfigureSuggestions(config, options) {
2203
+ function useConfigureSuggestions(config, deps) {
2139
2204
  const { copilotkit } = useCopilotKit();
2140
2205
  const chatConfig = useCopilotChatConfiguration();
2141
- const extraDeps = options?.deps ?? EMPTY_DEPS;
2206
+ const extraDeps = deps ?? [];
2142
2207
  const resolvedConsumerAgentId = (0, import_react15.useMemo)(() => chatConfig?.agentId ?? import_shared7.DEFAULT_AGENT_ID, [chatConfig?.agentId]);
2143
2208
  const rawConsumerAgentId = (0, import_react15.useMemo)(() => config ? config.consumerAgentId : void 0, [config]);
2144
2209
  const normalizationCacheRef = (0, import_react15.useRef)({
@@ -2888,8 +2953,103 @@ CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
2888
2953
  var CopilotChatSuggestionView_default = CopilotChatSuggestionView;
2889
2954
 
2890
2955
  // src/components/chat/CopilotChatMessageView.tsx
2956
+ var import_react21 = __toESM(require("react"));
2891
2957
  var import_tailwind_merge6 = require("tailwind-merge");
2892
2958
  var import_jsx_runtime17 = require("react/jsx-runtime");
2959
+ var MemoizedAssistantMessage = import_react21.default.memo(
2960
+ function MemoizedAssistantMessage2({
2961
+ message,
2962
+ messages,
2963
+ isRunning,
2964
+ AssistantMessageComponent
2965
+ }) {
2966
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2967
+ AssistantMessageComponent,
2968
+ {
2969
+ message,
2970
+ messages,
2971
+ isRunning
2972
+ }
2973
+ );
2974
+ },
2975
+ (prevProps, nextProps) => {
2976
+ if (prevProps.message.id !== nextProps.message.id) return false;
2977
+ if (prevProps.message.content !== nextProps.message.content) return false;
2978
+ const prevToolCalls = prevProps.message.toolCalls;
2979
+ const nextToolCalls = nextProps.message.toolCalls;
2980
+ if (prevToolCalls?.length !== nextToolCalls?.length) return false;
2981
+ if (prevToolCalls && nextToolCalls) {
2982
+ for (let i = 0; i < prevToolCalls.length; i++) {
2983
+ const prevTc = prevToolCalls[i];
2984
+ const nextTc = nextToolCalls[i];
2985
+ if (!prevTc || !nextTc) return false;
2986
+ if (prevTc.id !== nextTc.id) return false;
2987
+ if (prevTc.function.arguments !== nextTc.function.arguments) return false;
2988
+ }
2989
+ }
2990
+ if (prevToolCalls && prevToolCalls.length > 0) {
2991
+ const toolCallIds = new Set(prevToolCalls.map((tc) => tc.id));
2992
+ const prevToolResults = prevProps.messages.filter(
2993
+ (m) => m.role === "tool" && toolCallIds.has(m.toolCallId)
2994
+ );
2995
+ const nextToolResults = nextProps.messages.filter(
2996
+ (m) => m.role === "tool" && toolCallIds.has(m.toolCallId)
2997
+ );
2998
+ if (prevToolResults.length !== nextToolResults.length) return false;
2999
+ for (let i = 0; i < prevToolResults.length; i++) {
3000
+ if (prevToolResults[i].content !== nextToolResults[i].content) return false;
3001
+ }
3002
+ }
3003
+ const nextIsLatest = nextProps.messages[nextProps.messages.length - 1]?.id === nextProps.message.id;
3004
+ if (nextIsLatest && prevProps.isRunning !== nextProps.isRunning) return false;
3005
+ if (prevProps.AssistantMessageComponent !== nextProps.AssistantMessageComponent) return false;
3006
+ return true;
3007
+ }
3008
+ );
3009
+ var MemoizedUserMessage = import_react21.default.memo(
3010
+ function MemoizedUserMessage2({
3011
+ message,
3012
+ UserMessageComponent
3013
+ }) {
3014
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(UserMessageComponent, { message });
3015
+ },
3016
+ (prevProps, nextProps) => {
3017
+ if (prevProps.message.id !== nextProps.message.id) return false;
3018
+ if (prevProps.message.content !== nextProps.message.content) return false;
3019
+ if (prevProps.UserMessageComponent !== nextProps.UserMessageComponent) return false;
3020
+ return true;
3021
+ }
3022
+ );
3023
+ var MemoizedActivityMessage = import_react21.default.memo(
3024
+ function MemoizedActivityMessage2({
3025
+ message,
3026
+ renderActivityMessage
3027
+ }) {
3028
+ return renderActivityMessage(message);
3029
+ },
3030
+ (prevProps, nextProps) => {
3031
+ if (prevProps.message.id !== nextProps.message.id) return false;
3032
+ if (prevProps.message.activityType !== nextProps.message.activityType) return false;
3033
+ if (JSON.stringify(prevProps.message.content) !== JSON.stringify(nextProps.message.content)) return false;
3034
+ return true;
3035
+ }
3036
+ );
3037
+ var MemoizedCustomMessage = import_react21.default.memo(
3038
+ function MemoizedCustomMessage2({
3039
+ message,
3040
+ position,
3041
+ renderCustomMessage
3042
+ }) {
3043
+ return renderCustomMessage({ message, position });
3044
+ },
3045
+ (prevProps, nextProps) => {
3046
+ if (prevProps.message.id !== nextProps.message.id) return false;
3047
+ if (prevProps.position !== nextProps.position) return false;
3048
+ if (prevProps.message.content !== nextProps.message.content) return false;
3049
+ if (prevProps.message.role !== nextProps.message.role) return false;
3050
+ return true;
3051
+ }
3052
+ );
2893
3053
  function CopilotChatMessageView({
2894
3054
  messages = [],
2895
3055
  assistantMessage,
@@ -2906,40 +3066,66 @@ function CopilotChatMessageView({
2906
3066
  const elements = [];
2907
3067
  if (renderCustomMessage) {
2908
3068
  elements.push(
2909
- renderCustomMessage({
2910
- message,
2911
- position: "before"
2912
- })
3069
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3070
+ MemoizedCustomMessage,
3071
+ {
3072
+ message,
3073
+ position: "before",
3074
+ renderCustomMessage
3075
+ },
3076
+ `${message.id}-custom-before`
3077
+ )
2913
3078
  );
2914
3079
  }
2915
3080
  if (message.role === "assistant") {
3081
+ const AssistantComponent = typeof assistantMessage === "function" ? assistantMessage : CopilotChatAssistantMessage_default;
2916
3082
  elements.push(
2917
- renderSlot(assistantMessage, CopilotChatAssistantMessage_default, {
2918
- key: message.id,
2919
- message,
2920
- messages,
2921
- isRunning
2922
- })
3083
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3084
+ MemoizedAssistantMessage,
3085
+ {
3086
+ message,
3087
+ messages,
3088
+ isRunning,
3089
+ AssistantMessageComponent: AssistantComponent
3090
+ },
3091
+ message.id
3092
+ )
2923
3093
  );
2924
3094
  } else if (message.role === "user") {
3095
+ const UserComponent = typeof userMessage === "function" ? userMessage : CopilotChatUserMessage_default;
2925
3096
  elements.push(
2926
- renderSlot(userMessage, CopilotChatUserMessage_default, {
2927
- key: message.id,
2928
- message
2929
- })
3097
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3098
+ MemoizedUserMessage,
3099
+ {
3100
+ message,
3101
+ UserMessageComponent: UserComponent
3102
+ },
3103
+ message.id
3104
+ )
2930
3105
  );
2931
3106
  } else if (message.role === "activity") {
2932
- const renderedActivity = renderActivityMessage(message);
2933
- if (renderedActivity) {
2934
- elements.push(renderedActivity);
2935
- }
3107
+ elements.push(
3108
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3109
+ MemoizedActivityMessage,
3110
+ {
3111
+ message,
3112
+ renderActivityMessage
3113
+ },
3114
+ message.id
3115
+ )
3116
+ );
2936
3117
  }
2937
3118
  if (renderCustomMessage) {
2938
3119
  elements.push(
2939
- renderCustomMessage({
2940
- message,
2941
- position: "after"
2942
- })
3120
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3121
+ MemoizedCustomMessage,
3122
+ {
3123
+ message,
3124
+ position: "after",
3125
+ renderCustomMessage
3126
+ },
3127
+ `${message.id}-custom-after`
3128
+ )
2943
3129
  );
2944
3130
  }
2945
3131
  return elements;
@@ -2964,21 +3150,21 @@ CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
2964
3150
  var CopilotChatMessageView_default = CopilotChatMessageView;
2965
3151
 
2966
3152
  // src/components/chat/CopilotChatView.tsx
2967
- var import_react22 = __toESM(require("react"));
3153
+ var import_react23 = __toESM(require("react"));
2968
3154
  var import_tailwind_merge7 = require("tailwind-merge");
2969
3155
  var import_use_stick_to_bottom = require("use-stick-to-bottom");
2970
3156
  var import_lucide_react6 = require("lucide-react");
2971
3157
 
2972
3158
  // src/hooks/use-keyboard-height.tsx
2973
- var import_react21 = require("react");
3159
+ var import_react22 = require("react");
2974
3160
  function useKeyboardHeight() {
2975
- const [keyboardState, setKeyboardState] = (0, import_react21.useState)({
3161
+ const [keyboardState, setKeyboardState] = (0, import_react22.useState)({
2976
3162
  isKeyboardOpen: false,
2977
3163
  keyboardHeight: 0,
2978
3164
  availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
2979
3165
  viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
2980
3166
  });
2981
- (0, import_react21.useEffect)(() => {
3167
+ (0, import_react22.useEffect)(() => {
2982
3168
  if (typeof window === "undefined") {
2983
3169
  return;
2984
3170
  }
@@ -3031,12 +3217,12 @@ function CopilotChatView({
3031
3217
  className,
3032
3218
  ...props
3033
3219
  }) {
3034
- const inputContainerRef = (0, import_react22.useRef)(null);
3035
- const [inputContainerHeight, setInputContainerHeight] = (0, import_react22.useState)(0);
3036
- const [isResizing, setIsResizing] = (0, import_react22.useState)(false);
3037
- const resizeTimeoutRef = (0, import_react22.useRef)(null);
3220
+ const inputContainerRef = (0, import_react23.useRef)(null);
3221
+ const [inputContainerHeight, setInputContainerHeight] = (0, import_react23.useState)(0);
3222
+ const [isResizing, setIsResizing] = (0, import_react23.useState)(false);
3223
+ const resizeTimeoutRef = (0, import_react23.useRef)(null);
3038
3224
  const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
3039
- (0, import_react22.useEffect)(() => {
3225
+ (0, import_react23.useEffect)(() => {
3040
3226
  const element = inputContainerRef.current;
3041
3227
  if (!element) return;
3042
3228
  const resizeObserver = new ResizeObserver((entries) => {
@@ -3072,16 +3258,12 @@ function CopilotChatView({
3072
3258
  });
3073
3259
  const BoundInput = renderSlot(input, CopilotChatInput_default, inputProps ?? {});
3074
3260
  const hasSuggestions = Array.isArray(suggestions) && suggestions.length > 0;
3075
- const BoundSuggestionView = hasSuggestions ? renderSlot(
3076
- suggestionView,
3077
- CopilotChatSuggestionView_default,
3078
- {
3079
- suggestions,
3080
- loadingIndexes: suggestionLoadingIndexes,
3081
- onSelectSuggestion,
3082
- className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
3083
- }
3084
- ) : null;
3261
+ const BoundSuggestionView = hasSuggestions ? renderSlot(suggestionView, CopilotChatSuggestionView_default, {
3262
+ suggestions,
3263
+ loadingIndexes: suggestionLoadingIndexes,
3264
+ onSelectSuggestion,
3265
+ className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
3266
+ }) : null;
3085
3267
  const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
3086
3268
  const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
3087
3269
  autoScroll,
@@ -3149,13 +3331,13 @@ function CopilotChatView({
3149
3331
  className,
3150
3332
  ...props
3151
3333
  }) => {
3152
- const [hasMounted, setHasMounted] = (0, import_react22.useState)(false);
3334
+ const [hasMounted, setHasMounted] = (0, import_react23.useState)(false);
3153
3335
  const { scrollRef, contentRef, scrollToBottom } = (0, import_use_stick_to_bottom.useStickToBottom)();
3154
- const [showScrollButton, setShowScrollButton] = (0, import_react22.useState)(false);
3155
- (0, import_react22.useEffect)(() => {
3336
+ const [showScrollButton, setShowScrollButton] = (0, import_react23.useState)(false);
3337
+ (0, import_react23.useEffect)(() => {
3156
3338
  setHasMounted(true);
3157
3339
  }, []);
3158
- (0, import_react22.useEffect)(() => {
3340
+ (0, import_react23.useEffect)(() => {
3159
3341
  if (autoScroll) return;
3160
3342
  const scrollElement = scrollRef.current;
3161
3343
  if (!scrollElement) return;
@@ -3255,7 +3437,7 @@ function CopilotChatView({
3255
3437
  ...props
3256
3438
  }
3257
3439
  );
3258
- CopilotChatView2.InputContainer = import_react22.default.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3440
+ CopilotChatView2.InputContainer = import_react23.default.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3259
3441
  "div",
3260
3442
  {
3261
3443
  ref,
@@ -3287,14 +3469,14 @@ var CopilotChatView_default = CopilotChatView;
3287
3469
 
3288
3470
  // src/components/chat/CopilotChat.tsx
3289
3471
  var import_shared8 = require("@copilotkitnext/shared");
3290
- var import_react23 = require("react");
3472
+ var import_react24 = require("react");
3291
3473
  var import_ts_deepmerge = require("ts-deepmerge");
3292
3474
  var import_client = require("@ag-ui/client");
3293
3475
  var import_jsx_runtime19 = require("react/jsx-runtime");
3294
3476
  function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
3295
3477
  const existingConfig = useCopilotChatConfiguration();
3296
3478
  const resolvedAgentId = agentId ?? existingConfig?.agentId ?? import_shared8.DEFAULT_AGENT_ID;
3297
- const resolvedThreadId = (0, import_react23.useMemo)(
3479
+ const resolvedThreadId = (0, import_react24.useMemo)(
3298
3480
  () => threadId ?? existingConfig?.threadId ?? (0, import_shared8.randomUUID)(),
3299
3481
  [threadId, existingConfig?.threadId]
3300
3482
  );
@@ -3307,7 +3489,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
3307
3489
  suggestionView: providedSuggestionView,
3308
3490
  ...restProps
3309
3491
  } = props;
3310
- (0, import_react23.useEffect)(() => {
3492
+ (0, import_react24.useEffect)(() => {
3311
3493
  const connect = async (agent2) => {
3312
3494
  try {
3313
3495
  await copilotkit.connectAgent({ agent: agent2 });
@@ -3323,7 +3505,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
3323
3505
  return () => {
3324
3506
  };
3325
3507
  }, [resolvedThreadId, agent, copilotkit, resolvedAgentId]);
3326
- const onSubmitInput = (0, import_react23.useCallback)(
3508
+ const onSubmitInput = (0, import_react24.useCallback)(
3327
3509
  async (value) => {
3328
3510
  agent.addMessage({
3329
3511
  id: (0, import_shared8.randomUUID)(),
@@ -3338,7 +3520,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
3338
3520
  },
3339
3521
  [agent, copilotkit]
3340
3522
  );
3341
- const handleSelectSuggestion = (0, import_react23.useCallback)(
3523
+ const handleSelectSuggestion = (0, import_react24.useCallback)(
3342
3524
  async (suggestion) => {
3343
3525
  agent.addMessage({
3344
3526
  id: (0, import_shared8.randomUUID)(),
@@ -3353,7 +3535,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
3353
3535
  },
3354
3536
  [agent, copilotkit]
3355
3537
  );
3356
- const stopCurrentRun = (0, import_react23.useCallback)(() => {
3538
+ const stopCurrentRun = (0, import_react24.useCallback)(() => {
3357
3539
  try {
3358
3540
  copilotkit.stopAgent({ agent });
3359
3541
  } catch (error) {
@@ -3409,7 +3591,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
3409
3591
  })(CopilotChat || (CopilotChat = {}));
3410
3592
 
3411
3593
  // src/components/chat/CopilotChatToggleButton.tsx
3412
- var import_react24 = __toESM(require("react"));
3594
+ var import_react25 = __toESM(require("react"));
3413
3595
  var import_lucide_react7 = require("lucide-react");
3414
3596
  var import_jsx_runtime20 = require("react/jsx-runtime");
3415
3597
  var DefaultOpenIcon = ({
@@ -3436,11 +3618,11 @@ var BUTTON_BASE_CLASSES = cn(
3436
3618
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
3437
3619
  "disabled:pointer-events-none disabled:opacity-60"
3438
3620
  );
3439
- var CopilotChatToggleButton = import_react24.default.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
3621
+ var CopilotChatToggleButton = import_react25.default.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
3440
3622
  const { onClick, type, disabled, ...restProps } = buttonProps;
3441
3623
  const configuration = useCopilotChatConfiguration();
3442
3624
  const labels = configuration?.labels ?? CopilotChatDefaultLabels;
3443
- const [fallbackOpen, setFallbackOpen] = (0, import_react24.useState)(false);
3625
+ const [fallbackOpen, setFallbackOpen] = (0, import_react25.useState)(false);
3444
3626
  const isOpen = configuration?.isModalOpen ?? fallbackOpen;
3445
3627
  const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
3446
3628
  const handleClick = (event) => {
@@ -3526,10 +3708,10 @@ CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
3526
3708
  var CopilotChatToggleButton_default = CopilotChatToggleButton;
3527
3709
 
3528
3710
  // src/components/chat/CopilotSidebarView.tsx
3529
- var import_react26 = require("react");
3711
+ var import_react27 = require("react");
3530
3712
 
3531
3713
  // src/components/chat/CopilotModalHeader.tsx
3532
- var import_react25 = require("react");
3714
+ var import_react26 = require("react");
3533
3715
  var import_lucide_react8 = require("lucide-react");
3534
3716
  var import_jsx_runtime21 = require("react/jsx-runtime");
3535
3717
  function CopilotModalHeader({
@@ -3543,7 +3725,7 @@ function CopilotModalHeader({
3543
3725
  const configuration = useCopilotChatConfiguration();
3544
3726
  const fallbackTitle = configuration?.labels.modalHeaderTitle ?? CopilotChatDefaultLabels.modalHeaderTitle;
3545
3727
  const resolvedTitle = title ?? fallbackTitle;
3546
- const handleClose = (0, import_react25.useCallback)(() => {
3728
+ const handleClose = (0, import_react26.useCallback)(() => {
3547
3729
  configuration?.setModalOpen(false);
3548
3730
  }, [configuration]);
3549
3731
  const BoundTitle = renderSlot(titleContent, CopilotModalHeader.Title, {
@@ -3619,8 +3801,8 @@ var SIDEBAR_TRANSITION_MS = 260;
3619
3801
  function CopilotSidebarView({ header, width, ...props }) {
3620
3802
  const configuration = useCopilotChatConfiguration();
3621
3803
  const isSidebarOpen = configuration?.isModalOpen ?? false;
3622
- const sidebarRef = (0, import_react26.useRef)(null);
3623
- const [sidebarWidth, setSidebarWidth] = (0, import_react26.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
3804
+ const sidebarRef = (0, import_react27.useRef)(null);
3805
+ const [sidebarWidth, setSidebarWidth] = (0, import_react27.useState)(width ?? DEFAULT_SIDEBAR_WIDTH);
3624
3806
  const widthToCss = (w) => {
3625
3807
  return typeof w === "number" ? `${w}px` : w;
3626
3808
  };
@@ -3630,7 +3812,7 @@ function CopilotSidebarView({ header, width, ...props }) {
3630
3812
  }
3631
3813
  return w;
3632
3814
  };
3633
- (0, import_react26.useEffect)(() => {
3815
+ (0, import_react27.useEffect)(() => {
3634
3816
  if (width !== void 0) {
3635
3817
  return;
3636
3818
  }
@@ -3709,7 +3891,7 @@ function CopilotSidebarView({ header, width, ...props }) {
3709
3891
  CopilotSidebarView.displayName = "CopilotSidebarView";
3710
3892
 
3711
3893
  // src/components/chat/CopilotPopupView.tsx
3712
- var import_react27 = require("react");
3894
+ var import_react28 = require("react");
3713
3895
  var import_jsx_runtime23 = require("react/jsx-runtime");
3714
3896
  var DEFAULT_POPUP_WIDTH = 420;
3715
3897
  var DEFAULT_POPUP_HEIGHT = 560;
@@ -3734,10 +3916,10 @@ function CopilotPopupView({
3734
3916
  const isPopupOpen = configuration?.isModalOpen ?? false;
3735
3917
  const setModalOpen = configuration?.setModalOpen;
3736
3918
  const labels = configuration?.labels ?? CopilotChatDefaultLabels;
3737
- const containerRef = (0, import_react27.useRef)(null);
3738
- const [isRendered, setIsRendered] = (0, import_react27.useState)(isPopupOpen);
3739
- const [isAnimatingOut, setIsAnimatingOut] = (0, import_react27.useState)(false);
3740
- (0, import_react27.useEffect)(() => {
3919
+ const containerRef = (0, import_react28.useRef)(null);
3920
+ const [isRendered, setIsRendered] = (0, import_react28.useState)(isPopupOpen);
3921
+ const [isAnimatingOut, setIsAnimatingOut] = (0, import_react28.useState)(false);
3922
+ (0, import_react28.useEffect)(() => {
3741
3923
  if (isPopupOpen) {
3742
3924
  setIsRendered(true);
3743
3925
  setIsAnimatingOut(false);
@@ -3753,7 +3935,7 @@ function CopilotPopupView({
3753
3935
  }, 200);
3754
3936
  return () => clearTimeout(timeout);
3755
3937
  }, [isPopupOpen, isRendered]);
3756
- (0, import_react27.useEffect)(() => {
3938
+ (0, import_react28.useEffect)(() => {
3757
3939
  if (!isPopupOpen) {
3758
3940
  return;
3759
3941
  }
@@ -3769,7 +3951,7 @@ function CopilotPopupView({
3769
3951
  window.addEventListener("keydown", handleKeyDown);
3770
3952
  return () => window.removeEventListener("keydown", handleKeyDown);
3771
3953
  }, [isPopupOpen, setModalOpen]);
3772
- (0, import_react27.useEffect)(() => {
3954
+ (0, import_react28.useEffect)(() => {
3773
3955
  if (!isPopupOpen) {
3774
3956
  return;
3775
3957
  }
@@ -3778,7 +3960,7 @@ function CopilotPopupView({
3778
3960
  }, 200);
3779
3961
  return () => clearTimeout(focusTimer);
3780
3962
  }, [isPopupOpen]);
3781
- (0, import_react27.useEffect)(() => {
3963
+ (0, import_react28.useEffect)(() => {
3782
3964
  if (!isPopupOpen || !clickOutsideToClose) {
3783
3965
  return;
3784
3966
  }
@@ -3803,10 +3985,10 @@ function CopilotPopupView({
3803
3985
  document.addEventListener("pointerdown", handlePointerDown);
3804
3986
  return () => document.removeEventListener("pointerdown", handlePointerDown);
3805
3987
  }, [isPopupOpen, clickOutsideToClose, setModalOpen]);
3806
- const headerElement = (0, import_react27.useMemo)(() => renderSlot(header, CopilotModalHeader, {}), [header]);
3988
+ const headerElement = (0, import_react28.useMemo)(() => renderSlot(header, CopilotModalHeader, {}), [header]);
3807
3989
  const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
3808
3990
  const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
3809
- const popupStyle = (0, import_react27.useMemo)(
3991
+ const popupStyle = (0, import_react28.useMemo)(
3810
3992
  () => ({
3811
3993
  "--copilot-popup-width": resolvedWidth,
3812
3994
  "--copilot-popup-height": resolvedHeight,
@@ -3868,10 +4050,10 @@ function CopilotPopupView({
3868
4050
  CopilotPopupView.displayName = "CopilotPopupView";
3869
4051
 
3870
4052
  // src/components/chat/CopilotSidebar.tsx
3871
- var import_react28 = require("react");
4053
+ var import_react29 = require("react");
3872
4054
  var import_jsx_runtime24 = require("react/jsx-runtime");
3873
4055
  function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
3874
- const SidebarViewOverride = (0, import_react28.useMemo)(() => {
4056
+ const SidebarViewOverride = (0, import_react29.useMemo)(() => {
3875
4057
  const Component = (viewProps) => {
3876
4058
  const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
3877
4059
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
@@ -3897,7 +4079,7 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
3897
4079
  CopilotSidebar.displayName = "CopilotSidebar";
3898
4080
 
3899
4081
  // src/components/chat/CopilotPopup.tsx
3900
- var import_react29 = require("react");
4082
+ var import_react30 = require("react");
3901
4083
  var import_jsx_runtime25 = require("react/jsx-runtime");
3902
4084
  function CopilotPopup({
3903
4085
  header,
@@ -3907,7 +4089,7 @@ function CopilotPopup({
3907
4089
  clickOutsideToClose,
3908
4090
  ...chatProps
3909
4091
  }) {
3910
- const PopupViewOverride = (0, import_react29.useMemo)(() => {
4092
+ const PopupViewOverride = (0, import_react30.useMemo)(() => {
3911
4093
  const Component = (viewProps) => {
3912
4094
  const {
3913
4095
  header: viewHeader,
@@ -3953,12 +4135,12 @@ function defineToolCallRenderer(def) {
3953
4135
  }
3954
4136
 
3955
4137
  // src/components/WildcardToolCallRender.tsx
3956
- var import_react30 = require("react");
4138
+ var import_react31 = require("react");
3957
4139
  var import_jsx_runtime26 = require("react/jsx-runtime");
3958
4140
  var WildcardToolCallRender = defineToolCallRenderer({
3959
4141
  name: "*",
3960
4142
  render: ({ args, result, name, status }) => {
3961
- const [isExpanded, setIsExpanded] = (0, import_react30.useState)(false);
4143
+ const [isExpanded, setIsExpanded] = (0, import_react31.useState)(false);
3962
4144
  const statusString = String(status);
3963
4145
  const isActive = statusString === "inProgress" || statusString === "executing";
3964
4146
  const isComplete = statusString === "complete";