import { type Duration, type RetryPolicy, type WorkflowContext } from '../types.ts'; import { completeActivityRetryAttempt, readActivityRetryAttempt, readCompletedRetrySleepCount, type ActivityRetryStateKey } from './activity-retry-state.ts'; import { type ScheduleToCloseBudget } from './activity-schedule-to-close.ts'; import type { Context } from './index.ts'; import { type ContextInternals } from './internals.ts'; import type { ContextOperationRequest } from './operation-request.ts'; /** * Recover the concrete {@link Context} from the public {@link WorkflowContext} * the engine passes to a workflow handler. Under the inline execution strategy * the engine invokes a handler with the concrete `Context` instance (carrying * the `stepIndex`/`accumulatedResults` replay machinery). Worker execution mode * instead drives the handler with a minimal `WorkerWorkflowContext`, which has * no replay internals — so infrastructure such as `compileStepWorkflow` cannot * drive the durable activity machinery there. This probes for the inline * internals (via the `hasContextInternals` type guard, which narrows without a * cast) and throws an actionable error rather than the cryptic * "Context internals not initialized" from a downstream `getInternals` call. */ export declare function asConcreteContext(context: WorkflowContext): Context; export type ActivityInput = string | (Function & { retry?: RetryPolicy; }); export type ActivityOperationRequest = Extract; export interface RunActivityRequest { request: ActivityOperationRequest; step: number; retryStateKey: ActivityRetryStateKey; cacheResultStep?: number; hasCachedResult: boolean; cachedResult?: TResult; retryAttempt: number; retryPolicy?: RetryPolicy; scheduleToCloseTimeout?: Duration; } export type ActivityRetrySleepGenerator = (duration: number, nextAttempt: number) => Generator; export interface RunActivityAtStepConfiguration { explicitName?: string; advanceStepIndexForCachedRetryState?: boolean; retryStateKey?: ActivityRetryStateKey; cacheResultStep?: number | false; activityStateKey?: string; retrySleep?: ActivityRetrySleepGenerator; } export declare const readActivityRetryAttemptForTesting: typeof readActivityRetryAttempt; export declare const readCompletedRetrySleepCountForTesting: typeof readCompletedRetrySleepCount; export declare const completeActivityRetryAttemptForTesting: typeof completeActivityRetryAttempt; export declare function readOrInitActivityRetrySleepFireAt(context: Context, operationId: string, duration: number): number; /** Parse the schedule-to-close budget and anchor it to the step's first dispatch. */ export declare function resolveScheduleToCloseBudget(internals: ContextInternals, retryStateKey: ActivityRetryStateKey, scheduleToCloseTimeout: Duration | undefined): ScheduleToCloseBudget | undefined; export declare function shouldRetryActivityError(error: unknown, policy: RetryPolicy | undefined, attempt: number): policy is RetryPolicy; export declare function prepareActivityRetryRequest(request: ActivityOperationRequest, attempt: number): ActivityOperationRequest; export declare function createRunActivityRequest(context: Context, activity: ActivityInput, rest: readonly unknown[], explicitName?: string): RunActivityRequest; export declare function createRunActivityRequestAtStep(context: Context, activity: ActivityInput, rest: readonly unknown[], step: number, configuration?: RunActivityAtStepConfiguration): RunActivityRequest; export declare function runActivityWithRetry(context: Context, activity: ActivityInput, rest: readonly unknown[], explicitName?: string): Generator; export declare function runActivityWithRetryAtStep(context: Context, activity: ActivityInput, rest: readonly unknown[], step: number, configuration?: RunActivityAtStepConfiguration): Generator;