history-trim 0.1.0: a middleware that trims repeated and oversized history (#423)
A new middleware package, @magpie-community/middleware-history-trim 0.1.0,
ported from OmniRoute's lite engine (MIT). It makes a request's history
smaller in four steps:
- folds runs of blank lines;
- drops a system prompt whose whole text repeats an earlier one;
- drops a message equal in every field to the one before it (tool results
excepted);
- cuts a history tool result over maxToolLength at a word boundary.
None of the steps touch the turn being sent (after the last assistant), and
a request with no assistant goes on unchanged. The README states the
prompt-cache cost.
Reviewed at 8af038a60201728f00ee350f56eb35228049baa3, merged locally with
main b2fe48e:
- bun test packages/history-trim: 21 pass.
- On the Mac mini, sandbox HOME under TMPDIR: bun scripts/check.mjs ok; full
bun test 2919 pass, 8 skip, 0 fail.
- Broken by hand, each turning cases.json red:
- the current-turn guard in dropRepeatedSystemPrompts;
- the current-turn guard in dropRepeatedMessages;
- a 200-char system key;
- a content-only compare;
- folding the current turn;
- the surrogate guard;
- turnStart returning length with no assistant;
- the cut's turn guard.
- Probes against the earlier review findings, each now as expected:
- two system prompts under a shared header both kept;
- tool_calls assistants that differ both kept;
- alice and bob kept apart;
- a patch with trailing spaces left whole;
- emoji and astral CJK cuts well-formed;
- the current turn's Anthropic tool_result left whole.
- npm and the dist index have no history-trim package yet, so 0.1.0 is free.
Not run: GitHub CI. The fork's pr workflow is waiting for approval
(action_required); the Mac mini run above stands in for it. No real
upstream request was sent through the middleware.
This commit is contained in:
@@ -51,6 +51,7 @@ These packages aren't OpenCode plugins. magpie runs them in its gateway, on the
|
||||
| [think-tags](packages/think-tags) | Take `<think>…</think>` out of a reply's text, or put a Chat reply's `reasoning_content` into it (`thinking_to_content`) |
|
||||
| [antigravity-cloak](packages/antigravity-cloak) | Claude Code and Claude Desktop on Antigravity: break the words Antigravity turns their system prompt away for, in what Antigravity alone is sent |
|
||||
| [codex-history](packages/codex-history) | Opt-in Responses history compatibility after switching providers: remove historical ciphertext and optional item IDs while preserving readable content and tool-call pairing |
|
||||
| [history-trim](packages/history-trim) | Send a request's history smaller: fold a run of blank lines, drop a system prompt written twice and a message repeated right after itself, and cut a past tool result longer than `maxToolLength` at a word boundary |
|
||||
|
||||
```sh
|
||||
magpie plugin add @magpie-community/middleware-<name>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 diegosouzapw, OmniRoute contributors
|
||||
(the lite engine this middleware is ported from: https://github.com/cheaper-inference/OmniRoute)
|
||||
Copyright (c) 2026 manjughosa
|
||||
(the magpie gateway middleware port)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"source": "https://github.com/cheaper-inference/OmniRoute",
|
||||
"commit": "1ac00b05e2d507d416a3e9c4c278ab625ce1dbf2",
|
||||
"version": "v3.8.53",
|
||||
"license": "MIT",
|
||||
"files": {
|
||||
"open-sse/services/compression/lite.ts": {
|
||||
"sha256": "0e857ed68a700e8000fa20cb7e3adddaf40c126149fe119024b4e4a2a8c317fd"
|
||||
}
|
||||
},
|
||||
"changes": [
|
||||
"Inlined the engine into one import-free middleware file that exports only onRequest.",
|
||||
"Reads body.messages only. The protocol adapter that walks Chat, Anthropic, Responses and Gemini bodies is not ported, so a request without a messages array goes on unchanged instead of being rewritten segment by segment.",
|
||||
"Dropped replaceImageUrls: which models take images is provider configuration, and its placeholders would only fire for some of them.",
|
||||
"Dropped createCompressionStats and the telemetry that goes with it.",
|
||||
"The four steps, their order, the word-boundary lookback of 80 characters and the [truncated] suffix are the engine's own. Four places differ on purpose, each because the engine's version drops or rewrites something the request needed:",
|
||||
"A repeated system prompt is dropped only when its whole trimmed text is equal. The engine compares the first 200 trimmed characters, so a second system prompt that shares an opening — two rule sets, two agents — is dropped and the model never reads it.",
|
||||
"A repeated message is dropped only when every field is equal, tool_calls and name included. The engine compares the content alone, so a second assistant message carrying different tool calls is dropped and the tool result answering it is left with no call, which an OpenAI-compatible upstream refuses with a 400.",
|
||||
"All four steps leave the turn being sent alone — every message after the last assistant one. The engine skips that turn in the tool-result cut only, so its whitespace step rewrites a patch line, a Markdown hard line break or a trailing tab in the message about to go out. A history with no assistant message in it has no past the model has read: there this package touches nothing, while the engine treats every message as history to fold, dedupe and cut.",
|
||||
"A cut steps back one unit when it lands between a high and a low surrogate. The engine's word-boundary back-off finds no space in emoji or CJK text, so it cuts a surrogate pair in half.",
|
||||
"Options are read from ctx.options instead of a module-level configuration: maxToolLength, compressToolResults and preserveSystemPrompt."
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
# @magpie-community/middleware-history-trim
|
||||
|
||||
A request's history, sent smaller, as [magpie](https://usemagpie.ai) gateway middleware. It folds a run of blank lines, drops a system prompt written twice and a message repeated right after itself, and cuts a past tool result longer than `maxToolLength` at a word boundary.
|
||||
|
||||
Install it from magpie's **Plugins › Discover**, or with `magpie plugin add @magpie-community/middleware-history-trim`. Set its options under **Plugins › Installed › Options**, or with `magpie plugin options history-trim '<json>'`.
|
||||
|
||||
## Options
|
||||
|
||||
```json
|
||||
{ "maxToolLength": 2000 }
|
||||
```
|
||||
|
||||
**`maxToolLength`** (the default, 2000). A tool result from an earlier turn longer than this many characters is cut to it, at the nearest word boundary within 80 characters, and ends with `\n...[truncated]`. A cut never splits an emoji or another surrogate pair in half.
|
||||
|
||||
- The turn being sent now is never cut, and never rewritten by any of the four steps. A message at or after the last assistant message is the history the model has not read yet, so it goes out whole — a patch line, a Markdown hard line break or a trailing tab in it survives; a history with no assistant message in it is left whole too.
|
||||
- Both shapes are cut: a Chat `role: "tool"` message whose content is a string, and an Anthropic `tool_result` block inside a content array, whether its content is a string or an array of text parts.
|
||||
- A number below 256 or above 1000000 is not a length anyone means, and falls back to the default.
|
||||
|
||||
**`compressToolResults: false`**. Leaves every tool result whole. The other three steps still run.
|
||||
|
||||
**`preserveSystemPrompt: true`**. Keeps system messages out of all four steps: not folded, not deduplicated, not dropped as a repeat.
|
||||
|
||||
Nothing sent once is dropped. Apart from the tool-result cut, every step removes only what is there twice: a second system message with the same text, and a message equal to the one before it in every field — role, content, `tool_calls`, `name` — neither of them a tool result.
|
||||
|
||||
**Prompt cache.** Dropping a message or folding whitespace changes the prefix of the request, and a provider caches on that prefix: the request after each change, and every turn of a conversation whose history keeps changing, is billed as uncached input. On a long history read back many times that is a fraction of what the steps save; on a short history that would have been a cache hit every turn it can cost more than it saves.
|
||||
|
||||
Only `body.messages` is read, so it acts on a Chat or an Anthropic request. A Responses or a Gemini request carries its history elsewhere and goes on unchanged; so does a request whose body it cannot read, because an exception here would take the request down with it.
|
||||
|
||||
Ported from OmniRoute's lite engine (`open-sse/services/compression/lite.ts`, MIT); what was left out, and the four places this one deliberately differs, are listed in `PROVENANCE.json`.
|
||||
|
||||
中文:把请求的历史发得更小——连续空行折叠成一行空行、逐字重复的 system 提示与紧挨着重复的消息去掉、历史中超过 `maxToolLength` 的工具结果在词边界处截断并标上 `[truncated]`。正在发送的这一轮(最后一条 assistant 之后的消息)四步都不碰:补丁行、Markdown 硬换行、行尾空白原样发出;整段没有 assistant 的首轮请求同样原样发出。判"重复"比的是整条消息不是内容——system 要整段文本相同,其它消息要每个字段(`tool_calls`、`name` 都算)都相同。只读 `body.messages`,Chat 与 Anthropic 请求生效;`compressToolResults: false` 不截断工具结果,`preserveSystemPrompt: true` 让 system 消息不被任何一步改动。prompt cache 的账:删一条消息或折叠空白都会改掉请求前缀,提供方按前缀缓存,改动后的那次请求、以及历史一直在变的后续轮次,输入按未缓存价计费——历史长且反复回读时这笔开销只占省下的一小部分,历史短且本来每轮都命中缓存时可能得不偿失。
|
||||
@@ -0,0 +1,782 @@
|
||||
[
|
||||
{
|
||||
"name": "blank-line runs in the history folded, trailing spaces and tabs gone",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "a\n\n\n\nb\n \t "
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "a\n\nb\n"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a first request with no assistant message goes out whole",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "a\n\n\n\nb\n \t "
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "text already folded passes untouched",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "a\n\nb"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "content that isn't a string is left as it is",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "a\n\n\n\nb\n "
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "the turn being sent keeps its whitespace, the history before it is folded",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "old\n\n\n\nx"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "apply this patch:\n+foo \n+bar\t\n\n\n\nend"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "old\n\nx"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "apply this patch:\n+foo \n+bar\t\n\n\n\nend"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a system prompt written twice goes once",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are X."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "hi"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are X."
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are X."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "hi"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a second system prompt whose opening matches is kept when the rest differs",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. Rule set A: never push."
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. You are a coding agent. Rule set B: always run tests."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "hi"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "the turn being sent keeps a system prompt the history already has",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a coding agent."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a coding agent."
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a coding agent."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a coding agent."
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "preserveSystemPrompt keeps every system message, folded or repeated",
|
||||
"options": {
|
||||
"preserveSystemPrompt": true
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are X."
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are X."
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "hi"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a long past tool result is cut at a word boundary",
|
||||
"options": {
|
||||
"maxToolLength": 256
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"content": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"content": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha\n...[truncated]"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "the turn being sent is never cut",
|
||||
"options": {
|
||||
"maxToolLength": 256
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"content": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "compressToolResults false leaves the history whole",
|
||||
"options": {
|
||||
"maxToolLength": 256,
|
||||
"compressToolResults": false
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"content": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "an Anthropic tool_result block is cut inside",
|
||||
"options": {
|
||||
"maxToolLength": 256
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "reading"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "tool_result",
|
||||
"tool_use_id": "t",
|
||||
"content": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "reading"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "tool_result",
|
||||
"tool_use_id": "t",
|
||||
"content": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha\n...[truncated]"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "text parts inside a tool_result are cut too",
|
||||
"options": {
|
||||
"maxToolLength": 256
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "tool_result",
|
||||
"tool_use_id": "t",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "tool_result",
|
||||
"tool_use_id": "t",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha\n...[truncated]"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a cut never splits a surrogate pair",
|
||||
"options": {
|
||||
"maxToolLength": 257
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀\n...[truncated]"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a message repeated right after itself goes",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "same"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "same"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "same"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "two identical messages in the turn being sent are both kept",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "hello"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "hi"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "continue"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "continue"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expect_request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "hello"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "hi"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "continue"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "continue"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "two assistant messages that differ only in their tool calls are both kept",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "a",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "f",
|
||||
"arguments": "{}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "b",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "f",
|
||||
"arguments": "{}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"tool_call_id": "a",
|
||||
"content": "ra"
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"tool_call_id": "b",
|
||||
"content": "rb"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "two user messages that differ only in their name are both kept",
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"name": "alice",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"name": "bob",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "ok"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "next"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a maxToolLength below the floor falls back to 2000",
|
||||
"options": {
|
||||
"maxToolLength": 100
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "go"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "reading"
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"content": "alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha alpha"
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "done"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a request without a messages array goes on unchanged",
|
||||
"ctx": {
|
||||
"protocol": "responses"
|
||||
},
|
||||
"request": {
|
||||
"model": "m",
|
||||
"input": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "input_text",
|
||||
"text": "a\n\n\n\nb"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,267 @@
|
||||
// A request's history, sent smaller: a run of blank lines folded, a system
|
||||
// prompt repeated word for word dropped, a past tool result longer than
|
||||
// maxToolLength cut at a word boundary, and a message repeated right after
|
||||
// itself dropped. OmniRoute's lite engine, as magpie gateway middleware.
|
||||
//
|
||||
// {"maxToolLength": 2000} (the default)
|
||||
// {"compressToolResults": false} leave every tool result whole
|
||||
// {"preserveSystemPrompt": true} keep system messages out of all four steps
|
||||
//
|
||||
// Only body.messages is read, so a Chat or an Anthropic request; a request
|
||||
// without one (Responses, Gemini) goes on unchanged.
|
||||
//
|
||||
// The turn being sent now — every message after the last assistant one — is
|
||||
// left alone by all four steps. It is the history the model has not read yet,
|
||||
// and a patch, a Markdown hard break or a trailing tab in it means something.
|
||||
// The tool-result cut is the one step that loses words, and it works on the
|
||||
// history only. The other three drop only what is there twice: a system
|
||||
// message with the same trimmed text, and a message equal to the one before it
|
||||
// in every field, tool_calls and name included.
|
||||
//
|
||||
// 移植自 OmniRoute 的 lite 引擎(open-sse/services/compression/lite.ts),
|
||||
// 四步的顺序、阈值与边界回退逐条对应;四处与它不同,见 PROVENANCE.json。
|
||||
|
||||
const DEFAULT_MAX_TOOL_LENGTH = 2000
|
||||
const MIN_MAX_TOOL_LENGTH = 256
|
||||
const MAX_MAX_TOOL_LENGTH = 1000000
|
||||
const TOOL_TRUNCATION_LOOKBACK = 80
|
||||
const TRUNCATION_SUFFIX = "\n...[truncated]"
|
||||
|
||||
export function onRequest(body, ctx) {
|
||||
if (!body || typeof body !== "object") return
|
||||
const messages = body.messages
|
||||
if (!Array.isArray(messages) || messages.length === 0) return
|
||||
const o = (ctx && ctx.options) || {}
|
||||
const preserveSystemPrompt = o.preserveSystemPrompt === true
|
||||
|
||||
let next = foldWhitespace(messages, preserveSystemPrompt)
|
||||
next = dropRepeatedSystemPrompts(next, preserveSystemPrompt)
|
||||
if (o.compressToolResults !== false) next = cutToolResults(next, resolveMaxToolLength(o.maxToolLength))
|
||||
next = dropRepeatedMessages(next, preserveSystemPrompt)
|
||||
|
||||
if (next === messages) return
|
||||
return { ...body, messages: next }
|
||||
}
|
||||
|
||||
// The turn being sent starts after the last assistant message: findLastIndex,
|
||||
// written out. A history with no assistant message has no past at all — every
|
||||
// message in it is the turn being sent, and none of the four steps touch it.
|
||||
function turnStart(messages) {
|
||||
for (let i = messages.length - 1; i >= 0; i--) {
|
||||
if (messages[i] && messages[i].role === "assistant") return i + 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 1. whitespace: a run of three or more newlines becomes one blank line, and
|
||||
// trailing spaces and tabs on a line go. Words are untouched.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function foldText(text) {
|
||||
return text.replace(/\n{3,}/g, "\n\n").replace(/[ \t]+$/gm, "")
|
||||
}
|
||||
|
||||
function foldWhitespace(messages, preserveSystemPrompt) {
|
||||
const start = turnStart(messages)
|
||||
let changed = false
|
||||
const out = messages.map((msg, index) => {
|
||||
if (index >= start) return msg
|
||||
if (!msg || typeof msg !== "object") return msg
|
||||
if (preserveSystemPrompt && msg.role === "system") return msg
|
||||
if (typeof msg.content !== "string") return msg
|
||||
const folded = foldText(msg.content)
|
||||
if (folded === msg.content) return msg
|
||||
changed = true
|
||||
return { ...msg, content: folded }
|
||||
})
|
||||
return changed ? out : messages
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 2. system: a second system message with the same trimmed text is the same
|
||||
// prompt again, and goes. Two prompts that share an opening are two prompts.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function dropRepeatedSystemPrompts(messages, preserveSystemPrompt) {
|
||||
if (preserveSystemPrompt) return messages
|
||||
const start = turnStart(messages)
|
||||
const seen = new Set()
|
||||
let changed = false
|
||||
const out = messages.filter((msg, index) => {
|
||||
if (index >= start) return true
|
||||
if (!msg || msg.role !== "system" || typeof msg.content !== "string") return true
|
||||
const text = msg.content.trim()
|
||||
if (seen.has(text)) {
|
||||
changed = true
|
||||
return false
|
||||
}
|
||||
seen.add(text)
|
||||
return true
|
||||
})
|
||||
return changed ? out : messages
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 3. tool results: a past result longer than maxToolLength is cut, backing off
|
||||
// to the nearest space within 80 characters and marking the cut.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isWordChar(char) {
|
||||
return char !== undefined && /\S/.test(char)
|
||||
}
|
||||
|
||||
function findWhitespaceBackward(content, cutIndex) {
|
||||
const windowStart = Math.max(0, cutIndex - TOOL_TRUNCATION_LOOKBACK)
|
||||
for (let i = cutIndex; i > windowStart; i--) {
|
||||
if (!isWordChar(content[i - 1])) return i - 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function findWhitespaceForward(content, cutIndex) {
|
||||
const windowEnd = Math.min(content.length, cutIndex + TOOL_TRUNCATION_LOOKBACK)
|
||||
for (let i = cutIndex; i < windowEnd; i++) {
|
||||
if (!isWordChar(content[i])) return i
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function backOffToWordBoundary(content, cutIndex) {
|
||||
const onWordBoundary = !isWordChar(content[cutIndex - 1]) || !isWordChar(content[cutIndex])
|
||||
if (onWordBoundary) return cutIndex
|
||||
const backward = findWhitespaceBackward(content, cutIndex)
|
||||
if (backward !== -1) return backward
|
||||
const forward = findWhitespaceForward(content, cutIndex)
|
||||
if (forward !== -1) return forward
|
||||
return cutIndex
|
||||
}
|
||||
|
||||
// A cut between a high and a low surrogate pair leaves half a character, which
|
||||
// is neither a word boundary nor valid text: emoji and CJK never offer a space
|
||||
// to back off to. Step back one unit instead.
|
||||
function isHighSurrogate(code) {
|
||||
return code >= 0xd800 && code <= 0xdbff
|
||||
}
|
||||
|
||||
function isLowSurrogate(code) {
|
||||
return code >= 0xdc00 && code <= 0xdfff
|
||||
}
|
||||
|
||||
function avoidSplitSurrogate(text, cutIndex) {
|
||||
if (cutIndex <= 0 || cutIndex >= text.length) return cutIndex
|
||||
return isHighSurrogate(text.charCodeAt(cutIndex - 1)) && isLowSurrogate(text.charCodeAt(cutIndex))
|
||||
? cutIndex - 1
|
||||
: cutIndex
|
||||
}
|
||||
|
||||
function cutText(text, maxLength) {
|
||||
const cutIndex = avoidSplitSurrogate(text, backOffToWordBoundary(text, maxLength))
|
||||
return text.slice(0, cutIndex) + TRUNCATION_SUFFIX
|
||||
}
|
||||
|
||||
function cutToolResultBlocks(msg, maxLength) {
|
||||
if (msg.role !== "user" || !Array.isArray(msg.content)) {
|
||||
return { message: msg, changed: false }
|
||||
}
|
||||
let changed = false
|
||||
const content = msg.content.map((block) => {
|
||||
if (!block || typeof block !== "object" || block.type !== "tool_result") return block
|
||||
const inner = block.content
|
||||
if (typeof inner === "string") {
|
||||
if (inner.length <= maxLength) return block
|
||||
changed = true
|
||||
return { ...block, content: cutText(inner, maxLength) }
|
||||
}
|
||||
if (Array.isArray(inner)) {
|
||||
let innerChanged = false
|
||||
const nextInner = inner.map((part) => {
|
||||
if (!part || typeof part !== "object" || part.type !== "text") return part
|
||||
if (typeof part.text !== "string" || part.text.length <= maxLength) return part
|
||||
innerChanged = true
|
||||
return { ...part, text: cutText(part.text, maxLength) }
|
||||
})
|
||||
if (innerChanged) {
|
||||
changed = true
|
||||
return { ...block, content: nextInner }
|
||||
}
|
||||
return block
|
||||
}
|
||||
return block
|
||||
})
|
||||
if (changed) return { message: { ...msg, content }, changed: true }
|
||||
return { message: msg, changed: false }
|
||||
}
|
||||
|
||||
function resolveMaxToolLength(value) {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_MAX_TOOL_LENGTH
|
||||
const n = Math.floor(value)
|
||||
if (n < MIN_MAX_TOOL_LENGTH || n > MAX_MAX_TOOL_LENGTH) return DEFAULT_MAX_TOOL_LENGTH
|
||||
return n
|
||||
}
|
||||
|
||||
function cutToolResults(messages, maxLength) {
|
||||
const currentTurnStart = turnStart(messages)
|
||||
let changed = false
|
||||
const out = messages.map((msg, index) => {
|
||||
if (index >= currentTurnStart) return msg
|
||||
if (!msg || typeof msg !== "object") return msg
|
||||
if (msg.role === "tool" && typeof msg.content === "string") {
|
||||
if (msg.content.length <= maxLength) return msg
|
||||
changed = true
|
||||
return { ...msg, content: cutText(msg.content, maxLength) }
|
||||
}
|
||||
const r = cutToolResultBlocks(msg, maxLength)
|
||||
if (r.changed) changed = true
|
||||
return r.message
|
||||
})
|
||||
return changed ? out : messages
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 4. a message equal to the one before it — same role, and every other field
|
||||
// the same too — says nothing new and goes. Comparing the content alone
|
||||
// would merge two different tool calls, or two speakers with one line.
|
||||
// Tool results are left alone.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Every field counts, and key order does not: JSON.stringify alone would call
|
||||
// the same message different because a body wrote its keys in another order.
|
||||
function canonical(value) {
|
||||
if (Array.isArray(value)) return "[" + value.map(canonical).join(",") + "]"
|
||||
if (value && typeof value === "object") {
|
||||
return "{" + Object.keys(value).sort().map((k) => JSON.stringify(k) + ":" + canonical(value[k])).join(",") + "}"
|
||||
}
|
||||
return JSON.stringify(value) ?? "null"
|
||||
}
|
||||
|
||||
function dropRepeatedMessages(messages, preserveSystemPrompt) {
|
||||
const start = turnStart(messages)
|
||||
let changed = false
|
||||
const out = []
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
const msg = messages[i]
|
||||
if (!msg || typeof msg !== "object") {
|
||||
out.push(msg)
|
||||
continue
|
||||
}
|
||||
if (i >= start || (preserveSystemPrompt && msg.role === "system")) {
|
||||
out.push(msg)
|
||||
continue
|
||||
}
|
||||
const previous = i > 0 ? messages[i - 1] : undefined
|
||||
if (
|
||||
i > 0 &&
|
||||
msg.role !== "tool" &&
|
||||
previous &&
|
||||
typeof previous === "object" &&
|
||||
previous.role === msg.role &&
|
||||
canonical(previous) === canonical(msg)
|
||||
) {
|
||||
changed = true
|
||||
continue
|
||||
}
|
||||
out.push(msg)
|
||||
}
|
||||
return changed ? out : messages
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import * as mod from "./history-trim.middleware.js"
|
||||
import { check } from "../../scripts/middleware.mjs"
|
||||
|
||||
check(import.meta.dir, mod)
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@magpie-community/middleware-history-trim",
|
||||
"version": "0.1.0",
|
||||
"description": "Send a request's history smaller: blank-line runs folded, a system prompt written twice and a message repeated right after itself dropped, a past tool result longer than maxToolLength cut, as magpie gateway middleware",
|
||||
"type": "module",
|
||||
"files": ["history-trim.middleware.js", "README.md", "LICENSE", "PROVENANCE.json"],
|
||||
"keywords": ["magpie", "magpie-middleware", "compression", "context", "history", "tokens", "llm-gateway"],
|
||||
"license": "MIT",
|
||||
"repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/history-trim" },
|
||||
"magpie": {
|
||||
"middleware": "./history-trim.middleware.js",
|
||||
"options": { "maxToolLength": 2000 }
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,8 @@
|
||||
"summary": { "en": "Claude Code and Claude Desktop on an Antigravity account: the words Antigravity refuses their system prompt for are broken up, in what Antigravity alone is sent.", "zh": "让 Claude Code 和 Claude Desktop 能用 Antigravity 账号:只在发给 Antigravity 的请求里拆开它据以拒绝系统提示词的那几个词。" } },
|
||||
{ "package": "@magpie-community/middleware-codex-history", "name": "Codex History Filter", "kind": "middleware", "community": true,
|
||||
"summary": { "en": "Opt-in, per-provider Codex Responses history filtering after switching providers. Preserves readable content and tool-call pairing; no model probes.", "zh": "按供应商开关 Codex Responses 历史过滤,缓解切换上游后的密文和历史 ID 兼容问题;保留正文与工具配对,不运行模型检测。" } },
|
||||
{ "package": "@magpie-community/middleware-history-trim", "name": "History Trim", "kind": "middleware", "community": true,
|
||||
"summary": { "en": "Send a request's history smaller: fold a run of blank lines, drop a system prompt written twice and a message repeated right after itself, and cut a past tool result longer than maxToolLength at a word boundary. The turn being sent now is left whole.", "zh": "把请求的历史发得更小:折叠连续空行、去掉逐字重复的 system 提示与紧挨着重复的消息、把历史中超过 maxToolLength 的工具结果在词边界处截断;正在发送的这一轮原样不动。" } },
|
||||
{ "package": "@magpie-community/agent-aider", "name": "Aider", "kind": "agent", "community": true,
|
||||
"summary": { "en": "Aider (aider.chat) on magpie's Agents page: pick one of magpie's models for it, and switch it off to put its config back.", "zh": "把 Aider(aider.chat)加到 magpie 的 Agent 页:给它选 magpie 的模型,关掉即恢复它原来的配置。" } },
|
||||
{ "package": "@magpie-community/agent-pig", "name": "PiG", "kind": "agent", "community": true,
|
||||
|
||||
Reference in New Issue
Block a user