@copilotkit/react-ui 1.10.4-next.2 → 1.10.4-next.3

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{chunk-KCRWXHWT.mjs → chunk-53C3S7R3.mjs} +2 -2
  3. package/dist/{chunk-QQDCZRPA.mjs → chunk-73V4ZLAN.mjs} +2 -2
  4. package/dist/{chunk-FJFWH5AF.mjs → chunk-AUCJZBT5.mjs} +3 -3
  5. package/dist/{chunk-PHH6DYUW.mjs → chunk-EELILZTD.mjs} +2 -2
  6. package/dist/chunk-EELILZTD.mjs.map +1 -0
  7. package/dist/{chunk-Z66Y3KRE.mjs → chunk-WOYNUDPM.mjs} +4 -7
  8. package/dist/chunk-WOYNUDPM.mjs.map +1 -0
  9. package/dist/components/chat/Chat.js +47 -99
  10. package/dist/components/chat/Chat.js.map +1 -1
  11. package/dist/components/chat/Chat.mjs +2 -3
  12. package/dist/components/chat/Messages.js +1 -1
  13. package/dist/components/chat/Messages.js.map +1 -1
  14. package/dist/components/chat/Messages.mjs +1 -1
  15. package/dist/components/chat/Modal.js +61 -113
  16. package/dist/components/chat/Modal.js.map +1 -1
  17. package/dist/components/chat/Modal.mjs +3 -4
  18. package/dist/components/chat/Popup.js +63 -115
  19. package/dist/components/chat/Popup.js.map +1 -1
  20. package/dist/components/chat/Popup.mjs +4 -5
  21. package/dist/components/chat/Sidebar.js +65 -117
  22. package/dist/components/chat/Sidebar.js.map +1 -1
  23. package/dist/components/chat/Sidebar.mjs +4 -5
  24. package/dist/components/chat/index.js +67 -119
  25. package/dist/components/chat/index.js.map +1 -1
  26. package/dist/components/chat/index.mjs +5 -6
  27. package/dist/components/chat/messages/ErrorMessage.mjs +57 -4
  28. package/dist/components/chat/messages/ErrorMessage.mjs.map +1 -1
  29. package/dist/components/chat/props.d.ts +1 -1
  30. package/dist/components/chat/props.js.map +1 -1
  31. package/dist/components/index.js +67 -119
  32. package/dist/components/index.js.map +1 -1
  33. package/dist/components/index.mjs +5 -6
  34. package/dist/index.js +69 -121
  35. package/dist/index.js.map +1 -1
  36. package/dist/index.mjs +5 -6
  37. package/package.json +4 -4
  38. package/src/components/chat/Chat.tsx +1 -2
  39. package/src/components/chat/Messages.tsx +1 -1
  40. package/src/components/chat/props.ts +1 -1
  41. package/dist/chunk-PHH6DYUW.mjs.map +0 -1
  42. package/dist/chunk-SRY5COHG.mjs +0 -63
  43. package/dist/chunk-SRY5COHG.mjs.map +0 -1
  44. package/dist/chunk-Z66Y3KRE.mjs.map +0 -1
  45. /package/dist/{chunk-KCRWXHWT.mjs.map → chunk-53C3S7R3.mjs.map} +0 -0
  46. /package/dist/{chunk-QQDCZRPA.mjs.map → chunk-73V4ZLAN.mjs.map} +0 -0
  47. /package/dist/{chunk-FJFWH5AF.mjs.map → chunk-AUCJZBT5.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # ui
2
2
 
3
+ ## 1.10.4-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 5d55555: - fix: remove default error message
8
+ - @copilotkit/react-core@1.10.4-next.3
9
+ - @copilotkit/runtime-client-gql@1.10.4-next.3
10
+ - @copilotkit/shared@1.10.4-next.3
11
+
3
12
  ## 1.10.4-next.2
4
13
 
5
14
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotModal
3
- } from "./chunk-FJFWH5AF.mjs";
3
+ } from "./chunk-AUCJZBT5.mjs";
4
4
  import {
5
5
  __spreadProps,
6
6
  __spreadValues
@@ -27,4 +27,4 @@ function CopilotSidebar(props) {
27
27
  export {
28
28
  CopilotSidebar
29
29
  };
30
- //# sourceMappingURL=chunk-KCRWXHWT.mjs.map
30
+ //# sourceMappingURL=chunk-53C3S7R3.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotModal
3
- } from "./chunk-FJFWH5AF.mjs";
3
+ } from "./chunk-AUCJZBT5.mjs";
4
4
  import {
5
5
  __spreadProps,
6
6
  __spreadValues
@@ -18,4 +18,4 @@ function CopilotPopup(props) {
18
18
  export {
19
19
  CopilotPopup
20
20
  };
21
- //# sourceMappingURL=chunk-QQDCZRPA.mjs.map
21
+ //# sourceMappingURL=chunk-73V4ZLAN.mjs.map
@@ -9,13 +9,13 @@ import {
9
9
  } from "./chunk-UFN2VWSR.mjs";
10
10
  import {
11
11
  CopilotChat
12
- } from "./chunk-Z66Y3KRE.mjs";
12
+ } from "./chunk-WOYNUDPM.mjs";
13
13
  import {
14
14
  Input
15
15
  } from "./chunk-DTRPPNSA.mjs";
16
16
  import {
17
17
  Messages
18
- } from "./chunk-PHH6DYUW.mjs";
18
+ } from "./chunk-EELILZTD.mjs";
19
19
  import {
20
20
  AssistantMessage
21
21
  } from "./chunk-X477GDGZ.mjs";
@@ -219,4 +219,4 @@ var CopilotModal = (_a) => {
219
219
  export {
220
220
  CopilotModal
221
221
  };
222
- //# sourceMappingURL=chunk-FJFWH5AF.mjs.map
222
+ //# sourceMappingURL=chunk-AUCJZBT5.mjs.map
@@ -88,7 +88,7 @@ var Messages = ({
88
88
  );
89
89
  }),
90
90
  interrupt,
91
- chatError && /* @__PURE__ */ jsx(ErrorMessage, { error: chatError, isCurrentMessage: true })
91
+ chatError && ErrorMessage && /* @__PURE__ */ jsx(ErrorMessage, { error: chatError, isCurrentMessage: true })
92
92
  ] }),
93
93
  /* @__PURE__ */ jsx("footer", { className: "copilotKitMessagesFooter", ref: messagesEndRef, children })
94
94
  ] });
@@ -175,4 +175,4 @@ export {
175
175
  Messages,
176
176
  useScrollToBottom
177
177
  };
