/** * Request payload sent to a Web Worker (or passed to {@link executeActivity}) * describing a single activity execution. * * Generated by the worker dispatcher and consumed by the activity runner * inside the worker. Callers do not normally construct this directly — it is * built by the engine's task-dispatch path. * * @example * ```ts * import { executeActivity, type ActivityExecutionRequest } from '@lostgradient/weft'; * * const request: ActivityExecutionRequest = { * operationId: crypto.randomUUID(), * activityName: 'sendEmail', * input: { to: 'user@example.com' }, * attempt: 1, * }; * const result = await executeActivity(request, async (input) => { * return `sent to ${(input as { to: string }).to}`; * }); * console.log(result.status); // 'completed' * ``` */ export interface ActivityExecutionRequest { operationId: string; activityName: string; input: unknown; attempt: number; workflowExecutionToken?: string; activityAttemptToken?: string; } /** * Result payload returned by {@link executeActivity} and posted back by the * Web Worker after activity execution. * * Check `status` first: `'completed'` means `value` holds the return value; * `'failed'` means `error` holds a human-readable failure message. The * `operationId` mirrors the request so the dispatcher can match results. * * @example * ```ts * import { executeActivity, type ActivityExecutionResult } from '@lostgradient/weft'; * * const result: ActivityExecutionResult = await executeActivity( * { operationId: 'op-1', activityName: 'add', input: [1, 2], attempt: 1 }, * async (input) => (input as number[])[0]! + (input as number[])[1]!, * ); * * if (result.status === 'completed') { * console.log(result.value); // 3 * } * ``` */ export interface ActivityExecutionResult { operationId: string; status: 'completed' | 'failed'; value?: unknown; error?: string; /** Error constructor name used by retry classification and diagnostics. */ errorName?: string; } /** * Executes an activity function with structured error handling and optional * abort-signal support. * * Returns a resolved {@link ActivityExecutionResult} regardless of whether the * function throws — failures are caught and returned as `{ status: 'failed' }`. * If `signal` is already aborted before execution begins, the function is * skipped and a failed result is returned immediately. * * @example * ```ts * import { executeActivity } from '@lostgradient/weft'; * * const result = await executeActivity( * { * operationId: 'op-abc', * activityName: 'greet', * input: { name: 'World' }, * attempt: 1, * }, * async (input) => `Hello, ${(input as { name: string }).name}!`, * ); * console.log(result.status); // 'completed' * console.log(result.value); // 'Hello, World!' * ``` */ export declare function executeActivity(request: ActivityExecutionRequest, activityFunction: (...arguments_: unknown[]) => unknown, signal?: AbortSignal): Promise;