import type { AppServerManifest, AppServerRun, AppServerTrigger, ToolGatewayIdentity } from "@opengeni/contracts"; import { type Database } from "./database.js"; /** * App server code (migration 1554, docs/app-server-code.md): the runs log * and a version's server manifest. Every read and write runs under the * workspace's row-level security. */ type Scope = { accountId: string; workspaceId: string; }; export type AppServerRunStart = { id: string; siteId: string; versionId: string; trigger: AppServerTrigger; target: string; /** Who the run serves: `user:` or `guest:`. */ viewerSubjectId: string | null; }; export type AppServerRunFinish = { id: string; siteId: string; status: "ok" | "error"; httpStatus: number | null; durationMs: number; error: string | null; logs: string; }; /** * Start one run under the app's rate limits: at most `perApp` runs of the * app, and `perViewer` runs for one viewer, started in the last minute. The * run is inserted as `running`, so concurrent bursts count too; an advisory * lock per app makes the check and the insert one step. */ export declare function startAppServerRun(db: Database, scope: Scope, run: AppServerRunStart, limits: { perApp: number; perViewer: number; perGuests: number; }): Promise<"started" | "app_limit" | "viewer_limit" | "guest_limit">; /** End a run. Rows past the retention window in this workspace are pruned on the way. */ export declare function finishAppServerRun(db: Database, scope: Scope, run: AppServerRunFinish, keptDays: number): Promise; /** * Count one call back to Opengeni against a live run: the run must be the * app's and version's, still `running` and inside its deadline, and under * `limit` calls. The API enforces this whatever the code does in its isolate. * Returns the run's viewer (recorded by the API at start) for per-call checks. */ export declare function claimAppServerHostCall(db: Database, scope: Scope, call: { runId: string; siteId: string; versionId: string; limit: number; maxAgeMs: number; }): Promise<{ outcome: "ok" | "ended" | "limit"; viewerSubjectId: string | null; }>; /** One run of an app, or null. */ export declare function getAppServerRun(db: Database, scope: Scope, siteId: string, runId: string): Promise; /** Runs of one app, newest first. */ export declare function listAppServerRuns(db: Database, scope: Scope, siteId: string, options: { limit: number; status?: "running" | "ok" | "error"; before?: string; }): Promise; /** Runs and errors of one app since `since`, its newest error, and whether its newest finished run failed. */ export declare function summarizeAppServerRuns(db: Database, scope: Scope, siteId: string, since: Date): Promise<{ runs: number; errors: number; lastError: { message: string; at: string; } | null; lastRunFailed: boolean; }>; /** A version's server manifest, or null (no such version, or no server code). */ export declare function getAppServerManifest(db: Database, workspaceId: string, siteId: string, versionId: string): Promise; /** The server code an app currently serves, and on whose authority it runs. */ export type AppServerDeployment = { accountId: string; workspaceId: string; siteId: string; status: "active" | "archived"; versionId: string; manifest: AppServerManifest | null; requestedTools: ToolGatewayIdentity[]; /** * The person who made this version the current one (its latest publish or * rollback), else who created it: the code runs on their authority while * they still manage the app. When an agent did it, this is the person whose * turn the agent was acting on, not the agent's own service subject. */ deployerSubjectId: string; }; /** * The app's current version and its server code. With `versionId`, only * that version while it is still the current one (null otherwise), so a run * started for a version that was since replaced or rolled back stops. */ export declare function getAppServerDeployment(db: Database, workspaceId: string, siteId: string, versionId?: string): Promise; export {};