@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.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,17 +1395,25 @@ 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);
1399
+ const Markdown = ({ content, components, remarkPlugins, rehypePlugins, ...rest }) => {
1400
+ const mergedComponents = (0, react.useMemo)(() => ({
1401
+ ...defaultComponents,
1402
+ ...components
1403
+ }), [components]);
1404
+ const mergedRemarkPlugins = (0, react.useMemo)(() => [
1405
+ remark_gfm.default,
1406
+ [remark_math.default, { singleDollarTextMath: false }],
1407
+ ...remarkPlugins !== null && remarkPlugins !== void 0 ? remarkPlugins : []
1408
+ ], [remarkPlugins]);
1409
+ const mergedRehypePlugins = (0, react.useMemo)(() => [rehype_raw.default, ...rehypePlugins !== null && rehypePlugins !== void 0 ? rehypePlugins : []], [rehypePlugins]);
1399
1410
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1400
1411
  className: "copilotKitMarkdown",
1401
1412
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedReactMarkdown, {
1402
- components: (0, react.useMemo)(() => ({
1403
- ...defaultComponents,
1404
- ...components
1405
- }), [components]),
1406
- remarkPlugins: [remark_gfm.default, [remark_math.default, { singleDollarTextMath: false }]],
1407
- rehypePlugins: [rehype_raw.default],
1413
+ ...rest,
1414
+ components: mergedComponents,
1415
+ remarkPlugins: mergedRemarkPlugins,
1416
+ rehypePlugins: mergedRehypePlugins,
1408
1417
  children: content
1409
1418
  })
1410
1419
  });
@@ -1653,7 +1662,7 @@ rehype_raw = __toESM(rehype_raw);
1653
1662
  //#endregion
1654
1663
  //#region src/components/chat/Messages.tsx
1655
1664
  const Messages = ({ inProgress, children, RenderMessage, AssistantMessage, UserMessage, ErrorMessage, ImageRenderer, onRegenerate, onCopy, onThumbsUp, onThumbsDown, messageFeedback, markdownTagRenderers, chatError, RenderTextMessage, RenderActionExecutionMessage, RenderAgentStateMessage, RenderResultMessage, RenderImageMessage }) => {
1656
- var _messages;
1665
+ var _messages, _messages2;
1657
1666
  const { labels, icons } = useChatContext();
1658
1667
  const { messages: visibleMessages, interrupt } = (0, _copilotkit_react_core.useCopilotChatInternal)();
1659
1668
  const messages = [...(0, react.useMemo)(() => makeInitialMessages(labels.initial), [labels.initial]), ...visibleMessages];
@@ -1704,7 +1713,7 @@ rehype_raw = __toESM(rehype_raw);
1704
1713
  markdownTagRenderers
1705
1714
  }, index);
1706
1715
  }),
1707
- ((_messages = messages[messages.length - 1]) === null || _messages === void 0 ? void 0 : _messages.role) === "user" && inProgress && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingIcon, {}),
1716
+ 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
1717
  interrupt,
1709
1718
  chatError && ErrorMessage && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
1710
1719
  error: chatError,
@@ -1843,13 +1852,18 @@ rehype_raw = __toESM(rehype_raw);
1843
1852
  };
1844
1853
  mediaRecorderRef.current.onstop = onStop;
1845
1854
  };
1846
- const stopRecording = (mediaRecorderRef) => {
1855
+ const stopRecording = (mediaRecorderRef, mediaStreamRef) => {
1847
1856
  if (mediaRecorderRef.current && mediaRecorderRef.current.state !== "inactive") mediaRecorderRef.current.stop();
1857
+ if (mediaStreamRef === null || mediaStreamRef === void 0 ? void 0 : mediaStreamRef.current) {
1858
+ mediaStreamRef.current.getTracks().forEach((track) => track.stop());
1859
+ mediaStreamRef.current = null;
1860
+ }
1848
1861
  };
1849
- const transcribeAudio = async (recordedChunks, transcribeAudioUrl) => {
1850
- const completeBlob = new Blob(recordedChunks, { type: "audio/mp4" });
1862
+ const transcribeAudio = async (recordedChunks, transcribeAudioUrl, mediaType = "audio/mp4") => {
1863
+ const extension = mediaType.split("/")[1] || "mp4";
1864
+ const completeBlob = new Blob(recordedChunks, { type: mediaType });
1851
1865
  const formData = new FormData();
1852
- formData.append("file", completeBlob, "recording.mp4");
1866
+ formData.append("file", completeBlob, `recording.${extension}`);
1853
1867
  const response = await fetch(transcribeAudioUrl, {
1854
1868
  method: "POST",
1855
1869
  body: formData
@@ -1868,7 +1882,7 @@ rehype_raw = __toESM(rehype_raw);
1868
1882
  console.error("Error with decoding audio data", error);
1869
1883
  });
1870
1884
  };
1871
- const usePushToTalk = ({ sendFunction, inProgress }) => {
1885
+ const usePushToTalk = ({ sendFunction, inProgress, mediaType = "audio/mp4" }) => {
1872
1886
  const [pushToTalkState, setPushToTalkState] = (0, react.useState)("idle");
1873
1887
  const mediaStreamRef = (0, react.useRef)(null);
1874
1888
  const audioContextRef = (0, react.useRef)(null);
@@ -1886,15 +1900,16 @@ rehype_raw = __toESM(rehype_raw);
1886
1900
  setPushToTalkState("transcribing");
1887
1901
  });
1888
1902
  else {
1889
- stopRecording(mediaRecorderRef);
1890
- if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl).then(async (transcription) => {
1903
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1904
+ if (pushToTalkState === "transcribing") transcribeAudio(recordedChunks.current, context.copilotApiConfig.transcribeAudioUrl, mediaType).then(async (transcription) => {
1891
1905
  recordedChunks.current = [];
1892
1906
  setPushToTalkState("idle");
1893
- setStartReadingFromMessageId((await sendFunction(transcription)).id);
1907
+ const message = await sendFunction(transcription);
1908
+ if (message) setStartReadingFromMessageId(message.id);
1894
1909
  });
1895
1910
  }
1896
1911
  return () => {
1897
- stopRecording(mediaRecorderRef);
1912
+ stopRecording(mediaRecorderRef, mediaStreamRef);
1898
1913
  };
1899
1914
  }, [pushToTalkState]);
1900
1915
  (0, react.useEffect)(() => {
@@ -2990,6 +3005,7 @@ rehype_raw = __toESM(rehype_raw);
2990
3005
  exports.AssistantMessage = AssistantMessage;
2991
3006
  exports.CopilotChat = CopilotChat;
2992
3007
  exports.CopilotDevConsole = CopilotDevConsole;
3008
+ exports.CopilotModal = CopilotModal;
2993
3009
  exports.CopilotPopup = CopilotPopup;
2994
3010
  exports.CopilotSidebar = CopilotSidebar;
2995
3011
  exports.ImageRenderer = ImageRenderer;