import type { Op } from "./protocol.js"; import { ORDER_ACTIONS, TASK_ACTIONS } from "./protocol-schema.js"; export type Caller = { kind: "person"; } | { kind: "unregistered"; } | { kind: "concierge"; id: string; } /** `job`: a session the daemon runs; `fg`: a foreground pi registered as a peer. */ | { kind: "session"; form: "job" | "fg"; id: string; }; export type CallerKind = Caller["kind"]; /** * The caller on a connection: an identified peer is a Session (the Concierge when its job * is the concierge's); a connection that said it is an agent but is not a peer (yet) is an * Unregistered agent; one that never said is the Person (the socket is the user's own). */ export declare function callerOf(conn: { peer?: { kind: "job" | "fg"; id: string; }; agentSide?: boolean; }, isConcierge: (jobId: string) => boolean): Caller; export interface Refusal { code: "unauthorized" | "unsupported"; message: string; } type Rule = "allow" | Refusal; /** A session's rule, or one for each form of session. */ type SessionRule = Rule | { job: Rule; fg: Rule; }; export interface Policy { person: Rule; session: SessionRule; concierge: Rule; unregistered: Rule; } export { ORDER_ACTIONS, TASK_ACTIONS }; type Expanded = "task" | "concierge-order"; export type PolicyKey = Exclude /** The op itself: an action not named (the op refuses it as a bad request). */ | Expanded | `task.${(typeof TASK_ACTIONS)[number]}` | `concierge-order.${(typeof ORDER_ACTIONS)[number]}`; export declare const POLICY: Record; /** The row an op takes: task and concierge-order by their action (an action not in the table: the op's own row). */ export declare function policyKey(op: string, action?: unknown): PolicyKey | undefined; /** Whether the caller may do it: null, or the refusal. An op not in the table is the daemon's to refuse (unknown op). */ export declare function allow(caller: Caller, op: string, action?: unknown): Refusal | null;