@lynn123411/dsh-subagent-judge-dispatch 0.6.9 → 0.6.11

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/lib/client.js CHANGED
@@ -384,8 +384,10 @@ var DispatchCardStore = class {
384
384
  listeners = /* @__PURE__ */ new Set();
385
385
  /** One commit at a time: a queued write reads the drafts as they stand when it runs. */
386
386
  queue = Promise.resolve();
387
+ pendingOps = [];
387
388
  form = null;
388
389
  allowedForm = null;
390
+ modelLoadRevision = 0;
389
391
  session = null;
390
392
  remote = null;
391
393
  credentials = null;
@@ -412,8 +414,8 @@ var DispatchCardStore = class {
412
414
  }
413
415
  if (this.allowedForm !== null) {
414
416
  this.offAllowed = this.allowedForm.subscribe(() => void this.loadModels());
415
- void this.loadModels();
416
417
  }
418
+ void this.loadModels();
417
419
  void this.refreshKeyStatus();
418
420
  }
419
421
  getState() {
@@ -427,11 +429,12 @@ var DispatchCardStore = class {
427
429
  }
428
430
  /** Read the Host's allowlist and the adapter catalogue into the model options. */
429
431
  async loadModels() {
432
+ const revision = ++this.modelLoadRevision;
430
433
  const allowedValue = this.allowedForm?.getSnapshot().value;
431
434
  const allowed = Array.isArray(allowedValue?.allowedModels) ? allowedValue.allowedModels : [];
432
435
  let groups = [];
433
436
  let catalogRead = false;
434
- if (this.session !== null) {
437
+ if (this.allowedForm !== null && this.session !== null) {
435
438
  try {
436
439
  const response = await this.session.modelCatalog();
437
440
  if (response.ok) {
@@ -441,6 +444,7 @@ var DispatchCardStore = class {
441
444
  } catch {
442
445
  }
443
446
  }
447
+ if (revision !== this.modelLoadRevision) return;
444
448
  this.state = { ...this.state, models: buildModelOptions(allowed, groups), catalogRead };
445
449
  this.notify();
446
450
  }
@@ -468,7 +472,7 @@ var DispatchCardStore = class {
468
472
  * while holding nothing would discard input mid-typing every time the Host
469
473
  * publishes.
470
474
  */
471
- deriveCommitted() {
475
+ deriveCommitted(notify = true) {
472
476
  const snapshot = this.form?.getSnapshot();
473
477
  const value = snapshot?.value;
474
478
  if (value === void 0) return;
@@ -480,20 +484,24 @@ var DispatchCardStore = class {
480
484
  judgeModel: typeof value.judgeModel === "string" ? value.judgeModel : "",
481
485
  rows
482
486
  };
483
- const staged = (current, previously) => current !== previously;
484
- const before = this.state.committed;
487
+ const staged = (key) => {
488
+ const equal = key === "rows" ? (left, right) => JSON.stringify(left) === JSON.stringify(right) : Object.is;
489
+ const current = this.state[key];
490
+ const pending = this.pendingOps.find((op) => op.path[0] === key);
491
+ return !equal(current, this.state.committed[key]) || pending?.op === "set" && !equal(current, pending.value);
492
+ };
485
493
  this.state = {
486
494
  ...this.state,
487
495
  available: snapshot?.status === "ready",
488
496
  writable: snapshot?.writable ?? false,
489
497
  committed,
490
- enabled: staged(this.state.enabled, before.enabled) ? this.state.enabled : committed.enabled,
491
- logEnabled: staged(this.state.logEnabled, before.logEnabled) ? this.state.logEnabled : committed.logEnabled,
492
- endpointUrl: staged(this.state.endpointUrl, before.endpointUrl) ? this.state.endpointUrl : committed.endpointUrl,
493
- judgeModel: staged(this.state.judgeModel, before.judgeModel) ? this.state.judgeModel : committed.judgeModel,
494
- rows: JSON.stringify(this.state.rows) !== JSON.stringify(before.rows) ? this.state.rows : committed.rows
498
+ enabled: staged("enabled") ? this.state.enabled : committed.enabled,
499
+ logEnabled: staged("logEnabled") ? this.state.logEnabled : committed.logEnabled,
500
+ endpointUrl: staged("endpointUrl") ? this.state.endpointUrl : committed.endpointUrl,
501
+ judgeModel: staged("judgeModel") ? this.state.judgeModel : committed.judgeModel,
502
+ rows: staged("rows") ? this.state.rows : committed.rows
495
503
  };
496
- this.notify();
504
+ if (notify) this.notify();
497
505
  }
498
506
  /**
499
507
  * Stage one edit.
@@ -649,6 +657,7 @@ var DispatchCardStore = class {
649
657
  }
650
658
  return;
651
659
  }
660
+ this.pendingOps = ops;
652
661
  this.state = { ...this.state, writing: section, writeFailed: "", writeError: "" };
653
662
  this.notify();
654
663
  let failure = "";
@@ -668,14 +677,15 @@ var DispatchCardStore = class {
668
677
  failure = error instanceof Error && error.message !== "" ? error.message : this.translate("write.invalid");
669
678
  }
670
679
  }
680
+ if (failure === "") this.deriveCommitted(false);
681
+ this.pendingOps = [];
671
682
  this.state = {
672
683
  ...this.state,
673
684
  writing: "",
674
685
  writeFailed: failure === "" || keyFailed ? "" : section,
675
686
  writeError: keyFailed ? "" : failure
676
687
  };
677
- if (failure === "") this.deriveCommitted();
678
- else this.notify();
688
+ this.notify();
679
689
  }
680
690
  /**
681
691
  * Write one judgement key through the credentials service.
@@ -875,10 +885,14 @@ var en = {
875
885
  "log.resultJudged": "Type {id}",
876
886
  "log.resultHistorical": "Type {id} at the time",
877
887
  "log.resultInherited": "No match",
878
- "log.promptTitle": "Judgement request metrics",
879
- "log.promptDesc": "Judge model, number of offered choices, and input length.",
880
- "log.promptClose": "Close",
881
- "log.promptEmpty": "No judge request was attempted.",
888
+ "log.detailTitle": "Judgement details",
889
+ "log.detailClose": "Close",
890
+ "log.detailModel": "Judge model",
891
+ "log.detailType": "Selected task type",
892
+ "log.detailTask": "Task content",
893
+ "log.detailMissing": "Unavailable in this record",
894
+ "log.detailUnmatched": "No task type selected",
895
+ "log.detailBlankType": "The selected type had no description",
882
896
  "log.copyAnalysis": "Analyze judgement results",
883
897
  "log.analysisPrompt": "Analyze the latest 100 records in dsh-subagent-judge-dispatch/judgements.json under DSH_HOME (default ~/.dsh). Summarize results by type, fallback reasons, and latency. Type numbering can change when the list is edited. Do not infer whether individual tasks were classified correctly from metrics alone.",
884
898
  "log.analysisCopied": "Analysis prompt copied.",
@@ -996,10 +1010,14 @@ var zh = {
996
1010
  "log.resultJudged": "\u7C7B\u578B {id}",
997
1011
  "log.resultHistorical": "\u5F53\u65F6\u7684\u7C7B\u578B {id}",
998
1012
  "log.resultInherited": "\u672A\u5224\u6210",
999
- "log.promptTitle": "\u5224\u65AD\u8BF7\u6C42\u7EDF\u8BA1",
1000
- "log.promptDesc": "\u5224\u65AD\u6A21\u578B\u3001\u53EF\u9009\u7C7B\u578B\u6570\u548C\u8F93\u5165\u957F\u5EA6\u3002",
1001
- "log.promptClose": "\u5173\u95ED",
1002
- "log.promptEmpty": "\u8FD9\u6B21\u6CA1\u6709\u5C1D\u8BD5\u53D1\u9001\u5224\u65AD\u8BF7\u6C42\u3002",
1013
+ "log.detailTitle": "\u5224\u65AD\u8BE6\u60C5",
1014
+ "log.detailClose": "\u5173\u95ED",
1015
+ "log.detailModel": "\u5224\u65AD\u6A21\u578B",
1016
+ "log.detailType": "\u5224\u65AD\u51FA\u7684\u4EFB\u52A1\u7C7B\u578B",
1017
+ "log.detailTask": "\u4EFB\u52A1\u5185\u5BB9",
1018
+ "log.detailMissing": "\u6B64\u8BB0\u5F55\u672A\u4FDD\u5B58",
1019
+ "log.detailUnmatched": "\u672A\u9009\u4E2D\u4EFB\u52A1\u7C7B\u578B",
1020
+ "log.detailBlankType": "\u9009\u4E2D\u7684\u7C7B\u578B\u672A\u586B\u5199\u63CF\u8FF0",
1003
1021
  "log.copyAnalysis": "\u5206\u6790\u5224\u65AD\u7ED3\u679C",
1004
1022
  "log.analysisPrompt": "\u8BF7\u5206\u6790 DSH \u5BB6\u76EE\u5F55\uFF08DSH_HOME\uFF0C\u9ED8\u8BA4 ~/.dsh\uFF09\u4E0B dsh-subagent-judge-dispatch/judgements.json \u4E2D\u6700\u8FD1 100 \u6761\u5224\u65AD\u8BB0\u5F55\u3002\u7EDF\u8BA1\u5404\u7C7B\u578B\u7684\u5224\u65AD\u6B21\u6570\u3001\u5931\u8D25\u539F\u56E0\u548C\u8017\u65F6\u3002\u6E05\u5355\u6539\u52A8\u540E\u7C7B\u578B\u7F16\u53F7\u53EF\u80FD\u53D8\u5316\uFF0C\u4EC5\u51ED\u8FD9\u4E9B\u6307\u6807\u65E0\u6CD5\u5224\u65AD\u5355\u4E2A\u4EFB\u52A1\u662F\u5426\u88AB\u6B63\u786E\u5F52\u7C7B\u3002",
1005
1023
  "log.analysisCopied": "\u5DF2\u590D\u5236\u5206\u6790\u63D0\u793A\u8BCD\u3002",
@@ -1148,6 +1166,9 @@ var CARD_CSS = `
1148
1166
  .dsh-judge-modal { width: min(760px, 100%); max-height: min(85vh, 100%); --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2); --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2); }
1149
1167
  .dsh-judge-prompt { max-height: 58vh; overflow: auto; }
1150
1168
  .dsh-judge-prompt pre { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
1169
+ .dsh-judge-log-details { display: grid; gap: 8px; margin: 0; }
1170
+ .dsh-judge-log-details dt { font-weight: 600; }
1171
+ .dsh-judge-log-details dd { margin: 0 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
1151
1172
  /* \u7C98\u8D34\u6846\uFF1A\u7B49\u5BBD\u663E\u793A\uFF0C\u597D\u8BA9\u8BFB\u8005\u770B\u51FA JSON \u7684\u5C42\u7EA7\uFF1B\u81EA\u5DF1\u6491\u9AD8\u5230\u4E00\u5C4F\u7684\u4E00\u534A\u518D\u6EDA\u52A8\u3002 */
1152
1173
  .dsh-judge-paste { box-sizing: border-box; width: 100%; min-height: 220px; max-height: 45vh; resize: vertical; padding: 10px 12px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: var(--dsw-font-markdown-code-block); }
1153
1174
  .dsh-judge-paste:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-state-business-primary); }
@@ -1697,18 +1718,17 @@ function JudgeDispatchPanel(props) {
1697
1718
  {
1698
1719
  open: detail !== null,
1699
1720
  onClose: () => setDetail(null),
1700
- title: t("log.promptTitle"),
1701
- closeLabel: t("log.promptClose"),
1702
- description: t("log.promptDesc"),
1721
+ title: t("log.detailTitle"),
1722
+ closeLabel: t("log.detailClose"),
1703
1723
  className: "dsh-judge-modal",
1704
- children: detail !== null && (detail.metrics === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dsh-judge-desc", children: t("log.promptEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dsh-judge-prompt", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1705
- import_dsh_client_ui_primitives2.CodeBlock,
1706
- {
1707
- code: JSON.stringify(detail.metrics, null, 2),
1708
- copyLabel: t("preview.copy"),
1709
- copiedLabel: t("preview.copied")
1710
- }
1711
- ) }))
1724
+ children: detail !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("dl", { className: "dsh-judge-prompt dsh-judge-log-details", children: [
1725
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dt", { children: t("log.detailModel") }),
1726
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dd", { children: detail.metrics?.judgeModel || t("log.detailMissing") }),
1727
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dt", { children: t("log.detailType") }),
1728
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dd", { children: detail.typeDescription === void 0 ? t(detail.typeId === null ? "log.detailUnmatched" : "log.detailMissing") : detail.typeDescription.trim() || t("log.detailBlankType") }),
1729
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dt", { children: t("log.detailTask") }),
1730
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dd", { children: detail.taskText ?? t("log.detailMissing") })
1731
+ ] })
1712
1732
  }
1713
1733
  )
1714
1734
  ] });