dsh-plugin-core-demo 0.37.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.
- package/dist/client.js +310 -113
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -70023,12 +70023,20 @@ h(SideSheet, {
|
|
|
70023
70023
|
},
|
|
70024
70024
|
"prose": [
|
|
70025
70025
|
{
|
|
70026
|
-
"zh": "\u65E7\u7684\u72B6\u6001\u6E90\u6A21\u5F0F\u53EA\u662F\u300C\u6309\u5DF2\u77E5 key \u95EE\u670D\u52A1\u7AEF\u300D\uFF1A\u9875\u9762\u5168\u5173\u540E\u62FF\u4E0D\u5230 key\uFF0C\u5237\u65B0\u4F1A\u628A\u65F6\u949F\u4ECE\u96F6\u7B97\u8D77\uFF0C\u6309\u94AE handler \u4E5F\u968F\u9875\u9762\u9500\u6BC1\u3002\u8981\u5B8C\u6574\u6062\u590D\uFF0C\u6539\u7528 `taskNotifications.setTaskBackend(project, backend)` + `notifyTask.server(title, options)`\u3002\u540E\u7AEF\u5FC5\u987B\u63D0\u4F9B `list / follow / invoke / ack` \
|
|
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 / invoke / ack`; registering otherwise throws \u2014 there is no silent fallback."
|
|
70026
|
+
"zh": "\u65E7\u7684\u72B6\u6001\u6E90\u6A21\u5F0F\u53EA\u662F\u300C\u6309\u5DF2\u77E5 key \u95EE\u670D\u52A1\u7AEF\u300D\uFF1A\u9875\u9762\u5168\u5173\u540E\u62FF\u4E0D\u5230 key\uFF0C\u5237\u65B0\u4F1A\u628A\u65F6\u949F\u4ECE\u96F6\u7B97\u8D77\uFF0C\u6309\u94AE handler \u4E5F\u968F\u9875\u9762\u9500\u6BC1\u3002\u8981\u5B8C\u6574\u6062\u590D\uFF0C\u6539\u7528 `taskNotifications.setTaskBackend(project, backend)` + `notifyTask.server(title, options)`\u3002\u540E\u7AEF\u5FC5\u987B\u63D0\u4F9B `list / follow / listNotices / ackNotices / invoke / ack` \u516D\u4E2A\u80FD\u529B\uFF0C\u7F3A\u4E00\u5373\u6CE8\u518C\u5931\u8D25\u2014\u2014\u4E0D\u505A\u9759\u9ED8\u964D\u7EA7\u3002",
|
|
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": "\
|
|
70031
|
-
"en": "
|
|
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.'
|
|
70036
|
+
},
|
|
70037
|
+
{
|
|
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",
|
|
70039
|
+
"en": "The server owns the truth: atomic `create` decides `created`; `startedAt / deadlineAt / version` come from the server; a server watchdog decides timeouts and lease expiry; terminal records are cleared by TTL. Actions are `{id, token, expiresAt}` descriptors and `runAction` dispatches by actionId to the server, never through page closures. Every click emits an `action` event to `taskNotificationEvents` (with task snapshot, actionId, ok, reason, result) so consumers can restore their UI. An authoritative handle exposes only `id / isSettled / settled`; update/touch/background/done/fail/track do not exist \u2014 the server decides terminal state, and the type system prevents misuse."
|
|
70032
70040
|
}
|
|
70033
70041
|
],
|
|
70034
70042
|
"api": [
|
|
@@ -70040,17 +70048,17 @@ h(SideSheet, {
|
|
|
70040
70048
|
"type": "(project: string, backend: TaskBackend) => void",
|
|
70041
70049
|
"def": "\u2014",
|
|
70042
70050
|
"desc": {
|
|
70043
|
-
"zh": "\u5207\u6362\u5230\u670D\u52A1\u7AEF\u6743\u5A01\u6A21\u5F0F\uFF1B\u5FC5\u987B\u63D0\u4F9B list/follow/invoke/ack\uFF0C\u5426\u5219\u629B\u9519",
|
|
70044
|
-
"en": "Switches to authoritative mode; list/follow/invoke/ack are mandatory or registration throws"
|
|
70051
|
+
"zh": "\u5207\u6362\u5230\u670D\u52A1\u7AEF\u6743\u5A01\u6A21\u5F0F\uFF1B\u5FC5\u987B\u63D0\u4F9B list/follow/listNotices/ackNotices/invoke/ack\uFF0C\u5426\u5219\u629B\u9519",
|
|
70052
|
+
"en": "Switches to authoritative mode; list/follow/listNotices/ackNotices/invoke/ack are mandatory or registration throws"
|
|
70045
70053
|
}
|
|
70046
70054
|
},
|
|
70047
70055
|
{
|
|
70048
70056
|
"name": "notifyTask.server(title, options?)",
|
|
70049
|
-
"type": "(title: string, options?: NotifyTaskOptions) => Promise<
|
|
70057
|
+
"type": "(title: string, options?: NotifyTaskOptions) => Promise<AuthoritativeClaim>",
|
|
70050
70058
|
"def": "\u2014",
|
|
70051
70059
|
"desc": {
|
|
70052
|
-
"zh": "\u670D\u52A1\u7AEF\u539F\u5B50 create \u767B\u8BB0\uFF1B\
|
|
70053
|
-
"en": "Registers through server-side atomic create;
|
|
70060
|
+
"zh": "\u670D\u52A1\u7AEF\u539F\u5B50 create \u767B\u8BB0\uFF1B\u53E5\u67C4\u53EA\u6709 id/isSettled/settled\uFF0C\u6CA1\u6709\u53EF\u88AB\u9875\u9762\u5199\u7684\u65B9\u6CD5",
|
|
70061
|
+
"en": "Registers through server-side atomic create; the handle exposes only id/isSettled/settled with no page-writable methods"
|
|
70054
70062
|
}
|
|
70055
70063
|
},
|
|
70056
70064
|
{
|
|
@@ -74820,7 +74828,7 @@ function mergeInto(state, rows) {
|
|
|
74820
74828
|
if (row3.version < seenVersion)
|
|
74821
74829
|
continue;
|
|
74822
74830
|
const terminal = state.terminal.get(row3.key);
|
|
74823
|
-
if (terminal !== void 0 && row3.version <= terminal
|
|
74831
|
+
if (terminal !== void 0 && row3.version <= terminal)
|
|
74824
74832
|
continue;
|
|
74825
74833
|
const current3 = state.seen.get(row3.key);
|
|
74826
74834
|
if (current3 !== void 0 && current3.version > row3.version)
|
|
@@ -74829,16 +74837,16 @@ function mergeInto(state, rows) {
|
|
|
74829
74837
|
continue;
|
|
74830
74838
|
state.seen.set(row3.key, row3);
|
|
74831
74839
|
state.watermark.set(row3.key, row3.version);
|
|
74832
|
-
if (row3.tombstone === true || row3.state !== "running")
|
|
74833
|
-
state.terminal.set(row3.key,
|
|
74834
|
-
}
|
|
74840
|
+
if (row3.tombstone === true || row3.state !== "running")
|
|
74841
|
+
state.terminal.set(row3.key, row3.version);
|
|
74835
74842
|
accepted.push(row3);
|
|
74836
74843
|
}
|
|
74837
74844
|
return accepted;
|
|
74838
74845
|
}
|
|
74839
74846
|
function createAuthoritativeEngine(options) {
|
|
74840
|
-
const { onChange,
|
|
74847
|
+
const { onChange, onNotice, clientId } = options;
|
|
74841
74848
|
const rebaseMinMs = options.rebaseMinMs ?? 5e3;
|
|
74849
|
+
const actionTimeoutMs = options.actionTimeoutMs ?? 5e3;
|
|
74842
74850
|
const backends = /* @__PURE__ */ new Map();
|
|
74843
74851
|
const projects = /* @__PURE__ */ new Map();
|
|
74844
74852
|
const followers = /* @__PURE__ */ new Map();
|
|
@@ -74847,6 +74855,32 @@ function createAuthoritativeEngine(options) {
|
|
|
74847
74855
|
let lastRebase = 0;
|
|
74848
74856
|
let reconnectFailures = 0;
|
|
74849
74857
|
let reconnectTimer = null;
|
|
74858
|
+
const noticeCursors = /* @__PURE__ */ new Map();
|
|
74859
|
+
let noticePumping = false;
|
|
74860
|
+
let noticePending = false;
|
|
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;
|
|
74883
|
+
}
|
|
74850
74884
|
const invokes = /* @__PURE__ */ new Map();
|
|
74851
74885
|
const INVOKE_CACHE_MS = 6e4;
|
|
74852
74886
|
function invokeCacheKey(project, key, actionId, version) {
|
|
@@ -74872,21 +74906,69 @@ function createAuthoritativeEngine(options) {
|
|
|
74872
74906
|
onChange(Object.freeze(all));
|
|
74873
74907
|
}
|
|
74874
74908
|
function applyRows(project, rows) {
|
|
74875
|
-
|
|
74876
|
-
const accepted = mergeInto(state, rows);
|
|
74877
|
-
if (accepted.length === 0)
|
|
74909
|
+
if (mergeInto(projectState(project), rows).length === 0)
|
|
74878
74910
|
return;
|
|
74879
|
-
for (const row3 of accepted) {
|
|
74880
|
-
if (row3.tombstone !== true && row3.state === "running")
|
|
74881
|
-
continue;
|
|
74882
|
-
const terminal = state.terminal.get(row3.key);
|
|
74883
|
-
if (terminal === void 0 || terminal.version !== row3.version || terminal.acked)
|
|
74884
|
-
continue;
|
|
74885
|
-
terminal.acked = true;
|
|
74886
|
-
onTerminal?.(row3);
|
|
74887
|
-
}
|
|
74888
74911
|
emitChange();
|
|
74889
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
|
+
}
|
|
74944
|
+
async function pumpNotices() {
|
|
74945
|
+
if (disposed || !started || backends.size === 0)
|
|
74946
|
+
return;
|
|
74947
|
+
if (noticePumping) {
|
|
74948
|
+
noticePending = true;
|
|
74949
|
+
return;
|
|
74950
|
+
}
|
|
74951
|
+
noticePumping = true;
|
|
74952
|
+
const generation = pumpGeneration;
|
|
74953
|
+
try {
|
|
74954
|
+
do {
|
|
74955
|
+
noticePending = false;
|
|
74956
|
+
for (const [backend, projects2] of byBackend()) {
|
|
74957
|
+
if (disposed || generation !== pumpGeneration)
|
|
74958
|
+
return;
|
|
74959
|
+
try {
|
|
74960
|
+
await pumpBackendNotices(backend, projects2, generation);
|
|
74961
|
+
} catch {
|
|
74962
|
+
}
|
|
74963
|
+
}
|
|
74964
|
+
} while (noticePending && !disposed && generation === pumpGeneration);
|
|
74965
|
+
} catch {
|
|
74966
|
+
} finally {
|
|
74967
|
+
noticePumping = false;
|
|
74968
|
+
if (noticePending && started && !disposed)
|
|
74969
|
+
void pumpNotices();
|
|
74970
|
+
}
|
|
74971
|
+
}
|
|
74890
74972
|
function advanceCursor2(project, event) {
|
|
74891
74973
|
const state = projectState(project);
|
|
74892
74974
|
if (event.kind === "cursor")
|
|
@@ -74900,7 +74982,6 @@ function createAuthoritativeEngine(options) {
|
|
|
74900
74982
|
const generation = state.epoch;
|
|
74901
74983
|
try {
|
|
74902
74984
|
let cursor2 = state.cursor;
|
|
74903
|
-
let first = true;
|
|
74904
74985
|
while (!disposed && generation === state.epoch) {
|
|
74905
74986
|
const page = await backend.list(project, cursor2);
|
|
74906
74987
|
if (disposed || generation !== state.epoch)
|
|
@@ -74913,8 +74994,6 @@ function createAuthoritativeEngine(options) {
|
|
|
74913
74994
|
if (page.nextCursor === void 0 || page.nextCursor === cursor2)
|
|
74914
74995
|
break;
|
|
74915
74996
|
cursor2 = page.nextCursor;
|
|
74916
|
-
if (first)
|
|
74917
|
-
first = false;
|
|
74918
74997
|
}
|
|
74919
74998
|
if (disposed || generation !== state.epoch)
|
|
74920
74999
|
return;
|
|
@@ -74927,15 +75006,7 @@ function createAuthoritativeEngine(options) {
|
|
|
74927
75006
|
function startFollow() {
|
|
74928
75007
|
if (disposed || backends.size === 0)
|
|
74929
75008
|
return;
|
|
74930
|
-
const
|
|
74931
|
-
for (const [project, backend] of backends) {
|
|
74932
|
-
const bucket = byBackend.get(backend);
|
|
74933
|
-
if (bucket === void 0)
|
|
74934
|
-
byBackend.set(backend, [project]);
|
|
74935
|
-
else
|
|
74936
|
-
bucket.push(project);
|
|
74937
|
-
}
|
|
74938
|
-
for (const [backend, owned] of byBackend) {
|
|
75009
|
+
for (const [backend, owned] of byBackend()) {
|
|
74939
75010
|
if (followers.has(backend))
|
|
74940
75011
|
continue;
|
|
74941
75012
|
const cursors = {};
|
|
@@ -74949,6 +75020,8 @@ function createAuthoritativeEngine(options) {
|
|
|
74949
75020
|
return;
|
|
74950
75021
|
if (event.kind === "upsert")
|
|
74951
75022
|
applyRows(project, event.rows);
|
|
75023
|
+
else if (event.kind === "notice-available")
|
|
75024
|
+
void pumpNotices();
|
|
74952
75025
|
advanceCursor2(project, event);
|
|
74953
75026
|
}, () => {
|
|
74954
75027
|
for (const project of owned) {
|
|
@@ -74973,16 +75046,22 @@ function createAuthoritativeEngine(options) {
|
|
|
74973
75046
|
if (disposed)
|
|
74974
75047
|
return;
|
|
74975
75048
|
await Promise.all([...backends.keys()].map((project) => rebase(project)));
|
|
75049
|
+
void pumpNotices();
|
|
74976
75050
|
}
|
|
74977
75051
|
return {
|
|
74978
75052
|
attach(project, backend) {
|
|
74979
75053
|
if (disposed)
|
|
74980
75054
|
throw new Error("authoritative engine is disposed");
|
|
74981
|
-
if (typeof backend.list !== "function" || typeof backend.follow !== "function" || typeof backend.invoke !== "function" || typeof backend.ack !== "function") {
|
|
74982
|
-
throw new Error(`task backend for ${project} must provide list/follow/invoke/ack`);
|
|
75055
|
+
if (typeof backend.list !== "function" || typeof backend.follow !== "function" || typeof backend.listNotices !== "function" || typeof backend.ackNotices !== "function" || typeof backend.invoke !== "function" || typeof backend.ack !== "function") {
|
|
75056
|
+
throw new Error(`task backend for ${project} must provide list/follow/listNotices/ackNotices/invoke/ack`);
|
|
74983
75057
|
}
|
|
74984
75058
|
backends.set(project, backend);
|
|
74985
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
|
+
}
|
|
74986
75065
|
if (started) {
|
|
74987
75066
|
const wasStarted = started;
|
|
74988
75067
|
this.stop();
|
|
@@ -75042,23 +75121,37 @@ function createAuthoritativeEngine(options) {
|
|
|
75042
75121
|
}
|
|
75043
75122
|
if (entry.result !== void 0)
|
|
75044
75123
|
return entry.result;
|
|
75045
|
-
|
|
75046
|
-
|
|
75047
|
-
|
|
75048
|
-
|
|
75049
|
-
|
|
75050
|
-
|
|
75051
|
-
|
|
75052
|
-
|
|
75053
|
-
|
|
75054
|
-
|
|
75055
|
-
|
|
75124
|
+
let timer = null;
|
|
75125
|
+
try {
|
|
75126
|
+
const timed = new Promise((_, reject) => {
|
|
75127
|
+
timer = setTimeout(() => reject(new Error("action timeout")), actionTimeoutMs);
|
|
75128
|
+
});
|
|
75129
|
+
const raw = await Promise.race([backend.invoke({
|
|
75130
|
+
project,
|
|
75131
|
+
key,
|
|
75132
|
+
actionId,
|
|
75133
|
+
token: action.token,
|
|
75134
|
+
version: record.version,
|
|
75135
|
+
idempotencyKey: entry.idempotencyKey
|
|
75136
|
+
}), timed]);
|
|
75137
|
+
const result = { ...raw, idempotencyKey: entry.idempotencyKey };
|
|
75138
|
+
if (result.ok) {
|
|
75139
|
+
entry.result = result;
|
|
75140
|
+
entry.at = Date.now();
|
|
75141
|
+
}
|
|
75142
|
+
return result;
|
|
75143
|
+
} finally {
|
|
75144
|
+
if (timer !== null)
|
|
75145
|
+
clearTimeout(timer);
|
|
75056
75146
|
}
|
|
75057
|
-
return result;
|
|
75058
75147
|
} catch (error) {
|
|
75059
75148
|
return { ok: false, reason: error instanceof Error ? error.message : String(error) };
|
|
75060
75149
|
}
|
|
75061
75150
|
},
|
|
75151
|
+
/** 暴露幂等键供上层在 action 事件里回传,迟到结果由它抑制二次 emit。 */
|
|
75152
|
+
idempotencyKeyFor(project, key, actionId, version) {
|
|
75153
|
+
return invokes.get(invokeCacheKey(project, key, actionId, version))?.idempotencyKey;
|
|
75154
|
+
},
|
|
75062
75155
|
async acknowledge(request) {
|
|
75063
75156
|
const backend = backends.get(request.project);
|
|
75064
75157
|
if (backend === void 0)
|
|
@@ -75077,8 +75170,8 @@ function createAuthoritativeEngine(options) {
|
|
|
75077
75170
|
has(project) {
|
|
75078
75171
|
return backends.has(project);
|
|
75079
75172
|
},
|
|
75080
|
-
/** 停止连接但保留后端与已水合状态;pool.dispose → connect 后可重新 follow。 */
|
|
75081
75173
|
stop() {
|
|
75174
|
+
pumpGeneration += 1;
|
|
75082
75175
|
for (const state of projects.values())
|
|
75083
75176
|
state.epoch += 1;
|
|
75084
75177
|
for (const off of followers.values())
|
|
@@ -75094,6 +75187,7 @@ function createAuthoritativeEngine(options) {
|
|
|
75094
75187
|
this.stop();
|
|
75095
75188
|
projects.clear();
|
|
75096
75189
|
invokes.clear();
|
|
75190
|
+
noticeCursors.clear();
|
|
75097
75191
|
}
|
|
75098
75192
|
};
|
|
75099
75193
|
}
|
|
@@ -75102,10 +75196,10 @@ function createAuthoritativeEngine(options) {
|
|
|
75102
75196
|
var import_react106 = require("react");
|
|
75103
75197
|
|
|
75104
75198
|
// dist/adv/tasks/pool.js
|
|
75105
|
-
var TASK_NOTIFICATIONS_PROTOCOL =
|
|
75106
|
-
var TASK_NOTIFICATIONS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/
|
|
75107
|
-
var TASK_NOTIFICATIONS_EVENTS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/events/
|
|
75108
|
-
var TASK_NOTIFICATIONS_CHANNEL = "dsh-plugin-core/task-notifications/
|
|
75199
|
+
var TASK_NOTIFICATIONS_PROTOCOL = 5;
|
|
75200
|
+
var TASK_NOTIFICATIONS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/v5");
|
|
75201
|
+
var TASK_NOTIFICATIONS_EVENTS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/events/v5");
|
|
75202
|
+
var TASK_NOTIFICATIONS_CHANNEL = "dsh-plugin-core/task-notifications/v5";
|
|
75109
75203
|
var SERVER_SHARD_ORIGIN = "__server__";
|
|
75110
75204
|
var INVOKE_TIMEOUT_MS = 2e3;
|
|
75111
75205
|
var DEFAULT_LEASE_MS = 5 * 6e4;
|
|
@@ -75360,7 +75454,7 @@ function makeOrigin2() {
|
|
|
75360
75454
|
function compareTasks(a, b) {
|
|
75361
75455
|
return a.startedAt - b.startedAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
75362
75456
|
}
|
|
75363
|
-
var TASK_NOTIFICATIONS_LOCK_PREFIX = "dsh-plugin-core/task-notifications/
|
|
75457
|
+
var TASK_NOTIFICATIONS_LOCK_PREFIX = "dsh-plugin-core/task-notifications/v5/";
|
|
75364
75458
|
function lockNameFor(pageOrigin) {
|
|
75365
75459
|
return `${TASK_NOTIFICATIONS_LOCK_PREFIX}${pageOrigin}`;
|
|
75366
75460
|
}
|
|
@@ -75434,31 +75528,79 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75434
75528
|
revision += 1;
|
|
75435
75529
|
store.setState({ tasks: collect(), revision }, true);
|
|
75436
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
|
+
}
|
|
75437
75568
|
const serverSettlers = /* @__PURE__ */ new Map();
|
|
75438
75569
|
const serverHandles = /* @__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
|
+
}
|
|
75581
|
+
function deliverTerminal(notice) {
|
|
75582
|
+
const row3 = notice.record;
|
|
75583
|
+
const cacheKey = `${row3.project}:${row3.key}`;
|
|
75584
|
+
if (deliveredNotices.has(notice.notificationId))
|
|
75585
|
+
return;
|
|
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 });
|
|
75591
|
+
const waiter = serverSettlers.get(cacheKey);
|
|
75592
|
+
if (waiter !== void 0) {
|
|
75593
|
+
serverSettlers.delete(cacheKey);
|
|
75594
|
+
serverHandles.delete(cacheKey);
|
|
75595
|
+
waiter(settlement);
|
|
75596
|
+
} else {
|
|
75597
|
+
settledResults.set(cacheKey, settlement);
|
|
75598
|
+
}
|
|
75599
|
+
}
|
|
75439
75600
|
const authoritative = createAuthoritativeEngine({
|
|
75440
75601
|
clientId: origin,
|
|
75441
75602
|
onChange: publishServerRows,
|
|
75442
|
-
|
|
75443
|
-
const waiter = serverSettlers.get(`${row3.project}:${row3.key}`);
|
|
75444
|
-
if (waiter !== void 0) {
|
|
75445
|
-
serverSettlers.delete(`${row3.project}:${row3.key}`);
|
|
75446
|
-
serverHandles.delete(`${row3.project}:${row3.key}`);
|
|
75447
|
-
waiter({
|
|
75448
|
-
outcome: row3.state === "done" ? "done" : "failed",
|
|
75449
|
-
reason: row3.reason,
|
|
75450
|
-
task: serverRecordToProjection(row3)
|
|
75451
|
-
});
|
|
75452
|
-
}
|
|
75453
|
-
void authoritative.acknowledge({
|
|
75454
|
-
project: row3.project,
|
|
75455
|
-
key: row3.key,
|
|
75456
|
-
version: row3.version,
|
|
75457
|
-
kind: row3.state === "done" ? "settled" : "failed",
|
|
75458
|
-
cursor: `${row3.project}:${row3.key}:${row3.version}`
|
|
75459
|
-
}).catch(() => {
|
|
75460
|
-
});
|
|
75461
|
-
}
|
|
75603
|
+
onNotice: deliverTerminal
|
|
75462
75604
|
});
|
|
75463
75605
|
let seq = 0;
|
|
75464
75606
|
let revision = 0;
|
|
@@ -75729,19 +75871,64 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75729
75871
|
post({ kind: "invoke", origin, reqId, target, taskId, index: index3 });
|
|
75730
75872
|
});
|
|
75731
75873
|
}
|
|
75874
|
+
function emitAction(taskId, snapshot, index3, ok, actionId, reason, result, idempotencyKey) {
|
|
75875
|
+
bus().emit({
|
|
75876
|
+
type: "action",
|
|
75877
|
+
taskId,
|
|
75878
|
+
task: snapshot,
|
|
75879
|
+
...actionId === void 0 ? {} : { actionId },
|
|
75880
|
+
index: index3,
|
|
75881
|
+
ok,
|
|
75882
|
+
...reason === void 0 ? {} : { reason },
|
|
75883
|
+
...result === void 0 ? {} : { result },
|
|
75884
|
+
...idempotencyKey === void 0 ? {} : { idempotencyKey },
|
|
75885
|
+
remote: false
|
|
75886
|
+
});
|
|
75887
|
+
}
|
|
75888
|
+
function serverFallbackSnapshot(taskId) {
|
|
75889
|
+
const rest = taskId.startsWith(`${SERVER_SHARD_ORIGIN}:`) ? taskId.slice(SERVER_SHARD_ORIGIN.length + 1) : "";
|
|
75890
|
+
const separator = rest.indexOf(":");
|
|
75891
|
+
const project = separator >= 0 ? rest.slice(0, separator) : "";
|
|
75892
|
+
const key = separator >= 0 ? rest.slice(separator + 1) : "";
|
|
75893
|
+
return {
|
|
75894
|
+
id: taskId,
|
|
75895
|
+
...key === "" ? {} : { key },
|
|
75896
|
+
project,
|
|
75897
|
+
group: "default",
|
|
75898
|
+
title: "",
|
|
75899
|
+
status: "failed",
|
|
75900
|
+
startedAt: 0,
|
|
75901
|
+
updatedAt: 0,
|
|
75902
|
+
origin: SERVER_SHARD_ORIGIN,
|
|
75903
|
+
backgrounded: false
|
|
75904
|
+
};
|
|
75905
|
+
}
|
|
75732
75906
|
async function runAction(taskId, index3) {
|
|
75733
75907
|
const record = locate(taskId);
|
|
75734
|
-
|
|
75908
|
+
const isServer = record?.origin === SERVER_SHARD_ORIGIN || record === void 0 && taskId.startsWith(`${SERVER_SHARD_ORIGIN}:`);
|
|
75909
|
+
if (record === void 0) {
|
|
75910
|
+
if (isServer)
|
|
75911
|
+
emitAction(taskId, serverFallbackSnapshot(taskId), index3, false, void 0, "task unavailable");
|
|
75735
75912
|
return false;
|
|
75736
|
-
|
|
75913
|
+
}
|
|
75914
|
+
if (record.timeoutMs !== void 0 && Date.now() - record.updatedAt > record.timeoutMs) {
|
|
75915
|
+
if (isServer)
|
|
75916
|
+
emitAction(taskId, record, index3, false, record.actions?.[index3]?.id, "task expired");
|
|
75737
75917
|
return false;
|
|
75918
|
+
}
|
|
75738
75919
|
const action = record.actions?.[index3];
|
|
75739
|
-
if (action === void 0)
|
|
75920
|
+
if (action === void 0) {
|
|
75921
|
+
if (isServer)
|
|
75922
|
+
emitAction(taskId, record, index3, false, void 0, "action unavailable");
|
|
75740
75923
|
return false;
|
|
75741
|
-
|
|
75742
|
-
|
|
75924
|
+
}
|
|
75925
|
+
if (isServer) {
|
|
75926
|
+
if (record.key === void 0 || action.id === void 0) {
|
|
75927
|
+
emitAction(taskId, record, index3, false, action.id, "action unavailable");
|
|
75743
75928
|
return false;
|
|
75929
|
+
}
|
|
75744
75930
|
const result = await authoritative.runAction(record.project, record.key, action.id);
|
|
75931
|
+
emitAction(taskId, record, index3, result.ok, action.id, result.reason, result.result, result.idempotencyKey);
|
|
75745
75932
|
return result.ok;
|
|
75746
75933
|
}
|
|
75747
75934
|
if (record.origin === origin)
|
|
@@ -76127,33 +76314,19 @@ function createTaskNotificationPool(options = {}) {
|
|
|
76127
76314
|
let handle = serverHandles.get(keyOfHandle);
|
|
76128
76315
|
if (handle === void 0) {
|
|
76129
76316
|
let isSettled = false;
|
|
76317
|
+
let resolveSettled = () => {
|
|
76318
|
+
};
|
|
76130
76319
|
const settled = new Promise((resolve) => {
|
|
76131
|
-
|
|
76132
|
-
isSettled = true;
|
|
76133
|
-
resolve(value);
|
|
76134
|
-
});
|
|
76320
|
+
resolveSettled = resolve;
|
|
76135
76321
|
});
|
|
76136
|
-
handle = {
|
|
76137
|
-
|
|
76138
|
-
|
|
76139
|
-
return isSettled;
|
|
76140
|
-
},
|
|
76141
|
-
settled,
|
|
76142
|
-
update() {
|
|
76143
|
-
},
|
|
76144
|
-
touch() {
|
|
76145
|
-
},
|
|
76146
|
-
background() {
|
|
76147
|
-
},
|
|
76148
|
-
done() {
|
|
76149
|
-
},
|
|
76150
|
-
fail() {
|
|
76151
|
-
},
|
|
76152
|
-
track(promise) {
|
|
76153
|
-
return promise;
|
|
76154
|
-
}
|
|
76155
|
-
};
|
|
76322
|
+
handle = { id: id3, get isSettled() {
|
|
76323
|
+
return isSettled;
|
|
76324
|
+
}, settled };
|
|
76156
76325
|
serverHandles.set(keyOfHandle, handle);
|
|
76326
|
+
serverSettlers.set(keyOfHandle, (value) => {
|
|
76327
|
+
isSettled = true;
|
|
76328
|
+
resolveSettled(value);
|
|
76329
|
+
});
|
|
76157
76330
|
}
|
|
76158
76331
|
const created = await authoritative.create({
|
|
76159
76332
|
project,
|
|
@@ -76167,6 +76340,28 @@ function createTaskNotificationPool(options = {}) {
|
|
|
76167
76340
|
});
|
|
76168
76341
|
if (created === void 0)
|
|
76169
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
|
+
}
|
|
76170
76365
|
return { handle, created: created.created };
|
|
76171
76366
|
}
|
|
76172
76367
|
function settleLocal(reason) {
|
|
@@ -76244,6 +76439,8 @@ function createTaskNotificationPool(options = {}) {
|
|
|
76244
76439
|
authoritative.stop();
|
|
76245
76440
|
serverSettlers.clear();
|
|
76246
76441
|
serverHandles.clear();
|
|
76442
|
+
settledResults.clear();
|
|
76443
|
+
deliveredNotices.clear();
|
|
76247
76444
|
if (channel !== null) {
|
|
76248
76445
|
channel.onmessage = null;
|
|
76249
76446
|
channel.close();
|
|
@@ -76916,9 +77113,9 @@ function ReferencePage() {
|
|
|
76916
77113
|
"tbody",
|
|
76917
77114
|
null,
|
|
76918
77115
|
[
|
|
76919
|
-
[t3("buildCore"), `v${"0.
|
|
76920
|
-
[t3("buildDemo"), `v${"0.
|
|
76921
|
-
[t3("buildStamp"), "261116-
|
|
77116
|
+
[t3("buildCore"), `v${"0.39.0"}`],
|
|
77117
|
+
[t3("buildDemo"), `v${"0.39.0"}`],
|
|
77118
|
+
[t3("buildStamp"), "261116-170322-841"]
|
|
76922
77119
|
].map(
|
|
76923
77120
|
([label, value]) => (0, import_react110.createElement)(
|
|
76924
77121
|
"tr",
|
|
@@ -77237,9 +77434,9 @@ function DemoPage() {
|
|
|
77237
77434
|
lineHeight: "14px"
|
|
77238
77435
|
}
|
|
77239
77436
|
},
|
|
77240
|
-
(0, import_react112.createElement)("span", null, `core v${"0.
|
|
77241
|
-
(0, import_react112.createElement)("span", null, `demo v${"0.
|
|
77242
|
-
(0, import_react112.createElement)("span", { style: { marginTop: "4px", fontSize: "9px" } }, "261116-
|
|
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")
|
|
77243
77440
|
)
|
|
77244
77441
|
)
|
|
77245
77442
|
),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-core-demo",
|
|
3
|
-
"version": "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": [
|