@dsh-workbench/shared 1.5.2-alpha.4 → 1.5.2-rc.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/components/Activity.css +69 -0
- package/dist/components/Activity.d.ts +56 -0
- package/dist/components/Activity.js +47 -0
- package/dist/components/ApprovalDetail.css +3 -0
- package/dist/components/ApprovalDetail.d.ts +42 -0
- package/dist/components/ApprovalDetail.js +53 -0
- package/dist/components/ApprovalPlan.css +39 -0
- package/dist/components/ApprovalPlan.d.ts +27 -0
- package/dist/components/ApprovalPlan.js +19 -0
- package/dist/components/Card.css +19 -0
- package/dist/components/Card.d.ts +26 -0
- package/dist/components/Card.js +18 -0
- package/dist/components/CardAnchor.d.ts +21 -0
- package/dist/components/CardAnchor.js +19 -0
- package/dist/components/CardAnchor.module.css +3 -0
- package/dist/components/CardBoundary.d.ts +42 -0
- package/dist/components/CardBoundary.js +58 -0
- package/dist/components/CardBoundary.module.css +5 -0
- package/dist/components/CardHead.css +87 -0
- package/dist/components/CardHead.d.ts +30 -0
- package/dist/components/CardHead.js +27 -0
- package/dist/components/ChoiceGroup.css +182 -0
- package/dist/components/ChoiceGroup.d.ts +54 -0
- package/dist/components/ChoiceGroup.js +63 -0
- package/dist/components/ConfirmBar.css +26 -0
- package/dist/components/ConfirmBar.d.ts +36 -0
- package/dist/components/ConfirmBar.js +26 -0
- package/dist/components/EmptyIllustration.d.ts +12 -0
- package/dist/components/EmptyIllustration.js +32 -0
- package/dist/components/Field.css +20 -0
- package/dist/components/Field.d.ts +18 -0
- package/dist/components/Field.js +15 -0
- package/dist/components/Form.css +6 -0
- package/dist/components/Form.d.ts +22 -0
- package/dist/components/Form.js +60 -0
- package/dist/components/FormActions.css +13 -0
- package/dist/components/FormActions.d.ts +29 -0
- package/dist/components/FormActions.js +43 -0
- package/dist/components/FormNodes.d.ts +107 -0
- package/dist/components/FormNodes.js +165 -0
- package/dist/components/FormRows.css +107 -0
- package/dist/components/FormRows.d.ts +36 -0
- package/dist/components/FormRows.js +26 -0
- package/dist/components/FormTypes.d.ts +84 -0
- package/dist/components/FormTypes.js +1 -0
- package/dist/components/Link.css +22 -0
- package/dist/components/Link.d.ts +22 -0
- package/dist/components/Link.js +17 -0
- package/dist/components/LongTaskRow.css +171 -0
- package/dist/components/LongTaskRow.d.ts +94 -0
- package/dist/components/LongTaskRow.js +103 -0
- package/dist/components/Note.css +13 -0
- package/dist/components/Note.d.ts +20 -0
- package/dist/components/Note.js +14 -0
- package/dist/components/ResourceStates.css +114 -0
- package/dist/components/ResourceStates.d.ts +44 -0
- package/dist/components/ResourceStates.js +41 -0
- package/dist/components/Rows.css +42 -0
- package/dist/components/Rows.d.ts +28 -0
- package/dist/components/Rows.js +21 -0
- package/dist/components/SaveBar.d.ts +24 -0
- package/dist/components/SaveBar.js +25 -0
- package/dist/components/SelectField.css +182 -0
- package/dist/components/SelectField.d.ts +89 -0
- package/dist/components/SelectField.js +260 -0
- package/dist/components/SelectFieldNodes.d.ts +49 -0
- package/dist/components/SelectFieldNodes.js +43 -0
- package/dist/components/SettingsSection.css +25 -0
- package/dist/components/SettingsSection.d.ts +20 -0
- package/dist/components/SettingsSection.js +17 -0
- package/dist/components/SetupShell.d.ts +93 -0
- package/dist/components/SetupShell.js +64 -0
- package/dist/components/SetupShell.module.css +81 -0
- package/dist/components/Spinner.css +5 -0
- package/dist/components/Spinner.d.ts +15 -0
- package/dist/components/Spinner.js +13 -0
- package/dist/components/Stack.css +6 -0
- package/dist/components/Stack.d.ts +14 -0
- package/dist/components/Stack.js +10 -0
- package/dist/components/StateBlock.css +38 -0
- package/dist/components/StateBlock.d.ts +24 -0
- package/dist/components/StateBlock.js +22 -0
- package/dist/components/TextField.css +32 -0
- package/dist/components/TextField.d.ts +14 -0
- package/dist/components/TextField.js +10 -0
- package/dist/components/board-module.d.ts +307 -0
- package/dist/components/board-module.js +1 -0
- package/dist/components/card-view-validate.d.ts +5 -0
- package/dist/components/card-view-validate.js +256 -0
- package/dist/components/icons.d.ts +63 -0
- package/dist/components/icons.js +107 -0
- package/dist/components/layout/icon-command.d.ts +8 -0
- package/dist/components/layout/icon-command.js +21 -0
- package/dist/contract/capture.d.ts +16 -0
- package/dist/contract/capture.js +1 -0
- package/dist/contract/diagnostics.d.ts +34 -0
- package/dist/contract/diagnostics.js +124 -0
- package/dist/contract/needs.d.ts +3 -1
- package/dist/contract/needs.js +4 -2
- package/dist/contract/protocol/bundle-install.d.ts +1 -1
- package/dist/contract/protocol/unit-manager.d.ts +50 -0
- package/dist/contract/protocol/unit-manager.js +2 -0
- package/dist/contract/unit.js +2 -1
- package/dist/host/adapter-contract.d.ts +3 -0
- package/dist/host/adapter-contract.js +95 -0
- package/dist/host/adapter-set.d.ts +27 -0
- package/dist/host/adapter-set.js +258 -0
- package/dist/host/adapter-types.d.ts +87 -0
- package/dist/host/adapter-types.js +23 -0
- package/dist/host/adapters/platform.d.ts +14 -0
- package/dist/host/adapters/platform.js +40 -0
- package/dist/host/adapters.d.ts +28 -0
- package/dist/host/adapters.js +9 -0
- package/dist/host/auth-loss.d.ts +33 -0
- package/dist/host/auth-loss.js +107 -0
- package/dist/host/board-fact.d.ts +8 -0
- package/dist/host/board-fact.js +16 -0
- package/dist/host/boot-record.d.ts +11 -0
- package/dist/host/boot-record.js +31 -0
- package/dist/host/browser.d.ts +3 -0
- package/dist/host/browser.js +3 -0
- package/dist/host/bundle-manager.d.ts +4 -0
- package/dist/host/bundle-manager.js +338 -0
- package/dist/host/changelog.d.ts +28 -0
- package/dist/host/changelog.js +201 -0
- package/dist/host/cli-error.d.ts +8 -0
- package/dist/host/cli-error.js +70 -0
- package/dist/host/cli.d.ts +4 -0
- package/dist/host/cli.js +9 -0
- package/dist/host/config-sync.d.ts +40 -0
- package/dist/host/config-sync.js +267 -0
- package/dist/host/context-ref.d.ts +13 -0
- package/dist/host/context-ref.js +41 -0
- package/dist/host/data-error.d.ts +15 -0
- package/dist/host/data-error.js +23 -0
- package/dist/host/data-plan-check.d.ts +10 -0
- package/dist/host/data-plan-check.js +315 -0
- package/dist/host/data-plan.d.ts +15 -0
- package/dist/host/data-plan.js +283 -0
- package/dist/host/data-root.d.ts +5 -0
- package/dist/host/data-root.js +23 -0
- package/dist/host/diy-debug.d.ts +80 -0
- package/dist/host/diy-debug.js +89 -0
- package/dist/host/diy-preset.d.ts +26 -0
- package/dist/host/diy-preset.js +115 -0
- package/dist/host/diy-record.d.ts +135 -0
- package/dist/host/diy-record.js +163 -0
- package/dist/host/dsh-compat.d.ts +27 -0
- package/dist/host/dsh-compat.js +75 -0
- package/dist/host/dsh-plugins.d.ts +5 -0
- package/dist/host/dsh-plugins.js +51 -0
- package/dist/host/env-policy.d.ts +82 -0
- package/dist/host/env-policy.js +181 -0
- package/dist/host/extension.d.ts +7 -0
- package/dist/host/extension.js +40 -0
- package/dist/host/facts.d.ts +31 -0
- package/dist/host/facts.js +58 -0
- package/dist/host/fs-write.d.ts +96 -0
- package/dist/host/fs-write.js +183 -0
- package/dist/host/git.d.ts +5 -0
- package/dist/host/git.js +1 -0
- package/dist/host/host-actions.d.ts +2 -0
- package/dist/host/host-actions.js +5 -0
- package/dist/host/host-kit.d.ts +37 -0
- package/dist/host/host-kit.js +27 -0
- package/dist/host/http.d.ts +47 -0
- package/dist/host/http.js +289 -0
- package/dist/host/install-failure.d.ts +50 -0
- package/dist/host/install-failure.js +184 -0
- package/dist/host/installed-module.d.ts +25 -0
- package/dist/host/installed-module.js +289 -0
- package/dist/host/installed-sources.d.ts +10 -0
- package/dist/host/installed-sources.js +63 -0
- package/dist/host/lease.d.ts +70 -0
- package/dist/host/lease.js +264 -0
- package/dist/host/lib-capabilities.d.ts +22 -0
- package/dist/host/lib-capabilities.js +37 -0
- package/dist/host/lib-install.d.ts +19 -0
- package/dist/host/lib-install.js +40 -0
- package/dist/host/lib-runners.d.ts +18 -0
- package/dist/host/lib-runners.js +46 -0
- package/dist/host/local-declaration.d.ts +7 -0
- package/dist/host/local-declaration.js +33 -0
- package/dist/host/long-task.d.ts +97 -0
- package/dist/host/long-task.js +297 -0
- package/dist/host/market-index-claim.d.ts +19 -0
- package/dist/host/market-index-claim.js +87 -0
- package/dist/host/market-index-doc.d.ts +12 -0
- package/dist/host/market-index-doc.js +1 -0
- package/dist/host/market-index-parse.d.ts +28 -0
- package/dist/host/market-index-parse.js +413 -0
- package/dist/host/market-index.d.ts +13 -0
- package/dist/host/market-index.js +105 -0
- package/dist/host/module-root.d.ts +1 -0
- package/dist/host/module-root.js +5 -0
- package/dist/host/needs.d.ts +4 -0
- package/dist/host/needs.js +2 -0
- package/dist/host/npm-registry.d.ts +10 -0
- package/dist/host/npm-registry.js +16 -0
- package/dist/host/package-content.d.ts +8 -0
- package/dist/host/package-content.js +90 -0
- package/dist/host/package-kind.d.ts +13 -0
- package/dist/host/package-kind.js +51 -0
- package/dist/host/package-route.d.ts +33 -0
- package/dist/host/package-route.js +68 -0
- package/dist/host/panel-state.d.ts +120 -0
- package/dist/host/panel-state.js +177 -0
- package/dist/host/patch-blocks.d.ts +13 -0
- package/dist/host/patch-blocks.js +52 -0
- package/dist/host/patch.d.ts +4 -0
- package/dist/host/patch.js +7 -0
- package/dist/host/paths.d.ts +12 -0
- package/dist/host/paths.js +20 -0
- package/dist/host/payload.d.ts +12 -0
- package/dist/host/payload.js +16 -0
- package/dist/host/plan-results.d.ts +5 -0
- package/dist/host/plan-results.js +71 -0
- package/dist/host/plan-run.d.ts +41 -0
- package/dist/host/plan-run.js +87 -0
- package/dist/host/platform.d.ts +14 -0
- package/dist/host/platform.js +40 -0
- package/dist/host/plugin-ledger.d.ts +32 -0
- package/dist/host/plugin-ledger.js +106 -0
- package/dist/host/plugin.d.ts +3 -0
- package/dist/host/plugin.js +38 -0
- package/dist/host/port-types.d.ts +233 -0
- package/dist/host/port-types.js +1 -0
- package/dist/host/preflight.d.ts +32 -0
- package/dist/host/preflight.js +1 -0
- package/dist/host/process-alive.d.ts +6 -0
- package/dist/host/process-alive.js +16 -0
- package/dist/host/profile-bundles.d.ts +20 -0
- package/dist/host/profile-bundles.js +48 -0
- package/dist/host/profile-create.d.ts +19 -0
- package/dist/host/profile-create.js +124 -0
- package/dist/host/profile-port.d.ts +4 -0
- package/dist/host/profile-port.js +4 -0
- package/dist/host/profile-registries.d.ts +10 -0
- package/dist/host/profile-registries.js +149 -0
- package/dist/host/provision.d.ts +32 -0
- package/dist/host/provision.js +105 -0
- package/dist/host/read-json.d.ts +1 -0
- package/dist/host/read-json.js +11 -0
- package/dist/host/recipe-rules.d.ts +5 -0
- package/dist/host/recipe-rules.js +412 -0
- package/dist/host/recipe.d.ts +14 -0
- package/dist/host/recipe.js +332 -0
- package/dist/host/registry-declaration.d.ts +21 -0
- package/dist/host/registry-declaration.js +42 -0
- package/dist/host/reinstall-record.d.ts +16 -0
- package/dist/host/reinstall-record.js +54 -0
- package/dist/host/release-age.d.ts +24 -0
- package/dist/host/release-age.js +92 -0
- package/dist/host/release-packages.generated.d.ts +1 -0
- package/dist/host/release-packages.generated.js +10 -0
- package/dist/host/release-probe.d.ts +37 -0
- package/dist/host/release-probe.js +156 -0
- package/dist/host/runtime/browser-argv.d.ts +1 -0
- package/dist/host/runtime/browser-argv.js +9 -0
- package/dist/host/runtime/dsh-compat.d.ts +4 -0
- package/dist/host/runtime/dsh-compat.js +32 -16
- package/dist/host/runtime/front-app.d.ts +6 -0
- package/dist/host/runtime/front-app.js +70 -0
- package/dist/host/runtime/verified-dsh.d.ts +5 -0
- package/dist/host/runtime/verified-dsh.js +20 -0
- package/dist/host/shell-render.d.ts +52 -0
- package/dist/host/shell-render.js +117 -0
- package/dist/host/shell-text.d.ts +30 -0
- package/dist/host/shell-text.js +40 -0
- package/dist/host/shell.d.ts +25 -0
- package/dist/host/shell.js +55 -0
- package/dist/host/site.d.ts +45 -0
- package/dist/host/site.js +182 -0
- package/dist/host/spec.d.ts +8 -0
- package/dist/host/spec.js +24 -0
- package/dist/host/submit-confirm.d.ts +19 -0
- package/dist/host/submit-confirm.js +45 -0
- package/dist/host/supply/builtin-catalog.d.ts +3 -0
- package/dist/host/supply/builtin-catalog.js +38 -0
- package/dist/host/supply/preflight.d.ts +14 -1
- package/dist/host/supply/supply-index.js +6 -0
- package/dist/host/supply-index.d.ts +38 -0
- package/dist/host/supply-index.js +209 -0
- package/dist/host/supply-port.d.ts +5 -0
- package/dist/host/supply-port.js +50 -0
- package/dist/host/time.d.ts +22 -0
- package/dist/host/time.js +33 -0
- package/dist/host/tokens.d.ts +26 -0
- package/dist/host/tokens.js +154 -0
- package/dist/host/tool-approval.d.ts +86 -0
- package/dist/host/tool-approval.js +118 -0
- package/dist/host/tool-kit.d.ts +8 -0
- package/dist/host/tool-kit.js +22 -0
- package/dist/host/toolbox-port.d.ts +16 -0
- package/dist/host/toolbox-port.js +1 -0
- package/dist/host/unit-config.d.ts +34 -0
- package/dist/host/unit-config.js +28 -0
- package/dist/host/unit-data.d.ts +3 -0
- package/dist/host/unit-data.js +127 -0
- package/dist/host/unit-face.d.ts +95 -0
- package/dist/host/unit-face.js +1 -0
- package/dist/host/unit-plugin.d.ts +24 -0
- package/dist/host/unit-plugin.js +25 -0
- package/dist/host/update-journal-manifest.d.ts +19 -0
- package/dist/host/update-journal-manifest.js +134 -0
- package/dist/host/update-journal-types.d.ts +33 -0
- package/dist/host/update-journal-types.js +2 -0
- package/dist/host/update-journal.d.ts +43 -0
- package/dist/host/update-journal.js +409 -0
- package/dist/host/value-handoff.d.ts +16 -0
- package/dist/host/value-handoff.js +22 -0
- package/dist/host/version-range.d.ts +2 -0
- package/dist/host/version-range.js +13 -0
- package/dist/host/version.d.ts +4 -0
- package/dist/host/version.js +32 -0
- package/dist/host/workspace-store.d.ts +19 -0
- package/dist/host/workspace-store.js +133 -0
- package/dist/host/write-result.d.ts +1 -0
- package/dist/host/write-result.js +18 -0
- package/dist/host.d.ts +2 -0
- package/dist/host.js +2 -0
- package/dist/i18n/en.js +14 -3
- package/dist/i18n/index.d.ts +15 -4
- package/dist/i18n/zh.d.ts +14 -3
- package/dist/i18n/zh.js +14 -3
- package/dist/lib/bundle-requirements.d.ts +1 -0
- package/dist/lib/bundle-requirements.js +9 -0
- package/package.json +1 -1
- package/src/contract/__tests__/unit.test.ts +7 -0
- package/src/contract/needs.ts +5 -3
- package/src/contract/protocol/bundle-install.ts +1 -0
- package/src/contract/unit.ts +2 -1
- package/src/host/runtime/__tests__/dsh-compat.test.ts +19 -1
- package/src/host/runtime/__tests__/verified-dsh.test.ts +55 -0
- package/src/host/runtime/dsh-compat.ts +36 -12
- package/src/host/runtime/verified-dsh.ts +22 -0
- package/src/host/supply/__tests__/builtin-catalog.test.ts +44 -0
- package/src/host/supply/builtin-catalog.ts +38 -0
- package/src/host/supply/preflight.ts +16 -1
- package/src/host/supply/supply-index.ts +3 -0
- package/src/host.ts +2 -0
- package/src/i18n/en.ts +17 -3
- package/src/i18n/zh.ts +16 -3
- package/src/lib/bundle-requirements.ts +11 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { epochOf, now as clockNow, nowIso } from './time.js';
|
|
2
|
+
import { runsRouteOf, } from '../contract/long-task.js';
|
|
3
|
+
function isLiveStatus(status) {
|
|
4
|
+
return status === 'running' || status === 'needs-human' || status === 'needs-login';
|
|
5
|
+
}
|
|
6
|
+
const RECENT_MS = 10 * 60 * 1000;
|
|
7
|
+
export function createLongTaskRegistry(deps) {
|
|
8
|
+
let bound = deps;
|
|
9
|
+
const runs = new Map();
|
|
10
|
+
const controls = new Map();
|
|
11
|
+
const now = () => (bound.now ?? nowIso)();
|
|
12
|
+
let counter = 0;
|
|
13
|
+
const nextId = () => (bound.nextId ?? (() => `run-${clockNow()}-${(counter += 1)}`))();
|
|
14
|
+
const recentMs = () => bound.recentMs ?? RECENT_MS;
|
|
15
|
+
const listeners = new Set();
|
|
16
|
+
const live = (id) => {
|
|
17
|
+
const current = runs.get(id);
|
|
18
|
+
if (current === undefined || !isLiveStatus(current.status))
|
|
19
|
+
return null;
|
|
20
|
+
return current;
|
|
21
|
+
};
|
|
22
|
+
const notify = (change) => {
|
|
23
|
+
for (const listener of [...listeners]) {
|
|
24
|
+
try {
|
|
25
|
+
listener(change);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const patch = (id, next, change) => {
|
|
32
|
+
const current = runs.get(id);
|
|
33
|
+
if (current === undefined)
|
|
34
|
+
return;
|
|
35
|
+
const patched = { ...current, ...next, at: now() };
|
|
36
|
+
runs.set(id, patched);
|
|
37
|
+
notify({ ...change, snapshot: patched });
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
get resumable() {
|
|
41
|
+
return bound.recheck !== undefined;
|
|
42
|
+
},
|
|
43
|
+
get answerable() {
|
|
44
|
+
return bound.answer !== undefined;
|
|
45
|
+
},
|
|
46
|
+
active(workspace, target) {
|
|
47
|
+
for (const snapshot of runs.values()) {
|
|
48
|
+
if (snapshot.workspace !== workspace || snapshot.target !== target)
|
|
49
|
+
continue;
|
|
50
|
+
if (isLiveStatus(snapshot.status))
|
|
51
|
+
return snapshot;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
},
|
|
55
|
+
current(workspace) {
|
|
56
|
+
const floor = epochOf(now()) - recentMs();
|
|
57
|
+
const newest = new Map();
|
|
58
|
+
for (const snapshot of runs.values()) {
|
|
59
|
+
if (snapshot.workspace !== workspace)
|
|
60
|
+
continue;
|
|
61
|
+
newest.set(snapshot.target, snapshot);
|
|
62
|
+
}
|
|
63
|
+
return [...newest.values()]
|
|
64
|
+
.filter((snapshot) => isLiveStatus(snapshot.status) || epochOf(snapshot.at) >= floor)
|
|
65
|
+
.reverse()
|
|
66
|
+
.map((snapshot) => ({
|
|
67
|
+
...bound.view(snapshot),
|
|
68
|
+
id: snapshot.id,
|
|
69
|
+
...(bound.recheck === undefined ? {} : { resumable: true }),
|
|
70
|
+
...(bound.answer === undefined ? {} : { answerable: true }),
|
|
71
|
+
}));
|
|
72
|
+
},
|
|
73
|
+
live() {
|
|
74
|
+
return [...runs.values()].filter((snapshot) => isLiveStatus(snapshot.status));
|
|
75
|
+
},
|
|
76
|
+
start(options) {
|
|
77
|
+
const running = this.active(options.workspace, options.target);
|
|
78
|
+
if (running !== null)
|
|
79
|
+
return running;
|
|
80
|
+
const id = nextId();
|
|
81
|
+
const startedAt = now();
|
|
82
|
+
runs.set(id, {
|
|
83
|
+
id,
|
|
84
|
+
workspace: options.workspace,
|
|
85
|
+
target: options.target,
|
|
86
|
+
status: 'running',
|
|
87
|
+
step: '',
|
|
88
|
+
steps: [],
|
|
89
|
+
startedAt,
|
|
90
|
+
at: startedAt,
|
|
91
|
+
...(options.session === undefined ? {} : { session: options.session }),
|
|
92
|
+
});
|
|
93
|
+
notify({ kind: 'start', snapshot: runs.get(id) });
|
|
94
|
+
const onStep = (step) => {
|
|
95
|
+
const current = live(id);
|
|
96
|
+
if (current === null)
|
|
97
|
+
return;
|
|
98
|
+
const line = `${step.kind === 'fail' ? '✗ ' : ''}${step.text}`;
|
|
99
|
+
const repeated = current.step === step.text &&
|
|
100
|
+
step.intervention !== undefined &&
|
|
101
|
+
current.intervention?.title === step.intervention.title;
|
|
102
|
+
const steps = repeated ? current.steps : [...current.steps, line].slice(-20);
|
|
103
|
+
const extra = bound.step?.(step, current) ?? {};
|
|
104
|
+
if (step.intervention !== undefined) {
|
|
105
|
+
patch(id, {
|
|
106
|
+
...extra,
|
|
107
|
+
status: 'needs-human',
|
|
108
|
+
step: step.text,
|
|
109
|
+
steps,
|
|
110
|
+
intervention: step.intervention,
|
|
111
|
+
loginUrl: undefined,
|
|
112
|
+
}, { kind: 'step', step });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (step.loginUrl !== undefined && step.loginUrl !== '') {
|
|
116
|
+
patch(id, { ...extra, status: 'needs-login', step: step.text, steps, loginUrl: step.loginUrl }, { kind: 'step', step });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
patch(id, {
|
|
120
|
+
...extra,
|
|
121
|
+
status: 'running',
|
|
122
|
+
step: step.text,
|
|
123
|
+
steps,
|
|
124
|
+
intervention: undefined,
|
|
125
|
+
loginUrl: undefined,
|
|
126
|
+
}, { kind: 'step', step });
|
|
127
|
+
};
|
|
128
|
+
const control = new AbortController();
|
|
129
|
+
controls.set(id, control);
|
|
130
|
+
void bound
|
|
131
|
+
.run({ payload: options.payload, onStep, signal: control.signal })
|
|
132
|
+
.then((result) => {
|
|
133
|
+
const current = live(id);
|
|
134
|
+
if (current === null)
|
|
135
|
+
return;
|
|
136
|
+
controls.delete(id);
|
|
137
|
+
patch(id, {
|
|
138
|
+
status: 'ok',
|
|
139
|
+
...(bound.outcome?.(result, current) ?? {}),
|
|
140
|
+
intervention: undefined,
|
|
141
|
+
loginUrl: undefined,
|
|
142
|
+
}, { kind: 'settle' });
|
|
143
|
+
})
|
|
144
|
+
.catch((error) => {
|
|
145
|
+
if (live(id) === null)
|
|
146
|
+
return;
|
|
147
|
+
controls.delete(id);
|
|
148
|
+
patch(id, {
|
|
149
|
+
status: 'failed',
|
|
150
|
+
why: error instanceof Error ? error.message : String(error),
|
|
151
|
+
intervention: undefined,
|
|
152
|
+
loginUrl: undefined,
|
|
153
|
+
}, { kind: 'settle' });
|
|
154
|
+
});
|
|
155
|
+
return runs.get(id);
|
|
156
|
+
},
|
|
157
|
+
recheck(id) {
|
|
158
|
+
const current = live(id);
|
|
159
|
+
if (current === null || bound.recheck === undefined)
|
|
160
|
+
return false;
|
|
161
|
+
bound.recheck(current);
|
|
162
|
+
return true;
|
|
163
|
+
},
|
|
164
|
+
answer(id, values) {
|
|
165
|
+
const current = live(id);
|
|
166
|
+
if (current === null || bound.answer === undefined)
|
|
167
|
+
return false;
|
|
168
|
+
const fields = current.intervention?.fields;
|
|
169
|
+
if (fields === undefined || fields.length === 0)
|
|
170
|
+
return false;
|
|
171
|
+
const clean = {};
|
|
172
|
+
for (const field of fields) {
|
|
173
|
+
const raw = values[field.key];
|
|
174
|
+
const text = typeof raw === 'string' ? raw.trim() : '';
|
|
175
|
+
if (text === '') {
|
|
176
|
+
if (field.required === true)
|
|
177
|
+
return false;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
clean[field.key] = text;
|
|
181
|
+
}
|
|
182
|
+
bound.answer(current, clean);
|
|
183
|
+
return true;
|
|
184
|
+
},
|
|
185
|
+
stop(id, by) {
|
|
186
|
+
const current = live(id);
|
|
187
|
+
if (current === null)
|
|
188
|
+
return false;
|
|
189
|
+
controls.get(id)?.abort();
|
|
190
|
+
controls.delete(id);
|
|
191
|
+
patch(id, {
|
|
192
|
+
...(bound.stopped?.(current) ?? {}),
|
|
193
|
+
status: 'stopped',
|
|
194
|
+
intervention: undefined,
|
|
195
|
+
loginUrl: undefined,
|
|
196
|
+
}, { kind: 'settle', by });
|
|
197
|
+
return true;
|
|
198
|
+
},
|
|
199
|
+
snapshot(id) {
|
|
200
|
+
return runs.get(id) ?? null;
|
|
201
|
+
},
|
|
202
|
+
onChange(listener) {
|
|
203
|
+
listeners.add(listener);
|
|
204
|
+
return () => listeners.delete(listener);
|
|
205
|
+
},
|
|
206
|
+
rebind(next) {
|
|
207
|
+
bound = next;
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const INTERVENTION_RETRY_ATTEMPTS = 5;
|
|
212
|
+
const INTERVENTION_RETRY_DELAY_MS = 1500;
|
|
213
|
+
function defaultInterventionSleep(ms) {
|
|
214
|
+
return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 把「看一眼接上没有」包成能交给 `longTasks.create({ recheck })` 的 handler:
|
|
218
|
+
* 用户在人工干预节点上按「我处理完了」时先立刻试一次,没接上就有界地再试(第 2 轮起每轮先等)。
|
|
219
|
+
* `check` 返回 true = 已经接上,不用再试;抛错算没接上、继续下一轮。
|
|
220
|
+
* 同一 id 上一轮还在飞时再按直接忽略;成功 / 用尽都清单飞;**永不抛错**(fire-and-forget)。
|
|
221
|
+
* @param check 看一眼接上没有,可同步可异步。
|
|
222
|
+
* @param options 轮次上限(默认 5)、第几次等待等多久(默认 1500ms,可给函数,从第 1 次等待起算)、怎么等(默认真等,测试可注入假的)。
|
|
223
|
+
* @returns 一条同签名的 handler,直接交给 `const longTasks = create({ recheck })`。
|
|
224
|
+
*/
|
|
225
|
+
export function withInterventionRetry(check, options = {}) {
|
|
226
|
+
const attempts = options.attempts ?? INTERVENTION_RETRY_ATTEMPTS;
|
|
227
|
+
const delayMs = options.delayMs ?? INTERVENTION_RETRY_DELAY_MS;
|
|
228
|
+
const sleep = options.sleep ?? defaultInterventionSleep;
|
|
229
|
+
const inFlight = new Set();
|
|
230
|
+
return (current) => {
|
|
231
|
+
if (inFlight.has(current.id))
|
|
232
|
+
return;
|
|
233
|
+
inFlight.add(current.id);
|
|
234
|
+
void (async () => {
|
|
235
|
+
try {
|
|
236
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
237
|
+
if (attempt > 1) {
|
|
238
|
+
await sleep(typeof delayMs === 'function' ? delayMs(attempt - 1) : delayMs);
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
if (await check(current))
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
inFlight.delete(current.id);
|
|
252
|
+
}
|
|
253
|
+
})();
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function isRegistry(value) {
|
|
257
|
+
if (typeof value !== 'object' || value === null)
|
|
258
|
+
return false;
|
|
259
|
+
const candidate = value;
|
|
260
|
+
return (typeof candidate.start === 'function' &&
|
|
261
|
+
typeof candidate.current === 'function' &&
|
|
262
|
+
typeof candidate.snapshot === 'function' &&
|
|
263
|
+
typeof candidate.onChange === 'function');
|
|
264
|
+
}
|
|
265
|
+
export function sharedLongTaskRegistry(scope, key, deps) {
|
|
266
|
+
const store = globalThis;
|
|
267
|
+
const slot = Symbol.for(`dsh-workbench:long-task:${scope}:${key}`);
|
|
268
|
+
const existing = store[slot];
|
|
269
|
+
if (existing !== undefined && isRegistry(existing)) {
|
|
270
|
+
existing.rebind?.(deps);
|
|
271
|
+
return existing;
|
|
272
|
+
}
|
|
273
|
+
const created = createLongTaskRegistry(deps);
|
|
274
|
+
store[slot] = created;
|
|
275
|
+
return created;
|
|
276
|
+
}
|
|
277
|
+
export function createLongTaskHost(options) {
|
|
278
|
+
const offs = [];
|
|
279
|
+
return {
|
|
280
|
+
host: {
|
|
281
|
+
create(createOptions) {
|
|
282
|
+
const { key, facts, ...deps } = createOptions;
|
|
283
|
+
const registry = sharedLongTaskRegistry(options.scope, `${options.unit}:${key}`, deps);
|
|
284
|
+
offs.push(registry.onChange((change) => {
|
|
285
|
+
const named = [runsRouteOf(options.unit), ...(facts?.(change) ?? [])];
|
|
286
|
+
options.bump([...new Set(named)]);
|
|
287
|
+
options.notify?.(change);
|
|
288
|
+
}));
|
|
289
|
+
return registry;
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
dispose() {
|
|
293
|
+
for (const off of offs.splice(0))
|
|
294
|
+
off();
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MarketClaim, MarketIndex, MarketIndexEntry } from '../contract/protocol/market-index.js';
|
|
2
|
+
export interface PublisherIdentity {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly email?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function publisherIdentityOf(text: string | undefined): PublisherIdentity | undefined;
|
|
7
|
+
export declare function samePublisher(left: string, right: string): boolean;
|
|
8
|
+
export declare function entryOwnerOf(entry: MarketIndexEntry): string | undefined;
|
|
9
|
+
export declare function claimOfEntry(entry: MarketIndexEntry | undefined, publisher: string | undefined): MarketClaim;
|
|
10
|
+
export interface MarketClaimInput {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly publisher: string | undefined;
|
|
13
|
+
readonly unit?: string | undefined;
|
|
14
|
+
readonly artifactPath?: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare function marketArtifactPath(name: string): string;
|
|
17
|
+
export declare function marketArtifactRoot(name: string): string;
|
|
18
|
+
export declare function entryUnitOf(entry: MarketIndexEntry): string | undefined;
|
|
19
|
+
export declare function claimOf(index: MarketIndex, input: MarketClaimInput): MarketClaim;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { MARKET_ARTIFACTS_DIR } from '../contract/protocol/market-index.js';
|
|
2
|
+
function foldedName(name) {
|
|
3
|
+
return name.replace(/\s+/gu, ' ').trim().toLowerCase();
|
|
4
|
+
}
|
|
5
|
+
export function publisherIdentityOf(text) {
|
|
6
|
+
const raw = (text ?? '').trim();
|
|
7
|
+
if (raw === '')
|
|
8
|
+
return undefined;
|
|
9
|
+
const match = /^(.*?)\s*<([^<>]*)>\s*$/u.exec(raw);
|
|
10
|
+
const name = (match === null ? raw : match[1]).trim();
|
|
11
|
+
const email = match === null ? '' : match[2].trim().toLowerCase();
|
|
12
|
+
if (name === '')
|
|
13
|
+
return undefined;
|
|
14
|
+
return email === '' ? { name } : { name, email };
|
|
15
|
+
}
|
|
16
|
+
export function samePublisher(left, right) {
|
|
17
|
+
const a = publisherIdentityOf(left);
|
|
18
|
+
const b = publisherIdentityOf(right);
|
|
19
|
+
if (a === undefined || b === undefined)
|
|
20
|
+
return false;
|
|
21
|
+
if (a.email !== undefined && b.email !== undefined)
|
|
22
|
+
return a.email === b.email;
|
|
23
|
+
return foldedName(a.name) === foldedName(b.name);
|
|
24
|
+
}
|
|
25
|
+
export function entryOwnerOf(entry) {
|
|
26
|
+
const owner = (entry.owner ?? '').trim();
|
|
27
|
+
if (owner !== '')
|
|
28
|
+
return owner;
|
|
29
|
+
const author = (entry.author ?? '').trim();
|
|
30
|
+
return author === '' ? undefined : author;
|
|
31
|
+
}
|
|
32
|
+
export function claimOfEntry(entry, publisher) {
|
|
33
|
+
if (entry === undefined)
|
|
34
|
+
return { state: 'new' };
|
|
35
|
+
const owner = entryOwnerOf(entry);
|
|
36
|
+
if (owner === undefined)
|
|
37
|
+
return { state: 'unowned' };
|
|
38
|
+
if (publisher === undefined || publisher.trim() === '')
|
|
39
|
+
return { state: 'unknown' };
|
|
40
|
+
return samePublisher(owner, publisher) ? { state: 'owned', owner } : { state: 'conflict', owner };
|
|
41
|
+
}
|
|
42
|
+
export function marketArtifactPath(name) {
|
|
43
|
+
return `packages/${name}`;
|
|
44
|
+
}
|
|
45
|
+
export function marketArtifactRoot(name) {
|
|
46
|
+
return `${MARKET_ARTIFACTS_DIR}/${name}`;
|
|
47
|
+
}
|
|
48
|
+
export function entryUnitOf(entry) {
|
|
49
|
+
const unit = entry.metadata?.unit?.trim();
|
|
50
|
+
if (unit !== undefined && unit !== '')
|
|
51
|
+
return unit;
|
|
52
|
+
for (const version of entry.versions) {
|
|
53
|
+
if (version.source.type !== 'git')
|
|
54
|
+
continue;
|
|
55
|
+
const match = /^packages\/([^/]+)$/u.exec(version.source.path ?? '');
|
|
56
|
+
const legacy = match?.[1];
|
|
57
|
+
if (legacy !== undefined)
|
|
58
|
+
return legacy;
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
export function claimOf(index, input) {
|
|
63
|
+
const base = claimOfEntry(index.plugins.find((one) => one.name === input.name), input.publisher);
|
|
64
|
+
if (base.state === 'conflict' || base.state === 'unknown')
|
|
65
|
+
return base;
|
|
66
|
+
const unit = (input.unit ?? '').trim();
|
|
67
|
+
if (unit !== '') {
|
|
68
|
+
for (const other of index.plugins) {
|
|
69
|
+
if (other.name === input.name)
|
|
70
|
+
continue;
|
|
71
|
+
if (entryUnitOf(other) !== unit)
|
|
72
|
+
continue;
|
|
73
|
+
return { state: 'unit-taken', entry: other.name };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const path = (input.artifactPath ?? '').trim();
|
|
77
|
+
if (path !== '') {
|
|
78
|
+
for (const other of index.plugins) {
|
|
79
|
+
if (other.name === input.name)
|
|
80
|
+
continue;
|
|
81
|
+
if (!other.versions.some((one) => one.source.type === 'git' && (one.source.path ?? '') === path))
|
|
82
|
+
continue;
|
|
83
|
+
return { state: 'path-taken', entry: other.name };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return base;
|
|
87
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MarketIndex, MarketIndexProblem } from '../contract/protocol/market-index.js';
|
|
2
|
+
export interface MarketEntryFile {
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly text: string;
|
|
5
|
+
}
|
|
6
|
+
export type MarketIndexAssemble = {
|
|
7
|
+
readonly ok: true;
|
|
8
|
+
readonly index: MarketIndex;
|
|
9
|
+
} | {
|
|
10
|
+
readonly ok: false;
|
|
11
|
+
readonly problems: readonly MarketIndexProblem[];
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DiscoverFilter, IndexSourceSpec, MarketIndex, MarketIndexEntry, MarketIndexParse, MarketIndexProblem, MarketIndexVersion, MarketSourceConfig } from '../contract/protocol/market-index.js';
|
|
2
|
+
export declare function compareSemver(left: string, right: string): number | undefined;
|
|
3
|
+
export declare function httpUrlProblem(url: string): string | undefined;
|
|
4
|
+
export declare function gitUrlOk(url: string): boolean;
|
|
5
|
+
export declare function parseMarketIndex(raw: unknown): MarketIndexParse;
|
|
6
|
+
export declare function parseMarketIndexJson(text: string): MarketIndexParse;
|
|
7
|
+
export declare function sortMarketVersions(versions: readonly MarketIndexVersion[]): MarketIndexVersion[];
|
|
8
|
+
export declare function upsertMarketEntry(index: MarketIndex, entry: MarketIndexEntry): MarketIndex;
|
|
9
|
+
export declare function marketEntryLabels(entry: MarketIndexEntry): readonly string[];
|
|
10
|
+
export declare function filterMarketIndex(index: MarketIndex, filter: DiscoverFilter): readonly MarketIndexEntry[];
|
|
11
|
+
export declare function marketSourceKey(source: IndexSourceSpec): string;
|
|
12
|
+
export type SourceConfigParse = {
|
|
13
|
+
readonly ok: true;
|
|
14
|
+
readonly source: MarketSourceConfig;
|
|
15
|
+
} | {
|
|
16
|
+
readonly ok: false;
|
|
17
|
+
readonly problem: MarketIndexProblem;
|
|
18
|
+
};
|
|
19
|
+
export declare function parseSourceConfig(raw: unknown): SourceConfigParse;
|
|
20
|
+
export declare function marketEntryPath(dir: string, name: string): string;
|
|
21
|
+
export type MarketEntryParse = {
|
|
22
|
+
readonly ok: true;
|
|
23
|
+
readonly entry: MarketIndexEntry;
|
|
24
|
+
} | {
|
|
25
|
+
readonly ok: false;
|
|
26
|
+
readonly problems: readonly MarketIndexProblem[];
|
|
27
|
+
};
|
|
28
|
+
export declare function parseMarketEntryJson(text: string): MarketEntryParse;
|