W4: @opencomputer/flue CF-native scaffolding - #490
Conversation
Replaces the serveOC/brain-box package with the Flue CF-native shape (design 013 §4/§5). A stock `flue build --target cloudflare` app opts into OC via: - useOcGateway(ctx) + DEFAULT_MODEL (claude-haiku-4.5, prompt-caching-safe): point managed anthropic at env.OC_GATEWAY. Called INSIDE the defineAgent initializer (top-level is tree-shaken — 1a). - route: the HTTP-transport opt-in every OC agent must export. - ocSandbox(env): a durable OC-fleet SandboxApi (files/exec over the OC sandbox HTTP API; stat/mkdir/rm via shell, mirroring cloudflareSandbox). - ocRepoTools(env): publish_pull_request (repo plane, used by W10). - ./app: default hosting app (flue() + /health + observe→OC_INGEST). ./wire: telemetry-only side-effect for apps with their own app.ts. Builds + typechecks clean against @flue/runtime@1.0.0-beta.9. Verified end-to-end: the re-scaffolded oc-flue-starter `flue build --target cloudflare`s with zero hand-editing and the wiring (useOcGateway/registerProvider, ocSandbox, /health, haiku model) is present in the bundle (not tree-shaken). TOKEN SEAM — OPEN, needs orchestrator decision (see gateway.ts): Flue's registerProvider takes only a static apiKey and its getApiKey(providerId) callback gets no request context, and the provider registry is isolate-global (shared across co-located DO instances) — so a per-SESSION token/header/baseUrl via registerProvider RACES. Wired the buildable env shape; robust per-session attribution needs the upstream `headers(ctx)` ask. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
W6 live bring-up hit three defects W4's bundle-grep acceptance missed.
Fixed at the package layer so the scaffolded starter needs no workarounds.
1. DEFAULT_MODEL dot->dash. `anthropic/claude-haiku-4.5` is absent from
pi-ai's model catalog, so pi-ai can't derive max output tokens and
defaults max_tokens=1 -> empty completions. Use the catalog id
`anthropic/claude-haiku-4-5` (dashes; OpenRouter routes it too).
2. ctx.env empty on the CF build. On `flue build --target cloudflare`
the real Worker bindings live on the ambient `cloudflare:workers`
env, not the per-agent `ctx.env` Flue threads in (that is empty for
OC bindings), so OC_GATEWAY was unset -> the anthropic provider never
registered ("Unknown model specifier"). New cf-env.ts reads the
ambient env via a guarded lazy import (falls back to the passed env
for local dev / node); useOcGateway + ocSandbox read through it.
3. Default `@opencomputer/flue/app` 500s. app.ts mounted flue() from
`@flue/runtime/routing`; the generated CF entry seeds the runtime via
configureFlueRuntime from `@flue/runtime/internal` and its no-app.ts
path builds the app with createDefaultFlueApp() from that same entry.
Compose via createDefaultFlueApp() so flue()'s module-scoped
runtimeConfig is the instance the build configures (+ keep /health and
installOcObserver) -> no "flue() route invoked before runtime was
configured".
Verified: scaffolded starter `flue build --target cloudflare` + wrangler
dev -> GET /health 200; POST /agents turn 202 -> model call reaches the
gateway with model=claude-haiku-4-5, max_tokens=64000 (not 1); full turn
settles completed with a non-empty agent message.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
W4 (Scaffolding) — the package that makes a stock Flue app OpenComputer-native, into the flue-native evergreen (#489). Draft; never merge (Igor).
What's here (
sdks/flue,@opencomputer/flue0.2.0)Replaces the serveOC/brain-box shape with the CF-native shape (design 013 §4/§5):
useOcGateway(ctx)+DEFAULT_MODEL(claude-haiku-4.5, prompt-caching-safe) — point managedanthropicatenv.OC_GATEWAY, called inside thedefineAgentinitializer (top-level is tree-shaken).route— HTTP-transport opt-in (every OC agent mustexport { route }).ocSandbox(env)— durable OC-fleetSandboxApi(files/exec over the OC sandbox HTTP API; stat/mkdir/rm via shell, mirroringcloudflareSandbox).ocRepoTools(env)—publish_pull_request(repo plane; W10).@opencomputer/flue/app(default hosting app:flue()+/health+observe→OC_INGEST) and/wire(telemetry-only side-effect).Verified
tsc+ build clean vs@flue/runtime@1.0.0-beta.9. End-to-end: the re-scaffoldedoc-flue-starter(separate PR)flue build --target cloudflares zero hand-editing, and the wiring (useOcGateway/registerProvider,ocSandbox,/health, haiku model) is present in the bundle — not tree-shaken.🔴 TOKEN SEAM — needs your decision
The buildout's seam (a) ("per-turn token → Flue's
getApiKey(providerId)callback") is not achievable:registerProvidertakes only a staticapiKey; its internalgetApiKey(providerId)gets no request/turn context; and the provider registry is module(isolate)-scoped, shared across co-located DO instances — so a per-sessionapiKey/headers/baseUrlset viaregisterProviderraces across sessions in one isolate. Seam (b)'s per-instanceX-OC-Sessionheader has the same race (registration is isolate-global).→ Robust per-session attribution needs the upstream ask: a per-request
headers(ctx)hook onregisterProvider(already in the buildout "Upstream asks"). Interim buildable shape wired here: staticenv.OC_SESSION_TOKEN(works one-session-per-isolate) metered bytoken.sub. Please confirm the direction (pursue the upstream hook / accept per-deploy metering / assume low co-location).Seams flagged for other lanes
ocSandboxresolves the session's sandbox viaOC_SANDBOX_IDor aPOST {OC_SANDBOX_API}/flue/session-sandbox?session=seam (W1/W5 pin it);ocRepoToolsposts to{OC_REPO_API}/publish(W10 pins it).🤖 Generated with Claude Code