@copilotkitnext/react 0.0.22 → 0.0.24

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.mjs CHANGED
@@ -484,7 +484,16 @@ CopilotChatAudioRecorder.displayName = "WebAudioRecorder";
484
484
 
485
485
  // src/lib/slots.tsx
486
486
  import React2 from "react";
487
- function renderSlot(slot, DefaultComponent, props) {
487
+ function shallowEqual(obj1, obj2) {
488
+ const keys1 = Object.keys(obj1);
489
+ const keys2 = Object.keys(obj2);
490
+ if (keys1.length !== keys2.length) return false;
491
+ for (const key of keys1) {
492
+ if (obj1[key] !== obj2[key]) return false;
493
+ }
494
+ return true;
495
+ }
496
+ function renderSlotElement(slot, DefaultComponent, props) {
488
497
  if (typeof slot === "string") {
489
498
  return React2.createElement(DefaultComponent, {
490
499
  ...props,
@@ -492,8 +501,7 @@ function renderSlot(slot, DefaultComponent, props) {
492
501
  });
493
502
  }
494
503
  if (typeof slot === "function") {
495
- const Comp = slot;
496
- return React2.createElement(Comp, props);
504
+ return React2.createElement(slot, props);
497
505
  }
498
506
  if (slot && typeof slot === "object" && !React2.isValidElement(slot)) {
499
507
  return React2.createElement(DefaultComponent, {
@@ -503,6 +511,30 @@ function renderSlot(slot, DefaultComponent, props) {
503
511
  }
504
512
  return React2.createElement(DefaultComponent, props);
505
513
  }
514
+ var MemoizedSlotWrapper = React2.memo(
515
+ React2.forwardRef(function MemoizedSlotWrapper2(props, ref) {
516
+ const { $slot, $component, ...rest } = props;
517
+ const propsWithRef = ref !== null ? { ...rest, ref } : rest;
518
+ return renderSlotElement($slot, $component, propsWithRef);
519
+ }),
520
+ (prev, next) => {
521
+ if (prev.$slot !== next.$slot) return false;
522
+ if (prev.$component !== next.$component) return false;
523
+ const { $slot: _ps, $component: _pc, ...prevRest } = prev;
524
+ const { $slot: _ns, $component: _nc, ...nextRest } = next;
525
+ return shallowEqual(
526
+ prevRest,
527
+ nextRest
528
+ );
529
+ }
530
+ );
531
+ function renderSlot(slot, DefaultComponent, props) {
532
+ return React2.createElement(MemoizedSlotWrapper, {
533
+ ...props,
534
+ $slot: slot,
535
+ $component: DefaultComponent
536
+ });
537
+ }
506
538
 
507
539
  // src/components/chat/CopilotChatInput.tsx
508
540
  import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
@@ -1346,7 +1378,7 @@ import "katex/dist/katex.min.css";
1346
1378
  import { Streamdown } from "streamdown";
1347
1379
 
1348
1380
  // src/hooks/use-render-tool-call.tsx
1349
- import { useCallback as useCallback2, useEffect as useEffect5, useState as useState4, useSyncExternalStore } from "react";
1381
+ import React6, { useCallback as useCallback2, useEffect as useEffect5, useMemo as useMemo4, useState as useState4, useSyncExternalStore } from "react";
1350
1382
  import { ToolCallStatus } from "@copilotkitnext/core";
1351
1383
 
1352
1384
  // src/providers/CopilotKitProvider.tsx
@@ -1635,6 +1667,63 @@ var useCopilotKit = () => {
1635
1667
  import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID2 } from "@copilotkitnext/shared";
1636
1668
  import { partialJSONParse } from "@copilotkitnext/shared";
1637
1669
  import { jsx as jsx9 } from "react/jsx-runtime";
1670
+ var ToolCallRenderer = React6.memo(
1671
+ function ToolCallRenderer2({
1672
+ toolCall,
1673
+ toolMessage,
1674
+ RenderComponent,
1675
+ isExecuting
1676
+ }) {
1677
+ const args = useMemo4(
1678
+ () => partialJSONParse(toolCall.function.arguments),
1679
+ [toolCall.function.arguments]
1680
+ );
1681
+ const toolName = toolCall.function.name;
1682
+ if (toolMessage) {
1683
+ return /* @__PURE__ */ jsx9(
1684
+ RenderComponent,
1685
+ {
1686
+ name: toolName,
1687
+ args,
1688
+ status: ToolCallStatus.Complete,
1689
+ result: toolMessage.content
1690
+ }
1691
+ );
1692
+ } else if (isExecuting) {
1693
+ return /* @__PURE__ */ jsx9(
1694
+ RenderComponent,
1695
+ {
1696
+ name: toolName,
1697
+ args,
1698
+ status: ToolCallStatus.Executing,
1699
+ result: void 0
1700
+ }
1701
+ );
1702
+ } else {
1703
+ return /* @__PURE__ */ jsx9(
1704
+ RenderComponent,
1705
+ {
1706
+ name: toolName,
1707
+ args,
1708
+ status: ToolCallStatus.InProgress,
1709
+ result: void 0
1710
+ }
1711
+ );
1712
+ }
1713
+ },
1714
+ // Custom comparison function to prevent re-renders when tool call data hasn't changed
1715
+ (prevProps, nextProps) => {
1716
+ if (prevProps.toolCall.id !== nextProps.toolCall.id) return false;
1717
+ if (prevProps.toolCall.function.name !== nextProps.toolCall.function.name) return false;
1718
+ if (prevProps.toolCall.function.arguments !== nextProps.toolCall.function.arguments) return false;
1719
+ const prevResult = prevProps.toolMessage?.content;
1720
+ const nextResult = nextProps.toolMessage?.content;
1721
+ if (prevResult !== nextResult) return false;
1722
+ if (prevProps.isExecuting !== nextProps.isExecuting) return false;
1723
+ if (prevProps.RenderComponent !== nextProps.RenderComponent) return false;
1724
+ return true;
1725
+ }
1726
+ );
1638
1727
  function useRenderToolCall() {
1639
1728
  const { copilotkit } = useCopilotKit();
1640
1729
  const config = useCopilotChatConfiguration();
@@ -1683,42 +1772,17 @@ function useRenderToolCall() {
1683
1772
  return null;
1684
1773
  }
1685
1774
  const RenderComponent = renderConfig.render;
1686
- const args = partialJSONParse(toolCall.function.arguments);
1687
- const toolName = toolCall.function.name;
1688
- if (toolMessage) {
1689
- return /* @__PURE__ */ jsx9(
1690
- RenderComponent,
1691
- {
1692
- name: toolName,
1693
- args,
1694
- status: ToolCallStatus.Complete,
1695
- result: toolMessage.content
1696
- },
1697
- toolCall.id
1698
- );
1699
- } else if (executingToolCallIds.has(toolCall.id)) {
1700
- return /* @__PURE__ */ jsx9(
1701
- RenderComponent,
1702
- {
1703
- name: toolName,
1704
- args,
1705
- status: ToolCallStatus.Executing,
1706
- result: void 0
1707
- },
1708
- toolCall.id
1709
- );
1710
- } else {
1711
- return /* @__PURE__ */ jsx9(
1775
+ const isExecuting = executingToolCallIds.has(toolCall.id);
1776
+ return /* @__PURE__ */ jsx9(
1777
+ ToolCallRenderer,
1778
+ {
1779
+ toolCall,
1780
+ toolMessage,
1712
1781
  RenderComponent,
1713
- {
1714
- name: toolName,
1715
- args,
1716
- status: ToolCallStatus.InProgress,
1717
- result: void 0
1718
- },
1719
- toolCall.id
1720
- );
1721
- }
1782
+ isExecuting
1783
+ },
1784
+ toolCall.id
1785
+ );
1722
1786
  },
1723
1787
  [renderToolCalls, executingToolCallIds, agentId]
1724
1788
  );
@@ -1831,8 +1895,10 @@ function useRenderActivityMessage() {
1831
1895
 
1832
1896
  // src/hooks/use-frontend-tool.tsx
1833
1897
  import { useEffect as useEffect6 } from "react";
1834
- function useFrontendTool(tool) {
1898
+ var EMPTY_DEPS = [];
1899
+ function useFrontendTool(tool, deps) {
1835
1900
  const { copilotkit } = useCopilotKit();
1901
+ const extraDeps = deps ?? EMPTY_DEPS;
1836
1902
  useEffect6(() => {
1837
1903
  const name = tool.name;
1838
1904
  if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
@@ -1861,13 +1927,13 @@ function useFrontendTool(tool) {
1861
1927
  return () => {
1862
1928
  copilotkit.removeTool(name, tool.agentId);
1863
1929
  };
1864
- }, [tool.name, copilotkit]);
1930
+ }, [tool.name, copilotkit, extraDeps.length, ...extraDeps]);
1865
1931
  }
1866
1932
 
1867
1933
  // src/hooks/use-human-in-the-loop.tsx
1868
1934
  import { useCallback as useCallback4, useRef as useRef5, useEffect as useEffect7 } from "react";
1869
1935
  import React7 from "react";
1870
- function useHumanInTheLoop(tool) {
1936
+ function useHumanInTheLoop(tool, deps) {
1871
1937
  const { copilotkit } = useCopilotKit();
1872
1938
  const resolvePromiseRef = useRef5(null);
1873
1939
  const respond = useCallback4(async (result) => {
@@ -1918,7 +1984,7 @@ function useHumanInTheLoop(tool) {
1918
1984
  handler,
1919
1985
  render: RenderComponent
1920
1986
  };
1921
- useFrontendTool(frontendTool);
1987
+ useFrontendTool(frontendTool, deps);
1922
1988
  useEffect7(() => {
1923
1989
  return () => {
1924
1990
  const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
@@ -1932,7 +1998,7 @@ function useHumanInTheLoop(tool) {
1932
1998
  }
1933
1999
 
1934
2000
  // src/hooks/use-agent.tsx
1935
- import { useMemo as useMemo4, useEffect as useEffect8, useReducer as useReducer2 } from "react";
2001
+ import { useMemo as useMemo5, useEffect as useEffect8, useReducer as useReducer2 } from "react";
1936
2002
  import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID4 } from "@copilotkitnext/shared";
1937
2003
  import { ProxiedCopilotRuntimeAgent, CopilotKitCoreRuntimeConnectionStatus } from "@copilotkitnext/core";
1938
2004
  var ALL_UPDATES = [
@@ -1944,11 +2010,11 @@ function useAgent({ agentId, updates } = {}) {
1944
2010
  agentId ??= DEFAULT_AGENT_ID4;
1945
2011
  const { copilotkit } = useCopilotKit();
1946
2012
  const [, forceUpdate] = useReducer2((x) => x + 1, 0);
1947
- const updateFlags = useMemo4(
2013
+ const updateFlags = useMemo5(
1948
2014
  () => updates ?? ALL_UPDATES,
1949
2015
  [JSON.stringify(updates)]
1950
2016
  );
1951
- const agent = useMemo4(() => {
2017
+ const agent = useMemo5(() => {
1952
2018
  const existing = copilotkit.getAgent(agentId);
1953
2019
  if (existing) {
1954
2020
  return existing;
@@ -2027,12 +2093,12 @@ function useAgentContext(context) {
2027
2093
  }
2028
2094
 
2029
2095
  // src/hooks/use-suggestions.tsx
2030
- import { useCallback as useCallback5, useEffect as useEffect10, useMemo as useMemo5, useState as useState5 } from "react";
2096
+ import { useCallback as useCallback5, useEffect as useEffect10, useMemo as useMemo6, useState as useState5 } from "react";
2031
2097
  import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID5 } from "@copilotkitnext/shared";
2032
2098
  function useSuggestions({ agentId } = {}) {
2033
2099
  const { copilotkit } = useCopilotKit();
2034
2100
  const config = useCopilotChatConfiguration();
2035
- const resolvedAgentId = useMemo5(() => agentId ?? config?.agentId ?? DEFAULT_AGENT_ID5, [agentId, config?.agentId]);
2101
+ const resolvedAgentId = useMemo6(() => agentId ?? config?.agentId ?? DEFAULT_AGENT_ID5, [agentId, config?.agentId]);
2036
2102
  const [suggestions, setSuggestions] = useState5(() => {
2037
2103
  const result = copilotkit.getSuggestions(resolvedAgentId);
2038
2104
  return result.suggestions;
@@ -2091,20 +2157,19 @@ function useSuggestions({ agentId } = {}) {
2091
2157
  }
2092
2158
 
2093
2159
  // src/hooks/use-configure-suggestions.tsx
2094
- import { useCallback as useCallback6, useEffect as useEffect11, useMemo as useMemo6, useRef as useRef6 } from "react";
2160
+ import { useCallback as useCallback6, useEffect as useEffect11, useMemo as useMemo7, useRef as useRef6 } from "react";
2095
2161
  import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID6 } from "@copilotkitnext/shared";
2096
- var EMPTY_DEPS = [];
2097
- function useConfigureSuggestions(config, options) {
2162
+ function useConfigureSuggestions(config, deps) {
2098
2163
  const { copilotkit } = useCopilotKit();
2099
2164
  const chatConfig = useCopilotChatConfiguration();
2100
- const extraDeps = options?.deps ?? EMPTY_DEPS;
2101
- const resolvedConsumerAgentId = useMemo6(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID6, [chatConfig?.agentId]);
2102
- const rawConsumerAgentId = useMemo6(() => config ? config.consumerAgentId : void 0, [config]);
2165
+ const extraDeps = deps ?? [];
2166
+ const resolvedConsumerAgentId = useMemo7(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID6, [chatConfig?.agentId]);
2167
+ const rawConsumerAgentId = useMemo7(() => config ? config.consumerAgentId : void 0, [config]);
2103
2168
  const normalizationCacheRef = useRef6({
2104
2169
  serialized: null,
2105
2170
  config: null
2106
2171
  });
2107
- const { normalizedConfig, serializedConfig } = useMemo6(() => {
2172
+ const { normalizedConfig, serializedConfig } = useMemo7(() => {
2108
2173
  if (!config) {
2109
2174
  normalizationCacheRef.current = { serialized: null, config: null };
2110
2175
  return { normalizedConfig: null, serializedConfig: null };
@@ -2137,7 +2202,7 @@ function useConfigureSuggestions(config, options) {
2137
2202
  const latestConfigRef = useRef6(null);
2138
2203
  latestConfigRef.current = normalizedConfig;
2139
2204
  const previousSerializedConfigRef = useRef6(null);
2140
- const targetAgentId = useMemo6(() => {
2205
+ const targetAgentId = useMemo7(() => {
2141
2206
  if (!normalizedConfig) {
2142
2207
  return resolvedConsumerAgentId;
2143
2208
  }
@@ -2481,7 +2546,7 @@ CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistant
2481
2546
  var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
2482
2547
 
2483
2548
  // src/components/chat/CopilotChatUserMessage.tsx
2484
- import { useMemo as useMemo7, useState as useState7 } from "react";
2549
+ import { useMemo as useMemo8, useState as useState7 } from "react";
2485
2550
  import { Copy as Copy2, Check as Check3, Edit, ChevronLeft, ChevronRight } from "lucide-react";
2486
2551
  import { twMerge as twMerge5 } from "tailwind-merge";
2487
2552
  import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
@@ -2515,7 +2580,7 @@ function CopilotChatUserMessage({
2515
2580
  className,
2516
2581
  ...props
2517
2582
  }) {
2518
- const flattenedContent = useMemo7(
2583
+ const flattenedContent = useMemo8(
2519
2584
  () => flattenUserMessageContent(message.content),
2520
2585
  [message.content]
2521
2586
  );
@@ -2847,8 +2912,103 @@ CopilotChatSuggestionView.displayName = "CopilotChatSuggestionView";
2847
2912
  var CopilotChatSuggestionView_default = CopilotChatSuggestionView;
2848
2913
 
2849
2914
  // src/components/chat/CopilotChatMessageView.tsx
2915
+ import React11 from "react";
2850
2916
  import { twMerge as twMerge6 } from "tailwind-merge";
2851
2917
  import { jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
2918
+ var MemoizedAssistantMessage = React11.memo(
2919
+ function MemoizedAssistantMessage2({
2920
+ message,
2921
+ messages,
2922
+ isRunning,
2923
+ AssistantMessageComponent
2924
+ }) {
2925
+ return /* @__PURE__ */ jsx17(
2926
+ AssistantMessageComponent,
2927
+ {
2928
+ message,
2929
+ messages,
2930
+ isRunning
2931
+ }
2932
+ );
2933
+ },
2934
+ (prevProps, nextProps) => {
2935
+ if (prevProps.message.id !== nextProps.message.id) return false;
2936
+ if (prevProps.message.content !== nextProps.message.content) return false;
2937
+ const prevToolCalls = prevProps.message.toolCalls;
2938
+ const nextToolCalls = nextProps.message.toolCalls;
2939
+ if (prevToolCalls?.length !== nextToolCalls?.length) return false;
2940
+ if (prevToolCalls && nextToolCalls) {
2941
+ for (let i = 0; i < prevToolCalls.length; i++) {
2942
+ const prevTc = prevToolCalls[i];
2943
+ const nextTc = nextToolCalls[i];
2944
+ if (!prevTc || !nextTc) return false;
2945
+ if (prevTc.id !== nextTc.id) return false;
2946
+ if (prevTc.function.arguments !== nextTc.function.arguments) return false;
2947
+ }
2948
+ }
2949
+ if (prevToolCalls && prevToolCalls.length > 0) {
2950
+ const toolCallIds = new Set(prevToolCalls.map((tc) => tc.id));
2951
+ const prevToolResults = prevProps.messages.filter(
2952
+ (m) => m.role === "tool" && toolCallIds.has(m.toolCallId)
2953
+ );
2954
+ const nextToolResults = nextProps.messages.filter(
2955
+ (m) => m.role === "tool" && toolCallIds.has(m.toolCallId)
2956
+ );
2957
+ if (prevToolResults.length !== nextToolResults.length) return false;
2958
+ for (let i = 0; i < prevToolResults.length; i++) {
2959
+ if (prevToolResults[i].content !== nextToolResults[i].content) return false;
2960
+ }
2961
+ }
2962
+ const nextIsLatest = nextProps.messages[nextProps.messages.length - 1]?.id === nextProps.message.id;
2963
+ if (nextIsLatest && prevProps.isRunning !== nextProps.isRunning) return false;
2964
+ if (prevProps.AssistantMessageComponent !== nextProps.AssistantMessageComponent) return false;
2965
+ return true;
2966
+ }
2967
+ );
2968
+ var MemoizedUserMessage = React11.memo(
2969
+ function MemoizedUserMessage2({
2970
+ message,
2971
+ UserMessageComponent
2972
+ }) {
2973
+ return /* @__PURE__ */ jsx17(UserMessageComponent, { message });
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
+ if (prevProps.UserMessageComponent !== nextProps.UserMessageComponent) return false;
2979
+ return true;
2980
+ }
2981
+ );
2982
+ var MemoizedActivityMessage = React11.memo(
2983
+ function MemoizedActivityMessage2({
2984
+ message,
2985
+ renderActivityMessage
2986
+ }) {
2987
+ return renderActivityMessage(message);
2988
+ },
2989
+ (prevProps, nextProps) => {
2990
+ if (prevProps.message.id !== nextProps.message.id) return false;
2991
+ if (prevProps.message.activityType !== nextProps.message.activityType) return false;
2992
+ if (JSON.stringify(prevProps.message.content) !== JSON.stringify(nextProps.message.content)) return false;
2993
+ return true;
2994
+ }
2995
+ );
2996
+ var MemoizedCustomMessage = React11.memo(
2997
+ function MemoizedCustomMessage2({
2998
+ message,
2999
+ position,
3000
+ renderCustomMessage
3001
+ }) {
3002
+ return renderCustomMessage({ message, position });
3003
+ },
3004
+ (prevProps, nextProps) => {
3005
+ if (prevProps.message.id !== nextProps.message.id) return false;
3006
+ if (prevProps.position !== nextProps.position) return false;
3007
+ if (prevProps.message.content !== nextProps.message.content) return false;
3008
+ if (prevProps.message.role !== nextProps.message.role) return false;
3009
+ return true;
3010
+ }
3011
+ );
2852
3012
  function CopilotChatMessageView({
2853
3013
  messages = [],
2854
3014
  assistantMessage,
@@ -2865,40 +3025,66 @@ function CopilotChatMessageView({
2865
3025
  const elements = [];
2866
3026
  if (renderCustomMessage) {
2867
3027
  elements.push(
2868
- renderCustomMessage({
2869
- message,
2870
- position: "before"
2871
- })
3028
+ /* @__PURE__ */ jsx17(
3029
+ MemoizedCustomMessage,
3030
+ {
3031
+ message,
3032
+ position: "before",
3033
+ renderCustomMessage
3034
+ },
3035
+ `${message.id}-custom-before`
3036
+ )
2872
3037
  );
2873
3038
  }
2874
3039
  if (message.role === "assistant") {
3040
+ const AssistantComponent = typeof assistantMessage === "function" ? assistantMessage : CopilotChatAssistantMessage_default;
2875
3041
  elements.push(
2876
- renderSlot(assistantMessage, CopilotChatAssistantMessage_default, {
2877
- key: message.id,
2878
- message,
2879
- messages,
2880
- isRunning
2881
- })
3042
+ /* @__PURE__ */ jsx17(
3043
+ MemoizedAssistantMessage,
3044
+ {
3045
+ message,
3046
+ messages,
3047
+ isRunning,
3048
+ AssistantMessageComponent: AssistantComponent
3049
+ },
3050
+ message.id
3051
+ )
2882
3052
  );
2883
3053
  } else if (message.role === "user") {
3054
+ const UserComponent = typeof userMessage === "function" ? userMessage : CopilotChatUserMessage_default;
2884
3055
  elements.push(
2885
- renderSlot(userMessage, CopilotChatUserMessage_default, {
2886
- key: message.id,
2887
- message
2888
- })
3056
+ /* @__PURE__ */ jsx17(
3057
+ MemoizedUserMessage,
3058
+ {
3059
+ message,
3060
+ UserMessageComponent: UserComponent
3061
+ },
3062
+ message.id
3063
+ )
2889
3064
  );
2890
3065
  } else if (message.role === "activity") {
2891
- const renderedActivity = renderActivityMessage(message);
2892
- if (renderedActivity) {
2893
- elements.push(renderedActivity);
2894
- }
3066
+ elements.push(
3067
+ /* @__PURE__ */ jsx17(
3068
+ MemoizedActivityMessage,
3069
+ {
3070
+ message,
3071
+ renderActivityMessage
3072
+ },
3073
+ message.id
3074
+ )
3075
+ );
2895
3076
  }
2896
3077
  if (renderCustomMessage) {
2897
3078
  elements.push(
2898
- renderCustomMessage({
2899
- message,
2900
- position: "after"
2901
- })
3079
+ /* @__PURE__ */ jsx17(
3080
+ MemoizedCustomMessage,
3081
+ {
3082
+ message,
3083
+ position: "after",
3084
+ renderCustomMessage
3085
+ },
3086
+ `${message.id}-custom-after`
3087
+ )
2902
3088
  );
2903
3089
  }
2904
3090
  return elements;
@@ -2923,7 +3109,7 @@ CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
2923
3109
  var CopilotChatMessageView_default = CopilotChatMessageView;
2924
3110
 
2925
3111
  // src/components/chat/CopilotChatView.tsx
2926
- import React11, { useRef as useRef7, useState as useState9, useEffect as useEffect13 } from "react";
3112
+ import React12, { useRef as useRef7, useState as useState9, useEffect as useEffect13 } from "react";
2927
3113
  import { twMerge as twMerge7 } from "tailwind-merge";
2928
3114
  import { StickToBottom, useStickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
2929
3115
  import { ChevronDown } from "lucide-react";
@@ -3031,16 +3217,12 @@ function CopilotChatView({
3031
3217
  });
3032
3218
  const BoundInput = renderSlot(input, CopilotChatInput_default, inputProps ?? {});
3033
3219
  const hasSuggestions = Array.isArray(suggestions) && suggestions.length > 0;
3034
- const BoundSuggestionView = hasSuggestions ? renderSlot(
3035
- suggestionView,
3036
- CopilotChatSuggestionView_default,
3037
- {
3038
- suggestions,
3039
- loadingIndexes: suggestionLoadingIndexes,
3040
- onSelectSuggestion,
3041
- className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
3042
- }
3043
- ) : null;
3220
+ const BoundSuggestionView = hasSuggestions ? renderSlot(suggestionView, CopilotChatSuggestionView_default, {
3221
+ suggestions,
3222
+ loadingIndexes: suggestionLoadingIndexes,
3223
+ onSelectSuggestion,
3224
+ className: "mb-3 lg:ml-4 lg:mr-4 ml-0 mr-0"
3225
+ }) : null;
3044
3226
  const BoundFeather = renderSlot(feather, CopilotChatView.Feather, {});
3045
3227
  const BoundScrollView = renderSlot(scrollView, CopilotChatView.ScrollView, {
3046
3228
  autoScroll,
@@ -3214,7 +3396,7 @@ function CopilotChatView({
3214
3396
  ...props
3215
3397
  }
3216
3398
  );
3217
- CopilotChatView2.InputContainer = React11.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ jsx18(
3399
+ CopilotChatView2.InputContainer = React12.forwardRef(({ children, className, keyboardHeight = 0, ...props }, ref) => /* @__PURE__ */ jsx18(
3218
3400
  "div",
3219
3401
  {
3220
3402
  ref,
@@ -3246,14 +3428,14 @@ var CopilotChatView_default = CopilotChatView;
3246
3428
 
3247
3429
  // src/components/chat/CopilotChat.tsx
3248
3430
  import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID7, randomUUID as randomUUID2 } from "@copilotkitnext/shared";
3249
- import { useCallback as useCallback7, useEffect as useEffect14, useMemo as useMemo8 } from "react";
3431
+ import { useCallback as useCallback7, useEffect as useEffect14, useMemo as useMemo9 } from "react";
3250
3432
  import { merge } from "ts-deepmerge";
3251
3433
  import { AGUIConnectNotImplementedError } from "@ag-ui/client";
3252
3434
  import { jsx as jsx19 } from "react/jsx-runtime";
3253
3435
  function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
3254
3436
  const existingConfig = useCopilotChatConfiguration();
3255
3437
  const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID7;
3256
- const resolvedThreadId = useMemo8(
3438
+ const resolvedThreadId = useMemo9(
3257
3439
  () => threadId ?? existingConfig?.threadId ?? randomUUID2(),
3258
3440
  [threadId, existingConfig?.threadId]
3259
3441
  );
@@ -3368,7 +3550,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
3368
3550
  })(CopilotChat || (CopilotChat = {}));
3369
3551
 
3370
3552
  // src/components/chat/CopilotChatToggleButton.tsx
3371
- import React12, { useState as useState10 } from "react";
3553
+ import React13, { useState as useState10 } from "react";
3372
3554
  import { MessageCircle, X as X2 } from "lucide-react";
3373
3555
  import { jsx as jsx20, jsxs as jsxs11 } from "react/jsx-runtime";
3374
3556
  var DefaultOpenIcon = ({
@@ -3395,7 +3577,7 @@ var BUTTON_BASE_CLASSES = cn(
3395
3577
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
3396
3578
  "disabled:pointer-events-none disabled:opacity-60"
3397
3579
  );
3398
- var CopilotChatToggleButton = React12.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
3580
+ var CopilotChatToggleButton = React13.forwardRef(function CopilotChatToggleButton2({ openIcon, closeIcon, className, ...buttonProps }, ref) {
3399
3581
  const { onClick, type, disabled, ...restProps } = buttonProps;
3400
3582
  const configuration = useCopilotChatConfiguration();
3401
3583
  const labels = configuration?.labels ?? CopilotChatDefaultLabels;
@@ -3668,7 +3850,7 @@ function CopilotSidebarView({ header, width, ...props }) {
3668
3850
  CopilotSidebarView.displayName = "CopilotSidebarView";
3669
3851
 
3670
3852
  // src/components/chat/CopilotPopupView.tsx
3671
- import { useEffect as useEffect16, useMemo as useMemo9, useRef as useRef9, useState as useState12 } from "react";
3853
+ import { useEffect as useEffect16, useMemo as useMemo10, useRef as useRef9, useState as useState12 } from "react";
3672
3854
  import { Fragment as Fragment8, jsx as jsx23, jsxs as jsxs14 } from "react/jsx-runtime";
3673
3855
  var DEFAULT_POPUP_WIDTH = 420;
3674
3856
  var DEFAULT_POPUP_HEIGHT = 560;
@@ -3762,10 +3944,10 @@ function CopilotPopupView({
3762
3944
  document.addEventListener("pointerdown", handlePointerDown);
3763
3945
  return () => document.removeEventListener("pointerdown", handlePointerDown);
3764
3946
  }, [isPopupOpen, clickOutsideToClose, setModalOpen]);
3765
- const headerElement = useMemo9(() => renderSlot(header, CopilotModalHeader, {}), [header]);
3947
+ const headerElement = useMemo10(() => renderSlot(header, CopilotModalHeader, {}), [header]);
3766
3948
  const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
3767
3949
  const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
3768
- const popupStyle = useMemo9(
3950
+ const popupStyle = useMemo10(
3769
3951
  () => ({
3770
3952
  "--copilot-popup-width": resolvedWidth,
3771
3953
  "--copilot-popup-height": resolvedHeight,
@@ -3827,10 +4009,10 @@ function CopilotPopupView({
3827
4009
  CopilotPopupView.displayName = "CopilotPopupView";
3828
4010
 
3829
4011
  // src/components/chat/CopilotSidebar.tsx
3830
- import { useMemo as useMemo10 } from "react";
4012
+ import { useMemo as useMemo11 } from "react";
3831
4013
  import { jsx as jsx24 } from "react/jsx-runtime";
3832
4014
  function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
3833
- const SidebarViewOverride = useMemo10(() => {
4015
+ const SidebarViewOverride = useMemo11(() => {
3834
4016
  const Component = (viewProps) => {
3835
4017
  const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
3836
4018
  return /* @__PURE__ */ jsx24(
@@ -3856,7 +4038,7 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
3856
4038
  CopilotSidebar.displayName = "CopilotSidebar";
3857
4039
 
3858
4040
  // src/components/chat/CopilotPopup.tsx
3859
- import { useMemo as useMemo11 } from "react";
4041
+ import { useMemo as useMemo12 } from "react";
3860
4042
  import { jsx as jsx25 } from "react/jsx-runtime";
3861
4043
  function CopilotPopup({
3862
4044
  header,
@@ -3866,7 +4048,7 @@ function CopilotPopup({
3866
4048
  clickOutsideToClose,
3867
4049
  ...chatProps
3868
4050
  }) {
3869
- const PopupViewOverride = useMemo11(() => {
4051
+ const PopupViewOverride = useMemo12(() => {
3870
4052
  const Component = (viewProps) => {
3871
4053
  const {
3872
4054
  header: viewHeader,