@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.
- package/LICENSE +201 -0
- package/README.md +63 -2
- package/dist/index.d.ts +15 -0
- package/dist/index.js +13 -0
- package/dist/serviceModules/events.d.ts +1 -0
- package/dist/serviceModules/events.js +1 -0
- package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
- package/dist/serviceModules/exposedApiRegistry.js +1 -0
- package/dist/serviceModules/identityRegistry.d.ts +1 -0
- package/dist/serviceModules/identityRegistry.js +1 -0
- package/dist/serviceModules/interception.d.ts +1 -0
- package/dist/serviceModules/interception.js +1 -0
- package/dist/serviceModules/parser.d.ts +1 -0
- package/dist/serviceModules/parser.js +1 -0
- package/dist/serviceModules/router.d.ts +1 -0
- package/dist/serviceModules/router.js +1 -0
- package/dist/serviceModules/wasmCage.d.ts +1 -0
- package/dist/serviceModules/wasmCage.js +1 -0
- package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
- package/dist/services/Events/contracts/IEventsService.js +1 -0
- package/dist/services/Events/contracts/errors.d.ts +31 -0
- package/dist/services/Events/contracts/errors.js +40 -0
- package/dist/services/Events/contracts/index.d.ts +3 -0
- package/dist/services/Events/contracts/index.js +3 -0
- package/dist/services/Events/contracts/tokens.d.ts +2 -0
- package/dist/services/Events/contracts/tokens.js +2 -0
- package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
- package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
- package/dist/services/Events/descriptor/tokens.d.ts +1 -0
- package/dist/services/Events/descriptor/tokens.js +1 -0
- package/dist/services/Events/index.d.ts +4 -0
- package/dist/services/Events/index.js +4 -0
- package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
- package/dist/services/Events/orchestrator/EventsService.js +339 -0
- package/dist/services/Events/orchestrator/index.d.ts +2 -0
- package/dist/services/Events/orchestrator/index.js +2 -0
- package/dist/services/Events/orchestrator/limits.d.ts +22 -0
- package/dist/services/Events/orchestrator/limits.js +33 -0
- package/dist/services/Events/serviceModule.d.ts +2 -0
- package/dist/services/Events/serviceModule.js +5 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +56 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
- package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
- package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
- package/dist/services/ExposedApiRegistry/contracts/types.d.ts +133 -0
- package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
- package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
- package/dist/services/ExposedApiRegistry/index.js +5 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +68 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +452 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
- package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
- package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
- package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
- package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
- package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
- package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
- package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
- package/dist/services/IdentityRegistry/contracts/index.js +3 -0
- package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
- package/dist/services/IdentityRegistry/contracts/types.js +18 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
- package/dist/services/IdentityRegistry/index.d.ts +11 -0
- package/dist/services/IdentityRegistry/index.js +6 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
- package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
- package/dist/services/IdentityRegistry/serviceModule.js +24 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
- package/dist/services/Interception/contracts/IInterceptionService.d.ts +155 -0
- package/dist/services/Interception/contracts/IInterceptionService.js +12 -0
- package/dist/services/Interception/contracts/errors.d.ts +26 -0
- package/dist/services/Interception/contracts/errors.js +35 -0
- package/dist/services/Interception/contracts/index.d.ts +3 -0
- package/dist/services/Interception/contracts/index.js +3 -0
- package/dist/services/Interception/contracts/tokens.d.ts +2 -0
- package/dist/services/Interception/contracts/tokens.js +2 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.js +50 -0
- package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
- package/dist/services/Interception/descriptor/tokens.js +1 -0
- package/dist/services/Interception/index.d.ts +4 -0
- package/dist/services/Interception/index.js +4 -0
- package/dist/services/Interception/orchestrator/InterceptionService.d.ts +40 -0
- package/dist/services/Interception/orchestrator/InterceptionService.js +343 -0
- package/dist/services/Interception/orchestrator/index.d.ts +1 -0
- package/dist/services/Interception/orchestrator/index.js +1 -0
- package/dist/services/Interception/serviceModule.d.ts +2 -0
- package/dist/services/Interception/serviceModule.js +5 -0
- package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
- package/dist/services/Parser/contracts/IParserService.js +1 -0
- package/dist/services/Parser/contracts/errors.d.ts +25 -0
- package/dist/services/Parser/contracts/errors.js +33 -0
- package/dist/services/Parser/contracts/index.d.ts +4 -0
- package/dist/services/Parser/contracts/index.js +1 -0
- package/dist/services/Parser/contracts/types.d.ts +42 -0
- package/dist/services/Parser/contracts/types.js +1 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
- package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
- package/dist/services/Parser/descriptor/tokens.js +8 -0
- package/dist/services/Parser/index.d.ts +8 -0
- package/dist/services/Parser/index.js +8 -0
- package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
- package/dist/services/Parser/orchestrator/ParserService.js +105 -0
- package/dist/services/Parser/orchestrator/index.d.ts +1 -0
- package/dist/services/Parser/orchestrator/index.js +1 -0
- package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
- package/dist/services/Parser/parser/indexSynthesis.js +13 -0
- package/dist/services/Parser/parser/parameters.d.ts +14 -0
- package/dist/services/Parser/parser/parameters.js +89 -0
- package/dist/services/Parser/parser/scanner.d.ts +48 -0
- package/dist/services/Parser/parser/scanner.js +156 -0
- package/dist/services/Parser/parser/syntax.d.ts +30 -0
- package/dist/services/Parser/parser/syntax.js +34 -0
- package/dist/services/Parser/serviceModule.d.ts +2 -0
- package/dist/services/Parser/serviceModule.js +5 -0
- package/dist/services/Router/bootOptions.d.ts +2 -0
- package/dist/services/Router/bootOptions.js +2 -0
- package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
- package/dist/services/Router/contracts/IRouterService.js +1 -0
- package/dist/services/Router/contracts/caller.d.ts +6 -0
- package/dist/services/Router/contracts/caller.js +6 -0
- package/dist/services/Router/contracts/errors.d.ts +67 -0
- package/dist/services/Router/contracts/errors.js +90 -0
- package/dist/services/Router/contracts/index.d.ts +8 -0
- package/dist/services/Router/contracts/index.js +4 -0
- package/dist/services/Router/contracts/kind.d.ts +7 -0
- package/dist/services/Router/contracts/kind.js +10 -0
- package/dist/services/Router/contracts/registrant.d.ts +23 -0
- package/dist/services/Router/contracts/registrant.js +13 -0
- package/dist/services/Router/contracts/types.d.ts +110 -0
- package/dist/services/Router/contracts/types.js +1 -0
- package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
- package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
- package/dist/services/Router/descriptor/tokens.d.ts +9 -0
- package/dist/services/Router/descriptor/tokens.js +9 -0
- package/dist/services/Router/index.d.ts +4 -0
- package/dist/services/Router/index.js +4 -0
- package/dist/services/Router/orchestrator/RouterService.d.ts +93 -0
- package/dist/services/Router/orchestrator/RouterService.js +457 -0
- package/dist/services/Router/orchestrator/index.d.ts +2 -0
- package/dist/services/Router/orchestrator/index.js +1 -0
- package/dist/services/Router/serviceModule.d.ts +4 -0
- package/dist/services/Router/serviceModule.js +22 -0
- package/dist/services/WasmCage/index.d.ts +7 -0
- package/dist/services/WasmCage/index.js +4 -0
- package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
- package/dist/services/WasmCage/scripts/prepin.js +38 -0
- package/dist/services/WasmCage/serviceModule.d.ts +12 -0
- package/dist/services/WasmCage/serviceModule.js +18 -0
- package/dist/services/WasmCage/src/caged.d.ts +121 -0
- package/dist/services/WasmCage/src/caged.js +460 -0
- package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
- package/dist/services/WasmCage/src/descriptor.js +56 -0
- package/dist/services/WasmCage/src/native.d.ts +29 -0
- package/dist/services/WasmCage/src/native.js +66 -0
- package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
- package/dist/services/WasmCage/src/nativeDigests.js +15 -0
- package/dist/services/WasmCage/src/package.d.ts +36 -0
- package/dist/services/WasmCage/src/package.js +122 -0
- package/dist/services/shared/canonicalJson.d.ts +29 -0
- package/dist/services/shared/canonicalJson.js +93 -0
- package/dist/services/shared/documentStore.d.ts +16 -0
- package/dist/services/shared/documentStore.js +98 -0
- package/dist/src/bootstrap/bootKernelInternal.d.ts +19 -0
- package/dist/src/bootstrap/bootKernelInternal.js +633 -0
- package/dist/src/bootstrap/bootTypes.d.ts +113 -0
- package/dist/src/bootstrap/bootTypes.js +1 -0
- package/dist/src/bootstrap/config/index.d.ts +3 -0
- package/dist/src/bootstrap/config/index.js +2 -0
- package/dist/src/bootstrap/config/integrity.d.ts +45 -0
- package/dist/src/bootstrap/config/integrity.js +92 -0
- package/dist/src/bootstrap/config/parse.d.ts +15 -0
- package/dist/src/bootstrap/config/parse.js +81 -0
- package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
- package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
- package/dist/src/bootstrap/config/types.d.ts +41 -0
- package/dist/src/bootstrap/config/types.js +15 -0
- package/dist/src/bootstrap/hardcore.d.ts +212 -0
- package/dist/src/bootstrap/hardcore.js +312 -0
- package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
- package/dist/src/bootstrap/hardcoreServices.js +258 -0
- package/dist/src/bootstrap/index.d.ts +13 -0
- package/dist/src/bootstrap/index.js +7 -0
- package/dist/src/bootstrap/loaded.d.ts +30 -0
- package/dist/src/bootstrap/loaded.js +45 -0
- package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
- package/dist/src/bootstrap/packageRequirements.js +52 -0
- package/dist/src/bootstrap/reload.d.ts +44 -0
- package/dist/src/bootstrap/reload.js +45 -0
- package/dist/src/bootstrap/seal.d.ts +32 -0
- package/dist/src/bootstrap/seal.js +101 -0
- package/dist/src/contracts/accessBroker.d.ts +53 -0
- package/dist/src/contracts/accessBroker.js +1 -0
- package/dist/src/contracts/brudOperation.d.ts +20 -0
- package/dist/src/contracts/brudOperation.js +20 -0
- package/dist/src/contracts/callChain.d.ts +161 -0
- package/dist/src/contracts/callChain.js +19 -0
- package/dist/src/contracts/capability.d.ts +26 -0
- package/dist/src/contracts/capability.js +26 -0
- package/dist/src/contracts/capabilitySet.d.ts +23 -0
- package/dist/src/contracts/capabilitySet.js +72 -0
- package/dist/src/contracts/container.d.ts +17 -0
- package/dist/src/contracts/container.js +8 -0
- package/dist/src/contracts/context.d.ts +19 -0
- package/dist/src/contracts/context.js +1 -0
- package/dist/src/contracts/contextContract.d.ts +132 -0
- package/dist/src/contracts/contextContract.js +274 -0
- package/dist/src/contracts/dispatchView.d.ts +21 -0
- package/dist/src/contracts/dispatchView.js +1 -0
- package/dist/src/contracts/handler.d.ts +21 -0
- package/dist/src/contracts/handler.js +1 -0
- package/dist/src/contracts/index.d.ts +26 -0
- package/dist/src/contracts/index.js +9 -0
- package/dist/src/contracts/kernel.d.ts +60 -0
- package/dist/src/contracts/kernel.js +1 -0
- package/dist/src/contracts/lifecycle.d.ts +59 -0
- package/dist/src/contracts/lifecycle.js +1 -0
- package/dist/src/contracts/manifest.d.ts +180 -0
- package/dist/src/contracts/manifest.js +334 -0
- package/dist/src/contracts/pipeline.d.ts +8 -0
- package/dist/src/contracts/pipeline.js +1 -0
- package/dist/src/contracts/policy.d.ts +75 -0
- package/dist/src/contracts/policy.js +77 -0
- package/dist/src/contracts/registry.d.ts +7 -0
- package/dist/src/contracts/registry.js +1 -0
- package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
- package/dist/src/contracts/serviceDescriptor.js +1 -0
- package/dist/src/contracts/serviceToken.d.ts +36 -0
- package/dist/src/contracts/serviceToken.js +16 -0
- package/dist/src/engine/BrudKernel.d.ts +120 -0
- package/dist/src/engine/BrudKernel.js +395 -0
- package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
- package/dist/src/engine/ExecutionPipeline.js +62 -0
- package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
- package/dist/src/engine/KernelAccessBroker.js +107 -0
- package/dist/src/engine/KernelRegistry.d.ts +14 -0
- package/dist/src/engine/KernelRegistry.js +33 -0
- package/dist/src/engine/OperationRegistry.d.ts +9 -0
- package/dist/src/engine/OperationRegistry.js +18 -0
- package/dist/src/engine/ServiceContainer.d.ts +13 -0
- package/dist/src/engine/ServiceContainer.js +53 -0
- package/dist/src/engine/callChain.d.ts +68 -0
- package/dist/src/engine/callChain.js +175 -0
- package/dist/src/engine/dag.d.ts +2 -0
- package/dist/src/engine/dag.js +34 -0
- package/dist/src/engine/errors.d.ts +26 -0
- package/dist/src/engine/errors.js +52 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.js +8 -0
- package/dist/src/engine/state.d.ts +1 -0
- package/dist/src/engine/state.js +1 -0
- package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
- package/dist/src/validation/jsonSchema/compile.js +386 -0
- package/dist/src/validation/jsonSchema/index.d.ts +3 -0
- package/dist/src/validation/jsonSchema/index.js +2 -0
- package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
- package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
- package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
- package/dist/src/validation/jsonSchema/pattern.js +155 -0
- package/dist/src/validation/jsonSchema/types.d.ts +71 -0
- package/dist/src/validation/jsonSchema/types.js +15 -0
- package/package.json +59 -4
- package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class OperationRegistry {
|
|
2
|
+
handlers = new Map();
|
|
3
|
+
register(handler) {
|
|
4
|
+
if (this.handlers.has(handler.kind)) {
|
|
5
|
+
throw new Error(`Operation "${handler.kind}" is already registered`);
|
|
6
|
+
}
|
|
7
|
+
this.handlers.set(handler.kind, handler);
|
|
8
|
+
}
|
|
9
|
+
get(kind) {
|
|
10
|
+
return this.handlers.get(kind);
|
|
11
|
+
}
|
|
12
|
+
has(kind) {
|
|
13
|
+
return this.handlers.has(kind);
|
|
14
|
+
}
|
|
15
|
+
list() {
|
|
16
|
+
return Array.from(this.handlers.values());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IServiceContainer, Token } from '../contracts/container.js';
|
|
2
|
+
export declare class ServiceContainer implements IServiceContainer {
|
|
3
|
+
private readonly registry;
|
|
4
|
+
private readonly parent;
|
|
5
|
+
private _isFrozen;
|
|
6
|
+
constructor(parent?: IServiceContainer);
|
|
7
|
+
get isFrozen(): boolean;
|
|
8
|
+
freeze(): void;
|
|
9
|
+
register<T>(token: Token<T>, provider: T | (() => T)): void;
|
|
10
|
+
resolve<T>(token: Token<T>): T;
|
|
11
|
+
has<T>(token: Token<T>): boolean;
|
|
12
|
+
createChildScope(): IServiceContainer;
|
|
13
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class ServiceContainer {
|
|
2
|
+
registry = new Map();
|
|
3
|
+
parent;
|
|
4
|
+
_isFrozen = false;
|
|
5
|
+
constructor(parent) {
|
|
6
|
+
this.parent = parent ?? null;
|
|
7
|
+
}
|
|
8
|
+
get isFrozen() {
|
|
9
|
+
return this._isFrozen;
|
|
10
|
+
}
|
|
11
|
+
freeze() {
|
|
12
|
+
this._isFrozen = true;
|
|
13
|
+
}
|
|
14
|
+
register(token, provider) {
|
|
15
|
+
if (this._isFrozen) {
|
|
16
|
+
throw new Error("SecurityFault: Cannot register services into a frozen ServiceContainer at runtime.");
|
|
17
|
+
}
|
|
18
|
+
if (typeof provider === 'function' && !('__brand' in provider)) {
|
|
19
|
+
this.registry.set(token, { factory: provider });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.registry.set(token, { value: provider });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
resolve(token) {
|
|
26
|
+
const entry = this.registry.get(token);
|
|
27
|
+
if (entry) {
|
|
28
|
+
if ('factory' in entry) {
|
|
29
|
+
const instance = entry.factory();
|
|
30
|
+
this.registry.set(token, { value: instance });
|
|
31
|
+
return instance;
|
|
32
|
+
}
|
|
33
|
+
return entry.value;
|
|
34
|
+
}
|
|
35
|
+
if (this.parent) {
|
|
36
|
+
return this.parent.resolve(token);
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Unresolved token: ${token.description ?? String(token)}`);
|
|
39
|
+
}
|
|
40
|
+
has(token) {
|
|
41
|
+
if (this.registry.has(token)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return this.parent ? this.parent.has(token) : false;
|
|
45
|
+
}
|
|
46
|
+
createChildScope() {
|
|
47
|
+
const child = new ServiceContainer(this);
|
|
48
|
+
if (this._isFrozen) {
|
|
49
|
+
child._isFrozen = true;
|
|
50
|
+
}
|
|
51
|
+
return child;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type CallOrigin, type KernelCallAuthority, type KernelCallContext, type KernelCallLimits, type KernelCaller, type KernelHostSession, type KernelObservation } from '../contracts/callChain.js';
|
|
2
|
+
/** The kernel itself as a caller. */
|
|
3
|
+
export declare const KERNEL_CALLER: KernelCaller;
|
|
4
|
+
/** A participant the kernel has not assigned an identity to. */
|
|
5
|
+
export declare const UNIDENTIFIED_PARTICIPANT: KernelCaller;
|
|
6
|
+
/** One admitted participant as the call chain records it. */
|
|
7
|
+
export interface ChainParticipant {
|
|
8
|
+
/** Descriptor token id of the participant. */
|
|
9
|
+
readonly tokenId: string;
|
|
10
|
+
/** The participant as a caller. */
|
|
11
|
+
readonly caller: KernelCaller;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One kernel's call chain.
|
|
15
|
+
*
|
|
16
|
+
* Starts root frames, switches the current caller when the kernel mediates a
|
|
17
|
+
* call into a participant, applies per-identity limits, and keeps the
|
|
18
|
+
* observation stream.
|
|
19
|
+
*/
|
|
20
|
+
export declare class KernelCallChain implements KernelCallAuthority {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* @param instanceOf - Reads the initialized instance registered for a token.
|
|
24
|
+
* @param limits - Per-identity call and size limits.
|
|
25
|
+
*/
|
|
26
|
+
constructor(instanceOf: (tokenId: string) => unknown, limits?: KernelCallLimits);
|
|
27
|
+
/**
|
|
28
|
+
* Records the admitted participants for this boot.
|
|
29
|
+
*
|
|
30
|
+
* @param participants - Every admitted participant with its kernel caller.
|
|
31
|
+
*/
|
|
32
|
+
admitParticipants(participants: readonly ChainParticipant[]): void;
|
|
33
|
+
/** Forgets every participant; nothing is live after shutdown. */
|
|
34
|
+
clearParticipants(): void;
|
|
35
|
+
/** The kernel caller recorded for a descriptor token, if any. */
|
|
36
|
+
callerForToken(tokenId: string): KernelCaller | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Starts a root frame. The origin is fixed for everything that runs inside.
|
|
39
|
+
*
|
|
40
|
+
* @param origin - Root origin of the new chain.
|
|
41
|
+
* @param caller - Caller that starts the chain.
|
|
42
|
+
* @param operation - Work performed inside the chain.
|
|
43
|
+
*/
|
|
44
|
+
runRoot<T>(origin: CallOrigin, caller: KernelCaller, operation: () => T): T;
|
|
45
|
+
/**
|
|
46
|
+
* Starts a host-origin chain for one host session.
|
|
47
|
+
*
|
|
48
|
+
* @param session - The host session's declaration.
|
|
49
|
+
* @param operation - Work performed inside the chain.
|
|
50
|
+
*/
|
|
51
|
+
runHost<T>(session: KernelHostSession, operation: () => T): T;
|
|
52
|
+
current(): KernelCallContext | undefined;
|
|
53
|
+
runAsOrigin<T>(origin: CallOrigin, identity: string, operation: () => T): T;
|
|
54
|
+
runAs<T>(identity: string, operation: () => T): T;
|
|
55
|
+
/**
|
|
56
|
+
* Token id of the live participant holding `identity`, if any.
|
|
57
|
+
*
|
|
58
|
+
* @param identity - Kernel-issued identity.
|
|
59
|
+
*/
|
|
60
|
+
tokenIdOf(identity: string): string | undefined;
|
|
61
|
+
isLive(identity: string): boolean;
|
|
62
|
+
instanceOf(identity: string): unknown;
|
|
63
|
+
callerForIdentity(identity: string): KernelCaller | undefined;
|
|
64
|
+
admitCall(caller: KernelCaller, requestBytes: number): boolean;
|
|
65
|
+
observe(source: string, event: string, detail: Readonly<Record<string, unknown>>): void;
|
|
66
|
+
/** A snapshot of the observation stream, oldest first. */
|
|
67
|
+
observations(): readonly KernelObservation[];
|
|
68
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { NO_CAPABILITIES, createCapabilitySet } from '../contracts/capabilitySet.js';
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { DEFAULT_KERNEL_CALL_LIMITS, } from '../contracts/callChain.js';
|
|
4
|
+
/**
|
|
5
|
+
* Process-wide carrier of active frames.
|
|
6
|
+
*
|
|
7
|
+
* Several kernels may share one process. Each frame names the chain that owns
|
|
8
|
+
* it, and a chain reads only its own frames.
|
|
9
|
+
*/
|
|
10
|
+
const frames = new AsyncLocalStorage();
|
|
11
|
+
/** Largest number of records the observation stream retains. */
|
|
12
|
+
const OBSERVATION_CAPACITY = 1_000;
|
|
13
|
+
/** The kernel itself as a caller. */
|
|
14
|
+
export const KERNEL_CALLER = Object.freeze({
|
|
15
|
+
callerClass: 'kernel',
|
|
16
|
+
identity: null,
|
|
17
|
+
official: true,
|
|
18
|
+
capabilities: NO_CAPABILITIES,
|
|
19
|
+
});
|
|
20
|
+
/** A participant the kernel has not assigned an identity to. */
|
|
21
|
+
export const UNIDENTIFIED_PARTICIPANT = Object.freeze({
|
|
22
|
+
callerClass: 'participant',
|
|
23
|
+
identity: null,
|
|
24
|
+
official: false,
|
|
25
|
+
capabilities: NO_CAPABILITIES,
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* One kernel's call chain.
|
|
29
|
+
*
|
|
30
|
+
* Starts root frames, switches the current caller when the kernel mediates a
|
|
31
|
+
* call into a participant, applies per-identity limits, and keeps the
|
|
32
|
+
* observation stream.
|
|
33
|
+
*/
|
|
34
|
+
export class KernelCallChain {
|
|
35
|
+
#limits;
|
|
36
|
+
#instanceOf;
|
|
37
|
+
#byToken = new Map();
|
|
38
|
+
#byIdentity = new Map();
|
|
39
|
+
#usage = new Map();
|
|
40
|
+
#observations = [];
|
|
41
|
+
/**
|
|
42
|
+
* @param instanceOf - Reads the initialized instance registered for a token.
|
|
43
|
+
* @param limits - Per-identity call and size limits.
|
|
44
|
+
*/
|
|
45
|
+
constructor(instanceOf, limits = DEFAULT_KERNEL_CALL_LIMITS) {
|
|
46
|
+
this.#instanceOf = instanceOf;
|
|
47
|
+
this.#limits = Object.freeze({ ...limits });
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Records the admitted participants for this boot.
|
|
51
|
+
*
|
|
52
|
+
* @param participants - Every admitted participant with its kernel caller.
|
|
53
|
+
*/
|
|
54
|
+
admitParticipants(participants) {
|
|
55
|
+
this.#byToken.clear();
|
|
56
|
+
this.#byIdentity.clear();
|
|
57
|
+
for (const participant of participants) {
|
|
58
|
+
this.#byToken.set(participant.tokenId, participant);
|
|
59
|
+
if (participant.caller.identity !== null) {
|
|
60
|
+
this.#byIdentity.set(participant.caller.identity, participant);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Forgets every participant; nothing is live after shutdown. */
|
|
65
|
+
clearParticipants() {
|
|
66
|
+
this.#byToken.clear();
|
|
67
|
+
this.#byIdentity.clear();
|
|
68
|
+
this.#usage.clear();
|
|
69
|
+
}
|
|
70
|
+
/** The kernel caller recorded for a descriptor token, if any. */
|
|
71
|
+
callerForToken(tokenId) {
|
|
72
|
+
return this.#byToken.get(tokenId)?.caller;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Starts a root frame. The origin is fixed for everything that runs inside.
|
|
76
|
+
*
|
|
77
|
+
* @param origin - Root origin of the new chain.
|
|
78
|
+
* @param caller - Caller that starts the chain.
|
|
79
|
+
* @param operation - Work performed inside the chain.
|
|
80
|
+
*/
|
|
81
|
+
runRoot(origin, caller, operation) {
|
|
82
|
+
return frames.run({ chain: this, context: Object.freeze({ origin, caller }) }, operation);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Starts a host-origin chain for one host session.
|
|
86
|
+
*
|
|
87
|
+
* @param session - The host session's declaration.
|
|
88
|
+
* @param operation - Work performed inside the chain.
|
|
89
|
+
*/
|
|
90
|
+
runHost(session, operation) {
|
|
91
|
+
const capabilities = createCapabilitySet([...(session.capabilities ?? [])].filter((capability) => typeof capability === 'string' && capability.length > 0));
|
|
92
|
+
const caller = Object.freeze({
|
|
93
|
+
callerClass: 'host',
|
|
94
|
+
identity: null,
|
|
95
|
+
official: false,
|
|
96
|
+
capabilities,
|
|
97
|
+
});
|
|
98
|
+
return this.runRoot('host', caller, operation);
|
|
99
|
+
}
|
|
100
|
+
current() {
|
|
101
|
+
const frame = frames.getStore();
|
|
102
|
+
return frame?.chain === this ? frame.context : undefined;
|
|
103
|
+
}
|
|
104
|
+
runAsOrigin(origin, identity, operation) {
|
|
105
|
+
const participant = this.#byIdentity.get(identity);
|
|
106
|
+
if (participant === undefined) {
|
|
107
|
+
throw new Error('Identity is not live in this composition');
|
|
108
|
+
}
|
|
109
|
+
return frames.run({
|
|
110
|
+
chain: this,
|
|
111
|
+
context: Object.freeze({ origin, caller: participant.caller }),
|
|
112
|
+
}, operation);
|
|
113
|
+
}
|
|
114
|
+
runAs(identity, operation) {
|
|
115
|
+
const context = this.current();
|
|
116
|
+
if (context === undefined) {
|
|
117
|
+
throw new Error('No kernel call chain is active');
|
|
118
|
+
}
|
|
119
|
+
const participant = this.#byIdentity.get(identity);
|
|
120
|
+
if (participant === undefined) {
|
|
121
|
+
throw new Error('Identity is not live in this composition');
|
|
122
|
+
}
|
|
123
|
+
return frames.run({
|
|
124
|
+
chain: this,
|
|
125
|
+
context: Object.freeze({ origin: context.origin, caller: participant.caller }),
|
|
126
|
+
}, operation);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Token id of the live participant holding `identity`, if any.
|
|
130
|
+
*
|
|
131
|
+
* @param identity - Kernel-issued identity.
|
|
132
|
+
*/
|
|
133
|
+
tokenIdOf(identity) {
|
|
134
|
+
return this.#byIdentity.get(identity)?.tokenId;
|
|
135
|
+
}
|
|
136
|
+
isLive(identity) {
|
|
137
|
+
return this.#byIdentity.has(identity);
|
|
138
|
+
}
|
|
139
|
+
instanceOf(identity) {
|
|
140
|
+
const participant = this.#byIdentity.get(identity);
|
|
141
|
+
return participant === undefined ? undefined : this.#instanceOf(participant.tokenId);
|
|
142
|
+
}
|
|
143
|
+
callerForIdentity(identity) {
|
|
144
|
+
return this.#byIdentity.get(identity)?.caller;
|
|
145
|
+
}
|
|
146
|
+
admitCall(caller, requestBytes) {
|
|
147
|
+
if (!Number.isFinite(requestBytes) || requestBytes > this.#limits.maxRequestBytes) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const key = caller.identity ?? `class:${caller.callerClass}`;
|
|
151
|
+
const now = Date.now();
|
|
152
|
+
const usage = this.#usage.get(key);
|
|
153
|
+
if (usage === undefined || now - usage.windowStart >= this.#limits.windowMs) {
|
|
154
|
+
this.#usage.set(key, { windowStart: now, calls: 1 });
|
|
155
|
+
return 1 <= this.#limits.maxCallsPerWindow;
|
|
156
|
+
}
|
|
157
|
+
usage.calls += 1;
|
|
158
|
+
return usage.calls <= this.#limits.maxCallsPerWindow;
|
|
159
|
+
}
|
|
160
|
+
observe(source, event, detail) {
|
|
161
|
+
this.#observations.push(Object.freeze({
|
|
162
|
+
at: Date.now(),
|
|
163
|
+
source,
|
|
164
|
+
event,
|
|
165
|
+
detail: Object.freeze({ ...detail }),
|
|
166
|
+
}));
|
|
167
|
+
if (this.#observations.length > OBSERVATION_CAPACITY) {
|
|
168
|
+
this.#observations.splice(0, this.#observations.length - OBSERVATION_CAPACITY);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** A snapshot of the observation stream, oldest first. */
|
|
172
|
+
observations() {
|
|
173
|
+
return Object.freeze([...this.#observations]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CircularDependencyError, MissingDependencyError } from './errors.js';
|
|
2
|
+
export function topologicalSort(descriptors) {
|
|
3
|
+
const visitStates = new Map();
|
|
4
|
+
const path = [];
|
|
5
|
+
const ordered = [];
|
|
6
|
+
const visit = (tokenId, dependentTokenId) => {
|
|
7
|
+
const visitState = visitStates.get(tokenId);
|
|
8
|
+
if (visitState === 'VISITED') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (visitState === 'VISITING') {
|
|
12
|
+
const cycleStart = path.indexOf(tokenId);
|
|
13
|
+
const cyclePath = path.slice(cycleStart === -1 ? 0 : cycleStart);
|
|
14
|
+
cyclePath.push(tokenId);
|
|
15
|
+
throw new CircularDependencyError(cyclePath);
|
|
16
|
+
}
|
|
17
|
+
const descriptor = descriptors.get(tokenId);
|
|
18
|
+
if (descriptor === undefined) {
|
|
19
|
+
throw new MissingDependencyError(tokenId, dependentTokenId ?? tokenId);
|
|
20
|
+
}
|
|
21
|
+
visitStates.set(tokenId, 'VISITING');
|
|
22
|
+
path.push(tokenId);
|
|
23
|
+
for (const dependency of descriptor.dependencies) {
|
|
24
|
+
visit(dependency.id, tokenId);
|
|
25
|
+
}
|
|
26
|
+
path.pop();
|
|
27
|
+
visitStates.set(tokenId, 'VISITED');
|
|
28
|
+
ordered.push(descriptor);
|
|
29
|
+
};
|
|
30
|
+
for (const tokenId of descriptors.keys()) {
|
|
31
|
+
visit(tokenId, undefined);
|
|
32
|
+
}
|
|
33
|
+
return ordered;
|
|
34
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { KernelLifecycleState } from './state.js';
|
|
2
|
+
export declare class LifecycleStateError extends Error {
|
|
3
|
+
readonly code: "INVALID_LIFECYCLE_STATE";
|
|
4
|
+
readonly operation: string;
|
|
5
|
+
readonly currentState: KernelLifecycleState | undefined;
|
|
6
|
+
readonly expectedState: KernelLifecycleState | undefined;
|
|
7
|
+
constructor(operation: string, currentState?: KernelLifecycleState, expectedState?: KernelLifecycleState);
|
|
8
|
+
private static formatMessage;
|
|
9
|
+
}
|
|
10
|
+
export declare class CircularDependencyError extends Error {
|
|
11
|
+
readonly code: "CIRCULAR_DEPENDENCY";
|
|
12
|
+
readonly cyclePath: readonly string[];
|
|
13
|
+
constructor(cyclePath: readonly string[]);
|
|
14
|
+
}
|
|
15
|
+
export declare class MissingDependencyError extends Error {
|
|
16
|
+
readonly code: "MISSING_DEPENDENCY";
|
|
17
|
+
readonly missingTokenId: string;
|
|
18
|
+
readonly dependentTokenId: string;
|
|
19
|
+
constructor(missingTokenId: string, dependentTokenId: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class ServiceNotFoundError extends Error {
|
|
22
|
+
readonly code: "SERVICE_NOT_FOUND";
|
|
23
|
+
readonly tokenId: string;
|
|
24
|
+
constructor(tokenId: string);
|
|
25
|
+
}
|
|
26
|
+
export { AccessDeniedError, BlacklistedAccessViolationError, AllowlistViolationError, } from '../contracts/policy.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class LifecycleStateError extends Error {
|
|
2
|
+
code = 'INVALID_LIFECYCLE_STATE';
|
|
3
|
+
operation;
|
|
4
|
+
currentState;
|
|
5
|
+
expectedState;
|
|
6
|
+
constructor(operation, currentState, expectedState) {
|
|
7
|
+
super(LifecycleStateError.formatMessage(operation, currentState, expectedState));
|
|
8
|
+
this.name = 'LifecycleStateError';
|
|
9
|
+
this.operation = operation;
|
|
10
|
+
this.currentState = currentState;
|
|
11
|
+
this.expectedState = expectedState;
|
|
12
|
+
}
|
|
13
|
+
static formatMessage(operation, currentState, expectedState) {
|
|
14
|
+
if (currentState === undefined) {
|
|
15
|
+
return `Operation "${operation}" is not permitted in the current kernel lifecycle state`;
|
|
16
|
+
}
|
|
17
|
+
if (expectedState === undefined) {
|
|
18
|
+
return `Operation "${operation}" is not permitted while the kernel is ${currentState}`;
|
|
19
|
+
}
|
|
20
|
+
return `Operation "${operation}" requires kernel state ${expectedState} but the kernel is ${currentState}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class CircularDependencyError extends Error {
|
|
24
|
+
code = 'CIRCULAR_DEPENDENCY';
|
|
25
|
+
cyclePath;
|
|
26
|
+
constructor(cyclePath) {
|
|
27
|
+
super(`Circular dependency detected: ${cyclePath.join(' -> ')}`);
|
|
28
|
+
this.name = 'CircularDependencyError';
|
|
29
|
+
this.cyclePath = [...cyclePath];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class MissingDependencyError extends Error {
|
|
33
|
+
code = 'MISSING_DEPENDENCY';
|
|
34
|
+
missingTokenId;
|
|
35
|
+
dependentTokenId;
|
|
36
|
+
constructor(missingTokenId, dependentTokenId) {
|
|
37
|
+
super(`Service "${dependentTokenId}" depends on unregistered service "${missingTokenId}"`);
|
|
38
|
+
this.name = 'MissingDependencyError';
|
|
39
|
+
this.missingTokenId = missingTokenId;
|
|
40
|
+
this.dependentTokenId = dependentTokenId;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class ServiceNotFoundError extends Error {
|
|
44
|
+
code = 'SERVICE_NOT_FOUND';
|
|
45
|
+
tokenId;
|
|
46
|
+
constructor(tokenId) {
|
|
47
|
+
super(`Service "${tokenId}" is not registered`);
|
|
48
|
+
this.name = 'ServiceNotFoundError';
|
|
49
|
+
this.tokenId = tokenId;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export { AccessDeniedError, BlacklistedAccessViolationError, AllowlistViolationError, } from '../contracts/policy.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ServiceContainer } from './ServiceContainer.js';
|
|
2
|
+
export { OperationRegistry } from './OperationRegistry.js';
|
|
3
|
+
export { ExecutionPipeline } from './ExecutionPipeline.js';
|
|
4
|
+
export { BrudKernel } from './BrudKernel.js';
|
|
5
|
+
export type { KernelExecuteOptions, PromptManifest, PromptManifestEntry } from './BrudKernel.js';
|
|
6
|
+
export { KernelRegistry } from './KernelRegistry.js';
|
|
7
|
+
export { KernelAccessBroker } from './KernelAccessBroker.js';
|
|
8
|
+
export type { KernelStateChecker } from './KernelAccessBroker.js';
|
|
9
|
+
export { topologicalSort } from './dag.js';
|
|
10
|
+
export { LifecycleStateError, CircularDependencyError, MissingDependencyError, ServiceNotFoundError, } from './errors.js';
|
|
11
|
+
export type { KernelLifecycleState } from './state.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { ServiceContainer } from './ServiceContainer.js';
|
|
2
|
+
export { OperationRegistry } from './OperationRegistry.js';
|
|
3
|
+
export { ExecutionPipeline } from './ExecutionPipeline.js';
|
|
4
|
+
export { BrudKernel } from './BrudKernel.js';
|
|
5
|
+
export { KernelRegistry } from './KernelRegistry.js';
|
|
6
|
+
export { KernelAccessBroker } from './KernelAccessBroker.js';
|
|
7
|
+
export { topologicalSort } from './dag.js';
|
|
8
|
+
export { LifecycleStateError, CircularDependencyError, MissingDependencyError, ServiceNotFoundError, } from './errors.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type KernelLifecycleState = 'UNINITIALIZED' | 'BOOTING' | 'RUNNING' | 'SHUTTING_DOWN' | 'DISPOSED';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JsonSchemaCompileResult, JsonSchemaLimits } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compiles an untrusted JSON Schema into a frozen, reusable validator.
|
|
4
|
+
*
|
|
5
|
+
* @param schema - Schema to compile. It is copied; later changes to it have no effect.
|
|
6
|
+
* @param limits - Optional overrides of {@link DEFAULT_JSON_SCHEMA_LIMITS}.
|
|
7
|
+
*/
|
|
8
|
+
export declare function compileJsonSchema(schema: unknown, limits?: Partial<JsonSchemaLimits>): JsonSchemaCompileResult;
|