Small, self-hosted PHP + vanilla JS chat UI that talks to an OpenCode server.
It includes:
legacy-api-viewer.php: the chat UI (single page, ES5 JS, minimal dependencies). Tested on a Kobo e-reader and worked fine.proxy.php: an SSE proxy that forwards OpenCode events to the browser and persists a session idreset.php: clears the persisted session and deletes it on the OpenCode server
- PHP 7.4+ (should also work on PHP 8.x)
curlavailable on the server (these scripts use the curl CLI viaproc_open)- An OpenCode server reachable over HTTP
These scripts are portable by default (no hardcoded LAN IPs). Configure via environment variables:
-
OPENCODE_URL- Base URL of the OpenCode server
- Default:
http://127.0.0.1:4096
-
OPENCODE_CORS_ORIGIN- Value for
Access-Control-Allow-Origin - Default:
* - If you are deploying behind a real domain, you should set this to your exact origin.
- Value for
Examples:
# OpenCode running on the same machine
export OPENCODE_URL="http://127.0.0.1:4096"
# Tighten CORS (recommended when exposed beyond localhost)
export OPENCODE_CORS_ORIGIN="https://chat.example.com"Serve this folder with any PHP-capable web server.
Using the built-in PHP server:
OPENCODE_URL="http://127.0.0.1:4096" \
php -S 0.0.0.0:8000Then open:
http://localhost:8000/legacy-api-viewer.php
-
Session persistence is implemented with a single file:
.opencode_sessionin this directory.- This is fine for personal use.
- For multi-user deployments you should switch to per-user sessions (cookie-based storage).
-
Prompts are sent as a query parameter (
GET ?prompt=...) becauseEventSourceonly supports GET.- Avoid putting this behind proxies that log full URLs if prompts are sensitive.
This project is intended for local/self-host use.
If you expose it on the public internet, add authentication and lock down CORS.
MIT. See LICENSE.