178
- //# sourceMappingURL=chunk-PHH6DYUW.mjs.map
178
+ //# sourceMappingURL=chunk-EELILZTD.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/chat/Messages.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from \"react\";\nimport { MessagesProps } from \"./props\";\nimport { useChatContext } from \"./ChatContext\";\nimport { Message } from \"@copilotkit/shared\";\nimport { useCopilotChatInternal as useCopilotChat } from \"@copilotkit/react-core\";\nimport { LegacyRenderMessage, LegacyRenderProps } from \"./messages/LegacyRenderMessage\";\n\nexport const Messages = ({\n inProgress,\n children,\n RenderMessage,\n AssistantMessage,\n UserMessage,\n ErrorMessage,\n ImageRenderer,\n onRegenerate,\n onCopy,\n onThumbsUp,\n onThumbsDown,\n markdownTagRenderers,\n chatError,\n\n // Legacy props\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n RenderImageMessage,\n}: MessagesProps) => {\n const { labels } = useChatContext();\n const { messages: visibleMessages, interrupt } = useCopilotChat();\n const initialMessages = useMemo(() => makeInitialMessages(labels.initial), [labels.initial]);\n const messages = [...initialMessages, ...visibleMessages];\n const { messagesContainerRef, messagesEndRef } = useScrollToBottom(messages);\n\n // Check if any legacy props are provided\n const hasLegacyProps = !!(\n RenderTextMessage ||\n RenderActionExecutionMessage ||\n RenderAgentStateMessage ||\n RenderResultMessage ||\n RenderImageMessage\n );\n\n // Show deprecation warning if legacy props are used\n useEffect(() => {\n if (hasLegacyProps) {\n console.warn(\n \"[CopilotKit] Legacy message render props (RenderTextMessage, RenderActionExecutionMessage, etc.) are deprecated. \" +\n \"Please use the unified 'RenderMessage' prop instead. \" +\n \"See migration guide: https://docs.copilotkit.ai/migration/render-message\",\n );\n }\n }, [hasLegacyProps]);\n\n // Create legacy props object for the adapter\n const legacyProps: LegacyRenderProps = useMemo(\n () => ({\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n RenderImageMessage,\n }),\n [\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n RenderImageMessage,\n ],\n );\n\n // Determine which render component to use\n const MessageRenderer = hasLegacyProps\n ? (props: any) => <LegacyRenderMessage {...props} legacyProps={legacyProps} />\n : RenderMessage;\n\n return (\n <div className=\"copilotKitMessages\" ref={messagesContainerRef}>\n <div className=\"copilotKitMessagesContainer\">\n {messages.map((message, index) => {\n const isCurrentMessage = index === messages.length - 1;\n return (\n <MessageRenderer\n key={index}\n message={message}\n inProgress={inProgress}\n index={index}\n isCurrentMessage={isCurrentMessage}\n AssistantMessage={AssistantMessage}\n UserMessage={UserMessage}\n ImageRenderer={ImageRenderer}\n onRegenerate={onRegenerate}\n onCopy={onCopy}\n onThumbsUp={onThumbsUp}\n onThumbsDown={onThumbsDown}\n markdownTagRenderers={markdownTagRenderers}\n />\n );\n })}\n {interrupt}\n {chatError && ErrorMessage && <ErrorMessage error={chatError} isCurrentMessage />}\n </div>\n <footer className=\"copilotKitMessagesFooter\" ref={messagesEndRef}>\n {children}\n </footer>\n </div>\n );\n};\n\nfunction makeInitialMessages(initial: string | string[] | undefined): Message[] {\n if (!initial) return [];\n\n if (Array.isArray(initial)) {\n return initial.map((message) => {\n return {\n id: message,\n role: \"assistant\",\n content: message,\n };\n });\n }\n\n return [\n {\n id: initial,\n role: \"assistant\",\n content: initial,\n },\n ];\n}\n\nexport function useScrollToBottom(messages: Message[]) {\n const messagesEndRef = useRef<HTMLDivElement>(null);\n const messagesContainerRef = useRef<HTMLDivElement | null>(null);\n const isProgrammaticScrollRef = useRef(false);\n const isUserScrollUpRef = useRef(false);\n\n const scrollToBottom = () => {\n if (messagesContainerRef.current && messagesEndRef.current) {\n isProgrammaticScrollRef.current = true;\n messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;\n }\n };\n\n const handleScroll = () => {\n if (isProgrammaticScrollRef.current) {\n isProgrammaticScrollRef.current = false;\n return;\n }\n\n if (messagesContainerRef.current) {\n const { scrollTop, scrollHeight, clientHeight } = messagesContainerRef.current;\n isUserScrollUpRef.current = scrollTop + clientHeight < scrollHeight;\n }\n };\n\n useEffect(() => {\n const container = messagesContainerRef.current;\n if (container) {\n container.addEventListener(\"scroll\", handleScroll);\n }\n return () => {\n if (container) {\n container.removeEventListener(\"scroll\", handleScroll);\n }\n };\n }, []);\n\n useEffect(() => {\n const container = messagesContainerRef.current;\n if (!container) {\n return;\n }\n\n const mutationObserver = new MutationObserver(() => {\n if (!isUserScrollUpRef.current) {\n scrollToBottom();\n }\n });\n\n mutationObserver.observe(container, {\n childList: true,\n subtree: true,\n characterData: true,\n });\n\n return () => {\n mutationObserver.disconnect();\n };\n }, []);\n\n useEffect(() => {\n isUserScrollUpRef.current = false;\n scrollToBottom();\n }, [messages.filter((m) => m.role === \"user\").length]);\n\n return { messagesEndRef, messagesContainerRef };\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,WAAW,SAAS,cAAc;AAI3C,SAAS,0BAA0B,sBAAsB;AAuEnC,cAKhB,YALgB;AApEf,IAAM,WAAW,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAqB;AACnB,QAAM,EAAE,OAAO,IAAI,eAAe;AAClC,QAAM,EAAE,UAAU,iBAAiB,UAAU,IAAI,eAAe;AAChE,QAAM,kBAAkB,QAAQ,MAAM,oBAAoB,OAAO,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC;AAC3F,QAAM,WAAW,CAAC,GAAG,iBAAiB,GAAG,eAAe;AACxD,QAAM,EAAE,sBAAsB,eAAe,IAAI,kBAAkB,QAAQ;AAG3E,QAAM,iBAAiB,CAAC,EACtB,qBACA,gCACA,2BACA,uBACA;AAIF,YAAU,MAAM;AACd,QAAI,gBAAgB;AAClB,cAAQ;AAAA,QACN;AAAA,MAGF;AAAA,IACF;AAAA,EACF,GAAG,CAAC,cAAc,CAAC;AAGnB,QAAM,cAAiC;AAAA,IACrC,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA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4
1
  import {
5
2
  Suggestions
6
3
  } from "./chunk-226ZMOE3.mjs";
@@ -12,7 +9,7 @@ import {
12
9
  } from "./chunk-DTRPPNSA.mjs";
13
10
  import {
14
11
  Messages
15
- } from "./chunk-PHH6DYUW.mjs";
12
+ } from "./chunk-EELILZTD.mjs";
16
13
  import {
17
14
  RenderMessage
18
15
  } from "./chunk-LJAYSRCB.mjs";
