Adds packages/window-warmup (@magpie-community/page-window-warmup 0.1.0), by YangHonghang: a page plugin whose host part runs a service on 127.0.0.1:3492 and, on a schedule (after a quota window resets, daily at a set time, or every N hours), sends "hi" with max_tokens 16 through magpie's gateway to a provider/account/model the user picks. The registry entry moves from the author's own npm package magpie-window-warmup to this one. The package README opens with the zh/en warning that sends spend real quota and that some vendors (Claude subscriptions especially) may treat scheduled requests as unusual use. Reviewed at 07a0b217adb2a111f839c984cbc955c5bb45b68d: - Outside packages/window-warmup only README.md and registry.json change; no workflow and no other package. - The service binds 127.0.0.1, checks Host (DNS rebinding) and Origin (null or itself), needs a per-process 32-byte token on /api/*, and serves the index with a nonce CSP. - It reaches only MAGPIE_ADDR (default 127.0.0.1:3425). providers.json is read for sha256 key fingerprints only; no spawn, eval or outside hosts. - A window task sends at most once per resetsAt (or once per hour when idle); daily/every tasks catch up only the latest missed point, once. Run on mote (bun 1.4.2): - HOME=$(mktemp -d) bun test at the repo root: 5142 pass, 15 skip, 0 fail. - scripts/check.mjs ok. - packages/window-warmup bun test: 242 pass (dist.test rebuilds dist byte for byte). - browser.test.ts with Playwright 1.62.0: chromium and webkit pass. Bun ignores NODE_PATH, so it needs node_modules/playwright linked and PLAYWRIGHT_BROWSERS_PATH set under a temp HOME; without them it skips. Not tried: a real send through a live magpie gateway, and tsc --noEmit (no typescript on mote).
38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
// 构建脚本:Bun.build 两次 + 复制静态页。
|
||
// - src/plugin.ts → dist/plugin.js(target bun,宿主加载入口)
|
||
// - web/app.ts → dist/ui/app.js(target browser,界面逻辑)
|
||
// - web/index.html、web/style.css → dist/ui/(服务从 dist/ui 提供静态资源)
|
||
import { cp, mkdir, rm } from "node:fs/promises";
|
||
import { resolve } from "node:path";
|
||
|
||
/** 从包根构建全部产物;默认写回 dist/,测试用 outDir 构建到临时目录做一致性比对 */
|
||
export async function buildAll(
|
||
root: string = resolve(import.meta.dir, ".."),
|
||
outDir: string = resolve(root, "dist"),
|
||
): Promise<void> {
|
||
const dist = resolve(outDir);
|
||
await rm(dist, { recursive: true, force: true });
|
||
await mkdir(resolve(dist, "ui"), { recursive: true });
|
||
// Bun 产物里的源文件注释相对当前工作目录:固定以包根为 cwd,从仓库根或别处调用都得到同一份输出
|
||
const prev = process.cwd();
|
||
process.chdir(resolve(root));
|
||
try {
|
||
await Bun.build({
|
||
entrypoints: [resolve(root, "src/plugin.ts")],
|
||
outdir: dist,
|
||
target: "bun",
|
||
});
|
||
await Bun.build({
|
||
entrypoints: [resolve(root, "web/app.ts")],
|
||
outdir: resolve(dist, "ui"),
|
||
target: "browser",
|
||
});
|
||
} finally {
|
||
process.chdir(prev);
|
||
}
|
||
await cp(resolve(root, "web/index.html"), resolve(dist, "ui/index.html"));
|
||
await cp(resolve(root, "web/style.css"), resolve(dist, "ui/style.css"));
|
||
}
|
||
|
||
if (import.meta.main) await buildAll();
|