Skip to content

About

Minimal PHP + vanilla JS chat UI and SSE proxy for an OpenCode server.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

OpenCode PHP Chat (Legacy Viewer)

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 id
  • reset.php: clears the persisted session and deletes it on the OpenCode server

Requirements

  • PHP 7.4+ (should also work on PHP 8.x)
  • curl available on the server (these scripts use the curl CLI via proc_open)
  • An OpenCode server reachable over HTTP

Configuration

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.

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"

Run Locally

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:8000

Then open:

  • http://localhost:8000/legacy-api-viewer.php

Notes / Limitations

  • Session persistence is implemented with a single file: .opencode_session in 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=...) because EventSource only supports GET.

    • Avoid putting this behind proxies that log full URLs if prompts are sensitive.

Security

This project is intended for local/self-host use.

If you expose it on the public internet, add authentication and lock down CORS.

License

MIT. See LICENSE.

About

Minimal PHP + vanilla JS chat UI and SSE proxy for an OpenCode server.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages