@lushly-dev/afd-server 2.5.0 → 3.0.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 +65 -12
- package/dist/admission.d.ts +137 -0
- package/dist/admission.d.ts.map +1 -0
- package/dist/admission.js +144 -0
- package/dist/admission.js.map +1 -0
- package/dist/app-call-registry.d.ts +2 -2
- package/dist/app-call-registry.d.ts.map +1 -1
- package/dist/app-call-registry.js +12 -4
- package/dist/app-call-registry.js.map +1 -1
- package/dist/approval-admission.d.ts +47 -1
- package/dist/approval-admission.d.ts.map +1 -1
- package/dist/approval-admission.js +87 -0
- package/dist/approval-admission.js.map +1 -1
- package/dist/approval-crypto.d.ts +15 -1
- package/dist/approval-crypto.d.ts.map +1 -1
- package/dist/approval-crypto.js +43 -9
- package/dist/approval-crypto.js.map +1 -1
- package/dist/approval-process-state.d.ts +1 -0
- package/dist/approval-process-state.d.ts.map +1 -1
- package/dist/approval-process-state.js +1 -0
- package/dist/approval-process-state.js.map +1 -1
- package/dist/approval-relay.d.ts +23 -3
- package/dist/approval-relay.d.ts.map +1 -1
- package/dist/approval-relay.js +8 -11
- package/dist/approval-relay.js.map +1 -1
- package/dist/approval-up-front.d.ts.map +1 -1
- package/dist/approval-up-front.js +49 -5
- package/dist/approval-up-front.js.map +1 -1
- package/dist/approval.d.ts +48 -0
- package/dist/approval.d.ts.map +1 -1
- package/dist/approval.js +153 -26
- package/dist/approval.js.map +1 -1
- package/dist/approver.d.ts +2 -2
- package/dist/approver.d.ts.map +1 -1
- package/dist/approver.js +6 -6
- package/dist/approver.js.map +1 -1
- package/dist/auth-middleware-check.d.ts +23 -0
- package/dist/auth-middleware-check.d.ts.map +1 -0
- package/dist/auth-middleware-check.js +48 -0
- package/dist/auth-middleware-check.js.map +1 -0
- package/dist/bootstrap/afd-context.d.ts.map +1 -1
- package/dist/bootstrap/afd-context.js +27 -3
- package/dist/bootstrap/afd-context.js.map +1 -1
- package/dist/bootstrap/afd-help.d.ts +3 -1
- package/dist/bootstrap/afd-help.d.ts.map +1 -1
- package/dist/bootstrap/afd-help.js +2 -0
- package/dist/bootstrap/afd-help.js.map +1 -1
- package/dist/bootstrap/described-command.d.ts +2 -1
- package/dist/bootstrap/described-command.d.ts.map +1 -1
- package/dist/bootstrap/described-command.js.map +1 -1
- package/dist/command-allow.d.ts +4 -4
- package/dist/command-allow.d.ts.map +1 -1
- package/dist/command-allow.js +10 -15
- package/dist/command-allow.js.map +1 -1
- package/dist/command-routing.d.ts +56 -8
- package/dist/command-routing.d.ts.map +1 -1
- package/dist/command-routing.js +82 -16
- package/dist/command-routing.js.map +1 -1
- package/dist/command-timeout.d.ts.map +1 -1
- package/dist/command-timeout.js +8 -1
- package/dist/command-timeout.js.map +1 -1
- package/dist/confirmation-gate.d.ts +7 -7
- package/dist/confirmation-gate.d.ts.map +1 -1
- package/dist/confirmation-gate.js +26 -12
- package/dist/confirmation-gate.js.map +1 -1
- package/dist/confirmations.d.ts +28 -3
- package/dist/confirmations.d.ts.map +1 -1
- package/dist/confirmations.js +6 -7
- package/dist/confirmations.js.map +1 -1
- package/dist/context-fields.d.ts +16 -1
- package/dist/context-fields.d.ts.map +1 -1
- package/dist/context-fields.js +21 -4
- package/dist/context-fields.js.map +1 -1
- package/dist/context-scope.d.ts +3 -3
- package/dist/context-scope.d.ts.map +1 -1
- package/dist/context-scope.js +7 -8
- package/dist/context-scope.js.map +1 -1
- package/dist/define-core.d.ts +39 -3
- package/dist/define-core.d.ts.map +1 -1
- package/dist/define-core.js +20 -4
- package/dist/define-core.js.map +1 -1
- package/dist/define.d.ts +2 -2
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js.map +1 -1
- package/dist/direct-registry.d.ts +28 -6
- package/dist/direct-registry.d.ts.map +1 -1
- package/dist/direct-registry.js +23 -2
- package/dist/direct-registry.js.map +1 -1
- package/dist/direct-tool-surface.d.ts.map +1 -1
- package/dist/direct-tool-surface.js +15 -3
- package/dist/direct-tool-surface.js.map +1 -1
- package/dist/direct.d.ts +4 -2
- package/dist/direct.d.ts.map +1 -1
- package/dist/direct.js +2 -0
- package/dist/direct.js.map +1 -1
- package/dist/execution.d.ts +35 -6
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +108 -15
- package/dist/execution.js.map +1 -1
- package/dist/host-state.d.ts +81 -0
- package/dist/host-state.d.ts.map +1 -0
- package/dist/host-state.js +62 -0
- package/dist/host-state.js.map +1 -0
- package/dist/http-handler.d.ts +31 -12
- package/dist/http-handler.d.ts.map +1 -1
- package/dist/http-handler.js +129 -103
- package/dist/http-handler.js.map +1 -1
- package/dist/http-security.js +2 -2
- package/dist/http-security.js.map +1 -1
- package/dist/http-sessions.d.ts +10 -0
- package/dist/http-sessions.d.ts.map +1 -1
- package/dist/http-sessions.js +12 -2
- package/dist/http-sessions.js.map +1 -1
- package/dist/http-sse.d.ts +9 -0
- package/dist/http-sse.d.ts.map +1 -1
- package/dist/http-sse.js +12 -3
- package/dist/http-sse.js.map +1 -1
- package/dist/human-relay.d.ts +195 -0
- package/dist/human-relay.d.ts.map +1 -0
- package/dist/human-relay.js +670 -0
- package/dist/human-relay.js.map +1 -0
- package/dist/idempotency-step.d.ts +231 -0
- package/dist/idempotency-step.d.ts.map +1 -0
- package/dist/idempotency-step.js +389 -0
- package/dist/idempotency-step.js.map +1 -0
- package/dist/idempotency-store.d.ts +107 -0
- package/dist/idempotency-store.d.ts.map +1 -0
- package/dist/idempotency-store.js +100 -0
- package/dist/idempotency-store.js.map +1 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/instance-state.d.ts +7 -0
- package/dist/instance-state.d.ts.map +1 -1
- package/dist/instance-state.js +5 -2
- package/dist/instance-state.js.map +1 -1
- package/dist/journal-off-tape.d.ts +52 -0
- package/dist/journal-off-tape.d.ts.map +1 -0
- package/dist/journal-off-tape.js +150 -0
- package/dist/journal-off-tape.js.map +1 -0
- package/dist/journal-replay.d.ts.map +1 -1
- package/dist/journal-replay.js +7 -0
- package/dist/journal-replay.js.map +1 -1
- package/dist/journal-view.d.ts +50 -0
- package/dist/journal-view.d.ts.map +1 -0
- package/dist/journal-view.js +214 -0
- package/dist/journal-view.js.map +1 -0
- package/dist/journal.d.ts +24 -5
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +91 -40
- package/dist/journal.js.map +1 -1
- package/dist/lazy-tools.d.ts +13 -3
- package/dist/lazy-tools.d.ts.map +1 -1
- package/dist/lazy-tools.js +9 -2
- package/dist/lazy-tools.js.map +1 -1
- package/dist/mcp-auth-view.d.ts +2 -2
- package/dist/mcp-auth-view.d.ts.map +1 -1
- package/dist/mcp-auth-view.js +35 -22
- package/dist/mcp-auth-view.js.map +1 -1
- package/dist/mcp-auth.d.ts +17 -2
- package/dist/mcp-auth.d.ts.map +1 -1
- package/dist/mcp-auth.js +45 -13
- package/dist/mcp-auth.js.map +1 -1
- package/dist/mcp-modern.d.ts +70 -7
- package/dist/mcp-modern.d.ts.map +1 -1
- package/dist/mcp-modern.js +216 -110
- package/dist/mcp-modern.js.map +1 -1
- package/dist/meta-argument.d.ts +2 -1
- package/dist/meta-argument.d.ts.map +1 -1
- package/dist/meta-argument.js +13 -2
- package/dist/meta-argument.js.map +1 -1
- package/dist/meta-tools.js +2 -2
- package/dist/meta-tools.js.map +1 -1
- package/dist/middleware.d.ts +16 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +42 -5
- package/dist/middleware.js.map +1 -1
- package/dist/output-budget.d.ts.map +1 -1
- package/dist/output-budget.js +2 -0
- package/dist/output-budget.js.map +1 -1
- package/dist/principal-binding.js +1 -1
- package/dist/principal-binding.js.map +1 -1
- package/dist/relay-evidence.d.ts +74 -0
- package/dist/relay-evidence.d.ts.map +1 -0
- package/dist/relay-evidence.js +143 -0
- package/dist/relay-evidence.js.map +1 -0
- package/dist/schema.d.ts +4 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +3 -3
- package/dist/schema.js.map +1 -1
- package/dist/scope-view.d.ts +11 -5
- package/dist/scope-view.d.ts.map +1 -1
- package/dist/scope-view.js +9 -8
- package/dist/scope-view.js.map +1 -1
- package/dist/server-types.d.ts +33 -10
- package/dist/server-types.d.ts.map +1 -1
- package/dist/server-types.js.map +1 -1
- package/dist/server.d.ts +26 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +278 -78
- package/dist/server.js.map +1 -1
- package/dist/task-dispatch.d.ts +6 -5
- package/dist/task-dispatch.d.ts.map +1 -1
- package/dist/task-dispatch.js +11 -12
- package/dist/task-dispatch.js.map +1 -1
- package/dist/tasks-runtime.d.ts +6 -4
- package/dist/tasks-runtime.d.ts.map +1 -1
- package/dist/tasks-runtime.js +97 -24
- package/dist/tasks-runtime.js.map +1 -1
- package/dist/tasks.d.ts +34 -7
- package/dist/tasks.d.ts.map +1 -1
- package/dist/tasks.js +42 -10
- package/dist/tasks.js.map +1 -1
- package/dist/tool-router.d.ts +64 -3
- package/dist/tool-router.d.ts.map +1 -1
- package/dist/tool-router.js +215 -69
- package/dist/tool-router.js.map +1 -1
- package/dist/tools.d.ts +32 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +154 -40
- package/dist/tools.js.map +1 -1
- package/dist/up-front-steps.d.ts +8 -0
- package/dist/up-front-steps.d.ts.map +1 -1
- package/dist/up-front-steps.js +50 -1
- package/dist/up-front-steps.js.map +1 -1
- package/dist/validation.d.ts +14 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +62 -17
- package/dist/validation.js.map +1 -1
- package/package.json +12 -8
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview Shared helpers for tool listing, tool routing, discovery and
|
|
3
3
|
* execution: group/action derivation for the grouped strategy and context scoping.
|
|
4
4
|
*/
|
|
5
|
-
import type { CommandError } from '@lushly-dev/afd-core';
|
|
5
|
+
import type { CommandContext, CommandError } from '@lushly-dev/afd-core';
|
|
6
6
|
import type { ZodCommandDefinition } from './schema.js';
|
|
7
7
|
/** Derives a grouped-strategy tool name from a command (`McpServerOptions.groupByFn`). */
|
|
8
8
|
export type GroupByFn = (command: ZodCommandDefinition) => string | undefined;
|
|
@@ -30,25 +30,73 @@ export declare function commandAction(command: Pick<ZodCommandDefinition, 'name'
|
|
|
30
30
|
export declare function isAccessibleInContext(command: Contextual, activeContext: string | null | undefined): boolean;
|
|
31
31
|
/** Commands accessible in the active context (all of them when none is active). */
|
|
32
32
|
export declare function filterByContext<T extends Contextual>(commands: T[], activeContext: string | null | undefined): T[];
|
|
33
|
+
/**
|
|
34
|
+
* The meta-tools the tool router serves, as core's `AFD_META_TOOL_NAMES` lists them (a test keeps
|
|
35
|
+
* the two equal). Written out here because the engine, which `/direct` and Loam's first paint
|
|
36
|
+
* bundle, reads them, and importing core's `builtin-tools` would split it into a chunk of its own.
|
|
37
|
+
*/
|
|
38
|
+
export declare const ROUTED_META_TOOL_NAMES: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* What a surface serves, for {@link canCall}: whether it routes the meta-tools, and the command
|
|
41
|
+
* it registers and exposes to the caller's interface under a name.
|
|
42
|
+
*/
|
|
43
|
+
export interface CallableSurface {
|
|
44
|
+
/** Whether the surface serves the meta-tools (`afd-discover`, `afd-call` and the rest). */
|
|
45
|
+
metaTools: boolean;
|
|
46
|
+
/** The command registered and exposed under `name` on this surface, if any. */
|
|
47
|
+
command(name: string): Contextual | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the caller of `context` is shown `name` under MCP authorization (M6). Absent, every
|
|
50
|
+
* command is shown. The callers that hold the request's scope view pass it in, so this module,
|
|
51
|
+
* which `/direct` and the engine bundle, never loads `scope-view`.
|
|
52
|
+
*/
|
|
53
|
+
shown?(name: string, context: CommandContext | undefined): boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Whether the caller of `context` can call `name` on `surface` (`spec/recovery.md`, rule 2 and
|
|
57
|
+
* "Engine errors"): served (a meta-tool on a surface that routes them) or registered and exposed,
|
|
58
|
+
* admitted by the call's `allow` list, shown to the caller under MCP authorization, and allowed in
|
|
59
|
+
* the active context. A refusal names a command, in its suggestion and in a `call` recovery,
|
|
60
|
+
* only when this holds, so the two never disagree. A meta-tool is called as its own tool, and
|
|
61
|
+
* the context and authorization checks do not apply to it.
|
|
62
|
+
*/
|
|
63
|
+
export declare function canCall(surface: CallableSurface, name: string, context: CommandContext | undefined, activeContext: string | null | undefined): boolean;
|
|
64
|
+
/** The commands a `COMMAND_NOT_FOUND` suggestion and recovery may point to, in order. */
|
|
65
|
+
declare const NOT_FOUND_NEXT: readonly ['afd-discover', 'afd-help'];
|
|
66
|
+
/** The command a `COMMAND_NOT_FOUND` names next: the first of {@link NOT_FOUND_NEXT} `can` admits. */
|
|
67
|
+
export type NotFoundNext = (typeof NOT_FOUND_NEXT)[number];
|
|
68
|
+
/** The first command a not-found answer may point to, of those `can` admits; `null` for none. */
|
|
69
|
+
export declare function notFoundNext(can: (name: string) => boolean): NotFoundNext | null;
|
|
33
70
|
/**
|
|
34
71
|
* Recovery guidance for an unknown command name: at most
|
|
35
72
|
* {@link MAX_NOT_FOUND_MATCHES} close matches (bounded fuzzy matching; none for
|
|
36
|
-
* very long names) and a pointer to `afd-discover`. It never lists every
|
|
73
|
+
* very long names) and a pointer to `afd-discover` or `afd-help`. It never lists every
|
|
37
74
|
* command, which in lazy mode would load the whole surface into the agent's
|
|
38
75
|
* context on a single typo.
|
|
39
76
|
*
|
|
40
77
|
* @param commandName - The unknown name (untrusted; never echoed)
|
|
41
78
|
* @param commandNames - Names the caller may call
|
|
42
|
-
* @param
|
|
43
|
-
* as Rust's and C++'s do (`spec/error-codes.md`, "Suggestions name
|
|
79
|
+
* @param next - The command the caller can call to list the others ({@link notFoundNext}). With
|
|
80
|
+
* `null` the suggestion ends as Rust's and C++'s do (`spec/error-codes.md`, "Suggestions name
|
|
81
|
+
* only tools the host provides")
|
|
82
|
+
*/
|
|
83
|
+
export declare function notFoundSuggestion(commandName: string, commandNames: string[], next?: NotFoundNext | null): string;
|
|
84
|
+
/**
|
|
85
|
+
* The `COMMAND_NOT_FOUND` error for an unknown name at lookup (a call, `afd-call`, a batch item or
|
|
86
|
+
* a pipeline step). Its suggestion and its recovery name the same command, `next`, or none
|
|
87
|
+
* (`spec/recovery.md`, "Engine errors").
|
|
44
88
|
*/
|
|
45
|
-
export declare function
|
|
89
|
+
export declare function notFoundError(commandName: string, commandNames: string[], next: NotFoundNext | null): CommandError;
|
|
46
90
|
/**
|
|
47
91
|
* The `COMMAND_NOT_IN_CONTEXT` error for a command outside the active context.
|
|
48
92
|
*
|
|
49
|
-
* @param belongsTo - The command's contexts
|
|
50
|
-
*
|
|
93
|
+
* @param belongsTo - The command's contexts
|
|
94
|
+
* @param can - Whether the caller can call a command ({@link canCall}). When it can call
|
|
95
|
+
* `afd-context-list`, the suggestion and the recovery name it (and the suggestion names
|
|
96
|
+
* `afd-context-enter` too, when the caller can call that); otherwise the suggestion names the
|
|
97
|
+
* command's contexts, as Rust's and C++'s do, and the error carries no recovery. Default: every
|
|
98
|
+
* command can be called
|
|
51
99
|
*/
|
|
52
|
-
export declare function notInContextError(commandName: string, activeContext: string, belongsTo?: readonly string[]): CommandError;
|
|
100
|
+
export declare function notInContextError(commandName: string, activeContext: string, belongsTo?: readonly string[], can?: (name: string) => boolean): CommandError;
|
|
53
101
|
export {};
|
|
54
102
|
//# sourceMappingURL=command-routing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-routing.d.ts","sourceRoot":"","sources":["../src/command-routing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"command-routing.d.ts","sourceRoot":"","sources":["../src/command-routing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAA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S,GAAG,OAAO,CAAC;CACnE;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACtB,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACtC,OAAO,CAOT;AAKD,yFAAyF;AACzF,QAAA,MAAM,cAAc,YAAI,cAAc,EAAE,UAAU,CAAU,CAAC;AAE7D,sGAAsG;AACtG,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,iGAAiG;AACjG,wBAAgB,YAAY,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,YAAY,GAAG,IAAI,CAEhF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CACjC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,GAAE,YAAY,GAAG,IAAqB,GACxC,MAAM,CAUR;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC5B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,YAAY,GAAG,IAAI,GACvB,YAAY,CAOd;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,SAAS,GAAE,SAAS,MAAM,EAAO,EACjC,GAAG,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAoB,GACzC,YAAY,CAiBd"}
|
package/dist/command-routing.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* @fileoverview Shared helpers for tool listing, tool routing, discovery and
|
|
3
3
|
* execution: group/action derivation for the grouped strategy and context scoping.
|
|
4
4
|
*/
|
|
5
|
-
import { findSimilarTools } from '@lushly-dev/afd-core';
|
|
5
|
+
import { findSimilarTools, truncateName } from '@lushly-dev/afd-core';
|
|
6
|
+
import { isCommandAllowed } from './command-allow.js';
|
|
6
7
|
/**
|
|
7
8
|
* Default group (and discovery category) of a command: its `category`, else the
|
|
8
9
|
* first kebab-case segment of its name, else `'general'`.
|
|
@@ -42,45 +43,110 @@ export function filterByContext(commands, activeContext) {
|
|
|
42
43
|
return commands;
|
|
43
44
|
return commands.filter((command) => isAccessibleInContext(command, activeContext));
|
|
44
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The meta-tools the tool router serves, as core's `AFD_META_TOOL_NAMES` lists them (a test keeps
|
|
48
|
+
* the two equal). Written out here because the engine, which `/direct` and Loam's first paint
|
|
49
|
+
* bundle, reads them, and importing core's `builtin-tools` would split it into a chunk of its own.
|
|
50
|
+
*/
|
|
51
|
+
export const ROUTED_META_TOOL_NAMES = [
|
|
52
|
+
'afd-call',
|
|
53
|
+
'afd-batch',
|
|
54
|
+
'afd-pipe',
|
|
55
|
+
'afd-discover',
|
|
56
|
+
'afd-detail',
|
|
57
|
+
];
|
|
58
|
+
/**
|
|
59
|
+
* Whether the caller of `context` can call `name` on `surface` (`spec/recovery.md`, rule 2 and
|
|
60
|
+
* "Engine errors"): served (a meta-tool on a surface that routes them) or registered and exposed,
|
|
61
|
+
* admitted by the call's `allow` list, shown to the caller under MCP authorization, and allowed in
|
|
62
|
+
* the active context. A refusal names a command, in its suggestion and in a `call` recovery,
|
|
63
|
+
* only when this holds, so the two never disagree. A meta-tool is called as its own tool, and
|
|
64
|
+
* the context and authorization checks do not apply to it.
|
|
65
|
+
*/
|
|
66
|
+
export function canCall(surface, name, context, activeContext) {
|
|
67
|
+
if (!isCommandAllowed(context, name))
|
|
68
|
+
return false;
|
|
69
|
+
if (ROUTED_META_TOOL_NAMES.includes(name))
|
|
70
|
+
return surface.metaTools;
|
|
71
|
+
const command = surface.command(name);
|
|
72
|
+
if (!command)
|
|
73
|
+
return false;
|
|
74
|
+
if (surface.shown && !surface.shown(name, context))
|
|
75
|
+
return false;
|
|
76
|
+
return isAccessibleInContext(command, activeContext);
|
|
77
|
+
}
|
|
45
78
|
/** How many close matches a `COMMAND_NOT_FOUND` suggestion names at most. */
|
|
46
79
|
const MAX_NOT_FOUND_MATCHES = 3;
|
|
80
|
+
/** The commands a `COMMAND_NOT_FOUND` suggestion and recovery may point to, in order. */
|
|
81
|
+
const NOT_FOUND_NEXT = ['afd-discover', 'afd-help'];
|
|
82
|
+
/** The first command a not-found answer may point to, of those `can` admits; `null` for none. */
|
|
83
|
+
export function notFoundNext(can) {
|
|
84
|
+
return NOT_FOUND_NEXT.find((name) => can(name)) ?? null;
|
|
85
|
+
}
|
|
47
86
|
/**
|
|
48
87
|
* Recovery guidance for an unknown command name: at most
|
|
49
88
|
* {@link MAX_NOT_FOUND_MATCHES} close matches (bounded fuzzy matching; none for
|
|
50
|
-
* very long names) and a pointer to `afd-discover`. It never lists every
|
|
89
|
+
* very long names) and a pointer to `afd-discover` or `afd-help`. It never lists every
|
|
51
90
|
* command, which in lazy mode would load the whole surface into the agent's
|
|
52
91
|
* context on a single typo.
|
|
53
92
|
*
|
|
54
93
|
* @param commandName - The unknown name (untrusted; never echoed)
|
|
55
94
|
* @param commandNames - Names the caller may call
|
|
56
|
-
* @param
|
|
57
|
-
* as Rust's and C++'s do (`spec/error-codes.md`, "Suggestions name
|
|
95
|
+
* @param next - The command the caller can call to list the others ({@link notFoundNext}). With
|
|
96
|
+
* `null` the suggestion ends as Rust's and C++'s do (`spec/error-codes.md`, "Suggestions name
|
|
97
|
+
* only tools the host provides")
|
|
58
98
|
*/
|
|
59
|
-
export function notFoundSuggestion(commandName, commandNames,
|
|
60
|
-
const
|
|
61
|
-
?
|
|
99
|
+
export function notFoundSuggestion(commandName, commandNames, next = 'afd-discover') {
|
|
100
|
+
const pointer = next
|
|
101
|
+
? `Use ${next} to list all commands.`
|
|
62
102
|
: 'Check the command name against the available commands.';
|
|
63
103
|
const [best, ...others] = findSimilarTools(commandName, commandNames, MAX_NOT_FOUND_MATCHES);
|
|
64
104
|
if (best === undefined)
|
|
65
|
-
return
|
|
105
|
+
return pointer;
|
|
66
106
|
const alsoClose = others.length
|
|
67
107
|
? ` Other close matches: ${others.map((name) => `'${name}'`).join(', ')}.`
|
|
68
108
|
: '';
|
|
69
|
-
return `Did you mean '${best}'?${alsoClose} ${
|
|
109
|
+
return `Did you mean '${best}'?${alsoClose} ${pointer}`;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The `COMMAND_NOT_FOUND` error for an unknown name at lookup (a call, `afd-call`, a batch item or
|
|
113
|
+
* a pipeline step). Its suggestion and its recovery name the same command, `next`, or none
|
|
114
|
+
* (`spec/recovery.md`, "Engine errors").
|
|
115
|
+
*/
|
|
116
|
+
export function notFoundError(commandName, commandNames, next) {
|
|
117
|
+
return {
|
|
118
|
+
code: 'COMMAND_NOT_FOUND',
|
|
119
|
+
message: `Command '${truncateName(commandName)}' not found`,
|
|
120
|
+
suggestion: notFoundSuggestion(commandName, commandNames, next),
|
|
121
|
+
...(next && { recovery: { kind: 'call', command: next } }),
|
|
122
|
+
};
|
|
70
123
|
}
|
|
71
124
|
/**
|
|
72
125
|
* The `COMMAND_NOT_IN_CONTEXT` error for a command outside the active context.
|
|
73
126
|
*
|
|
74
|
-
* @param belongsTo - The command's contexts
|
|
75
|
-
*
|
|
127
|
+
* @param belongsTo - The command's contexts
|
|
128
|
+
* @param can - Whether the caller can call a command ({@link canCall}). When it can call
|
|
129
|
+
* `afd-context-list`, the suggestion and the recovery name it (and the suggestion names
|
|
130
|
+
* `afd-context-enter` too, when the caller can call that); otherwise the suggestion names the
|
|
131
|
+
* command's contexts, as Rust's and C++'s do, and the error carries no recovery. Default: every
|
|
132
|
+
* command can be called
|
|
76
133
|
*/
|
|
77
|
-
export function notInContextError(commandName, activeContext, belongsTo) {
|
|
78
|
-
|
|
134
|
+
export function notInContextError(commandName, activeContext, belongsTo = [], can = () => true) {
|
|
135
|
+
const error = {
|
|
79
136
|
code: 'COMMAND_NOT_IN_CONTEXT',
|
|
80
137
|
message: `Command '${commandName}' is not available in context '${activeContext}'`,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
138
|
+
};
|
|
139
|
+
const list = 'afd-context-list';
|
|
140
|
+
if (!can(list)) {
|
|
141
|
+
return {
|
|
142
|
+
...error,
|
|
143
|
+
suggestion: `Switch to a context this command belongs to (${belongsTo.map((name) => `'${name}'`).join(', ')}), or call it with no active context.`,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
...error,
|
|
148
|
+
suggestion: `Use ${list} to see available contexts${can('afd-context-enter') ? ', or afd-context-enter to switch' : ''}.`,
|
|
149
|
+
recovery: { kind: 'call', command: list },
|
|
84
150
|
};
|
|
85
151
|
}
|
|
86
152
|
//# sourceMappingURL=command-routing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-routing.js","sourceRoot":"","sources":["../src/command-routing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"command-routing.js","sourceRoot":"","sources":["../src/command-routing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,OAAwD;IAExD,OAAO,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;AACpE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAA6B,EAAE,SAAqB;IAChF,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,mBAAmB,C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|
|
1
|
-
{"version":3,"file":"command-timeout.d.ts","sourceRoot":"","sources":["../src/command-timeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,iBAAiB,EAAiB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"command-timeout.d.ts","sourceRoot":"","sources":["../src/command-timeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,iBAAiB,EAAiB,MAAM,sBAAsB,CAAC;AAI7F,0GAA0G;AAC1G,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAOvF;AA0ED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,SAAS,iBAAiB,EAAE,EACxC,gBAAgB,GAAE,MAAM,GAAG,IAAW,GACpC,iBAAiB,EAAE,CAerB"}
|
package/dist/command-timeout.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { failure, truncateName } from '@lushly-dev/afd-core';
|
|
2
|
+
import { idempotencyStepActed } from './approval-admission.js';
|
|
2
3
|
/** Normative server-level default per-command deadline in milliseconds (`spec/execution-controls.md`). */
|
|
3
4
|
export const DEFAULT_COMMAND_TIMEOUT_MS = 30_000;
|
|
4
5
|
/**
|
|
@@ -51,11 +52,17 @@ async function withCommandTimeout(name, context, execute, defaultTimeoutMs) {
|
|
|
51
52
|
const timedOut = new Promise((resolve) => {
|
|
52
53
|
timer = setTimeout(() => {
|
|
53
54
|
// Settle the deadline first, so a handler completing on abort cannot win the race.
|
|
55
|
+
// Where the idempotency step holds the call's key, a repeat with that key is answered
|
|
56
|
+
// from its store, so it is safe (spec/idempotency.md, R3); anywhere else it is not.
|
|
57
|
+
const keyed = idempotencyStepActed(context);
|
|
54
58
|
resolve(failure({
|
|
55
59
|
code: 'TIMEOUT',
|
|
56
60
|
message: `Command '${truncateName(name)}' timed out after ${effectiveTimeout}ms`,
|
|
57
|
-
suggestion:
|
|
61
|
+
suggestion: keyed
|
|
62
|
+
? 'Repeat the call with the same idempotency key and input: this server answers it from the first call, so the change is not applied twice.'
|
|
63
|
+
: 'Retry with a larger timeout. The command was signalled to abort but may have completed, so check its effect before retrying a mutation.',
|
|
58
64
|
retryable: true,
|
|
65
|
+
recovery: keyed ? { kind: 'retry' } : { kind: 'external' },
|
|
59
66
|
details: { command: name, timeoutMs: effectiveTimeout },
|
|
60
67
|
}));
|
|
61
68
|
controller.abort();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-timeout.js","sourceRoot":"","sources":["../src/command-timeout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"command-timeout.js","sourceRoot":"","sources":["../src/command-timeout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,0GAA0G;AAC1G,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAgC;IACvE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,0BAA0B,CAAC;IAC3D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,UAAU,CAAC,+DAA+D,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY;IACzC,OAAO,O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CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC;QACzF,GAAG,UAAU;QACb,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;YACrC,kFAAkF;YAClF,mFAAmF;YACnF,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;gBAC7B,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC;YACD,OAAO,IAAI,EAAE,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview The confirmation gate (`spec/
|
|
2
|
+
* @fileoverview The confirmation gate (`spec/confirmations.md`): the check
|
|
3
3
|
* that decides whether a call to confirm-gated commands may run, its binding digest, and the
|
|
4
|
-
*
|
|
4
|
+
* confirmation channel of the HTTP routes.
|
|
5
5
|
*
|
|
6
6
|
* Split from `confirmations.ts` because the binding digest uses `node:crypto`: only the MCP server
|
|
7
7
|
* (`server.ts`) and its HTTP handler import this module, so the tool router and the tool list stay
|
|
8
8
|
* free of Node.js built-ins for `createDirectToolSurface`. In-process calls are never gated.
|
|
9
9
|
*/
|
|
10
10
|
import type { IncomingMessage } from 'node:http';
|
|
11
|
-
import type
|
|
12
|
-
import { type ConfirmationGate, type ConfirmationMode, type ConfirmationStep } from './confirmations.js';
|
|
11
|
+
import { type ConfirmationChannel, type ConfirmationGate, type ConfirmationMode, type ConfirmationStep } from './confirmations.js';
|
|
13
12
|
import type { ZodCommandDefinition } from './schema.js';
|
|
14
13
|
/**
|
|
15
14
|
* The binding of a confirmation: a digest of the gated commands and their input. The lane that
|
|
@@ -25,8 +24,9 @@ export declare function createConfirmationGate(mode: ConfirmationMode, commands:
|
|
|
25
24
|
/** Header that acknowledges confirm-gated commands on the HTTP routes: their names, comma-separated. */
|
|
26
25
|
export declare const AFD_CONFIRM_HEADER = "afd-confirm";
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* What a request to the HTTP routes (`/rpc`, `/batch`, `/stream`) can carry for confirmations: no
|
|
28
|
+
* elicitation, and the command names its `Afd-Confirm` header acknowledges. The router's gate then
|
|
29
|
+
* decides it as it decides any call (`admission.ts`).
|
|
30
30
|
*/
|
|
31
|
-
export declare function
|
|
31
|
+
export declare function httpConfirmationChannel(req: IncomingMessage): ConfirmationChannel;
|
|
32
32
|
//# sourceMappingURL=confirmation-gate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmation-gate.d.ts","sourceRoot":"","sources":["../src/confirmation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"confirmation-gate.d.ts","sourceRoot":"","sources":["../src/confirmation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAEN,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAErB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAcxD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAI9E;AAkBD;;;GAGG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,SAAS,oBAAoB,EAAE,GACvC,gBAAgB,CA0ElB;AAED,wGAAwG;AACxG,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAehD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,eAAe,GAAG,mBAAmB,CAajF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview The confirmation gate (`spec/
|
|
2
|
+
* @fileoverview The confirmation gate (`spec/confirmations.md`): the check
|
|
3
3
|
* that decides whether a call to confirm-gated commands may run, its binding digest, and the
|
|
4
|
-
*
|
|
4
|
+
* confirmation channel of the HTTP routes.
|
|
5
5
|
*
|
|
6
6
|
* Split from `confirmations.ts` because the binding digest uses `node:crypto`: only the MCP server
|
|
7
7
|
* (`server.ts`) and its HTTP handler import this module, so the tool router and the tool list stay
|
|
@@ -56,7 +56,12 @@ export function createConfirmationGate(mode, commands) {
|
|
|
56
56
|
throw new Error("confirmations must be 'off', 'enforce' or 'require-human'");
|
|
57
57
|
}
|
|
58
58
|
const byName = new Map(commands.map((command) => [command.name, command]));
|
|
59
|
-
const gated = (steps) => mode === 'off'
|
|
59
|
+
const gated = (steps) => mode === 'off'
|
|
60
|
+
? []
|
|
61
|
+
: steps.filter((step) => {
|
|
62
|
+
const command = byName.get(step.command);
|
|
63
|
+
return !!command?.confirmPrompt && command.confirmationMode !== 'host-verified';
|
|
64
|
+
});
|
|
60
65
|
return {
|
|
61
66
|
mode,
|
|
62
67
|
gated,
|
|
@@ -78,6 +83,7 @@ export function createConfirmationGate(mode, commands) {
|
|
|
78
83
|
message: `The user did not confirm ${names.map((name) => `'${name}'`).join(', ')}`,
|
|
79
84
|
suggestion: 'Do not run this again without asking the user first; the user chose not to proceed.',
|
|
80
85
|
retryable: false,
|
|
86
|
+
recovery: { kind: 'stop' },
|
|
81
87
|
details: { commands: names },
|
|
82
88
|
},
|
|
83
89
|
};
|
|
@@ -105,6 +111,8 @@ export function createConfirmationGate(mode, commands) {
|
|
|
105
111
|
? `Make sure the user intends this, then ${howToAcknowledge}.`
|
|
106
112
|
: 'This server accepts only a confirmation from the user: use an MCP client that supports elicitation.',
|
|
107
113
|
retryable: false,
|
|
114
|
+
// The user confirms, which never goes in a recovery's input (rule 5).
|
|
115
|
+
recovery: { kind: 'external' },
|
|
108
116
|
details: { commands: names },
|
|
109
117
|
},
|
|
110
118
|
};
|
|
@@ -125,16 +133,22 @@ function headerAcknowledgement(req) {
|
|
|
125
133
|
.filter(Boolean));
|
|
126
134
|
}
|
|
127
135
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
136
|
+
* What a request to the HTTP routes (`/rpc`, `/batch`, `/stream`) can carry for confirmations: no
|
|
137
|
+
* elicitation, and the command names its `Afd-Confirm` header acknowledges. The router's gate then
|
|
138
|
+
* decides it as it decides any call (`admission.ts`).
|
|
130
139
|
*/
|
|
131
|
-
export function
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
export function httpConfirmationChannel(req) {
|
|
141
|
+
return {
|
|
142
|
+
canElicit: false,
|
|
143
|
+
acknowledged: false,
|
|
144
|
+
response: async () => 'missing',
|
|
145
|
+
request: async () => {
|
|
146
|
+
throw new Error('The HTTP routes cannot ask for a confirmation');
|
|
147
|
+
},
|
|
148
|
+
acknowledgement: {
|
|
149
|
+
names: headerAcknowledgement(req),
|
|
150
|
+
how: (names) => `repeat the request with the header 'Afd-Confirm: ${names.join(', ')}'`,
|
|
151
|
+
},
|
|
138
152
|
};
|
|
139
153
|
}
|
|
140
154
|
//# sourceMappingURL=confirmation-gate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmation-gate.js","sourceRoot":"","sources":["../src/confirmation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"confirmation-gate.js","sourceRoot":"","sources":["../src/confirmation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAMN,mBAAmB,G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DAAoD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACvF;KACD,CAAC;AACH,CAAC"}
|
package/dist/confirmations.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Confirmation enforcement for commands that declare `confirmPrompt`
|
|
3
|
-
* (`spec/
|
|
3
|
+
* (`spec/confirmations.md`): the types, constants and plain helpers.
|
|
4
4
|
*
|
|
5
5
|
* The server option `confirmations` turns it on. A call that reaches a confirm-gated command runs
|
|
6
6
|
* only when it carries a confirmation:
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* handler runs. In-process calls (DirectClient, `server.execute`) are never gated.
|
|
16
16
|
*
|
|
17
17
|
* The lane that received a request describes what that request can carry with a
|
|
18
|
-
* {@link ConfirmationChannel}, bound to the `CommandContext`
|
|
19
|
-
* state is), so `createContext` cannot forge one.
|
|
18
|
+
* {@link ConfirmationChannel}, bound to the `CommandContext`'s host state (`host-state.ts`, as
|
|
19
|
+
* context state is), so `createContext` cannot forge one.
|
|
20
20
|
*
|
|
21
21
|
* Module-graph rule: this module loads no Node.js built-in, because the tool router and the tool
|
|
22
22
|
* list import it and `createDirectToolSurface` bundles them for the browser. The gate itself,
|
|
@@ -62,6 +62,15 @@ export interface ConfirmationChannel {
|
|
|
62
62
|
response(binding: string): Promise<'accept' | 'decline' | 'missing'>;
|
|
63
63
|
/** The `input_required` result that asks `message`, bound to `binding`. */
|
|
64
64
|
request(message: string, binding: string): Promise<unknown>;
|
|
65
|
+
/**
|
|
66
|
+
* On a lane whose acknowledgement is not a tool argument (the HTTP routes' `Afd-Confirm`
|
|
67
|
+
* header): what the request acknowledges, and how to acknowledge the gated `names`. A `confirm`
|
|
68
|
+
* argument then acknowledges nothing.
|
|
69
|
+
*/
|
|
70
|
+
readonly acknowledgement?: {
|
|
71
|
+
readonly names: Acknowledgement;
|
|
72
|
+
how(names: readonly string[]): string;
|
|
73
|
+
};
|
|
65
74
|
}
|
|
66
75
|
/** What the gate decided for one call. */
|
|
67
76
|
export type ConfirmationOutcome = {
|
|
@@ -104,4 +113,20 @@ export interface ConfirmationGate {
|
|
|
104
113
|
*/
|
|
105
114
|
check(steps: readonly ConfirmationStep[], acknowledged: Acknowledgement, context: CommandContext | undefined, howToAcknowledge: string): Promise<ConfirmationOutcome>;
|
|
106
115
|
}
|
|
116
|
+
/** What the host-verified confirmation gate decided for one call. */
|
|
117
|
+
export type HumanRelayOutcome = {
|
|
118
|
+
kind: 'proceed';
|
|
119
|
+
context: CommandContext;
|
|
120
|
+
} | {
|
|
121
|
+
kind: 'error';
|
|
122
|
+
error: CommandError;
|
|
123
|
+
} | {
|
|
124
|
+
kind: 'input-required';
|
|
125
|
+
result: unknown;
|
|
126
|
+
};
|
|
127
|
+
/** Host-verified confirmation gate wired into `createToolRouter` on MCP servers. */
|
|
128
|
+
export interface HumanRelayGate {
|
|
129
|
+
refuseSteps(steps: readonly ConfirmationStep[]): CommandError | undefined;
|
|
130
|
+
check(command: ZodCommandDefinition, input: unknown, callContext: CommandContext): Promise<HumanRelayOutcome>;
|
|
131
|
+
}
|
|
107
132
|
//# sourceMappingURL=confirmations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmations.d.ts","sourceRoot":"","sources":["../src/confirmations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"confirmations.d.ts","sourceRoot":"","sources":["../src/confirmations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,sFAAsF;AACtF,MAAM,MAAM,gBAA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AAS,gBAAgB,EAAE,GAAG,YAAY,GAAG,SAAS,CAAC;IAC1E,KAAK,CACJ,OAAO,EAAE,oBAAoB,EAC7B,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,cAAc,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC9B"}
|
package/dist/confirmations.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Confirmation enforcement for commands that declare `confirmPrompt`
|
|
3
|
-
* (`spec/
|
|
3
|
+
* (`spec/confirmations.md`): the types, constants and plain helpers.
|
|
4
4
|
*
|
|
5
5
|
* The server option `confirmations` turns it on. A call that reaches a confirm-gated command runs
|
|
6
6
|
* only when it carries a confirmation:
|
|
@@ -15,14 +15,15 @@
|
|
|
15
15
|
* handler runs. In-process calls (DirectClient, `server.execute`) are never gated.
|
|
16
16
|
*
|
|
17
17
|
* The lane that received a request describes what that request can carry with a
|
|
18
|
-
* {@link ConfirmationChannel}, bound to the `CommandContext`
|
|
19
|
-
* state is), so `createContext` cannot forge one.
|
|
18
|
+
* {@link ConfirmationChannel}, bound to the `CommandContext`'s host state (`host-state.ts`, as
|
|
19
|
+
* context state is), so `createContext` cannot forge one.
|
|
20
20
|
*
|
|
21
21
|
* Module-graph rule: this module loads no Node.js built-in, because the tool router and the tool
|
|
22
22
|
* list import it and `createDirectToolSurface` bundles them for the browser. The gate itself,
|
|
23
23
|
* whose binding digest uses `node:crypto`, is in `confirmation-gate.ts`, which only the MCP
|
|
24
24
|
* server and its HTTP handler import.
|
|
25
25
|
*/
|
|
26
|
+
import { hostState, withHostState } from './host-state.js';
|
|
26
27
|
/** `_meta` key a client sets to `true` to acknowledge every confirm-gated command in a call. */
|
|
27
28
|
export const AFD_CONFIRM_META_KEY = 'dev.afd/confirm';
|
|
28
29
|
/** The `inputRequests` key of the confirmation elicitation. */
|
|
@@ -49,15 +50,13 @@ export class InputRequiredSignal {
|
|
|
49
50
|
this.result = result;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
const CHANNEL = Symbol('afd.confirmationChannel');
|
|
53
53
|
/** Return a copy of `context` bound to `channel`. */
|
|
54
54
|
export function bindConfirmationChannel(context, channel) {
|
|
55
|
-
|
|
56
|
-
return bound;
|
|
55
|
+
return withHostState(context, { confirmationChannel: channel });
|
|
57
56
|
}
|
|
58
57
|
/** The channel bound to `context`, if any. */
|
|
59
58
|
export function confirmationChannel(context) {
|
|
60
|
-
return context
|
|
59
|
+
return hostState(context).confirmationChannel;
|
|
61
60
|
}
|
|
62
61
|
/** Whether a command's own input schema declares a `confirm` property. */
|
|
63
62
|
export function declaresConfirmInput(command) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmations.js","sourceRoot":"","sources":["../src/confirmations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"confirmations.js","sourceRoot":"","sources":["../src/confirmations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAM3D,gGAAgG;AAChG,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAEtD,+DAA+D;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE3C,kDAAkD;AAClD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACX,OAAO,EAAE;YACR,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,iBAAiB;SAC9B;KACD;IACD,QAAQ,EAAE,CAAC,SAAS,CAAC;CACZ,CAAC;AAuCX;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IACV,MAAM;IAA3B,YAAqB,MAAe;sBAAf,MAAM;IAAY,CAAC;CACxC;AAKD,qDAAqD;AACrD,MAAM,UAAU,uBAAuB,CACtC,OAAuB,EACvB,OAA4B;IAE5B,OAAO,aAAa,CAAC,OAAO,EAAE,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,mBAAmB,CAClC,OAAmC;IAEnC,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC;AAC/C,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,oBAAoB,CAAC,OAA6B;IACjE,MAAM,UAAU,GAAI,OAAO,CAAC,UAAuD,CAAC,UAAU,CAAC;IAC/F,OAAO,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAC7D,CAAC"}
|
package/dist/context-fields.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface ContextField<T = unknown> {
|
|
|
18
18
|
/** Fail a call that has no value for this field. Default `false`. */
|
|
19
19
|
required?: boolean;
|
|
20
20
|
}
|
|
21
|
+
/** Context keys AFD or its packages set, which a declared field or host annotation cannot take. */
|
|
22
|
+
export declare const RESERVED_CONTEXT_NAMES: Set<string>;
|
|
21
23
|
/**
|
|
22
24
|
* On a context the engine validated: the names of the declared fields marked `journal: true`, for
|
|
23
25
|
* the journal middleware. A symbol, so it never shows up among the context's keys.
|
|
@@ -37,14 +39,27 @@ export declare function contextFieldValues(fields: readonly ContextField[] | und
|
|
|
37
39
|
* reverse-DNS prefix or with a reserved one, a repeated `meta` key, or a missing schema
|
|
38
40
|
*/
|
|
39
41
|
export declare function checkContextFields(fields: readonly ContextField[] | undefined): readonly ContextField[];
|
|
42
|
+
/** How `applyContextFields` reports a schema that throws. */
|
|
43
|
+
export interface ApplyContextFieldsOptions {
|
|
44
|
+
/** Return the exception's text to the caller. Default `false`: a generic message. */
|
|
45
|
+
devMode?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Receives the exception a schema callback threw, as thrown. It must not throw or reject: each
|
|
48
|
+
* caller passes a guarded hook.
|
|
49
|
+
*/
|
|
50
|
+
onError?: (error: unknown) => void;
|
|
51
|
+
}
|
|
40
52
|
/**
|
|
41
53
|
* Validate a call's declared fields on its context, in place: each value is replaced by its
|
|
42
54
|
* schema's output, and the journaled names are marked for the journal. An absent or `null` value
|
|
43
55
|
* is no value. A required field is not enforced for AFD's own `afd-*` commands, so a client can
|
|
44
56
|
* discover the fields before it sends them.
|
|
45
57
|
*
|
|
58
|
+
* A schema callback that throws is an invalid value too. Its exception text reaches the caller only
|
|
59
|
+
* in `devMode`, as `execution.ts` does for a handler; the exception always goes to `onError`.
|
|
60
|
+
*
|
|
46
61
|
* @returns a `VALIDATION_ERROR` result for an invalid value or a missing required one, else
|
|
47
62
|
* `undefined`
|
|
48
63
|
*/
|
|
49
|
-
export declare function applyContextFields(fields: readonly ContextField[], context: CommandContext, commandName: string): CommandResult | undefined;
|
|
64
|
+
export declare function applyContextFields(fields: readonly ContextField[], context: CommandContext, commandName: string, options?: ApplyContextFieldsOptions): CommandResult | undefined;
|
|
50
65
|
//# sourceMappingURL=context-fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-fields.d.ts","sourceRoot":"","sources":["../src/context-fields.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAAE,KAAK,QAAQ,EAAa,MAAM,aAAa,CAAC;AAGvD,8FAA8F;AAC9F,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACxC,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,kGAAkG;IAClG,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpB,oGAAoG;IACpG,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qEAAqE;IACrE,QAAQ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