This commit is contained in:
+16
-7
@@ -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 { Layout } from './components/Layout';
|
||||||
import { EmbedLayout } from './components/EmbedLayout';
|
import { EmbedLayout } from './components/EmbedLayout';
|
||||||
import { EmbedAuthWrapper } from './components/EmbedAuthWrapper';
|
import { EmbedAuthWrapper } from './components/EmbedAuthWrapper';
|
||||||
@@ -26,10 +26,11 @@ const App: Component = () => {
|
|||||||
const [currentView, setCurrentView] = createSignal("critical");
|
const [currentView, setCurrentView] = createSignal("critical");
|
||||||
const [lastNonAIView, setLastNonAIView] = createSignal("critical");
|
const [lastNonAIView, setLastNonAIView] = createSignal("critical");
|
||||||
const [isAuthenticated, setIsAuthenticated] = createSignal(pb.authStore.isValid);
|
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 [location, setLocation] = createSignal(window.location.href);
|
||||||
const [isDesktop, setIsDesktop] = createSignal(window.matchMedia("(min-width: 768px)").matches);
|
const [isDesktop, setIsDesktop] = createSignal(window.matchMedia("(min-width: 768px)").matches);
|
||||||
const [aiHelpTip, setAiHelpTip] = createSignal<string | null>(null);
|
const [aiHelpTip, setAiHelpTip] = createSignal<string | null>(null);
|
||||||
const [hasRequestedSessionTip, setHasRequestedSessionTip] = createSignal(false);
|
const [tipGeneratedForUserId, setTipGeneratedForUserId] = createSignal<string | null>(null);
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const view = currentView();
|
const view = currentView();
|
||||||
@@ -43,15 +44,17 @@ const App: Component = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const ready = isAuthenticated() && isDesktop() && !store.isInitializing;
|
const userId = authUserId();
|
||||||
|
const ready = isAuthenticated() && !!userId && isDesktop() && !store.isInitializing;
|
||||||
if (!ready) return;
|
if (!ready) return;
|
||||||
if (!hasFireworksApiKey()) return;
|
if (!hasFireworksApiKey()) return;
|
||||||
if (hasRequestedSessionTip()) return;
|
if (tipGeneratedForUserId() === userId) return;
|
||||||
|
|
||||||
setHasRequestedSessionTip(true);
|
setTipGeneratedForUserId(userId);
|
||||||
|
const historySnapshot = untrack(() => [...store.aiHelpTipHistory]);
|
||||||
void (async () => {
|
void (async () => {
|
||||||
try {
|
try {
|
||||||
const nextTip = await generateAIHelpTip(store.aiHelpTipHistory);
|
const nextTip = await generateAIHelpTip(historySnapshot);
|
||||||
if (!nextTip) return;
|
if (!nextTip) return;
|
||||||
setAiHelpTip(nextTip);
|
setAiHelpTip(nextTip);
|
||||||
await appendAIHelpTipHistory(nextTip);
|
await appendAIHelpTipHistory(nextTip);
|
||||||
@@ -102,9 +105,15 @@ const App: Component = () => {
|
|||||||
let isFirstRun = true;
|
let isFirstRun = true;
|
||||||
const removeListener = pb.authStore.onChange((token) => {
|
const removeListener = pb.authStore.onChange((token) => {
|
||||||
const wasAuthenticated = isAuthenticated();
|
const wasAuthenticated = isAuthenticated();
|
||||||
|
const previousUserId = authUserId();
|
||||||
|
const nextUserId = token ? (pb.authStore.model?.id || null) : null;
|
||||||
setIsAuthenticated(!!token);
|
setIsAuthenticated(!!token);
|
||||||
setHasRequestedSessionTip(false);
|
setAuthUserId(nextUserId);
|
||||||
|
|
||||||
|
if (!token || nextUserId !== previousUserId) {
|
||||||
|
setTipGeneratedForUserId(null);
|
||||||
setAiHelpTip(null);
|
setAiHelpTip(null);
|
||||||
|
}
|
||||||
|
|
||||||
if (token && (isFirstRun || !wasAuthenticated)) {
|
if (token && (isFirstRun || !wasAuthenticated)) {
|
||||||
initStore();
|
initStore();
|
||||||
|
|||||||
+11
-1
@@ -26,6 +26,12 @@ const normalizeLine = (value: string) =>
|
|||||||
.replace(/\s+/g, " ")
|
.replace(/\s+/g, " ")
|
||||||
.toLowerCase();
|
.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;
|
export const hasFireworksApiKey = () => FIREWORKS_API_KEY.trim().length > 0;
|
||||||
|
|
||||||
const extractTextFromContent = (content: unknown): string => {
|
const extractTextFromContent = (content: unknown): string => {
|
||||||
@@ -131,7 +137,11 @@ ${historyBlock}`;
|
|||||||
);
|
);
|
||||||
|
|
||||||
const firstLine = response.split("\n")[0]?.trim() || "";
|
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);
|
const normalized = normalizeLine(cleaned);
|
||||||
|
|
||||||
if (!cleaned || !normalized) continue;
|
if (!cleaned || !normalized) continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user