Skip to main content

@siglo/hono Adapter Guide

@siglo/hono provides a modern, Web Standards-compliant middleware and route handler adapter for executing Siglo workflows. It is optimized for cross-runtime deployment across Cloudflare Workers, Fastly Compute, Deno, Bun, AWS Lambda (via Hono), and traditional Node.js servers.

1. Overview & Architecture

Because Hono is built on standard Request and Response Web APIs, @siglo/hono enables portable, edge-ready workflow orchestration without any platform-specific Node.js bindings:

2. Installation & Requirements

Install @siglo/hono and Hono:
Peer dependency matrix:
  • Siglo: * (v1.0.0+)
  • hono: ^3.0.0 || ^4.0.0
[!IMPORTANT] Edge Runtime Compatibility (nodejs_compat): @siglo/core relies on node:async_hooks (for context propagation and networkPolicy AsyncLocalStorage perimeter tracking) and node:net (for socket egress checks). When deploying to edge environments like Cloudflare Workers, ensure Node.js compatibility is enabled in wrangler.toml:

3. API Reference

sigloMiddleware(workflow, options)

[!NOTE] Backward Compatibility: rivuletMiddleware is exported as an identical alias for legacy workflows.
Creates a Hono route handler or middleware (c: Context, next?: Next) => Promise<any>:

4. Configuration Options (SigloHonoMiddlewareOptions)

Without a custom output callback, a workflow result with status: 'waiting' returns 202 Accepted with the suspension descriptor as JSON. Completed workflows use the normal 200 OK response. Suspension is a successful result and does not invoke onError. A custom output callback controls both the response body and status.

5. Web Standard Request Cancellation

In modern edge runtimes (Cloudflare Workers, Bun, Deno), clients closing the connection abort the native Web Standard c.req.raw.signal. @siglo/hono passes this signal directly to ExecutionOptions.signal. Within workflow steps, access the cancellation signal via param.$signal?.():

6. Multi-Runtime Deployment Guides

A. Cloudflare Workers


B. Bun / Node.js Server


7. Error Handling & Status Code Mapping

When a step fails, @siglo/hono checks the error type using getErrorStatusCode(err):
Default HTTP status mappings:
  • StepTimeoutException / FlowTimeoutException: 504 Gateway Timeout
  • ValidationException / SpecFailedException: 400 Bad Request
  • IdempotencyConflictException: 409 Conflict
  • CancellationException / AbortError: 499 Client Closed Request
  • Unhandled Error: 500 Internal Server Error (sanitized in production)

8. Durable Workflows and Automatic HTTP Responses

Enable durable: true so waitForEvent() or wait() can suspend execution. The adapter automatically returns 202 Accepted when the result has status: 'waiting', including the suspension descriptor and X-Workflow-Stack-Id header. A workflow that completes uses 200 OK by default.
The waiting JSON includes status, stackId, stepId, correlationKey, eventName, expiresAt (a Unix timestamp in milliseconds when a timeout is set), and continuationStepIndex. Suspension is a successful result, so it does not invoke onError. Calling the submission handler again starts a new execution; approval webhooks must call resumeWorkflow() to continue the suspended one. For request-specific control, replace durable: true with durable: (c) => c.req.header('x-durable') === 'true'. Headers, query parameters, and JSON fields do not automatically enable durable mode in this adapter. Explicit durable: false disables suspension; wait nodes then use their non-durable behavior. A custom output callback takes full control of the response body and status, including for waiting results. If you supply one, handle result.status === 'waiting' explicitly when you want to preserve the 202 response. The HTTP adapter does not supply persistence. Configure a shared storage adapter that supports checkpoints and wait records to survive process restarts and resume across replicas. Timer waits also need a scheduler to resume them when due. See Durable Workflows, Storage and Adapters, and the distributed checkout tutorial.