/** * `/provider` wizard — interactively adds, edits, or deletes an LLM * provider route at runtime. * * The wizard is a sequence of `QuestionStore` asks (the same panel the * model-facing `ask_user_question` tool uses), so it needs no UI state of * its own. All side effects go through {@link ProviderSetupHost}, which the * channel implements over the dsh settings/credentials/llm seams: * * profile → settings `llm-pi-ai.providers.` (dsh-llm-pi-ai watches * the section and registers the route without a restart) * key → credentials store (`~/.dsh/.credentials.yaml`, 0600), named by * the derived `_API_KEY` env-style ref the profile's * `apiKeyEnv` points at * * The module is React-free so `scripts/verify-provider-wizard.mjs` can drive * it headless with a stubbed host and scripted answers. */ import type { CustomModelSettingsStore } from './customModelSettings.js'; import type { CustomModelTestRequest } from './customModelTest.js'; import type { CatalogProviderDefaults } from './catalogDefaults.js'; import { type AskUserQuestionAnswer, type AskUserQuestionRequest } from '@deepseek-ai/dsh-user-questions'; import type { LlmDiscoveredModel } from '@deepseek-ai/dsh-llm'; /** Route id rule shared with the dsh configuration surface (web Models page). */ export declare const PROVIDER_ROUTE_ID: RegExp; /** Wire protocols dsh-llm-pi-ai can serve on a manually declared route. */ export declare const PROVIDER_PROTOCOLS: readonly ["openai-completions", "openai-responses", "anthropic-messages"]; /** * Derive the credential ref for a route, matching the official web UI * convention so TUI- and web-added providers resolve the same key. */ export declare function deriveKeyRef(route: string): string; /** One catalog route the mounted adapters offer for activation. */ export interface CatalogProviderCandidate { readonly provider: string; readonly displayName: string; } /** * One user-added provider route read from the settings section. The parsed * fields drive the edit/delete picker rows, the catalog/custom split * (`isCatalog`) and the key-keep question (`ref` + `shadowed`). */ export interface ConfiguredProvider { readonly route: string; /** Human-facing provider name; omission means the route id is the name. */ readonly displayName?: string; /** Credential ref (profile.apiKeyEnv) when the profile names one. */ readonly ref: string; /** Whether the process environment shadows the ref (env-provided key). */ readonly shadowed: boolean; /** * Whether the route belongs to the installed catalog — real membership * as the llm adapter reports it, never inferred from the profile shape: * a catalog profile may carry an explicit `api` override and still be a * catalog route. */ readonly isCatalog: boolean; /** baseURL when the profile sets one. */ readonly baseURL?: string; /** Explicit `api` override in the stored profile; catalog routes can * carry one too, so this alone does not classify the route. */ readonly api?: string; /** Enabled model ids; undefined means the whole catalog stays served. */ readonly models?: readonly string[]; /** * Raw `profile.models` entries (plain objects, in order) as stored. A * targeted model-list rewrite reuses these for kept ids so fields the * wizard never learned about (`input`, `compat`, …) survive the edit. */ readonly modelEntries?: readonly Record[]; } /** One path op inside a provider profile, relative to the profile object. */ export type ProfilePathOp = { op: 'set'; path: readonly string[]; value: unknown; } | { op: 'unset'; path: readonly string[]; }; /** One OAuth-capable provider a dsh-auth-style plugin mounts (masked state only). */ export interface OAuthProviderStatus { readonly provider: string; readonly label: string; readonly oauthLabel: string; readonly loginLabel: string | undefined; readonly signedIn: boolean; readonly expiresAt: number | undefined; readonly expired: boolean; } /** One successful OAuth login. */ export interface OAuthLoginResult { readonly provider: string; readonly oauthLabel: string; readonly expiresAt: number; } /** One read-only MAAS model registered from the managed platform catalog. */ export interface MaasCatalogModel { readonly provider: string; readonly id: string; readonly name?: string; } /** * The `ctx.dshAuth` api, structural so this tree never imports the plugin: * mounting dsh-auth (or anything exporting this shape) lights up the wizard's * OAuth branch; absent it, the wizard behaves exactly as before. */ export interface OAuthSetupHost { providers(): Promise; login(provider?: string, signal?: AbortSignal): Promise; logout(provider: string): Promise; } /** * Runtime capabilities the wizard needs, implemented by the channel over * `ctx.settings` / `ctx.credentials` / `ctx.llm`. `undefined` from * `channel.providerSetup()` means the bare cordis.yml start (no dsh-base * services) and the command refuses to run. */ export interface ProviderSetupHost { /** Custom provider models shared with Web through the home-level patch. */ readonly customModels: CustomModelSettingsStore; /** Catalog routes activatable via the `llm-pi-ai` settings section. */ listCatalogProviders(): readonly CatalogProviderCandidate[]; /** Installed catalog endpoint/protocol defaults; no credentials or remote I/O. */ providerDefaults?(provider: string, model?: string): Promise; /** * The editable/deletable set: provider profiles the user layer itself * carries. Profiles inherited from the composition base are deliberately * absent — an unset only clears the user layer, so listing an inherited * route would promise a delete that silently reverts to the base value. */ listConfiguredProviders(): readonly ConfiguredProvider[]; /** * Routes whose stored profile names `ref` as `apiKeyEnv` at ANY settings * layer (user + inherited base), minus `exceptRoute`. Credential-impact * decisions (delete cleanup, shared-key confirm) must go through this, * never through {@link listConfiguredProviders}: that lists the user * layer only (a deletable set), so a base provider or a composition-base * route sharing the ref would be invisible and its key destroyed. */ listRefUsers(ref: string, exceptRoute?: string): readonly string[]; /** Whether a profile (any layer) already exists for the route. */ routeExists(route: string): boolean; /** Interrogate a draft endpoint; the draft key is never persisted. */ discoverModels(request: { provider?: string; baseURL?: string; api?: string; apiKey?: string; }): Promise; /** Send one real, tool-less request using an unsaved custom-model draft. */ testCustomModel(request: CustomModelTestRequest): Promise; /** Send one isolated, tool-less message through an already configured * provider/model route and return its visible text response. */ testModel(provider: string, model: string, prompt: string): Promise; /** Whether the process environment already provides this ref (shadow). */ envShadows(ref: string): boolean; /** The process-environment value for a shadowed ref; undefined when absent. */ envValue(ref: string): string | undefined; /** * Read the currently stored value for rollback purposes; undefined when no * credential exists under the ref. Only called when {@link envShadows} is * false, so the value comes from a writable/seeded store, never the env. */ readCredential(ref: string): Promise; /** Persist the key under the ref; rejects when env-shadowed or invalid. */ writeCredential(ref: string, value: string): void | Promise; /** Best-effort rollback of a just-written credential. */ removeCredential(ref: string): void | Promise; /** * Persist the provider profile under `llm-pi-ai.providers.`; * rejects when the adapter's validation deems it unserviceable. Used by * the add flow, where a whole-profile write is the intent. */ writeProfile(route: string, profile: Record): Promise; /** * Apply targeted path ops inside `llm-pi-ai.providers.`. Edits go * through here, never through {@link writeProfile}: replacing the whole * object would silently drop every field the wizard does not model * (`headers`, `timeoutMs`, `retryPolicy`, `displayName`, …). Paths are * relative to the profile object, so `['baseURL']` patches exactly the * one item the user picked; unknown fields stay untouched by omission. */ mutateProfile(route: string, ops: readonly ProfilePathOp[]): Promise; /** Unset the profile under `llm-pi-ai.providers.`. */ removeProfile(route: string): Promise; /** Host-owned Yuanjing catalog; older hosts may expose a shared settings switch. */ readonly maas?: { enabled(): boolean; /** Present only when the host supports changing Yuanjing availability. */ setEnabled?(enabled: boolean): Promise; /** Models currently registered from the MAAS platform API. */ listModels(): Promise; }; /** The OAuth sign-in surface; absent when no dsh-auth-style plugin is mounted. */ readonly oauth?: OAuthSetupHost; } export interface ProviderWizardDeps { readonly host: ProviderSetupHost; readonly ask: (request: AskUserQuestionRequest, options?: { redact?: boolean; }) => Promise; readonly notify: (text: string, options?: { color?: 'error' | 'warning' | 'success'; timeoutMs?: number; }) => void; readonly pushLocal: (title: string, lines: readonly string[]) => void; /** Live turn state; the model-switch question is skipped while working. */ readonly working: () => boolean; readonly switchModel: (provider: string, model: string) => Promise; } export type ProviderWizardOutcome = 'added' | 'updated' | 'deleted' | 'signed-out' | 'cancelled' | 'failed'; /** * Run the provider wizard. Opens with an action choice (add / edit); the * add path runs the guided config flow, and edit picks a configured route * then opens a menu of targeted edits (API key, base URL, wire protocol, * model list, delete this provider) with the route locked. Each menu item * applies immediately and exits — no confirmation between picking an edit * and writing it — and patches only the picked field, leaving every other * stored setting (including fields the wizard does not model) in place. * For built-in (catalog) routes the menu is limited to API * key, model list, and delete; base URL and wire protocol are only * meaningful for custom endpoints. Resolves 'cancelled' when the user * dismisses any question (Esc) — nothing has been written at that point. */ export declare function runProviderWizard(deps: ProviderWizardDeps): Promise; //# sourceMappingURL=providerWizard.d.ts.map