@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 standardRequest 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:
Siglo:*(v1.0.0+)hono:^3.0.0 || ^4.0.0
[!IMPORTANT] Edge Runtime Compatibility (nodejs_compat):@siglo/corerelies onnode:async_hooks(for context propagation andnetworkPolicyAsyncLocalStorage perimeter tracking) andnode:net(for socket egress checks). When deploying to edge environments like Cloudflare Workers, ensure Node.js compatibility is enabled inwrangler.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 Standardc.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):
StepTimeoutException/FlowTimeoutException:504 Gateway TimeoutValidationException/SpecFailedException:400 Bad RequestIdempotencyConflictException:409 ConflictCancellationException/AbortError:499 Client Closed Request- Unhandled
Error:500 Internal Server Error(sanitized in production)
8. Durable Workflows and Automatic HTTP Responses
Enabledurable: 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.
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.