/** * Runs on (Console agents, docs/agents.md "Runs on"): the organization * machines and sandbox environments (rigs) an organization agent can name. * * Organization machines and rigs live in the workspace they were connected * from or made in, so an account-level caller (Console, an organization key, * a code deploy) cannot read their rows directly. The listing uses * `list_organization_compute_v1` (1224), which lists every active * organization machine or rig of the account wherever it works, read as the * system (no session actor) from one of the account's shared workspaces. * Personal (Only me) and workspace machines are never listed, so they can * never be named. Callers check `agents:read` / `agents:manage` or * organization administration first: this is not authorization. */ import type { OrganizationComputeReach, OrgAgentRunsOn } from "@opengeni/contracts"; import { type Database } from "./database.js"; export type OrgComputeKind = "machine" | "rig"; /** One organization machine (enrollment id, with its sandbox) or rig. */ export type OrgComputeEntry = { id: string; sandboxId: string | null; name: string; reach: OrganizationComputeReach; }; /** * Every active organization machine or rig of the account. `tx` is in the * account's RLS context (no workspace); the read runs in a nested scope of * one shared workspace and restores the caller's scope. Empty when the * account has no shared workspace. */ export declare function listOrganizationComputeInAccount(tx: Database, accountId: string, kind: OrgComputeKind): Promise; /** * Whether a reach includes every workspace the organization's product * manages, the Console test workspace too: only the explicit "All * product-managed workspaces" switch (migration 1512). "All shared * workspaces" reaches the other managed workspaces but never the test one. */ export declare function computeReachIncludesManagedWorkspaces(reach: OrganizationComputeReach): boolean; /** The organization machines and sandbox environments, for the Console "Runs on" control. */ export declare function listOrgAgentCompute(db: Database, accountId: string): Promise<{ machines: OrgComputeEntry[]; environments: OrgComputeEntry[]; }>; export type OrgComputeMatch = { status: "found"; entry: OrgComputeEntry; } | { status: "not_found"; } | { status: "ambiguous"; count: number; }; /** * The entry a `runsOn` reference names: an id (a machine's enrollment or * sandbox id, a rig's id), else a name (case-insensitive). A name that * several share is ambiguous: name it by id. */ export declare function findOrgCompute(entries: readonly OrgComputeEntry[], ref: string): OrgComputeMatch; export type OrgAgentRunsOnProblem = { code: "machine_not_found" | "environment_not_found"; message: string; }; /** * The machine or sandbox environment a version's `runsOn` resolved to when the * version was saved (`agent_revisions.runs_on_target`): chats then use this id, * so a later rename or a second machine with the same name can't move or break * the agent. `runsOn` keeps what was written, for display and the config hash. */ export type OrgAgentRunsOnTarget = { /** The organization machine's enrollment id. */ machineId?: string; /** The organization sandbox environment's (rig's) id. */ environmentId?: string; }; /** Reads a stored `runs_on_target`; anything else is null (resolve by `runsOn`). */ export declare function parseOrgAgentRunsOnTarget(value: unknown): OrgAgentRunsOnTarget | null; /** * What a `runsOn` names: the ids to save with the version (null when it names * no machine or environment), or why it names nothing usable. `tx` is in the * account's RLS context. */ export declare function resolveOrgAgentRunsOn(tx: Database, accountId: string, runsOn: OrgAgentRunsOn | undefined): Promise<{ target: OrgAgentRunsOnTarget | null; } | { problem: OrgAgentRunsOnProblem; }>; /** Why a `runsOn` names nothing usable, or null. `tx` is in the account's RLS context. */ export declare function orgAgentRunsOnProblem(tx: Database, accountId: string, runsOn: OrgAgentRunsOn | undefined): Promise; /** {@link resolveOrgAgentRunsOn} in its own account-scoped transaction. */ export declare function resolveOrgAgentRunsOnInAccount(db: Database, accountId: string, runsOn: OrgAgentRunsOn | undefined): Promise<{ target: OrgAgentRunsOnTarget | null; } | { problem: OrgAgentRunsOnProblem; }>;