feat: add Russian localization and independent STT languages
CI / Typecheck, tests, lint (push) Canceled after 0s
CI / Standalone (mac-arm64) (push) Canceled after 0s
CI / Standalone (linux-x64) (push) Canceled after 0s
CI / Standalone (windows-x64) (push) Canceled after 0s

This commit is contained in:
2026-10-25 17:18:44 +03:00
parent b277ee3e0f
commit a50ca4b867
93 changed files with 3261 additions and 904 deletions
+43 -41
View File
@@ -1,4 +1,6 @@
"use client";
import { useI18n } from "@/components/i18n";
/**
* The Agent section (settings-app wave): the THREE MODEL SLOTS, the tool
* toggles + the search-engine preference, and the prompt override
@@ -250,6 +252,7 @@ function MenuTrigger({
/** The no-key search state grays the whole row; the trigger follows. */
disabled?: boolean;
}) {
const { t } = useI18n();
return (
<button
type="button"
@@ -263,7 +266,7 @@ function MenuTrigger({
disabled ? "cursor-not-allowed" : "hover:border-muted-foreground/50"
} ${widthClass}`}
>
<span className="min-w-0 flex-1 truncate">{value || emptyLabel}</span>
<span className="min-w-0 flex-1 truncate">{t(value || emptyLabel)}</span>
<span aria-hidden className="text-muted-foreground">
▾
</span>
@@ -303,6 +306,7 @@ export function AgentSection({
/** Writes the whole compaction section (replace-PUT discipline). */
onCompactionChange: (next: CompactionSettings) => void;
}) {
const { t } = useI18n();
const [catalog, setCatalog] = useState<ModelCatalogEntry[] | null>(null);
/** The three tiers' resolved pins — GET /api/models `slots`. The rows'
* Default hints and thinking lists resolve from it. */
@@ -492,7 +496,7 @@ export function AgentSection({
>
<span>{label}</span>
<span className="text-muted-foreground">
{live === null ? (active && <span aria-hidden>✓</span>) : live ? <span aria-hidden>✓ key</span> : <span aria-hidden>· no key</span>}
{live === null ? (active && <span aria-hidden>✓</span>) : live ? <span aria-hidden>{t("✓ key")}</span> : <span aria-hidden>{t("· no key")}</span>}
</span>
</button>
);
@@ -527,7 +531,7 @@ export function AgentSection({
<Toggle
checked={info.enabled}
disabled={!fileExists}
label={`prompt ${info.path}`}
label={t("prompt {v0}", { v0: info.path })}
onChange={(on) => onSectionChange(composePromptSwitch(agent, info.path, on))}
/>
</span>
@@ -540,26 +544,26 @@ export function AgentSection({
}}
className="text-xs text-muted-foreground/70 underline-offset-2 hover:text-foreground hover:underline"
>
{open ? "Hide text" : "Show text"}
{open ? t("Hide text") : t("Show text")}
</button>
{open && (
<div className="mt-1 flex flex-col gap-2">
<div>
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">Source</p>
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">{t("Source")}</p>
<textarea
readOnly
value={info.sourceText}
aria-label="The original instructions"
aria-label={t("The original instructions")}
className="h-24 w-full resize-y rounded-sm border border-border bg-muted p-2 font-ui text-xs text-muted-foreground"
/>
</div>
<div>
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">Override</p>
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">{t("Override")}</p>
<textarea
value={segmentDraft[info.path] ?? info.overrideText ?? ""}
onChange={(e) => setSegmentDraft({ ...segmentDraft, [info.path]: e.target.value })}
aria-label="Your version of the instructions"
placeholder="Add your own instructions…"
aria-label={t("Your version of the instructions")}
placeholder={t("Add your own instructions…")}
className="h-24 w-full resize-y rounded-sm border border-border bg-background p-2 font-ui text-xs text-foreground outline-none"
/>
</div>
@@ -574,16 +578,14 @@ export function AgentSection({
: "cursor-not-allowed text-xs text-muted-foreground/40 underline-offset-2"
}
>
Save
</button>
{t("Save")}</button>
{fileExists && (
<button
type="button"
onClick={() => void deleteSegment(info.path)}
className="text-xs text-muted-foreground/70 underline-offset-2 hover:text-red-500 hover:underline"
>
Delete
</button>
{t("Delete")}</button>
)}
{/* The quiet inline confirmation — next to the
action, not the old path-echoing line at the
@@ -593,7 +595,7 @@ export function AgentSection({
status reads unambiguously. */}
{segmentStatus && (
<p className="text-xs text-muted-foreground/70" data-testid="segment-status">
{segmentStatus}
{t(segmentStatus)}
</p>
)}
</div>
@@ -614,7 +616,7 @@ export function AgentSection({
return (
<>
<SettingsGroup label="Models" testid="group-models">
<SettingsGroup label={t("Models")} testid="group-models">
{MODEL_SLOTS.map((slot) => {
const override = models?.[slot];
const modelId = override?.model?.id ?? "";
@@ -653,7 +655,7 @@ export function AgentSection({
<MenuTrigger
value={modelId ? prettyModel(modelId) : ""}
emptyLabel="—"
ariaLabel={`${SLOT_META[slot].label} model`}
ariaLabel={t("{v0} model", { v0: t(SLOT_META[slot].label) })}
testid={`slot-model-${slot}`}
open={thisMenuOpen === "model"}
onClick={() => setOpenMenu(thisMenuOpen === "model" ? null : { target: slot, kind: "model" })}
@@ -665,7 +667,7 @@ export function AgentSection({
// what the engine build runs). Display-only until a pick writes.
value={thinking || (chosen ? defaultOrderLevel(levels) : "")}
emptyLabel="—"
ariaLabel={`${SLOT_META[slot].label} thinking`}
ariaLabel={t("{v0} thinking", { v0: t(SLOT_META[slot].label) })}
testid={`slot-thinking-${slot}`}
open={thisMenuOpen === "thinking"}
onClick={() => setOpenMenu(thisMenuOpen === "thinking" ? null : { target: slot, kind: "thinking" })}
@@ -692,8 +694,8 @@ export function AgentSection({
}}
footer={
catalog && catalog.length === 0
? "No models — add a provider key in Keys"
: "Runs every agent of this tier"
? t("No models — add a provider key in Keys")
: t("Runs every agent of this tier")
}
/>
</MenuShell>
@@ -723,7 +725,7 @@ export function AgentSection({
})}
</SettingsGroup>
<SettingsGroup label="Tools" testid="group-tools">
<SettingsGroup label={t("Tools")} testid="group-tools">
{/* The prober's graph tools (wave 7, owner ruling 2026-09-23):
FIRST row of the group — its subject is the map, its
mechanism is agent capability, so it lives in Tools but
@@ -735,15 +737,15 @@ export function AgentSection({
const graphOn = graph?.enabled ?? true;
return (
<SettingsRow
label="Graph tools"
hint={graphOn ? "Lets the tutor consult your knowledge map between sessions" : "Graph is disabled"}
label={t("Graph tools")}
hint={graphOn ? t("Lets the tutor consult your knowledge map between sessions") : t("Graph is disabled")}
testid="graph-tools-row"
dimmed={!graphOn}
>
<Toggle
checked={agent?.graphTools?.enabled ?? true}
disabled={!graphOn}
label="graph tools"
label={t("graph tools")}
onChange={(on) => onSectionChange(composeGraphTools(agent, on))}
/>
</SettingsRow>
@@ -757,13 +759,13 @@ export function AgentSection({
const free = agent?.tools?.explain === true;
return (
<SettingsRow
label="Quizzing"
hint="How both tutors check your understanding"
label={t("Quizzing")}
hint={t("How both tutors check your understanding")}
testid="quiz-mechanics-row"
>
<div
role="radiogroup"
aria-label="Quizzing mechanics"
aria-label={t("Quizzing mechanics")}
className="flex rounded-lg border border-border/60 bg-muted/30 p-0.5"
>
{(["choice", "free"] as const).map((m) => {
@@ -781,7 +783,7 @@ export function AgentSection({
active ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground",
)}
>
{m === "choice" ? "Multiple choice" : "Free recall"}
{m === "choice" ? t("Multiple choice") : t("Free recall")}
</button>
);
})}
@@ -792,12 +794,12 @@ export function AgentSection({
{TOGGLE_TOOLS.map((id) => (
<SettingsRow
key={id}
label={`Tool · ${id}`}
label={t("Tool · {v0}", { v0: id })}
testid={`tool-row-${id}`}
>
<Toggle
checked={agent?.tools?.[id] ?? true}
label={`tool ${id}`}
label={t("tool {v0}", { v0: id })}
onChange={(on) => onSectionChange(composeTool(agent, id, on))}
/>
</SettingsRow>
@@ -808,7 +810,7 @@ export function AgentSection({
const open = openMenu?.target === "search";
return (
<SettingsRow
label="Search engine"
label={t("Search engine")}
hint={search?.reason ?? undefined}
testid="search-engine-row"
dimmed={!anyKey}
@@ -816,8 +818,8 @@ export function AgentSection({
<span ref={open ? menuAnchorRef : undefined} className="relative flex items-center gap-2">
<MenuTrigger
value={engine === "tavily" ? "Tavily" : engine === "brave" ? "Brave" : ""}
emptyLabel="Automatic"
ariaLabel="Search engine"
emptyLabel={t("Automatic")}
ariaLabel={t("Search engine")}
testid="search-engine-trigger"
open={open}
onClick={() => setOpenMenu(open ? null : { target: "search", kind: "engine" })}
@@ -831,7 +833,7 @@ export function AgentSection({
testid="search-engine-menu"
menuClass="flex w-44 flex-col gap-0.5 rounded-xl border border-border bg-card p-2 text-xs shadow-xl"
>
{engineOption("auto", "Automatic", engine === null, null, () => {
{engineOption("auto", t("Automatic"), engine === null, null, () => {
onSectionChange(composeSearchEngine(agent, null));
setOpenMenu(null);
})}
@@ -849,17 +851,17 @@ export function AgentSection({
})()}
</SettingsGroup>
<SettingsGroup label="Context" testid="group-context">
<SettingsGroup label={t("Context")} testid="group-context">
<SettingsRow
label="Compaction threshold"
hint={`${resolvedCompaction.thresholdTokens} tok`}
label={t("Compaction threshold")}
hint={t("{v0} tok", { v0: resolvedCompaction.thresholdTokens })}
testid="compaction-row-threshold"
>
<CommitInput
type="number"
value={String(compaction?.thresholdTokens ?? "")}
placeholder={String(resolvedCompaction.thresholdTokens)}
ariaLabel="compaction threshold"
ariaLabel={t("compaction threshold")}
testid="input-compaction-threshold"
onCommit={(v) => {
// Empty = factory default (the budget row's discipline):
@@ -882,9 +884,9 @@ export function AgentSection({
</SettingsRow>
</SettingsGroup>
<SettingsGroup label="System prompts" testid="group-prompts">
<SettingsGroup label={t("System prompts")} testid="group-prompts">
{prompts === null ? (
<p className="text-xs text-muted-foreground/70">Loading prompt segments…</p>
<p className="text-xs text-muted-foreground/70">{t("Loading prompt segments…")}</p>
) : (
<div className="flex flex-col gap-4">
{/* The owner's ruled order (2026-09-26): Teacher first,
@@ -894,10 +896,10 @@ export function AgentSection({
{sectionedSegments(prompts).map((section) => (
<div key={section.id} data-testid={`prompt-section-${section.id}`}>
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">
{section.label}
{t(section.label)}
</p>
{section.hint && (
<p className="mb-1 text-xs text-muted-foreground/60">{section.hint}</p>
<p className="mb-1 text-xs text-muted-foreground/60">{t(section.hint)}</p>
)}
<div className="flex flex-col gap-2">
{section.segments.map((info) => segmentRow(info))}
+36 -32
View File
@@ -1,4 +1,6 @@
"use client";
import { useI18n } from "@/components/i18n";
/**
* The Appearance + Graph sections (thin settings wave).
*
@@ -97,6 +99,7 @@ export function AppearanceSection({
/** PUT the whole appearance section; the page re-applies on success. */
onSectionChange: (next: AppearanceSettings) => void;
}) {
const { t, language } = useI18n();
const { appearance: resolved } = useAppearance();
const md = appearance?.mdRendering;
@@ -186,27 +189,27 @@ export function AppearanceSection({
return (
<>
<SettingsRow label="Mode" hint="Coming soon" testid="row-mode" dimmed>
<SettingsRow label={t("Mode")} hint={t("Coming soon")} testid="row-mode" dimmed>
<ThinSelect value="dark" ariaLabel="mode" onChange={() => {}} testid="select-mode" disabled>
<option value="dark">Dark</option>
<option value="dark">{t("Dark")}</option>
</ThinSelect>
</SettingsRow>
<SettingsRow
label="Background"
hint={`Empty = ${resolved.background ?? "#141414"}`}
label={t("Background")}
hint={t("Empty = {v0}", { v0: resolved.background ?? "#141414" })}
testid="row-background"
>
<CommitInput
value={appearance?.background ?? ""}
placeholder="#141414"
ariaLabel="background hex"
ariaLabel={t("background hex")}
testid="input-background"
onCommit={(v) => onSectionChange({ ...appearance, background: v === "" ? null : v })}
/>
</SettingsRow>
<SettingsRow
label="Reading font"
hint={`Empty = ${DEFAULT_READING_FONT}`}
label={t("Reading font")}
hint={t("Empty = {v0}", { v0: language === "ru" ? "Noto Sans" : DEFAULT_READING_FONT })}
testid="row-font"
>
<span ref={fontMenuOpen ? menuAnchorRef : undefined} className="relative flex items-center gap-2">
@@ -222,13 +225,13 @@ export function AppearanceSection({
const triggerButton = (
<button
type="button"
aria-label="Reading font"
aria-label={t("Reading font")}
aria-expanded={fontMenuOpen}
data-testid="font-trigger"
onClick={openFontMenu}
className="flex h-7 min-w-20 items-center gap-1 rounded-sm border border-border bg-background px-1.5 font-ui text-xs text-foreground transition-colors hover:border-muted-foreground/50"
>
<span className="min-w-0 flex-1 truncate">{appearance?.fontFamily || DEFAULT_READING_FONT}</span>
<span className="min-w-0 flex-1 truncate">{appearance?.fontFamily || (language === "ru" ? "Noto Sans" : DEFAULT_READING_FONT)}</span>
<span aria-hidden className="text-muted-foreground">
▾
</span>
@@ -237,7 +240,7 @@ export function AppearanceSection({
return fontMenuOpen ? (
triggerButton
) : (
<Hint label="Choose from your installed fonts" side="left">
<Hint label={t("Choose from your installed fonts")} side="left">
{triggerButton}
</Hint>
);
@@ -258,21 +261,21 @@ export function AppearanceSection({
? undefined
: localFonts === null
? enumEmpty
? "Common families — installed fonts could not be read"
: "Common families — your installed list needs the desktop app"
: "Your installed fonts"
? t("Common families — installed fonts could not be read")
: t("Common families — your installed list needs the desktop app")
: t("Your installed fonts")
}
/>
</MenuShell>
)}
</span>
</SettingsRow>
<SettingsRow label="Reading font size" hint={`${resolved.proseFontSize}px`} testid="row-prose-size">
<SettingsRow label={t("Reading font size")} hint={`${resolved.proseFontSize}px`} testid="row-prose-size">
<CommitInput
type="number"
value={String(appearance?.proseFontSize ?? "")}
placeholder="16"
ariaLabel="prose font size"
ariaLabel={t("prose font size")}
testid="input-prose-size"
onCommit={(v) => {
// Empty = factory default (owner, fix wave): omit the key so the record
@@ -288,19 +291,19 @@ export function AppearanceSection({
}}
/>
</SettingsRow>
<SettingsRow label="Session names in serif" testid="row-session-serif">
<SettingsRow label={t("Session names in serif")} testid="row-session-serif">
<Toggle
checked={appearance?.sessionNameSerif ?? true}
label="session names serif"
label={t("session names serif")}
onChange={(on) => onSectionChange({ ...appearance, sessionNameSerif: on })}
/>
</SettingsRow>
<SettingsRow label="Heading weight" hint={`${resolved.mdRendering.headingWeight}`} testid="row-heading-weight">
<SettingsRow label={t("Heading weight")} hint={`${resolved.mdRendering.headingWeight}`} testid="row-heading-weight">
<CommitInput
type="number"
value={String(md?.headingWeight ?? "")}
placeholder="900"
ariaLabel="heading weight"
ariaLabel={t("heading weight")}
testid="input-heading-weight"
onCommit={(v) => {
// Empty = factory default (owner, fix wave): Number("") is 0, so
@@ -321,20 +324,20 @@ export function AppearanceSection({
{/* The emphasis inks default to the REGULAR TEXT COLOR now
(appearance wave, 2026-09-26) — the empty-state labels say
so; explicit hex overrides ride unchanged. */}
<SettingsRow label="Bold color" hint="Empty = same as text" testid="row-bold-color">
<SettingsRow label={t("Bold color")} hint={t("Empty = same as text")} testid="row-bold-color">
<CommitInput
value={md?.boldColor ?? ""}
placeholder="same as text"
ariaLabel="bold color"
placeholder={t("same as text")}
ariaLabel={t("bold color")}
testid="input-bold-color"
onCommit={(v) => onSectionChange({ ...appearance, mdRendering: { ...md, boldColor: v === "" ? null : v } })}
/>
</SettingsRow>
<SettingsRow label="Italic color" hint="Empty = same as text" testid="row-italic-color">
<SettingsRow label={t("Italic color")} hint={t("Empty = same as text")} testid="row-italic-color">
<CommitInput
value={md?.italicColor ?? ""}
placeholder="same as text"
ariaLabel="italic color"
placeholder={t("same as text")}
ariaLabel={t("italic color")}
testid="input-italic-color"
onCommit={(v) => onSectionChange({ ...appearance, mdRendering: { ...md, italicColor: v === "" ? null : v } })}
/>
@@ -350,6 +353,7 @@ export function GraphSection({
graph: GraphSettings | undefined;
onSectionChange: (next: GraphSettings) => void;
}) {
const { t } = useI18n();
// Wave 7 collapse (owner ruling 2026-09-23): the section is the MASTER
// SWITCH — the embedding/clustering/labeling rungs are gone; clustering
// is the free birth-session partition derived on read, labels ARE session
@@ -370,10 +374,10 @@ export function GraphSection({
switch below arrived: off ≠ no graph, off = the graph stops
growing. The testid keeps the old name's shape (row-enabled) so
this stays one rename, not a test re-pin. */}
<SettingsRow label="Extraction" hint="Off = the graph stops growing" testid="graph-row-enabled">
<SettingsRow label={t("Extraction")} hint={t("Off = the graph stops growing")} testid="graph-row-enabled">
<Toggle
checked={graph?.enabled ?? true}
label="extraction enabled"
label={t("extraction enabled")}
onChange={(on) =>
// Compose, never replace-whole (the section PUT is, but the
// row must not drop its sibling field — fixed with the budget
@@ -386,23 +390,23 @@ export function GraphSection({
round): display-only. Off = the home shows the chains view
instead of the canvas. The ledgers, the pipeline, everything
data keeps working — that is the extraction switch above. */}
<SettingsRow label="Graph rendering" hint="Off = home shows the chains view" testid="graph-row-rendering">
<SettingsRow label={t("Graph rendering")} hint={t("Off = home shows the chains view")} testid="graph-row-rendering">
<Toggle
checked={graph?.rendering ?? true}
label="graph rendering enabled"
label={t("graph rendering enabled")}
onChange={(on) => onSectionChange({ ...graph, rendering: on })}
/>
</SettingsRow>
<SettingsRow
label="Extraction chunk budget"
hint={`${resolved.extractionChunkTokens} tok`}
label={t("Extraction chunk budget")}
hint={t("{v0} tok", { v0: resolved.extractionChunkTokens })}
testid="graph-row-chunk-tokens"
>
<CommitInput
type="number"
value={String(graph?.extractionChunkTokens ?? "")}
placeholder={String(resolved.extractionChunkTokens)}
ariaLabel="extraction chunk budget"
ariaLabel={t("extraction chunk budget")}
testid="input-chunk-tokens"
onCommit={(v) => {
// Empty = factory default (the fix-wave discipline): absence is
+41 -35
View File
@@ -1,4 +1,6 @@
"use client";
import { useI18n } from "@/components/i18n";
import { createContext, useContext, useEffect, useRef, useState } from "react";
import type { ChatGPTStatus } from "@/src/core";
@@ -41,6 +43,7 @@ const Context = createContext({
/** UI lifetime spans setup's keys → models transition. Only existing safe controls
* are used; account IDs remain control values, never displayed account labels. */
export function ChatGPTUIProvider({ children }: { children: React.ReactNode }) {
const { t } = useI18n();
const [status, setStatus] = useState<ChatGPTStatus>(empty);
const [dialog, setDialog] = useState<Dialog | null>(null);
const [busy, setBusy] = useState(false);
@@ -257,55 +260,55 @@ export function ChatGPTUIProvider({ children }: { children: React.ReactNode }) {
{dialog && <AccountDialog key={`${dialog.kind}:${dialog.kind === "manage" && !!dialog.confirm}`} onClose={close} busy={busy && operation.current !== "login"}>
<h2 className="text-sm font-semibold text-foreground">ChatGPT</h2>
{dialog.kind === "warning" ? <>
<p role="alert" className="rounded-sm border border-border px-3 py-2 text-xs text-foreground" data-testid="chatgpt-revocation-warning">{REVOCATION_WARNING}</p>
<div className="mt-4 flex justify-end"><Button variant="outline" size="sm" onClick={() => { context.dismissWarning(); showDialog(null); }}>Dismiss</Button></div>
<p role="alert" className="rounded-sm border border-border px-3 py-2 text-xs text-foreground" data-testid="chatgpt-revocation-warning">{t(REVOCATION_WARNING)}</p>
<div className="mt-4 flex justify-end"><Button variant="outline" size="sm" onClick={() => { context.dismissWarning(); showDialog(null); }}>{t("Dismiss")}</Button></div>
</> : dialog.kind === "manage" && dialog.confirm ? <div data-testid="chatgpt-disconnect-confirmation">
<p className="mt-3 text-sm font-semibold text-red-400">{CHATGPT_DISCONNECT_COPY.title}</p>
<p className="mt-3 text-xs text-foreground">{managed?.email || "ChatGPT account"}</p>
<p className="mt-3 text-xs text-muted-foreground">{CHATGPT_DISCONNECT_COPY.body}</p>
{context.error && <p role="alert" className="mt-3 text-xs text-red-400">{context.error}</p>}
<p className="mt-3 text-sm font-semibold text-red-400">{t(CHATGPT_DISCONNECT_COPY.title)}</p>
<p className="mt-3 text-xs text-foreground">{managed?.email || t("ChatGPT account")}</p>
<p className="mt-3 text-xs text-muted-foreground">{t(CHATGPT_DISCONNECT_COPY.body)}</p>
{context.error && <p role="alert" className="mt-3 text-xs text-red-400">{t(context.error)}</p>}
<div className="mt-4 flex items-center justify-end gap-2">
<Button variant="ghost" size="sm" disabled={busy} onClick={close}>Cancel</Button>
<Button variant="destructive" size="sm" data-testid="chatgpt-confirm-disconnect" disabled={busy || !managedPresent} onClick={() => bridge && managed && void control("disconnect", () => bridge.disconnect(managed.id), managed.id)}>Disconnect account</Button>
<Button variant="ghost" size="sm" disabled={busy} onClick={close}>{t("Cancel")}</Button>
<Button variant="destructive" size="sm" data-testid="chatgpt-confirm-disconnect" disabled={busy || !managedPresent} onClick={() => bridge && managed && void control("disconnect", () => bridge.disconnect(managed.id), managed.id)}>{t("Disconnect account")}</Button>
</div>
</div> : <>
{dialog.kind === "connect" ? <>
{status.accounts.length > 0 && <div className="mt-3 flex items-center gap-2 text-xs text-muted-foreground">
<select aria-label="Saved ChatGPT account" value={registration} onChange={(event) => setRegistration(event.target.value)} disabled={busy || status.pending} className="min-w-0 rounded-sm border border-border bg-background px-2 py-1.5 text-foreground">
<option value="">Add another account or workspace</option>
{status.accounts.map((a) => <option key={a.id} value={a.id}>{a.email || "ChatGPT account"}</option>)}
<select aria-label={t("Saved ChatGPT account")} value={registration} onChange={(event) => setRegistration(event.target.value)} disabled={busy || status.pending} className="min-w-0 rounded-sm border border-border bg-background px-2 py-1.5 text-foreground">
<option value="">{t("Add another account or workspace")}</option>
{status.accounts.map((a) => <option key={a.id} value={a.id}>{a.email || t("ChatGPT account")}</option>)}
</select>
{registration && <Button variant="ghost" size="xs" disabled={busy} onClick={() => context.manage(registration)}>Manage…</Button>}
{registration && <Button variant="ghost" size="xs" disabled={busy} onClick={() => context.manage(registration)}>{t("Manage…")}</Button>}
</div>}
<p className="mt-3 text-xs leading-relaxed text-muted-foreground" data-testid="chatgpt-privacy-notice">{CHATGPT_NOTICE}</p>
<p className="mt-3 text-xs leading-relaxed text-muted-foreground" data-testid="chatgpt-privacy-notice">{t(CHATGPT_NOTICE)}</p>
</> : null}
<div className={`mt-4 flex items-center gap-3 text-xs text-foreground ${busy && operation.current === "change" && status.available && !status.pending ? "[&>button:disabled]:cursor-auto" : ""}`} data-testid="chatgpt-global-background">
<Toggle label={BACKGROUND_LABEL} checked={dialog.kind === "connect" ? background : status.allowBackgroundUse} disabled={busy || status.pending || !status.available} onChange={(enabled) => {
<Toggle label={t(BACKGROUND_LABEL)} checked={dialog.kind === "connect" ? background : status.allowBackgroundUse} disabled={busy || status.pending || !status.available} onChange={(enabled) => {
if (dialog.kind === "connect") { setBackground(enabled); setBackgroundDirty(true); }
else if (bridge) void control("change", () => bridge.consent(enabled));
}} />
<span>{BACKGROUND_LABEL}<span className="mt-1 block leading-relaxed text-muted-foreground">{CHATGPT_BACKGROUND_HINT}</span></span>
<span>{t(BACKGROUND_LABEL)}<span className="mt-1 block leading-relaxed text-muted-foreground">{t(CHATGPT_BACKGROUND_HINT)}</span></span>
</div>
<div className="mt-3 flex flex-wrap items-center gap-3 text-xs text-muted-foreground">
<a href="https://openai.com/policies/privacy-policy/" target="_blank" rel="noreferrer" className="underline underline-offset-2">OpenAI privacy</a>
<a href="https://chatgpt.com/settings/usage" target="_blank" rel="noreferrer" className="underline underline-offset-2">Manage usage</a>
<a href="https://openai.com/policies/privacy-policy/" target="_blank" rel="noreferrer" className="underline underline-offset-2">{t("OpenAI privacy")}</a>
<a href="https://chatgpt.com/settings/usage" target="_blank" rel="noreferrer" className="underline underline-offset-2">{t("Manage usage")}</a>
</div>
{!status.available && <p className="mt-3 text-xs text-muted-foreground">ChatGPT sign-in is available only in the desktop app. API-key connections remain available here.</p>}
{status.pending && <p role="status" className="mt-3 text-xs text-muted-foreground">Waiting for browser sign-in…</p>}
{context.error && <p role="alert" className="mt-3 text-xs text-red-400">{context.error}</p>}
{!status.available && <p className="mt-3 text-xs text-muted-foreground">{t("ChatGPT sign-in is available only in the desktop app. API-key connections remain available here.")}</p>}
{status.pending && <p role="status" className="mt-3 text-xs text-muted-foreground">{t("Waiting for browser sign-in…")}</p>}
{context.error && <p role="alert" className="mt-3 text-xs text-red-400">{t(context.error)}</p>}
{dialog.kind === "manage" && managed && <div className="mt-4 flex flex-wrap items-center justify-between gap-3" data-testid="chatgpt-account-strip">
<div data-testid="chatgpt-managed-identity" className="flex min-w-0 items-center gap-2 text-xs text-foreground">
{status.accounts.length > 1 && managedPresent && !busy ? <select aria-label="Manage ChatGPT account" value={managed.id} onChange={(event) => context.manage(event.target.value)} className="min-w-0 rounded-sm border border-border bg-background px-2 py-1.5">
{status.accounts.map((a) => <option key={a.id} value={a.id}>{a.email || "ChatGPT account"}</option>)}
</select> : <span className="break-all">{managed.email || "ChatGPT account"}</span>}
{status.accounts.length > 1 && managedPresent && !busy ? <select aria-label={t("Manage ChatGPT account")} value={managed.id} onChange={(event) => context.manage(event.target.value)} className="min-w-0 rounded-sm border border-border bg-background px-2 py-1.5">
{status.accounts.map((a) => <option key={a.id} value={a.id}>{a.email || t("ChatGPT account")}</option>)}
</select> : <span className="break-all">{managed.email || t("ChatGPT account")}</span>}
</div>
<Button variant="ghost" size="sm" data-testid="chatgpt-add-accounts" className="cursor-pointer text-muted-foreground disabled:cursor-not-allowed" onClick={() => openConnect()} disabled={busy || status.pending || !status.available}>Add accounts</Button>
<Button variant="ghost" size="sm" data-testid="chatgpt-add-accounts" className="cursor-pointer text-muted-foreground disabled:cursor-not-allowed" onClick={() => openConnect()} disabled={busy || status.pending || !status.available}>{t("Add accounts")}</Button>
</div>}
<ConnectionFooter testid="chatgpt-account-footer" leading={dialog.kind === "manage" && <div data-testid="chatgpt-account-actions">
<Button variant="ghost" size="sm" className="cursor-pointer text-red-400 hover:bg-red-500/10 hover:text-red-300" data-testid="chatgpt-disconnect" disabled={busy || status.pending || !managedPresent} onClick={() => showDialog({ ...dialog, confirm: true })}>Disconnect</Button>
<Button variant="ghost" size="sm" className="cursor-pointer text-red-400 hover:bg-red-500/10 hover:text-red-300" data-testid="chatgpt-disconnect" disabled={busy || status.pending || !managedPresent} onClick={() => showDialog({ ...dialog, confirm: true })}>{t("Disconnect")}</Button>
</div>}>
{dialog.kind === "manage" && managedPresent && managed && !managed.connected && managed.canSignInAgain === true && status.available && <Button variant="outline" size="sm" disabled={busy || status.pending || !status.available} onClick={() => openConnect(managed.id)}>Sign in again</Button>}
<Button variant={dialog.kind === "manage" ? "outline" : "ghost"} size="sm" onClick={close} disabled={busy && operation.current !== "login"}>{dialog.kind === "connect" ? "Cancel" : "Close"}</Button>
{dialog.kind === "manage" && managedPresent && managed && !managed.connected && managed.canSignInAgain === true && status.available && <Button variant="outline" size="sm" disabled={busy || status.pending || !status.available} onClick={() => openConnect(managed.id)}>{t("Sign in again")}</Button>}
<Button variant={dialog.kind === "manage" ? "outline" : "ghost"} size="sm" onClick={close} disabled={busy && operation.current !== "login"}>{dialog.kind === "connect" ? t("Cancel") : t("Close")}</Button>
{dialog.kind === "connect" && <ContinueButton onClick={() => void login()} disabled={!status.available || busy || status.pending} testid="chatgpt-proceed" />}
</ConnectionFooter>
</>}
@@ -314,38 +317,41 @@ export function ChatGPTUIProvider({ children }: { children: React.ReactNode }) {
}
function ContinueButton({ onClick, disabled, testid = "chatgpt-login" }: { onClick: () => void; disabled: boolean; testid?: string }) {
const { t } = useI18n();
return <Button type="button" variant="outline" size="sm" data-testid={testid} onClick={onClick} disabled={disabled} className="cursor-pointer disabled:cursor-not-allowed">
{/* Official unmodified mark; existing secondary button hover/focus treatment. */}
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src="/siwc/chatgpt-logo-white.svg" width="16" height="16" alt="" aria-hidden="true" />
Continue with ChatGPT
</Button>;
{t("Continue with ChatGPT")}</Button>;
}
function AccountDialog({ children, onClose, busy }: { children: React.ReactNode; onClose: () => void; busy: boolean }) {
return <ConnectionDialog label="ChatGPT account" testid="chatgpt-account-dialog" backdropTestid="chatgpt-dialog-backdrop" onClose={onClose} busy={busy}>{children}</ConnectionDialog>;
const { t } = useI18n();
return <ConnectionDialog label={t("ChatGPT account")} testid="chatgpt-account-dialog" backdropTestid="chatgpt-dialog-backdrop" onClose={onClose} busy={busy}>{children}</ConnectionDialog>;
}
/** Shared compact settings/setup row; account selection precedes the quiet action. */
export function ChatGPTConnection(_props: { setup?: boolean } = {}) {
const { t } = useI18n();
const ui = useContext(Context);
const active = ui.status.accounts.find((a) => a.id === ui.status.activeId && a.connected);
const accounts = ui.status.accounts.filter((a) => a.connected);
return <div className="flex flex-col gap-2" data-testid="chatgpt-connection">
<ConnectionRow label="ChatGPT" actionTestid={active ? undefined : "chatgpt-login"} action={active ? "Manage…" : "Connect"} disabled={!ui.status.available || ui.busy || ui.status.pending} onAction={() => active ? ui.manage(active.id) : ui.connect()}>
{active && <select aria-label="ChatGPT account" value={active.id} disabled={ui.busy || ui.status.pending} onChange={(event) => ui.select(event.target.value)} className="min-w-0 rounded-sm border border-border bg-background px-2 py-1 text-xs text-foreground">
{accounts.map((a) => <option key={a.id} value={a.id}>{a.email || "ChatGPT account"}</option>)}
<ConnectionRow label="ChatGPT" actionTestid={active ? undefined : "chatgpt-login"} action={active ? t("Manage…") : t("Connect")} disabled={!ui.status.available || ui.busy || ui.status.pending} onAction={() => active ? ui.manage(active.id) : ui.connect()}>
{active && <select aria-label={t("ChatGPT account")} value={active.id} disabled={ui.busy || ui.status.pending} onChange={(event) => ui.select(event.target.value)} className="min-w-0 rounded-sm border border-border bg-background px-2 py-1 text-xs text-foreground">
{accounts.map((a) => <option key={a.id} value={a.id}>{a.email || t("ChatGPT account")}</option>)}
</select>}
</ConnectionRow>
{ui.inlineError && <p role="alert" className="text-xs text-red-400">{ui.inlineError}</p>}
{ui.warning && <div role="alert" data-testid="chatgpt-revocation-warning" className="rounded-sm border border-border px-3 py-2 text-xs text-muted-foreground">{ui.warning}<button type="button" className="ml-2 cursor-pointer underline underline-offset-2" onClick={ui.dismissWarning}>Dismiss</button></div>}
{ui.warning && <div role="alert" data-testid="chatgpt-revocation-warning" className="rounded-sm border border-border px-3 py-2 text-xs text-muted-foreground">{ui.warning}<button type="button" className="ml-2 cursor-pointer underline underline-offset-2" onClick={ui.dismissWarning}>{t("Dismiss")}</button></div>}
</div>;
}
/** Contextual consent discovery belongs beside background model choices only. */
export function ChatGPTBackgroundAccess({ provider }: { provider: string | undefined }) {
const { t } = useI18n();
const ui = useContext(Context);
const account: Account | undefined = ui.status.accounts.find((a) => a.id === ui.status.activeId && a.connected);
if (provider !== "chatgpt" || !account || ui.status.allowBackgroundUse) return null;
return <Button type="button" size="xs" variant="ghost" className="cursor-pointer" disabled={ui.busy} onClick={() => ui.manage(account.id)}>Enable background use</Button>;
return <Button type="button" size="xs" variant="ghost" className="cursor-pointer" disabled={ui.busy} onClick={() => ui.manage(account.id)}>{t("Enable background use")}</Button>;
}
+4 -1
View File
@@ -1,14 +1,17 @@
"use client";
import { useI18n } from "@/components/i18n";
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 }) {
const { t } = useI18n();
return <div className="flex flex-wrap items-center gap-3" data-testid={testid}>
<span className="font-ui text-xs text-foreground">{label}</span>
{children}
<Button type="button" size="xs" variant={action === "Connect" ? "outline" : "ghost"} className={`cursor-pointer disabled:cursor-not-allowed ${action === "Connect" ? "" : "text-muted-foreground hover:text-foreground"}`} data-testid={actionTestid} disabled={disabled} onClick={onAction}>{action}</Button>
<Button type="button" size="xs" variant={action === t("Connect") ? "outline" : "ghost"} className={`cursor-pointer disabled:cursor-not-allowed ${action === t("Connect") ? "" : "text-muted-foreground hover:text-foreground"}`} data-testid={actionTestid} disabled={disabled} onClick={onAction}>{action}</Button>
</div>;
}
+13 -7
View File
@@ -1,4 +1,6 @@
"use client";
import { useI18n } from "@/components/i18n";
/**
* Thin settings primitives (settings-app wave): the control kit the
* settings dialog needs. Sections → groups → rows; everything SSRs clean
@@ -25,10 +27,11 @@ export function SettingsSection({
children: React.ReactNode;
testid?: string;
}) {
const { t } = useI18n();
return (
<section data-testid={testid} className="px-6 py-5">
<h2 className="text-sm uppercase tracking-widest text-foreground">{title}</h2>
{hint && <p className="mt-1 text-xs text-muted-foreground">{hint}</p>}
<h2 className="text-sm uppercase tracking-widest text-foreground">{t(title)}</h2>
{hint && <p className="mt-1 text-xs text-muted-foreground">{t(hint)}</p>}
<div className="mt-4 flex flex-col gap-3">{children}</div>
</section>
);
@@ -45,9 +48,10 @@ export function SettingsGroup({
children: React.ReactNode;
testid?: string;
}) {
const { t } = useI18n();
return (
<div data-testid={testid} className="mt-5 border-t border-border/60 pt-4 first:mt-0 first:border-t-0 first:pt-0">
<p className="mb-2 text-xs uppercase tracking-widest text-muted-foreground">{label}</p>
<p className="mb-2 text-xs uppercase tracking-widest text-muted-foreground">{t(label)}</p>
<div className="flex flex-col gap-2">{children}</div>
</div>
);
@@ -70,11 +74,12 @@ export function SettingsRow({
* control is inert (parent off, no file yet, …). */
dimmed?: boolean;
}) {
const { t } = useI18n();
return (
<div data-testid={testid} className={cn("flex items-center justify-between gap-4 py-1", dimmed && "opacity-40")}>
<span className="min-w-0">
<span className="block font-prose text-(length:--lh-prose-size)">{label}</span>
{hint && <span className="block text-xs text-muted-foreground/70">{hint}</span>}
<span className="block font-prose text-(length:--lh-prose-size)">{t(label)}</span>
{hint && <span className="block text-xs text-muted-foreground/70">{t(hint)}</span>}
</span>
{children}
</div>
@@ -102,13 +107,14 @@ export function Toggle({
/** Optional native tooltip on the switch. */
title?: string;
}) {
const { t } = useI18n();
return (
<button
type="button"
role="switch"
aria-checked={checked}
aria-label={label}
{...(title ? { title } : {})}
aria-label={t(label)}
{...(title ? { title: t(title) } : {})}
disabled={disabled}
data-testid={`toggle-${label.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`}
onClick={() => onChange(!checked)}
+12 -13
View File
@@ -1,4 +1,6 @@
"use client";
import { useI18n } from "@/components/i18n";
/**
* The Keyboard section (thin settings wave): view / rebind / reset over
* core/keyboard.ts's registry. The overrides persist in localStorage
@@ -48,6 +50,7 @@ export function nextOverrides(
}
export function KeyboardSection() {
const { t } = useI18n();
const [overrides, setOverrides] = useState<Partial<Record<KeyAction, string>>>({});
const [rebinding, setRebinding] = useState<KeyAction | null>(null);
const [nonce, setNonce] = useState(0);
@@ -101,20 +104,20 @@ export function KeyboardSection() {
if (!actions.length) return null;
return (
<div key={scope} data-testid={`kbd-scope-${scope}`}>
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">{label}</p>
<p className="mb-1 text-xs uppercase tracking-widest text-muted-foreground/70">{t(label)}</p>
<div className="flex flex-col gap-2">
{actions.map((def) => {
const effective = overrides[def.id] ?? def.binding;
return (
<SettingsRow
key={def.id}
label={def.label}
hint={def.displayOnly ? "Fixed — part of this screen" : undefined}
label={t(def.label)}
hint={def.displayOnly ? t("Fixed — part of this screen") : undefined}
testid={`kbd-row-${def.id}`}
>
<span className="flex items-center gap-2">
<kbd className="rounded-sm border border-border bg-muted px-1.5 py-0.5 font-ui text-xs">
{rebinding === def.id ? "Press keys…" : formatBinding(effective)}
{rebinding === def.id ? t("Press keys…") : t(formatBinding(effective))}
</kbd>
{def.displayOnly ? null : rebinding === def.id ? (
<button
@@ -122,8 +125,7 @@ export function KeyboardSection() {
onClick={() => setRebinding(null)}
className="text-xs text-muted-foreground/70 underline-offset-2 hover:text-foreground hover:underline"
>
Cancel
</button>
{t("Cancel")}</button>
) : (
<>
<button
@@ -132,8 +134,7 @@ export function KeyboardSection() {
data-testid={`kbd-rebind-${def.id}`}
className="text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
>
Rebind
</button>
{t("Rebind")}</button>
{overridden(def.id) && (
<button
type="button"
@@ -141,8 +142,7 @@ export function KeyboardSection() {
data-testid={`kbd-reset-${def.id}`}
className="text-xs text-muted-foreground/70 underline-offset-2 hover:text-foreground hover:underline"
>
Reset
</button>
{t("Reset")}</button>
)}
</>
)}
@@ -155,15 +155,14 @@ export function KeyboardSection() {
);
})}
<div className="mt-1 flex items-center justify-between">
<span className="text-xs text-muted-foreground/70">Stored on this device (lh:keymap) — overrides only.</span>
<span className="text-xs text-muted-foreground/70">{t("Stored on this device (lh:keymap) — overrides only.")}</span>
<button
type="button"
onClick={resetAll}
data-testid="kbd-reset-all"
className="text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
>
Reset all to defaults
</button>
{t("Reset all to defaults")}</button>
</div>
</>
);
+28 -27
View File
@@ -1,4 +1,7 @@
"use client";
import { translator, type Translator } from "@/src/core";
import { useI18n } from "@/components/i18n";
/**
* The Keys section (wave-5 polish, 2026-09-21 — owner design): a MINIMAL
* key-value table. Provider left, masked key right, no description hints
@@ -98,11 +101,11 @@ export function classifyKeys(
/** The minimal status line, e.g. "…ab12 · 64 chars" (" · env" marks an
* environment-owned value — the row itself is read-only then). Pure. */
export function keyStatusLine(status: AuthKeyStatus): string {
if (!status.present || !status.masked) return "not set";
export function keyStatusLine(status: AuthKeyStatus, t: Translator = translator("en")): string {
if (!status.present || !status.masked) return t("not set");
const tail = status.masked.replace(/ \((\d+) chars\)$/, "");
const chars = status.masked.match(/\((\d+) chars\)$/)?.[1] ?? "?";
return `${tail} · ${chars}${status.source === "env" ? " · env" : ""}`;
return `${tail} · ${chars}${status.source === "env" ? t(" · env") : ""}`;
}
/** One table row: label left, tiny docs link + status right. Writable
@@ -132,6 +135,7 @@ function KeyTableRow({
onCancel: () => void;
testid: string;
}) {
const { t } = useI18n();
const envOwned = status.source === "env";
const [value, setValue] = useState("");
const [error, setError] = useState<string | null>(null);
@@ -163,8 +167,8 @@ function KeyTableRow({
onKeyDown={(e) => {
if (e.key === "Enter") void save();
}}
placeholder="Paste key…"
aria-label={`${label} key`}
placeholder={t("Paste key…")}
aria-label={t("{v0} key", { v0: label })}
data-testid={`${testid}-input`}
disabled={busy}
autoFocus
@@ -177,8 +181,7 @@ function KeyTableRow({
data-testid={`${testid}-save`}
className="shrink-0 text-xs text-foreground underline-offset-2 hover:underline disabled:text-muted-foreground/40 disabled:no-underline"
>
Save
</button>
{t("Save")}</button>
<button
type="button"
onClick={onCancel}
@@ -186,8 +189,7 @@ function KeyTableRow({
data-testid={`${testid}-cancel`}
className="shrink-0 text-xs text-muted-foreground/70 underline-offset-2 hover:text-foreground hover:underline"
>
Cancel
</button>
{t("Cancel")}</button>
{status.present && status.source === "file" && onDelete && (
<button
type="button"
@@ -196,13 +198,12 @@ function KeyTableRow({
data-testid={`${testid}-delete`}
className="shrink-0 text-xs text-muted-foreground/70 underline-offset-2 hover:text-red-500 hover:underline"
>
Delete
</button>
{t("Delete")}</button>
)}
</div>
{error && (
<p role="alert" data-testid={`${testid}-error`} className="px-1 text-xs text-red-500">
{error}
{t(error)}
</p>
)}
</div>
@@ -230,17 +231,16 @@ function KeyTableRow({
onClick={(e) => e.stopPropagation()}
className="text-[10px] text-muted-foreground/60 underline-offset-2 hover:text-foreground hover:underline"
>
key ↗
</a>
{t("key ↗")}</a>
)}
<span data-testid={`${testid}-status`} className="font-mono text-[11px] text-muted-foreground">
{keyStatusLine(status)}
{keyStatusLine(status, t)}
</span>
</span>
</button>
{error && (
<p role="alert" data-testid={`${testid}-error`} className="pl-6 text-xs text-red-500">
{error}
{t(error)}
</p>
)}
</div>
@@ -256,6 +256,7 @@ function AddProviderRow({
addable: ProviderKeyInfo[];
onPick: (p: ProviderKeyInfo) => void;
}) {
const { t } = useI18n();
const [open, setOpen] = useState(false);
const anchorRef = useRef<HTMLDivElement>(null);
@@ -290,7 +291,7 @@ function AddProviderRow({
onClick={() => setOpen((v) => !v)}
className="flex w-full items-center justify-between gap-3 rounded-sm px-1 py-1.5 text-left font-ui text-xs text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
>
<span>+ Add provider key</span>
<span>{t("+ Add provider key")}</span>
{addable.length > 0 && <span className="font-mono text-[11px]">{addable.length}</span>}
</button>
{open && (
@@ -324,6 +325,7 @@ export function KeysSection({
}: {
initialRow?: string;
}) {
const { t } = useI18n();
const [statuses, setStatuses] = useState<AuthKeyStatus[] | null>(null);
const [providers, setProviders] = useState<ProviderKeyInfo[] | undefined>(undefined);
const [loading, setLoading] = useState(true);
@@ -397,7 +399,7 @@ export function KeysSection({
}
if (loading || statuses === null) {
return <p className="px-6 py-5 text-xs text-muted-foreground/70">Loading keys…</p>;
return <p className="px-6 py-5 text-xs text-muted-foreground/70">{t("Loading keys…")}</p>;
}
const { providerRows, toolRows, unknownRows, addable } = classifyKeys(statuses, providers);
@@ -413,7 +415,7 @@ export function KeysSection({
return (
<>
<SettingsGroup label="Model API keys" testid="group-provider-keys">
<SettingsGroup label={t("Model API keys")} testid="group-provider-keys">
{providerRows.map((status) => (
<KeyTableRow
key={status.id}
@@ -455,7 +457,7 @@ export function KeysSection({
</div>}
</SettingsGroup>
<SettingsGroup label="Subscriptions" testid="group-subscriptions">
<SettingsGroup label={t("Subscriptions")} testid="group-subscriptions">
<SubscriptionConnections />
</SettingsGroup>
@@ -497,6 +499,7 @@ function AddProviderEditor({
onCancel: () => void;
error: string | null;
}) {
const { t } = useI18n();
const [value, setValue] = useState("");
return (
<>
@@ -507,8 +510,8 @@ function AddProviderEditor({
onKeyDown={(e) => {
if (e.key === "Enter" && value.trim()) onSave(value);
}}
placeholder="Paste key…"
aria-label={`${provider.label} key`}
placeholder={t("Paste key…")}
aria-label={t("{v0} key", { v0: provider.label })}
data-testid={`key-${provider.id}-input`}
autoFocus
className="h-7 min-w-0 flex-1 rounded-sm border border-border bg-background px-1.5 font-mono text-xs text-foreground outline-none placeholder:text-muted-foreground/60 focus:border-muted-foreground/50"
@@ -520,19 +523,17 @@ function AddProviderEditor({
data-testid={`key-${provider.id}-save`}
className="shrink-0 text-xs text-foreground underline-offset-2 hover:underline disabled:text-muted-foreground/40 disabled:no-underline"
>
Save
</button>
{t("Save")}</button>
<button
type="button"
onClick={onCancel}
data-testid={`key-${provider.id}-cancel`}
className="shrink-0 text-xs text-muted-foreground/70 underline-offset-2 hover:text-foreground hover:underline"
>
Cancel
</button>
{t("Cancel")}</button>
{error && (
<p role="alert" className="w-full pl-0 text-xs text-red-500" data-testid={`key-${provider.id}-error`}>
{error}
{t(error)}
</p>
)}
</>
+30 -23
View File
@@ -1,4 +1,6 @@
"use client";
import { useI18n } from "@/components/i18n";
/**
* The model menu (extracted 2026-09-20 from model-picker.tsx, owner ask:
* the agent settings' role selects use the EXACT same dropdown as the
@@ -53,6 +55,7 @@ export function ModelMenuList({
/** Quiet footer note under the list (context-specific). */
footer?: string;
}) {
const { t, language } = useI18n();
const [query, setQuery] = useState("");
const [menuIdx, setMenuIdx] = useState<number | null>(null);
const searchRef = useRef<HTMLInputElement>(null);
@@ -104,12 +107,12 @@ export function ModelMenuList({
}
}
}}
placeholder="Search models…"
placeholder={t("Search models…")}
className="lh-input mb-1.5 w-full rounded-lg border bg-background px-2 py-1.5 text-foreground outline-none focus:ring-1 focus:ring-ring"
/>
{!models && <div className="px-2 py-3 text-center text-muted-foreground">Loading models…</div>}
{!models && <div className="px-2 py-3 text-center text-muted-foreground">{t("Loading models…")}</div>}
{models && results.length === 0 && (
<div className="px-2 py-3 text-center text-muted-foreground">No models match.</div>
<div className="px-2 py-3 text-center text-muted-foreground">{t("No models match.")}</div>
)}
<ul ref={listRef} data-testid="model-list" className="flex max-h-72 flex-col overflow-y-auto px-1">
{results.map((m, i) => (
@@ -125,13 +128,13 @@ export function ModelMenuList({
>
<span className="flex items-center justify-between gap-2">
<span className="truncate text-card-foreground">{m.name}</span>
<span className="shrink-0 tabular-nums text-muted-foreground" title={subscriptionLabel(`${m.provider}:${m.id}`) ? "Subscription connection" : "USD per 1M tokens in/out"}>
<span className="shrink-0 tabular-nums text-muted-foreground" title={subscriptionLabel(`${m.provider}:${m.id}`) ? t("Subscription connection") : t("USD per 1M tokens in/out")}>
{subscriptionLabel(`${m.provider}:${m.id}`) ?? priceLabel(m.cost)}
</span>
</span>
<span className="flex items-center justify-between gap-2 text-muted-foreground">
<span className="truncate">{subscriptionLabel(`${m.provider}:${m.id}`) ? `${subscriptionLabel(`${m.provider}:${m.id}`)} (subscription)` : m.provider} · {m.id}</span>
<span className="shrink-0 tabular-nums">{formatTokens(m.contextWindow)}</span>
<span className="truncate">{subscriptionLabel(`${m.provider}:${m.id}`) ? t("{v0} (subscription)", { v0: subscriptionLabel(`${m.provider}:${m.id}`) }) : m.provider} · {m.id}</span>
<span className="shrink-0 tabular-nums">{formatTokens(m.contextWindow, language)}</span>
</span>
</button>
</li>
@@ -160,22 +163,23 @@ export function ThinkingMenuList({
empty?: string;
footer?: string;
}) {
const { t } = useI18n();
return (
<>
{levels.length === 0 ? (
<div className="px-2 py-3 text-center text-muted-foreground">{empty ?? "No thinking levels."}</div>
<div className="px-2 py-3 text-center text-muted-foreground">{empty ?? t("No thinking levels.")}</div>
) : (
levels.map((level) => (
<button
key={level}
key={t(level)}
type="button"
data-testid={`thinking-option-${level}`}
data-testid={`thinking-option-${t(level)}`}
onClick={() => onPick(level)}
className={`flex items-center justify-between rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-muted ${
level === effectiveLevel ? "bg-muted/60 text-card-foreground" : "text-card-foreground"
}`}
>
<span>{level}</span>
<span>{t(level)}</span>
{level === effectiveLevel && <span aria-hidden>✓</span>}
</button>
))
@@ -199,6 +203,7 @@ export function ProviderMenuList({
providers: { id: string; envVar: string; label: string }[];
onPick: (provider: { id: string; envVar: string; label: string }) => void;
}) {
const { t } = useI18n();
const [query, setQuery] = useState("");
const [menuIdx, setMenuIdx] = useState<number | null>(null);
const searchRef = useRef<HTMLInputElement>(null);
@@ -248,11 +253,11 @@ export function ProviderMenuList({
}
}
}}
placeholder="Search providers…"
placeholder={t("Search providers…")}
className="lh-input mb-1.5 w-full rounded-lg border bg-background px-2 py-1.5 text-foreground outline-none focus:ring-1 focus:ring-ring"
/>
{results.length === 0 && (
<div className="px-2 py-3 text-center text-muted-foreground">No providers match.</div>
<div className="px-2 py-3 text-center text-muted-foreground">{t("No providers match.")}</div>
)}
<ul ref={listRef} data-testid="provider-list" className="flex max-h-72 flex-col overflow-y-auto px-1">
{results.map((p, i) => (
@@ -283,7 +288,7 @@ export function ProviderMenuList({
* with the default first and a searched list drops it honestly — Enter
* can never pick a row that isn't on screen. Pure — exported for
* tests. */
export function fontMenuResults(query: string, families: string[]): Array<string | null> {
export function fontMenuResults(query: string, families: string[], defaultFamily = "Source Sans 3"): Array<string | null> {
const scored = families
.map((f) => ({ f, s: fuzzyScore(query, f) }))
.filter((r) => r.s !== null)
@@ -291,7 +296,7 @@ export function fontMenuResults(query: string, families: string[]): Array<string
.map((r) => r.f);
// The default row's searchable identity: the factory family + the
// word "default" (the suffix it renders with).
const defaultScore = fuzzyScore(query, "Source Sans 3", "default");
const defaultScore = fuzzyScore(query, defaultFamily, "default");
if (query.trim() === "" || defaultScore !== null) return [null, ...scored];
return scored;
}
@@ -300,10 +305,10 @@ export function fontMenuResults(query: string, families: string[]): Array<string
* query that matches NO family becomes the "Use '<query>'" custom pick —
* a matching family is the better pick, so the action row only exists
* when there is nothing else to pick. Exported for tests. */
export function customFamilyFor(query: string, families: string[]): string | null {
export function customFamilyFor(query: string, families: string[], defaultFamily = "Source Sans 3"): string | null {
const trimmed = query.trim();
if (trimmed === "") return null;
return fontMenuResults(query, families).length === 0 ? trimmed : null;
return fontMenuResults(query, families, defaultFamily).length === 0 ? trimmed : null;
}
/** The reading-font dropdown body — ONE search field (owner ask
@@ -329,6 +334,7 @@ export function FontMenuList({
/** Quiet footer note under the list. */
footer?: string;
}) {
const { t, language } = useI18n();
const [query, setQuery] = useState("");
const [menuIdx, setMenuIdx] = useState<number | null>(null);
const searchRef = useRef<HTMLInputElement>(null);
@@ -343,10 +349,11 @@ export function FontMenuList({
listRef.current?.querySelector(`[data-idx="${menuIdx}"]`)?.scrollIntoView({ block: "nearest" });
}, [menuIdx]);
const results = fontMenuResults(query, families ?? []);
const defaultFamily = language === "ru" ? "Noto Sans" : "Source Sans 3";
const results = fontMenuResults(query, families ?? [], defaultFamily);
// The custom-family action row: only when a typed query matches
// nothing (a matching family is the better pick). Enter picks it.
const customFamily = customFamilyFor(query, families ?? []);
const customFamily = customFamilyFor(query, families ?? [], defaultFamily);
const walkable: Array<string | null> = customFamily !== null ? ["__custom__"] : results;
return (
@@ -378,10 +385,10 @@ export function FontMenuList({
}
}
}}
placeholder="Search fonts…"
placeholder={t("Search fonts…")}
className="lh-input mb-1.5 w-full rounded-lg border bg-background px-2 py-1.5 text-foreground outline-none focus:ring-1 focus:ring-ring"
/>
{!families && <div className="px-2 py-3 text-center text-muted-foreground">Loading fonts…</div>}
{!families && <div className="px-2 py-3 text-center text-muted-foreground">{t("Loading fonts…")}</div>}
<ul ref={listRef} data-testid="font-list" className="flex max-h-72 flex-col overflow-y-auto px-1">
{families &&
results.map((family, i) => {
@@ -398,7 +405,7 @@ export function FontMenuList({
i === menuIdx ? "bg-accent/40 ring-1 ring-inset ring-border" : ""
}${effective && i !== menuIdx ? " bg-muted/60" : ""}`}
>
<span className="truncate text-card-foreground">{family ?? "Source Sans 3"}</span>
<span className="truncate text-card-foreground">{family ?? (language === "ru" ? "Noto Sans" : "Source Sans 3")}</span>
<span className="shrink-0 text-muted-foreground">{isDefault ? "default" : effective && <span aria-hidden>✓</span>}</span>
</button>
</li>
@@ -415,8 +422,8 @@ export function FontMenuList({
menuIdx === 0 ? "bg-accent/40 ring-1 ring-inset ring-border" : ""
}`}
>
<span className="truncate text-card-foreground">Use “{customFamily}”</span>
<span className="shrink-0 text-muted-foreground">custom</span>
<span className="truncate text-card-foreground">{t("Use “")}{customFamily}”</span>
<span className="shrink-0 text-muted-foreground">{t("custom")}</span>
</button>
</li>
)}
+28 -22
View File
@@ -39,6 +39,7 @@ import {
type GraphSettings,
type UserSettings,
} from "@/src/core";
import { LanguageSelect, useI18n } from "@/components/i18n";
import { useAppearance } from "./appearance.tsx";
import { SettingsSection, SettingsRow, Toggle } from "./controls.tsx";
import { AgentSection } from "./agent-section.tsx";
@@ -144,6 +145,7 @@ export function SettingsDialogBody({
* retargets follow it exactly like initialSection below. */
initialRow?: string | null;
}) {
const { t, general, saveGeneral } = useI18n();
const { onAppearanceChange } = useAppearance();
const [record, setRecord] = useState<UserSettings | null | undefined>(
undefined,
@@ -232,6 +234,10 @@ export function SettingsDialogBody({
body: object,
) => {
setError(null);
if (section === "general") {
try { await saveGeneral(body); } catch (error) { setError(error instanceof Error ? error.message : "Could not save language settings"); }
return;
}
const res = await fetch(`/api/settings/${section}`, {
method: "PUT",
headers: { "content-type": "application/json" },
@@ -260,30 +266,30 @@ export function SettingsDialogBody({
if (section === "appearance")
onAppearanceChange(body as AppearanceSettings);
},
[onAppearanceChange],
[onAppearanceChange, saveGeneral, t],
);
return (
<div
role="dialog"
aria-modal="true"
aria-label="Settings"
aria-label={t("Settings")}
data-testid="settings-dialog"
className="settings-dialog-pop flex h-[620px] max-h-[85vh] w-[920px] max-w-[90vw] flex-col overflow-hidden rounded-md border border-border bg-card shadow-xl"
onClick={(e) => e.stopPropagation()}
>
{/* Header — the app's quiet CMU title language. */}
<header className="flex h-15 shrink-0 items-center gap-3 border-b border-border px-5">
<h2 className="font-title text-2xl tracking-tight">Settings</h2>
<h2 className="font-title text-2xl tracking-tight">{t("Settings")}</h2>
<Hint
// Esc closes the dialog (its own listener) — surface it.
label="Close"
label={t("Close")}
binding="escape"
side="left"
>
<button
type="button"
aria-label="Close settings"
aria-label={t("Close settings")}
data-testid="settings-close"
className="ml-auto size-7 rounded-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
onClick={onClose}
@@ -305,7 +311,7 @@ export function SettingsDialogBody({
{/* Left nav — text-only, the session-list mono language,
active = bg-accent. */}
<nav
aria-label="Settings sections"
aria-label={t("Settings sections")}
data-testid="settings-nav"
className="flex w-44 shrink-0 flex-col gap-1 border-r border-border p-2"
>
@@ -322,7 +328,7 @@ export function SettingsDialogBody({
}`}
onClick={() => setActive(s.id)}
>
{s.label}
{t(s.label)}
</button>
))}
</nav>
@@ -344,32 +350,32 @@ export function SettingsDialogBody({
className="m-4 rounded-sm border border-red-500/40 px-3 py-2 text-xs text-red-500"
data-testid="settings-error"
>
{error}
{t(error)}
</p>
)}
{record === undefined ? (
<p className="px-6 py-5 text-xs text-muted-foreground/70">
Loading settings…
</p>
{t("Loading settings…")}</p>
) : record === null ? (
<p className="px-6 py-5 text-xs text-muted-foreground/70">
Settings could not be loaded — refresh to retry.
</p>
{t("Settings could not be loaded — refresh to retry.")}</p>
) : (
<div>
{active === "general" && (
<SettingsSection
title="General"
title={t("General")}
testid="section-general"
>
<SettingsRow label={t("Interface language")} testid="row-language"><LanguageSelect field="language" /></SettingsRow>
<SettingsRow label={t("Speech recognition language")} testid="row-stt-language"><LanguageSelect field="sttLanguage" /></SettingsRow>
<SettingsRow
label="Auto-update"
label={t("Auto-update")}
hint={AUTO_UPDATE_HINT}
testid="row-auto-update"
>
<Toggle
checked={record.general?.autoUpdate ?? true}
label="auto update"
checked={general.autoUpdate ?? true}
label={t("auto update")}
onChange={(on) =>
void write("general", { autoUpdate: on })
}
@@ -378,13 +384,13 @@ export function SettingsDialogBody({
</SettingsSection>
)}
{active === "keys" && (
<SettingsSection title="Providers" testid="section-keys">
<SettingsSection title={t("Providers")} testid="section-keys">
<KeysSection initialRow={initialRow ?? undefined} />
</SettingsSection>
)}
{active === "agent" && (
<SettingsSection
title="Agent"
title={t("Agent")}
testid="section-agent"
>
<AgentSection
@@ -406,7 +412,7 @@ export function SettingsDialogBody({
)}
{active === "appearance" && (
<SettingsSection
title="Appearance"
title={t("Appearance")}
testid="section-appearance"
>
<AppearanceSection
@@ -419,7 +425,7 @@ export function SettingsDialogBody({
)}
{active === "graph" && (
<SettingsSection
title="Graph"
title={t("Graph")}
testid="section-graph"
>
<GraphSection
@@ -432,8 +438,8 @@ export function SettingsDialogBody({
)}
{active === "keyboard" && (
<SettingsSection
title="Keyboard"
hint="Stored on this device"
title={t("Keyboard")}
hint={t("Stored on this device")}
testid="section-keyboard"
>
<KeyboardSection />
@@ -1,4 +1,7 @@
"use client";
import { translator, type Translator } from "@/src/core";
import { useI18n } from "@/components/i18n";
import { createContext, useContext, useEffect, useRef, useState } from "react";
import { NATIVE_SUBSCRIPTIONS, type NativeSubscriptionProviderId, type NativeSubscriptionStatus } from "@/src/core";
import { Button } from "@/components/ui/button";
@@ -9,13 +12,14 @@ 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 subscriptionNotice(label: string, t: Translator = translator("en")): string { return t("Your prompts, tool results, and relevant session context are sent to {v0} 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.", { v0: label }); }
export function subscriptionDisconnectCopy(label: string, t: Translator = translator("en")): string { return t("Disconnect {v0} 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.", { v0: label }); }
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 { t } = useI18n();
const [statuses, setStatuses] = useState<NativeSubscriptionStatus[]>([]);
const [dialog, setDialog] = useState<NativeSubscriptionProviderId | null>(null);
const [view, setView] = useState<"notice" | "connection" | "manage">("notice");
@@ -81,58 +85,60 @@ export function NativeSubscriptionUIProvider({ children }: { children: React.Rea
const bridge = typeof window === "undefined" ? undefined : window.lh?.subscriptions;
return <Context.Provider value={{ statuses, busy: !!operation, open }}>
{children}
{dialog && descriptor && status && <ConnectionDialog key={`${dialog}:${view}:${confirm}`} label={`${descriptor.label} connection`} testid="subscription-connection-dialog" backdropTestid="subscription-dialog-backdrop" busy={busy} onClose={close}>
{dialog && descriptor && status && <ConnectionDialog key={`${dialog}:${view}:${confirm}`} label={t("{v0} connection", { v0: descriptor.label })} testid="subscription-connection-dialog" backdropTestid="subscription-dialog-backdrop" busy={busy} onClose={close}>
<h2 className="text-sm font-semibold text-foreground">{descriptor.label}</h2>
{confirm ? <>
<p className="mt-3 text-sm font-semibold text-red-400">Disconnect {descriptor.label}?</p>
<p className="mt-3 text-xs leading-relaxed text-muted-foreground">{subscriptionDisconnectCopy(descriptor.label)}</p>
<p className="mt-3 text-sm font-semibold text-red-400">{t("Disconnect")}{" "}{descriptor.label}?</p>
<p className="mt-3 text-xs leading-relaxed text-muted-foreground">{subscriptionDisconnectCopy(descriptor.label, t)}</p>
</> : view === "notice" ? <>
<p className="mt-3 text-xs leading-relaxed text-muted-foreground" data-testid="subscription-privacy-notice">{subscriptionNotice(descriptor.label)}</p>
{dialog === "github-copilot" && <p className="mt-3 text-xs leading-relaxed text-muted-foreground" data-testid="copilot-policy-notice">{COPILOT_POLICY_NOTICE}</p>}
<p className="mt-3 text-xs leading-relaxed text-muted-foreground" data-testid="subscription-privacy-notice">{subscriptionNotice(descriptor.label, t)}</p>
{dialog === "github-copilot" && <p className="mt-3 text-xs leading-relaxed text-muted-foreground" data-testid="copilot-policy-notice">{t(COPILOT_POLICY_NOTICE)}</p>}
</> : <>
<div className="mt-4 flex items-center gap-3 text-xs text-foreground">
<Toggle label="Allow background use" checked={management ? status.allowBackgroundUse : background} disabled={busy || !!operation || status.pending || !status.available} onChange={(enabled) => { setBackground(enabled); if (management && bridge) void control(() => bridge.consent(dialog, enabled)); else setBackgroundDirty(true); }} />
<span>Allow background use<span className="mt-1 block leading-relaxed text-muted-foreground">{SUBSCRIPTION_BACKGROUND_HINT}</span></span>
<Toggle label={t("Allow background use")} checked={management ? status.allowBackgroundUse : background} disabled={busy || !!operation || status.pending || !status.available} onChange={(enabled) => { setBackground(enabled); if (management && bridge) void control(() => bridge.consent(dialog, enabled)); else setBackgroundDirty(true); }} />
<span>{t("Allow background use")}<span className="mt-1 block leading-relaxed text-muted-foreground">{t(SUBSCRIPTION_BACKGROUND_HINT)}</span></span>
</div>
{!status.available && <p className="mt-3 text-xs text-muted-foreground">Subscription sign-in requires the desktop app's private server connection. API-key connections remain available here.</p>}
{!status.available && <p className="mt-3 text-xs text-muted-foreground">{t("Subscription sign-in requires the desktop app's private server connection. API-key connections remain available here.")}</p>}
{view === "connection" && interaction && <div className="mt-3 space-y-3 text-xs" data-testid="subscription-login-interaction">
{interaction.progress && <p role="status" className="text-muted-foreground">{interaction.progress}</p>}
{interaction.userCode && <p>Device code: <code className="select-text font-mono">{interaction.userCode}</code></p>}
{interaction.browser && <Button variant="outline" size="sm" disabled={busy} onClick={() => bridge && void bridge.open(dialog, interaction.attemptId, interaction.browser!.id).catch(() => setError("The browser could not be opened. Try again."))}>Open browser</Button>}
{interaction.progress && <p role="status" className="text-muted-foreground">{t(interaction.progress)}</p>}
{interaction.userCode && <p>{t("Device code:")}{" "}<code className="select-text font-mono">{interaction.userCode}</code></p>}
{interaction.browser && <Button variant="outline" size="sm" disabled={busy} onClick={() => bridge && void bridge.open(dialog, interaction.attemptId, interaction.browser!.id).catch(() => setError("The browser could not be opened. Try again."))}>{t("Open browser")}</Button>}
{prompt && <form className="space-y-2" onSubmit={(event) => { event.preventDefault(); if (bridge) void bridge.respond(dialog, interaction.attemptId, prompt.id, promptValue).catch(() => setError(CONTROL_ERROR)); }}>
<label className="block" htmlFor="subscription-auth-prompt">{prompt.message}</label>
{prompt.type === "select" ? <select id="subscription-auth-prompt" value={promptValue} onChange={(event) => setPromptValue(event.target.value)} className="w-full rounded-sm border border-border bg-background px-2 py-1.5"><option value="" disabled>Select…</option>{prompt.options?.map((option) => <option key={option.id} value={option.id}>{option.label}</option>)}</select> : <input id="subscription-auth-prompt" type={prompt.type === "secret" ? "password" : "text"} autoComplete="off" value={promptValue} placeholder={prompt.placeholder} onChange={(event) => setPromptValue(event.target.value)} className="w-full rounded-sm border border-border bg-background px-2 py-1.5" />}
<Button type="submit" variant="outline" size="sm" disabled={busy || (prompt.type === "select" && !promptValue)}>Continue</Button>
<label className="block" htmlFor="subscription-auth-prompt">{t(prompt.message)}</label>
{prompt.type === "select" ? <select id="subscription-auth-prompt" value={promptValue} onChange={(event) => setPromptValue(event.target.value)} className="w-full rounded-sm border border-border bg-background px-2 py-1.5"><option value="" disabled>{t("Select…")}</option>{prompt.options?.map((option) => <option key={option.id} value={option.id}>{t(option.label)}</option>)}</select> : <input id="subscription-auth-prompt" type={prompt.type === "secret" ? "password" : "text"} autoComplete="off" value={promptValue} placeholder={prompt.placeholder ? t(prompt.placeholder) : undefined} onChange={(event) => setPromptValue(event.target.value)} className="w-full rounded-sm border border-border bg-background px-2 py-1.5" />}
<Button type="submit" variant="outline" size="sm" disabled={busy || (prompt.type === "select" && !promptValue)}>{t("Continue")}</Button>
</form>}
</div>}
</>}
{(error || status.error) && <p role="alert" className="mt-3 text-xs text-red-400">{error || status.error}</p>}
<ConnectionFooter testid="subscription-connection-footer" leading={!confirm && management && status.connectionId && !status.pending && <Button variant="ghost" size="sm" className="cursor-pointer text-red-400 hover:bg-red-500/10 hover:text-red-300" disabled={busy || !!operation} onClick={() => setConfirm(true)}>Disconnect</Button>}>
{(error || status.error) && <p role="alert" className="mt-3 text-xs text-red-400">{t(error || status.error || "")}</p>}
<ConnectionFooter testid="subscription-connection-footer" leading={!confirm && management && status.connectionId && !status.pending && <Button variant="ghost" size="sm" className="cursor-pointer text-red-400 hover:bg-red-500/10 hover:text-red-300" disabled={busy || !!operation} onClick={() => setConfirm(true)}>{t("Disconnect")}</Button>}>
{!confirm && management && status.connectionId && status.available && !status.connected && !!status.error && !status.pending && <>
{status.error && <Button variant="outline" size="sm" disabled={busy || !!operation} onClick={() => bridge && void control(() => bridge.retry(dialog))}>Retry</Button>}
<Button variant="outline" size="sm" disabled={!status.available || busy || !!operation} onClick={beginSignIn}>Sign in again</Button>
{status.error && <Button variant="outline" size="sm" disabled={busy || !!operation} onClick={() => bridge && void control(() => bridge.retry(dialog))}>{t("Retry")}</Button>}
<Button variant="outline" size="sm" disabled={!status.available || busy || !!operation} onClick={beginSignIn}>{t("Sign in again")}</Button>
</>}
<Button variant={!confirm && management ? "outline" : "ghost"} size="sm" disabled={busy} onClick={close}>{confirm || !management ? "Cancel" : "Close"}</Button>
{confirm ? <Button variant="destructive" size="sm" disabled={busy} onClick={() => bridge && void control(() => bridge.disconnect(dialog), true)}>Disconnect</Button> : view === "notice" ? <Button variant="outline" size="sm" disabled={!status.available || !!operation} onClick={() => setView("connection")}>Continue</Button> : view === "connection" && <Button variant="outline" size="sm" disabled={!status.available || !!operation || status.pending} onClick={() => void login()}>Connect</Button>}
<Button variant={!confirm && management ? "outline" : "ghost"} size="sm" disabled={busy} onClick={close}>{confirm || !management ? t("Cancel") : t("Close")}</Button>
{confirm ? <Button variant="destructive" size="sm" disabled={busy} onClick={() => bridge && void control(() => bridge.disconnect(dialog), true)}>{t("Disconnect")}</Button> : view === "notice" ? <Button variant="outline" size="sm" disabled={!status.available || !!operation} onClick={() => setView("connection")}>{t("Continue")}</Button> : view === "connection" && <Button variant="outline" size="sm" disabled={!status.available || !!operation || status.pending} onClick={() => void login()}>{t("Connect")}</Button>}
</ConnectionFooter>
</ConnectionDialog>}
</Context.Provider>;
}
export function NativeSubscriptionConnection({ providerId }: { providerId: NativeSubscriptionProviderId }) {
const { t } = useI18n();
const ui = useContext(Context), descriptor = NATIVE_SUBSCRIPTIONS.find((p) => p.providerId === providerId)!;
const status = ui.statuses.find((s) => s.providerId === providerId) ?? emptySubscriptionStatus(providerId);
return <div className="flex flex-col gap-2" data-testid={`${providerId}-connection`}>
<ConnectionRow label={descriptor.label} action={status.connectionId ? "Manage…" : "Connect"} disabled={ui.busy || !status.available || ui.statuses.some((s) => s.pending)} onAction={() => ui.open(providerId)} />
{status.error && <p role="alert" className="text-xs text-red-400">{status.error}</p>}
<ConnectionRow label={descriptor.label} action={status.connectionId ? t("Manage…") : t("Connect")} disabled={ui.busy || !status.available || ui.statuses.some((s) => s.pending)} onAction={() => ui.open(providerId)} />
{status.error && <p role="alert" className="text-xs text-red-400">{t(status.error)}</p>}
</div>;
}
export function SubscriptionConnections({ setup = false }: { setup?: boolean }) {
return <div className="space-y-3" data-testid="subscription-connections"><ChatGPTConnection setup={setup} />{NATIVE_SUBSCRIPTIONS.map((p) => <NativeSubscriptionConnection key={p.providerId} providerId={p.providerId} />)}</div>;
}
export function NativeSubscriptionBackgroundAccess({ provider }: { provider: string | undefined }) {
const { t } = useI18n();
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 <Button type="button" size="xs" variant="ghost" disabled={ui.busy} onClick={() => ui.open(descriptor.providerId)}>Enable background use</Button>;
return <Button type="button" size="xs" variant="ghost" disabled={ui.busy} onClick={() => ui.open(descriptor.providerId)}>{t("Enable background use")}</Button>;
}