@lushly-dev/afd-server 2.3.0 → 2.5.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.
Files changed (223) hide show
  1. package/README.md +277 -31
  2. package/dist/app-call-registry.d.ts +31 -0
  3. package/dist/app-call-registry.d.ts.map +1 -0
  4. package/dist/app-call-registry.js +56 -0
  5. package/dist/app-call-registry.js.map +1 -0
  6. package/dist/approval-admission.d.ts +93 -0
  7. package/dist/approval-admission.d.ts.map +1 -0
  8. package/dist/approval-admission.js +165 -0
  9. package/dist/approval-admission.js.map +1 -0
  10. package/dist/approval-crypto.d.ts +22 -16
  11. package/dist/approval-crypto.d.ts.map +1 -1
  12. package/dist/approval-crypto.js +41 -66
  13. package/dist/approval-crypto.js.map +1 -1
  14. package/dist/approval-process-state.d.ts +20 -0
  15. package/dist/approval-process-state.d.ts.map +1 -0
  16. package/dist/approval-process-state.js +28 -0
  17. package/dist/approval-process-state.js.map +1 -0
  18. package/dist/approval-relay.d.ts +171 -8
  19. package/dist/approval-relay.d.ts.map +1 -1
  20. package/dist/approval-relay.js +42 -3
  21. package/dist/approval-relay.js.map +1 -1
  22. package/dist/approval-up-front.d.ts +40 -0
  23. package/dist/approval-up-front.d.ts.map +1 -0
  24. package/dist/approval-up-front.js +365 -0
  25. package/dist/approval-up-front.js.map +1 -0
  26. package/dist/approval.d.ts +17 -12
  27. package/dist/approval.d.ts.map +1 -1
  28. package/dist/approval.js +178 -41
  29. package/dist/approval.js.map +1 -1
  30. package/dist/approver.d.ts +84 -0
  31. package/dist/approver.d.ts.map +1 -0
  32. package/dist/approver.js +107 -0
  33. package/dist/approver.js.map +1 -0
  34. package/dist/bootstrap/afd-docs.d.ts.map +1 -1
  35. package/dist/bootstrap/afd-docs.js +4 -0
  36. package/dist/bootstrap/afd-docs.js.map +1 -1
  37. package/dist/bootstrap/afd-help.d.ts +2 -1
  38. package/dist/bootstrap/afd-help.d.ts.map +1 -1
  39. package/dist/bootstrap/afd-help.js +17 -4
  40. package/dist/bootstrap/afd-help.js.map +1 -1
  41. package/dist/bootstrap/described-command.d.ts +2 -1
  42. package/dist/bootstrap/described-command.d.ts.map +1 -1
  43. package/dist/bootstrap/described-command.js.map +1 -1
  44. package/dist/command-timeout.d.ts +17 -0
  45. package/dist/command-timeout.d.ts.map +1 -0
  46. package/dist/command-timeout.js +92 -0
  47. package/dist/command-timeout.js.map +1 -0
  48. package/dist/context-fields.d.ts.map +1 -1
  49. package/dist/context-fields.js +9 -9
  50. package/dist/context-fields.js.map +1 -1
  51. package/dist/credentials.d.ts +17 -0
  52. package/dist/credentials.d.ts.map +1 -0
  53. package/dist/credentials.js +16 -0
  54. package/dist/credentials.js.map +1 -0
  55. package/dist/define-core.d.ts +27 -1
  56. package/dist/define-core.d.ts.map +1 -1
  57. package/dist/define-core.js +8 -1
  58. package/dist/define-core.js.map +1 -1
  59. package/dist/define.d.ts +3 -2
  60. package/dist/define.d.ts.map +1 -1
  61. package/dist/define.js +1 -1
  62. package/dist/define.js.map +1 -1
  63. package/dist/direct-registry.d.ts +27 -3
  64. package/dist/direct-registry.d.ts.map +1 -1
  65. package/dist/direct-registry.js +41 -6
  66. package/dist/direct-registry.js.map +1 -1
  67. package/dist/direct-tool-surface.d.ts +1 -1
  68. package/dist/direct-tool-surface.d.ts.map +1 -1
  69. package/dist/direct-tool-surface.js +14 -4
  70. package/dist/direct-tool-surface.js.map +1 -1
  71. package/dist/direct.d.ts +3 -1
  72. package/dist/direct.d.ts.map +1 -1
  73. package/dist/direct.js +2 -1
  74. package/dist/direct.js.map +1 -1
  75. package/dist/elicitation-state.d.ts +5 -1
  76. package/dist/elicitation-state.d.ts.map +1 -1
  77. package/dist/elicitation-state.js +4 -1
  78. package/dist/elicitation-state.js.map +1 -1
  79. package/dist/execution.d.ts +17 -0
  80. package/dist/execution.d.ts.map +1 -1
  81. package/dist/execution.js +78 -7
  82. package/dist/execution.js.map +1 -1
  83. package/dist/http-handler.d.ts +26 -2
  84. package/dist/http-handler.d.ts.map +1 -1
  85. package/dist/http-handler.js +154 -19
  86. package/dist/http-handler.js.map +1 -1
  87. package/dist/http-security.d.ts +14 -1
  88. package/dist/http-security.d.ts.map +1 -1
  89. package/dist/http-security.js +79 -17
  90. package/dist/http-security.js.map +1 -1
  91. package/dist/http-sessions.d.ts +45 -7
  92. package/dist/http-sessions.d.ts.map +1 -1
  93. package/dist/http-sessions.js +44 -12
  94. package/dist/http-sessions.js.map +1 -1
  95. package/dist/index.d.ts +18 -5
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +18 -3
  98. package/dist/index.js.map +1 -1
  99. package/dist/instance-state.d.ts +46 -0
  100. package/dist/instance-state.d.ts.map +1 -0
  101. package/dist/instance-state.js +91 -0
  102. package/dist/instance-state.js.map +1 -0
  103. package/dist/journal-replay.d.ts.map +1 -1
  104. package/dist/journal-replay.js +41 -3
  105. package/dist/journal-replay.js.map +1 -1
  106. package/dist/journal.d.ts +10 -1
  107. package/dist/journal.d.ts.map +1 -1
  108. package/dist/journal.js +95 -10
  109. package/dist/journal.js.map +1 -1
  110. package/dist/json-rpc.d.ts +3 -2
  111. package/dist/json-rpc.d.ts.map +1 -1
  112. package/dist/json-rpc.js +5 -3
  113. package/dist/json-rpc.js.map +1 -1
  114. package/dist/lazy-tools.d.ts +16 -1
  115. package/dist/lazy-tools.d.ts.map +1 -1
  116. package/dist/lazy-tools.js +13 -2
  117. package/dist/lazy-tools.js.map +1 -1
  118. package/dist/mcp-auth-bearer.d.ts +25 -0
  119. package/dist/mcp-auth-bearer.d.ts.map +1 -0
  120. package/dist/mcp-auth-bearer.js +50 -0
  121. package/dist/mcp-auth-bearer.js.map +1 -0
  122. package/dist/mcp-auth-dispatch.d.ts +38 -0
  123. package/dist/mcp-auth-dispatch.d.ts.map +1 -0
  124. package/dist/mcp-auth-dispatch.js +113 -0
  125. package/dist/mcp-auth-dispatch.js.map +1 -0
  126. package/dist/mcp-auth-jwt.d.ts +179 -0
  127. package/dist/mcp-auth-jwt.d.ts.map +1 -0
  128. package/dist/mcp-auth-jwt.js +365 -0
  129. package/dist/mcp-auth-jwt.js.map +1 -0
  130. package/dist/mcp-auth-resource.d.ts +78 -0
  131. package/dist/mcp-auth-resource.d.ts.map +1 -0
  132. package/dist/mcp-auth-resource.js +197 -0
  133. package/dist/mcp-auth-resource.js.map +1 -0
  134. package/dist/mcp-auth-rules.d.ts +135 -0
  135. package/dist/mcp-auth-rules.d.ts.map +1 -0
  136. package/dist/mcp-auth-rules.js +306 -0
  137. package/dist/mcp-auth-rules.js.map +1 -0
  138. package/dist/mcp-auth-scopes.d.ts +84 -0
  139. package/dist/mcp-auth-scopes.d.ts.map +1 -0
  140. package/dist/mcp-auth-scopes.js +125 -0
  141. package/dist/mcp-auth-scopes.js.map +1 -0
  142. package/dist/mcp-auth-view.d.ts +50 -0
  143. package/dist/mcp-auth-view.d.ts.map +1 -0
  144. package/dist/mcp-auth-view.js +166 -0
  145. package/dist/mcp-auth-view.js.map +1 -0
  146. package/dist/mcp-auth.d.ts +157 -0
  147. package/dist/mcp-auth.d.ts.map +1 -0
  148. package/dist/mcp-auth.js +442 -0
  149. package/dist/mcp-auth.js.map +1 -0
  150. package/dist/mcp-modern.d.ts +15 -1
  151. package/dist/mcp-modern.d.ts.map +1 -1
  152. package/dist/mcp-modern.js +218 -31
  153. package/dist/mcp-modern.js.map +1 -1
  154. package/dist/meta-argument.d.ts +8 -8
  155. package/dist/meta-argument.d.ts.map +1 -1
  156. package/dist/meta-argument.js +17 -10
  157. package/dist/meta-argument.js.map +1 -1
  158. package/dist/meta-tools.js +1 -1
  159. package/dist/meta-tools.js.map +1 -1
  160. package/dist/middleware.d.ts.map +1 -1
  161. package/dist/middleware.js +16 -6
  162. package/dist/middleware.js.map +1 -1
  163. package/dist/output-budget.d.ts +77 -0
  164. package/dist/output-budget.d.ts.map +1 -0
  165. package/dist/output-budget.js +200 -0
  166. package/dist/output-budget.js.map +1 -0
  167. package/dist/request-context.d.ts +7 -1
  168. package/dist/request-context.d.ts.map +1 -1
  169. package/dist/request-context.js +14 -3
  170. package/dist/request-context.js.map +1 -1
  171. package/dist/resources.d.ts +35 -10
  172. package/dist/resources.d.ts.map +1 -1
  173. package/dist/resources.js +59 -18
  174. package/dist/resources.js.map +1 -1
  175. package/dist/scope-view.d.ts +59 -0
  176. package/dist/scope-view.d.ts.map +1 -0
  177. package/dist/scope-view.js +44 -0
  178. package/dist/scope-view.js.map +1 -0
  179. package/dist/server-types.d.ts +191 -26
  180. package/dist/server-types.d.ts.map +1 -1
  181. package/dist/server-types.js.map +1 -1
  182. package/dist/server.d.ts.map +1 -1
  183. package/dist/server.js +165 -18
  184. package/dist/server.js.map +1 -1
  185. package/dist/skills.d.ts.map +1 -1
  186. package/dist/skills.js +99 -3
  187. package/dist/skills.js.map +1 -1
  188. package/dist/strict-json.d.ts +17 -0
  189. package/dist/strict-json.d.ts.map +1 -0
  190. package/dist/strict-json.js +93 -0
  191. package/dist/strict-json.js.map +1 -0
  192. package/dist/task-dispatch.d.ts +34 -0
  193. package/dist/task-dispatch.d.ts.map +1 -0
  194. package/dist/task-dispatch.js +26 -0
  195. package/dist/task-dispatch.js.map +1 -0
  196. package/dist/tasks-runtime.d.ts +113 -0
  197. package/dist/tasks-runtime.d.ts.map +1 -0
  198. package/dist/tasks-runtime.js +687 -0
  199. package/dist/tasks-runtime.js.map +1 -0
  200. package/dist/tasks.d.ts +210 -0
  201. package/dist/tasks.d.ts.map +1 -0
  202. package/dist/tasks.js +289 -0
  203. package/dist/tasks.js.map +1 -0
  204. package/dist/tool-router.d.ts +4 -0
  205. package/dist/tool-router.d.ts.map +1 -1
  206. package/dist/tool-router.js +103 -26
  207. package/dist/tool-router.js.map +1 -1
  208. package/dist/tools.d.ts.map +1 -1
  209. package/dist/tools.js +11 -18
  210. package/dist/tools.js.map +1 -1
  211. package/dist/up-front-steps.d.ts +27 -0
  212. package/dist/up-front-steps.d.ts.map +1 -0
  213. package/dist/up-front-steps.js +110 -0
  214. package/dist/up-front-steps.js.map +1 -0
  215. package/dist/validation.d.ts +24 -3
  216. package/dist/validation.d.ts.map +1 -1
  217. package/dist/validation.js +56 -6
  218. package/dist/validation.js.map +1 -1
  219. package/dist/verified-credentials.d.ts +42 -0
  220. package/dist/verified-credentials.d.ts.map +1 -0
  221. package/dist/verified-credentials.js +84 -0
  222. package/dist/verified-credentials.js.map +1 -0
  223. package/package.json +12 -7
