From 7653c6bf0ea36e55dbd9a89d13245f7dad2f4dcf Mon Sep 17 00:00:00 2001 From: Timothy Cardoza Date: Wed, 25 Mar 2026 18:48:37 -0500 Subject: [PATCH] fix --- src/App.tsx | 25 +++++++++++++++++-------- src/lib/ai-help.ts | 12 +++++++++++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 7546449..73fb283 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { type Component, createSignal, onMount, onCleanup, createMemo, createEffect, lazy, Suspense, Show } from 'solid-js'; +import { type Component, createSignal, onMount, onCleanup, createMemo, createEffect, lazy, Suspense, Show, untrack } from 'solid-js'; import { Layout } from './components/Layout'; import { EmbedLayout } from './components/EmbedLayout'; import { EmbedAuthWrapper } from './components/EmbedAuthWrapper'; @@ -26,10 +26,11 @@ const App: Component = () => { const [currentView, setCurrentView] = createSignal("critical"); const [lastNonAIView, setLastNonAIView] = createSignal("critical"); const [isAuthenticated, setIsAuthenticated] = createSignal(pb.authStore.isValid); + const [authUserId, setAuthUserId] = createSignal(pb.authStore.model?.id || null); const [location, setLocation] = createSignal(window.location.href); const [isDesktop, setIsDesktop] = createSignal(window.matchMedia("(min-width: 768px)").matches); const [aiHelpTip, setAiHelpTip] = createSignal(null); - const [hasRequestedSessionTip, setHasRequestedSessionTip] = createSignal(false); + const [tipGeneratedForUserId, setTipGeneratedForUserId] = createSignal(null); createEffect(() => { const view = currentView(); @@ -43,15 +44,17 @@ const App: Component = () => { ); createEffect(() => { - const ready = isAuthenticated() && isDesktop() && !store.isInitializing; + const userId = authUserId(); + const ready = isAuthenticated() && !!userId && isDesktop() && !store.isInitializing; if (!ready) return; if (!hasFireworksApiKey()) return; - if (hasRequestedSessionTip()) return; + if (tipGeneratedForUserId() === userId) return; - setHasRequestedSessionTip(true); + setTipGeneratedForUserId(userId); + const historySnapshot = untrack(() => [...store.aiHelpTipHistory]); void (async () => { try { - const nextTip = await generateAIHelpTip(store.aiHelpTipHistory); + const nextTip = await generateAIHelpTip(historySnapshot); if (!nextTip) return; setAiHelpTip(nextTip); await appendAIHelpTipHistory(nextTip); @@ -102,9 +105,15 @@ const App: Component = () => { let isFirstRun = true; const removeListener = pb.authStore.onChange((token) => { const wasAuthenticated = isAuthenticated(); + const previousUserId = authUserId(); + const nextUserId = token ? (pb.authStore.model?.id || null) : null; setIsAuthenticated(!!token); - setHasRequestedSessionTip(false); - setAiHelpTip(null); + setAuthUserId(nextUserId); + + if (!token || nextUserId !== previousUserId) { + setTipGeneratedForUserId(null); + setAiHelpTip(null); + } if (token && (isFirstRun || !wasAuthenticated)) { initStore(); diff --git a/src/lib/ai-help.ts b/src/lib/ai-help.ts index f4088ee..e093f59 100644 --- a/src/lib/ai-help.ts +++ b/src/lib/ai-help.ts @@ -26,6 +26,12 @@ const normalizeLine = (value: string) => .replace(/\s+/g, " ") .toLowerCase(); +const keepSingleSentence = (value: string) => { + const trimmed = value.trim(); + const sentenceMatch = trimmed.match(/.+?[.!?](?=\s|$)/); + return (sentenceMatch?.[0] || trimmed).trim(); +}; + export const hasFireworksApiKey = () => FIREWORKS_API_KEY.trim().length > 0; const extractTextFromContent = (content: unknown): string => { @@ -131,7 +137,11 @@ ${historyBlock}`; ); const firstLine = response.split("\n")[0]?.trim() || ""; - const cleaned = firstLine.replace(/^[-*•\d.\s]+/, "").trim(); + const cleaned = keepSingleSentence( + firstLine + .replace(/^[\-\*\u2022\d.\s]+/, "") + .trim() + ); const normalized = normalizeLine(cleaned); if (!cleaned || !normalized) continue;