@copilotkit/react-ui 1.56.0 → 1.56.2-canary.pin-to-send

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,17 +1397,25 @@ 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);
1401
+ const Markdown = ({ content, components, remarkPlugins, rehypePlugins, ...rest }) => {
1402
+ const mergedComponents = (0, react.useMemo)(() => ({
1403
+ ...defaultComponents,
1404
+ ...components
1405
+ }), [components]);
1406
+ const mergedRemarkPlugins = (0, react.useMemo)(() => [
1407
+ remark_gfm.default,
1408
+ [remark_math.default, { singleDollarTextMath: false }],
1409
+ ...remarkPlugins ?? []
1410
+ ], [remarkPlugins]);
1411
+ const mergedRehypePlugins = (0, react.useMemo)(() => [rehype_raw.default, ...rehypePlugins ?? []], [rehypePlugins]);
1401
1412
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1402
1413
  className: "copilotKitMarkdown",
1403
1414
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedReactMarkdown, {
1404
- components: (0, react.useMemo)(() => ({
1405
- ...defaultComponents,
1406
- ...components
1407
- }), [components]),
1408
- remarkPlugins: [remark_gfm.default, [remark_math.default, { singleDollarTextMath: false }]],
1409
- rehypePlugins: [rehype_raw.default],
1415
+ ...rest,
1416
+ components: mergedComponents,
1417
+ remarkPlugins: mergedRemarkPlugins,
1418
+ rehypePlugins: mergedRehypePlugins,
1410
1419
  children: content
1411
1420
  })
1412
1421
  });
@@ -1701,7 +1710,7 @@ const Messages = ({ inProgress, children, RenderMessage, AssistantMessage, UserM
1701
1710
  markdownTagRenderers
1702
1711
  }, index);
1703
1712
  }),
1704
- messages[messages.length - 1]?.role === "user" && inProgress && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingIcon, {}),
1713
+ inProgress && (messages[messages.length - 1]?.role === "user" || messages[messages.length - 1]?.role === "tool") && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingIcon, {}),
1705
1714
  interrupt,
1706
1715
  chatError && ErrorMessage && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
1707
1716
  error: chatError,
@@ -1840,13 +1849,18 @@ const startRecording = async (mediaStreamRef, mediaRecorderRef, audioContextRef,
1840
1849
  };
1841
1850
  mediaRecorderRef.current.onstop = onStop;
1842
1851
  };
1843
- const stopRecording = (mediaRecorderRef) => {
1852
+ const stopRecording = (mediaRecorderRef, mediaStreamRef) => {
1844
1853
  if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") mediaRecorderRef.current.stop();
1854
+ if (mediaStreamRef?.current) {
1855
+ mediaStreamRef.current.getTracks().forEach((track) => track.stop());
1856
+ mediaStreamRef.current = null;
1857
+ }
1845
1858
  };
1846
- const transcribeAudio = async (recordedChunks, transcribeAudioUrl) => {
1847
- const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
1859
+ const transcribeAudio = async (recordedChunks, transcribeAudioUrl, mediaType = "audio/mp4") => {
1860
+ const extension = mediaType.split("/")[1] || "mp4";
1861
+ const completeBlob = new Blob(recordedChunks, { type: mediaType });
1848
1862
  const formData = new FormData();
1849
- formData.append("file", completeBlob, "recording.mp4");
1863
+ formData.append("file", completeBlob, `recording.${extension}`);
1850
1864
  const response = await fetch(transcribeAudioUrl, {
1851
1865
  method: "POST",
1852
1866
  body: formData
@@ -1865,7 +1879,7 @@ const playAudioResponse = (text, textToSpeechUrl, audioContext) => {
1865
1879
  console.error("Error with decoding audio data", error);
1866
1880
  });
1867
1881
  };
1868
- const usePushToTalk = ({ sendFunction, inProgress }) => {
1882
+ const usePushToTalk = ({ sendFunction, inProgress, mediaType = "audio/mp4" }) => {
1869
1883
  const [pushToTalkState, setPushToTalkState] = (0, react.useState)("idle");
1870
1884
  const mediaStreamRef = (0, react.useRef)(null);
1871
1885
  const audioContextRef = (0, react.useRef)(null);
@@ -1883,15 +1897,16 @@ const usePushToTalk = ({ sendFunction, inProgress }) => {
1883
1897
  setPushToTalkState("transcribing");
1884
1898
  });
1885
1899
  else {
1886
- stopRecording(mediaRecorderRef);
1887
- if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(async (transcription) => {
1900
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1901
+ if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl, mediaType).then(async (transcription) => {
1888
1902
  recordedChunks.current = [];
1889
1903
  setPushToTalkState("idle");
1890
- setStartReadingFromMessageId((await sendFunction(transcription)).id);
1904
+ const message = await sendFunction(transcription);
1905
+ if (message) setStartReadingFromMessageId(message.id);
1891
1906
  });
1892
1907
  }
1893
1908
  return () => {
1894
- stopRecording(mediaRecorderRef);
1909
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1895
1910
  };
1896
1911
  }, [pushToTalkState]);
1897
1912
  (0, react.useEffect)(() => {
@@ -2969,6 +2984,7 @@ function useCopilotChatSuggestions(config, dependencies = []) {
2969
2984
  exports.AssistantMessage = AssistantMessage;
2970
2985
  exports.CopilotChat = CopilotChat;
2971
2986
  exports.CopilotDevConsole = CopilotDevConsole;
2987
+ exports.CopilotModal = CopilotModal;
2972
2988
  exports.CopilotPopup = CopilotPopup;
2973
2989
  exports.CopilotSidebar = CopilotSidebar;
2974
2990
  exports.ImageRenderer = ImageRenderer;