@lushly-dev/afd-server 2.4.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.
Files changed (279) hide show
  1. package/README.md +239 -56
  2. package/dist/admission.d.ts +137 -0
  3. package/dist/admission.d.ts.map +1 -0
  4. package/dist/admission.js +144 -0
  5. package/dist/admission.js.map +1 -0
  6. package/dist/app-call-registry.d.ts +31 -0
  7. package/dist/app-call-registry.d.ts.map +1 -0
  8. package/dist/app-call-registry.js +64 -0
  9. package/dist/app-call-registry.js.map +1 -0
  10. package/dist/approval-admission.d.ts +139 -0
  11. package/dist/approval-admission.d.ts.map +1 -0
  12. package/dist/approval-admission.js +252 -0
  13. package/dist/approval-admission.js.map +1 -0
  14. package/dist/approval-crypto.d.ts +37 -17
  15. package/dist/approval-crypto.d.ts.map +1 -1
  16. package/dist/approval-crypto.js +84 -75
  17. package/dist/approval-crypto.js.map +1 -1
  18. package/dist/approval-process-state.d.ts +21 -0
  19. package/dist/approval-process-state.d.ts.map +1 -0
  20. package/dist/approval-process-state.js +29 -0
  21. package/dist/approval-process-state.js.map +1 -0
  22. package/dist/approval-relay.d.ts +192 -9
  23. package/dist/approval-relay.d.ts.map +1 -1
  24. package/dist/approval-relay.js +45 -9
  25. package/dist/approval-relay.js.map +1 -1
  26. package/dist/approval-up-front.d.ts +40 -0
  27. package/dist/approval-up-front.d.ts.map +1 -0
  28. package/dist/approval-up-front.js +409 -0
  29. package/dist/approval-up-front.js.map +1 -0
  30. package/dist/approval.d.ts +65 -12
  31. package/dist/approval.d.ts.map +1 -1
  32. package/dist/approval.js +311 -47
  33. package/dist/approval.js.map +1 -1
  34. package/dist/approver.d.ts +84 -0
  35. package/dist/approver.d.ts.map +1 -0
  36. package/dist/approver.js +107 -0
  37. package/dist/approver.js.map +1 -0
  38. package/dist/auth-middleware-check.d.ts +23 -0
  39. package/dist/auth-middleware-check.d.ts.map +1 -0
  40. package/dist/auth-middleware-check.js +48 -0
  41. package/dist/auth-middleware-check.js.map +1 -0
  42. package/dist/bootstrap/afd-context.d.ts.map +1 -1
  43. package/dist/bootstrap/afd-context.js +27 -3
  44. package/dist/bootstrap/afd-context.js.map +1 -1
  45. package/dist/bootstrap/afd-docs.d.ts.map +1 -1
  46. package/dist/bootstrap/afd-docs.js +4 -0
  47. package/dist/bootstrap/afd-docs.js.map +1 -1
  48. package/dist/bootstrap/afd-help.d.ts +4 -1
  49. package/dist/bootstrap/afd-help.d.ts.map +1 -1
  50. package/dist/bootstrap/afd-help.js +19 -4
  51. package/dist/bootstrap/afd-help.js.map +1 -1
  52. package/dist/bootstrap/described-command.d.ts +3 -1
  53. package/dist/bootstrap/described-command.d.ts.map +1 -1
  54. package/dist/bootstrap/described-command.js.map +1 -1
  55. package/dist/command-allow.d.ts +4 -4
  56. package/dist/command-allow.d.ts.map +1 -1
  57. package/dist/command-allow.js +10 -15
  58. package/dist/command-allow.js.map +1 -1
  59. package/dist/command-routing.d.ts +56 -8
  60. package/dist/command-routing.d.ts.map +1 -1
  61. package/dist/command-routing.js +82 -16
  62. package/dist/command-routing.js.map +1 -1
  63. package/dist/command-timeout.d.ts +17 -0
  64. package/dist/command-timeout.d.ts.map +1 -0
  65. package/dist/command-timeout.js +99 -0
  66. package/dist/command-timeout.js.map +1 -0
  67. package/dist/confirmation-gate.d.ts +7 -7
  68. package/dist/confirmation-gate.d.ts.map +1 -1
  69. package/dist/confirmation-gate.js +26 -12
  70. package/dist/confirmation-gate.js.map +1 -1
  71. package/dist/confirmations.d.ts +28 -3
  72. package/dist/confirmations.d.ts.map +1 -1
  73. package/dist/confirmations.js +6 -7
  74. package/dist/confirmations.js.map +1 -1
  75. package/dist/context-fields.d.ts +16 -1
  76. package/dist/context-fields.d.ts.map +1 -1
  77. package/dist/context-fields.js +30 -13
  78. package/dist/context-fields.js.map +1 -1
  79. package/dist/context-scope.d.ts +3 -3
  80. package/dist/context-scope.d.ts.map +1 -1
  81. package/dist/context-scope.js +7 -8
  82. package/dist/context-scope.js.map +1 -1
  83. package/dist/define-core.d.ts +63 -1
  84. package/dist/define-core.d.ts.map +1 -1
  85. package/dist/define-core.js +27 -4
  86. package/dist/define-core.js.map +1 -1
  87. package/dist/define.d.ts +4 -3
  88. package/dist/define.d.ts.map +1 -1
  89. package/dist/define.js +1 -1
  90. package/dist/define.js.map +1 -1
  91. package/dist/direct-registry.d.ts +54 -8
  92. package/dist/direct-registry.d.ts.map +1 -1
  93. package/dist/direct-registry.js +64 -8
  94. package/dist/direct-registry.js.map +1 -1
  95. package/dist/direct-tool-surface.d.ts +1 -1
  96. package/dist/direct-tool-surface.d.ts.map +1 -1
  97. package/dist/direct-tool-surface.js +28 -6
  98. package/dist/direct-tool-surface.js.map +1 -1
  99. package/dist/direct.d.ts +6 -2
  100. package/dist/direct.d.ts.map +1 -1
  101. package/dist/direct.js +4 -1
  102. package/dist/direct.js.map +1 -1
  103. package/dist/elicitation-state.d.ts +5 -1
  104. package/dist/elicitation-state.d.ts.map +1 -1
  105. package/dist/elicitation-state.js +4 -1
  106. package/dist/elicitation-state.js.map +1 -1
  107. package/dist/execution.d.ts +52 -6
  108. package/dist/execution.d.ts.map +1 -1
  109. package/dist/execution.js +183 -19
  110. package/dist/execution.js.map +1 -1
  111. package/dist/host-state.d.ts +81 -0
  112. package/dist/host-state.d.ts.map +1 -0
  113. package/dist/host-state.js +62 -0
  114. package/dist/host-state.js.map +1 -0
  115. package/dist/http-handler.d.ts +48 -11
  116. package/dist/http-handler.d.ts.map +1 -1
  117. package/dist/http-handler.js +207 -58
  118. package/dist/http-handler.js.map +1 -1
  119. package/dist/http-security.d.ts +14 -1
  120. package/dist/http-security.d.ts.map +1 -1
  121. package/dist/http-security.js +79 -17
  122. package/dist/http-security.js.map +1 -1
  123. package/dist/http-sessions.d.ts +45 -5
  124. package/dist/http-sessions.d.ts.map +1 -1
  125. package/dist/http-sessions.js +52 -10
  126. package/dist/http-sessions.js.map +1 -1
  127. package/dist/http-sse.d.ts +9 -0
  128. package/dist/http-sse.d.ts.map +1 -1
  129. package/dist/http-sse.js +12 -3
  130. package/dist/http-sse.js.map +1 -1
  131. package/dist/human-relay.d.ts +195 -0
  132. package/dist/human-relay.d.ts.map +1 -0
  133. package/dist/human-relay.js +670 -0
  134. package/dist/human-relay.js.map +1 -0
  135. package/dist/idempotency-step.d.ts +231 -0
  136. package/dist/idempotency-step.d.ts.map +1 -0
  137. package/dist/idempotency-step.js +389 -0
  138. package/dist/idempotency-step.js.map +1 -0
  139. package/dist/idempotency-store.d.ts +107 -0
  140. package/dist/idempotency-store.d.ts.map +1 -0
  141. package/dist/idempotency-store.js +100 -0
  142. package/dist/idempotency-store.js.map +1 -0
  143. package/dist/index.d.ts +18 -8
  144. package/dist/index.d.ts.map +1 -1
  145. package/dist/index.js +15 -4
  146. package/dist/index.js.map +1 -1
  147. package/dist/instance-state.d.ts +53 -0
  148. package/dist/instance-state.d.ts.map +1 -0
  149. package/dist/instance-state.js +94 -0
  150. package/dist/instance-state.js.map +1 -0
  151. package/dist/journal-off-tape.d.ts +52 -0
  152. package/dist/journal-off-tape.d.ts.map +1 -0
  153. package/dist/journal-off-tape.js +150 -0
  154. package/dist/journal-off-tape.js.map +1 -0
  155. package/dist/journal-replay.d.ts.map +1 -1
  156. package/dist/journal-replay.js +48 -3
  157. package/dist/journal-replay.js.map +1 -1
  158. package/dist/journal-view.d.ts +50 -0
  159. package/dist/journal-view.d.ts.map +1 -0
  160. package/dist/journal-view.js +214 -0
  161. package/dist/journal-view.js.map +1 -0
  162. package/dist/journal.d.ts +34 -6
  163. package/dist/journal.d.ts.map +1 -1
  164. package/dist/journal.js +183 -47
  165. package/dist/journal.js.map +1 -1
  166. package/dist/json-rpc.d.ts +3 -2
  167. package/dist/json-rpc.d.ts.map +1 -1
  168. package/dist/json-rpc.js +5 -3
  169. package/dist/json-rpc.js.map +1 -1
  170. package/dist/lazy-tools.d.ts +27 -2
  171. package/dist/lazy-tools.d.ts.map +1 -1
  172. package/dist/lazy-tools.js +22 -4
  173. package/dist/lazy-tools.js.map +1 -1
  174. package/dist/mcp-auth-bearer.d.ts +2 -0
  175. package/dist/mcp-auth-bearer.d.ts.map +1 -1
  176. package/dist/mcp-auth-bearer.js +1 -1
  177. package/dist/mcp-auth-bearer.js.map +1 -1
  178. package/dist/mcp-auth-dispatch.d.ts +38 -0
  179. package/dist/mcp-auth-dispatch.d.ts.map +1 -0
  180. package/dist/mcp-auth-dispatch.js +113 -0
  181. package/dist/mcp-auth-dispatch.js.map +1 -0
  182. package/dist/mcp-auth-jwt.d.ts +3 -2
  183. package/dist/mcp-auth-jwt.d.ts.map +1 -1
  184. package/dist/mcp-auth-jwt.js.map +1 -1
  185. package/dist/mcp-auth-resource.d.ts +6 -2
  186. package/dist/mcp-auth-resource.d.ts.map +1 -1
  187. package/dist/mcp-auth-resource.js +6 -5
  188. package/dist/mcp-auth-resource.js.map +1 -1
  189. package/dist/mcp-auth-scopes.d.ts +84 -0
  190. package/dist/mcp-auth-scopes.d.ts.map +1 -0
  191. package/dist/mcp-auth-scopes.js +125 -0
  192. package/dist/mcp-auth-scopes.js.map +1 -0
  193. package/dist/mcp-auth-view.d.ts +50 -0
  194. package/dist/mcp-auth-view.d.ts.map +1 -0
  195. package/dist/mcp-auth-view.js +179 -0
  196. package/dist/mcp-auth-view.js.map +1 -0
  197. package/dist/mcp-auth.d.ts +94 -3
  198. package/dist/mcp-auth.d.ts.map +1 -1
  199. package/dist/mcp-auth.js +241 -23
  200. package/dist/mcp-auth.js.map +1 -1
  201. package/dist/mcp-modern.d.ts +80 -6
  202. package/dist/mcp-modern.d.ts.map +1 -1
  203. package/dist/mcp-modern.js +378 -91
  204. package/dist/mcp-modern.js.map +1 -1
  205. package/dist/meta-argument.d.ts +9 -8
  206. package/dist/meta-argument.d.ts.map +1 -1
  207. package/dist/meta-argument.js +28 -10
  208. package/dist/meta-argument.js.map +1 -1
  209. package/dist/meta-tools.js +2 -2
  210. package/dist/meta-tools.js.map +1 -1
  211. package/dist/middleware.d.ts +16 -1
  212. package/dist/middleware.d.ts.map +1 -1
  213. package/dist/middleware.js +57 -10
  214. package/dist/middleware.js.map +1 -1
  215. package/dist/output-budget.d.ts +77 -0
  216. package/dist/output-budget.d.ts.map +1 -0
  217. package/dist/output-budget.js +202 -0
  218. package/dist/output-budget.js.map +1 -0
  219. package/dist/principal-binding.js +1 -1
  220. package/dist/principal-binding.js.map +1 -1
  221. package/dist/relay-evidence.d.ts +74 -0
  222. package/dist/relay-evidence.d.ts.map +1 -0
  223. package/dist/relay-evidence.js +143 -0
  224. package/dist/relay-evidence.js.map +1 -0
  225. package/dist/resources.d.ts +35 -10
  226. package/dist/resources.d.ts.map +1 -1
  227. package/dist/resources.js +59 -18
  228. package/dist/resources.js.map +1 -1
  229. package/dist/schema.d.ts +4 -3
  230. package/dist/schema.d.ts.map +1 -1
  231. package/dist/schema.js +3 -3
  232. package/dist/schema.js.map +1 -1
  233. package/dist/scope-view.d.ts +65 -0
  234. package/dist/scope-view.d.ts.map +1 -0
  235. package/dist/scope-view.js +45 -0
  236. package/dist/scope-view.js.map +1 -0
  237. package/dist/server-types.d.ts +182 -27
  238. package/dist/server-types.d.ts.map +1 -1
  239. package/dist/server-types.js.map +1 -1
  240. package/dist/server.d.ts +26 -0
  241. package/dist/server.d.ts.map +1 -1
  242. package/dist/server.js +403 -61
  243. package/dist/server.js.map +1 -1
  244. package/dist/skills.d.ts.map +1 -1
  245. package/dist/skills.js +99 -3
  246. package/dist/skills.js.map +1 -1
  247. package/dist/task-dispatch.d.ts +35 -0
  248. package/dist/task-dispatch.d.ts.map +1 -0
  249. package/dist/task-dispatch.js +25 -0
  250. package/dist/task-dispatch.js.map +1 -0
  251. package/dist/tasks-runtime.d.ts +115 -0
  252. package/dist/tasks-runtime.d.ts.map +1 -0
  253. package/dist/tasks-runtime.js +760 -0
  254. package/dist/tasks-runtime.js.map +1 -0
  255. package/dist/tasks.d.ts +237 -0
  256. package/dist/tasks.d.ts.map +1 -0
  257. package/dist/tasks.js +321 -0
  258. package/dist/tasks.js.map +1 -0
  259. package/dist/tool-router.d.ts +68 -3
  260. package/dist/tool-router.d.ts.map +1 -1
  261. package/dist/tool-router.js +293 -70
  262. package/dist/tool-router.js.map +1 -1
  263. package/dist/tools.d.ts +32 -0
  264. package/dist/tools.d.ts.map +1 -1
  265. package/dist/tools.js +162 -55
  266. package/dist/tools.js.map +1 -1
  267. package/dist/up-front-steps.d.ts +35 -0
  268. package/dist/up-front-steps.d.ts.map +1 -0
  269. package/dist/up-front-steps.js +159 -0
  270. package/dist/up-front-steps.js.map +1 -0
  271. package/dist/validation.d.ts +38 -3
  272. package/dist/validation.d.ts.map +1 -1
  273. package/dist/validation.js +118 -23
  274. package/dist/validation.js.map +1 -1
  275. package/dist/verified-credentials.d.ts +13 -5
  276. package/dist/verified-credentials.d.ts.map +1 -1
  277. package/dist/verified-credentials.js +43 -10
  278. package/dist/verified-credentials.js.map +1 -1
  279. package/package.json +15 -11
