Context
I’m trying to build an agentic email system on Cloudflare Workers:
- inbound email via Cloudflare Email Service / Agents SDK
- D1 for storing emails, summaries, drafts, and thread state
- Telegram bot/webhook for personal notifications and commands
- online draft/reply UI served by the Worker
- Codegraff as the agent harness for summarizing emails and drafting replies
The Worker side is a natural fit for email routing, D1, Telegram webhooks, and outbound send_email, but the current TypeScript SDK docs describe @codegraff/sdk as an in-process native Node addon. The docs also say Edge / Cloudflare Workers / Deno Deploy are unsupported because there is no N-API.
Question
Can we expose a Worker-compatible harness API so Cloudflare Workers can use Codegraff without embedding the native addon?
Something like one of these would work well:
-
Hosted harness HTTP API
POST /v1/harness/run or similar
- accepts prompt/session/tools/config
- streams the same event model as
@codegraff/sdk (TaskMessage, ToolCallStart, TaskComplete, etc.) over SSE or newline-delimited JSON
-
Edge-safe TypeScript client
- e.g.
@codegraff/edge or an edge mode in @codegraff/sdk
- uses only
fetch, ReadableStream, Web Crypto, etc.
- no native addon / no Node-only APIs
-
Documented pattern for remote harness proxy
- recommended minimal Node service that runs the native SDK
- Worker calls it over HTTP
- preserves session IDs and streaming events
Why the OpenAI-compatible API is not quite enough
The OpenAI-compatible gateway is useful for plain model calls, and a Worker can call it directly with fetch. But for this use case we want the Codegraff agent harness semantics: sessions, tool events, structured event streaming, and a stable way to build workflows around email processing/drafting.
nodejs_compat question
Could Cloudflare nodejs_compat make the current SDK work? My understanding is probably no: nodejs_compat provides/polyfills a subset of Node.js built-ins, but it does not provide a native Node addon / N-API runtime inside Workers. Since @codegraff/sdk embeds the harness as a native addon, Workers still cannot load it even with nodejs_compat.
If that understanding is wrong, it would be great to document the exact wrangler.toml/compatibility-date setup that makes it work. If it is correct, we should probably document that nodejs_compat does not change the Cloudflare Worker limitation.
Desired outcome
A supported path for this architecture:
Cloudflare Email Worker + D1 + Telegram
↓
Worker-compatible Codegraff harness API/client
↓
Summaries, classifications, follow-up detection, and draft replies
This would make Codegraff much easier to use in edge/event-driven systems where the Worker is the natural integration point but cannot run native Node addons.
Acceptance ideas
Context
I’m trying to build an agentic email system on Cloudflare Workers:
The Worker side is a natural fit for email routing, D1, Telegram webhooks, and outbound
send_email, but the current TypeScript SDK docs describe@codegraff/sdkas an in-process native Node addon. The docs also say Edge / Cloudflare Workers / Deno Deploy are unsupported because there is no N-API.Question
Can we expose a Worker-compatible harness API so Cloudflare Workers can use Codegraff without embedding the native addon?
Something like one of these would work well:
Hosted harness HTTP API
POST /v1/harness/runor similar@codegraff/sdk(TaskMessage,ToolCallStart,TaskComplete, etc.) over SSE or newline-delimited JSONEdge-safe TypeScript client
@codegraff/edgeor an edge mode in@codegraff/sdkfetch,ReadableStream, Web Crypto, etc.Documented pattern for remote harness proxy
Why the OpenAI-compatible API is not quite enough
The OpenAI-compatible gateway is useful for plain model calls, and a Worker can call it directly with
fetch. But for this use case we want the Codegraff agent harness semantics: sessions, tool events, structured event streaming, and a stable way to build workflows around email processing/drafting.nodejs_compat question
Could Cloudflare
nodejs_compatmake the current SDK work? My understanding is probably no:nodejs_compatprovides/polyfills a subset of Node.js built-ins, but it does not provide a native Node addon / N-API runtime inside Workers. Since@codegraff/sdkembeds the harness as a native addon, Workers still cannot load it even withnodejs_compat.If that understanding is wrong, it would be great to document the exact
wrangler.toml/compatibility-date setup that makes it work. If it is correct, we should probably document thatnodejs_compatdoes not change the Cloudflare Worker limitation.Desired outcome
A supported path for this architecture:
This would make Codegraff much easier to use in edge/event-driven systems where the Worker is the natural integration point but cannot run native Node addons.
Acceptance ideas
nodejs_compatcan/cannot support@codegraff/sdkin Workers.