import { type PluginId } from '@zhin.js/plugin-runtime'; import type { RuntimeEnvironment } from './environment.js'; export type EnvironmentSource = Readonly>; export interface EnvironmentLayers { readonly base?: EnvironmentSource; readonly environments?: Readonly>; readonly plugins?: Readonly>; } /** Reloadable authority for environment layers and their watched files. */ export interface EnvironmentLayersPort { readonly sources: readonly string[]; read(): Promise; } export interface EnvSchema { readonly secretKeys?: readonly string[]; parse(source: EnvironmentSource): T; } export interface EnvStore { readonly owner: PluginId; readonly environment: RuntimeEnvironment; has(key: string): boolean; get(key: string): string | undefined; require(key: string): string; parse(schema: EnvSchema): Readonly; /** Strict expansion: missing keys throw `EnvironmentVariableMissingError`. */ expand(value: T): T; /** * Config-document expansion for Root compose. * Missing keys become `""` so adapters that require credentials soft-fail at * create instead of treating literal `${VAR}` as a real token. */ expandMissingAsEmpty(value: T): T; redact(value: unknown, secretKeys: readonly string[]): unknown; } export declare const envStoreToken: import("@zhin.js/plugin-runtime").Token; export declare class EnvironmentVariableMissingError extends Error { readonly owner: PluginId; readonly key: string; constructor(owner: PluginId, key: string); } export declare class EnvSchemaParseError extends Error { readonly owner: PluginId; constructor(owner: PluginId, message: string); } /** * The PluginGraph owner path is the sole namespace for Plugin overlays. * Package names and bare instance keys are deliberately not accepted as * aliases: a layer for `root/a` can flow only to `root/a` and descendants. */ export declare function environmentOwnerPath(owner: PluginId): readonly PluginId[]; export declare function defineEnvSchema(schema: EnvSchema): Readonly>; export declare function defineEnvironmentLayers(layers?: EnvironmentLayers): Readonly; export declare function createEnvStore(owner: PluginId, environment: RuntimeEnvironment, layers?: EnvironmentLayers): EnvStore; /** Normalizes layers once, then derives immutable stores for each Plugin owner. */ export declare class EnvStoreFactory { #private; constructor(environment: RuntimeEnvironment, layers?: EnvironmentLayers); create(owner: PluginId): EnvStore; } /** * Standalone deep expansion over an arbitrary config value (e.g. a raw `ai` * config document before EnvStore scoping exists). Supports `${VAR}` and * `${VAR:-default}` / `${VAR:=default}` (default applies when the variable is * unset or empty). Missing plain references resolve via `onMissing` * (default: `""`, matching `EnvStore.expandMissingAsEmpty`). */ export declare function expandEnvironmentValue(value: T, lookup: (key: string) => string | undefined, onMissing?: (key: string) => string): T;