package/dist/index.d.ts CHANGED
@@ -45,28 +45,38 @@
45
45
  *
46
46
  * @packageDocumentation
47
47
  */
48
- export type { ApprovalDecision, ApprovalPolicy, CommandMiddleware, CreateHandoffOptions, ExposeOptions, HandoffCredentials, HandoffMetadata, HandoffProtocol, HandoffResult, ReconnectPolicy, TelemetryEvent, TelemetrySink, } from '@lushly-dev/afd-core';
49
- export { createHandoff, createTelemetryEvent, defaultExpose, defaultReconnectPolicy, error, failure, getHandoffProtocol, isFailure, isHandoff, isHandoffCommand, isHandoffProtocol, isReconnectPolicy, isSuccess, isTelemetryEvent, success, } from '@lushly-dev/afd-core';
50
- export { type ApprovalCommand, type ApprovalMiddlewareOptions, type ApprovalNonceStore, type ApprovalRejection, type ApprovalRequest, type ApprovalSecret, createApprovalMiddleware, } from './approval.js';
48
+ export type { ApprovalDecision, ApprovalPolicy, CommandConfirmationMode, CommandMiddleware, CreateHandoffOptions, ExposeOptions, HandoffCredentials, HandoffMetadata, HandoffProtocol, HandoffResult, OutputBudget, ReconnectPolicy, TaskSupport, TelemetryEvent, TelemetrySink, } from '@lushly-dev/afd-core';
49
+ export { AFD_OUTPUT_BUDGET_META_KEY, createHandoff, createTelemetryEvent, defaultExpose, defaultReconnectPolicy, error, failure, getHandoffProtocol, isFailure, isHandoff, isHandoffCommand, isHandoffProtocol, isReconnectPolicy, isSuccess, isTelemetryEvent, MAX_OUTPUT_BUDGET_BYTES, success, } from '@lushly-dev/afd-core';
50
+ export type { OutputBudgetAsk, OutputBudgetReport } from '@lushly-dev/afd-core/commands';
51
+ export type { CallGrant } from '@lushly-dev/afd-core/internal/app-calls';
52
+ export { type AppCallRegistryOptions, createAppCallRegistry } from './app-call-registry.js';
53
+ export { type ApprovalCommand, type ApprovalMiddlewareOptions, type ApprovalNonceStore, type ApprovalRejection, type ApprovalRequest, type ApprovalSecret, type ApprovalSummary, createApprovalMiddleware, } from './approval.js';
54
+ export { AFD_APPROVAL_META_KEY, type ApproverPredicate } from './approver.js';
51
55
  export { type ContextState, createAfdContextEnterCommand, createAfdContextExitCommand, createAfdContextListCommand, createAfdDocsCommand, createAfdHelpCommand, createAfdSchemaCommand, createContextState, type DescribedCommand, getBootstrapCommands, } from './bootstrap/index.js';