@@ -10,9 +10,13 @@
10
10
  * with `input_required` instead of the held result.
11
11
  *
12
12
  * `afd-batch` and `afd-pipe` replace the relay with one that never asks, because asking mid-run
13
- * would run the earlier steps again on the retry.
13
+ * would run the earlier steps again on the retry. Instead (#459), the router binds an
14
+ * {@link UpFrontApproval} for the whole call: before any step runs, the approval middleware works
15
+ * out every gated step's input and asks once for all of them, or refuses the call when a gated
16
+ * pipeline step's input comes from an earlier step.
14
17
  */
15
- import type { CommandContext } from '@lushly-dev/afd-core';
18
+ import type { BatchRequest, Clock, CommandContext, CommandError, CommandResult, PipelineRequest } from '@lushly-dev/afd-core';
19
+ import type { ZodCommandDefinition } from './schema.js';
16
20
  /** The `inputRequests` key of the approval elicitation. */
17
21
  export declare const APPROVAL_INPUT_KEY = "approval";
18
22
  /** The approval elicitation form: one required boolean. */
@@ -27,8 +31,22 @@ export declare const APPROVAL_REQUESTED_SCHEMA: {
27
31
  };
28
32
  readonly required: readonly ['approve'];
29
33
  };
30
- /** A call held for the human's approval, as recorded by the middleware. */
31
- export interface ApprovalHold {
34
+ /**
35
+ * The step of an `afd-batch` or `afd-pipe` an up-front approval was asked for, kept with the
36
+ * question in the signed `requestState` (#1414). The request that brings the answer runs the step
37
+ * on this input instead of validating what was sent again, so a schema whose defaults differ from
38
+ * one validation to the next (a random id, the time) still runs exactly what the human approved.
39
+ */
40
+ export interface ApprovedStep {
41
+ /** The step's position in the request, 0-based. */
42
+ index: number;
43
+ /** The canonical JSON of the step's validated input, as the human was shown it. */
44
+ input: string;
45
+ /** A digest of the whole request as sent: the input serves that request and no other. */
46
+ call: string;
47
+ }
48
+ /** One approval asked of the human: a command, its validated input and the actor. */
49
+ export interface ApprovalQuestion {
32
50
  /** Keyed digest of the command, its validated input and the actor, under the signing key. */
33
51
  binding: string;
34
52
  /** The same digest under every verification key: earlier answers to any of them are dropped. */
@@ -39,21 +57,45 @@ export interface ApprovalHold {
39
57
  expiresAt: number;
40
58
  /** MAC of the binding, nonce and expiry under the approval secret. */
41
59
  mac: string;
60
+ /** For an up-front approval, the step asked about (left out when its input is too long to keep). */
61
+ step?: ApprovedStep;
62
+ }
63
+ /** A call held for the human's approval, as recorded by the middleware. */
64
+ export interface ApprovalHold extends ApprovalQuestion {
42
65
  /** The question shown to the human. */
43
66
  message: string;
44
67
  }
45
- /** The human's answer to an earlier approval elicitation for one binding. */
46
- export type ApprovalAnswer = {
47
- kind: 'accept';
68
+ /**
69
+ * A whole `afd-batch` or `afd-pipe` held for the human's approval: one elicitation, one
70
+ * question per gated step, each answered by the same form.
71
+ */
72
+ export interface StepsHold {
73
+ questions: readonly ApprovalQuestion[];
74
+ /** The question shown to the human, listing every gated step. */
75
+ message: string;
76
+ }
77
+ /** An accepted approval as the request carries it: its binding, nonce, expiry and MAC. */
78
+ export interface AcceptedApproval {
48
79
  binding: string;
49
80
  nonce: string;
50
81
  expiresAt: number;
51
82
  mac: string;
52
- } | {
83
+ /** The step the approval was asked for, when the question kept it. */
84
+ step?: ApprovedStep;
85
+ }
86
+ /** The human's answer to an earlier approval elicitation for one binding. */
87
+ export type ApprovalAnswer = ({
88
+ kind: 'accept';
89
+ } & AcceptedApproval) | {
53
90
  kind: 'decline';
54
91
  } | {
55
92
  kind: 'missing';
56
93
  };
94
+ /** Every approval answer a request carries: those accepted, and the bindings declined. */
95
+ export interface ApprovalAnswers {
96
+ accepted: readonly AcceptedApproval[];
97
+ declined: readonly string[];
98
+ }
57
99
  /** What one MCP `tools/call` offers the approval middleware. */
58
100
  export interface ApprovalRelay {
59
101
  /** Name the command this tool call routes to; only that command can claim the relay. */
@@ -70,6 +112,108 @@ export interface ApprovalRelay {
70
112
  answer(bindings: readonly string[]): Promise<ApprovalAnswer>;
71
113
  /** Record that the call needs the human's approval; the lane asks once the call returns. */
72
114
  hold(hold: ApprovalHold): void;
115
+ /** Every approval answer this request carries, for an up-front approval of several steps. */
116
+ answers(): Promise<ApprovalAnswers>;
117
+ /** Record that a batch or pipeline needs the human's approval of `hold`'s steps. */
118
+ holdSteps(hold: StepsHold): void;
119
+ /**
120
+ * The up-front approval of an `afd-batch` or `afd-pipe` request, which runs `commands` (#459).
121
+ * Only the MCP lane offers one, so a host that never serves MCP does not load its code.
122
+ */
123
+ upFront?(tool: UpFrontApproval['tool'], request: BatchRequest | PipelineRequest, commands: readonly ZodCommandDefinition[]): UpFrontApproval;
124
+ }
125
+ /** What the up-front gate needs from the approval middleware. */
126
+ export interface UpFrontDeps {
127
+ clock: Clock;
128
+ /** Whether `command`'s policy holds this input. */
129
+ requiresApproval(command: string, input: unknown, context: CommandContext): Promise<boolean>;
130
+ /** Whether `command`'s policy could hold some input ('required' or a function). */
131
+ mayRequireApproval(command: string, context: CommandContext): boolean;
132
+ /**
133
+ * The bindings of an up-front approval, one per key, the signing key's first: a keyed digest of
134
+ * the call (its {@link callTags} under that key), the command, its input and the actor.
135
+ */
136
+ bindings(tags: readonly string[], command: string, input: string, actor: string): Promise<string[]>;
137
+ /** The call's tag under each key: a keyed digest of the whole request as sent. */
138
+ callTags(call: string): Promise<string[]>;
139
+ /** Whether an accepted approval's MAC verifies for `bindings` and it has not expired. */
140
+ genuine(answer: AcceptedApproval, bindings: readonly string[], now: number): Promise<boolean>;
141
+ /** Spend a single-use nonce; `true` when it was fresh (or reuse is allowed). */
142
+ spend(nonce: string, expiresAt: number, now: number): Promise<boolean>;
143
+ /** A fresh question (nonce, expiry and MAC) for `bindings`. */
144
+ question(bindings: readonly string[], now: number): Promise<ApprovalQuestion>;
145
+ summarize(command: string, input: unknown, context: CommandContext): string;
146
+ }
147
+ /** One step of an `afd-batch` or `afd-pipe`, as the up-front approval sees it. */
148
+ export interface UpFrontStep {
149
+ /** The step's position in the request, 0-based as in its results. */
150
+ index: number;
151
+ command: string;
152
+ /**
153
+ * Whether the step's input comes from an earlier step (`$prev`, `$first` or `$steps`), so its
154
+ * input is not known until the pipeline runs.
155
+ */
156
+ dynamic: boolean;
157
+ /** The validated input of a step that is not dynamic; absent when it does not validate. */
158
+ input?: unknown;
159
+ /** Whether {@link input} holds the validated input. */
160
+ valid: boolean;
161
+ /**
162
+ * The input as sent (after `$input` references are resolved), as canonical JSON: how the engine
163
+ * finds the step it is about to run. Absent when {@link valid} is false.
164
+ */
165
+ sent?: string;
166
+ }
167
+ /**
168
+ * The up-front approval of one `afd-batch` or `afd-pipe` call that can carry a form elicitation
169
+ * (#459). The approval middleware decides it once, before any step's handler runs: every step
170
+ * runs, each gated step on its own single-use approval, or none does.
171
+ */
172
+ export interface UpFrontApproval {
173
+ tool: 'afd-batch' | 'afd-pipe';
174
+ /**
175
+ * The whole request as sent (its steps or commands, inputs, conditions and options), as
176
+ * canonical JSON: every approval is bound to it, so it covers this call and no other.
177
+ */
178
+ call: string;
179
+ /** Whether a step runs only under a condition (`when`), so one may run while another is skipped. */
180
+ conditional: boolean;
181
+ /**
182
+ * The call's steps, worked out once, when the engine or the middleware first asks for them. A
183
+ * step the human already approved in an earlier round of this request has the input approved
184
+ * then; any other is validated now.
185
+ */
186
+ steps(): Promise<readonly UpFrontStep[]>;
187
+ /**
188
+ * The input validated up front for a step that runs `command` on `input` as sent, handed out
189
+ * once per step (#1414). The server runs the step on it instead of on a second validation's
190
+ * result, so the input that runs is the one the human approved even when the schema's defaults
191
+ * differ from one validation to the next (a random id, the time). `undefined` for a command
192
+ * with no approval policy and for a step that is not known up front or did not validate: the
193
+ * step runs on its own validation, as usual.
194
+ */
195
+ validated(command: string, input: unknown): Promise<{
196
+ input: unknown;
197
+ } | undefined>;
198
+ /**
199
+ * The server's definition of `command` (its approval policy and prompt), so the middleware
200
+ * decides every step from the command that step runs.
201
+ */
202
+ command(command: string): Pick<ZodCommandDefinition, 'name' | 'approval' | 'confirmPrompt'> | undefined;
203
+ /**
204
+ * Run one step through the up-front gate, with the approval middleware's own keys, nonce
205
+ * store and policies (`deps`): nothing runs until the whole call is approved.
206
+ */
207
+ run(deps: UpFrontDeps, command: string, input: unknown, context: CommandContext,
208
+ /** Lets the step through, admitting it on the canonical input it was decided on. */
209
+ next: (canonical: string | undefined) => Promise<CommandResult>): Promise<CommandResult>;
210
+ /** The call's relay, which reads the human's answers and records the hold. */
211
+ relay: ApprovalRelay;
212
+ /**
213
+ * Set by the middleware when nothing may run (a gated step whose input is not known up front,
214
+ * a decline, or a pending question): the router answers with this instead of the run.
215
+ */
216
+ refusal?: CommandError;
73
217
  }
74
218
  /** Return a copy of `context` bound to `relay`. */
75
219
  export declare function bindApprovalRelay(context: CommandContext, relay: ApprovalRelay): CommandContext;
@@ -80,6 +224,25 @@ export declare function bindApprovalRelay(context: CommandContext, relay: Approv
80
224
  export declare function withoutApprovalRelay(context: CommandContext): CommandContext;
81
225
  /** The relay bound to `context`, if any. */
82
226
  export declare function approvalRelay(context: CommandContext | undefined): ApprovalRelay | undefined;
227
+ /**
228
+ * Return a copy of `context` for the steps of an `afd-batch` or `afd-pipe` whose call can carry a
229
+ * form elicitation: its relay never asks for one step, and `upFront` asks once for them all.
230
+ */
231
+ export declare function bindUpFrontApproval(context: CommandContext, upFront: UpFrontApproval): CommandContext;
232
+ /** The up-front approval bound to `context`, if any. */
233
+ export declare function upFrontApproval(context: CommandContext | undefined): UpFrontApproval | undefined;
234
+ /**
235
+ * Remove the up-front approval from a step's own context before its handler runs, so a command
236
+ * the handler runs never takes a step's approval. Each step runs with a context of its own. The
237
+ * approval middleware does this (not the engine, which keeps the gate out of `/direct` hosts), so
238
+ * only a handler behind an `mcp-elicitation` approval middleware is covered. The approval is read
239
+ * twice: by that middleware, and by the engine's up-front step hook, which takes the step's
240
+ * approved input (#1414). Without the middleware nothing is gated, so a nested command could at
241
+ * most take a later step's approved input as its own, never an approval. A retry middleware placed
242
+ * before it retries the step on the ordinary single-command path, which holds it again.
243
+ */
244
+ export declare function releaseUpFrontApproval(context: CommandContext): void;
245
+ export declare function shownInput(input: string): string;
83
246
  /** The question of a relayed approval: the summary, then what exactly would run. */
84
247
  export declare function relayMessage(summary: string, command: string, input: string, note?: string): string;
85
248
  //# sourceMappingURL=approval-relay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"approval-relay.d.ts","sourceRoot":"","sources":["../src/approval-relay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,2DAA2D;AAC3D,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAE7C,2DAA2D;AAC3D,eAAO,MAAM,yBAAyB;aACrC,IAAI,EAAE,QAAQ;aACd,UAAU;iBACT,OAAO;qBACN,IAAI,EAAE,SAAS;qBACf,KAAK,EAAE,SAAS;qBAChB,WAAW,EAAE,0BAA0B;;;aAGzC,QAAQ,YAAG,SAAS;CACX,CAAC;AAEX,2EAA2E;AAC3E,MAAM,WAAW,YAAY;IAC5B,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;IAChB,gGAAgG;IAChG,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,6EAA6E;AAC7E,MAAM,MAAM,cAAc,GACvB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,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;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAEpE;AAKD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,GACX,MAAM,CAQR"}
@@ -10,7 +10,10 @@
10
10
  * with `input_required` instead of the held result.
11
11
  *
12
12
  * `afd-batch` and `afd-pipe` replace the relay with one that never asks, because asking mid-run
13
- * would run the earlier steps again on the retry.
13
+ * would run the earlier steps again on the retry. Instead (#459), the router binds an
14
+ * {@link UpFrontApproval} for the whole call: before any step runs, the approval middleware works
15
+ * out every gated step's input and asks once for all of them, or refuses the call when a gated
16
+ * pipeline step's input comes from an earlier step.
14
17
  */
15
18
  /** The `inputRequests` key of the approval elicitation. */
16
19
  export const APPROVAL_INPUT_KEY = 'approval';
@@ -27,12 +30,15 @@ export const APPROVAL_REQUESTED_SCHEMA = {
27
30
  required: ['approve'],
28
31
  };
29
32
  const RELAY = Symbol('afd.approvalRelay');
33
+ const UP_FRONT = Symbol('afd.upFrontApproval');
30
34
  /** A relay that never asks: the steps of `afd-batch` and `afd-pipe` get it. */
31
35
  const NEVER_ASKS = {
32
36
  route() { },
33
37
  claim: () => false,
34
38
  answer: async () => ({ kind: 'missing' }),
35
39
  hold() { },
40
+ answers: async () => ({ accepted: [], declined: [] }),
41
+ holdSteps() { },
36
42
  };
37
43
  /** Return a copy of `context` bound to `relay`. */
38
44
  export function bindApprovalRelay(context, relay) {
@@ -52,11 +58,44 @@ export function withoutApprovalRelay(context) {
52
58
  export function approvalRelay(context) {
53
59
  return context?.[RELAY];
54
60
  }
61
+ /**
62
+ * Return a copy of `context` for the steps of an `afd-batch` or `afd-pipe` whose call can carry a
63
+ * form elicitation: its relay never asks for one step, and `upFront` asks once for them all.
64
+ */
65
+ export function bindUpFrontApproval(context, upFront) {
66
+ const bound = { ...context, [RELAY]: NEVER_ASKS, [UP_FRONT]: upFront };
67
+ return bound;
68
+ }
69
+ /** The up-front approval bound to `context`, if any. */
70
+ export function upFrontApproval(context) {
71
+ return context?.[UP_FRONT];
72
+ }
73
+ /**
74
+ * Remove the up-front approval from a step's own context before its handler runs, so a command
75
+ * the handler runs never takes a step's approval. Each step runs with a context of its own. The
76
+ * approval middleware does this (not the engine, which keeps the gate out of `/direct` hosts), so
77
+ * only a handler behind an `mcp-elicitation` approval middleware is covered. The approval is read
78
+ * twice: by that middleware, and by the engine's up-front step hook, which takes the step's
79
+ * approved input (#1414). Without the middleware nothing is gated, so a nested command could at
80
+ * most take a later step's approved input as its own, never an approval. A retry middleware placed
81
+ * before it retries the step on the ordinary single-command path, which holds it again.
82
+ */
83
+ export function releaseUpFrontApproval(context) {
84
+ delete context[UP_FRONT];
85
+ }
55
86
  /** Longest input shown in an approval elicitation, in characters. */
56
87
  const MAX_SHOWN_INPUT = 1000;
88
+ export function shownInput(input) {
89
+ return input.length > MAX_SHOWN_INPUT ? `${input.slice(0, MAX_SHOWN_INPUT)}…` : input;
90
+ }
57
91
  /** The question of a relayed approval: the summary, then what exactly would run. */
58
92
  export function relayMessage(summary, command, input, note) {
59
- const shown = input.length > MAX_SHOWN_INPUT ? `${input.slice(0, MAX_SHOWN_INPUT)}…` : input;
60
- return [...(note ? [note] : []), summary, '', `Command: ${command}`, `Input: ${shown}`].join('\n');
93
+ return [
94
+ ...(note ? [note] : []),
95
+ summary,
96
+ '',
97
+ `Command: ${command}`,
98
+ `Input: ${shownInput(input)}`,
99
+ ].join('\n');
61
100
  }
62
101
  //# sourceMappingURL=approval-relay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"approval-relay.js","sourceRoot":"","sources":["../src/approval-relay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,2DAA2D;AAC3D,MAAM,CAAC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AED,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAC3B,OAAe,EACf,OAAe,EACf,KAAa,EACb,IAAa;IAEb,OAAO;QACN,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO;QACP,EAAE;QACF,YAAY,OAAO,EAAE;QACrB,UAAU,UAAU,CAAC,KAAK,CAAC,EAAE;KAC7B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @fileoverview One up-front approval for an `afd-batch` or `afd-pipe` (#459, option A).
3
+ *
4
+ * Asking mid-run would run the earlier steps again on the retry, so the approval middleware
5
+ * decides the whole call before any step's handler runs, the first time a step reaches it:
6
+ *
7
+ * - a gated pipeline step whose input comes from an earlier step (`$prev`, `$first`, `$steps`)
8
+ * cannot be shown to the human up front, so nothing runs and the agent is told to split the
9
+ * pipeline there;
10
+ * - otherwise, when the request carries the human's acceptance of every gated step (each bound to
11
+ * its command, canonical validated input and actor, with a MAC, an expiry and a nonce), each
12
+ * nonce is spent and the call runs: each gated step then takes one approval matching its own
13
+ * binding, once. The engine runs every step on the input validated here, never on a second
14
+ * validation of it (#1414), so the input that runs is the one the human was shown;
15
+ * - a decline refuses the call; anything else asks once, listing every gated step.
16
+ *
17
+ * While the plan is not to run, every step answers without calling `next`, and the router answers
18
+ * the call with the refusal (or the lane with the elicitation), so no handler runs.
19
+ *
20
+ * Only the MCP lane loads this module (through its relay's `upFront`): a host that runs commands
21
+ * in process, with or without the approval middleware or the tool surface, never does.
22
+ */
23
+ import type { BatchRequest, PipelineRequest } from '@lushly-dev/afd-core';
24
+ import { type ApprovalRelay, type UpFrontApproval } from './approval-relay.js';
25
+ import type { ZodCommandDefinition } from './schema.js';
26
+ /** The most gated steps one question lists; a person cannot weigh more at once. */
27
+ export declare const MAX_UP_FRONT_APPROVALS = 20;
28
+ /**
29
+ * The most characters (UTF-16 code units) of approved input one question keeps in the
30
+ * `requestState`, over all its steps. A step past it is validated again by the request that brings the answer, as every step
31
+ * was before #1414.
32
+ */
33
+ export declare const MAX_KEPT_INPUT = 32768;
34
+ /**
35
+ * The up-front approval of one `afd-batch` or `afd-pipe` request that can carry a form
36
+ * elicitation, asking and reading answers through `relay`. Its steps are worked out only when a
37
+ * step whose command has an approval policy is about to run, or an approval middleware asks.
38
+ */
39
+ export declare function createUpFrontApproval(relay: ApprovalRelay, tool: UpFrontApproval['tool'], request: BatchRequest | PipelineRequest, commands: readonly ZodCommandDefinition[]): UpFrontApproval;
40
+ //# sourceMappingURL=approval-up-front.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-up-front.d.ts","sourceRoot":"","sources":["../src/approval-up-front.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EACX,YAAY,EAIZ,eAAe,EACf,MAAM,sBAAsB,CAAC;AAU9B,OAAO,EAEN,KAAK,aAAa,EAGlB,KAAK,eAAe,EAGpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAWxD,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAS,CAAC;AAQrC;;;;GAIG;AACH,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,YAAY,GAAG,eAAe,EACvC,QAAQ,EAAE,SAAS,oBAAoB,EAAE,GACvC,eAAe,CAiEjB"}