@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
package/dist/registry.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandRegistryError = void 0;
|
|
4
|
+
exports.createCommandRegistry = createCommandRegistry;
|
|
5
|
+
const define_command_1 = require("./define-command");
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown on command registry lifecycle or uniqueness violations.
|
|
8
|
+
*/
|
|
9
|
+
class CommandRegistryError extends Error {
|
|
10
|
+
constructor(code, message, command) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.command = command;
|
|
14
|
+
this.name = 'CommandRegistryError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.CommandRegistryError = CommandRegistryError;
|
|
18
|
+
function compareByName(a, b) {
|
|
19
|
+
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new {@link CommandRegistry} instance.
|
|
23
|
+
*/
|
|
24
|
+
function createCommandRegistry(options) {
|
|
25
|
+
const staticCommands = new Map();
|
|
26
|
+
const groupIds = new Set();
|
|
27
|
+
const sourceIds = new Set();
|
|
28
|
+
const dynamicSources = [];
|
|
29
|
+
const warnedSourceIds = new Set();
|
|
30
|
+
const latestSourceErrors = new Map();
|
|
31
|
+
const refreshErrors = new Map();
|
|
32
|
+
const warnedRefreshIds = new Set();
|
|
33
|
+
const warn = options?.warn ?? ((message) => console.warn(message));
|
|
34
|
+
let sealed = false;
|
|
35
|
+
function assertNotSealed() {
|
|
36
|
+
if (sealed) {
|
|
37
|
+
throw new CommandRegistryError('registry-sealed', 'Cannot register commands, groups, or sources after the registry has been sealed.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function resolveAllCommands() {
|
|
41
|
+
const resolved = new Map(staticCommands);
|
|
42
|
+
for (const source of dynamicSources) {
|
|
43
|
+
try {
|
|
44
|
+
const staged = [];
|
|
45
|
+
const seenInSource = new Set();
|
|
46
|
+
for (const cmd of source.commands()) {
|
|
47
|
+
(0, define_command_1.validateCommandDefinition)(cmd);
|
|
48
|
+
// Dynamic sources may only produce employee reads (mcp-connector-contract.md §9.3);
|
|
49
|
+
// isolating a failing source is safe only because it can never hold a write.
|
|
50
|
+
if (cmd.access !== 'read' || cmd.surfaces.includes('mcp-admin')) {
|
|
51
|
+
throw new CommandRegistryError('invalid-dynamic-command', `Dynamic source "${source.sourceId}" produced "${cmd.name}", which is not an employee read.`, cmd.name);
|
|
52
|
+
}
|
|
53
|
+
if (resolved.has(cmd.name) || seenInSource.has(cmd.name)) {
|
|
54
|
+
throw new CommandRegistryError('duplicate-command', `Dynamic source "${source.sourceId}" produced duplicate command "${cmd.name}".`, cmd.name);
|
|
55
|
+
}
|
|
56
|
+
seenInSource.add(cmd.name);
|
|
57
|
+
staged.push((0, define_command_1.freezeCommandDefinition)(cmd));
|
|
58
|
+
}
|
|
59
|
+
for (const cmd of staged) {
|
|
60
|
+
resolved.set(cmd.name, cmd);
|
|
61
|
+
}
|
|
62
|
+
latestSourceErrors.delete(source.sourceId);
|
|
63
|
+
warnedSourceIds.delete(source.sourceId);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
latestSourceErrors.set(source.sourceId, {
|
|
68
|
+
sourceId: source.sourceId,
|
|
69
|
+
phase: 'commands',
|
|
70
|
+
message,
|
|
71
|
+
error,
|
|
72
|
+
});
|
|
73
|
+
if (!warnedSourceIds.has(source.sourceId)) {
|
|
74
|
+
warnedSourceIds.add(source.sourceId);
|
|
75
|
+
warn(`Dynamic command source "${source.sourceId}" failed and was skipped: ${message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return resolved;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
register(definition) {
|
|
83
|
+
assertNotSealed();
|
|
84
|
+
(0, define_command_1.validateCommandDefinition)(definition);
|
|
85
|
+
if (staticCommands.has(definition.name)) {
|
|
86
|
+
throw new CommandRegistryError('duplicate-command', `Command "${definition.name}" is already registered.`, definition.name);
|
|
87
|
+
}
|
|
88
|
+
staticCommands.set(definition.name, (0, define_command_1.freezeCommandDefinition)(definition));
|
|
89
|
+
return this;
|
|
90
|
+
},
|
|
91
|
+
registerGroup(adapter) {
|
|
92
|
+
assertNotSealed();
|
|
93
|
+
if (groupIds.has(adapter.groupId)) {
|
|
94
|
+
throw new CommandRegistryError('duplicate-group', `External tool group "${adapter.groupId}" is already registered.`);
|
|
95
|
+
}
|
|
96
|
+
const incoming = adapter.listCommands();
|
|
97
|
+
const staged = new Map();
|
|
98
|
+
for (const cmd of incoming) {
|
|
99
|
+
(0, define_command_1.validateCommandDefinition)(cmd);
|
|
100
|
+
if (staticCommands.has(cmd.name) || staged.has(cmd.name)) {
|
|
101
|
+
throw new CommandRegistryError('duplicate-command', `Command "${cmd.name}" from group "${adapter.groupId}" duplicates an existing command.`, cmd.name);
|
|
102
|
+
}
|
|
103
|
+
staged.set(cmd.name, (0, define_command_1.freezeCommandDefinition)(cmd));
|
|
104
|
+
}
|
|
105
|
+
groupIds.add(adapter.groupId);
|
|
106
|
+
for (const [name, cmd] of staged) {
|
|
107
|
+
staticCommands.set(name, cmd);
|
|
108
|
+
}
|
|
109
|
+
return this;
|
|
110
|
+
},
|
|
111
|
+
registerSource(source) {
|
|
112
|
+
assertNotSealed();
|
|
113
|
+
if (sourceIds.has(source.sourceId)) {
|
|
114
|
+
throw new CommandRegistryError('duplicate-source', `Dynamic command source "${source.sourceId}" is already registered.`);
|
|
115
|
+
}
|
|
116
|
+
sourceIds.add(source.sourceId);
|
|
117
|
+
dynamicSources.push(source);
|
|
118
|
+
return this;
|
|
119
|
+
},
|
|
120
|
+
seal() {
|
|
121
|
+
sealed = true;
|
|
122
|
+
},
|
|
123
|
+
isSealed() {
|
|
124
|
+
return sealed;
|
|
125
|
+
},
|
|
126
|
+
list(surface) {
|
|
127
|
+
const result = [];
|
|
128
|
+
for (const cmd of resolveAllCommands().values()) {
|
|
129
|
+
if (cmd.surfaces.includes(surface)) {
|
|
130
|
+
result.push(cmd);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
result.sort(compareByName);
|
|
134
|
+
return result;
|
|
135
|
+
},
|
|
136
|
+
get(name, surface) {
|
|
137
|
+
const cmd = resolveAllCommands().get(name);
|
|
138
|
+
if (!cmd)
|
|
139
|
+
return undefined;
|
|
140
|
+
if (surface !== undefined && !cmd.surfaces.includes(surface)) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
return cmd;
|
|
144
|
+
},
|
|
145
|
+
listConfirmationExemptions() {
|
|
146
|
+
const exemptions = [];
|
|
147
|
+
for (const cmd of resolveAllCommands().values()) {
|
|
148
|
+
if (cmd.access === 'write' && cmd.confirmation === 'exempt') {
|
|
149
|
+
exemptions.push({
|
|
150
|
+
name: cmd.name,
|
|
151
|
+
access: cmd.access,
|
|
152
|
+
surfaces: cmd.surfaces,
|
|
153
|
+
exemptReason: cmd.exemptReason,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exemptions.sort(compareByName);
|
|
158
|
+
return exemptions;
|
|
159
|
+
},
|
|
160
|
+
listResourceAclCommands() {
|
|
161
|
+
const result = [];
|
|
162
|
+
for (const cmd of resolveAllCommands().values()) {
|
|
163
|
+
if (cmd.permissions.length === 0 && cmd.resourceAclReason !== undefined) {
|
|
164
|
+
result.push({
|
|
165
|
+
name: cmd.name,
|
|
166
|
+
access: cmd.access,
|
|
167
|
+
surfaces: cmd.surfaces,
|
|
168
|
+
resourceAclReason: cmd.resourceAclReason,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
result.sort(compareByName);
|
|
173
|
+
return result;
|
|
174
|
+
},
|
|
175
|
+
async refreshSources() {
|
|
176
|
+
await Promise.all(dynamicSources.map(async (source) => {
|
|
177
|
+
try {
|
|
178
|
+
await source.refresh();
|
|
179
|
+
refreshErrors.delete(source.sourceId);
|
|
180
|
+
warnedRefreshIds.delete(source.sourceId);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
184
|
+
refreshErrors.set(source.sourceId, {
|
|
185
|
+
sourceId: source.sourceId,
|
|
186
|
+
phase: 'refresh',
|
|
187
|
+
message,
|
|
188
|
+
error,
|
|
189
|
+
});
|
|
190
|
+
if (!warnedRefreshIds.has(source.sourceId)) {
|
|
191
|
+
warnedRefreshIds.add(source.sourceId);
|
|
192
|
+
warn(`Dynamic command source "${source.sourceId}" failed to refresh: ${message}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}));
|
|
196
|
+
},
|
|
197
|
+
sourceErrors() {
|
|
198
|
+
return [...refreshErrors.values(), ...latestSourceErrors.values()];
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";;;AA2GA,sDA0NC;AApUD,qDAAsF;AAmBtF;;GAEG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YACW,IAA8B,EACvC,OAAe,EACN,OAAgB;QAEzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAA0B;QAE9B,YAAO,GAAP,OAAO,CAAS;QAGzB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AATD,oDASC;AAoED,SAAS,aAAa,CAAC,CAAmB,EAAE,CAAmB;IAC7D,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CACnC,OAAsC;IAEtC,MAAM,cAAc,GAAG,IAAI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AE,EAAE,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
/** Side-effect classification of a command (`mcp-connector-contract.md` §3.1; 1A §4). */
|
|
3
|
+
export type CommandAccess = 'read' | 'write';
|
|
4
|
+
/** RBAC multi-permission matching mode (`mcp-connector-contract.md` §3.1; 1A §4). */
|
|
5
|
+
export type CommandMatch = 'any' | 'all';
|
|
6
|
+
/** Entry surface where a command is exposed (`mcp-connector-contract.md` §3.1; 1A §4). */
|
|
7
|
+
export type CommandSurface = 'web' | 'mcp' | 'mcp-admin';
|
|
8
|
+
/** App admission requirement for a command (`mcp-connector-contract.md` §3.1; 1A §4 "App 准入"). */
|
|
9
|
+
export type CommandAdmissionPolicy = 'required' | 'exempt' | 'independent';
|
|
10
|
+
/** Write confirmation requirement (`mcp-connector-contract.md` §3.1; 1A §4, §6). */
|
|
11
|
+
export type CommandConfirmation = 'required' | 'exempt';
|
|
12
|
+
/** Authenticated principal kind (`mcp-connector-contract.md` §3.1; 1A §4). */
|
|
13
|
+
export type CommandPrincipalKind = 'web-session' | 'm2m-api-key' | 'oauth-employee' | 'oauth-admin';
|
|
14
|
+
/**
|
|
15
|
+
* Normalized caller context passed to command handlers and authorizers
|
|
16
|
+
* (`mcp-connector-contract.md` §3.1).
|
|
17
|
+
*/
|
|
18
|
+
export interface CommandActor {
|
|
19
|
+
surface: CommandSurface;
|
|
20
|
+
/** 供授權器第 1 步直接判斷 principal 與 surface 是否相符。 */
|
|
21
|
+
principalKind: CommandPrincipalKind;
|
|
22
|
+
/** OAuth / Web OIDC 為 issuer URL;M2M API key 無 OIDC issuer 時為 null。 */
|
|
23
|
+
issuer: string | null;
|
|
24
|
+
/** OAuth / Web OIDC 為 sub;M2M API key 時為 null。 */
|
|
25
|
+
subject: string | null;
|
|
26
|
+
/** 本地使用者 ID(M2M 沿用 web 路徑時為綁定的 actingUserId;無綁定時為 null)。 */
|
|
27
|
+
actingUserId: string | null;
|
|
28
|
+
isServiceAccount: boolean;
|
|
29
|
+
/** 本機帳號是否啟用。 */
|
|
30
|
+
isActive: boolean;
|
|
31
|
+
/** OAuth token 的 scope(Web 互動登入不檢查 scope)。 */
|
|
32
|
+
scopes: readonly string[];
|
|
33
|
+
/** 若為 mcp-admin,已通過第 3 節管理檢查。 */
|
|
34
|
+
mfaVerified?: boolean;
|
|
35
|
+
authTime?: number | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Shared command declaration for Web and MCP (`mcp-connector-contract.md` §3.1, §9.1; 1A §4).
|
|
39
|
+
*
|
|
40
|
+
* Uses discriminated unions on `access`/`confirmation` and `permissions`/`resourceAclReason`
|
|
41
|
+
* so `exemptReason`, `resourceAclReason`, and read-only constraints are enforced at compile time.
|
|
42
|
+
*/
|
|
43
|
+
type CommandBase<TInputSchema extends ZodType = ZodType, TOutputSchema extends ZodType | undefined = ZodType | undefined, TTx = unknown> = {
|
|
44
|
+
name: string;
|
|
45
|
+
/** MCP tool description; required and non-empty when `surfaces` includes `'mcp'` or `'mcp-admin'`. */
|
|
46
|
+
description?: string;
|
|
47
|
+
/**
|
|
48
|
+
* 1A 第 6 節確認收據綁定之 schema 版本(正整數,由所屬 App 或套件維護)。
|
|
49
|
+
* 當 inputSchema 欄位語意、必填性、預設值或摘要解讀方式變更時必須遞增,
|
|
50
|
+
* 避免未提交之 pending 收據或 requestState 套用到新 schema。
|
|
51
|
+
*/
|
|
52
|
+
schemaVersion: number;
|
|
53
|
+
inputSchema: TInputSchema;
|
|
54
|
+
outputSchema?: TOutputSchema;
|
|
55
|
+
match: CommandMatch;
|
|
56
|
+
scope: string;
|
|
57
|
+
/** 1A 第 4 節「App 准入」:預設為 'required'。 */
|
|
58
|
+
admissionPolicy?: CommandAdmissionPolicy;
|
|
59
|
+
/** 至少包含一個 surface;不可為空陣列。 */
|
|
60
|
+
surfaces: readonly [CommandSurface, ...CommandSurface[]];
|
|
61
|
+
handler(actor: CommandActor, input: TInputSchema['_output'], tx: TTx): Promise<TOutputSchema extends ZodType ? TOutputSchema['_output'] : unknown>;
|
|
62
|
+
} & ({
|
|
63
|
+
permissions: readonly [string, ...string[]];
|
|
64
|
+
resourceAclReason?: never;
|
|
65
|
+
} | {
|
|
66
|
+
/** Empty only when authorization relies solely on resource-level ACL in the handler. */
|
|
67
|
+
permissions: readonly [];
|
|
68
|
+
resourceAclReason: string;
|
|
69
|
+
});
|
|
70
|
+
export type CommandDefinition<TInputSchema extends ZodType = ZodType, TOutputSchema extends ZodType | undefined = ZodType | undefined, TTx = unknown> = CommandBase<TInputSchema, TOutputSchema, TTx> & ({
|
|
71
|
+
access: 'read';
|
|
72
|
+
confirmation?: never;
|
|
73
|
+
exemptReason?: never;
|
|
74
|
+
} | {
|
|
75
|
+
access: 'write';
|
|
76
|
+
/** 1A 第 4 節:'required' | 'exempt';宣告 'exempt' 時 exemptReason 必填且不可為空。 */
|
|
77
|
+
confirmation: 'required';
|
|
78
|
+
exemptReason?: never;
|
|
79
|
+
} | {
|
|
80
|
+
access: 'write';
|
|
81
|
+
/** 1A 第 4 節:'required' | 'exempt';宣告 'exempt' 時 exemptReason 必填且不可為空。 */
|
|
82
|
+
confirmation: 'exempt';
|
|
83
|
+
/**
|
|
84
|
+
* 1A 第 6 節:僅在同時符合「可完整還原」與「只寫入呼叫者自己的資料」時可宣告 exempt;
|
|
85
|
+
* confirmation === 'exempt' 時必填,供測試與審查清單列管(W4-03)。
|
|
86
|
+
*/
|
|
87
|
+
exemptReason: string;
|
|
88
|
+
});
|
|
89
|
+
/** 動態工具來源:繼承底層讀取能力宣告,每次依目前來源解析並套用可見性(`mcp-connector-contract.md` §3.2; 1A §4)。 */
|
|
90
|
+
export interface DynamicCommandSource<TTx = unknown> {
|
|
91
|
+
readonly sourceId: string;
|
|
92
|
+
refresh(): Promise<void>;
|
|
93
|
+
commands(): readonly CommandDefinition<ZodType, ZodType | undefined, TTx>[];
|
|
94
|
+
}
|
|
95
|
+
/** 套件提供之工具組 adapter(如 report-engine、definition-registry)(`mcp-connector-contract.md` §3.2; 1A §4)。 */
|
|
96
|
+
export interface ExternalToolGroupAdapter<TTx = unknown> {
|
|
97
|
+
readonly groupId: string;
|
|
98
|
+
listCommands(): readonly CommandDefinition<ZodType, ZodType | undefined, TTx>[];
|
|
99
|
+
}
|
|
100
|
+
export type { ScopeCatalogEntry } from '@haneinfo/plugin-api';
|
|
101
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,yFAAyF;AACzF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,CAAC;AAE7C,qFAAqF;AACrF,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,CAAC;AAEzC,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,KAAK,GAAG,WAAW,CAAC;AAEzD,kGAAkG;AAClG,MAAM,MAAM,sBAAsB,GAAG,UAAU,GAAG,QAAQ,GAAG,aAAa,CAAC;AAE3E,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,QAAQ,CAAC;AAExD,8EAA8E;AAC9E,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG,aAAa,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAEpG;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,8CAA8C;IAC9C,aAAa,EAAE,oBAAoB,CAAC;IACpC,uEAAuE;IACvE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,kDAAkD;IAClD,OAAO,EAAE,MAAM,GAAG,IAAI,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
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haneinfo/commands",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Shared command declarations, validation, and surface-aware registry for Web and MCP.",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"agent-guide.md",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"type": "commonjs",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./nest": {
|
|
20
|
+
"types": "./dist/nest/index.d.ts",
|
|
21
|
+
"default": "./dist/nest/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./agent-guide.md": "./agent-guide.md",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@haneinfo/plugin-api": "1.29.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@haneinfo/plugin-api": "^1.29.0",
|
|
31
|
+
"@haneinfo/plugin-host-nest": "^2.0.0",
|
|
32
|
+
"@nestjs/common": "^11.0.0 || ^12.0.0",
|
|
33
|
+
"zod": "^4.4.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@haneinfo/plugin-host-nest": {
|
|
37
|
+
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"@nestjs/common": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@nestjs/common": "^12.3.2",
|
|
45
|
+
"@nestjs/core": "^12.3.2",
|
|
46
|
+
"@nestjs/testing": "^12.3.2",
|
|
47
|
+
"@types/node": "^24.13.0",
|
|
48
|
+
"@types/pg": "8.23.1",
|
|
49
|
+
"pg": "8.23.1",
|
|
50
|
+
"reflect-metadata": "^0.2.2",
|
|
51
|
+
"rxjs": "^7.8.2",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"vitest": "^4.1.11",
|
|
54
|
+
"zod": "^4.4.0",
|
|
55
|
+
"@haneinfo/plugin-host-nest": "2.2.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=22.0.0"
|
|
59
|
+
},
|
|
60
|
+
"license": "UNLICENSED",
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"registry": "https://registry.npmjs.org/",
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc -p tsconfig.build.json",
|
|
67
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
68
|
+
"test": "vitest run --exclude '**/*.pg.spec.ts'",
|
|
69
|
+
"test:pg": "vitest run src/authorizer.pg.spec.ts",
|
|
70
|
+
"typecheck": "tsc --noEmit"
|
|
71
|
+
}
|
|
6
72
|
}
|