56
+ export { DEFAULT_COMMAND_TIMEOUT_MS } from './command-timeout.js';
52
57
  export { createDirectRegistry, type DirectCommandRegistry, type DirectExecuteOptions, type DirectListToolsOptions, type DirectRegistryCommand, type DirectRegistryOptions, type DirectToolSurface, type ExposeInterface, } from './direct-registry.js';
53
58
  export { createDirectToolSurface, type DirectToolSurfaceOptions } from './direct-tool-surface.js';
54
59
  export { type HandoffCredentialsInput, type HandoffCredentialsOutput, HandoffCredentialsSchema, type HandoffMetadataInput, type HandoffMetadataOutput, HandoffMetadataSchema, type HandoffResultInput, type HandoffResultOutput, HandoffResultSchema, } from './handoff-schema.js';
55
- export { createJournalMiddleware, type JournalMiddlewareOptions } from './journal.js';
60
+ export { allowsUrlElicitation, type HumanRelay, inputDigest, isDecisionId, isRelayUrl, type PendingListOutcome, RELAY_INPUT_KEY, type RelayBeginResult, type RelayCall, type RelayOutcome, type RelayPending, type RelayPrompt, } from './human-relay.js';
61
+ export { createIdempotencyStep, DEFAULT_IDEMPOTENCY_LEASE_MS, DEFAULT_IDEMPOTENCY_TTL_MS, type IdempotencyOptions, type IdempotencyStep, type IdempotencyStepDeps, } from './idempotency-step.js';
62
+ export { type IdempotencyRecord, type IdempotencyReservationRequest, type IdempotencyReserveOutcome, type IdempotencySettlement, type IdempotencyStore, InMemoryIdempotencyStore, type InMemoryIdempotencyStoreOptions, } from './idempotency-store.js';
63
+ export { createJournalMiddleware, JOURNAL_RESULT_UNSERIALIZABLE, type JournalMiddlewareOptions, type JournalRedactInfo, } from './journal.js';
56
64
  export { type JournalReplayTarget, type ReplayDifference, type ReplayEntryReport, type ReplayJournalOptions, type ReplayReport, type ReplayStatus, replayJournal, } from './journal-replay.js';
57
- export { type AuthRefusal, credentialsActor, type McpAuthOptions } from './mcp-auth.js';
65
+ export { type AuthRefusal, credentialsActor, type McpAuthOptions, type PreDispatch, type PreDispatchCheck, type PreDispatchCheckOptions, } from './mcp-auth.js';
58
66
  export { type BearerResult, extractBearer } from './mcp-auth-bearer.js';
59
67
  export { createIntrospectionVerifier, type IntrospectionVerifierOptions, isCompactJws, type JwksKeySourceOptions, type JwtIssuer, JwtVerifier, type JwtVerifierOptions, jwksKeySource, type KeyLookup, type KeySource, type TokenRequest, type TokenVerification, type TokenVerifier, } from './mcp-auth-jwt.js';
60
68
  export { audienceAccepts, createProtectedResource, isScopeToken, PROTECTED_RESOURCE_WELL_KNOWN, type ProtectedResource, type ProtectedResourceOptions, } from './mcp-auth-resource.js';
61
69
  export { AUTH_RULE_CODES, type AuthRuleCode, type Credentials, checkClaims, checkIntrospection, checkJwsHeader, checkKeyFit, createTokenRules, DEFAULT_CLOCK_SKEW_S, DEFAULT_MAX_TOKEN_LIFETIME_S, DEFAULT_SCOPE_LIMIT, MAX_CLAIM_CHARS, MAX_CLOCK_SKEW_S, parseScopeClaim, type RuleResult, SIGNING_ALGORITHMS, type SigningAlgorithm, type TokenRules, type TokenRulesOptions, } from './mcp-auth-rules.js';
70
+ export { type RequestDecision, requestDecision, ScopeChallenge, type ScopeDecision, type ScopeResolver, staticDecision, } from './mcp-auth-scopes.js';
62
71
  export { checkMetaEntry } from './meta-keys.js';
