@copilotkitnext/react 0.0.27 → 0.0.28

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
@@ -2079,26 +2079,32 @@ function useAgent({ agentId, updates } = {}) {
2079
2079
  }
2080
2080
 
2081
2081
  // src/hooks/use-agent-context.tsx
2082
- import { useEffect as useEffect9 } from "react";
2082
+ import { useEffect as useEffect9, useMemo as useMemo6 } from "react";
2083
2083
  function useAgentContext(context) {
2084
2084
  const { description, value } = context;
2085
2085
  const { copilotkit } = useCopilotKit();
2086
+ const stringValue = useMemo6(() => {
2087
+ if (typeof value === "string") {
2088
+ return value;
2089
+ }
2090
+ return JSON.stringify(value);
2091
+ }, [value]);
2086
2092
  useEffect9(() => {
2087
2093
  if (!copilotkit) return;
2088
- const id = copilotkit.addContext(context);
2094
+ const id = copilotkit.addContext({ description, value: stringValue });
2089
2095
  return () => {
2090
2096
  copilotkit.removeContext(id);
2091
2097
  };
2092
- }, [description, value, copilotkit]);
2098
+ }, [description, stringValue, copilotkit]);
2093
2099
  }
2094
2100
 
2095
2101
  // src/hooks/use-suggestions.tsx
2096
- import { useCallback as useCallback5, useEffect as useEffect10, useMemo as useMemo6, useState as useState5 } from "react";
2102
+ import { useCallback as useCallback5, useEffect as useEffect10, useMemo as useMemo7, useState as useState5 } from "react";
2097
2103
  import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID5 } from "@copilotkitnext/shared";
