import { z } from "zod"; import { type Principal } from "./principal.js"; import type { Json } from "./ids.js"; /** What the meter counts. `message` is one user turn; `generation` is one app the agent built. Both are things a person does, never tokens or calls — a host writes its policy in the units it sells in. */ export type LimitAction = "message" | "generation"; export declare const limitActionSchema: z.ZodEnum<["message", "generation"]>; /** The stretch of usage one `count` covers. The three durations are ANDed into a single lookback and `since` names an instant floor instead; omit all four and the count is all-time. `pool` counts the whole shared bucket rather than the one user — a seat pool, a team, an org — and is only answerable for a pool the user is actually in ({@link LimitUser.pools}). Every org the host asserts in `RunContext.memberships` is one of those pools already, named `org:` (§9.2's principal encoding, the same string an app grant names it by), so an org-wide cap needs nothing wired for it. */ export interface LimitWindow { days?: number; hours?: number; minutes?: number; since?: Date; pool?: string; } export declare const limitWindowSchema: z.ZodObject<{ days: z.ZodOptional; hours: z.ZodOptional; minutes: z.ZodOptional; since: z.ZodOptional; pool: z.ZodOptional; }, "passthrough", z.ZodTypeAny, z.objectOutputType<{ days: z.ZodOptional; hours: z.ZodOptional; minutes: z.ZodOptional; since: z.ZodOptional; pool: z.ZodOptional; }, z.ZodTypeAny, "passthrough">, z.objectInputType<{ days: z.ZodOptional; hours: z.ZodOptional; minutes: z.ZodOptional; since: z.ZodOptional; pool: z.ZodOptional; }, z.ZodTypeAny, "passthrough">>; /** What a policy answers with. `true`/`false` is the whole grammar; the object form exists only to carry the sentence the user reads when denied, so there is deliberately no `{ allow: true }` — allowing has nothing to say. */ export type LimitDecision = boolean | { allow: false; message?: string; }; export declare const limitDecisionSchema: z.ZodUnion<[z.ZodBoolean, z.ZodObject<{ allow: z.ZodLiteral; message: z.ZodOptional; }, "passthrough", z.ZodTypeAny, z.objectOutputType<{ allow: z.ZodLiteral; message: z.ZodOptional; }, z.ZodTypeAny, "passthrough">, z.objectInputType<{ allow: z.ZodLiteral; message: z.ZodOptional; }, z.ZodTypeAny, "passthrough">>]>; /** Who the policy is deciding about — the {@link Principal} the request resolved to, plus the host-asserted profile the same resolve produced. `facts` is the host's own bag (plan, role, tenure, …) and is what a tiered policy branches on; `pools` are the shared buckets this user draws from, and naming one in a {@link LimitWindow} is how a policy counts a team's usage rather than a person's. */ export interface LimitUser extends Principal { facts?: Record; pools?: string[]; } export declare const limitUserSchema: z.ZodObject<{ kind: z.ZodEnum<["user", "org"]>; subject: z.ZodString; display: z.ZodOptional; ephemeral: z.ZodOptional; } & { facts: z.ZodOptional>; pools: z.ZodOptional>; }, "passthrough", z.ZodTypeAny, z.objectOutputType<{ kind: z.ZodEnum<["user", "org"]>; subject: z.ZodString; display: z.ZodOptional; ephemeral: z.ZodOptional; } & { facts: z.ZodOptional>; pools: z.ZodOptional>; }, z.ZodTypeAny, "passthrough">, z.objectInputType<{ kind: z.ZodEnum<["user", "org"]>; subject: z.ZodString; display: z.ZodOptional; ephemeral: z.ZodOptional; } & { facts: z.ZodOptional>; pools: z.ZodOptional>; }, z.ZodTypeAny, "passthrough">>; /** The host's policy, asked once before each metered action. Vendo counts; this decides. `count` is a meter reader already bound to THIS user, so a policy never names a subject and can never read another person's usage by accident. It is a callback and not a number because most policies read the meter once, for one window, and pre-computing every window a policy might ask about would be a query per action per call. */ export type LimitsCallback = (input: { user: LimitUser; action: LimitAction; count: (action: LimitAction, window?: LimitWindow) => Promise; }) => Promise | LimitDecision;