From f30b160fa50eb2cd9c1a1d02c3686d5360b0834c Mon Sep 17 00:00:00 2001 From: Timothy Cardoza Date: Wed, 25 Mar 2026 18:41:57 -0500 Subject: [PATCH] tip fix --- src/App.tsx | 2 +- src/components/Navigation.tsx | 4 ++-- src/lib/ai-help.ts | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 932988e..7546449 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -56,7 +56,7 @@ const App: Component = () => { setAiHelpTip(nextTip); await appendAIHelpTipHistory(nextTip); } catch (err) { - console.error("Failed to generate AI help tip", err); + console.warn("Tip generation skipped", err); } })(); }); diff --git a/src/components/Navigation.tsx b/src/components/Navigation.tsx index 67a44ff..4c0f17a 100644 --- a/src/components/Navigation.tsx +++ b/src/components/Navigation.tsx @@ -392,10 +392,10 @@ export const Sidebar: Component<{
- +
diff --git a/src/lib/ai-help.ts b/src/lib/ai-help.ts index 9cf8770..f4088ee 100644 --- a/src/lib/ai-help.ts +++ b/src/lib/ai-help.ts @@ -28,6 +28,33 @@ const normalizeLine = (value: string) => export const hasFireworksApiKey = () => FIREWORKS_API_KEY.trim().length > 0; +const extractTextFromContent = (content: unknown): string => { + if (typeof content === "string") { + return content.trim(); + } + + if (Array.isArray(content)) { + return content + .map(part => { + if (typeof part === "string") return part; + if (part && typeof part === "object") { + if ("text" in part && typeof (part as any).text === "string") { + return (part as any).text; + } + if ("content" in part && typeof (part as any).content === "string") { + return (part as any).content; + } + } + return ""; + }) + .filter(Boolean) + .join("\n") + .trim(); + } + + return ""; +}; + const requestFireworks = async (messages: ChatRequestMessage[], options?: { maxTokens?: number; temperature?: number }) => { const response = await fetch(FIREWORKS_API_URL, { method: "POST", @@ -50,7 +77,12 @@ const requestFireworks = async (messages: ChatRequestMessage[], options?: { maxT } const data = await response.json(); - const content = data?.choices?.[0]?.message?.content?.trim(); + const choice = data?.choices?.[0]; + const content = extractTextFromContent(choice?.message?.content) + || extractTextFromContent(choice?.message?.reasoning_content) + || extractTextFromContent(choice?.delta?.content) + || extractTextFromContent(choice?.text) + || extractTextFromContent(data?.output_text); if (!content) { throw new Error("The help assistant did not return any text.");