@@ -76,7 +73,7 @@ function CopilotChat({
76
73
  AssistantMessage: AssistantMessage2 = AssistantMessage,
77
74
  UserMessage: UserMessage2 = UserMessage,
78
75
  ImageRenderer: ImageRenderer2 = ImageRenderer,
79
- ErrorMessage: ErrorMessage2 = ErrorMessage,
76
+ ErrorMessage,
80
77
  imageUploadsEnabled,
81
78
  inputFileAccept = "image/*",
82
79
  hideStopButton,
@@ -357,7 +354,7 @@ function CopilotChat({
357
354
  onThumbsDown: handleThumbsDown,
358
355
  markdownTagRenderers,
359
356
  ImageRenderer: ImageRenderer2,
360
- ErrorMessage: ErrorMessage2,
357
+ ErrorMessage,
361
358
  chatError,
362
359
  RenderTextMessage,
363
360
  RenderActionExecutionMessage,
@@ -655,4 +652,4 @@ export {
655
652
  WrappedCopilotChat,
656
653
  useCopilotChatLogic
657
654
  };
658
- //# sourceMappingURL=chunk-Z66Y3KRE.mjs.map
655
+ //# sourceMappingURL=chunk-WOYNUDPM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/chat/Chat.tsx"],"sourcesContent":["/**\n * <br/>\n * <img src=\"https://cdn.copilotkit.ai/docs/copilotkit/images/CopilotChat.gif\" width=\"500\" />\n *\n * A chatbot panel component for the CopilotKit framework. The component allows for a high degree\n * of customization through various props and custom CSS.\n *\n * ## Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ## Usage\n *\n * ```tsx\n * import { CopilotChat } from \"@copilotkit/react-ui\";\n * import \"@copilotkit/react-ui/styles.css\";\n *\n * <CopilotChat\n * labels={{\n * title: \"Your Assistant\",\n * initial: \"Hi! 👋 How can I assist you today?\",\n * }}\n * />\n * ```\n *\n * ### With Observability Hooks\n *\n * To monitor user interactions, provide the `observabilityHooks` prop.\n * **Note:** This requires a `publicApiKey` in the `<CopilotKit>` provider.\n *\n * ```tsx\n * <CopilotKit publicApiKey=\"YOUR_PUBLIC_API_KEY\">\n * <CopilotChat\n * observabilityHooks={{\n * onMessageSent: (message) => {\n * console.log(\"Message sent:\", message);\n * },\n * }}\n * />\n * </CopilotKit>\n * ```\n *\n * ### Look & Feel\n *\n * By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:\n * ```tsx title=\"YourRootComponent.tsx\"\n * ...\n * import \"@copilotkit/react-ui/styles.css\"; // [!code highlight]\n *\n * export function YourRootComponent() {\n * return (\n * <CopilotKit>\n * ...\n * </CopilotKit>\n * );\n * }\n * ```\n * For more information about how to customize the styles, check out the [Customize Look & Feel](/guides/custom-look-and-feel/customize-built-in-ui-components) guide.\n */\n\nimport {\n ChatContext,\n ChatContextProvider,\n CopilotChatIcons,\n CopilotChatLabels,\n} from \"./ChatContext\";\nimport { Messages as DefaultMessages } from \"./Messages\";\nimport { Input as DefaultInput } from \"./Input\";\nimport { RenderMessage as DefaultRenderMessage } from \"./messages/RenderMessage\";\nimport { AssistantMessage as DefaultAssistantMessage } from \"./messages/AssistantMessage\";\nimport { UserMessage as DefaultUserMessage } from \"./messages/UserMessage\";\nimport { ImageRenderer as DefaultImageRenderer } from \"./messages/ImageRenderer\";\nimport React, { useEffect, useRef, useState, useCallback, useMemo } from \"react\";\nimport {\n SystemMessageFunction,\n useCopilotChatInternal as useCopilotChat,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"@copilotkit/react-core\";\nimport type { SuggestionItem } from \"@copilotkit/react-core\";\nimport {\n CopilotKitError,\n CopilotKitErrorCode,\n CopilotErrorEvent,\n Message,\n Severity,\n ErrorVisibility,\n styledConsole,\n CopilotErrorHandler,\n} from \"@copilotkit/shared\";\nimport { randomId } from \"@copilotkit/shared\";\nimport {\n AssistantMessageProps,\n ChatError,\n ComponentsMap,\n CopilotObservabilityHooks,\n ErrorMessageProps,\n ImageRendererProps,\n InputProps,\n MessagesProps,\n RenderMessageProps,\n RenderSuggestionsListProps,\n UserMessageProps,\n} from \"./props\";\n\nimport { HintFunction, runAgent, stopAgent } from \"@copilotkit/react-core\";\nimport { ImageUploadQueue } from \"./ImageUploadQueue\";\nimport { Suggestions as DefaultRenderSuggestionsList } from \"./Suggestions\";\n\n/**\n * The type of suggestions to use in the chat.\n *\n * `auto` - Suggestions are generated automatically.\n * `manual` - Suggestions are controlled programmatically.\n * `SuggestionItem[]` - Static suggestions array.\n */\nexport type ChatSuggestions = \"auto\" | \"manual\" | SuggestionItem[];\n\n/**\n * Props for CopilotChat component.\n */\nexport interface CopilotChatProps {\n /**\n * Custom instructions to be added to the system message. Use this property to\n * provide additional context or guidance to the language model, influencing\n * its responses. These instructions can include specific directions,\n * preferences, or criteria that the model should consider when generating\n * its output, thereby tailoring the conversation more precisely to the\n * user's needs or the application's requirements.\n */\n instructions?: string;\n\n /**\n * Controls the behavior of suggestions in the chat interface.\n *\n * `auto` (default) - Suggestions are generated automatically:\n * - When the chat is first opened (empty state)\n * - After each message exchange completes\n * - Uses configuration from `useCopilotChatSuggestions` hooks\n *\n * `manual` - Suggestions are controlled programmatically:\n * - Use `setSuggestions()` to set custom suggestions\n * - Use `generateSuggestions()` to trigger AI generation\n * - Access via `useCopilotChat` hook\n *\n * `SuggestionItem[]` - Static suggestions array:\n * - Always shows the same suggestions\n * - No AI generation involved\n */\n suggestions?: ChatSuggestions;\n\n /**\n * A callback that gets called when the in progress state changes.\n */\n onInProgress?: (inProgress: boolean) => void;\n\n /**\n * A callback that gets called when a new message it submitted.\n */\n onSubmitMessage?: (message: string) => void | Promise<void>;\n\n /**\n * A custom stop generation function.\n */\n onStopGeneration?: OnStopGeneration;\n\n /**\n * A custom reload messages function.\n */\n onReloadMessages?: OnReloadMessages;\n\n /**\n * A callback function to regenerate the assistant's response\n */\n onRegenerate?: (messageId: string) => void;\n\n /**\n * A callback function when the message is copied\n */\n onCopy?: (message: string) => void;\n\n /**\n * A callback function for thumbs up feedback\n */\n onThumbsUp?: (message: Message) => void;\n\n /**\n * A callback function for thumbs down feedback\n */\n onThumbsDown?: (message: Message) => void;\n\n /**\n * A list of markdown components to render in assistant message.\n * Useful when you want to render custom elements in the message (e.g a reference tag element)\n */\n markdownTagRenderers?: ComponentsMap;\n\n /**\n * Icons can be used to set custom icons for the chat window.\n */\n icons?: CopilotChatIcons;\n\n /**\n * Labels can be used to set custom labels for the chat window.\n */\n labels?: CopilotChatLabels;\n\n /**\n * Enable image upload button (image inputs only supported on some models)\n */\n imageUploadsEnabled?: boolean;\n\n /**\n * The 'accept' attribute for the file input used for image uploads.\n * Defaults to \"image/*\".\n */\n inputFileAccept?: string;\n\n /**\n * A function that takes in context string and instructions and returns\n * the system message to include in the chat request.\n * Use this to completely override the system message, when providing\n * instructions is not enough.\n */\n makeSystemMessage?: SystemMessageFunction;\n\n /**\n * Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).\n */\n disableSystemMessage?: boolean;\n\n /**\n * A custom assistant message component to use instead of the default.\n */\n AssistantMessage?: React.ComponentType<AssistantMessageProps>;\n\n /**\n * A custom user message component to use instead of the default.\n */\n UserMessage?: React.ComponentType<UserMessageProps>;\n\n /**\n * A custom error message component to use instead of the default.\n */\n ErrorMessage?: React.ComponentType<ErrorMessageProps>;\n\n /**\n * A custom Messages component to use instead of the default.\n */\n Messages?: React.ComponentType<MessagesProps>;\n\n /**\n * @deprecated - use RenderMessage instead\n */\n RenderTextMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * @deprecated - use RenderMessage instead\n */\n RenderActionExecutionMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * @deprecated - use RenderMessage instead\n */\n RenderAgentStateMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * @deprecated - use RenderMessage instead\n */\n RenderResultMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * @deprecated - use RenderMessage instead\n */\n RenderImageMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * A custom RenderMessage component to use instead of the default.\n *\n * **Warning**: This is a break-glass solution to allow for custom\n * rendering of messages. You are most likely looking to swap out\n * the AssistantMessage and UserMessage components instead which\n * are also props.\n */\n RenderMessage?: React.ComponentType<RenderMessageProps>;\n\n /**\n * A custom suggestions list component to use instead of the default.\n */\n RenderSuggestionsList?: React.ComponentType<RenderSuggestionsListProps>;\n\n /**\n * A custom Input component to use instead of the default.\n */\n Input?: React.ComponentType<InputProps>;\n\n /**\n * A custom image rendering component to use instead of the default.\n */\n ImageRenderer?: React.ComponentType<ImageRendererProps>;\n\n /**\n * A class name to apply to the root element.\n */\n className?: string;\n\n /**\n * Children to render.\n */\n children?: React.ReactNode;\n\n hideStopButton?: boolean;\n\n /**\n * Event hooks for CopilotKit chat events.\n * These hooks only work when publicApiKey is provided.\n */\n observabilityHooks?: CopilotObservabilityHooks;\n\n /**\n * Custom error renderer for chat-specific errors.\n * When provided, errors will be displayed inline within the chat interface.\n */\n renderError?: (error: {\n message: string;\n operation?: string;\n timestamp: number;\n onDismiss: () => void;\n onRetry?: () => void;\n }) => React.ReactNode;\n\n /**\n * Optional handler for comprehensive debugging and observability.\n */\n onError?: CopilotErrorHandler;\n}\n\ninterface OnStopGenerationArguments {\n /**\n * The name of the currently executing agent.\n */\n currentAgentName: string | undefined;\n\n /**\n * The messages in the chat.\n */\n messages: Message[];\n\n /**\n * Set the messages in the chat.\n */\n setMessages: (messages: Message[]) => void;\n\n /**\n * Stop chat generation.\n */\n stopGeneration: () => void;\n\n /**\n * Restart the currently executing agent.\n */\n restartCurrentAgent: () => void;\n\n /**\n * Stop the currently executing agent.\n */\n stopCurrentAgent: () => void;\n\n /**\n * Run the currently executing agent.\n */\n runCurrentAgent: (hint?: HintFunction) => Promise<void>;\n\n /**\n * Set the state of the currently executing agent.\n */\n setCurrentAgentState: (state: any) => void;\n}\n\nexport type OnReloadMessagesArguments = OnStopGenerationArguments & {\n /**\n * The message on which \"regenerate\" was pressed\n */\n messageId: string;\n};\n\nexport type OnStopGeneration = (args: OnStopGenerationArguments) => void;\n\nexport type OnReloadMessages = (args: OnReloadMessagesArguments) => void;\n\nexport type ImageUpload = {\n contentType: string;\n bytes: string;\n};\n\nexport function CopilotChat({\n instructions,\n suggestions = \"auto\",\n onSubmitMessage,\n makeSystemMessage,\n disableSystemMessage,\n onInProgress,\n onStopGeneration,\n onReloadMessages,\n onRegenerate,\n onCopy,\n onThumbsUp,\n onThumbsDown,\n markdownTagRenderers,\n Messages = DefaultMessages,\n RenderMessage = DefaultRenderMessage,\n RenderSuggestionsList = DefaultRenderSuggestionsList,\n Input = DefaultInput,\n className,\n icons,\n labels,\n AssistantMessage = DefaultAssistantMessage,\n UserMessage = DefaultUserMessage,\n ImageRenderer = DefaultImageRenderer,\n ErrorMessage,\n imageUploadsEnabled,\n inputFileAccept = \"image/*\",\n hideStopButton,\n observabilityHooks,\n renderError,\n onError,\n // Legacy props - deprecated\n RenderTextMessage,\n RenderActionExecutionMessage,\n RenderAgentStateMessage,\n RenderResultMessage,\n RenderImageMessage,\n}: CopilotChatProps) {\n const {\n additionalInstructions,\n setChatInstructions,\n copilotApiConfig,\n setBannerError,\n setInternalErrorHandler,\n removeInternalErrorHandler,\n } = useCopilotContext();\n\n // Destructure stable values to avoid object reference changes\n const { publicApiKey, chatApiEndpoint } = copilotApiConfig;\n const [selectedImages, setSelectedImages] = useState<Array<ImageUpload>>([]);\n const [chatError, setChatError] = useState<ChatError | null>(null);\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n // Helper function to trigger event hooks only if publicApiKey is provided\n const triggerObservabilityHook = useCallback(\n (hookName: keyof CopilotObservabilityHooks, ...args: any[]) => {\n if (publicApiKey && observabilityHooks?.[hookName]) {\n (observabilityHooks[hookName] as any)(...args);\n }\n if (observabilityHooks?.[hookName] && !publicApiKey) {\n setBannerError(\n new CopilotKitError({\n message: \"observabilityHooks requires a publicApiKey to function.\",\n code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,\n severity: Severity.CRITICAL,\n visibility: ErrorVisibility.BANNER,\n }),\n );\n styledConsole.publicApiKeyRequired(\"observabilityHooks\");\n }\n },\n [publicApiKey, observabilityHooks, setBannerError],\n );\n\n // Helper function to trigger chat error and render error UI\n const triggerChatError = useCallback(\n (error: any, operation: string, originalError?: any) => {\n const errorMessage = error?.message || error?.toString() || \"An error occurred\";\n\n // Set chat error state for rendering\n setChatError({\n message: errorMessage,\n operation,\n timestamp: Date.now(),\n });\n\n const errorEvent: CopilotErrorEvent = {\n type: \"error\",\n timestamp: Date.now(),\n context: {\n source: \"ui\",\n request: {\n operation,\n url: chatApiEndpoint,\n startTime: Date.now(),\n },\n technical: {\n environment: \"browser\",\n userAgent: typeof navigator !== \"undefined\" ? navigator.userAgent : undefined,\n stackTrace: originalError instanceof Error ? originalError.stack : undefined,\n },\n },\n error,\n };\n\n if (onError) {\n onError(errorEvent);\n }\n\n // Also trigger observability hook if available\n if (publicApiKey && observabilityHooks?.onError) {\n observabilityHooks.onError(errorEvent);\n }\n\n // Show banner error if onError hook is used without publicApiKey\n if (observabilityHooks?.onError && !publicApiKey) {\n setBannerError(\n new CopilotKitError({\n message: \"observabilityHooks.onError requires a publicApiKey to function.\",\n code: CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,\n severity: Severity.CRITICAL,\n visibility: ErrorVisibility.BANNER,\n }),\n );\n styledConsole.publicApiKeyRequired(\"observabilityHooks.onError\");\n }\n },\n [publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError],\n );\n\n useEffect(() => {\n const id = \"chat-component\";\n setInternalErrorHandler({\n [id]: (error: CopilotErrorEvent) => {\n if (!error) return;\n triggerChatError(error.error, \"sendMessage\");\n },\n });\n return () => {\n // unregister when this instance unmounts\n removeInternalErrorHandler?.(id);\n };\n }, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);\n\n // Clipboard paste handler\n useEffect(() => {\n if (!imageUploadsEnabled) return;\n\n const handlePaste = async (e: ClipboardEvent) => {\n const target = e.target as HTMLElement;\n if (!target.parentElement?.classList.contains(\"copilotKitInput\")) return;\n\n const items = Array.from(e.clipboardData?.items || []);\n const imageItems = items.filter((item) => item.type.startsWith(\"image/\"));\n\n if (imageItems.length === 0) return;\n\n e.preventDefault(); // Prevent default paste behavior for images\n\n const imagePromises: Promise<ImageUpload | null>[] = imageItems.map((item) => {\n const file = item.getAsFile();\n if (!file) return Promise.resolve(null);\n\n return new Promise<ImageUpload | null>((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = (e) => {\n const base64String = (e.target?.result as string)?.split(\",\")[1];\n if (base64String) {\n resolve({\n contentType: file.type,\n bytes: base64String,\n });\n } else {\n resolve(null);\n }\n };\n reader.onerror = reject;\n reader.readAsDataURL(file);\n });\n });\n\n try {\n const loadedImages = (await Promise.all(imagePromises)).filter((img) => img !== null);\n setSelectedImages((prev) => [...prev, ...loadedImages]);\n } catch (error) {\n // Trigger chat-level error handler\n triggerChatError(error, \"processClipboardImages\", error);\n console.error(\"Error processing pasted images:\", error);\n }\n };\n\n document.addEventListener(\"paste\", handlePaste);\n return () => document.removeEventListener(\"paste\", handlePaste);\n }, [imageUploadsEnabled, triggerChatError]);\n\n useEffect(() => {\n if (!additionalInstructions?.length) {\n setChatInstructions(instructions || \"\");\n return;\n }\n\n /*\n Will result in a prompt like:\n\n You are a helpful assistant. \n Additionally, follow these instructions:\n - Do not answer questions about the weather.\n - Do not answer questions about the stock market.\"\n */\n const combinedAdditionalInstructions = [\n instructions,\n \"Additionally, follow these instructions:\",\n ...additionalInstructions.map((instruction) => `- ${instruction}`),\n ];\n\n setChatInstructions(combinedAdditionalInstructions.join(\"\\n\") || \"\");\n }, [instructions, additionalInstructions]);\n\n const {\n messages,\n isLoading,\n sendMessage,\n stopGeneration,\n reloadMessages,\n suggestions: currentSuggestions,\n } = useCopilotChatLogic(\n suggestions,\n makeSystemMessage,\n disableSystemMessage,\n onInProgress,\n onSubmitMessage,\n onStopGeneration,\n onReloadMessages,\n );\n\n // Track loading state changes for chat start/stop events\n const prevIsLoading = useRef(isLoading);\n useEffect(() => {\n if (prevIsLoading.current !== isLoading) {\n if (isLoading) {\n triggerObservabilityHook(\"onChatStarted\");\n } else {\n triggerObservabilityHook(\"onChatStopped\");\n }\n prevIsLoading.current = isLoading;\n }\n }, [isLoading, triggerObservabilityHook]);\n\n // Wrapper for sendMessage to clear selected images\n const handleSendMessage = (text: string) => {\n const images = selectedImages;\n setSelectedImages([]);\n if (fileInputRef.current) {\n fileInputRef.current.value = \"\";\n }\n\n // Trigger message sent event\n triggerObservabilityHook(\"onMessageSent\", text);\n\n return sendMessage(text, images);\n };\n\n const chatContext = React.useContext(ChatContext);\n const isVisible = chatContext ? chatContext.open : true;\n\n const handleRegenerate = (messageId: string) => {\n if (onRegenerate) {\n onRegenerate(messageId);\n }\n\n // Trigger message regenerated event\n triggerObservabilityHook(\"onMessageRegenerated\", messageId);\n\n reloadMessages(messageId);\n };\n\n const handleCopy = (message: string) => {\n if (onCopy) {\n onCopy(message);\n }\n\n // Trigger message copied event\n triggerObservabilityHook(\"onMessageCopied\", message);\n };\n\n const handleImageUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {\n if (!event.target.files || event.target.files.length === 0) {\n return;\n }\n\n const files = Array.from(event.target.files).filter((file) => file.type.startsWith(\"image/\"));\n if (files.length === 0) return;\n\n const fileReadPromises = files.map((file) => {\n return new Promise<{ contentType: string; bytes: string }>((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = (e) => {\n const base64String = (e.target?.result as string)?.split(\",\")[1] || \"\";\n if (base64String) {\n resolve({\n contentType: file.type,\n bytes: base64String,\n });\n }\n };\n reader.onerror = reject;\n reader.readAsDataURL(file);\n });\n });\n\n try {\n const loadedImages = await Promise.all(fileReadPromises);\n setSelectedImages((prev) => [...prev, ...loadedImages]);\n } catch (error) {\n // Trigger chat-level error handler\n triggerChatError(error, \"processUploadedImages\", error);\n console.error(\"Error reading files:\", error);\n }\n };\n\n const removeSelectedImage = (index: number) => {\n setSelectedImages((prev) => prev.filter((_, i) => i !== index));\n };\n\n const handleThumbsUp = (message: Message) => {\n if (onThumbsUp) {\n onThumbsUp(message);\n }\n\n // Trigger feedback given event\n triggerObservabilityHook(\"onFeedbackGiven\", message.id, \"thumbsUp\");\n };\n\n const handleThumbsDown = (message: Message) => {\n if (onThumbsDown) {\n onThumbsDown(message);\n }\n\n // Trigger feedback given event\n triggerObservabilityHook(\"onFeedbackGiven\", message.id, \"thumbsDown\");\n };\n\n return (\n <WrappedCopilotChat icons={icons} labels={labels} className={className}>\n {/* Render error above messages if present */}\n {chatError &&\n renderError &&\n renderError({\n ...chatError,\n onDismiss: () => setChatError(null),\n onRetry: () => {\n // Clear error and potentially retry based on operation\n setChatError(null);\n // TODO: Implement specific retry logic based on operation type\n },\n })}\n\n <Messages\n AssistantMessage={AssistantMessage}\n UserMessage={UserMessage}\n RenderMessage={RenderMessage}\n messages={messages}\n inProgress={isLoading}\n onRegenerate={handleRegenerate}\n onCopy={handleCopy}\n onThumbsUp={handleThumbsUp}\n onThumbsDown={handleThumbsDown}\n markdownTagRenderers={markdownTagRenderers}\n ImageRenderer={ImageRenderer}\n ErrorMessage={ErrorMessage}\n chatError={chatError}\n // Legacy props - passed through to Messages component\n RenderTextMessage={RenderTextMessage}\n RenderActionExecutionMessage={RenderActionExecutionMessage}\n RenderAgentStateMessage={RenderAgentStateMessage}\n RenderResultMessage={RenderResultMessage}\n RenderImageMessage={RenderImageMessage}\n >\n {currentSuggestions.length > 0 && (\n <RenderSuggestionsList\n onSuggestionClick={handleSendMessage}\n suggestions={currentSuggestions}\n />\n )}\n </Messages>\n\n {imageUploadsEnabled && (\n <>\n <ImageUploadQueue images={selectedImages} onRemoveImage={removeSelectedImage} />\n <input\n type=\"file\"\n multiple\n ref={fileInputRef}\n onChange={handleImageUpload}\n accept={inputFileAccept}\n style={{ display: \"none\" }}\n />\n </>\n )}\n <Input\n inProgress={isLoading}\n onSend={handleSendMessage}\n isVisible={isVisible}\n onStop={stopGeneration}\n onUpload={imageUploadsEnabled ? () => fileInputRef.current?.click() : undefined}\n hideStopButton={hideStopButton}\n />\n </WrappedCopilotChat>\n );\n}\n\nexport function WrappedCopilotChat({\n children,\n icons,\n labels,\n className,\n}: {\n children: React.ReactNode;\n icons?: CopilotChatIcons;\n labels?: CopilotChatLabels;\n className?: string;\n}) {\n const chatContext = React.useContext(ChatContext);\n if (!chatContext) {\n return (\n <ChatContextProvider icons={icons} labels={labels} open={true} setOpen={() => {}}>\n <div className={`copilotKitChat ${className ?? \"\"}`}>{children}</div>\n </ChatContextProvider>\n );\n }\n return <>{children}</>;\n}\n\nexport const useCopilotChatLogic = (\n chatSuggestions: ChatSuggestions,\n makeSystemMessage?: SystemMessageFunction,\n disableSystemMessage?: boolean,\n onInProgress?: (isLoading: boolean) => void,\n onSubmitMessage?: (messageContent: string) => Promise<void> | void,\n onStopGeneration?: OnStopGeneration,\n onReloadMessages?: OnReloadMessages,\n) => {\n const {\n messages,\n sendMessage,\n setMessages,\n reloadMessages: defaultReloadMessages,\n stopGeneration: defaultStopGeneration,\n runChatCompletion,\n isLoading,\n suggestions,\n setSuggestions,\n generateSuggestions,\n resetSuggestions: resetSuggestionsFromHook,\n isLoadingSuggestions,\n } = useCopilotChat({\n makeSystemMessage,\n disableSystemMessage,\n });\n\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n\n // Get actions from context for message conversion\n const { actions } = generalContext;\n\n // Suggestion state management\n const [suggestionsFailed, setSuggestionsFailed] = useState(false);\n const hasGeneratedInitialSuggestions = useRef<boolean>(false);\n\n // Handle static suggestions (when suggestions prop is an array)\n useEffect(() => {\n if (Array.isArray(chatSuggestions)) {\n setSuggestions(chatSuggestions);\n hasGeneratedInitialSuggestions.current = true;\n }\n }, [JSON.stringify(chatSuggestions), setSuggestions]);\n\n // Error handling wrapper\n const generateSuggestionsWithErrorHandling = useCallback(\n async (context: string) => {\n try {\n await generateSuggestions();\n } catch (error) {\n console.error(\"Failed to generate suggestions:\", error);\n setSuggestionsFailed(true);\n }\n },\n [generateSuggestions],\n );\n\n // Automatic suggestion generation logic\n useEffect(() => {\n // Only proceed if in auto mode, not currently loading, and not failed\n if (chatSuggestions !== \"auto\" || isLoadingSuggestions || suggestionsFailed) {\n return;\n }\n\n // Don't run during chat loading (when the assistant is responding)\n if (isLoading) {\n return;\n }\n\n // Check if we have any configurations\n if (Object.keys(generalContext.chatSuggestionConfiguration).length === 0) {\n return;\n }\n\n // Generate initial suggestions when chat is empty\n if (messages.length === 0 && !hasGeneratedInitialSuggestions.current) {\n hasGeneratedInitialSuggestions.current = true;\n generateSuggestionsWithErrorHandling(\"initial\");\n return;\n }\n\n // Generate post-message suggestions after assistant responds\n if (messages.length > 0 && suggestions.length === 0) {\n generateSuggestionsWithErrorHandling(\"post-message\");\n return;\n }\n }, [\n chatSuggestions,\n isLoadingSuggestions,\n suggestionsFailed,\n messages.length,\n isLoading,\n suggestions.length,\n Object.keys(generalContext.chatSuggestionConfiguration).join(\",\"), // Use stable string instead of object reference\n generateSuggestionsWithErrorHandling,\n ]);\n\n // Reset suggestion state when switching away from auto mode\n useEffect(() => {\n if (chatSuggestions !== \"auto\") {\n hasGeneratedInitialSuggestions.current = false;\n setSuggestionsFailed(false);\n }\n }, [chatSuggestions]);\n\n // Memoize context to prevent infinite re-renders\n const stableContext = useMemo(\n () => ({\n ...generalContext,\n ...messagesContext,\n }),\n [\n // Only include stable dependencies\n generalContext.actions,\n messagesContext.messages.length,\n generalContext.isLoading,\n ],\n );\n\n // Wrapper for resetSuggestions that also resets local state\n const resetSuggestions = useCallback(() => {\n resetSuggestionsFromHook();\n setSuggestionsFailed(false);\n hasGeneratedInitialSuggestions.current = false;\n }, [resetSuggestionsFromHook]);\n\n useEffect(() => {\n onInProgress?.(isLoading);\n }, [onInProgress, isLoading]);\n\n const safelySendMessage = async (\n messageContent: string,\n imagesToUse?: Array<{ contentType: string; bytes: string }>,\n ) => {\n const images = imagesToUse || [];\n\n // Clear existing suggestions when user sends a message\n // This prevents stale suggestions from remaining visible during new conversation flow\n if (chatSuggestions === \"auto\" || chatSuggestions === \"manual\") {\n setSuggestions([]);\n }\n\n let firstMessage: Message | null = null;\n\n // Send text message if content provided\n if (messageContent.trim().length > 0) {\n const textMessage: Message = {\n id: randomId(),\n role: \"user\",\n content: messageContent,\n };\n\n // Call user-provided submit handler if available\n if (onSubmitMessage) {\n try {\n await onSubmitMessage(messageContent);\n } catch (error) {\n console.error(\"Error in onSubmitMessage:\", error);\n }\n }\n\n // Send the message and clear suggestions for auto/manual modes\n await sendMessage(textMessage, {\n followUp: images.length === 0,\n clearSuggestions: chatSuggestions === \"auto\" || chatSuggestions === \"manual\",\n });\n\n if (!firstMessage) {\n firstMessage = textMessage;\n }\n }\n\n // Send image messages\n if (images.length > 0) {\n for (let i = 0; i < images.length; i++) {\n const imageMessage = {\n id: randomId(),\n role: \"user\" as const,\n image: {\n format: images[i].contentType.replace(\"image/\", \"\"),\n bytes: images[i].bytes,\n },\n } as unknown as Message;\n await sendMessage(imageMessage, { followUp: i === images.length - 1 });\n if (!firstMessage) {\n firstMessage = imageMessage;\n }\n }\n }\n\n if (!firstMessage) {\n // Should not happen if send button is properly disabled, but handle just in case\n return { role: \"user\", content: \"\", id: randomId() } as Message; // Return a dummy message\n }\n\n // The hook implicitly triggers API call on appendMessage.\n // We return the first message sent (either text or first image)\n return firstMessage;\n };\n\n const currentAgentName = generalContext.agentSession?.agentName;\n const restartCurrentAgent = async (hint?: HintFunction) => {\n if (generalContext.agentSession) {\n generalContext.setAgentSession({\n ...generalContext.agentSession,\n nodeName: undefined,\n threadId: undefined,\n });\n generalContext.setCoagentStates((prevAgentStates) => {\n return {\n ...prevAgentStates,\n [generalContext.agentSession!.agentName]: {\n ...prevAgentStates[generalContext.agentSession!.agentName],\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n },\n };\n });\n }\n };\n const runCurrentAgent = async (hint?: HintFunction) => {\n if (generalContext.agentSession) {\n await runAgent(\n generalContext.agentSession.agentName,\n stableContext,\n messagesContext.messages,\n sendMessage,\n runChatCompletion,\n );\n }\n };\n const stopCurrentAgent = () => {\n if (generalContext.agentSession) {\n stopAgent(generalContext.agentSession.agentName, stableContext);\n }\n };\n const setCurrentAgentState = (state: any) => {\n if (generalContext.agentSession) {\n generalContext.setCoagentStates((prevAgentStates) => {\n return {\n ...prevAgentStates,\n [generalContext.agentSession!.agentName]: {\n state,\n },\n } as any;\n });\n }\n };\n\n function stopGeneration() {\n // Clear suggestions when stopping generation\n setSuggestions([]);\n\n if (onStopGeneration) {\n onStopGeneration({\n messages: messages,\n setMessages,\n stopGeneration: defaultStopGeneration,\n currentAgentName,\n restartCurrentAgent,\n stopCurrentAgent,\n runCurrentAgent,\n setCurrentAgentState,\n });\n } else {\n defaultStopGeneration();\n }\n }\n function reloadMessages(messageId: string) {\n if (onReloadMessages) {\n onReloadMessages({\n messages: messages,\n setMessages,\n stopGeneration: defaultStopGeneration,\n currentAgentName,\n restartCurrentAgent,\n stopCurrentAgent,\n runCurrentAgent,\n setCurrentAgentState,\n messageId,\n });\n } else {\n defaultReloadMessages(messageId);\n }\n }\n\n return {\n messages,\n isLoading,\n suggestions,\n sendMessage: safelySendMessage,\n stopGeneration,\n reloadMessages,\n resetSuggestions,\n context: stableContext,\n actions,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,OAAO,SAAS,WAAW,QAAQ,UAAU,aAAa,eAAe;AACzE;AAAA,EAEE,0BAA0B;AAAA,EAC1B;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;A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4BAAsB;AAAA,IACxB;AAAA,EACF;AACA,WAAS,eAAe,WAAmB;AACzC,QAAI,kBAAkB;AACpB,uBAAiB;AAAA,QACf;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,QAChB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AACL,4BAAsB,SAAS;AAAA,IACjC;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AACF;","names":["Messages","RenderMessage","Input","AssistantMessage","UserMessage","ImageRenderer","e","_a","_b"]}
@@ -1242,7 +1242,7 @@ var Messages = ({
1242
1242
  RenderMessage: RenderMessage2,
1243
1243
  AssistantMessage: AssistantMessage2,
1244
1244
  UserMessage: UserMessage2,
1245
- ErrorMessage: ErrorMessage2,
1245
+ ErrorMessage,
1246
1246
  ImageRenderer: ImageRenderer2,
1247
1247
  onRegenerate,
1248
1248
  onCopy,
@@ -1311,7 +1311,7 @@ var Messages = ({
1311
1311
  );
1312
1312
  }),
1313
1313
  interrupt,
1314
- chatError && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ErrorMessage2, { error: chatError, isCurrentMessage: true })
1314
+ chatError && ErrorMessage && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ErrorMessage, { error: chatError, isCurrentMessage: true })
1315
1315
  ] }),
