@brud/kernel 0.0.0-stage → 0.0.2

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 (286) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +63 -2
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js +13 -0
  5. package/dist/serviceModules/events.d.ts +1 -0
  6. package/dist/serviceModules/events.js +1 -0
  7. package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
  8. package/dist/serviceModules/exposedApiRegistry.js +1 -0
  9. package/dist/serviceModules/identityRegistry.d.ts +1 -0
  10. package/dist/serviceModules/identityRegistry.js +1 -0
  11. package/dist/serviceModules/interception.d.ts +1 -0
  12. package/dist/serviceModules/interception.js +1 -0
  13. package/dist/serviceModules/parser.d.ts +1 -0
  14. package/dist/serviceModules/parser.js +1 -0
  15. package/dist/serviceModules/router.d.ts +1 -0
  16. package/dist/serviceModules/router.js +1 -0
  17. package/dist/serviceModules/wasmCage.d.ts +1 -0
  18. package/dist/serviceModules/wasmCage.js +1 -0
  19. package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
  20. package/dist/services/Events/contracts/IEventsService.js +1 -0
  21. package/dist/services/Events/contracts/errors.d.ts +31 -0
  22. package/dist/services/Events/contracts/errors.js +40 -0
  23. package/dist/services/Events/contracts/index.d.ts +3 -0
  24. package/dist/services/Events/contracts/index.js +3 -0
  25. package/dist/services/Events/contracts/tokens.d.ts +2 -0
  26. package/dist/services/Events/contracts/tokens.js +2 -0
  27. package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
  28. package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
  29. package/dist/services/Events/descriptor/tokens.d.ts +1 -0
  30. package/dist/services/Events/descriptor/tokens.js +1 -0
  31. package/dist/services/Events/index.d.ts +4 -0
  32. package/dist/services/Events/index.js +4 -0
  33. package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
  34. package/dist/services/Events/orchestrator/EventsService.js +339 -0
  35. package/dist/services/Events/orchestrator/index.d.ts +2 -0
  36. package/dist/services/Events/orchestrator/index.js +2 -0
  37. package/dist/services/Events/orchestrator/limits.d.ts +22 -0
  38. package/dist/services/Events/orchestrator/limits.js +33 -0
  39. package/dist/services/Events/serviceModule.d.ts +2 -0
  40. package/dist/services/Events/serviceModule.js +5 -0
  41. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +56 -0
  42. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
  43. package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
  44. package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
  45. package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
  46. package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
  47. package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
  48. package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
  49. package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
  50. package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
  51. package/dist/services/ExposedApiRegistry/contracts/types.d.ts +133 -0
  52. package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
  53. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
  54. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
  55. package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
  56. package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
  57. package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
  58. package/dist/services/ExposedApiRegistry/index.js +5 -0
  59. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +68 -0
  60. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +452 -0
  61. package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
  62. package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
  63. package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
  64. package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
  65. package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
  66. package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
  67. package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
  68. package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
  69. package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
  70. package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
  71. package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
  72. package/dist/services/IdentityRegistry/contracts/index.js +3 -0
  73. package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
  74. package/dist/services/IdentityRegistry/contracts/types.js +18 -0
  75. package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
  76. package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
  77. package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
  78. package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
  79. package/dist/services/IdentityRegistry/index.d.ts +11 -0
  80. package/dist/services/IdentityRegistry/index.js +6 -0
  81. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
  82. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
  83. package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
  84. package/dist/services/IdentityRegistry/serviceModule.js +24 -0
  85. package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
  86. package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
  87. package/dist/services/Interception/contracts/IInterceptionService.d.ts +155 -0
  88. package/dist/services/Interception/contracts/IInterceptionService.js +12 -0
  89. package/dist/services/Interception/contracts/errors.d.ts +26 -0
  90. package/dist/services/Interception/contracts/errors.js +35 -0
  91. package/dist/services/Interception/contracts/index.d.ts +3 -0
  92. package/dist/services/Interception/contracts/index.js +3 -0
  93. package/dist/services/Interception/contracts/tokens.d.ts +2 -0
  94. package/dist/services/Interception/contracts/tokens.js +2 -0
  95. package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
  96. package/dist/services/Interception/descriptor/InterceptionDescriptor.js +50 -0
  97. package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
  98. package/dist/services/Interception/descriptor/tokens.js +1 -0
  99. package/dist/services/Interception/index.d.ts +4 -0
  100. package/dist/services/Interception/index.js +4 -0
  101. package/dist/services/Interception/orchestrator/InterceptionService.d.ts +40 -0
  102. package/dist/services/Interception/orchestrator/InterceptionService.js +343 -0
  103. package/dist/services/Interception/orchestrator/index.d.ts +1 -0
  104. package/dist/services/Interception/orchestrator/index.js +1 -0
  105. package/dist/services/Interception/serviceModule.d.ts +2 -0
  106. package/dist/services/Interception/serviceModule.js +5 -0
  107. package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
  108. package/dist/services/Parser/contracts/IParserService.js +1 -0
  109. package/dist/services/Parser/contracts/errors.d.ts +25 -0
  110. package/dist/services/Parser/contracts/errors.js +33 -0
  111. package/dist/services/Parser/contracts/index.d.ts +4 -0
  112. package/dist/services/Parser/contracts/index.js +1 -0
  113. package/dist/services/Parser/contracts/types.d.ts +42 -0
  114. package/dist/services/Parser/contracts/types.js +1 -0
  115. package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
  116. package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
  117. package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
  118. package/dist/services/Parser/descriptor/tokens.js +8 -0
  119. package/dist/services/Parser/index.d.ts +8 -0
  120. package/dist/services/Parser/index.js +8 -0
  121. package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
  122. package/dist/services/Parser/orchestrator/ParserService.js +105 -0
  123. package/dist/services/Parser/orchestrator/index.d.ts +1 -0
  124. package/dist/services/Parser/orchestrator/index.js +1 -0
  125. package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
  126. package/dist/services/Parser/parser/indexSynthesis.js +13 -0
  127. package/dist/services/Parser/parser/parameters.d.ts +14 -0
  128. package/dist/services/Parser/parser/parameters.js +89 -0
  129. package/dist/services/Parser/parser/scanner.d.ts +48 -0
  130. package/dist/services/Parser/parser/scanner.js +156 -0
  131. package/dist/services/Parser/parser/syntax.d.ts +30 -0
  132. package/dist/services/Parser/parser/syntax.js +34 -0
  133. package/dist/services/Parser/serviceModule.d.ts +2 -0
  134. package/dist/services/Parser/serviceModule.js +5 -0
  135. package/dist/services/Router/bootOptions.d.ts +2 -0
  136. package/dist/services/Router/bootOptions.js +2 -0
  137. package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
  138. package/dist/services/Router/contracts/IRouterService.js +1 -0
  139. package/dist/services/Router/contracts/caller.d.ts +6 -0
  140. package/dist/services/Router/contracts/caller.js +6 -0
  141. package/dist/services/Router/contracts/errors.d.ts +67 -0
  142. package/dist/services/Router/contracts/errors.js +90 -0
  143. package/dist/services/Router/contracts/index.d.ts +8 -0
  144. package/dist/services/Router/contracts/index.js +4 -0
  145. package/dist/services/Router/contracts/kind.d.ts +7 -0
  146. package/dist/services/Router/contracts/kind.js +10 -0
  147. package/dist/services/Router/contracts/registrant.d.ts +23 -0
  148. package/dist/services/Router/contracts/registrant.js +13 -0
  149. package/dist/services/Router/contracts/types.d.ts +110 -0
  150. package/dist/services/Router/contracts/types.js +1 -0
  151. package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
  152. package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
  153. package/dist/services/Router/descriptor/tokens.d.ts +9 -0
  154. package/dist/services/Router/descriptor/tokens.js +9 -0
  155. package/dist/services/Router/index.d.ts +4 -0
  156. package/dist/services/Router/index.js +4 -0
  157. package/dist/services/Router/orchestrator/RouterService.d.ts +93 -0
  158. package/dist/services/Router/orchestrator/RouterService.js +457 -0
  159. package/dist/services/Router/orchestrator/index.d.ts +2 -0
  160. package/dist/services/Router/orchestrator/index.js +1 -0
  161. package/dist/services/Router/serviceModule.d.ts +4 -0
  162. package/dist/services/Router/serviceModule.js +22 -0
  163. package/dist/services/WasmCage/index.d.ts +7 -0
  164. package/dist/services/WasmCage/index.js +4 -0
  165. package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
  166. package/dist/services/WasmCage/scripts/prepin.js +38 -0
  167. package/dist/services/WasmCage/serviceModule.d.ts +12 -0
  168. package/dist/services/WasmCage/serviceModule.js +18 -0
  169. package/dist/services/WasmCage/src/caged.d.ts +121 -0
  170. package/dist/services/WasmCage/src/caged.js +460 -0
  171. package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
  172. package/dist/services/WasmCage/src/descriptor.js +56 -0
  173. package/dist/services/WasmCage/src/native.d.ts +29 -0
  174. package/dist/services/WasmCage/src/native.js +66 -0
  175. package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
  176. package/dist/services/WasmCage/src/nativeDigests.js +15 -0
  177. package/dist/services/WasmCage/src/package.d.ts +36 -0
  178. package/dist/services/WasmCage/src/package.js +122 -0
  179. package/dist/services/shared/canonicalJson.d.ts +29 -0
  180. package/dist/services/shared/canonicalJson.js +93 -0
  181. package/dist/services/shared/documentStore.d.ts +16 -0
  182. package/dist/services/shared/documentStore.js +98 -0
  183. package/dist/src/bootstrap/bootKernelInternal.d.ts +19 -0
  184. package/dist/src/bootstrap/bootKernelInternal.js +633 -0
  185. package/dist/src/bootstrap/bootTypes.d.ts +113 -0
  186. package/dist/src/bootstrap/bootTypes.js +1 -0
  187. package/dist/src/bootstrap/config/index.d.ts +3 -0
  188. package/dist/src/bootstrap/config/index.js +2 -0
  189. package/dist/src/bootstrap/config/integrity.d.ts +45 -0
  190. package/dist/src/bootstrap/config/integrity.js +92 -0
  191. package/dist/src/bootstrap/config/parse.d.ts +15 -0
  192. package/dist/src/bootstrap/config/parse.js +81 -0
  193. package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
  194. package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
  195. package/dist/src/bootstrap/config/types.d.ts +41 -0
  196. package/dist/src/bootstrap/config/types.js +15 -0
  197. package/dist/src/bootstrap/hardcore.d.ts +212 -0
  198. package/dist/src/bootstrap/hardcore.js +312 -0
  199. package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
  200. package/dist/src/bootstrap/hardcoreServices.js +258 -0
  201. package/dist/src/bootstrap/index.d.ts +13 -0
  202. package/dist/src/bootstrap/index.js +7 -0
  203. package/dist/src/bootstrap/loaded.d.ts +30 -0
  204. package/dist/src/bootstrap/loaded.js +45 -0
  205. package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
  206. package/dist/src/bootstrap/packageRequirements.js +52 -0
  207. package/dist/src/bootstrap/reload.d.ts +44 -0
  208. package/dist/src/bootstrap/reload.js +45 -0
  209. package/dist/src/bootstrap/seal.d.ts +32 -0
  210. package/dist/src/bootstrap/seal.js +101 -0
  211. package/dist/src/contracts/accessBroker.d.ts +53 -0
  212. package/dist/src/contracts/accessBroker.js +1 -0
  213. package/dist/src/contracts/brudOperation.d.ts +20 -0
  214. package/dist/src/contracts/brudOperation.js +20 -0
  215. package/dist/src/contracts/callChain.d.ts +161 -0
  216. package/dist/src/contracts/callChain.js +19 -0
  217. package/dist/src/contracts/capability.d.ts +26 -0
  218. package/dist/src/contracts/capability.js +26 -0
  219. package/dist/src/contracts/capabilitySet.d.ts +23 -0
  220. package/dist/src/contracts/capabilitySet.js +72 -0
  221. package/dist/src/contracts/container.d.ts +17 -0
  222. package/dist/src/contracts/container.js +8 -0
  223. package/dist/src/contracts/context.d.ts +19 -0
  224. package/dist/src/contracts/context.js +1 -0
  225. package/dist/src/contracts/contextContract.d.ts +132 -0
  226. package/dist/src/contracts/contextContract.js +274 -0
  227. package/dist/src/contracts/dispatchView.d.ts +21 -0
  228. package/dist/src/contracts/dispatchView.js +1 -0
  229. package/dist/src/contracts/handler.d.ts +21 -0
  230. package/dist/src/contracts/handler.js +1 -0
  231. package/dist/src/contracts/index.d.ts +26 -0
  232. package/dist/src/contracts/index.js +9 -0
  233. package/dist/src/contracts/kernel.d.ts +60 -0
  234. package/dist/src/contracts/kernel.js +1 -0
  235. package/dist/src/contracts/lifecycle.d.ts +59 -0
  236. package/dist/src/contracts/lifecycle.js +1 -0
  237. package/dist/src/contracts/manifest.d.ts +180 -0
  238. package/dist/src/contracts/manifest.js +334 -0
  239. package/dist/src/contracts/pipeline.d.ts +8 -0
  240. package/dist/src/contracts/pipeline.js +1 -0
  241. package/dist/src/contracts/policy.d.ts +75 -0
  242. package/dist/src/contracts/policy.js +77 -0
  243. package/dist/src/contracts/registry.d.ts +7 -0
  244. package/dist/src/contracts/registry.js +1 -0
  245. package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
  246. package/dist/src/contracts/serviceDescriptor.js +1 -0
  247. package/dist/src/contracts/serviceToken.d.ts +36 -0
  248. package/dist/src/contracts/serviceToken.js +16 -0
  249. package/dist/src/engine/BrudKernel.d.ts +120 -0
  250. package/dist/src/engine/BrudKernel.js +395 -0
  251. package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
  252. package/dist/src/engine/ExecutionPipeline.js +62 -0
  253. package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
  254. package/dist/src/engine/KernelAccessBroker.js +107 -0
  255. package/dist/src/engine/KernelRegistry.d.ts +14 -0
  256. package/dist/src/engine/KernelRegistry.js +33 -0
  257. package/dist/src/engine/OperationRegistry.d.ts +9 -0
  258. package/dist/src/engine/OperationRegistry.js +18 -0
  259. package/dist/src/engine/ServiceContainer.d.ts +13 -0
  260. package/dist/src/engine/ServiceContainer.js +53 -0
  261. package/dist/src/engine/callChain.d.ts +68 -0
  262. package/dist/src/engine/callChain.js +175 -0
  263. package/dist/src/engine/dag.d.ts +2 -0
  264. package/dist/src/engine/dag.js +34 -0
  265. package/dist/src/engine/errors.d.ts +26 -0
  266. package/dist/src/engine/errors.js +52 -0
  267. package/dist/src/engine/index.d.ts +11 -0
  268. package/dist/src/engine/index.js +8 -0
  269. package/dist/src/engine/state.d.ts +1 -0
  270. package/dist/src/engine/state.js +1 -0
  271. package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
  272. package/dist/src/validation/jsonSchema/compile.js +386 -0
  273. package/dist/src/validation/jsonSchema/index.d.ts +3 -0
  274. package/dist/src/validation/jsonSchema/index.js +2 -0
  275. package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
  276. package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
  277. package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
  278. package/dist/src/validation/jsonSchema/pattern.js +155 -0
  279. package/dist/src/validation/jsonSchema/types.d.ts +71 -0
  280. package/dist/src/validation/jsonSchema/types.js +15 -0
  281. package/package.json +59 -4
  282. package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
  283. package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
  284. package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
  285. package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
  286. package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
