Files
plugins/packages
yetone f2b0dacdb7 workbuddy 0.1.42: a chat is parsed once on its way, and goes as it came when nothing changed (#461)
jihuayu measured a 45 MiB chat going through 0.1.41's fetch: each step
(withSystem, fitted, normalizeToolChoice, attend, the model, systemKey)
parsed the whole body again, 6 parses a request, and normalizeToolChoice
wrote it out whole even for an unchanged "auto". Bun's RSS reached 618-751
MiB for 4 serial requests where passing the body through took 270.

prepared parses a request once. Each step makes its own change to that one
object, in the same order (systemOn, fitTools, toolChoiceOn; unsignedOn
for Messages). attend, the model and the system key read the same object,
and a refused system prompt moves on it (systemAsUserOn). The body is
written out once, only when a step changed it. The parsed chat is let go
before the request is sent. A body a step throws on goes through the steps
one by one, as before. The string-level helpers stay as wrappers.

What was run, on this tree:
- mote, the reporter's benchmark (no network, fetch stubbed, 4 x 45.3 MiB,
  peak RSS sampled every 5ms): 0.1.41 7 parses/request, 1087.5 MiB parsed,
  peak RSS 1096 / 979 MiB. This change: 2 parses/request (the request and
  the stub's SSE reply), 181.3 MiB parsed, peak 682 / 680 MiB. The bodies
  sent have the same SHA-256 in both.
- HOME=$(mktemp -d) bun test packages/workbuddy on mote: 189 pass, 0 fail.
  bun scripts/check.mjs workbuddy: ok.
- oneparse.test.mjs (new): 17 chat shapes, invalid JSON and bytes come out
  the same as the steps one by one made them, with the same tool names; an
  unchanged chat goes byte for byte; the loader parses a 2 MiB chat once.
  Broken by hand: every request sent through the step-by-step fallback,
  the loader test FAILs (5 parses, want 1). An unchanged "auto" counted as
  a change, the byte-for-byte test FAILs.
- Real account (WorkBuddy AI, free-only on, sandbox HOME, this Mac):
  deepseek-v4.1-flash, a 373-byte chat and a 205,595-byte chat with a
  developer message, max_completion_tokens and a dotted tool name, through
  0.1.41 and this change: 200 "OK" on all four; no sign-in refreshed.

npm has 0.1.41, so 0.1.42 is free.

Reported-by: jihuayu
2026-10-28 18:46:03 +08:00
..
middleware: param-override, model-map, system-prompt, word-guard and think-tags — gateway middleware that magpie runs on every agent's requests and replies, mostly New API's channel settings with the same JSON (the owner) — magpie can now run a plugin as gateway middleware (onRequest, onEvent, onResponse, in-process on moejs), and these are the first ones: param-override is New API's param_override (both forms, operations with gjson paths and conditions, return_error); model-map is model_mapping (chains, /regex/ keys with $1) and puts the asked-for name back into replies; system-prompt adds a prompt in each API's own place, keeping an agent's own unless override (New API's semantics), by agent or model; word-guard is the sensitive-word filter (reject or mask the user's text, optionally replies); think-tags strips a leading <think>…</think> from replies across stream chunks, or puts Chat reasoning_content into the text (thinking_to_content). Each is one file with no imports, named @magpie-community/middleware-<name>, with magpie.options as the example the app's editor starts from; registry.json lists them with "kind": "middleware" and no providers; check.mjs skips middleware-only packages. scripts/middleware.mjs calls the hooks as the gateway does (events split, [DONE] passed by) and runs each package's cases.json. Tested with a real DeepSeek account and real Claude Code through magpie's gateway: a mapped model named back in message_start, max_tokens capped, a system prompt appended for claude only, a word turned away as a 400 in Anthropic's shape, return_error as a 403 in Chat's, <think> stripped from Chat and Responses streams and an Anthropic whole reply, reasoning_content moved into the text. bun test (61 for these five) and bun scripts/check.mjs pass; packages/devin's two image tests fail on this machine only, as on main. Their first npm version has to be published by hand (trusted publishing can't create a package); until then magpie shows them as Coming soon.
2026-10-05 20:49:42 +08:00
middleware: param-override, model-map, system-prompt, word-guard and think-tags — gateway middleware that magpie runs on every agent's requests and replies, mostly New API's channel settings with the same JSON (the owner) — magpie can now run a plugin as gateway middleware (onRequest, onEvent, onResponse, in-process on moejs), and these are the first ones: param-override is New API's param_override (both forms, operations with gjson paths and conditions, return_error); model-map is model_mapping (chains, /regex/ keys with $1) and puts the asked-for name back into replies; system-prompt adds a prompt in each API's own place, keeping an agent's own unless override (New API's semantics), by agent or model; word-guard is the sensitive-word filter (reject or mask the user's text, optionally replies); think-tags strips a leading <think>…</think> from replies across stream chunks, or puts Chat reasoning_content into the text (thinking_to_content). Each is one file with no imports, named @magpie-community/middleware-<name>, with magpie.options as the example the app's editor starts from; registry.json lists them with "kind": "middleware" and no providers; check.mjs skips middleware-only packages. scripts/middleware.mjs calls the hooks as the gateway does (events split, [DONE] passed by) and runs each package's cases.json. Tested with a real DeepSeek account and real Claude Code through magpie's gateway: a mapped model named back in message_start, max_tokens capped, a system prompt appended for claude only, a word turned away as a 400 in Anthropic's shape, return_error as a 403 in Chat's, <think> stripped from Chat and Responses streams and an Anthropic whole reply, reasoning_content moved into the text. bun test (61 for these five) and bun scripts/check.mjs pass; packages/devin's two image tests fail on this machine only, as on main. Their first npm version has to be published by hand (trusted publishing can't create a package); until then magpie shows them as Coming soon.
2026-10-05 20:49:42 +08:00