import { type GatewayConfig } from './gateway-config.js'; import { Masker } from './mask.js'; export type GatewayDecision = 'allow' | 'deny' | 'ask'; export interface Who { /** OpenWebUI user id; empty when the caller did not send one. */ user: string; /** OpenWebUI chat id; empty when unknown — the call is then judged as made after outside text. */ chat: string; } export interface PreAnswer { decision: GatewayDecision; /** Flow-guard reason code (`FlowReason`), when a rule fired. */ reason?: string; /** Text for the model or the person: the guard's explanation, never the call's arguments. */ message?: string; /** For `ask`: the one-time code the person types (or the adapter approves after a dialog). */ code?: string; /** For a dialog: the arguments with secret-looking values masked and long text cut, never the raw call. */ preview?: string; /** `approved` when a grant was consumed; `audit` when audit mode let a refused call through. */ resolution?: 'approved' | 'policy' | 'audit'; /** Audit mode only: the reason code the call would have been refused with in `ask` or `deny`. */ wouldRefuse?: string; mode: string; } export interface PostAnswer { /** The result read as instructions to the model: put this in front of it. */ notice?: string; /** The flow guard's note for the model (outside text; stronger when it addresses the model): put it after the result. */ flowNote?: string; /** The flow note says the result addressed the model as if instructing it. */ instruction?: boolean; /** The result read as instructions and `results` is `block`: the caller must withhold it. */ withhold?: boolean; codes?: string[]; } export type SourceKind = 'web_search' | 'url' | 'document' | 'file' | 'knowledge' | 'other'; export declare class GatewayError extends Error { status: number; constructor(status: number, message: string); } /** * Arguments as a person may see them in a confirmation: secret-looking values masked. Whatever is shortened says so * (`[… 312 chars not shown …]`, `[+7 more keys not shown]`): a person must never approve text they could not see * without being told it was there. */ export declare function previewArgs(args: Record): string; /** The digest an approval is bound to. RFC 8785, so any JSON the call can carry (decimals included) has one; a value * that has none (a lone surrogate) is refused as a request, never treated as an outage. */ export declare function argsHash(args: Record): string; /** `mcp____`, the name the flow policy's labels match. */ export declare function guardToolName(server: string, tool: string): string; /** The call as the flow guard sees it. Server `builtin` is the platform's own tools: web search and fetch become * `WebSearch` / `WebFetch`, the rest `mcp__owui__`. */ export declare function guardCall(server: string, tool: string, args: Record): { name: string; input: Record; }; export declare function checkWho(who: Who): Who; export declare class Decider { readonly config: GatewayConfig; private now; readonly env: NodeJS.ProcessEnv; readonly cwd: string; private grants; private readonly expiredDir; /** Placeholders per chat, in memory only (mask.ts). The header values the gateway sends its servers are masked too. */ readonly masker: Masker; constructor(config: GatewayConfig, env?: NodeJS.ProcessEnv, now?: () => number); /** The masking session of a chat. A call with no chat id gets a session of its own: its placeholders cannot come back. */ private maskSession; /** * Text on its way to the model: placeholders for credentials and, when on, personal data. `origin` is the server the * text came from (`user` for the person's own message). `history`: text the chat showed before and now sends again, * whose known values keep the origins they had. */ mask(who: Who, origin: string, tool: string | undefined, value: T, history?: boolean): { value: T; total: number; counts: Record; note?: string; }; /** Real values back into a call to `server`/`tool`; a placeholder the policy keeps from it throws MaskRefusal. */ restore(who: Who, server: string, tool: string, value: T, encode?: (v: string) => string): T; /** Placeholders back to values for the person reading the answer (personal data by default; credentials stay masked). */ reveal(who: Who, text: string): string; /** * `requireAdapter`: a chat the platform adapter never reported a message for is judged as having read outside text. * With the adapter switched off or failing, nothing tells the gateway what the chat read, so it must not assume a * clean chat. The first call of such a chat records that, once. */ private unreported; mode(): string; /** * The flow-guard session of a chat. One state per user and chat. Without a chat id there is nothing to tie the call * to, so it gets a fresh session that already holds outside text: a send from it is judged as one made after * reading a page (fail-closed), and no approval code issued for it can ever be redeemed from a real chat. */ session(who: Who): string; private note; /** The person wrote a message: their own words and the destinations they name. `first` is true when the gateway had * no state for this chat (new, removed by retention, or older than the install): the adapter then reports what the * chat's earlier messages may have brought in. */ prompt(who: Who, prompt: unknown): { first: boolean; }; /** Outside text reached the chat without a tool call: web search, a document, a file, a fetched page. */ source(who: Who, body: Record): { tainted: boolean; }; /** Before a call. `allow` runs it; `deny` refuses it; `ask` refuses it until the code is approved. */ /** `bind` replaces the argument digest an approval is tied to (the OpenAPI proxy binds the exact request). */ pre(who: Who, server: string, tool: string, args: Record, bind?: string): PreAnswer; /** What the person answered. Only the adapter calls this, on the person's own message or dialog answer. */ approve(who: Who, code: unknown, approved: unknown, peek?: boolean): { ok: boolean; tool?: string; preview?: string; }; /** After a call: record what the result brought in, and screen it for text addressed to the model. */ post(who: Who, server: string, tool: string, args: Record, result: unknown, isError?: boolean): Promise; /** The text a proxy returns instead of running a refused call. */ refusal(answer: PreAnswer, tool: string): string; private sweep; /** * Remove chat state older than `retentionDays`, and expired approval codes (with the argument previews they keep). * A chat whose state is removed leaves a mark (`gateway/expired/`, empty): if the chat comes back, what it * read before is unknown, and its first call or message records that as outside text. Marks go after a year. * Returns the number of state files removed. */ purge(): number; /** A chat whose state retention removed: record once that what it read before is unknown. */ private expired; } /** Parse the who/where fields of a /v1 request body. */ export declare function whoOf(body: Record): Who; export declare function argsOf(v: unknown): Record; //# sourceMappingURL=gateway-decide.d.ts.map