dsh-desktop-enhance 0.9.5 → 0.9.8

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
@@ -14,7 +14,7 @@
14
14
 
15
15
  ### 页内查找
16
16
 
17
- 宿主没有页内查找。装上后按 **`Cmd+F`** 唤出查找条,在当前对话里搜文字:
17
+ 宿主没有对话内查找条。桌面版装上后按 **`Cmd+F`**(Windows / Linux 为 `Ctrl+F`)唤出查找条,在当前对话里搜文字:
18
18
 
19
19
  - 输入即时高亮全部命中,并标出当前那一处,如 `3/28`
20
20
  - `Enter` / `Shift+Enter` 前后跳转,环绕
@@ -22,7 +22,7 @@
22
22
  - `Escape` 关闭(快捷键再按一次也关)
23
23
  - 匹配**大小写不敏感**,按字面匹配(正则符号当普通字符)
24
24
 
25
- Web 版(浏览器里打开的那种)键位是 **`Cmd+Shift+.`** —— `Cmd+F` 是浏览器自己的查找,抢不过来。
25
+ Web 版(浏览器里打开的那种)**不提供插件查找的默认快捷键**,也不替换为其他键位;`Cmd+F` / `Ctrl+F` 仍是浏览器原生查找,不受影响。已有用户键位配置保持不变。
26
26
 
27
27
  ### 轮次编号
28
28
 
