@copilotkit/react-ui 1.55.3 → 1.56.1

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.umd.js CHANGED
@@ -789,10 +789,11 @@ rehype_raw = __toESM(rehype_raw);
789
789
  });
790
790
  };
791
791
  (0, react.useEffect)(() => {
792
+ if (!showDevConsole) return;
792
793
  if (dontRunTwiceInDevMode.current === true) return;
793
794
  dontRunTwiceInDevMode.current = true;
794
795
  checkForUpdates();
795
- }, []);
796
+ }, [showDevConsole]);
796
797
  if (!showDevConsole) return null;
797
798
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
798
799
  ref: consoleRef,
@@ -834,11 +835,11 @@ rehype_raw = __toESM(rehype_raw);
834
835
  `@copilotkit/react-textarea@${latestVersion}`,
835
836
  `&& npm install @copilotkit/runtime@${latestVersion}`
836
837
  ].join(" ");
837
- const handleCopyClick = () => {
838
- navigator.clipboard.writeText(installCommand.trim()).then(() => {
838
+ const handleCopyClick = async () => {
839
+ if (await (0, _copilotkit_shared.copyToClipboard)(installCommand.trim())) {
839
840
  setCopyStatus("Command copied to clipboard!");
840
841
  setTimeout(() => setCopyStatus(""), 1e3);
841
- });
842
+ }
842
843
  };
843
844
  if (versionStatus === "update-available" || versionStatus === "outdated") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
844
845
  className: "copilotKitVersionInfo",
@@ -1336,7 +1337,7 @@ rehype_raw = __toESM(rehype_raw);
1336
1337
  language: match && match[1] || "",
1337
1338
  value: String(children).replace(/\n$/, ""),
1338
1339
  ...props
1339
- }, Math.random());
1340
+ });
1340
1341
  },
1341
1342
  h1: ({ children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", {
1342
1343
  className: "copilotKitMarkdownElement",
@@ -1368,8 +1369,8 @@ rehype_raw = __toESM(rehype_raw);
1368
1369
  ...props,
1369
1370
  children
1370
1371
  }),
1371
- p: ({ children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1372
- className: "copilotKitMarkdownElement",
1372
+ p: ({ children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1373
+ className: "copilotKitMarkdownElement copilotKitParagraph",
1373
1374
  ...props,
1374
1375
  children
1375
1376
  }),
@@ -1394,8 +1395,8 @@ rehype_raw = __toESM(rehype_raw);
1394
1395
  children
1395
1396
  })
1396
1397
  };
1397
- const MemoizedReactMarkdown = (0, react.memo)(react_markdown.default, (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components);
1398
- const Markdown = ({ content, components }) => {
1398
+ const MemoizedReactMarkdown = (0, react.memo)(react_markdown.default, (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components && prevProps.urlTransform === nextProps.urlTransform);
1399
+ const Markdown = ({ content, components, urlTransform }) => {
1399
1400
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1400
1401
  className: "copilotKitMarkdown",
1401
1402
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedReactMarkdown, {
@@ -1405,6 +1406,7 @@ rehype_raw = __toESM(rehype_raw);
1405
1406
  }), [components]),
1406
1407
  remarkPlugins: [remark_gfm.default, [remark_math.default, { singleDollarTextMath: false }]],
1407
1408
  rehypePlugins: [rehype_raw.default],
1409
+ ...urlTransform !== void 0 ? { urlTransform } : {},
1408
1410
  children: content
1409
1411
  })
1410
1412
  });
@@ -1417,16 +1419,12 @@ rehype_raw = __toESM(rehype_raw);
1417
1419
  const { icons, labels } = useChatContext();
1418
1420
  const { message, isLoading, onRegenerate, onCopy, onThumbsUp, onThumbsDown, isCurrentMessage, feedback, markdownTagRenderers } = props;
1419
1421
  const [copied, setCopied] = (0, react.useState)(false);
1420
- const handleCopy = () => {
1422
+ const handleCopy = async () => {
1421
1423
  const content = (message === null || message === void 0 ? void 0 : message.content) || "";
1422
- if (content && onCopy) {
1423
- navigator.clipboard.writeText(content);
1424
- setCopied(true);
1425
- onCopy(content);
1426
- setTimeout(() => setCopied(false), 2e3);
1427
- } else if (content) {
1428
- navigator.clipboard.writeText(content);
1424
+ if (!content) return;
1425
+ if (await (0, _copilotkit_shared.copyToClipboard)(content)) {
1429
1426
  setCopied(true);
1427
+ if (onCopy) onCopy(content);
1430
1428
  setTimeout(() => setCopied(false), 2e3);
1431
1429
  }
1432
1430
  };
@@ -1657,7 +1655,7 @@ rehype_raw = __toESM(rehype_raw);
1657
1655
  //#endregion
1658
1656
  //#region src/components/chat/Messages.tsx
1659
1657
  const Messages = ({ inProgress, children, RenderMessage, AssistantMessage, UserMessage, ErrorMessage, ImageRenderer, onRegenerate, onCopy, onThumbsUp, onThumbsDown, messageFeedback, markdownTagRenderers, chatError, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, RenderImageMessage }) => {
1660
- var _messages;
1658
+ var _messages, _messages2;
1661
1659
  const { labels, icons } = useChatContext();
1662
1660
  const { messages: visibleMessages, interrupt } = (0, _copilotkit_react_core.useCopilotChatInternal)();
1663
1661
  const messages = [...(0, react.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]), ...visibleMessages];
@@ -1708,7 +1706,7 @@ rehype_raw = __toESM(rehype_raw);
1708
1706
  markdownTagRenderers
1709
1707
  }, index);
