import type { SessionsApi } from "../auth/types.js"; import type { Api, Model } from "../types.js"; /** One scoped client. */ export interface AuthGatewayClient { /** Operator-chosen name, logged with the client's requests. */ name: string; /** Hex SHA-256 digest of the client's bearer token. */ tokenSha256: string; /** `provider/id` or `provider/*` grants; absent allows every served model, `[]` none. */ models?: readonly string[]; /** Provider id → OAuth identity keys the client's requests to that provider may use. */ accounts?: Readonly>; } /** An admitted scoped client, as the gateway's routes see it. */ export interface AuthGatewayClientScope { readonly name: string; /** False when the client may call every served model. */ readonly limitsModels: boolean; /** Whether the client may call `model`. */ allows(model: Model): boolean; /** * Session id the client's credential lookups for `provider` resolve under: * its own restricted session when `accounts` lists the provider, otherwise * the request's `sessionId`. Throws for a provider `accounts` omits, and for * a bound provider once the restriction is lifted, so a lookup can never * resolve unrestricted on the client's behalf. */ credentialSessionId(provider: string, sessionId: string): string; /** * Hold the client's account restriction while a request uses it; call the * returned release once the request can no longer resolve a credential. A * reload that retires the client lifts the restriction only after every * hold is released. Take the first hold in the same tick as * `authenticate`, before a reload can retire the client. */ retain(): () => void; } /** * Parse a clients file: a JSON object mapping each client name to * `{ tokenSha256, models?, accounts? }`. Any malformed entry or unknown field * rejects the whole file, since a misspelled `models` would otherwise allow * every model. Errors name the offending field, never its value. */ export declare function parseAuthGatewayClients(text: string): AuthGatewayClient[]; /** Hex SHA-256 digest of a bearer token, as `tokenSha256` records it. */ export declare function hashAuthGatewayToken(token: string): string; type RestrictionSessions = Pick; /** * The scoped clients one gateway admits, looked up by the digest of the * presented bearer. */ export declare class AuthGatewayClientTable { #private; constructor(sessions: RestrictionSessions, gatewayTokens: Iterable); /** * Replace the admitted clients. An invalid table throws and changes * nothing. An unchanged client keeps its scope; a new or changed one is * restricted before its token is admitted; the scopes left out are retired. * Ignored once the table is closed. */ set(clients: readonly AuthGatewayClient[]): void; /** The client `token` authenticates, if any. */ authenticate(token: string): AuthGatewayClientScope | undefined; /** Admit no more clients and retire every scope. */ close(): void; } export {};