Files
plugins/packages/chat
yetone 740e1af252 tests: grok's nocli puts PATH back when its file ends, so gumloop's Node children find node on CI
publish.yml has been red on main since 7ebab07c (run 43011771755, and
43012668584, 43012789287 after it): 4 of gumloop's regression tests
failed with `Executable not found in $PATH: "node"`, so dist and npm
were skipped and gumloop 0.1.0 and agy-cli 0.1.19 reached neither.

Cause: bun test runs every file of the root run in one process.
packages/grok/nocli.mjs sets PATH=/usr/bin:/bin (and HOME, USERPROFILE,
GROK_HOME, GROK_BIN_DIR) for grok's files and never put them back, so
every file after grok's ran with that PATH. On ubuntu CI node is
actions/setup-node's, under /opt/hostedtoolcache, so gumloop's
spawn("node") found none whenever bun ran grok's files before
gumloop's (CI's order). Locally bun ran gumloop first, so it passed.

Change:
- grok/nocli.mjs: the first noRealGrok of a file snapshots process.env
  and registers an afterAll that puts it back, removing what was added.
- gumloop/regression.test.mjs: node's absolute path is found once with
  Bun.which at load and spawned by path; not found, the Node tests fail
  as before (no skip).
- Siblings the same way (a file-level env change never put back), found
  by a full-run env audit: chat/chat.test.mjs (XDG_CONFIG_HOME pointing
  at its deleted temp dir, MAGPIE_API_KEY/GATEWAY_KEY/ADDR deleted) and
  cursor/calls.test.mjs (XDG_DATA_HOME) now restore them in afterAll.
  window-warmup's fake-gateway.ts/scheduler.test.ts XDG pins are left,
  filed as #996 (fake-gateway is also the --serve demo's).
  Other PATH writers (devin, gcp-ai, grok's own tests, sap-aicore,
  agy-cli, layerfs) already restore theirs; the audit saw PATH change
  only at grok's files.

Ran (magpie-desktop WSL, node only in ~/sdk/node/bin, bun 1.4.2):
- Red first, origin/main: `bun test --randomize --seed=3` (and 5) on
  grok/loop-check + gumloop/regression: the 4 CI failures, same error;
  also with --preload ./packages/grok/nocli.mjs.
- Same seeds with this change: 95 pass 0 fail (new gumloop test plus
  origin/main's copy of it).
- Broken by hand: afterAll(putBack) commented out -> both seeds red
  again, 4 fail.
- Root `HOME=$(mktemp -d) bun test` (with an env-audit preload): 8298
  pass, 19 skip, 0 fail, 8317 tests, 584 files; PATH back to the start
  value at the first file after grok's.
- Touched packages (chat, cursor, grok, gumloop, qoder) after the
  chat/cursor change: 1117 pass 0 fail, each XDG value back to start.

Not tried: ubuntu CI itself before pushing (publish.yml runs it next);
Windows (nocli sets PATH empty there, restored the same way).
2026-11-11 19:53:46 +08:00
..

@magpie-community/page-chat

A chat page in magpie's window. Talk to magpie's own models with your MCP servers, instructions and skills, with images and LaTeX, without starting an agent.

Made by Magic_zero (Magiczerowxy), from Magiczerowxy/magpie-chat (0.1.21). This package is that code, with the changes listed under Changes from the original.

Chat inside magpie's window

Install

From magpie's Plugins › Discover, or:

magpie plugin add @magpie-community/page-chat

It then has a tab, Chat (对话, 對話, チャット), under Plugins in the sidebar.

What it does

  • magpie's models. The list comes from the gateway's /v1/models. Models with reasoning levels get an effort picker. Each model shows its brand icon (OpenAI, Claude, Gemini, DeepSeek, Qwen, Kimi, GLM, MiniMax and more) in the picker and next to its name in the transcript. The icons come from @lobehub/icons (MIT); see chat/icons/models/NOTICE.
  • magpie's library. Tick instructions and skills from ~/.config/magpie/library/ (folded into the system prompt), and MCP servers from library.json (their tools run as real tool_calls, at most 8 rounds, Streamable HTTP and stdio). The switch "使用 magpie 的全部 MCP 服务器" at the top of the MCP list uses every server in the library instead, one added to magpie later too; it is off by default, and turning it off brings back the servers you ticked. magpie's own MCP servers (web search, image recognition, image generation, plugin tools) are in the list beside the library's while they are on in magpie (asked of the gateway's /v1/magpie/mcp, magpie v0.1.2397 and later; an older magpie lists none); one turned off in magpie's Settings is left out, and a library server of the same name, such as an installed magpie-image, is used in its place.
  • EPUB books. Chat reads selectable text in chapter order when you send a message. An EPUB already in the conversation history also works. Each follow-up sends the text again while the attachment is in history, so it counts toward the selected model's input limit each time. Attaching the same file twice sends one copy of the text. Chat does not transcribe images.
  • Images and files. Pick, drop or paste them. Images go to the model as image_url. Replies can carry base64 data-URI images, which render inline and open full size on click. Remote ![alt](https://…) images are shown as a link instead of being loaded — fetching them automatically would let a reply make the page request an arbitrary URL.
  • Streaming. Reasoning unfolds while it arrives, then collapses. While the answer streams, the page follows it down unless you scroll up yourself; scroll back to the bottom and it resumes.
  • Model status. Every reply ends with a line saying what the model is doing: Magpie正在觅食ing… · 2s with a running timer while it generates, green Magpie找到了食物! · 2s when done, red Magpie没有找到食物 on failure. The elapsed time is kept with the conversation.
  • Math. $…$, $$…$$, \(…\) and \[…\] render with a bundled KaTeX 0.16.11. No CDN.
  • Conversations kept, pinned, renamed or deleted, under ~/.config/magpie/magpie-chat/. Clicking "+" starts a draft row in the sidebar; it becomes a real conversation as soon as you send, and disappears if you switch away without writing anything. The pencil button on each row renames it inline.
  • Layout. Conversation width and composer width are adjustable in the sidebar; a Sync switch keeps the two equal — move either one and the other follows.
  • System prompt switch. The text you write under 系统提示词 can be turned off without deleting it; ticked instructions and skills still apply.
  • Looks like magpie. Colors and fonts come from the window's theme.

It registers no provider, asks for no sign-in and stores no credentials of its own. Every request goes out through magpie's gateway, so usage, routing and failover are the same as an agent's.

How it works

A plugin page runs in a sandboxed frame with no network (connect-src 'none'). Its only way out is to navigate itself. So this plugin has two parts:

  1. page/index.html and page/boot.js: a launcher magpie hosts. It reads the window's theme and the port option through _magpie/bridge.js, then sends its frame to http://127.0.0.1:<port>/. It makes no request of its own.
  2. index.mjs: an OpenCode v1 plugin (export default {id, server}). When magpie's plugin host calls server(), it starts a local service on 127.0.0.1:3477 (the port option). lib/server.mjs serves the chat UI in chat/ and /api/*, and forwards chat to magpie's gateway.

What the service reads and sends

  • From magpie's config folder ($XDG_CONFIG_HOME/magpie or ~/.config/magpie): caller-keys.json (the first gateway key, sent as Authorization: Bearer to the gateway, so the chat's usage is counted on that key), providers.json and routing.json (icons), settings.json (fonts, and the gateway port when the build writes one there), library.json and library/ (MCP servers, instructions, skills).
  • To magpie's gateway: MAGPIE_CHAT_GATEWAY if set, else MAGPIE_ADDR, else the port from magpie's settings.json (the portable build writes its real port there, e.g. 18086), else http://127.0.0.1:3425. The key goes there, so set MAGPIE_CHAT_GATEWAY only to a gateway you trust.
  • To your MCP servers: what the model asks their tools, with the headers you configured for them. A stdio server's command is run as you configured it. magpie's own MCP servers are on the gateway, and get the gateway key.

