dsh-plugin-core-demo 0.36.2 → 0.37.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 +529 -13
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -70015,6 +70015,66 @@ h(SideSheet, {
|
|
|
70015
70015
|
}
|
|
70016
70016
|
]
|
|
70017
70017
|
},
|
|
70018
|
+
"bt-authoritative": {
|
|
70019
|
+
"id": "bt-authoritative",
|
|
70020
|
+
"heading": {
|
|
70021
|
+
"zh": "\u670D\u52A1\u7AEF\u6743\u5A01\u4EFB\u52A1\uFF1A\u6062\u590D\u3001\u5224\u6B7B\u4E0E\u547D\u4EE4",
|
|
70022
|
+
"en": "Authoritative server tasks: recovery, watchdog and commands"
|
|
70023
|
+
},
|
|
70024
|
+
"prose": [
|
|
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` \u56DB\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 / invoke / ack`; registering otherwise throws \u2014 there is no silent fallback."
|
|
70028
|
+
},
|
|
70029
|
+
{
|
|
70030
|
+
"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\uFF0C\u7EC8\u6001\u5893\u7891\u6321\u4F4F\u8FDF\u5230\u5FEB\u7167\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\u7ED3\u679C\u901A\u77E5\u6309 `(project, scope, key, version, kind)` \u53BB\u91CD\u5E76 ack\uFF1B\u672A\u786E\u8BA4\u7684\u4E0B\u6B21\u5F00\u9875\u8865\u53D1\u3002",
|
|
70031
|
+
"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. The core only merges baseline, pages and deltas by monotonic version, with terminal tombstones blocking late snapshots. Actions are `{id, token, expiresAt}` descriptors and `runAction` dispatches by actionId to the server, never through page closures. Result notices are deduplicated by `(project, scope, key, version, kind)` and acked; unacked notices replay on the next page open."
|
|
70032
|
+
}
|
|
70033
|
+
],
|
|
70034
|
+
"api": [
|
|
70035
|
+
{
|
|
70036
|
+
"id": "bt-authoritative-api",
|
|
70037
|
+
"rows": [
|
|
70038
|
+
{
|
|
70039
|
+
"name": "taskNotifications.setTaskBackend(project, backend)",
|
|
70040
|
+
"type": "(project: string, backend: TaskBackend) => void",
|
|
70041
|
+
"def": "\u2014",
|
|
70042
|
+
"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"
|
|
70045
|
+
}
|
|
70046
|
+
},
|
|
70047
|
+
{
|
|
70048
|
+
"name": "notifyTask.server(title, options?)",
|
|
70049
|
+
"type": "(title: string, options?: NotifyTaskOptions) => Promise<TaskNotificationClaim>",
|
|
70050
|
+
"def": "\u2014",
|
|
70051
|
+
"desc": {
|
|
70052
|
+
"zh": "\u670D\u52A1\u7AEF\u539F\u5B50 create \u767B\u8BB0\uFF1B\u5FC5\u987B\u6709 key\uFF0Ccreated === false \u65F6\u4E0D\u8981\u8D77\u7B2C\u4E8C\u4EFD\u4F5C\u4E1A",
|
|
70053
|
+
"en": "Registers through server-side atomic create; a key is required, and created === false means do not start a second job"
|
|
70054
|
+
}
|
|
70055
|
+
},
|
|
70056
|
+
{
|
|
70057
|
+
"name": "createHttpTaskBackend(options)",
|
|
70058
|
+
"type": "(options: HttpTaskBackendOptions) => TaskBackend",
|
|
70059
|
+
"def": "\u2014",
|
|
70060
|
+
"desc": {
|
|
70061
|
+
"zh": "HTTP transport\uFF1B\u4ECE dsh-plugin-core/adv/tasks/http-backend \u5BFC\u5165\uFF0C\u957F\u8FDE\u63A5\u65AD\u5F00\u7531\u5F15\u64CE\u9000\u907F\u91CD\u8FDE",
|
|
70062
|
+
"en": "HTTP transport from dsh-plugin-core/adv/tasks/http-backend; the engine reconnects a dropped stream with backoff"
|
|
70063
|
+
}
|
|
70064
|
+
},
|
|
70065
|
+
{
|
|
70066
|
+
"name": "serveTaskCenter(ctx, options)",
|
|
70067
|
+
"type": "(ctx: HostContextLike, options: TaskCenterRouteOptions) => () => void",
|
|
70068
|
+
"def": "\u2014",
|
|
70069
|
+
"desc": {
|
|
70070
|
+
"zh": "\u5BBF\u4E3B\u4FA7\u8DEF\u7531\u88C5\u914D\uFF08dsh-plugin-core/host/task-center\uFF09\uFF1Bauthorize \u5FC5\u586B\uFF0C\u5BBF\u4E3B\u4E0D\u63D0\u4F9B\u5168\u5C40\u9274\u6743",
|
|
70071
|
+
"en": "Host-side route wiring (dsh-plugin-core/host/task-center); authorize is mandatory because the host provides no global auth"
|
|
70072
|
+
}
|
|
70073
|
+
}
|
|
70074
|
+
]
|
|
70075
|
+
}
|
|
70076
|
+
]
|
|
70077
|
+
},
|
|
70018
70078
|
"bt-use-tasks": {
|
|
70019
70079
|
"id": "bt-use-tasks",
|
|
70020
70080
|
"heading": {
|
|
@@ -74744,14 +74804,309 @@ function PaginationPage() {
|
|
|
74744
74804
|
// packages/demo/src/sections/task-notifications.tsx
|
|
74745
74805
|
var import_react108 = require("react");
|
|
74746
74806
|
|
|
74807
|
+
// dist/adv/tasks/authoritative.js
|
|
74808
|
+
var idempotencySeq = 0;
|
|
74809
|
+
function newIdempotencyKey(clientId) {
|
|
74810
|
+
idempotencySeq += 1;
|
|
74811
|
+
const random = Math.random().toString(36).slice(2);
|
|
74812
|
+
return `${clientId}:${Date.now().toString(36)}:${idempotencySeq.toString(36)}:${random}`;
|
|
74813
|
+
}
|
|
74814
|
+
function mergeInto(state, rows) {
|
|
74815
|
+
const accepted = [];
|
|
74816
|
+
for (const row3 of rows) {
|
|
74817
|
+
if (!Number.isFinite(row3.version))
|
|
74818
|
+
continue;
|
|
74819
|
+
const seenVersion = state.watermark.get(row3.key) ?? -1;
|
|
74820
|
+
if (row3.version < seenVersion)
|
|
74821
|
+
continue;
|
|
74822
|
+
const terminal = state.terminal.get(row3.key);
|
|
74823
|
+
if (terminal !== void 0 && row3.version <= terminal.version)
|
|
74824
|
+
continue;
|
|
74825
|
+
const current3 = state.seen.get(row3.key);
|
|
74826
|
+
if (current3 !== void 0 && current3.version > row3.version)
|
|
74827
|
+
continue;
|
|
74828
|
+
if (current3 !== void 0 && current3.version === row3.version && current3.state === row3.state)
|
|
74829
|
+
continue;
|
|
74830
|
+
state.seen.set(row3.key, row3);
|
|
74831
|
+
state.watermark.set(row3.key, row3.version);
|
|
74832
|
+
if (row3.tombstone === true || row3.state !== "running") {
|
|
74833
|
+
state.terminal.set(row3.key, { version: row3.version, acked: false });
|
|
74834
|
+
}
|
|
74835
|
+
accepted.push(row3);
|
|
74836
|
+
}
|
|
74837
|
+
return accepted;
|
|
74838
|
+
}
|
|
74839
|
+
function createAuthoritativeEngine(options) {
|
|
74840
|
+
const { onChange, onTerminal, clientId } = options;
|
|
74841
|
+
const rebaseMinMs = options.rebaseMinMs ?? 5e3;
|
|
74842
|
+
const backends = /* @__PURE__ */ new Map();
|
|
74843
|
+
const projects = /* @__PURE__ */ new Map();
|
|
74844
|
+
const followers = /* @__PURE__ */ new Map();
|
|
74845
|
+
let started = false;
|
|
74846
|
+
let disposed = false;
|
|
74847
|
+
let lastRebase = 0;
|
|
74848
|
+
let reconnectFailures = 0;
|
|
74849
|
+
let reconnectTimer = null;
|
|
74850
|
+
const invokes = /* @__PURE__ */ new Map();
|
|
74851
|
+
const INVOKE_CACHE_MS = 6e4;
|
|
74852
|
+
function invokeCacheKey(project, key, actionId, version) {
|
|
74853
|
+
return `${project}:${key}:${actionId}:${version}`;
|
|
74854
|
+
}
|
|
74855
|
+
function projectState(project) {
|
|
74856
|
+
let state = projects.get(project);
|
|
74857
|
+
if (state === void 0) {
|
|
74858
|
+
state = { snapshotVersion: -1, epoch: 0, seen: /* @__PURE__ */ new Map(), watermark: /* @__PURE__ */ new Map(), terminal: /* @__PURE__ */ new Map() };
|
|
74859
|
+
projects.set(project, state);
|
|
74860
|
+
}
|
|
74861
|
+
return state;
|
|
74862
|
+
}
|
|
74863
|
+
function emitChange() {
|
|
74864
|
+
const all = [];
|
|
74865
|
+
for (const state of projects.values()) {
|
|
74866
|
+
for (const row3 of state.seen.values()) {
|
|
74867
|
+
if (row3.tombstone === true || row3.state !== "running")
|
|
74868
|
+
continue;
|
|
74869
|
+
all.push(row3);
|
|
74870
|
+
}
|
|
74871
|
+
}
|
|
74872
|
+
onChange(Object.freeze(all));
|
|
74873
|
+
}
|
|
74874
|
+
function applyRows(project, rows) {
|
|
74875
|
+
const state = projectState(project);
|
|
74876
|
+
const accepted = mergeInto(state, rows);
|
|
74877
|
+
if (accepted.length === 0)
|
|
74878
|
+
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
|
+
emitChange();
|
|
74889
|
+
}
|
|
74890
|
+
function advanceCursor2(project, event) {
|
|
74891
|
+
const state = projectState(project);
|
|
74892
|
+
if (event.kind === "cursor")
|
|
74893
|
+
state.cursor = event.cursor;
|
|
74894
|
+
}
|
|
74895
|
+
async function rebase(project) {
|
|
74896
|
+
const backend = backends.get(project);
|
|
74897
|
+
if (backend === void 0 || disposed)
|
|
74898
|
+
return;
|
|
74899
|
+
const state = projectState(project);
|
|
74900
|
+
const generation = state.epoch;
|
|
74901
|
+
try {
|
|
74902
|
+
let cursor2 = state.cursor;
|
|
74903
|
+
let first = true;
|
|
74904
|
+
while (!disposed && generation === state.epoch) {
|
|
74905
|
+
const page = await backend.list(project, cursor2);
|
|
74906
|
+
if (disposed || generation !== state.epoch)
|
|
74907
|
+
return;
|
|
74908
|
+
if (page.rows.length > 0)
|
|
74909
|
+
applyRows(project, page.rows);
|
|
74910
|
+
if (page.snapshotVersion < state.snapshotVersion)
|
|
74911
|
+
break;
|
|
74912
|
+
state.snapshotVersion = page.snapshotVersion;
|
|
74913
|
+
if (page.nextCursor === void 0 || page.nextCursor === cursor2)
|
|
74914
|
+
break;
|
|
74915
|
+
cursor2 = page.nextCursor;
|
|
74916
|
+
if (first)
|
|
74917
|
+
first = false;
|
|
74918
|
+
}
|
|
74919
|
+
if (disposed || generation !== state.epoch)
|
|
74920
|
+
return;
|
|
74921
|
+
state.cursor = cursor2;
|
|
74922
|
+
reconnectFailures = 0;
|
|
74923
|
+
startFollow();
|
|
74924
|
+
} catch {
|
|
74925
|
+
}
|
|
74926
|
+
}
|
|
74927
|
+
function startFollow() {
|
|
74928
|
+
if (disposed || backends.size === 0)
|
|
74929
|
+
return;
|
|
74930
|
+
const byBackend = /* @__PURE__ */ new Map();
|
|
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) {
|
|
74939
|
+
if (followers.has(backend))
|
|
74940
|
+
continue;
|
|
74941
|
+
const cursors = {};
|
|
74942
|
+
for (const project of owned) {
|
|
74943
|
+
const state = projects.get(project);
|
|
74944
|
+
if (state?.cursor !== void 0)
|
|
74945
|
+
cursors[project] = state.cursor;
|
|
74946
|
+
}
|
|
74947
|
+
followers.set(backend, backend.follow(owned, cursors, (project, event) => {
|
|
74948
|
+
if (disposed || !owned.includes(project))
|
|
74949
|
+
return;
|
|
74950
|
+
if (event.kind === "upsert")
|
|
74951
|
+
applyRows(project, event.rows);
|
|
74952
|
+
advanceCursor2(project, event);
|
|
74953
|
+
}, () => {
|
|
74954
|
+
for (const project of owned) {
|
|
74955
|
+
const state = projects.get(project);
|
|
74956
|
+
if (state !== void 0)
|
|
74957
|
+
state.epoch += 1;
|
|
74958
|
+
}
|
|
74959
|
+
followers.get(backend)?.();
|
|
74960
|
+
followers.delete(backend);
|
|
74961
|
+
if (disposed || reconnectTimer !== null)
|
|
74962
|
+
return;
|
|
74963
|
+
reconnectFailures += 1;
|
|
74964
|
+
const delay = Math.min(15e3, 250 * 2 ** Math.min(reconnectFailures, 6)) + Math.random() * 250;
|
|
74965
|
+
reconnectTimer = setTimeout(() => {
|
|
74966
|
+
reconnectTimer = null;
|
|
74967
|
+
void rebaseAll();
|
|
74968
|
+
}, delay);
|
|
74969
|
+
}));
|
|
74970
|
+
}
|
|
74971
|
+
}
|
|
74972
|
+
async function rebaseAll() {
|
|
74973
|
+
if (disposed)
|
|
74974
|
+
return;
|
|
74975
|
+
await Promise.all([...backends.keys()].map((project) => rebase(project)));
|
|
74976
|
+
}
|
|
74977
|
+
return {
|
|
74978
|
+
attach(project, backend) {
|
|
74979
|
+
if (disposed)
|
|
74980
|
+
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`);
|
|
74983
|
+
}
|
|
74984
|
+
backends.set(project, backend);
|
|
74985
|
+
projectState(project);
|
|
74986
|
+
if (started) {
|
|
74987
|
+
const wasStarted = started;
|
|
74988
|
+
this.stop();
|
|
74989
|
+
started = wasStarted;
|
|
74990
|
+
void rebaseAll();
|
|
74991
|
+
}
|
|
74992
|
+
},
|
|
74993
|
+
start() {
|
|
74994
|
+
if (started || disposed)
|
|
74995
|
+
return;
|
|
74996
|
+
started = true;
|
|
74997
|
+
void rebaseAll();
|
|
74998
|
+
},
|
|
74999
|
+
visible() {
|
|
75000
|
+
const now = Date.now();
|
|
75001
|
+
if (now - lastRebase < rebaseMinMs)
|
|
75002
|
+
return;
|
|
75003
|
+
lastRebase = now;
|
|
75004
|
+
void rebaseAll();
|
|
75005
|
+
},
|
|
75006
|
+
refresh(project) {
|
|
75007
|
+
if (project === void 0)
|
|
75008
|
+
void rebaseAll();
|
|
75009
|
+
else
|
|
75010
|
+
void rebase(project);
|
|
75011
|
+
},
|
|
75012
|
+
find(project, key) {
|
|
75013
|
+
return projectState(project).seen.get(key);
|
|
75014
|
+
},
|
|
75015
|
+
all() {
|
|
75016
|
+
const all = [];
|
|
75017
|
+
for (const state of projects.values()) {
|
|
75018
|
+
for (const row3 of state.seen.values()) {
|
|
75019
|
+
if (row3.tombstone === true || row3.state !== "running")
|
|
75020
|
+
continue;
|
|
75021
|
+
all.push(row3);
|
|
75022
|
+
}
|
|
75023
|
+
}
|
|
75024
|
+
return Object.freeze(all);
|
|
75025
|
+
},
|
|
75026
|
+
async runAction(project, key, actionId) {
|
|
75027
|
+
try {
|
|
75028
|
+
const backend = backends.get(project);
|
|
75029
|
+
const record = projectState(project).seen.get(key);
|
|
75030
|
+
const action = record?.actions.find((item) => item.id === actionId);
|
|
75031
|
+
if (backend === void 0 || record === void 0 || action === void 0) {
|
|
75032
|
+
return { ok: false, reason: "action unavailable" };
|
|
75033
|
+
}
|
|
75034
|
+
if (!action.enabled || action.expiresAt <= Date.now() || action.version !== void 0 && action.version !== record.version) {
|
|
75035
|
+
return { ok: false, reason: "action expired" };
|
|
75036
|
+
}
|
|
75037
|
+
const cacheKey = invokeCacheKey(project, key, actionId, record.version);
|
|
75038
|
+
let entry = invokes.get(cacheKey);
|
|
75039
|
+
if (entry === void 0 || Date.now() - entry.at > INVOKE_CACHE_MS) {
|
|
75040
|
+
entry = { idempotencyKey: newIdempotencyKey(clientId), at: Date.now() };
|
|
75041
|
+
invokes.set(cacheKey, entry);
|
|
75042
|
+
}
|
|
75043
|
+
if (entry.result !== void 0)
|
|
75044
|
+
return entry.result;
|
|
75045
|
+
const result = await backend.invoke({
|
|
75046
|
+
project,
|
|
75047
|
+
key,
|
|
75048
|
+
actionId,
|
|
75049
|
+
token: action.token,
|
|
75050
|
+
version: record.version,
|
|
75051
|
+
idempotencyKey: entry.idempotencyKey
|
|
75052
|
+
});
|
|
75053
|
+
if (result.ok) {
|
|
75054
|
+
entry.result = result;
|
|
75055
|
+
entry.at = Date.now();
|
|
75056
|
+
}
|
|
75057
|
+
return result;
|
|
75058
|
+
} catch (error) {
|
|
75059
|
+
return { ok: false, reason: error instanceof Error ? error.message : String(error) };
|
|
75060
|
+
}
|
|
75061
|
+
},
|
|
75062
|
+
async acknowledge(request) {
|
|
75063
|
+
const backend = backends.get(request.project);
|
|
75064
|
+
if (backend === void 0)
|
|
75065
|
+
return;
|
|
75066
|
+
await backend.ack(request);
|
|
75067
|
+
},
|
|
75068
|
+
async create(input) {
|
|
75069
|
+
const backend = backends.get(input.project);
|
|
75070
|
+
if (backend?.create === void 0)
|
|
75071
|
+
return void 0;
|
|
75072
|
+
const result = await backend.create(input);
|
|
75073
|
+
if (result.record !== void 0)
|
|
75074
|
+
applyRows(input.project, [result.record]);
|
|
75075
|
+
return result;
|
|
75076
|
+
},
|
|
75077
|
+
has(project) {
|
|
75078
|
+
return backends.has(project);
|
|
75079
|
+
},
|
|
75080
|
+
/** 停止连接但保留后端与已水合状态;pool.dispose → connect 后可重新 follow。 */
|
|
75081
|
+
stop() {
|
|
75082
|
+
for (const state of projects.values())
|
|
75083
|
+
state.epoch += 1;
|
|
75084
|
+
for (const off of followers.values())
|
|
75085
|
+
off();
|
|
75086
|
+
followers.clear();
|
|
75087
|
+
started = false;
|
|
75088
|
+
if (reconnectTimer !== null)
|
|
75089
|
+
clearTimeout(reconnectTimer);
|
|
75090
|
+
reconnectTimer = null;
|
|
75091
|
+
},
|
|
75092
|
+
dispose() {
|
|
75093
|
+
disposed = true;
|
|
75094
|
+
this.stop();
|
|
75095
|
+
projects.clear();
|
|
75096
|
+
invokes.clear();
|
|
75097
|
+
}
|
|
75098
|
+
};
|
|
75099
|
+
}
|
|
75100
|
+
|
|
74747
75101
|
// dist/adv/tasks/TaskBar.js
|
|
74748
75102
|
var import_react106 = require("react");
|
|
74749
75103
|
|
|
74750
75104
|
// dist/adv/tasks/pool.js
|
|
74751
|
-
var TASK_NOTIFICATIONS_PROTOCOL =
|
|
74752
|
-
var TASK_NOTIFICATIONS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/
|
|
74753
|
-
var TASK_NOTIFICATIONS_EVENTS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/events/
|
|
74754
|
-
var TASK_NOTIFICATIONS_CHANNEL = "dsh-plugin-core/task-notifications/
|
|
75105
|
+
var TASK_NOTIFICATIONS_PROTOCOL = 4;
|
|
75106
|
+
var TASK_NOTIFICATIONS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/v4");
|
|
75107
|
+
var TASK_NOTIFICATIONS_EVENTS_KEY = /* @__PURE__ */ Symbol.for("dsh-plugin-core/task-notifications/events/v4");
|
|
75108
|
+
var TASK_NOTIFICATIONS_CHANNEL = "dsh-plugin-core/task-notifications/v4";
|
|
75109
|
+
var SERVER_SHARD_ORIGIN = "__server__";
|
|
74755
75110
|
var INVOKE_TIMEOUT_MS = 2e3;
|
|
74756
75111
|
var DEFAULT_LEASE_MS = 5 * 6e4;
|
|
74757
75112
|
var DEFAULT_POLL_INTERVAL_MS = 6e4;
|
|
@@ -74884,7 +75239,7 @@ function isActionInfos(value) {
|
|
|
74884
75239
|
return Array.isArray(value) && value.every((item) => {
|
|
74885
75240
|
if (!isRecord6(item))
|
|
74886
75241
|
return false;
|
|
74887
|
-
if (!Object.keys(item).every((key) => key === "label" || key === "icon" || key === "color"))
|
|
75242
|
+
if (!Object.keys(item).every((key) => key === "id" || key === "label" || key === "icon" || key === "color"))
|
|
74888
75243
|
return false;
|
|
74889
75244
|
if (!isOptionalString(item.label))
|
|
74890
75245
|
return false;
|
|
@@ -74932,6 +75287,10 @@ function isTaskRecord(value) {
|
|
|
74932
75287
|
if (value.maxDurationMs !== void 0 && (typeof value.maxDurationMs !== "number" || !Number.isFinite(value.maxDurationMs) || value.maxDurationMs < 0)) {
|
|
74933
75288
|
return false;
|
|
74934
75289
|
}
|
|
75290
|
+
if (value.version !== void 0 && (typeof value.version !== "number" || !Number.isFinite(value.version)))
|
|
75291
|
+
return false;
|
|
75292
|
+
if (value.deadlineAt !== void 0 && (typeof value.deadlineAt !== "number" || !Number.isFinite(value.deadlineAt)))
|
|
75293
|
+
return false;
|
|
74935
75294
|
return typeof value.id === "string" && typeof value.project === "string" && typeof value.group === "string" && typeof value.title === "string" && (value.status === "running" || value.status === "done" || value.status === "failed") && Number.isFinite(value.startedAt) && Number.isFinite(value.updatedAt) && typeof value.origin === "string" && typeof value.backgrounded === "boolean";
|
|
74936
75295
|
}
|
|
74937
75296
|
function isNotice(value) {
|
|
@@ -75001,7 +75360,7 @@ function makeOrigin2() {
|
|
|
75001
75360
|
function compareTasks(a, b) {
|
|
75002
75361
|
return a.startedAt - b.startedAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
75003
75362
|
}
|
|
75004
|
-
var TASK_NOTIFICATIONS_LOCK_PREFIX = "dsh-plugin-core/task-notifications/
|
|
75363
|
+
var TASK_NOTIFICATIONS_LOCK_PREFIX = "dsh-plugin-core/task-notifications/v4/";
|
|
75005
75364
|
function lockNameFor(pageOrigin) {
|
|
75006
75365
|
return `${TASK_NOTIFICATIONS_LOCK_PREFIX}${pageOrigin}`;
|
|
75007
75366
|
}
|
|
@@ -75041,6 +75400,66 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75041
75400
|
const store = createStore2(() => EMPTY_SNAPSHOT);
|
|
75042
75401
|
const shards = /* @__PURE__ */ new Map();
|
|
75043
75402
|
const knownSeq = /* @__PURE__ */ new Map();
|
|
75403
|
+
function serverRecordToProjection(row3) {
|
|
75404
|
+
return {
|
|
75405
|
+
id: `${SERVER_SHARD_ORIGIN}:${row3.project}:${row3.key}`,
|
|
75406
|
+
key: row3.key,
|
|
75407
|
+
project: row3.project,
|
|
75408
|
+
group: row3.group,
|
|
75409
|
+
...row3.groupLabel === void 0 ? {} : { groupLabel: row3.groupLabel },
|
|
75410
|
+
...row3.projectLabel === void 0 ? {} : { projectLabel: row3.projectLabel },
|
|
75411
|
+
...row3.icon === void 0 ? {} : { icon: row3.icon },
|
|
75412
|
+
...row3.iconSvg === void 0 ? {} : { iconSvg: row3.iconSvg },
|
|
75413
|
+
title: row3.title,
|
|
75414
|
+
...row3.detail === void 0 ? {} : { detail: row3.detail },
|
|
75415
|
+
...row3.actions.length === 0 ? {} : { actions: row3.actions.map(({ id: id3, label, icon, color }) => ({ ...id3 === "" ? {} : { id: id3 }, label, icon, color })) },
|
|
75416
|
+
status: row3.state === "running" ? "running" : row3.state,
|
|
75417
|
+
startedAt: row3.startedAt,
|
|
75418
|
+
updatedAt: row3.updatedAt,
|
|
75419
|
+
origin: SERVER_SHARD_ORIGIN,
|
|
75420
|
+
backgrounded: false,
|
|
75421
|
+
...row3.hidden === true ? { hidden: true } : {},
|
|
75422
|
+
...row3.reason === void 0 ? {} : { reason: row3.reason },
|
|
75423
|
+
version: row3.version,
|
|
75424
|
+
deadlineAt: row3.deadlineAt
|
|
75425
|
+
};
|
|
75426
|
+
}
|
|
75427
|
+
function publishServerRows(rows) {
|
|
75428
|
+
const projections = rows.map(serverRecordToProjection);
|
|
75429
|
+
shards.set(SERVER_SHARD_ORIGIN, {
|
|
75430
|
+
origin: SERVER_SHARD_ORIGIN,
|
|
75431
|
+
seq: 0,
|
|
75432
|
+
tasks: Object.freeze(projections)
|
|
75433
|
+
});
|
|
75434
|
+
revision += 1;
|
|
75435
|
+
store.setState({ tasks: collect(), revision }, true);
|
|
75436
|
+
}
|
|
75437
|
+
const serverSettlers = /* @__PURE__ */ new Map();
|
|
75438
|
+
const serverHandles = /* @__PURE__ */ new Map();
|
|
75439
|
+
const authoritative = createAuthoritativeEngine({
|
|
75440
|
+
clientId: origin,
|
|
75441
|
+
onChange: publishServerRows,
|
|
75442
|
+
onTerminal: (row3) => {
|
|
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
|
+
}
|
|
75462
|
+
});
|
|
75044
75463
|
let seq = 0;
|
|
75045
75464
|
let revision = 0;
|
|
75046
75465
|
let idSeq2 = 0;
|
|
@@ -75316,8 +75735,15 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75316
75735
|
return false;
|
|
75317
75736
|
if (record.timeoutMs !== void 0 && Date.now() - record.updatedAt > record.timeoutMs)
|
|
75318
75737
|
return false;
|
|
75319
|
-
|
|
75738
|
+
const action = record.actions?.[index3];
|
|
75739
|
+
if (action === void 0)
|
|
75320
75740
|
return false;
|
|
75741
|
+
if (record.origin === SERVER_SHARD_ORIGIN) {
|
|
75742
|
+
if (record.key === void 0 || action.id === void 0)
|
|
75743
|
+
return false;
|
|
75744
|
+
const result = await authoritative.runAction(record.project, record.key, action.id);
|
|
75745
|
+
return result.ok;
|
|
75746
|
+
}
|
|
75321
75747
|
if (record.origin === origin)
|
|
75322
75748
|
return runLocal(taskId, index3);
|
|
75323
75749
|
return requestInvoke(record.origin, taskId, index3);
|
|
@@ -75474,10 +75900,12 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75474
75900
|
}
|
|
75475
75901
|
scheduleExpiry();
|
|
75476
75902
|
schedulePoll();
|
|
75903
|
+
authoritative.start();
|
|
75477
75904
|
}
|
|
75478
75905
|
function refresh() {
|
|
75479
75906
|
holdLiveness();
|
|
75480
75907
|
post({ kind: "hello", origin });
|
|
75908
|
+
authoritative.visible();
|
|
75481
75909
|
}
|
|
75482
75910
|
function ensure(input) {
|
|
75483
75911
|
const project = requireProject(input.project);
|
|
@@ -75494,6 +75922,9 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75494
75922
|
throw new Error("task notification timeoutMs must be a finite number >= 0");
|
|
75495
75923
|
}
|
|
75496
75924
|
const serverBacked = input.serverBacked === true;
|
|
75925
|
+
if (serverBacked && key !== void 0 && authoritative.has(project)) {
|
|
75926
|
+
throw new Error("authoritative project requires ensureServer(), not ensure()");
|
|
75927
|
+
}
|
|
75497
75928
|
if (serverBacked && key === void 0) {
|
|
75498
75929
|
throw new Error("task notification serverBacked requires a key");
|
|
75499
75930
|
}
|
|
@@ -75681,6 +76112,63 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75681
76112
|
}
|
|
75682
76113
|
return { handle, created: true };
|
|
75683
76114
|
}
|
|
76115
|
+
async function ensureServer(input) {
|
|
76116
|
+
const project = requireProject(input.project);
|
|
76117
|
+
if (project === null)
|
|
76118
|
+
throw new Error("task notification project cannot be null when registering");
|
|
76119
|
+
if (input.key === void 0)
|
|
76120
|
+
throw new Error("server task requires a key");
|
|
76121
|
+
if (!authoritative.has(project)) {
|
|
76122
|
+
throw new Error(`project ${project} has no authoritative backend; call setTaskBackend first`);
|
|
76123
|
+
}
|
|
76124
|
+
const key = taskKey(input.key);
|
|
76125
|
+
const id3 = `${SERVER_SHARD_ORIGIN}:${project}:${key}`;
|
|
76126
|
+
const keyOfHandle = `${project}:${key}`;
|
|
76127
|
+
let handle = serverHandles.get(keyOfHandle);
|
|
76128
|
+
if (handle === void 0) {
|
|
76129
|
+
let isSettled = false;
|
|
76130
|
+
const settled = new Promise((resolve) => {
|
|
76131
|
+
serverSettlers.set(keyOfHandle, (value) => {
|
|
76132
|
+
isSettled = true;
|
|
76133
|
+
resolve(value);
|
|
76134
|
+
});
|
|
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);
|
|
76157
|
+
}
|
|
76158
|
+
const created = await authoritative.create({
|
|
76159
|
+
project,
|
|
76160
|
+
key,
|
|
76161
|
+
group: normalizeGroup(input.group),
|
|
76162
|
+
title: input.title,
|
|
76163
|
+
...input.detail === void 0 ? {} : { detail: cloneDetail(input.detail) },
|
|
76164
|
+
...input.timeoutMs === void 0 ? {} : { timeoutMs: input.timeoutMs },
|
|
76165
|
+
...input.leaseMs === void 0 ? {} : { leaseMs: input.leaseMs },
|
|
76166
|
+
...input.maxDurationMs === void 0 ? {} : { maxDurationMs: input.maxDurationMs }
|
|
76167
|
+
});
|
|
76168
|
+
if (created === void 0)
|
|
76169
|
+
throw new Error(`project ${project} backend does not support create`);
|
|
76170
|
+
return { handle, created: created.created };
|
|
76171
|
+
}
|
|
75684
76172
|
function settleLocal(reason) {
|
|
75685
76173
|
let settledCount = 0;
|
|
75686
76174
|
for (const task of [...localShard()]) {
|
|
@@ -75706,6 +76194,7 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75706
76194
|
select: (groups, options2) => selectTaskNotifications(store.getState(), groups, options2),
|
|
75707
76195
|
register: (input) => ensure(input).handle,
|
|
75708
76196
|
ensure,
|
|
76197
|
+
ensureServer,
|
|
75709
76198
|
broadcast,
|
|
75710
76199
|
setStatusSource(project, source) {
|
|
75711
76200
|
if (typeof project !== "string" || project.trim() === "") {
|
|
@@ -75714,9 +76203,23 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75714
76203
|
if (typeof source !== "function") {
|
|
75715
76204
|
throw new Error("task notification status source must be a function");
|
|
75716
76205
|
}
|
|
76206
|
+
if (authoritative.has(project)) {
|
|
76207
|
+
throw new Error(`project ${project} is in authoritative mode; setStatusSource is not allowed`);
|
|
76208
|
+
}
|
|
75717
76209
|
statusSources.set(project, source);
|
|
75718
76210
|
schedulePoll();
|
|
75719
76211
|
},
|
|
76212
|
+
setTaskBackend(project, backend) {
|
|
76213
|
+
if (typeof project !== "string" || project.trim() === "") {
|
|
76214
|
+
throw new Error("task backend project must be a non-empty string");
|
|
76215
|
+
}
|
|
76216
|
+
if (store.getState().tasks.some((task) => task.project === project && task.serverBacked === true)) {
|
|
76217
|
+
throw new Error(`project ${project} still has legacy serverBacked tasks; settle them before switching`);
|
|
76218
|
+
}
|
|
76219
|
+
statusSources.delete(project);
|
|
76220
|
+
authoritative.attach(project, backend);
|
|
76221
|
+
authoritative.start();
|
|
76222
|
+
},
|
|
75720
76223
|
settleLocal,
|
|
75721
76224
|
runAction,
|
|
75722
76225
|
canRestore: (task) => task.origin === origin,
|
|
@@ -75738,6 +76241,9 @@ function createTaskNotificationPool(options = {}) {
|
|
|
75738
76241
|
for (const entry of pendingInvokes.values())
|
|
75739
76242
|
entry.resolve(false);
|
|
75740
76243
|
pendingInvokes.clear();
|
|
76244
|
+
authoritative.stop();
|
|
76245
|
+
serverSettlers.clear();
|
|
76246
|
+
serverHandles.clear();
|
|
75741
76247
|
if (channel !== null) {
|
|
75742
76248
|
channel.onmessage = null;
|
|
75743
76249
|
channel.close();
|
|
@@ -75776,10 +76282,14 @@ var taskNotifications = {
|
|
|
75776
76282
|
select: (groups, options) => globalPool().select(groups, options),
|
|
75777
76283
|
register: (input) => globalPool().register(input),
|
|
75778
76284
|
ensure: (input) => globalPool().ensure(input),
|
|
76285
|
+
ensureServer: (input) => globalPool().ensureServer(input),
|
|
75779
76286
|
broadcast: (input) => globalPool().broadcast(input),
|
|
75780
76287
|
setStatusSource: (project, source) => {
|
|
75781
76288
|
globalPool().setStatusSource(project, source);
|
|
75782
76289
|
},
|
|
76290
|
+
setTaskBackend: (project, backend) => {
|
|
76291
|
+
globalPool().setTaskBackend(project, backend);
|
|
76292
|
+
},
|
|
75783
76293
|
settleLocal: (reason) => globalPool().settleLocal(reason),
|
|
75784
76294
|
runAction: (taskId, index3) => globalPool().runAction(taskId, index3),
|
|
75785
76295
|
canRestore: (task) => globalPool().canRestore(task),
|
|
@@ -75816,6 +76326,11 @@ function ensureTask(title, options = {}) {
|
|
|
75816
76326
|
function backgroundTask(title, options = {}) {
|
|
75817
76327
|
return taskNotifications.ensure(notifyTaskInput(title, { ...options, serverBacked: true }));
|
|
75818
76328
|
}
|
|
76329
|
+
function serverTask(title, options = {}) {
|
|
76330
|
+
if (options.key === void 0)
|
|
76331
|
+
return Promise.reject(new Error("notifyTask.server requires a key"));
|
|
76332
|
+
return taskNotifications.ensureServer(notifyTaskInput(title, { ...options, serverBacked: true }));
|
|
76333
|
+
}
|
|
75819
76334
|
function runTask(title, work, options = {}) {
|
|
75820
76335
|
let claim2;
|
|
75821
76336
|
let key;
|
|
@@ -75841,6 +76356,7 @@ function runTask(title, work, options = {}) {
|
|
|
75841
76356
|
var notifyTask = Object.assign(notifyTaskBase, {
|
|
75842
76357
|
ensure: ensureTask,
|
|
75843
76358
|
background: backgroundTask,
|
|
76359
|
+
server: serverTask,
|
|
75844
76360
|
run: runTask
|
|
75845
76361
|
});
|
|
75846
76362
|
var taskNotificationEvents = {
|
|
@@ -76400,9 +76916,9 @@ function ReferencePage() {
|
|
|
76400
76916
|
"tbody",
|
|
76401
76917
|
null,
|
|
76402
76918
|
[
|
|
76403
|
-
[t3("buildCore"), `v${"0.
|
|
76404
|
-
[t3("buildDemo"), `v${"0.
|
|
76405
|
-
[t3("buildStamp"), "261116-
|
|
76919
|
+
[t3("buildCore"), `v${"0.37.0"}`],
|
|
76920
|
+
[t3("buildDemo"), `v${"0.37.0"}`],
|
|
76921
|
+
[t3("buildStamp"), "261116-141954-478"]
|
|
76406
76922
|
].map(
|
|
76407
76923
|
([label, value]) => (0, import_react110.createElement)(
|
|
76408
76924
|
"tr",
|
|
@@ -76721,9 +77237,9 @@ function DemoPage() {
|
|
|
76721
77237
|
lineHeight: "14px"
|
|
76722
77238
|
}
|
|
76723
77239
|
},
|
|
76724
|
-
(0, import_react112.createElement)("span", null, `core v${"0.
|
|
76725
|
-
(0, import_react112.createElement)("span", null, `demo v${"0.
|
|
76726
|
-
(0, import_react112.createElement)("span", { style: { marginTop: "4px", fontSize: "9px" } }, "261116-
|
|
77240
|
+
(0, import_react112.createElement)("span", null, `core v${"0.37.0"}`),
|
|
77241
|
+
(0, import_react112.createElement)("span", null, `demo v${"0.37.0"}`),
|
|
77242
|
+
(0, import_react112.createElement)("span", { style: { marginTop: "4px", fontSize: "9px" } }, "261116-141954-478")
|
|
76727
77243
|
)
|
|
76728
77244
|
)
|
|
76729
77245
|
),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-core-demo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.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": [
|