63
72
  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';
64
73
  export { type DateRange, type Pagination, type PaginationInput, patterns, type Search, type Sorting, type SortingInput, } from './patterns.js';
65
74
  export { credentialsBinding, type PrincipalCredentials, principalBinding, } from './principal-binding.js';
66
- export { MCP_APP_MIME_TYPE, type ResourceContents, type ResourceEntry, type ResourceProvider, type ResourcesOption, } from './resources.js';
67
- export { defineCommand, defineCommandWithSchema, getRequiredFields, isObjectSchema, type ZodCommandDefinition, type ZodCommandOptions, type ZodToJsonSchemaOptions, zodToJsonSchema, } from './schema.js';
75
+ export { MCP_APP_MIME_TYPE, type ResourceCaller, type ResourceContents, type ResourceEntry, type ResourceProvider, type ResourcesOption, } from './resources.js';
76
+ export { type AnyZodCommandDefinition, defineCommand, defineCommandWithSchema, getRequiredFields, isObjectSchema, type ZodCommandDefinition, type ZodCommandOptions, type ZodToJsonSchemaOptions, zodToJsonSchema, } from './schema.js';
68
77
  export { type ContextConfig, createMcpHandler, createMcpServer, isStdinPiped, MAX_FIRST_CLASS_TOOLS, type McpHandler, type McpHandlerOptions, type McpServer, type McpServerOptions, type McpTransport, type ToolStrategy, } from './server.js';
69
78
  export { type Skill, SkillCatalog, type SkillCatalogOptions, skillFromDirectory, } from './skills.js';
70
- export { type EnhancedValidationResult, formatEnhancedValidationError, formatValidationErrors, isValid, optional, type SchemaInfo, type ValidationError, ValidationException, type ValidationResult, validateInput, validateInputEnhanced, validateOrThrow, withDefault, } from './validation.js';
79
+ export { applyTaskChange, DEFAULT_MAX_RUNNING_TASKS, DEFAULT_MAX_TASK_RESULT_BYTES, DEFAULT_MAX_TASKS, DEFAULT_MAX_TASKS_PER_OWNER, DEFAULT_TASK_CHECK_INTERVAL_MS, DEFAULT_TASK_MAX_RUN_MS, DEFAULT_TASK_POLL_INTERVAL_MS, DEFAULT_TASK_TTL_MS, InMemoryTaskStore, type InMemoryTaskStoreOptions, isTaskExpired, isTerminalTaskStatus, TASKS_EXTENSION_ID, type TaskCall, type TaskChange, type TaskOptions, type TaskRecord, type TaskRpcError, type TaskStatus, type TaskStore, TaskStoreError, type TaskStoreErrorKind, taskFailureResult, taskOwnerMatches, } from './tasks.js';
80
+ export { DEFAULT_MAX_VALIDATION_ISSUES, type EnhancedValidationResult, formatEnhancedValidationError, formatValidationErrors, isValid, mapZodIssueCode, optional, type SchemaInfo, VALIDATION_ISSUE_CODES, type ValidationError, ValidationException, type ValidationIssueCode, type ValidationResult, validateInput, validateInputEnhanced, validateOrThrow, withDefault, } from './validation.js';
71
81
  export { isVerifiedCredentials } from './verified-credentials.js';
72
82
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAKH,YAAY,EACX,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,cAAc,EACd,aAAa,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,sBAAsB,E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B,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,eAAe,EACf,yBAAyB,EACzB,6BAA6B,EAC7B,iBAAiB,EACjB,2BAA2B,EAC3B,8BAA8B,EAC9B,uBAAuB,EACvB,6BAA6B,EAC7B,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,cAAc,EACd,KAAK,kBAAkB,EACvB,iBAAiB,EACjB,gBAAgB,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,6BAA6B,EAC7B,KAAK,wBAAwB,EAC7B,6BAA6B,EAC7B,sBAAsB,EACtB,OAAO,EACP,eAAe,EACf,QAAQ,EACR,KAAK,UAAU,EACf,sBAAsB,EACtB,KAAK,eAAe,EACpB,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -46,25 +46,34 @@
46
46
  * @packageDocumentation
47
47
  */
48
48
  // Re-export core helpers for convenience
49
- export { createHandoff, createTelemetryEvent, defaultExpose, defaultReconnectPolicy, error, failure, getHandoffProtocol, isFailure, isHandoff, isHandoffCommand, isHandoffProtocol, isReconnectPolicy, isSuccess, isTelemetryEvent, success, } from '@lushly-dev/afd-core';
49
+ export { AFD_OUTPUT_BUDGET_META_KEY, createHandoff, createTelemetryEvent, defaultExpose, defaultReconnectPolicy, error, failure, getHandoffProtocol, isFailure, isHandoff, isHandoffCommand, isHandoffProtocol, isReconnectPolicy, isSuccess, isTelemetryEvent, MAX_OUTPUT_BUDGET_BYTES, success, } from '@lushly-dev/afd-core';
50
+ export { createAppCallRegistry } from './app-call-registry.js';
50
51
  // Pre-execution approval gate
51
52
  export { createApprovalMiddleware, } from './approval.js';
53
+ // Approval evidence from an approver client (spec/approvals.md)
54
+ export { AFD_APPROVAL_META_KEY } from './approver.js';
52
55
  // Bootstrap tools
53
56
  export { createAfdContextEnterCommand, createAfdContextExitCommand, createAfdContextListCommand, createAfdDocsCommand, createAfdHelpCommand, createAfdSchemaCommand, createContextState, getBootstrapCommands, } from './bootstrap/index.js';
57
+ export { DEFAULT_COMMAND_TIMEOUT_MS } from './command-timeout.js';
54
58
  // Validating in-process registry for DirectClient
55
59
  export { createDirectRegistry, } from './direct-registry.js';
56
60
  export { createDirectToolSurface } from './direct-tool-surface.js';
57
61
  // Handoff schemas
58
62
  export { HandoffCredentialsSchema, HandoffMetadataSchema, HandoffResultSchema, } from './handoff-schema.js';
63
+ // Host-verified confirmation relay and input digest (spec/confirmations.md)
64
+ export { allowsUrlElicitation, inputDigest, isDecisionId, isRelayUrl, RELAY_INPUT_KEY, } from './human-relay.js';
65
+ export { createIdempotencyStep, DEFAULT_IDEMPOTENCY_LEASE_MS, DEFAULT_IDEMPOTENCY_TTL_MS, } from './idempotency-step.js';
66
+ export { InMemoryIdempotencyStore, } from './idempotency-store.js';
59
67
  // Command journal: recording middleware and replay
60
- export { createJournalMiddleware } from './journal.js';
68
+ export { createJournalMiddleware, JOURNAL_RESULT_UNSERIALIZABLE, } from './journal.js';
61
69
  export { replayJournal, } from './journal-replay.js';
62
70
  // MCP authorization on HTTP (spec/authorization.md, M1 to M5 and M7): createMcpHandler's `auth`
63
- export { credentialsActor } from './mcp-auth.js';
71
+ export { credentialsActor, } from './mcp-auth.js';
64
72
  export { extractBearer } from './mcp-auth-bearer.js';
65
73
  export { createIntrospectionVerifier, isCompactJws, JwtVerifier, jwksKeySource, } from './mcp-auth-jwt.js';
66
74
  export { audienceAccepts, createProtectedResource, isScopeToken, PROTECTED_RESOURCE_WELL_KNOWN, } from './mcp-auth-resource.js';