@@ -0,0 +1,60 @@
1
+ import type { IKernelAccessBroker } from './accessBroker.js';
2
+ import type { KernelHostSession, KernelObservation } from './callChain.js';
3
+ import type { ContextSchema } from './contextContract.js';
4
+ import type { KernelLogger } from './lifecycle.js';
5
+ import type { ServiceDescriptor } from './serviceDescriptor.js';
6
+ /**
7
+ * Options controlling a kernel boot sequence.
8
+ */
9
+ export interface KernelBootOptions {
10
+ /** Open options bag supplied by the host and forwarded to services. */
11
+ readonly options?: Readonly<Record<string, unknown>>;
12
+ /** Optional diagnostic sink forwarded to every service context. */
13
+ readonly logger?: KernelLogger;
14
+ }
15
+ /**
16
+ * Root microkernel contract governing service registration and lifecycle.
17
+ */
18
+ export interface IBrudKernel extends IKernelAccessBroker {
19
+ /**
20
+ * Registers a service descriptor. Must be called before {@link boot}.
21
+ *
22
+ * @typeParam TService - The public interface exposed by the service.
23
+ * @param descriptor - Self-describing registration record.
24
+ */
25
+ register<TService>(descriptor: ServiceDescriptor<TService>): void;
26
+ /**
27
+ * Initializes every registered service in dependency order.
28
+ *
29
+ * @param options - Boot configuration.
30
+ */
31
+ boot(options: KernelBootOptions): Promise<void>;
32
+ /** Disposes every initialized service in reverse dependency order. */
33
+ shutdown(): Promise<void>;
34
+ /** Returns the dynamically built context schema. */
35
+ getContextSchema(): ContextSchema;
36
+ /**
37
+ * Validates an options bag against the locked context schema.
38
+ *
39
+ * Used by hosts that build a fresh context after boot.
40
+ */
41
+ validateContextOptions(options: Readonly<Record<string, unknown>>): void;
42
+ /**
43
+ * Runs an operation inside a host-origin call chain.
44
+ *
45
+ * This is the only way a chain gets the `host` origin. It is a method of the
46
+ * kernel object, which only the host holds; a participant receives the access
47
+ * broker, never the kernel. The host calls it from its authenticated session.
48
+ *
49
+ * @param session - The host session's declaration.
50
+ * @param operation - Work performed inside the host-origin chain.
51
+ */
52
+ runHostCall<T>(session: KernelHostSession, operation: () => T): T;
53
+ /**
54
+ * Reads the kernel's observation stream.
55
+ *
56
+ * Detailed denial reasons are recorded here, never returned to the refused
57
+ * caller. Only the holder of the kernel object can read the stream.
58
+ */
59
+ readObservations(): readonly KernelObservation[];
60
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import type { IKernelAccessBroker } from './accessBroker.js';
2
+ /**
3
+ * Privilege tier a service belongs to, ordered from most to least trusted.
4
+ */
5
+ export type ServiceTier = 'kernel' | 'core' | 'userland';
6
+ /**
7
+ * Minimal diagnostic logger surface a kernel can inject into services.
8
+ *
9
+ * Services treat it as an optional sink: the kernel supplies it during boot,
10
+ * but standalone construction (tests, adapters) may omit it.
11
+ */
12
+ export interface KernelLogger {
13
+ /** Emits a structured, non-fatal diagnostic warning. */
14
+ warn(message: string, meta?: Record<string, unknown>): void;
15
+ }
16
+ /**
17
+ * Ambient context supplied to a service at construction and access time.
18
+ */
19
+ export interface ServiceContext {
20
+ /** Identifier of the caller or service this context describes. */
21
+ readonly callerId: string;
22
+ /** Privilege tier of the caller. */
23
+ readonly tier: ServiceTier;
24
+ /**
25
+ * Opaque host-supplied options bag.
26
+ *
27
+ * The kernel stores the bag at boot and attaches it unchanged to every
28
+ * service context. The core never inspects a key; services read the options
29
+ * their own domain owns.
30
+ */
31
+ readonly options: Readonly<Record<string, unknown>>;
32
+ /** Kernel diagnostic sink. Absent in standalone construction. */
33
+ readonly logger?: KernelLogger;
34
+ }
35
+ /**
36
+ * Optional lifecycle hooks a service may implement.
37
+ */
38
+ export interface IServiceLifecycle {
39
+ /**
40
+ * Prepares the service for use. Called once during kernel boot.
41
+ *
42
+ * @param broker - Mediated access broker for resolving dependencies.
43
+ */
44
+ initialize?(broker: IKernelAccessBroker): Promise<void> | void;
45
+ /**
46
+ * Starts work that needs other services through the broker. Called once,
47
+ * after the kernel enters `RUNNING` and before `boot()` resolves, in the same
48
+ * dependency order as {@link IServiceLifecycle.initialize}.
49
+ *
50
+ * The broker grants access here, unlike during `initialize()`. If this hook
51
+ * throws, the kernel disposes every initialized service in reverse order,
52
+ * ends `DISPOSED`, and `boot()` rejects with the original error.
53
+ *
54
+ * @param broker - Mediated access broker for resolving dependencies.
55
+ */
56
+ onRunning?(broker: IKernelAccessBroker): Promise<void> | void;
57
+ /** Releases resources held by the service. Called once during shutdown. */
58
+ dispose?(): Promise<void> | void;
59
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Participant manifest.
3
+ *
4
+ * A manifest is declarative data. It states what a participant requests and
5
+ * which exposures it gives, with the scope and policy of each. It contains no
6
+ * executable code. The kernel admits it at boot without invoking the
7
+ * participant's factory, and the participant's code cannot add, change, or
8
+ * remove an exposure afterwards.
9
+ */
10
+ /** What a participant requests. A request is not a grant; the giver decides. */
11
+ export interface ParticipantRequests {
12
+ /** Capability tokens the participant asks for. */
13
+ readonly capabilities?: readonly string[];
14
+ }
15
+ /**
16
+ * One exposure a participant declares.
17
+ *
18
+ * The resolution primitive interprets and validates every field. The kernel
19
+ * core carries the declaration unchanged.
20
+ */
21
+ export interface ExposureDeclaration {
22
+ /** Stable exposure name. */
23
+ readonly name: string;
24
+ /** Version: a positive integer major version or a semantic version. */
25
+ readonly version?: number | string;
26
+ /** Reachability scope. */
27
+ readonly scope?: string;
28
+ /** Declarative Layer 1 policy for this exposure. */
29
+ readonly policy?: Readonly<Record<string, unknown>>;
30
+ }
31
+ /**
32
+ * One event a participant declares.
33
+ *
34
+ * A separate type from {@link ExposureDeclaration}: events are a push-model
35
+ * observable, not a pull-model callable. For Step 3 the field set matches the
36
+ * exposure declaration; the payload schema is deferred to the delivery step.
37
+ */
38
+ export interface EventDeclaration {
39
+ /** Stable event name. */
40
+ readonly name: string;
41
+ /** Version: a positive integer major version or a semantic version. */
42
+ readonly version?: number | string;
43
+ /** Reachability scope. */
44
+ readonly scope?: string;
45
+ /** Declarative Layer 1 policy for this event. */
46
+ readonly policy?: Readonly<Record<string, unknown>>;
47
+ /**
48
+ * JSON Schema subset the emitted payload must satisfy. Admission checks only
49
+ * that it is an object; the schema itself is compiled and enforced at emit.
50
+ */
51
+ readonly payloadSchema?: Readonly<Record<string, unknown>>;
52
+ }
53
+ /**
54
+ * One interception a participant declares: it asks to intercept calls to an
55
+ * exposure another participant gives. Held only by the interception hardcore;
56
+ * it is not an exposure and is not reachable through `resolve`.
57
+ */
58
+ export interface InterceptionDeclaration {
59
+ /** Exposure name to intercept. */
60
+ readonly target: string;
61
+ /** Major version of the target; defaults to 1. */
62
+ readonly version?: number | string;
63
+ /**
64
+ * The stages this interceptor takes part in: `'input'` (it sees a call's
65
+ * arguments before the giver runs, and may modify or block them) and
66
+ * `'output'` (it may append content to the giver's result). Defaults to
67
+ * `['output']`: seeing or changing arguments must be asked for explicitly.
68
+ * A declared stage must be implemented. An output interceptor that is not is
69
+ * skipped; an input interceptor that is not blocks the call.
70
+ */
71
+ readonly stages?: readonly ('input' | 'output')[];
72
+ }
73
+ /**
74
+ * One interception point a giver declares on one of its own exposures, naming
75
+ * (by service token) the interceptors it admits, in the order they run.
76
+ */
77
+ export interface InterceptionPointDeclaration {
78
+ /** The giver's own exposure name. */
79
+ readonly exposure: string;
80
+ /** Major version of the exposure; defaults to 1. */
81
+ readonly version?: number | string;
82
+ /** Optional public description of the kind (shown to remote clients). */
83
+ readonly description?: string;
84
+ /**
85
+ * Optional public operations of the kind: name → description and a JSON
86
+ * Schema for its input. Plain JSON data; the owner may serve more.
87
+ */
88
+ readonly operations?: Readonly<Record<string, KindOperationDescription>>;
89
+ /** Service tokens of the admitted interceptors, in run order. */
90
+ readonly admit: readonly string[];
91
+ /**
92
+ * Lowers the kernel's output-stage limits for this point, in bytes of
93
+ * canonical JSON. The Interception primitive validates the values; a value
94
+ * can lower a kernel ceiling and never raise it.
95
+ */
96
+ readonly outputLimits?: Readonly<Record<string, number>>;
97
+ }
98
+ /**
99
+ * One Brud Syntax kind a participant claims, served by one of its own
100
+ * exposures (which must provide `dispatch(operation, context)`).
101
+ */
102
+ /** Public description of one operation of a kind. */
103
+ export interface KindOperationDescription {
104
+ readonly description?: string;
105
+ /** JSON Schema of the operation's input (plain JSON). */
106
+ readonly input?: Readonly<Record<string, unknown>>;
107
+ /**
108
+ * Who may call this operation: a Layer 1 policy object, in the same
109
+ * language as an exposure's `policy`. Falls back to the kind's `permission`.
110
+ * The Router validates and evaluates it; admission checks only its shape.
111
+ */
112
+ readonly permission?: Readonly<Record<string, unknown>>;
113
+ }
114
+ export interface KindDeclaration {
115
+ /** The kind word written after `[CALL`, e.g. `tool`. */
116
+ readonly kind: string;
117
+ /** The participant's own exposure name that dispatches the kind. */
118
+ readonly exposure: string;
119
+ /** Major version of the exposure; defaults to 1. */
120
+ readonly version?: number | string;
121
+ /** Public description of the kind. */
122
+ readonly description?: string;
123
+ /**
124
+ * Every operation the kind serves, by name. Required: the kernel refuses an
125
+ * operation that is not listed, before the owner is reached.
126
+ *
127
+ * `'open'` declares that the owner defines the operation names itself (for
128
+ * example from a registry filled at runtime), so the kernel cannot list them.
129
+ * It must be written out, and the kind's `permission` is then required and is
130
+ * enforced on every call; the owner decides which names exist.
131
+ */
132
+ readonly operations: Readonly<Record<string, KindOperationDescription>> | 'open';
133
+ /** Default permission for operations that declare none; required when `operations` is `'open'`. */
134
+ readonly permission?: Readonly<Record<string, unknown>>;
135
+ }
136
+ /** A participant's manifest. */
137
+ export interface ParticipantManifest {
138
+ /** What the participant requests. */
139
+ readonly requests?: ParticipantRequests;
140
+ /** Exposures the participant gives. */
141
+ readonly exposures?: readonly ExposureDeclaration[];
142
+ /** Events the participant declares. */
143
+ readonly events?: readonly EventDeclaration[];
144
+ /** Interceptions the participant asks for. */
145
+ readonly interceptions?: readonly InterceptionDeclaration[];
146
+ /** Interception points the participant opens on its own exposures. */
147
+ readonly interceptionPoints?: readonly InterceptionPointDeclaration[];
148
+ readonly kinds?: readonly KindDeclaration[];
149
+ }
150
+ /** A manifest after the kernel has validated and frozen it. */
151
+ export interface AdmittedManifest {
152
+ /** Requested capability tokens, deduplicated, in declaration order. */
153
+ readonly capabilities: readonly string[];
154
+ /** Declared exposures, deep-copied and frozen. */
155
+ readonly exposures: readonly ExposureDeclaration[];
156
+ /** Declared events, deep-copied and frozen. */
157
+ readonly events: readonly EventDeclaration[];
158
+ /** Declared interceptions, deep-copied and frozen. */
159
+ readonly interceptions: readonly InterceptionDeclaration[];
160
+ /** Declared interception points, deep-copied and frozen. */
161
+ readonly interceptionPoints: readonly InterceptionPointDeclaration[];
162
+ readonly kinds: readonly KindDeclaration[];
163
+ }
164
+ /** Raised when a manifest is not valid declarative data. */
165
+ export declare class ParticipantManifestError extends Error {
166
+ readonly code: "PARTICIPANT_MANIFEST_INVALID";
167
+ /** Token id of the participant whose manifest was refused. */
168
+ readonly participant: string;
169
+ constructor(participant: string, reason: string);
170
+ }
171
+ /**
172
+ * Validates and freezes a participant's manifest.
173
+ *
174
+ * Fails closed: an unknown field, a non-data value, or a malformed shape refuses
175
+ * the manifest. An absent manifest admits no requests and no exposures.
176
+ *
177
+ * @param participant - Token id of the participant, used in diagnostics.
178
+ * @param manifest - The declared manifest, or `undefined`.
179
+ */
180
+ export declare function admitParticipantManifest(participant: string, manifest: unknown): AdmittedManifest;
@@ -0,0 +1,334 @@
1
+ /**
2
+ * Participant manifest.
3
+ *
4
+ * A manifest is declarative data. It states what a participant requests and
5
+ * which exposures it gives, with the scope and policy of each. It contains no
6
+ * executable code. The kernel admits it at boot without invoking the
7
+ * participant's factory, and the participant's code cannot add, change, or
8
+ * remove an exposure afterwards.
9
+ */
10
+ /** Raised when a manifest is not valid declarative data. */
11
+ export class ParticipantManifestError extends Error {
12
+ code = 'PARTICIPANT_MANIFEST_INVALID';
13
+ /** Token id of the participant whose manifest was refused. */
14
+ participant;
15
+ constructor(participant, reason) {
16
+ super(`Manifest of participant "${participant}" is invalid: ${reason}`);
17
+ this.name = 'ParticipantManifestError';
18
+ this.participant = participant;
19
+ }
20
+ }
21
+ const MANIFEST_KEYS = new Set(['requests', 'exposures', 'events', 'interceptions', 'interceptionPoints', 'kinds']);
22
+ const KIND_KEYS = new Set(['kind', 'exposure', 'version', 'description', 'operations', 'permission']);
23
+ const KIND_OPERATION_KEYS = new Set(['description', 'input', 'permission']);
24
+ const KIND_OPERATION_PATTERN = /^[A-Za-z][A-Za-z0-9_.-]*$/u;
25
+ const KIND_PATTERN = /^[a-z][a-z0-9_-]*$/u;
26
+ const REQUEST_KEYS = new Set(['capabilities']);
27
+ const EXPOSURE_KEYS = new Set(['name', 'version', 'scope', 'policy']);
28
+ const EVENT_KEYS = new Set(['name', 'version', 'scope', 'policy', 'payloadSchema']);
29
+ const INTERCEPTION_KEYS = new Set(['target', 'version', 'stages']);
30
+ const INTERCEPTION_POINT_KEYS = new Set(['exposure', 'version', 'admit', 'outputLimits']);
31
+ function isPlainObject(value) {
32
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
33
+ return false;
34
+ }
35
+ const prototype = Object.getPrototypeOf(value);
36
+ return prototype === Object.prototype || prototype === null;
37
+ }
38
+ /** Deep-copies plain JSON data, refusing anything that is not plain data. */
39
+ function cloneData(value, path, participant) {
40
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') {
41
+ return value;
42
+ }
43
+ if (typeof value === 'number') {
44
+ if (!Number.isFinite(value)) {
45
+ throw new ParticipantManifestError(participant, `${path} must be a finite number`);
46
+ }
47
+ return value;
48
+ }
49
+ if (Array.isArray(value)) {
50
+ return Object.freeze(value.map((item, index) => cloneData(item, `${path}[${String(index)}]`, participant)));
51
+ }
52
+ if (isPlainObject(value)) {
53
+ const copy = {};
54
+ for (const [key, item] of Object.entries(value)) {
55
+ copy[key] = cloneData(item, `${path}.${key}`, participant);
56
+ }
57
+ return Object.freeze(copy);
58
+ }
59
+ throw new ParticipantManifestError(participant, `${path} must be declarative data, not code`);
60
+ }
61
+ function assertKnownKeys(value, allowed, path, participant) {
62
+ for (const key of Object.keys(value)) {
63
+ if (!allowed.has(key)) {
64
+ throw new ParticipantManifestError(participant, `${path} has unknown field "${key}"`);
65
+ }
66
+ }
67
+ }
68
+ /**
69
+ * Validates and freezes a participant's manifest.
70
+ *
71
+ * Fails closed: an unknown field, a non-data value, or a malformed shape refuses
72
+ * the manifest. An absent manifest admits no requests and no exposures.
73
+ *
74
+ * @param participant - Token id of the participant, used in diagnostics.
75
+ * @param manifest - The declared manifest, or `undefined`.
76
+ */
77
+ export function admitParticipantManifest(participant, manifest) {
78
+ if (manifest === undefined) {
79
+ return Object.freeze({
80
+ capabilities: Object.freeze([]),
81
+ exposures: Object.freeze([]),
82
+ events: Object.freeze([]),
83
+ interceptions: Object.freeze([]),
84
+ interceptionPoints: Object.freeze([]),
85
+ kinds: Object.freeze([]),
86
+ });
87
+ }
88
+ const data = cloneData(manifest, 'manifest', participant);
89
+ if (!isPlainObject(data)) {
90
+ throw new ParticipantManifestError(participant, 'manifest must be an object');
91
+ }
92
+ assertKnownKeys(data, MANIFEST_KEYS, 'manifest', participant);
93
+ const capabilities = [];
94
+ const requests = data.requests;
95
+ if (requests !== undefined) {
96
+ if (!isPlainObject(requests)) {
97
+ throw new ParticipantManifestError(participant, 'manifest.requests must be an object');
98
+ }
99
+ assertKnownKeys(requests, REQUEST_KEYS, 'manifest.requests', participant);
100
+ const requested = requests.capabilities;
101
+ if (requested !== undefined) {
102
+ if (!Array.isArray(requested)) {
103
+ throw new ParticipantManifestError(participant, 'manifest.requests.capabilities must be an array');
104
+ }
105
+ for (const capability of requested) {
106
+ if (typeof capability !== 'string' || capability.length === 0) {
107
+ throw new ParticipantManifestError(participant, 'manifest.requests.capabilities must contain non-empty strings');
108
+ }
109
+ if (!capabilities.includes(capability)) {
110
+ capabilities.push(capability);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ const exposures = [];
116
+ const declared = data.exposures;
117
+ if (declared !== undefined) {
118
+ if (!Array.isArray(declared)) {
119
+ throw new ParticipantManifestError(participant, 'manifest.exposures must be an array');
120
+ }
121
+ declared.forEach((exposure, index) => {
122
+ const path = `manifest.exposures[${String(index)}]`;
123
+ if (!isPlainObject(exposure)) {
124
+ throw new ParticipantManifestError(participant, `${path} must be an object`);
125
+ }
126
+ assertKnownKeys(exposure, EXPOSURE_KEYS, path, participant);
127
+ if (typeof exposure.name !== 'string' || exposure.name.length === 0) {
128
+ throw new ParticipantManifestError(participant, `${path}.name must be a non-empty string`);
129
+ }
130
+ if (exposure.version !== undefined
131
+ && typeof exposure.version !== 'number'
132
+ && typeof exposure.version !== 'string') {
133
+ throw new ParticipantManifestError(participant, `${path}.version must be a number or string`);
134
+ }
135
+ if (exposure.scope !== undefined && typeof exposure.scope !== 'string') {
136
+ throw new ParticipantManifestError(participant, `${path}.scope must be a string`);
137
+ }
138
+ if (exposure.policy !== undefined && !isPlainObject(exposure.policy)) {
139
+ throw new ParticipantManifestError(participant, `${path}.policy must be an object`);
140
+ }
141
+ exposures.push(exposure);
142
+ });
143
+ }
144
+ const events = [];
145
+ const declaredEvents = data.events;
146
+ if (declaredEvents !== undefined) {
147
+ if (!Array.isArray(declaredEvents)) {
148
+ throw new ParticipantManifestError(participant, 'manifest.events must be an array');
149
+ }
150
+ declaredEvents.forEach((event, index) => {
151
+ const path = `manifest.events[${String(index)}]`;
152
+ if (!isPlainObject(event)) {
153
+ throw new ParticipantManifestError(participant, `${path} must be an object`);
154
+ }
155
+ assertKnownKeys(event, EVENT_KEYS, path, participant);
156
+ if (typeof event.name !== 'string' || event.name.length === 0) {
157
+ throw new ParticipantManifestError(participant, `${path}.name must be a non-empty string`);
158
+ }
159
+ if (event.version !== undefined
160
+ && typeof event.version !== 'number'
161
+ && typeof event.version !== 'string') {
162
+ throw new ParticipantManifestError(participant, `${path}.version must be a number or string`);
163
+ }
164
+ if (event.scope !== undefined && typeof event.scope !== 'string') {
165
+ throw new ParticipantManifestError(participant, `${path}.scope must be a string`);
166
+ }
167
+ if (event.policy !== undefined && !isPlainObject(event.policy)) {
168
+ throw new ParticipantManifestError(participant, `${path}.policy must be an object`);
169
+ }
170
+ if (event.payloadSchema !== undefined && !isPlainObject(event.payloadSchema)) {
171
+ throw new ParticipantManifestError(participant, `${path}.payloadSchema must be an object`);
172
+ }
173
+ events.push(event);
174
+ });
175
+ }
176
+ const interceptions = admitInterceptions(data.interceptions, participant);
177
+ const interceptionPoints = admitInterceptionPoints(data.interceptionPoints, participant);
178
+ const kinds = admitKinds(data.kinds, exposures, participant);
179
+ return Object.freeze({
180
+ capabilities: Object.freeze(capabilities),
181
+ exposures: Object.freeze(exposures),
182
+ events: Object.freeze(events),
183
+ interceptions,
184
+ interceptionPoints,
185
+ kinds,
186
+ });
187
+ }
188
+ function assertVersion(value, path, participant) {
189
+ if (value !== undefined && typeof value !== 'number' && typeof value !== 'string') {
190
+ throw new ParticipantManifestError(participant, `${path}.version must be a number or string`);
191
+ }
192
+ }
193
+ function admitInterceptions(value, participant) {
194
+ if (value === undefined) {
195
+ return Object.freeze([]);
196
+ }
197
+ if (!Array.isArray(value)) {
198
+ throw new ParticipantManifestError(participant, 'manifest.interceptions must be an array');
199
+ }
200
+ return Object.freeze(value.map((entry, index) => {
201
+ const path = `manifest.interceptions[${String(index)}]`;
202
+ if (!isPlainObject(entry)) {
203
+ throw new ParticipantManifestError(participant, `${path} must be an object`);
204
+ }
205
+ assertKnownKeys(entry, INTERCEPTION_KEYS, path, participant);
206
+ if (typeof entry.target !== 'string' || entry.target.length === 0) {
207
+ throw new ParticipantManifestError(participant, `${path}.target must be a non-empty string`);
208
+ }
209
+ assertVersion(entry.version, path, participant);
210
+ const stages = entry.stages;
211
+ if (stages !== undefined
212
+ && (!Array.isArray(stages)
213
+ || stages.length === 0
214
+ || new Set(stages).size !== stages.length
215
+ || stages.some((stage) => stage !== 'input' && stage !== 'output'))) {
216
+ throw new ParticipantManifestError(participant, `${path}.stages must be a non-empty list of unique "input" or "output"`);
217
+ }
218
+ return Object.freeze({
219
+ ...entry,
220
+ ...(stages === undefined ? {} : { stages: Object.freeze([...stages]) }),
221
+ });
222
+ }));
223
+ }
224
+ /**
225
+ * Admits `manifest.kinds`. Each kind names one of the participant's own
226
+ * declared exposures, lists every operation it serves, and gives each
227
+ * operation a permission (its own, or the kind's); a kind may be claimed once
228
+ * per manifest. The Router validates and evaluates the permissions.
229
+ */
230
+ function admitKinds(value, exposures, participant) {
231
+ if (value === undefined) {
232
+ return Object.freeze([]);
233
+ }
234
+ if (!Array.isArray(value)) {
235
+ throw new ParticipantManifestError(participant, 'manifest.kinds must be an array');
236
+ }
237
+ const seen = new Set();
238
+ return Object.freeze(value.map((entry, index) => {
239
+ const path = `manifest.kinds[${String(index)}]`;
240
+ if (!isPlainObject(entry)) {
241
+ throw new ParticipantManifestError(participant, `${path} must be an object`);
242
+ }
243
+ assertKnownKeys(entry, KIND_KEYS, path, participant);
244
+ if (typeof entry.kind !== 'string' || !KIND_PATTERN.test(entry.kind)) {
245
+ throw new ParticipantManifestError(participant, `${path}.kind must be a lower-case kind word`);
246
+ }
247
+ if (seen.has(entry.kind)) {
248
+ throw new ParticipantManifestError(participant, `${path}.kind "${entry.kind}" is claimed twice`);
249
+ }
250
+ seen.add(entry.kind);
251
+ if (typeof entry.exposure !== 'string' || entry.exposure.length === 0) {
252
+ throw new ParticipantManifestError(participant, `${path}.exposure must be a non-empty string`);
253
+ }
254
+ assertVersion(entry.version, path, participant);
255
+ const major = String(entry.version ?? 1);
256
+ if (!exposures.some((exposure) => exposure.name === entry.exposure && String(exposure.version ?? 1) === major)) {
257
+ throw new ParticipantManifestError(participant, `${path}.exposure must name one of the participant's own declared exposures`);
258
+ }
259
+ if (entry.description !== undefined && typeof entry.description !== 'string') {
260
+ throw new ParticipantManifestError(participant, `${path}.description must be a string`);
261
+ }
262
+ if (entry.permission !== undefined && !isPlainObject(entry.permission)) {
263
+ throw new ParticipantManifestError(participant, `${path}.permission must be a policy object`);
264
+ }
265
+ if (entry.operations === 'open') {
266
+ if (entry.permission === undefined) {
267
+ throw new ParticipantManifestError(participant, `${path}.permission is required when operations is "open"; write { "policyVersion": 2 } to allow every routing caller`);
268
+ }
269
+ return Object.freeze(JSON.parse(JSON.stringify(entry)));
270
+ }
271
+ if (!isPlainObject(entry.operations) || Object.keys(entry.operations).length === 0) {
272
+ throw new ParticipantManifestError(participant, `${path}.operations is required: declare every operation the kind serves, or write "open" if its owner defines the names at runtime`);
273
+ }
274
+ for (const [name, operation] of Object.entries(entry.operations)) {
275
+ const at = `${path}.operations.${name}`;
276
+ if (!KIND_OPERATION_PATTERN.test(name)) {
277
+ throw new ParticipantManifestError(participant, `${at}: operation names start with a letter and use letters, digits, "_", "-" and "."`);
278
+ }
279
+ if (!isPlainObject(operation)) {
280
+ throw new ParticipantManifestError(participant, `${at} must be an object`);
281
+ }
282
+ assertKnownKeys(operation, KIND_OPERATION_KEYS, at, participant);
283
+ if (operation.description !== undefined && typeof operation.description !== 'string') {
284
+ throw new ParticipantManifestError(participant, `${at}.description must be a string`);
285
+ }
286
+ if (operation.input !== undefined && !isPlainObject(operation.input)) {
287
+ throw new ParticipantManifestError(participant, `${at}.input must be a JSON Schema object`);
288
+ }
289
+ if (operation.permission !== undefined && !isPlainObject(operation.permission)) {
290
+ throw new ParticipantManifestError(participant, `${at}.permission must be a policy object`);
291
+ }
292
+ if (operation.permission === undefined && entry.permission === undefined) {
293
+ throw new ParticipantManifestError(participant, `${at}.permission is required, or declare a kind-level permission; write { "policyVersion": 2 } to allow every routing caller`);
294
+ }
295
+ }
296
+ // Deep copy so the admitted declaration is plain, frozen data.
297
+ return Object.freeze(JSON.parse(JSON.stringify(entry)));
298
+ }));
299
+ }
300
+ function admitInterceptionPoints(value, participant) {
301
+ if (value === undefined) {
302
+ return Object.freeze([]);
303
+ }
304
+ if (!Array.isArray(value)) {
305
+ throw new ParticipantManifestError(participant, 'manifest.interceptionPoints must be an array');
306
+ }
307
+ return Object.freeze(value.map((entry, index) => {
308
+ const path = `manifest.interceptionPoints[${String(index)}]`;
309
+ if (!isPlainObject(entry)) {
310
+ throw new ParticipantManifestError(participant, `${path} must be an object`);
311
+ }
312
+ assertKnownKeys(entry, INTERCEPTION_POINT_KEYS, path, participant);
313
+ if (typeof entry.exposure !== 'string' || entry.exposure.length === 0) {
314
+ throw new ParticipantManifestError(participant, `${path}.exposure must be a non-empty string`);
315
+ }
316
+ assertVersion(entry.version, path, participant);
317
+ const admit = entry.admit;
318
+ if (!Array.isArray(admit)
319
+ || admit.some((token) => typeof token !== 'string' || token.length === 0)
320
+ || new Set(admit).size !== admit.length) {
321
+ const object = Array.isArray(admit) ? admit.find((token) => isPlainObject(token) && typeof token.id === 'string') : undefined;
322
+ const hint = object === undefined ? '' : ` A token object was given; pass its id string ("${object.id}") instead`;
323
+ throw new ParticipantManifestError(participant, `${path}.admit must be an array of unique non-empty service token id strings.${hint}`);
324
+ }
325
+ if (entry.outputLimits !== undefined && !isPlainObject(entry.outputLimits)) {
326
+ throw new ParticipantManifestError(participant, `${path}.outputLimits must be an object`);
327
+ }
328
+ return Object.freeze({
329
+ ...entry,
330
+ admit: Object.freeze([...admit]),
331
+ ...(entry.outputLimits === undefined ? {} : { outputLimits: Object.freeze({ ...entry.outputLimits }) }),
332
+ });
333
+ }));
334
+ }
@@ -0,0 +1,8 @@
1
+ import type { ExecutionContext } from './context.js';
2
+ import type { OperationHandler, OperationResult } from './handler.js';
3
+ export type MiddlewareNext = () => Promise<OperationResult>;
4
+ export type Middleware = (context: ExecutionContext, input: unknown, next: MiddlewareNext) => Promise<OperationResult>;
5
+ export interface IExecutionPipeline {
6
+ use(middleware: Middleware): void;
7
+ execute<TInput, TOutput>(handler: OperationHandler<TInput, TOutput>, context: ExecutionContext, input: TInput): Promise<OperationResult<TOutput>>;
8
+ }
@@ -0,0 +1 @@
1
+ export {};