@lushly-dev/afd-server 2.2.1 → 2.4.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 +468 -6
- package/dist/approval-crypto.d.ts +26 -4
- package/dist/approval-crypto.d.ts.map +1 -1
- package/dist/approval-crypto.js +90 -7
- package/dist/approval-crypto.js.map +1 -1
- package/dist/approval-relay.d.ts +5 -5
- package/dist/approval-relay.d.ts.map +1 -1
- package/dist/approval.d.ts +6 -1
- package/dist/approval.d.ts.map +1 -1
- package/dist/approval.js +43 -32
- package/dist/approval.js.map +1 -1
- package/dist/bootstrap/afd-context.d.ts +2 -27
- package/dist/bootstrap/afd-context.d.ts.map +1 -1
- package/dist/bootstrap/afd-context.js +6 -36
- package/dist/bootstrap/afd-context.js.map +1 -1
- package/dist/bootstrap/afd-help.d.ts +24 -2
- package/dist/bootstrap/afd-help.d.ts.map +1 -1
- package/dist/bootstrap/afd-help.js +17 -2
- package/dist/bootstrap/afd-help.js.map +1 -1
- package/dist/bootstrap/described-command.d.ts +1 -0
- package/dist/bootstrap/described-command.d.ts.map +1 -1
- package/dist/bootstrap/described-command.js.map +1 -1
- package/dist/bootstrap/registry.d.ts +13 -0
- package/dist/bootstrap/registry.d.ts.map +1 -1
- package/dist/bootstrap/registry.js +30 -1
- package/dist/bootstrap/registry.js.map +1 -1
- package/dist/command-allow.d.ts +31 -0
- package/dist/command-allow.d.ts.map +1 -0
- package/dist/command-allow.js +55 -0
- package/dist/command-allow.js.map +1 -0
- package/dist/command-names.d.ts +17 -0
- package/dist/command-names.d.ts.map +1 -1
- package/dist/command-names.js +55 -0
- package/dist/command-names.js.map +1 -1
- package/dist/command-routing.d.ts +10 -3
- package/dist/command-routing.d.ts.map +1 -1
- package/dist/command-routing.js +18 -7
- package/dist/command-routing.js.map +1 -1
- package/dist/confirmation-gate.d.ts +32 -0
- package/dist/confirmation-gate.d.ts.map +1 -0
- package/dist/confirmation-gate.js +140 -0
- package/dist/confirmation-gate.js.map +1 -0
- package/dist/confirmations.d.ts +15 -23
- package/dist/confirmations.d.ts.map +1 -1
- package/dist/confirmations.js +8 -127
- package/dist/confirmations.js.map +1 -1
- package/dist/context-fields-describe.d.ts +18 -0
- package/dist/context-fields-describe.d.ts.map +1 -0
- package/dist/context-fields-describe.js +17 -0
- package/dist/context-fields-describe.js.map +1 -0
- package/dist/context-fields.d.ts +50 -0
- package/dist/context-fields.d.ts.map +1 -0
- package/dist/context-fields.js +146 -0
- package/dist/context-fields.js.map +1 -0
- package/dist/context-scope.d.ts +29 -2
- package/dist/context-scope.d.ts.map +1 -1
- package/dist/context-scope.js +37 -1
- package/dist/context-scope.js.map +1 -1
- package/dist/credentials.d.ts +17 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +16 -0
- package/dist/credentials.js.map +1 -0
- package/dist/define-core.d.ts +213 -0
- package/dist/define-core.d.ts.map +1 -0
- package/dist/define-core.js +161 -0
- package/dist/define-core.js.map +1 -0
- package/dist/define.d.ts +13 -8
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +13 -8
- package/dist/define.js.map +1 -1
- package/dist/direct-registry.d.ts +154 -7
- package/dist/direct-registry.d.ts.map +1 -1
- package/dist/direct-registry.js +111 -13
- package/dist/direct-registry.js.map +1 -1
- package/dist/direct-tool-surface.d.ts +66 -0
- package/dist/direct-tool-surface.d.ts.map +1 -0
- package/dist/direct-tool-surface.js +162 -0
- package/dist/direct-tool-surface.js.map +1 -0
- package/dist/direct.d.ts +68 -0
- package/dist/direct.d.ts.map +1 -0
- package/dist/direct.js +66 -0
- package/dist/direct.js.map +1 -0
- package/dist/execution.d.ts +11 -1
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +18 -4
- package/dist/execution.js.map +1 -1
- package/dist/frontmatter.d.ts +16 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +111 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/http-handler.d.ts +11 -2
- package/dist/http-handler.d.ts.map +1 -1
- package/dist/http-handler.js +46 -15
- package/dist/http-handler.js.map +1 -1
- package/dist/http-security.d.ts.map +1 -1
- package/dist/http-security.js.map +1 -1
- package/dist/http-sessions.d.ts +12 -4
- package/dist/http-sessions.d.ts.map +1 -1
- package/dist/http-sessions.js +4 -4
- package/dist/http-sessions.js.map +1 -1
- package/dist/http-sse.js.map +1 -1
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/issue-message.d.ts +20 -0
- package/dist/issue-message.d.ts.map +1 -0
- package/dist/issue-message.js +55 -0
- package/dist/issue-message.js.map +1 -0
- package/dist/journal-replay.d.ts +7 -0
- package/dist/journal-replay.d.ts.map +1 -1
- package/dist/journal-replay.js +18 -1
- package/dist/journal-replay.js.map +1 -1
- package/dist/journal.d.ts +9 -1
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +44 -1
- package/dist/journal.js.map +1 -1
- package/dist/json-rpc.d.ts +2 -2
- package/dist/json-rpc.d.ts.map +1 -1
- package/dist/json-rpc.js.map +1 -1
- package/dist/json-schema.d.ts +30 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +25 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/lazy-tools.d.ts +3 -0
- package/dist/lazy-tools.d.ts.map +1 -1
- package/dist/lazy-tools.js +2 -0
- package/dist/lazy-tools.js.map +1 -1
- package/dist/mcp-auth-bearer.d.ts +23 -0
- package/dist/mcp-auth-bearer.d.ts.map +1 -0
- package/dist/mcp-auth-bearer.js +50 -0
- package/dist/mcp-auth-bearer.js.map +1 -0
- package/dist/mcp-auth-jwt.d.ts +178 -0
- package/dist/mcp-auth-jwt.d.ts.map +1 -0
- package/dist/mcp-auth-jwt.js +365 -0
- package/dist/mcp-auth-jwt.js.map +1 -0
- package/dist/mcp-auth-resource.d.ts +74 -0
- package/dist/mcp-auth-resource.d.ts.map +1 -0
- package/dist/mcp-auth-resource.js +196 -0
- package/dist/mcp-auth-resource.js.map +1 -0
- package/dist/mcp-auth-rules.d.ts +135 -0
- package/dist/mcp-auth-rules.d.ts.map +1 -0
- package/dist/mcp-auth-rules.js +306 -0
- package/dist/mcp-auth-rules.js.map +1 -0
- package/dist/mcp-auth.d.ts +81 -0
- package/dist/mcp-auth.d.ts.map +1 -0
- package/dist/mcp-auth.js +256 -0
- package/dist/mcp-auth.js.map +1 -0
- package/dist/mcp-modern.d.ts +29 -5
- package/dist/mcp-modern.d.ts.map +1 -1
- package/dist/mcp-modern.js +99 -19
- package/dist/mcp-modern.js.map +1 -1
- package/dist/meta-argument.d.ts +42 -0
- package/dist/meta-argument.d.ts.map +1 -0
- package/dist/meta-argument.js +102 -0
- package/dist/meta-argument.js.map +1 -0
- package/dist/meta-keys.d.ts +29 -0
- package/dist/meta-keys.d.ts.map +1 -0
- package/dist/meta-keys.js +90 -0
- package/dist/meta-keys.js.map +1 -0
- package/dist/meta-tools.d.ts +8 -1
- package/dist/meta-tools.d.ts.map +1 -1
- package/dist/meta-tools.js +17 -7
- package/dist/meta-tools.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +0 -1
- package/dist/middleware.js.map +1 -1
- package/dist/patterns.d.ts +46 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +38 -0
- package/dist/patterns.js.map +1 -0
- package/dist/principal-binding.d.ts +42 -0
- package/dist/principal-binding.d.ts.map +1 -0
- package/dist/principal-binding.js +70 -0
- package/dist/principal-binding.js.map +1 -0
- package/dist/request-context.d.ts +7 -1
- package/dist/request-context.d.ts.map +1 -1
- package/dist/request-context.js +14 -3
- package/dist/request-context.js.map +1 -1
- package/dist/resources.d.ts +122 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +256 -0
- package/dist/resources.js.map +1 -0
- package/dist/schema.d.ts +7 -171
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +10 -135
- package/dist/schema.js.map +1 -1
- package/dist/server-types.d.ts +94 -7
- package/dist/server-types.d.ts.map +1 -1
- package/dist/server-types.js +2 -0
- package/dist/server-types.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +45 -31
- package/dist/server.js.map +1 -1
- package/dist/skills.d.ts +95 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +340 -0
- package/dist/skills.js.map +1 -0
- package/dist/strict-json.d.ts +17 -0
- package/dist/strict-json.d.ts.map +1 -0
- package/dist/strict-json.js +93 -0
- package/dist/strict-json.js.map +1 -0
- package/dist/tool-router.d.ts +13 -1
- package/dist/tool-router.d.ts.map +1 -1
- package/dist/tool-router.js +44 -10
- package/dist/tool-router.js.map +1 -1
- package/dist/tools.d.ts +10 -5
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +48 -22
- package/dist/tools.js.map +1 -1
- package/dist/validation.d.ts +6 -45
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +25 -58
- package/dist/validation.js.map +1 -1
- package/dist/verified-credentials.d.ts +34 -0
- package/dist/verified-credentials.d.ts.map +1 -0
- package/dist/verified-credentials.js +51 -0
- package/dist/verified-credentials.js.map +1 -0
- package/package.json +18 -6
package/dist/direct-registry.js
CHANGED
|
@@ -5,9 +5,24 @@
|
|
|
5
5
|
* `createMcpServer()`: Zod input validation, middleware, error sanitization and
|
|
6
6
|
* `onCommand`/`onError` hooks. It only lists and runs the commands exposed to
|
|
7
7
|
* one interface, `'agent'` by default.
|
|
8
|
+
*
|
|
9
|
+
* With `contexts`, each call names its active context in the `activeContext` call option, as an
|
|
10
|
+
* MCP 2026-07-28 request names it in `_meta["dev.afd/context"]`; the registry keeps no context
|
|
11
|
+
* state between calls. With `tools: createDirectToolSurface()`, it also lists and routes the MCP
|
|
12
|
+
* tool surface: the module-graph rule below keeps that surface out of a registry that does not
|
|
13
|
+
* ask for it. The `allow` call option, which `DirectClient` passes from its own `allow`, narrows
|
|
14
|
+
* one call to the commands a trusted predicate permits, at every level the call reaches.
|
|
15
|
+
*
|
|
16
|
+
* Module-graph rule: this module imports only types from the tool router, the tool list, the
|
|
17
|
+
* meta-tools and `bootstrap/`, so a registry built without `tools` does not bundle them.
|
|
18
|
+
* `entry-points.test.ts` holds it to that with a size budget.
|
|
8
19
|
*/
|
|
9
|
-
import { failure, isExposedTo as isCoreExposedTo } from '@lushly-dev/afd-core';
|
|
20
|
+
import { failure, isExposedTo as isCoreExposedTo, truncateName } from '@lushly-dev/afd-core';
|
|
21
|
+
import { commandNotAllowed } from '@lushly-dev/afd-core/internal/direct-allow';
|
|
10
22
|
import { createDirectApprovalExchange, directApprovalExchange, publicDirectContext, } from '@lushly-dev/afd-core/internal/direct-approval';
|
|
23
|
+
import { bindCommandAllow, filterAllowed, isCommandAllowed } from './command-allow.js';
|
|
24
|
+
import { checkContextFields } from './context-fields.js';
|
|
25
|
+
import { bindContextState, createContextState } from './context-scope.js';
|
|
11
26
|
import { createExecutionEngine } from './execution.js';
|
|
12
27
|
/**
|
|
13
28
|
* Whether a command is exposed to an interface. Each flag the command's
|
|
@@ -18,6 +33,16 @@ import { createExecutionEngine } from './execution.js';
|
|
|
18
33
|
export function isExposedTo(command, iface) {
|
|
19
34
|
return isCoreExposedTo(command, iface);
|
|
20
35
|
}
|
|
36
|
+
/** The message and suggestion for an active context the registry does not configure. */
|
|
37
|
+
function unknownContext(name, contexts) {
|
|
38
|
+
const names = contexts.map((context) => context.name);
|
|
39
|
+
return {
|
|
40
|
+
message: `Context '${truncateName(String(name))}' is not configured`,
|
|
41
|
+
suggestion: names.length > 0
|
|
42
|
+
? `Use one of: ${names.join(', ')}`
|
|
43
|
+
: 'This registry configures no contexts: pass contexts to createDirectRegistry, or leave activeContext unset',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
21
46
|
/**
|
|
22
47
|
* Create a validating in-process registry for `DirectClient`.
|
|
23
48
|
*
|
|
@@ -28,8 +53,9 @@ export function isExposedTo(command, iface) {
|
|
|
28
53
|
* that are not exposed to the chosen interface.
|
|
29
54
|
*
|
|
30
55
|
* @param commands - Commands created with `defineCommand()`
|
|
31
|
-
* @param options - Interface, middleware and
|
|
32
|
-
* @throws If two commands share a name
|
|
56
|
+
* @param options - Interface, middleware, hooks, contexts and the tool surface
|
|
57
|
+
* @throws If two commands share a name; with a tool surface, also for a reserved name or an
|
|
58
|
+
* invalid `firstClassTools`, as `createMcpServer` does
|
|
33
59
|
*
|
|
34
60
|
* @example
|
|
35
61
|
* ```typescript
|
|
@@ -47,27 +73,86 @@ export function isExposedTo(command, iface) {
|
|
|
47
73
|
*/
|
|
48
74
|
export function createDirectRegistry(commands, options = {}) {
|
|
49
75
|
const iface = options.interface ?? 'agent';
|
|
76
|
+
const contexts = [...(options.contexts ?? [])];
|
|
77
|
+
const contextNames = new Set(contexts.map((context) => context.name));
|
|
78
|
+
const contextFields = checkContextFields(options.contextFields);
|
|
79
|
+
const devMode = options.devMode ?? false;
|
|
50
80
|
const registered = new Map();
|
|
51
|
-
|
|
81
|
+
const register = (command) => {
|
|
52
82
|
if (registered.has(command.name)) {
|
|
53
83
|
throw new Error(`Duplicate command name: ${command.name}`);
|
|
54
84
|
}
|
|
55
85
|
registered.set(command.name, command);
|
|
56
|
-
}
|
|
86
|
+
};
|
|
87
|
+
for (const command of commands)
|
|
88
|
+
register(command);
|
|
89
|
+
// The surface checks the names, adds its context and bootstrap tools, and routes tool calls
|
|
90
|
+
// back into this registry's engine.
|
|
91
|
+
const tools = options.tools?.attach({
|
|
92
|
+
interface: iface,
|
|
93
|
+
contexts,
|
|
94
|
+
contextFields,
|
|
95
|
+
devMode,
|
|
96
|
+
commands: [...registered.values()],
|
|
97
|
+
isExposed: (command) => isExposedTo(command, iface),
|
|
98
|
+
executeCommand: (name, input, context) => engine.executeCommand(name, input, context),
|
|
99
|
+
executeBatch: (request, context) => engine.executeBatch(request, context),
|
|
100
|
+
executePipeline: (request, context) => engine.executePipeline(request, context),
|
|
101
|
+
});
|
|
102
|
+
for (const command of tools?.commands ?? [])
|
|
103
|
+
register(command);
|
|
57
104
|
const exposed = new Map([...registered].filter(([, command]) => isExposedTo(command, iface)));
|
|
58
105
|
const engine = createExecutionEngine({
|
|
59
106
|
commandMap: exposed,
|
|
60
107
|
middleware: options.middleware ?? [],
|
|
61
|
-
devMode
|
|
108
|
+
devMode,
|
|
62
109
|
onCommand: options.onCommand,
|
|
63
110
|
onError: options.onError,
|
|
64
111
|
contextDefaults: { clock: options.clock, random: options.random, actor: options.actor },
|
|
112
|
+
contextFields,
|
|
113
|
+
// Refusals name afd-discover and the context tools only where the surface serves them.
|
|
114
|
+
suggestTools: tools !== undefined,
|
|
65
115
|
});
|
|
116
|
+
/**
|
|
117
|
+
* The context state of one call, as the MCP 2026-07-28 lane builds one per request: nothing
|
|
118
|
+
* persists, and the context tools only validate. Without contexts the state is `null`, which
|
|
119
|
+
* also drops any state a caller's context carried in from another surface.
|
|
120
|
+
*/
|
|
121
|
+
function callContextState(activeContext) {
|
|
122
|
+
if (contexts.length === 0)
|
|
123
|
+
return null;
|
|
124
|
+
const state = createContextState({ persistent: false });
|
|
125
|
+
if (activeContext !== undefined)
|
|
126
|
+
state.enter(activeContext);
|
|
127
|
+
return state;
|
|
128
|
+
}
|
|
66
129
|
return {
|
|
67
130
|
interface: iface,
|
|
68
|
-
|
|
131
|
+
contextFields,
|
|
132
|
+
async execute(name, input = {}, context = {}, callOptions = {}) {
|
|
133
|
+
const { allow } = callOptions;
|
|
134
|
+
let { activeContext } = callOptions;
|
|
135
|
+
if (tools && !exposed.has(name) && tools.routes(name)) {
|
|
136
|
+
const lifted = tools.liftMetaArgument(name, input, context, activeContext);
|
|
137
|
+
if (!lifted.ok)
|
|
138
|
+
return failure(lifted.error);
|
|
139
|
+
({ input, context, activeContext } = lifted);
|
|
140
|
+
}
|
|
141
|
+
if (activeContext !== undefined && !contextNames.has(activeContext)) {
|
|
142
|
+
return failure({
|
|
143
|
+
code: 'CONTEXT_NOT_FOUND',
|
|
144
|
+
...unknownContext(activeContext, contexts),
|
|
145
|
+
retryable: false,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// The predicate rides on the context, under a private symbol, so every command this call
|
|
149
|
+
// runs (through the router, a batch or a pipeline) is checked by the engine.
|
|
150
|
+
const allowed = bindCommandAllow(publicDirectContext(context), allow);
|
|
151
|
+
if (!isCommandAllowed(allowed, name)) {
|
|
152
|
+
return failure(commandNotAllowed(name));
|
|
153
|
+
}
|
|
69
154
|
if (!exposed.has(name) && registered.has(name)) {
|
|
70
|
-
const available = [...exposed.
|
|
155
|
+
const available = filterAllowed([...exposed.values()], allowed).map((command) => command.name);
|
|
71
156
|
return failure({
|
|
72
157
|
code: 'COMMAND_NOT_EXPOSED',
|
|
73
158
|
message: `Command '${name}' is not exposed to ${iface}`,
|
|
@@ -81,22 +166,35 @@ export function createDirectRegistry(commands, options = {}) {
|
|
|
81
166
|
const supplied = directApprovalExchange(context);
|
|
82
167
|
const exchange = supplied ?? createDirectApprovalExchange();
|
|
83
168
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
169
|
+
const scoped = exchange.bind(bindContextState({ ...allowed, interface: iface }, callContextState(activeContext)));
|
|
170
|
+
if (tools && !exposed.has(name) && tools.routes(name)) {
|
|
171
|
+
return (await tools.callTool(name, input, scoped));
|
|
172
|
+
}
|
|
173
|
+
return (await engine.executeCommand(name, input, scoped));
|
|
88
174
|
}
|
|
89
175
|
finally {
|
|
90
176
|
if (!supplied)
|
|
91
177
|
exchange.dispose();
|
|
92
178
|
}
|
|
93
179
|
},
|
|
180
|
+
listTools(listOptions = {}) {
|
|
181
|
+
if (!tools) {
|
|
182
|
+
throw new TypeError('This registry has no tool surface: create it with createDirectRegistry(commands, { tools: createDirectToolSurface() }) to list tools');
|
|
183
|
+
}
|
|
184
|
+
const { activeContext, allow } = listOptions;
|
|
185
|
+
if (activeContext !== undefined && !contextNames.has(activeContext)) {
|
|
186
|
+
const { message, suggestion } = unknownContext(activeContext, contexts);
|
|
187
|
+
throw new RangeError(`${message}. ${suggestion}`);
|
|
188
|
+
}
|
|
189
|
+
return tools.listTools(listOptions.strategy, activeContext ?? null, allow);
|
|
190
|
+
},
|
|
94
191
|
listCommandNames() {
|
|
95
192
|
return [...exposed.keys()];
|
|
96
193
|
},
|
|
97
194
|
listCommands() {
|
|
98
195
|
return [...exposed.values()].map((command) => ({
|
|
99
196
|
name: command.name,
|
|
197
|
+
...(command.title !== undefined && { title: command.title }),
|
|
100
198
|
description: command.description,
|
|
101
199
|
category: command.category,
|
|
102
200
|
mutation: command.mutation,
|
|
@@ -106,7 +204,7 @@ export function createDirectRegistry(commands, options = {}) {
|
|
|
106
204
|
}));
|
|
107
205
|
},
|
|
108
206
|
hasCommand(name) {
|
|
109
|
-
return exposed.has(name);
|
|
207
|
+
return exposed.has(name) || (tools?.routes(name) ?? false);
|
|
110
208
|
},
|
|
111
209
|
};
|
|
112
210
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direct-registry.js","sourceRoot":"","sources":["../src/direct-registry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"direct-registry.js","sourceRoot":"","sources":["../src/direct-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAiBH,OAAO,EAAE,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EACN,4BAA4B,EAC5B,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAqB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAqB,kBAAk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c,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;gBACxE,MAAM,IAAI,UAAU,CAAC,GAAG,OAAO,KAAK,UAAU,EAAE,CAAC,CAAC;YACnD,CAAC;YACD,OAAO,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,EAAE,aAAa,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5E,CAAC;QAED,gBAAgB;YACf,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5B,CAAC;QAED,YAAY;YACX,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC9C,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC5D,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,WAAW,EAAE,OAAO,CAAC,UAAU;aAC/B,CAAC,CAAC,CAAC;QACL,CAAC;QAED,UAAU,CAAC,IAAY;YACtB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC;QAC5D,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The MCP tool surface of an in-process registry: `createDirectToolSurface()`.
|
|
3
|
+
*
|
|
4
|
+
* A host passes the surface to `createDirectRegistry(commands, { tools })`. The registry then
|
|
5
|
+
* lists the tools an MCP server with the same commands, contexts and strategy lists, by calling
|
|
6
|
+
* the server's own `getToolsList`, and routes the meta-tools through the server's own tool
|
|
7
|
+
* router, so an in-process agent sees the surface an MCP agent sees. The surface also registers
|
|
8
|
+
* the context tools when the registry has contexts, and the bootstrap tools with `bootstrap`.
|
|
9
|
+
*
|
|
10
|
+
* Exposure: where the MCP server lists, routes and describes its MCP-exposed commands, the
|
|
11
|
+
* surface uses the commands exposed to the registry's interface (`'agent'` by default). A
|
|
12
|
+
* registry built with `interface: 'mcp'` therefore sees exactly the server's commands. The
|
|
13
|
+
* surface's own context and bootstrap tools are exposed to the registry's interface, as the
|
|
14
|
+
* server's are exposed over MCP.
|
|
15
|
+
*
|
|
16
|
+
* Contexts follow the MCP 2026-07-28 lane: the registry binds a non-persistent state per call
|
|
17
|
+
* from its `activeContext` option, so `afd-context-enter` and `afd-context-exit` validate the
|
|
18
|
+
* name, change nothing, and return `persisted: false` with the hint.
|
|
19
|
+
*
|
|
20
|
+
* The registry's `allow` option narrows the surface per call: the router and engine refuse every
|
|
21
|
+
* command it rejects, `afd-discover`, `afd-detail` and the bootstrap tools leave them out, and
|
|
22
|
+
* `listTools` with `allow` lists neither those commands nor the tool names it rejects.
|
|
23
|
+
*
|
|
24
|
+
* This module is what keeps the router out of the base registry: `direct-registry.ts` imports it
|
|
25
|
+
* only as types. It loads no Node.js built-in, so it runs in a browser too.
|
|
26
|
+
*/
|
|
27
|
+
import type { DirectToolSurface } from './direct-registry.js';
|
|
28
|
+
import type { ToolStrategy } from './server-types.js';
|
|
29
|
+
/** Options for {@link createDirectToolSurface}. */
|
|
30
|
+
export interface DirectToolSurfaceOptions {
|
|
31
|
+
/**
|
|
32
|
+
* The strategy `listTools` uses by default, as `toolStrategy` on `createMcpServer`. Grouped
|
|
33
|
+
* tool calls route only when it is `'grouped'`. Default: `'individual'`.
|
|
34
|
+
*/
|
|
35
|
+
strategy?: ToolStrategy;
|
|
36
|
+
/**
|
|
37
|
+
* The hybrid strategy's first-class commands, in list order, as on `createMcpServer`: required
|
|
38
|
+
* with `strategy: 'hybrid'` and refused with any other. Each must be exposed to the registry's
|
|
39
|
+
* interface. `createDirectRegistry` throws on a mistake, naming the entry.
|
|
40
|
+
*/
|
|
41
|
+
firstClassTools?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Register `afd-help`, `afd-docs` and `afd-schema`, as `bootstrap: true` does on
|
|
44
|
+
* `createMcpServer`. Default: `false`.
|
|
45
|
+
*/
|
|
46
|
+
bootstrap?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create the MCP tool surface for `createDirectRegistry`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { createDirectRegistry, createDirectToolSurface } from '@lushly-dev/afd-server/direct';
|
|
54
|
+
*
|
|
55
|
+
* const registry = createDirectRegistry(commands, {
|
|
56
|
+
* contexts: [{ name: 'billing' }],
|
|
57
|
+
* tools: createDirectToolSurface({ strategy: 'lazy' }),
|
|
58
|
+
* });
|
|
59
|
+
* registry.listTools(); // afd-discover, afd-detail, afd-batch, afd-pipe, afd-call
|
|
60
|
+
* await registry.execute('afd-discover', {}, {}, { activeContext: 'billing' });
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @throws TypeError for a strategy that is not `individual`, `grouped`, `lazy` or `hybrid`
|
|
64
|
+
*/
|
|
65
|
+
export declare function createDirectToolSurface(options?: DirectToolSurfaceOptions): DirectToolSurface;
|
|
66
|
+
//# sourceMappingURL=direct-tool-surface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-tool-surface.d.ts","sourceRoot":"","sources":["../src/direct-tool-surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAWH,OAAO,KAAK,EAAqC,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AASjG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD,mDAAmD;AACnD,MAAM,WAAW,wBAAwB;IACxC;;;OAGG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAaD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,wBAA6B,GAAG,iBAAiB,CAqHjG"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The MCP tool surface of an in-process registry: `createDirectToolSurface()`.
|
|
3
|
+
*
|
|
4
|
+
* A host passes the surface to `createDirectRegistry(commands, { tools })`. The registry then
|
|
5
|
+
* lists the tools an MCP server with the same commands, contexts and strategy lists, by calling
|
|
6
|
+
* the server's own `getToolsList`, and routes the meta-tools through the server's own tool
|
|
7
|
+
* router, so an in-process agent sees the surface an MCP agent sees. The surface also registers
|
|
8
|
+
* the context tools when the registry has contexts, and the bootstrap tools with `bootstrap`.
|
|
9
|
+
*
|
|
10
|
+
* Exposure: where the MCP server lists, routes and describes its MCP-exposed commands, the
|
|
11
|
+
* surface uses the commands exposed to the registry's interface (`'agent'` by default). A
|
|
12
|
+
* registry built with `interface: 'mcp'` therefore sees exactly the server's commands. The
|
|
13
|
+
* surface's own context and bootstrap tools are exposed to the registry's interface, as the
|
|
14
|
+
* server's are exposed over MCP.
|
|
15
|
+
*
|
|
16
|
+
* Contexts follow the MCP 2026-07-28 lane: the registry binds a non-persistent state per call
|
|
17
|
+
* from its `activeContext` option, so `afd-context-enter` and `afd-context-exit` validate the
|
|
18
|
+
* name, change nothing, and return `persisted: false` with the hint.
|
|
19
|
+
*
|
|
20
|
+
* The registry's `allow` option narrows the surface per call: the router and engine refuse every
|
|
21
|
+
* command it rejects, `afd-discover`, `afd-detail` and the bootstrap tools leave them out, and
|
|
22
|
+
* `listTools` with `allow` lists neither those commands nor the tool names it rejects.
|
|
23
|
+
*
|
|
24
|
+
* This module is what keeps the router out of the base registry: `direct-registry.ts` imports it
|
|
25
|
+
* only as types. It loads no Node.js built-in, so it runs in a browser too.
|
|
26
|
+
*/
|
|
27
|
+
import { isMcpExposed } from '@lushly-dev/afd-core';
|
|
28
|
+
import { directAllows } from '@lushly-dev/afd-core/internal/direct-allow';
|
|
29
|
+
import { createContextCommands, getBootstrapCommands } from './bootstrap/registry.js';
|
|
30
|
+
import { filterAllowed } from './command-allow.js';
|
|
31
|
+
import { assertValidCommandNames, assertValidFirstClassTools } from './command-names.js';
|
|
32
|
+
import { commandGroup, filterByContext } from './command-routing.js';
|
|
33
|
+
import { contextFieldValues } from './context-fields.js';
|
|
34
|
+
import { createContextState, resolveContextState } from './context-scope.js';
|
|
35
|
+
import { CONTEXT_META_KEY, inProcessMeta, liftMetaArgument, metaArgumentKeys, } from './meta-argument.js';
|
|
36
|
+
import { META_TOOL_NAMES } from './meta-tools.js';
|
|
37
|
+
import { createToolRouter } from './tool-router.js';
|
|
38
|
+
import { getToolsList } from './tools.js';
|
|
39
|
+
const STRATEGIES = ['individual', 'grouped', 'lazy', 'hybrid'];
|
|
40
|
+
/**
|
|
41
|
+
* A command as the server's tool list and router see an exposed one. Both filter on
|
|
42
|
+
* `expose.mcp`; in process the registry's interface decides, so a command it exposes is shown
|
|
43
|
+
* to them as MCP-exposed. The registry still runs the command itself.
|
|
44
|
+
*/
|
|
45
|
+
function asListed(command) {
|
|
46
|
+
return isMcpExposed(command) ? command : { ...command, expose: { ...command.expose, mcp: true } };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create the MCP tool surface for `createDirectRegistry`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { createDirectRegistry, createDirectToolSurface } from '@lushly-dev/afd-server/direct';
|
|
54
|
+
*
|
|
55
|
+
* const registry = createDirectRegistry(commands, {
|
|
56
|
+
* contexts: [{ name: 'billing' }],
|
|
57
|
+
* tools: createDirectToolSurface({ strategy: 'lazy' }),
|
|
58
|
+
* });
|
|
59
|
+
* registry.listTools(); // afd-discover, afd-detail, afd-batch, afd-pipe, afd-call
|
|
60
|
+
* await registry.execute('afd-discover', {}, {}, { activeContext: 'billing' });
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @throws TypeError for a strategy that is not `individual`, `grouped`, `lazy` or `hybrid`
|
|
64
|
+
*/
|
|
65
|
+
export function createDirectToolSurface(options = {}) {
|
|
66
|
+
const strategy = options.strategy ?? 'individual';
|
|
67
|
+
if (!STRATEGIES.includes(strategy)) {
|
|
68
|
+
throw new TypeError(`Unknown tool strategy '${String(strategy)}': use one of ${STRATEGIES.join(', ')}`);
|
|
69
|
+
}
|
|
70
|
+
// A copy: the set must not change while the registry runs.
|
|
71
|
+
const firstClassTools = options.firstClassTools ? [...options.firstClassTools] : undefined;
|
|
72
|
+
const bootstrap = options.bootstrap ?? false;
|
|
73
|
+
return {
|
|
74
|
+
strategy,
|
|
75
|
+
attach(host) {
|
|
76
|
+
assertValidCommandNames(host.commands, { bootstrap, contexts: host.contexts.length > 0 });
|
|
77
|
+
const metaKeys = metaArgumentKeys(host.contextFields);
|
|
78
|
+
const expose = { mcp: true, [host.interface]: true };
|
|
79
|
+
const builtins = [];
|
|
80
|
+
if (host.contexts.length > 0) {
|
|
81
|
+
// Never used: the registry binds a state to every call.
|
|
82
|
+
const fallback = createContextState({ persistent: false });
|
|
83
|
+
builtins.push(...createContextCommands(host.contexts, fallback, expose));
|
|
84
|
+
}
|
|
85
|
+
// What the agent can see and call, filled in below; the bootstrap tools read it per call.
|
|
86
|
+
let listed = [];
|
|
87
|
+
if (bootstrap) {
|
|
88
|
+
const describe = (context) => filterAllowed(filterByContext(listed, resolveContextState(context)?.getActive()), context);
|
|
89
|
+
const toolSurface = {
|
|
90
|
+
toolStrategy: strategy,
|
|
91
|
+
firstClassTools,
|
|
92
|
+
contextFields: host.contextFields,
|
|
93
|
+
};
|
|
94
|
+
for (const command of getBootstrapCommands(describe, { toolSurface })) {
|
|
95
|
+
builtins.push({ ...command, expose: { ...command.expose, ...expose } });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const registered = [...host.commands, ...builtins];
|
|
99
|
+
assertValidFirstClassTools({
|
|
100
|
+
toolStrategy: strategy,
|
|
101
|
+
firstClassTools,
|
|
102
|
+
commands: registered,
|
|
103
|
+
interface: host.interface,
|
|
104
|
+
});
|
|
105
|
+
listed = registered.filter((command) => host.isExposed(command)).map(asListed);
|
|
106
|
+
const names = new Set(listed.map((command) => command.name));
|
|
107
|
+
const groups = new Set(strategy === 'grouped' ? listed.map((command) => commandGroup(command)) : []);
|
|
108
|
+
const routeToolCall = createToolRouter({
|
|
109
|
+
executeCommand: (name, input, context) => host.executeCommand(name, input, context),
|
|
110
|
+
executeBatch: (request, context) => host.executeBatch(request, context),
|
|
111
|
+
executePipeline: (request, context) => host.executePipeline(request, context),
|
|
112
|
+
commands: listed,
|
|
113
|
+
toolStrategy: strategy,
|
|
114
|
+
devMode: host.devMode,
|
|
115
|
+
allCommands: listed,
|
|
116
|
+
exposedCommandNames: names,
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
commands: builtins,
|
|
120
|
+
routes(name) {
|
|
121
|
+
return META_TOOL_NAMES.includes(name) || (groups.has(name) && !names.has(name));
|
|
122
|
+
},
|
|
123
|
+
liftMetaArgument(name, input, context, activeContext) {
|
|
124
|
+
const lifted = liftMetaArgument(name, input, inProcessMeta(host.contextFields, context, activeContext), metaKeys);
|
|
125
|
+
if (!lifted.ok)
|
|
126
|
+
return lifted;
|
|
127
|
+
const meta = lifted.meta;
|
|
128
|
+
const requested = meta[CONTEXT_META_KEY];
|
|
129
|
+
return {
|
|
130
|
+
ok: true,
|
|
131
|
+
input: lifted.args,
|
|
132
|
+
// Values the caller set on the context are trusted code's, and win.
|
|
133
|
+
context: { ...contextFieldValues(host.contextFields, meta), ...context },
|
|
134
|
+
activeContext: requested === undefined
|
|
135
|
+
? activeContext
|
|
136
|
+
: typeof requested === 'string'
|
|
137
|
+
? requested
|
|
138
|
+
: JSON.stringify(requested),
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
async callTool(name, input, context) {
|
|
142
|
+
const result = await routeToolCall(name, input, context);
|
|
143
|
+
return result.structuredContent ?? JSON.parse(result.content[0]?.text ?? 'null');
|
|
144
|
+
},
|
|
145
|
+
listTools(listStrategy = strategy, activeContext, allow) {
|
|
146
|
+
if (!allow) {
|
|
147
|
+
return getToolsList(listed, listStrategy, undefined, activeContext, {
|
|
148
|
+
firstClassTools,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// The commands first, so grouped tools list only the actions allow permits; then the
|
|
152
|
+
// tool names, which allow checks as DirectClient does.
|
|
153
|
+
const visible = listed.filter((command) => directAllows(allow, command.name));
|
|
154
|
+
return getToolsList(visible, listStrategy, undefined, activeContext, {
|
|
155
|
+
firstClassTools,
|
|
156
|
+
}).filter((tool) => directAllows(allow, tool.name));
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=direct-tool-surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-tool-surface.js","sourceRoot":"","sources":["../src/direct-tool-surface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,YAAY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C,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;oBAClC,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;oBACzD,OAAO,MAAM,CAAC,iBAAiB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,MAAM,CAAC,CAAC;gBAClF,CAAC;gBAED,SAAS,CAAC,YAAY,GAAG,QAAQ,EAAE,aAAa,EAAE,KAAK;oBACtD,IAAI,CAAC,KAAK,EAAE,CAAC;wBACZ,OAAO,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE;4BACnE,eAAe;yBACf,CAAC,CAAC;oBACJ,CAAC;oBACD,qFAAqF;oBACrF,uDAAuD;oBACvD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC9E,OAAO,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE;wBACpE,eAAe;qBACf,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBACrD,CAAC;aACD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/direct.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview In-process entry point: `@lushly-dev/afd-server/direct`
|
|
3
|
+
*
|
|
4
|
+
* Exposes what a host that runs commands in its own process needs: the validating
|
|
5
|
+
* `createDirectRegistry`, the approval middleware, the command journal with an in-memory sink and
|
|
6
|
+
* its replay, and the middleware whose module graph loads no Node.js built-in, plus everything
|
|
7
|
+
* `/define` exports. It
|
|
8
|
+
* loads neither the MCP SDK nor a Node.js built-in, so the same code runs in a browser, a web
|
|
9
|
+
* worker or a webview as in Node.js. The name says what the entry is for, not where it runs: a
|
|
10
|
+
* Node.js host that does not want the MCP SDK can use it too.
|
|
11
|
+
*
|
|
12
|
+
* `createDirectToolSurface` adds the MCP tool surface to a registry: the tool list of every
|
|
13
|
+
* strategy, the meta-tools, the context tools and, optionally, the bootstrap tools, from the same
|
|
14
|
+
* code the MCP server runs. A registry built without it does not bundle the tool router.
|
|
15
|
+
*
|
|
16
|
+
* The root entry (`@lushly-dev/afd-server`) still exports everything below.
|
|
17
|
+
*
|
|
18
|
+
* Approvals run on WebCrypto. In a page, the approval secret is visible to every script on that
|
|
19
|
+
* page: the gate stops a model from approving its own call through tool input, and the registry's
|
|
20
|
+
* private approval exchange keeps tokens out of results the model reads, but the secret is not a
|
|
21
|
+
* boundary against code running in the page. Keep approvals on a server when you need one.
|
|
22
|
+
*
|
|
23
|
+
* Module-graph rule: nothing reachable from this file may import the MCP SDK, a Node.js built-in
|
|
24
|
+
* or the core subpaths that need Node.js (`/platform`, `/connectors`, `/journal-file`). Nothing
|
|
25
|
+
* reachable from `createDirectRegistry`, `createJournalMiddleware` or `defineCommandWithSchema` may
|
|
26
|
+
* import `zod` or `toJSONSchema` at run time, only `zod/v4/core`. `entry-points.test.ts` bundles this
|
|
27
|
+
* entry with esbuild for the browser to enforce both, and holds AFD's own code to a size budget.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { z } from 'zod';
|
|
32
|
+
* import {
|
|
33
|
+
* createDirectRegistry,
|
|
34
|
+
* createJournalMiddleware,
|
|
35
|
+
* defineCommand,
|
|
36
|
+
* MemoryJournalSink,
|
|
37
|
+
* success,
|
|
38
|
+
* } from '@lushly-dev/afd-server/direct';
|
|
39
|
+
*
|
|
40
|
+
* const panelOpen = defineCommand({
|
|
41
|
+
* name: 'panel-open',
|
|
42
|
+
* description: 'Open a panel',
|
|
43
|
+
* input: z.object({ id: z.string() }),
|
|
44
|
+
* async handler(input) {
|
|
45
|
+
* return success({ id: input.id, open: true });
|
|
46
|
+
* },
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* const journal = new MemoryJournalSink();
|
|
50
|
+
* const registry = createDirectRegistry([panelOpen], {
|
|
51
|
+
* middleware: [createJournalMiddleware(journal)],
|
|
52
|
+
* });
|
|
53
|
+
* await registry.execute('panel-open', { id: 'settings' });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @packageDocumentation
|
|
57
|
+
*/
|
|
58
|
+
export type { CommandMiddleware, JournalEntry, JournalRecord, JournalSink, TelemetryEvent, TelemetrySink, } from '@lushly-dev/afd-core';
|
|
59
|
+
export { MemoryJournalSink } from '@lushly-dev/afd-core';
|
|
60
|
+
export { type ApprovalCommand, type ApprovalMiddlewareOptions, type ApprovalNonceStore, type ApprovalRejection, type ApprovalRequest, type ApprovalSecret, createApprovalMiddleware, } from './approval.js';
|
|
61
|
+
export * from './define.js';
|
|
62
|
+
export { createDirectRegistry, type DirectCommandRegistry, type DirectExecuteOptions, type DirectListToolsOptions, type DirectRegistryCommand, type DirectRegistryOptions, type DirectToolSurface, type ExposeInterface, } from './direct-registry.js';
|
|
63
|
+
export { createDirectToolSurface, type DirectToolSurfaceOptions } from './direct-tool-surface.js';
|
|
64
|
+
export { createJournalMiddleware, type JournalMiddlewareOptions } from './journal.js';
|
|
65
|
+
export { type JournalReplayTarget, type ReplayDifference, type ReplayEntryReport, type ReplayJournalOptions, type ReplayReport, type ReplayStatus, replayJournal, } from './journal-replay.js';
|
|
66
|
+
export { ConsoleTelemetrySink, type ConsoleTelemetrySinkOptions, composeMiddleware, createAutoTraceIdMiddleware, createLoggingMiddleware, createRateLimitMiddleware, createRetryMiddleware, createTelemetryMiddleware, createTimingMiddleware, createTracingMiddleware, type DefaultMiddlewareOptions, defaultMiddleware, type LoggingOptions, type RateLimitOptions, type RetryOptions, type Span, type TelemetryOptions, type TimingOptions, type TraceIdOptions, type Tracer, type TracingOptions, } from './middleware.js';
|
|
67
|
+
export type { ContextConfig, ToolStrategy } from './server-types.js';
|
|
68
|
+
//# sourceMappingURL=direct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct.d.ts","sourceRoot":"","sources":["../src/direct.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,YAAY,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,EACd,aAAa,GACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,wBAAwB,GACxB,MAAM,eAAe,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EACN,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAE,KAAK,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,EAAE,uBAAuB,EAAE,KAAK,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,aAAa,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,oBAAoB,EACpB,KAAK,2BAA2B,EAChC,iBAAiB,EACjB,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,cAAc,GACnB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/direct.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview In-process entry point: `@lushly-dev/afd-server/direct`
|
|
3
|
+
*
|
|
4
|
+
* Exposes what a host that runs commands in its own process needs: the validating
|
|
5
|
+
* `createDirectRegistry`, the approval middleware, the command journal with an in-memory sink and
|
|
6
|
+
* its replay, and the middleware whose module graph loads no Node.js built-in, plus everything
|
|
7
|
+
* `/define` exports. It
|
|
8
|
+
* loads neither the MCP SDK nor a Node.js built-in, so the same code runs in a browser, a web
|
|
9
|
+
* worker or a webview as in Node.js. The name says what the entry is for, not where it runs: a
|
|
10
|
+
* Node.js host that does not want the MCP SDK can use it too.
|
|
11
|
+
*
|
|
12
|
+
* `createDirectToolSurface` adds the MCP tool surface to a registry: the tool list of every
|
|
13
|
+
* strategy, the meta-tools, the context tools and, optionally, the bootstrap tools, from the same
|
|
14
|
+
* code the MCP server runs. A registry built without it does not bundle the tool router.
|
|
15
|
+
*
|
|
16
|
+
* The root entry (`@lushly-dev/afd-server`) still exports everything below.
|
|
17
|
+
*
|
|
18
|
+
* Approvals run on WebCrypto. In a page, the approval secret is visible to every script on that
|
|
19
|
+
* page: the gate stops a model from approving its own call through tool input, and the registry's
|
|
20
|
+
* private approval exchange keeps tokens out of results the model reads, but the secret is not a
|
|
21
|
+
* boundary against code running in the page. Keep approvals on a server when you need one.
|
|
22
|
+
*
|
|
23
|
+
* Module-graph rule: nothing reachable from this file may import the MCP SDK, a Node.js built-in
|
|
24
|
+
* or the core subpaths that need Node.js (`/platform`, `/connectors`, `/journal-file`). Nothing
|
|
25
|
+
* reachable from `createDirectRegistry`, `createJournalMiddleware` or `defineCommandWithSchema` may
|
|
26
|
+
* import `zod` or `toJSONSchema` at run time, only `zod/v4/core`. `entry-points.test.ts` bundles this
|
|
27
|
+
* entry with esbuild for the browser to enforce both, and holds AFD's own code to a size budget.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { z } from 'zod';
|
|
32
|
+
* import {
|
|
33
|
+
* createDirectRegistry,
|
|
34
|
+
* createJournalMiddleware,
|
|
35
|
+
* defineCommand,
|
|
36
|
+
* MemoryJournalSink,
|
|
37
|
+
* success,
|
|
38
|
+
* } from '@lushly-dev/afd-server/direct';
|
|
39
|
+
*
|
|
40
|
+
* const panelOpen = defineCommand({
|
|
41
|
+
* name: 'panel-open',
|
|
42
|
+
* description: 'Open a panel',
|
|
43
|
+
* input: z.object({ id: z.string() }),
|
|
44
|
+
* async handler(input) {
|
|
45
|
+
* return success({ id: input.id, open: true });
|
|
46
|
+
* },
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* const journal = new MemoryJournalSink();
|
|
50
|
+
* const registry = createDirectRegistry([panelOpen], {
|
|
51
|
+
* middleware: [createJournalMiddleware(journal)],
|
|
52
|
+
* });
|
|
53
|
+
* await registry.execute('panel-open', { id: 'settings' });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @packageDocumentation
|
|
57
|
+
*/
|
|
58
|
+
export { MemoryJournalSink } from '@lushly-dev/afd-core';
|
|
59
|
+
export { createApprovalMiddleware, } from './approval.js';
|
|
60
|
+
export * from './define.js';
|
|
61
|
+
export { createDirectRegistry, } from './direct-registry.js';
|
|
62
|
+
export { createDirectToolSurface } from './direct-tool-surface.js';
|
|
63
|
+
export { createJournalMiddleware } from './journal.js';
|
|
64
|
+
export { replayJournal, } from './journal-replay.js';
|
|
65
|
+
export { ConsoleTelemetrySink, composeMiddleware, createAutoTraceIdMiddleware, createLoggingMiddleware, createRateLimitMiddleware, createRetryMiddleware, createTelemetryMiddleware, createTimingMiddleware, createTracingMiddleware, defaultMiddleware, } from './middleware.js';
|
|
66
|
+
//# sourceMappingURL=direct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct.js","sourceRoot":"","sources":["../src/direct.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAUH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAON,wBAAwB,GACxB,MAAM,eAAe,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EACN,oBAAoB,GAQpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAiC,MAAM,0BAA0B,CAAC;AAClG,OAAO,EAAE,uBAAuB,EAAiC,MAAM,cAAc,CAAC;AACtF,OAAO,EAON,aAAa,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,oBAAoB,EAEpB,iBAAiB,EACjB,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EAEvB,iBAAiB,GAUjB,MAAM,iBAAiB,CAAC"}
|
package/dist/execution.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* core registry and DirectClient.
|
|
9
9
|
*/
|
|
10
10
|
import type { BatchRequest, BatchResult, CommandContext, CommandMiddleware, CommandResult, ContextDefaults, PipelineRequest, PipelineResult, StreamChunk } from '@lushly-dev/afd-core';
|
|
11
|
-
import type
|
|
11
|
+
import { type ContextField } from './context-fields.js';
|
|
12
|
+
import { type ContextState } from './context-scope.js';
|
|
12
13
|
import type { ZodCommandDefinition } from './schema.js';
|
|
13
14
|
export interface ExecutionDeps {
|
|
14
15
|
commandMap: Map<string, ZodCommandDefinition>;
|
|
@@ -20,6 +21,15 @@ export interface ExecutionDeps {
|
|
|
20
21
|
onError?: (error: Error) => void;
|
|
21
22
|
/** `clock`, `random` and `actor` for contexts that do not set them. */
|
|
22
23
|
contextDefaults?: ContextDefaults;
|
|
24
|
+
/** Declared context fields, validated on each call's context (`spec/context-fields.md`). */
|
|
25
|
+
contextFields?: readonly ContextField[];
|
|
26
|
+
/**
|
|
27
|
+
* Whether refusals may name `afd-discover` and the `afd-context-*` tools, which only a host that
|
|
28
|
+
* serves them can (`spec/error-codes.md`, "Suggestions name only tools the host provides").
|
|
29
|
+
* Default `true`: the MCP server serves both. A direct registry without a tool surface sets
|
|
30
|
+
* `false`.
|
|
31
|
+
*/
|
|
32
|
+
suggestTools?: boolean;
|
|
23
33
|
}
|
|
24
34
|
export declare function createExecutionEngine(deps: ExecutionDeps): {
|
|
25
35
|
executeCommand: (commandName: string, input: unknown, callerContext?: CommandContext) => Promise<CommandResult>;
|