import { type AgentSqlToken } from "./lexer.js"; export type AgentSqlPolicyErrorCode = "unreadable" | "empty" | "multiple_statements" | "refused"; /** * Agent SQL was refused by policy. The message is written for the agent: it * says what was refused and what to do instead. `code` lets a caller word the * structural cases in its own terms. */ export declare class AgentSqlPolicyError extends Error { readonly code: AgentSqlPolicyErrorCode; constructor(message: string, code?: AgentSqlPolicyErrorCode); } export interface AgentPostgresStatement { /** * The statement text from its first token to its last, so a trailing * semicolon or comment is gone and appended text cannot be swallowed. */ sql: string; tokens: AgentSqlToken[]; /** Lower-case leading keyword, ignoring leading parentheses. */ keyword: string | null; } /** * Reads exactly one Postgres statement the way the database will. Throws * {@link AgentSqlPolicyError} for text the lexer cannot read, an empty input, * or more than one statement. */ export declare function readAgentPostgresStatement(sql: string): AgentPostgresStatement; /** * Checks that need only the statement's tokens. Run them on every statement * before it reaches the database, and again on the final executed text. */ export declare function assertAgentPostgresExpressionTokenPolicy(statement: AgentPostgresStatement): void; /** Includes the schema-qualification restrictions needed by raw DB tools. */ export declare function assertAgentPostgresTokenPolicy(statement: AgentPostgresStatement): void; export interface AgentSqlQueryRunner { unsafe(sql: string, args?: unknown[]): Promise; } /** * Checks expression resolution inside the executing transaction. Callers * must separately scope relation reads; this check does not require temp * views. Conversions can invoke a type's input routines or domain checks, * including those nested inside a temporary view's composite row type. */ export declare function verifyAgentPostgresExpressions(db: AgentSqlQueryRunner, statement: AgentPostgresStatement): Promise; /** * Checks expression and relation resolution in the executing transaction, * after the per-user temporary views exist. Every resolved relation must * belong to this session's temp schema; qualifiers cannot name a schema or * this database. */ export declare function verifyAgentPostgresResolution(db: AgentSqlQueryRunner, statement: AgentPostgresStatement): Promise;