@lushly-dev/afd-server 1.0.0 → 2.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/README.md +297 -14
- package/dist/bootstrap/afd-context.d.ts +11 -2
- package/dist/bootstrap/afd-context.d.ts.map +1 -1
- package/dist/bootstrap/afd-context.js +56 -11
- package/dist/bootstrap/afd-context.js.map +1 -1
- package/dist/bootstrap/afd-docs.d.ts +6 -3
- package/dist/bootstrap/afd-docs.d.ts.map +1 -1
- package/dist/bootstrap/afd-docs.js +27 -9
- package/dist/bootstrap/afd-docs.js.map +1 -1
- package/dist/bootstrap/afd-help.d.ts +11 -3
- package/dist/bootstrap/afd-help.d.ts.map +1 -1
- package/dist/bootstrap/afd-help.js +15 -9
- package/dist/bootstrap/afd-help.js.map +1 -1
- package/dist/bootstrap/afd-schema.d.ts +8 -4
- package/dist/bootstrap/afd-schema.d.ts.map +1 -1
- package/dist/bootstrap/afd-schema.js +55 -42
- package/dist/bootstrap/afd-schema.js.map +1 -1
- package/dist/bootstrap/described-command.d.ts +35 -0
- package/dist/bootstrap/described-command.d.ts.map +1 -0
- package/dist/bootstrap/described-command.js +12 -0
- package/dist/bootstrap/described-command.js.map +1 -0
- package/dist/bootstrap/index.d.ts +1 -0
- package/dist/bootstrap/index.d.ts.map +1 -1
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/bootstrap/json-schema-to-ts.d.ts +27 -0
- package/dist/bootstrap/json-schema-to-ts.d.ts.map +1 -0
- package/dist/bootstrap/json-schema-to-ts.js +154 -0
- package/dist/bootstrap/json-schema-to-ts.js.map +1 -0
- package/dist/bootstrap/registry.d.ts +17 -6
- package/dist/bootstrap/registry.d.ts.map +1 -1
- package/dist/bootstrap/registry.js +29 -5
- package/dist/bootstrap/registry.js.map +1 -1
- package/dist/command-names.d.ts +19 -0
- package/dist/command-names.d.ts.map +1 -0
- package/dist/command-names.js +33 -0
- package/dist/command-names.js.map +1 -0
- package/dist/command-routing.d.ts +47 -0
- package/dist/command-routing.d.ts.map +1 -0
- package/dist/command-routing.js +75 -0
- package/dist/command-routing.js.map +1 -0
- package/dist/context-scope.d.ts +26 -0
- package/dist/context-scope.d.ts.map +1 -0
- package/dist/context-scope.js +31 -0
- package/dist/context-scope.js.map +1 -0
- package/dist/define.d.ts +42 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +41 -0
- package/dist/define.js.map +1 -0
- package/dist/direct-registry.d.ts +104 -0
- package/dist/direct-registry.d.ts.map +1 -0
- package/dist/direct-registry.js +103 -0
- package/dist/direct-registry.js.map +1 -0
- package/dist/execution.d.ts +9 -0
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +105 -321
- package/dist/execution.js.map +1 -1
- package/dist/http-handler.d.ts +24 -17
- package/dist/http-handler.d.ts.map +1 -1
- package/dist/http-handler.js +283 -252
- package/dist/http-handler.js.map +1 -1
- package/dist/http-security.d.ts +23 -0
- package/dist/http-security.d.ts.map +1 -0
- package/dist/http-security.js +101 -0
- package/dist/http-security.js.map +1 -0
- package/dist/http-sessions.d.ts +33 -0
- package/dist/http-sessions.d.ts.map +1 -0
- package/dist/http-sessions.js +65 -0
- package/dist/http-sessions.js.map +1 -0
- package/dist/http-sse.d.ts +30 -0
- package/dist/http-sse.d.ts.map +1 -0
- package/dist/http-sse.js +70 -0
- package/dist/http-sse.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/json-rpc.d.ts +56 -0
- package/dist/json-rpc.d.ts.map +1 -0
- package/dist/json-rpc.js +73 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/lazy-tools.d.ts +3 -12
- package/dist/lazy-tools.d.ts.map +1 -1
- package/dist/lazy-tools.js +10 -14
- package/dist/lazy-tools.js.map +1 -1
- package/dist/meta-tools.d.ts +116 -0
- package/dist/meta-tools.d.ts.map +1 -0
- package/dist/meta-tools.js +154 -0
- package/dist/meta-tools.js.map +1 -0
- package/dist/middleware.d.ts +34 -7
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +82 -40
- package/dist/middleware.js.map +1 -1
- package/dist/schema.d.ts +34 -6
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +22 -13
- package/dist/schema.js.map +1 -1
- package/dist/server-types.d.ts +90 -14
- package/dist/server-types.d.ts.map +1 -1
- package/dist/server-types.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +103 -21
- package/dist/server.js.map +1 -1
- package/dist/tool-router.d.ts +6 -5
- package/dist/tool-router.d.ts.map +1 -1
- package/dist/tool-router.js +105 -139
- package/dist/tool-router.js.map +1 -1
- package/dist/tools.d.ts +10 -420
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +82 -208
- package/dist/tools.js.map +1 -1
- package/package.json +13 -8
package/dist/tool-router.js
CHANGED
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Used by both stdio and HTTP transports to eliminate routing duplication.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { failedBatchRequest, failure, isBatchRequest, isPipelineRequest, truncateName, } from '@lushly-dev/afd-core';
|
|
8
|
+
import { commandAction, commandGroup, filterByContext, isAccessibleInContext, notFoundSuggestion, notInContextError, } from './command-routing.js';
|
|
9
|
+
import { resolveContextState } from './context-scope.js';
|
|
8
10
|
import { executeDetail, executeDiscover } from './lazy-tools.js';
|
|
11
|
+
import { batchArgsSchema, callArgsSchema, checkMetaArgs, detailArgsSchema, discoverArgsSchema, parseMetaArgs, pipeArgsSchema, } from './meta-tools.js';
|
|
9
12
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
10
13
|
// EMPTY PIPELINE RESULT (for invalid pipeline requests)
|
|
11
14
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
@@ -27,145 +30,132 @@ const emptyPipelineResult = {
|
|
|
27
30
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
28
31
|
// ROUTER
|
|
29
32
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
33
|
+
/**
|
|
34
|
+
* Wrap a result as MCP tool content. The JSON is compact: the text is read by an
|
|
35
|
+
* agent, and indentation only adds tokens.
|
|
36
|
+
*/
|
|
30
37
|
function resultContent(data, isError) {
|
|
31
38
|
return {
|
|
32
|
-
content: [{ type: 'text', text: JSON.stringify(data
|
|
39
|
+
content: [{ type: 'text', text: JSON.stringify(data) }],
|
|
33
40
|
isError,
|
|
34
41
|
};
|
|
35
42
|
}
|
|
36
43
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* - No active context (everything visible)
|
|
40
|
-
* - Command has no contexts array (universal / backward compat)
|
|
41
|
-
* - Command's contexts include the active context
|
|
44
|
+
* The `COMMAND_NOT_IN_CONTEXT` tool result when `cmd` exists but is outside the
|
|
45
|
+
* active context; undefined otherwise (a missing command is left to execution).
|
|
42
46
|
*/
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!cmd.contexts?.length)
|
|
49
|
-
return true;
|
|
50
|
-
return cmd.contexts.includes(activeContext);
|
|
47
|
+
function contextDenial(cmd, commandName, contextState) {
|
|
48
|
+
const activeContext = contextState?.getActive();
|
|
49
|
+
if (!cmd || !activeContext || isAccessibleInContext(cmd, activeContext))
|
|
50
|
+
return undefined;
|
|
51
|
+
return resultContent({ success: false, error: notInContextError(commandName, activeContext) }, true);
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Create a tool call router that dispatches to the appropriate execution function.
|
|
54
55
|
*/
|
|
55
56
|
export function createToolRouter(deps) {
|
|
56
|
-
const { executeCommand, executeBatch, executePipeline, commands, toolStrategy, groupByFn, devMode, allCommands, exposedCommandNames,
|
|
57
|
-
|
|
57
|
+
const { executeCommand, executeBatch, executePipeline, commands, toolStrategy, groupByFn, devMode, allCommands, exposedCommandNames, } = deps;
|
|
58
|
+
/**
|
|
59
|
+
* Route one tool call.
|
|
60
|
+
*
|
|
61
|
+
* @param callContext - Base `CommandContext` for commands this call runs (request values,
|
|
62
|
+
* `signal`, and the caller's context state); each execution adds its own `traceId`.
|
|
63
|
+
*/
|
|
64
|
+
return async function routeToolCall(toolName, args, callContext = {}) {
|
|
65
|
+
const contextState = resolveContextState(callContext, deps.contextState);
|
|
66
|
+
const traced = (prefix) => ({
|
|
67
|
+
...callContext,
|
|
68
|
+
traceId: `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
69
|
+
});
|
|
58
70
|
// Handle afd-call (available in all strategies)
|
|
59
71
|
if (toolName === 'afd-call') {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
success: false,
|
|
65
|
-
error: {
|
|
66
|
-
code: 'VALIDATION_ERROR',
|
|
67
|
-
message: 'Missing required field: command',
|
|
68
|
-
suggestion: 'Provide { command: "command-name", input: {...} }',
|
|
69
|
-
},
|
|
70
|
-
}, true);
|
|
71
|
-
}
|
|
72
|
+
const parsed = parseMetaArgs(toolName, callArgsSchema, args, 'Provide { command: "command-name", input: {...} }');
|
|
73
|
+
if (!parsed.success)
|
|
74
|
+
return resultContent(parsed.result, true);
|
|
75
|
+
const { command: commandName, input } = parsed.data;
|
|
72
76
|
// Check if command exists in the exposed commands
|
|
73
77
|
const cmd = commands.find((c) => c.name === commandName);
|
|
74
78
|
if (!cmd) {
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
success: false,
|
|
80
|
-
error: {
|
|
81
|
-
code: 'COMMAND_NOT_EXPOSED',
|
|
82
|
-
message: `Command '${commandName}' exists but is not exposed via this server`,
|
|
83
|
-
suggestion: "This command is registered but not included in the server's commands array.",
|
|
84
|
-
},
|
|
85
|
-
}, true);
|
|
86
|
-
}
|
|
87
|
-
// Not found at all — suggest similar
|
|
88
|
-
const allNames = commands.map((c) => c.name);
|
|
89
|
-
const suggestions = findSimilarTools(commandName, allNames, 3);
|
|
90
|
-
const suggestionText = suggestions.length > 0
|
|
91
|
-
? `Did you mean '${suggestions[0]}'? Use afd-discover to list all commands.`
|
|
92
|
-
: 'Use afd-discover to list all commands.';
|
|
79
|
+
// An unexposed command gets the same answer as an unknown one, so a remote
|
|
80
|
+
// caller cannot learn that a private command exists (spec/error-codes.md, D4).
|
|
81
|
+
// Suggest a few close matches the caller can use.
|
|
82
|
+
const callable = filterByContext(commands, contextState?.getActive());
|
|
93
83
|
return resultContent({
|
|
94
84
|
success: false,
|
|
95
85
|
error: {
|
|
96
86
|
code: 'COMMAND_NOT_FOUND',
|
|
97
|
-
message: `Command '${commandName}' not found`,
|
|
98
|
-
suggestion:
|
|
87
|
+
message: `Command '${truncateName(commandName)}' not found`,
|
|
88
|
+
suggestion: notFoundSuggestion(commandName, callable.map((c) => c.name)),
|
|
99
89
|
},
|
|
100
90
|
}, true);
|
|
101
91
|
}
|
|
102
92
|
// Context check: validate the command is accessible in current context
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return resultContent({
|
|
107
|
-
success: false,
|
|
108
|
-
error: {
|
|
109
|
-
code: 'COMMAND_NOT_IN_CONTEXT',
|
|
110
|
-
message: `Command '${commandName}' is not available in context '${activeContext}'`,
|
|
111
|
-
suggestion: 'Use afd-context-list to see available contexts, or afd-context-enter to switch.',
|
|
112
|
-
},
|
|
113
|
-
}, true);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
93
|
+
const denied = contextDenial(cmd, commandName, contextState);
|
|
94
|
+
if (denied)
|
|
95
|
+
return denied;
|
|
116
96
|
// Execute through the execution engine (full middleware chain)
|
|
117
|
-
const result = await executeCommand(commandName,
|
|
118
|
-
traceId: `afd-call-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
119
|
-
});
|
|
97
|
+
const result = await executeCommand(commandName, input ?? {}, traced('afd-call'));
|
|
120
98
|
return resultContent(result, !result.success);
|
|
121
99
|
}
|
|
122
|
-
// Handle afd-discover (lazy strategy
|
|
100
|
+
// Handle afd-discover (listed by the lazy strategy, routable in all)
|
|
123
101
|
if (toolName === 'afd-discover') {
|
|
102
|
+
const parsed = parseMetaArgs(toolName, discoverArgsSchema, args, 'Provide optional { category, tag, tagMode, search, includeMutation, limit, offset }');
|
|
103
|
+
if (!parsed.success)
|
|
104
|
+
return resultContent(parsed.result, true);
|
|
124
105
|
// Filter by active context when context state is available
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
? commands.filter((cmd) => !cmd.contexts?.length || cmd.contexts.includes(activeContext))
|
|
128
|
-
: commands;
|
|
129
|
-
const result = executeDiscover(discoverCommands, (args ?? {}));
|
|
106
|
+
const discoverCommands = filterByContext(commands, contextState?.getActive());
|
|
107
|
+
const result = executeDiscover(discoverCommands, parsed.data);
|
|
130
108
|
return resultContent(result, false);
|
|
131
109
|
}
|
|
132
|
-
// Handle afd-detail (lazy
|
|
110
|
+
// Handle afd-detail (listed by the lazy and grouped strategies, routable in all)
|
|
133
111
|
if (toolName === 'afd-detail') {
|
|
112
|
+
const parsed = parseMetaArgs(toolName, detailArgsSchema, args, 'Provide { command: "command-name" } or { command: ["name-1", "name-2"] } (max 10)');
|
|
113
|
+
if (!parsed.success)
|
|
114
|
+
return resultContent(parsed.result, true);
|
|
134
115
|
const exposedNames = exposedCommandNames ?? new Set(commands.map((c) => c.name));
|
|
135
|
-
const allCmds = allCommands ?? commands;
|
|
136
116
|
// Filter by active context so agents cannot inspect commands outside their context
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
? allCmds.filter((cmd) => !cmd.contexts?.length || cmd.contexts.includes(activeContext))
|
|
140
|
-
: allCmds;
|
|
141
|
-
const result = executeDetail(contextFilteredCmds, exposedNames, (args ?? {}));
|
|
117
|
+
const contextFilteredCmds = filterByContext(allCommands ?? commands, contextState?.getActive());
|
|
118
|
+
const result = executeDetail(contextFilteredCmds, exposedNames, parsed.data);
|
|
142
119
|
return resultContent(result, false);
|
|
143
120
|
}
|
|
144
121
|
// Handle built-in afd-batch tool
|
|
145
122
|
if (toolName === 'afd-batch') {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
suggestion: 'Provide { commands: [...] } with command objects',
|
|
153
|
-
},
|
|
154
|
-
}, true);
|
|
123
|
+
// The Zod schema pinpoints shape errors; isBatchRequest is the envelope check
|
|
124
|
+
// shared with POST /batch. Both report INVALID_BATCH_REQUEST.
|
|
125
|
+
const check = checkMetaArgs(batchArgsSchema, args);
|
|
126
|
+
if (!check.success || !isBatchRequest(args)) {
|
|
127
|
+
const usage = 'Provide { commands: [...] } with command objects';
|
|
128
|
+
return resultContent(failedBatchRequest({}, check.success ? undefined : { errors: check.errors }, check.success ? usage : `${check.suggestion}. ${usage}`), true);
|
|
155
129
|
}
|
|
156
|
-
const result = await executeBatch(args,
|
|
157
|
-
traceId: `batch-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
158
|
-
});
|
|
130
|
+
const result = await executeBatch(args, traced('batch'));
|
|
159
131
|
return resultContent(result, !result.success);
|
|
160
132
|
}
|
|
161
133
|
// Handle built-in afd-pipe tool
|
|
162
134
|
if (toolName === 'afd-pipe') {
|
|
163
|
-
|
|
164
|
-
|
|
135
|
+
// As for afd-batch: Zod pinpoints shape errors, and isPipelineRequest checks the
|
|
136
|
+
// whole envelope (including `when` conditions). Both report INVALID_PIPELINE_REQUEST.
|
|
137
|
+
const check = checkMetaArgs(pipeArgsSchema, args);
|
|
138
|
+
if (!check.success || !isPipelineRequest(args)) {
|
|
139
|
+
const usage = 'Provide steps with nonempty command names, object inputs, valid conditions, and correctly typed options; input must be JSON';
|
|
140
|
+
return resultContent({
|
|
141
|
+
...emptyPipelineResult,
|
|
142
|
+
steps: [
|
|
143
|
+
{
|
|
144
|
+
index: -1,
|
|
145
|
+
command: '',
|
|
146
|
+
status: 'failure',
|
|
147
|
+
executionTimeMs: 0,
|
|
148
|
+
error: {
|
|
149
|
+
code: 'INVALID_PIPELINE_REQUEST',
|
|
150
|
+
message: 'Invalid pipeline request envelope',
|
|
151
|
+
suggestion: check.success ? usage : `${check.suggestion}. ${usage}`,
|
|
152
|
+
...(!check.success && { details: { errors: check.errors } }),
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
}, true);
|
|
165
157
|
}
|
|
166
|
-
const result = await executePipeline(args,
|
|
167
|
-
traceId: `pipeline-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
168
|
-
});
|
|
158
|
+
const result = await executePipeline(args, traced('pipeline'));
|
|
169
159
|
const hasFailed = result.steps.some((s) => s.status === 'failure');
|
|
170
160
|
return resultContent(result, hasFailed);
|
|
171
161
|
}
|
|
@@ -178,38 +168,27 @@ export function createToolRouter(deps) {
|
|
|
178
168
|
console.error(`[MCP Debug] Grouped tool call: toolName=${toolName}, action=${action}, args=${JSON.stringify(args)}`);
|
|
179
169
|
}
|
|
180
170
|
if (action && typeof action === 'string') {
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
success: false,
|
|
189
|
-
error: {
|
|
190
|
-
code: 'COMMAND_NOT_IN_CONTEXT',
|
|
191
|
-
message: `Command '${actualCommandName}' is not available in context '${activeContext}'`,
|
|
192
|
-
suggestion: 'Use afd-context-list to see available contexts, or afd-context-enter to switch.',
|
|
193
|
-
},
|
|
194
|
-
}, true);
|
|
195
|
-
}
|
|
171
|
+
const candidates = commands.filter((command) => commandGroup(command, groupByFn) === toolName && commandAction(command) === action);
|
|
172
|
+
if (candidates.length !== 1) {
|
|
173
|
+
return resultContent(failure({
|
|
174
|
+
code: candidates.length ? 'AMBIGUOUS_ACTION' : 'COMMAND_NOT_FOUND',
|
|
175
|
+
message: `Action '${truncateName(action)}' does not identify one command in group '${truncateName(toolName)}'`,
|
|
176
|
+
suggestion: 'Use afd-call with the full command name, or list tools to find a valid action.',
|
|
177
|
+
}), true);
|
|
196
178
|
}
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
179
|
+
const actualCommandName = candidates[0]?.name;
|
|
180
|
+
// Context check for grouped strategy
|
|
181
|
+
const denied = contextDenial(candidates[0], actualCommandName, contextState);
|
|
182
|
+
if (denied)
|
|
183
|
+
return denied;
|
|
184
|
+
const result = await executeCommand(actualCommandName, commandParams, traced('trace'));
|
|
200
185
|
return resultContent(result, !result.success);
|
|
201
186
|
}
|
|
202
187
|
// In grouped mode, if tool is a known group but action is missing/invalid,
|
|
203
188
|
// return a helpful error instead of falling through
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (groupNames.has(toolName)) {
|
|
208
|
-
const groupCommands = commands.filter((cmd) => getGroup(cmd) === toolName);
|
|
209
|
-
const availableActions = groupCommands.map((cmd) => {
|
|
210
|
-
const parts = cmd.name.split('-');
|
|
211
|
-
return parts.length > 1 ? parts.slice(1).join('-') : cmd.name;
|
|
212
|
-
});
|
|
189
|
+
const groupCommands = commands.filter((cmd) => commandGroup(cmd, groupByFn) === toolName);
|
|
190
|
+
if (groupCommands.length > 0) {
|
|
191
|
+
const availableActions = groupCommands.map(commandAction);
|
|
213
192
|
return resultContent({
|
|
214
193
|
success: false,
|
|
215
194
|
error: {
|
|
@@ -223,23 +202,10 @@ export function createToolRouter(deps) {
|
|
|
223
202
|
}
|
|
224
203
|
// Handle user-defined commands (individual mode or direct command calls)
|
|
225
204
|
// Context check: validate the command is accessible in current context
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return resultContent({
|
|
231
|
-
success: false,
|
|
232
|
-
error: {
|
|
233
|
-
code: 'COMMAND_NOT_IN_CONTEXT',
|
|
234
|
-
message: `Command '${toolName}' is not available in context '${activeContext}'`,
|
|
235
|
-
suggestion: 'Use afd-context-list to see available contexts, or afd-context-enter to switch.',
|
|
236
|
-
},
|
|
237
|
-
}, true);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
const result = await executeCommand(toolName, args ?? {}, {
|
|
241
|
-
traceId: `trace-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
242
|
-
});
|
|
205
|
+
const denied = contextDenial(commands.find((c) => c.name === toolName), toolName, contextState);
|
|
206
|
+
if (denied)
|
|
207
|
+
return denied;
|
|
208
|
+
const result = await executeCommand(toolName, args ?? {}, traced('trace'));
|
|
243
209
|
return resultContent(result, !result.success);
|
|
244
210
|
};
|
|
245
211
|
}
|
package/dist/tool-router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-router.js","sourceRoot":"","sources":["../src/tool-router.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,
|
|
1
|
+
{"version":3,"file":"tool-router.js","sourceRoot":"","sources":["../src/tool-router.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,EACN,kBAAkB,EAClB,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,aAAa,EACb,YAAY,EACZ,eAAe,EAEf,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EACN,eAAe,EACf,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,cAAc,GACd,MAAM,iBAAiB,CAAC;AAgCzB,kFAAkF;AAClF,wDAAwD;AACxD,kFAAkF;AAElF,MAAM,mBAAmB,GAAG;IAC3B,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE;QACT,UAAU,EAAE,CAAC;QACb,mBAAmB,EAAE,EAAE;QAC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