Enderson Vizcaino 952cd42c0b
fix(ai): send x-opencode-session on every OpenCode request (#23)
* fix(ai): send x-opencode-session on every OpenCode request

OpenCode Go and Zen require a stable per-conversation session id in the
x-opencode-session header so the gateway can route traffic and reuse prompt
caches (https://opencode.ai/docs/go/#where-can-i-use-it). Without it the
gateway answers "Request is missing x-opencode-session and cannot be routed
efficiently" and the run fails.

- build one module-scope session id per browser session and pass it through
  headers to all four OpenCode dialects (responses, chat, messages, google),
  which also covers the vision describer
- forward the header through the hosted Cloudflare Worker proxy, whose
  allowlist previously stripped it; the Vite dev proxy already forwarded it

* fix(ai): keep the OpenCode session id stable across reloads

The module-scope session id was regenerated on every full page load, so
reloads dropped the stable identity the OpenCode gateway needs for routing
and prompt caching.

Read the id from sessionStorage, generate one when none is stored, and
persist it; a fresh tab still gets its own id, which keeps sharding traffic
across clients. Storage that is unavailable or throws falls back to a
per-page-load id instead of failing the request.
2026-10-19 23:16:55 +02:00
..