@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.cjs CHANGED
@@ -793,10 +793,11 @@ function CopilotDevConsole() {
793
793
  });
794
794
  };
795
795
  (0, react.useEffect)(() => {
796
+ if (!showDevConsole) return;
796
797
  if (dontRunTwiceInDevMode.current === true) return;
797
798
  dontRunTwiceInDevMode.current = true;
798
799
  checkForUpdates();
799
- }, []);
800
+ }, [showDevConsole]);
800
801
  if (!showDevConsole) return null;
801
802
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
802
803
  ref: consoleRef,
@@ -1396,8 +1397,8 @@ const defaultComponents = {
1396
1397
  children
1397
1398
  })
1398
1399
  };
1399
- const MemoizedReactMarkdown = (0, react.memo)(react_markdown.default, (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components);
1400
- const Markdown = ({ content, components }) => {
1400
+ const MemoizedReactMarkdown = (0, react.memo)(react_markdown.default, (prevProps, nextProps) => prevProps.children === nextProps.children && prevProps.components === nextProps.components && prevProps.urlTransform === nextProps.urlTransform);
1401
+ const Markdown = ({ content, components, urlTransform }) => {
1401
1402
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1402
1403
  className: "copilotKitMarkdown",
1403
1404
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedReactMarkdown, {
@@ -1407,6 +1408,7 @@ const Markdown = ({ content, components }) => {
1407
1408
  }), [components]),
1408
1409
  remarkPlugins: [remark_gfm.default, [remark_math.default, { singleDollarTextMath: false }]],
1409
1410
  rehypePlugins: [rehype_raw.default],
1411
+ ...urlTransform !== void 0 ? { urlTransform } : {},
1410
1412
  children: content
1411
1413
  })
1412
1414
  });
@@ -1701,7 +1703,7 @@ const Messages = ({ inProgress, children, RenderMessage, AssistantMessage, UserM
1701
1703
  markdownTagRenderers
1702
1704
  }, index);
1703
1705
  }),
1704
- messages[messages.length - 1]?.role === "user" && inProgress && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingIcon, {}),
1706
+ inProgress && (messages[messages.length - 1]?.role === "user" || messages[messages.length - 1]?.role === "tool") && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingIcon, {}),
1705
1707
  interrupt,
1706
1708
  chatError && ErrorMessage && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
1707
1709
  error: chatError,
@@ -1840,13 +1842,18 @@ const startRecording = async (mediaStreamRef, mediaRecorderRef, audioContextRef,
1840
1842
  };
1841
1843
  mediaRecorderRef.current.onstop = onStop;
1842
1844
  };
1843
- const stopRecording = (mediaRecorderRef) => {
1845
+ const stopRecording = (mediaRecorderRef, mediaStreamRef) => {
1844
1846
  if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") mediaRecorderRef.current.stop();
1847
+ if (mediaStreamRef?.current) {
1848
+ mediaStreamRef.current.getTracks().forEach((track) => track.stop());
1849
+ mediaStreamRef.current = null;
1850
+ }
1845
1851
  };
1846
- const transcribeAudio = async (recordedChunks, transcribeAudioUrl) => {
1847
- const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
1852
+ const transcribeAudio = async (recordedChunks, transcribeAudioUrl, mediaType = "audio/mp4") => {
1853
+ const extension = mediaType.split("/")[1] || "mp4";
1854
+ const completeBlob = new Blob(recordedChunks, { type: mediaType });
1848
1855
  const formData = new FormData();
1849
- formData.append("file", completeBlob, "recording.mp4");
1856
+ formData.append("file", completeBlob, `recording.${extension}`);
1850
1857
  const response = await fetch(transcribeAudioUrl, {
1851
1858
  method: "POST",
1852
1859
  body: formData
@@ -1865,7 +1872,7 @@ const playAudioResponse = (text, textToSpeechUrl, audioContext) => {
1865
1872
  console.error("Error with decoding audio data", error);
1866
1873
  });
1867
1874
  };
1868
- const usePushToTalk = ({ sendFunction, inProgress }) => {
1875
+ const usePushToTalk = ({ sendFunction, inProgress, mediaType = "audio/mp4" }) => {
1869
1876
  const [pushToTalkState, setPushToTalkState] = (0, react.useState)("idle");
1870
1877
  const mediaStreamRef = (0, react.useRef)(null);
1871
1878
  const audioContextRef = (0, react.useRef)(null);
@@ -1883,15 +1890,16 @@ const usePushToTalk = ({ sendFunction, inProgress }) => {
1883
1890
  setPushToTalkState("transcribing");
1884
1891
  });
1885
1892
  else {
1886
- stopRecording(mediaRecorderRef);
1887
- if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(async (transcription) => {
1893
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1894
+ if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl, mediaType).then(async (transcription) => {
1888
1895
  recordedChunks.current = [];
1889
1896
  setPushToTalkState("idle");
1890
- setStartReadingFromMessageId((await sendFunction(transcription)).id);
1897
+ const message = await sendFunction(transcription);
1898
+ if (message) setStartReadingFromMessageId(message.id);
1891
1899
  });
1892
1900
  }
1893
1901
  return () => {
1894
- stopRecording(mediaRecorderRef);
1902
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1895
1903
  };
1896
1904
  }, [pushToTalkState]);
1897
1905
  (0, react.useEffect)(() => {
@@ -2969,6 +2977,7 @@ function useCopilotChatSuggestions(config, dependencies = []) {
2969
2977
  exports.AssistantMessage = AssistantMessage;
2970
2978
  exports.CopilotChat = CopilotChat;
2971
2979
  exports.CopilotDevConsole = CopilotDevConsole;
2980
+ exports.CopilotModal = CopilotModal;
2972
2981
  exports.CopilotPopup = CopilotPopup;
2973
2982
  exports.CopilotSidebar = CopilotSidebar;
2974
2983
  exports.ImageRenderer = ImageRenderer;