@@ -85,6 +85,10 @@ Web 版(浏览器里打开的那种)键位是 **`Cmd+Shift+.`** —— `Cmd+
85
85
  改坏了有「恢复默认」一键还原。与出厂模板**一字不差**时会存成空串(也就是「用默认」),所以恢复默认之后配置是干净的。
86
86
 
87
87
 
88
+ ### 图片 token 估价
89
+
90
+ 默认补齐未声明图片价格的模型路由,让上下文计量与自动压缩保留预算计入图片视觉 tokens;已有适配器定价优先。没有独立界面开关,可通过插件 Config 的 `imagePricing: false` 停用。估价不改 provider usage,也不保证压后固定占比。安装此 Host 变更后需完整重启应用;规则与限制见[图片 token 估价](docs/features/image-pricing.md)。
91
+
88
92
  ### 每步耗时
89
93
 
90
94
  进程里每一步**几点开始的、花了多久**,直接跟在这一行的文字后面(`14:32 · 23s`):
@@ -226,7 +230,7 @@ dsh plugin --profile desktop update dsh-desktop-enhance
226
230
  ## 已知限制
227
231
 
228
232
  - **只搜已经加载的内容。** 更早的轮次需要点「加载更早」才会进搜索范围,查找条不会替你加载。
229
- - **`Cmd+F` 只在桌面版注册。** Web 实例上是 `Cmd+Shift+.`。
233
+ - **插件查找默认键位只在桌面版提供。** Web 不提供默认键位,原生浏览器查找不受影响。
230
234
  - 跳转临时展开的内容,**关掉查找条就复原** —— 这是有意设计,不会把整组工具调用永久摊开。
231
235
  - **建议依赖宿主能打模型调用。** 会话还没发过第一次请求、或宿主里 `llm` 服务不在时,建议退化成空列表(页面不报错,也没有提示)—— 这是有意的降级:建议是加分项,不该因为它弹错误。
232
236
  - **建议的语言跟着你。** 指令里点名要求「用用户自己在用的语言」,所以中文对话给中文建议;模型不听话时可能混出英文。
package/lib/client.js CHANGED
@@ -988,7 +988,7 @@ ABORT_ERR ETIMEDOUT ECONNREFUSED ECONNRESET EPIPE EADDRINUSE ENOSPC EACCES STORE
988
988
  "settings.badge.turnPrefix": "#N",
989
989
  "settings.badge.stepDuration": "14:32 · 23s",
990
990
  "settings.findBar": "页内查找",
991
- "settings.findBar.hint": "按 Cmd+F 唤出查找条,在整个对话里搜索并高亮",
991
+ "settings.findBar.hint": "桌面按 Cmd+F / Ctrl+F 查找并高亮对话;Web 无默认键位,使用浏览器原生查找",
992
992
  "settings.turnPrefix": "轮次编号",
993
993
  "settings.turnPrefix.hint": "悬停右侧轨道刻度时,预览卡上显示 #轮次 前缀",
994
994
  "settings.compactionRow": "压缩行高亮",
@@ -1222,7 +1222,7 @@ ABORT_ERR ETIMEDOUT ECONNREFUSED ECONNRESET EPIPE EADDRINUSE ENOSPC EACCES STORE
1222
1222
  "settings.badge.turnPrefix": "#N",
1223
1223
  "settings.badge.stepDuration": "14:32 · 23s",
1224
1224
  "settings.findBar": "Find in conversation",
1225
- "settings.findBar.hint": "Cmd+F opens a find bar that searches and highlights the whole conversation",
1225
+ "settings.findBar.hint": "On desktop, Cmd+F / Ctrl+F searches and highlights the conversation; Web has no default binding and uses browser find",
1226
1226
  "settings.turnPrefix": "Turn numbers",
1227
1227
  "settings.turnPrefix.hint": "Shows a #N prefix on the preview card when hovering the rail marks",
1228
1228
  "settings.compactionRow": "Compaction row highlight",
@@ -10369,14 +10369,6 @@ ABORT_ERR ETIMEDOUT ECONNREFUSED ECONNRESET EPIPE EADDRINUSE ENOSPC EACCES STORE
10369
10369
  "desktop:linux": {
10370
10370
  code: "KeyF",
10371
10371
  modifiers: ["primary"]
10372
- },
10373
- "web:macos": {
10374
- code: "Period",
10375
- modifiers: ["primary", "shift"]
10376
- },
10377
- "web:windows": {
10378
- code: "Period",
10379
- modifiers: ["primary", "shift"]
10380
10372
  }
10381
10373
  },
10382
10374
  regions: [
package/lib/index.d.ts CHANGED
@@ -7,6 +7,13 @@ interface RequestEvent {
7
7
  readonly data: unknown;
8
8
  }
9
9
  //#endregion
10
+ //#region src/image-pricing/host.d.ts
11
+ declare function imageTokensForModel(model: string, width: number, height: number): number | null;
12
+ declare function readImagePricingEnabled(config: unknown): boolean;
13
+ declare function installImagePricing(ctx: {
14
+ get(name: string): unknown;
15
+ }, enabled?: () => boolean): () => void;
16
+ //#endregion
10
17
  //#region src/shared/session-state.d.ts
11
18
  interface SessionPolicyDelta {
12
19
  readonly allow: readonly string[];
@@ -736,6 +743,7 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
736
743
  disabledSkills: Schema<string, string, "volatile-defined">;
737
744
  contextManager: Schema<boolean, boolean, "volatile-defined">;
738
745
  skillRecovery: Schema<boolean, boolean, "volatile-defined">;
746
+ imagePricing: Schema<boolean, boolean, "volatile-defined">;
739
747
  diagnosticsRetentionDays: Schema<number, number, "defined">;
740
748
  diagnosticsMaxMiB: Schema<number, number, "defined">;
741
749
  }>>, Schemastery.ObjectT<NoInfer<{
@@ -759,11 +767,15 @@ export declare const Config: Schema<Schemastery.ObjectS<NoInfer<{
759
767
  disabledSkills: Schema<string, string, "volatile-defined">;
760
768
  contextManager: Schema<boolean, boolean, "volatile-defined">;
761
769
  skillRecovery: Schema<boolean, boolean, "volatile-defined">;
770
+ imagePricing: Schema<boolean, boolean, "volatile-defined">;
762
771
  diagnosticsRetentionDays: Schema<number, number, "defined">;
763
772
  diagnosticsMaxMiB: Schema<number, number, "defined">;
764
773
  }>>, "plain">;
765
774
  export declare function apply(ctx: ToolsHostContext, config?: unknown): void;
766
775
  export declare const __test: {
776
+ imageTokensForModel: typeof imageTokensForModel;
777
+ installImagePricing: typeof installImagePricing;
778
+ readImagePricingEnabled: typeof readImagePricingEnabled;
767
779
  createUpdateEngine: typeof createUpdateEngine;
768
780
  productionDeps: typeof productionDeps;
769
781
  readInstalledVersion: typeof readInstalledVersion;
package/lib/index.js CHANGED
@@ -19,6 +19,145 @@ function applyPolicyDelta(global, delta) {
19
19
  return effective;
20
20
  }
21
21
  //#endregion
22
+ //#region src/image-pricing/host.ts
23
+ const PATCH_SIZE = 14;
24
+ const DOWNSAMPLE_RATIO = 3;
25
+ const MAX_IMAGE_TOKENS = 1024;
26
+ const MIN_PIXELS = 295936;
27
+ const CELL_SIZE = 42;
28
+ const intDiv = (value, divisor) => Math.floor(value / divisor);
29
+ const ceilDiv = (value, divisor) => Math.floor((value + divisor - 1) / divisor);
30
+ const gridCells = (paddedLength) => ceilDiv(intDiv(paddedLength, PATCH_SIZE), DOWNSAMPLE_RATIO);
31
+ const gridTokens = (height, width) => height * (width + 1) + 2;
32
+ function solveResizeRatio(height, width) {
33
+ const aspect = height / width;
34
+ const idealGridWidth = Math.sqrt(1022 / aspect + .25) - .5;
35
+ const idealGridHeight = idealGridWidth * aspect;
36
+ let bestHeight;
37
+ let bestWidth;
38
+ if (idealGridWidth < 1) {
39
+ bestWidth = CELL_SIZE;
40
+ bestHeight = intDiv(1022, 2) * CELL_SIZE;
41
+ } else if (idealGridHeight < 1) {
42
+ bestWidth = 1021 * CELL_SIZE;
43
+ bestHeight = CELL_SIZE;
44
+ } else {
45
+ const scale = Math.min(Math.trunc(idealGridWidth) * CELL_SIZE / width, Math.trunc(idealGridHeight) * CELL_SIZE / height);
46
+ bestWidth = Math.trunc(width * scale / PATCH_SIZE) * PATCH_SIZE;
47
+ bestHeight = Math.trunc(height * scale / PATCH_SIZE) * PATCH_SIZE;
48
+ }
49
+ return {
50
+ bestHeight,
51
+ bestWidth,
52
+ gridHeight: gridCells(bestHeight),
53
+ gridWidth: gridCells(bestWidth)
54
+ };
55
+ }
56
+ function resizeOnce(width, height) {
57
+ let scaledWidth = width;
58
+ let scaledHeight = height;
59
+ const pixels = width * height;
60
+ if (pixels < MIN_PIXELS && pixels > 0) {
61
+ const scale = Math.sqrt(MIN_PIXELS / pixels);
62
+ scaledWidth = Math.trunc(width * scale);
63
+ scaledHeight = Math.trunc(height * scale);
64
+ }
65
+ const paddedWidth = ceilDiv(scaledWidth, PATCH_SIZE) * PATCH_SIZE;
66
+ const paddedHeight = ceilDiv(scaledHeight, PATCH_SIZE) * PATCH_SIZE;
67
+ const direct = {
68
+ bestHeight: paddedHeight,
69
+ bestWidth: paddedWidth,
70
+ gridHeight: gridCells(paddedHeight),
71
+ gridWidth: gridCells(paddedWidth)
72
+ };
73
+ if (gridTokens(direct.gridHeight, direct.gridWidth) <= MAX_IMAGE_TOKENS) return direct;
74
+ const solved = solveResizeRatio(scaledHeight, scaledWidth);
75
+ if (gridTokens(solved.gridHeight, solved.gridWidth) > MAX_IMAGE_TOKENS) throw new Error(`deepseek image tokens: no grid fits the token budget for ${width}x${height}`);
76
+ return solved;
77
+ }
78
+ function deepSeekImageTokens(width, height) {
79
+ let result = resizeOnce(width, height);
80
+ for (let iteration = 1; iteration < 10; iteration += 1) {
81
+ const next = resizeOnce(result.bestWidth, result.bestHeight);
82
+ if (next.gridHeight === result.gridHeight && next.gridWidth === result.gridWidth && next.bestHeight === result.bestHeight && next.bestWidth === result.bestWidth) return gridTokens(result.gridHeight, result.gridWidth);
83
+ result = next;
84
+ }
85
+ throw new Error(`deepseek image tokens: resize did not converge for ${width}x${height}`);
86
+ }
87
+ const IMAGE_RULES = [
88
+ [/deepseek/i, deepSeekImageTokens],
89
+ [/qwen/i, (width, height) => Math.ceil(width / 32) * Math.ceil(height / 32)],
90
+ [/seed|doubao/i, (width, height) => Math.min(Math.round(width * height / 1764), 1280)],
91
+ [/^gemini/i, (width, height) => Math.ceil(width / 768) * Math.ceil(height / 768) * 258],
92
+ [/^gpt-6/i, (width, height) => Math.ceil(Math.ceil(width / 32) * Math.ceil(height / 32) * 1.2)]
93
+ ];
94
+ const ruleForModel = (model) => IMAGE_RULES.find(([pattern]) => pattern.test(model))?.[1];
95
+ function imageTokensForModel(model, width, height) {
96
+ const rule = ruleForModel(model);
97
+ if (!rule) return null;
98
+ return tokensForDimensions(rule, width, height);
99
+ }
100
+ function tokensForDimensions(rule, width, height) {
101
+ if (!Number.isSafeInteger(width) || width <= 0 || !Number.isSafeInteger(height) || height <= 0) throw new RangeError(`image pricing: invalid dimensions ${width}x${height}`);
102
+ return rule(width, height);
103
+ }
104
+ function readImagePricingEnabled(config) {
105
+ if (config === null || typeof config !== "object") return true;
106
+ const raw = config.imagePricing;
107
+ if (typeof raw === "boolean") return raw;
108
+ if (raw !== null && typeof raw === "object" && typeof raw.get === "function") try {
109
+ const value = raw.get();
110
+ return typeof value === "boolean" ? value : true;
111
+ } catch {
112
+ return true;
113
+ }
114
+ return true;
115
+ }
116
+ const installedPricing = new WeakSet();
117
+ function installImagePricing(ctx, enabled = () => true) {
118
+ const llm = ctx.get("llm");
119
+ if (!llm) return () => {};
120
+ const previous = Object.getOwnPropertyDescriptor(llm, "imageRequestPricing");
121
+ if (previous && installedPricing.has(previous.value)) return () => {};
122
+ const basePricing = llm.imageRequestPricing;
123
+ const replacement = function(provider, model) {
124
+ const declared = basePricing.call(this, provider, model);
125
+ if (declared !== void 0 || !installedPricing.has(replacement) || !enabled()) return declared;
126
+ const rule = ruleForModel(model);
127
+ if (!rule) return void 0;
128
+ return { priceImages: (images) => images.map((image) => {
129
+ if (image.offloaded === true) return {
130
+ visualTokens: 0,
131
+ text: ""
132
+ };
133
+ let target = {
134
+ width: image.attachment.width,
135
+ height: image.attachment.height
136
+ };
137
+ try {
138
+ target = llm.imageRequestTarget(provider, model, image.attachment);
139
+ } catch {}
140
+ return {
141
+ visualTokens: tokensForDimensions(rule, target.width, target.height),
142
+ text: ""
143
+ };
144
+ }) };
145
+ };
146
+ Object.defineProperty(llm, "imageRequestPricing", {
147
+ value: replacement,
148
+ configurable: true,
149
+ writable: true,
150
+ enumerable: previous?.enumerable ?? false
151
+ });
152
+ installedPricing.add(replacement);
153
+ return () => {
154
+ installedPricing.delete(replacement);
155
+ if (Object.getOwnPropertyDescriptor(llm, "imageRequestPricing")?.value !== replacement) return;
156
+ if (previous) Object.defineProperty(llm, "imageRequestPricing", previous);
157
+ else delete llm.imageRequestPricing;
158
+ };
159
+ }
160
+ //#endregion
22
161
  //#region src/shared/route.ts
23
162
  const SUGGEST_ROUTE = "/api/desktop-enhance/suggest";
24
163
  const SUGGEST_MODELS_ROUTE = "/api/desktop-enhance/suggest-models";
@@ -5770,6 +5909,7 @@ const Config = Schema.object({
5770
5909
  disabledSkills: Schema.string().default("").volatile(),
5771
5910
  contextManager: Schema.boolean().default(true).volatile(),
5772
5911
  skillRecovery: Schema.boolean().default(true).volatile(),
5912
+ imagePricing: Schema.boolean().default(true).volatile(),
5773
5913
  diagnosticsRetentionDays: Schema.number().min(1).max(30).step(1).default(7),
5774
5914
  diagnosticsMaxMiB: Schema.number().min(4).max(256).step(1).default(64)
5775
5915
  });
@@ -5781,6 +5921,9 @@ function apply(ctx, config) {
5781
5921
  ctx.inject(["sessionProjections"], (serviceCtx) => {
5782
5922
  serviceCtx.get("sessionProjections").register(sessionModelProjection);
5783
5923
  });
5924
+ ctx.inject(["llm"], (serviceCtx) => {
5925
+ serviceCtx.effect(() => installImagePricing(serviceCtx, () => readImagePricingEnabled(config)), "desktop-enhance: image pricing");
5926
+ });
5784
5927
  ctx.inject(["connection"], (serviceCtx) => {
5785
5928
  try {
5786
5929
  serviceCtx.effect(() => registerSuggestRoute(serviceCtx), "desktop-enhance: suggest route");
@@ -5920,6 +6063,9 @@ function apply(ctx, config) {
5920
6063
  });
5921
6064
  }
5922
6065
  const __test = {
6066
+ imageTokensForModel,
6067
+ installImagePricing,
6068
+ readImagePricingEnabled,
5923
6069
  createUpdateEngine,
5924
6070
  productionDeps,
5925
6071
  readInstalledVersion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-desktop-enhance",
3
- "version": "0.9.5",
3
+ "version": "0.9.8",
4
4
  "description": "DSH Desktop 界面增强:页内查找(Cmd+F)、轮次编号、上下文压缩行常显、建议、每步耗时、折叠文件夹状态计数、会话信息(含上下文注入 C1 视图)、工具管理、Skill 管理、独立远程接入与手机体验,以及智能建议、会话能力和远程接入的持久诊断日志。",
5
5
  "type": "module",
6
6
  "icon": "./icon.svg",