diff --git a/apps/desktop/src/components/editor-area/index.tsx b/apps/desktop/src/components/editor-area/index.tsx index 81c69b7121..2ac84f02df 100644 --- a/apps/desktop/src/components/editor-area/index.tsx +++ b/apps/desktop/src/components/editor-area/index.tsx @@ -309,6 +309,10 @@ export function useEnhanceMutation({ setEnhancedContent: s.updateEnhancedNote, })); + const getCurrentEnhancedContent = useSession(sessionId, (s) => s.session?.enhanced_memo_html ?? ""); + + const originalContentRef = useRef(""); + const enhance = useMutation({ mutationKey: ["enhance", sessionId], mutationFn: async ({ @@ -318,6 +322,7 @@ export function useEnhanceMutation({ triggerType: "manual" | "template" | "auto"; templateId?: string | null; } = { triggerType: "manual" }) => { + originalContentRef.current = getCurrentEnhancedContent; const abortController = new AbortController(); setEnhanceController(abortController); @@ -408,6 +413,20 @@ export function useEnhanceMutation({ }, }), onError: (error) => { + toast({ + id: "something went wrong", + title: "🚨 Something went wrong", + content: ( +
+ Please try again or contact the team. +
+
+ Error: {String(error.error)} +
+ ), + dismissible: true, + duration: 5000, + }); throw error; }, messages: [ @@ -433,10 +452,17 @@ export function useEnhanceMutation({ }); let acc = ""; + for await (const chunk of fullStream) { if (chunk.type === "text-delta") { acc += chunk.textDelta; } + if (chunk.type === "error") { + if (originalContentRef.current !== "" && acc === "") { + setEnhancedContent(originalContentRef.current); + } + throw new Error("Error occured right away"); + } if (chunk.type === "tool-call" && freshIsLocalLlm) { const chunkProgress = chunk.args?.progress ?? 0; setProgress(chunkProgress); diff --git a/crates/template/assets/enhance.system.jinja b/crates/template/assets/enhance.system.jinja index 9721cd1cf9..0198765ea2 100644 --- a/crates/template/assets/enhance.system.jinja +++ b/crates/template/assets/enhance.system.jinja @@ -80,7 +80,7 @@ You will be given multiple inputs from the user. Below are useful information th - It is super important to acknowledge what the user found to be important, and raw notes show a glimpse of the important information as well as moments during the meeting. Naturally integrate raw note entries into relevant sections instead of forcefully converting them into headers. - Preserve essential details; avoid excessive abstraction. Ensure content remains concrete and specific. - Pay close attention to emphasized text in raw notes. Users highlight information using four styles: bold(**text**), italic(_text_), underline(text), strikethrough(~~text~~). -- Recognize H3 headers (### Header) in raw notes—these indicate highly important topics that the user wants to retain no matter what. +- Recognize # headings in raw notes—these indicate highly important topics that the user wants to retain no matter what. - Below is the guideline on how many changes you should make to the original raw note, please pay close atteion: {%- if specificity == 1 %}