dsh-plugin-core-demo 0.38.0 → 0.39.0

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 (2) hide show
  1. package/dist/client.js +162 -70
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -70027,8 +70027,12 @@ h(SideSheet, {
70027
70027
  "en": "The status-source mode only asks the server about keys it already knows: after every page closes there are no keys, a reload restarts the clock, and action handlers die with the page. For full recovery use `taskNotifications.setTaskBackend(project, backend)` plus `notifyTask.server(title, options)`. A backend must provide `list / follow / listNotices / ackNotices / invoke / ack`; registering otherwise throws \u2014 there is no silent fallback."
70028
70028
  },
70029
70029
  {
70030
- "zh": "\u4E24\u6761\u901A\u9053\u5404\u53F8\u5176\u804C\uFF1A\u901A\u9053 A\uFF08`list / follow`\uFF09\u53EA\u6C34\u5408\u5728\u8DD1\u4EFB\u52A1\uFF0C\u7EC8\u6001\u5893\u7891\u53EA\u66F4\u65B0\u672C\u5730\u7EC8\u6001\u95E8\uFF0C\u7EDD\u4E0D\u53D1 `settled`\u3001\u7EDD\u4E0D ack\uFF1B\u901A\u9053 B\uFF08`listNotices / ackNotices`\uFF09\u4E13\u95E8\u6295\u9012\u672A\u786E\u8BA4\u7684\u7EC8\u6001\u901A\u77E5\uFF0C\u4E8B\u4EF6\u53D1\u51FA\u540E\u624D\u6309\u8FDE\u7EED\u6210\u529F\u524D\u7F00 ack\u3002\u56E0\u6B64\u9875\u9762\u91CD\u5F00\u540E\u57FA\u7EBF\u56DE\u653E\u4E0D\u4F1A\u9020\u6210\u91CD\u590D\u901A\u77E5\uFF0C\u672A\u786E\u8BA4\u7684\u901A\u77E5\u4ECD\u4F1A\u901A\u8FC7\u901A\u9053 B \u9001\u8FBE\u3002",
70031
- "en": "Two channels with separate jobs: channel A (`list / follow`) only hydrates running tasks; a terminal tombstone only updates the local terminal gate and never emits `settled` nor acks. Channel B (`listNotices / ackNotices`) delivers unacknowledged terminal notices; the cursor advances only after the event is emitted. A page reopen therefore never duplicates a notice from baseline replay, and unacknowledged notices still arrive through channel B."
70030
+ "zh": "\u4E24\u6761\u901A\u9053\u5404\u53F8\u5176\u804C\uFF1A\u901A\u9053 A\uFF08`list / follow`\uFF09\u53EA\u6C34\u5408\u5728\u8DD1\u4EFB\u52A1\uFF0C\u7EC8\u6001\u5893\u7891\u53EA\u66F4\u65B0\u672C\u5730\u7EC8\u6001\u95E8\uFF0C\u7EDD\u4E0D\u53D1 `settled`\u3001\u7EDD\u4E0D ack\uFF1B\u901A\u9053 B\uFF08`listNotices / ackNotices`\uFF09\u4E13\u95E8\u6295\u9012\u672A\u786E\u8BA4\u7684\u7EC8\u6001\u901A\u77E5\uFF0C\u4E8B\u4EF6\u53D1\u51FA\u540E\u624D\u6309\u8FDE\u7EED\u6210\u529F\u524D\u7F00 ack\u3002\u56E0\u6B64\u9875\u9762\u91CD\u5F00\u540E\u57FA\u7EBF\u56DE\u653E\u4E0D\u4F1A\u9020\u6210\u91CD\u590D\u901A\u77E5\uFF0C\u672A\u786E\u8BA4\u7684\u901A\u77E5\u4ECD\u4F1A\u901A\u8FC7\u901A\u9053 B \u9001\u8FBE\u3002\u901A\u9053 B \u6309\u540E\u7AEF\u5F52\u5C5E\u5206\u7EC4\uFF1A\u6BCF\u4E2A\u540E\u7AEF\u53EA\u67E5\u81EA\u5DF1\u6CE8\u518C\u7684 project\u3001\u7528\u81EA\u5DF1\u7684\u6E38\u6807\u63A8\u8FDB\u4E0E ack\uFF0C\u7EDD\u4E0D\u62FF\u9996\u4E2A\u540E\u7AEF\u4EE3\u67E5\u5168\u90E8\u9879\u76EE\u2014\u2014\u4E0D\u540C\u540E\u7AEF\u53EF\u80FD\u662F\u4E0D\u540C\u670D\u52A1\u6216\u4E0D\u540C\u9274\u6743\u57DF\u3002",
70031
+ "en": "Two channels with separate jobs: channel A (`list / follow`) only hydrates running tasks; a terminal tombstone only updates the local terminal gate and never emits `settled` nor acks. Channel B (`listNotices / ackNotices`) delivers unacknowledged terminal notices; the cursor advances only after the event is emitted. A page reopen therefore never duplicates a notice from baseline replay, and unacknowledged notices still arrive through channel B. Channel B is grouped by backend ownership: each backend queries only the projects registered to it and advances/acks with its own cursor \u2014 it never queries all projects through whichever backend was registered first, since backends may be different services or auth domains."
70032
+ },
70033
+ {
70034
+ "zh": "\u524D\u7AEF\u7684\u901A\u77E5\u53BB\u91CD id \u4E0E\u7EC8\u6001\u4EA4\u63A5\u7ED3\u679C\u7528\u6709\u754C LRU \u7F13\u5B58\uFF08\u4E0A\u9650 512\uFF09\uFF0C\u4E0D\u4F1A\u968F\u957F\u65F6\u95F4\u5F00\u9875\u65E0\u9650\u589E\u957F\uFF1B\u8DE8\u9875 / \u91CD\u5F00\u53BB\u91CD\u9760\u670D\u52A1\u7AEF cursor\u3002\u53E5\u67C4\u5151\u73B0\u4EE5\u767B\u8BB0\u65F6\u670D\u52A1\u7AEF\u539F\u5B50 create \u8FD4\u56DE\u7684\u6743\u5A01\u8BB0\u5F55\u4E3A\u771F\u6E90\uFF0C\u672C\u5730\u7F13\u5B58\u53EA\u662F\u300C\u901A\u77E5\u65E9\u4E8E waiter\u300D\u7684\u5FEB\u8DEF\u5F84\u2014\u2014\u6DD8\u6C70\u540E\u4ECD\u80FD\u5151\u73B0\u3001\u4E0D\u7559 pending\uFF0C\u4E14\u540C key \u91CD\u5EFA\u4E0D\u4F1A\u88AB\u4E0A\u4E00\u8F6E\u7EC8\u6001\u9519\u8BEF\u5151\u73B0\u3002",
70035
+ "en": 'Notification de-duplication ids and terminal handoff results on the client use a bounded LRU cache (limit 512) and never grow without bound on a long-lived page. Cross-page / reopen de-duplication relies on the server cursor. Settling an authoritative handle uses the authoritative record returned by the server atomic create at registration as the source of truth; the local cache is only a fast path for "notice before waiter" \u2014 eviction still settles without leaving a pending handle, and reusing a key can never settle a fresh handle with the previous instance terminal.'
70032
70036
  },
70033
70037
  {
70034
70038
  "zh": "\u771F\u6E90\u5728\u670D\u52A1\u7AEF\uFF1A\u539F\u5B50 `create` \u51B3\u5B9A `created`\uFF0C`startedAt / deadlineAt / version` \u7531\u670D\u52A1\u7AEF\u751F\u6210\uFF0C\u8D85\u65F6\u4E0E\u79DF\u7EA6\u7531\u670D\u52A1\u7AEF watchdog \u5224\u5B9A\uFF0C\u7EC8\u6001\u6309 TTL \u6E05\u7406\u3002\u6838\u5FC3\u53EA\u6309\u5355\u8C03 version \u5408\u5E76\u57FA\u7EBF\u3001\u5206\u9875\u4E0E\u589E\u91CF\uFF1B\u6309\u94AE\u662F `{id, token, expiresAt}` \u63CF\u8FF0\uFF0C`runAction` \u6309 actionId \u8D70\u670D\u52A1\u7AEF\u547D\u4EE4\uFF0C\u4E0D\u4F9D\u8D56\u9875\u9762\u95ED\u5305\u3002\u70B9\u51FB\u6309\u94AE\u4F1A\u5411 `taskNotificationEvents` \u53D1 `action` \u4E8B\u4EF6\uFF08\u542B\u4EFB\u52A1\u5FEB\u7167\u3001actionId\u3001ok\u3001reason\u3001result\uFF09\uFF0C\u6D88\u8D39\u65B9\u636E\u6B64\u628A\u754C\u9762\u5E26\u56DE\u6765\u3002\u6743\u5A01\u53E5\u67C4\u53EA\u6709 `id / isSettled / settled`\uFF0C\u6CA1\u6709 update/touch/background/done/fail/track\u2014\u2014\u7EC8\u6001\u7531\u670D\u52A1\u7AEF\u5224\u5B9A\uFF0C\u7F16\u8BD1\u671F\u5373\u963B\u6B62\u8BEF\u7528\u3002",
@@ -74854,8 +74858,28 @@ function createAuthoritativeEngine(options) {
74854
74858
  const noticeCursors = /* @__PURE__ */ new Map();
74855
74859
  let noticePumping = false;
74856
74860
  let noticePending = false;
74857
- function clientCursor() {
74858
- return noticeCursors.get(clientId);
74861
+ let pumpGeneration = 0;
74862
+ function clientCursor(backend) {
74863
+ return noticeCursors.get(backend)?.get(clientId);
74864
+ }
74865
+ function setClientCursor(backend, cursor2) {
74866
+ let byClient = noticeCursors.get(backend);
74867
+ if (byClient === void 0) {
74868
+ byClient = /* @__PURE__ */ new Map();
74869
+ noticeCursors.set(backend, byClient);
74870
+ }
74871
+ byClient.set(clientId, cursor2);
74872
+ }
74873
+ function byBackend() {
74874
+ const grouped = /* @__PURE__ */ new Map();
74875
+ for (const [project, backend] of backends) {
74876
+ const bucket = grouped.get(backend);
74877
+ if (bucket === void 0)
74878
+ grouped.set(backend, [project]);
74879
+ else
74880
+ bucket.push(project);
74881
+ }
74882
+ return grouped;
74859
74883
  }
74860
74884
  const invokes = /* @__PURE__ */ new Map();
74861
74885
  const INVOKE_CACHE_MS = 6e4;
@@ -74886,6 +74910,37 @@ function createAuthoritativeEngine(options) {
74886
74910
  return;
74887
74911
  emitChange();
74888
74912
  }
74913
+ async function pumpBackendNotices(backend, projects2, generation) {
74914
+ let cursor2 = clientCursor(backend);
74915
+ const seenCursors = /* @__PURE__ */ new Set();
74916
+ for (; ; ) {
74917
+ if (disposed || generation !== pumpGeneration)
74918
+ return;
74919
+ if (cursor2 !== void 0) {
74920
+ if (seenCursors.has(cursor2))
74921
+ return;
74922
+ seenCursors.add(cursor2);
74923
+ }
74924
+ const page = await backend.listNotices(projects2, cursor2);
74925
+ if (disposed || generation !== pumpGeneration || page.notices.length === 0)
74926
+ return;
74927
+ let delivered = 0;
74928
+ for (const notice of page.notices) {
74929
+ onNotice(notice);
74930
+ cursor2 = notice.cursor;
74931
+ delivered += 1;
74932
+ }
74933
+ if (delivered > 0 && cursor2 !== void 0) {
74934
+ await backend.ackNotices(projects2, cursor2);
74935
+ if (disposed || generation !== pumpGeneration)
74936
+ return;
74937
+ setClientCursor(backend, cursor2);
74938
+ }
74939
+ if (page.nextCursor === void 0 || page.nextCursor === cursor2)
74940
+ return;
74941
+ cursor2 = page.nextCursor;
74942
+ }
74943
+ }
74889
74944
  async function pumpNotices() {
74890
74945
  if (disposed || !started || backends.size === 0)
74891
74946
  return;
@@ -74894,44 +74949,24 @@ function createAuthoritativeEngine(options) {
74894
74949
  return;
74895
74950
  }
74896
74951
  noticePumping = true;
74952
+ const generation = pumpGeneration;
74897
74953
  try {
74898
74954
  do {
74899
74955
  noticePending = false;
74900
- const projectsNow = [...backends.keys()];
74901
- const backend = backends.get(projectsNow[0] ?? "");
74902
- if (backend === void 0)
74903
- return;
74904
- let cursor2 = clientCursor();
74905
- const seenCursors = /* @__PURE__ */ new Set();
74906
- for (; ; ) {
74907
- if (disposed)
74956
+ for (const [backend, projects2] of byBackend()) {
74957
+ if (disposed || generation !== pumpGeneration)
74908
74958
  return;
74909
- if (cursor2 !== void 0) {
74910
- if (seenCursors.has(cursor2))
74911
- return;
74912
- seenCursors.add(cursor2);
74913
- }
74914
- const page = await backend.listNotices(projectsNow, cursor2);
74915
- if (disposed || page.notices.length === 0)
74916
- break;
74917
- let delivered = 0;
74918
- for (const notice of page.notices) {
74919
- onNotice(notice);
74920
- cursor2 = notice.cursor;
74921
- delivered += 1;
74922
- }
74923
- if (delivered > 0 && cursor2 !== void 0) {
74924
- await backend.ackNotices(projectsNow, cursor2);
74925
- noticeCursors.set(clientId, cursor2);
74959
+ try {
74960
+ await pumpBackendNotices(backend, projects2, generation);
74961
+ } catch {
74926
74962
  }
74927
- if (page.nextCursor === void 0 || page.nextCursor === cursor2)
74928
- break;
74929
- cursor2 = page.nextCursor;
74930
74963
  }
74931
- } while (noticePending && !disposed);
74964
+ } while (noticePending && !disposed && generation === pumpGeneration);
74932
74965
  } catch {
74933
74966
  } finally {
74934
74967
  noticePumping = false;
74968
+ if (noticePending && started && !disposed)
74969
+ void pumpNotices();
74935
74970
  }
74936
74971
  }
74937
74972
  function advanceCursor2(project, event) {
@@ -74971,15 +75006,7 @@ function createAuthoritativeEngine(options) {
74971
75006
  function startFollow() {
74972
75007
  if (disposed || backends.size === 0)
74973
75008
  return;
74974
- const byBackend = /* @__PURE__ */ new Map();
74975
- for (const [project, backend] of backends) {
74976
- const bucket = byBackend.get(backend);
74977
- if (bucket === void 0)
74978
- byBackend.set(backend, [project]);
74979
- else
74980
- bucket.push(project);
74981
- }
74982
- for (const [backend, owned] of byBackend) {
75009
+ for (const [backend, owned] of byBackend()) {
74983
75010
  if (followers.has(backend))
74984
75011
  continue;
74985
75012
  const cursors = {};
@@ -75030,6 +75057,11 @@ function createAuthoritativeEngine(options) {
75030
75057
  }
75031
75058
  backends.set(project, backend);
75032
75059
  projectState(project);
75060
+ const active = new Set(backends.values());
75061
+ for (const stale of noticeCursors.keys()) {
75062
+ if (!active.has(stale))
75063
+ noticeCursors.delete(stale);
75064
+ }
75033
75065
  if (started) {
75034
75066
  const wasStarted = started;
75035
75067
  this.stop();
@@ -75139,6 +75171,7 @@ function createAuthoritativeEngine(options) {
75139
75171
  return backends.has(project);
75140
75172
  },
75141
75173
  stop() {
75174
+ pumpGeneration += 1;
75142
75175
  for (const state of projects.values())
75143
75176
  state.epoch += 1;
75144
75177
  for (const off of followers.values())
@@ -75154,6 +75187,7 @@ function createAuthoritativeEngine(options) {
75154
75187
  this.stop();
75155
75188
  projects.clear();
75156
75189
  invokes.clear();
75190
+ noticeCursors.clear();
75157
75191
  }
75158
75192
  };
75159
75193
  }
@@ -75494,29 +75528,73 @@ function createTaskNotificationPool(options = {}) {
75494
75528
  revision += 1;
75495
75529
  store.setState({ tasks: collect(), revision }, true);
75496
75530
  }
75531
+ const NOTICE_CACHE_LIMIT = 512;
75532
+ function boundedLru(limit) {
75533
+ const entries2 = /* @__PURE__ */ new Map();
75534
+ const refresh2 = (key, value) => {
75535
+ entries2.delete(key);
75536
+ entries2.set(key, value);
75537
+ };
75538
+ return {
75539
+ has(key) {
75540
+ if (!entries2.has(key))
75541
+ return false;
75542
+ refresh2(key, entries2.get(key));
75543
+ return true;
75544
+ },
75545
+ get(key) {
75546
+ if (!entries2.has(key))
75547
+ return void 0;
75548
+ const value = entries2.get(key);
75549
+ refresh2(key, value);
75550
+ return value;
75551
+ },
75552
+ set(key, value) {
75553
+ refresh2(key, value);
75554
+ if (entries2.size > limit) {
75555
+ const oldest = entries2.keys().next();
75556
+ if (!oldest.done)
75557
+ entries2.delete(oldest.value);
75558
+ }
75559
+ },
75560
+ delete(key) {
75561
+ entries2.delete(key);
75562
+ },
75563
+ clear() {
75564
+ entries2.clear();
75565
+ }
75566
+ };
75567
+ }
75497
75568
  const serverSettlers = /* @__PURE__ */ new Map();
75498
75569
  const serverHandles = /* @__PURE__ */ new Map();
75499
- const deliveredNotices = /* @__PURE__ */ new Set();
75500
- const settledResults = /* @__PURE__ */ new Map();
75570
+ const deliveredNotices = boundedLru(NOTICE_CACHE_LIMIT);
75571
+ const settledResults = boundedLru(NOTICE_CACHE_LIMIT);
75572
+ function settlementOf(row3) {
75573
+ if (row3.state !== "done" && row3.state !== "failed")
75574
+ return void 0;
75575
+ return {
75576
+ outcome: row3.state,
75577
+ reason: row3.reason,
75578
+ task: serverRecordToProjection(row3)
75579
+ };
75580
+ }
75501
75581
  function deliverTerminal(notice) {
75502
75582
  const row3 = notice.record;
75503
75583
  const cacheKey = `${row3.project}:${row3.key}`;
75504
75584
  if (deliveredNotices.has(notice.notificationId))
75505
75585
  return;
75506
- deliveredNotices.add(notice.notificationId);
75507
- const projection = serverRecordToProjection(row3);
75508
- const settlement = {
75509
- outcome: row3.state === "done" ? "done" : "failed",
75510
- reason: row3.reason,
75511
- task: projection
75512
- };
75513
- settledResults.set(cacheKey, settlement);
75514
- bus().emit({ type: "settled", outcome: settlement.outcome, task: projection, remote: false });
75586
+ const settlement = settlementOf(row3);
75587
+ if (settlement === void 0)
75588
+ return;
75589
+ deliveredNotices.set(notice.notificationId, true);
75590
+ bus().emit({ type: "settled", outcome: settlement.outcome, task: settlement.task, remote: false });
75515
75591
  const waiter = serverSettlers.get(cacheKey);
75516
75592
  if (waiter !== void 0) {
75517
75593
  serverSettlers.delete(cacheKey);
75518
75594
  serverHandles.delete(cacheKey);
75519
75595
  waiter(settlement);
75596
+ } else {
75597
+ settledResults.set(cacheKey, settlement);
75520
75598
  }
75521
75599
  }
75522
75600
  const authoritative = createAuthoritativeEngine({
@@ -76245,18 +76323,10 @@ function createTaskNotificationPool(options = {}) {
76245
76323
  return isSettled;
76246
76324
  }, settled };
76247
76325
  serverHandles.set(keyOfHandle, handle);
76248
- const cached = settledResults.get(keyOfHandle);
76249
- if (cached !== void 0) {
76250
- settledResults.delete(keyOfHandle);
76251
- serverHandles.delete(keyOfHandle);
76326
+ serverSettlers.set(keyOfHandle, (value) => {
76252
76327
  isSettled = true;
76253
- resolveSettled(cached);
76254
- } else {
76255
- serverSettlers.set(keyOfHandle, (value) => {
76256
- isSettled = true;
76257
- resolveSettled(value);
76258
- });
76259
- }
76328
+ resolveSettled(value);
76329
+ });
76260
76330
  }
76261
76331
  const created = await authoritative.create({
76262
76332
  project,
@@ -76270,6 +76340,28 @@ function createTaskNotificationPool(options = {}) {
76270
76340
  });
76271
76341
  if (created === void 0)
76272
76342
  throw new Error(`project ${project} backend does not support create`);
76343
+ const waiter = serverSettlers.get(keyOfHandle);
76344
+ if (waiter !== void 0) {
76345
+ const authoritative2 = settlementOf(created.record);
76346
+ if (authoritative2 !== void 0) {
76347
+ settledResults.delete(keyOfHandle);
76348
+ serverSettlers.delete(keyOfHandle);
76349
+ serverHandles.delete(keyOfHandle);
76350
+ waiter(authoritative2);
76351
+ } else if (created.created === false) {
76352
+ const cached = settledResults.get(keyOfHandle);
76353
+ if (cached !== void 0 && cached.task.version !== void 0 && cached.task.version > created.record.version) {
76354
+ settledResults.delete(keyOfHandle);
76355
+ serverSettlers.delete(keyOfHandle);
76356
+ serverHandles.delete(keyOfHandle);
76357
+ waiter(cached);
76358
+ } else {
76359
+ settledResults.delete(keyOfHandle);
76360
+ }
76361
+ } else {
76362
+ settledResults.delete(keyOfHandle);
76363
+ }
76364
+ }
76273
76365
  return { handle, created: created.created };
76274
76366
  }
76275
76367
  function settleLocal(reason) {
@@ -77021,9 +77113,9 @@ function ReferencePage() {
77021
77113
  "tbody",
77022
77114
  null,
77023
77115
  [
77024
- [t3("buildCore"), `v${"0.38.0"}`],
77025
- [t3("buildDemo"), `v${"0.38.0"}`],
77026
- [t3("buildStamp"), "261116-161113-772"]
77116
+ [t3("buildCore"), `v${"0.39.0"}`],
77117
+ [t3("buildDemo"), `v${"0.39.0"}`],
77118
+ [t3("buildStamp"), "261116-170322-841"]
77027
77119
  ].map(
77028
77120
  ([label, value]) => (0, import_react110.createElement)(
77029
77121
  "tr",
@@ -77342,9 +77434,9 @@ function DemoPage() {
77342
77434
  lineHeight: "14px"
77343
77435
  }
77344
77436
  },
77345
- (0, import_react112.createElement)("span", null, `core v${"0.38.0"}`),
77346
- (0, import_react112.createElement)("span", null, `demo v${"0.38.0"}`),
77347
- (0, import_react112.createElement)("span", { style: { marginTop: "4px", fontSize: "9px" } }, "261116-161113-772")
77437
+ (0, import_react112.createElement)("span", null, `core v${"0.39.0"}`),
77438
+ (0, import_react112.createElement)("span", null, `demo v${"0.39.0"}`),
77439
+ (0, import_react112.createElement)("span", { style: { marginTop: "4px", fontSize: "9px" } }, "261116-170322-841")
77348
77440
  )
77349
77441
  )
77350
77442
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-core-demo",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "description": "The shared UI foundation for DSH plugins, with a live component preview: design tokens, common controls, workspace browsing and notifications maintained in one place — install it to preview every component in a real host.",
5
5
  "icon": "./assets/icon-components.svg",
6
6
  "keywords": [