import { type AppServerManifest, type SiteAssetManifest, type ToolGatewayIdentity, type WorkspaceArtifact, type WorkspaceArtifactDetailResponse, type WorkspaceArtifactMutationResponse, type WorkspaceArtifactVersion } from "@opengeni/contracts"; import type { Database } from "./database.js"; /** * Who is reading Sites: the person, or the person an agent acts for. They see * every workspace Site plus their own Only me Sites. Null (keys, services and * runs without a person) sees workspace Sites only. Every read and mutation * takes one, so no path can skip the audience. */ export type WorkspaceArtifactViewer = { subjectId: string | null; }; /** Any exact publication from this session establishes the Site association. */ export declare function hasWorkspaceArtifactSessionLink(db: Database, workspaceId: string, viewer: WorkspaceArtifactViewer, sessionId: string, artifactId: string): Promise; /** Validate a published Site identity without loading its HTML or version history. */ export declare function getWorkspaceSiteSessionOrigin(db: Database, workspaceId: string, viewer: WorkspaceArtifactViewer, siteId: string, versionId: string): Promise<{ siteId: string; title: string; revision: number; }>; export declare function createWorkspaceArtifactUpload(db: Database, input: { accountId: string; workspaceId: string; ownerId: string; }): Promise<{ accountId: string; expiresAt: Date; id: string; ownerId: string; status: "expired" | "pending" | "published"; workspaceId: string; }>; export declare function getWorkspaceArtifactUpload(db: Database, workspaceId: string, id: string): Promise<{ id: string; accountId: string; workspaceId: string; ownerId: string; expiresAt: Date; status: "expired" | "pending" | "published"; } | null>; /** Claim expired uploads before deleting blobs; publication takes the same row lock. */ export declare function expireWorkspaceArtifactUploads(db: Database, workspaceId: string): Promise<{ id: string; accountId: string; workspaceId: string; ownerId: string; expiresAt: Date; status: "expired" | "pending" | "published"; }[]>; type ArtifactMutationToolName = "artifacts_create" | "artifacts_publish" | "artifacts_rollback" | "artifacts_archive" | "artifacts_restore" | "app_install" | "app_upgrade"; export declare class WorkspaceArtifactNotFoundError extends Error { readonly name = "WorkspaceArtifactNotFoundError"; } /** * Records that a person opened a Site in the console, for the order of their * own Site rows. Only a Site this viewer can see is recorded; the row grants * nothing. Repeated opens only move the time forward. */ export declare function recordSiteOpened(db: Database, input: { workspaceId: string; subjectId: string; viewer: WorkspaceArtifactViewer; siteId: string; }): Promise<{ openedAt: string; }>; /** One person's sidebar state for one Site row. */ export type SiteSidebarState = { siteId: string; pinned: boolean; pinnedAt: string | null; archived: boolean; archivedAt: string | null; }; /** * Pins or archives a Site row in one person's sidebar. Personal like session * pins: it never changes the Site, its publication or its audience, and only * a Site this viewer can see is recorded. Archiving hides the row (and the * conversations listed under it) until it is restored or the Site is opened * again; a pin survives archive and returns with the row. Repeating a state * keeps its original time. */ export declare function setSiteSidebarState(db: Database, input: { workspaceId: string; subjectId: string; viewer: WorkspaceArtifactViewer; siteId: string; pinned?: boolean | undefined; archived?: boolean | undefined; }): Promise; export declare class WorkspaceArtifactConflictError extends Error { readonly currentVersionId: string | null; readonly name = "WorkspaceArtifactConflictError"; constructor(message: string, currentVersionId?: string | null); } export declare class WorkspaceArtifactOperationError extends Error { readonly name = "WorkspaceArtifactOperationError"; } /** The Site is visible to the caller, but only its owner may do this. */ export declare class WorkspaceArtifactOwnerRequiredError extends Error { readonly name = "WorkspaceArtifactOwnerRequiredError"; } /** Whether this viewer can see the Site at all, without loading its history. */ export declare function isWorkspaceArtifactVisible(db: Database, workspaceId: string, viewer: WorkspaceArtifactViewer, artifactId: string): Promise; export declare function listWorkspaceArtifacts(db: Database, workspaceId: string, viewer: WorkspaceArtifactViewer, options?: { limit?: number; cursor?: string; status?: "active" | "archived"; sourceSessionId?: string; }): Promise<{ artifacts: WorkspaceArtifact[]; nextCursor: string | null; truncated: boolean; }>; export declare function getWorkspaceArtifact(db: Database, workspaceId: string, viewer: WorkspaceArtifactViewer, artifactId: string): Promise; /** * The Site and its current version alone, without its history: what an open * Site view checks every few seconds to see whether a new version is live. */ export declare function getWorkspaceArtifactCurrent(db: Database, workspaceId: string, viewer: WorkspaceArtifactViewer, artifactId: string): Promise; export declare function getWorkspaceArtifactContentRef(db: Database, workspaceId: string, viewer: WorkspaceArtifactViewer, artifactId: string, versionId?: string): Promise<{ artifactId: string; status: WorkspaceArtifact["status"]; version: WorkspaceArtifactVersion; contentKey: string; sourceKey: string | null; assetManifest: SiteAssetManifest | null; }>; /** * The asset manifest of one version, for the console's asset route. That * route has no signed-in caller (app frames send no credentials): the * version's unguessable token in the URL is the capability, checked by the * caller against this manifest. Null for an unknown version or a * single-file app. */ export declare function getSiteVersionAssetManifest(db: Database, workspaceId: string, versionId: string): Promise; type PublishMetadata = { uploadId?: string; accountId: string; workspaceId: string; contentKey: string; contentSha256: string | null; sizeBytes: number; sourceKey: string | null; sourceSha256: string | null; sourceSizeBytes: number | null; requestedTools?: ToolGatewayIdentity[]; /** Asset files of a multi-file build; omitted or null for a single-file app. */ assetManifest?: SiteAssetManifest | null; /** * App server code (docs/app-server-code.md): a new version's code, null to * remove it, or omitted to keep the current version's code (publish). */ serverManifest?: AppServerManifest | null; /** `requestedTools` as the caller declared them, before the server paired connector identities. */ declaredRequestedTools?: ToolGatewayIdentity[]; operationKey: string; actorSubjectId: string; sourceSessionId: string | null; sourceTurnId: string | null; sourceAttemptId: string | null; sourceExecutionGeneration: number | null; sourceToolName: ArtifactMutationToolName | null; persistContent: () => Promise; discardContent: () => Promise; }; type AttemptToolCatalogScope = Pick; /** * The requested tools an agent attempt may not declare: neither in its exact * tool catalog nor a connector identity paired with one of its own account * routes. Empty for a caller that is not an attempt. Throws when the * attempt's catalog can't be read. */ export declare function artifactRequestedToolsMissingFromAttemptCatalog(db: Database, input: AttemptToolCatalogScope, requestedTools: readonly ToolGatewayIdentity[]): Promise; export declare function createWorkspaceArtifact(db: Database, input: PublishMetadata & { artifactId: string; slug: string; title: string; description: string | null; requestedSlug?: string | null; /** Who can see it; `user_private` needs an owner. */ visibility: "workspace_shared" | "user_private"; /** The person it is published for: the human caller or the human an agent acts for. */ ownerSubjectId: string | null; }): Promise; /** * A new Site from a Site's current version. Stored Site content is immutable * and never collected per version, so the copy's first version references * the original's HTML and source objects instead of copying their bytes. * A retry with the same operation replays before the original is read again, * so later edits to the original cannot turn a committed copy into a conflict. */ export declare function duplicateWorkspaceArtifact(db: Database, input: Pick & { viewer: WorkspaceArtifactViewer; sourceArtifactId: string; artifactId: string; /** Omitted: `defaultTitle` of the original's title. */ title?: string; defaultTitle: (originalTitle: string) => string; slugFor: (title: string, artifactId: string) => string; /** Who can see the copy, from the original's visibility. */ resolveAudience: (visibility: WorkspaceArtifact["visibility"]) => Promise<{ visibility: "workspace_shared" | "user_private"; ownerSubjectId: string | null; }>; }): Promise; export declare function publishWorkspaceArtifactVersion(db: Database, input: PublishMetadata & { artifactId: string; expectedCurrentVersionId: string; title?: string; description?: string | null; viewer: WorkspaceArtifactViewer; }): Promise; export declare function rollbackWorkspaceArtifact(db: Database, input: Omit & { artifactId: string; versionId: string; expectedCurrentVersionId: string; reason: string; viewer: WorkspaceArtifactViewer; }): Promise; export declare function setWorkspaceArtifactStatus(db: Database, input: Omit & { artifactId: string; status: "active" | "archived"; expectedCurrentVersionId: string; reason: string; viewer: WorkspaceArtifactViewer; }): Promise; /** * Change who can see a Site. Only its owner can, and only while they can see * it; anyone else gets the same answer as for a Site that does not exist, or, * when the Site is shared with them, an owner-required refusal. Whether the * owner may make anything Only me is decided by the caller first. */ export declare function updateWorkspaceArtifactVisibility(db: Database, input: { workspaceId: string; artifactId: string; viewer: WorkspaceArtifactViewer; visibility: "workspace_shared" | "user_private"; }): Promise; export {};