import { Permission } from "@opengeni/contracts"; import { type Database } from "./database.js"; /** * Full access for agent sessions (migration 0691; stored as "admin access"). * An organization allows it (off by default); any member then gives a session * they started themselves their own access for a number of hours or with no * time limit, and the agent there can do what that person can do, never more: * every action it runs is checked against the person's live access. Every use * goes through {@link resolveSessionAdminAuthority}, which re-checks the * allowance, the grant, its time limit and that the person still belongs to * the session's workspace. What a turn may do with it goes through * {@link resolveSessionAppActionAuthority}: only turns the person who gave it * caused run as them, so another member's message in the same shared chat * never does. */ export type OrganizationAgentAdminAccess = { sessionAdminAccessAllowed: boolean; /** In-chat app actions, each change confirmed by the person (0971). On unless turned off. */ chatActionsAllowed: boolean; updatedAt: string | null; }; export type SessionAdminAccessGrant = { sessionId: string; grantedBySubjectId: string; grantedAt: string; /** When it ends by itself; null means no time limit. */ expiresAt: string | null; }; /** Raised when the organization does not allow admin access for sessions. */ export declare class SessionAdminAccessNotAllowedError extends Error { constructor(); } /** Raised when the person no longer belongs to the session's workspace. */ export declare class SessionAdminAccessNotWorkspaceMemberError extends Error { constructor(); } /** * Raised when the session isn't the person's own: only a session someone * started themselves can be given their access, so nobody else's agent ever * acts as them. */ export declare class SessionAdminAccessNotOwnSessionError extends Error { constructor(); } /** The organization's agent choices. Absent reads as full access off, in-chat actions on. */ export declare function getOrganizationAgentAdminAccess(db: Database, accountId: string): Promise; /** * Allow or stop full access for sessions, in-chat app actions, or both; an * omitted choice stays as it is. Only an owner or admin may change them. * Turning full access off also removes every session's full access, so * turning it on again never silently restores old grants. */ export declare function setOrganizationAgentAdminAccess(db: Database, input: { organizationId: string; actorSubjectId: string; sessionAdminAccessAllowed?: boolean | undefined; chatActionsAllowed?: boolean | undefined; }): Promise; /** The session's admin access as recorded; null when it has none. */ export declare function getSessionAdminAccess(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; }): Promise; /** * Give a session admin access as `actorSubjectId`, who must belong to the * session's workspace (or be an active owner or admin), in an organization * that allows it, on a session they started themselves, for `durationHours` hours or, when null, with no time limit. * Giving it again while it is on sets a new time limit from now; after it * ended by itself, it counts as given anew. */ export declare function grantSessionAdminAccess(db: Database, input: { organizationId: string; workspaceId: string; sessionId: string; actorSubjectId: string; durationHours: number | null; }): Promise; /** End a session's admin access. Returns whether it had any. */ export declare function revokeSessionAdminAccess(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; }): Promise; /** * The person whose access this session uses right now, or null. Live on every * call: the organization must still allow it, the grant must still exist and * be within its time limit, and the person who gave it must still belong to * the session's workspace (or be an active owner or admin). * * This describes the session (its grant state and tool listing), not a turn: * anything acting for a turn uses {@link resolveSessionAppActionAuthority}. */ export declare function resolveSessionAdminAuthority(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; }): Promise<{ subjectId: string; grantedAt: string; expiresAt: string | null; } | null>; /** * What a viewer needs to show and change a session's admin access: whether * the organization allows it, the grant while it is within its time limit, * whether it is in effect right now, whether the viewer started this * session, and whether they are an owner or admin (who may end anyone's). */ export declare function getSessionAdminAccessView(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; viewerSubjectId: string; }): Promise<{ allowed: boolean; grant: SessionAdminAccessGrant | null; active: boolean; viewerStartedSession: boolean; viewerIsAdministrator: boolean; }>; /** * Whether a session lists the app-action tools: it is one a person started * themselves (not a child or service session). Fixed for the session's life, * so its tool list never changes because of it. */ export declare function sessionStartedByPerson(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; }): Promise; /** Why an app action can't run as anyone in this turn. */ export type SessionAppActionUnavailableReason = "organization_off" | "not_person_session" | "no_person_present" | "not_signed_in_person" | "not_member"; /** * What one turn's message may do through app actions, frozen when the message * is accepted and never changed: who sent it, whether they can confirm changes * from where they sent it, and the most it may do (their own access then). */ export type TurnAppActionGrant = { subjectId: string; /** * `confirm`: each change runs after this person confirms it in the chat * (signed in to the app itself, or an embed whose host opted in). * `none`: reads only (any other embed or integration). */ changes: "confirm" | "none"; permissions: readonly Permission[]; }; /** Record a turn's frozen app-action grant, inside the transaction that accepts its message. */ export declare function recordTurnAppActionGrant(tx: Database, input: { accountId: string; workspaceId: string; turnId: string; grant: TurnAppActionGrant; }): Promise; /** * What one person's sign-in could do in this workspace when they last sent a * message to this chat (the frozen grants above, whatever the organization * allows through app actions): the same effective access their chat shows, * narrowed by an embed's token and including their own workspace. This * turn's own grant when they sent its message; otherwise, for a turn the * platform started for them (a wake-up, a child's result, a goal * continuation), their latest message's grant in the same chat. `null` when * they never sent one here. */ export declare function readTurnSenderAccess(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; turnId: string; subjectId: string; }): Promise<{ permissions: Permission[]; } | null>; /** * As whom an app action in this turn runs, checked live on every call: * * - `full_access`: the session has full access and this turn is one the * person who gave it caused: their own message (with the grant frozen with * it theirs), or a continuation whose recorded causal person is them. That * person, with everything they can do, no confirmation. A turn someone else * caused continues below exactly as without full access. * - `confirm`: the person who sent this turn's message, in a session a person * started, in an organization that allows in-chat actions, from where they * can confirm (see {@link TurnAppActionGrant}). Reads run; each change runs * only after that same person confirms it in the chat. * - `read_only`: the same, from an embed or integration that can't confirm * changes; reads run, changes never do. * - `unavailable`: nobody; scheduled, goal and other unattended turns, child * and service sessions gain nothing. * * `confirm` and `read_only` carry the turn's frozen permissions: an action * never runs with more than the sender's own access when they sent it, and * each route still checks their live access. */ export declare function resolveSessionAppActionAuthority(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; turnId: string; }): Promise<{ kind: "full_access"; subjectId: string; } | { kind: "confirm" | "read_only"; subjectId: string; permissions: Permission[]; } | { kind: "unavailable"; reason: SessionAppActionUnavailableReason; }>; /** * The saved arguments of app-action changes `subjectId` confirmed in the chat * that this attempt is running right now: approved by that person while signed * in where a change may be confirmed (the app itself, or an embed the * deployment opted in), and marked as executing by this exact attempt. An * Allow sent with a key, a chat integration button or another token carrying * the same identity confirms nothing. The API runs a change without full access * only when its arguments are one of these. */ export declare function listConfirmedAppActionChanges(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; turnId: string; attemptId: string; subjectId: string; toolName: string; }): Promise;