1710
1708
  }),
1711
- ((_messages = messages[messages.length - 1]) === null || _messages === void 0 ? void 0 : _messages.role) === "user" && inProgress && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingIcon, {}),
1709
+ inProgress && (((_messages = messages[messages.length - 1]) === null || _messages === void 0 ? void 0 : _messages.role) === "user" || ((_messages2 = messages[messages.length - 1]) === null || _messages2 === void 0 ? void 0 : _messages2.role) === "tool") && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingIcon, {}),
1712
1710
  interrupt,
1713
1711
  chatError && ErrorMessage && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
1714
1712
  error: chatError,
@@ -1847,13 +1845,18 @@ rehype_raw = __toESM(rehype_raw);
1847
1845
  };
1848
1846
  mediaRecorderRef.current.onstop = onStop;
1849
1847
  };
1850
- const stopRecording = (mediaRecorderRef) => {
1848
+ const stopRecording = (mediaRecorderRef, mediaStreamRef) => {
1851
1849
  if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") mediaRecorderRef.current.stop();
1850
+ if (mediaStreamRef === null || mediaStreamRef === void 0 ? void 0 : mediaStreamRef.current) {
1851
+ mediaStreamRef.current.getTracks().forEach((track) => track.stop());
1852
+ mediaStreamRef.current = null;
1853
+ }
1852
1854
  };
1853
- const transcribeAudio = async (recordedChunks, transcribeAudioUrl) => {
1854
- const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
1855
+ const transcribeAudio = async (recordedChunks, transcribeAudioUrl, mediaType = "audio/mp4") => {
1856
+ const extension = mediaType.split("/")[1] || "mp4";
1857
+ const completeBlob = new Blob(recordedChunks, { type: mediaType });
1855
1858
  const formData = new FormData();
1856
- formData.append("file", completeBlob, "recording.mp4");
1859
+ formData.append("file", completeBlob, `recording.${extension}`);
1857
1860
  const response = await fetch(transcribeAudioUrl, {
1858
1861
  method: "POST",
1859
1862
  body: formData
@@ -1872,7 +1875,7 @@ rehype_raw = __toESM(rehype_raw);
1872
1875
  console.error("Error with decoding audio data", error);
1873
1876
  });
1874
1877
  };
1875
- const usePushToTalk = ({ sendFunction, inProgress }) => {
1878
+ const usePushToTalk = ({ sendFunction, inProgress, mediaType = "audio/mp4" }) => {
1876
1879
  const [pushToTalkState, setPushToTalkState] = (0, react.useState)("idle");
1877
1880
  const mediaStreamRef = (0, react.useRef)(null);
1878
1881
  const audioContextRef = (0, react.useRef)(null);
@@ -1890,15 +1893,16 @@ rehype_raw = __toESM(rehype_raw);
1890
1893
  setPushToTalkState("transcribing");
1891
1894
  });
1892
1895
  else {
1893
- stopRecording(mediaRecorderRef);
1894
- if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(async (transcription) => {
1896
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1897
+ if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl, mediaType).then(async (transcription) => {
1895
1898
  recordedChunks.current = [];
1896
1899
  setPushToTalkState("idle");
1897
- setStartReadingFromMessageId((await sendFunction(transcription)).id);
1900
+ const message = await sendFunction(transcription);
1901
+ if (message) setStartReadingFromMessageId(message.id);
1898
1902
  });
1899
1903
  }
1900
1904
  return () => {
1901
- stopRecording(mediaRecorderRef);
1905
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1902
1906
  };
1903
1907
  }, [pushToTalkState]);
1904
1908
  (0, react.useEffect)(() => {
@@ -2994,6 +2998,7 @@ rehype_raw = __toESM(rehype_raw);
2994
2998
  exports.AssistantMessage = AssistantMessage;
2995
2999
  exports.CopilotChat = CopilotChat;
2996
3000
  exports.CopilotDevConsole = CopilotDevConsole;
3001
+ exports.CopilotModal = CopilotModal;
2997
3002
  exports.CopilotPopup = CopilotPopup;
2998
3003
  exports.CopilotSidebar = CopilotSidebar;
2999
3004
  exports.ImageRenderer = ImageRenderer;