@dsh-workbench/shared 1.5.2-alpha.0 → 1.5.2-alpha.2
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/contract/protocol/bundle-install.d.ts +7 -1
- package/dist/contract/protocol/bundle-install.js +1 -0
- package/dist/host/runtime/dsh-compat.js +20 -6
- package/dist/i18n/en.js +2 -0
- package/dist/i18n/index.d.ts +3 -1
- package/dist/i18n/zh.d.ts +2 -0
- package/dist/i18n/zh.js +2 -0
- package/dist/lib/dsh-client.d.ts +1 -1
- package/package.json +47 -51
- package/src/contract/protocol/bundle-install.ts +9 -1
- package/src/host/runtime/__tests__/dsh-compat.test.ts +23 -0
- package/src/host/runtime/dsh-compat.ts +18 -5
- package/src/i18n/en.ts +2 -0
- package/src/i18n/zh.ts +2 -0
- package/src/lib/dsh-client.ts +1 -2
- package/dist/components/Activity.css +0 -69
- package/dist/components/Activity.d.ts +0 -56
- package/dist/components/Activity.js +0 -47
- package/dist/components/ApprovalDetail.css +0 -3
- package/dist/components/ApprovalDetail.d.ts +0 -42
- package/dist/components/ApprovalDetail.js +0 -53
- package/dist/components/ApprovalPlan.css +0 -39
- package/dist/components/ApprovalPlan.d.ts +0 -27
- package/dist/components/ApprovalPlan.js +0 -19
- package/dist/components/Card.css +0 -19
- package/dist/components/Card.d.ts +0 -26
- package/dist/components/Card.js +0 -18
- package/dist/components/CardAnchor.d.ts +0 -21
- package/dist/components/CardAnchor.js +0 -19
- package/dist/components/CardAnchor.module.css +0 -3
- package/dist/components/CardBoundary.d.ts +0 -42
- package/dist/components/CardBoundary.js +0 -58
- package/dist/components/CardBoundary.module.css +0 -5
- package/dist/components/CardHead.css +0 -87
- package/dist/components/CardHead.d.ts +0 -30
- package/dist/components/CardHead.js +0 -27
- package/dist/components/ChoiceGroup.css +0 -182
- package/dist/components/ChoiceGroup.d.ts +0 -54
- package/dist/components/ChoiceGroup.js +0 -63
- package/dist/components/ConfirmBar.css +0 -26
- package/dist/components/ConfirmBar.d.ts +0 -36
- package/dist/components/ConfirmBar.js +0 -26
- package/dist/components/EmptyIllustration.d.ts +0 -12
- package/dist/components/EmptyIllustration.js +0 -32
- package/dist/components/Field.css +0 -20
- package/dist/components/Field.d.ts +0 -18
- package/dist/components/Field.js +0 -15
- package/dist/components/Form.css +0 -6
- package/dist/components/Form.d.ts +0 -22
- package/dist/components/Form.js +0 -60
- package/dist/components/FormActions.css +0 -13
- package/dist/components/FormActions.d.ts +0 -29
- package/dist/components/FormActions.js +0 -43
- package/dist/components/FormNodes.d.ts +0 -107
- package/dist/components/FormNodes.js +0 -165
- package/dist/components/FormRows.css +0 -107
- package/dist/components/FormRows.d.ts +0 -36
- package/dist/components/FormRows.js +0 -26
- package/dist/components/FormTypes.d.ts +0 -84
- package/dist/components/FormTypes.js +0 -1
- package/dist/components/Link.css +0 -22
- package/dist/components/Link.d.ts +0 -22
- package/dist/components/Link.js +0 -17
- package/dist/components/LongTaskRow.css +0 -171
- package/dist/components/LongTaskRow.d.ts +0 -94
- package/dist/components/LongTaskRow.js +0 -103
- package/dist/components/Note.css +0 -13
- package/dist/components/Note.d.ts +0 -20
- package/dist/components/Note.js +0 -14
- package/dist/components/ResourceStates.css +0 -114
- package/dist/components/ResourceStates.d.ts +0 -44
- package/dist/components/ResourceStates.js +0 -41
- package/dist/components/Rows.css +0 -42
- package/dist/components/Rows.d.ts +0 -28
- package/dist/components/Rows.js +0 -21
- package/dist/components/SaveBar.d.ts +0 -24
- package/dist/components/SaveBar.js +0 -25
- package/dist/components/SelectField.css +0 -182
- package/dist/components/SelectField.d.ts +0 -89
- package/dist/components/SelectField.js +0 -260
- package/dist/components/SelectFieldNodes.d.ts +0 -49
- package/dist/components/SelectFieldNodes.js +0 -43
- package/dist/components/SettingsSection.css +0 -25
- package/dist/components/SettingsSection.d.ts +0 -20
- package/dist/components/SettingsSection.js +0 -17
- package/dist/components/SetupShell.d.ts +0 -93
- package/dist/components/SetupShell.js +0 -64
- package/dist/components/SetupShell.module.css +0 -81
- package/dist/components/Spinner.css +0 -5
- package/dist/components/Spinner.d.ts +0 -15
- package/dist/components/Spinner.js +0 -13
- package/dist/components/Stack.css +0 -6
- package/dist/components/Stack.d.ts +0 -14
- package/dist/components/Stack.js +0 -10
- package/dist/components/StateBlock.css +0 -38
- package/dist/components/StateBlock.d.ts +0 -24
- package/dist/components/StateBlock.js +0 -22
- package/dist/components/TextField.css +0 -32
- package/dist/components/TextField.d.ts +0 -14
- package/dist/components/TextField.js +0 -10
- package/dist/components/board-module.d.ts +0 -307
- package/dist/components/board-module.js +0 -1
- package/dist/components/card-view-validate.d.ts +0 -5
- package/dist/components/card-view-validate.js +0 -256
- package/dist/components/icons.d.ts +0 -63
- package/dist/components/icons.js +0 -107
- package/dist/components/layout/icon-command.d.ts +0 -8
- package/dist/components/layout/icon-command.js +0 -21
- package/dist/contract/capture.d.ts +0 -16
- package/dist/contract/capture.js +0 -1
- package/dist/contract/diagnostics.d.ts +0 -34
- package/dist/contract/diagnostics.js +0 -124
- package/dist/contract/protocol/unit-manager.d.ts +0 -50
- package/dist/contract/protocol/unit-manager.js +0 -2
- package/dist/host/adapter-contract.d.ts +0 -3
- package/dist/host/adapter-contract.js +0 -95
- package/dist/host/adapter-set.d.ts +0 -27
- package/dist/host/adapter-set.js +0 -258
- package/dist/host/adapter-types.d.ts +0 -87
- package/dist/host/adapter-types.js +0 -23
- package/dist/host/adapters/platform.d.ts +0 -14
- package/dist/host/adapters/platform.js +0 -40
- package/dist/host/adapters.d.ts +0 -28
- package/dist/host/adapters.js +0 -9
- package/dist/host/auth-loss.d.ts +0 -33
- package/dist/host/auth-loss.js +0 -107
- package/dist/host/board-fact.d.ts +0 -8
- package/dist/host/board-fact.js +0 -16
- package/dist/host/boot-record.d.ts +0 -11
- package/dist/host/boot-record.js +0 -31
- package/dist/host/browser.d.ts +0 -3
- package/dist/host/browser.js +0 -3
- package/dist/host/bundle-manager.d.ts +0 -4
- package/dist/host/bundle-manager.js +0 -338
- package/dist/host/changelog.d.ts +0 -28
- package/dist/host/changelog.js +0 -201
- package/dist/host/cli-error.d.ts +0 -8
- package/dist/host/cli-error.js +0 -70
- package/dist/host/cli.d.ts +0 -4
- package/dist/host/cli.js +0 -9
- package/dist/host/config-sync.d.ts +0 -40
- package/dist/host/config-sync.js +0 -267
- package/dist/host/context-ref.d.ts +0 -13
- package/dist/host/context-ref.js +0 -41
- package/dist/host/data-error.d.ts +0 -15
- package/dist/host/data-error.js +0 -23
- package/dist/host/data-plan-check.d.ts +0 -10
- package/dist/host/data-plan-check.js +0 -315
- package/dist/host/data-plan.d.ts +0 -15
- package/dist/host/data-plan.js +0 -283
- package/dist/host/data-root.d.ts +0 -5
- package/dist/host/data-root.js +0 -23
- package/dist/host/diy-debug.d.ts +0 -80
- package/dist/host/diy-debug.js +0 -89
- package/dist/host/diy-preset.d.ts +0 -26
- package/dist/host/diy-preset.js +0 -115
- package/dist/host/diy-record.d.ts +0 -135
- package/dist/host/diy-record.js +0 -163
- package/dist/host/dsh-compat.d.ts +0 -27
- package/dist/host/dsh-compat.js +0 -75
- package/dist/host/dsh-plugins.d.ts +0 -5
- package/dist/host/dsh-plugins.js +0 -51
- package/dist/host/env-policy.d.ts +0 -82
- package/dist/host/env-policy.js +0 -181
- package/dist/host/extension.d.ts +0 -7
- package/dist/host/extension.js +0 -40
- package/dist/host/facts.d.ts +0 -31
- package/dist/host/facts.js +0 -58
- package/dist/host/fs-write.d.ts +0 -96
- package/dist/host/fs-write.js +0 -183
- package/dist/host/git.d.ts +0 -5
- package/dist/host/git.js +0 -1
- package/dist/host/host-actions.d.ts +0 -2
- package/dist/host/host-actions.js +0 -5
- package/dist/host/host-kit.d.ts +0 -37
- package/dist/host/host-kit.js +0 -27
- package/dist/host/http.d.ts +0 -47
- package/dist/host/http.js +0 -289
- package/dist/host/install-failure.d.ts +0 -50
- package/dist/host/install-failure.js +0 -184
- package/dist/host/installed-module.d.ts +0 -25
- package/dist/host/installed-module.js +0 -289
- package/dist/host/installed-sources.d.ts +0 -10
- package/dist/host/installed-sources.js +0 -63
- package/dist/host/lease.d.ts +0 -70
- package/dist/host/lease.js +0 -264
- package/dist/host/lib-capabilities.d.ts +0 -22
- package/dist/host/lib-capabilities.js +0 -37
- package/dist/host/lib-install.d.ts +0 -19
- package/dist/host/lib-install.js +0 -40
- package/dist/host/lib-runners.d.ts +0 -18
- package/dist/host/lib-runners.js +0 -46
- package/dist/host/local-declaration.d.ts +0 -7
- package/dist/host/local-declaration.js +0 -33
- package/dist/host/long-task.d.ts +0 -97
- package/dist/host/long-task.js +0 -297
- package/dist/host/market-index-claim.d.ts +0 -19
- package/dist/host/market-index-claim.js +0 -87
- package/dist/host/market-index-doc.d.ts +0 -12
- package/dist/host/market-index-doc.js +0 -1
- package/dist/host/market-index-parse.d.ts +0 -28
- package/dist/host/market-index-parse.js +0 -413
- package/dist/host/market-index.d.ts +0 -13
- package/dist/host/market-index.js +0 -105
- package/dist/host/module-root.d.ts +0 -1
- package/dist/host/module-root.js +0 -5
- package/dist/host/needs.d.ts +0 -4
- package/dist/host/needs.js +0 -2
- package/dist/host/npm-registry.d.ts +0 -10
- package/dist/host/npm-registry.js +0 -16
- package/dist/host/package-content.d.ts +0 -8
- package/dist/host/package-content.js +0 -90
- package/dist/host/package-kind.d.ts +0 -13
- package/dist/host/package-kind.js +0 -51
- package/dist/host/package-route.d.ts +0 -33
- package/dist/host/package-route.js +0 -68
- package/dist/host/panel-state.d.ts +0 -120
- package/dist/host/panel-state.js +0 -177
- package/dist/host/patch-blocks.d.ts +0 -13
- package/dist/host/patch-blocks.js +0 -52
- package/dist/host/patch.d.ts +0 -4
- package/dist/host/patch.js +0 -7
- package/dist/host/paths.d.ts +0 -12
- package/dist/host/paths.js +0 -20
- package/dist/host/payload.d.ts +0 -12
- package/dist/host/payload.js +0 -16
- package/dist/host/plan-results.d.ts +0 -5
- package/dist/host/plan-results.js +0 -71
- package/dist/host/plan-run.d.ts +0 -41
- package/dist/host/plan-run.js +0 -87
- package/dist/host/platform.d.ts +0 -14
- package/dist/host/platform.js +0 -40
- package/dist/host/plugin-ledger.d.ts +0 -32
- package/dist/host/plugin-ledger.js +0 -106
- package/dist/host/plugin.d.ts +0 -3
- package/dist/host/plugin.js +0 -38
- package/dist/host/port-types.d.ts +0 -233
- package/dist/host/port-types.js +0 -1
- package/dist/host/preflight.d.ts +0 -32
- package/dist/host/preflight.js +0 -1
- package/dist/host/process-alive.d.ts +0 -6
- package/dist/host/process-alive.js +0 -16
- package/dist/host/profile-bundles.d.ts +0 -20
- package/dist/host/profile-bundles.js +0 -48
- package/dist/host/profile-create.d.ts +0 -19
- package/dist/host/profile-create.js +0 -124
- package/dist/host/profile-port.d.ts +0 -4
- package/dist/host/profile-port.js +0 -4
- package/dist/host/profile-registries.d.ts +0 -10
- package/dist/host/profile-registries.js +0 -149
- package/dist/host/provision.d.ts +0 -32
- package/dist/host/provision.js +0 -105
- package/dist/host/read-json.d.ts +0 -1
- package/dist/host/read-json.js +0 -11
- package/dist/host/recipe-rules.d.ts +0 -5
- package/dist/host/recipe-rules.js +0 -412
- package/dist/host/recipe.d.ts +0 -14
- package/dist/host/recipe.js +0 -332
- package/dist/host/registry-declaration.d.ts +0 -21
- package/dist/host/registry-declaration.js +0 -42
- package/dist/host/reinstall-record.d.ts +0 -16
- package/dist/host/reinstall-record.js +0 -54
- package/dist/host/release-age.d.ts +0 -24
- package/dist/host/release-age.js +0 -92
- package/dist/host/release-packages.generated.d.ts +0 -1
- package/dist/host/release-packages.generated.js +0 -10
- package/dist/host/release-probe.d.ts +0 -37
- package/dist/host/release-probe.js +0 -156
- package/dist/host/runtime/browser-argv.d.ts +0 -1
- package/dist/host/runtime/browser-argv.js +0 -9
- package/dist/host/runtime/front-app.d.ts +0 -6
- package/dist/host/runtime/front-app.js +0 -70
- package/dist/host/shell-render.d.ts +0 -52
- package/dist/host/shell-render.js +0 -117
- package/dist/host/shell-text.d.ts +0 -30
- package/dist/host/shell-text.js +0 -40
- package/dist/host/shell.d.ts +0 -25
- package/dist/host/shell.js +0 -55
- package/dist/host/site.d.ts +0 -45
- package/dist/host/site.js +0 -182
- package/dist/host/spec.d.ts +0 -8
- package/dist/host/spec.js +0 -24
- package/dist/host/submit-confirm.d.ts +0 -19
- package/dist/host/submit-confirm.js +0 -45
- package/dist/host/supply-index.d.ts +0 -38
- package/dist/host/supply-index.js +0 -209
- package/dist/host/supply-port.d.ts +0 -5
- package/dist/host/supply-port.js +0 -50
- package/dist/host/time.d.ts +0 -22
- package/dist/host/time.js +0 -33
- package/dist/host/tokens.d.ts +0 -26
- package/dist/host/tokens.js +0 -154
- package/dist/host/tool-approval.d.ts +0 -86
- package/dist/host/tool-approval.js +0 -118
- package/dist/host/tool-kit.d.ts +0 -8
- package/dist/host/tool-kit.js +0 -22
- package/dist/host/toolbox-port.d.ts +0 -16
- package/dist/host/toolbox-port.js +0 -1
- package/dist/host/unit-config.d.ts +0 -34
- package/dist/host/unit-config.js +0 -28
- package/dist/host/unit-data.d.ts +0 -3
- package/dist/host/unit-data.js +0 -127
- package/dist/host/unit-face.d.ts +0 -95
- package/dist/host/unit-face.js +0 -1
- package/dist/host/unit-plugin.d.ts +0 -24
- package/dist/host/unit-plugin.js +0 -25
- package/dist/host/update-journal-manifest.d.ts +0 -19
- package/dist/host/update-journal-manifest.js +0 -134
- package/dist/host/update-journal-types.d.ts +0 -33
- package/dist/host/update-journal-types.js +0 -2
- package/dist/host/update-journal.d.ts +0 -43
- package/dist/host/update-journal.js +0 -409
- package/dist/host/value-handoff.d.ts +0 -16
- package/dist/host/value-handoff.js +0 -22
- package/dist/host/version-range.d.ts +0 -2
- package/dist/host/version-range.js +0 -13
- package/dist/host/version.d.ts +0 -4
- package/dist/host/version.js +0 -32
- package/dist/host/workspace-store.d.ts +0 -19
- package/dist/host/workspace-store.js +0 -133
- package/dist/host/write-result.d.ts +0 -1
- package/dist/host/write-result.js +0 -18
package/dist/host/tokens.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join, resolve } from 'node:path';
|
|
3
|
-
export const DSH_THEME_PACKAGE = '@deepseek-ai/dsh-client-ui-theme';
|
|
4
|
-
export const SHELL_PACKAGE = '@dsh-workbench/core';
|
|
5
|
-
export const DSW_PREFIX = '--dsw-';
|
|
6
|
-
export const WB_PREFIX = '--wb-';
|
|
7
|
-
const BLOCK = /([^{}]*)\{([^{}]*)\}/g;
|
|
8
|
-
const DECLARATION = /(--[a-z0-9-]+)\s*:\s*([^;{}]+)/g;
|
|
9
|
-
const DARK_BLOCK = /data-ds-dark-theme/;
|
|
10
|
-
const VAR_USE = /var\(\s*(--[a-z0-9-]+)\s*(?:,[^()]*)?\)/g;
|
|
11
|
-
function rawDefinitionsIn(text, prefix) {
|
|
12
|
-
const defs = new Map();
|
|
13
|
-
for (const block of text.matchAll(BLOCK)) {
|
|
14
|
-
const selector = block[1] ?? '';
|
|
15
|
-
const dark = DARK_BLOCK.test(selector);
|
|
16
|
-
for (const declaration of (block[2] ?? '').matchAll(DECLARATION)) {
|
|
17
|
-
const name = declaration[1] ?? '';
|
|
18
|
-
const value = (declaration[2] ?? '').trim();
|
|
19
|
-
if (!name.startsWith(prefix) || value === '')
|
|
20
|
-
continue;
|
|
21
|
-
const found = defs.get(name) ?? {};
|
|
22
|
-
const key = dark ? 'dark' : 'light';
|
|
23
|
-
if (found[key] === undefined)
|
|
24
|
-
found[key] = value;
|
|
25
|
-
defs.set(name, found);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return defs;
|
|
29
|
-
}
|
|
30
|
-
function resolved(value, scheme, defs, depth = 0) {
|
|
31
|
-
if (depth >= 4 || !value.includes('var('))
|
|
32
|
-
return value;
|
|
33
|
-
return value.replace(VAR_USE, (whole, name) => {
|
|
34
|
-
const found = defs.get(name);
|
|
35
|
-
if (found === undefined)
|
|
36
|
-
return whole;
|
|
37
|
-
const next = scheme === 'dark' ? found.dark ?? found.light : found.light ?? found.dark;
|
|
38
|
-
return next === undefined ? whole : resolved(next, scheme, defs, depth + 1);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
export function tokenEntriesIn(text, prefix) {
|
|
42
|
-
const defs = rawDefinitionsIn(text, prefix);
|
|
43
|
-
return [...defs.entries()]
|
|
44
|
-
.map(([name, found]) => ({
|
|
45
|
-
name,
|
|
46
|
-
values: {
|
|
47
|
-
light: found.light === undefined ? null : resolved(found.light, 'light', defs),
|
|
48
|
-
dark: found.dark === undefined ? null : resolved(found.dark, 'dark', defs),
|
|
49
|
-
},
|
|
50
|
-
}))
|
|
51
|
-
.sort((left, right) => left.name.localeCompare(right.name));
|
|
52
|
-
}
|
|
53
|
-
function manifestAt(root) {
|
|
54
|
-
try {
|
|
55
|
-
const manifest = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
56
|
-
if (typeof manifest !== 'object' || manifest === null)
|
|
57
|
-
return null;
|
|
58
|
-
const record = manifest;
|
|
59
|
-
return {
|
|
60
|
-
name: typeof record.name === 'string' ? record.name : null,
|
|
61
|
-
version: typeof record.version === 'string' ? record.version : null,
|
|
62
|
-
root,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function findPackage(startDirs, packageName) {
|
|
70
|
-
for (const start of startDirs) {
|
|
71
|
-
if (start.trim() === '')
|
|
72
|
-
continue;
|
|
73
|
-
const own = manifestAt(start);
|
|
74
|
-
if (own !== null && own.name === packageName)
|
|
75
|
-
return own;
|
|
76
|
-
let at = resolve(start);
|
|
77
|
-
for (;;) {
|
|
78
|
-
const candidate = join(at, 'node_modules', ...packageName.split('/'));
|
|
79
|
-
const manifest = manifestAt(candidate);
|
|
80
|
-
if (manifest !== null && (manifest.name === null || manifest.name === packageName))
|
|
81
|
-
return manifest;
|
|
82
|
-
const parent = dirname(at);
|
|
83
|
-
if (parent === at)
|
|
84
|
-
break;
|
|
85
|
-
at = parent;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
function sourceAt(startDirs, packageName, tail, prefix) {
|
|
91
|
-
const manifest = findPackage(startDirs, packageName);
|
|
92
|
-
if (manifest === null)
|
|
93
|
-
return null;
|
|
94
|
-
const file = join(manifest.root, tail);
|
|
95
|
-
if (!existsSync(file))
|
|
96
|
-
return null;
|
|
97
|
-
return {
|
|
98
|
-
package: packageName,
|
|
99
|
-
version: manifest.version,
|
|
100
|
-
file,
|
|
101
|
-
entries: tokenEntriesIn(readFileSync(file, 'utf8'), prefix),
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
export function readTokens(startDirs) {
|
|
105
|
-
const dsw = sourceAt(startDirs, DSH_THEME_PACKAGE, join('lib', 'client.js'), DSW_PREFIX);
|
|
106
|
-
const wb = sourceAt(startDirs, SHELL_PACKAGE, 'client.js', WB_PREFIX);
|
|
107
|
-
return { dsw, wb };
|
|
108
|
-
}
|
|
109
|
-
function distance(left, right) {
|
|
110
|
-
let previous = Array.from({ length: right.length + 1 }, (_unused, index) => index);
|
|
111
|
-
for (let row = 1; row <= left.length; row += 1) {
|
|
112
|
-
const current = [row];
|
|
113
|
-
for (let column = 1; column <= right.length; column += 1) {
|
|
114
|
-
const same = left[row - 1] === right[column - 1] ? 0 : 1;
|
|
115
|
-
current.push(Math.min((previous[column] ?? 0) + 1, (current[column - 1] ?? 0) + 1, (previous[column - 1] ?? 0) + same));
|
|
116
|
-
}
|
|
117
|
-
previous = current;
|
|
118
|
-
}
|
|
119
|
-
return previous[right.length] ?? 0;
|
|
120
|
-
}
|
|
121
|
-
function commonPrefixLength(left, right) {
|
|
122
|
-
const cap = Math.min(left.length, right.length);
|
|
123
|
-
let at = 0;
|
|
124
|
-
while (at < cap && left[at] === right[at])
|
|
125
|
-
at += 1;
|
|
126
|
-
return at;
|
|
127
|
-
}
|
|
128
|
-
export function nearestTokens(name, names, limit = 6) {
|
|
129
|
-
const wanted = name.trim().toLowerCase();
|
|
130
|
-
if (wanted === '')
|
|
131
|
-
return [];
|
|
132
|
-
const shared = wanted.slice(0, wanted.lastIndexOf('-') + 1);
|
|
133
|
-
return names
|
|
134
|
-
.flatMap((one) => {
|
|
135
|
-
const lower = one.toLowerCase();
|
|
136
|
-
const typos = lower.length < 3 ? Number.POSITIVE_INFINITY : distance(lower, wanted);
|
|
137
|
-
if (typos <= 2)
|
|
138
|
-
return [{ one, typos }];
|
|
139
|
-
const prefix = commonPrefixLength(lower, wanted);
|
|
140
|
-
if (prefix < 8)
|
|
141
|
-
return [];
|
|
142
|
-
const sameStem = shared.length >= 8 && lower.startsWith(shared);
|
|
143
|
-
const score = 10 + typos - prefix + (sameStem ? 0 : 20);
|
|
144
|
-
return score < 20 ? [{ one, typos: score }] : [];
|
|
145
|
-
})
|
|
146
|
-
.sort((left, right) => left.typos - right.typos || left.one.length - right.one.length || left.one.localeCompare(right.one))
|
|
147
|
-
.slice(0, limit)
|
|
148
|
-
.map((one) => one.one);
|
|
149
|
-
}
|
|
150
|
-
export function tokenFamilyOf(name) {
|
|
151
|
-
const rest = name.startsWith(DSW_PREFIX) ? name.slice(DSW_PREFIX.length) : name.startsWith(WB_PREFIX) ? name.slice(WB_PREFIX.length) : name;
|
|
152
|
-
const cut = rest.indexOf('-');
|
|
153
|
-
return cut === -1 ? rest : rest.slice(0, cut);
|
|
154
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
export { APPROVAL_NOTE_ARG } from '../contract/approval.js';
|
|
2
|
-
export type AskDecision = {
|
|
3
|
-
readonly kind: 'ask';
|
|
4
|
-
readonly reason: string;
|
|
5
|
-
readonly displayReason: {
|
|
6
|
-
readonly en: string;
|
|
7
|
-
readonly zh: string;
|
|
8
|
-
};
|
|
9
|
-
} | {
|
|
10
|
-
readonly kind: 'deny';
|
|
11
|
-
readonly reason: string;
|
|
12
|
-
};
|
|
13
|
-
export interface ApprovalDetail {
|
|
14
|
-
readonly en: string;
|
|
15
|
-
readonly zh: string;
|
|
16
|
-
}
|
|
17
|
-
export type ApprovalFacts = ApprovalDetail | {
|
|
18
|
-
readonly blocked: string;
|
|
19
|
-
};
|
|
20
|
-
export declare const APPROVAL_NOTE_LIMIT = 40;
|
|
21
|
-
export declare const APPROVAL_DETAIL_LIMIT = 20;
|
|
22
|
-
export declare const APPROVAL_QUESTION_LIMIT = 40;
|
|
23
|
-
export declare const APPROVAL_SEPARATOR_LIMIT = 8;
|
|
24
|
-
export declare const APPROVAL_HEADLINE_LIMIT: number;
|
|
25
|
-
export declare function withApprovalNote(parameters: Record<string, unknown>, options?: {
|
|
26
|
-
readonly required?: boolean | undefined;
|
|
27
|
-
}): Record<string, unknown>;
|
|
28
|
-
export interface ApprovalCall {
|
|
29
|
-
readonly name?: string | undefined;
|
|
30
|
-
readonly arguments?: unknown;
|
|
31
|
-
readonly workspace?: string | undefined;
|
|
32
|
-
readonly session?: string | undefined;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 套件对一次写调用给出的判定:`read` 只是看看、`allow` 会写但本套件不问、`deny` 这一次根本跑不成
|
|
36
|
-
* (连问都不该问,`reason` 原样交给 agent)、`ask` 要用户点头(`question` 接在明细后,`fallback` 是没明细时的整句;
|
|
37
|
-
* `noteInDetail` 为真表示套件把 agent 的附注画在自己的详情座里,标题只留动作、不再追加)。
|
|
38
|
-
*/
|
|
39
|
-
export type ApprovalVerdict = {
|
|
40
|
-
readonly kind: 'read';
|
|
41
|
-
} | {
|
|
42
|
-
readonly kind: 'allow';
|
|
43
|
-
} | {
|
|
44
|
-
readonly kind: 'deny';
|
|
45
|
-
readonly reason: string;
|
|
46
|
-
} | {
|
|
47
|
-
readonly kind: 'ask';
|
|
48
|
-
readonly reason: string;
|
|
49
|
-
readonly question: ApprovalDetail;
|
|
50
|
-
readonly fallback: ApprovalDetail;
|
|
51
|
-
readonly noteInDetail?: boolean;
|
|
52
|
-
};
|
|
53
|
-
export type ApprovalPolicy = (call: ApprovalCall) => ApprovalVerdict | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* 闸门的输入:`skipAsk` 为真表示会话已经不要审批提示(完全权限)—— 认领检查、`{blocked}` 与套件自己的
|
|
56
|
-
* `deny` 照旧,只是不再返回 `ask`;dsh 在 `approval: never` 下会把 `ask` 直接拒掉。
|
|
57
|
-
*/
|
|
58
|
-
export interface ApprovalContext {
|
|
59
|
-
readonly writes?: boolean | undefined;
|
|
60
|
-
readonly elevates?: boolean | undefined;
|
|
61
|
-
readonly policy?: ApprovalPolicy | undefined;
|
|
62
|
-
readonly declaredNote?: boolean | undefined;
|
|
63
|
-
readonly skipAsk?: boolean | undefined;
|
|
64
|
-
readonly detailOf?: ((call: ApprovalCall) => ApprovalFacts | undefined | Promise<ApprovalFacts | undefined>) | undefined;
|
|
65
|
-
}
|
|
66
|
-
export declare function approvalFor(call: ApprovalCall, context?: ApprovalContext): Promise<AskDecision | undefined>;
|
|
67
|
-
/**
|
|
68
|
-
* 「写工具要点头」那一对的默认口径:点名的工具一律 `ask` + 同一份明细,其余一律 `read`。
|
|
69
|
-
* 把它直接摊在 `mount()` 的返回值里:`...writeApprovalOf({ … })`。
|
|
70
|
-
* @param options.tools 需要点头的工具名。
|
|
71
|
-
* @param options.reason 为什么问(给 agent 看的理由)。
|
|
72
|
-
* @param options.question 问句(zh / en,≤40 字)。
|
|
73
|
-
* @param options.fallback 没有明细时的整句(zh / en,≤40 字)。
|
|
74
|
-
* @param options.detail 审批屏头行那句明细(zh / en,≤20 字)。
|
|
75
|
-
* @returns `{ needsApproval, approvalDetail }`。
|
|
76
|
-
*/
|
|
77
|
-
export declare function writeApprovalOf(options: {
|
|
78
|
-
readonly tools: readonly string[];
|
|
79
|
-
readonly reason: string;
|
|
80
|
-
readonly question: ApprovalDetail;
|
|
81
|
-
readonly fallback: ApprovalDetail;
|
|
82
|
-
readonly detail: ApprovalDetail;
|
|
83
|
-
}): {
|
|
84
|
-
needsApproval(call: ApprovalCall): ApprovalVerdict;
|
|
85
|
-
approvalDetail(call: ApprovalCall): ApprovalFacts | undefined;
|
|
86
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
export { APPROVAL_NOTE_ARG } from '../contract/approval.js';
|
|
2
|
-
import { APPROVAL_NOTE_ARG } from '../contract/approval.js';
|
|
3
|
-
export const APPROVAL_NOTE_LIMIT = 40;
|
|
4
|
-
export const APPROVAL_DETAIL_LIMIT = 20;
|
|
5
|
-
export const APPROVAL_QUESTION_LIMIT = 40;
|
|
6
|
-
export const APPROVAL_SEPARATOR_LIMIT = 8;
|
|
7
|
-
export const APPROVAL_HEADLINE_LIMIT = APPROVAL_DETAIL_LIMIT + APPROVAL_QUESTION_LIMIT + APPROVAL_NOTE_LIMIT + APPROVAL_SEPARATOR_LIMIT;
|
|
8
|
-
const NOTE_SCHEMA = {
|
|
9
|
-
type: 'string',
|
|
10
|
-
description: '一句话说明你这次想拿它干什么(要点头时显示在审批屏上;40 字以内)。',
|
|
11
|
-
};
|
|
12
|
-
export function withApprovalNote(parameters, options = {}) {
|
|
13
|
-
const properties = parameters['properties'];
|
|
14
|
-
if (typeof properties !== 'object' || properties === null)
|
|
15
|
-
return parameters;
|
|
16
|
-
const map = properties;
|
|
17
|
-
if (APPROVAL_NOTE_ARG in map)
|
|
18
|
-
return parameters;
|
|
19
|
-
const declared = Array.isArray(parameters['required']) ? parameters['required'] : [];
|
|
20
|
-
const kept = declared.filter((name) => name !== APPROVAL_NOTE_ARG);
|
|
21
|
-
const required = options.required === true ? [...kept, APPROVAL_NOTE_ARG] : kept;
|
|
22
|
-
return {
|
|
23
|
-
...parameters,
|
|
24
|
-
properties: { ...map, [APPROVAL_NOTE_ARG]: NOTE_SCHEMA },
|
|
25
|
-
...(required.length === 0 ? {} : { required }),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function oneLine(text) {
|
|
29
|
-
return text.replace(/\s+/g, ' ').trim();
|
|
30
|
-
}
|
|
31
|
-
function approvalNoteOf(call) {
|
|
32
|
-
const raw = call.arguments;
|
|
33
|
-
const value = typeof raw === 'object' && raw !== null ? raw[APPROVAL_NOTE_ARG] : undefined;
|
|
34
|
-
if (typeof value !== 'string')
|
|
35
|
-
return undefined;
|
|
36
|
-
const line = oneLine(value);
|
|
37
|
-
if (line === '')
|
|
38
|
-
return undefined;
|
|
39
|
-
return line.length > APPROVAL_NOTE_LIMIT ? `${line.slice(0, APPROVAL_NOTE_LIMIT)}…` : line;
|
|
40
|
-
}
|
|
41
|
-
function messageOf(error) {
|
|
42
|
-
return error instanceof Error ? error.message : String(error);
|
|
43
|
-
}
|
|
44
|
-
function compose(detail, verdict, note) {
|
|
45
|
-
const base = detail === undefined || typeof detail.zh !== 'string' || detail.zh.trim() === ''
|
|
46
|
-
? verdict.fallback
|
|
47
|
-
: {
|
|
48
|
-
en: `${detail.en} — ${verdict.question.en}`,
|
|
49
|
-
zh: `${detail.zh} —— ${verdict.question.zh}`,
|
|
50
|
-
};
|
|
51
|
-
const line = note === undefined ? base : { en: `${base.en} — ${note}`, zh: `${base.zh} —— ${note}` };
|
|
52
|
-
return { en: oneLine(line.en), zh: oneLine(line.zh) };
|
|
53
|
-
}
|
|
54
|
-
export async function approvalFor(call, context = {}) {
|
|
55
|
-
const asked = context.writes === true || context.elevates === true;
|
|
56
|
-
if (!asked)
|
|
57
|
-
return undefined;
|
|
58
|
-
let verdict;
|
|
59
|
-
try {
|
|
60
|
-
verdict = context.policy?.(call);
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
return {
|
|
64
|
-
kind: 'deny',
|
|
65
|
-
reason: `问"要不要审批"的时候套件的策略抛了错,已经停下:${messageOf(error)}`,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
if (verdict?.kind === 'read' || verdict?.kind === 'allow')
|
|
69
|
-
return undefined;
|
|
70
|
-
if (verdict?.kind === 'deny')
|
|
71
|
-
return { kind: 'deny', reason: verdict.reason };
|
|
72
|
-
if (verdict?.kind !== 'ask') {
|
|
73
|
-
return {
|
|
74
|
-
kind: 'deny',
|
|
75
|
-
reason: `${call.name ?? '这把工具'} 在清单里声明` +
|
|
76
|
-
(context.elevates === true ? '会抬高工具面' : '会写东西') +
|
|
77
|
-
',但它的套件没认领这次调用 —— 停下:' +
|
|
78
|
-
'在套件的 needsApproval 里补一条审批(含"这次会发生什么"),别让它静默过去',
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
let facts;
|
|
82
|
-
try {
|
|
83
|
-
facts = await context.detailOf?.(call);
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
return { kind: 'deny', reason: `拿不到"这次会发生什么",已经停下:${messageOf(error)}` };
|
|
87
|
-
}
|
|
88
|
-
if (facts !== undefined && 'blocked' in facts)
|
|
89
|
-
return { kind: 'deny', reason: facts.blocked };
|
|
90
|
-
if (context.skipAsk === true)
|
|
91
|
-
return undefined;
|
|
92
|
-
const note = context.declaredNote === true && verdict.noteInDetail !== true ? approvalNoteOf(call) : undefined;
|
|
93
|
-
return {
|
|
94
|
-
kind: 'ask',
|
|
95
|
-
reason: verdict.reason,
|
|
96
|
-
displayReason: compose(facts, verdict, note),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 「写工具要点头」那一对的默认口径:点名的工具一律 `ask` + 同一份明细,其余一律 `read`。
|
|
101
|
-
* 把它直接摊在 `mount()` 的返回值里:`...writeApprovalOf({ … })`。
|
|
102
|
-
* @param options.tools 需要点头的工具名。
|
|
103
|
-
* @param options.reason 为什么问(给 agent 看的理由)。
|
|
104
|
-
* @param options.question 问句(zh / en,≤40 字)。
|
|
105
|
-
* @param options.fallback 没有明细时的整句(zh / en,≤40 字)。
|
|
106
|
-
* @param options.detail 审批屏头行那句明细(zh / en,≤20 字)。
|
|
107
|
-
* @returns `{ needsApproval, approvalDetail }`。
|
|
108
|
-
*/
|
|
109
|
-
export function writeApprovalOf(options) {
|
|
110
|
-
const tools = new Set(options.tools);
|
|
111
|
-
const named = (call) => call.name !== undefined && tools.has(call.name);
|
|
112
|
-
return {
|
|
113
|
-
needsApproval: (call) => named(call)
|
|
114
|
-
? { kind: 'ask', reason: options.reason, question: options.question, fallback: options.fallback }
|
|
115
|
-
: { kind: 'read' },
|
|
116
|
-
approvalDetail: (call) => (named(call) ? options.detail : undefined),
|
|
117
|
-
};
|
|
118
|
-
}
|
package/dist/host/tool-kit.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ToolOutputDefinition, ToolRunContext } from '../contract/module-context.js';
|
|
2
|
-
import type { ContentBlock } from '@deepseek-ai/dsh-llm';
|
|
3
|
-
export declare function sessionWorkspace(exec: ToolRunContext | undefined): string | null;
|
|
4
|
-
export declare function sessionIdOf(exec: ToolRunContext | undefined): string | null;
|
|
5
|
-
export declare function textOutput(text: string): ContentBlock[];
|
|
6
|
-
export declare function textRender(_args: unknown, value: unknown): ContentBlock[];
|
|
7
|
-
export declare const TEXT_OUTPUT: ToolOutputDefinition;
|
|
8
|
-
export declare function jsonText(value: unknown): string;
|
package/dist/host/tool-kit.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export function sessionWorkspace(exec) {
|
|
2
|
-
const cwd = exec?.agent?.session?.header?.cwd;
|
|
3
|
-
return typeof cwd === 'string' && cwd.trim() !== '' ? cwd.trim() : null;
|
|
4
|
-
}
|
|
5
|
-
export function sessionIdOf(exec) {
|
|
6
|
-
const id = exec?.agent?.session?.id;
|
|
7
|
-
return typeof id === 'string' && id.trim() !== '' ? id.trim() : null;
|
|
8
|
-
}
|
|
9
|
-
export function textOutput(text) {
|
|
10
|
-
return [{ type: 'text', text }];
|
|
11
|
-
}
|
|
12
|
-
export function textRender(_args, value) {
|
|
13
|
-
const text = value?.text;
|
|
14
|
-
return textOutput(typeof text === 'string' ? text : JSON.stringify(value));
|
|
15
|
-
}
|
|
16
|
-
export const TEXT_OUTPUT = {
|
|
17
|
-
schema: { type: 'object', properties: {}, additionalProperties: true },
|
|
18
|
-
render: textRender,
|
|
19
|
-
};
|
|
20
|
-
export function jsonText(value) {
|
|
21
|
-
return JSON.stringify(value);
|
|
22
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface ToolboxCapability {
|
|
2
|
-
readonly name: string;
|
|
3
|
-
readonly description: string;
|
|
4
|
-
readonly content: string;
|
|
5
|
-
}
|
|
6
|
-
export interface ToolboxPort {
|
|
7
|
-
packsOf(session: string | null, preset: string | null): ReadonlySet<string>;
|
|
8
|
-
capabilityBrief?(workspace: string | null): ToolboxCapability;
|
|
9
|
-
}
|
|
10
|
-
export interface McpServerPacks {
|
|
11
|
-
readonly name: string;
|
|
12
|
-
readonly tools: readonly string[];
|
|
13
|
-
}
|
|
14
|
-
export interface McpToolsPort {
|
|
15
|
-
servers(): readonly McpServerPacks[];
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 单元配置的落盘接口:`deps.store.for(unit, workspace)` 交出来的那个形状。
|
|
3
|
-
*/
|
|
4
|
-
export interface UnitConfigStore {
|
|
5
|
-
read(name: string): unknown | null;
|
|
6
|
-
write(name: string, value: unknown): void;
|
|
7
|
-
remove(name: string): void;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* `createUnitConfig` 的入参。
|
|
11
|
-
*/
|
|
12
|
-
export interface UnitConfigOptions<T> {
|
|
13
|
-
readonly store: UnitConfigStore;
|
|
14
|
-
readonly file: string;
|
|
15
|
-
readonly fallback: T;
|
|
16
|
-
readonly normalize: (raw: unknown) => T;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 一份单元配置的读写器:读坏了退回兜底,写入前先规范化。
|
|
20
|
-
*/
|
|
21
|
-
export interface UnitConfig<T> {
|
|
22
|
-
read(): T;
|
|
23
|
-
write(payload: unknown): T;
|
|
24
|
-
reset(): void;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 把「一个 JSON 文件 + 一份兜底 + 一个规范化函数」接成模块配置的读写器。
|
|
28
|
-
* @param options.store - 落盘位置:模块自己的 `deps.store.for(unit, workspace)`。
|
|
29
|
-
* @param options.file - 文件名(如 `config.json`)。
|
|
30
|
-
* @param options.fallback - 没存过或存坏了时返回的那份。
|
|
31
|
-
* @param options.normalize - 把任意输入收成 `T`;写口不合法时直接抛。
|
|
32
|
-
* @returns 读 / 写 / 清空三件事。
|
|
33
|
-
*/
|
|
34
|
-
export declare function createUnitConfig<T>({ store, file, fallback, normalize, }: UnitConfigOptions<T>): UnitConfig<T>;
|
package/dist/host/unit-config.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 把「一个 JSON 文件 + 一份兜底 + 一个规范化函数」接成模块配置的读写器。
|
|
3
|
-
* @param options.store - 落盘位置:模块自己的 `deps.store.for(unit, workspace)`。
|
|
4
|
-
* @param options.file - 文件名(如 `config.json`)。
|
|
5
|
-
* @param options.fallback - 没存过或存坏了时返回的那份。
|
|
6
|
-
* @param options.normalize - 把任意输入收成 `T`;写口不合法时直接抛。
|
|
7
|
-
* @returns 读 / 写 / 清空三件事。
|
|
8
|
-
*/
|
|
9
|
-
export function createUnitConfig({ store, file, fallback, normalize, }) {
|
|
10
|
-
return {
|
|
11
|
-
read() {
|
|
12
|
-
try {
|
|
13
|
-
return normalize(store.read(file));
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return fallback;
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
write(payload) {
|
|
20
|
-
const value = normalize(payload);
|
|
21
|
-
store.write(file, value);
|
|
22
|
-
return value;
|
|
23
|
-
},
|
|
24
|
-
reset() {
|
|
25
|
-
store.remove(file);
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
}
|
package/dist/host/unit-data.d.ts
DELETED
package/dist/host/unit-data.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { allSame } from './plan-results.js';
|
|
2
|
-
import { resolvePlanOf, resolveRecipeOf } from './site.js';
|
|
3
|
-
function denied(origin, write = false) {
|
|
4
|
-
return {
|
|
5
|
-
ok: false,
|
|
6
|
-
error: {
|
|
7
|
-
code: 'invalid-request',
|
|
8
|
-
message: write
|
|
9
|
-
? `这个模块没声明写 ${origin}:在清单 host.origins 里加上它`
|
|
10
|
-
: `这个模块没声明读 ${origin}:在清单 host.origins 里加上它`,
|
|
11
|
-
pageCode: 'origin-not-declared',
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function unreadable(origin) {
|
|
16
|
-
return {
|
|
17
|
-
ok: false,
|
|
18
|
-
error: {
|
|
19
|
-
code: 'invalid-request',
|
|
20
|
-
message: `读不了 ${origin}:它不是一个能解析的地址(要带 http / https)`,
|
|
21
|
-
pageCode: 'origin-invalid',
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function unresolved(problem) {
|
|
26
|
-
return {
|
|
27
|
-
ok: false,
|
|
28
|
-
error: { code: problem.code, message: problem.message, pageCode: problem.pageCode },
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function failuresOf(calls, error) {
|
|
32
|
-
const names = calls !== null && typeof calls === 'object' ? Object.keys(calls) : [];
|
|
33
|
-
return Object.fromEntries(names.map((name) => [name, { ok: false, error }]));
|
|
34
|
-
}
|
|
35
|
-
function planDenied(plan, origin, write = false) {
|
|
36
|
-
const error = originOfValue(origin) === undefined ? unreadable(origin).error : denied(origin, write).error;
|
|
37
|
-
return allSame(plan, error);
|
|
38
|
-
}
|
|
39
|
-
function originOfValue(value) {
|
|
40
|
-
try {
|
|
41
|
-
return new URL(value).origin;
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export function scopedDataReader(data, origins, sites) {
|
|
48
|
-
if (origins === undefined && sites === undefined)
|
|
49
|
-
return data;
|
|
50
|
-
const originOf = originOfValue;
|
|
51
|
-
const siteOrigins = sites === undefined
|
|
52
|
-
? []
|
|
53
|
-
: Object.values(sites).flatMap((site) => typeof site?.origin === 'string' && site.origin.trim() !== '' ? [site.origin] : []);
|
|
54
|
-
const declared = origins === undefined ? (siteOrigins.length === 0 ? undefined : siteOrigins) : origins;
|
|
55
|
-
const allowed = declared === undefined ? undefined : new Set(declared.map(originOf).filter((one) => one !== undefined));
|
|
56
|
-
const allows = (value) => {
|
|
57
|
-
const origin = originOf(value);
|
|
58
|
-
return origin !== undefined && (allowed === undefined || allowed.has(origin));
|
|
59
|
-
};
|
|
60
|
-
const denyOf = (value, write = false) => originOf(value) === undefined ? unreadable(value) : denied(value, write);
|
|
61
|
-
const shapedPlan = (plan) => typeof plan === 'object' && plan !== null && Array.isArray(plan.steps) ? undefined : '计划要是对象且带 steps';
|
|
62
|
-
const planInputOf = (plan, write) => {
|
|
63
|
-
const bad = shapedPlan(plan);
|
|
64
|
-
if (bad !== undefined)
|
|
65
|
-
return { failure: allSame(plan, { code: 'invalid-request', message: bad }) };
|
|
66
|
-
const resolved = resolvePlanOf(plan, sites);
|
|
67
|
-
if (!resolved.ok)
|
|
68
|
-
return { failure: allSame(plan, unresolved(resolved.problem).error) };
|
|
69
|
-
if (!allows(resolved.value.origin))
|
|
70
|
-
return { failure: planDenied(plan, resolved.value.origin, write) };
|
|
71
|
-
return { plan: resolved.value };
|
|
72
|
-
};
|
|
73
|
-
const scoped = {
|
|
74
|
-
read: (request, options) => {
|
|
75
|
-
if (typeof request !== 'object' || request === null) {
|
|
76
|
-
return Promise.resolve({
|
|
77
|
-
ok: false,
|
|
78
|
-
error: { code: 'invalid-request', message: '请求要是对象' },
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
const raw = request.kind === 'http' ? request.url : request.kind === 'browser' ? request.url : undefined;
|
|
82
|
-
const target = raw === undefined || raw === '' ? undefined : raw;
|
|
83
|
-
if (target !== undefined && !allows(target))
|
|
84
|
-
return Promise.resolve(denyOf(target));
|
|
85
|
-
return data.read(request, options);
|
|
86
|
-
},
|
|
87
|
-
request: (recipe, overrides, options) => {
|
|
88
|
-
const resolved = resolveRecipeOf(recipe, sites);
|
|
89
|
-
if (!resolved.ok)
|
|
90
|
-
return Promise.resolve(unresolved(resolved.problem));
|
|
91
|
-
if (!allows(resolved.value.origin))
|
|
92
|
-
return Promise.resolve(denyOf(resolved.value.origin));
|
|
93
|
-
return data.request(resolved.value, overrides, options);
|
|
94
|
-
},
|
|
95
|
-
requestMany: (recipe, calls, options) => {
|
|
96
|
-
const resolved = resolveRecipeOf(recipe, sites);
|
|
97
|
-
if (!resolved.ok) {
|
|
98
|
-
return Promise.resolve(failuresOf(calls, unresolved(resolved.problem).error));
|
|
99
|
-
}
|
|
100
|
-
if (!allows(resolved.value.origin)) {
|
|
101
|
-
return Promise.resolve(failuresOf(calls, denyOf(resolved.value.origin).error));
|
|
102
|
-
}
|
|
103
|
-
return data.requestMany(resolved.value, calls, options);
|
|
104
|
-
},
|
|
105
|
-
plan: (plan, options) => {
|
|
106
|
-
const input = planInputOf(plan, false);
|
|
107
|
-
if ('failure' in input)
|
|
108
|
-
return Promise.resolve(input.failure);
|
|
109
|
-
return data.plan(input.plan, options);
|
|
110
|
-
},
|
|
111
|
-
submit: (recipe, overrides, options) => {
|
|
112
|
-
const resolved = resolveRecipeOf(recipe, sites);
|
|
113
|
-
if (!resolved.ok)
|
|
114
|
-
return Promise.resolve(unresolved(resolved.problem));
|
|
115
|
-
if (!allows(resolved.value.origin))
|
|
116
|
-
return Promise.resolve(denyOf(resolved.value.origin, true));
|
|
117
|
-
return data.submit(resolved.value, overrides, options);
|
|
118
|
-
},
|
|
119
|
-
submitPlan: (plan, options) => {
|
|
120
|
-
const input = planInputOf(plan, true);
|
|
121
|
-
if ('failure' in input)
|
|
122
|
-
return Promise.resolve(input.failure);
|
|
123
|
-
return data.submitPlan(input.plan, options);
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
return scoped;
|
|
127
|
-
}
|