aigcfree (Discord DM) runs `magpie web --addr 0.0.0.0:3430` on an Ubuntu
server behind nginx, and opens it from a Windows PC. The chat tab showed
"127.0.0.1 refused to connect": boot.js sent the frame to 127.0.0.1, the
viewer's own PC. 0.1.1 (8a9680b) explains an SSH tunnel instead. With a
magpie that proxies a page's service, no tunnel is needed:
- package.json declares magpie.page.service {port: 3477, option: "port"},
the same port index.mjs listens on. magpie web then proxies the service
under the page's token (/_magpie/plugin/<token>/_magpie/service/) and the
bridge hands that address to the page as magpie.service.
- boot.js goes to magpie.service when it is an http(s) address. Without
one (the desktop window, or an older magpie) it behaves as 0.1.1: on
loopback it goes to 127.0.0.1, from another machine it explains the
tunnel.
- The chat client asks api/... by relative address (app.js, index.html,
library.mjs's icon URLs), so it works under the proxied path. Served
from 127.0.0.1:<port>/ these resolve as before.
The service still listens on 127.0.0.1 only, and still checks Host,
Origin and its token. magpie's proxy sets Host to 127.0.0.1:<port>.
Run: bun test packages/chat (16 pass) and bun scripts/check.mjs on mote.
Real: a sandbox magpie web on mote (0.0.0.0, LAN), this package installed
from a folder, a fake gateway. Playwright on the Windows box opened the
chat tab over the LAN in Chromium and WebKit, sent a message, and got the
streamed answer; the fake gateway logged both requests.
Broken by hand: the service branch in boot.js off, 2 tests red.
Not tried: behind a real nginx; the desktop window with this version (the
fallback is the 0.1.1 path, covered by the launcher tests).
Lists Magic_zero's (Magiczerowxy) magpie-chat as @magpie-community/page-chat:
a chat page in magpie's window over magpie's own gateway, models, MCP
servers, instructions and skills. Not a provider or a relay: it signs in
to nothing and every request goes through magpie's gateway.
- chat.test.mjs starts the service on a free port against a fake
gateway in a temp config folder: no token (Origin null and none), a
wrong token, another Origin and a rebound Host are refused and nothing
reaches the gateway; with the token a chat streams with the caller key;
the icon redirect has a Location; boot.js makes no request; app.js
sends the token.
- scripts/check.mjs takes the OpenCode v1 default export {id, server}
as magpie's host does, and doesn't start a page's server (it would bind
a port and write config); layerfs's tools are still checked.
- package.json declares the port option (3477) both parts read; boot.js's
comment says so instead of a fallback to 3478 that never existed.
- README in the repo's style with credit, what the service reads and
sends, who can use it, and the changes from the original.
- registry.json entry and a row in the Pages table.
Run on mote (bun 1.4.2) at this tree:
- cd packages/chat && HOME=$(mktemp -d) bun test: 11 pass.
- HOME=$(mktemp -d) bun test (whole repo): 3119 pass, 0 fail, 3127
tests across 261 files; bun scripts/check.mjs: exit 0, chat and
layerfs ok.
Broken by hand: with the token check off, "a page without the token
can't chat" went red; with the Host check off, "a DNS-rebound Host is
refused" went red.
Not tried: the page in a real magpie window (sandboxed frame navigation
and the host calling server()).
Co-authored-by: Magiczerowxy <magiczerowxy@users.noreply.github.com>
The service on 127.0.0.1:3477 answered Origin: null (any site's sandboxed
iframe or a data: page) with ACAO null, and had no Host check, so a
hostile page could POST /api/chat on the user's magpie gateway key, read
and rewrite conversations and settings, and drive MCP tools; a DNS-rebound
page could read conversations with a plain GET.
- Every /api/ route except ping, fonts.css and icon/* now needs a
per-process token (x-magpie-chat-token, timing-safe compare). The token
is put in index.html as a meta tag, and index.html goes out without
CORS, so only a page that navigated to the service can read it. app.js
sends it on every call and reloads once when the service restarted.
- The Host must be 127.0.0.1:<port> or localhost:<port>, checked first.
- index.mjs starts the service when the host calls server(), not on
import, and passes the plugin option's port, which page/boot.js already
read; before, a port set in the options moved the page and not the
service.
- Port 0 binds a free port (tests); the actual port is used for the Host
and Origin lists.
- /api/icon's remote icon answered 302 without a Location; it has one.
- /api/bootstrap reports the package version instead of "0.1.0".
- package.json: 0.1.0 in magpie-community/plugins, author credit, start
runs serve.mjs.
Co-authored-by: Magiczerowxy <magiczerowxy@users.noreply.github.com>
The files its package.json ships, unchanged, from
https://github.com/Magiczerowxy/magpie-chat at 15de02d (0.1.18). The
vendored KaTeX is katex@0.16.11's dist, byte for byte (checked against
npm's tarball). Not published from this commit: the next ones close the
local service to other pages and fit it to the repo.
Co-authored-by: Magiczerowxy <magiczerowxy@users.noreply.github.com>