Who can use the service

Only the chat page it served:

  • Every /api/ route needs x-magpie-chat-token, a random token made each time the service starts. The service writes it into the chat page's HTML, which it sends without CORS headers, so another page can't read it. /api/ping, /api/fonts.css and /api/icon/* are open; they give nothing secret.
  • Host must be 127.0.0.1:<port> or localhost:<port>, so a DNS-rebound page is turned away.
  • Origin must be null (the sandboxed frame) or the service's own.

Options

{ "port": 3477 }

The launcher and the service both read it. Change it if something else holds 3477.

When magpie swaps plugin hosts (a plugin updated, installed or set) while the old host is still finishing a call, the old host's service keeps the port until that call ends. The new host's service waits for it, trying again every second, and takes the port once it is free. The open page's next request then gets a new token and the page reloads itself.

Starting it without magpie's host

serve.mjs (node serve.mjs, or start-server.cmd / start-server.vbs on Windows) starts the same service on its own, and install-autostart.cmd puts it in Windows' Startup folder. See SERVE.md. None of these runs unless you start it.

Changes from the original

  • The service answered Origin: null and requests with no Origin, and didn't check Host. Any website's sandboxed iframe sends Origin: null, so it could chat on your gateway key, read and change conversations and settings, and drive your MCP tools. A DNS-rebound page could read conversations. The token and the Host check above close it.
  • The service started when index.mjs was imported, on 3477 whatever the port option said, while the launcher went to the option's port. It now starts when the host calls server(), on the option's port.
  • A remote provider icon answered 302 with no Location. It has one.
  • /api/bootstrap said version 0.1.0 whatever the version. It says the package's.

Known limits

  • The page opens the service on this computer's 127.0.0.1, so magpie web used from another machine won't reach it.
  • MCP has no legacy GET SSE stream and no reconnect.
  • Images go inline as base64, at most 24MB each.
  • Built-in provider icons live inside magpie's binary; when one can't be read, the service draws a letter badge.

Test

bun test packages/chat

The test starts the service on a free port against a fake gateway, in a temporary config folder.

License

MIT, © 2026 Magiczerowxy. See LICENSE.


中文:Magic_zero(Magiczerowxy)做的「对话」页面,来自 Magiczerowxy/magpie-chat。装好后侧栏「插件」里点「对话」,就能用 magpie 自己的模型聊天,带上你的 MCP 服务器、指令和技能,支持图片与 LaTeX。它不注册供应商、不保存凭据,请求都经 magpie 网关发出,用的是 caller-keys.json 里第一把网关 key。本地服务只听 127.0.0.1,每个 /api/ 请求都要带上服务写进对话页里的口令,并检查 Host,别的网页用不了它。