@almadar/shell-runtime 0.0.0-stage → 1.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 (127) hide show
  1. package/dist/chunk-4SEK5ER2.js +8 -0
  2. package/dist/chunk-57SBCUSM.js +62 -0
  3. package/dist/chunk-625EP7W2.js +108 -0
  4. package/dist/chunk-64IH2SMY.js +22 -0
  5. package/dist/chunk-7SDV3QWR.js +67 -0
  6. package/dist/chunk-7WB6VWRK.js +798 -0
  7. package/dist/chunk-A2JJT4GA.js +56 -0
  8. package/dist/chunk-BAS26HBN.js +10 -0
  9. package/dist/chunk-BOVU4TCQ.js +65 -0
  10. package/dist/chunk-BY5G4225.js +6 -0
  11. package/dist/chunk-DFDNHVDW.js +284 -0
  12. package/dist/chunk-ELBLT2HZ.js +1 -0
  13. package/dist/chunk-EZZYLTWY.js +1 -0
  14. package/dist/chunk-FWA5K7Q2.js +48 -0
  15. package/dist/chunk-HC6ERSAH.js +55 -0
  16. package/dist/chunk-HLOUDLPI.js +48 -0
  17. package/dist/chunk-I3TKINSO.js +398 -0
  18. package/dist/chunk-IOPUS6Q5.js +15 -0
  19. package/dist/chunk-LKWYCYX5.js +22 -0
  20. package/dist/chunk-LYFIQPXX.js +1 -0
  21. package/dist/chunk-LZIOTBFX.js +1 -0
  22. package/dist/chunk-MU335ZA4.js +63 -0
  23. package/dist/chunk-MZKIL5IN.js +74 -0
  24. package/dist/chunk-N7HYNKK6.js +83 -0
  25. package/dist/chunk-NTFQ36UN.js +52 -0
  26. package/dist/chunk-NU6LVKGS.js +15 -0
  27. package/dist/chunk-O57GKTYU.js +30 -0
  28. package/dist/chunk-P2N6K2IV.js +20 -0
  29. package/dist/chunk-P53CKOME.js +1 -0
  30. package/dist/chunk-QCJWPXLH.js +40 -0
  31. package/dist/chunk-SKLMWHQD.js +109 -0
  32. package/dist/chunk-SOQDEPME.js +131 -0
  33. package/dist/chunk-UBN5JJKZ.js +26 -0
  34. package/dist/chunk-UD2CXYSJ.js +244 -0
  35. package/dist/chunk-UP6GGGAN.js +34 -0
  36. package/dist/chunk-V4EMDPCO.js +33 -0
  37. package/dist/chunk-VNGXRYFF.js +9 -0
  38. package/dist/chunk-WGCWJOT2.js +21 -0
  39. package/dist/chunk-X6W44WHO.js +26 -0
  40. package/dist/chunk-XXWNMJI6.js +15 -0
  41. package/dist/chunk-ZUSM4VW4.js +197 -0
  42. package/dist/client/EventTransport.d.ts +147 -0
  43. package/dist/client/EventTransport.js +1 -0
  44. package/dist/client/awaiting.d.ts +28 -0
  45. package/dist/client/awaiting.js +1 -0
  46. package/dist/client/channel-transport.d.ts +69 -0
  47. package/dist/client/channel-transport.js +1 -0
  48. package/dist/client/circuit-store.d.ts +87 -0
  49. package/dist/client/circuit-store.js +3 -0
  50. package/dist/client/client-kernel.d.ts +134 -0
  51. package/dist/client/client-kernel.js +1 -0
  52. package/dist/client/declared-input-dispatch.d.ts +22 -0
  53. package/dist/client/declared-input-dispatch.js +1 -0
  54. package/dist/client/inbound-dispatch.d.ts +24 -0
  55. package/dist/client/inbound-dispatch.js +1 -0
  56. package/dist/client/local-fold.d.ts +33 -0
  57. package/dist/client/local-fold.js +1 -0
  58. package/dist/client/render-sigils.d.ts +24 -0
  59. package/dist/client/render-sigils.js +1 -0
  60. package/dist/client/state-book.d.ts +30 -0
  61. package/dist/client/state-book.js +1 -0
  62. package/dist/client/trait-mount-error.d.ts +9 -0
  63. package/dist/client/trait-mount-error.js +1 -0
  64. package/dist/client/trait-types.d.ts +67 -0
  65. package/dist/client/trait-types.js +1 -0
  66. package/dist/credentials/env-vars.d.ts +18 -0
  67. package/dist/credentials/env-vars.js +1 -0
  68. package/dist/credentials/scope.d.ts +51 -0
  69. package/dist/credentials/scope.js +1 -0
  70. package/dist/credentials/vault.d.ts +142 -0
  71. package/dist/credentials/vault.js +1 -0
  72. package/dist/effects/in-flight-calls.d.ts +36 -0
  73. package/dist/effects/in-flight-calls.js +1 -0
  74. package/dist/effects/on-device-model.d.ts +22 -0
  75. package/dist/effects/on-device-model.js +1 -0
  76. package/dist/events/EventBus.d.ts +87 -0
  77. package/dist/events/EventBus.js +1 -0
  78. package/dist/events/emit-stamp.d.ts +47 -0
  79. package/dist/events/emit-stamp.js +1 -0
  80. package/dist/index.d.ts +43 -0
  81. package/dist/index.js +41 -0
  82. package/dist/kernel/decode.d.ts +13 -0
  83. package/dist/kernel/decode.js +1 -0
  84. package/dist/kernel/engine.d.ts +195 -0
  85. package/dist/kernel/engine.js +9 -0
  86. package/dist/kernel/frame-applier.d.ts +44 -0
  87. package/dist/kernel/frame-applier.js +1 -0
  88. package/dist/kernel/host.d.ts +206 -0
  89. package/dist/kernel/host.js +6 -0
  90. package/dist/kernel/lane.d.ts +7 -0
  91. package/dist/kernel/lane.js +1 -0
  92. package/dist/kernel/os-fetch-port.d.ts +7 -0
  93. package/dist/kernel/os-fetch-port.js +3 -0
  94. package/dist/kernel/os-port.d.ts +155 -0
  95. package/dist/kernel/os-port.js +1 -0
  96. package/dist/kernel/program-effects.d.ts +48 -0
  97. package/dist/kernel/program-effects.js +1 -0
  98. package/dist/kernel/secret-ports.d.ts +139 -0
  99. package/dist/kernel/secret-ports.js +2 -0
  100. package/dist/kernel/wire.d.ts +104 -0
  101. package/dist/kernel/wire.js +1 -0
  102. package/dist/loader/fetch-loader.d.ts +26 -0
  103. package/dist/loader/fetch-loader.js +1 -0
  104. package/dist/loader/lazy-page.d.ts +12 -0
  105. package/dist/loader/lazy-page.js +1 -0
  106. package/dist/loader/schema-loader.d.ts +144 -0
  107. package/dist/loader/schema-loader.js +1 -0
  108. package/dist/persistence/native-memory.d.ts +28 -0
  109. package/dist/persistence/native-memory.js +1 -0
  110. package/dist/runtime/entities/declaredCollections.d.ts +6 -0
  111. package/dist/runtime/entities/declaredCollections.js +1 -0
  112. package/dist/runtime/evaluation/local-store-transport.d.ts +59 -0
  113. package/dist/runtime/evaluation/local-store-transport.js +14 -0
  114. package/dist/runtime/evaluation/residence-transport.d.ts +15 -0
  115. package/dist/runtime/evaluation/residence-transport.js +1 -0
  116. package/dist/runtime/evaluation/routed-persistence.d.ts +9 -0
  117. package/dist/runtime/evaluation/routed-persistence.js +1 -0
  118. package/dist/runtime/events/identity/routing.d.ts +33 -0
  119. package/dist/runtime/events/identity/routing.js +1 -0
  120. package/dist/runtime/types.d.ts +374 -0
  121. package/dist/runtime/types.js +1 -0
  122. package/dist/service/default-call-service.d.ts +23 -0
  123. package/dist/service/default-call-service.js +2 -0
  124. package/dist/service/service-provider.d.ts +37 -0
  125. package/dist/service/service-provider.js +1 -0
  126. package/package.json +49 -3
  127. package/README.md +0 -3
