@bratsos/workflow-engine 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +274 -513
  2. package/dist/{chunk-7IITBLFY.js → chunk-NYKMT46J.js} +268 -25
  3. package/dist/chunk-NYKMT46J.js.map +1 -0
  4. package/dist/chunk-SPXBCZLB.js +17 -0
  5. package/dist/chunk-SPXBCZLB.js.map +1 -0
  6. package/dist/chunk-WZ533CPU.js +1108 -0
  7. package/dist/chunk-WZ533CPU.js.map +1 -0
  8. package/dist/{client-5vz5Vv4A.d.ts → client-D4PoxADF.d.ts} +3 -143
  9. package/dist/client.d.ts +3 -2
  10. package/dist/{index-DmR3E8D7.d.ts → index-DAzCfO1R.d.ts} +20 -1
  11. package/dist/index.d.ts +234 -601
  12. package/dist/index.js +46 -2034
  13. package/dist/index.js.map +1 -1
  14. package/dist/{interface-Cv22wvLG.d.ts → interface-MMqhfQQK.d.ts} +69 -2
  15. package/dist/kernel/index.d.ts +26 -0
  16. package/dist/kernel/index.js +3 -0
  17. package/dist/kernel/index.js.map +1 -0
  18. package/dist/kernel/testing/index.d.ts +44 -0
  19. package/dist/kernel/testing/index.js +85 -0
  20. package/dist/kernel/testing/index.js.map +1 -0
  21. package/dist/persistence/index.d.ts +2 -2
  22. package/dist/persistence/index.js +2 -1
  23. package/dist/persistence/prisma/index.d.ts +2 -2
  24. package/dist/persistence/prisma/index.js +2 -1
  25. package/dist/plugins-CPC-X0rR.d.ts +421 -0
  26. package/dist/ports-tU3rzPXJ.d.ts +245 -0
  27. package/dist/stage-BPw7m9Wx.d.ts +144 -0
  28. package/dist/testing/index.d.ts +23 -1
  29. package/dist/testing/index.js +156 -13
  30. package/dist/testing/index.js.map +1 -1
  31. package/package.json +11 -1
  32. package/skills/workflow-engine/SKILL.md +234 -348
  33. package/skills/workflow-engine/references/03-runtime-setup.md +111 -426
  34. package/skills/workflow-engine/references/05-persistence-setup.md +32 -0
  35. package/skills/workflow-engine/references/07-testing-patterns.md +141 -474
  36. package/skills/workflow-engine/references/08-common-patterns.md +125 -428
  37. package/dist/chunk-7IITBLFY.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/types.ts","../src/kernel/errors.ts","../src/kernel/helpers/load-workflow-context.ts","../src/kernel/helpers/save-stage-output.ts","../src/kernel/helpers/create-storage-shim.ts","../src/kernel/handlers/job-execute.ts","../src/kernel/handlers/lease-reap-stale.ts","../src/kernel/handlers/outbox-flush.ts","../src/kernel/handlers/plugin-replay-dlq.ts","../src/kernel/handlers/run-cancel.ts","../src/kernel/handlers/run-claim-pending.ts","../src/kernel/handlers/run-create.ts","../src/kernel/handlers/run-rerun-from.ts","../src/kernel/handlers/run-transition.ts","../src/kernel/handlers/stage-poll-suspended.ts","../src/kernel/kernel.ts","../src/kernel/plugins.ts"],"names":["TERMINAL_STATUSES"],"mappings":";;;AAkEoC,EAAE,MAAA,CAAO;AAAA,EAC3C,OAAA,EAAS,EAAE,MAAA,EAAO;AAAA,EAClB,SAAA,EAAW,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC/B,MAAA,EAAQ,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC5B,WAAA,EAAa,EAAE,MAAA,EAAO;AAAA;AAAA,EACtB,YAAA,EAAc,EAAE,MAAA,EAAO;AAAA;AAAA,EACvB,WAAA,EAAa,EAAE,MAAA,EAAO;AAAA;AAAA,EACtB,QAAA,EAAU,CAAA,CAAE,MAAA,CAAO,CAAA,CAAE,MAAA,IAAU,CAAA,CAAE,OAAA,EAAS,CAAA,CAAE,QAAA;AAC9C,CAAC;AA4CM,SAAS,kBACd,MAAA,EAC2B;AAC3B,EAAA,OAAO,WAAA,IAAe,MAAA,IAAU,MAAA,CAAO,SAAA,KAAc,IAAA;AACvD;;;AC1HO,IAAM,0BAAA,GAAN,cAAyC,KAAA,CAAM;AAA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e,GAAA,CAAI,KAAA,CAAM,IAAI,CAAA;AAC9C,MAAA,IAAI,CAAC,QAAA,IAAY,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG;AAExC,MAAA,KAAA,MAAW,UAAU,QAAA,EAAU;AAC7B,QAAA,MAAM,MAAA,CAAO,OAAO,KAAY,CAAA;AAAA,MAClC;AAAA,IACF;AAAA,GACF;AACF","file":"chunk-WZ533CPU.js","sourcesContent":["/**\n * Core type definitions for Workflow System v2\n *\n * See WORKFLOW_SYSTEM_PROPOSAL.md for full architectural details\n */\n\nimport { z } from \"zod\";\n\n// ============================================================================\n// Progress & Metrics\n// ============================================================================\n\nexport interface ProgressUpdate {\n stageId: string;\n stageName: string;\n progress: number; // 0-100\n message: string;\n details?: Record<string, unknown>;\n}\n\nexport interface StageMetrics {\n startTime: number;\n endTime: number;\n duration: number;\n itemsProcessed?: number;\n itemsProduced?: number;\n aiCalls?: number;\n totalTokens?: number;\n totalCost?: number;\n}\n\n// ============================================================================\n// Embedding Support\n// ============================================================================\n\nexport interface EmbeddingResult {\n id: string;\n content: string;\n embedding: number[];\n similarity?: number;\n metadata?: Record<string, unknown>;\n}\n\nexport interface EmbeddingInfo {\n model: string;\n dimensions: number;\n results: EmbeddingResult[];\n totalProcessed?: number;\n averageSimilarity?: number;\n}\n\n// ============================================================================\n// Stage Results\n// ============================================================================\n\nexport interface StageResult<TOutput> {\n output: TOutput;\n metrics: StageMetrics;\n artifacts?: Record<string, unknown>;\n embeddings?: EmbeddingInfo;\n}\n\n// ============================================================================\n// Suspended State (for async-batch operations)\n// ============================================================================\n\nexport const SuspendedStateSchema = z.object({\n batchId: z.string(),\n statusUrl: z.string().optional(),\n apiKey: z.string().optional(),\n submittedAt: z.string(), // ISO date string\n pollInterval: z.number(), // milliseconds\n maxWaitTime: z.number(), // milliseconds\n metadata: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport interface SuspendedResult {\n suspended: true;\n state: z.infer<typeof SuspendedStateSchema>;\n pollConfig: {\n pollInterval: number;\n maxWaitTime: number;\n nextPollAt: Date;\n };\n metrics: StageMetrics;\n}\n\n// ============================================================================\n// Completion Check Result (for orchestrator polling)\n// ============================================================================\n\nexport interface CompletionCheckResult<TOutput> {\n ready: boolean;\n output?: TOutput;\n error?: string;\n nextCheckIn?: number; // Optional: override next poll interval\n metrics?: StageMetrics;\n embeddings?: EmbeddingInfo;\n}\n\n// ============================================================================\n// Log Levels\n// ============================================================================\n\nexport type LogLevel = \"DEBUG\" | \"INFO\" | \"WARN\" | \"ERROR\";\n\n// ============================================================================\n// Stage Mode\n// ============================================================================\n\nexport type StageMode =\n | \"sync\" // Execute and return immediately\n | \"async-batch\"; // Start batch job, return suspended state (separate poller handles completion)\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\nexport function isSuspendedResult<T>(\n result: StageResult<T> | SuspendedResult,\n): result is SuspendedResult {\n return \"suspended\" in result && result.suspended === true;\n}\n\nexport function isStageResult<T>(\n result: StageResult<T> | SuspendedResult,\n): result is StageResult<T> {\n return !isSuspendedResult(result);\n}\n","export class IdempotencyInProgressError extends Error {\n constructor(\n public readonly key: string,\n public readonly commandType: string,\n ) {\n super(\n `Command \"${commandType}\" with idempotency key \"${key}\" is already in progress`,\n );\n this.name = \"IdempotencyInProgressError\";\n }\n}\n","/**\n * Load workflow context from completed stages.\n *\n * For each completed stage, loads the output from BlobStore using\n * the _artifactKey stored in stage.outputData.\n */\n\nimport type { KernelDeps } from \"../kernel.js\";\n\nexport async function loadWorkflowContext(\n workflowRunId: string,\n deps: KernelDeps,\n): Promise<Record<string, unknown>> {\n const completedStages = await deps.persistence.getStagesByRun(workflowRunId, {\n status: \"COMPLETED\",\n orderBy: \"asc\",\n });\n\n const context: Record<string, unknown> = {};\n\n for (const stage of completedStages) {\n const outputData = stage.outputData as any;\n if (outputData?._artifactKey) {\n context[stage.stageId] = await deps.blobStore.get(\n outputData._artifactKey,\n );\n } else if (outputData && typeof outputData === \"object\") {\n context[stage.stageId] = outputData;\n }\n }\n\n return context;\n}\n","/**\n * Save stage output to BlobStore and return the blob key.\n *\n * The key is stored in stage.outputData._artifactKey so that\n * loadWorkflowContext() can retrieve it later.\n */\n\nimport type { KernelDeps } from \"../kernel.js\";\n\nexport async function saveStageOutput(\n runId: string,\n workflowType: string,\n stageId: string,\n output: unknown,\n deps: KernelDeps,\n): Promise<string> {\n const key = `workflow-v2/${workflowType}/${runId}/${stageId}/output.json`;\n await deps.blobStore.put(key, output);\n return key;\n}\n","/**\n * Shared StageStorage implementation backed by BlobStore.\n *\n * Used by both job-execute and stage-poll-suspended handlers.\n */\n\nimport type { StageStorage } from \"../../core/stage.js\";\nimport type { KernelDeps } from \"../kernel.js\";\n\nexport function createStorageShim(\n workflowRunId: string,\n workflowType: string,\n deps: KernelDeps,\n): StageStorage {\n return {\n async save<T>(key: string, data: T): Promise<void> {\n await deps.blobStore.put(key, data);\n },\n\n async load<T>(key: string): Promise<T> {\n return deps.blobStore.get(key) as Promise<T>;\n },\n\n async exists(key: string): Promise<boolean> {\n return deps.blobStore.has(key);\n },\n\n async delete(key: string): Promise<void> {\n return deps.blobStore.delete(key);\n },\n\n getStageKey(stageId: string, suffix?: string): string {\n const base = `workflow-v2/${workflowType}/${workflowRunId}/${stageId}`;\n return suffix ? `${base}/${suffix}` : `${base}/output.json`;\n },\n };\n}\n","/**\n * Handler: job.execute\n *\n * Executes a single stage within a workflow run using a multi-phase\n * transaction pattern:\n *\n * Phase 1 (Start): upsert stage to RUNNING + write stage:started\n * outbox event in one transaction. Commits\n * immediately so RUNNING is visible.\n *\n * Phase 2 (Execute): run stageDef.execute() outside any database\n * transaction. Progress events are collected\n * in memory.\n *\n * Phase 3 (Complete): update stage to COMPLETED/SUSPENDED/FAILED +\n * write completion outbox event (and progress\n * events) in one transaction.\n *\n * This avoids holding a database transaction open for the duration of\n * potentially long-running stage execution (AI calls, HTTP requests,\n * etc.). If the process crashes between Phase 1 and Phase 3, the\n * stage stays RUNNING and lease.reapStale will retry the job.\n */\n\nimport type { StageContext } from \"../../core/stage\";\nimport type { ProgressUpdate } from \"../../core/types\";\nimport { isSuspendedResult } from \"../../core/types\";\nimport type { Workflow } from \"../../core/workflow\";\nimport type { CreateOutboxEventInput } from \"../../persistence/interface\";\nimport type { JobExecuteCommand, JobExecuteResult } from \"../commands\";\nimport type { KernelEvent } from \"../events\";\nimport {\n createStorageShim,\n loadWorkflowContext,\n saveStageOutput,\n} from \"../helpers/index.js\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\n\n// ---------------------------------------------------------------------------\n// Helper: resolve stage input\n// ---------------------------------------------------------------------------\n\nfunction resolveStageInput(\n workflow: Workflow<any, any>,\n stageId: string,\n workflowRun: { input: any },\n workflowContext: Record<string, unknown>,\n): unknown {\n const groupIndex = workflow.getExecutionGroupIndex(stageId);\n\n if (groupIndex === 0) return workflowRun.input;\n\n const prevStageId = workflow.getPreviousStageId(stageId);\n if (prevStageId && workflowContext[prevStageId] !== undefined) {\n return workflowContext[prevStageId];\n }\n\n return workflowRun.input;\n}\n\n// ---------------------------------------------------------------------------\n// Helper: build outbox event inputs from kernel events\n// ---------------------------------------------------------------------------\n\nfunction toOutboxEvents(\n workflowRunId: string,\n causationId: string,\n events: KernelEvent[],\n): CreateOutboxEventInput[] {\n return events.map((event) => ({\n workflowRunId,\n eventType: event.type,\n payload: event,\n causationId,\n occurredAt: event.timestamp,\n }));\n}\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\nexport async function handleJobExecute(\n command: JobExecuteCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<JobExecuteResult>> {\n const { workflowRunId, workflowId, stageId, config } = command;\n const startTime = deps.clock.now().getTime();\n const causationId = command.idempotencyKey ?? crypto.randomUUID();\n\n // ── Pre-flight (no transaction) ──────────────────────────────────\n // Read-only lookups: workflow def, stage def, run record, context.\n\n const workflow = deps.registry.getWorkflow(workflowId);\n if (!workflow)\n throw new Error(`Workflow ${workflowId} not found in registry`);\n\n const stageDef = workflow.getStage(stageId);\n if (!stageDef)\n throw new Error(`Stage ${stageId} not found in workflow ${workflowId}`);\n\n const workflowRun = await deps.persistence.getRun(workflowRunId);\n if (!workflowRun) throw new Error(`WorkflowRun ${workflowRunId} not found`);\n\n const workflowContext = await loadWorkflowContext(workflowRunId, deps);\n\n // ── Phase 1: Start transaction ───────────────────────────────────\n // Upsert stage to RUNNING and write stage:started outbox event.\n // Commits immediately so RUNNING status is visible to observers.\n\n const stageRecord = await deps.persistence.withTransaction(async (tx) => {\n const record = await tx.upsertStage({\n workflowRunId,\n stageId,\n create: {\n workflowRunId,\n stageId,\n stageName: stageDef.name,\n stageNumber: workflow.getStageIndex(stageId) + 1,\n executionGroup: workflow.getExecutionGroupIndex(stageId),\n status: \"RUNNING\",\n startedAt: deps.clock.now(),\n config: config as any,\n },\n update: {\n status: \"RUNNING\",\n startedAt: deps.clock.now(),\n },\n });\n\n await tx.appendOutboxEvents(\n toOutboxEvents(workflowRunId, causationId, [\n {\n type: \"stage:started\",\n timestamp: deps.clock.now(),\n workflowRunId,\n stageId,\n stageName: stageDef.name,\n stageNumber: record.stageNumber,\n },\n ]),\n );\n\n return record;\n });\n\n // ── Phase 2: Execute (no transaction) ────────────────────────────\n // The stage's execute() function runs outside any database\n // transaction. Progress events are collected in memory and\n // written to the outbox in Phase 3.\n\n const progressEvents: KernelEvent[] = [];\n\n try {\n // Resolve and validate input\n const rawInput = resolveStageInput(\n workflow,\n stageId,\n workflowRun,\n workflowContext,\n );\n const validatedInput = stageDef.inputSchema.parse(rawInput);\n\n // Parse config\n let stageConfig = (config as any)[stageId] || {};\n try {\n if (stageDef.configSchema) {\n stageConfig = stageDef.configSchema.parse(stageConfig);\n }\n } catch {\n // Fall back to raw config on parse failure\n }\n\n // Build log function (fire-and-forget, no transaction needed)\n const logFn = async (\n level: any,\n message: string,\n meta?: Record<string, unknown>,\n ) => {\n await deps.persistence\n .createLog({\n workflowRunId,\n workflowStageId: stageRecord.id,\n level: level as any,\n message,\n metadata: meta,\n })\n .catch(() => {});\n };\n\n // Build context\n const context: StageContext<any, any, any> = {\n workflowRunId,\n stageId,\n stageNumber: stageRecord.stageNumber,\n stageName: stageDef.name,\n stageRecordId: stageRecord.id,\n input: validatedInput,\n config: stageConfig,\n resumeState: stageRecord.suspendedState as any,\n onProgress: (update: ProgressUpdate) => {\n progressEvents.push({\n type: \"stage:progress\",\n timestamp: deps.clock.now(),\n workflowRunId,\n stageId,\n progress: update.progress,\n message: update.message,\n details: update.details,\n });\n },\n onLog: logFn,\n log: logFn,\n storage: createStorageShim(workflowRunId, workflowRun.workflowType, deps),\n workflowContext,\n };\n\n // Execute the stage — this is the potentially long-running part\n const result = await stageDef.execute(context);\n\n // ── Phase 3a: Complete transaction (success) ─────────────────\n if (isSuspendedResult(result)) {\n const { state, pollConfig, metrics } = result;\n const nextPollAt = new Date(\n pollConfig.nextPollAt?.getTime() ??\n deps.clock.now().getTime() + (pollConfig.pollInterval || 60000),\n );\n\n await deps.persistence.withTransaction(async (tx) => {\n await tx.updateStage(stageRecord.id, {\n status: \"SUSPENDED\",\n suspendedState: state as any,\n nextPollAt,\n pollInterval: pollConfig.pollInterval,\n maxWaitUntil: pollConfig.maxWaitTime\n ? new Date(deps.clock.now().getTime() + pollConfig.maxWaitTime)\n : undefined,\n metrics: metrics as any,\n });\n\n const suspendedEvent: KernelEvent = {\n type: \"stage:suspended\",\n timestamp: deps.clock.now(),\n workflowRunId,\n stageId,\n stageName: stageDef.name,\n nextPollAt,\n };\n\n await tx.appendOutboxEvents(\n toOutboxEvents(workflowRunId, causationId, [\n ...progressEvents,\n suspendedEvent,\n ]),\n );\n });\n\n return { outcome: \"suspended\" as const, nextPollAt, _events: [] };\n } else {\n const duration = deps.clock.now().getTime() - startTime;\n\n // Save output to blob store (not a DB operation)\n const outputKey = await saveStageOutput(\n workflowRunId,\n workflowRun.workflowType,\n stageId,\n result.output,\n deps,\n );\n\n await deps.persistence.withTransaction(async (tx) => {\n await tx.updateStage(stageRecord.id, {\n status: \"COMPLETED\",\n completedAt: deps.clock.now(),\n duration,\n outputData: { _artifactKey: outputKey } as any,\n metrics: result.metrics as any,\n embeddingInfo: result.embeddings as any,\n });\n\n const completedEvent: KernelEvent = {\n type: \"stage:completed\",\n timestamp: deps.clock.now(),\n workflowRunId,\n stageId,\n stageName: stageDef.name,\n duration,\n };\n\n await tx.appendOutboxEvents(\n toOutboxEvents(workflowRunId, causationId, [\n ...progressEvents,\n completedEvent,\n ]),\n );\n });\n\n return {\n outcome: \"completed\" as const,\n output: result.output,\n _events: [],\n };\n }\n } catch (error) {\n // ── Phase 3b: Complete transaction (failure) ─────────────────\n // The stage's execute() threw. Write FAILED status + outbox\n // event. If Phase 3 itself fails, re-throw the original error\n // so the idempotency key is released and the job can be retried.\n const errorMessage = error instanceof Error ? error.message : String(error);\n const duration = deps.clock.now().getTime() - startTime;\n\n try {\n await deps.persistence.withTransaction(async (tx) => {\n await tx.updateStage(stageRecord.id, {\n status: \"FAILED\",\n completedAt: deps.clock.now(),\n duration,\n errorMessage,\n });\n\n const failedEvent: KernelEvent = {\n type: \"stage:failed\",\n timestamp: deps.clock.now(),\n workflowRunId,\n stageId,\n stageName: stageDef.name,\n error: errorMessage,\n };\n\n await tx.appendOutboxEvents(\n toOutboxEvents(workflowRunId, causationId, [\n ...progressEvents,\n failedEvent,\n ]),\n );\n });\n } catch {\n // Phase 3 itself failed. Stage stays RUNNING.\n // Re-throw the original error so the idempotency key is\n // released and lease.reapStale can retry the job.\n throw error;\n }\n\n await deps.persistence\n .createLog({\n workflowRunId,\n workflowStageId: stageRecord.id,\n level: \"ERROR\",\n message: errorMessage,\n })\n .catch(() => {});\n\n return { outcome: \"failed\" as const, error: errorMessage, _events: [] };\n }\n}\n","/**\n * Handler: lease.reapStale\n *\n * Releases stale job leases that have exceeded the threshold.\n */\n\nimport type { LeaseReapStaleCommand, LeaseReapStaleResult } from \"../commands\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\n\nexport async function handleLeaseReapStale(\n command: LeaseReapStaleCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<LeaseReapStaleResult>> {\n const released = await deps.jobTransport.releaseStaleJobs(\n command.staleThresholdMs,\n );\n\n return { released, _events: [] };\n}\n","/**\n * Handler: outbox.flush\n *\n * Reads unpublished outbox events and publishes them through EventSink.\n * Events are emitted in order (workflowRunId, sequence) and marked as\n * published after successful emission.\n *\n * On handler failure:\n * - Increments retryCount on the outbox event\n * - If retryCount >= maxRetries, moves event to DLQ\n * - Event is NOT marked as published (will retry on next flush)\n *\n * This handler returns _events: [] — it does NOT produce new outbox events.\n */\n\nimport type { OutboxFlushCommand, OutboxFlushResult } from \"../commands\";\nimport type { KernelEvent } from \"../events\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\nimport type { PluginRunner } from \"../plugins\";\n\nexport async function handleOutboxFlush(\n command: OutboxFlushCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<OutboxFlushResult>> {\n const limit = command.maxEvents ?? 100;\n const events = await deps.persistence.getUnpublishedOutboxEvents(limit);\n\n // Determine maxRetries from EventSink (if it's a PluginRunner)\n const maxRetries = (deps.eventSink as Partial<PluginRunner>).maxRetries ?? 3;\n\n const publishedIds: string[] = [];\n\n for (const outboxEvent of events) {\n try {\n await deps.eventSink.emit(outboxEvent.payload as KernelEvent);\n publishedIds.push(outboxEvent.id);\n } catch {\n const newCount = await deps.persistence.incrementOutboxRetryCount(\n outboxEvent.id,\n );\n if (newCount >= maxRetries) {\n await deps.persistence.moveOutboxEventToDLQ(outboxEvent.id);\n }\n // Event stays unpublished — will retry on next flush (unless DLQ'd)\n }\n }\n\n if (publishedIds.length > 0) {\n await deps.persistence.markOutboxEventsPublished(publishedIds);\n }\n\n return { published: publishedIds.length, _events: [] };\n}\n","/**\n * Handler: plugin.replayDLQ\n *\n * Resets DLQ outbox events (dlqAt and retryCount) so they are\n * picked up by the next outbox.flush invocation.\n *\n * This handler returns _events: [] — it does NOT produce new outbox events.\n */\n\nimport type {\n PluginReplayDLQCommand,\n PluginReplayDLQResult,\n} from \"../commands\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\n\nexport async function handlePluginReplayDLQ(\n command: PluginReplayDLQCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<PluginReplayDLQResult>> {\n const maxEvents = command.maxEvents ?? 100;\n const replayed = await deps.persistence.replayDLQEvents(maxEvents);\n return { replayed, _events: [] };\n}\n","/**\n * Handler: run.cancel\n *\n * Cancels a running workflow if it is not already in a terminal state.\n */\n\nimport type { RunCancelCommand, RunCancelResult } from \"../commands\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\n\nconst TERMINAL_STATUSES = new Set([\"COMPLETED\", \"FAILED\", \"CANCELLED\"]);\n\nexport async function handleRunCancel(\n command: RunCancelCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<RunCancelResult>> {\n const run = await deps.persistence.getRun(command.workflowRunId);\n\n if (!run || TERMINAL_STATUSES.has(run.status)) {\n return { cancelled: false, _events: [] };\n }\n\n await deps.persistence.updateRun(command.workflowRunId, {\n status: \"CANCELLED\",\n completedAt: deps.clock.now(),\n });\n\n return {\n cancelled: true,\n _events: [\n {\n type: \"workflow:cancelled\",\n timestamp: deps.clock.now(),\n workflowRunId: command.workflowRunId,\n reason: command.reason,\n },\n ],\n };\n}\n","/**\n * Handler: run.claimPending\n *\n * Claims pending workflow runs, creates first-stage records, and enqueues\n * their jobs for processing.\n */\n\nimport type {\n RunClaimPendingCommand,\n RunClaimPendingResult,\n} from \"../commands\";\nimport type { KernelEvent } from \"../events\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\n\nexport async function handleRunClaimPending(\n command: RunClaimPendingCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<RunClaimPendingResult>> {\n const maxClaims = command.maxClaims ?? 10;\n const claimed: Array<{\n workflowRunId: string;\n workflowId: string;\n jobIds: string[];\n }> = [];\n const events: KernelEvent[] = [];\n\n for (let i = 0; i < maxClaims; i++) {\n const run = await deps.persistence.claimNextPendingRun();\n if (!run) break;\n\n const workflow = deps.registry.getWorkflow(run.workflowId);\n if (!workflow) {\n const error = `Workflow ${run.workflowId} not found in registry`;\n const failedAt = deps.clock.now();\n await deps.persistence.updateRun(run.id, {\n status: \"FAILED\",\n completedAt: failedAt,\n output: {\n error: {\n code: \"WORKFLOW_NOT_FOUND\",\n message: error,\n workerId: command.workerId,\n },\n },\n });\n await deps.persistence\n .createLog({\n workflowRunId: run.id,\n level: \"ERROR\",\n message: error,\n metadata: {\n workerId: command.workerId,\n code: \"WORKFLOW_NOT_FOUND\",\n },\n })\n .catch(() => {});\n events.push({\n type: \"workflow:failed\",\n timestamp: failedAt,\n workflowRunId: run.id,\n error,\n });\n continue;\n }\n\n const stages = workflow.getStagesInExecutionGroup(1);\n if (stages.length === 0) {\n const error = `Workflow ${run.workflowId} has no stages in execution group 1`;\n const failedAt = deps.clock.now();\n await deps.persistence.updateRun(run.id, {\n status: \"FAILED\",\n completedAt: failedAt,\n output: {\n error: {\n code: \"EMPTY_STAGE_GRAPH\",\n message: error,\n workerId: command.workerId,\n },\n },\n });\n await deps.persistence\n .createLog({\n workflowRunId: run.id,\n level: \"ERROR\",\n message: error,\n metadata: {\n workerId: command.workerId,\n code: \"EMPTY_STAGE_GRAPH\",\n },\n })\n .catch(() => {});\n events.push({\n type: \"workflow:failed\",\n timestamp: failedAt,\n workflowRunId: run.id,\n error,\n });\n continue;\n }\n\n // Create stage records\n for (const stage of stages) {\n await deps.persistence.createStage({\n workflowRunId: run.id,\n stageId: stage.id,\n stageName: stage.name,\n stageNumber: workflow.getStageIndex(stage.id) + 1,\n executionGroup: 1,\n status: \"PENDING\",\n config: (run.config as any)?.[stage.id] || {},\n });\n }\n\n // Enqueue jobs\n const jobIds = await deps.jobTransport.enqueueParallel(\n stages.map((stage) => ({\n workflowRunId: run.id,\n workflowId: run.workflowId,\n stageId: stage.id,\n priority: run.priority,\n payload: { config: run.config || {} },\n })),\n );\n\n events.push({\n type: \"workflow:started\",\n timestamp: deps.clock.now(),\n workflowRunId: run.id,\n });\n\n claimed.push({\n workflowRunId: run.id,\n workflowId: run.workflowId,\n jobIds,\n });\n }\n\n return { claimed, _events: events };\n}\n","/**\n * Handler: run.create\n *\n * Creates a new workflow run record after validating input and config.\n */\n\nimport type { RunCreateCommand, RunCreateResult } from \"../commands\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\n\nexport async function handleRunCreate(\n command: RunCreateCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<RunCreateResult>> {\n // 1. Get workflow from registry\n const workflow = deps.registry.getWorkflow(command.workflowId);\n if (!workflow) {\n throw new Error(`Workflow ${command.workflowId} not found in registry`);\n }\n\n // 2. Validate input against workflow's input schema\n try {\n workflow.inputSchema.parse(command.input);\n } catch (error) {\n throw new Error(`Invalid workflow input: ${error}`);\n }\n\n // 3. Get default config and merge with provided config\n const defaultConfig = workflow.getDefaultConfig?.() ?? {};\n const mergedConfig = { ...defaultConfig, ...command.config };\n\n // 4. Validate merged config\n const configValidation = workflow.validateConfig(mergedConfig);\n if (!configValidation.valid) {\n const errors = configValidation.errors\n .map((e) => `${e.stageId}: ${e.error}`)\n .join(\", \");\n throw new Error(`Invalid workflow config: ${errors}`);\n }\n\n // 5. Calculate priority\n const priority = command.priority ?? 5;\n\n // 6. Create the run record\n const run = await deps.persistence.createRun({\n workflowId: command.workflowId,\n workflowName: workflow.name,\n workflowType: command.workflowId,\n input: command.input,\n config: mergedConfig,\n priority,\n metadata: command.metadata,\n });\n\n return {\n workflowRunId: run.id,\n status: \"PENDING\" as const,\n _events: [\n {\n type: \"workflow:created\",\n timestamp: deps.clock.now(),\n workflowRunId: run.id,\n workflowId: command.workflowId,\n },\n ],\n };\n}\n","/**\n * Handler: run.rerunFrom\n *\n * Reruns a workflow from a specific stage. Deletes stage records and\n * blob artifacts at/after the target execution group, resets the run\n * to RUNNING, creates new stage records, and enqueues jobs.\n *\n * Works for both COMPLETED runs (rerun from any stage) and FAILED runs\n * (retry from the failed stage).\n */\n\nimport type { RunRerunFromCommand, RunRerunFromResult } from \"../commands\";\nimport type { KernelEvent } from \"../events\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\n\nexport async function handleRunRerunFrom(\n command: RunRerunFromCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<RunRerunFromResult>> {\n const { workflowRunId, fromStageId } = command;\n const events: KernelEvent[] = [];\n\n // 1. Load run\n const run = await deps.persistence.getRun(workflowRunId);\n if (!run) throw new Error(`WorkflowRun ${workflowRunId} not found`);\n\n // 2. Validate run is in a rerunnable state\n if (run.status !== \"COMPLETED\" && run.status !== \"FAILED\") {\n throw new Error(\n `Cannot rerun workflow in ${run.status} state. Must be COMPLETED or FAILED.`,\n );\n }\n\n // 3. Load workflow definition\n const workflow = deps.registry.getWorkflow(run.workflowId);\n if (!workflow)\n throw new Error(`Workflow ${run.workflowId} not found in registry`);\n\n // 4. Validate stage exists in workflow\n const stageDef = workflow.getStage(fromStageId);\n if (!stageDef) {\n throw new Error(\n `Stage ${fromStageId} not found in workflow ${run.workflowId}`,\n );\n }\n\n // 5. Get the execution group of the target stage\n const targetGroup = workflow.getExecutionGroupIndex(fromStageId);\n\n // 6. Get all existing stage records\n const existingStages = await deps.persistence.getStagesByRun(workflowRunId);\n\n // 7. Validate: stages before the target group must have been executed\n if (targetGroup > 1) {\n const priorStages = existingStages.filter(\n (s) => s.executionGroup < targetGroup,\n );\n if (priorStages.length === 0) {\n throw new Error(\n `Cannot rerun from stage ${fromStageId}: previous stages have not been executed`,\n );\n }\n }\n\n // 8. Find stages to delete (at or after the target group)\n const stagesToDelete = existingStages.filter(\n (s) => s.executionGroup >= targetGroup,\n );\n const deletedStageIds = stagesToDelete.map((s) => s.stageId);\n\n // 9. Delete blob artifacts for stages being removed\n for (const stage of stagesToDelete) {\n const outputRef = stage.outputData as { _artifactKey?: string } | null;\n if (outputRef?._artifactKey) {\n await deps.blobStore.delete(outputRef._artifactKey).catch(() => {});\n }\n }\n\n // 10. Delete stage records\n for (const stage of stagesToDelete) {\n await deps.persistence.deleteStage(stage.id);\n }\n\n // 11. Reset run to RUNNING\n await deps.persistence.updateRun(workflowRunId, {\n status: \"RUNNING\",\n completedAt: null,\n });\n\n // 12. Create new stage records for the target execution group\n const targetStages = workflow.getStagesInExecutionGroup(targetGroup);\n for (const stage of targetStages) {\n await deps.persistence.createStage({\n workflowRunId,\n stageId: stage.id,\n stageName: stage.name,\n stageNumber: workflow.getStageIndex(stage.id) + 1,\n executionGroup: targetGroup,\n status: \"PENDING\",\n config: (run.config as any)?.[stage.id] || {},\n });\n }\n\n // 13. Enqueue jobs\n await deps.jobTransport.enqueueParallel(\n targetStages.map((stage) => ({\n workflowRunId,\n workflowId: run.workflowId,\n stageId: stage.id,\n priority: run.priority,\n payload: { config: run.config || {} },\n })),\n );\n\n // 14. Emit workflow:started event (restarted)\n events.push({\n type: \"workflow:started\",\n timestamp: deps.clock.now(),\n workflowRunId,\n });\n\n return {\n workflowRunId,\n fromStageId,\n deletedStages: deletedStageIds,\n _events: events,\n };\n}\n","/**\n * Handler: run.transition\n *\n * Advances a workflow run to its next execution group, or marks it as\n * completed/failed depending on the current state of its stages.\n *\n * Extracted from WorkflowRuntime.transitionWorkflow() and completeWorkflow().\n */\n\nimport type { Workflow } from \"../../core/workflow\";\nimport type { RunTransitionCommand, RunTransitionResult } from \"../commands\";\nimport type { KernelEvent } from \"../events\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\nimport type { WorkflowRunRecord } from \"../ports\";\n\n// ---------------------------------------------------------------------------\n// Terminal statuses -- a run in one of these states cannot be transitioned.\n// ---------------------------------------------------------------------------\n\nconst TERMINAL_STATUSES = new Set([\"COMPLETED\", \"FAILED\", \"CANCELLED\"]);\n\n// ---------------------------------------------------------------------------\n// Active statuses -- if any stage is in one of these states the run is still\n// in-flight and should not be transitioned yet.\n// ---------------------------------------------------------------------------\n\nconst ACTIVE_STATUSES = new Set([\"RUNNING\", \"PENDING\", \"SUSPENDED\"]);\n\n// ---------------------------------------------------------------------------\n// Helper: enqueue an execution group\n// ---------------------------------------------------------------------------\n\nasync function enqueueExecutionGroup(\n run: WorkflowRunRecord,\n workflow: Workflow<any, any>,\n groupIndex: number,\n deps: KernelDeps,\n): Promise<string[]> {\n const stages = workflow.getStagesInExecutionGroup(groupIndex);\n\n for (const stage of stages) {\n await deps.persistence.createStage({\n workflowRunId: run.id,\n stageId: stage.id,\n stageName: stage.name,\n stageNumber: workflow.getStageIndex(stage.id) + 1,\n executionGroup: groupIndex,\n status: \"PENDING\",\n config: (run.config as any)?.[stage.id] || {},\n });\n }\n\n return deps.jobTransport.enqueueParallel(\n stages.map((stage) => ({\n workflowRunId: run.id,\n workflowId: run.workflowId,\n stageId: stage.id,\n priority: run.priority,\n payload: { config: run.config || {} },\n })),\n );\n}\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\nexport async function handleRunTransition(\n command: RunTransitionCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<RunTransitionResult>> {\n const events: KernelEvent[] = [];\n\n // 1. Get run from persistence\n const run = await deps.persistence.getRun(command.workflowRunId);\n if (!run) {\n return { action: \"noop\" as const, _events: [] };\n }\n\n // 2. If run is already in a terminal state, nothing to do\n if (TERMINAL_STATUSES.has(run.status)) {\n return { action: \"noop\" as const, _events: [] };\n }\n\n // 3. Get workflow definition from registry\n const workflow = deps.registry.getWorkflow(run.workflowId);\n if (!workflow) {\n return { action: \"noop\" as const, _events: [] };\n }\n\n // 4. Get all stages for this run\n const stages = await deps.persistence.getStagesByRun(command.workflowRunId);\n\n // 5. If no stages exist, this is the first transition -- enqueue group 1\n if (stages.length === 0) {\n await enqueueExecutionGroup(run, workflow, 1, deps);\n\n events.push({\n type: \"workflow:started\",\n timestamp: deps.clock.now(),\n workflowRunId: run.id,\n });\n\n return { action: \"advanced\" as const, nextGroup: 1, _events: events };\n }\n\n // 6. If any stage is still active, the run is in-flight -- noop\n const hasActive = stages.some((s) => ACTIVE_STATUSES.has(s.status));\n if (hasActive) {\n return { action: \"noop\" as const, _events: [] };\n }\n\n // 7. If any stage has failed, mark the entire run as failed\n const failedStage = stages.find((s) => s.status === \"FAILED\");\n if (failedStage) {\n await deps.persistence.updateRun(command.workflowRunId, {\n status: \"FAILED\",\n completedAt: deps.clock.now(),\n });\n\n events.push({\n type: \"workflow:failed\",\n timestamp: deps.clock.now(),\n workflowRunId: command.workflowRunId,\n error: failedStage.errorMessage || \"Stage failed\",\n });\n\n return { action: \"failed\" as const, _events: events };\n }\n\n // 8. Find the maximum execution group among completed stages\n const maxGroup = stages.reduce(\n (max, s) => (s.executionGroup > max ? s.executionGroup : max),\n 0,\n );\n\n // 9. Get stages in the next execution group\n const nextGroupStages = workflow.getStagesInExecutionGroup(maxGroup + 1);\n\n // 10. If there are stages in the next group, enqueue them\n if (nextGroupStages.length > 0) {\n await enqueueExecutionGroup(run, workflow, maxGroup + 1, deps);\n return {\n action: \"advanced\" as const,\n nextGroup: maxGroup + 1,\n _events: events,\n };\n }\n\n // 11. No next group -- the workflow is complete\n let totalCost = 0;\n let totalTokens = 0;\n\n for (const stage of stages) {\n const metrics = stage.metrics as any;\n if (metrics) {\n totalCost += metrics.totalCost ?? 0;\n totalTokens += metrics.totalTokens ?? 0;\n }\n }\n\n const duration = deps.clock.now().getTime() - run.createdAt.getTime();\n\n await deps.persistence.updateRun(command.workflowRunId, {\n status: \"COMPLETED\",\n completedAt: deps.clock.now(),\n duration,\n totalCost,\n totalTokens,\n });\n\n events.push({\n type: \"workflow:completed\",\n timestamp: deps.clock.now(),\n workflowRunId: command.workflowRunId,\n duration,\n totalCost,\n totalTokens,\n });\n\n return { action: \"completed\" as const, _events: events };\n}\n","/**\n * Handler: stage.pollSuspended\n *\n * Polls suspended stages whose nextPollAt has passed, calls each stage's\n * checkCompletion() method, and either resumes (completes) or re-schedules\n * them for a future poll.\n *\n * Extracted from WorkflowRuntime.pollSuspendedStages() + checkAndResume().\n */\n\nimport type {\n StagePollSuspendedCommand,\n StagePollSuspendedResult,\n} from \"../commands\";\nimport type { KernelEvent } from \"../events\";\nimport { createStorageShim, saveStageOutput } from \"../helpers/index.js\";\nimport type { HandlerResult, KernelDeps } from \"../kernel\";\n\n// ---------------------------------------------------------------------------\n// Handler\n// ---------------------------------------------------------------------------\n\nexport async function handleStagePollSuspended(\n command: StagePollSuspendedCommand,\n deps: KernelDeps,\n): Promise<HandlerResult<StagePollSuspendedResult>> {\n const events: KernelEvent[] = [];\n const maxChecks = command.maxChecks ?? 50;\n\n // 1. Get suspended stages that are ready to be polled\n const suspendedStages = await deps.persistence.getSuspendedStages(\n deps.clock.now(),\n );\n\n // 2. Limit to maxChecks\n const stagesToCheck = suspendedStages.slice(0, maxChecks);\n\n let checked = 0;\n let resumed = 0;\n let failed = 0;\n const resumedWorkflowRunIds = new Set<string>();\n\n // 3. Process each suspended stage\n for (const stageRecord of stagesToCheck) {\n checked++;\n\n // 3a. Get workflow run\n const run = await deps.persistence.getRun(stageRecord.workflowRunId);\n if (!run) continue;\n\n // 3b. Get workflow from registry\n const workflow = deps.registry.getWorkflow(run.workflowId);\n if (!workflow) {\n await deps.persistence.updateStage(stageRecord.id, {\n status: \"FAILED\",\n completedAt: deps.clock.now(),\n errorMessage: `Workflow ${run.workflowId} not found in registry`,\n });\n failed++;\n\n events.push({\n type: \"stage:failed\",\n timestamp: deps.clock.now(),\n workflowRunId: stageRecord.workflowRunId,\n stageId: stageRecord.stageId,\n stageName: stageRecord.stageName,\n error: `Workflow ${run.workflowId} not found in registry`,\n });\n continue;\n }\n\n // 3c. Get stage definition\n const stageDef = workflow.getStage(stageRecord.stageId);\n if (!stageDef || !stageDef.checkCompletion) {\n const errorMsg = !stageDef\n ? `Stage ${stageRecord.stageId} not found in workflow ${run.workflowId}`\n : `Stage ${stageRecord.stageId} does not support checkCompletion`;\n\n await deps.persistence.updateStage(stageRecord.id, {\n status: \"FAILED\",\n completedAt: deps.clock.now(),\n errorMessage: errorMsg,\n });\n failed++;\n\n events.push({\n type: \"stage:failed\",\n timestamp: deps.clock.now(),\n workflowRunId: stageRecord.workflowRunId,\n stageId: stageRecord.stageId,\n stageName: stageRecord.stageName,\n error: errorMsg,\n });\n continue;\n }\n\n // 3d. Create storage shim\n const storage = createStorageShim(\n stageRecord.workflowRunId,\n run.workflowType,\n deps,\n );\n\n // 3e. Create log function\n const logFn = async (\n level: any,\n message: string,\n meta?: Record<string, unknown>,\n ) => {\n await deps.persistence\n .createLog({\n workflowRunId: stageRecord.workflowRunId,\n workflowStageId: stageRecord.id,\n level: level as any,\n message,\n metadata: meta,\n })\n .catch(() => {});\n };\n\n // 3f. Build check context\n const checkContext = {\n workflowRunId: run.id,\n stageId: stageRecord.stageId,\n stageRecordId: stageRecord.id,\n config: stageRecord.config || {},\n log: logFn,\n onLog: logFn,\n storage,\n };\n\n try {\n // 3g. Call checkCompletion\n const checkResult = await stageDef.checkCompletion(\n stageRecord.suspendedState as any,\n checkContext,\n );\n\n if (checkResult.error) {\n // Error during check -- fail the stage and the run\n await deps.persistence.updateStage(stageRecord.id, {\n status: \"FAILED\",\n completedAt: deps.clock.now(),\n errorMessage: checkResult.error,\n nextPollAt: null,\n });\n\n await deps.persistence.updateRun(stageRecord.workflowRunId, {\n status: \"FAILED\",\n completedAt: deps.clock.now(),\n });\n\n failed++;\n\n events.push({\n type: \"stage:failed\",\n timestamp: deps.clock.now(),\n workflowRunId: stageRecord.workflowRunId,\n stageId: stageRecord.stageId,\n stageName: stageRecord.stageName,\n error: checkResult.error,\n });\n\n events.push({\n type: \"workflow:failed\",\n timestamp: deps.clock.now(),\n workflowRunId: stageRecord.workflowRunId,\n error: checkResult.error,\n });\n } else if (checkResult.ready) {\n // Ready -- complete the stage (output is optional)\n let outputRef: { _artifactKey: string } | undefined;\n if (checkResult.output !== undefined) {\n let validatedOutput = checkResult.output;\n try {\n validatedOutput = stageDef.outputSchema.parse(checkResult.output);\n } catch {\n // Fall back to raw output on validation failure\n }\n\n const outputKey = await saveStageOutput(\n stageRecord.workflowRunId,\n run.workflowType,\n stageRecord.stageId,\n validatedOutput,\n deps,\n );\n outputRef = { _artifactKey: outputKey };\n }\n\n const duration =\n deps.clock.now().getTime() -\n (stageRecord.startedAt?.getTime() ?? deps.clock.now().getTime());\n\n await deps.persistence.updateStage(stageRecord.id, {\n status: \"COMPLETED\",\n completedAt: deps.clock.now(),\n duration,\n outputData: outputRef as any,\n nextPollAt: null,\n metrics: checkResult.metrics as any,\n embeddingInfo: checkResult.embeddings as any,\n });\n\n resumed++;\n resumedWorkflowRunIds.add(stageRecord.workflowRunId);\n\n events.push({\n type: \"stage:completed\",\n timestamp: deps.clock.now(),\n workflowRunId: stageRecord.workflowRunId,\n stageId: stageRecord.stageId,\n stageName: stageRecord.stageName,\n duration,\n });\n } else {\n // Not ready -- update nextPollAt for next check\n const pollInterval =\n checkResult.nextCheckIn ?? stageRecord.pollInterval ?? 60000;\n\n const nextPollAt = new Date(deps.clock.now().getTime() + pollInterval);\n\n await deps.persistence.updateStage(stageRecord.id, {\n nextPollAt,\n });\n }\n } catch (error) {\n // Unexpected error during checkCompletion\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n await deps.persistence.updateStage(stageRecord.id, {\n status: \"FAILED\",\n completedAt: deps.clock.now(),\n errorMessage,\n nextPollAt: null,\n });\n\n await deps.persistence.updateRun(stageRecord.workflowRunId, {\n status: \"FAILED\",\n completedAt: deps.clock.now(),\n });\n\n failed++;\n\n events.push({\n type: \"stage:failed\",\n timestamp: deps.clock.now(),\n workflowRunId: stageRecord.workflowRunId,\n stageId: stageRecord.stageId,\n stageName: stageRecord.stageName,\n error: errorMessage,\n });\n\n events.push({\n type: \"workflow:failed\",\n timestamp: deps.clock.now(),\n workflowRunId: stageRecord.workflowRunId,\n error: errorMessage,\n });\n }\n }\n\n return {\n checked,\n resumed,\n failed,\n resumedWorkflowRunIds: [...resumedWorkflowRunIds],\n _events: events,\n };\n}\n","/**\n * Kernel Factory\n *\n * Creates a Kernel instance with a typed `dispatch` method that routes\n * commands to their corresponding handlers. Events are written to a\n * transactional outbox (not emitted directly). Use the `outbox.flush`\n * command to publish pending outbox events through EventSink.\n *\n * Most commands execute inside a single database transaction (handler\n * logic + outbox event writes). `job.execute` is the exception — it\n * uses a multi-phase transaction pattern so that long-running stage\n * execution does not hold a database connection open. See the handler\n * in `handlers/job-execute.ts` for details.\n *\n * Commands with idempotency keys are deduplicated: a replay returns the\n * cached result without re-executing the handler.\n */\n\nimport type { Workflow } from \"../core/workflow\";\nimport type { CreateOutboxEventInput } from \"../persistence/interface\";\nimport type {\n CommandResult,\n JobExecuteCommand,\n KernelCommand,\n LeaseReapStaleCommand,\n OutboxFlushCommand,\n PluginReplayDLQCommand,\n RunCancelCommand,\n RunClaimPendingCommand,\n RunCreateCommand,\n RunRerunFromCommand,\n RunTransitionCommand,\n StagePollSuspendedCommand,\n} from \"./commands\";\nimport { IdempotencyInProgressError } from \"./errors\";\nimport type { KernelEvent } from \"./events\";\nimport { handleJobExecute } from \"./handlers/job-execute\";\nimport { handleLeaseReapStale } from \"./handlers/lease-reap-stale\";\nimport { handleOutboxFlush } from \"./handlers/outbox-flush\";\nimport { handlePluginReplayDLQ } from \"./handlers/plugin-replay-dlq\";\nimport { handleRunCancel } from \"./handlers/run-cancel\";\nimport { handleRunClaimPending } from \"./handlers/run-claim-pending\";\nimport { handleRunCreate } from \"./handlers/run-create\";\nimport { handleRunRerunFrom } from \"./handlers/run-rerun-from\";\nimport { handleRunTransition } from \"./handlers/run-transition\";\nimport { handleStagePollSuspended } from \"./handlers/stage-poll-suspended\";\nimport type {\n BlobStore,\n Clock,\n EventSink,\n JobTransport,\n Persistence,\n Scheduler,\n} from \"./ports\";\n\n// ============================================================================\n// Public interfaces\n// ============================================================================\n\nexport interface WorkflowRegistry {\n getWorkflow(id: string): Workflow<any, any> | undefined;\n}\n\nexport interface KernelConfig {\n persistence: Persistence;\n blobStore: BlobStore;\n jobTransport: JobTransport;\n eventSink: EventSink;\n scheduler: Scheduler;\n clock: Clock;\n registry: WorkflowRegistry;\n}\n\nexport interface Kernel {\n dispatch<T extends KernelCommand>(command: T): Promise<CommandResult<T>>;\n}\n\n// ============================================================================\n// Shared dependency bundle passed to every handler\n// ============================================================================\n\nexport interface KernelDeps {\n persistence: Persistence;\n blobStore: BlobStore;\n jobTransport: JobTransport;\n eventSink: EventSink;\n scheduler: Scheduler;\n clock: Clock;\n registry: WorkflowRegistry;\n}\n\n// ============================================================================\n// Internal handler result type (includes _events for central emission)\n// ============================================================================\n\nexport type HandlerResult<T> = T & { _events: KernelEvent[] };\n\n// ============================================================================\n// Helpers\n// ============================================================================\n\n/** Extract idempotency key from commands that carry one. */\nfunction getIdempotencyKey(command: KernelCommand): string | undefined {\n if (command.type === \"run.create\") return command.idempotencyKey;\n if (command.type === \"job.execute\") return command.idempotencyKey;\n return undefined;\n}\n\n// ============================================================================\n// Factory\n// ============================================================================\n\nexport function createKernel(config: KernelConfig): Kernel {\n const {\n persistence,\n blobStore,\n jobTransport,\n eventSink,\n scheduler,\n clock,\n registry,\n } = config;\n\n const deps: KernelDeps = {\n persistence,\n blobStore,\n jobTransport,\n eventSink,\n scheduler,\n clock,\n registry,\n };\n\n async function dispatch<T extends KernelCommand>(\n command: T,\n ): Promise<CommandResult<T>> {\n // -----------------------------------------------------------------\n // outbox.flush routes directly — no outbox write, no idempotency\n // -----------------------------------------------------------------\n if (command.type === \"outbox.flush\") {\n const result = await handleOutboxFlush(\n command as OutboxFlushCommand,\n deps,\n );\n const { _events: _, ...publicResult } = result;\n return publicResult as CommandResult<T>;\n }\n\n // -----------------------------------------------------------------\n // plugin.replayDLQ routes directly — no outbox write, no idempotency\n // -----------------------------------------------------------------\n if (command.type === \"plugin.replayDLQ\") {\n const result = await handlePluginReplayDLQ(\n command as PluginReplayDLQCommand,\n deps,\n );\n const { _events: _, ...publicResult } = result;\n return publicResult as CommandResult<T>;\n }\n\n // -----------------------------------------------------------------\n // job.execute manages its own multi-phase transactions so that\n // RUNNING status is visible immediately and long-running stage\n // execution does not hold a database transaction open.\n // -----------------------------------------------------------------\n if (command.type === \"job.execute\") {\n const jobCommand = command as JobExecuteCommand;\n const jobIdempotencyKey = jobCommand.idempotencyKey;\n let jobIdempotencyAcquired = false;\n\n if (jobIdempotencyKey) {\n const acquired = await persistence.acquireIdempotencyKey(\n jobIdempotencyKey,\n command.type,\n );\n if (acquired.status === \"replay\") {\n return acquired.result as CommandResult<T>;\n }\n if (acquired.status === \"in_progress\") {\n throw new IdempotencyInProgressError(jobIdempotencyKey, command.type);\n }\n jobIdempotencyAcquired = true;\n }\n\n try {\n const result = await handleJobExecute(jobCommand, deps);\n const { _events: _, ...publicResult } = result;\n\n if (jobIdempotencyKey && jobIdempotencyAcquired) {\n await persistence.completeIdempotencyKey(\n jobIdempotencyKey,\n command.type,\n publicResult,\n );\n }\n\n return publicResult as CommandResult<T>;\n } catch (error) {\n if (jobIdempotencyKey && jobIdempotencyAcquired) {\n await persistence\n .releaseIdempotencyKey(jobIdempotencyKey, command.type)\n .catch(() => {});\n }\n throw error;\n }\n }\n\n // -----------------------------------------------------------------\n // Idempotency acquisition\n // -----------------------------------------------------------------\n const idempotencyKey = getIdempotencyKey(command);\n let idempotencyAcquired = false;\n\n if (idempotencyKey) {\n const acquired = await persistence.acquireIdempotencyKey(\n idempotencyKey,\n command.type,\n );\n\n if (acquired.status === \"replay\") {\n return acquired.result as CommandResult<T>;\n }\n if (acquired.status === \"in_progress\") {\n throw new IdempotencyInProgressError(idempotencyKey, command.type);\n }\n idempotencyAcquired = true;\n }\n\n try {\n // ---------------------------------------------------------------\n // Route to handler + append outbox events in one transaction\n // ---------------------------------------------------------------\n const publicResult = await persistence.withTransaction(async (tx) => {\n const txDeps: KernelDeps = { ...deps, persistence: tx };\n let result: HandlerResult<any>;\n\n switch (command.type) {\n case \"run.create\":\n result = await handleRunCreate(command as RunCreateCommand, txDeps);\n break;\n case \"run.claimPending\":\n result = await handleRunClaimPending(\n command as RunClaimPendingCommand,\n txDeps,\n );\n break;\n case \"run.transition\":\n result = await handleRunTransition(\n command as RunTransitionCommand,\n txDeps,\n );\n break;\n case \"run.cancel\":\n result = await handleRunCancel(command as RunCancelCommand, txDeps);\n break;\n case \"run.rerunFrom\":\n result = await handleRunRerunFrom(\n command as RunRerunFromCommand,\n txDeps,\n );\n break;\n case \"stage.pollSuspended\":\n result = await handleStagePollSuspended(\n command as StagePollSuspendedCommand,\n txDeps,\n );\n break;\n case \"lease.reapStale\":\n result = await handleLeaseReapStale(\n command as LeaseReapStaleCommand,\n txDeps,\n );\n break;\n default: {\n const _exhaustive: never = command;\n throw new Error(\n `Unknown command type: ${(_exhaustive as KernelCommand).type}`,\n );\n }\n }\n\n const events = result._events as KernelEvent[];\n if (events.length > 0) {\n const causationId = idempotencyKey ?? crypto.randomUUID();\n const outboxEvents: CreateOutboxEventInput[] = events.map(\n (event) => ({\n workflowRunId: event.workflowRunId,\n eventType: event.type,\n payload: event,\n causationId,\n occurredAt: event.timestamp,\n }),\n );\n await tx.appendOutboxEvents(outboxEvents);\n }\n\n const { _events: _, ...stripped } = result;\n return stripped as CommandResult<T>;\n });\n\n if (idempotencyKey && idempotencyAcquired) {\n await persistence.completeIdempotencyKey(\n idempotencyKey,\n command.type,\n publicResult,\n );\n }\n\n return publicResult;\n } catch (error) {\n if (idempotencyKey && idempotencyAcquired) {\n await persistence\n .releaseIdempotencyKey(idempotencyKey, command.type)\n .catch(() => {});\n }\n throw error;\n }\n }\n\n return { dispatch };\n}\n","/**\n * Plugin Runner\n *\n * A concrete EventSink implementation that routes kernel events\n * to registered plugin handlers. Used as the eventSink when the\n * consumer wants domain side-effects on workflow events.\n */\n\nimport type { KernelEvent, KernelEventType } from \"./events.js\";\nimport type { EventSink } from \"./ports.js\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface PluginDefinition<T extends KernelEventType = KernelEventType> {\n readonly id: string;\n readonly name: string;\n readonly on: readonly T[];\n handle(event: Extract<KernelEvent, { type: T }>): Promise<void>;\n}\n\nexport interface PluginRunnerConfig {\n plugins: PluginDefinition[];\n /** Max retries before an event moves to DLQ (default: 3). */\n maxRetries?: number;\n}\n\nexport interface PluginRunner extends EventSink {\n /** Max retries before DLQ. Exposed so outbox.flush can read it. */\n readonly maxRetries: number;\n}\n\n// ============================================================================\n// definePlugin\n// ============================================================================\n\nexport function definePlugin<T extends KernelEventType>(\n definition: PluginDefinition<T>,\n): PluginDefinition<T> {\n return definition;\n}\n\n// ============================================================================\n// createPluginRunner\n// ============================================================================\n\nexport function createPluginRunner(config: PluginRunnerConfig): PluginRunner {\n const { plugins, maxRetries = 3 } = config;\n\n // Pre-index plugins by event type for O(1) lookup\n const handlersByType = new Map<string, PluginDefinition[]>();\n for (const plugin of plugins) {\n for (const eventType of plugin.on) {\n const existing = handlersByType.get(eventType) ?? [];\n existing.push(plugin as PluginDefinition);\n handlersByType.set(eventType, existing);\n }\n }\n\n return {\n maxRetries,\n\n async emit(event: KernelEvent): Promise<void> {\n const matching = handlersByType.get(event.type);\n if (!matching || matching.length === 0) return;\n\n for (const plugin of matching) {\n await plugin.handle(event as any);\n }\n },\n };\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { ToolSet, generateText, StepResult, streamText } from 'ai';
