Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

update chat, upgrade dialog, account section, and settings

Louis Beaumontcd462d4301a8
diff --git a/apps/screenpipe-app-tauri/components/settings/account-section.tsx b/apps/screenpipe-app-tauri/components/settings/account-section.tsx
index b78e69846..78fba90b3 100644
--- a/apps/screenpipe-app-tauri/components/settings/account-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/account-section.tsx
@@ -55,7 +55,7 @@ export function AccountSection() {
stripe_connected: true,
},
});
- loadUser(settings.user.token!, true);
+ loadUser(settings.user.token!);
}
toast({
title: "stripe connected!",
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index f9c99b3c8..5791d516f 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -79,6 +79,40 @@ const STATIC_MENTION_SUGGESTIONS: MentionSuggestion[] = [
// TOOLS definition removed — search is now handled by Pi's screenpipe-search skill
+/**
+ * Extract tier info from gateway error JSON embedded in error strings and
+ * return a user-facing message appropriate to their actual subscription tier.
+ */
+function buildDailyLimitMessage(errorStr: string): string {
+ try {
+ const tierMatch = errorStr.match(/"tier":\s*"([^"]+)"/);
+ const limitMatch = errorStr.match(/"limit_today":\s*(\d+)/);
+ const tier = tierMatch?.[1];
+ const limit = limitMatch ? parseInt(limitMatch[1]) : null;
+
+ if (tier === "subscribed") {
+ return `You've hit your daily Pro limit${limit ? ` (${limit} queries)` : ""}. Resets at midnight UTC.`;
+ } else if (tier === "logged_in") {
+ return `You've used all ${limit ?? 50} free queries for today. Upgrade to Pro for more.`;
+ } else {
+ return `You've used all ${limit ?? 25} free queries for today. Sign in for more, or upgrade to Pro.`;
+ }
+ } catch {
+ return "You've reached your daily query limit.";
+ }
+}
+
+/** Extract the gateway-reported tier from an error string, if present. */
+function extractTierFromError(errorStr: string): "anonymous" | "logged_in" | "subscribed" | undefined {
+ try {
+ const match = errorStr.match(/"tier":\s*"([^"]+)"/);
+ if (match?.[1] === "subscribed" || match?.[1] === "logged_in" || match?.[1] === "anonymous") {
+ return match[1] as "anonymous" | "logged_in" | "subscribed";
+ }
+ } catch {}
+ return undefined;
+}
+
// Helper to get timezone offset string (e.g., "+1" or "-5")
function getTimezoneOffsetString(): string {
const offsetMinutes = new Date().getTimezoneOffset();
@@ -865,6 +899,7 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
const [showUpgradeDialog, setShowUpgradeDialog] = useState(false);
const [upgradeReason, setUpgradeReason] = useState<"daily_limit" | "model_not_allowed" | "rate_limit">("daily_limit");
const [upgradeResetsAt, setUpgradeResetsAt] = useState<string | undefined>();
+ const [upgradeTier, setUpgradeTier] = useState<"anonymous" | "logged_in" | "subscribed" | undefined>();
const [scheduleDialogMessage, setScheduleDialogMessage] = useState<{ prompt: string; response: string } | null>(null);
const [prefillContext, setPrefillContext] = useState<string | null>(null);
const [prefillSource, setPrefillSource] = useState<string>("search");
@@ -1744,6 +1779,7 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
if (isDailyLimit) {
setUpgradeReason("daily_limit");
+ setUpgradeTier(extractTierFromError(errorStr));
posthog.capture("wall_hit", { reason: "daily_limit", source: "chat" });
} else {
setUpgradeReason("rate_limit");
@@ -1753,7 +1789,7 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
const msgId = piMessageIdRef.current;
let content: string;
if (isDailyLimit) {
- content = "You've used all your free queries for today.";
+ content = buildDailyLimitMessage(errorStr);
} else if (isPerMinuteRate) {
// Extract wait time from error
const waitMatch = errorStr.match(/wait (\d+) seconds/i);
@@ -1795,8 +1831,9 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
if (match) setUpgradeResetsAt(match[1]);
} catch {}
setUpgradeReason("daily_limit");
+ setUpgradeTier(extractTierFromError(fullError));
setMessages((prev) =>
- prev.map((m) => m.id === msgId ? { ...m, content: "You've used all your free queries for today." } : m)
+ prev.map((m) => m.id === msgId ? { ...m, content: buildDailyLimitMessage(fullError) } : m)
);
} else {
setUpgradeReason("rate_limit");
@@ -1839,9 +1876,10 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
if (resetsAtMatch) setUpgradeResetsAt(resetsAtMatch[1]);
} catch {}
setUpgradeReason("daily_limit");
+ setUpgradeTier(extractTierFromError(errMsg));
posthog.capture("wall_hit", { reason: "daily_limit", source: "chat" });
setMessages((prev) =>
- prev.map((m) => m.id === msgId ? { ...m, content: "You've used all your free queries for today." } : m)
+ prev.map((m) => m.id === msgId ? { ...m, content: buildDailyLimitMessage(errMsg) } : m)
);
} else if (errMsg.includes("rate limit") || errMsg.includes("rate_limit")) {
setUpgradeReason("rate_limit");
@@ -1897,7 +1935,8 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
if (resetsAtMatch) setUpgradeResetsAt(resetsAtMatch[1]);
} catch {}
setUpgradeReason("daily_limit");
- content = "You've used all your free queries for today.";
+ setUpgradeTier(extractTierFromError(errStr));
+ content = buildDailyLimitMessage(errStr);
} else if (errStr.includes("rate limit")) {
setUpgradeReason("rate_limit");
content = "Rate limited — try again in a moment.";
@@ -1915,7 +1954,10 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
setMessages((prev) => {
const existing = prev.find((m) => m.id === msgId);
// Don't overwrite error messages with "Done" or empty content
- const isErrorMessage = existing?.content?.includes("used all your free queries") ||
+ const isErrorMessage = existing?.content?.includes("daily") && existing?.content?.includes("limit") ||
+ existing?.content?.includes("free queries") ||
+ existing?.content?.includes("daily Pro limit") ||
+ existing?.content?.includes("daily query limit") ||
existing?.content?.includes("requires an upgrade") ||
existing?.content?.includes("Rate limited") ||
existing?.content?.includes("rate limit") ||
@@ -1980,8 +2022,9 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
if (match) setUpgradeResetsAt(match[1]);
} catch {}
setUpgradeReason("daily_limit");
+ setUpgradeTier(extractTierFromError(errorStr));
setMessages((prev) =>
- prev.map((m) => m.id === msgId ? { ...m, content: "You've used all your free queries for today." } : m)
+ prev.map((m) => m.id === msgId ? { ...m, content: buildDailyLimitMessage(errorStr) } : m)
);
} else {
setUpgradeReason("rate_limit");
@@ -3111,7 +3154,9 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
<MessageContent message={message} onImageClick={(images, index) => setImageViewer({ images, index })} />
{/* Upgrade button for daily limit errors */}
{message.role === "assistant" &&
- (message.content.includes("used all your free queries") ||
+ (message.content.includes("free queries") ||
+ message.content.includes("daily Pro limit") ||
+ message.content.includes("daily query limit") ||
message.content.includes("requires an upgrade")) && (
<button
onClick={() => setShowUpgradeDialog(true)}
@@ -3709,6 +3754,7 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
reason={upgradeReason}
resetsAt={upgradeResetsAt}
source="chat"
+ gatewayTier={upgradeTier}
/>
{scheduleDialogMessage && (
diff --git a/apps/screenpipe-app-tauri/components/upgrade-dialog.tsx b/apps/screenpipe-app-tauri/components/upgrade-dialog.tsx
index 24adfa748..8e05eb56a 100644
--- a/apps/screenpipe-app-tauri/components/upgrade-dialog.tsx
+++ b/apps/screenpipe-app-tauri/components/upgrade-dialog.tsx
@@ -23,6 +23,8 @@ interface UpgradeDialogProps {
reason?: "daily_limit" | "model_not_allowed" | "rate_limit";
resetsAt?: string;
source?: string;
+ /** Tier reported by the gateway in the error response — more reliable than local settings */
+ gatewayTier?: "anonymous" | "logged_in" | "subscribed";
}
export function UpgradeDialog({
@@ -30,10 +32,13 @@ export function UpgradeDialog({
onOpenChange,
reason = "daily_limit",
source = "unknown",
+ gatewayTier,
}: UpgradeDialogProps) {
const { settings } = useSettings();
const isLoggedIn = !!settings.user?.token;
- const tier = settings.user?.cloud_subscribed ? "subscribed" : isLoggedIn ? "logged_in" : "anonymous";
+ const localTier = settings.user?.cloud_subscribed ? "subscribed" : isLoggedIn ? "logged_in" : "anonymous";
+ // Prefer the tier the gateway reported — it's authoritative
+ const tier = gatewayTier ?? localTier;
const trackedRef = useRef(false);
// Track dialog shown
@@ -107,7 +112,9 @@ export function UpgradeDialog({
<Sparkles className="h-4 w-4 shrink-0" />
<span>
{reason === "daily_limit"
- ? "you've used all your free queries today"
+ ? tier === "subscribed"
+ ? "you've hit your daily pro limit"
+ : "you've used all your free queries today"
: reason === "rate_limit"
? "too many requests"
: "this model requires an upgrade"}
@@ -115,7 +122,11 @@ export function UpgradeDialog({
</DialogTitle>
<DialogDescription className="text-xs">
{reason === "daily_limit"
- ? "upgrade to pro to keep going"
+ ? tier === "subscribed"
+ ? "buy credits to keep going, or wait until midnight UTC"
+ : tier === "logged_in"
+ ? "upgrade to pro for 1500 queries/day"
+ : "sign in for 50/day, or upgrade to pro for 1500/day"
: reason === "rate_limit"
? "upgrade for 3x higher rate limits"
: "upgrade for access to all models"}
@@ -123,38 +134,42 @@ export function UpgradeDialog({
</DialogHeader>
<div className="space-y-2.5">
- <Button
- variant="outline"
- className="w-full justify-start gap-2.5 h-auto py-2.5 text-xs"
- onClick={() => handleSubscribe(false)}
- >
- <Zap className="h-4 w-4 shrink-0" />
- <div className="text-left flex-1 min-w-0">
- <div className="font-medium">screenpipe pro — $39/mo</div>
- <div className="text-[11px] text-muted-foreground mt-0.5">
- cloud transcription + claude opus 4.6 + encrypted sync
- </div>
- </div>
- </Button>
+ {tier !== "subscribed" && (
+ <>
+ <Button
+ variant="outline"
+ className="w-full justify-start gap-2.5 h-auto py-2.5 text-xs"
+ onClick={() => handleSubscribe(false)}
+ >
+ <Zap className="h-4 w-4 shrink-0" />
+ <div className="text-left flex-1 min-w-0">
+ <div className="font-medium">screenpipe pro — $39/mo</div>
+ <div className="text-[11px] text-muted-foreground mt-0.5">
+ cloud transcription + claude opus 4.6 + encrypted sync
+ </div>
+ </div>
+ </Button>
- <Button
- variant="outline"
- className="w-full justify-start gap-2.5 h-auto py-2.5 text-xs"
- onClick={() => handleSubscribe(true)}
- >
- <Star className="h-4 w-4 shrink-0" />
- <div className="text-left flex-1 min-w-0">
- <div className="font-medium flex items-center gap-1.5">
- $312/year
- <Badge variant="secondary" className="text-[10px] px-1.5 py-0">
- save 33%
- </Badge>
- </div>
- <div className="text-[11px] text-muted-foreground mt-0.5">
- everything in pro, billed annually
- </div>
- </div>
- </Button>
+ <Button
+ variant="outline"
+ className="w-full justify-start gap-2.5 h-auto py-2.5 text-xs"
+ onClick={() => handleSubscribe(true)}
+ >
+ <Star className="h-4 w-4 shrink-0" />
+ <div className="text-left flex-1 min-w-0">
+ <div className="font-medium flex items-center gap-1.5">
+ $312/year
+ <Badge variant="secondary" className="text-[10px] px-1.5 py-0">
+ save 33%
+ </Badge>
+ </div>
+ <div className="text-[11px] text-muted-foreground mt-0.5">
+ everything in pro, billed annually
+ </div>
+ </div>
+ </Button>
+ </>
+ )}
{!isLoggedIn && (
<Button
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
index 0af57e9f9..ffdc59b92 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
@@ -4,7 +4,6 @@ import { platform } from "@tauri-apps/plugin-os";
import { Store } from "@tauri-apps/plugin-store";
import React, { createContext, useContext, useEffect, useState } from "react";
import posthog from "posthog-js";
-import localforage from "localforage";
import { User } from "../utils/tauri";
import { SettingsStore } from "../utils/tauri";
export type VadSensitivity = "low" | "medium" | "high";
@@ -549,7 +548,7 @@ interface SettingsContextType {
resetSettings: () => Promise<void>;
resetSetting: <K extends keyof Settings>(key: K) => Promise<void>;
reloadStore: () => Promise<void>;
- loadUser: (token: string, forceReload?: boolean) => Promise<void>;
+ loadUser: (token: string) => Promise<void>;
getDataDir: () => Promise<string>;
isSettingsLoaded: boolean;
loadingError: string | null;
@@ -592,15 +591,38 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
// Auto-refresh user data from API when app starts with a stored token.
// This ensures subscription status (cloud_subscribed) stays current —
// e.g. when a subscription is granted after the user last logged in.
+ // Retries with exponential backoff so transient network failures don't
+ // leave the user stuck on a stale tier for the entire session.
useEffect(() => {
if (!isSettingsLoaded) return;
const token = settings.user?.token;
if (!token) return;
- // Force reload to bypass localforage cache
- loadUser(token, true).catch((err) => {
- console.warn("auto-refresh user data failed:", err);
- });
+ let cancelled = false;
+ const MAX_RETRIES = 3;
+ const BASE_DELAY_MS = 2000; // 2s, 4s, 8s
+
+ const attemptLoad = async () => {
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
+ if (cancelled) return;
+ try {
+ await loadUser(token);
+ return; // success
+ } catch (err) {
+ console.warn(
+ `auto-refresh user data failed (attempt ${attempt + 1}/${MAX_RETRIES + 1}):`,
+ err
+ );
+ if (attempt < MAX_RETRIES && !cancelled) {
+ const delay = BASE_DELAY_MS * Math.pow(2, attempt);
+ await new Promise((r) => setTimeout(r, delay));
+ }
+ }
+ }
+ };
+
+ attemptLoad();
+ return () => { cancelled = true; };
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSettingsLoaded]);
@@ -687,23 +709,8 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
return `${homeDirPath}/.screenpipe`;
};
- const loadUser = async (token: string, forceReload = false) => {
+ const loadUser = async (token: string) => {
try {
- // try to get from cache first (unless force reload)
- const cacheKey = `user_data_${token}`;
- if (!forceReload) {
- const cached = await localforage.getItem<{
- data: User;
- timestamp: number;
- }>(cacheKey);
-
- // use cache if less than 30s old
- if (cached && Date.now() - cached.timestamp < 30000) {
- await updateSettings({ user: cached.data });
- return;
- }
- }
-
const response = await fetch(`https://screenpi.pe/api/user`, {
method: "POST",
headers: {
@@ -741,12 +748,6 @@ export const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({ chil
}
}
- // cache the result
- await localforage.setItem(cacheKey, {
- data: userData,
- timestamp: Date.now(),
- });
-
await updateSettings({ user: userData });
} catch (err) {
console.error("failed to load user:", err instanceof Error ? err.message : err);