omp-cache-optimizer 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -5
- package/index.ts +30 -3
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
## 安装
|
|
61
61
|
|
|
62
62
|
```bash
|
|
63
|
-
omp install
|
|
63
|
+
omp plugin install omp-cache-optimizer
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
如果之前安装过原版本:
|
|
67
67
|
|
|
68
68
|
```bash
|
|
69
|
-
omp
|
|
69
|
+
omp plugin uninstall pi-cache-optimizer && omp plugin install omp-cache-optimizer
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
安装、更新或移除后,在 OMP 中运行 `/reload`,让 extension hooks 刷新。
|
|
@@ -186,10 +186,22 @@ OMP 0.79+ 已内置 footer `CH` 标记,用于显示最近一次 prompt cache h
|
|
|
186
186
|
示例 footer:
|
|
187
187
|
|
|
188
188
|
```text
|
|
189
|
-
OpenAI
|
|
189
|
+
OpenAI Cache 3/10 · 0.002M/0.005M tok (40%) ⚠️ 配置
|
|
190
190
|
```
|
|
191
|
+
格式:`<适配器标签> <命中请求数>/<总请求数> · <缓存 tokens>/<总输入 tokens> tok (<token 命中率>)`。部分 adapter 还可能追加 `· 写入 <tokens> tok`,运行时诊断可能追加 `⚠️ 配置` 或 `⚠️ 完整性`。
|
|
191
192
|
|
|
192
|
-
|
|
193
|
+
各部分说明:
|
|
194
|
+
|
|
195
|
+
| 部分 | 示例 | 说明 |
|
|
196
|
+
|---|---|---|
|
|
197
|
+
| 适配器标签 | `OpenAI Cache` | 识别到的模型家族,匹配对应的缓存适配器。未命中时显示 `0/0` |
|
|
198
|
+
| 命中/总请求 | `3/10` | 当前 session + 模型下的缓存命中次数与总请求数 |
|
|
199
|
+
| 缓存/总 tokens | `0.002M/0.005M tok` | prompt cache 命中的 input tokens 与总 input tokens(M = million = 百万) |
|
|
200
|
+
| token 命中率 | `(40%)` | 缓存 tokens 占总输入 tokens 的百分比 |
|
|
201
|
+
| 写入 | `· 写入 0.001M tok` | 当前 session 累计新写入 prompt cache 的 tokens。仅 DeepSeek、OpenAI、Gemini 等适配器显示 |
|
|
202
|
+
| `⚠️ 配置` | 显示在末尾 | 当前模型缺少可安全修复的 compat 配置(如 reasoning 相关字段),建议运行 `/cache-optimizer fix` |
|
|
203
|
+
| `⚠️ 完整性` | 显示在末尾 | prompt 重排时检测到结构标记丢失,已回退到原始 prompt。一次性告警,`/reload` 后清除 |
|
|
204
|
+
| `缓存优化已关闭 ·` | 前缀 | `/cache-optimizer disable` 后出现,表示统计以对比模式采集,不再改写 prompt |
|
|
193
205
|
|
|
194
206
|
支持的 footer label 包括:DS、Claude、OpenAI、Gemini、Kimi、Qwen、GLM、MiniMax、Mimo、Hunyuan、Mistral、Grok、Llama、Nemotron、Cohere、Yi、Doubao、ERNIE、Baichuan、StepFun、Spark、InternLM、Gemma、Phi、Jamba、Solar、Sonar、Nova、Reka、Falcon、DBRX、MPT、StableLM、Aquila、EXAONE、HyperCLOVA、Luminous、Hermes、Granite、Arctic、Pangu、SenseNova、Zhinao、MiniCPM、XVERSE、Orion、OpenChat、Vicuna、Wizard、Zephyr、Dolphin、OpenOrca、Starling、BLOOM、RWKV、Aya。
|
|
195
207
|
|
|
@@ -279,7 +291,7 @@ cache hints 协议(`Symbol.for("omp.cache.hints.v1")`)形状与原项目一
|
|
|
279
291
|
## 卸载
|
|
280
292
|
|
|
281
293
|
```bash
|
|
282
|
-
omp
|
|
294
|
+
omp plugin uninstall omp-cache-optimizer
|
|
283
295
|
```
|
|
284
296
|
|
|
285
297
|
卸载后运行 `/reload`。本地统计文件 `~/.omp/agent/omp-cache-optimizer-stats.json` 不会自动删除,可手动清理。
|
package/index.ts
CHANGED
|
@@ -1997,6 +1997,33 @@ function extractSystemPrompt(payload: unknown): string | undefined {
|
|
|
1997
1997
|
return undefined;
|
|
1998
1998
|
}
|
|
1999
1999
|
|
|
2000
|
+
function rewriteTextBlockArray(
|
|
2001
|
+
items: unknown[],
|
|
2002
|
+
text: string,
|
|
2003
|
+
makeFallback: (text: string) => Record<string, unknown>,
|
|
2004
|
+
): unknown[] {
|
|
2005
|
+
const rewritten: unknown[] = [];
|
|
2006
|
+
let replacedText = false;
|
|
2007
|
+
|
|
2008
|
+
for (const item of items) {
|
|
2009
|
+
const record = asRecord(item);
|
|
2010
|
+
if (typeof record?.text === "string") {
|
|
2011
|
+
if (!replacedText) {
|
|
2012
|
+
rewritten.push({ ...record, text });
|
|
2013
|
+
replacedText = true;
|
|
2014
|
+
}
|
|
2015
|
+
continue;
|
|
2016
|
+
}
|
|
2017
|
+
rewritten.push(item);
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
if (!replacedText) {
|
|
2021
|
+
return [makeFallback(text), ...items];
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
return rewritten;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2000
2027
|
function setSystemPrompt(payload: unknown, text: string): boolean {
|
|
2001
2028
|
const record = asRecord(payload);
|
|
2002
2029
|
if (!record) return false;
|
|
@@ -2007,14 +2034,14 @@ function setSystemPrompt(payload: unknown, text: string): boolean {
|
|
|
2007
2034
|
return true;
|
|
2008
2035
|
}
|
|
2009
2036
|
if (Array.isArray(record.system) && record.system.length > 0) {
|
|
2010
|
-
record.system =
|
|
2037
|
+
record.system = rewriteTextBlockArray(record.system, text, (value) => ({ type: "text", text: value }));
|
|
2011
2038
|
return true;
|
|
2012
2039
|
}
|
|
2013
2040
|
|
|
2014
2041
|
// google-generative-ai: payload.systemInstruction
|
|
2015
2042
|
const systemInstruction = asRecord(record.systemInstruction);
|
|
2016
2043
|
if (systemInstruction && Array.isArray(systemInstruction.parts) && systemInstruction.parts.length > 0) {
|
|
2017
|
-
systemInstruction.parts =
|
|
2044
|
+
systemInstruction.parts = rewriteTextBlockArray(systemInstruction.parts, text, (value) => ({ text: value }));
|
|
2018
2045
|
return true;
|
|
2019
2046
|
}
|
|
2020
2047
|
|
|
@@ -2030,7 +2057,7 @@ function setSystemPrompt(payload: unknown, text: string): boolean {
|
|
|
2030
2057
|
return true;
|
|
2031
2058
|
}
|
|
2032
2059
|
if (Array.isArray(r.content) && r.content.length > 0) {
|
|
2033
|
-
r.content = text;
|
|
2060
|
+
r.content = rewriteTextBlockArray(r.content, text, (value) => ({ type: "text", text: value }));
|
|
2034
2061
|
return true;
|
|
2035
2062
|
}
|
|
2036
2063
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omp-cache-optimizer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Improve OMP prompt/KV cache hit rates with stable prompts, OpenAI-compatible cache keys, proxy compat warnings, and footer cache stats.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"omp-package",
|
|
@@ -35,7 +35,10 @@
|
|
|
35
35
|
"@oh-my-pi/pi-coding-agent": "*"
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|
|
38
|
-
"
|
|
39
|
-
|
|
38
|
+
"url": "git+https://github.com/EF-FlowCode/omp-cache-optimizer.git"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/EF-FlowCode/omp-cache-optimizer",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/EF-FlowCode/omp-cache-optimizer/issues"
|
|
40
43
|
}
|
|
41
44
|
}
|