2
2
  import z$1, { z } from 'zod';
3
- import { A as AICallLogger } from './interface-Cv22wvLG.js';
3
+ import { A as AICallLogger } from './interface-MMqhfQQK.js';
4
+ import { b as StageContext, c as SuspendedStateSchema, C as CheckCompletionContext, d as CompletionCheckResult, S as Stage } from './stage-BPw7m9Wx.js';
4
5
 
5
6
  /**
6
7
  * Schema Helpers and Utilities
@@ -52,147 +53,6 @@ declare const NoInputSchema: z.ZodObject<{}, z.core.$strip>;
52
53
  */
53
54
  declare function requireStageOutput<T>(workflowContext: Record<string, unknown>, stageId: string, field?: string): T;
54
55
 
55
- /**
56
- * Core type definitions for Workflow System v2
57
- *
58
- * See WORKFLOW_SYSTEM_PROPOSAL.md for full architectural details
59
- */
60
-
61
- interface ProgressUpdate {
62
- stageId: string;
63
- stageName: string;
64
- progress: number;
65
- message: string;
66
- details?: Record<string, unknown>;
67
- }
68
- interface StageMetrics {
69
- startTime: number;
70
- endTime: number;
71
- duration: number;
72
- itemsProcessed?: number;
73
- itemsProduced?: number;
74
- aiCalls?: number;
75
- totalTokens?: number;
76
- totalCost?: number;
77
- }
78
- interface EmbeddingResult {
79
- id: string;
80
- content: string;
81
- embedding: number[];
82
- similarity?: number;
83
- metadata?: Record<string, unknown>;
84
- }
85
- interface EmbeddingInfo {
86
- model: string;
87
- dimensions: number;
88
- results: EmbeddingResult[];
89
- totalProcessed?: number;
90
- averageSimilarity?: number;
91
- }
92
- interface StageResult<TOutput> {
93
- output: TOutput;
94
- metrics: StageMetrics;
95
- artifacts?: Record<string, unknown>;
96
- embeddings?: EmbeddingInfo;
97
- }
98
- declare const SuspendedStateSchema: z.ZodObject<{
99
- batchId: z.ZodString;
100
- statusUrl: z.ZodOptional<z.ZodString>;
101
- apiKey: z.ZodOptional<z.ZodString>;
102
- submittedAt: z.ZodString;
103
- pollInterval: z.ZodNumber;
104
- maxWaitTime: z.ZodNumber;
105
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
106
- }, z.core.$strip>;
107
- interface SuspendedResult {
108
- suspended: true;
109
- state: z.infer<typeof SuspendedStateSchema>;
110
- pollConfig: {
111
- pollInterval: number;
112
- maxWaitTime: number;
113
- nextPollAt: Date;
114
- };
115
- metrics: StageMetrics;
116
- }
117
- interface CompletionCheckResult<TOutput> {
118
- ready: boolean;
119
- output?: TOutput;
120
- error?: string;
121
- nextCheckIn?: number;
122
- metrics?: StageMetrics;
123
- embeddings?: EmbeddingInfo;
124
- }
125
- type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR";
126
- type StageMode = "sync" | "async-batch";
127
-
128
- /**
129
- * Stage interface and context definitions
130
- *
131
- * Stages are the building blocks of workflows. Each stage:
132
- * - Has strongly-typed input, output, and config schemas (Zod)
133
- * - Can be sync or async-batch
134
- * - Has access to AI helper, storage, and logging via context
135
- * - Can suspend workflow for long-running batch operations
136
- */
137
-
138
- interface StageContext<TInput, TConfig, TWorkflowContext = Record<string, unknown>> {
139
- workflowRunId: string;
140
- stageId: string;
141
- stageNumber: number;
142
- stageName: string;
143
- /** Database record ID for this stage execution (for logging to persistence) */
144
- stageRecordId?: string;
145
- input: TInput;
146
- config: TConfig;
147
- resumeState?: z.infer<typeof SuspendedStateSchema>;
148
- onProgress: (update: ProgressUpdate) => void;
149
- onLog: (level: LogLevel, message: string, meta?: Record<string, unknown>) => void;
150
- log: (level: LogLevel, message: string, meta?: Record<string, unknown>) => void;
151
- storage: StageStorage;
152
- workflowContext: Partial<TWorkflowContext>;
153
- }
154
- interface StageStorage {
155
- save<T>(key: string, data: T): Promise<void>;
156
- load<T>(key: string): Promise<T>;
157
- exists(key: string): Promise<boolean>;
158
- delete(key: string): Promise<void>;
159
- getStageKey(stageId: string, suffix?: string): string;
160
- }
161
- /**
162
- * Context passed to checkCompletion for async-batch stages.
163
- * Includes identification info so stages don't need to store it in metadata.
164
- */
165
- interface CheckCompletionContext<TConfig> {
166
- workflowRunId: string;
167
- stageId: string;
168
- /** Database record ID for this stage execution (for logging to persistence) */
169
- stageRecordId?: string;
170
- config: TConfig;
171
- onLog: (level: LogLevel, message: string, meta?: Record<string, unknown>) => void;
172
- log: (level: LogLevel, message: string, meta?: Record<string, unknown>) => void;
173
- storage: StageStorage;
174
- }
175
- interface Stage<TInput extends z.ZodTypeAny, TOutput extends z.ZodTypeAny, TConfig extends z.ZodTypeAny, TWorkflowContext = Record<string, unknown>> {
176
- id: string;
177
- name: string;
178
- description?: string;
179
- /**
180
- * Optional: List of stage IDs that this stage depends on.
181
- * The workflow builder will validate that all dependencies are present
182
- * in the workflow before this stage is executed.
183
- *
184
- * Example: dependencies: ["data-extraction", "guidelines"]
185
- */
186
- dependencies?: string[];
187
- inputSchema: TInput;
188
- outputSchema: TOutput;
189
- configSchema: TConfig;
190
- execute: (context: StageContext<z.infer<TInput>, z.infer<TConfig>, TWorkflowContext>) => Promise<StageResult<z.infer<TOutput>> | SuspendedResult>;
191
- checkCompletion?: (suspendedState: z.infer<typeof SuspendedStateSchema>, context: CheckCompletionContext<z.infer<TConfig>>) => Promise<CompletionCheckResult<z.infer<TOutput>>>;
192
- mode?: StageMode;
193
- estimateCost?: (input: z.infer<TInput>, config: z.infer<TConfig>) => number;
194
- }
195
-
196
56
  /**
197
57
  * Stage Factory - Simplified stage definition with auto-metrics
198
58
  *
@@ -935,4 +795,4 @@ interface LogPayload {
935
795
  meta?: Record<string, unknown>;
936
796
  }
937
797
 
938
- export { type ModelFilter as $, type AIHelper as A, type BatchLogFn as B, createAIHelper as C, DEFAULT_MODEL_KEY as D, type EmbedOptions as E, defineAsyncBatchStage as F, defineStage as G, getDefaultModel as H, type InferInput as I, getModel as J, getModelById as K, type LogContext as L, ModelKey as M, NoInputSchema as N, type ObjectOptions as O, getRegisteredModel as P, listModels as Q, type RecordCallParams as R, type Stage as S, type TextOptions as T, listRegisteredModels as U, modelSupportsBatch as V, type WorkflowEventType as W, printAvailableModels as X, registerModels as Y, requireStageOutput as Z, type LogPayload as _, type StageMetrics as a, type StageCompletedPayload as a0, type StageFailedPayload as a1, type StageStartedPayload as a2, type WorkflowCompletedPayload as a3, type WorkflowFailedPayload as a4, type WorkflowStartedPayload as a5, type WorkflowSuspendedPayload as a6, type WorkflowSSEEvent as b, type LogLevel as c, type AIBatch as d, type AIBatchHandle as e, type AIBatchProvider as f, type AIBatchRequest as g, type AIBatchResult as h, type AICallType as i, type AIEmbedResult as j, type AIObjectResult as k, type AIStreamResult as l, type AITextResult as m, AVAILABLE_MODELS as n, type AsyncBatchStageDefinition as o, type EnhancedStageContext as p, type ModelConfig as q, type ModelRegistry as r, type ModelStats as s, ModelStatsTracker as t, type ModelSyncConfig as u, type SimpleStageResult as v, type StageResult as w, type StreamOptions as x, type SyncStageDefinition as y, calculateCost as z };
798
+ export { type WorkflowCompletedPayload as $, type AIBatch as A, type BatchLogFn as B, getModel as C, DEFAULT_MODEL_KEY as D, type EmbedOptions as E, getModelById as F, getRegisteredModel as G, listModels as H, type InferInput as I, listRegisteredModels as J, modelSupportsBatch as K, type LogContext as L, ModelKey as M, NoInputSchema as N, type ObjectOptions as O, printAvailableModels as P, registerModels as Q, type RecordCallParams as R, type SimpleStageResult as S, type TextOptions as T, requireStageOutput as U, type LogPayload as V, type WorkflowEventType as W, type ModelFilter as X, type StageCompletedPayload as Y, type StageFailedPayload as Z, type StageStartedPayload as _, type AIBatchHandle as a, type WorkflowFailedPayload as a0, type WorkflowStartedPayload as a1, type WorkflowSuspendedPayload as a2, type AIBatchProvider as b, type AIBatchRequest as c, type AIBatchResult as d, type AICallType as e, type AIEmbedResult as f, type AIHelper as g, type AIObjectResult as h, type AIStreamResult as i, type AITextResult as j, AVAILABLE_MODELS as k, type AsyncBatchStageDefinition as l, type EnhancedStageContext as m, type ModelConfig as n, type ModelRegistry as o, type ModelStats as p, ModelStatsTracker as q, type ModelSyncConfig as r, type StreamOptions as s, type SyncStageDefinition as t, type WorkflowSSEEvent as u, calculateCost as v, createAIHelper as w, defineAsyncBatchStage as x, defineStage as y, getDefaultModel as z };
package/dist/client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { A as AIHelper, n as AVAILABLE_MODELS, o as AsyncBatchStageDefinition, D as DEFAULT_MODEL_KEY, p as EnhancedStageContext, I as InferInput, _ as LogPayload, q as ModelConfig, $ as ModelFilter, M as ModelKey, r as ModelRegistry, N as NoInputSchema, v as SimpleStageResult, a0 as StageCompletedPayload, a1 as StageFailedPayload, a2 as StageStartedPayload, y as SyncStageDefinition, a3 as WorkflowCompletedPayload, W as WorkflowEventType, a4 as WorkflowFailedPayload, b as WorkflowSSEEvent, a5 as WorkflowStartedPayload, a6 as WorkflowSuspendedPayload, z as calculateCost, F as defineAsyncBatchStage, G as defineStage, Q as listModels, V as modelSupportsBatch, Y as registerModels } from './client-5vz5Vv4A.js';
1
+ export { g as AIHelper, k as AVAILABLE_MODELS, l as AsyncBatchStageDefinition, D as DEFAULT_MODEL_KEY, m as EnhancedStageContext, I as InferInput, V as LogPayload, n as ModelConfig, X as ModelFilter, M as ModelKey, o as ModelRegistry, N as NoInputSchema, S as SimpleStageResult, Y as StageCompletedPayload, Z as StageFailedPayload, _ as StageStartedPayload, t as SyncStageDefinition, $ as WorkflowCompletedPayload, W as WorkflowEventType, a0 as WorkflowFailedPayload, u as WorkflowSSEEvent, a1 as WorkflowStartedPayload, a2 as WorkflowSuspendedPayload, v as calculateCost, x as defineAsyncBatchStage, y as defineStage, H as listModels, K as modelSupportsBatch, Q as registerModels } from './client-D4PoxADF.js';
2
2
  import 'ai';
3
3
  import 'zod';
4
- import './interface-Cv22wvLG.js';
4
+ import './interface-MMqhfQQK.js';
5
+ import './stage-BPw7m9Wx.js';
@@ -1,4 +1,4 @@
1
- import { A as AICallLogger, C as CreateAICallInput, a as AIHelperStats, W as WorkflowPersistence, e as CreateRunInput, f as WorkflowRunRecord, U as UpdateRunInput, g as WorkflowStatus, h as CreateStageInput, i as WorkflowStageRecord, j as UpsertStageInput, k as UpdateStageInput, l as WorkflowStageStatus, m as CreateLogInput, S as SaveArtifactInput, n as WorkflowArtifactRecord, J as JobQueue, E as EnqueueJobInput, D as DequeueResult } from './interface-Cv22wvLG.js';
1
+ import { A as AICallLogger, g as CreateAICallInput, h as AIHelperStats, l as WorkflowPersistence, a as CreateRunInput, W as WorkflowRunRecord, U as UpdateRunInput, m as WorkflowStatus, b as CreateStageInput, c as WorkflowStageRecord, d as UpsertStageInput, e as UpdateStageInput, n as WorkflowStageStatus, f as CreateLogInput, o as SaveArtifactInput, p as WorkflowArtifactRecord, C as CreateOutboxEventInput, O as OutboxRecord, J as JobQueue, E as EnqueueJobInput, D as DequeueResult } from './interface-MMqhfQQK.js';
2
2
 
3
3
  /**
4
4
  * PrismaAICallLogger - Prisma implementation of AICallLogger
@@ -52,6 +52,7 @@ declare class PrismaWorkflowPersistence implements WorkflowPersistence {
52
52
  private enums;
53
53
  private databaseType;
54
54
  constructor(prisma: PrismaClient$1, options?: PrismaWorkflowPersistenceOptions);
55
+ withTransaction<T>(fn: (tx: WorkflowPersistence) => Promise<T>): Promise<T>;
55
56
  createRun(data: CreateRunInput): Promise<WorkflowRunRecord>;
56
57
  updateRun(id: string, data: UpdateRunInput): Promise<void>;
57
58
  getRun(id: string): Promise<WorkflowRunRecord | null>;
@@ -80,6 +81,7 @@ declare class PrismaWorkflowPersistence implements WorkflowPersistence {
80
81
  upsertStage(data: UpsertStageInput): Promise<WorkflowStageRecord>;
81
82
  updateStage(id: string, data: UpdateStageInput): Promise<void>;
82
83
  updateStageByRunAndStageId(workflowRunId: string, stageId: string, data: UpdateStageInput): Promise<void>;
84
+ private buildRunUpdateData;
83
85
  private buildStageUpdateData;
84
86
  getStage(runId: string, stageId: string): Promise<WorkflowStageRecord | null>;
85
87
  getStageById(id: string): Promise<WorkflowStageRecord | null>;
@@ -101,8 +103,25 @@ declare class PrismaWorkflowPersistence implements WorkflowPersistence {
101
103
  listArtifacts(runId: string): Promise<WorkflowArtifactRecord[]>;
102
104
  getStageIdForArtifact(runId: string, stageId: string): Promise<string | null>;
103
105
  saveStageOutput(runId: string, workflowType: string, stageId: string, output: unknown): Promise<string>;
106
+ appendOutboxEvents(events: CreateOutboxEventInput[]): Promise<void>;
107
+ getUnpublishedOutboxEvents(limit?: number): Promise<OutboxRecord[]>;
108
+ markOutboxEventsPublished(ids: string[]): Promise<void>;
109
+ incrementOutboxRetryCount(id: string): Promise<number>;
110
+ moveOutboxEventToDLQ(id: string): Promise<void>;
111
+ replayDLQEvents(maxEvents: number): Promise<number>;
112
+ acquireIdempotencyKey(key: string, commandType: string): Promise<{
113
+ status: "acquired";
114
+ } | {
115
+ status: "replay";
116
+ result: unknown;
117
+ } | {
118
+ status: "in_progress";
119
+ }>;
120
+ completeIdempotencyKey(key: string, commandType: string, result: unknown): Promise<void>;
121
+ releaseIdempotencyKey(key: string, commandType: string): Promise<void>;
104
122
  private mapWorkflowRun;
105
123
  private mapWorkflowStage;
124
+ private mapOutboxEvent;
106
125
  private mapWorkflowArtifact;
107
126
  }
108
127
  /**