@@ -0,0 +1,195 @@
1
+ import { OrbitalSchema, ExternalInput, InboundRoute, InboundAnswer, InboundDelivery, EventPayload, EventRequest, LiveBroadcastItem, MountSeed, PayloadField, JsonSchema, PayloadIssue, EntityRow, UserContext, RowSetRef, RowQueryPage, EventResponse, EventStreamItem, JsonValue } from '@almadar/core';
2
+ import { ProgramSurface } from '@almadar/core/kernel-wire';
3
+ import { KernelHostPorts, KernelAnswerScope } from './host.js';
4
+ import { KernelModule, KernelServerHandle, FiredByOrbital } from './wire.js';
5
+ import '../effects/in-flight-calls.js';
6
+ import '../service/service-provider.js';
7
+ import './program-effects.js';
8
+ import './secret-ports.js';
9
+ import '../credentials/vault.js';
10
+ import './os-port.js';
11
+
12
+ /**
13
+ * The kernel-backed implementation of `evaluateOrbitalEvent` / `OrbitalServerRuntime`: the Rust kernel
14
+ * (`@almadar/kernel`, WebAssembly) decides every execution step; this host answers the I/O it asks for
15
+ * and nothing else. The continuation of a stopped dispatch never leaves the wasm instance.
16
+ */
17
+
18
+ type ContractAsk = <T>(schema: {
19
+ parse(input: ReturnType<typeof JSON.parse>): T;
20
+ }, query: object) => T;
21
+ declare function contractAnswers(ask: ContractAsk): {
22
+ findExternalInput(orbital: string, trait: string, event: string): ExternalInput | undefined;
23
+ findInbound(name: string): {
24
+ route: InboundRoute;
25
+ } | {
26
+ answer: InboundAnswer;
27
+ };
28
+ inboundPayload(route: InboundRoute, delivery: InboundDelivery, credential: string | null | undefined): EventPayload;
29
+ inboundAnswer(route: InboundRoute, emitted: readonly {
30
+ event: string;
31
+ payload?: EventPayload;
32
+ }[], error: string | undefined): InboundAnswer;
33
+ credentialUnset(credential: string): InboundAnswer;
34
+ dispatchFailed(message: string): InboundAnswer;
35
+ };
36
+ /** The declared-contract answers of a host holding no program: the kernel's own answers on an empty kernel. */
37
+ type ProgramlessContract = ReturnType<typeof contractAnswers>;
38
+ declare class KernelEngine {
39
+ private readonly kernel;
40
+ private readonly schemaJson;
41
+ private readonly ports;
42
+ private readonly entityTypes;
43
+ private readonly preserveProgramContext;
44
+ private readonly lazyDir?;
45
+ private handle;
46
+ private readonly turns;
47
+ private tickRelayIntervalMs;
48
+ private stateful;
49
+ constructor(kernel: KernelModule, schemaJson: string, ports: KernelHostPorts, entityTypes?: readonly string[], forkedFrom?: KernelServerHandle, providedHandle?: KernelServerHandle, preserveProgramContext?: boolean, lazyDir?: string | undefined);
50
+ /**
51
+ * A kernel on the same program, registered once, holding none of this one's session: every trait at its initial
52
+ * state, no rows the kernel held, its mounted ticks kept. A stateless host serves each request a
53
+ * fork (EXEC-DIST-5), `ports` answering it.
54
+ */
55
+ fork(ports?: KernelHostPorts): KernelEngine;
56
+ forkProgram(program: OrbitalSchema, ports?: KernelHostPorts): KernelEngine;
57
+ /** A server over the host's ports. */
58
+ private openServer;
59
+ private declare;
60
+ /** The contract answers for a host with no program registered yet: the kernel's, asked with no program. */
61
+ static withoutProgram(kernel: KernelModule): ProgramlessContract;
62
+ static open(kernel: KernelModule, schema: OrbitalSchema, ports: KernelHostPorts, lazyDir?: string): KernelEngine;
63
+ /** A fresh kernel on the same program: every trait back at its initial state. */
64
+ reset(): void;
65
+ private managedProgram;
66
+ /** The program whose declared credentials this kernel's credential effects manage beside its own (a console's app). */
67
+ setManagedProgram(program: OrbitalSchema): void;
68
+ /** `client` mounted `traits` of `orbital`: their mount-scoped ticks fire while any client holds them. A request derives this itself; this is for a mount made outside a request. */
69
+ mountClient(client: string, orbital: string, traits: readonly string[]): void;
70
+ unmountClient(client: string, orbital: string, traits: readonly string[]): void;
71
+ /** `client` is gone: everything it mounted is released. */
72
+ releaseClient(client: string): void;
73
+ /** This host holds the circuit state: the kernel takes a client's copy of it only on a delegated leg and refuses any other request carrying one. */
74
+ setStateful(): void;
75
+ /** Whether the program declares any tick: the host runs its timer only then. */
76
+ declaresTicks(): boolean;
77
+ /** Queue a tick-stamped dispatch for the coalesced peer relay; the ms after which to flush when it opened a window. */
78
+ relayTick(orbital: string, request: EventRequest): number | undefined;
79
+ /** The relay window's length in ms; the kernel's default is 50. */
80
+ setTickRelayInterval(intervalMs: number): void;
81
+ /** Every item queued since the window opened, in first-arrival order; the window closes. */
82
+ flushTickRelay(): LiveBroadcastItem[];
83
+ /** One pass of the kernel's tick clock: the ticks due at monotonic `nowMs` that this server runs (`[background]` ticks, and those of a mounted trait), keyed by the orbital each `runTick` request is addressed to. */
84
+ tickPass(nowMs: number): FiredByOrbital;
85
+ /** Stop the kernel's tick clock; its phase is kept. */
86
+ tickPause(): void;
87
+ /** Restart the kernel's tick clock; the paused span is never counted. */
88
+ tickResume(): void;
89
+ tickPaused(): boolean;
90
+ /** What this host mounts when it starts: the kernel's boot mounts for the side it serves (EXEC-ENDPOINT-3). */
91
+ bootMounts(side: 'server' | 'process'): MountSeed[];
92
+ /** What mounts when a client opens `routePath` (EXEC-ENDPOINT-3). */
93
+ routeMounts(routePath: string): MountSeed[];
94
+ dispose(): void;
95
+ private readonly answers;
96
+ private contract;
97
+ /** Every external input the program declares: what an outside client may send which trait. */
98
+ externalInputs(): ExternalInput[];
99
+ /** What the kernel holds of every trait of the program, in name order, and the browser-stored entities. */
100
+ programSurface(): ProgramSurface;
101
+ /** The entities a provider acting as the caller may read. */
102
+ readableEntities(): string[];
103
+ /** The declared input of `trait.event` in `orbital`, when there is one. */
104
+ findExternalInput(orbital: string, trait: string, event: string): ExternalInput | undefined;
105
+ /** The declared input a `listens`-addressed event names from `caller`'s position (`EVENT`, `Trait.EVENT`, `Orbital.Trait.EVENT`), when there is one. */
106
+ findInputByAddress(address: string, caller: {
107
+ orbital: string;
108
+ trait: string;
109
+ }): ExternalInput | undefined;
110
+ /** A declared payload as the JSON Schema of one object: what a tool-calling model fills. */
111
+ payloadJsonSchema(fields: readonly PayloadField[]): JsonSchema;
112
+ /** The ways `value` misses the declared payload `fields`. */
113
+ payloadIssues(fields: readonly PayloadField[], value: EventPayload): PayloadIssue[];
114
+ /** The route a hook name is delivered to, or the answer to write for a hook the program does not serve. */
115
+ findInbound(name: string): {
116
+ route: InboundRoute;
117
+ } | {
118
+ answer: InboundAnswer;
119
+ };
120
+ /** The trait that handles `event` as an inbound hook in `orbital`, with the refusal message, when a client-facing request names it. */
121
+ inboundOnly(orbital: string, trait: string | undefined, event: string): {
122
+ trait: string;
123
+ message: string;
124
+ } | undefined;
125
+ /** The payload an inbound event is delivered with. */
126
+ inboundPayload(route: InboundRoute, delivery: InboundDelivery, credential: string | null | undefined): EventPayload;
127
+ /** The HTTP answer a finished dispatch produced for `route`. */
128
+ inboundAnswer(route: InboundRoute, emitted: readonly {
129
+ event: string;
130
+ payload?: EventPayload;
131
+ }[], error: string | undefined): InboundAnswer;
132
+ /** The answer for a route whose credential the host holds no value for. */
133
+ credentialUnset(credential: string): InboundAnswer;
134
+ /** The answer for a delivery whose dispatch failed. */
135
+ dispatchFailed(message: string): InboundAnswer;
136
+ /** The name of the program's `[identity]` entity, when it declares one. */
137
+ identityEntity(): string | undefined;
138
+ /** The orbital that declares `entity` inline. */
139
+ entityOwnerOrbital(entity: string): string | undefined;
140
+ /** `rows` of `entity` as `user` reads them: narrowed by the entity's declared `@read`, which the kernel evaluates with `@user` bound to the viewer. */
141
+ readRows(entity: string, rows: readonly EntityRow[], user: UserContext | undefined): EntityRow[];
142
+ liveItemDelivered(item: object, clientId?: string): boolean;
143
+ /** `OsGrants::allows` over the grants of `orbital` in the program this kernel runs (the app level alone with no orbital). */
144
+ osAllows(requirementJson: string, orbital?: string): boolean;
145
+ /** Whether `url`'s origin is declared in the program's `egress` (the kernel's rule). */
146
+ egressAllows(url: string): boolean;
147
+ /** Place the program's anchored grants and arguments under the host's anchors. */
148
+ setOsAnchors(anchorsJson: string): string;
149
+ /** An `os/` call's arguments with its anchored parts resolved under the host's anchors. */
150
+ osResolveArgs(op: string, argsJson: string): string;
151
+ tlsComplete(key: string, outcomeJson: string): string;
152
+ /** A live stream of `client`'s session opened (EXEC-DIST-9); the id closes it. */
153
+ openSessionStream(client: string): number;
154
+ /** The live stream `id` dropped: the kernel frees the session once its streams have all dropped and it is quiet. */
155
+ closeSessionStream(id: number): boolean;
156
+ /** The current state of a trait instance, `''` when it has none. */
157
+ stateOf(traitName: string, entityId?: string): string;
158
+ /**
159
+ * `reference` resolved for the identity `scope.originClientId`'s session bound (the anonymous viewer with none) against the host-answered store (EXEC-RENDER-3): the rows that still
160
+ * match its query and that identity's `@read` in the reference's order, a missing or hidden row omitted, and `total`
161
+ * re-counted (a `total: none` reference is not re-counted: the total is the resolved window). Each read the
162
+ * kernel makes is answered here, as in `evaluate`.
163
+ */
164
+ resolveRows(reference: RowSetRef, scope: KernelAnswerScope): Promise<RowQueryPage>;
165
+ /**
166
+ * Run `request` against `orbital`. The kernel orders every start and every resumption (EXEC-CONC-2): while another
167
+ * dispatch holds the lane it answers `queued` and runs the work itself once the lane frees; this host only answers
168
+ * what each dispatch asks.
169
+ */
170
+ evaluate(orbital: string, request: EventRequest, scope: KernelAnswerScope): Promise<EventResponse>;
171
+ /** The kernel's answer to a start or resume, once it has run: at once, or when the kernel takes it from its queue. */
172
+ private ran;
173
+ private running;
174
+ /** Run each piece of queued work that can run now, in the kernel's order, handing each to the dispatch it continues. */
175
+ private runQueued;
176
+ }
177
+ /** What `evaluateOrbitalEvent` needs to run a request on the kernel instead of the JS composition. */
178
+ interface KernelEvaluation {
179
+ engine: KernelEngine;
180
+ /** The orbital the request is addressed to. */
181
+ orbital: string;
182
+ onStream?: (item: EventStreamItem) => void;
183
+ }
184
+ /**
185
+ * The request as the kernel takes it: the locale the host resolved, the `_targetTrait` sidecar
186
+ * promoted to `targetTrait`, and the `_activeTraits` sidecar dropped (the kernel's mounted set is explicit,
187
+ * not carried per request).
188
+ */
189
+ declare function kernelRequest(request: EventRequest & {
190
+ user?: JsonValue;
191
+ }, locale: string | undefined): EventRequest;
192
+ declare function evaluateOnKernel(kernel: KernelEvaluation, request: EventRequest, locale: string | undefined): Promise<EventResponse>;
193
+
194
+ export { KernelEngine, evaluateOnKernel, kernelRequest };
195
+ export type { KernelEvaluation, ProgramlessContract };
@@ -0,0 +1,9 @@
1
+ export { KernelEngine, evaluateOnKernel, kernelRequest } from '../chunk-I3TKINSO.js';
2
+ import '../chunk-NU6LVKGS.js';
3
+ import '../chunk-X6W44WHO.js';
4
+ import '../chunk-7WB6VWRK.js';
5
+ import '../chunk-WGCWJOT2.js';
6
+ import '../chunk-ZUSM4VW4.js';
7
+ import '../chunk-FWA5K7Q2.js';
8
+ import '../chunk-HLOUDLPI.js';
9
+ import '../chunk-MZKIL5IN.js';
@@ -0,0 +1,44 @@
1
+ import { FrameWire, RoutedLeg } from '@almadar/core/kernel-wire';
2
+ import { EventResponse } from '@almadar/core';
3
+ import { ClientKernelOutcome, LocalFoldKernel } from '../client/client-kernel.js';
4
+ import '../client/circuit-store.js';
5
+ import '../client/awaiting.js';
6
+ import '../client/state-book.js';
7
+ import '../client/trait-types.js';
8
+
9
+ /**
10
+ * Applies one host frame of the tick clock (`Kernel.frame`'s `FrameWire`) to the view. The in-process
11
+ * kernel already ran the frame, so it folds locally (`LocalFoldKernel`), never through the server fold:
12
+ * the aggregate response first (embed.rs: "the host folds `response` before the dispatches"; it is built
13
+ * from the fired ticks' own outcomes, not from the dispatches, so the two are disjoint), then each tick
14
+ * dispatch. Every post a dispatch owes (its server legs or stateful leg) and every browser-store leg goes
15
+ * through the injected `FramePostPort`; the answers settle off the frame (`tickSettled`) so a tick round trip
16
+ * never delays the next frame.
17
+ */
18
+
19
+ /** `frame()`'s JSON; `undefined` (no tick due) decodes to `undefined`. */
20
+ declare function decodeFrame(json: string | undefined): FrameWire | undefined;
21
+ type TickEffects = Pick<EventResponse, 'clientEffectsByTrait'>;
22
+ type FrameDispatch = FrameWire['dispatches'][number];
23
+ /** The host transport's side of a frame: posts what a fired tick owes and folds the answer back through the kernel. */
24
+ interface FramePostPort {
25
+ /** Posts one dispatch's server legs (or stateful leg); resolves to what the server's fold added. */
26
+ postDispatch(dispatch: FrameDispatch): Promise<TickEffects>;
27
+ /** Sends a leg the kernel routed to the browser store; `frameResponse` is the frame's aggregate response. */
28
+ sendBrowserLeg(leg: RoutedLeg, frameResponse: EventResponse): Promise<TickEffects>;
29
+ }
30
+ interface FrameApplied {
31
+ fired: FrameWire['fired'];
32
+ /** How many ticks fired, across every orbital. */
33
+ firedCount: number;
34
+ folded: number;
35
+ browserLegs: number;
36
+ droppedServerEffects: number;
37
+ /** The head is the frame's aggregate response, then one outcome per browser leg, then one per dispatch. */
38
+ outcomes: ClientKernelOutcome[];
39
+ errors: string[];
40
+ }
41
+ declare function applyFrame(json: string | undefined, kernel: LocalFoldKernel, post: FramePostPort | undefined): Promise<FrameApplied>;
42
+
43
+ export { applyFrame, decodeFrame };
44
+ export type { FrameApplied, FrameDispatch, FramePostPort, TickEffects };
@@ -0,0 +1 @@
1
+ export { applyFrame, decodeFrame } from '../chunk-NTFQ36UN.js';
@@ -0,0 +1,206 @@
1
+ import { PageFactField, BrowserPageFacts, PersistenceAdapter, ServiceParams, EventPayload, JsonValue, UserContext, ServiceHostPorts, OnDeviceModelPorts, BrowserTabPort, JsonObject, EventStreamItem, HostAskCompletion } from '@almadar/core';
2
+ import { InFlightCalls } from '../effects/in-flight-calls.js';
3
+ import { ServiceCallContext } from '../service/service-provider.js';
4
+ import { ProgramEffectName, ProgramEffectOutcome } from './program-effects.js';
5
+ import { SecretPorts } from './secret-ports.js';
6
+ import { Settled, EventRequest, CallSiteWire, SubstrateFailureWire, IoRequestWire, IoAnswerWire, OsError } from '@almadar/core/kernel-wire';
7
+ import { KernelModule } from './wire.js';
8
+ import { OsHostPort, OsCompletionPort, OsTlsPort, OsCompletionEvent } from './os-port.js';
9
+ import '../credentials/vault.js';
10
+
11
+ /**
12
+ * The host half of the kernel path: the I/O the kernel asks for, answered with the runtime's own
13
+ * adapters. Persistence goes through the `PersistenceAdapter` (`@almadar/db`), `call-service` through the
14
+ * injected provider (or the mock / integrations default the JS stage uses), substrate operators through
15
+ * the program host. Nothing here decides an execution step.
16
+ */
17
+
18
+ /** `call-service`, as the host answers it: the host's handler, mock mode, or the integrations default. */
19
+ type KernelCallService = (service: string, action: string, params: ServiceParams | undefined, context: ServiceCallContext | undefined) => Promise<EventPayload | null>;
20
+ /** A follow-on step's `call-service` outcome, run later as a dispatch of its own on `traitName`. */
21
+ interface DeferredCallOutcome {
22
+ orbital: string;
23
+ traitName: string;
24
+ event: string;
25
+ payload: EventPayload | undefined;
26
+ entityId: string | undefined;
27
+ originClientId: string | undefined;
28
+ locale: string | undefined;
29
+ }
30
+ interface SubstrateStreamSource {
31
+ subscribe(message: (value: JsonValue) => void, ended: () => void): () => void;
32
+ }
33
+ /** The `audio/*` asks: a sound or music key, absent where the op names none (stop every sound, stop the music). */
34
+ type HostAudioAsk = {
35
+ op: 'audio/play-sound';
36
+ key: string;
37
+ } | {
38
+ op: 'audio/stop-sound';
39
+ key: string | undefined;
40
+ } | {
41
+ op: 'audio/change-music';
42
+ key: string | undefined;
43
+ } | {
44
+ op: 'audio/stop-music';
45
+ };
46
+ /** The one object `auth/sign-in` takes: the method and the credentials it needs. */
47
+ type HostSignInRequest = {
48
+ method: 'google';
49
+ } | {
50
+ method: 'email';
51
+ email: string;
52
+ password: string;
53
+ } | {
54
+ method: 'emailLink';
55
+ email: string;
56
+ continueUrl: string;
57
+ } | {
58
+ method: 'emailLink';
59
+ email: string;
60
+ link: string;
61
+ } | {
62
+ method: 'customToken';
63
+ token: string;
64
+ };
65
+ /** What a sign-in answers: the viewer, or `{ sent: true }` for an email link that was only sent. */
66
+ type HostSignInAnswer = {
67
+ uid: string;
68
+ email?: string;
69
+ displayName?: string;
70
+ } | {
71
+ sent: true;
72
+ };
73
+ /** The one object `auth/consent` takes: the authorize URL the viewer is sent to. */
74
+ interface HostConsentRequest {
75
+ authorizeUrl: string;
76
+ }
77
+ /** What a consent answers: the `code` and `state` query params of the final redirect URL, read as they are. */
78
+ interface HostConsentAnswer {
79
+ code: string;
80
+ state: string;
81
+ }
82
+ /** Why a host ask failed: the viewer closed it, the provider denied it, the request was malformed, or the host has no such action. */
83
+ type HostAskFailureKind = 'cancelled' | 'denied' | 'invalid' | 'unavailable';
84
+ /** A host action's own failure, carrying the kind the completion reports. */
85
+ declare class HostAskError extends Error {
86
+ readonly kind: HostAskFailureKind;
87
+ constructor(kind: HostAskFailureKind, message: string);
88
+ }
89
+ /** What the client host does for the `audio/*`, `auth/sign-out`, `auth/sign-in` and `auth/consent` asks; a host that has none refuses them by name. */
90
+ interface KernelHostActions {
91
+ audio?: (ask: HostAudioAsk) => void;
92
+ signOut?: () => void | Promise<void>;
93
+ signIn?: (request: HostSignInRequest) => Promise<HostSignInAnswer>;
94
+ consent?: (request: HostConsentRequest) => Promise<HostConsentAnswer>;
95
+ }
96
+ /** A host ask's answer: the payload of its success route, or the error and kind of its failure route. */
97
+ type HostAskOutcome = {
98
+ ok: JsonObject;
99
+ } | {
100
+ error: string;
101
+ kind: HostAskFailureKind;
102
+ };
103
+ /** The event a host's answer dispatches: to `trait` (on `entityId` when the frame is a row), carrying `payload`. */
104
+ interface HostAskReturn {
105
+ trait: string;
106
+ entityId?: string;
107
+ event: string;
108
+ payload: JsonObject;
109
+ }
110
+ interface KernelHostPorts {
111
+ hostActions?: KernelHostActions;
112
+ pageFacts?: (fields: readonly PageFactField[]) => BrowserPageFacts;
113
+ persistence: PersistenceAdapter;
114
+ callService: KernelCallService;
115
+ /** The program host, read per call: a host wires it lazily. */
116
+ programEffect: () => ((op: ProgramEffectName, args: readonly JsonValue[], context?: Pick<ServiceCallContext, 'principal' | 'role'>) => Promise<ProgramEffectOutcome>) | undefined;
117
+ inFlightCalls: InFlightCalls;
118
+ /** The running app lent to one `call-service` provider as the caller. */
119
+ servicePorts: (caller: {
120
+ orbital: string;
121
+ trait: string;
122
+ }, user: UserContext | undefined, message: (payload: EventPayload) => void, assertReentry?: () => void) => ServiceHostPorts;
123
+ /** Deliver one live message of a running call (`emit.onMessage`) to the requesting tab only, never in-band. */
124
+ deliverLive: (site: {
125
+ orbital: string;
126
+ trait: string;
127
+ event: string;
128
+ }, payload: EventPayload, originClientId: string | undefined) => void;
129
+ /** Read per call: the sink a follow-on call's outcome runs through, absent when the host cannot deliver it to the tab. */
130
+ deferCallOutcome: () => ((call: DeferredCallOutcome) => void) | undefined;
131
+ /** The secret store, CSPRNG and credential administration ports the kernel's secret, random and credential asks use. */
132
+ secretPorts?: SecretPorts;
133
+ /** The on-device model and embedder; absent, a `browser/prompt` or `browser/embed` ask fails `unconfigured`. */
134
+ onDevice?: OnDeviceModelPorts;
135
+ /** The browser's tabs for the `browser/tab-*` effects; absent, a tab ask fails `unavailable`. */
136
+ tabs?: BrowserTabPort;
137
+ /** The `os` effect's host (Node: `createNodeOsHost` from `@almadar/shell-node`); absent, every `os` ask is denied, as the native host does with none. */
138
+ os?: OsHostPort;
139
+ /** What the kernel decides about a deferred `os` call (which ops defer, the event an outcome fires); absent, every `os` ask is answered in place. */
140
+ osCompletions?: OsCompletionPort;
141
+ /** The kernel's TLS state for sockets it owns (EXEC-HTTP-7); absent, a deferred outcome reaches its route as the host gave it. */
142
+ osTls?: OsTlsPort;
143
+ /** The kernel's typed parse of a `program/dispatch` event request; absent, that ask is refused. */
144
+ parseEventRequest?: EventRequestParser;
145
+ substrateStream?: (op: string, args: readonly JsonValue[], scope: KernelAnswerScope) => SubstrateStreamSource | undefined;
146
+ substrateMessage?: (site: CallSiteWire, key: string, value: JsonValue) => OsCompletionEvent | null;
147
+ substrateCompletion?: (site: CallSiteWire, key: string, op: string, args: readonly JsonValue[], outcome: Settled<JsonValue, SubstrateFailureWire>) => OsCompletionEvent | null;
148
+ /** The host clock in epoch milliseconds, answering the kernel's `clock` ask; absent, the system clock. */
149
+ now?: () => number;
150
+ }
151
+ /** What one dispatch brings to its answers. */
152
+ interface KernelAnswerScope {
153
+ /** The orbital the request is addressed to. */
154
+ orbital: string;
155
+ /** The requesting tab. */
156
+ originClientId?: string;
157
+ locale?: string;
158
+ entityId?: string;
159
+ onStream?: (item: EventStreamItem) => void;
160
+ assertReentry?: () => void;
161
+ }
162
+ /** The kernel's typed parse of a `program/dispatch` event request: the request, or the reason it is none. */
163
+ type EventRequestParser = (payload: JsonObject, options: JsonObject) => Settled<EventRequest, string>;
164
+ /** The request parser over the kernel module: `EventRequest::from_dispatch`, not copied. */
165
+ declare function kernelEventRequestParser(kernel: Pick<KernelModule, 'parseEventRequest'>): EventRequestParser;
166
+ /** `audio/*` and `auth/sign-out`: one ask each, performed by the host's actions; a host without them refuses by name. */
167
+ declare function performHostAsk(actions: KernelHostActions | undefined, op: string, args: readonly JsonValue[]): Promise<Settled<null, string>>;
168
+ /** The `auth/sign-in` request an ask carries, or why it is refused before the host is asked. */
169
+ declare function parseSignInRequest(args: readonly JsonValue[]): {
170
+ request: HostSignInRequest;
171
+ } | {
172
+ error: string;
173
+ };
174
+ /** The `auth/consent` request an ask carries, or why it is refused before the host is asked. */
175
+ declare function parseConsentRequest(args: readonly JsonValue[]): {
176
+ request: HostConsentRequest;
177
+ } | {
178
+ error: string;
179
+ };
180
+ /** The `code` and `state` query params of a consent's final redirect URL, read as they are; a redirect without both is a denial. */
181
+ declare function consentFromRedirect(redirectUrl: string): HostConsentAnswer;
182
+ /** The answer of one host ask whose completion the host returns: `auth/sign-in` through the host's sign-in, `auth/consent` through its consent, any other op as it is performed (an empty success). */
183
+ declare function performHostAnswer(actions: KernelHostActions | undefined, op: string, args: readonly JsonValue[]): Promise<HostAskOutcome>;
184
+ /** The event `outcome` fires on the ask's declared route, or undefined when the ask declared none for it (nothing fires). */
185
+ declare function hostAskReturn(completion: HostAskCompletion, outcome: HostAskOutcome): HostAskReturn | undefined;
186
+ /**
187
+ * A deferred raw `os` outcome that belongs to a TLS operation the kernel parked (EXEC-HTTP-7) is finished in the kernel:
188
+ * it decrypts or encrypts the raw outcome and, while it needs more raw bytes, asks the host's `os` port for them. Any
189
+ * other key's outcome is returned as it stands.
190
+ */
191
+ declare function finishTls(ports: KernelHostPorts, os: OsHostPort, key: string, raw: Settled<JsonValue, OsError>): Promise<Settled<JsonValue, OsError>>;
192
+ /**
193
+ * The same loop, handing the outcome to `finish` in the calling turn whenever the kernel needs no further raw ask
194
+ * (nothing parked, or done at once); only a parked operation's follow-up ask makes it wait (EXEC-QUEUE-10/13).
195
+ */
196
+ declare function completeTls(ports: KernelHostPorts, os: OsHostPort, key: string, raw: Settled<JsonValue, OsError>, finish: (outcome: Settled<JsonValue, OsError>) => void): void;
197
+ declare function writeRows(persistence: PersistenceAdapter, request: Extract<IoRequestWire, {
198
+ kind: 'writeRows';
199
+ }>): Promise<IoAnswerWire>;
200
+ /** Tell the kernel what the adapter pushes down for each entity type, once, before the first dispatch. */
201
+ declare function declareCapabilities(persistence: PersistenceAdapter, declare: (entityType: string, queryJson: string, writeJson: string) => void, entityTypes: readonly string[]): void;
202
+ /** Answer one request of the kernel; a thrown adapter error becomes the request's declared failure. */
203
+ declare function answerRequest(ports: KernelHostPorts, request: IoRequestWire, scope: KernelAnswerScope): Promise<IoAnswerWire>;
204
+
205
+ export { HostAskError, answerRequest, completeTls, consentFromRedirect, declareCapabilities, finishTls, hostAskReturn, kernelEventRequestParser, parseConsentRequest, parseSignInRequest, performHostAnswer, performHostAsk, writeRows };
206
+ export type { DeferredCallOutcome, EventRequestParser, HostAskFailureKind, HostAskOutcome, HostAskReturn, HostAudioAsk, HostConsentAnswer, HostConsentRequest, HostSignInAnswer, HostSignInRequest, KernelAnswerScope, KernelCallService, KernelHostActions, KernelHostPorts, SubstrateStreamSource };
@@ -0,0 +1,6 @@
1
+ export { HostAskError, answerRequest, completeTls, consentFromRedirect, declareCapabilities, finishTls, hostAskReturn, kernelEventRequestParser, parseConsentRequest, parseSignInRequest, performHostAnswer, performHostAsk, writeRows } from '../chunk-7WB6VWRK.js';
2
+ import '../chunk-WGCWJOT2.js';
3
+ import '../chunk-ZUSM4VW4.js';
4
+ import '../chunk-FWA5K7Q2.js';
5
+ import '../chunk-HLOUDLPI.js';
6
+ import '../chunk-MZKIL5IN.js';
@@ -0,0 +1,7 @@
1
+ declare class LaneHeldByParkedDispatch extends Error {
2
+ readonly ticket: number;
3
+ readonly event: string;
4
+ constructor(ticket: number, event: string);
5
+ }
6
+
7
+ export { LaneHeldByParkedDispatch };
@@ -0,0 +1 @@
1
+ export { LaneHeldByParkedDispatch } from '../chunk-NU6LVKGS.js';
@@ -0,0 +1,7 @@
1
+ import { OsHostPort } from './os-port.js';
2
+ import '@almadar/core';
3
+ import '@almadar/core/kernel-wire';
4
+
5
+ declare function createFetchOsHost(performFetch: typeof fetch): OsHostPort;
6
+
7
+ export { createFetchOsHost };
@@ -0,0 +1,3 @@
1
+ export { createFetchOsHost } from '../chunk-625EP7W2.js';
2
+ import '../chunk-ZUSM4VW4.js';
3
+ import '../chunk-HLOUDLPI.js';
@@ -0,0 +1,155 @@
1
+ import { JsonValue } from '@almadar/core';
2
+ import { OsOp, Settled, OsError, CallSiteWire } from '@almadar/core/kernel-wire';
3
+
4
+ /**
5
+ * The `os` ports of a kernel host, with no Node builtin in sight so the browser bundle can import them.
6
+ * The Node answerer is `os-node.ts`; the grant check is the Rust `OsGrants` (`allows` below), never TypeScript.
7
+ */
8
+
9
+ type OsFsMode = 'read' | 'write' | 'create' | 'remove' | 'meta';
10
+ type OsNetKind = 'tcp' | 'udp' | 'listen';
11
+ type OsStdioKind = 'in' | 'out' | 'err';
12
+ type OsSysKind = 'cpu' | 'memory' | 'disk' | 'network' | 'power-state' | 'identity';
13
+ type OsDesktopKind = 'notify' | 'speak' | 'brightness' | 'volume' | 'power';
14
+ /** One thing an `os/` call needs from the program's grants: the JSON of Rust `OsRequirement`. */
15
+ type OsRequirement = {
16
+ need: 'fs';
17
+ path: string;
18
+ mode: OsFsMode;
19
+ } | {
20
+ need: 'exec';
21
+ command: string;
22
+ } | {
23
+ need: 'net';
24
+ host: string;
25
+ port: number;
26
+ kinds: OsNetKind[];
27
+ } | {
28
+ need: 'env';
29
+ name: string;
30
+ } | {
31
+ need: 'stdio';
32
+ kind: OsStdioKind;
33
+ } | {
34
+ need: 'sys';
35
+ kind: OsSysKind;
36
+ } | {
37
+ need: 'desktop';
38
+ kind: OsDesktopKind;
39
+ };
40
+ /** The grant decisions the wasm kernel owns (`OsGrants::allows`, the one-grant glob matcher, `is_public_address`). */
41
+ interface OsGrantPort {
42
+ /** `OsGrants::allows` over the grants of `orbital` (its own plus the app level); with no orbital, the app level alone. */
43
+ allows(need: OsRequirement, orbital?: string): boolean;
44
+ /** Whether the absolute `glob` (`**`, `*`, `?`) matches `path`, as a one-grant `fs_allows` for read. */
45
+ globMatches(glob: string, path: string): boolean;
46
+ /** `is_public_address`: the rule an outbound host name must pass. */
47
+ isPublicAddress(ip: string): boolean;
48
+ /** Place the program's anchored grants and arguments under the host's anchors (`set_os_anchors_json`); answers what grants nothing. */
49
+ anchor(anchors: OsAnchors): OsAnchorProblem[];
50
+ /** An `os/` call's arguments with every anchored part replaced by what it names under the host's anchors (`resolve_anchored_args`). */
51
+ resolveArgs(op: OsOp, args: JsonValue[]): Settled<JsonValue[], OsError>;
52
+ }
53
+ /** An anchored grant entry that grants nothing under the host's anchors. */
54
+ interface OsAnchorProblem {
55
+ path: string;
56
+ message: string;
57
+ }
58
+ /** What a host answers an `os` ask with; `close` drops every handle it holds, as the native `OsHandles::close_all`. */
59
+ interface OsHostPort {
60
+ /** `orbital` is the orbital whose trait made the ask: its grants (plus the app's) answer it. */
61
+ answer(op: OsOp, args: JsonValue[], orbital?: string): Promise<Settled<JsonValue, OsError>>;
62
+ /**
63
+ * `Completions::run_later`: a keyed ask of a completion-deferring op. A failed check (or a key already pending) is the
64
+ * in-place `error`; `ok` means the work runs in the background and its outcome reaches `deliver` once, unless
65
+ * the key is cancelled first. A host with no `defer` answers every ask in place.
66
+ */
67
+ defer?(op: OsOp, args: JsonValue[], key: string, deliver: (outcome: Settled<JsonValue, OsError>) => void, orbital?: string): Settled<null, OsError>;
68
+ /**
69
+ * A keyed stream (`OsOp::is_stream`, EXEC-QUEUE-12): the host binds and answers once in place, then hands each message
70
+ * to `message` until it ends; `message` answers `false` when no one takes it any more. A failure after the answer
71
+ * reaches `fail` once. A host with no `stream` answers every stream ask in place, as unsupported.
72
+ */
73
+ stream?(op: OsOp, args: JsonValue[], key: string, message: (value: JsonValue) => boolean, fail: (error: OsError) => void, orbital?: string): Promise<Settled<JsonValue, OsError>>;
74
+ /** `OsHandles::cancel_completion`: drop the pending completion of `key`, or stop its stream; `false` when none is open. */
75
+ cancel?(key: string): boolean;
76
+ close(): void;
77
+ }
78
+ /** The event a deferred `os` call's outcome fires on its call site, as the kernel shapes it. */
79
+ interface OsCompletionEvent {
80
+ event: string;
81
+ payload: JsonValue;
82
+ }
83
+ /** What the wasm kernel decides about a deferred `os` call: which ops defer, and the event an outcome fires. */
84
+ interface OsCompletionPort {
85
+ defers(op: OsOp): boolean;
86
+ streams(op: OsOp): boolean;
87
+ event(site: CallSiteWire, key: string, outcome: Settled<JsonValue, OsError>): OsCompletionEvent | null;
88
+ }
89
+ /** The next step of a TLS operation the kernel parked on a deferred raw ask. */
90
+ type OsTlsStep = {
91
+ ask: {
92
+ op: OsOp;
93
+ args: JsonValue[];
94
+ };
95
+ } | {
96
+ done: Settled<JsonValue, OsError>;
97
+ };
98
+ /** The kernel's TLS sockets (EXEC-HTTP-7): the host's raw outcome of a deferred ask goes in, the next raw ask or the program's outcome comes out. */
99
+ interface OsTlsPort {
100
+ /** `null` when `key` parks no TLS operation. */
101
+ complete(key: string, outcome: Settled<JsonValue, OsError>): OsTlsStep | null;
102
+ }
103
+ /** The server handle's TLS export. */
104
+ interface OsTlsKernel {
105
+ tlsComplete(key: string, outcomeJson: string): string;
106
+ }
107
+ /** The TLS port over the kernel `Server` handle: every decision is `RuntimeKernel::tls_complete`. */
108
+ declare function kernelOsTls(server: () => OsTlsKernel): OsTlsPort;
109
+ /** The kernel exports the completion port is built from. */
110
+ interface OsCompletionMatchers {
111
+ osDeferringOps(): string;
112
+ osStreamOps(): string;
113
+ osCompletionEvent(siteJson: string, key: string, outcomeJson: string): string;
114
+ }
115
+ /** The completion port over the wasm kernel: `OsOp::defers_completion`, `OsOp::is_stream` and `completion_event`, not copied. */
116
+ declare function kernelOsCompletions(kernel: OsCompletionMatchers): OsCompletionPort;
117
+ /** The kernel pieces a grant port is built from: the `Server` handle holding the program's grants and the module-level matchers. */
118
+ interface OsGrantKernel {
119
+ osAllows(requirementJson: string, orbital?: string): boolean;
120
+ setOsAnchors(anchorsJson: string): string;
121
+ osResolveArgs(op: string, argsJson: string): string;
122
+ }
123
+ interface OsGrantMatchers {
124
+ osGlobMatches(glob: string, path: string): boolean;
125
+ isPublicAddress(ip: string): boolean;
126
+ }
127
+ /** The grant port over the wasm kernel: every decision is `OsGrants::allows` and the exports beside it. */
128
+ declare function kernelOsGrants(matchers: OsGrantMatchers, server: () => OsGrantKernel): OsGrantPort;
129
+ /**
130
+ * Where a host anchors `~/` and `./` paths and grants (the user's home and the directory it started the program in), and
131
+ * what a grant's declared anchors resolve to: its executable's directory and its boot environment (`orbital-core` `OsAnchors`).
132
+ */
133
+ interface OsAnchors {
134
+ readonly home?: string;
135
+ readonly start?: string;
136
+ readonly exeDir?: string;
137
+ readonly exe?: string;
138
+ readonly env?: Readonly<Record<string, string>>;
139
+ }
140
+ /** What a written path names under the host's anchors (`OsAnchors::expand`). */
141
+ type AnchoredPath = {
142
+ kind: 'plain';
143
+ } | {
144
+ kind: 'anchored';
145
+ path: string;
146
+ } | {
147
+ kind: 'unknown';
148
+ message: string;
149
+ };
150
+ declare function expandAnchor(anchors: OsAnchors, text: string): AnchoredPath;
151
+ /** The grant port a host checks absolute paths through: an fs need also matches the program's `~/` and `./` grants (`OsGrants::fs_allows_at`). */
152
+ declare function anchoredGrants(grants: OsGrantPort, anchors: OsAnchors): OsGrantPort;
153
+
154
+ export { anchoredGrants, expandAnchor, kernelOsCompletions, kernelOsGrants, kernelOsTls };
155
+ export type { AnchoredPath, OsAnchorProblem, OsAnchors, OsCompletionEvent, OsCompletionMatchers, OsCompletionPort, OsDesktopKind, OsFsMode, OsGrantKernel, OsGrantMatchers, OsGrantPort, OsHostPort, OsNetKind, OsRequirement, OsStdioKind, OsSysKind, OsTlsKernel, OsTlsPort, OsTlsStep };
@@ -0,0 +1 @@
1
+ export { anchoredGrants, expandAnchor, kernelOsCompletions, kernelOsGrants, kernelOsTls } from '../chunk-BOVU4TCQ.js';