import type { AgentMiddleware } from '../create-agent.js'; /** The personal data and secrets `piiMiddleware()` finds on its own. */ export type PiiKind = 'email' | 'credit-card' | 'ssn' | 'phone' | 'iban' | 'ip-address' | 'secret'; /** * What happens to a match: `redact` replaces it with its kind, `mask` keeps its last four * characters, `hash` replaces it with a stable token so two values stay distinguishable, and `block` * refuses the whole message. */ export type PiiStrategy = 'redact' | 'mask' | 'hash' | 'block'; /** Where a match was found. */ export type PiiWhere = 'input' | 'output' | 'tool'; /** One match, as `onDetect` sees it: never the value itself. */ export interface PiiFinding { /** Its kind: a built-in kind or a name from `patterns`. */ kind: string; /** Where it was found. */ where: PiiWhere; /** What was done with it. */ strategy: PiiStrategy; } /** Options for `piiMiddleware()`. */ export interface PiiMiddlewareOptions { /** The built-in kinds to find. Defaults to all of them. */ kinds?: readonly PiiKind[]; /** Kinds of your own, by name: `{ 'employee-id': /\bEMP-\d{6}\b/ }`. */ patterns?: Readonly>; /** * What happens to a match, for every kind or per kind: `'mask'`, or * `{ email: 'hash', 'credit-card': 'block' }`. Kinds not named are redacted. */ strategy?: PiiStrategy | Readonly>; /** * Where to look. `input` is every message sent to the model but the system prompt; `output` is * the model's answer; `toolResults` cleans a result before it enters the transcript, so it is never * checkpointed either. Defaults to input and tool results. */ apply?: { input?: boolean; output?: boolean; toolResults?: boolean; }; /** Called for each match, for an audit trail. */ onDetect?: (finding: PiiFinding) => void; } /** Thrown when a match under the `block` strategy is found in the model's input or output. */ export declare class PiiBlockedError extends Error { /** The kind that was found. */ readonly kind: string; /** Where it was found. */ readonly where: PiiWhere; /** Always `PII_BLOCKED`. */ readonly code = "PII_BLOCKED"; constructor( /** The kind that was found. */ kind: string, /** Where it was found. */ where: PiiWhere); } /** * Keeps personal data and secrets away from the model, the transcript, or both. * * Finds emails, card numbers (checked with Luhn), US social security numbers, phone numbers, IBANs * (checked with their checksum), IP addresses, and common API keys and private keys, plus any kinds * of your own; and redacts, masks, hashes, or blocks each. The validated kinds keep false positives * low: an order number is not a card number unless its checksum says so. */ export declare function piiMiddleware(options?: PiiMiddlewareOptions): AgentMiddleware;