2098
2104
  function useSuggestions({ agentId } = {}) {
2099
2105
  const { copilotkit } = useCopilotKit();
2100
2106
  const config = useCopilotChatConfiguration();
2101
- const resolvedAgentId = useMemo6(() => agentId ?? config?.agentId ?? DEFAULT_AGENT_ID5, [agentId, config?.agentId]);
2107
+ const resolvedAgentId = useMemo7(() => agentId ?? config?.agentId ?? DEFAULT_AGENT_ID5, [agentId, config?.agentId]);
2102
2108
  const [suggestions, setSuggestions] = useState5(() => {
2103
2109
  const result = copilotkit.getSuggestions(resolvedAgentId);
2104
2110
  return result.suggestions;
@@ -2157,19 +2163,19 @@ function useSuggestions({ agentId } = {}) {
2157
2163
  }
2158
2164
 
2159
2165
  // src/hooks/use-configure-suggestions.tsx
2160
- import { useCallback as useCallback6, useEffect as useEffect11, useMemo as useMemo7, useRef as useRef6 } from "react";
2166
+ import { useCallback as useCallback6, useEffect as useEffect11, useMemo as useMemo8, useRef as useRef6 } from "react";
2161
2167
  import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID6 } from "@copilotkitnext/shared";
2162
2168
  function useConfigureSuggestions(config, deps) {
2163
2169
  const { copilotkit } = useCopilotKit();
2164
2170
  const chatConfig = useCopilotChatConfiguration();
2165
2171
  const extraDeps = deps ?? [];
2166
- const resolvedConsumerAgentId = useMemo7(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID6, [chatConfig?.agentId]);
2167
- const rawConsumerAgentId = useMemo7(() => config ? config.consumerAgentId : void 0, [config]);
2172
+ const resolvedConsumerAgentId = useMemo8(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID6, [chatConfig?.agentId]);
2173
+ const rawConsumerAgentId = useMemo8(() => config ? config.consumerAgentId : void 0, [config]);
2168
2174
  const normalizationCacheRef = useRef6({
2169
2175
  serialized: null,
2170
2176
  config: null
2171
2177
  });
2172
- const { normalizedConfig, serializedConfig } = useMemo7(() => {
2178
+ const { normalizedConfig, serializedConfig } = useMemo8(() => {
2173
2179
  if (!config) {
2174
2180
  normalizationCacheRef.current = { serialized: null, config: null };
2175
2181
  return { normalizedConfig: null, serializedConfig: null };
@@ -2202,7 +2208,7 @@ function useConfigureSuggestions(config, deps) {
2202
2208
  const latestConfigRef = useRef6(null);
2203
2209
  latestConfigRef.current = normalizedConfig;
2204
2210
  const previousSerializedConfigRef = useRef6(null);
2205
- const targetAgentId = useMemo7(() => {
2211
+ const targetAgentId = useMemo8(() => {
2206
2212
  if (!normalizedConfig) {
2207
2213
  return resolvedConsumerAgentId;
2208
2214
  }
@@ -2546,7 +2552,7 @@ CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistant
2546
2552
  var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
2547
2553
 
2548
2554
  // src/components/chat/CopilotChatUserMessage.tsx
2549
- import { useMemo as useMemo8, useState as useState7 } from "react";
2555
+ import { useMemo as useMemo9, useState as useState7 } from "react";
2550
2556
  import { Copy as Copy2, Check as Check3, Edit, ChevronLeft, ChevronRight } from "lucide-react";
2551
2557
  import { twMerge as twMerge5 } from "tailwind-merge";
2552
2558
  import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
@@ -2580,7 +2586,7 @@ function CopilotChatUserMessage({
2580
2586
  className,
2581
2587
  ...props
2582
2588
  }) {
2583
- const flattenedContent = useMemo8(
2589
+ const flattenedContent = useMemo9(
2584
2590
  () => flattenUserMessageContent(message.content),
2585
2591
  [message.content]
2586
2592
  );
@@ -3428,14 +3434,14 @@ var CopilotChatView_default = CopilotChatView;
3428
3434
 
3429
3435
  // src/components/chat/CopilotChat.tsx
3430
3436
  import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID7, randomUUID as randomUUID2 } from "@copilotkitnext/shared";
3431
- import { useCallback as useCallback7, useEffect as useEffect14, useMemo as useMemo9 } from "react";
3437
+ import { useCallback as useCallback7, useEffect as useEffect14, useMemo as useMemo10 } from "react";
3432
3438
  import { merge } from "ts-deepmerge";
3433
3439
  import { AGUIConnectNotImplementedError } from "@ag-ui/client";
3434
3440
  import { jsx as jsx19 } from "react/jsx-runtime";
3435
3441
  function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
3436
3442
  const existingConfig = useCopilotChatConfiguration();
3437
3443
  const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID7;
3438
- const resolvedThreadId = useMemo9(
3444
+ const resolvedThreadId = useMemo10(
3439
3445
  () => threadId ?? existingConfig?.threadId ?? randomUUID2(),
3440
3446
  [threadId, existingConfig?.threadId]
3441
3447
  );
@@ -3850,7 +3856,7 @@ function CopilotSidebarView({ header, width, ...props }) {
3850
3856
  CopilotSidebarView.displayName = "CopilotSidebarView";
3851
3857
 
3852
3858
  // src/components/chat/CopilotPopupView.tsx
3853
- import { useEffect as useEffect16, useMemo as useMemo10, useRef as useRef9, useState as useState12 } from "react";
3859
+ import { useEffect as useEffect16, useMemo as useMemo11, useRef as useRef9, useState as useState12 } from "react";
3854
3860
  import { Fragment as Fragment8, jsx as jsx23, jsxs as jsxs14 } from "react/jsx-runtime";
3855
3861
  var DEFAULT_POPUP_WIDTH = 420;
3856
3862
  var DEFAULT_POPUP_HEIGHT = 560;
@@ -3944,10 +3950,10 @@ function CopilotPopupView({
3944
3950
  document.addEventListener("pointerdown", handlePointerDown);
3945
3951
  return () => document.removeEventListener("pointerdown", handlePointerDown);
3946
3952
  }, [isPopupOpen, clickOutsideToClose, setModalOpen]);
3947
- const headerElement = useMemo10(() => renderSlot(header, CopilotModalHeader, {}), [header]);
3953
+ const headerElement = useMemo11(() => renderSlot(header, CopilotModalHeader, {}), [header]);
3948
3954
  const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
3949
3955
  const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
3950
- const popupStyle = useMemo10(
3956
+ const popupStyle = useMemo11(
3951
3957
  () => ({
3952
3958
  "--copilot-popup-width": resolvedWidth,
3953
3959
  "--copilot-popup-height": resolvedHeight,
@@ -4009,10 +4015,10 @@ function CopilotPopupView({
4009
4015
  CopilotPopupView.displayName = "CopilotPopupView";
4010
4016
 
4011
4017
  // src/components/chat/CopilotSidebar.tsx
4012
- import { useMemo as useMemo11 } from "react";
4018
+ import { useMemo as useMemo12 } from "react";
4013
4019
  import { jsx as jsx24 } from "react/jsx-runtime";
4014
4020
  function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
4015
- const SidebarViewOverride = useMemo11(() => {
4021
+ const SidebarViewOverride = useMemo12(() => {
4016
4022
  const Component = (viewProps) => {
4017
4023
  const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
4018
4024
  return /* @__PURE__ */ jsx24(
@@ -4038,7 +4044,7 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
4038
4044
  CopilotSidebar.displayName = "CopilotSidebar";
4039
4045
 
4040
4046
  // src/components/chat/CopilotPopup.tsx
4041
- import { useMemo as useMemo12 } from "react";
4047
+ import { useMemo as useMemo13 } from "react";
4042
4048
  import { jsx as jsx25 } from "react/jsx-runtime";
4043
4049
  function CopilotPopup({
4044
4050
  header,
@@ -4048,7 +4054,7 @@ function CopilotPopup({
4048
4054
  clickOutsideToClose,
4049
4055
  ...chatProps
4050
4056
  }) {
4051
- const PopupViewOverride = useMemo12(() => {
4057
+ const PopupViewOverride = useMemo13(() => {
4052
4058
  const Component = (viewProps) => {
4053
4059
  const {
4054
4060
  header: viewHeader,