@copilotkit/react-ui 1.56.0 → 1.56.2

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,
@@ -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
  });
@@ -1653,7 +1655,7 @@ rehype_raw = __toESM(rehype_raw);
1653
1655
  //#endregion
1654
1656
  //#region src/components/chat/Messages.tsx
1655
1657
  const Messages = ({ inProgress, children, RenderMessage, AssistantMessage, UserMessage, ErrorMessage, ImageRenderer, onRegenerate, onCopy, onThumbsUp, onThumbsDown, messageFeedback, markdownTagRenderers, chatError, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, RenderImageMessage }) => {
1656
- var _messages;
1658
+ var _messages, _messages2;
1657
1659
  const { labels, icons } = useChatContext();
1658
1660
  const { messages: visibleMessages, interrupt } = (0, _copilotkit_react_core.useCopilotChatInternal)();
1659
1661
  const messages = [...(0, react.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]), ...visibleMessages];
@@ -1704,7 +1706,7 @@ rehype_raw = __toESM(rehype_raw);
1704
1706
  markdownTagRenderers
1705
1707
  }, index);
1706
1708
  }),
1707
- ((_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, {}),
1708
1710
  interrupt,
1709
1711
  chatError && ErrorMessage && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
1710
1712
  error: chatError,
@@ -1843,13 +1845,18 @@ rehype_raw = __toESM(rehype_raw);
1843
1845
  };
1844
1846
  mediaRecorderRef.current.onstop = onStop;
1845
1847
  };
1846
- const stopRecording = (mediaRecorderRef) => {
1848
+ const stopRecording = (mediaRecorderRef, mediaStreamRef) => {
1847
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
+ }
1848
1854
  };
1849
- const transcribeAudio = async (recordedChunks, transcribeAudioUrl) => {
1850
- 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 });
1851
1858
  const formData = new FormData();
1852
- formData.append("file", completeBlob, "recording.mp4");
1859
+ formData.append("file", completeBlob, `recording.${extension}`);
1853
1860
  const response = await fetch(transcribeAudioUrl, {
1854
1861
  method: "POST",
1855
1862
  body: formData
@@ -1868,7 +1875,7 @@ rehype_raw = __toESM(rehype_raw);
1868
1875
  console.error("Error with decoding audio data", error);
1869
1876
  });
1870
1877
  };
1871
- const usePushToTalk = ({ sendFunction, inProgress }) => {
1878
+ const usePushToTalk = ({ sendFunction, inProgress, mediaType = "audio/mp4" }) => {
1872
1879
  const [pushToTalkState, setPushToTalkState] = (0, react.useState)("idle");
1873
1880
  const mediaStreamRef = (0, react.useRef)(null);
1874
1881
  const audioContextRef = (0, react.useRef)(null);
@@ -1886,15 +1893,16 @@ rehype_raw = __toESM(rehype_raw);
1886
1893
  setPushToTalkState("transcribing");
1887
1894
  });
1888
1895
  else {
1889
- stopRecording(mediaRecorderRef);
1890
- 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) => {
1891
1898
  recordedChunks.current = [];
1892
1899
  setPushToTalkState("idle");
1893
- setStartReadingFromMessageId((await sendFunction(transcription)).id);
1900
+ const message = await sendFunction(transcription);
1901
+ if (message) setStartReadingFromMessageId(message.id);
1894
1902
  });
1895
1903
  }
1896
1904
  return () => {
1897
- stopRecording(mediaRecorderRef);
1905
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1898
1906
  };
1899
1907
  }, [pushToTalkState]);
1900
1908
  (0, react.useEffect)(() => {
@@ -2990,6 +2998,7 @@ rehype_raw = __toESM(rehype_raw);
2990
2998
  exports.AssistantMessage = AssistantMessage;
2991
2999
  exports.CopilotChat = CopilotChat;
2992
3000
  exports.CopilotDevConsole = CopilotDevConsole;
3001
+ exports.CopilotModal = CopilotModal;
2993
3002
  exports.CopilotPopup = CopilotPopup;
2994
3003
  exports.CopilotSidebar = CopilotSidebar;
2995
3004
  exports.ImageRenderer = ImageRenderer;