/** * Configuration loader for Genspark Tool CLI * * Loads configuration from multiple sources with the following priority (highest to lowest): * 1. Command-line options * 2. Environment variables (GSK_API_KEY, GSK_BASE_URL) * 3. Config file (~/.genspark-tool-cli/config.json) * * The credential and its base URL are one pair (see resolveCredentialPair): * a key is only valid on the server that issued it (a `gsk-` key on www, an * `sbx-` Sandbox Passport only on the sbx gateway), so the base URL follows * the tier the key came from instead of being resolved independently. * * API key: --api-key > GSK_API_KEY > config api_key (unchanged) * Base URL: 1. --base-url (explicit flag, always wins) * 2. the key's own tier: GSK_BASE_URL for an env key, * config base_url for a config key (the CLI tier has none) * 3. the first other tier, in order env > config, that has a * base URL and holds either no key or this same key * 4. the default base URL * With no key at all: --base-url > GSK_BASE_URL > config base_url > default. * * So an env key never borrows the config file's base URL when the config * file holds a different key (and vice versa) — it gets the default instead. * With only one tier populated, or all tiers holding the same key, the result * is what plain "CLI > env > config > default" per field gives. */ import type { ToolSchema } from './types.js'; export interface ConfigFile { api_key?: string; base_url?: string; timeout?: number; debug?: boolean; project_id?: string; auto_update?: boolean; /** * Virtual Developer project ID — gates the visibility of the `gsk vd` * subcommand group. When set (either here or via GSK_VD_PROJECT_ID env * var), the CLI exposes `gsk vd ` and auto-injects this value as * the default for every `--vd_project_id` flag. When unset, the whole * `vd` subcommand group is hidden from the CLI. */ vd_project_id?: string; } export declare const WEBSITE_CLI_CAP = "cli-website-v1"; export declare const GSK_CLI_CAPS = "cli-groups-v2,cli-paths-v3,cli-actions-v4,cli-confirm-v1,cli-yes-only-v1,cli-local-source-v1,cli-drive-actions-v1,cli-developer-input-v1,cli-website-v1"; /** * Set (or clear) the custom config path. Call this before any other * function in this module so that subsequent reads/writes target the * override. Pass `undefined` to reset to the default location. */ export declare function setConfigPathOverride(absPath: string | undefined): void; /** Directory for small private CLI state files (0700), next to the config. */ export declare function getStateDir(): string; /** * Get the path to the config file — honours a `--config` override. */ export declare function getConfigPath(): string; /** * Keep one canonical spelling for endpoint persistence and cache keys. */ export declare function normalizeBaseUrl(baseUrl: string): string; /** * Load configuration from the config file * Returns an empty object if the file doesn't exist or is invalid */ export declare function loadConfigFile(): ConfigFile; /** * Replace the selected config file. * * Prefer `updateConfigFile` for login/logout-style field changes because this * replacement API intentionally cannot preserve fields absent from `config`. */ export declare function saveConfigFile(config: ConfigFile): void; /** * Patch known fields in the selected config without dropping extension fields. */ export declare function updateConfigFile(updates: Partial, removeKeys?: (keyof ConfigFile)[]): void; export declare function getCachedFeatures(): Record | undefined; /** * Load tools from the cache file. * Returns null if cache doesn't exist, is stale (>24h), or base_url doesn't match. */ export declare function loadToolsCache(baseUrl: string): ToolSchema[] | null; /** * Delete this binary's tools cache so the NEXT invocation refetches the * manifest. For refusal paths where the cached schema itself may be the * problem (the manifest is cached 24h and gatekeeper-tailored per user, so * a parameter the server just started accepting can be missing only from * the stale cache): busting here makes the user's rerun authoritative. * Only the caps-scoped file is touched — the legacy file belongs to * pre-caps binaries (see LEGACY_TOOLS_CACHE_FILE). */ export declare function clearToolsCache(): void; /** * Save tools (and the server-negotiated feature bits) to the cache file. */ export declare function saveToolsCache(baseUrl: string, tools: ToolSchema[], features?: Record): void; /** * The credential the CLI sends on its own HTTP requests. * * GenTeam sandboxes export a per-turn credential (`dtk-…`, minted by the * backend for the running turn — see * `backend/digital_employee/runtime/turn_credential.py`) as * `GSK_TURN_TOKEN` into each bash exec. It is preferred over the * per-agent `GSK_API_KEY` for gsk requests only: `GSK_API_KEY` itself is * untouched because sb-git clone URLs and other tooling still need the * plain key. Anything else in the variable is ignored (fail back to the * key), so a stray value can never break the CLI. */ export declare function resolveRequestCredential(apiKey: string | undefined, env?: NodeJS.ProcessEnv): string; /** * The running chat turn's envelope, exported by a Second Brain sandbox as * `GSK_TURN_ENVELOPE`; sent as `X-GSK-Envelope` so the server can bind a * runtime-Passport call to that turn. A value that is not a plain * base64url-ish token is ignored, so a stray value can never break the CLI. */ export declare function resolveTurnEnvelope(env?: NodeJS.ProcessEnv): string; /** * The envelope a request carries as `X-GSK-Envelope`: the chat turn's, or, in a * scheduled run on the runtime-Passport lane, the run's job envelope. */ export declare function resolveRequestEnvelope(env?: NodeJS.ProcessEnv, read?: (file: string) => string): string; /** * Second Brain runtime credential for this CLI call, from the platform-managed * file the backend writes atomically (`~/.config/genspark/sb-runtime-credential.json`, * token and origin read together). Used only when the running chat turn * exported its envelope (`GSK_TURN_ENVELOPE`) AND the file is the platform's * own (owner marker) with `"cli":true`, or, in a scheduled run outside any * chat turn, the daemon exported the run's job envelope * (`SB_BACKGROUND_ENVELOPE`) AND the file also carries `"clibg":true` (written * only by a backend whose tool CLI accepts that envelope). Then: * - valid and unexpired → `{apiKey: , baseUrl: }`; * - expired / damaged → `{apiKey: '', baseUrl: }`: the call fails * and the next deploy pass renews the file. Never the launch gsk. * Anything else (no file, a user's file, `cli` off, no envelope) → `undefined`: * the normal credential resolution applies unchanged. */ export declare function resolveSbRuntimeCredential(env?: NodeJS.ProcessEnv, read?: (file: string) => string): { apiKey: string; baseUrl: string; } | undefined; /** One configuration tier's view of the credential pair; empty = unset. */ export interface CredentialTier { apiKey?: string; baseUrl?: string; } export interface CredentialPairSources { /** `--api-key`. */ cliApiKey?: string; /** `--base-url`, only when the user passed the flag explicitly. */ cliBaseUrl?: string; env: CredentialTier; file: CredentialTier; defaultBaseUrl: string; } /** * Resolve the API key and the base URL as one pair — precedence documented * in the header comment of this file. */ export declare function resolveCredentialPair(sources: CredentialPairSources): { apiKey: string | undefined; baseUrl: string; }; //# sourceMappingURL=config.d.ts.map