@haneinfo/commands 0.0.0-stage → 0.1.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/LICENSE +14 -0
- package/README.md +200 -2
- package/agent-guide.md +9 -0
- package/dist/authorizer.d.ts +73 -0
- package/dist/authorizer.d.ts.map +1 -0
- package/dist/authorizer.js +245 -0
- package/dist/authorizer.js.map +1 -0
- package/dist/command-tool-error.d.ts +10 -0
- package/dist/command-tool-error.d.ts.map +1 -0
- package/dist/command-tool-error.js +25 -0
- package/dist/command-tool-error.js.map +1 -0
- package/dist/define-command.d.ts +49 -0
- package/dist/define-command.d.ts.map +1 -0
- package/dist/define-command.js +175 -0
- package/dist/define-command.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/nest/commands-web.executor.d.ts +38 -0
- package/dist/nest/commands-web.executor.d.ts.map +1 -0
- package/dist/nest/commands-web.executor.js +115 -0
- package/dist/nest/commands-web.executor.js.map +1 -0
- package/dist/nest/commands-web.module.d.ts +12 -0
- package/dist/nest/commands-web.module.d.ts.map +1 -0
- package/dist/nest/commands-web.module.js +38 -0
- package/dist/nest/commands-web.module.js.map +1 -0
- package/dist/nest/index.d.ts +3 -0
- package/dist/nest/index.d.ts.map +1 -0
- package/dist/nest/index.js +10 -0
- package/dist/nest/index.js.map +1 -0
- package/dist/registry.d.ts +77 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +202 -0
- package/dist/registry.js.map +1 -0
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -3
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
import type { CommandDefinition } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Machine-readable error codes thrown by {@link defineCommand} and command registration
|
|
5
|
+
* (`mcp-connector-contract.md` §3.1; 1A §4, §6).
|
|
6
|
+
*/
|
|
7
|
+
export type CommandDefinitionErrorCode = 'invalid-name' | 'invalid-schema-version' | 'missing-access' | 'read-confirmation-forbidden' | 'missing-confirmation' | 'missing-exempt-reason' | 'admin-write-requires-confirmation' | 'invalid-surfaces' | 'missing-description' | 'invalid-permissions' | 'missing-resource-acl-reason' | 'unexpected-resource-acl-reason' | 'admin-resource-acl-forbidden' | 'invalid-match' | 'invalid-scope' | 'admission-policy-surface' | 'invalid-schema' | 'invalid-handler';
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when a {@link CommandDefinition} violates platform contract invariants.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CommandDefinitionError extends Error {
|
|
12
|
+
readonly code: CommandDefinitionErrorCode;
|
|
13
|
+
readonly command: string | undefined;
|
|
14
|
+
constructor(code: CommandDefinitionErrorCode, command: string | undefined, message: string);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validates a command definition against the platform contract rules:
|
|
18
|
+
*
|
|
19
|
+
* 1. `invalid-name`: `name` must be a non-empty string with no whitespace (`mcp-connector-contract.md` §3.1; 1A §4).
|
|
20
|
+
* 2. `invalid-schema-version`: `schemaVersion` must be a positive integer (`mcp-connector-contract.md` §3.1; 1A §6).
|
|
21
|
+
* 3. `missing-access`: `access` must be `'read'` or `'write'` (`mcp-connector-contract.md` §3.1; 1A §4).
|
|
22
|
+
* 4. `read-confirmation-forbidden` / `missing-confirmation`: `'read'` commands must not declare `confirmation` or `exemptReason`; `'write'` commands must declare `confirmation` as `'required'` or `'exempt'` (`mcp-connector-contract.md` §9.1).
|
|
23
|
+
* 5. `missing-exempt-reason`: when `access === 'write'` and `confirmation === 'exempt'`, `exemptReason` must be a non-empty string after trimming (`mcp-connector-contract.md` §9.1; 1A §6).
|
|
24
|
+
* 6. `admin-write-requires-confirmation`: `access === 'write'` on `'mcp-admin'` must not declare `confirmation === 'exempt'` (`1A` §6).
|
|
25
|
+
* 7. `invalid-surfaces` / `missing-description`: `surfaces` must be a non-empty array of unique `'web' | 'mcp' | 'mcp-admin'` values; `description` must be a non-empty trimmed string whenever `surfaces` includes `'mcp'` or `'mcp-admin'` (`mcp-connector-contract.md` §3.1, §9.1; 1A §4).
|
|
26
|
+
* 8. `invalid-permissions` / `missing-resource-acl-reason` / `unexpected-resource-acl-reason` / `admin-resource-acl-forbidden`: `permissions` must be either a non-empty array of unique non-empty strings (with no `resourceAclReason`) or an empty array `[]` with a non-empty trimmed `resourceAclReason` (forbidden on `'mcp-admin'`) (`mcp-connector-contract.md` §9.1).
|
|
27
|
+
* 9. `invalid-match`: `match` must be `'any'` or `'all'` (`mcp-connector-contract.md` §3.1; 1A §4).
|
|
28
|
+
* 10. `invalid-scope`: `scope` must parse via `parseScope` with exactly three `<app>:<resource>:<action>` segments and no `*` in any segment (`mcp-connector-contract.md` §3.1, §5.2; 1A §4; `@haneinfo/plugin-api` `scopes.ts`).
|
|
29
|
+
* 11. `admission-policy-surface`: `admissionPolicy` defaults to `'required'`; `'exempt'` or `'independent'` requires `surfaces` to be exactly `['web']` (`mcp-connector-contract.md` §3.1, §3.3; 1A §4 "App 准入").
|
|
30
|
+
* 12. `invalid-schema` / `invalid-handler`: `inputSchema` (and optional `outputSchema` if provided) must exist, and `handler` must be a function (`mcp-connector-contract.md` §3.1; 1A §4).
|
|
31
|
+
*/
|
|
32
|
+
export declare function validateCommandDefinition(definition: unknown): asserts definition is CommandDefinition;
|
|
33
|
+
/**
|
|
34
|
+
* Validates and freezes a {@link CommandDefinition}, returning the exact same object reference.
|
|
35
|
+
*
|
|
36
|
+
* Enforces all rules from `mcp-connector-contract.md` §3.1, §5.2 and `1A` §4, §6 at call time,
|
|
37
|
+
* throwing {@link CommandDefinitionError} on violation.
|
|
38
|
+
*/
|
|
39
|
+
export declare function defineCommand<TInputSchema extends ZodType, TOutputSchema extends ZodType | undefined = undefined, TTx = unknown>(definition: CommandDefinition<TInputSchema, TOutputSchema, TTx>): CommandDefinition<TInputSchema, TOutputSchema, TTx>;
|
|
40
|
+
/**
|
|
41
|
+
* Freezes the definition and the arrays the validation rules depend on. A shallow freeze would let
|
|
42
|
+
* a caller push `'mcp-admin'` into `surfaces` (or empty `permissions`) after validation and bypass
|
|
43
|
+
* rules 6–8.
|
|
44
|
+
*/
|
|
45
|
+
export declare function freezeCommandDefinition<T extends {
|
|
46
|
+
surfaces: readonly unknown[];
|
|
47
|
+
permissions: readonly unknown[];
|
|
48
|
+
}>(definition: T): T;
|
|
49
|
+
//# sourceMappingURL=define-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-command.d.ts","sourceRoot":"","sources":["../src/define-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,SAAS,CAAC;AASjE;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAClC,cAAc,GACd,wBAAwB,GACxB,gBAAgB,GAChB,6BAA6B,GAC7B,sBAAsB,GACtB,uBAAuB,GACvB,mCAAmC,GACnC,kBAAkB,GAClB,qBAAqB,GACrB,qBAAqB,GACrB,6BAA6B,GAC7B,gCAAgC,GAChC,8BAA8B,GAC9B,eAAe,GACf,eAAe,GACf,0BAA0B,GAC1B,gBAAgB,GAChB,iBAAiB,CAAC;AAEtB;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAE7C,QAAQ,CAAC,IAAI,EAAE,0BAA0B;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;gBAD3B,IAAI,EAAE,0BAA0B,EAChC,OAAO,EAAE,MAAM,GAAG,SAAS,EACpC,OAAO,EAAE,MAAM;CAKlB;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,UAAU,IAAI,iBAAiB,CAmOzC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,YAAY,SAAS,OAAO,EAC5B,aAAa,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EACrD,GAAG,GAAG,OAAO,EAEb,UAAU,EAAE,iBAAiB,CAAC,YAAY,EAAE,aAAa,EAAE,GAAG,CAAC,GAC9D,iBAAiB,CAAC,YAAY,EAAE,aAAa,EAAE,GAAG,CAAC,CAGrD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,CAAC,SAAS;IAAE,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAAC,WAAW,EAAE,SAAS,OAAO,EAAE,CAAA;CAAE,EAC3E,UAAU,EAAE,CAAC,GAAG,CAAC,CAIlB"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandDefinitionError = void 0;
|
|
4
|
+
exports.validateCommandDefinition = validateCommandDefinition;
|
|
5
|
+
exports.defineCommand = defineCommand;
|
|
6
|
+
exports.freezeCommandDefinition = freezeCommandDefinition;
|
|
7
|
+
const plugin_api_1 = require("@haneinfo/plugin-api");
|
|
8
|
+
const VALID_SURFACES = new Set(['web', 'mcp', 'mcp-admin']);
|
|
9
|
+
const VALID_ADMISSION_POLICIES = new Set([
|
|
10
|
+
'required',
|
|
11
|
+
'exempt',
|
|
12
|
+
'independent',
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when a {@link CommandDefinition} violates platform contract invariants.
|
|
16
|
+
*/
|
|
17
|
+
class CommandDefinitionError extends Error {
|
|
18
|
+
constructor(code, command, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.command = command;
|
|
22
|
+
this.name = 'CommandDefinitionError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.CommandDefinitionError = CommandDefinitionError;
|
|
26
|
+
function commandNameOf(raw) {
|
|
27
|
+
return typeof raw.name === 'string' && raw.name.length > 0 ? raw.name : undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validates a command definition against the platform contract rules:
|
|
31
|
+
*
|
|
32
|
+
* 1. `invalid-name`: `name` must be a non-empty string with no whitespace (`mcp-connector-contract.md` §3.1; 1A §4).
|
|
33
|
+
* 2. `invalid-schema-version`: `schemaVersion` must be a positive integer (`mcp-connector-contract.md` §3.1; 1A §6).
|
|
34
|
+
* 3. `missing-access`: `access` must be `'read'` or `'write'` (`mcp-connector-contract.md` §3.1; 1A §4).
|
|
35
|
+
* 4. `read-confirmation-forbidden` / `missing-confirmation`: `'read'` commands must not declare `confirmation` or `exemptReason`; `'write'` commands must declare `confirmation` as `'required'` or `'exempt'` (`mcp-connector-contract.md` §9.1).
|
|
36
|
+
* 5. `missing-exempt-reason`: when `access === 'write'` and `confirmation === 'exempt'`, `exemptReason` must be a non-empty string after trimming (`mcp-connector-contract.md` §9.1; 1A §6).
|
|
37
|
+
* 6. `admin-write-requires-confirmation`: `access === 'write'` on `'mcp-admin'` must not declare `confirmation === 'exempt'` (`1A` §6).
|
|
38
|
+
* 7. `invalid-surfaces` / `missing-description`: `surfaces` must be a non-empty array of unique `'web' | 'mcp' | 'mcp-admin'` values; `description` must be a non-empty trimmed string whenever `surfaces` includes `'mcp'` or `'mcp-admin'` (`mcp-connector-contract.md` §3.1, §9.1; 1A §4).
|
|
39
|
+
* 8. `invalid-permissions` / `missing-resource-acl-reason` / `unexpected-resource-acl-reason` / `admin-resource-acl-forbidden`: `permissions` must be either a non-empty array of unique non-empty strings (with no `resourceAclReason`) or an empty array `[]` with a non-empty trimmed `resourceAclReason` (forbidden on `'mcp-admin'`) (`mcp-connector-contract.md` §9.1).
|
|
40
|
+
* 9. `invalid-match`: `match` must be `'any'` or `'all'` (`mcp-connector-contract.md` §3.1; 1A §4).
|
|
41
|
+
* 10. `invalid-scope`: `scope` must parse via `parseScope` with exactly three `<app>:<resource>:<action>` segments and no `*` in any segment (`mcp-connector-contract.md` §3.1, §5.2; 1A §4; `@haneinfo/plugin-api` `scopes.ts`).
|
|
42
|
+
* 11. `admission-policy-surface`: `admissionPolicy` defaults to `'required'`; `'exempt'` or `'independent'` requires `surfaces` to be exactly `['web']` (`mcp-connector-contract.md` §3.1, §3.3; 1A §4 "App 准入").
|
|
43
|
+
* 12. `invalid-schema` / `invalid-handler`: `inputSchema` (and optional `outputSchema` if provided) must exist, and `handler` must be a function (`mcp-connector-contract.md` §3.1; 1A §4).
|
|
44
|
+
*/
|
|
45
|
+
function validateCommandDefinition(definition) {
|
|
46
|
+
if (definition === null || typeof definition !== 'object') {
|
|
47
|
+
throw new CommandDefinitionError('invalid-name', undefined, 'Command definition must be an object.');
|
|
48
|
+
}
|
|
49
|
+
const raw = definition;
|
|
50
|
+
const cmdName = commandNameOf(raw);
|
|
51
|
+
// Rule 1: name non-empty string without whitespace (mcp-connector-contract.md §3.1; 1A §4)
|
|
52
|
+
if (typeof raw.name !== 'string' || raw.name.length === 0 || /\s/.test(raw.name)) {
|
|
53
|
+
throw new CommandDefinitionError('invalid-name', typeof raw.name === 'string' ? raw.name : undefined, 'Command name must be a non-empty string without whitespace.');
|
|
54
|
+
}
|
|
55
|
+
// Rule 2: schemaVersion positive integer (mcp-connector-contract.md §3.1; 1A §6)
|
|
56
|
+
if (typeof raw.schemaVersion !== 'number' ||
|
|
57
|
+
!Number.isInteger(raw.schemaVersion) ||
|
|
58
|
+
raw.schemaVersion <= 0) {
|
|
59
|
+
throw new CommandDefinitionError('invalid-schema-version', cmdName, `Command "${raw.name}" must declare a positive integer schemaVersion.`);
|
|
60
|
+
}
|
|
61
|
+
// Rule 3: access must be 'read' | 'write' (mcp-connector-contract.md §3.1; 1A §4)
|
|
62
|
+
if (raw.access !== 'read' && raw.access !== 'write') {
|
|
63
|
+
throw new CommandDefinitionError('missing-access', cmdName, `Command "${raw.name}" must declare access as 'read' or 'write'.`);
|
|
64
|
+
}
|
|
65
|
+
// Rule 4 & 5: reads must not declare confirmation/exemptReason; writes must declare confirmation (mcp-connector-contract.md §9.1)
|
|
66
|
+
if (raw.access === 'read') {
|
|
67
|
+
if (raw.confirmation !== undefined || raw.exemptReason !== undefined) {
|
|
68
|
+
throw new CommandDefinitionError('read-confirmation-forbidden', cmdName, `Read command "${raw.name}" must not declare confirmation or exemptReason.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (raw.confirmation !== 'required' && raw.confirmation !== 'exempt') {
|
|
73
|
+
throw new CommandDefinitionError('missing-confirmation', cmdName, `Write command "${raw.name}" must declare confirmation as 'required' or 'exempt'.`);
|
|
74
|
+
}
|
|
75
|
+
if (raw.confirmation === 'exempt' &&
|
|
76
|
+
(typeof raw.exemptReason !== 'string' || raw.exemptReason.trim().length === 0)) {
|
|
77
|
+
throw new CommandDefinitionError('missing-exempt-reason', cmdName, `Command "${raw.name}" declares confirmation 'exempt' and must provide a non-empty exemptReason.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Rule 7: surfaces non-empty, valid enum values, unique (mcp-connector-contract.md §3.1; 1A §4)
|
|
81
|
+
if (!Array.isArray(raw.surfaces) ||
|
|
82
|
+
raw.surfaces.length === 0 ||
|
|
83
|
+
raw.surfaces.some((s) => typeof s !== 'string' || !VALID_SURFACES.has(s)) ||
|
|
84
|
+
new Set(raw.surfaces).size !== raw.surfaces.length) {
|
|
85
|
+
throw new CommandDefinitionError('invalid-surfaces', cmdName, `Command "${raw.name}" must declare a non-empty array of unique surfaces ('web' | 'mcp' | 'mcp-admin').`);
|
|
86
|
+
}
|
|
87
|
+
// Rule 7b: description required when surfaces includes 'mcp' or 'mcp-admin' (mcp-connector-contract.md §9.1)
|
|
88
|
+
if ((raw.surfaces.includes('mcp') || raw.surfaces.includes('mcp-admin')) &&
|
|
89
|
+
(typeof raw.description !== 'string' || raw.description.trim().length === 0)) {
|
|
90
|
+
throw new CommandDefinitionError('missing-description', cmdName, `Command "${raw.name}" exposes an MCP surface and must declare a non-empty description.`);
|
|
91
|
+
}
|
|
92
|
+
// Rule 6: write + mcp-admin + exempt is forbidden (1A §6)
|
|
93
|
+
if (raw.access === 'write' &&
|
|
94
|
+
raw.surfaces.includes('mcp-admin') &&
|
|
95
|
+
raw.confirmation === 'exempt') {
|
|
96
|
+
throw new CommandDefinitionError('admin-write-requires-confirmation', cmdName, `Command "${raw.name}" is a write on 'mcp-admin' and must require confirmation (1A §6).`);
|
|
97
|
+
}
|
|
98
|
+
// Rule 8: permissions non-empty unique strings (no resourceAclReason) OR [] with resourceAclReason (not on mcp-admin) (mcp-connector-contract.md §9.1)
|
|
99
|
+
if (!Array.isArray(raw.permissions)) {
|
|
100
|
+
throw new CommandDefinitionError('invalid-permissions', cmdName, `Command "${raw.name}" must declare permissions as an array.`);
|
|
101
|
+
}
|
|
102
|
+
if (raw.permissions.length === 0) {
|
|
103
|
+
if (typeof raw.resourceAclReason !== 'string' || raw.resourceAclReason.trim().length === 0) {
|
|
104
|
+
throw new CommandDefinitionError('missing-resource-acl-reason', cmdName, `Command "${raw.name}" has empty permissions and must provide a non-empty resourceAclReason.`);
|
|
105
|
+
}
|
|
106
|
+
if (raw.surfaces.includes('mcp-admin')) {
|
|
107
|
+
throw new CommandDefinitionError('admin-resource-acl-forbidden', cmdName, `Command "${raw.name}" on 'mcp-admin' must declare RBAC permissions and cannot rely solely on resource ACL.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
if (raw.permissions.some((p) => typeof p !== 'string' || p.trim().length === 0) ||
|
|
112
|
+
new Set(raw.permissions).size !== raw.permissions.length) {
|
|
113
|
+
throw new CommandDefinitionError('invalid-permissions', cmdName, `Command "${raw.name}" must declare unique non-empty permission strings.`);
|
|
114
|
+
}
|
|
115
|
+
if (raw.resourceAclReason !== undefined) {
|
|
116
|
+
throw new CommandDefinitionError('unexpected-resource-acl-reason', cmdName, `Command "${raw.name}" declares RBAC permissions and must not declare resourceAclReason.`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Rule 9: match must be 'any' | 'all' (mcp-connector-contract.md §3.1; 1A §4)
|
|
120
|
+
if (raw.match !== 'any' && raw.match !== 'all') {
|
|
121
|
+
throw new CommandDefinitionError('invalid-match', cmdName, `Command "${raw.name}" must declare match as 'any' or 'all'.`);
|
|
122
|
+
}
|
|
123
|
+
// Rule 10: scope parseable by parseScope, exactly 3 segments <app>:<resource>:<action>, no '*' (mcp-connector-contract.md §3.1, §5.2; 1A §4)
|
|
124
|
+
if (typeof raw.scope !== 'string') {
|
|
125
|
+
throw new CommandDefinitionError('invalid-scope', cmdName, `Command "${raw.name}" must declare a string scope in '<app>:<resource>:<action>' format.`);
|
|
126
|
+
}
|
|
127
|
+
const parsedScope = (0, plugin_api_1.parseScope)(raw.scope);
|
|
128
|
+
if (parsedScope === null ||
|
|
129
|
+
parsedScope.resource.split(':').length !== 2 ||
|
|
130
|
+
parsedScope.action.includes('*')) {
|
|
131
|
+
throw new CommandDefinitionError('invalid-scope', cmdName, `Command "${raw.name}" scope "${raw.scope}" must be '<app>:<resource>:<action>' with no '*' wildcards.`);
|
|
132
|
+
}
|
|
133
|
+
// Rule 11: admissionPolicy defaults to 'required'; 'exempt' | 'independent' must have surfaces === ['web'] (mcp-connector-contract.md §3.1, §3.3; 1A §4 "App 准入")
|
|
134
|
+
const admissionPolicy = raw.admissionPolicy ?? 'required';
|
|
135
|
+
if (typeof admissionPolicy !== 'string' || !VALID_ADMISSION_POLICIES.has(admissionPolicy)) {
|
|
136
|
+
throw new CommandDefinitionError('admission-policy-surface', cmdName, `Command "${raw.name}" has invalid admissionPolicy.`);
|
|
137
|
+
}
|
|
138
|
+
if ((admissionPolicy === 'exempt' || admissionPolicy === 'independent') &&
|
|
139
|
+
(raw.surfaces.length !== 1 || raw.surfaces[0] !== 'web')) {
|
|
140
|
+
throw new CommandDefinitionError('admission-policy-surface', cmdName, `Command "${raw.name}" with admissionPolicy '${admissionPolicy}' must only expose the ['web'] surface.`);
|
|
141
|
+
}
|
|
142
|
+
// Rule 12a: inputSchema must exist (and outputSchema if provided must be an object) (mcp-connector-contract.md §3.1; 1A §4)
|
|
143
|
+
if (raw.inputSchema === undefined ||
|
|
144
|
+
raw.inputSchema === null ||
|
|
145
|
+
typeof raw.inputSchema !== 'object' ||
|
|
146
|
+
(raw.outputSchema !== undefined &&
|
|
147
|
+
(raw.outputSchema === null || typeof raw.outputSchema !== 'object'))) {
|
|
148
|
+
throw new CommandDefinitionError('invalid-schema', cmdName, `Command "${raw.name}" must provide an inputSchema.`);
|
|
149
|
+
}
|
|
150
|
+
// Rule 12b: handler must be a function (mcp-connector-contract.md §3.1; 1A §4)
|
|
151
|
+
if (typeof raw.handler !== 'function') {
|
|
152
|
+
throw new CommandDefinitionError('invalid-handler', cmdName, `Command "${raw.name}" must provide a handler function.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Validates and freezes a {@link CommandDefinition}, returning the exact same object reference.
|
|
157
|
+
*
|
|
158
|
+
* Enforces all rules from `mcp-connector-contract.md` §3.1, §5.2 and `1A` §4, §6 at call time,
|
|
159
|
+
* throwing {@link CommandDefinitionError} on violation.
|
|
160
|
+
*/
|
|
161
|
+
function defineCommand(definition) {
|
|
162
|
+
validateCommandDefinition(definition);
|
|
163
|
+
return freezeCommandDefinition(definition);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Freezes the definition and the arrays the validation rules depend on. A shallow freeze would let
|
|
167
|
+
* a caller push `'mcp-admin'` into `surfaces` (or empty `permissions`) after validation and bypass
|
|
168
|
+
* rules 6–8.
|
|
169
|
+
*/
|
|
170
|
+
function freezeCommandDefinition(definition) {
|
|
171
|
+
Object.freeze(definition.surfaces);
|
|
172
|
+
Object.freeze(definition.permissions);
|
|
173
|
+
return Object.freeze(definition);
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=define-command.js.map
|
|
@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C,CAAC;IACtC,OAAO,uBAAuB,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED;;;;GAIG;AACH,SAAgB,uBAAuB,CAErC,UAAa;IACb,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { type AuthorizationDecision, type AuthorizationDenialCode, type AuthorizationStep, type AuthorizeCommandInput, type AuthorizerTxClient, type AuthorizeWriteInTransactionInput, type CommandAuthorizer, type CommandAuthorizerDeps, checkAppAdmission, createCommandAuthorizer, holdsPermissions, } from './authorizer';
|
|
2
|
+
export { CommandToolError } from './command-tool-error';
|
|
3
|
+
export { CommandDefinitionError, type CommandDefinitionErrorCode, defineCommand, validateCommandDefinition, } from './define-command';
|
|
4
|
+
export { type CommandRegistry, CommandRegistryError, type CommandRegistryErrorCode, type ConfirmationExemptionSummary, type CreateCommandRegistryOptions, createCommandRegistry, type DynamicSourceError, type ResourceAclCommandSummary, } from './registry';
|
|
5
|
+
export type { CommandAccess, CommandActor, CommandAdmissionPolicy, CommandConfirmation, CommandDefinition, CommandMatch, CommandPrincipalKind, CommandSurface, DynamicCommandSource, ExternalToolGroupAdapter, ScopeCatalogEntry, } from './types';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,gCAAgC,EACrC,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,KAAK,0BAA0B,EAC/B,aAAa,EACb,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,eAAe,EACpB,oBAAoB,EACpB,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,EACjC,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCommandRegistry = exports.CommandRegistryError = exports.validateCommandDefinition = exports.defineCommand = exports.CommandDefinitionError = exports.CommandToolError = exports.holdsPermissions = exports.createCommandAuthorizer = exports.checkAppAdmission = void 0;
|
|
4
|
+
var authorizer_1 = require("./authorizer");
|
|
5
|
+
Object.defineProperty(exports, "checkAppAdmission", { enumerable: true, get: function () { return authorizer_1.checkAppAdmission; } });
|
|
6
|
+
Object.defineProperty(exports, "createCommandAuthorizer", { enumerable: true, get: function () { return authorizer_1.createCommandAuthorizer; } });
|
|
7
|
+
Object.defineProperty(exports, "holdsPermissions", { enumerable: true, get: function () { return authorizer_1.holdsPermissions; } });
|
|
8
|
+
var command_tool_error_1 = require("./command-tool-error");
|
|
9
|
+
Object.defineProperty(exports, "CommandToolError", { enumerable: true, get: function () { return command_tool_error_1.CommandToolError; } });
|
|
10
|
+
var define_command_1 = require("./define-command");
|
|
11
|
+
Object.defineProperty(exports, "CommandDefinitionError", { enumerable: true, get: function () { return define_command_1.CommandDefinitionError; } });
|
|
12
|
+
Object.defineProperty(exports, "defineCommand", { enumerable: true, get: function () { return define_command_1.defineCommand; } });
|
|
13
|
+
Object.defineProperty(exports, "validateCommandDefinition", { enumerable: true, get: function () { return define_command_1.validateCommandDefinition; } });
|
|
14
|
+
var registry_1 = require("./registry");
|
|
15
|
+
Object.defineProperty(exports, "CommandRegistryError", { enumerable: true, get: function () { return registry_1.CommandRegistryError; } });
|
|
16
|
+
Object.defineProperty(exports, "createCommandRegistry", { enumerable: true, get: function () { return registry_1.createCommandRegistry; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAYsB;AAHpB,+GAAA,iBAAiB,OAAA;AACjB,qHAAA,uBAAuB,OAAA;AACvB,8GAAA,gBAAgB,OAAA;AAElB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,mDAK0B;AAJxB,wHAAA,sBAAsB,OAAA;AAEtB,+GAAA,aAAa,OAAA;AACb,2HAAA,yBAAyB,OAAA;AAE3B,uCASoB;AAPlB,gHAAA,oBAAoB,OAAA;AAIpB,iHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type IdentityStorePort, type Principal, type RbacPolicyPort, type ScopeMatcherPort } from '@haneinfo/plugin-api';
|
|
2
|
+
import { type HttpException } from '@nestjs/common';
|
|
3
|
+
import { type AuthorizationDenialCode, type AuthorizerTxClient } from '../authorizer';
|
|
4
|
+
import type { CommandRegistry } from '../registry';
|
|
5
|
+
/** Minimal Prisma client contract required by {@link CommandWebExecutor}. */
|
|
6
|
+
export interface CommandPrismaClient extends AuthorizerTxClient {
|
|
7
|
+
$transaction<T>(fn: (tx: AuthorizerTxClient) => Promise<T>, options?: {
|
|
8
|
+
isolationLevel?: 'ReadCommitted' | string;
|
|
9
|
+
}): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
/** Configuration options for {@link CommandsWebModule.forRoot}. */
|
|
12
|
+
export interface CommandsWebModuleOptions {
|
|
13
|
+
registry: CommandRegistry<any>;
|
|
14
|
+
/** Positive integer in milliseconds passed to `createCommandAuthorizer`. */
|
|
15
|
+
lockTimeoutMs: number;
|
|
16
|
+
}
|
|
17
|
+
/** Minimal HTTP request shape carrying the host-attached {@link Principal}. */
|
|
18
|
+
export interface CommandWebRequest {
|
|
19
|
+
user?: Principal;
|
|
20
|
+
}
|
|
21
|
+
/** Injection token for {@link CommandsWebModuleOptions}. */
|
|
22
|
+
export declare const COMMANDS_WEB_OPTIONS: unique symbol;
|
|
23
|
+
/** Maps an {@link AuthorizationDenialCode} to its contract §4 Web HTTP exception. */
|
|
24
|
+
export declare function denialToHttpException(code: AuthorizationDenialCode): HttpException;
|
|
25
|
+
/**
|
|
26
|
+
* NestJS web adapter that executes registered commands for `web` callers
|
|
27
|
+
* (`web-session` and `m2m-api-key`) with unified validation, authorization,
|
|
28
|
+
* and Read Committed write-transaction rechecks (`mcp-connector-contract.md` §3.3, §4).
|
|
29
|
+
*/
|
|
30
|
+
export declare class CommandWebExecutor {
|
|
31
|
+
private readonly identityStore;
|
|
32
|
+
private readonly prisma;
|
|
33
|
+
private readonly registry;
|
|
34
|
+
private readonly authorizer;
|
|
35
|
+
constructor(options: CommandsWebModuleOptions, rbac: Pick<RbacPolicyPort, 'rolesForUser' | 'flatten'>, identityStore: Pick<IdentityStorePort, 'findById'>, prisma: CommandPrismaClient, scopeMatcher?: ScopeMatcherPort);
|
|
36
|
+
execute<TOutput = unknown>(request: CommandWebRequest | null | undefined, commandName: string, rawInput: unknown): Promise<TOutput>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=commands-web.executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|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AAoB;gBAGf,OAAO,EAAE,wBAAwB,EAC1C,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,CAAC,EAE1D,aAAa,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,EAClC,MAAM,EAAE,mBAAmB,EACzB,YAAY,CAAC,EAAE,gBAAgB;IAU9D,OAAO,CAAC,OAAO,GAAG,OAAO,EAC7B,OAAO,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EAC7C,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,OAAO,CAAC;CAgEpB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CommandWebExecutor = exports.COMMANDS_WEB_OPTIONS = void 0;
|
|
16
|
+
exports.denialToHttpException = denialToHttpException;
|
|
17
|
+
const plugin_api_1 = require("@haneinfo/plugin-api");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const authorizer_1 = require("../authorizer");
|
|
20
|
+
/** Injection token for {@link CommandsWebModuleOptions}. */
|
|
21
|
+
exports.COMMANDS_WEB_OPTIONS = Symbol.for('haneinfo.commands.web-options');
|
|
22
|
+
/** Maps an {@link AuthorizationDenialCode} to its contract §4 Web HTTP exception. */
|
|
23
|
+
function denialToHttpException(code) {
|
|
24
|
+
switch (code) {
|
|
25
|
+
case 'command_unavailable':
|
|
26
|
+
return new common_1.NotFoundException({ code });
|
|
27
|
+
case 'lock_timeout':
|
|
28
|
+
return new common_1.ConflictException({ code });
|
|
29
|
+
case 'surface_mismatch':
|
|
30
|
+
case 'app_admission_denied':
|
|
31
|
+
case 'insufficient_scope':
|
|
32
|
+
case 'insufficient_permission':
|
|
33
|
+
case 'authorization_stale':
|
|
34
|
+
return new common_1.ForbiddenException({ code });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* NestJS web adapter that executes registered commands for `web` callers
|
|
39
|
+
* (`web-session` and `m2m-api-key`) with unified validation, authorization,
|
|
40
|
+
* and Read Committed write-transaction rechecks (`mcp-connector-contract.md` §3.3, §4).
|
|
41
|
+
*/
|
|
42
|
+
let CommandWebExecutor = class CommandWebExecutor {
|
|
43
|
+
constructor(options, rbac, identityStore, prisma, scopeMatcher) {
|
|
44
|
+
this.identityStore = identityStore;
|
|
45
|
+
this.prisma = prisma;
|
|
46
|
+
this.registry = options.registry;
|
|
47
|
+
this.authorizer = (0, authorizer_1.createCommandAuthorizer)({
|
|
48
|
+
rbac,
|
|
49
|
+
scopeMatcher,
|
|
50
|
+
lockTimeoutMs: options.lockTimeoutMs,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async execute(request, commandName, rawInput) {
|
|
54
|
+
const principal = request?.user;
|
|
55
|
+
if (!principal) {
|
|
56
|
+
throw new common_1.UnauthorizedException({ code: 'unauthorized' });
|
|
57
|
+
}
|
|
58
|
+
const command = this.registry.get(commandName, 'web');
|
|
59
|
+
if (!command) {
|
|
60
|
+
throw new common_1.NotFoundException({ code: 'command_unavailable' });
|
|
61
|
+
}
|
|
62
|
+
const isMachine = (0, plugin_api_1.isMachinePrincipal)(principal);
|
|
63
|
+
const actingUserId = (0, plugin_api_1.actingUserIdOf)(principal);
|
|
64
|
+
const localUser = actingUserId !== null && actingUserId.length > 0
|
|
65
|
+
? await this.identityStore.findById(actingUserId)
|
|
66
|
+
: null;
|
|
67
|
+
const actor = {
|
|
68
|
+
surface: 'web',
|
|
69
|
+
principalKind: isMachine ? 'm2m-api-key' : 'web-session',
|
|
70
|
+
issuer: null,
|
|
71
|
+
subject: isMachine ? null : principal.sub,
|
|
72
|
+
actingUserId,
|
|
73
|
+
isServiceAccount: localUser ? localUser.isServiceAccount : false,
|
|
74
|
+
isActive: localUser ? localUser.isActive : false,
|
|
75
|
+
scopes: isMachine ? principal.scopes : [],
|
|
76
|
+
};
|
|
77
|
+
const machineAuthorization = isMachine ? principal : undefined;
|
|
78
|
+
const preCheck = await this.authorizer.authorize({
|
|
79
|
+
actor,
|
|
80
|
+
command,
|
|
81
|
+
machineAuthorization,
|
|
82
|
+
});
|
|
83
|
+
if (!preCheck.ok) {
|
|
84
|
+
throw denialToHttpException(preCheck.code);
|
|
85
|
+
}
|
|
86
|
+
// Validate input only after authorization, so a caller without access cannot use the
|
|
87
|
+
// 400-versus-403 difference to probe a command's input schema.
|
|
88
|
+
const parsed = command.inputSchema.safeParse(rawInput);
|
|
89
|
+
if (!parsed.success) {
|
|
90
|
+
throw new common_1.BadRequestException({ code: 'invalid_input' });
|
|
91
|
+
}
|
|
92
|
+
if (command.access === 'read') {
|
|
93
|
+
return (await command.handler(actor, parsed.data, this.prisma));
|
|
94
|
+
}
|
|
95
|
+
return await this.prisma.$transaction(async (tx) => {
|
|
96
|
+
const txCheck = await this.authorizer.authorizeWriteInTransaction({ actor, command, machineAuthorization }, tx);
|
|
97
|
+
if (!txCheck.ok) {
|
|
98
|
+
throw denialToHttpException(txCheck.code);
|
|
99
|
+
}
|
|
100
|
+
return (await command.handler(actor, parsed.data, tx));
|
|
101
|
+
}, { isolationLevel: 'ReadCommitted' });
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
exports.CommandWebExecutor = CommandWebExecutor;
|
|
105
|
+
exports.CommandWebExecutor = CommandWebExecutor = __decorate([
|
|
106
|
+
(0, common_1.Injectable)(),
|
|
107
|
+
__param(0, (0, common_1.Inject)(exports.COMMANDS_WEB_OPTIONS)),
|
|
108
|
+
__param(1, (0, common_1.Inject)(plugin_api_1.RBAC_POLICY)),
|
|
109
|
+
__param(2, (0, common_1.Inject)(plugin_api_1.IDENTITY_STORE)),
|
|
110
|
+
__param(3, (0, common_1.Inject)(plugin_api_1.PRISMA)),
|
|
111
|
+
__param(4, (0, common_1.Optional)()),
|
|
112
|
+
__param(4, (0, common_1.Inject)(plugin_api_1.SCOPE_MATCHER)),
|
|
113
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object, Object])
|
|
114
|
+
], CommandWebExecutor);
|
|
115
|
+
//# sourceMappingURL=commands-web.executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands-web.executor.js","sourceRoot":"","sources":["../../src/nest/commands-web.executor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAwDA,sDAaC;AArED,qDAW8B;AAC9B,2CAUwB;AACxB,8CAKuB;AAwBvB,4DAA4D;AAC/C,QAAA,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAEhF,qFAAqF;AACrF,SAAgB,qBAAqB,CAAC,IAA6B;IACjE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,qBAAqB;YACxB,OAAO,IAAI,0BAAiB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,KAAK,cAAc;YACjB,OAAO,IAAI,0BAAiB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,KAAK,kBAAkB,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KAAK,MAAM,EAAE,CAAC;YAC9B,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAY,CAAC;QAC7E,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CACnC,KAAK,EAAE,EAAE,EAAE,EAAE;YACX,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,2BAA2B,CAC/D,EAAE,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,EACxC,EAAE,CACH,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;gBAChB,MAAM,qBAAqB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5C,CAAC;YACD,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAY,CAAC;QACpE,CAAC,EACD,EAAE,cAAc,EAAE,eAAe,EAAE,CACpC,CAAC;IACJ,CAAC;CACF,CAAA;AAxFY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,4BAAoB,CAAC,CAAA;IAC5B,WAAA,IAAA,eAAM,EAAC,wBAAW,CAAC,CAAA;IACnB,WAAA,IAAA,eAAM,EAAC,2BAAc,CAAC,CAAA;IAEtB,WAAA,IAAA,eAAM,EAAC,mBAAM,CAAC,CAAA;IACd,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,0BAAa,CAAC,CAAA;;GAVzB,kBAAkB,CAwF9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { type CommandsWebModuleOptions } from './commands-web.executor';
|
|
3
|
+
/**
|
|
4
|
+
* NestJS module providing {@link CommandWebExecutor} for web-surface command execution.
|
|
5
|
+
*
|
|
6
|
+
* Expects `RBAC_POLICY`, `IDENTITY_STORE`, `PRISMA`, and optionally `SCOPE_MATCHER`
|
|
7
|
+
* from `@haneinfo/plugin-api` to be available in the host DI container.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CommandsWebModule {
|
|
10
|
+
static forRoot(options: CommandsWebModuleOptions): DynamicModule;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=commands-web.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands-web.module.d.ts","sourceRoot":"","sources":["../../src/nest/commands-web.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAEL,KAAK,wBAAwB,EAE9B,MAAM,yBAAyB,CAAC;AAEjC;;;;;GAKG;AACH,qBACa,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;CAajE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var CommandsWebModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.CommandsWebModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const commands_web_executor_1 = require("./commands-web.executor");
|
|
13
|
+
/**
|
|
14
|
+
* NestJS module providing {@link CommandWebExecutor} for web-surface command execution.
|
|
15
|
+
*
|
|
16
|
+
* Expects `RBAC_POLICY`, `IDENTITY_STORE`, `PRISMA`, and optionally `SCOPE_MATCHER`
|
|
17
|
+
* from `@haneinfo/plugin-api` to be available in the host DI container.
|
|
18
|
+
*/
|
|
19
|
+
let CommandsWebModule = CommandsWebModule_1 = class CommandsWebModule {
|
|
20
|
+
static forRoot(options) {
|
|
21
|
+
return {
|
|
22
|
+
module: CommandsWebModule_1,
|
|
23
|
+
providers: [
|
|
24
|
+
{
|
|
25
|
+
provide: commands_web_executor_1.COMMANDS_WEB_OPTIONS,
|
|
26
|
+
useValue: options,
|
|
27
|
+
},
|
|
28
|
+
commands_web_executor_1.CommandWebExecutor,
|
|
29
|
+
],
|
|
30
|
+
exports: [commands_web_executor_1.CommandWebExecutor],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.CommandsWebModule = CommandsWebModule;
|
|
35
|
+
exports.CommandsWebModule = CommandsWebModule = CommandsWebModule_1 = __decorate([
|
|
36
|
+
(0, common_1.Module)({})
|
|
37
|
+
], CommandsWebModule);
|
|
38
|
+
//# sourceMappingURL=commands-web.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands-web.module.js","sourceRoot":"","sources":["../../src/nest/commands-web.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA4D;AAC5D,mEAIiC;AAEjC;;;;;GAKG;AAEI,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CAAC,OAAiC;QAC9C,OAAO;YACL,MAAM,EAAE,mBAAiB;YACzB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,4CAAoB;oBAC7B,QAAQ,EAAE,OAAO;iBAClB;gBACD,0CAAkB;aACnB;YACD,OAAO,EAAE,CAAC,0CAAkB,CAAC;SAC9B,CAAC;IACJ,CAAC;CACF,CAAA;AAdY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,iBAAiB,CAc7B"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { COMMANDS_WEB_OPTIONS, type CommandPrismaClient, type CommandsWebModuleOptions, CommandWebExecutor, type CommandWebRequest, denialToHttpException, } from './commands-web.executor';
|
|
2
|
+
export { CommandsWebModule } from './commands-web.module';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandsWebModule = exports.denialToHttpException = exports.CommandWebExecutor = exports.COMMANDS_WEB_OPTIONS = void 0;
|
|
4
|
+
var commands_web_executor_1 = require("./commands-web.executor");
|
|
5
|
+
Object.defineProperty(exports, "COMMANDS_WEB_OPTIONS", { enumerable: true, get: function () { return commands_web_executor_1.COMMANDS_WEB_OPTIONS; } });
|
|
6
|
+
Object.defineProperty(exports, "CommandWebExecutor", { enumerable: true, get: function () { return commands_web_executor_1.CommandWebExecutor; } });
|
|
7
|
+
Object.defineProperty(exports, "denialToHttpException", { enumerable: true, get: function () { return commands_web_executor_1.denialToHttpException; } });
|
|
8
|
+
var commands_web_module_1 = require("./commands-web.module");
|
|
9
|
+
Object.defineProperty(exports, "CommandsWebModule", { enumerable: true, get: function () { return commands_web_module_1.CommandsWebModule; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nest/index.ts"],"names":[],"mappings":";;;AAAA,iEAOiC;AAN/B,6HAAA,oBAAoB,OAAA;AAGpB,2HAAA,kBAAkB,OAAA;AAElB,8HAAA,qBAAqB,OAAA;AAEvB,6DAA0D;AAAjD,wHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
import type { CommandAccess, CommandDefinition, CommandSurface, DynamicCommandSource, ExternalToolGroupAdapter } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Machine-readable error codes thrown by {@link CommandRegistry} lifecycle and registration methods.
|
|
5
|
+
*/
|
|
6
|
+
export type CommandRegistryErrorCode = 'duplicate-command' | 'duplicate-group' | 'duplicate-source' | 'invalid-dynamic-command' | 'registry-sealed';
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown on command registry lifecycle or uniqueness violations.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CommandRegistryError extends Error {
|
|
11
|
+
readonly code: CommandRegistryErrorCode;
|
|
12
|
+
readonly command?: string | undefined;
|
|
13
|
+
constructor(code: CommandRegistryErrorCode, message: string, command?: string | undefined);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Summary entry returned by {@link CommandRegistry.listConfirmationExemptions} for test and
|
|
17
|
+
* audit-list verification (`1A` §6; `mcp-connector-contract.md` §9.1).
|
|
18
|
+
*/
|
|
19
|
+
export interface ConfirmationExemptionSummary {
|
|
20
|
+
name: string;
|
|
21
|
+
access: 'write';
|
|
22
|
+
surfaces: readonly [CommandSurface, ...CommandSurface[]];
|
|
23
|
+
exemptReason: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Summary entry returned by {@link CommandRegistry.listResourceAclCommands} for test and
|
|
27
|
+
* audit-list verification (`mcp-connector-contract.md` §9.1).
|
|
28
|
+
*/
|
|
29
|
+
export interface ResourceAclCommandSummary {
|
|
30
|
+
name: string;
|
|
31
|
+
access: CommandAccess;
|
|
32
|
+
surfaces: readonly [CommandSurface, ...CommandSurface[]];
|
|
33
|
+
resourceAclReason: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Diagnostic entry recorded when a {@link DynamicCommandSource} fails during
|
|
37
|
+
* {@link CommandRegistry.list} or {@link CommandRegistry.get} (`mcp-connector-contract.md` §9.3).
|
|
38
|
+
*/
|
|
39
|
+
export interface DynamicSourceError {
|
|
40
|
+
sourceId: string;
|
|
41
|
+
/** `refresh`: {@link DynamicCommandSource.refresh} threw; `commands`: its commands were rejected. */
|
|
42
|
+
phase: 'refresh' | 'commands';
|
|
43
|
+
message: string;
|
|
44
|
+
error: unknown;
|
|
45
|
+
}
|
|
46
|
+
/** Optional configuration for {@link createCommandRegistry}. */
|
|
47
|
+
export interface CreateCommandRegistryOptions {
|
|
48
|
+
/** Warning sink called once per failing dynamic source (`mcp-connector-contract.md` §9.3). */
|
|
49
|
+
warn?: (message: string) => void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Surface-aware command registry supporting static commands, external tool groups, dynamic
|
|
53
|
+
* sources, and startup sealing (`mcp-connector-contract.md` §3.1, §3.2, §9.3; 1A §4, §6).
|
|
54
|
+
*/
|
|
55
|
+
export interface CommandRegistry<TTx = unknown> {
|
|
56
|
+
register(definition: CommandDefinition<ZodType, ZodType | undefined, TTx>): this;
|
|
57
|
+
registerGroup(adapter: ExternalToolGroupAdapter<TTx>): this;
|
|
58
|
+
registerSource(source: DynamicCommandSource<TTx>): this;
|
|
59
|
+
seal(): void;
|
|
60
|
+
isSealed(): boolean;
|
|
61
|
+
list(surface: CommandSurface): readonly CommandDefinition<ZodType, ZodType | undefined, TTx>[];
|
|
62
|
+
get(name: string, surface?: CommandSurface): CommandDefinition<ZodType, ZodType | undefined, TTx> | undefined;
|
|
63
|
+
listConfirmationExemptions(): readonly ConfirmationExemptionSummary[];
|
|
64
|
+
listResourceAclCommands(): readonly ResourceAclCommandSummary[];
|
|
65
|
+
/**
|
|
66
|
+
* Lets every dynamic source recompute (each throttles itself) before a list or call
|
|
67
|
+
* (1A §4: dynamic tools resolve against the current source on every request). A failing
|
|
68
|
+
* source is recorded in {@link sourceErrors} and keeps serving its previous commands.
|
|
69
|
+
*/
|
|
70
|
+
refreshSources(): Promise<void>;
|
|
71
|
+
sourceErrors(): readonly DynamicSourceError[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new {@link CommandRegistry} instance.
|
|
75
|
+
*/
|
|
76
|
+
export declare function createCommandRegistry<TTx = unknown>(options?: CreateCommandRegistryOptions): CommandRegistry<TTx>;
|
|
77
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAChC,mBAAmB,GACnB,iBAAiB,GACjB,kBAAkB,GAClB,yBAAyB,GACzB,iBAAiB,CAAC;AAEtB;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAE3C,QAAQ,CAAC,IAAI,EAAE,wBAAwB;IAEvC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM;gBAFhB,IAAI,EAAE,wBAAwB,EACvC,OAAO,EAAE,MAAM,EACN,OAAO,CAAC,EAAE,MAAM,YAAA;CAK5B;AAED;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC,cAAc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