67
75
  export { AUTH_RULE_CODES, checkClaims, checkIntrospection, checkJwsHeader, checkKeyFit, createTokenRules, DEFAULT_CLOCK_SKEW_S, DEFAULT_MAX_TOKEN_LIFETIME_S, DEFAULT_SCOPE_LIMIT, MAX_CLAIM_CHARS, MAX_CLOCK_SKEW_S, parseScopeClaim, SIGNING_ALGORITHMS, } from './mcp-auth-rules.js';
76
+ export { requestDecision, ScopeChallenge, staticDecision, } from './mcp-auth-scopes.js';
68
77
  // MCP resources, tool `_meta` keys and Agent Skills (spec/mcp-resources.md)
69
78
  export { checkMetaEntry } from './meta-keys.js';
70
79
  // Middleware
@@ -78,7 +87,9 @@ export { MCP_APP_MIME_TYPE, } from './resources.js';
78
87
  export { defineCommand, defineCommandWithSchema, getRequiredFields, isObjectSchema, zodToJsonSchema, } from './schema.js';
79
88
  export { createMcpHandler, createMcpServer, isStdinPiped, MAX_FIRST_CLASS_TOOLS, } from './server.js';
80
89
  export { SkillCatalog, skillFromDirectory, } from './skills.js';
81
- export { formatEnhancedValidationError, formatValidationErrors, isValid, optional, ValidationException, validateInput, validateInputEnhanced, validateOrThrow, withDefault, } from './validation.js';
90
+ // MCP Tasks (spec/tasks.md; SEP-2663)
91
+ export { applyTaskChange, DEFAULT_MAX_RUNNING_TASKS, DEFAULT_MAX_TASK_RESULT_BYTES, DEFAULT_MAX_TASKS, DEFAULT_MAX_TASKS_PER_OWNER, DEFAULT_TASK_CHECK_INTERVAL_MS, DEFAULT_TASK_MAX_RUN_MS, DEFAULT_TASK_POLL_INTERVAL_MS, DEFAULT_TASK_TTL_MS, InMemoryTaskStore, isTaskExpired, isTerminalTaskStatus, TASKS_EXTENSION_ID, TaskStoreError, taskFailureResult, taskOwnerMatches, } from './tasks.js';
92
+ export { DEFAULT_MAX_VALIDATION_ISSUES, formatEnhancedValidationError, formatValidationErrors, isValid, mapZodIssueCode, optional, VALIDATION_ISSUE_CODES, ValidationException, validateInput, validateInputEnhanced, validateOrThrow, withDefault, } from './validation.js';
82
93
  // The brand on credentials afd-server verified itself (also `@lushly-dev/afd-server/credentials`)
83
94
  export { isVerifiedCredentials } from './verified-credentials.js';
