Skip to content

Add Worker-compatible harness API for edge runtimes #168

@justrach

Description

@justrach

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:

  1. 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
  2. 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
  3. 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

  • Add docs clarifying whether nodejs_compat can/cannot support @codegraff/sdk in Workers.
  • Provide an edge-compatible harness API or recommended proxy pattern.
  • Provide a small Cloudflare Worker example that streams harness events and stores results in D1.
  • Preserve the SDK event model so Worker apps do not have to downgrade to plain chat completions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions