/** * @file Layered provider-credential resolver for AI backends. One call site, * dev and CI: a provider token resolves from an explicit override, then the * provider's env var, then the OS keychain — mirroring the * `readSocketApiToken` env → keychain precedence * (`secrets/socket-api-token.ts`). Why a single resolver: `ai/http.mts` read * `process.env[tokenEnv]` inline, so every consumer hard-coded the env-only * path and none could reach the keychain. Routing skills also need a uniform * way to ask "do I have a credential for provider X?" without knowing its * env-var name. This centralizes the provider → { tokenEnv, keychainService } * map (the HTTP providers reuse `AI_HTTP_PROVIDERS` so the env var isn't * duplicated) and the precedence. CI vs dev: pass `allowEnvOnly: true` (the * resolver's existing escape) in headless contexts so a missing token returns * `undefined` immediately instead of triggering a keychain auth prompt. CI * sets the token as a GH-secret env var (e.g. `ANTHROPIC_API_KEY`); the same * `resolveProviderCredential` call reads it there with no keychain. sockeye * hook-point: the forthcoming biometric credential daemon slots in as a * layer between the env check and the keychain read inside `resolve()`'s * implementation — call sites here do not change when it lands. This module * is the stable injection point. */ /** * A KEYED provider whose credential this module resolves from a token source: * the HTTP providers fireworks and synthetic, plus the CLI/first-party * providers anthropic, openai, and xai for CI env + keychain. Every keyed * provider has a `{ tokenEnv, keychainService }` entry in * `PROVIDER_CREDENTIALS`. */ export type KeyedCredentialProvider = 'anthropic' | 'fireworks' | 'openai' | 'synthetic' | 'xai'; /** * The keyless on-device provider: a `local` engine (the `builtin.mts` * LanguageModel injection point / an injected local runner) that needs NO * credential — it runs on the machine, so it is "always present with no token". * It is a `CredentialProvider` so routing can name it uniformly, but it is * deliberately NOT in `PROVIDER_CREDENTIALS` because there is nothing to * resolve. Use `isKeylessProvider` to branch before a token lookup. */ export declare const KEYLESS_PROVIDER: 'local'; /** * A provider routing can name: every keyed provider, plus the keyless `local` * on-device engine. Token resolution only applies to the keyed subset; a * keyless provider resolves as always-present-with-no-token. */ export type CredentialProvider = KeyedCredentialProvider | typeof KEYLESS_PROVIDER; export interface ProviderCredentialSpec { readonly tokenEnv: string; readonly keychainService: string; } export declare const PROVIDER_CREDENTIALS: Readonly>; export interface DeleteProviderCredentialOptions { readonly provider: CredentialProvider; } /** * Remove a provider's stored credential from the OS keychain — the same * `{ service, account }` slot `resolveProviderCredential` reads. Returns * `'removed'` when a value was deleted, `'absent'` when none was stored (or the * platform has no keychain backend — delete degrades to a no-op rather than * throwing, since "nothing to remove" is the same outcome either way). * * @unused No internal or Socket consumers; exercised only by its unit tests. */ export declare function deleteProviderCredential(options: DeleteProviderCredentialOptions): Promise<'absent' | 'removed'>; /** * True when `value` names a provider routing can use: a keyed provider with a * resolvable credential, or the keyless `local` on-device engine. */ export declare function isCredentialProvider(value: string): value is CredentialProvider; /** * True when `value` is the keyless `local` provider — the on-device engine that * needs no credential. Callers branch on this BEFORE a token lookup: routing * treats a keyless provider as always-present (no `keyed` membership required), * and the credential resolvers short-circuit it with no keychain/env access. */ export declare function isKeylessProvider(value: string): value is typeof KEYLESS_PROVIDER; export interface ResolveProviderCredentialOptions { readonly provider: CredentialProvider; readonly explicit?: string | undefined; readonly allowEnvOnly?: boolean | undefined; } /** * Resolve a provider's bearer token: explicit override → env var → keychain → * undefined. The token never appears inline or in logs — callers pass the * result straight to an `Authorization` header. Returns `undefined` when no * source has it; the caller decides whether that's fatal. */ export declare function resolveProviderCredential(options: ResolveProviderCredentialOptions): Promise; export interface WriteProviderCredentialOptions { readonly provider: CredentialProvider; readonly value: string; } /** * Persist a provider's bearer token to the OS keychain — the SAME `{ service, * account }` slot `resolveProviderCredential` reads (account == `tokenEnv`, * service == the Socket-uniform `socketsecurity` scope), so a written token * resolves on the next read without an env var. * * Keychain ONLY — this never writes a shell-rc export. That matters most for * anthropic: a live `ANTHROPIC_API_KEY` env var overrides a Claude Max-seat * OAuth session and silently flips the user to metered billing, so its token * must live only in the keychain and be read on demand, never exported. A setup * wizard that rc-exports `FIREWORKS_API_KEY`/`SYNTHETIC_API_KEY` for * convenience must still route anthropic here, keychain-only. * * Returns `'written'` | `'unchanged'` (idempotent — an identical stored value * is a no-op). Throws when the OS has no keychain backend; a caller that wants * to degrade gracefully should check `getBackendAvailability()` first. */ export declare function writeProviderCredential(options: WriteProviderCredentialOptions): Promise<'unchanged' | 'written'>;