@jayyuen66/dsh-zvec-grep 0.1.4 → 0.1.5

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 (6) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +26 -20
  3. package/README.zh-CN.md +28 -20
  4. package/client.js +184 -137
  5. package/host.js +1260 -1327
  6. package/package.json +48 -43
package/client.js CHANGED
@@ -82,6 +82,13 @@ const LOCAL_EMBEDDINGS = [
82
82
  }
83
83
  ];
84
84
  //#endregion
85
+ //#region node_modules/@jayyuen66/dsh-plugin-shared/dist/card-diff.js
86
+ function e$1(e, t) {
87
+ let n = [];
88
+ for (let r of Object.keys(e)) JSON.stringify(e[r] ?? null) !== JSON.stringify(t[r] ?? null) && n.push(r);
89
+ return n;
90
+ }
91
+ //#endregion
85
92
  //#region lib/card-draft.ts
86
93
  /** 草稿优先取值:touched 有该键(哪怕值是 undefined=待清空)即用草稿。 */
87
94
  function draftOf(touched, value, field) {
@@ -92,11 +99,6 @@ function numberText(raw, fallback) {
92
99
  return typeof raw === "number" && Number.isFinite(raw) ? String(raw) : fallback;
93
100
  }
94
101
  //#endregion
95
- //#region node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
96
- function e$1(e) {
97
- return typeof e == `object` && !!e && !Array.isArray(e);
98
- }
99
- //#endregion
100
102
  //#region lib/card-logic.ts
101
103
  /**
102
104
  * 引导端点交回的守护进程就绪态该显示哪一行。
@@ -243,32 +245,130 @@ function parseRebuildPoll(body, t) {
243
245
  output: outputText.length > 0 ? `${reason}\n${outputText}` : reason
244
246
  };
245
247
  }
246
- /**
247
- * 响应不健康的可行动描述;健康返回 null。
248
- * @param ok - res.ok
249
- * @param status - res.status(403 单列:CSRF token 过期时卡片要「重取 token 重试」)
250
- * @param contentType - res.headers.get('content-type') ?? ''
251
- * @param t - 文案取值(官方 locale 的 translator)
252
- */
253
- function httpProblem(ok, status, contentType, t) {
254
- if (status === 403) return t("httpForbidden");
255
- if (!ok) return t("httpFailed", { status });
256
- if (!contentType.toLowerCase().includes("application/json")) return t("httpNotJson", { contentType: contentType.length > 0 ? contentType : t("contentTypeMissing") });
257
- return null;
248
+ //#endregion
249
+ //#region node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
250
+ function e(e) {
251
+ return typeof e == `object` && !!e && !Array.isArray(e);
258
252
  }
259
- /** JSON 文本 → 对象;非对象/解析失败返回 null(调用方给可读错误)。 */
260
- function parseJsonRecord(text) {
261
- let parsed;
262
- try {
263
- parsed = JSON.parse(text);
264
- } catch {
265
- return null;
253
+ //#endregion
254
+ //#region src/rebuild-reader.ts
255
+ const REBUILD_NAMESPACE = "zvecGrepRebuild";
256
+ /** 网关给命名空间注册的**服务键**:`remote.<namespace>`。它在 `$mount` 完成之后才存在,
257
+ * 所以只能在挂载后按这个键去读,而不是提前 inject。 */
258
+ const REBUILD_SERVICE_KEY = `remote.${REBUILD_NAMESPACE}`;
259
+ /** 卡片所在 bundle 的包名(`$mount` 的 `package` 位与槽位键同源,见 client-entry.ts 的 BUNDLE_PKG)。 */
260
+ const PACKAGE_NAME = "@jayyuen66/dsh-zvec-grep";
261
+ /** 把宿主那三个方法挂到客户端远程面上的描述符(`id` 的形状照生成器:`<包>#<命名空间>/<方法>`)。
262
+ * 导出它只为一件事:`test/rebuild-remote.test.ts` 拿它与宿主侧 `remoteMethods()` 的标记对质
263
+ * —— 两侧分叉时卡片不会报错,只会"读不到",所以那条比较必须在门禁里。 */
264
+ const REBUILD_DESCRIPTORS = [
265
+ {
266
+ id: `${PACKAGE_NAME}#${REBUILD_NAMESPACE}/roots`,
267
+ service: REBUILD_NAMESPACE,
268
+ namespace: REBUILD_NAMESPACE,
269
+ method: "roots",
270
+ invocation: { kind: "direct" },
271
+ parameters: [],
272
+ result: { mode: "src-json" }
273
+ },
274
+ {
275
+ id: `${PACKAGE_NAME}#${REBUILD_NAMESPACE}/rebuild`,
276
+ service: REBUILD_NAMESPACE,
277
+ namespace: REBUILD_NAMESPACE,
278
+ method: "rebuild",
279
+ invocation: { kind: "direct" },
280
+ parameters: [{
281
+ name: "request",
282
+ wire: "request",
283
+ source: "json",
284
+ codec: {
285
+ mode: "strict",
286
+ typeSymbol: `${PACKAGE_NAME}#rebuild-request`,
287
+ create: () => ({ parse(value) {
288
+ if (!e(value) || typeof value["root"] !== "string") throw new TypeError("rebuild request requires a string root");
289
+ return { root: value["root"] };
290
+ } })
291
+ }
292
+ }],
293
+ result: { mode: "src-json" }
294
+ },
295
+ {
296
+ id: `${PACKAGE_NAME}#${REBUILD_NAMESPACE}/status`,
297
+ service: REBUILD_NAMESPACE,
298
+ namespace: REBUILD_NAMESPACE,
299
+ method: "status",
300
+ invocation: { kind: "direct" },
301
+ parameters: [{
302
+ name: "request",
303
+ wire: "request",
304
+ source: "json",
305
+ codec: {
306
+ mode: "strict",
307
+ typeSymbol: `${PACKAGE_NAME}#rebuild-status-request`,
308
+ create: () => ({ parse(value) {
309
+ if (!e(value) || typeof value["jobId"] !== "string") throw new TypeError("rebuild status request requires a string jobId");
310
+ return { jobId: value["jobId"] };
311
+ } })
312
+ }
313
+ }],
314
+ result: { mode: "src-json" }
266
315
  }
267
- return e$1(parsed) ? parsed : null;
316
+ ];
317
+ /** 这个值能当远程面用吗(只核我们要调的那一位;服务来自别的实现或版本时保守当作没有)。 */
318
+ const isRemoteMounter = (value) => e(value) && typeof value["$mount"] === "function";
319
+ /** 同上:命名空间服务(挂载之后才有,缺它说明网关没认这枚贡献)。 */
320
+ const isRebuildNamespace = (value) => e(value) && typeof value["roots"] === "function" && typeof value["rebuild"] === "function" && typeof value["status"] === "function";
321
+ /**
322
+ * 造出真正的读取器(挂载一次 + 每次读命名空间服务)。
323
+ * @param ctx - 客户端上下文
324
+ * @param remote - 已核过形状的远程面
325
+ * @returns 读取器
326
+ */
327
+ function buildRebuildReader(ctx, remote) {
328
+ let mounted;
329
+ const namespaceOf = async () => {
330
+ mounted ??= remote.$mount({
331
+ package: PACKAGE_NAME,
332
+ descriptors: REBUILD_DESCRIPTORS
333
+ });
334
+ await mounted;
335
+ const namespace = ctx.get?.(REBUILD_SERVICE_KEY, false);
336
+ if (!isRebuildNamespace(namespace)) throw new Error(`${REBUILD_SERVICE_KEY} 未提供:宿主网关没有挂上这枚命名空间`);
337
+ return namespace;
338
+ };
339
+ return {
340
+ async roots() {
341
+ const result = await (await namespaceOf()).roots();
342
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
343
+ return result.value;
344
+ },
345
+ async rebuild(root) {
346
+ const result = await (await namespaceOf()).rebuild({ root });
347
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
348
+ if (!result.value.ok) throw new Error(result.value.error);
349
+ return result.value;
350
+ },
351
+ async status(jobId) {
352
+ const result = await (await namespaceOf()).status({ jobId });
353
+ if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
354
+ if (!result.value.ok) throw new Error(result.value.error);
355
+ return { ...result.value };
356
+ }
357
+ };
268
358
  }
269
- /** 端点统一应答形状:`{ ok: true, … }` 才算成功。 */
270
- function isOkBody(body) {
271
- return body["ok"] === true;
359
+ /**
360
+ * 造一个「读宿主侧工作区重建」的读取器;**当前部署没有远程面时返回 `undefined`**
361
+ * (卡片照常渲染,只是点重建时给出错误 —— 与 host 侧可选读面同一条口径)。
362
+ *
363
+ * `$mount` 是**幂等**的(挂进本 fiber,随卡片卸载自动撤),所以这里缓存那枚 promise:
364
+ * 同一次会话里反复轮询只挂一次。
365
+ *
366
+ * @param ctx - 客户端上下文(只用 `get` 一位)
367
+ * @returns 读取器;没有远程面时 `undefined`
368
+ */
369
+ function createRebuildReader(ctx) {
370
+ const remote = ctx.get?.("remote");
371
+ return isRemoteMounter(remote) ? buildRebuildReader(ctx, remote) : void 0;
272
372
  }
273
373
  //#endregion
274
374
  //#region src/ui-messages.ts
@@ -314,16 +414,11 @@ const UI_MESSAGES = {
314
414
  rebuildExitCode: "重建进程退出码 {exitCode}(zg 未安装/权限不足/沙箱拒绝都会走到这里)",
315
415
  rebuildMissingJobId: "启动重建失败:应答缺 jobId",
316
416
  rebuildRootNotAbsolute: "root 必须是绝对路径(以 / 开头)",
417
+ rebuildUnavailable: "宿主没有提供工作区重建读面(未装远程服务)",
317
418
  modelOption: "{reference}({dimension}维)",
318
419
  backendLlamaCpp: "llama-cpp(原生,需 node-llama-cpp)",
319
420
  backendTransformersJs: "transformers-js(纯 JS ONNX)",
320
- backendModel2Vec: "model2vec(纯 JS worker,最轻)",
321
- httpForbidden: "403:请求被拒绝(同源校验或 CSRF token 失效)",
322
- httpFailed: "请求失败(HTTP {status})",
323
- httpNotJson: "响应不是 JSON(content-type={contentType}):重建端点未注册或路径被前端兜住了",
324
- contentTypeMissing: "缺省",
325
- notJsonBody: "响应不是 JSON 对象:{url}",
326
- requestRejected: "请求未被接受"
421
+ backendModel2Vec: "model2vec(纯 JS worker,最轻)"
327
422
  },
328
423
  en: {
329
424
  cardTitle: "zvec-grep (zg)",
@@ -366,73 +461,61 @@ const UI_MESSAGES = {
366
461
  rebuildExitCode: "the rebuild process exited with code {exitCode} (missing zg, insufficient permissions and sandbox denials all land here)",
367
462
  rebuildMissingJobId: "failed to start the rebuild: the response has no jobId",
368
463
  rebuildRootNotAbsolute: "root must be an absolute path (starting with /)",
464
+ rebuildUnavailable: "the host does not expose the rebuild Remote API",
369
465
  modelOption: "{reference} ({dimension} dims)",
370
466
  backendLlamaCpp: "llama-cpp (native, requires node-llama-cpp)",
371
467
  backendTransformersJs: "transformers-js (pure JS ONNX)",
372
- backendModel2Vec: "model2vec (pure JS worker, lightest)",
373
- httpForbidden: "403: request rejected (same-origin check or expired CSRF token)",
374
- httpFailed: "request failed (HTTP {status})",
375
- httpNotJson: "response is not JSON (content-type={contentType}): the rebuild endpoint is not registered, or a front-end fallback caught the path",
376
- contentTypeMissing: "unset",
377
- notJsonBody: "response is not a JSON object: {url}",
378
- requestRejected: "the request was not accepted"
468
+ backendModel2Vec: "model2vec (pure JS worker, lightest)"
379
469
  }
380
470
  };
381
471
  //#endregion
382
472
  //#region node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
383
- function e(e) {
473
+ function t(e) {
384
474
  let t = Object.getOwnPropertyDescriptor(e, `message`);
385
475
  return t !== void 0 && `value` in t && typeof t.value == `string` ? t.value : void 0;
386
476
  }
387
- function t(n, r) {
388
- if (r.has(n)) return `<circular cause>`;
389
- r.add(n);
477
+ function n(e, r) {
478
+ if (r.has(e)) return `<circular cause>`;
479
+ r.add(e);
390
480
  try {
391
- if (!(n instanceof Error)) {
392
- if (typeof n == `object` && n) {
393
- let t = e(n);
394
- if (t !== void 0) return t;
481
+ if (!(e instanceof Error)) {
482
+ if (typeof e == `object` && e) {
483
+ let n = t(e);
484
+ if (n !== void 0) return n;
395
485
  }
396
- return String(n);
486
+ return String(e);
397
487
  }
398
- let i = n.message === `` ? n.name : n.message, a = n instanceof AggregateError && n.errors.length > 0 ? ` [${n.errors.map((e) => t(e, r)).join(`; `)}]` : ``, o = n.cause === void 0 || n.cause === null ? `` : t(n.cause, r);
488
+ let i = e.message === `` ? e.name : e.message, a = e instanceof AggregateError && e.errors.length > 0 ? ` [${e.errors.map((e) => n(e, r)).join(`; `)}]` : ``, o = e.cause === void 0 || e.cause === null ? `` : n(e.cause, r);
399
489
  return `${i}${a}${o === `` || o === i ? `` : `: ${o}`}`;
400
490
  } catch {
401
491
  return `<unrenderable value>`;
402
492
  } finally {
403
- r.delete(n);
493
+ r.delete(e);
404
494
  }
405
495
  }
406
- function n(e) {
407
- return t(e, /* @__PURE__ */ new Set());
496
+ function r(e) {
497
+ return n(e, /* @__PURE__ */ new Set());
408
498
  }
409
499
  //#endregion
410
500
  //#region src/client-entry.ts
411
501
  const NS = "zvec-grep";
412
502
  /**
413
503
  * `plugins.bundle.config` 的 key = **bundle 的 npm 包名**(不是裸条目 id)。
414
- * 派发证据(installed dsh 0.1.7):
415
- * · dsh-client-ui-plugin-manager/lib/client.js:1821 `renderSlot("plugins.bundle.config",
504
+ * 派发证据(installed dsh 0.2.1-rc.2,按符号核对):
505
+ * · dsh-client-ui-plugin-manager 的 client.js 里 `renderSlot("plugins.bundle.config",
416
506
  * { view: "page" }, { entryKey: pkg.name })`——pkg.name 是 bundle 包名;
417
- * · 同文件 :2698 `configured: ledger.bundles.has(openPkg.name)`,:306/:320 的
418
- * `packageView()` 里 `name: bundle.name`(= bundle 包),所以没有第二条可匹配的 key;
507
+ * · 同文件里 `configured: ledger.bundles.has(openPkg.name)` 与 `packageView()` 的
508
+ * `name: bundle.name`(= bundle 包),所以没有第二条可匹配的 key;
419
509
  * · 同包 lib/types/client/slot-contract.d.ts「A bundle's own configuration,
420
510
  * **keyed by the bundle's package name**」,且 kind 为 `keyed` → `key` 必填;
421
- * · dsh-client-ui-renderer/lib/client.js:1154 逐字相等匹配 `entry.options.key === entryKey`,
422
- * 错一个字符就是「整张卡不渲染」(不是回落、不是报错);
423
- * · 官方占位者 dsh-experimental-client-ui-voice-input/lib/client.js:5659-5661 同样把
424
- * key 写成包名 `@deepseek-ai/dsh-experimental-voice-input-bundle`。
425
- * 行槽(本包未用)则是 `<pkg>#<rowId>`(plugin-manager/lib/client.js:27-28 `rowConfigKey`)。
511
+ * · dsh-client-ui-renderer 的 `entriesOfSlot(...).find((e) => e.options.key === opts?.entryKey)`
512
+ * 是逐字相等匹配,错一个字符就是「整张卡不渲染」(不是回落、不是报错)。
513
+ * 行槽(本包未用)则是 `<pkg>#<rowId>`(同包的 `rowConfigKey(bundle, rowId)`)。
426
514
  * 值 = 本包 package.json 的 name,且必须出现在 profile 的 `dsh.profile.bundles` 里;
427
515
  * test/build-client.test.ts 从 `~/.dsh/profiles/web/package.json` 解析校验,不在此处硬抄。
428
516
  * 设置命名空间**不跟着改**:`ctx.configForms.get(entryId)` 仍吃裸条目 id(见 apply)。
429
517
  */
430
518
  const BUNDLE_PKG = "@jayyuen66/dsh-zvec-grep";
431
- const REBUILD_ROOTS_URL = "/_dsh/zvec-grep/rebuild-roots";
432
- const REBUILD_URL = "/_dsh/zvec-grep/rebuild";
433
- const REBUILD_STATUS_URL = "/_dsh/zvec-grep/rebuild-status";
434
- /** 与 host.ts REBUILD_CSRF_HEADER 一致:动作端点要求回填这个头。 */
435
- const REBUILD_CSRF_HEADER = "x-zvec-grep-csrf";
436
519
  /** 重建轮询间隔(宿主后台进程,2s 足够跟上 zg 的进度输出)。 */
437
520
  const REBUILD_POLL_MS = 2e3;
438
521
  /** 解锁配额/时效的合法上限(与 host Config 的 schema 同范围,输入框与提示共用)。 */
@@ -519,12 +602,6 @@ function PluginCard(props) {
519
602
  const body = open ? (0, react.createElement)("div", { className: "zgc-card-body" }, children) : null;
520
603
  return (0, react.createElement)("li", { className: open ? "zgc-card zgc-card-open" : "zgc-card" }, header, body);
521
604
  }
522
- /** touched 层与快照的差异字段(值语义比较;undefined 与缺失等价)。 */
523
- function diffTouched(touched, value) {
524
- const out = [];
525
- for (const key of Object.keys(touched)) if (JSON.stringify(touched[key] ?? null) !== JSON.stringify(value[key] ?? null)) out.push(key);
526
- return out;
527
- }
528
605
  /** 保存条(全自研插件统一)。 */
529
606
  function SaveBar(props) {
530
607
  const { t } = props;
@@ -796,47 +873,22 @@ function pushFieldWrite(ops, key, draft, set) {
796
873
  else if (key === "grepBudgetPerSearch") ops.push(set("grepBudgetPerSearch", draft));
797
874
  else if (key === "unlockWindowMin") ops.push(set("unlockWindowMin", draft));
798
875
  }
799
- /** 服务端 `{ok:false,error}` 里的可行动文案(无 error 字段给通用兜底)。 */
800
- function serverErrorOf(body, t) {
801
- if (body === null) return null;
802
- const { error } = body;
803
- return typeof error === "string" && error.length > 0 ? error : t("requestRejected");
804
- }
805
- /**
806
- * 一次 JSON 往返:先按 content-type 决定能不能当 JSON 读(未注册的路径会被前端
807
- * SPA fallback 兜成 200 + text/html,直接 JSON.parse 只能给出
808
- * `SyntaxError: Unexpected token '<'`),再让服务端的 error 文案优先于 HTTP 层
809
- * 的笼统描述。
810
- */
811
- async function requestJson(url, t, init) {
812
- const res = await fetch(url, init);
813
- const contentType = res.headers.get("content-type") ?? "";
814
- const record = contentType.toLowerCase().includes("json") ? parseJsonRecord(await res.text()) : null;
815
- const problem = serverErrorOf(record, t) ?? httpProblem(res.ok, res.status, contentType, t);
816
- if (problem !== null) throw new Error(problem);
817
- if (record === null) throw new Error(t("notJsonBody", { url }));
818
- return record;
876
+ /** 读取器缺席时的可行动文案:宿主没装远程面(或网关没挂上这枚命名空间)。 */
877
+ function requireReader(reader, t) {
878
+ if (reader === void 0) throw new Error(t("rebuildUnavailable"));
879
+ return reader;
819
880
  }
820
881
  const NO_ACCESS = {
821
- csrf: "",
822
882
  roots: [],
823
883
  serverReady: void 0
824
884
  };
825
- /** 引导端点应答 → { csrf, roots, serverReady }(字段缺失/类型不对一律当作没拿到)。 */
826
- function readAccess(body) {
827
- const { csrf, roots, serverReady } = body;
828
- return {
829
- csrf: typeof csrf === "string" ? csrf : "",
830
- roots: Array.isArray(roots) ? roots.filter((item) => typeof item === "string") : [],
831
- serverReady: typeof serverReady === "boolean" ? serverReady : void 0
832
- };
833
- }
834
885
  /**
835
- * 「工作区重建」状态机:取 token/白名单 → POST 启动 → 2s 轮询到终态。
886
+ * 「工作区重建」状态机:取白名单 → 起一条重建 → 2s 轮询到终态。
836
887
  * 从 ZgCard 拆出,保持组件体在一屏内可读。
837
888
  * @param t - 取文案(官方 locale 的 translator,随卡片一起下发)。
889
+ * @param reader - 宿主重建读面;`undefined` = 当前部署没有远程面(点重建时报错)。
838
890
  */
839
- function useRebuild(t) {
891
+ function useRebuild(t, reader) {
840
892
  const [root, setRoot] = (0, react.useState)("");
841
893
  const [access, setAccess] = (0, react.useState)(NO_ACCESS);
842
894
  const [rebuild, setRebuild] = (0, react.useState)({
@@ -853,13 +905,17 @@ function useRebuild(t) {
853
905
  (0, react.useEffect)(() => () => {
854
906
  stopPolling();
855
907
  }, []);
856
- /** 拉 CSRF token + 白名单。失败**不**改重建面板:面板 idle 时冒一个红字只是噪音,
908
+ /** 拉白名单 + 就绪态。失败**不**改重建面板:面板 idle 时冒一个红字只是噪音,
857
909
  * 用户真点「重建」时 start() 会把同一错误显示出来。 */
858
910
  const refreshAccess = (0, react.useCallback)(async () => {
859
- const next = readAccess(await requestJson(REBUILD_ROOTS_URL, t));
860
- setAccess(next);
861
- return next;
862
- }, [t]);
911
+ const next = await requireReader(reader, t).roots();
912
+ const view = {
913
+ roots: [...next.roots],
914
+ serverReady: next.serverReady
915
+ };
916
+ setAccess(view);
917
+ return view;
918
+ }, [reader, t]);
863
919
  (0, react.useEffect)(() => {
864
920
  (async () => {
865
921
  try {
@@ -871,7 +927,7 @@ function useRebuild(t) {
871
927
  }, [refreshAccess]);
872
928
  async function pollStatus(jobId) {
873
929
  try {
874
- const poll = parseRebuildPoll(await requestJson(`${REBUILD_STATUS_URL}?jobId=${encodeURIComponent(jobId)}`, t), t);
930
+ const poll = parseRebuildPoll(await requireReader(reader, t).status(jobId), t);
875
931
  if (poll.phase !== "running") stopPolling();
876
932
  setRebuild({
877
933
  phase: poll.phase,
@@ -881,18 +937,15 @@ function useRebuild(t) {
881
937
  stopPolling();
882
938
  setRebuild({
883
939
  phase: "error",
884
- output: n(error)
940
+ output: r(error)
885
941
  });
886
942
  }
887
943
  }
888
- /** 发起一次重建(带 token);成功后进入轮询。 */
889
- async function startOnce(token) {
890
- const body = await requestJson(`${REBUILD_URL}?root=${encodeURIComponent(root.trim())}`, t, {
891
- method: "POST",
892
- headers: { [REBUILD_CSRF_HEADER]: token }
893
- });
894
- const { jobId } = body;
895
- if (!isOkBody(body) || typeof jobId !== "string") throw new Error(t("rebuildMissingJobId"));
944
+ /** 发起一次重建;成功后进入轮询。 */
945
+ async function startOnce() {
946
+ const started = await requireReader(reader, t).rebuild(root.trim());
947
+ if (typeof started.jobId !== "string") throw new TypeError(t("rebuildMissingJobId"));
948
+ const { jobId } = started;
896
949
  pollRef.current = setInterval(() => {
897
950
  pollStatus(jobId);
898
951
  }, REBUILD_POLL_MS);
@@ -911,19 +964,12 @@ function useRebuild(t) {
911
964
  output: t("rebuildStarting")
912
965
  });
913
966
  try {
914
- let token = access.csrf;
915
- if (token === "") token = (await refreshAccess()).csrf;
916
- try {
917
- await startOnce(token);
918
- } catch (error) {
919
- if (access.csrf === "") throw error;
920
- await startOnce((await refreshAccess()).csrf);
921
- }
967
+ await startOnce();
922
968
  } catch (error) {
923
969
  stopPolling();
924
970
  setRebuild({
925
971
  phase: "error",
926
- output: n(error)
972
+ output: r(error)
927
973
  });
928
974
  }
929
975
  }
@@ -945,9 +991,9 @@ function ZgCard(props) {
945
991
  const [touched, setTouched] = (0, react.useState)({});
946
992
  const [busy, setBusy] = (0, react.useState)(false);
947
993
  const [saveError, setSaveError] = (0, react.useState)(null);
948
- const rebuildView = useRebuild(t);
994
+ const rebuildView = useRebuild(t, props.rebuildRemote);
949
995
  const fields = draftFields(touched, value);
950
- const dirty = diffTouched(touched, value).length > 0;
996
+ const dirty = e$1(touched, value).length > 0;
951
997
  const setField = (field, draft) => {
952
998
  setTouched((prev) => ({
953
999
  ...prev,
@@ -955,7 +1001,7 @@ function ZgCard(props) {
955
1001
  }));
956
1002
  };
957
1003
  const save = async () => {
958
- const keys = diffTouched(touched, value);
1004
+ const keys = e$1(touched, value);
959
1005
  if (keys.length === 0) return;
960
1006
  setBusy(true);
961
1007
  setSaveError(null);
@@ -973,7 +1019,7 @@ function ZgCard(props) {
973
1019
  }
974
1020
  } catch (error) {
975
1021
  setBusy(false);
976
- setSaveError(t("saveFailed", { reason: n(error) }));
1022
+ setSaveError(t("saveFailed", { reason: r(error) }));
977
1023
  return;
978
1024
  }
979
1025
  const savedKeys = new Set(keys);
@@ -1032,6 +1078,7 @@ function apply(ctx) {
1032
1078
  const store = cardStore(scope);
1033
1079
  ctx.effect(() => ctx.locale.register(NS, UI_MESSAGES), "zvec-grep-card: locale dictionaries");
1034
1080
  const t = ctx.locale.bind(NS);
1081
+ const rebuildRemote = createRebuildReader(ctx);
1035
1082
  const writeField = async (field, valueDraft) => {
1036
1083
  try {
1037
1084
  return await scope.set(field, valueDraft);
@@ -1056,7 +1103,8 @@ function apply(ctx) {
1056
1103
  t,
1057
1104
  hooks: { card: store },
1058
1105
  set: writeField,
1059
- unset: unsetField
1106
+ unset: unsetField,
1107
+ rebuildRemote
1060
1108
  })
1061
1109
  }, ZgCard);
1062
1110
  });
@@ -1064,7 +1112,6 @@ function apply(ctx) {
1064
1112
  //#endregion
1065
1113
  exports.apply = apply;
1066
1114
  exports.cardStore = cardStore;
1067
- exports.diffTouched = diffTouched;
1068
1115
  exports.draftFields = draftFields;
1069
1116
  exports.inject = inject;
1070
1117
  exports.parseRebuildPoll = parseRebuildPoll;