1316
1316
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("footer", { className: "copilotKitMessagesFooter", ref: messagesEndRef, children })
1317
1317
  ] });
@@ -1694,67 +1694,15 @@ var Input = ({
1694
1694
  ] });
1695
1695
  };
1696
1696
 
1697
- // src/components/chat/messages/ErrorMessage.tsx
1698
- var import_react10 = require("react");
1699
- var import_jsx_runtime14 = require("react/jsx-runtime");
1700
- var ErrorMessage = (props) => {
1701
- const { icons, labels } = useChatContext();
1702
- const { error, onRegenerate, onCopy, isCurrentMessage } = props;
1703
- const [copied, setCopied] = (0, import_react10.useState)(false);
1704
- const handleCopy = () => {
1705
- const content = error.message;
1706
- if (content && onCopy) {
1707
- navigator.clipboard.writeText(content);
1708
- setCopied(true);
1709
- onCopy(content);
1710
- setTimeout(() => setCopied(false), 2e3);
1711
- } else if (content) {
1712
- navigator.clipboard.writeText(content);
1713
- setCopied(true);
1714
- setTimeout(() => setCopied(false), 2e3);
1715
- }
1716
- };
1717
- const handleRegenerate = () => {
1718
- if (onRegenerate)
1719
- onRegenerate();
1720
- };
1721
- console.log(error);
1722
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
1723
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Markdown, { content: error.message }),
1724
- /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: `copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`, children: [
1725
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1726
- "button",
1727
- {
1728
- className: "copilotKitMessageControlButton",
1729
- onClick: handleRegenerate,
1730
- "aria-label": labels.regenerateResponse,
1731
- title: labels.regenerateResponse,
1732
- children: icons.regenerateIcon
1733
- }
1734
- ),
1735
- /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1736
- "button",
1737
- {
1738
- className: "copilotKitMessageControlButton",
1739
- onClick: handleCopy,
1740
- "aria-label": labels.copyToClipboard,
1741
- title: labels.copyToClipboard,
1742
- children: copied ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { style: { fontSize: "10px", fontWeight: "bold" }, children: "\u2713" }) : icons.copyIcon
1743
- }
1744
- )
1745
- ] })
1746
- ] });
1747
- };
1748
-
1749
1697
  // src/components/chat/Chat.tsx
