From 0306b21e95024e7927df9ef3f21404d292b0977e Mon Sep 17 00:00:00 2001 From: Ilya Shcherbak Date: Fri, 20 Nov 2026 15:08:06 +0300 Subject: [PATCH] wizard-ui: add proxy banner and video setup flow --- README.md | 2 +- .../wizard-ui/.storybook/preview.tsx | 2 + .../src/agents/AgentConfiguration.tsx | 44 ++- .../src/agents/AgentConnectionPanel.tsx | 14 +- .../wizard-ui/src/agents/AgentPage.tsx | 23 +- .../src/agents/PreparedPlanDialog.tsx | 262 +++++++++++------- .../wizard-ui/src/agents/VideoConnection.tsx | 105 +++++-- .../wizard-ui/src/agents/agents_state.ts | 23 +- .../wizard-ui/src/design-system/patterns.css | 31 ++- .../wizard-ui/src/onboarding/SetupDialog.tsx | 119 +------- .../wizard-ui/src/onboarding/agents.tsx | 6 + .../wizard-ui/src/overview/Overview.css | 34 ++- .../wizard-ui/src/overview/Overview.tsx | 14 +- .../src/overview/SystemProxyBanner.tsx | 62 +++++ .../src/preview/Application.stories.tsx | 20 ++ .../wizard-ui/src/preview/Flows.stories.tsx | 39 ++- .../wizard-gui/wizard-ui/src/preview/mocks.ts | 4 +- .../wizard-ui/src/settings/SettingsPage.tsx | 8 +- .../src/settings/SystemProxyPrompt.tsx | 37 +-- .../wizard-ui/src/settings/system_proxy.ts | 37 ++- .../wizard-ui/src/test/flows.test.tsx | 157 +++++++++-- 21 files changed, 707 insertions(+), 336 deletions(-) create mode 100644 crates/wizard-gui/wizard-ui/src/overview/SystemProxyBanner.tsx diff --git a/README.md b/README.md index e7f0f61..fc60dc5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ An application for configuring agents to use CoreInfra. Start Wizard, sign in to CoreInfra Hub and select the Hub to charge. Keep Wizard running and ask for a video in a new ChatGPT Work or Codex chat, or invoke `$coreinfra-video`. Wizard automatically installs the skill and registers its MCP server at startup. -The bundled skill and the `coreinfra_video` MCP registration live in the profile selected by `CODEX_HOME`. Wizard listens at `http://127.0.0.1:33789/mcp` and publishes a new local bearer on each start. **ChatGPT / Codex → Видеомодели CoreInfra → Отключить** revokes local access and removes the managed registration and unmodified skill files. The opt-out persists across restarts. +The bundled skill and the `coreinfra_video` MCP registration live in the profile selected by `CODEX_HOME`. Wizard listens at `http://127.0.0.1:33789/mcp` and publishes a new local bearer on each start. Turning off **Подключить `coreinfra-video` для видео-моделей** under **Дополнительные модели** on the ChatGPT / Codex page revokes local access and removes the managed registration and unmodified skill files. The opt-out persists across restarts. `video_models` returns the public catalog and prices in RUB per second. `video_create` submits one paid job. Save the full returned `job` object and pass it to `video_result` to poll, including after restarting Wizard. The original Hub and key must still be available. A completed download returns a local MP4 in **Downloads/CoreInfra Video**. Use `download: false` to poll without creating a file. fal also returns its signed result URL in this mode. Repeating a submission after a network timeout can incur another charge. diff --git a/crates/wizard-gui/wizard-ui/.storybook/preview.tsx b/crates/wizard-gui/wizard-ui/.storybook/preview.tsx index 716254d..bde3d47 100644 --- a/crates/wizard-gui/wizard-ui/.storybook/preview.tsx +++ b/crates/wizard-gui/wizard-ui/.storybook/preview.tsx @@ -4,6 +4,7 @@ import { MotionConfig } from "motion/react"; import { startPreviewMocks, type Scenario } from "../src/preview/mocks"; import { initializeTheme, setTheme } from "../src/settings/theme"; import { SubscriptionTokenPreviewContext } from "../src/agents/connection_preview"; +import { systemProxyBannerDismissedKey } from "../src/overview/SystemProxyBanner"; import "../src/styles.css"; import "../src/components/BrandIcons.css"; @@ -99,6 +100,7 @@ const preview: Preview = { }, beforeEach(context) { const scenario = (context.parameters.scenario ?? "update") as Scenario; + localStorage.removeItem(systemProxyBannerDismissedKey); if (scenario !== "startup") localStorage.setItem("coreinfra.startup.seen", "true"); const environment = startPreviewMocks(scenario, { onboarding: context.parameters.onboarding }); diff --git a/crates/wizard-gui/wizard-ui/src/agents/AgentConfiguration.tsx b/crates/wizard-gui/wizard-ui/src/agents/AgentConfiguration.tsx index 9866f56..526b4ba 100644 --- a/crates/wizard-gui/wizard-ui/src/agents/AgentConfiguration.tsx +++ b/crates/wizard-gui/wizard-ui/src/agents/AgentConfiguration.tsx @@ -3,6 +3,7 @@ import { CheckIcon } from "@heroicons/react/20/solid"; import { type AgentChange, type AgentId, + type ConnectionDraft, type HubMode, type RoutingMode, type TokenChoice, @@ -35,6 +36,7 @@ import { ErrorText } from "../components/ErrorText"; import { useSystemProxy } from "../settings/system_proxy"; import { SystemProxyPrompt } from "../settings/SystemProxyPrompt"; import { SubscriptionTokenPreviewContext } from "./connection_preview"; +import { VideoConnection, useVideoConnection } from "./VideoConnection"; type ModeOption = { mode: M; @@ -273,7 +275,7 @@ export function RoutingFieldset({ note?: ReactNode; disabled: boolean; error?: string; - onPrepare: (change: AgentChange, token: TokenChoice | null) => void; + onPrepare: (draft: ConnectionDraft) => void; initialMode?: M; actions?: ReactNode; actionsClassName?: string; @@ -292,8 +294,12 @@ export function RoutingFieldset({ (token.selected?.kind === "create" || (token.selected?.kind === "existing" && token.selected.token !== agentToken)); - const changed = + const routingChanged = selected !== mode || (enabled && (needsApply || tokenChanged)); + const prepareRouting = !editing || routingChanged; + const showVideo = agent === "codex" || agent === "claude" || (agent === "claude_desktop" && selected === "hub"); + const video = useVideoConnection(showVideo); + const videoChanged = showVideo && video.needsApply; const systemProxy = useSystemProxy(); const [proxyPrompt, setProxyPrompt] = useState(false); @@ -307,14 +313,25 @@ export function RoutingFieldset({ setProxyPrompt(true); } + function prepare() { + const includeVideo = showVideo && (video.needsApply || (prepareRouting && video.enabled)); + onPrepare({ + agent, + routing: prepareRouting ? { + change: toChange(selected), + token: enabled && !proxyOnly ? (token.selected ?? null) : null, + } : undefined, + videoEnabled: includeVideo ? video.enabled : undefined, + }); + } + return ( <> - +
- {note && {note}} - + ({ ) )} + {showVideo && ( + + )} diff --git a/crates/wizard-gui/wizard-ui/src/agents/AgentConnectionPanel.tsx b/crates/wizard-gui/wizard-ui/src/agents/AgentConnectionPanel.tsx index c4f249c..03638c7 100644 --- a/crates/wizard-gui/wizard-ui/src/agents/AgentConnectionPanel.tsx +++ b/crates/wizard-gui/wizard-ui/src/agents/AgentConnectionPanel.tsx @@ -1,11 +1,11 @@ import { useEffect, useRef, useState } from "react"; -import { type AgentChange, type AgentId, type AgentStates, type PreparedAgentChange, type RoutingMode, type TokenChoice, prepareAgentChange } from "./agents_state"; +import { type AgentChange, type AgentId, type AgentStates, type ConnectionDraft, type ConnectionPlan, type RoutingMode, prepareAgentChange } from "./agents_state"; import { RoutingFieldset, hubModes, routingModes, type Hub } from "./AgentConfiguration"; import { PreparedPlanDialog } from "./PreparedPlanDialog"; import { MissingAgent } from "./MissingAgent"; import { useProxy } from "./proxy"; import { agentPageNames } from "./navigation"; -import { AgentIcon, choices } from "../onboarding/agents"; +import { AgentIcon, choices, launchChoiceFor } from "../onboarding/agents"; import { useHubTokens } from "../settings/hub_tokens"; import type { HubAccountControl } from "../settings/HubAccount"; import { Identity } from "../components/ui/Identity"; @@ -20,7 +20,7 @@ export function AgentConnectionPanel({ agent, agents, account, onBack }: { account: HubAccountControl; onBack: () => void; }) { - const [prepared, setPrepared] = useState(); + const [prepared, setPrepared] = useState(); const [preparing, setPreparing] = useState(false); const [error, setError] = useState(); const inFlight = useRef(false); @@ -40,12 +40,12 @@ export function AgentConnectionPanel({ agent, agents, account, onBack }: { const errors = detection.status === "error" ? [detection.data] : agent === "codex" && agents.codex.status === "found" ? [agents.codex.data.cli, agents.codex.data.desktop].flatMap(part => part.status === "error" ? [part.data] : []) : []; - async function prepare(change: AgentChange, token: TokenChoice | null) { + async function prepare(draft: ConnectionDraft) { if (inFlight.current || prepared) return; inFlight.current = true; setPreparing(true); setError(undefined); - try { setPrepared(await prepareAgentChange(change, token)); } + try { setPrepared(await prepareAgentChange(draft)); } catch (cause) { setError(typeof cause === "string" ? cause : "Не удалось подготовить изменения. Попробуйте ещё раз."); } finally { inFlight.current = false; setPreparing(false); } } @@ -70,12 +70,12 @@ export function AgentConnectionPanel({ agent, agents, account, onBack }: { needsApply={needsApply} disabled={busy || account.submitting} error={error} note={agent === "codex" ? "Настройка общая для ChatGPT и Codex." : undefined} actions={} - onPrepare={(change, token) => void prepare(change, token)} + onPrepare={prepare} /> : <> {detection.status === "not_found" && agent !== "claude_desktop" && } } - {prepared && setPrepared(undefined)} onApplied={onBack} applyLabel="Применить" />} ; } diff --git a/crates/wizard-gui/wizard-ui/src/agents/AgentPage.tsx b/crates/wizard-gui/wizard-ui/src/agents/AgentPage.tsx index b45f139..7da4c30 100644 --- a/crates/wizard-gui/wizard-ui/src/agents/AgentPage.tsx +++ b/crates/wizard-gui/wizard-ui/src/agents/AgentPage.tsx @@ -1,12 +1,11 @@ import { type ReactNode, useEffect, useRef, useState } from "react"; import { - type AgentChange, type AgentDetection, type AgentId, type AgentStates, type BackupAgent, - type PreparedAgentChange, - type TokenChoice, + type ConnectionDraft, + type ConnectionPlan, prepareAgentChange, } from "./agents_state"; import { @@ -18,7 +17,8 @@ import { import { PreparedPlanDialog } from "./PreparedPlanDialog"; import { BackupDialog } from "./BackupDialog"; import { DesktopVersion } from "./DesktopInstall"; -import { VideoConnection } from "./VideoConnection"; +import { StandaloneVideoConnection } from "./VideoConnection"; +import { launchChoiceFor } from "../onboarding/agents"; import { MissingAgent } from "./MissingAgent"; import { agentPageNames } from "./navigation"; import { useHubTokens } from "../settings/hub_tokens"; @@ -116,7 +116,7 @@ export function AgentPage({ proxy: ReturnType; account: HubAccountControl; }) { - const [preparedChange, setPreparedChange] = useState(); + const [preparedChange, setPreparedChange] = useState(); const [isPreparingPlan, setIsPreparingPlan] = useState(false); const [configurationRevision, setConfigurationRevision] = useState(0); const pageContent = useRef(null); @@ -155,14 +155,14 @@ export function AgentPage({ : null, ); - async function prepare(change: AgentChange, token: TokenChoice | null) { + async function prepare(draft: ConnectionDraft) { if (isChangeInProgress) return; setIsPreparingPlan(true); setError(undefined); try { - setPreparedChange(await prepareAgentChange(change, token)); + setPreparedChange(await prepareAgentChange(draft)); } catch (cause: unknown) { const message = "Не удалось подготовить изменения"; reportError(message, cause); @@ -252,7 +252,10 @@ export function AgentPage({ onPrepare={prepare} /> )} - + {codex.status !== "found" && ( + + )} {(codex.status === "not_found" || (codex.status === "found" && codex.data.cli.status === "not_found")) && ( )} @@ -292,9 +295,6 @@ export function AgentPage({ onPrepare={prepare} /> )} - {claude.status === "found" && claude.data.routing_mode === "hub" && ( - - )} ); break; @@ -403,6 +403,7 @@ export function AgentPage({ {preparedChange && ( setPreparedChange(undefined)} onApplied={() => setConfigurationRevision((value) => value + 1)} diff --git a/crates/wizard-gui/wizard-ui/src/agents/PreparedPlanDialog.tsx b/crates/wizard-gui/wizard-ui/src/agents/PreparedPlanDialog.tsx index 39987be..65a432f 100644 --- a/crates/wizard-gui/wizard-ui/src/agents/PreparedPlanDialog.tsx +++ b/crates/wizard-gui/wizard-ui/src/agents/PreparedPlanDialog.tsx @@ -1,143 +1,207 @@ -import { useState } from "react"; +import { type ReactNode, useEffect, useRef, useState } from "react"; +import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/react"; +import { ChevronRightIcon } from "@heroicons/react/16/solid"; +import { invoke } from "@tauri-apps/api/core"; import { - type PreparedAgentChange, + type ConnectionPlan, applyAgentPlan, + applyVideoConnection, prepareAgentChange, } from "./agents_state"; import { reportError } from "../logs/log"; import { ErrorText } from "../components/ErrorText"; import { Button } from "../components/catalyst/button"; -import { - Dialog, - DialogActions, - DialogBody, -} from "../components/catalyst/dialog"; +import { Dialog, DialogActions, DialogBody } from "../components/catalyst/dialog"; import { DialogHeader } from "../components/ui/DialogHeader"; -import { Text } from "../components/catalyst/text"; +import { Code, Text } from "../components/catalyst/text"; +import type { AgentChoice } from "../onboarding/agents"; import { agentPageNames } from "./navigation"; +const visibleSteps = 2; +const plural = new Intl.PluralRules("ru"); +function stepCount(count: number) { + const form = plural.select(count); + return count + " " + (form === "one" ? "шаг" : form === "few" ? "шага" : "шагов"); +} + +function PlanSteps({ plan }: { plan: ConnectionPlan }) { + const steps: ReactNode[] = (plan.routing?.info ?? []).map(step => step.description); + // Keep the choice from the form visible alongside the first routing action. + if (plan.videoEnabled !== undefined) { + steps.unshift(plan.videoEnabled + ? <>Установит скилл coreinfra-video для видео-моделей. + : <>Отключит видео-модели и удалит скилл coreinfra-video, установленный Wizard.); + } + const rows = steps.map((step, index) =>
  • {step}
  • ); + return ( + <> +
      {rows.slice(0, visibleSteps)}
    + {rows.length > visibleSteps && ( + + + {({ open }) => <> + + +
      {rows.slice(visibleSteps)}
    +
    +
    + )} + + ); +} + export function PreparedPlanDialog({ - prepared, - onReprepared, - onClose, - onApplied, + prepared, launchChoice, onReprepared, onClose, onApplied, applyLabel = "Завершить настройку", }: { - prepared: PreparedAgentChange; - onReprepared: (prepared: PreparedAgentChange) => void; + prepared: ConnectionPlan; + launchChoice: AgentChoice; + onReprepared: (prepared: ConnectionPlan) => void; onClose: () => void; onApplied?: () => void; applyLabel?: "Применить" | "Завершить настройку"; }) { - const { agent, info } = prepared; - const hasChanges = info.length > 0; - const [applying, setApplying] = useState(false); - const [repreparing, setRepreparing] = useState(false); + const { agent, routing, videoEnabled } = prepared; + const hasChanges = Boolean(routing?.info.length) || videoEnabled !== undefined; + const [operation, setOperation] = useState<"apply" | "prepare" | "launch">(); + const [routingApplied, setRoutingApplied] = useState(false); + const [applied, setApplied] = useState(false); const [error, setError] = useState(); - const busy = applying || repreparing; + const inFlight = useRef(false); + const success = useRef(null); + const busy = operation !== undefined; - async function reprepare() { - if (busy || !error) return; + useEffect(() => { + if (applied) success.current?.querySelector("h2")?.focus(); + }, [applied]); - setRepreparing(true); + function finish() { + onApplied?.(); + onClose(); + } + async function reprepare() { + if (inFlight.current || !routing || routingApplied) return; + inFlight.current = true; + setOperation("prepare"); try { - const token = - prepared.token === null - ? null - : { kind: "existing" as const, token: prepared.token }; - const next = await prepareAgentChange(prepared.change, token); + const token = routing.token === null ? null : { kind: "existing" as const, token: routing.token }; + const next = await prepareAgentChange({ agent, routing: { change: routing.change, token }, videoEnabled }); onReprepared(next); setError(undefined); - } catch (cause: unknown) { - const message = "Не удалось пересоздать план"; - reportError(message, cause); - setError( - `${message}: ${cause instanceof Error ? cause.message : String(cause)}. Показан прежний план. Часть изменений могла быть применена.`, - ); + } catch (cause) { + reportError("Не удалось пересоздать план", cause); + setError("Не удалось пересоздать план. " + String(cause)); } finally { - setRepreparing(false); + inFlight.current = false; + setOperation(undefined); } } async function apply() { - if (busy || !hasChanges) return; - - setApplying(true); + if (inFlight.current || !hasChanges || applied) return; + inFlight.current = true; + setOperation("apply"); setError(undefined); + let applyingVideo = false; + try { + if (routing?.info.length && !routingApplied) { + await applyAgentPlan(routing.plan); + setRoutingApplied(true); + } + if (videoEnabled !== undefined) { + // A routing plan may snapshot the same agent files. Finish it before changing video. + applyingVideo = true; + await applyVideoConnection(videoEnabled); + } + setApplied(true); + } catch (cause) { + const message = applyingVideo ? "Не удалось применить настройку видео." : "Не удалось применить изменения. Часть изменений могла быть применена."; + reportError(message, cause); + setError(message + " " + String(cause)); + } finally { + inFlight.current = false; + setOperation(undefined); + } + } + async function launch() { + if (inFlight.current) return; + inFlight.current = true; + setOperation("launch"); + setError(undefined); try { - await applyAgentPlan(prepared.plan); - onApplied?.(); - onClose(); - } catch (cause: unknown) { - const message = "Не удалось применить изменения"; + await invoke("launch_agent", { agent: launchChoice.id }); + finish(); + } catch (cause) { + const message = "Не удалось запустить " + launchChoice.name + "."; reportError(message, cause); - setError( - `${message}: ${cause instanceof Error ? cause.message : String(cause)}. Часть изменений могла быть применена.`, - ); + setError(message + " " + String(cause)); } finally { - setApplying(false); + inFlight.current = false; + setOperation(undefined); } } + function close() { + if (inFlight.current) return; + if (applied || !hasChanges) finish(); + else onClose(); + } + return ( - { - if (!busy) onClose(); - }} - > - - - {hasChanges ? ( -
      - {info.map((step, index) => ( -
    1. - {step.description} -
    2. - ))} -
    - ) : ( - Изменения не требуются. - )} - {error && ( -
    - {error} -
    - )} -
    + + {applied ? ( +
    + +
    + ) : ( + <> + + + {hasChanges ? : Изменения не требуются.} + + + )} + {error &&
    {error}
    } - - {error && ( - - )} - {hasChanges && ( - + ) : ( + <> + {error && routing && !routingApplied && ( + + )} + {hasChanges && } + )}
    diff --git a/crates/wizard-gui/wizard-ui/src/agents/VideoConnection.tsx b/crates/wizard-gui/wizard-ui/src/agents/VideoConnection.tsx index a9d638a..71994af 100644 --- a/crates/wizard-gui/wizard-ui/src/agents/VideoConnection.tsx +++ b/crates/wizard-gui/wizard-ui/src/agents/VideoConnection.tsx @@ -1,49 +1,94 @@ import { invoke } from "@tauri-apps/api/core"; import { useEffect, useState } from "react"; import { Button } from "../components/catalyst/button"; -import { Fieldset } from "../components/catalyst/fieldset"; -import { Text } from "../components/catalyst/text"; +import { Label } from "../components/catalyst/fieldset"; +import { Switch, SwitchField } from "../components/catalyst/switch"; +import { Code, Text } from "../components/catalyst/text"; +import { ActionBar, Panel } from "../components/ui/Layout"; +import { StateNotice } from "../components/ui/StateNotice"; import { ErrorText } from "../components/ErrorText"; +import type { ConnectionDraft } from "./agents_state"; type Status = { enabled: boolean; running: boolean; error: string | null }; -export function VideoConnection({ signedIn, disabled }: { signedIn: boolean; disabled: boolean }) { +export function useVideoConnection(available: boolean) { const [status, setStatus] = useState(); - const [busy, setBusy] = useState(false); + const [draft, setDraft] = useState(); const [error, setError] = useState(); const [revision, setRevision] = useState(0); + useEffect(() => { + if (!available) return; let active = true; - invoke("get_video_connection").then(result => { - if (active) setStatus(result); - }).catch(cause => { if (active) setError(String(cause)); }); + void invoke("get_video_connection").then(result => { + if (!active) return; + setStatus(result); + setError(undefined); + }, cause => { + if (!active) return; + setStatus(undefined); + setError(String(cause)); + }); return () => { active = false; }; - }, [revision]); + }, [available, revision]); - async function apply(enabled: boolean) { - setBusy(true); + const enabled = draft ?? status?.enabled; + const needsApply = !!status && (enabled !== status.enabled || (enabled && !status.running) || !!status.error); + function retry() { setError(undefined); - try { - await invoke("set_video_connection", { enabled }); - } catch (cause) { - setError(String(cause)); - } finally { - setRevision(value => value + 1); - setBusy(false); - } + setRevision(value => value + 1); } + return { status, enabled, needsApply, error, retry, setEnabled: setDraft }; +} - if (!status && !error) return null; +export function VideoConnection({ video, signedIn, disabled }: { + video: ReturnType; + signedIn: boolean; + disabled: boolean; +}) { + const { status, enabled, error } = video; + return ( + +
    + {status && ( + + + + + )} + {!status && !error && Проверяем подключение…} + {error && Повторить}>{error}} + {status?.running && !signedIn && Для генерации видео войдите в CoreInfra Hub.} + {status?.error && {status.error}} + {enabled && status?.enabled && !status.running && !status.error && ( + Видеосервис Wizard остановлен. Он запустится при применении настроек. + )} +
    +
    + ); +} - return
    - {status?.running && !signedIn && Для генерации войдите в CoreInfra Hub в Wizard.} - {status && !status.enabled && Видеомодели отключены.} - {(error || status?.error) && {error || status?.error}} - {status &&
    - {!status.running && } - {status.enabled && } -
    } -
    ; +// The shared video setting is also available when Codex is not installed. +export function StandaloneVideoConnection({ signedIn, disabled, error, onPrepare }: { + signedIn: boolean; + disabled: boolean; + error?: string; + onPrepare: (draft: ConnectionDraft) => void; +}) { + const video = useVideoConnection(true); + return ( +
    + + + + + {error && {error}} +
    + ); } diff --git a/crates/wizard-gui/wizard-ui/src/agents/agents_state.ts b/crates/wizard-gui/wizard-ui/src/agents/agents_state.ts index 379a176..9825a33 100644 --- a/crates/wizard-gui/wizard-ui/src/agents/agents_state.ts +++ b/crates/wizard-gui/wizard-ui/src/agents/agents_state.ts @@ -33,14 +33,33 @@ export type PreparedAgentChange = { // Values are secrets. export type TokenChoice = { kind: "existing"; token: string } | { kind: "create" }; -export function prepareAgentChange(change: AgentChange, token: TokenChoice | null): Promise { - return invoke("prepare_agent_change", { change, token }); +export type ConnectionDraft = { + agent: AgentId; + routing?: { change: AgentChange; token: TokenChoice | null }; + videoEnabled?: boolean; +}; + +export type ConnectionPlan = { + agent: AgentId; + routing?: PreparedAgentChange; + videoEnabled?: boolean; +}; + +export async function prepareAgentChange({ agent, routing, videoEnabled }: ConnectionDraft): Promise { + const prepared = routing + ? await invoke("prepare_agent_change", routing) + : undefined; + return { agent, routing: prepared, videoEnabled }; } export function applyAgentPlan(plan: PreparedPlan): Promise { return invoke("apply_agent_plan", { plan }); } +export function applyVideoConnection(enabled: boolean): Promise { + return invoke("set_video_connection", { enabled }); +} + export type BackupAgent = "codex" | "claude" | "claude_desktop"; export type Backup = { diff --git a/crates/wizard-gui/wizard-ui/src/design-system/patterns.css b/crates/wizard-gui/wizard-ui/src/design-system/patterns.css index c031119..6d59fe6 100644 --- a/crates/wizard-gui/wizard-ui/src/design-system/patterns.css +++ b/crates/wizard-gui/wizard-ui/src/design-system/patterns.css @@ -203,7 +203,7 @@ .ui-choice [data-slot="label"] { cursor: pointer; } -.agent-routing-options { +.agent-connection-options { display: grid; gap: var(--ui-space-5); padding: var(--ui-space-5); @@ -211,8 +211,35 @@ border-radius: var(--ui-radius-control); background: var(--ui-surface); } -.agent-routing-options > * { margin-block: 0; } +.agent-connection-options > * { margin-block: 0; } .agent-routing-option [data-slot="label"] { cursor: pointer; } +.agent-plan-steps { + display: grid; + gap: var(--ui-space-2); + padding-inline-start: var(--ui-space-5); + list-style: disc; + overflow-wrap: anywhere; +} +.agent-plan-steps li::marker { color: var(--ui-ink-subtle); } +.agent-plan-steps [data-slot="text"] { color: var(--ui-ink); } +.agent-plan-steps code { white-space: nowrap; } +.agent-plan-disclosure { + display: inline-flex; + align-items: center; + gap: var(--ui-space-1); + min-height: 32px; + margin-top: var(--ui-space-2); + border-radius: var(--ui-radius-control); + color: var(--ui-ink); + font-size: 14px; + font-weight: 500; + cursor: pointer; +} +.agent-plan-disclosure svg { width: 16px; height: 16px; } +.agent-plan-disclosure[aria-expanded="true"] svg { transform: rotate(90deg); } +.agent-plan-disclosure:hover { text-decoration: underline; text-underline-offset: 3px; } +.agent-plan-disclosure:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 2px; } +.agent-plan-disclosure + div { margin-top: var(--ui-space-1); } .ui-setting-list { display: grid; gap: var(--ui-space-6); diff --git a/crates/wizard-gui/wizard-ui/src/onboarding/SetupDialog.tsx b/crates/wizard-gui/wizard-ui/src/onboarding/SetupDialog.tsx index ee38df5..69dbe33 100644 --- a/crates/wizard-gui/wizard-ui/src/onboarding/SetupDialog.tsx +++ b/crates/wizard-gui/wizard-ui/src/onboarding/SetupDialog.tsx @@ -1,14 +1,12 @@ -import { invoke } from "@tauri-apps/api/core"; import { useCallback, useEffect, useRef, useState } from "react"; import { Button } from "../components/catalyst/button"; import { Dialog } from "../components/catalyst/dialog"; import { DialogHeader } from "../components/ui/DialogHeader"; -import { ActionBar, ViewTransition } from "../components/ui/Layout"; +import { ViewTransition } from "../components/ui/Layout"; import { Identity } from "../components/ui/Identity"; import { Field, Label } from "../components/catalyst/fieldset"; import { Select } from "../components/catalyst/select"; import { Text } from "../components/catalyst/text"; -import { ErrorText } from "../components/ErrorText"; import type { HubAccountControl } from "../settings/HubAccount"; import { hubDisplayName } from "../settings/hub_account"; import { useHubTokens } from "../settings/hub_tokens"; @@ -19,9 +17,8 @@ import { type Hub, } from "../agents/AgentConfiguration"; import { - type AgentChange, - type PreparedAgentChange, - type TokenChoice, + type ConnectionDraft, + type ConnectionPlan, type useAgentState, prepareAgentChange, } from "../agents/agents_state"; @@ -50,10 +47,10 @@ function Configure({ hub: Hub; account: HubAccountControl; onBusy: (busy: boolean) => void; - onComplete: (restarted: boolean) => void; + onComplete: () => void; onBack: () => void; }) { - const [prepared, setPrepared] = useState(); + const [prepared, setPrepared] = useState(); const [preparing, setPreparing] = useState(false); const [error, setError] = useState(); const inFlight = useRef(false); @@ -66,13 +63,13 @@ function Configure({ return () => onBusy(false); }, [busy, onBusy]); - async function prepare(change: AgentChange, token: TokenChoice | null) { + async function prepare(draft: ConnectionDraft) { if (inFlight.current) return; inFlight.current = true; setPreparing(true); setError(undefined); try { - setPrepared(await prepareAgentChange(change, token)); + setPrepared(await prepareAgentChange(draft)); } catch (cause) { setError( `Не удалось подготовить изменения: ${typeof cause === "string" ? cause : "попробуйте снова"}`, @@ -148,7 +145,7 @@ function Configure({ return { SetPiHub: mode === "hub" ? "hub" : "disabled" }; } }} - onPrepare={(change, token) => void prepare(change, token)} + onPrepare={prepare} /> ) : (
    @@ -165,91 +162,17 @@ function Configure({ {prepared && ( setPrepared(undefined)} - onApplied={() => onComplete(prepared.restarts_desktop)} + onApplied={onComplete} /> )}
    ); } -function Completed({ - choice, - restarted, - onFinish, - onBusy, - onBack, -}: { - choice: AgentChoice; - restarted: boolean; - onFinish: () => void; - onBusy: (busy: boolean) => void; - onBack: () => void; -}) { - const [launching, setLaunching] = useState(false); - const [error, setError] = useState(); - const inFlight = useRef(false); - async function launch() { - if (inFlight.current) return; - inFlight.current = true; - setLaunching(true); - onBusy(true); - setError(undefined); - try { - await invoke("launch_agent", { agent: choice.id }); - onFinish(); - } catch (cause) { - setError( - typeof cause === "string" - ? cause - : `Не удалось запустить ${choice.name}. Попробуйте ещё раз.`, - ); - } finally { - inFlight.current = false; - setLaunching(false); - onBusy(false); - } - } - return ( -
    - } - title={`${choice.name} настроен`} - focusable - /> - - {restarted - ? "Приложение открыто с новыми настройками." - : choice.desktop - ? "Можно открывать приложение и начинать работу." - : "Агент откроется в терминале."} - - - Выбрать другого агента - - } - > - - - {error && ( -
    - {error} -
    - )} -
    - ); -} - -type Stage = "entry" | "select" | "configure" | "complete"; +type Stage = "entry" | "select" | "configure"; export function SetupDialog({ account, @@ -266,7 +189,6 @@ export function SetupDialog({ : []; const [selected, setSelected] = useState(); const [stage, setStage] = useState("entry"); - const [restarted, setRestarted] = useState(false); // Resolve the entry screen from live detection, not the first (possibly partial) snapshot. const viewStage = stage === "entry" @@ -306,9 +228,6 @@ export function SetupDialog({ setSelected(id); setStage("configure"); } - function finish() { - onClose(); - } return ( { - setSelected(selectedChoice.id); - setRestarted(restarted && Boolean(selectedChoice.desktop)); - changeBusy(false); - setStage("complete"); - }} - onBack={() => setStage("select")} - /> - )} - {viewStage === "complete" && selectedChoice && ( - setStage("select")} /> )} diff --git a/crates/wizard-gui/wizard-ui/src/onboarding/agents.tsx b/crates/wizard-gui/wizard-ui/src/onboarding/agents.tsx index 5425fc9..c958f93 100644 --- a/crates/wizard-gui/wizard-ui/src/onboarding/agents.tsx +++ b/crates/wizard-gui/wizard-ui/src/onboarding/agents.tsx @@ -28,6 +28,12 @@ export function isFound(choice: AgentChoice, agents: AgentStates) { return agents[choice.agent].status === "found"; } +export function launchChoiceFor(agent: AgentId, agents: AgentStates): AgentChoice { + const id = agent === "codex" && agents.codex.status === "found" && agents.codex.data.desktop.status === "found" + ? "chatgpt" : agent; + return choices.find(choice => choice.id === id)!; +} + export function AgentIcon({ choice, className = "" }: { choice: AgentChoice; className?: string }) { return