import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'; import type { ApprovalDispatchRouteV2 } from '@dsh-enhanced/assistant-policy'; import { type ResolvedWorkflowAutomationTemplate, type WorkflowAutomationTemplate, type WorkflowAutomationTemplateContent, type WorkflowStepFingerprint, type WorkflowTraceRevision, type WorkflowTraceSourceAttestation } from '@dsh-enhanced/assistant-growth-contract'; import { type ObjectiveCommand, type ObjectiveFeedbackStatus } from './feedback-command.js'; import { type OwnerGoalOutcomeFeedbackLocator, type OwnerGoalOutcomeFeedbackProof } from './goal-wake-types.js'; import type { AcceptanceContract, AcceptedExecution, ForegroundExecution } from './acceptance.js'; import type { ForegroundTaskIdentity } from './foreground-observation.js'; import type { SessionLease, SessionLeaseClaim, SessionLeaseTarget } from './session-lease-types.js'; import type { ConversationBinding, ConversationModelSelection, ConversationRef, DeadLetterResolutionKind, DeadLetterResolutionReceipt, DeadLetterResolutionResult, DeliveryAttachment, DeliveryGoalOutcomeTarget, DeliveryPreferenceEvent, DeliveryPresentationUpdate, DeliveryPrincipal, DeliveryProgressIntent, DeliveryProgressRecord, DeliveryReceipt, ExternalPrincipalKey, InboundEnvelope, InboxRecord, OutboundIntent, ModelPickerIntent, ModelPickerState, ModelRouteRef, OwnerApprovalForPreferenceInput, OwnerRouteAuthority, OwnerForegroundTaskSource, OwnerForegroundTaskSourceScope, OwnerForegroundTaskSourceCursor, OwnerForegroundTaskSourcePage, OwnerForegroundTaskSourceContent, OwnerForegroundTaskSourceRef, OutboxRecord, PairingChallenge, PermissionPickerIntent, StoredDeliveryPresentation } from './types.js'; export type DeliveryStoreErrorCode = 'conflict' | 'idempotency-conflict' | 'invalid-binding' | 'invalid-envelope' | 'invalid-intent' | 'not-found' | 'pairing-expired' | 'pairing-invalid' | 'pairing-locked' | 'pairing-principal-mismatch' | 'pairing-replayed' | 'receipt-mismatch' | 'stale-fence' | 'unauthorized-principal' | 'version-conflict'; export declare class DeliveryStoreError extends Error { readonly code: DeliveryStoreErrorCode; constructor(code: DeliveryStoreErrorCode, message: string); } interface DeliveryStoreOptions { path: string; now?: () => number; codeGenerator?: () => string; maxTextBytes?: number; } export interface OwnerRouteDispatchGuard { readonly ownerRoutes: readonly Readonly[]; /** False is an explicit revocation; throw means the check is unavailable and must be retried without I/O. */ readonly authorize: (input: { authority: Readonly; sourceId: string; idempotencyKey: string; }) => boolean; } export type OwnerRouteDispatchValidation = { kind: 'not-route'; } | { kind: 'authorized'; } | { kind: 'deferred'; failureCode: string; } | { kind: 'denied'; failureCode: string; }; /** * Immutable binding evidence required at the Inbox-to-Agent dispatch boundary. * * A Host-native input uses the same snapshot when it atomically admits and * claims its exact Inbox, then again before it crosses `dispatch-started`. */ export type InboundDispatchBindingSnapshot = Pick; export interface ApprovalDispatchCursor { createdAt: number; proposalId: string; } export interface ApprovalDispatchCursorState { version: number; after?: ApprovalDispatchCursor; } interface WorkflowTraceRevisionRow { subject_ref: string; version: number; source_generation: number; source_authority_digest: string; scope_key: string; workspace: string; preset: string; disposition: WorkflowTraceRevision['disposition']; digest: string; payload_json: string; created_at: number; } interface WorkflowTraceOutboxRow extends WorkflowTraceRevisionRow { status: 'delivered' | 'pending' | 'retry_wait'; attempt_count: number; next_attempt_at: number; failure_code: string | null; updated_at: number; } interface PreferenceProjectionLane { epoch: string; workspace: string; preset: string; principalRecordId: string; principalVersion: number; admissionSequence: number; } interface WorkflowTemplateRow { template_ref: string; template_digest: string; scope_key: string; workspace: string; preset: string; owner_binding_id: string; content_json: string; privacy_kind: WorkflowAutomationTemplate['privacyAttestation']['kind']; privacy_attestation_id: string; privacy_attestation_digest: string; review_receipt_json: string; status: 'active' | 'revoked'; review_inbox_id: string; source_inbox_id: string; source_outbox_id: string; created_at: number; updated_at: number; version: number; } export interface WorkflowTraceOutboxEntry { revision: Readonly; status: WorkflowTraceOutboxRow['status']; attemptCount: number; nextAttemptAt: number; failureCode?: string; updatedAt: number; } export interface PreferenceProjectionOutboxEntry { batchKey: string; payloadDigest: string; events: readonly Readonly[]; lane?: Readonly; attemptCount: number; nextAttemptAt: number; failureCode?: string; } export type PreferenceProjectionFenceResult = 'completed' | 'ignored' | 'missing'; export interface OwnerWorkflowTraceCommandResult { revision: Readonly; template?: Readonly; replayed: boolean; } /** * The durable result of an authenticated owner objective judgement over one * ordinary Agent reply. Only an achieved judgement with a closed-set, * deterministic template can create a workflow trace. */ export type VerifiedWorkflowTraceFeedbackResult = Readonly<{ ownerFeedbackState?: Readonly<{ version: number; objectiveStatus: 'achieved' | 'partial' | 'not-achieved' | 'unknown'; }>; }> & (Readonly<{ outcome: 'trace-recorded'; revision: Readonly; template: Readonly; replayed: boolean; }> | Readonly<{ outcome: 'no-trace'; reason: 'objective-not-achieved' | 'privacy-abstained'; replayed: boolean; }>); /** Shared binding/principal anchors every review kind must carry. */ export interface WorkflowTemplateReviewBinding { bindingId: string; bindingVersion: number; bindingGeneration: number; principalId: string; } /** * Review receipt anchored on the live Inbox/Outbox fence for the owner-explicit * and deterministic-deidentification routes stored in workflow_template_registry. */ export type StoredWorkflowTemplateReview = Readonly & (Readonly<{ kind: 'inbox-anchored'; reviewInboxId: string; sourceInboxId: string; sourceOutboxId: string; }> | Readonly<{ /** * Anchored on a Delivery-reverified owner-root successful Goal run rather * than a live conversation fence. It carries the exact goal/run/acceptance * identity and the owner-run-trace digest instead of inbox/outbox ids. */ kind: 'goal-anchored'; ownerRouteId: string; goalId: string; nativeGoalId: string; sessionId: string; runId: string; turn: number; acceptanceContractId: string; acceptanceReceiptDigest: string; ownerRunTraceDigest: string; taskRef: string; }>); export interface StoredWorkflowTemplate { resolved: Readonly; review: StoredWorkflowTemplateReview; status: WorkflowTemplateRow['status']; version: number; } /** * Outcome of an owner-anchored workflow learning attempt. A goal that cannot be * honestly reduced to the single `assistant.agent-turn` step Automations can * safely materialize abstains with zero writes rather than emitting a trace. */ export type CommitOwnerAnchoredWorkflowTraceResult = Readonly<{ outcome: 'trace-recorded'; revision: Readonly; template: Readonly; replayed: boolean; }> | Readonly<{ outcome: 'abstained'; reason: 'not-reducible'; replayed: false; }>; export type NaturalObjectiveIntent = Readonly<{ inboxId: string; envelopeHash: string; sourceInboxId: string; sourceOutboxId: string; bindingId: string; bindingVersion: number; bindingGeneration: number; principalRecordId: string; principalVersion: number; admissionEpoch: string; admissionSequence: number; occurredAt: number; selection: ObjectiveFeedbackStatus | 'withdraw'; status: 'awaiting-evaluation' | 'frozen' | 'projected' | 'conflict'; command?: Extract; canonical?: Readonly<{ version: number; objectiveStatus: ObjectiveFeedbackStatus | 'unknown'; }>; }>; export declare class DeliveryStore { private readonly database; /** Scan position only; every candidate is authorized again before a provider retry. */ private readonly progressRecoveryCursors; private readonly databaseInstanceId; private readonly now; private readonly codeGenerator; private readonly maxTextBytes; private closed; private writerTransactionActive; constructor(options: DeliveryStoreOptions); instanceId(): string; issuePairing(input: ExternalPrincipalKey, options: { ttlMs: number; maxAttempts: number; }): { challenge: PairingChallenge; code: string; }; confirmPairing(input: { challengeId: string; principal: ExternalPrincipalKey; code: string; }): DeliveryPrincipal; /** * Trusted local owner rotation. Unlike an ordinary pairing, this promotes * the exact replacement principal and retires every previous active owner in * one SQLite transaction, so setup can never leave two active owners or turn * the newly discovered owner into a merely linked identity. */ handoffOwner(input: ExternalPrincipalKey): DeliveryPrincipal; /** * Bootstrap one empty Delivery database for a fixed local operator. This is * deliberately narrower than handoffOwner(): once any principal history * exists it can only return the exact, sole active owner without changing a * row, its bindings, or any linked authority. */ ensureOwner(input: ExternalPrincipalKey): DeliveryPrincipal; isAuthorizedPrincipal(input: ExternalPrincipalKey): boolean; getPrincipal(input: ExternalPrincipalKey): DeliveryPrincipal | undefined; private getBindingPrincipal; createBinding(input: { conversation: ConversationRef; principal: ExternalPrincipalKey; workspace: string; agentPreset: string; sessionId: string; policyRef: string; expectedGeneration?: number; constructionLease?: SessionLease; }): ConversationBinding; /** * Snapshot the generation a newly-created session must use. `createBinding` * revalidates this value under `BEGIN IMMEDIATE` when passed as * `expectedGeneration`, so a concurrent generation change fails closed. */ nextBindingGeneration(input: ConversationRef): number; getActiveBinding(input: ConversationRef): ConversationBinding | undefined; getBinding(id: string): ConversationBinding | undefined; listBindings(input: ConversationRef): ConversationBinding[]; /** Read-only operator query. Callers must apply their own exact route checks. */ listActiveBindings(): ConversationBinding[]; /** Snapshot one exact active owner binding under the Delivery write fence. */ resolveApprovalRouteByBinding(input: Readonly<{ sourceId: string; bindingId: string; scope: Readonly<{ workspace: string; preset: string; }>; principalId?: string; }>): ApprovalDispatchRouteV2 | undefined; /** Resolve one unique current owner from content-free Host authority evidence. */ resolveOwnerApprovalForPreference(input: Readonly): ApprovalDispatchRouteV2 | undefined; getBindingBySession(sessionId: string): ConversationBinding | undefined; /** Read one exact Agent owner attestation under a single SQLite snapshot. */ getPreferencePrincipalForSession(input: Readonly<{ sessionId: string; workspace: string | undefined; preset: string | undefined; }>): Readonly<{ binding: ConversationBinding; principal: DeliveryPrincipal; }> | undefined; getModelSelection(input: ConversationRef): ConversationModelSelection | undefined; setModelSelection(input: ConversationRef, route: ModelRouteRef): ConversationModelSelection; clearModelSelection(input: ConversationRef): boolean; /** * Remove one now-invalid persisted effort without replacing a newer model choice. * * Model capability directories are intentionally live data: an effort selected yesterday can * disappear when a provider changes a model or account entitlement. The compare-and-swap keeps * a concurrently chosen provider/model/effort authoritative instead of silently applying this * recovery to it. */ clearStaleModelReasoningEffort(input: { conversation: ConversationRef; expected: Pick; }): { applied: false; } | { applied: true; selection: ConversationModelSelection; }; beginModelCommand(input: ConversationRef): number; commitModelCommand(input: { conversation: ConversationRef; expectedEpoch: number; route?: ModelRouteRef; }): { applied: false; } | { applied: true; selection?: ConversationModelSelection; }; rotateBinding(input: { bindingId: string; expectedVersion: number; sessionId: string; }): ConversationBinding; /** * Consume one exact `/new` Inbox while rotating its binding. * * The Inbox transition is part of the same SQLite commit as revoking the * previous binding and inserting its successor. Consequently a provider * replay can observe either the entirely old state or the entirely new * state, never a rotated binding paired with an unconsumed command. */ rotateBindingAndQueueCommand(input: { bindingId: string; expectedVersion: number; sessionId: string; inboxId: string; }): { binding: ConversationBinding; inbox: InboxRecord; }; acceptInbound(input: InboundEnvelope): { duplicate: boolean; record: InboxRecord; }; /** * Admit and claim one exact Host-native input under one SQLite write fence. * * The normal Delivery scheduler can only claim queued work. Publishing a * fresh native input directly as `claimed` therefore prevents it from * observing a moment where the input is in the ordinary queue. Replays are * read-only: a duplicate never renews, reclaims, or otherwise re-executes * its existing Inbox. */ claimNativeInbox(input: { envelope: InboundEnvelope; binding: Readonly; ownerLineage: { principalRecordId: string; principalVersion: number; }; ownerId: string; leaseMs: number; }): { duplicate: boolean; record: InboxRecord; fencingToken?: number; }; listAttachments(input: { ownerKind: 'inbox' | 'outbox'; ownerId: string; }): DeliveryAttachment[]; /** * Return complete durable image references in the provider descriptor order. * `undefined` means the image descriptors have not been materialized yet. */ listReadyInboundImageRefs(inboxId: string): readonly ImageAttachmentRef[] | undefined; /** Atomically persist one ordered image batch while the caller still owns the live inbox lease. */ commitInboundImageRefs(input: { inboxId: string; ownerId: string; fencingToken: number; images: readonly { ref: ImageAttachmentRef; contentSha256: string; }[]; }): readonly ImageAttachmentRef[]; queueInbox(inboxId: string, bindingId: string): InboxRecord; /** * Establish a durable command boundary before `/stop` or `/new` is queued. * * Every earlier record in the same binding that has not crossed the exact * dispatch marker becomes terminal in one transaction. A normal claim * carrying `dispatch-started` is deliberately left live because the external * Agent may have observed it already. Exact permission commands instead get * a durable cancelled-recovery marker before the runtime is asked to abort. */ cancelUndispatchedInboxBefore(input: { bindingId: string; beforeInboxId: string; failureCode: string; }): { cancelled: number; dispatching: number; claimedInboxIds: string[]; dispatchingInboxIds: string[]; }; getInbox(id: string): InboxRecord | undefined; getInboxByProviderEvent(channel: string, account: string, eventId: string): InboxRecord | undefined; private progressAuthority; private progressRecord; private progressRow; /** Reserve before provider I/O; a stranded creating row must never trigger another create. */ beginProgress(intent: DeliveryProgressIntent, credentialFingerprint: string, sequence: number, showDetails: boolean): { record: DeliveryProgressRecord; created: boolean; } | undefined; getProgress(intent: DeliveryProgressIntent, credentialFingerprint: string): DeliveryProgressRecord | undefined; attachProgressHandle(intent: DeliveryProgressIntent, credentialFingerprint: string, providerHandle: string): DeliveryProgressRecord | undefined; advanceProgress(intent: DeliveryProgressIntent, credentialFingerprint: string): DeliveryProgressRecord | undefined; stageProgressTerminal(intent: DeliveryProgressIntent, credentialFingerprint: string): DeliveryProgressRecord | undefined; confirmProgressTerminal(intent: DeliveryProgressIntent, credentialFingerprint: string): void; /** Only authoritative settled Inbox rows are eligible for restart repair. */ recoverProgress(channel: string, account: string, credentialFingerprint: string, limit: number, authorize?: (binding: ConversationBinding, inbox: InboxRecord) => boolean): DeliveryProgressRecord[]; /** Return the oldest durable admission that did not finish before another Inbox. */ findPendingInboundBefore(input: { conversation: ConversationRef; principal: ExternalPrincipalKey; beforeInboxId: string; }): InboxRecord | undefined; /** * List a bounded page of persisted admissions that have not reached the * worker queue yet. The admission cursor, rather than timestamps or rowid, * preserves the global order across restarts and database maintenance. */ listRecoverableInboundAdmissions(input?: { afterSequence?: number; limit?: number; }): InboxRecord[]; /** Scan durable, unacknowledged dispatched turns without replaying their Agent work. */ listInterruptedInboxNotices(input?: { afterSequence?: number; limit?: number; }): InboxRecord[]; /** The final notice decision and Outbox insert share one SQLite writer fence. */ enqueueInterruptedInboxNotice(input: { inboxId: string; binding: Readonly; intent: OutboundIntent; }): OutboxRecord; /** Recheck a queued interruption notice immediately before an adapter send. */ canSendInterruptedInboxNotice(record: Readonly): boolean; private interruptedInboxNoticeCurrent; listInbox(input?: { bindingId?: string; limit?: number; }): InboxRecord[]; getDeadLetterResolution(input: { kind: DeadLetterResolutionKind; id: string; attemptCount: number; }): DeadLetterResolutionReceipt | undefined; health(): { pendingInbox: number; /** All retained Inbox rows in dead_letter, including operator-resolved tombstones. */ deadLetterInbox: number; actionableDeadLetterInbox: number; resolvedDeadLetterInbox: number; pendingOutbox: number; /** All retained Outbox rows in dead, including operator-resolved tombstones. */ deadLetterOutbox: number; actionableDeadLetterOutbox: number; resolvedDeadLetterOutbox: number; /** All retained ambiguous Outbox rows, including operator-resolved tombstones. */ unknownOutbox: number; actionableUnknownOutbox: number; resolvedUnknownOutbox: number; pendingPresentations: number; deadPresentations: number; }; getApprovalDispatchCursor(): ApprovalDispatchCursorState; advanceApprovalDispatchCursor(input: { expectedVersion: number; after?: Readonly; }): ApprovalDispatchCursorState; deadLetterInbox(inboxId: string, failureCode: string): InboxRecord; /** A durable control message wins even while its async binding transition is waiting. */ hasRestartCancellationAfter(inboxId: string, binding: Readonly): boolean; /** The fence and Inbox claims share this database's write transaction. */ setRestartFence(requestId: string, sourceInvocationId: string): void; getRestartFence(): { requestId: string; sourceInvocationId: string; } | undefined; clearRestartFence(requestId: string): void; claimInbox(input: { ownerId: string; leaseMs: number; limit: number; maxAttempts: number; maintenanceLimit?: number; }): { record: InboxRecord; fencingToken: number; }[]; finishInbox(input: { inboxId: string; ownerId: string; fencingToken: number; outcome: 'dead_letter' | 'processed' | 'retry_wait'; failureCode?: string; retryAt?: number; }): InboxRecord; /** Return an undispatched Inbox to its queue while another live session holds the lane. */ deferInboxForSessionLease(input: { inboxId: string; ownerId: string; fencingToken: number; retryAt: number; }): boolean; markInboxDispatching(input: { inboxId: string; ownerId: string; fencingToken: number; binding: Readonly; }): InboxRecord; /** Immutable pre-prompt binding for a foreground acceptance contract. */ bindForegroundTaskAcceptance(input: { inboxId: string; contractId: string; contractDigest: string; scope: { workspace: string; preset: string; }; owner: { principalRecordId: string; principalVersion: number; }; binding: Pick; dispatchedAt: number; }): void; finishForegroundTaskAcceptance(input: { contractId: string; status: AcceptedExecution['status']; quiescent: boolean; completedAt: number; }): void; recordForegroundTaskModelSelection(input: { contractId: string; provider: string; model: string; reasoningEffort?: string; }): void; inspectForegroundAcceptedExecution(contract: AcceptanceContract): AcceptedExecution | null; /** * Re-read the immutable acceptance fence for one exact owner reply target. * This deliberately exposes only the completed execution receipt: callers * cannot manufacture a foreground subject by naming an arbitrary Inbox. */ inspectForegroundAcceptedExecutionForOwner(input: { inboxId: string; scope: { workspace: string; preset: string; }; owner: { principalRecordId: string; principalVersion: number; }; bindingId: string; }): AcceptedExecution | null; /** One SQL snapshot binds a pending execution to its still claimed Inbox and current owner. */ inspectPendingForegroundToolTask(input: Readonly<{ inboxId: string; sessionId: string; scope: { workspace: string; preset: string; }; owner: { principalRecordId: string; principalVersion: number; }; binding: { id: string; version: number; generation: number; }; }>): Readonly | undefined; /** Immutable pre-prompt receipt for an authenticated owner foreground turn. */ bindForegroundTaskExecution(input: { inboxId: string; scope: { workspace: string; preset: string; }; owner: { principalRecordId: string; principalVersion: number; }; binding: Pick; dispatchedAt: number; }): void; finishForegroundTaskExecution(input: { inboxId: string; status: ForegroundExecution['status']; quiescent: boolean; completedAt: number; }): void; recordForegroundExecutionModelSelection(input: { inboxId: string; provider: string; model: string; reasoningEffort?: string; }): void; private foregroundSourceFence; private foregroundSource; /** Host-only durable completion feed. Mutable delivery state never hides a completion. */ listOwnerForegroundTaskSources(input: OwnerForegroundTaskSourceScope & { after?: Readonly; limit?: number; }, authority: OwnerRouteAuthority): Readonly; /** Host-only exact inbox metadata under the same owner writer fence as the feed. */ inspectOwnerForegroundTaskSource(input: OwnerForegroundTaskSourceScope & { inboxId: string; }, authority: OwnerRouteAuthority): Readonly | undefined; /** Content comes from the canonical Inbox/Outbox, with no alternate text ledger. */ readOwnerForegroundTaskSource(input: OwnerForegroundTaskSourceScope & { inboxId: string; expectedSourceDigest: string; maxInputBytes?: number; maxReplyBytes?: number; }, authority: OwnerRouteAuthority): Readonly | undefined; /** Lock order: Delivery, then downstream Evaluation/Memory writer fences. */ withOwnerForegroundTaskSourceFence(input: OwnerForegroundTaskSourceScope & { inboxId: string; expectedSourceDigest: string; maxInputBytes?: number; maxReplyBytes?: number; }, authority: OwnerRouteAuthority, callback: (source: Readonly) => T): T; /** One owner check and one Delivery writer transaction for an ordered set of exact sources. */ withOwnerForegroundTaskSourcesFence(input: OwnerForegroundTaskSourceScope & { sources: readonly Readonly[]; }, authority: OwnerRouteAuthority, callback: (sources: readonly (Readonly | undefined)[]) => T): T; private assertForegroundSourceSyncResult; private withForegroundSourceRead; private foregroundSourceContent; inspectForegroundExecutionForOwner(input: { inboxId: string; scope: { workspace: string; preset: string; }; owner: { principalRecordId: string; principalVersion: number; }; bindingId: string; bindingVersion: number; bindingGeneration: number; }): ForegroundExecution | null; renewInboxClaim(input: { inboxId: string; ownerId: string; fencingToken: number; leaseMs: number; }): boolean; recoverInbox(input: { maxAttempts: number; limit?: number; }): InboxRecord[]; enqueue(input: OutboundIntent): OutboxRecord; private enqueueIntent; /** * Atomically revalidate one immutable Policy route and insert its approval * Outbox. Legacy routes are deliberately not accepted by this boundary. */ enqueueApprovalRoute(input: { route: Readonly; intent: Readonly<{ approval: NonNullable; idempotencyKey: string; text: string; }>; }): OutboxRecord; /** Atomically insert a typed whole-goal result and its immutable authority sidecar. */ enqueueGoalOutcomeTarget(input: Readonly<{ intent: OutboundIntent; locator: OwnerGoalOutcomeFeedbackLocator; proof: OwnerGoalOutcomeFeedbackProof; }>): OutboxRecord; getGoalOutcomeTarget(outboxId: string): DeliveryGoalOutcomeTarget | undefined; /** * Resolve and enqueue one Host-owned stable owner route under the same * `BEGIN IMMEDIATE` fence as Outbox insertion. * * This closes the `/new` race between an earlier read and insertion. An * existing idempotency winner is returned without mutation (including * `unknown_after_send`) only after both the current route and the winner's * immutable historical route receipt are revalidated. */ enqueueOwnerRoute(input: { authority: OwnerRouteAuthority; sourceId: string; sourceHash: string; idempotencyKey: string; text: string; format?: 'markdown' | 'plain'; }): OutboxRecord; getOutbox(id: string): OutboxRecord | undefined; getOutboxByIdempotencyKey(idempotencyKeyInput: string): OutboxRecord | undefined; /** Persist the latest desired replacement for one exact durable message. */ publishDeliveryPresentation(input: DeliveryPresentationUpdate): StoredDeliveryPresentation; getDeliveryPresentation(presentationKeyInput: string): StoredDeliveryPresentation | undefined; claimDeliveryPresentation(input: { ownerId: string; leaseMs: number; /** Lifecycles already attempted by this drain pass. */ excludePresentationKeys?: readonly string[]; }): { presentation: StoredDeliveryPresentation; fencingToken: number; } | undefined; finishDeliveryPresentation(input: { presentationKey: string; revision: number; ownerId: string; fencingToken: number; outcome: 'presented' | 'retry_wait' | 'dead'; providerMessageId?: string; failureCode?: string; nextAttemptAt?: number; }): StoredDeliveryPresentation; /** Exact provider-addressed lookup used only to bind authenticated replies. */ getOutboxByProviderMessage(channelInput: string, accountInput: string, providerMessageIdInput: string): OutboxRecord | undefined; getApprovalIntent(operationId: string, bindingId: string): NonNullable | undefined; getModelPicker(operationId: string, bindingId: string): ModelPickerIntent | undefined; getModelPickerRecord(operationId: string, bindingId: string): OutboxRecord | undefined; getPermissionPicker(operationId: string, bindingId: string): PermissionPickerIntent | undefined; getPermissionPickerRecord(operationId: string, bindingId: string): OutboxRecord | undefined; getModelPickerState(operationId: string, bindingId: string): ModelPickerState | undefined; advanceModelPicker(input: { operationId: string; bindingId: string; expected: ModelPickerState; next: ModelRouteRef; }): { applied: boolean; state: ModelPickerState; }; listOutbox(input?: { bindingId?: string; limit?: number; }): OutboxRecord[]; /** Recheck a claimed route immediately before provider I/O. */ validateClaimedOwnerRoute(recordInput: Readonly, guard: Readonly): OwnerRouteDispatchValidation; /** Recheck a durable owner route before mutating its exact provider message. */ validatePresentationOwnerRoute(recordInput: Readonly, guard: Readonly): OwnerRouteDispatchValidation; private inspectOwnerRouteDispatch; private ownerRouteIsProvablyUnsent; private rebindOwnerRouteBeforeClaim; private deadLetterOwnerRouteBeforeClaim; private deferOwnerRouteBeforeClaim; claimOutbox(input: { ownerId: string; leaseMs: number; limit: number; maxAttempts: number; /** Undefined preserves the legacy store-level behavior; an empty list parks every unknown lane. */ unknownReconcileRoutes?: readonly Readonly<{ channel: string; account: string; }>[]; /** Locally active work that must not be reclaimed even if its durable lease was externally lost. */ excludeIds?: readonly string[]; maintenanceLimit?: number; ownerRouteGuard?: Readonly; }): { record: OutboxRecord; fencingToken: number; mode: 'reconcile' | 'send'; }[]; renewOutboxClaim(input: { outboxId: string; ownerId: string; fencingToken: number; leaseMs: number; }): boolean; finishOutbox(input: { outboxId: string; ownerId: string; fencingToken: number; outcome: 'accepted' | 'dead' | 'retry_wait' | 'unknown_after_send'; providerMessageId?: string; failureCode?: string; retryAt?: number; }): OutboxRecord; recoverOutbox(input: { maxAttempts: number; limit?: number; }): OutboxRecord[]; recordReceipt(input: DeliveryReceipt): OutboxRecord; revokePrincipal(id: string, expectedVersion: number): DeliveryPrincipal; linkPrincipal(input: { owner: ExternalPrincipalKey; linked: ExternalPrincipalKey; expectedLinkedVersion: number; }): DeliveryPrincipal; resolveInbox(input: { inboxId: string; expectedAttemptCount: number; resolution: 'cancel' | 'retry'; operatorId: string; }): DeadLetterResolutionResult; resolveOutbox(input: { outboxId: string; expectedAttemptCount: number; resolution: 'cancel' | 'retry'; operatorId: string; }): DeadLetterResolutionResult; beginApprovalSettlement(input: { operationId: string; payload: unknown; createIfMissing?: boolean; }): { payloadHash: string; replayed: boolean; result?: unknown; }; completeApprovalSettlement(input: { operationId: string; payloadHash: string; result: unknown; }): unknown; beginModelSelectionSettlement(input: { operationId: string; bindingId: string; expected: ModelPickerState; payload: unknown; createIfMissing?: boolean; }): { payloadHash: string; replayed: boolean; status: 'completed' | 'pending'; result?: unknown; }; getModelSelectionSettlement(input: { operationId: string; bindingId: string; expected: ModelPickerState; payload: unknown; }): { status: 'completed' | 'pending' | 'processing'; result?: unknown; } | undefined; claimModelSelectionSettlements(input: { ownerId: string; leaseMs: number; limit?: number; }): Array<{ operationId: string; bindingId: string; payloadHash: string; payload: unknown; fencingToken: number; }>; nextModelSelectionClaimAt(): number | undefined; renewModelSelectionSettlement(input: { operationId: string; ownerId: string; fencingToken: number; leaseMs: number; }): boolean; completeModelSelectionSettlement(input: { operationId: string; payloadHash: string; result: unknown; selection?: { conversation: ConversationRef; route: ModelRouteRef; }; reply?: OutboundIntent; superseded?: { result: unknown; reply?: OutboundIntent; }; ownerId?: string; fencingToken?: number; }): unknown; workflowTraceSourceAttestation(): Readonly; /** * Apply one already-authenticated source revision. First version may be any * positive integer and gaps are allowed; lower versions and same-version * content changes fail closed. */ recordWorkflowTraceRevision(input: Readonly): { revision: Readonly; replayed: boolean; }; /** * Atomic owner command ledger + private template review + source revision. * Prompt text is stored only in workflow_template_registry.content_json; the * command receipt and Growth trace carry only references and digests. */ commitOwnerWorkflowTraceCommand(input: Readonly<{ action: 'retract' | 'upsert'; operationId: string; payloadDigest: string; binding: Readonly; reviewInboxId: string; sourceInboxId: string; sourceOutboxId: string; subjectRef: string; occurredAt: number; taskRef?: string; /** Principal identity is derived below from the authenticated live binding. */ templateContent?: Readonly>; steps?: readonly Readonly[]; }>): OwnerWorkflowTraceCommandResult; getNaturalObjectiveIntent(inboxId: string): NaturalObjectiveIntent | undefined; listPendingNaturalObjectiveIntents(limit?: number, afterAdmissionSequence?: number): readonly NaturalObjectiveIntent[]; hasEarlierPendingNaturalObjectiveIntent(sourceOutboxId: string, admissionSequence: number): boolean; /** Same source proof required by the local workflow commit, before Evaluation append. */ isVerifiedForegroundObjectiveTarget(binding: Readonly, sourceInboxId: string, sourceOutboxId: string): boolean; /** Freeze the immutable owner wording and exact completed result before any Evaluation I/O. */ prepareNaturalObjectiveIntent(input: Readonly<{ binding: Readonly; feedbackInboxId: string; sourceInboxId: string; sourceOutboxId: string; selection: ObjectiveFeedbackStatus | 'withdraw'; }>): NaturalObjectiveIntent; /** A CAS command is fixed once; retries may never inspect a newer version and rebase it. */ freezeNaturalObjectiveIntent(inboxId: string, current: Readonly<{ version: number; objectiveStatus: ObjectiveFeedbackStatus | 'unknown'; }> | undefined): NaturalObjectiveIntent | undefined; settleNaturalObjectiveIntent(inboxId: string, status: 'projected' | 'conflict', canonical?: NaturalObjectiveIntent['canonical']): void; findNaturalObjectiveFeedbackByOperation(sourceOutboxId: string, operationId: string, lineage: Readonly<{ principalRecordId: string; principalVersion: number; }>): Readonly<{ inboxId: string; text: string; truncated: boolean; }> | undefined; verifiedWorkflowObjectiveState(sourceOutboxId: string, lineage?: Readonly<{ principalRecordId: string; principalVersion: number; }>): { version: number; objectiveStatus: 'achieved' | 'partial' | 'not-achieved' | 'unknown'; } | undefined; /** Commit exact owner feedback (typed command or frozen natural intent) and closed-set workflow evidence. */ commitVerifiedWorkflowTraceFeedback(input: Readonly<{ binding: Readonly; feedbackInboxId: string; sourceInboxId: string; sourceOutboxId: string; objectiveStatus: 'achieved' | 'partial' | 'not-achieved' | 'unknown'; command?: Readonly; }>): VerifiedWorkflowTraceFeedbackResult; /** * Record a workflow learned from one Delivery-reverified owner-root successful * Goal run. Unlike the two conversation-fenced routes, there is no live * Inbox/Outbox: the caller (the Host-only Delivery service method) must have * independently re-fetched the verified Goals source and the owner-run-trace * proof, so this method never accepts a caller-supplied prompt, template, or * proof digest — all of them are rebuilt below from the verified source. * * The goal must be honestly reducible to the single built-in * `assistant.agent-turn` step that paused Growth materialization can run * (exactly one step, zero executable/business tools). Otherwise it abstains * with zero writes. The raw objective is stored only in the new table's * content_json and never enters the trace. Re-submitting the same verified * run deterministically replays its prior revision. */ commitOwnerAnchoredWorkflowTrace(input: Readonly<{ binding: Readonly; ownerRouteId: string; scope: Readonly<{ workspace: string; preset: string; }>; goal: Readonly<{ id: string; definition: Readonly<{ version: number; digest: string; objective: string; }>; sessionId: string; nativeGoalId: string; }>; runId: string; turn: number; acceptance: Readonly<{ contractId: string; receiptDigest: string; verifiedAt: number; validUntil: number; }>; steps: readonly Readonly<{ id: string; toolName: string; }>[]; failedObservations?: readonly unknown[]; /** Trusted owner-run-trace digest re-fetched by the service via Goals Host proof. */ ownerRunTraceDigest: string; }>): CommitOwnerAnchoredWorkflowTraceResult; private insertVerifiedWorkflowTaskFeedback; private replayVerifiedWorkflowTraceFeedback; getWorkflowAutomationTemplate(templateInput: Readonly): StoredWorkflowTemplate | undefined; /** * Rebuild a template learned from a Delivery-reverified owner-root Goal run. * Every column and receipt field is re-derived and cross-checked; a mismatch * fails closed rather than resolving attacker- or corruption-influenced data. */ private getOwnerAnchoredWorkflowTemplate; requeueCurrentWorkflowTraces(): number; enqueuePreferenceProjection(events: readonly Readonly[]): Readonly<{ batchKey: string; payloadDigest: string; replayed: boolean; }>; /** * Persist an Agent reply and its content-free learning projection under one * SQLite commit. A process crash can therefore expose neither row or both, * but never a durable reply that permanently lost its completion signal. */ enqueueReplyWithPreferenceProjection(input: OutboundIntent, eventsForReply: (reply: Readonly) => readonly Readonly[] | undefined): Readonly<{ reply: OutboxRecord; projection?: Readonly<{ batchKey: string; payloadDigest: string; replayed: boolean; }>; }>; listPendingPreferenceProjections(limitInput?: number, nowInput?: number): PreferenceProjectionOutboxEntry[]; /** Earliest retry time among global legacy or exact owner-lane heads. */ nextPreferenceProjectionAttemptAt(nowInput?: number): number | undefined; /** * A direct control may run only after every earlier projection in its exact * owner lane is terminal. Valid legacy rows are a global upgrade barrier * because their missing cursor makes a narrower comparison impossible. */ hasBlockingPreferenceProjectionBefore(input: Readonly<{ scope: Readonly<{ workspace: string; preset: string; }>; principalLineage: Readonly<{ principalRecordId: string; principalVersion: number; }>; admissionCursor: Readonly<{ epoch: string; sequence: number; }>; }>): boolean; completePreferenceProjection(input: { batchKey: string; payloadDigest: string; }): void; deferPreferenceProjection(input: { batchKey: string; payloadDigest: string; now: number; retryAt: number; failureCode: string; }): void; /** * Revalidate one previously-read batch against the live Delivery owner. * Stale, legacy, poison, already-terminal, and peer-completed rows are * acknowledged without invoking a downstream sink. */ preferenceProjectionHasCurrentOwner(input: { batchKey: string; payloadDigest: string; }): boolean; /** * Linearizable projection for a process-local synchronous Preference writer. * Delivery's BEGIN IMMEDIATE remains held while Preference commits, giving * all cooperating processes the fixed Delivery -> Preference lock order. * A handoff therefore linearizes wholly before the callback (which is then * skipped) or wholly after the Preference commit and Delivery ACK. */ projectPreferenceProjectionUnderOwnerFence(input: { batchKey: string; payloadDigest: string; }, project: (entry: Readonly) => void): PreferenceProjectionFenceResult; requeuePreferenceProjections(): number; private normalizePreferenceProjectionLanes; private currentPreferenceProjectionInTransaction; private terminalizePreferenceProjectionInTransaction; private validPreferenceProjectionEntries; private insertPreferenceProjection; listPendingWorkflowTraceRevisions(limitInput?: number, nowInput?: number): WorkflowTraceOutboxEntry[]; completeWorkflowTraceRevision(input: { subjectRef: string; version: number; digest: string; now?: number; }): void; deferWorkflowTraceRevision(input: { subjectRef: string; version: number; digest: string; now: number; retryAt: number; failureCode: string; }): void; private insertWorkflowTraceRevisionInTransaction; private revokeCurrentWorkflowTemplateInTransaction; /** Ownership survives release, revocation and restart; it is not an active-lease query. */ requiresSessionLease(sessionId: string): boolean; claimSessionLease(target: SessionLeaseTarget, holderId: string, leaseMs: number): SessionLeaseClaim; markSessionLeaseDispatched(lease: SessionLease): boolean; hasSessionLease(lease: SessionLease): boolean; renewSessionLease(lease: SessionLease, leaseMs: number): boolean; finishSessionLease(lease: SessionLease, result: { quiescent: boolean; }): boolean; private sessionLeaseShape; /** Re-reads target authority; no runtime-supplied binding is trusted after claim. */ private sessionLeaseAuthority; private sessionLeaseCurrent; close(): void; private transaction; private advanceModelCommandEpoch; private nextBindingGenerationByHash; private assertOpen; } export {}; //# sourceMappingURL=store.d.ts.map