1750
- var import_react11 = __toESM(require("react"));
1698
+ var import_react10 = __toESM(require("react"));
1751
1699
  var import_react_core5 = require("@copilotkit/react-core");
1752
1700
  var import_shared = require("@copilotkit/shared");
1753
1701
  var import_shared2 = require("@copilotkit/shared");
1754
1702
  var import_react_core6 = require("@copilotkit/react-core");
1755
1703
 
1756
1704
  // src/components/chat/ImageUploadQueue.tsx
1757
- var import_jsx_runtime15 = require("react/jsx-runtime");
1705
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1758
1706
  var ImageUploadQueue = ({
1759
1707
  images,
1760
1708
  onRemoveImage,
@@ -1762,7 +1710,7 @@ var ImageUploadQueue = ({
1762
1710
  }) => {
1763
1711
  if (images.length === 0)
1764
1712
  return null;
1765
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1713
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1766
1714
  "div",
1767
1715
  {
1768
1716
  className: `copilotKitImageUploadQueue ${className}`,
@@ -1773,7 +1721,7 @@ var ImageUploadQueue = ({
1773
1721
  margin: "8px",
1774
1722
  padding: "8px"
1775
1723
  },
1776
- children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1724
+ children: images.map((image, index) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
1777
1725
  "div",
1778
1726
  {
1779
1727
  className: "copilotKitImageUploadQueueItem",
@@ -1786,7 +1734,7 @@ var ImageUploadQueue = ({
1786
1734
  overflow: "hidden"
1787
1735
  },
1788
1736
  children: [
1789
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1737
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1790
1738
  "img",
1791
1739
  {
1792
1740
  src: `data:${image.contentType};base64,${image.bytes}`,
@@ -1798,7 +1746,7 @@ var ImageUploadQueue = ({
1798
1746
  }
1799
1747
  }
1800
1748
  ),
1801
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1749
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1802
1750
  "button",
1803
1751
  {
1804
1752
  onClick: () => onRemoveImage(index),
@@ -1833,12 +1781,12 @@ var ImageUploadQueue = ({
1833
1781
 
1834
1782
  // src/components/chat/Suggestion.tsx
1835
1783
  var import_react_core4 = require("@copilotkit/react-core");
1836
- var import_jsx_runtime16 = require("react/jsx-runtime");
1784
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1837
1785
  function Suggestion({ title, onClick, partial, className }) {
1838
1786
  if (!title)
1839
1787
  return null;
1840
1788
  const { isLoading } = (0, import_react_core4.useCopilotChatInternal)();
1841
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1789
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1842
1790
  "button",
1843
1791
  {
1844
1792
  disabled: partial || isLoading,
@@ -1848,15 +1796,15 @@ function Suggestion({ title, onClick, partial, className }) {
1848
1796
  },
1849
1797
  className: className || (partial ? "suggestion loading" : "suggestion"),
1850
1798
  "data-test-id": "suggestion",
1851
- children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { children: title })
1799
+ children: partial ? SmallSpinnerIcon : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: title })
1852
1800
  }
1853
1801
  );
1854
1802
  }
1855
1803
 
1856
1804
  // src/components/chat/Suggestions.tsx
1857
- var import_jsx_runtime17 = require("react/jsx-runtime");
1805
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1858
1806
  function Suggestions({ suggestions, onSuggestionClick }) {
1859
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "suggestions", children: suggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1807
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "suggestions", children: suggestions.map((suggestion, index) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1860
1808
  Suggestion,
1861
1809
  {
1862
1810
  title: suggestion.title,
@@ -1870,7 +1818,7 @@ function Suggestions({ suggestions, onSuggestionClick }) {
1870
1818
  }
1871
1819
 
1872
1820
  // src/components/chat/Chat.tsx
1873
- var import_jsx_runtime18 = require("react/jsx-runtime");
1821
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1874
1822
  function CopilotChat({
1875
1823
  instructions,
1876
1824
  suggestions = "auto",
@@ -1895,7 +1843,7 @@ function CopilotChat({
1895
1843
  AssistantMessage: AssistantMessage2 = AssistantMessage,
1896
1844
  UserMessage: UserMessage2 = UserMessage,
1897
1845
  ImageRenderer: ImageRenderer2 = ImageRenderer,
1898
- ErrorMessage: ErrorMessage2 = ErrorMessage,
1846
+ ErrorMessage,
1899
1847
  imageUploadsEnabled,
1900
1848
  inputFileAccept = "image/*",
1901
1849
  hideStopButton,
@@ -1918,10 +1866,10 @@ function CopilotChat({
1918
1866
  removeInternalErrorHandler
1919
1867
  } = (0, import_react_core5.useCopilotContext)();
1920
1868
  const { publicApiKey, chatApiEndpoint } = copilotApiConfig;
1921
- const [selectedImages, setSelectedImages] = (0, import_react11.useState)([]);
1922
- const [chatError, setChatError] = (0, import_react11.useState)(null);
1923
- const fileInputRef = (0, import_react11.useRef)(null);
1924
- const triggerObservabilityHook = (0, import_react11.useCallback)(
1869
+ const [selectedImages, setSelectedImages] = (0, import_react10.useState)([]);
1870
+ const [chatError, setChatError] = (0, import_react10.useState)(null);
1871
+ const fileInputRef = (0, import_react10.useRef)(null);
1872
+ const triggerObservabilityHook = (0, import_react10.useCallback)(
1925
1873
  (hookName, ...args) => {
1926
1874
  if (publicApiKey && (observabilityHooks == null ? void 0 : observabilityHooks[hookName])) {
1927
1875
  observabilityHooks[hookName](...args);
@@ -1940,7 +1888,7 @@ function CopilotChat({
1940
1888
  },
1941
1889
  [publicApiKey, observabilityHooks, setBannerError]
1942
1890
  );
1943
- const triggerChatError = (0, import_react11.useCallback)(
1891
+ const triggerChatError = (0, import_react10.useCallback)(
1944
1892
  (error, operation, originalError) => {
1945
1893
  const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "An error occurred";
1946
1894
  setChatError({
@@ -1986,7 +1934,7 @@ function CopilotChat({
1986
1934
  },
1987
1935
  [publicApiKey, chatApiEndpoint, observabilityHooks, setBannerError]
1988
1936
  );
1989
- (0, import_react11.useEffect)(() => {
1937
+ (0, import_react10.useEffect)(() => {
1990
1938
  const id = "chat-component";
1991
1939
  setInternalErrorHandler({
1992
1940
  [id]: (error) => {
@@ -1999,7 +1947,7 @@ function CopilotChat({
1999
1947
  removeInternalErrorHandler == null ? void 0 : removeInternalErrorHandler(id);
2000
1948
  };
2001
1949
  }, [triggerChatError, setInternalErrorHandler, removeInternalErrorHandler]);
2002
- (0, import_react11.useEffect)(() => {
1950
+ (0, import_react10.useEffect)(() => {
2003
1951
  if (!imageUploadsEnabled)
2004
1952
  return;
2005
1953
  const handlePaste = (e) => __async(this, null, function* () {
@@ -2045,7 +1993,7 @@ function CopilotChat({
2045
1993
  document.addEventListener("paste", handlePaste);
2046
1994
  return () => document.removeEventListener("paste", handlePaste);
2047
1995
  }, [imageUploadsEnabled, triggerChatError]);
2048
- (0, import_react11.useEffect)(() => {
1996
+ (0, import_react10.useEffect)(() => {
2049
1997
  if (!(additionalInstructions == null ? void 0 : additionalInstructions.length)) {
2050
1998
  setChatInstructions(instructions || "");
2051
1999
  return;
@@ -2073,8 +2021,8 @@ function CopilotChat({
2073
2021
  onStopGeneration,
2074
2022
  onReloadMessages
2075
2023
  );
2076
- const prevIsLoading = (0, import_react11.useRef)(isLoading);
2077
- (0, import_react11.useEffect)(() => {
2024
+ const prevIsLoading = (0, import_react10.useRef)(isLoading);
2025
+ (0, import_react10.useEffect)(() => {
2078
2026
  if (prevIsLoading.current !== isLoading) {
2079
2027
  if (isLoading) {
2080
2028
  triggerObservabilityHook("onChatStarted");
@@ -2093,7 +2041,7 @@ function CopilotChat({
2093
2041
  triggerObservabilityHook("onMessageSent", text);
2094
2042
  return sendMessage(text, images);
2095
2043
  };
2096
- const chatContext = import_react11.default.useContext(ChatContext);
2044
+ const chatContext = import_react10.default.useContext(ChatContext);
2097
2045
  const isVisible = chatContext ? chatContext.open : true;
2098
2046
  const handleRegenerate = (messageId) => {
2099
2047
  if (onRegenerate) {
@@ -2155,14 +2103,14 @@ function CopilotChat({
2155
2103
  }
2156
2104
  triggerObservabilityHook("onFeedbackGiven", message.id, "thumbsDown");
2157
2105
  };
2158
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2106
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(WrappedCopilotChat, { icons, labels, className, children: [
2159
2107
  chatError && renderError && renderError(__spreadProps(__spreadValues({}, chatError), {
2160
2108
  onDismiss: () => setChatError(null),
2161
2109
  onRetry: () => {
2162
2110
  setChatError(null);
2163
2111
  }
2164
2112
  })),
2165
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2113
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2166
2114
  Messages2,
2167
2115
  {
2168
2116
  AssistantMessage: AssistantMessage2,
@@ -2176,14 +2124,14 @@ function CopilotChat({
2176
2124
  onThumbsDown: handleThumbsDown,
2177
2125
  markdownTagRenderers,
2178
2126
  ImageRenderer: ImageRenderer2,
2179
- ErrorMessage: ErrorMessage2,
2127
+ ErrorMessage,
2180
2128
  chatError,
2181
2129
  RenderTextMessage,
2182
2130
  RenderActionExecutionMessage,
2183
2131
  RenderAgentStateMessage,
2184
2132
  RenderResultMessage,
2185
2133
  RenderImageMessage,
2186
- children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2134
+ children: currentSuggestions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2187
2135
  RenderSuggestionsList,
2188
2136
  {
2189
2137
  onSuggestionClick: handleSendMessage,
@@ -2192,9 +2140,9 @@ function CopilotChat({
2192
2140
  )
2193
2141
  }
2194
2142
  ),
2195
- imageUploadsEnabled && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
2196
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ImageUploadQueue, { images: selectedImages, onRemoveImage: removeSelectedImage }),
2197
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2143
+ imageUploadsEnabled && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
2144
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ImageUploadQueue, { images: selectedImages, onRemoveImage: removeSelectedImage }),
2145
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2198
2146
  "input",
2199
2147
  {
2200
2148
  type: "file",
@@ -2206,7 +2154,7 @@ function CopilotChat({
2206
2154
  }
2207
2155
  )
2208
2156
  ] }),
2209
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2157
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2210
2158
  Input2,
2211
2159
  {
2212
2160
  inProgress: isLoading,
@@ -2228,12 +2176,12 @@ function WrappedCopilotChat({
2228
2176
  labels,
2229
2177
  className
2230
2178
  }) {
2231
- const chatContext = import_react11.default.useContext(ChatContext);
2179
+ const chatContext = import_react10.default.useContext(ChatContext);
2232
2180
  if (!chatContext) {
2233
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
2234
- }, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
2181
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ChatContextProvider, { icons, labels, open: true, setOpen: () => {
2182
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: `copilotKitChat ${className != null ? className : ""}`, children }) });
2235
2183
  }
2236
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_jsx_runtime18.Fragment, { children });
2184
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, { children });
2237
2185
  }
2238
2186
  var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMessage, onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) => {
2239
2187
  var _a;
@@ -2257,15 +2205,15 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
2257
2205
  const generalContext = (0, import_react_core5.useCopilotContext)();
2258
2206
  const messagesContext = (0, import_react_core5.useCopilotMessagesContext)();
2259
2207
  const { actions } = generalContext;
2260
- const [suggestionsFailed, setSuggestionsFailed] = (0, import_react11.useState)(false);
2261
- const hasGeneratedInitialSuggestions = (0, import_react11.useRef)(false);
2262
- (0, import_react11.useEffect)(() => {
2208
+ const [suggestionsFailed, setSuggestionsFailed] = (0, import_react10.useState)(false);
2209
+ const hasGeneratedInitialSuggestions = (0, import_react10.useRef)(false);
2210
+ (0, import_react10.useEffect)(() => {
2263
2211
  if (Array.isArray(chatSuggestions)) {
2264
2212
  setSuggestions(chatSuggestions);
2265
2213
  hasGeneratedInitialSuggestions.current = true;
2266
2214
  }
2267
2215
  }, [JSON.stringify(chatSuggestions), setSuggestions]);
2268
- const generateSuggestionsWithErrorHandling = (0, import_react11.useCallback)(
2216
+ const generateSuggestionsWithErrorHandling = (0, import_react10.useCallback)(
2269
2217
  (context) => __async(void 0, null, function* () {
2270
2218
  try {
2271
2219
  yield generateSuggestions();
@@ -2276,7 +2224,7 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
2276
2224
  }),
2277
2225
  [generateSuggestions]
2278
2226
  );
2279
- (0, import_react11.useEffect)(() => {
2227
+ (0, import_react10.useEffect)(() => {
2280
2228
  if (chatSuggestions !== "auto" || isLoadingSuggestions || suggestionsFailed) {
2281
2229
  return;
2282
2230
  }
@@ -2306,13 +2254,13 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
2306
2254
  // Use stable string instead of object reference
2307
2255
  generateSuggestionsWithErrorHandling
2308
2256
  ]);
2309
- (0, import_react11.useEffect)(() => {
2257
+ (0, import_react10.useEffect)(() => {
2310
2258
  if (chatSuggestions !== "auto") {
2311
2259
  hasGeneratedInitialSuggestions.current = false;
2312
2260
  setSuggestionsFailed(false);
2313
2261
  }
2314
2262
  }, [chatSuggestions]);
2315
- const stableContext = (0, import_react11.useMemo)(
2263
+ const stableContext = (0, import_react10.useMemo)(
2316
2264
  () => __spreadValues(__spreadValues({}, generalContext), messagesContext),
2317
2265
  [
2318
2266
  // Only include stable dependencies
@@ -2321,12 +2269,12 @@ var useCopilotChatLogic = (chatSuggestions, makeSystemMessage, disableSystemMess
2321
2269
  generalContext.isLoading
2322
2270
  ]
2323
2271
  );
2324
- const resetSuggestions = (0, import_react11.useCallback)(() => {
2272
+ const resetSuggestions = (0, import_react10.useCallback)(() => {
2325
2273
  resetSuggestionsFromHook();
2326
2274
  setSuggestionsFailed(false);
2327
2275
  hasGeneratedInitialSuggestions.current = false;
2328
2276
  }, [resetSuggestionsFromHook]);
2329
- (0, import_react11.useEffect)(() => {
2277
+ (0, import_react10.useEffect)(() => {
2330
2278
  onInProgress == null ? void 0 : onInProgress(isLoading);
2331
2279
  }, [onInProgress, isLoading]);
2332
2280
  const safelySendMessage = (messageContent, imagesToUse) => __async(void 0, null, function* () {