@yandy0725/pi-vision-tools 0.1.0 → 0.2.1

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 CHANGED
@@ -21,6 +21,12 @@ calling model → describe_image → vision model → text back to calling
21
21
  2. The tool decodes the image, optionally compresses it with sharp, then calls the configured vision model
22
22
  3. The vision model's text answer is returned as the tool result
23
23
 
24
+ ## Prefix cache
25
+
26
+ Model switching already invalidates the prefix cache (different provider or model name is part of the request). The `setActiveTools` add/remove of `describe_image` is simply part of the new model's system prompt — there is zero additional cache churn.
27
+
28
+ The tool list is deterministic per model (vision models never include `describe_image`, non-vision models always do). Switching to another model and back therefore produces the same prefix as before, and the original cache hit is preserved.
29
+
24
30
  ## Install
25
31
 
26
32
  ```bash
package/README.zh.md CHANGED
@@ -21,6 +21,12 @@
21
21
  2. 工具解码图像,可选使用 sharp 压缩,然后调用配置好的视觉模型
22
22
  3. 视觉模型的文本回答作为工具结果返回
23
23
 
24
+ ## 前缀缓存
25
+
26
+ 切换模型时自身的 prefix cache 已因 model 变化而失效,`setActiveTools` 增删 `describe_image` 只是新 model 系统提示的正常组成部分,不会额外造成 cache 抖动。
27
+
28
+ 对同一个 model,tool 列表是确定的(无视觉一定带 `describe_image`,有视觉一定不带),所以中间切换到其他 model 再切回来时,前缀内容与先前一致,仍然能命中原有缓存。
29
+
24
30
  ## 安装
25
31
 
26
32
  ```bash
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.0",
6
+ "version": "0.2.1",
7
7
  "description": "pi package adding a describe_image tool that lets non-multimodal models delegate image analysis to a vision model",
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -24,8 +24,7 @@
24
24
  "test:watch": "vitest",
25
25
  "typecheck": "tsc --noEmit",
26
26
  "lint": "biome lint .",
27
- "format": "biome format --write .",
28
- "check": "biome check ."
27
+ "format": "biome format --write ."
29
28
  },
30
29
  "pi": {
31
30
  "extensions": [
@@ -33,13 +32,19 @@
33
32
  ]
34
33
  },
35
34
  "peerDependencies": {
36
- "@earendil-works/pi-coding-agent": ">=0.74.0"
35
+ "@earendil-works/pi-ai": ">=0.80.2",
36
+ "@earendil-works/pi-coding-agent": ">=0.80.2",
37
+ "@earendil-works/pi-tui": ">=0.80.2",
38
+ "typebox": "*"
37
39
  },
38
- "dependencies": {
39
- "@earendil-works/pi-ai": "^0.80.2"
40
+ "optionalDependencies": {
41
+ "sharp": "^0.35.4"
40
42
  },
41
43
  "devDependencies": {
42
- "@earendil-works/pi-tui": "^0.79.9",
43
- "typebox": "^1.1.38"
44
+ "@biomejs/biome": "^2.5.14",
45
+ "@types/node": "^26.6.2",
46
+ "typebox": "^1.3.34",
47
+ "typescript": "~7.0.2",
48
+ "vitest": "^5.0.1"
44
49
  }
45
50
  }
package/src/compress.ts CHANGED
@@ -33,7 +33,7 @@ type SharpModule = (data: Buffer) => SharpPipeline;
33
33
 
34
34
  const defaultSharpLoader = async (): Promise<SharpModule | null> => {
35
35
  try {
36
- // @ts-ignore sharp is an optional dependency, may not be installed
36
+ // @ts-expect-error sharp is an optional dependency, may not be installed
37
37
  const mod = (await import("sharp")) as { default?: SharpModule } & SharpModule;
38
38
  return mod.default ?? (mod as unknown as SharpModule);
39
39
  } catch {