import { WorkflowEvent, WorkflowStep, WorkflowStepConfig } from "cloudflare:workers"; //#region src/core/workflows/index.d.ts /** * Whether `id` is a valid Workflow instance ID: letters, digits, `-`, and `_`, * not starting with `-`, and at most 100 characters. Cloudflare rejects any * other ID when it creates the instance, which {@link startWorkflow} checks * before it calls `create`. */ declare function isWorkflowInstanceId(id: string): boolean; /** * Start a new Workflow instance. Mirrors {@link import("../queues/index.js").enqueue}: * the producer is one call, and a create failure is wrapped in * {@link LouiseWorkflowError}. `Workflow`/`WorkflowInstance` are the ambient * Cloudflare binding types. * * `id` names the instance, and must pass {@link isWorkflowInstanceId}: an ID * with a `:` or `/` is refused here, before `create`, rather than by Cloudflare. * Creating an instance whose ID still exists throws, so key it by the operation, * not the thing the operation touches: `publish-pages-42-v7` (page 42, version 7) * rather than `publish-pages-42`, which fails on the page's second publish. */ declare function startWorkflow

(workflow: Workflow

, params: P, options?: { id?: string; }): Promise; /** * One durable step in a Louise workflow pipeline. `run` does the work and returns * a patch merged into the shared `state` for later steps; the patch is the value * `step.do` persists, so on a retry/resume the stored patch is reused rather than * `run` being called again. Keep `name` stable—Workflows keys the persisted * result by it. */ interface WorkflowPipelineStep { /** Durable step name—stable across deploys (the persisted-result key). */ name: string; /** Per-step retries/backoff/timeout (Cloudflare's `WorkflowStepConfig`). */ config?: WorkflowStepConfig; /** The work: receives the runtime `env`, the event `payload`, the state * accumulated from prior steps, and the run's `instanceId`; returns a patch * merged into that state. The `instanceId` is the same on every retry, so * it's the idempotency key for a side effect, such as a webhook's delivery * ID. */ run: (ctx: { env: Env; payload: Readonly; state: Readonly; instanceId: string; }) => Promise | void> | Partial | void; } /** * Build a `WorkflowEntrypoint.run` body from an ordered list of steps. Mirrors * {@link import("../queues/index.js").processBatch}: it encapsulates the durable * loop so a site's Workflow collapses to composing steps. Each step runs inside * `step.do` (durable + retried per its `config`); its returned patch is merged * into a shared `State` that later steps read and the run resolves to. * * ```ts * // site worker (imports `cloudflare:workers`, owns the class + wrangler binding): * const runPublish = defineWorkflow([ * { name: "og", run: ({ env, payload }) => ({ ogKey: … }) }, * { name: "cache", run: ({ env, state }) => { … } }, * { name: "reindex", config: { retries: { limit: 5, delay: "10 seconds" } }, run: … }, * { name: "webhook", run: … }, * ]); * export class PublishWorkflow extends WorkflowEntrypoint { * run(event, step) { return runPublish(this.env, event, step); } * } * ``` */ declare function defineWorkflow>(steps: WorkflowPipelineStep[], initialState?: State): (env: Env, event: Readonly>, step: WorkflowStep) => Promise; //#endregion export { WorkflowPipelineStep, defineWorkflow, isWorkflowInstanceId, startWorkflow };