import { type SessionTenancyBlocker } from "@opengeni/contracts"; import { type Database } from "./database.js"; import { type SessionVisibilityWork, type SessionVisibilityWorkSettlement } from "./session-visibility-work.js"; export type { SessionVisibilityWork } from "./session-visibility-work.js"; export { EMPTY_SESSION_VISIBILITY_WORK } from "./session-visibility-work.js"; export declare class SessionTenancyConflictError extends Error { readonly reason: "not_quiescent" | "authority_epoch" | "operation_reuse"; readonly blocker: SessionTenancyBlocker | null; readonly name = "SessionTenancyConflictError"; constructor(reason: "not_quiescent" | "authority_epoch" | "operation_reuse", blocker?: SessionTenancyBlocker | null, options?: ErrorOptions); } /** * The organization's owner/admin Only-me setting does not permit a new private * session (or private transition) in this shared workspace. Activation itself is * universal since migration 0611; the name and the SESSION_TENANCY_NOT_ACTIVATED * wire code are kept for client compatibility. */ export declare class SessionTenancyNotActivatedError extends Error { readonly name = "SessionTenancyNotActivatedError"; constructor(options?: ErrorOptions); } export declare class SessionTenancyAccessError extends Error { readonly name = "SessionTenancyAccessError"; constructor(options?: ErrorOptions); } /** * The chat has work the person can see (a running or parked response, queued * messages, an active goal). `active_work` asks for "make private anyway" * consent; `stopping_active_work` means the consented stop is still settling * and the same request can be retried. */ export declare class SessionVisibilityWorkConflictError extends Error { readonly reason: "active_work" | "stopping_active_work"; readonly work: SessionVisibilityWork; /** Attempts a worker is executing right now; stopping them is asynchronous. */ readonly liveAttemptCount: number; readonly name = "SessionVisibilityWorkConflictError"; constructor(reason: "active_work" | "stopping_active_work", work: SessionVisibilityWork, /** Attempts a worker is executing right now; stopping them is asynchronous. */ liveAttemptCount: number, options?: ErrorOptions); } export declare class SessionTenancyInvalidRequestError extends Error { /** Why a message could not be used as a fork point, when that was the refusal. */ readonly forkPointRefusal: SessionForkPointRefusal | null; readonly name = "SessionTenancyInvalidRequestError"; constructor(options?: ErrorOptions, /** Why a message could not be used as a fork point, when that was the refusal. */ forkPointRefusal?: SessionForkPointRefusal | null); } /** Why `fork_session_content` refused the selected message as a fork boundary. */ export type SessionForkPointRefusal = "message_unavailable" | "boundary_not_retained" | "history_compacted" | "unfinished_tool_exchange"; /** Extract only the fixed fork-boundary refusal vocabulary from a nested driver error. */ export declare function nestedSessionForkPointRefusal(error: unknown): SessionForkPointRefusal | null; /** Extract only the fixed quiescence DETAIL vocabulary, never arbitrary driver detail. */ export declare function nestedSessionTenancyBlocker(error: unknown): SessionTenancyBlocker | null; export type SessionTenancyVisibility = "user_private" | "workspace_shared"; export type PrivateSessionCreatePolicy = { personalWorkspace: boolean; platformAvailable: boolean; organizationEnabled: boolean; }; export type TransitionSessionVisibilityInput = { workspaceId: string; sessionId: string; actorSubjectId: string; targetVisibility: SessionTenancyVisibility; expectedAuthorityEpoch: number; operationKey: string; /** * The owner consented to stop visible work (cancel parked and queued turns, * pause the active goal). Leftovers are always settled. Excluded from the * idempotency hash: it is consent, not a different requested outcome. */ stopActiveWork?: boolean; beforeCommit?: (tx: Database) => Promise; }; export type TransitionSessionVisibilityResult = { operationId: string; eventId: string | null; eventSequence: number | null; visibility: SessionTenancyVisibility; authorityEpoch: number; ownerOrganizationMembershipId: string | null; changed: boolean; replay: boolean; interruptedAttemptCount: number; cancelledTurnCount: number; cancelledUpdateCount: number; pausedGoalCount: number; revokedGrantCount: number; /** Events written while settling leftovers and consented work, in order. */ settledEventIds: string[]; workflowWake: SessionVisibilityWorkSettlement["workflowWake"]; }; export type ForkSessionContentInput = { sourceEventId?: string; sourceWorkspaceId: string; sourceSessionId: string; actorSubjectId: string; destinationWorkspaceId: string; destinationVisibility: SessionTenancyVisibility; workspaceSharedAcknowledged: boolean; operationKey: string; runtimeRequest?: ForkSessionRuntimeRequest; runtimeConfiguration?: ForkSessionRuntimeConfiguration; beforeCommit?: (tx: Database) => Promise; }; export type ForkSessionRuntimeRequest = { rigId: string | null; }; export type ForkSessionRuntimeConfiguration = ForkSessionRuntimeRequest & { rigVersionId: string | null; }; export type ForkSessionContentResult = { operationId: string; eventId: string; eventSequence: number; sessionId: string; workspaceId: string; visibility: SessionTenancyVisibility; authorityEpoch: number; copiedHistoryItemCount: number; replay: boolean; runtimeEventId: string | null; runtimeEventSequence: number | null; }; export declare function getPrivateSessionCreatePolicy(db: Database, input: { workspaceId: string; actorSubjectId: string; }): Promise; /** Open the exact transaction-local trigger capability used by atomic private create. */ export declare function openPrivateSessionCreateCapability(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; actorSubjectId: string; }): Promise<{ capabilityId: string; ownerMembershipId: string; }>; /** Open the exact transaction-local capability for one private child insert. */ export declare function openPrivateChildSessionCreateCapability(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; parentSessionId: string; actorTurnId: string; actorAttemptId: string; actorExecutionGeneration: number; }): Promise<{ capabilityId: string; ownerMembershipId: string; ownerSubjectId: string; }>; export declare function closePrivateSessionCreateCapability(db: Database, capabilityId: string): Promise; export declare function canonicalSessionVisibilityTransitionHash(input: Pick): string; export declare function canonicalSessionForkHash(input: Pick): string; export declare function transitionSessionVisibility(db: Database, input: TransitionSessionVisibilityInput): Promise; export type SessionVisibilityChangePreview = { visibility: SessionTenancyVisibility; authorityEpoch: number; /** What a confirmed change to Only me stops or removes; nothing else refuses it. */ work: SessionVisibilityWork; }; /** Owner-only, read-only answer to "what happens if I make this chat Only me?". */ export declare function inspectSessionVisibilityChange(db: Database, input: { workspaceId: string; sessionId: string; actorSubjectId: string; }): Promise; export type StopSessionWorkForVisibilityChangeResult = { interruptedAttemptCount: number; liveAttemptCount: number; eventIds: string[]; workflowWake: SessionVisibilityWorkSettlement["workflowWake"]; }; /** * First half of a consented "make private anyway" when a worker is executing * the chat: durably interrupt each live attempt (the worker cancels the turn * when it settles), cancel everything queued or parked, and pause the goal. * It commits on its own; the transition that follows drops everything else. */ export declare function stopSessionWorkForVisibilityChange(db: Database, input: { workspaceId: string; sessionId: string; actorSubjectId: string; expectedAuthorityEpoch: number; operationKey: string; }): Promise; /** Whether a worker is still executing an attempt of this session (read-only). */ export declare function sessionHasLiveAttempts(db: Database, input: { workspaceId: string; sessionId: string; actorSubjectId: string; }): Promise; export declare function forkSessionContent(db: Database, input: ForkSessionContentInput): Promise; /** * Recover one exact committed fork before mutable source-session authorization. * * The database capability requires the authenticated actor's active workspace * authority and matches the complete actor/workspace/source/key/request-hash * tuple. A fresh key returns null; changed intent raises the ordinary tenancy * idempotency conflict. This is receipt recovery, not session discovery. */ export declare function replayAppliedSessionFork(db: Database, input: ForkSessionContentInput): Promise;