import { useEffect, useState, useSyncExternalStore } from "react"; import { Button, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, Field, FieldLabel, Input, } from "@ace/ui"; import type { ProviderSettings, Settings as HostSettings } from "@ace/host/protocol"; import { host } from "./host"; import { desktop } from "./desktop"; import { HostStatus } from "./host-settings"; import { UpdateSettings } from "./updates"; const sources = { keychain: "Saved in Keychain", environment: "Using an environment key", missing: "No key added", unavailable: "Keychain access needed", }; function Provider({ provider, disabled }: { provider: ProviderSettings; disabled: boolean }) { const [value, setValue] = useState(""); const [confirm, setConfirm] = useState(false); const [action, setAction] = useState<{ busy?: boolean; error?: string; message?: string }>({}); const id = `key-${provider.id}`; async function run(op: "key-set" | "key-check" | "key-remove") { setAction({ busy: true }); try { await host.request( op === "key-set" ? { op, provider: provider.id, value } : { op, provider: provider.id }, ); if (op === "key-set") setValue(""); setConfirm(false); setAction({ message: op === "key-check" ? "Connection verified." : op === "key-remove" ? "Saved key removed." : "Key checked and saved.", }); } catch (error) { setAction({ error: (error as Error).message }); } } return (
); } function DefaultModel({ settings, disabled }: { settings: HostSettings; disabled: boolean }) { const [action, setAction] = useState<{ busy?: boolean; error?: string }>({}); const chosen = settings.modelOverride || settings.model; const value = chosen ? `${chosen.provider}/${chosen.modelId}` : ""; const available = settings.models.map((model) => `${model.provider}/${model.modelId}`); async function save(value: string) { const split = value.indexOf("/"); const model = value ? { provider: value.slice(0, split), modelId: value.slice(split + 1) } : null; setAction({ busy: true }); try { await host.request({ op: "preferences", model }); setAction({}); } catch (error) { setAction({ error: (error as Error).message }); } } return ({settings.modelOverride ? "ACE_MODEL overrides this preference. Remove it and restart Ace Helper to use your saved choice." : "Used for a chat's first agent run. Existing chats keep their model."}
{action.busy &&Saving default model…
} {action.error &&{action.error}
}