@jayyuen66/dsh-ocr-review 0.1.5-rc → 0.1.7

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/client.js CHANGED
@@ -20,7 +20,8 @@ const UI_MESSAGES = {
20
20
  revert: "撤销",
21
21
  saveFailed: "保存失败:",
22
22
  saveRefused: "未写入(宿主拒收或跳过):{fields}",
23
- loadProvidersFailed: "加载 providers 失败:{error}(端点未就绪?重启 dsh 后重试)",
23
+ loadProvidersFailed: "加载 providers 失败:{error}(远程面未就绪?重启 dsh 后重试)",
24
+ remoteUnavailable: "远程服务不可用:宿主没有挂上本插件的设置通道。",
24
25
  loadingProviders: "加载 providers…",
25
26
  noKeySuffix: "(未配置 key)",
26
27
  noModel: "(无模型)",
@@ -36,7 +37,7 @@ const UI_MESSAGES = {
36
37
  noProvider: "当前未配置 provider",
37
38
  noReason: "宿主未给出原因(重启 dsh 或重试可恢复)",
38
39
  readProvidersFailed: "未能从 dsh 配置服务读取 provider 列表:{reason}",
39
- endpointVerifyFailed: "装载期端点自检失败(配置仍可修改):{reason}",
40
+ endpointVerifyFailed: "装载期端点自检未通过:{reason}(这条是端点给的回执,不是本插件的故障;配置照样能改,也可点「测试连接」重跑)",
40
41
  applied: "已应用:{provider} / {model}\n{test}",
41
42
  notVerified: "(未自动验证,可点「测试连接」手动验证)",
42
43
  llmTestPassed: "✓ ocr llm test 通过",
@@ -62,7 +63,7 @@ const UI_MESSAGES = {
62
63
  maxCommentsLabel: "摘要评论条数 (maxComments)",
63
64
  maxCommentsHint: "返回给模型的 top 评论条数;0 = 全部(含未锚定行,输出大)(默认 12)",
64
65
  timeoutLabel: "运行超时 (timeoutMinutes)",
65
- timeoutHint: "前台墙钟超时(分钟);0 = 宿主上限(shell.maxTimeoutMs,当前 60 分钟);更长的评审用工具 wait=false 后台模式(不设宿主 deadline,2 小时后兜底回收)(默认 0)",
66
+ timeoutHint: "前台墙钟超时(分钟);0 = 宿主上限(shell.maxTimeoutMs,当前 60 分钟);更长的评审用工具 wait=false 后台模式(不设宿主 deadline,兜底窗口看设置项 ocrBackgroundMaxMs,默认 0 = 不设窗口)(默认 0)",
66
67
  configPathLabel: "OCR 配置文件 (ocrConfigPath)",
67
68
  configPathHint: "外部 open-code-review CLI 自己的配置位置;留空 = ~/.opencodereview/config.json。自定义时必须是 <X>/.opencodereview/config.json 布局(OCR 只认该形状,插件经 HOME 重定向让它生效)",
68
69
  settingsLoading: "设置加载中,稍候可改",
@@ -70,14 +71,21 @@ const UI_MESSAGES = {
70
71
  keyScriptMissing: "⚠ get-cred 脚本缺失,api_key_cmd 无法工作",
71
72
  binaryTitle: "外部 CLI(ocr)",
72
73
  binaryUnknown: "状态未取到:刷新本页,或确认 dsh 的 web 服务已起来",
73
- binaryBundled: "随本插件分发已就位,无需再全局安装",
74
- binaryPath: "用 PATH 上的全局安装:{path}",
75
- binaryNone: "未找到 ocr:`brew install open-code-review` 或 `npm i -g @alibaba-group/open-code-review`",
74
+ binaryBundled: "随本插件分发的兜底入口已就位:{path}({channel})",
75
+ binaryPath: "用 PATH 上的全局安装:{path}({channel})",
76
+ binaryNone: "未找到 ocr:PATH 与随包兜底两条路都没有可执行候选。装法与版本看下一行(由插件按核对版本给出)",
77
+ channelBrew: "brew formula",
78
+ channelNpm: "npm 全局包",
79
+ channelUnknown: "装法未识别",
80
+ versionExpected: "本插件的契约按 ocr {expected} 逐条核对",
81
+ versionMatched: "本机实测 {actual},与核对版本一致",
82
+ versionDiverged: "本机实测 {actual},与核对版本 {expected} 不一致:评论口径可能随版本漂移",
83
+ badgeDiverged: "ocr 版本不一致",
76
84
  detectCli: "检测版本",
77
85
  detecting: "检测中…",
78
86
  probeVersion: "ocr 版本:{version}",
79
87
  probeReason: "未取到版本号:{reason}",
80
- badgeBundled: "ocr 随包就位",
88
+ badgeBundled: "ocr 走随包兜底",
81
89
  badgePath: "ocr 来自 PATH",
82
90
  badgeNone: "未找到 ocr",
83
91
  badgeUnknown: "ocr 状态未取到",
@@ -96,7 +104,8 @@ const UI_MESSAGES = {
96
104
  revert: "Revert",
97
105
  saveFailed: "save failed: ",
98
106
  saveRefused: "not written (host refused or skipped): {fields}",
99
- loadProvidersFailed: "failed to load providers: {error} (endpoint not ready? restart dsh and retry)",
107
+ loadProvidersFailed: "failed to load providers: {error} (remote face not ready? restart dsh and retry)",
108
+ remoteUnavailable: "remote service unavailable: the host did not mount this plugin's settings channel",
100
109
  loadingProviders: "loading providers…",
101
110
  noKeySuffix: " (no key configured)",
102
111
  noModel: " (no model)",
@@ -112,7 +121,7 @@ const UI_MESSAGES = {
112
121
  noProvider: "No provider configured yet",
113
122
  noReason: "the host gave no reason (restart dsh or retry to recover)",
114
123
  readProvidersFailed: "Could not read the provider list from the dsh settings service: {reason}",
115
- endpointVerifyFailed: "Startup endpoint check failed (the config is still editable): {reason}",
124
+ endpointVerifyFailed: "Startup endpoint check did not pass: {reason} (this is the endpoint's reply, not a fault of this plugin; the config stays editable, and “Test connection” reruns it)",
116
125
  applied: "Applied: {provider} / {model}\n{test}",
117
126
  notVerified: "(not verified automatically — use “Test connection” to check manually)",
118
127
  llmTestPassed: "✓ ocr llm test passed",
@@ -138,7 +147,7 @@ const UI_MESSAGES = {
138
147
  maxCommentsLabel: "Summary comment cap (maxComments)",
139
148
  maxCommentsHint: "Top comments returned to the model; 0 = all (including unanchored lines, large output) (default 12)",
140
149
  timeoutLabel: "Run timeout (timeoutMinutes)",
141
- timeoutHint: "Foreground wall-clock timeout in minutes; 0 = host cap (shell.maxTimeoutMs, currently 60 min); for longer reviews use the tool's wait=false background mode (no host deadline, reclaimed by a 2-hour backstop) (default 0)",
150
+ timeoutHint: "Foreground wall-clock timeout in minutes; 0 = host cap (shell.maxTimeoutMs, currently 60 min); for longer reviews use the tool's wait=false background mode (no host deadline; the backstop window is the ocrBackgroundMaxMs setting, default 0 = none) (default 0)",
142
151
  configPathLabel: "OCR config file (ocrConfigPath)",
143
152
  configPathHint: "Where the external open-code-review CLI keeps its own config; empty = ~/.opencodereview/config.json. A custom value must follow the <X>/.opencodereview/config.json layout (OCR only reads that shape; the plugin makes it effective via a HOME redirect)",
144
153
  settingsLoading: "settings still loading — editable in a moment",
@@ -146,14 +155,21 @@ const UI_MESSAGES = {
146
155
  keyScriptMissing: "⚠ get-cred script missing, api_key_cmd cannot work",
147
156
  binaryTitle: "External CLI (ocr)",
148
157
  binaryUnknown: "status not reported: reload this page, or check that the dsh web server is up",
149
- binaryBundled: "bundled with this plugin, no global install needed",
150
- binaryPath: "using the global install on PATH: {path}",
151
- binaryNone: "ocr not found: `brew install open-code-review` or `npm i -g @alibaba-group/open-code-review`",
158
+ binaryBundled: "bundled fallback entry in place: {path} ({channel})",
159
+ binaryPath: "using the global install on PATH: {path} ({channel})",
160
+ binaryNone: "ocr not found: neither PATH nor the bundled fallback has an executable candidate. The install command and version are on the next line (this plugin states the version its contract was verified against)",
161
+ channelBrew: "brew formula",
162
+ channelNpm: "npm global package",
163
+ channelUnknown: "install method unrecognised",
164
+ versionExpected: "this plugin's contract was verified against ocr {expected}",
165
+ versionMatched: "this machine reports {actual}, matching it",
166
+ versionDiverged: "this machine reports {actual}, which is not the verified {expected}: comment wording and severity may drift between versions",
167
+ badgeDiverged: "ocr version differs",
152
168
  detectCli: "Detect version",
153
169
  detecting: "Detecting...",
154
170
  probeVersion: "ocr version: {version}",
155
171
  probeReason: "no version read: {reason}",
156
- badgeBundled: "ocr bundled",
172
+ badgeBundled: "ocr from bundled fallback",
157
173
  badgePath: "ocr from PATH",
158
174
  badgeNone: "ocr not found",
159
175
  badgeUnknown: "ocr status unavailable",
@@ -163,12 +179,174 @@ const UI_MESSAGES = {
163
179
  }
164
180
  };
165
181
  //#endregion
166
- //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.5-rc_@deepseek-ai+cordis@4.0.5-alpha.1_@deepseek-ai+ds_e716d822a8a24fbc7ac6d086dd04b807/node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
167
- function e(e) {
182
+ //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_@deepseek-ai+cordis@4.0.5_@deepseek-ai+dsh-client-lo_8c875f5679b30ed9bd8ed9c09e6b1478/node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
183
+ function e$2(e) {
168
184
  return typeof e == `object` && !!e && !Array.isArray(e);
169
185
  }
170
- function t(t, n) {
171
- return e(t) ? t[n] : void 0;
186
+ function n(t, n) {
187
+ return e$2(t) ? t[n] : void 0;
188
+ }
189
+ //#endregion
190
+ //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_@deepseek-ai+cordis@4.0.5_@deepseek-ai+dsh-client-lo_8c875f5679b30ed9bd8ed9c09e6b1478/node_modules/@jayyuen66/dsh-plugin-shared/dist/card-apply.js
191
+ function e$1(e, t, n) {
192
+ let r = globalThis;
193
+ if (Object.hasOwn(r, t) && r[t] === !0) return !1;
194
+ r[t] = !0;
195
+ try {
196
+ e.effect(() => () => {
197
+ r[t] = void 0;
198
+ }, n);
199
+ } catch (e) {
200
+ throw r[t] = void 0, e;
201
+ }
202
+ return !0;
203
+ }
204
+ //#endregion
205
+ //#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.6_@deepseek-ai+cordis@4.0.5_@deepseek-ai+dsh-client-lo_8c875f5679b30ed9bd8ed9c09e6b1478/node_modules/@jayyuen66/dsh-plugin-shared/dist/card-diff.js
206
+ function e(e, t) {
207
+ let n = [];
208
+ for (let r of Object.keys(e)) JSON.stringify(e[r] ?? null) !== JSON.stringify(t[r] ?? null) && n.push(r);
209
+ return n;
210
+ }
211
+ //#endregion
212
+ //#region lib/remote-shape.ts
213
+ /** 宿主服务键 = 客户端线上命名空间(两侧共用的唯一来源)。 */
214
+ const OCR_REMOTE_NAMESPACE = "ocrReview";
215
+ //#endregion
216
+ //#region src/remote.ts
217
+ /** 网关给命名空间注册的**服务键**:`remote.<namespace>`。它在 `$mount` 完成之后才存在,
218
+ * 所以只能在挂载后按这个键去读,而不是提前 inject。 */
219
+ const OCR_SERVICE_KEY = `remote.${OCR_REMOTE_NAMESPACE}`;
220
+ /** 卡片所在 bundle 的包名(`$mount` 的 `package` 位与槽位键同源,见 client-entry.ts 的 BUNDLE_PKG)。 */
221
+ const PACKAGE_NAME = "@jayyuen66/dsh-ocr-review";
222
+ /** 把宿主那五个方法挂到客户端远程面上的描述符(`id` 的形状照生成器:`<包>#<命名空间>/<方法>`)。
223
+ * 导出它只为一件事:`test/remote.test.ts` 拿它与宿主侧 `remoteMethods()` 的标记对质
224
+ * —— 两侧分叉时卡片不会报错,只会"读不到",所以那条比较必须在门禁里。 */
225
+ const OCR_DESCRIPTORS = [
226
+ {
227
+ id: `${PACKAGE_NAME}#${OCR_REMOTE_NAMESPACE}/providers`,
228
+ service: OCR_REMOTE_NAMESPACE,
229
+ namespace: OCR_REMOTE_NAMESPACE,
230
+ method: "providers",
231
+ invocation: { kind: "direct" },
232
+ parameters: [],
233
+ result: { mode: "src-json" }
234
+ },
235
+ {
236
+ id: `${PACKAGE_NAME}#${OCR_REMOTE_NAMESPACE}/select`,
237
+ service: OCR_REMOTE_NAMESPACE,
238
+ namespace: OCR_REMOTE_NAMESPACE,
239
+ method: "select",
240
+ invocation: { kind: "direct" },
241
+ parameters: [{
242
+ name: "request",
243
+ wire: "request",
244
+ source: "json",
245
+ codec: {
246
+ mode: "strict",
247
+ typeSymbol: `${PACKAGE_NAME}#select-request`,
248
+ create: () => ({ parse(value) {
249
+ if (!e$2(value)) throw new TypeError("select request must be an object");
250
+ const { provider, model } = value;
251
+ if (typeof provider !== "string" || typeof model !== "string") throw new TypeError("select request requires string provider and model");
252
+ return {
253
+ provider,
254
+ model
255
+ };
256
+ } })
257
+ }
258
+ }],
259
+ result: { mode: "src-json" }
260
+ },
261
+ {
262
+ id: `${PACKAGE_NAME}#${OCR_REMOTE_NAMESPACE}/migrate`,
263
+ service: OCR_REMOTE_NAMESPACE,
264
+ namespace: OCR_REMOTE_NAMESPACE,
265
+ method: "migrate",
266
+ invocation: { kind: "direct" },
267
+ parameters: [],
268
+ result: { mode: "src-json" }
269
+ },
270
+ {
271
+ id: `${PACKAGE_NAME}#${OCR_REMOTE_NAMESPACE}/test`,
272
+ service: OCR_REMOTE_NAMESPACE,
273
+ namespace: OCR_REMOTE_NAMESPACE,
274
+ method: "test",
275
+ invocation: { kind: "direct" },
276
+ parameters: [],
277
+ result: { mode: "src-json" }
278
+ },
279
+ {
280
+ id: `${PACKAGE_NAME}#${OCR_REMOTE_NAMESPACE}/probe`,
281
+ service: OCR_REMOTE_NAMESPACE,
282
+ namespace: OCR_REMOTE_NAMESPACE,
283
+ method: "probe",
284
+ invocation: { kind: "direct" },
285
+ parameters: [],
286
+ result: { mode: "src-json" }
287
+ }
288
+ ];
289
+ /** 这个值能当远程面用吗(只核我们要调的那一位;服务来自别的实现或版本时保守当作没有)。 */
290
+ const isRemoteMounter = (value) => e$2(value) && typeof value["$mount"] === "function";
291
+ /** 同上:命名空间服务(挂载之后才有,缺它说明网关没认这枚贡献)。 */
292
+ const isOcrNamespace = (value) => e$2(value) && typeof value["providers"] === "function" && typeof value["select"] === "function" && typeof value["migrate"] === "function" && typeof value["test"] === "function" && typeof value["probe"] === "function";
293
+ /** 网关回执 → 值;载体/网关失败抛(卡片那层按「请求失败」显示)。 */
294
+ function unwrap(result) {
295
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
296
+ return result.value;
297
+ }
298
+ /**
299
+ * 造出真正的读取器(挂载一次 + 每次读命名空间服务)。
300
+ * @param ctx - 客户端上下文
301
+ * @param remote - 已核过形状的远程面
302
+ * @returns 读取器
303
+ */
304
+ function buildOcrReader(ctx, remote) {
305
+ let mounted;
306
+ const namespaceOf = async () => {
307
+ mounted ??= remote.$mount({
308
+ package: PACKAGE_NAME,
309
+ descriptors: OCR_DESCRIPTORS
310
+ });
311
+ await mounted;
312
+ const namespace = ctx.get?.(OCR_SERVICE_KEY, false);
313
+ if (!isOcrNamespace(namespace)) throw new Error(`${OCR_SERVICE_KEY} 未提供:宿主网关没有挂上这枚命名空间`);
314
+ return namespace;
315
+ };
316
+ return {
317
+ async providers() {
318
+ return unwrap(await (await namespaceOf()).providers());
319
+ },
320
+ async select(provider, model) {
321
+ return unwrap(await (await namespaceOf()).select({
322
+ provider,
323
+ model
324
+ }));
325
+ },
326
+ async migrate() {
327
+ return unwrap(await (await namespaceOf()).migrate());
328
+ },
329
+ async test() {
330
+ return unwrap(await (await namespaceOf()).test());
331
+ },
332
+ async probe() {
333
+ return unwrap(await (await namespaceOf()).probe());
334
+ }
335
+ };
336
+ }
337
+ /**
338
+ * 造一个「读/写宿主侧 OCR 配置」的读取器;**当前部署没有远程面时返回 `undefined`**
339
+ * (卡片照常渲染,只是数据面显示读不到 —— 与 host 侧可选读面同一条口径)。
340
+ *
341
+ * `$mount` 是**幂等**的(挂进本 fiber,随卡片卸载自动撤),所以这里缓存那枚 promise:
342
+ * 同一次会话里反复拉取只挂一次。
343
+ *
344
+ * @param ctx - 客户端上下文(只用 `get` 一位)
345
+ * @returns 读取器;没有远程面时 `undefined`
346
+ */
347
+ function createOcrReader(ctx) {
348
+ const remote = ctx.get?.("remote");
349
+ return isRemoteMounter(remote) ? buildOcrReader(ctx, remote) : void 0;
172
350
  }
173
351
  //#endregion
174
352
  //#region src/client-entry.ts
@@ -191,13 +369,6 @@ const NS = "ocr-review";
191
369
  * dsh-client-ui-settings/lib/client.js:1309-1315 把入参原样当 settings 命名空间用)。
192
370
  */
193
371
  const BUNDLE_PKG = "@jayyuen66/dsh-ocr-review";
194
- const PROVIDERS_URL = "/_dsh/ocr-review/providers";
195
- const SELECT_URL = "/_dsh/ocr-review/select";
196
- const MIGRATE_URL = "/_dsh/ocr-review/migrate";
197
- const TEST_URL = "/_dsh/ocr-review/test";
198
- const PROBE_URL = "/_dsh/ocr-review/probe";
199
- /** 写端点 CSRF 头名(与 host.ts OCR_CSRF_HEADER 同源,改名要两端一起改)。 */
200
- const CSRF_HEADER = "x-ocr-csrf";
201
372
  /** 未知值 → 安全字符串(非字符串给 '')。 */
202
373
  function strOf(value) {
203
374
  return typeof value === "string" ? value : "";
@@ -212,21 +383,21 @@ function errorSummary(error) {
212
383
  }
213
384
  function modelOf(raw) {
214
385
  return {
215
- id: strOf(t(raw, "id")),
216
- name: strOf(t(raw, "name"))
386
+ id: strOf(n(raw, "id")),
387
+ name: strOf(n(raw, "name"))
217
388
  };
218
389
  }
219
390
  function providerOf(raw) {
220
- const modelsArr = t(raw, "models");
391
+ const modelsArr = n(raw, "models");
221
392
  const models = Array.isArray(modelsArr) ? modelsArr.map((item) => modelOf(item)) : [];
222
- const apiKeyEnvRaw = t(raw, "apiKeyEnv");
393
+ const apiKeyEnvRaw = n(raw, "apiKeyEnv");
223
394
  return {
224
- name: strOf(t(raw, "name")),
225
- displayName: strOf(t(raw, "displayName")),
395
+ name: strOf(n(raw, "name")),
396
+ displayName: strOf(n(raw, "displayName")),
226
397
  apiKeyEnv: typeof apiKeyEnvRaw === "string" ? apiKeyEnvRaw : null,
227
- baseURL: strOf(t(raw, "baseURL")),
398
+ baseURL: strOf(n(raw, "baseURL")),
228
399
  models,
229
- hasKey: t(raw, "hasKey") === true
400
+ hasKey: n(raw, "hasKey") === true
230
401
  };
231
402
  }
232
403
  /** 可得性来源的合法域(与 host 侧 `OcrBinarySource` 同一份取值)。形状不合即「没报」。 */
@@ -235,57 +406,71 @@ const BINARY_SOURCES = /* @__PURE__ */ new Set([
235
406
  "path",
236
407
  "none"
237
408
  ]);
238
- /** 解析宿主送的可得性对象。导出是为了让「wire 键名」这条契约能被钉住:卡片与 host
239
- * 两处各写一份键名时,写错了的症状是状态行永远显示「未取到」,而不是任何报错。 */
409
+ /**
410
+ * 解析宿主送的可得性对象。导出是为了让「wire 键名」这条契约能被钉住:卡片与 host
411
+ * 两处各写一份键名时,写错了的症状是状态行永远显示「未取到」,而不是任何报错。
412
+ *
413
+ * 只有 `source` 是必需的:其余四样各管一句附加信息,缺了就少说那一句,而不是把整行判定
414
+ * 作废——「宿主报了 PATH 却没报版本」仍然是一条用户要看的事实。`measuredVersion` 例外,
415
+ * 它恒在(null = 还没测过),因为「没测过」与「旧宿主不带这字段」在卡片上是同一句话。
416
+ */
240
417
  function binaryOf(raw) {
241
- if (!e(raw)) return null;
418
+ if (!e$2(raw)) return null;
242
419
  const source = strOf(raw["source"]);
243
420
  if (!BINARY_SOURCES.has(source)) return null;
244
421
  const path = strOf(raw["path"]);
245
- return path === "" ? { source } : {
422
+ const channel = strOf(raw["channel"]);
423
+ const expectedVersion = strOf(raw["expectedVersion"]);
424
+ const installHint = strOf(raw["installHint"]);
425
+ const measured = raw["measuredVersion"];
426
+ return {
246
427
  source,
247
- path
428
+ ...path === "" ? {} : { path },
429
+ ...channel === "" ? {} : { channel },
430
+ ...expectedVersion === "" ? {} : { expectedVersion },
431
+ ...installHint === "" ? {} : { installHint },
432
+ measuredVersion: typeof measured === "string" ? measured : null
248
433
  };
249
434
  }
250
435
  /**
251
- * 详情页徽标/区块/启用指引共用的取数口:读同一条 GET providers 的 `ocrBinary` 那半。
436
+ * 详情页徽标/区块/启用指引共用的取数口:读同一条 providers 载荷的 `ocrBinary` 那半。
252
437
  * 判据只在 host 的 `resolveOcrAvailability` 一处,本包三个显示面都只翻译它的结论。
438
+ * 读取器缺席(部署没装远程面)与传输失败都归成 null:这三处只负责显示。
253
439
  */
254
- async function loadCliStatus() {
440
+ async function loadCliStatus(reader) {
441
+ if (reader === void 0) return null;
255
442
  try {
256
- const res = await fetch(PROVIDERS_URL, { headers: { accept: "application/json" } });
257
- return res.ok ? binaryOf(t(await res.json(), "ocrBinary")) : null;
443
+ return binaryOf(n(await reader.providers(), "ocrBinary"));
258
444
  } catch {
259
445
  return null;
260
446
  }
261
447
  }
262
448
  function providersPayloadOf(json) {
263
- const providersArr = t(json, "providers");
449
+ const providersArr = n(json, "providers");
264
450
  const providers = Array.isArray(providersArr) ? providersArr.map((item) => providerOf(item)) : [];
265
- const currentRaw = t(json, "current");
451
+ const currentRaw = n(json, "current");
266
452
  const current = {
267
- provider: strOf(t(currentRaw, "provider")),
268
- model: strOf(t(currentRaw, "model")),
269
- keyIsDynamic: t(currentRaw, "keyIsDynamic") === true,
270
- url: strOf(t(currentRaw, "url"))
453
+ provider: strOf(n(currentRaw, "provider")),
454
+ model: strOf(n(currentRaw, "model")),
455
+ keyIsDynamic: n(currentRaw, "keyIsDynamic") === true,
456
+ url: strOf(n(currentRaw, "url"))
271
457
  };
272
- const sourceRaw = t(json, "source");
273
- const verifyRaw = t(json, "endpointVerify");
458
+ const sourceRaw = n(json, "source");
459
+ const verifyRaw = n(json, "endpointVerify");
274
460
  const endpointVerify = verifyRaw === null || verifyRaw === void 0 ? null : {
275
- ok: t(verifyRaw, "ok") === true,
276
- message: strOf(t(verifyRaw, "message"))
461
+ ok: n(verifyRaw, "ok") === true,
462
+ message: strOf(n(verifyRaw, "message"))
277
463
  };
278
464
  return {
279
465
  providers,
280
466
  current,
281
- getCredReady: t(json, "getCredReady") === true,
467
+ getCredReady: n(json, "getCredReady") === true,
282
468
  source: {
283
- status: strOf(t(sourceRaw, "status")),
284
- message: strOf(t(sourceRaw, "message"))
469
+ status: strOf(n(sourceRaw, "status")),
470
+ message: strOf(n(sourceRaw, "message"))
285
471
  },
286
- csrf: strOf(t(json, "csrf")),
287
472
  endpointVerify,
288
- ocrBinary: binaryOf(t(json, "ocrBinary"))
473
+ ocrBinary: binaryOf(n(json, "ocrBinary"))
289
474
  };
290
475
  }
291
476
  /** 三行表单控件(数字/文本/下拉)共用的类名 = CARD_CSS 里 `.ocr-select{…}` 那条规则。
@@ -343,12 +528,6 @@ function cardStore(scope) {
343
528
  }
344
529
  };
345
530
  }
346
- /** touched 层与快照的差异字段(值语义比较;undefined 与缺失等价)。 */
347
- function diffTouched(touched, value) {
348
- const out = [];
349
- for (const key of Object.keys(touched)) if (JSON.stringify(touched[key] ?? null) !== JSON.stringify(value[key] ?? null)) out.push(key);
350
- return out;
351
- }
352
531
  function SaveBar(props) {
353
532
  const { t } = props;
354
533
  const disabled = !props.writable || props.busy;
@@ -543,16 +722,53 @@ function currentConfigText(t, current) {
543
722
  keyPart: t(current.keyIsDynamic ? "dynamicKey" : "plainKeyWarning")
544
723
  });
545
724
  }
725
+ /** 装法枚举到文案键:查表而不是嵌套三元(本仓 lint 禁嵌套三元),查不到就是「未识别」那一档。 */
726
+ const CHANNEL_KEYS = {
727
+ brew: "channelBrew",
728
+ npm: "channelNpm"
729
+ };
730
+ /** 那份 CLI 是怎么装上的,翻成人话。判不出来源(含 host 没报这一档)不猜。 */
731
+ function channelText(t, channel) {
732
+ return t(CHANNEL_KEYS[channel ?? ""] ?? "channelUnknown");
733
+ }
546
734
  /**
547
735
  * 外部 CLI 可得性那一行的文本。三档来源与「宿主没报」四种说法,判据全在 host 侧
548
736
  * (`lib/cli.ts` 的 resolveOcrAvailability),卡片只翻译结论——两处各算各的就会漂。
549
737
  */
550
738
  function binaryStatusText(t, binary) {
551
739
  if (binary === null) return t("binaryUnknown");
552
- if (binary.source === "bundled") return t("binaryBundled");
553
- if (binary.source === "path") return t("binaryPath", { path: binary.path ?? "" });
740
+ if (binary.source === "bundled") return t("binaryBundled", {
741
+ path: binary.path ?? "",
742
+ channel: channelText(t, binary.channel)
743
+ });
744
+ if (binary.source === "path") return t("binaryPath", {
745
+ path: binary.path ?? "",
746
+ channel: channelText(t, binary.channel)
747
+ });
554
748
  return t("binaryNone");
555
749
  }
750
+ /**
751
+ * 版本核对那一行:「插件按哪一版核对」恒说,「本机是哪一版」只在测过之后才说。
752
+ * 没测过时不编造任何结论,也不在这里重复「点检测」——那句在按钮本身与区块指路里已经有了。
753
+ */
754
+ function cliVersionText(t, binary) {
755
+ if (binary?.expectedVersion === void 0) return "";
756
+ const expected = binary.expectedVersion;
757
+ const lines = [t("versionExpected", { expected })];
758
+ if (binary.measuredVersion !== null) lines.push(binary.measuredVersion === expected ? t("versionMatched", { actual: binary.measuredVersion }) : t("versionDiverged", {
759
+ actual: binary.measuredVersion,
760
+ expected
761
+ }));
762
+ return lines.join(" · ");
763
+ }
764
+ /**
765
+ * 装法那一行:只在两条路都没有候选时出现。已装着的时候这条是噪音——那种情况下用户要的是
766
+ * 「哪一份、什么版本、要不要换」,那两行已经说了。
767
+ */
768
+ function cliInstallText(binary) {
769
+ if (binary?.source !== "none") return "";
770
+ return binary.installHint ?? "";
771
+ }
556
772
  /** 一条错误提示行的类名(多处在用;sonarjs 的重复字面量门禁要求收成常量)。 */
557
773
  const STATUS_ERROR_CLASS = "ocr-status ocr-err";
558
774
  /** 一条成功/失败回执行的类名(动作条、探测回执共用)。 */
@@ -586,6 +802,10 @@ function buildCliStatusRow(deps) {
586
802
  }, label, button);
587
803
  const statusText = binaryStatusText(t, deps.binary);
588
804
  const status = (0, react.createElement)("div", { className: "ocr-hint" }, statusText);
805
+ const versionText = cliVersionText(t, deps.binary);
806
+ const versionLine = versionText === "" ? null : (0, react.createElement)("div", { className: "ocr-hint" }, versionText);
807
+ const hintText = cliInstallText(deps.binary);
808
+ const installLine = hintText === "" ? null : (0, react.createElement)("div", { className: "ocr-hint" }, hintText);
589
809
  const probe = deps.probeMsg ? (0, react.createElement)("div", {
590
810
  className: statusClass(deps.probeMsg.ok),
591
811
  "data-field": "probe-result"
@@ -593,14 +813,18 @@ function buildCliStatusRow(deps) {
593
813
  return (0, react.createElement)("div", {
594
814
  style: { padding: "2px 0" },
595
815
  "data-field": "cli-status"
596
- }, row, status, probe);
816
+ }, row, status, versionLine, installLine, probe);
597
817
  }
598
818
  /**
599
819
  * 徽标用的短文案(标题旁那只标签放不下整句装法)。与 `binaryStatusText` 同一判据、
600
820
  * 不同长度:两处各算一份「哪一档」就会漂,所以入参仍是 host 送的那份 `OcrBinaryView`。
821
+ *
822
+ * 「实测过且与核对版本不一致」压过来源那一档:用户扫一眼列表要看到的结论是「这份 CLI
823
+ * 与本插件不同版本」,来源在哪一行里已经写了。没实测过就不压——那时不一致与否无从谈起。
601
824
  */
602
825
  function cliBadgeText(t, binary) {
603
826
  if (binary === null) return t("badgeUnknown");
827
+ if (binary.expectedVersion !== void 0 && binary.measuredVersion !== null && binary.measuredVersion !== binary.expectedVersion) return t("badgeDiverged");
604
828
  if (binary.source === "bundled") return t("badgeBundled");
605
829
  if (binary.source === "path") return t("badgePath");
606
830
  return t("badgeNone");
@@ -652,15 +876,19 @@ function OcrCliBadge(props) {
652
876
  if (!mine || status === void 0) return null;
653
877
  return buildCliBadge(props.t, status);
654
878
  }
655
- /** 区块体:标题 + 完整状态那一行 + 指路那一句。 */
879
+ /** 区块体:标题 + 完整状态那一行 + 版本核对那一行 + 装法(没装时)+ 指路那一句。 */
656
880
  function buildCliSection(t, status) {
657
881
  const title = (0, react.createElement)("div", { className: CARD_NAME_CLASS }, t("binaryTitle"));
658
882
  const body = (0, react.createElement)("div", { className: "ocr-hint" }, binaryStatusText(t, status));
883
+ const versionText = cliVersionText(t, status);
884
+ const versionLine = versionText === "" ? null : (0, react.createElement)("div", { className: "ocr-hint" }, versionText);
885
+ const hintText = cliInstallText(status);
886
+ const installLine = hintText === "" ? null : (0, react.createElement)("div", { className: "ocr-hint" }, hintText);
659
887
  const hint = (0, react.createElement)("div", { className: "ocr-hint" }, t("binaryProbeHint"));
660
888
  return (0, react.createElement)("div", {
661
889
  style: { padding: "8px 0" },
662
890
  "data-field": "cli-section"
663
- }, title, body, hint);
891
+ }, title, body, versionLine, installLine, hint);
664
892
  }
665
893
  /** 详情页下方的区块:完整状态 + 「版本号要在配置卡片里点检测」的指路。 */
666
894
  function OcrCliSection(props) {
@@ -670,11 +898,15 @@ function OcrCliSection(props) {
670
898
  return buildCliSection(props.t, status);
671
899
  }
672
900
  /**
673
- * 启用指引的内容:一句「两条路都没找到」+ 去详情页 / 收起这两个动作。
901
+ * 启用指引的内容:一句「两条路都没找到」+ 带版本的装法 + 去详情页 / 收起这两个动作。
674
902
  * 动作回调由宿主给(`onOpenDetails` 顺带把用户送到本包配置页,那里才有「检测」按钮)。
903
+ * @param t - 文案口。
904
+ * @param props - 只取那两个动作回调。
905
+ * @param install - 装法那一句(host 按核对版本与部署偏好组好的原文)。
675
906
  */
676
- function buildCliActivation(t, props) {
907
+ function buildCliActivation(t, props, install) {
677
908
  const text = (0, react.createElement)("div", { className: STATUS_ERROR_CLASS }, t("binaryNone"));
909
+ const installLine = install === "" ? null : (0, react.createElement)("div", { className: "ocr-hint" }, install);
678
910
  const details = (0, react.createElement)("button", {
679
911
  className: "ocr-btn",
680
912
  type: "button",
@@ -694,7 +926,7 @@ function buildCliActivation(t, props) {
694
926
  gap: 8
695
927
  },
696
928
  "data-field": "cli-activation"
697
- }, text, details, dismiss);
929
+ }, text, installLine, details, dismiss);
698
930
  }
699
931
  /**
700
932
  * 启用后的一次性指引:只在「两条路都没找到 ocr」那一刻说话。
@@ -707,7 +939,7 @@ function OcrCliActivation(props) {
707
939
  const mine = props.packageName === BUNDLE_PKG;
708
940
  const status = useCliStatus(mine, props.loadCliStatus);
709
941
  if (!mine || status?.source !== "none") return null;
710
- return buildCliActivation(props.t, props);
942
+ return buildCliActivation(props.t, props, cliInstallText(status));
711
943
  }
712
944
  /** 数据齐(source.status === "ready")那一支:provider/model 两行 + 三个动作按钮 +
713
945
  * 当前配置与 key 两行提示。拆出来是因为这一支画的是整块表单,与上面三条「一行提示」
@@ -938,16 +1170,21 @@ function buildSettingsSection(deps, writable, setField) {
938
1170
  const statusHintNode = deps.statusHint !== null && deps.statusHint !== "" ? (0, react.createElement)("div", { className: "ocr-hint" }, deps.statusHint) : null;
939
1171
  return (0, react.createElement)("div", { style: { padding: "2px 0" } }, statusHintNode, effortRow, languageRow, verifyRow, maxCommentsRow, timeoutRow, configPathRow, saveRow);
940
1172
  }
941
- /** 读 providers 端点(卡片唯一的 GET):失败只落 fetchError 文本,不抛穿渲染。 */
942
- async function refreshProviders(sinks) {
1173
+ /**
1174
+ * 读设置页载荷(卡片唯一的数据入口):失败只落 fetchError 文本,不抛穿渲染。
1175
+ * 拒绝回执(`ok:false`)里的 error 就是「为什么读不到」的可读原因;只报一句
1176
+ * 「读取失败」等于把最有用的半句丢掉。
1177
+ */
1178
+ async function refreshProviders(reader, t, sinks) {
943
1179
  sinks.setFetchError(null);
944
1180
  try {
945
- const res = await fetch(PROVIDERS_URL, { headers: { accept: "application/json" } });
946
- if (!res.ok) {
947
- const detail = strOf(t(await res.json().catch(() => ({})), "error"));
948
- throw new Error(detail === "" ? `HTTP ${res.status}` : detail);
1181
+ if (reader === void 0) throw new Error(t("remoteUnavailable"));
1182
+ const json = await reader.providers();
1183
+ if (n(json, "ok") === false) {
1184
+ const detail = strOf(n(json, "error"));
1185
+ throw new Error(detail === "" ? t("remoteUnavailable") : detail);
949
1186
  }
950
- const payload = providersPayloadOf(await res.json());
1187
+ const payload = providersPayloadOf(json);
951
1188
  sinks.setData(payload);
952
1189
  return payload;
953
1190
  } catch (error) {
@@ -955,49 +1192,58 @@ async function refreshProviders(sinks) {
955
1192
  return null;
956
1193
  }
957
1194
  }
958
- /**
959
- * 写端点统一出口:回填宿主下发的 x-ocr-csrf token(宿主只接受带 token 的
960
- * POST,sec-fetch-site 挡不住本地进程)。宿主每次 apply 会换 token,页面开着
961
- * 时它可能已过期 → 403 就重取 token 重试一次,避免卡片变成「点什么都没反应」。
962
- */
963
- async function postWithCsrf(url, body, deps) {
964
- const request = (token) => fetch(url, {
965
- method: "POST",
966
- headers: {
967
- [CSRF_HEADER]: token,
968
- ...body === void 0 ? {} : { "content-type": "application/json" }
969
- },
970
- ...body === void 0 ? {} : { body }
971
- });
972
- const first = await request(deps.csrf);
973
- if (first.status !== 403) return first;
974
- return await request((await deps.refresh())?.csrf ?? "");
1195
+ /** 把读取器接成动作函数认的那个 `post` 形状:拒绝回执原样交回,传输失败才抛。 */
1196
+ function readerPost(reader, t) {
1197
+ return async (action, body) => {
1198
+ if (reader === void 0) throw new Error(t("remoteUnavailable"));
1199
+ switch (action) {
1200
+ case "select": {
1201
+ const provider = strOf(n(body, "provider"));
1202
+ const model = strOf(n(body, "model"));
1203
+ const reply = await reader.select(provider, model);
1204
+ return { json: () => Promise.resolve(reply) };
1205
+ }
1206
+ case "migrate": {
1207
+ const reply = await reader.migrate();
1208
+ return { json: () => Promise.resolve(reply) };
1209
+ }
1210
+ case "test": {
1211
+ const reply = await reader.test();
1212
+ return { json: () => Promise.resolve(reply) };
1213
+ }
1214
+ case "probe": {
1215
+ const reply = await reader.probe();
1216
+ return { json: () => Promise.resolve(reply) };
1217
+ }
1218
+ default: throw new Error(`unknown remote action: ${String(action)}`);
1219
+ }
1220
+ };
975
1221
  }
976
1222
  /** POST select:把选中的 provider/model 写进 OCR 配置,回执里按 autoVerify 决定是否带 llm test。 */
977
1223
  async function runApplySelection(deps) {
978
- const { t: t$1, effectiveProvider, effectiveModel } = deps;
1224
+ const { t, effectiveProvider, effectiveModel } = deps;
979
1225
  if (!effectiveProvider || !effectiveModel) {
980
1226
  deps.setActionMsg({
981
1227
  ok: false,
982
- text: t$1("pickProviderModel")
1228
+ text: t("pickProviderModel")
983
1229
  });
984
1230
  return;
985
1231
  }
986
1232
  deps.setBusy("apply");
987
1233
  deps.setActionMsg(null);
988
1234
  try {
989
- const selJson = await (await deps.post(SELECT_URL, JSON.stringify({
1235
+ const selJson = await (await deps.post("select", {
990
1236
  provider: effectiveProvider,
991
1237
  model: effectiveModel
992
- }))).json();
993
- if (t(selJson, "ok") === true) {
1238
+ })).json();
1239
+ if (n(selJson, "ok") === true) {
994
1240
  let testText;
995
- const llmTestRaw = t(selJson, "llmTest");
996
- if (e(llmTestRaw)) {
997
- const testOutput = strOf(t(llmTestRaw, "output")).slice(0, 400);
998
- testText = t(llmTestRaw, "ok") === true ? t$1("llmTestPassed") : `${t$1("llmTestFailed")}${testOutput}`;
999
- } else testText = t$1("notVerified");
1000
- const appliedText = t$1("applied", {
1241
+ const llmTestRaw = n(selJson, "llmTest");
1242
+ if (e$2(llmTestRaw)) {
1243
+ const testOutput = strOf(n(llmTestRaw, "output")).slice(0, 400);
1244
+ testText = n(llmTestRaw, "ok") === true ? t("llmTestPassed") : `${t("llmTestFailed")}${testOutput}`;
1245
+ } else testText = t("notVerified");
1246
+ const appliedText = t("applied", {
1001
1247
  provider: effectiveProvider,
1002
1248
  model: effectiveModel,
1003
1249
  test: testText
@@ -1008,14 +1254,14 @@ async function runApplySelection(deps) {
1008
1254
  });
1009
1255
  deps.refresh();
1010
1256
  } else {
1011
- const failure = strOf(t(selJson, "error"));
1257
+ const failure = strOf(n(selJson, "error"));
1012
1258
  deps.setActionMsg({
1013
1259
  ok: false,
1014
- text: failure === "" ? t$1("applyFailed") : failure
1260
+ text: failure === "" ? t("applyFailed") : failure
1015
1261
  });
1016
1262
  }
1017
1263
  } catch (error) {
1018
- const failedText = `${t$1("requestFailed")}${errorSummary(error)}`;
1264
+ const failedText = `${t("requestFailed")}${errorSummary(error)}`;
1019
1265
  deps.setActionMsg({
1020
1266
  ok: false,
1021
1267
  text: failedText
@@ -1026,24 +1272,24 @@ async function runApplySelection(deps) {
1026
1272
  }
1027
1273
  /** POST migrate:明文 api_key 一键迁到 api_key_cmd,回执把迁移/跳过两个名单拼成一行。 */
1028
1274
  async function runMigrateKeys(deps) {
1029
- const { t: t$2 } = deps;
1275
+ const { t } = deps;
1030
1276
  deps.setBusy("migrate");
1031
1277
  deps.setActionMsg(null);
1032
1278
  try {
1033
- const json = await (await deps.post(MIGRATE_URL)).json();
1034
- const migratedVal = t(json, "migrated");
1035
- const skippedVal = t(json, "skippedUnknown");
1279
+ const json = await (await deps.post("migrate")).json();
1280
+ const migratedVal = n(json, "migrated");
1281
+ const skippedVal = n(json, "skippedUnknown");
1036
1282
  const migrated = Array.isArray(migratedVal) ? migratedVal.filter((item) => typeof item === "string") : [];
1037
1283
  const skipped = Array.isArray(skippedVal) ? skippedVal.filter((item) => typeof item === "string") : [];
1038
- const ok = t(json, "ok") === true;
1039
- const head = ok ? (migrated.length > 0 ? t$2("migratedPrefix") + migrated.join(", ") : t$2("noPlainKey")) + (skipped.length > 0 ? t$2("skippedPrefix") + skipped.join(", ") : "") : t$2("migrateFailed");
1284
+ const ok = n(json, "ok") === true;
1285
+ const head = ok ? (migrated.length > 0 ? t("migratedPrefix") + migrated.join(", ") : t("noPlainKey")) + (skipped.length > 0 ? t("skippedPrefix") + skipped.join(", ") : "") : t("migrateFailed");
1040
1286
  deps.setActionMsg({
1041
1287
  ok,
1042
1288
  text: head
1043
1289
  });
1044
1290
  deps.refresh();
1045
1291
  } catch (error) {
1046
- const failedText = `${t$2("requestFailed")}${errorSummary(error)}`;
1292
+ const failedText = `${t("requestFailed")}${errorSummary(error)}`;
1047
1293
  deps.setActionMsg({
1048
1294
  ok: false,
1049
1295
  text: failedText
@@ -1054,19 +1300,19 @@ async function runMigrateKeys(deps) {
1054
1300
  }
1055
1301
  /** POST test:手动触发 ocr llm test,输出原样回显在动作条上。 */
1056
1302
  async function runTestConnection(deps) {
1057
- const { t: t$3 } = deps;
1303
+ const { t } = deps;
1058
1304
  deps.setBusy("test");
1059
1305
  deps.setActionMsg(null);
1060
1306
  try {
1061
- const json = await (await deps.post(TEST_URL)).json();
1062
- const ok = t(json, "ok") === true;
1063
- const testOutput = strOf(t(json, "output"));
1307
+ const json = await (await deps.post("test")).json();
1308
+ const ok = n(json, "ok") === true;
1309
+ const testOutput = strOf(n(json, "output"));
1064
1310
  deps.setActionMsg({
1065
1311
  ok,
1066
- text: (ok ? t$3("llmTestPassed") : t$3("llmTestFailed")) + testOutput
1312
+ text: (ok ? t("llmTestPassed") : t("llmTestFailed")) + testOutput
1067
1313
  });
1068
1314
  } catch (error) {
1069
- const failedText = `${t$3("requestFailed")}${errorSummary(error)}`;
1315
+ const failedText = `${t("requestFailed")}${errorSummary(error)}`;
1070
1316
  deps.setActionMsg({
1071
1317
  ok: false,
1072
1318
  text: failedText
@@ -1082,23 +1328,28 @@ async function runTestConnection(deps) {
1082
1328
  * 一处会跟着漂的判据;那段文本本来就带在页面上供人选中复制(含上游给的 `npm i -g …`)。
1083
1329
  */
1084
1330
  async function runProbe(deps) {
1085
- const { t: t$4 } = deps;
1331
+ const { t } = deps;
1086
1332
  deps.setBusy("probe");
1087
1333
  deps.setProbeMsg(null);
1088
1334
  try {
1089
- const json = await (await deps.post(PROBE_URL)).json();
1090
- const ok = t(json, "ok") === true;
1091
- const head = ok ? t$4("probeVersion", { version: strOf(t(json, "version")) }) : t$4("probeReason", { reason: strOf(t(json, "reason")) });
1092
- const output = strOf(t(json, "output"));
1335
+ const json = await (await deps.post("probe")).json();
1336
+ const ok = n(json, "ok") === true;
1337
+ const head = ok ? t("probeVersion", { version: strOf(n(json, "version")) }) : t("probeReason", { reason: strOf(n(json, "reason")) });
1338
+ const output = strOf(n(json, "output"));
1339
+ const lines = [
1340
+ head,
1341
+ strOf(n(json, "changeText")),
1342
+ output
1343
+ ].filter((line) => line !== "");
1093
1344
  deps.setProbeMsg({
1094
1345
  ok,
1095
- text: output === "" ? head : `${head}\n${output}`
1346
+ text: lines.join("\n")
1096
1347
  });
1097
1348
  deps.refresh();
1098
1349
  } catch (error) {
1099
1350
  deps.setProbeMsg({
1100
1351
  ok: false,
1101
- text: `${t$4("requestFailed")}${errorSummary(error)}`
1352
+ text: `${t("requestFailed")}${errorSummary(error)}`
1102
1353
  });
1103
1354
  } finally {
1104
1355
  deps.setBusy(null);
@@ -1110,7 +1361,7 @@ async function runProbe(deps) {
1110
1361
  * 传输失败仍以 rejection 表达。 */
1111
1362
  async function saveSettingsDraft(deps) {
1112
1363
  const { t, value, touched } = deps;
1113
- const keys = diffTouched(touched, value);
1364
+ const keys = e(touched, value);
1114
1365
  if (keys.length === 0) return;
1115
1366
  deps.setSettingsBusy(true);
1116
1367
  deps.setSaveError(null);
@@ -1173,17 +1424,14 @@ function OcrCard(props) {
1173
1424
  const [busy, setBusy] = (0, react.useState)(null);
1174
1425
  const [actionMsg, setActionMsg] = (0, react.useState)(null);
1175
1426
  const [probeMsg, setProbeMsg] = (0, react.useState)(null);
1176
- const refresh = async () => refreshProviders({
1427
+ const refresh = (0, react.useCallback)(async () => refreshProviders(props.reader, t, {
1177
1428
  setData,
1178
1429
  setFetchError
1179
- });
1430
+ }), [props.reader, t]);
1180
1431
  (0, react.useEffect)(() => {
1181
1432
  refresh();
1182
- }, []);
1183
- const post = async (url, body) => postWithCsrf(url, body, {
1184
- csrf: data?.csrf ?? "",
1185
- refresh
1186
- });
1433
+ }, [refresh]);
1434
+ const post = readerPost(props.reader, t);
1187
1435
  const [selProvider, setSelProvider] = (0, react.useState)("");
1188
1436
  const [selModel, setSelModel] = (0, react.useState)("");
1189
1437
  const { effectiveProvider, effectiveModel, chosenProvider, modelOptions } = resolveSelection(data?.providers ?? [], data?.current, selProvider, selModel);
@@ -1205,7 +1453,7 @@ function OcrCard(props) {
1205
1453
  const [touched, setTouched] = (0, react.useState)({});
1206
1454
  const [settingsBusy, setSettingsBusy] = (0, react.useState)(false);
1207
1455
  const [saveError, setSaveError] = (0, react.useState)(null);
1208
- const dirty = diffTouched(touched, value).length > 0;
1456
+ const dirty = e(touched, value).length > 0;
1209
1457
  const setField = (field, draft) => {
1210
1458
  setTouched((prev) => ({
1211
1459
  ...prev,
@@ -1285,11 +1533,7 @@ const inject = [
1285
1533
  "locale"
1286
1534
  ];
1287
1535
  function apply(ctx) {
1288
- if (globalThis.ocrReviewCardApplied === true) return;
1289
- globalThis.ocrReviewCardApplied = true;
1290
- ctx.effect(() => () => {
1291
- globalThis.ocrReviewCardApplied = void 0;
1292
- }, "ocr-review-card: apply claim");
1536
+ if (!e$1(ctx, "ocrReviewCardApplied", "ocr-review-card: apply claim")) return;
1293
1537
  ctx.effect(() => {
1294
1538
  const tag = document.createElement("style");
1295
1539
  tag.id = "ocr-review-card-css";
@@ -1303,6 +1547,7 @@ function apply(ctx) {
1303
1547
  const store = cardStore(scope);
1304
1548
  ctx.effect(() => ctx.locale.register(NS, UI_MESSAGES), "ocr-review-card: locale dictionaries");
1305
1549
  const t = ctx.locale.bind(NS);
1550
+ const reader = createOcrReader(ctx);
1306
1551
  ctx.slots.inject("plugins.bundle.config", () => {
1307
1552
  return ctx.slots.register({
1308
1553
  name: "plugins.bundle.config",
@@ -1310,13 +1555,14 @@ function apply(ctx) {
1310
1555
  inject: () => ({
1311
1556
  t,
1312
1557
  hooks: { card: store },
1313
- set: (field, value) => scope.set(field, value)
1558
+ set: (field, value) => scope.set(field, value),
1559
+ ...reader === void 0 ? {} : { reader }
1314
1560
  })
1315
1561
  }, OcrCard);
1316
1562
  });
1317
1563
  const cliShare = {
1318
1564
  t,
1319
- loadCliStatus
1565
+ loadCliStatus: () => loadCliStatus(reader)
1320
1566
  };
1321
1567
  ctx.slots.inject("plugins.detail.badge", () => ctx.slots.register({
1322
1568
  name: "plugins.detail.badge",
@@ -1355,8 +1601,9 @@ exports.buildProviderSection = buildProviderSection;
1355
1601
  exports.buildSettingsSection = buildSettingsSection;
1356
1602
  exports.cardStore = cardStore;
1357
1603
  exports.cliBadgeText = cliBadgeText;
1604
+ exports.cliInstallText = cliInstallText;
1605
+ exports.cliVersionText = cliVersionText;
1358
1606
  exports.currentConfigText = currentConfigText;
1359
- exports.diffTouched = diffTouched;
1360
1607
  exports.inject = inject;
1361
1608
  exports.isOwnSubject = isOwnSubject;
1362
1609
  exports.loadCliStatus = loadCliStatus;