2 Commits

Author SHA1 Message Date
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
mahmoud
5bccd8338b
feat(ai): add OpenCode Zen and Go providers (#18)
* feat(ai): add OpenCode Zen and Go providers

Add OpenCode as a key-based provider with shared Zen/Go credentials, a same-origin CORS proxy, runtime model catalogs, and a vision-model fallback that describes screenshots for text-only coding models.

* fix(ai): keep OpenCode Zen/Go path prefixes when proxying

Absolute /v1/... suffixes were resolved against the OpenCode origin and dropped /zen and /zen/go. Join relative to those prefixes in the worker and Vite rewrites.


* chore(deps): bump nanoid override to 3.3.18

Clear GHSA-2v37-7h3g-55p8 so bun audit can pass. The previous 3.3.17 pin is now reported as vulnerable.

* fix(ai): surface run status events and cache image descriptions across steps

OpenCode text-only models describe screenshots with a vision model before
generating. The modal dropped 'status' run events, so the band showed
'Starting up …' for the whole describe phase, and each tool-loop step
re-described every image from scratch because the description cache lived
only one prepare call.


* refactor(ai): enhance OpenCode model handling and proxy functionality

* fix: allow images to be used in devices

* fix(ai): defer vision fallback, harden image cache keys, and remount model browser per provider

Address CodeRabbit review on #18:
- resolve the OpenCode vision describer only once a prepared step contains
  an image, so text-only models run image-free requests without a fallback
- relay tool preview images whenever the vision fallback is active, not
  only for chat-dialect models
- hash full binary payloads for image description cache keys so distinct
  same-length images are described separately
- build the unavailable-transport error from the selected provider
- remount AiCatalogModelBrowser per provider so catalogs never leak
  between OpenRouter and OpenCode gateways
- bound the OpenCode catalog fetch with a 10s timeout and guard the
  catalog-revision state update after unmount
- correct the worker key-handling doc and the vision-default comment
2026-08-20 01:10:05 +02:00