page-chat 0.1.0: Magic_zero's chat page, with tests, a registry entry and check.mjs for a page's host part
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>
This commit is contained in:
+8
-1
@@ -22,8 +22,15 @@ for (const name of readdirSync(root)) {
|
||||
const problems = []
|
||||
try {
|
||||
const mod = await import(pathToFileURL(join(dir, pkg.main ?? "index.mjs")).href)
|
||||
// as magpie's host takes them: every exported function, and the
|
||||
// OpenCode v1 form, a default export of { id, server }
|
||||
const fns = Object.values(mod).filter((v) => typeof v === "function")
|
||||
if (!fns.length) problems.push("exports no plugin function")
|
||||
const v1 = typeof mod.default?.server === "function" ? mod.default.server : null
|
||||
if (!fns.length && !v1) problems.push("exports no plugin function")
|
||||
// a page's v1 server is its host part, a local service the page
|
||||
// navigates to: no provider, no tools. It isn't started here (it would
|
||||
// take a port and write config); the package's own tests start it.
|
||||
if (v1 && !pkg.magpie?.page) fns.push(v1)
|
||||
const client = { app: { log: async () => {} }, auth: { set: async () => {} }, tui: { showToast: async () => {} }, config: { get: async () => ({ data: {} }) } }
|
||||
for (const fn of fns) {
|
||||
const hooks = await fn({ client, directory: process.cwd(), worktree: process.cwd(), $: undefined, project: {} })
|
||||
|
||||
Reference in New Issue
Block a user