This commit is contained in:
+17
-8
@@ -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<string | null>(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<string | null>(null);
|
||||
const [hasRequestedSessionTip, setHasRequestedSessionTip] = createSignal(false);
|
||||
const [tipGeneratedForUserId, setTipGeneratedForUserId] = createSignal<string | null>(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();
|
||||
|
||||
+11
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user