From d6e317c6fef6cf4e71e9e0f098a211aef7c81889 Mon Sep 17 00:00:00 2001 From: amosblomqvist Date: Sun, 25 Oct 2026 00:27:52 +0300 Subject: [PATCH] feat: add app-owned Copilot and Grok subscription connections --- components/activity-dock.tsx | 8 +- components/graph-view.tsx | 17 +- components/settings/agent-section.tsx | 3 +- components/settings/chatgpt-connection.tsx | 43 +-- components/settings/connection-controls.tsx | 38 +++ components/settings/keys-section.tsx | 4 +- components/settings/model-menu.tsx | 8 +- components/settings/settings-dialog.tsx | 5 +- .../settings/subscription-connections.tsx | 131 +++++++++ components/setup-dialog.tsx | 7 +- components/sidebar.tsx | 3 +- components/stats-bar.tsx | 11 +- components/usage-format.ts | 6 +- docs/architecture.md | 12 +- electron/main.cjs | 31 ++- electron/preload.cjs | 15 ++ electron/subscription-ipc.cjs | 45 ++++ electron/subscription-store.cjs | 64 +++++ electron/subscriptions.cjs | 251 ++++++++++++++++++ next.config.ts | 5 + scripts/smoke-provider-runtime.mjs | 23 ++ src/agent/chatgpt-request-cycle.ts | 126 +-------- src/agent/models.ts | 8 +- src/agent/subagents/pi-run.ts | 2 + src/agent/subscription-bridge.ts | 132 +++++++++ src/agent/subscription-connections.ts | 23 ++ src/agent/subscription-request-cycle.ts | 128 +++++++++ src/agent/subscription-stream.ts | 85 ++++++ src/agent/teacher-agent.ts | 3 +- src/core/contracts/subscriptions.ts | 68 +++++ src/core/cost-summary.ts | 25 +- src/core/index.ts | 2 + src/core/prices.ts | 18 +- src/server/chat-handler.ts | 32 +-- src/server/jobs.ts | 8 +- src/server/keys.ts | 4 +- src/server/model-catalog.ts | 22 +- src/server/pricing.ts | 4 +- tests/chatgpt-connection-ui.test.tsx | 6 +- tests/chatgpt-ui.test.tsx | 2 +- tests/chatgpt-usage.test.ts | 6 +- tests/desktop-platform.test.ts | 3 +- tests/graph-pricing.test.tsx | 4 +- tests/provider-tracing.test.ts | 2 + tests/subscription-auth.test.ts | 221 +++++++++++++++ tests/subscription-background.test.ts | 62 +++++ tests/subscription-connection-ui.test.tsx | 81 ++++++ tests/subscription-stream.test.ts | 107 ++++++++ tests/subscription-usage.test.tsx | 43 +++ 49 files changed, 1709 insertions(+), 248 deletions(-) create mode 100644 components/settings/connection-controls.tsx create mode 100644 components/settings/subscription-connections.tsx create mode 100644 electron/subscription-ipc.cjs create mode 100644 electron/subscription-store.cjs create mode 100644 electron/subscriptions.cjs create mode 100644 src/agent/subscription-bridge.ts create mode 100644 src/agent/subscription-connections.ts create mode 100644 src/agent/subscription-request-cycle.ts create mode 100644 src/agent/subscription-stream.ts create mode 100644 src/core/contracts/subscriptions.ts create mode 100644 tests/subscription-auth.test.ts create mode 100644 tests/subscription-background.test.ts create mode 100644 tests/subscription-connection-ui.test.tsx create mode 100644 tests/subscription-stream.test.ts create mode 100644 tests/subscription-usage.test.tsx diff --git a/components/activity-dock.tsx b/components/activity-dock.tsx index 32d7469..41f456e 100644 --- a/components/activity-dock.tsx +++ b/components/activity-dock.tsx @@ -4,7 +4,7 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, use import { ActivityIcon, BotIcon, FileTextIcon, PenToolIcon, PlayIcon, SearchIcon, SquareIcon, WaypointsIcon } from "lucide-react"; import { cn } from "@/lib/utils"; import type { CallUsage, JobKind, JobRecord } from "@/src/core"; -import { isModelsRefusal, isProviderKeyRefusal } from "@/src/core"; +import { isModelsRefusal, isProviderKeyRefusal, subscriptionLabel, subscriptionLabels } from "@/src/core"; import { formatTokens, planCostLabel } from "@/components/usage-format"; import { useServerEvent, useServerResync } from "@/components/server-events"; @@ -350,7 +350,7 @@ export function ActivitySection({ feed: feedProp }: { feed?: ActivityFeed }) { Background agents {blobs.length > 0 && ( - {planCostLabel(totalCost, blobs.some((blob) => blob.model?.startsWith("chatgpt:")))} + {planCostLabel(totalCost, subscriptionLabels(blobs.map((blob) => blob.model)))} )} @@ -425,7 +425,7 @@ function ActivityBlobRow({ )} - {planCostLabel(blob.cost, blob.model?.startsWith("chatgpt:") === true)} + {planCostLabel(blob.cost, subscriptionLabel(blob.model))} {formatElapsed(now - blob.startedAt)} @@ -464,7 +464,7 @@ function ActivityBlobRow({
Cost - {planCostLabel(blob.cost, blob.model?.startsWith("chatgpt:") === true)} + {planCostLabel(blob.cost, subscriptionLabel(blob.model))}
diff --git a/components/graph-view.tsx b/components/graph-view.tsx index 293bf44..9cde6cf 100644 --- a/components/graph-view.tsx +++ b/components/graph-view.tsx @@ -68,6 +68,7 @@ import { NotesImportErrors, useNotesImport } from "@/components/notes-import.tsx import Link from "next/link"; import { FileTextIcon, ListTreeIcon, Loader2Icon, SearchIcon, SettingsIcon, UploadIcon, WaypointsIcon } from "lucide-react"; import { incrementalLayout, propositionSessionHref, type GraphCostSummary, type GraphNode, type GraphSnapshot } from "@/src/core"; +import { planCostLabel } from "@/components/usage-format"; import { GraphCanvasRenderer, type GraphRenderSettings } from "./graph-canvas.ts"; import { usePopoverDismiss } from "@/components/popover-dismiss"; import { useActivity } from "@/components/activity-dock"; @@ -294,16 +295,18 @@ function timeAgo(startedAt: number): string { /** Run/stage cost at 3 decimals (pipeline pennies are real money at this * scale); headline totals use 2. Null (unpriced model) renders "—". */ -function fmtRunCost(dollars: number | null, subscription = false): string { - if (subscription) return dollars === null ? "ChatGPT plan" : `$${dollars.toFixed(3)} API + ChatGPT plan`; - return dollars === null ? "—" : `$${dollars.toFixed(3)}`; +function fmtRunCost(dollars: number | null, providers: readonly string[] = []): string { + return planCostLabel(dollars, providers, (value) => `$${value.toFixed(3)}`); +} +function graphProviders(value: { subscriptionRuns?: number; subscriptionProviders?: string[] }): string[] { + return value.subscriptionProviders ?? ((value.subscriptionRuns ?? 0) > 0 ? ["ChatGPT"] : []); } function graphUsageLabel(costs: Pick): string { const stages = [costs.stages.extraction, costs.stages.audit]; - const plan = stages.some((stage) => (stage.subscriptionRuns ?? 0) > 0); + const providers = [...new Set(stages.flatMap(graphProviders))]; const priced = stages.some((stage) => stage.runs - stage.unpricedRuns - (stage.subscriptionRuns ?? 0) > 0); const dollars = displayCostTotals(costs).totalDollars; - return plan ? (priced ? `$${dollars.toFixed(2)} API + ChatGPT plan` : "ChatGPT plan") : priced ? `$${dollars.toFixed(2)}` : "—"; + return planCostLabel(priced ? dollars : null, providers, (value) => `$${value.toFixed(2)}`); } /** @@ -405,7 +408,7 @@ function GraphCostPanel({ costs }: { costs: GraphCostSummary }) {
{label} - {fmtRunCost(stage.runs - stage.unpricedRuns - (stage.subscriptionRuns ?? 0) <= 0 ? null : stage.dollars, (stage.subscriptionRuns ?? 0) > 0)} + {fmtRunCost(stage.runs - stage.unpricedRuns - (stage.subscriptionRuns ?? 0) <= 0 ? null : stage.dollars, graphProviders(stage))} {stage.unpricedRuns > 0 && (stage.runs - stage.unpricedRuns - (stage.subscriptionRuns ?? 0) > 0 || (stage.subscriptionRuns ?? 0) > 0) && ( +{stage.unpricedRuns} unpriced )} @@ -430,7 +433,7 @@ function GraphCostPanel({ costs }: { costs: GraphCostSummary }) { )} - {fmtRunCost(run.dollars, (run.subscriptionRuns ?? 0) > 0)}{run.dollars === null && run.subscriptionRuns === 1 ? " +1 unpriced" : ""} + {fmtRunCost(run.dollars, graphProviders(run))}{run.dollars === null && run.subscriptionRuns === 1 ? " +1 unpriced" : ""}
))}
diff --git a/components/settings/agent-section.tsx b/components/settings/agent-section.tsx index 5395eec..bd7c810 100644 --- a/components/settings/agent-section.tsx +++ b/components/settings/agent-section.tsx @@ -73,6 +73,7 @@ import { cn } from "@/lib/utils"; import { SettingsGroup, SettingsRow, Toggle, CommitInput } from "./controls.tsx"; import { ModelMenuList, ThinkingMenuList } from "./model-menu"; import { ChatGPTBackgroundAccess } from "./chatgpt-connection"; +import { NativeSubscriptionBackgroundAccess } from "./subscription-connections"; /** One slot's display identity — the tier's roster as the row hint rides * with the resolved default (owner: the hint ALWAYS names the default). */ @@ -648,7 +649,7 @@ export function AgentSection({ ref={thisMenuOpen ? menuAnchorRef : undefined} className="relative flex items-center gap-2" > - {slot !== "strong" && } + {slot !== "strong" && <>} void; busy: boolean }) { - const ref = useRef(null); - const closeRef = useRef(onClose); - closeRef.current = onClose; - const backdropDismiss = useBackdropDismiss(onClose); - useEffect(() => { - const previous = document.activeElement as HTMLElement | null; - const focusable = () => [...(ref.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled])') ?? [])]; - focusable()[0]?.focus(); - const key = (event: KeyboardEvent) => { - if (event.key === "Escape") { - event.preventDefault(); event.stopImmediatePropagation(); closeRef.current(); - } else if (event.key === "Tab") { - const items = focusable(), first = items[0], last = items.at(-1); - if (!first) { event.preventDefault(); return; } - if (event.shiftKey && (document.activeElement === first || !ref.current?.contains(document.activeElement))) { event.preventDefault(); last?.focus(); } - else if (!event.shiftKey && (document.activeElement === last || !ref.current?.contains(document.activeElement))) { event.preventDefault(); first.focus(); } - } - }; - // Capture claims the nested dialog's Escape before outer Settings/setup. - document.addEventListener("keydown", key, true); - return () => { document.removeEventListener("keydown", key, true); if (previous?.isConnected) previous.focus(); }; - }, []); - return createPortal(
-
event.stopPropagation()} className="settings-dialog-pop mx-4 max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-md border border-border bg-card p-5 shadow-xl">{children}
-
, document.body); + return {children}; } /** Compact settings row, or setup's secondary action only. */ @@ -357,15 +332,11 @@ export function ChatGPTConnection({ setup = false }: { setup?: boolean }) { const active = ui.status.accounts.find((a) => a.id === ui.status.activeId && a.connected); const accounts = ui.status.accounts.filter((a) => a.connected); return
-
- {!setup && active && ChatGPT} - {active && !setup ? <> - - - : } -
+ active ? ui.manage(active.id) : ui.connect()}> + {active && !setup && } + {ui.inlineError &&

{ui.inlineError}

} {ui.warning &&
{ui.warning}
}
; diff --git a/components/settings/connection-controls.tsx b/components/settings/connection-controls.tsx new file mode 100644 index 0000000..2486cc0 --- /dev/null +++ b/components/settings/connection-controls.tsx @@ -0,0 +1,38 @@ +"use client"; +import { useEffect, useRef } from "react"; +import { createPortal } from "react-dom"; +import { useBackdropDismiss } from "@/components/backdrop-dismiss"; +import { Button } from "@/components/ui/button"; + +export function ConnectionRow({ label, action, disabled, onAction, children, testid, actionTestid }: { label: string; action: string; disabled: boolean; onAction: () => void; children?: React.ReactNode; testid?: string; actionTestid?: string }) { + return
+ {label} + {children} + +
; +} + +export function ConnectionDialog({ children, onClose, busy, label, testid, backdropTestid }: { children: React.ReactNode; onClose: () => void; busy: boolean; label: string; testid: string; backdropTestid: string }) { + const ref = useRef(null), closeRef = useRef(onClose); + closeRef.current = onClose; + const backdropDismiss = useBackdropDismiss(() => { if (!busy) onClose(); }); + useEffect(() => { + const previous = document.activeElement as HTMLElement | null; + const focusable = () => [...(ref.current?.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled])') ?? [])]; + focusable()[0]?.focus(); + const key = (event: KeyboardEvent) => { + if (event.key === "Escape") { event.preventDefault(); event.stopImmediatePropagation(); closeRef.current(); } + else if (event.key === "Tab") { + const items = focusable(), first = items[0], last = items.at(-1); + if (!first) { event.preventDefault(); return; } + if (event.shiftKey && (document.activeElement === first || !ref.current?.contains(document.activeElement))) { event.preventDefault(); last?.focus(); } + else if (!event.shiftKey && (document.activeElement === last || !ref.current?.contains(document.activeElement))) { event.preventDefault(); first.focus(); } + } + }; + document.addEventListener("keydown", key, true); + return () => { document.removeEventListener("keydown", key, true); if (previous?.isConnected) previous.focus(); }; + }, []); + return createPortal(
+
event.stopPropagation()} className="settings-dialog-pop mx-4 max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-md border border-border bg-card p-5 shadow-xl">{children}
+
, document.body); +} diff --git a/components/settings/keys-section.tsx b/components/settings/keys-section.tsx index f1f2652..3269ca8 100644 --- a/components/settings/keys-section.tsx +++ b/components/settings/keys-section.tsx @@ -26,7 +26,7 @@ import { useEffect, useRef, useState } from "react"; import { AUTH_KEYS, type AuthKeyStatus } from "@/src/core"; import { SettingsGroup } from "./controls.tsx"; -import { ChatGPTConnection } from "./chatgpt-connection.tsx"; +import { SubscriptionConnections } from "./subscription-connections.tsx"; import { ProviderMenuList } from "./model-menu.tsx"; import { MenuShell } from "@/components/menu-shell"; import { notifySettingsSaved } from "@/components/settings-signal"; @@ -456,7 +456,7 @@ export function KeysSection({ -
+
{(["Dictation", "Search"] as const).map((label) => diff --git a/components/settings/model-menu.tsx b/components/settings/model-menu.tsx index 8f46238..19697b9 100644 --- a/components/settings/model-menu.tsx +++ b/components/settings/model-menu.tsx @@ -21,7 +21,7 @@ import { useEffect, useRef, useState } from "react"; import type { ModelCatalogEntry } from "@/src/core"; -import { fuzzyScore } from "@/src/core"; +import { fuzzyScore, subscriptionLabel } from "@/src/core"; import { formatTokens } from "@/components/usage-format"; function priceLabel(cost: ModelCatalogEntry["cost"]): string { @@ -125,12 +125,12 @@ export function ModelMenuList({ > {m.name} - - {m.provider === "chatgpt" ? "ChatGPT plan" : priceLabel(m.cost)} + + {subscriptionLabel(`${m.provider}:${m.id}`) ?? priceLabel(m.cost)} - {m.provider} · {m.id} + {subscriptionLabel(`${m.provider}:${m.id}`) ? `${subscriptionLabel(`${m.provider}:${m.id}`)} (subscription)` : m.provider} · {m.id} {formatTokens(m.contextWindow)} diff --git a/components/settings/settings-dialog.tsx b/components/settings/settings-dialog.tsx index f0cca9f..1142bdf 100644 --- a/components/settings/settings-dialog.tsx +++ b/components/settings/settings-dialog.tsx @@ -50,6 +50,7 @@ import { Hint } from "@/components/ui/hint"; import { AppearanceSection, GraphSection } from "./appearance-section.tsx"; import { KeyboardSection } from "./keyboard-section.tsx"; import { ChatGPTUIProvider } from "./chatgpt-connection.tsx"; +import { NativeSubscriptionUIProvider } from "./subscription-connections.tsx"; /** Owner (2026-09-20): hints earn their place — mechanics-explaining * prose is out; only the keyboard note stays (storage location is a @@ -92,12 +93,12 @@ export function SettingsDialogProvider({ setShow(true); }, []); return ( - + {children} {show && ( setShow(false)} initialSection={landOn} initialRow={landOnRow} /> )} - + ); } diff --git a/components/settings/subscription-connections.tsx b/components/settings/subscription-connections.tsx new file mode 100644 index 0000000..b5c69a5 --- /dev/null +++ b/components/settings/subscription-connections.tsx @@ -0,0 +1,131 @@ +"use client"; +import { createContext, useContext, useEffect, useRef, useState } from "react"; +import { NATIVE_SUBSCRIPTIONS, type NativeSubscriptionProviderId, type NativeSubscriptionStatus } from "@/src/core"; +import { Button } from "@/components/ui/button"; +import { notifySettingsSaved } from "@/components/settings-signal"; +import { ConnectionDialog, ConnectionRow } from "./connection-controls"; +import { ChatGPTConnection } from "./chatgpt-connection"; +import { Toggle } from "./controls"; + +export const COPILOT_POLICY_NOTICE = "Pi's native Copilot sign-in may enable additional models whose policy is not yet configured. Models explicitly disabled by policy are not enabled. Organization restrictions still apply."; +export const SUBSCRIPTION_BACKGROUND_HINT = "Allow LearnHarness helper agents and automatic follow-ups to use this connection."; +export function subscriptionNotice(label: string): string { return `Your prompts, tool results, and relevant session context are sent to ${label} to run the work you select. Credentials are stored locally in an owner-only plaintext file. Provider terms, data-use policies, and plan limits apply. This connection never falls back to an API key.`; } +export function subscriptionDisconnectCopy(label: string): string { return `Disconnect ${label} from LearnHarness? This stops work using this connection and removes its saved credentials from this device. It does not cancel your subscription or revoke access at the provider. Saved model choices will remain unavailable until you reconnect or change them.`; } +export function emptySubscriptionStatus(providerId: NativeSubscriptionProviderId): NativeSubscriptionStatus { return { providerId, available: false, connected: false, pending: false, allowBackgroundUse: true, connectionId: null, epoch: 0, authorityRevision: 0, revision: 0 }; } +const Context = createContext({ statuses: [] as NativeSubscriptionStatus[], busy: false, open: (_providerId: NativeSubscriptionProviderId) => {} }); +const CONTROL_ERROR = "The connection could not be changed. Try again."; + +export function NativeSubscriptionUIProvider({ children }: { children: React.ReactNode }) { + const [statuses, setStatuses] = useState([]); + const [dialog, setDialog] = useState(null); + const [confirm, setConfirm] = useState(false), [background, setBackground] = useState(true), [backgroundDirty, setBackgroundDirty] = useState(false), [promptValue, setPromptValue] = useState(""); + const [operation, setOperation] = useState<"login" | "control" | null>(null), [error, setError] = useState(null); + const mounted = useRef(false), sequence = useRef(0), generation = useRef(0), statusesRef = useRef(statuses); + const descriptor = NATIVE_SUBSCRIPTIONS.find((p) => p.providerId === dialog); + const status = statuses.find((s) => s.providerId === dialog) ?? (dialog ? emptySubscriptionStatus(dialog) : undefined); + const interaction = status?.interaction, prompt = interaction?.prompt; + const busy = operation === "control" || status?.committing === true; + async function refresh() { + const request = ++sequence.current; + try { + const values = await window.lh?.subscriptions?.status(); + if (!mounted.current || request !== sequence.current || !Array.isArray(values)) return; + const accepted = NATIVE_SUBSCRIPTIONS.map(({ providerId }) => { + const next = values.find((s) => s.providerId === providerId), old = statusesRef.current.find((s) => s.providerId === providerId); + return next && (!old || next.revision >= old.revision) ? next : old ?? emptySubscriptionStatus(providerId); + }); + statusesRef.current = accepted; setStatuses(accepted); + } catch { if (mounted.current && request === sequence.current) setError("The desktop connection is unavailable. Retry when the app is ready."); } + } + useEffect(() => { + mounted.current = true; void refresh(); + const off = window.lh?.subscriptions?.onChange(() => { void refresh(); notifySettingsSaved("keys"); }); + return () => { mounted.current = false; generation.current++; off?.(); }; + // The root-lifetime subscriber reads current state through refs. + }, []); + useEffect(() => { setPromptValue(""); }, [prompt?.id]); + function open(providerId: NativeSubscriptionProviderId) { + if (operation || statusesRef.current.some((s) => s.pending)) return; + generation.current++; setError(null); setConfirm(false); setBackgroundDirty(false); + setBackground(statusesRef.current.find((s) => s.providerId === providerId)?.allowBackgroundUse ?? true); setDialog(providerId); + } + async function control(action: () => Promise, close = false) { + if (busy) return; + const owner = ++generation.current; setOperation("control"); setError(null); + try { await action(); await refresh(); if (mounted.current && owner === generation.current && close) setDialog(null); } + catch { if (mounted.current && owner === generation.current) setError(CONTROL_ERROR); } + finally { if (mounted.current && owner === generation.current) setOperation(null); } + } + function close() { + if (!dialog || busy) return; + if (confirm) { setConfirm(false); setError(null); return; } + const bridge = window.lh?.subscriptions; + if ((status?.pending || operation === "login") && bridge) { void control(() => bridge.cancel(dialog), true); return; } + generation.current++; setDialog(null); setError(null); + } + async function login() { + const bridge = window.lh?.subscriptions; + if (!dialog || !bridge || operation || !status?.available) return; + const owner = ++generation.current; setOperation("login"); setError(null); + try { await bridge.login(dialog, backgroundDirty ? background : undefined); await refresh(); if (mounted.current && generation.current === owner) setDialog(null); } + catch { if (mounted.current && generation.current === owner) setError("Sign-in did not complete. Try connecting again."); } + finally { if (mounted.current && generation.current === owner) setOperation(null); } + } + const bridge = typeof window === "undefined" ? undefined : window.lh?.subscriptions; + return + {children} + {dialog && descriptor && status && +

{confirm ? `Disconnect ${descriptor.label}?` : status.connectionId ? descriptor.label : `Connect to ${descriptor.label}`}

+ {confirm ?

{subscriptionDisconnectCopy(descriptor.label)}

: <> +

{subscriptionNotice(descriptor.label)}

+ {dialog === "github-copilot" &&

{COPILOT_POLICY_NOTICE}

} +
+ { setBackground(enabled); if (status.connectionId && bridge) void control(() => bridge.consent(dialog, enabled)); else setBackgroundDirty(true); }} /> + Allow background use{SUBSCRIPTION_BACKGROUND_HINT} +
+ {!status.available &&

Subscription sign-in requires the desktop app's private server connection. API-key connections remain available here.

} + {status.connected &&

Connected

} + {interaction &&
+ {interaction.progress &&

{interaction.progress}

} + {interaction.userCode &&

Device code: {interaction.userCode}

} + {interaction.browser && } + {prompt &&
{ event.preventDefault(); if (bridge) void bridge.respond(dialog, interaction.attemptId, prompt.id, promptValue).catch(() => setError(CONTROL_ERROR)); }}> + + {prompt.type === "select" ? : setPromptValue(event.target.value)} className="w-full rounded-sm border border-border bg-background px-2 py-1.5" />} + +
} +
} + } + {(error || status.error) &&

{error || status.error}

} +
+ {!confirm && status.connectionId && !status.pending && <> + + {status.error && } + + } + + {confirm ? : !status.connectionId && } +
+
} +
; +} + +export function NativeSubscriptionConnection({ providerId }: { providerId: NativeSubscriptionProviderId }) { + const ui = useContext(Context), descriptor = NATIVE_SUBSCRIPTIONS.find((p) => p.providerId === providerId)!; + const status = ui.statuses.find((s) => s.providerId === providerId) ?? emptySubscriptionStatus(providerId); + return
+ s.pending)} onAction={() => ui.open(providerId)}> + {status.connected && Connected} + + {status.error &&

{status.error}

} +
; +} +export function SubscriptionConnections({ setup = false }: { setup?: boolean }) { + return
{NATIVE_SUBSCRIPTIONS.map((p) => )}
; +} +export function NativeSubscriptionBackgroundAccess({ provider }: { provider: string | undefined }) { + const ui = useContext(Context), descriptor = NATIVE_SUBSCRIPTIONS.find((p) => p.logicalId === provider); + const status = ui.statuses.find((s) => s.providerId === descriptor?.providerId); + if (!descriptor || !status?.connected || status.allowBackgroundUse) return null; + return ; +} diff --git a/components/setup-dialog.tsx b/components/setup-dialog.tsx index 2372d01..461e507 100644 --- a/components/setup-dialog.tsx +++ b/components/setup-dialog.tsx @@ -44,7 +44,8 @@ import { notifySettingsSaved, useSettingsSaved } from "@/components/settings-sig import { Hint } from "@/components/ui/hint"; import { type ProviderKeyInfo } from "@/components/settings/keys-section"; import { ProviderMenuList } from "@/components/settings/model-menu"; -import { ChatGPTBackgroundAccess, ChatGPTConnection } from "@/components/settings/chatgpt-connection"; +import { ChatGPTBackgroundAccess } from "@/components/settings/chatgpt-connection"; +import { NativeSubscriptionBackgroundAccess, SubscriptionConnections } from "@/components/settings/subscription-connections"; import { defaultOrderLevel, populateLevel, THINKING_LABEL } from "@/components/thinking-default"; import { ThinkingMenuList } from "@/components/settings/model-menu"; import type { ThinkingLevel } from "@earendil-works/pi-agent-core"; @@ -211,7 +212,7 @@ export function SetupKeysBody({

)} -
+

Subscriptions

); } @@ -477,7 +478,7 @@ export function SetupDialog({ )}
{SLOT_META[slot].roster} - {slot !== "strong" && } + {slot !== "strong" && <>}