import { type Storage } from '../../storage/interface.ts'; import type { ContextOperationRequest } from '../context.ts'; import type { ActivityVerificationContext, ActivityVerificationResult } from '../types.ts'; import { WeftError } from '../weft-error.ts'; import type { EngineInternals } from './internals.ts'; type ActivityOperation = Extract; export type ActivityReconciliationMetadata = { verify?: (result: unknown, context?: ActivityVerificationContext) => Promise | ActivityVerificationResult; idempotencyKey?: (input: unknown) => string; }; export type ActivityReconciliationRecord = { version: 1; status: 'started'; workflowId: string; operationId: string; activityName: string; idempotencyKeyDigest: string; attempt: number; ownerId: string; createdAt: number; updatedAt: number; } | { version: 1; status: 'completed'; workflowId: string; operationId: string; activityName: string; idempotencyKeyDigest: string; attempt: number; ownerId: string; result: unknown; createdAt: number; updatedAt: number; }; export type ActivityReconciliationReference = { key: string; idempotencyKeyDigest: string; }; /** * Thrown before dispatching a keyed activity when the configured storage * adapter cannot claim the reconciliation marker atomically. Use a storage * adapter with `conditionalBatch` support before relying on Tier-0 activity * result reconciliation. * * @example * ```ts * import { ActivityReconciliationCapabilityError } from '@lostgradient/weft'; * * function needsConditionalBatchStorage(error: unknown): boolean { * return error instanceof ActivityReconciliationCapabilityError; * } * ``` */ export declare class ActivityReconciliationCapabilityError extends WeftError<'ActivityReconciliationCapabilityError'> { constructor(); } /** * Thrown when another engine turn changes the keyed activity reconciliation * marker between the read and the compare-and-set transition. Retry the * workflow turn so it can re-read the current marker state. * * @example * ```ts * import { ActivityReconciliationConflictError } from '@lostgradient/weft'; * * function shouldRetryWorkflowTurn(error: unknown): boolean { * return error instanceof ActivityReconciliationConflictError; * } * ``` */ export declare class ActivityReconciliationConflictError extends WeftError<'ActivityReconciliationConflictError'> { constructor(message: string); } /** * Thrown when a keyed activity has a prior dispatch marker but the engine * cannot prove whether the external work completed with a reusable result. * This is a fail-closed state: resolve the external side effect manually, then * resume with a verifier that returns a definitive reconciliation state. * * @example * ```ts * import { ActivityReconciliationIndeterminateError } from '@lostgradient/weft'; * * function needsOperatorReconciliation(error: unknown): boolean { * return error instanceof ActivityReconciliationIndeterminateError; * } * ``` */ export declare class ActivityReconciliationIndeterminateError extends WeftError<'ActivityReconciliationIndeterminateError'> { constructor(message: string); } export declare function buildActivityReconciliationReference(workflowId: string, activityName: string, idempotencyKey: string): Promise; export declare function resolveActivityIdempotencyKey(activity: ActivityReconciliationMetadata | undefined, operation: ActivityOperation): string | undefined; export declare function readActivityReconciliationRecord(storage: Storage, key: string): Promise; export declare function validateActivityResultForReconciliation(result: unknown, maxPayloadBytes: number | null): Uint8Array; export declare function claimActivityReconciliationStart(internals: EngineInternals, workflowId: string, reference: ActivityReconciliationReference, record: ActivityReconciliationRecord): Promise; export declare function createCompletedActivityReconciliationRecord(startedRecord: ActivityReconciliationRecord, result: unknown, now: number): ActivityReconciliationRecord; export declare function resolveStartedActivityReconciliationRecord(internals: EngineInternals, workflowId: string, operation: ActivityOperation, reference: ActivityReconciliationReference, activity: ActivityReconciliationMetadata | undefined, idempotencyKey: string, attempt: number): Promise; export declare function writeActivityReconciliationTransition(storage: Storage, reference: ActivityReconciliationReference, expectedRecord: ActivityReconciliationRecord, nextRecord: ActivityReconciliationRecord): Promise; export declare function stageActivityReconciliationTransitionWithAtomicWorkflowCommit(internals: EngineInternals, workflowId: string, reference: ActivityReconciliationReference, expectedRecord: ActivityReconciliationRecord, nextRecord: ActivityReconciliationRecord): void; export declare function commitActivityReconciliationTransitionWithFencedWrite(internals: EngineInternals, workflowId: string, reference: ActivityReconciliationReference, expectedRecord: ActivityReconciliationRecord, nextRecord: ActivityReconciliationRecord): Promise; export declare function normalizePreDispatchVerificationResult(result: ActivityVerificationResult): 'not-completed' | 'completed-result-unavailable' | 'indeterminate' | { result: unknown; }; export declare function buildActivityVerificationContext(phase: ActivityVerificationContext['phase'], workflowId: string, operationId: string, activityName: string, input: unknown, idempotencyKey: string | undefined, attempt: number): ActivityVerificationContext; export {};