omp-cache-optimizer 1.0.5 → 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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.ts +30 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -60,13 +60,13 @@
60
60
  ## 安装
61
61
 
62
62
  ```bash
63
- omp install npm:omp-cache-optimizer
63
+ omp plugin install omp-cache-optimizer
64
64
  ```
65
65
 
66
66
  如果之前安装过原版本:
67
67
 
68
68
  ```bash
69
- omp remove npm:pi-cache-optimizer && omp install npm:omp-cache-optimizer
69
+ omp plugin uninstall pi-cache-optimizer && omp plugin install omp-cache-optimizer
70
70
  ```
71
71
 
72
72
  安装、更新或移除后,在 OMP 中运行 `/reload`,让 extension hooks 刷新。
@@ -291,7 +291,7 @@ cache hints 协议(`Symbol.for("omp.cache.hints.v1")`)形状与原项目一
291
291
  ## 卸载
292
292
 
293
293
  ```bash
294
- omp remove npm:omp-cache-optimizer
294
+ omp plugin uninstall omp-cache-optimizer
295
295
  ```
296
296
 
297
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 = [{ type: "text", text }];
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 = [{ text }];
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.5",
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",