@copilotkit/react-core 1.55.3-canary.1776215089 → 1.55.3-canary.1776243725

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.
@@ -4865,11 +4865,8 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
4865
4865
  useKatexStyles();
4866
4866
  const boundMarkdownRenderer = renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
4867
4867
  const boundCopyButton = renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
4868
- if (message.content) try {
4869
- await navigator.clipboard.writeText(message.content);
4870
- } catch (err) {
4871
- console.error("Failed to copy message:", err);
4872
- }
4868
+ if (message.content) return await (0, _copilotkit_shared.copyToClipboard)(message.content);
4869
+ return false;
4873
4870
  } });
4874
4871
  const boundThumbsUpButton = renderSlot(thumbsUpButton, CopilotChatAssistantMessage.ThumbsUpButton, { onClick: onThumbsUp });
4875
4872
  const boundThumbsDownButton = renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown });
@@ -4967,14 +4964,17 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp,
4967
4964
  if (timerRef.current !== null) clearTimeout(timerRef.current);
4968
4965
  };
4969
4966
  }, []);
4970
- const handleClick = (event) => {
4971
- setCopied(true);
4972
- if (timerRef.current !== null) clearTimeout(timerRef.current);
4973
- timerRef.current = setTimeout(() => {
4974
- timerRef.current = null;
4975
- setCopied(false);
4976
- }, 2e3);
4977
- if (onClick) onClick(event);
4967
+ const handleClick = async (event) => {
4968
+ let success = false;
4969
+ if (onClick) success = await Promise.resolve(onClick(event)) === true;
4970
+ if (success) {
4971
+ setCopied(true);
4972
+ if (timerRef.current !== null) clearTimeout(timerRef.current);
4973
+ timerRef.current = setTimeout(() => {
4974
+ timerRef.current = null;
4975
+ setCopied(false);
4976
+ }, 2e3);
4977
+ }
4978
4978
  };
4979
4979
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
4980
4980
  "data-testid": "copilot-copy-button",
@@ -5127,11 +5127,8 @@ function CopilotChatUserMessage({ message, onEditMessage, branchIndex, numberOfB
5127
5127
  const mediaParts = (0, react.useMemo)(() => getMediaParts(message.content), [message.content]);
5128
5128
  const BoundMessageRenderer = renderSlot(messageRenderer, CopilotChatUserMessage.MessageRenderer, { content: flattenedContent });
5129
5129
  const BoundCopyButton = renderSlot(copyButton, CopilotChatUserMessage.CopyButton, { onClick: async () => {
5130
- if (flattenedContent) try {
5131
- await navigator.clipboard.writeText(flattenedContent);
5132
- } catch (err) {
5133
- console.error("Failed to copy message:", err);
5134
- }
5130
+ if (flattenedContent) return await (0, _copilotkit_shared.copyToClipboard)(flattenedContent);
5131
+ return false;
5135
5132
  } });
5136
5133
  const BoundEditButton = renderSlot(editButton, CopilotChatUserMessage.EditButton, { onClick: () => onEditMessage?.({ message }) });
5137
5134
  const BoundBranchNavigation = renderSlot(branchNavigation, CopilotChatUserMessage.BranchNavigation, {
@@ -5219,10 +5216,13 @@ function CopilotChatUserMessage({ message, onEditMessage, branchIndex, numberOfB
5219
5216
  _CopilotChatUserMessage.CopyButton = ({ className, title, onClick, ...props }) => {
5220
5217
  const labels = useCopilotChatConfiguration()?.labels ?? CopilotChatDefaultLabels;
5221
5218
  const [copied, setCopied] = (0, react.useState)(false);
5222
- const handleClick = (event) => {
5223
- setCopied(true);
5224
- setTimeout(() => setCopied(false), 2e3);
5225
- if (onClick) onClick(event);
5219
+ const handleClick = async (event) => {
5220
+ let success = false;
5221
+ if (onClick) success = await Promise.resolve(onClick(event)) === true;
5222
+ if (success) {
5223
+ setCopied(true);
5224
+ setTimeout(() => setCopied(false), 2e3);
5225
+ }
5226
5226
  };
5227
5227
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
5228
5228
  "data-testid": "copilot-user-copy-button",
@@ -5329,17 +5329,24 @@ function CopilotChatReasoningMessage({ message, messages, isRunning, header, con
5329
5329
  return () => clearInterval(timer);
5330
5330
  }, [isStreaming]);
5331
5331
  const [isOpen, setIsOpen] = (0, react.useState)(isStreaming);
5332
+ const userToggledRef = (0, react.useRef)(false);
5332
5333
  (0, react.useEffect)(() => {
5333
- if (isStreaming) setIsOpen(true);
5334
- else setIsOpen(false);
5334
+ if (isStreaming) {
5335
+ userToggledRef.current = false;
5336
+ setIsOpen(true);
5337
+ } else if (!userToggledRef.current) setIsOpen(false);
5335
5338
  }, [isStreaming]);
5339
+ const handleToggle = hasContent ? () => {
5340
+ userToggledRef.current = true;
5341
+ setIsOpen((prev) => !prev);
5342
+ } : void 0;
5336
5343
  const label = isStreaming ? "Thinking…" : `Thought for ${formatDuration(elapsed)}`;
5337
5344
  const boundHeader = renderSlot(header, CopilotChatReasoningMessage.Header, {
5338
5345
  isOpen,
5339
5346
  label,
5340
5347
  hasContent,
5341
5348
  isStreaming,
5342
- onClick: hasContent ? () => setIsOpen((prev) => !prev) : void 0
5349
+ onClick: handleToggle
5343
5350
  });
5344
5351
  const boundContent = renderSlot(contentView, CopilotChatReasoningMessage.Content, {
5345
5352
  isStreaming,
@@ -8043,6 +8050,20 @@ function shouldShowDevConsole(showDevConsole) {
8043
8050
  /**
8044
8051
  * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context
8045
8052
  */
8053
+ /**
8054
+ * Determine whether a GraphQL error should be suppressed based on its visibility
8055
+ * and whether the dev console is active.
8056
+ *
8057
+ * Returns `null` when the error should be surfaced to the UI, or a log prefix
8058
+ * string when the error should be suppressed (logged to console only).
8059
+ *
8060
+ * Exported for unit testing.
8061
+ */
8062
+ function getErrorSuppression(visibility, isDev) {
8063
+ if (visibility === _copilotkit_shared.ErrorVisibility.SILENT) return "CopilotKit Silent Error:";
8064
+ if (!isDev && visibility === _copilotkit_shared.ErrorVisibility.DEV_ONLY) return "CopilotKit Error (hidden in production):";
8065
+ return null;
8066
+ }
8046
8067
  const MessagesTapContext = (0, react.createContext)(null);
8047
8068
  function useMessagesTap() {
8048
8069
  const tap = (0, react.useContext)(MessagesTapContext);
@@ -8126,12 +8147,9 @@ function CopilotMessages({ children }) {
8126
8147
  const graphQLErrors = error.graphQLErrors;
8127
8148
  const routeError = (gqlError) => {
8128
8149
  const visibility = gqlError.extensions?.visibility;
8129
- if (!shouldShowDevConsole(showDevConsole)) {
8130
- console.error("CopilotKit Error (hidden in production):", gqlError.message);
8131
- return;
8132
- }
8133
- if (visibility === _copilotkit_shared.ErrorVisibility.SILENT) {
8134
- console.error("CopilotKit Silent Error:", gqlError.message);
8150
+ const suppression = getErrorSuppression(visibility, shouldShowDevConsole(showDevConsole));
8151
+ if (suppression) {
8152
+ console.error(suppression, gqlError.message);
8135
8153
  return;
8136
8154
  }
8137
8155
  const ckError = createStructuredError(gqlError);
@@ -8148,8 +8166,7 @@ function CopilotMessages({ children }) {
8148
8166
  }
8149
8167
  };
8150
8168
  graphQLErrors.forEach(routeError);
8151
- } else if (!shouldShowDevConsole(showDevConsole)) console.error("CopilotKit Error (hidden in production):", error);
8152
- else {
8169
+ } else {
8153
8170
  const fallbackError = new _copilotkit_shared.CopilotKitError({
8154
8171
  message: error?.message || String(error),
8155
8172
  code: _copilotkit_shared.CopilotKitErrorCode.UNKNOWN
@@ -9982,4 +9999,4 @@ Object.defineProperty(exports, 'useToast', {
9982
9999
  return useToast;
9983
10000
  }
9984
10001
  });
9985
- //# sourceMappingURL=copilotkit-BZuXjQLc.cjs.map
10002
+ //# sourceMappingURL=copilotkit-BoOnQHlE.cjs.map