/** Incrementally sanitizes streamed output while retaining any suffix that could contain an incomplete secret or PII match. Known values, surrogate tokens, authorization fields, key assignments, and structured secrets must not straddle an emitted boundary. Flush processes the retained tail; cancellation discards it. Streaming cannot redact text already emitted before a later chunk makes its sensitivity detectable. */ import type { PseudonymSession } from "./pii-pseudonymizer.js"; import type { SecretSwapSession } from "./secret-swap.js"; /** One increment of guarded output: provider-safe text and its user-visible form. */ export interface GuardedStreamOutput { /** Text safe to persist / send onward: secrets → placeholders, PII → surrogates. */ safe: string; /** Text safe to show the user: PII surrogates restored to their real values. */ visible: string; } export interface GuardedStreamScannerOptions { secretSession?: SecretSwapSession | null; piiSession?: PseudonymSession | null; } /** * Chunked, order-preserving replacement for the runtime's end-of-stream * `flushGuardedStream`. Constructed once per guarded turn; the same secret/PII * sessions are shared with the rest of the turn and may grow mid-stream (the * secret session learns new values as it substitutes each emitted prefix), so the * hold window is recomputed from live session state on every {@link push}. */ export declare class GuardedStreamScanner { private pending; private readonly secretSession; private readonly piiSession; constructor(options: GuardedStreamScannerOptions); /** Append a raw model chunk; return the text newly cleared for delivery (may be empty). */ push(chunk: string): GuardedStreamOutput; /** End of stream: process and return the entire held tail, then reset. */ flush(): GuardedStreamOutput; /** * The exact pipeline the buffered path ran: secret placeholders first, then PII * surrogates for the safe side, with the PII surrogates restored for the * user-visible side. Kept byte-identical so streamed and buffered turns produce * the same reply text. */ private transform; private maxTokenLength; /** * Every string that must not be split across the cut: known secret values and * their placeholders, PII values and their surrogates. Read live because the * secret session learns new values while substituting emitted prefixes. */ private tokenKeys; /** * Largest index up to which `pending` may be emitted. Starts at a window sized * to the longest known token, then moves left (only ever left) past any trailing * in-progress sensitive shape, to a fixpoint. Returns 0 when nothing is safe yet. */ private findSafeCut; /** * Move the cut left until the character before it is whitespace (or 0). This * makes the cut land exactly between tokens, so no whitespace-free token is * split and the PII replacer's `(?