dsh-plugin-core-demo 0.37.0 → 0.38.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 +208 -103
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -70023,12 +70023,16 @@ 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",
|
|
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."
|
|
70032
|
+
},
|
|
70033
|
+
{
|
|
70034
|
+
"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",
|
|
70035
|
+
"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
70036
|
}
|
|
70033
70037
|
],
|
|
70034
70038
|
"api": [
|
|
@@ -70040,17 +70044,17 @@ h(SideSheet, {
|
|
|
70040
70044
|
"type": "(project: string, backend: TaskBackend) => void",
|
|
70041
70045
|
"def": "\u2014",
|
|
70042
70046
|
"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"
|
|
70047
|
+
"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",
|
|
70048
|
+
"en": "Switches to authoritative mode; list/follow/listNotices/ackNotices/invoke/ack are mandatory or registration throws"
|
|
70045
70049
|
}
|
|
70046
70050
|
},
|
|
70047
70051
|
{
|
|
70048
70052
|
"name": "notifyTask.server(title, options?)",
|
|
70049
|
-
"type": "(title: string, options?: NotifyTaskOptions) => Promise<
|
|
70053
|
+
"type": "(title: string, options?: NotifyTaskOptions) => Promise<AuthoritativeClaim>",
|
|
70050
70054
|
"def": "\u2014",
|
|
70051
70055
|
"desc": {
|
|
70052
|
-
"zh": "\u670D\u52A1\u7AEF\u539F\u5B50 create \u767B\u8BB0\uFF1B\
|
|
70053
|
-
"en": "Registers through server-side atomic create;
|
|
70056
|
+
"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",
|
|
70057
|
+
"en": "Registers through server-side atomic create; the handle exposes only id/isSettled/settled with no page-writable methods"
|
|
70054
70058
|
}
|
|
70055
70059
|
},
|
|
70056
70060
|
{
|
|
@@ -74820,7 +74824,7 @@ function mergeInto(state, rows) {
|
|
|
74820
74824
|
if (row3.version < seenVersion)
|
|
74821
74825
|
continue;
|
|
74822
74826
|
const terminal = state.terminal.get(row3.key);
|
|
74823
|
-
if (terminal !== void 0 && row3.version <= terminal
|
|
74827
|
+
if (terminal !== void 0 && row3.version <= terminal)
|
|
74824
74828
|
continue;
|
|
74825
74829
|
const current3 = state.seen.get(row3.key);
|
|
74826
74830
|
if (current3 !== void 0 && current3.version > row3.version)
|
|
@@ -74829,16 +74833,16 @@ function mergeInto(state, rows) {
|
|
|
74829
74833
|
continue;
|
|
74830
74834
|
state.seen.set(row3.key, row3);
|
|
74831
74835
|
state.watermark.set(row3.key, row3.version);
|
|
74832
|
-
if (row3.tombstone === true || row3.state !== "running")
|
|
74833
|
-
state.terminal.set(row3.key,
|
|
74834
|
-
}
|
|
74836
|
+
if (row3.tombstone === true || row3.state !== "running")
|
|
74837
|
+
state.terminal.set(row3.key, row3.version);
|
|
74835
74838
|
accepted.push(row3);
|
|
74836
74839
|
}
|
|
74837
74840
|
return accepted;
|
|
74838
74841
|
}
|
|
74839
74842
|
function createAuthoritativeEngine(options) {
|
|
74840
|
-
const { onChange,
|
|
74843
|
+
const { onChange, onNotice, clientId } = options;
|
|
74841
74844
|
const rebaseMinMs = options.rebaseMinMs ?? 5e3;
|
|
74845
|
+
const actionTimeoutMs = options.actionTimeoutMs ?? 5e3;
|
|
74842
74846
|
const backends = /* @__PURE__ */ new Map();
|
|
74843
74847
|
const projects = /* @__PURE__ */ new Map();
|
|
74844
74848
|
const followers = /* @__PURE__ */ new Map();
|
|
@@ -74847,6 +74851,12 @@ function createAuthoritativeEngine(options) {
|
|
|
74847
74851
|
let lastRebase = 0;
|
|
74848
74852
|
let reconnectFailures = 0;
|
|
74849
74853
|
let reconnectTimer = null;
|
|
74854
|
+
const noticeCursors = /* @__PURE__ */ new Map();
|
|
74855
|
+
let noticePumping = false;
|
|
74856
|
+
let noticePending = false;
|
|
74857
|
+
function clientCursor() {
|
|
74858
|
+
return noticeCursors.get(clientId);
|
|
74859
|
+
}
|
|
74850
74860
|
const invokes = /* @__PURE__ */ new Map();
|
|
74851
74861
|
const INVOKE_CACHE_MS = 6e4;
|
|
74852
74862
|
function invokeCacheKey(project, key, actionId, version) {
|
|
@@ -74872,21 +74882,58 @@ function createAuthoritativeEngine(options) {
|
|
|
74872
74882
|
onChange(Object.freeze(all));
|
|
74873
74883
|
}
|
|
74874
74884
|
function applyRows(project, rows) {
|
|
74875
|
-
|
|
74876
|
-
const accepted = mergeInto(state, rows);
|
|
74877
|
-
if (accepted.length === 0)
|
|
74885
|
+
if (mergeInto(projectState(project), rows).length === 0)
|
|
74878
74886
|
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
74887
|
emitChange();
|
|
74889
74888
|
}
|
|
74889
|
+
async function pumpNotices() {
|
|
74890
|
+
if (disposed || !started || backends.size === 0)
|
|
74891
|
+
return;
|
|
74892
|
+
if (noticePumping) {
|
|
74893
|
+
noticePending = true;
|
|
74894
|
+
return;
|
|
74895
|
+
}
|
|
74896
|
+
noticePumping = true;
|
|
74897
|
+
try {
|
|
74898
|
+
do {
|
|
74899
|
+
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)
|
|
74908
|
+
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);
|
|
74926
|
+
}
|
|
74927
|
+
if (page.nextCursor === void 0 || page.nextCursor === cursor2)
|
|
74928
|
+
break;
|
|
74929
|
+
cursor2 = page.nextCursor;
|
|
74930
|
+
}
|
|
74931
|
+
} while (noticePending && !disposed);
|
|
74932
|
+
} catch {
|
|
74933
|
+
} finally {
|
|
74934
|
+
noticePumping = false;
|
|
74935
|
+
}
|
|
74936
|
+
}
|
|
74890
74937
|
function advanceCursor2(project, event) {
|
|
74891
74938
|
const state = projectState(project);
|
|
74892
74939
|
if (event.kind === "cursor")
|
|
@@ -74900,7 +74947,6 @@ function createAuthoritativeEngine(options) {
|
|
|
74900
74947
|
const generation = state.epoch;
|
|
74901
74948
|
try {
|
|
74902
74949
|
let cursor2 = state.cursor;
|
|
74903
|
-
let first = true;
|
|
74904
74950
|
while (!disposed && generation === state.epoch) {
|
|
74905
74951
|
const page = await backend.list(project, cursor2);
|
|
74906
74952
|
if (disposed || generation !== state.epoch)
|
|
@@ -74913,8 +74959,6 @@ function createAuthoritativeEngine(options) {
|
|
|
74913
74959
|
if (page.nextCursor === void 0 || page.nextCursor === cursor2)
|
|
74914
74960
|
break;
|
|
74915
74961
|
cursor2 = page.nextCursor;
|
|
74916
|
-
if (first)
|
|
74917
|
-
first = false;
|
|
74918
74962
|
}
|
|
74919
74963
|
if (disposed || generation !== state.epoch)
|
|
74920
74964
|
return;
|
|
@@ -74949,6 +74993,8 @@ function createAuthoritativeEngine(options) {
|
|
|
74949
74993
|
return;
|
|
74950
74994
|
if (event.kind === "upsert")
|
|
74951
74995
|
applyRows(project, event.rows);
|
|
74996
|
+
else if (event.kind === "notice-available")
|
|
74997
|
+
void pumpNotices();
|
|
74952
74998
|
advanceCursor2(project, event);
|
|
74953
74999
|
}, () => {
|
|
74954
75000
|
for (const project of owned) {
|
|
@@ -74973,13 +75019,14 @@ function createAuthoritativeEngine(options) {
|
|
|
74973
75019
|
if (disposed)
|
|
74974
75020
|
return;
|
|
74975
75021
|
await Promise.all([...backends.keys()].map((project) => rebase(project)));
|
|
75022
|
+
void pumpNotices();
|
|
74976
75023
|
}
|
|
74977
75024
|
return {
|
|
74978
75025
|
attach(project, backend) {
|
|
74979
75026
|
if (disposed)
|
|
74980
75027
|
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`);
|
|
75028
|
+
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") {
|
|
75029
|
+
throw new Error(`task backend for ${project} must provide list/follow/listNotices/ackNotices/invoke/ack`);
|
|
74983
75030
|
}
|
|
74984
75031
|
backends.set(project, backend);
|
|
74985
75032
|
projectState(project);
|
|
@@ -75042,23 +75089,37 @@ function createAuthoritativeEngine(options) {
|
|
|
75042
75089
|
}
|
|
75043
75090
|
if (entry.result !== void 0)
|
|
75044
75091
|
return entry.result;
|
|
75045
|
-
|
|
75046
|
-
|
|
75047
|
-
|
|
75048
|
-
|
|
75049
|
-
|
|
75050
|
-
|
|
75051
|
-
|
|
75052
|
-
|
|
75053
|
-
|
|
75054
|
-
|
|
75055
|
-
|
|
75092
|
+
let timer = null;
|
|
75093
|
+
try {
|
|
75094
|
+
const timed = new Promise((_, reject) => {
|
|
75095
|
+
timer = setTimeout(() => reject(new Error("action timeout")), actionTimeoutMs);
|
|
75096
|
+
});
|
|
75097
|
+
const raw = await Promise.race([backend.invoke({
|
|
75098
|
+
project,
|
|
75099
|
+
key,
|
|
75100
|
+
actionId,
|
|
75101
|
+
token: action.token,
|
|
75102
|
+
version: record.version,
|
|
75103
|
+
idempotencyKey: entry.idempotencyKey
|
|
75104
|
+
}), timed]);
|
|
75105
|
+
const result = { ...raw, idempotencyKey: entry.idempotencyKey };
|
|
75106
|
+
if (result.ok) {
|
|
75107
|
+
entry.result = result;
|
|
75108
|
+
entry.at = Date.now();
|
|
75109
|
+
}
|
|
75110
|
+
return result;
|
|
75111
|
+
} finally {
|
|
75112
|
+
if (timer !== null)
|
|
75113
|
+
clearTimeout(timer);
|
|
75056
75114
|
}
|
|
75057
|
-
return result;
|
|
75058
75115
|
} catch (error) {
|
|
75059
75116
|
return { ok: false, reason: error instanceof Error ? error.message : String(error) };
|
|
75060
75117
|
}
|
|
75061
75118
|
},
|
|
75119
|
+
/** 暴露幂等键供上层在 action 事件里回传,迟到结果由它抑制二次 emit。 */
|
|
75120
|
+
idempotencyKeyFor(project, key, actionId, version) {
|
|
75121
|
+
return invokes.get(invokeCacheKey(project, key, actionId, version))?.idempotencyKey;
|
|
75122
|
+
},
|
|
75062
75123
|
async acknowledge(request) {
|
|
75063
75124
|
const backend = backends.get(request.project);
|
|
75064
75125
|
if (backend === void 0)
|
|
@@ -75077,7 +75138,6 @@ function createAuthoritativeEngine(options) {
|
|
|
75077
75138
|
has(project) {
|
|
75078
75139
|
return backends.has(project);
|
|
75079
75140
|
},
|
|
75080
|
-
/** 停止连接但保留后端与已水合状态;pool.dispose → connect 后可重新 follow。 */
|
|
75081
75141
|
stop() {
|
|
75082
75142
|
for (const state of projects.values())
|
|
75083
75143
|
state.epoch += 1;
|
|
@@ -75102,10 +75162,10 @@ function createAuthoritativeEngine(options) {
|
|
|
75102
75162
|
var import_react106 = require("react");
|
|
75103
75163
|
|
|
75104
75164
|
// 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/
|
|
75165
|
+
var TASK_NOTIFICATIONS_PROTOCOL = 5;
|
|
75166
|
+
var TASK_NOTIFICATIONS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/v5");
|
|
75167
|
+
var TASK_NOTIFICATIONS_EVENTS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/events/v5");
|
|
75168
|
+
var TASK_NOTIFICATIONS_CHANNEL = "dsh-plugin-core/task-notifications/v5";
|
|
75109
75169
|
var SERVER_SHARD_ORIGIN = "__server__";
|
|
75110
75170
|
var INVOKE_TIMEOUT_MS = 2e3;
|
|
75111
75171
|
var DEFAULT_LEASE_MS = 5 * 6e4;
|
|
@@ -75360,7 +75420,7 @@ function makeOrigin2() {
|
|
|
75360
75420
|
function compareTasks(a, b) {
|
|
75361
75421
|
return a.startedAt - b.startedAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
75362
75422
|
}
|
|
75363
|
-
var TASK_NOTIFICATIONS_LOCK_PREFIX = "dsh-plugin-core/task-notifications/
|
|
75423
|
+
var TASK_NOTIFICATIONS_LOCK_PREFIX = "dsh-plugin-core/task-notifications/v5/";
|
|
75364
75424
|
function lockNameFor(pageOrigin) {
|
|
75365
75425
|
return `${TASK_NOTIFICATIONS_LOCK_PREFIX}${pageOrigin}`;
|
|
75366
75426
|
}
|
|
@@ -75436,29 +75496,33 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75436
75496
|
}
|
|
75437
75497
|
const serverSettlers = /* @__PURE__ */ new Map();
|
|
75438
75498
|
const serverHandles = /* @__PURE__ */ new Map();
|
|
75499
|
+
const deliveredNotices = /* @__PURE__ */ new Set();
|
|
75500
|
+
const settledResults = /* @__PURE__ */ new Map();
|
|
75501
|
+
function deliverTerminal(notice) {
|
|
75502
|
+
const row3 = notice.record;
|
|
75503
|
+
const cacheKey = `${row3.project}:${row3.key}`;
|
|
75504
|
+
if (deliveredNotices.has(notice.notificationId))
|
|
75505
|
+
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 });
|
|
75515
|
+
const waiter = serverSettlers.get(cacheKey);
|
|
75516
|
+
if (waiter !== void 0) {
|
|
75517
|
+
serverSettlers.delete(cacheKey);
|
|
75518
|
+
serverHandles.delete(cacheKey);
|
|
75519
|
+
waiter(settlement);
|
|
75520
|
+
}
|
|
75521
|
+
}
|
|
75439
75522
|
const authoritative = createAuthoritativeEngine({
|
|
75440
75523
|
clientId: origin,
|
|
75441
75524
|
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
|
-
}
|
|
75525
|
+
onNotice: deliverTerminal
|
|
75462
75526
|
});
|
|
75463
75527
|
let seq = 0;
|
|
75464
75528
|
let revision = 0;
|
|
@@ -75729,19 +75793,64 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75729
75793
|
post({ kind: "invoke", origin, reqId, target, taskId, index: index3 });
|
|
75730
75794
|
});
|
|
75731
75795
|
}
|
|
75796
|
+
function emitAction(taskId, snapshot, index3, ok, actionId, reason, result, idempotencyKey) {
|
|
75797
|
+
bus().emit({
|
|
75798
|
+
type: "action",
|
|
75799
|
+
taskId,
|
|
75800
|
+
task: snapshot,
|
|
75801
|
+
...actionId === void 0 ? {} : { actionId },
|
|
75802
|
+
index: index3,
|
|
75803
|
+
ok,
|
|
75804
|
+
...reason === void 0 ? {} : { reason },
|
|
75805
|
+
...result === void 0 ? {} : { result },
|
|
75806
|
+
...idempotencyKey === void 0 ? {} : { idempotencyKey },
|
|
75807
|
+
remote: false
|
|
75808
|
+
});
|
|
75809
|
+
}
|
|
75810
|
+
function serverFallbackSnapshot(taskId) {
|
|
75811
|
+
const rest = taskId.startsWith(`${SERVER_SHARD_ORIGIN}:`) ? taskId.slice(SERVER_SHARD_ORIGIN.length + 1) : "";
|
|
75812
|
+
const separator = rest.indexOf(":");
|
|
75813
|
+
const project = separator >= 0 ? rest.slice(0, separator) : "";
|
|
75814
|
+
const key = separator >= 0 ? rest.slice(separator + 1) : "";
|
|
75815
|
+
return {
|
|
75816
|
+
id: taskId,
|
|
75817
|
+
...key === "" ? {} : { key },
|
|
75818
|
+
project,
|
|
75819
|
+
group: "default",
|
|
75820
|
+
title: "",
|
|
75821
|
+
status: "failed",
|
|
75822
|
+
startedAt: 0,
|
|
75823
|
+
updatedAt: 0,
|
|
75824
|
+
origin: SERVER_SHARD_ORIGIN,
|
|
75825
|
+
backgrounded: false
|
|
75826
|
+
};
|
|
75827
|
+
}
|
|
75732
75828
|
async function runAction(taskId, index3) {
|
|
75733
75829
|
const record = locate(taskId);
|
|
75734
|
-
|
|
75830
|
+
const isServer = record?.origin === SERVER_SHARD_ORIGIN || record === void 0 && taskId.startsWith(`${SERVER_SHARD_ORIGIN}:`);
|
|
75831
|
+
if (record === void 0) {
|
|
75832
|
+
if (isServer)
|
|
75833
|
+
emitAction(taskId, serverFallbackSnapshot(taskId), index3, false, void 0, "task unavailable");
|
|
75735
75834
|
return false;
|
|
75736
|
-
|
|
75835
|
+
}
|
|
75836
|
+
if (record.timeoutMs !== void 0 && Date.now() - record.updatedAt > record.timeoutMs) {
|
|
75837
|
+
if (isServer)
|
|
75838
|
+
emitAction(taskId, record, index3, false, record.actions?.[index3]?.id, "task expired");
|
|
75737
75839
|
return false;
|
|
75840
|
+
}
|
|
75738
75841
|
const action = record.actions?.[index3];
|
|
75739
|
-
if (action === void 0)
|
|
75842
|
+
if (action === void 0) {
|
|
75843
|
+
if (isServer)
|
|
75844
|
+
emitAction(taskId, record, index3, false, void 0, "action unavailable");
|
|
75740
75845
|
return false;
|
|
75741
|
-
|
|
75742
|
-
|
|
75846
|
+
}
|
|
75847
|
+
if (isServer) {
|
|
75848
|
+
if (record.key === void 0 || action.id === void 0) {
|
|
75849
|
+
emitAction(taskId, record, index3, false, action.id, "action unavailable");
|
|
75743
75850
|
return false;
|
|
75851
|
+
}
|
|
75744
75852
|
const result = await authoritative.runAction(record.project, record.key, action.id);
|
|
75853
|
+
emitAction(taskId, record, index3, result.ok, action.id, result.reason, result.result, result.idempotencyKey);
|
|
75745
75854
|
return result.ok;
|
|
75746
75855
|
}
|
|
75747
75856
|
if (record.origin === origin)
|
|
@@ -76127,33 +76236,27 @@ function createTaskNotificationPool(options = {}) {
|
|
|
76127
76236
|
let handle = serverHandles.get(keyOfHandle);
|
|
76128
76237
|
if (handle === void 0) {
|
|
76129
76238
|
let isSettled = false;
|
|
76239
|
+
let resolveSettled = () => {
|
|
76240
|
+
};
|
|
76130
76241
|
const settled = new Promise((resolve) => {
|
|
76242
|
+
resolveSettled = resolve;
|
|
76243
|
+
});
|
|
76244
|
+
handle = { id: id3, get isSettled() {
|
|
76245
|
+
return isSettled;
|
|
76246
|
+
}, settled };
|
|
76247
|
+
serverHandles.set(keyOfHandle, handle);
|
|
76248
|
+
const cached = settledResults.get(keyOfHandle);
|
|
76249
|
+
if (cached !== void 0) {
|
|
76250
|
+
settledResults.delete(keyOfHandle);
|
|
76251
|
+
serverHandles.delete(keyOfHandle);
|
|
76252
|
+
isSettled = true;
|
|
76253
|
+
resolveSettled(cached);
|
|
76254
|
+
} else {
|
|
76131
76255
|
serverSettlers.set(keyOfHandle, (value) => {
|
|
76132
76256
|
isSettled = true;
|
|
76133
|
-
|
|
76257
|
+
resolveSettled(value);
|
|
76134
76258
|
});
|
|
76135
|
-
}
|
|
76136
|
-
handle = {
|
|
76137
|
-
id: id3,
|
|
76138
|
-
get isSettled() {
|
|
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
|
-
};
|
|
76156
|
-
serverHandles.set(keyOfHandle, handle);
|
|
76259
|
+
}
|
|
76157
76260
|
}
|
|
76158
76261
|
const created = await authoritative.create({
|
|
76159
76262
|
project,
|
|
@@ -76244,6 +76347,8 @@ function createTaskNotificationPool(options = {}) {
|
|
|
76244
76347
|
authoritative.stop();
|
|
76245
76348
|
serverSettlers.clear();
|
|
76246
76349
|
serverHandles.clear();
|
|
76350
|
+
settledResults.clear();
|
|
76351
|
+
deliveredNotices.clear();
|
|
76247
76352
|
if (channel !== null) {
|
|
76248
76353
|
channel.onmessage = null;
|
|
76249
76354
|
channel.close();
|
|
@@ -76916,9 +77021,9 @@ function ReferencePage() {
|
|
|
76916
77021
|
"tbody",
|
|
76917
77022
|
null,
|
|
76918
77023
|
[
|
|
76919
|
-
[t3("buildCore"), `v${"0.
|
|
76920
|
-
[t3("buildDemo"), `v${"0.
|
|
76921
|
-
[t3("buildStamp"), "261116-
|
|
77024
|
+
[t3("buildCore"), `v${"0.38.0"}`],
|
|
77025
|
+
[t3("buildDemo"), `v${"0.38.0"}`],
|
|
77026
|
+
[t3("buildStamp"), "261116-161113-772"]
|
|
76922
77027
|
].map(
|
|
76923
77028
|
([label, value]) => (0, import_react110.createElement)(
|
|
76924
77029
|
"tr",
|
|
@@ -77237,9 +77342,9 @@ function DemoPage() {
|
|
|
77237
77342
|
lineHeight: "14px"
|
|
77238
77343
|
}
|
|
77239
77344
|
},
|
|
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-
|
|
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")
|
|
77243
77348
|
)
|
|
77244
77349
|
)
|
|
77245
77350
|
),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-core-demo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.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": [
|