import { type MaskClass, type PersonalOptions, type Span } from './mask-detect.js'; export type RestorePolicy = 'origin' | 'never' | 'anywhere'; export declare const RESTORE_POLICIES: readonly RestorePolicy[]; export interface ClassPolicy { enabled: boolean; /** Where a placeholder may be turned back into its value: `origin` (default) the server it came from, plus `restoreTo`; * `anywhere` any tool; `never` nowhere, the tool receives the placeholder. */ restore: RestorePolicy; /** More destinations: `server` or `server/tool` (`*` matches any run of characters). */ restoreTo: string[]; /** Results of these tools are not masked: `server/tool` or `tool` patterns. */ exceptTools: string[]; } export interface CredentialPolicy extends ClassPolicy { /** Mask the values of this process's environment variables whose names say they hold a credential. */ autoEnv: boolean; /** More environment variables whose values are masked wherever they appear. */ envNames: string[]; } export interface PersonalPolicy extends ClassPolicy, PersonalOptions { profile: string; } export interface MaskConfig { credentials: CredentialPolicy; personal: PersonalPolicy; /** Placeholders a session keeps; the least recently used go first (their placeholders then pass as plain text). */ maxEntries: number; /** A session idle this long is forgotten (gateway chats; a stdio wrap is one session for its lifetime). */ idleMinutes: number; /** What the user sees (OpenWebUI outlet, Hermes final answer): personal data restored, credentials kept masked. */ display: { credentials: boolean; personal: boolean; }; } /** A term matches as a whole word (Unicode letters and digits), any case, with any run of spaces between its words. */ export declare function termPattern(term: string): RegExp; /** * Read a mask configuration. `raw` is the JSON object (`--mask FILE`, the gateway's `mask` field), or `undefined` for * the defaults: credentials masked with restore to their origin, personal data not masked. Shorthands: * `"credentials": false` turns credential masking off; `"personal": "gdpr"` turns personal masking on with that profile. * Unknown fields are an error, as everywhere in WARDEN's configuration. */ export declare function parseMaskConfig(raw: unknown, baseDir?: string): MaskConfig; export interface MaskOverrides { /** A JSON file (`--mask FILE`); without it `WARDEN_MASK` is read. */ file?: string; /** `--mask-credentials on|off`. */ credentials?: boolean; /** `--mask-personal |on|off`. */ personal?: string | false; } /** * The configuration a wrap or gateway runs with, for clients that start WARDEN with no flags as much as for those that * pass them. In order, later wins: the defaults; the file (`--mask FILE`, else `WARDEN_MASK`); the environment * switches `WARDEN_MASK_CREDENTIALS=off` and `WARDEN_MASK_PERSONAL=|off` (only without `--mask FILE`, so a * file the operator names is the whole policy); the flags. */ export declare function loadMaskConfig(o?: MaskOverrides, env?: NodeJS.ProcessEnv): MaskConfig; /** @deprecated name kept for callers of the first draft: same as loadMaskConfig({ file }, env). */ export declare function maskConfigFromEnv(env?: NodeJS.ProcessEnv, file?: string): MaskConfig; /** Environment variables whose names say they hold a credential, and whose values look like one. */ export declare function credentialEnvValues(env: NodeJS.ProcessEnv, extraNames?: readonly string[]): string[]; export interface MaskOrigin { server: string; tool?: string; } export interface MaskResult { value: T; total: number; counts: Record; } export interface RestoreResult { value: T; restored: number; kinds: Record; } /** A placeholder in a call's arguments that the policy does not let through to this destination. The call is not sent. */ export declare class MaskRefusal extends Error { } interface Entry { id: string; kind: string; cls: MaskClass; value: string; origins: Set; used: number; } /** The origin of values the user typed into the chat: theirs to use, so personal data from it is restored anywhere. */ export declare const USER_ORIGIN = "user"; export declare class Masker { readonly config: MaskConfig; private readonly known; private readonly sessions; private readonly now; /** `extraKnown`: more exact credentials to mask, such as the header values a gateway sends its tool servers. */ constructor(config: MaskConfig, env?: NodeJS.ProcessEnv, now?: () => number, extraKnown?: readonly string[]); get enabled(): boolean; /** The session for a chat (gateway) or the one session of a stdio wrap. Idle sessions are forgotten. */ session(key?: string): MaskSession; /** Spans to mask in one string, for an origin. */ spans(text: string, origin: MaskOrigin, field: string | undefined, known: readonly string[]): Span[]; } export declare class MaskSession { private readonly masker; private readonly known; private readonly byKey; private readonly byId; private clock; private noted; constructor(masker: Masker, known: readonly string[]); private entry; /** * Replace credentials (and personal data, when on) in every string of `value` with placeholders. `keepOrigins`: for * text that was shown before (a chat history sent to the model again), a value this session already knows keeps the * origins it had; only new values take `origin`. */ mask(value: T, origin: MaskOrigin, opts?: { keepOrigins?: boolean; }): MaskResult; private policy; /** May this entry's value go to `server`/`tool`? */ allowed(e: Entry, server: string, tool: string | undefined): boolean; /** * Put real values back into a call's arguments. A placeholder this session made, sent to a destination its policy * allows, becomes its value; with `restore: never` it stays a placeholder; sent anywhere else it stops the call * (MaskRefusal). A placeholder this session does not know (another WARDEN layer's, or one that aged out) is passed on * unchanged: the layer that made it restores or refuses it, and as plain text it carries no value. */ restore(value: T, target: MaskOrigin, encode?: (v: string) => string): RestoreResult; /** * Placeholders back to values for the person reading the answer (OpenWebUI outlet, Hermes final reply). By default * personal data is shown and credentials stay masked: a chat transcript is copied, shared and sent to the model again. */ reveal(text: string): string; /** The note that goes with a masked result: the full text once per session, a short line after. */ note(result: MaskResult): string | undefined; /** Placeholders this session holds (for tests and the audit count; never the values). */ get size(): number; } /** * Put the masking note where the model reads it: after a tool result's content, a resource's contents, a prompt's * messages, or an error's message. A value of another shape is returned as it is (the note is optional). */ export declare function withMaskNote(value: T, note: string | undefined): T; /** One log line of what a mask or restore did: kinds and counts, never values or placeholders' meaning. */ export declare function maskSummary(counts: Record): string; export {}; //# sourceMappingURL=mask.d.ts.map