import { type DbExec, type DbExecStatement } from "../db/client.js"; import { isLocalWorkspaceResourceId } from "../local-artifacts/index.js"; import { type StoreWriteOptions } from "../settings/store.js"; export declare const SHARED_OWNER = "__shared__"; export declare const WORKSPACE_OWNER = "__workspace__"; export declare function organizationResourceOwner(orgId: string): string; export declare function organizationIdFromResourceOwner(owner: string): string | null; export declare function sharedResourceOwner(orgId?: string | null): string; export declare function isBinaryResourceMimeType(mimeType: string): boolean; export declare function packScopeFromOwner(owner: string, userEmail: string): "personal" | "organization" | "workspace"; export declare function ownerForPackTarget(target: "personal" | "organization", userEmail: string, orgId?: string | null): string; export declare function workspaceResourceOwner(orgId?: string | null): string; export declare function isWorkspaceResourceOwner(owner: string): boolean; export declare function organizationIdFromWorkspaceResourceOwner(owner: string): string | null; export declare function isLegacySharedResourceVisibleToOrganization(resource: Pick, orgId?: string | null): boolean; export declare function isLegacyOrganizationWorkspaceFile(resource: Pick, orgId?: string | null): boolean; export interface Resource { id: string; path: string; owner: string; content: string; mimeType: string; size: number; createdAt: number; updatedAt: number; createdBy: ResourceCreatedBy; visibility: ResourceVisibility; threadId: string | null; runId: string | null; expiresAt: number | null; metadata: string | null; } export interface ResourceMeta { id: string; path: string; owner: string; mimeType: string; size: number; createdAt: number; updatedAt: number; createdBy: ResourceCreatedBy; visibility: ResourceVisibility; threadId: string | null; runId: string | null; expiresAt: number | null; metadata: string | null; } export interface ResourceContentProjection { id: string; path: string; owner: string; content: string; } export type ResourceCreatedBy = "user" | "agent" | "system"; export type ResourceVisibility = "workspace" | "agent_scratch"; export interface ResourceWriteOptions extends StoreWriteOptions { createdBy?: ResourceCreatedBy; visibility?: ResourceVisibility; threadId?: string | null; runId?: string | null; expiresAt?: number | null; metadata?: string | Record | null; } /** Notify listeners after commit and await asynchronous post-commit work. */ export interface TransactionScopedResourceWrite { value: T; notifyAfterCommit: () => void | Promise; } export interface PreparedResourceMutation extends TransactionScopedResourceWrite { statements: DbExecStatement[]; } export interface PrepareResourceCreateInput { id: string; owner: string; path: string; content: string; mimeType?: string; options?: ResourceWriteOptions; now?: number; } export interface ResourceConditionalWrite { owner: string; path: string; content: string; expectedId: string; expectedUpdatedAt: number; expectedContent: string; mimeType?: string; metadata?: ResourceWriteOptions["metadata"]; } export interface ResourceSnapshotWrite { previous: Resource | null; owner: string; path: string; content: string; mimeType?: string; options?: Pick; } export interface ResourceSnapshotWriteResult { before: Resource | null; resource: Resource; } export interface ResourceListOptions { includeAgentScratch?: boolean; limit?: number; workspaceAppId?: string | null; userEmail?: string | null; orgId?: string | null; } export interface ResourceResolutionOptions { workspaceAppId?: string | null; userEmail?: string | null; orgId?: string | null; } export type ResourceInheritanceScope = "workspace" | "shared" | "personal"; export interface EffectiveResourceLayer { scope: ResourceInheritanceScope; label: string; owner: string; resource: ResourceMeta | null; exists: boolean; effective: boolean; overridden: boolean; canWrite: boolean; } export interface EffectiveResourceContext { path: string; effectiveResource: ResourceMeta | null; effectiveScope: ResourceInheritanceScope | null; layers: EffectiveResourceLayer[]; } export declare const LOCAL_WORKSPACE_RESOURCE_METADATA_SOURCE = "local-workspace-resource"; export declare function canWriteLocalWorkspaceResourcePath(resourcePath: string): Promise; export { isLocalWorkspaceResourceId }; export declare const resourcesStore: import("../db/store-registry.js").Store; export declare function ensureTable(): Promise; export declare function ensurePersonalDefaults(owner: string): Promise; export declare function resourceGet(id: string, options?: ResourceResolutionOptions): Promise; export declare function resourceGetByPath(owner: string, path: string, options?: ResourceResolutionOptions): Promise; export declare function ensureResourceStoreReady(): Promise; /** * Write through an existing SQL transaction. The caller must initialize the * resource store before opening the transaction and invoke notifyAfterCommit * only after that transaction commits. */ export declare function prepareResourceCreate(input: PrepareResourceCreateInput): PreparedResourceMutation; export declare function prepareResourceBatchAssertion(condition: { sql: string; args: readonly unknown[]; }): { statements: DbExecStatement[]; cleanupStatement: DbExecStatement; }; export declare function prepareResourceUpdate(input: { current: Resource; content: string; mimeType?: string; now?: number; }): PreparedResourceMutation; export declare function prepareResourceDelete(resource: Resource): PreparedResourceMutation; export declare function resourcePutWithDb(client: DbExec, owner: string, path: string, content: string, mimeType?: string, options?: ResourceWriteOptions): Promise>; export declare function resourcePut(owner: string, path: string, content: string, mimeType?: string, options?: ResourceWriteOptions): Promise; export declare function resourcePutIfAbsent(owner: string, path: string, content: string, mimeType?: string, options?: ResourceWriteOptions): Promise; export declare function resourcePutIfCurrent(input: ResourceConditionalWrite): Promise; /** The caller must emit the returned notification only after its transaction commits. */ export declare function resourcePutIfCurrentInTransaction(input: ResourceConditionalWrite, tx: DbExec): Promise<{ resource: Resource; notify: () => Promise; } | null>; /** * Delete through an existing SQL transaction. The caller must await * notifyAfterCommit only after that transaction commits. */ export declare function resourceDeleteWithDb(client: DbExec, id: string): Promise>; export declare function resourcePutIfSnapshot(input: ResourceSnapshotWrite): Promise; export type ResourceSnapshotWriteOptions = { beforeWrite?: (tx: DbExec) => Promise; }; export type ResourceSnapshotPairOptions = ResourceSnapshotWriteOptions; export declare function resourcePutSnapshotBatchIfCurrent(writes: readonly ResourceSnapshotWrite[], options?: ResourceSnapshotWriteOptions): Promise; export declare function resourcePutSnapshotPairIfCurrent(writes: readonly [ResourceSnapshotWrite, ResourceSnapshotWrite], options?: ResourceSnapshotWriteOptions): Promise; export declare function resourceRestoreSnapshotIfCurrent(snapshot: Resource, current: Resource | null): Promise; export declare function resourceDeleteIfCurrent(resource: Resource): Promise; export declare function resourceDelete(id: string): Promise; export declare function resourceDeleteByPath(owner: string, path: string): Promise; export declare function resourceList(owner: string, pathPrefix?: string, options?: ResourceListOptions): Promise; export declare function resourceListContentByOwnersAndPrefixes(owners: readonly string[], pathPrefixes: readonly string[], options?: Pick): Promise; export declare function resourceListAccessible(userEmail: string, pathPrefix?: string, options?: ResourceListOptions): Promise; /** Organization/shared rows a caller can list, including the legacy app default. */ export declare function resourceListOrganization(orgId: string | null, pathPrefix?: string, options?: ResourceListOptions): Promise; export declare function resourceEffectiveContext(userEmail: string, path: string, options?: ResourceResolutionOptions): Promise; /** * A cheap change detector for everything `resourceListAllOwners(pathPrefix)` * reads: any insert, update, delete, move or snapshot restore of a SQL row * changes it, including a same-size edit in the same millisecond. Content is * hashed in the database, so only short per-row digests are transferred. * Local workspace files are tracked by path, modification time and content * hash. Equal to * the fingerprint `resourceListAllOwnersWithFingerprint` returns for the same * state. */ export declare function resourceFingerprintAllOwners(pathPrefix: string, options?: { timeoutMs?: number; }): Promise; export declare function resourceListAllOwners(pathPrefix: string, options?: { includeShadowedWorkspaceRows?: boolean; }): Promise; /** * `resourceListAllOwners` plus the fingerprint of exactly the rows that one * read returned, so a later `resourceFingerprintAllOwners` match proves the * list is unchanged. */ export declare function resourceListAllOwnersWithFingerprint(pathPrefix: string): Promise<{ resources: Resource[]; fingerprint: string; }>; export declare function resourceMove(id: string, newPath: string): Promise;