84
95
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAmBH,yCAAyC;AACzC,OAAO,EACN,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACtB,KAAK,EACL,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,OAAO,GACP,MAAM,sBAAsB,CAAC;AAC9B,8BAA8B;AAC9B,OAAO,EAON,wBAAwB,GACxB,MAAM,eAAe,CAAC;AACvB,kBAAkB;AAClB,OAAO,EAEN,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAElB,oBAAoB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,kDAAkD;AAClD,OAAO,EACN,oBAAoB,GAQpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAiC,MAAM,0BAA0B,CAAC;AAClG,kBAAkB;AAClB,OAAO,EAGN,wBAAwB,EAGxB,qBAAqB,EAGrB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,mDAAmD;AACnD,OAAO,EAAE,uBAAuB,EAAiC,MAAM,cAAc,CAAC;AACtF,OAAO,EAON,aAAa,GACb,MAAM,qBAAqB,CAAC;AAC7B,gGAAgG;AAChG,OAAO,EAAoB,gBAAgB,EAAuB,MAAM,eAAe,CAAC;AACxF,OAAO,EAAqB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACxE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,kBAAkB,EAElB,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,iBAAiB,GAMjB,MAAM,gBAAgB,CAAC;AACxB,gCAAgC;AAChC,OAAO,EAEN,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,cAAc,EAId,eAAe,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAEN,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,qBAAqB,GAOrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAEN,YAAY,EAEZ,kBAAkB,GAClB,MAAM,aAAa,CAAC;AACrB,sCAAsC;AACtC,OAAO,EACN,eAAe,EACf,yBAAyB,EACzB,6BAA6B,EAC7B,iBAAiB,EACjB,2BAA2B,EAC3B,8BAA8B,EAC9B,uBAAuB,EACvB,6BAA6B,EAC7B,mBAAmB,EACnB,iBAAiB,EAEjB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAQlB,cAAc,EAEd,iBAAiB,EACjB,gBAAgB,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,6BAA6B,EAE7B,6BAA6B,EAC7B,sBAAsB,EACtB,OAAO,EACP,eAAe,EACf,QAAQ,EAER,sBAAsB,EAEtB,mBAAmB,EAGnB,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,WAAW,GACX,MAAM,iBAAiB,CAAC;AACzB,kGAAkG;AAClG,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @fileoverview What a server keeps per process unless the host shares it: the key that signs the
3
+ * `requestState` of confirmation and approval elicitations, and each approval middleware's record
4
+ * of spent single-use tokens. Behind one URL served by several processes, a state signed by one
5
+ * fails on another and a single-use token works once on each, so the `instances` option makes
6
+ * that dependency explicit.
7
+ */
8
+ import type { CommandMiddleware } from '@lushly-dev/afd-core';
9
+ /** How many processes serve the server's URL: see `McpServerOptions.instances`. */
10
+ export type ServerInstances = 'single' | 'multiple';
11
+ export interface InstanceStateOptions {
12
+ name: string;
13
+ instances?: ServerInstances;
14
+ confirmationKey?: string | Uint8Array;
15
+ confirmations?: string;
16
+ hasHumanRelay?: boolean;
17
+ middleware?: readonly CommandMiddleware[];
18
+ /**
19
+ * Whether the idempotency step keeps its keys in this process's memory: no `store`, or an
20
+ * `InMemoryIdempotencyStore` given explicitly. A host's own store (a wrapper included) is taken
21
+ * as shared.
22
+ */
23
+ perProcessIdempotency?: boolean;
24
+ }
25
+ export interface InstanceState {
26
+ /** A copy of the validated `confirmationKey`, so a caller that reuses its buffer cannot change it. */
27
+ confirmationKey?: Uint8Array;
28
+ /**
29
+ * The one warning to log when the server is served over HTTP with `instances` left out and a
30
+ * per-process default in use. `undefined` when nothing depends on one process.
31
+ */
32
+ httpWarning?: string;
33
+ }
34
+ /**
35
+ * Validate `confirmationKey` and `instances`, and find the per-process defaults the server would
36
+ * depend on. With `instances: 'multiple'`, a default in use throws, naming what to supply.
37
+ *
38
+ * An approval middleware is seen in `middleware` directly or inside `composeMiddleware`, from
39
+ * any installed copy of this package from this version on (older copies do not mark theirs); one
40
+ * wrapped in another middleware is not.
41
+ *
42
+ * @throws TypeError for a `confirmationKey` that is not a string or Uint8Array of at least 32
43
+ * bytes, or an `instances` value other than `'single'` or `'multiple'`
44
+ * @throws Error with `instances: 'multiple'` when the server would sign elicitation state with a
45
+ * per-process key or an approval middleware would record single-use tokens in memory
46
+ */
47
+ export declare function checkInstanceState(options: InstanceStateOptions): InstanceState;
48
+ /**
49
+ * Log `message` to stderr unless an `instances` warning was already logged in this process, by
50
+ * any server or handler from any installed copy of this package.
51
+ */
52
+ export declare function warnInstancesOnce(message: string | undefined): void;
53
+ //# sourceMappingURL=instance-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance-state.d.ts","sourceRoot":"","sources":["../src/instance-state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,mFAAmF;AACnF,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC1C;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,aAAa;IAC7B,sGAAsG;IACtG,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAiBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAiD/E;AAKD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAYnE"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @fileoverview What a server keeps per process unless the host shares it: the key that signs the
3
+ * `requestState` of confirmation and approval elicitations, and each approval middleware's record
4
+ * of spent single-use tokens. Behind one URL served by several processes, a state signed by one
5
+ * fails on another and a single-use token works once on each, so the `instances` option makes
6
+ * that dependency explicit.
7
+ */
8
+ import { MIN_SECRET_BYTES } from './approval-crypto.js';
9
+ import { approvalProcessState } from './approval-process-state.js';
10
+ const encoder = new TextEncoder();
11
+ function checkKey(key) {
12
+ if (key === undefined)
13
+ return undefined;
14
+ if (typeof key !== 'string' && !(key instanceof Uint8Array)) {
15
+ throw new TypeError('confirmationKey must be a string or Uint8Array');
16
+ }
17
+ // A copy: `slice()` of a Node Buffer shares its memory, so the caller could change the key.
18
+ const bytes = typeof key === 'string' ? encoder.encode(key) : new Uint8Array(key);
19
+ if (bytes.length < MIN_SECRET_BYTES) {
20
+ throw new TypeError(`confirmationKey must be at least ${MIN_SECRET_BYTES} bytes`);
21
+ }
22
+ return bytes;
23
+ }
24
+ /**
25
+ * Validate `confirmationKey` and `instances`, and find the per-process defaults the server would
26
+ * depend on. With `instances: 'multiple'`, a default in use throws, naming what to supply.
27
+ *
28
+ * An approval middleware is seen in `middleware` directly or inside `composeMiddleware`, from
29
+ * any installed copy of this package from this version on (older copies do not mark theirs); one
30
+ * wrapped in another middleware is not.
31
+ *
32
+ * @throws TypeError for a `confirmationKey` that is not a string or Uint8Array of at least 32
33
+ * bytes, or an `instances` value other than `'single'` or `'multiple'`
34
+ * @throws Error with `instances: 'multiple'` when the server would sign elicitation state with a
35
+ * per-process key or an approval middleware would record single-use tokens in memory
36
+ */
37
+ export function checkInstanceState(options) {
38
+ const { instances } = options;
39
+ if (instances !== undefined && instances !== 'single' && instances !== 'multiple') {
40
+ throw new TypeError("instances must be 'single' or 'multiple'");
41
+ }
42
+ const confirmationKey = checkKey(options.confirmationKey);
43
+ const approvals = (options.middleware ?? []).flatMap((step) => {
44
+ const state = approvalProcessState(step);
45
+ return state ? [state] : [];
46
+ });
47
+ const elicits = (options.confirmations ?? 'off') !== 'off' || approvals.some((state) => state.relay);
48
+ const missing = [];
49
+ if (elicits && !confirmationKey) {
50
+ missing.push('confirmationKey (each process signs elicitation requestState with its own random key, so an answer must reach the process that asked)');
51
+ }
52
+ if (approvals.some((state) => state.perProcessNonces || (options.hasHumanRelay && state.perProcessRelayNonces))) {
53
+ missing.push("the approval middleware's nonceStore (spent single-use tokens are kept in this process's memory, so a token works once on each process)");
54
+ }
55
+ if (options.perProcessIdempotency) {
56
+ missing.push("the idempotency step's store (keys are kept in this process's memory, so a repeat that reaches another process runs again: spec/idempotency.md, S13)");
57
+ }
58
+ if (missing.length === 0)
59
+ return { confirmationKey };
60
+ if (instances === 'multiple') {
61
+ throw new Error(`[AFD] ${options.name}: instances: 'multiple' needs ${missing.join(' and ')}. ` +
62
+ 'Pass the same confirmationKey (at least 32 bytes) to every instance, give createApprovalMiddleware a nonceStore every instance shares, and give idempotency a store every instance shares.');
63
+ }
64
+ return {
65
+ confirmationKey,
66
+ httpWarning: instances === 'single'
67
+ ? undefined
68
+ : `[${options.name}] warning: one process must serve every request: this server has no ${missing.join(' and ')}. ` +
69
+ "Behind several processes, share them and set instances: 'multiple'; with one process, set instances: 'single' to silence this.",
70
+ };
71
+ }
72
+ const WARNED = Symbol.for('dev.afd/instances-warning');
73
+ let warnedHere = false;
74
+ /**
75
+ * Log `message` to stderr unless an `instances` warning was already logged in this process, by
76
+ * any server or handler from any installed copy of this package.
77
+ */
78
+ export function warnInstancesOnce(message) {
79
+ if (!message)
80
+ return;
81
+ const holder = globalThis;
82
+ if (Object.hasOwn(holder, WARNED) || warnedHere)
83
+ return;
84
+ try {
85
+ // Configurable, so a test can forget it.
86
+ Object.defineProperty(holder, WARNED, { value: true, configurable: true, enumerable: false });
87
+ }
88
+ catch {
89
+ // A frozen global: this copy still logs once.
90
+ warnedHere = true;
91
+ }
92
+ console.error(message);
93
+ }
94
+ //# sourceMappingURL=instance-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance-state.js","sourceRoot":"","sources":["../src/instance-state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AA8BnE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,SAAS,QAAQ,CAAC,GAAY;IAC7B,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,YAAY,UAAU,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IACvE,CAAC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,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/F,CAAC;IAAC,MAAM,CAAC;QACR,8CAA8C;QAC9C,UAAU,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @fileoverview Keeping a call off its recording parents' tapes, for the journal and the engine.
3
+ *
4
+ * Its own module, so the execution engine runs a call to a command declaring `secret` off tape
5
+ * (`spec/journal.md`, #3093) without bundling the journal middleware.
6
+ */
7
+ import type { Clock, CommandContext, CommandResult, JournalTape, RandomSource } from '@lushly-dev/afd-core';
8
+ /** On a recording clock: the clock it wraps, for timing that must stay off the tape. */
9
+ export declare const UNTAPED: unique symbol;
10
+ /** On a recording clock and random source: the tape they write to. */
11
+ export declare const TAPE: unique symbol;
12
+ /** On a recording clock and random source: the engine's opaque token for the call it records. */
13
+ export declare const DISPATCH: unique symbol;
14
+ /**
15
+ * The secret scope the current code runs in: the innermost off-tape call's, else `undefined`.
16
+ * A recorder keeps a read only in the scope its call started in or one enclosing it, so a read
17
+ * taken inside a secret call nested below it reaches its tape through no source (a host's own
18
+ * wrapping a recording one included), and neither does one its handler takes after a deadline
19
+ * ended the call (#3093). A callback that loses the async-local store (a native pool) reads as
20
+ * outside every secret call, as a thread without context variables does in Python.
21
+ */
22
+ export declare function secretScope(): Scope | undefined;
23
+ /** A secret scope: the scope it opened in. */
24
+ interface Scope {
25
+ parent?: Scope;
26
+ }
27
+ /**
28
+ * Whether a recorder that started in `scope` may keep a read on `tape` now: no off-tape call runs
29
+ * below it, and the read is taken in its scope or one enclosing it (work started outside every
30
+ * secret call), never in a secret scope opened inside it.
31
+ */
32
+ export declare function keeps(tape: JournalTape, scope: Scope | undefined): boolean;
33
+ /** The clock under any recording wrappers, so a journal's own timing lands on no tape. */
34
+ export declare function untaped(clock: Clock): Clock;
35
+ /** The random source under any recording wrappers. */
36
+ export declare function untapedRandom(random: RandomSource): RandomSource;
37
+ /**
38
+ * Run `next` off every tape: a call the journal leaves unrecorded because it may carry a secret
39
+ * reads the clock and random source a recording parent wrapped, which would put the values that
40
+ * built the secret on the parent's tape. Each recording layer's tape is marked `truncated`
41
+ * instead, so its replay says it cannot restore every value. It runs in a new secret scope
42
+ * ({@link secretScope}), so a read that still reaches a parent's recorder, through a source a host
43
+ * wraps around a recording one, is refused there; without `AsyncLocalStorage` (a browser) such a
44
+ * wrapper hides the recorder, so keep the journal's own sources on the context there.
45
+ *
46
+ * `dispatch` is the engine's token for the call: when every recorder around it records that very
47
+ * call (another journal in its chain, after the call went off its parents' tapes), those reads
48
+ * are the call's own, for `redact` to drop, and its tape is left whole (#3093).
49
+ */
50
+ export declare function offTape(context: CommandContext, next: () => Promise<CommandResult>, dispatch?: object): Promise<CommandResult>;
51
+ export {};
52
+ //# sourceMappingURL=journal-off-tape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal-off-tape.d.ts","sourceRoot":"","sources":["../src/journal-off-tape.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACX,KAAK,EACL,cAAc,EACd,aAAa,EACb,WAAW,EACX,YAAY,EACZ,MAAM,sBAAsB,CAAC;AAG9B,wFAAwF;AAGxF,eAAO,MAAM,OAAO,eAAwC,CAAC;AAE7D,sEAAsE;AACtE,eAAO,MAAM,IAAI,eAAqC,CAAC;AAEvD,iGAAiG;AACjG,eAAO,MAAM,QAAQ,eAAyC,CAAC;AAmC/D;;;;;;;GAOG;AACH,wBAAgB,WAAW,IAAI,KAAK,GAAG,SAAS,CAE/C;AAED,8CAA8C;AAC9C,UAAU,KAAK;IACd,MAAM,CAAC,EAAE,KAAK,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,OAAO,CAO1E;AAQD,0FAA0F;AAC1F,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAI3C;AAED,sDAAsD;AACtD,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAIhE;AAYD;;;;;;;;;;;;GAYG;AACH,wBAAsB,OAAO,CAC5B,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,EAClC,QAAQ,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,aAAa,CAAC,CA6CxB"}
@@ -0,0 +1,150 @@
1
+ /**
2
+ * @fileoverview Keeping a call off its recording parents' tapes, for the journal and the engine.
3
+ *
4
+ * Its own module, so the execution engine runs a call to a command declaring `secret` off tape
5
+ * (`spec/journal.md`, #3093) without bundling the journal middleware.
6
+ */
7
+ import { dispatchSource, hasDispatchViews, runWithSources } from './journal-view.js';
8
+ /** On a recording clock: the clock it wraps, for timing that must stay off the tape. */
9
+ // Registered, so the recording layers of separately installed copies of afd-server recognise
10
+ // each other's and a tape walk crosses them.
11
+ export const UNTAPED = Symbol.for('dev.afd/journal-untaped');
12
+ /** On a recording clock and random source: the tape they write to. */
13
+ export const TAPE = Symbol.for('dev.afd/journal-tape');
14
+ /** On a recording clock and random source: the engine's opaque token for the call it records. */
15
+ export const DISPATCH = Symbol.for('dev.afd/journal-dispatch');
16
+ /**
17
+ * On a tape (not enumerable): how many off-tape calls below its recorder are running. While any
18
+ * is, a read through the recorder may be one made for that call by work its recorded call started
19
+ * before it (a worker, a queue), which a nested call's own context cannot reach: it is not kept.
20
+ */
21
+ const OFF_TAPE_RUNNING = Symbol.for('dev.afd/journal-off-tape-running');
22
+ /**
23
+ * The secret scope each off-tape call opens, where the runtime has `AsyncLocalStorage`: one per
24
+ * process, under a registered symbol, so separately installed copies of this package share it.
25
+ */
26
+ const scopes = (() => {
27
+ try {
28
+ const host = globalThis;
29
+ const key = Symbol.for('dev.afd/journal-secret-scope');
30
+ const hooks = host.process?.getBuiltinModule?.('node:async_hooks');
31
+ if (!host[key] && hooks?.AsyncLocalStorage)
32
+ host[key] = new hooks.AsyncLocalStorage();
33
+ return host[key];
34
+ }
35
+ catch {
36
+ return undefined;
37
+ }
38
+ })();
39
+ /**
40
+ * The secret scope the current code runs in: the innermost off-tape call's, else `undefined`.
41
+ * A recorder keeps a read only in the scope its call started in or one enclosing it, so a read
42
+ * taken inside a secret call nested below it reaches its tape through no source (a host's own
43
+ * wrapping a recording one included), and neither does one its handler takes after a deadline
44
+ * ended the call (#3093). A callback that loses the async-local store (a native pool) reads as
45
+ * outside every secret call, as a thread without context variables does in Python.
46
+ */
47
+ export function secretScope() {
48
+ return scopes?.getStore();
49
+ }
50
+ /**
51
+ * Whether a recorder that started in `scope` may keep a read on `tape` now: no off-tape call runs
52
+ * below it, and the read is taken in its scope or one enclosing it (work started outside every
53
+ * secret call), never in a secret scope opened inside it.
54
+ */
55
+ export function keeps(tape, scope) {
56
+ if (tape[OFF_TAPE_RUNNING])
57
+ return false;
58
+ const current = secretScope();
59
+ for (let at = scope;; at = at.parent) {
60
+ if (at === current)
61
+ return true;
62
+ if (!at)
63
+ return false;
64
+ }
65
+ }
66
+ /** The clock under any recording wrappers, so a journal's own timing lands on no tape. */
67
+ export function untaped(clock) {
68
+ let current = clock;
69
+ while (current[UNTAPED])
70
+ current = current[UNTAPED];
71
+ return current;
72
+ }
73
+ /** The random source under any recording wrappers. */
74
+ export function untapedRandom(random) {
75
+ let current = random;
76
+ while (current[UNTAPED])
77
+ current = current[UNTAPED];
78
+ return current;
79
+ }
80
+ /** Whether `source` has a recording layer, and every one records `dispatch`. */
81
+ function recordsOnly(source, dispatch) {
82
+ let found = false;
83
+ for (let layer = source; layer?.[TAPE]; layer = layer[UNTAPED]) {
84
+ if (layer[DISPATCH] !== dispatch)
85
+ return false;
86
+ found = true;
87
+ }
88
+ return found;
89
+ }
90
+ /**
91
+ * Run `next` off every tape: a call the journal leaves unrecorded because it may carry a secret
92
+ * reads the clock and random source a recording parent wrapped, which would put the values that
93
+ * built the secret on the parent's tape. Each recording layer's tape is marked `truncated`
94
+ * instead, so its replay says it cannot restore every value. It runs in a new secret scope
95
+ * ({@link secretScope}), so a read that still reaches a parent's recorder, through a source a host
96
+ * wraps around a recording one, is refused there; without `AsyncLocalStorage` (a browser) such a
97
+ * wrapper hides the recorder, so keep the journal's own sources on the context there.
98
+ *
99
+ * `dispatch` is the engine's token for the call: when every recorder around it records that very
100
+ * call (another journal in its chain, after the call went off its parents' tapes), those reads
101
+ * are the call's own, for `redact` to drop, and its tape is left whole (#3093).
102
+ */
103
+ export async function offTape(context, next, dispatch) {
104
+ // The sources this dispatch reads, never another call's on the same context (#2890).
105
+ const clock = dispatchSource(context, 'clock');
106
+ const random = dispatchSource(context, 'random');
107
+ if (dispatch && recordsOnly(clock, dispatch) && recordsOnly(random, dispatch))
108
+ return next();
109
+ // Every recording layer's tape, not only the nearest: an outer journal around the parent loses
110
+ // these reads too, so its replay must also say it cannot restore every value.
111
+ const tapes = [];
112
+ for (const source of [clock, random]) {
113
+ for (let layer = source; layer; layer = layer[UNTAPED]) {
114
+ const tape = layer[TAPE];
115
+ if (tape && !tapes.includes(tape))
116
+ tapes.push(tape);
117
+ }
118
+ }
119
+ const running = (step) => {
120
+ for (const tape of tapes) {
121
+ const counted = tape;
122
+ Object.defineProperty(tape, OFF_TAPE_RUNNING, {
123
+ configurable: true,
124
+ value: (counted[OFF_TAPE_RUNNING] ?? 0) + step,
125
+ });
126
+ }
127
+ };
128
+ const run = async () => {
129
+ // Even with no tape around it: the call then keeps its own scope for its whole length, so a
130
+ // read it makes is never taken for its parent's once a sibling off-tape call ends (#2890).
131
+ if (tapes.length === 0 && !hasDispatchViews)
132
+ return next();
133
+ running(1);
134
+ try {
135
+ return await runWithSources(context, {
136
+ ...(clock ? { clock: untaped(clock) } : {}),
137
+ ...(random ? { random: untapedRandom(random) } : {}),
138
+ }, next,
139
+ // With no tape around it, the scope only guards siblings: never swap a source for it.
140
+ { offTape: true, optional: tapes.length === 0 });
141
+ }
142
+ finally {
143
+ running(-1);
144
+ }
145
+ };
146
+ for (const tape of tapes)
147
+ tape.truncated = true;
148
+ return scopes ? scopes.run({ parent: secretScope() }, run) : run();
149
+ }
150
+ //# sourceMappingURL=journal-off-tape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal-off-tape.js","sourceRoot":"","sources":["../src/journal-off-tape.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAErF,wFAAwF;AACxF,6FAA6F;AAC7F,6CAA6C;AAC7C,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAE7D,sEAAsE;AACtE,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAEvD,iGAAiG;AACjG,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAOxE;;;GAGG;AACH,MAAM,MAAM,GAAG,CAAC,GAA2B,EAAE;IAC5C,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,UAGZ,CAAC;QACF,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;QACvD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,CAAC,kBAAkB,CAErD,CAAC;QACb,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,iBAAiB;YAAE,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;QACtF,OAAO,IAAI,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AAE,MAAM,CAAC;CAChB;AA8JD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,aAAa,CAClC,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,OAAO,GAAE,oBAAyB,GAChC,OAAO,CAAC,YAAY,CAAC,CA6JvB"}
@@ -5,8 +5,10 @@
5
5
  * entry, whether the result is the same. It does not make handlers deterministic: any other
6
6
  * nondeterminism (I/O, global state, `Date.now()` read directly) shows up as divergence.
7
7
  */
8
- import { fixedClock, journalActor, seededRandom } from '@lushly-dev/afd-core';
9
- import { JOURNAL_REPLAY } from './journal.js';
8
+ import { AFD_OUTPUT_BUDGET_META_KEY, fixedClock, journalActor, seededRandom, } from '@lushly-dev/afd-core';
9
+ import { IDEMPOTENCY_KEY_SET_BY_ENGINE } from '@lushly-dev/afd-core/internal/idempotency';
10
+ import { JOURNAL_REPLAY, JOURNAL_RESULT_UNSERIALIZABLE, } from './journal.js';
11
+ import { OUTPUT_BUDGET_ASK, SKIP_OUTPUT_BUDGET } from './output-budget.js';
10
12
  const DEFAULT_IGNORE = ['metadata.executionTimeMs'];
11
13
  const DEFAULT_MAX_DIFFERENCES = 100;
12
14
  /** Replays the recorded clock readings, then holds the last one. */
@@ -191,6 +193,9 @@ export async function replayJournal(registry, entries, options = {}) {
191
193
  for (const name of entry.contextOmitted ?? []) {
192
194
  fieldNotes.push(`context field '${name}' was too large to journal; replayed without it`);
193
195
  }
196
+ if (!entry.result.success && entry.result.error?.code === JOURNAL_RESULT_UNSERIALIZABLE) {
197
+ fieldNotes.push(`the recorded result could not be serialized (${JOURNAL_RESULT_UNSERIALIZABLE}); replay cannot compare against the original value`);
198
+ }
194
199
  const random = tapeRandom(tape?.random ?? [], `${seed}:${entry.seq}`);
195
200
  let clock;
196
201
  let outcome;
@@ -223,9 +228,49 @@ export async function replayJournal(registry, entries, options = {}) {
223
228
  },
224
229
  };
225
230
  context[JOURNAL_REPLAY] = marker;
231
+ // The recorded key, restored as the engine's own (spec/journal.md, "Replay"), so a derived
232
+ // key (K4) is not refused as a caller's. A key `options.context` sets is a caller's.
233
+ if (entry.idempotencyKey !== undefined && extra?.idempotencyKey === undefined) {
234
+ context.idempotencyKey = entry.idempotencyKey;
235
+ context[IDEMPOTENCY_KEY_SET_BY_ENGINE] = entry.idempotencyKey;
236
+ }
237
+ // B8: restore the recorded effective budget as the call's ask (a trusted override on
238
+ // `options.context.outputBudget` still wins in `applyOutputBudget`). A recorded passing
239
+ // result with an effective budget and no `dev.afd/outputBudget` report came from a
240
+ // buffered stream where B5 was skipped (B7); preserve that exemption on replay so
241
+ // deterministic streams stay reproducible while normal budgeted calls still run B5.
242
+ if (entry.outputBudget !== undefined) {
243
+ context[OUTPUT_BUDGET_ASK] = {
244
+ maxBytes: entry.outputBudget,
245
+ };
246
+ if (entry.result.success === true &&
247
+ entry.result.metadata?.[AFD_OUTPUT_BUDGET_META_KEY] === undefined) {
248
+ Object.defineProperty(context, SKIP_OUTPUT_BUDGET, { value: true });
249
+ }
250
+ }
251
+ // An app's call replays only where its grant is checked again (`createAppCallRegistry`);
252
+ // any other target would run it unchecked, or as another interface.
253
+ // Keyed on the recorded interface too, so the `context` option cannot replay it as another.
254
+ if ((entry.contextDigest.interface === 'apps' || context.interface === 'apps') &&
255
+ registry.interface !== 'apps') {
256
+ throw new Error("An app's call replays only on createAppCallRegistry");
257
+ }
226
258
  const replayed = await registry.execute(entry.command, entry.input, context);
259
+ let replayedJson;
260
+ try {
261
+ replayedJson = toJson(replayed);
262
+ }
263
+ catch (error) {
264
+ throw new Error(`Replayed result could not be serialized: ${error instanceof Error ? error.message : String(error)}`);
265
+ }
266
+ if (!replayedJson ||
267
+ typeof replayedJson !== 'object' ||
268
+ Array.isArray(replayedJson) ||
269
+ typeof replayedJson.success !== 'boolean') {
270
+ throw new Error('Replayed result did not serialize to a CommandResult object');
271
+ }
227
272
  const differences = [];
228
- diffJson(toJson(entry.result), toJson(replayed), '', ignore, differences, maxDifferences);
273
+ diffJson(toJson(entry.result), replayedJson, '', ignore, differences, maxDifferences);
229
274
  outcome = {
230
275
  seq: entry.seq,
231
276
  command: entry.command,