@almadar/shell-runtime 0.1.0 → 1.1.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 (167) hide show
  1. package/dist/chunk-2WCVOMZ2.js +112 -0
  2. package/dist/chunk-57SBCUSM.js +62 -0
  3. package/dist/{chunk-Q2H75UYT.js → chunk-A2JJT4GA.js} +1 -37
  4. package/dist/chunk-BAS26HBN.js +10 -0
  5. package/dist/{chunk-REPX5QPI.js → chunk-BOVU4TCQ.js} +11 -3
  6. package/dist/chunk-BY5G4225.js +6 -0
  7. package/dist/chunk-DFDNHVDW.js +284 -0
  8. package/dist/{chunk-NATGCIVM.js → chunk-JVSREWQO.js} +378 -130
  9. package/dist/{chunk-DYOJGLIX.js → chunk-LKWYCYX5.js} +2 -5
  10. package/dist/chunk-LYFIQPXX.js +1 -0
  11. package/dist/{chunk-ODJCZ27I.js → chunk-N7HYNKK6.js} +35 -2
  12. package/dist/{chunk-4J2QEIUV.js → chunk-NTFQ36UN.js} +4 -30
  13. package/dist/chunk-NU6LVKGS.js +15 -0
  14. package/dist/{chunk-VNMG7NKY.js → chunk-OQVSN7DP.js} +21 -26
  15. package/dist/chunk-P2N6K2IV.js +20 -0
  16. package/dist/{chunk-QQRDUMB2.js → chunk-QCJWPXLH.js} +11 -11
  17. package/dist/{chunk-QELZ6TEJ.js → chunk-UD2CXYSJ.js} +39 -3
  18. package/dist/{chunk-UJHOUZAL.js → chunk-V4EMDPCO.js} +2 -5
  19. package/dist/chunk-VKQA2DJX.js +409 -0
  20. package/dist/chunk-VNGXRYFF.js +9 -0
  21. package/dist/{chunk-HNOAZWFH.js → chunk-WGCWJOT2.js} +2 -0
  22. package/dist/chunk-XZGVOBY6.js +33 -0
  23. package/dist/chunk-ZUSM4VW4.js +197 -0
  24. package/dist/client/EventTransport.d.ts +23 -7
  25. package/dist/client/EventTransport.js +1 -2
  26. package/dist/client/awaiting.js +0 -1
  27. package/dist/client/channel-transport.d.ts +6 -6
  28. package/dist/client/channel-transport.js +0 -1
  29. package/dist/client/circuit-store.d.ts +16 -5
  30. package/dist/client/circuit-store.js +2 -3
  31. package/dist/client/client-kernel.d.ts +36 -15
  32. package/dist/client/declared-input-dispatch.d.ts +19 -2
  33. package/dist/client/declared-input-dispatch.js +1 -2
  34. package/dist/client/inbound-dispatch.d.ts +21 -2
  35. package/dist/client/inbound-dispatch.js +1 -2
  36. package/dist/client/local-fold.d.ts +15 -8
  37. package/dist/client/local-fold.js +1 -2
  38. package/dist/client/render-sigils.js +0 -1
  39. package/dist/client/state-book.d.ts +9 -16
  40. package/dist/client/state-book.js +1 -2
  41. package/dist/client/trait-mount-error.js +0 -1
  42. package/dist/credentials/env-vars.d.ts +5 -1
  43. package/dist/credentials/env-vars.js +1 -3
  44. package/dist/credentials/scope.d.ts +8 -7
  45. package/dist/credentials/scope.js +0 -1
  46. package/dist/credentials/vault.d.ts +142 -0
  47. package/dist/credentials/vault.js +1 -0
  48. package/dist/effects/in-flight-calls.js +0 -1
  49. package/dist/effects/on-device-model.js +0 -1
  50. package/dist/events/EventBus.d.ts +1 -4
  51. package/dist/events/EventBus.js +0 -1
  52. package/dist/events/emit-stamp.js +0 -1
  53. package/dist/index.d.ts +25 -42
  54. package/dist/index.js +27 -45
  55. package/dist/kernel/decode.d.ts +10 -10
  56. package/dist/kernel/decode.js +1 -2
  57. package/dist/kernel/engine.d.ts +133 -31
  58. package/dist/kernel/engine.js +7 -9
  59. package/dist/kernel/frame-applier.d.ts +8 -7
  60. package/dist/kernel/frame-applier.js +1 -2
  61. package/dist/kernel/host.d.ts +148 -16
  62. package/dist/kernel/host.js +4 -7
  63. package/dist/kernel/lane.d.ts +1 -22
  64. package/dist/kernel/lane.js +1 -2
  65. package/dist/kernel/os-fetch-port.d.ts +7 -0
  66. package/dist/kernel/os-fetch-port.js +3 -0
  67. package/dist/kernel/os-port.d.ts +30 -8
  68. package/dist/kernel/os-port.js +1 -2
  69. package/dist/kernel/program-effects.d.ts +11 -28
  70. package/dist/kernel/program-effects.js +1 -2
  71. package/dist/kernel/secret-ports.d.ts +139 -0
  72. package/dist/kernel/secret-ports.js +2 -0
  73. package/dist/kernel/wire.d.ts +113 -12
  74. package/dist/loader/fetch-loader.d.ts +26 -0
  75. package/dist/loader/fetch-loader.js +1 -0
  76. package/dist/loader/lazy-page.js +0 -1
  77. package/dist/loader/schema-loader.d.ts +1 -17
  78. package/dist/persistence/native-memory.js +0 -1
  79. package/dist/runtime/entities/declaredCollections.d.ts +6 -0
  80. package/dist/runtime/entities/declaredCollections.js +1 -0
  81. package/dist/runtime/evaluation/local-store-transport.d.ts +16 -23
  82. package/dist/runtime/evaluation/local-store-transport.js +9 -13
  83. package/dist/runtime/evaluation/residence-transport.d.ts +3 -3
  84. package/dist/runtime/evaluation/residence-transport.js +1 -2
  85. package/dist/runtime/evaluation/routed-persistence.js +0 -1
  86. package/dist/runtime/events/identity/routing.d.ts +2 -53
  87. package/dist/runtime/events/identity/routing.js +1 -2
  88. package/dist/runtime/types.d.ts +5 -205
  89. package/dist/runtime/types.js +1 -2
  90. package/dist/service/default-call-service.js +0 -1
  91. package/dist/service/service-provider.js +0 -1
  92. package/package.json +8 -5
  93. package/dist/chunk-2JU7Y4KU.js +0 -21
  94. package/dist/chunk-46RWK2B5.js +0 -28
  95. package/dist/chunk-4ZICQ5PM.js +0 -192
  96. package/dist/chunk-53IPZXDP.js +0 -76
  97. package/dist/chunk-5D63EMO5.js +0 -16
  98. package/dist/chunk-CPSQXEJ6.js +0 -55
  99. package/dist/chunk-CQP5XAX6.js +0 -173
  100. package/dist/chunk-CROS2GEX.js +0 -49
  101. package/dist/chunk-D4XJTBLB.js +0 -217
  102. package/dist/chunk-D5USD2EX.js +0 -232
  103. package/dist/chunk-EV56K4GB.js +0 -63
  104. package/dist/chunk-FQ6IZMIU.js +0 -10
  105. package/dist/chunk-HMK6YMQS.js +0 -135
  106. package/dist/chunk-IHQLE5M7.js +0 -62
  107. package/dist/chunk-JFWFDUTR.js +0 -35
  108. package/dist/chunk-MHYSHSRG.js +0 -54
  109. package/dist/chunk-MLKGABMK.js +0 -7
  110. package/dist/chunk-NAECVIAR.js +0 -322
  111. package/dist/chunk-Q7JK4KY7.js +0 -9
  112. package/dist/chunk-RBUMDYFS.js +0 -681
  113. package/dist/chunk-SAS5KKCR.js +0 -43
  114. package/dist/chunk-SWPDU752.js +0 -28
  115. package/dist/chunk-T775TUCD.js +0 -18
  116. package/dist/chunk-VMOBW7RK.js +0 -21
  117. package/dist/chunk-WNPNNYXY.js +0 -22
  118. package/dist/chunk-XB5GYODW.js +0 -28
  119. package/dist/chunk-YL2SO5TP.js +0 -334
  120. package/dist/chunk-YO4LWS3I.js +0 -606
  121. package/dist/chunk-ZAQSS47X.js +0 -157
  122. package/dist/chunk-ZCQUUJIF.js +0 -129
  123. package/dist/client/ServerBridge.d.ts +0 -126
  124. package/dist/client/ServerBridge.js +0 -3
  125. package/dist/credentials/seed.d.ts +0 -21
  126. package/dist/credentials/seed.js +0 -2
  127. package/dist/credentials/store.d.ts +0 -110
  128. package/dist/credentials/store.js +0 -2
  129. package/dist/index-hT1xCdTq.d.ts +0 -46
  130. package/dist/kernel/beacon.d.ts +0 -32
  131. package/dist/kernel/beacon.js +0 -2
  132. package/dist/kernel/http.d.ts +0 -302
  133. package/dist/kernel/http.js +0 -6
  134. package/dist/kernel/oauth-effects.d.ts +0 -25
  135. package/dist/kernel/oauth-effects.js +0 -7
  136. package/dist/kernel/oauth-port.d.ts +0 -31
  137. package/dist/kernel/oauth-port.js +0 -2
  138. package/dist/loader/http-loader.d.ts +0 -111
  139. package/dist/loader/http-loader.js +0 -2
  140. package/dist/runtime/effects/composition/compose-behaviors.d.ts +0 -58
  141. package/dist/runtime/effects/composition/compose-behaviors.js +0 -4
  142. package/dist/runtime/effects/composition/event-wiring.d.ts +0 -38
  143. package/dist/runtime/effects/composition/event-wiring.js +0 -2
  144. package/dist/runtime/effects/composition/index.d.ts +0 -5
  145. package/dist/runtime/effects/composition/index.js +0 -6
  146. package/dist/runtime/effects/composition/layout-strategy.d.ts +0 -35
  147. package/dist/runtime/effects/composition/layout-strategy.js +0 -2
  148. package/dist/runtime/effects/composition/pipe.d.ts +0 -25
  149. package/dist/runtime/effects/composition/pipe.js +0 -2
  150. package/dist/runtime/entities/mockStoreSeed.d.ts +0 -56
  151. package/dist/runtime/entities/mockStoreSeed.js +0 -3
  152. package/dist/runtime/entities/seedBrowserStore.d.ts +0 -28
  153. package/dist/runtime/entities/seedBrowserStore.js +0 -2
  154. package/dist/runtime/entities/std-mock-seed.d.ts +0 -87
  155. package/dist/runtime/entities/std-mock-seed.js +0 -2
  156. package/dist/runtime/time/TickScheduler.d.ts +0 -77
  157. package/dist/runtime/time/TickScheduler.js +0 -3
  158. package/dist/runtime/time/cron.d.ts +0 -25
  159. package/dist/runtime/time/cron.js +0 -2
  160. package/dist/runtime/time/duration.d.ts +0 -20
  161. package/dist/runtime/time/duration.js +0 -2
  162. package/dist/runtime/traits/OrbitalTraitParsing.d.ts +0 -34
  163. package/dist/runtime/traits/OrbitalTraitParsing.js +0 -2
  164. package/dist/runtime/traits/listen-targets.d.ts +0 -16
  165. package/dist/runtime/traits/listen-targets.js +0 -3
  166. package/dist/runtime/traits/trait-index.d.ts +0 -35
  167. package/dist/runtime/traits/trait-index.js +0 -3
@@ -1,14 +1,12 @@
1
- import { OrbitalSchema, MessageCatalogs, MountSeed, RowSetRef, RowQueryPage, OrbitalEventRequest, OrbitalEventResponse, EventStreamItem, UserContext } from '@almadar/core';
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';
2
3
  import { KernelHostPorts, KernelAnswerScope } from './host.js';
3
- import { KernelModule, KernelServerHandle } from './wire.js';
4
+ import { KernelModule, KernelServerHandle, FiredByOrbital } from './wire.js';
4
5
  import '../effects/in-flight-calls.js';
5
6
  import '../service/service-provider.js';
6
7
  import './program-effects.js';
7
- import './http.js';
8
- import './beacon.js';
9
- import '../credentials/store.js';
10
- import './decode.js';
11
- import '@almadar/core/kernel-wire';
8
+ import './secret-ports.js';
9
+ import '../credentials/vault.js';
12
10
  import './os-port.js';
13
11
 
14
12
  /**
@@ -17,78 +15,182 @@ import './os-port.js';
17
15
  * and nothing else. The continuation of a stopped dispatch never leaves the wasm instance.
18
16
  */
19
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>;
20
38
  declare class KernelEngine {
21
39
  private readonly kernel;
22
40
  private readonly schemaJson;
23
41
  private readonly ports;
24
42
  private readonly entityTypes;
25
43
  private readonly preserveProgramContext;
44
+ private readonly lazyDir?;
26
45
  private handle;
27
- private readonly lane;
28
- private tickMount;
29
- private messages;
30
- constructor(kernel: KernelModule, schemaJson: string, ports: KernelHostPorts, entityTypes?: readonly string[], forkedFrom?: KernelServerHandle, providedHandle?: KernelServerHandle, preserveProgramContext?: boolean);
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);
31
50
  /**
32
51
  * A kernel on the same program, registered once, holding none of this one's session: every trait at its initial
33
- * state, no rows the kernel held, its locales and mounted ticks kept. A stateless host serves each request a
52
+ * state, no rows the kernel held, its mounted ticks kept. A stateless host serves each request a
34
53
  * fork (EXEC-DIST-5), `ports` answering it.
35
54
  */
36
55
  fork(ports?: KernelHostPorts): KernelEngine;
37
56
  forkProgram(program: OrbitalSchema, ports?: KernelHostPorts): KernelEngine;
38
57
  /** A server over the host's ports. */
58
+ /** A server over the host's ports; the host's GPU answerer is installed in it, so it holds every `gpu/` ask. */
39
59
  private openServer;
40
60
  private declare;
41
- static open(kernel: KernelModule, schema: OrbitalSchema, ports: KernelHostPorts): KernelEngine;
61
+ /** The contract answers for a host with no program registered yet: the kernel's, asked with no program. */
62
+ static withoutProgram(kernel: KernelModule): ProgramlessContract;
63
+ static open(kernel: KernelModule, schema: OrbitalSchema, ports: KernelHostPorts, lazyDir?: string): KernelEngine;
42
64
  /** A fresh kernel on the same program: every trait back at its initial state. */
43
65
  reset(): void;
44
66
  private managedProgram;
45
67
  /** The program whose declared credentials this kernel's credential effects manage beside its own (a console's app). */
46
68
  setManagedProgram(program: OrbitalSchema): void;
47
- /** The program's declared locales and merged catalogs (a lazy page's behavior contributes its namespaced keys). */
48
- setMessages(locales: readonly string[], catalogs: MessageCatalogs): void;
49
- /** The traits some client has mounted: a tick that is not `[background]` fires only for these. */
50
- setTickMount(traits: string[]): void;
69
+ /** `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. */
70
+ mountClient(client: string, orbital: string, traits: readonly string[]): void;
71
+ unmountClient(client: string, orbital: string, traits: readonly string[]): void;
72
+ /** `client` is gone: everything it mounted is released. */
73
+ releaseClient(client: string): void;
74
+ /** 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. */
75
+ setStateful(): void;
76
+ /** Whether the program declares any tick: the host runs its timer only then. */
77
+ declaresTicks(): boolean;
78
+ /** Queue a tick-stamped dispatch for the coalesced peer relay; the ms after which to flush when it opened a window. */
79
+ relayTick(orbital: string, request: EventRequest): number | undefined;
80
+ /** The relay window's length in ms; the kernel's default is 50. */
81
+ setTickRelayInterval(intervalMs: number): void;
82
+ /** Every item queued since the window opened, in first-arrival order; the window closes. */
83
+ flushTickRelay(): LiveBroadcastItem[];
84
+ /** 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. */
85
+ tickPass(nowMs: number): FiredByOrbital;
86
+ /** Stop the kernel's tick clock; its phase is kept. */
87
+ tickPause(): void;
88
+ /** Restart the kernel's tick clock; the paused span is never counted. */
89
+ tickResume(): void;
90
+ tickPaused(): boolean;
51
91
  /** What this host mounts when it starts: the kernel's boot mounts for the side it serves (EXEC-ENDPOINT-3). */
52
92
  bootMounts(side: 'server' | 'process'): MountSeed[];
53
93
  /** What mounts when a client opens `routePath` (EXEC-ENDPOINT-3). */
54
94
  routeMounts(routePath: string): MountSeed[];
55
- /** Mock-seed the `[runtime]` entities the kernel holds itself, owner columns stamped with `viewerId`. */
56
- seedRuntimeMock(viewerId: string | undefined): void;
57
95
  dispose(): void;
58
- liveItemDelivered(item: object, viewer: object | null, clientId?: string): boolean;
59
- /** `OsGrants::allows` over the grants of the program this kernel runs. */
60
- osAllows(requirementJson: string): boolean;
96
+ private readonly answers;
97
+ private contract;
98
+ /** Every external input the program declares: what an outside client may send which trait. */
99
+ externalInputs(): ExternalInput[];
100
+ /** What the kernel holds of every trait of the program, in name order, and the browser-stored entities. */
101
+ programSurface(): ProgramSurface;
102
+ /** The entities a provider acting as the caller may read. */
103
+ readableEntities(): string[];
104
+ /** The declared input of `trait.event` in `orbital`, when there is one. */
105
+ findExternalInput(orbital: string, trait: string, event: string): ExternalInput | undefined;
106
+ /** The declared input a `listens`-addressed event names from `caller`'s position (`EVENT`, `Trait.EVENT`, `Orbital.Trait.EVENT`), when there is one. */
107
+ findInputByAddress(address: string, caller: {
108
+ orbital: string;
109
+ trait: string;
110
+ }): ExternalInput | undefined;
111
+ /** A declared payload as the JSON Schema of one object: what a tool-calling model fills. */
112
+ payloadJsonSchema(fields: readonly PayloadField[]): JsonSchema;
113
+ /** The ways `value` misses the declared payload `fields`. */
114
+ payloadIssues(fields: readonly PayloadField[], value: EventPayload): PayloadIssue[];
115
+ /** The route a hook name is delivered to, or the answer to write for a hook the program does not serve. */
116
+ findInbound(name: string): {
117
+ route: InboundRoute;
118
+ } | {
119
+ answer: InboundAnswer;
120
+ };
121
+ /** The trait that handles `event` as an inbound hook in `orbital`, with the refusal message, when a client-facing request names it. */
122
+ inboundOnly(orbital: string, trait: string | undefined, event: string): {
123
+ trait: string;
124
+ message: string;
125
+ } | undefined;
126
+ /** The payload an inbound event is delivered with. */
127
+ inboundPayload(route: InboundRoute, delivery: InboundDelivery, credential: string | null | undefined): EventPayload;
128
+ /** The HTTP answer a finished dispatch produced for `route`. */
129
+ inboundAnswer(route: InboundRoute, emitted: readonly {
130
+ event: string;
131
+ payload?: EventPayload;
132
+ }[], error: string | undefined): InboundAnswer;
133
+ /** The answer for a route whose credential the host holds no value for. */
134
+ credentialUnset(credential: string): InboundAnswer;
135
+ /** The answer for a delivery whose dispatch failed. */
136
+ dispatchFailed(message: string): InboundAnswer;
137
+ /** The name of the program's `[identity]` entity, when it declares one. */
138
+ identityEntity(): string | undefined;
139
+ /** The orbital that declares `entity` inline. */
140
+ entityOwnerOrbital(entity: string): string | undefined;
141
+ /** `rows` of `entity` as `user` reads them: narrowed by the entity's declared `@read`, which the kernel evaluates with `@user` bound to the viewer. */
142
+ readRows(entity: string, rows: readonly EntityRow[], user: UserContext | undefined): EntityRow[];
143
+ liveItemDelivered(item: object, clientId?: string): boolean;
144
+ /** `OsGrants::allows` over the grants of `orbital` in the program this kernel runs (the app level alone with no orbital). */
145
+ osAllows(requirementJson: string, orbital?: string): boolean;
146
+ /** Whether `url`'s origin is declared in the program's `egress` (the kernel's rule). */
147
+ egressAllows(url: string): boolean;
61
148
  /** Place the program's anchored grants and arguments under the host's anchors. */
62
149
  setOsAnchors(anchorsJson: string): string;
63
150
  /** An `os/` call's arguments with its anchored parts resolved under the host's anchors. */
64
151
  osResolveArgs(op: string, argsJson: string): string;
152
+ tlsComplete(key: string, outcomeJson: string): string;
153
+ /** A live stream of `client`'s session opened (EXEC-DIST-9); the id closes it. */
154
+ openSessionStream(client: string): number;
155
+ /** The live stream `id` dropped: the kernel frees the session once its streams have all dropped and it is quiet. */
156
+ closeSessionStream(id: number): boolean;
65
157
  /** The current state of a trait instance, `''` when it has none. */
66
158
  stateOf(traitName: string, entityId?: string): string;
67
159
  /**
68
- * `reference` resolved for `scope.user` against the host-answered store (EXEC-RENDER-3): the rows that still
69
- * match its query and the viewer's `@read` in the reference's order, a missing or hidden row omitted, and `total`
160
+ * `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
161
+ * match its query and that identity's `@read` in the reference's order, a missing or hidden row omitted, and `total`
70
162
  * re-counted (a `total: none` reference is not re-counted: the total is the resolved window). Each read the
71
163
  * kernel makes is answered here, as in `evaluate`.
72
164
  */
73
165
  resolveRows(reference: RowSetRef, scope: KernelAnswerScope): Promise<RowQueryPage>;
74
- /** Run `request` against `orbital`: start it, answer every request the kernel asks for, resume until done. */
75
- evaluate(orbital: string, request: OrbitalEventRequest, scope: KernelAnswerScope): Promise<OrbitalEventResponse>;
166
+ /**
167
+ * Run `request` against `orbital`. The kernel orders every start and every resumption (EXEC-CONC-2): while another
168
+ * dispatch holds the lane it answers `queued` and runs the work itself once the lane frees; this host only answers
169
+ * what each dispatch asks.
170
+ */
171
+ evaluate(orbital: string, request: EventRequest, scope: KernelAnswerScope): Promise<EventResponse>;
172
+ /** The kernel's answer to a start or resume, once it has run: at once, or when the kernel takes it from its queue. */
173
+ private ran;
174
+ private running;
175
+ /** Run each piece of queued work that can run now, in the kernel's order, handing each to the dispatch it continues. */
176
+ private runQueued;
76
177
  }
77
178
  /** What `evaluateOrbitalEvent` needs to run a request on the kernel instead of the JS composition. */
78
179
  interface KernelEvaluation {
79
180
  engine: KernelEngine;
80
181
  /** The orbital the request is addressed to. */
81
182
  orbital: string;
82
- outsideEventQueue?: <T>(work: () => Promise<T>) => Promise<T>;
83
183
  onStream?: (item: EventStreamItem) => void;
84
184
  }
85
185
  /**
86
- * The request as the kernel takes it: the viewer and locale the host resolved, the `_targetTrait` sidecar
186
+ * The request as the kernel takes it: the locale the host resolved, the `_targetTrait` sidecar
87
187
  * promoted to `targetTrait`, and the `_activeTraits` sidecar dropped (the kernel's mounted set is explicit,
88
188
  * not carried per request).
89
189
  */
90
- declare function kernelRequest(request: OrbitalEventRequest, user: UserContext | undefined, locale: string | undefined): OrbitalEventRequest;
91
- declare function evaluateOnKernel(kernel: KernelEvaluation, request: OrbitalEventRequest, user: UserContext | undefined, locale: string | undefined): Promise<OrbitalEventResponse>;
190
+ declare function kernelRequest(request: EventRequest & {
191
+ user?: JsonValue;
192
+ }, locale: string | undefined): EventRequest;
193
+ declare function evaluateOnKernel(kernel: KernelEvaluation, request: EventRequest, locale: string | undefined): Promise<EventResponse>;
92
194
 
93
195
  export { KernelEngine, evaluateOnKernel, kernelRequest };
94
- export type { KernelEvaluation };
196
+ export type { KernelEvaluation, ProgramlessContract };
@@ -1,11 +1,9 @@
1
- export { KernelEngine, evaluateOnKernel, kernelRequest } from '../chunk-D4XJTBLB.js';
2
- import '../chunk-NATGCIVM.js';
3
- import '../chunk-HNOAZWFH.js';
4
- import '../chunk-53IPZXDP.js';
5
- import '../chunk-YO4LWS3I.js';
6
- import '../chunk-MZKIL5IN.js';
1
+ export { KernelEngine, evaluateOnKernel, kernelRequest } from '../chunk-VKQA2DJX.js';
2
+ import '../chunk-NU6LVKGS.js';
3
+ import '../chunk-XZGVOBY6.js';
4
+ import '../chunk-JVSREWQO.js';
5
+ import '../chunk-WGCWJOT2.js';
6
+ import '../chunk-ZUSM4VW4.js';
7
7
  import '../chunk-FWA5K7Q2.js';
8
- import '../chunk-VMOBW7RK.js';
9
- import '../chunk-RBUMDYFS.js';
10
8
  import '../chunk-HLOUDLPI.js';
11
- import '../chunk-MLKGABMK.js';
9
+ import '../chunk-MZKIL5IN.js';
@@ -1,5 +1,5 @@
1
- import { FiredTick, FrameWire, RoutedLeg } from '@almadar/core/kernel-wire';
2
- import { OrbitalEventResponse, JsonValue } from '@almadar/core';
1
+ import { FrameWire, RoutedLeg } from '@almadar/core/kernel-wire';
2
+ import { EventResponse } from '@almadar/core';
3
3
  import { ClientKernelOutcome, LocalFoldKernel } from '../client/client-kernel.js';
4
4
  import '../client/circuit-store.js';
5
5
  import '../client/awaiting.js';
@@ -16,20 +16,21 @@ import '../client/trait-types.js';
16
16
  * never delays the next frame.
17
17
  */
18
18
 
19
- declare function isFrameWire(value: JsonValue): value is JsonValue & FrameWire;
20
19
  /** `frame()`'s JSON; `undefined` (no tick due) decodes to `undefined`. */
21
20
  declare function decodeFrame(json: string | undefined): FrameWire | undefined;
22
- type TickEffects = Pick<OrbitalEventResponse, 'clientEffects' | 'clientEffectsByTrait'>;
21
+ type TickEffects = Pick<EventResponse, 'clientEffectsByTrait'>;
23
22
  type FrameDispatch = FrameWire['dispatches'][number];
24
23
  /** The host transport's side of a frame: posts what a fired tick owes and folds the answer back through the kernel. */
25
24
  interface FramePostPort {
26
25
  /** Posts one dispatch's server legs (or stateful leg); resolves to what the server's fold added. */
27
26
  postDispatch(dispatch: FrameDispatch): Promise<TickEffects>;
28
27
  /** Sends a leg the kernel routed to the browser store; `frameResponse` is the frame's aggregate response. */
29
- sendBrowserLeg(leg: RoutedLeg, frameResponse: OrbitalEventResponse): Promise<TickEffects>;
28
+ sendBrowserLeg(leg: RoutedLeg, frameResponse: EventResponse): Promise<TickEffects>;
30
29
  }
31
30
  interface FrameApplied {
32
- fired: FiredTick[];
31
+ fired: FrameWire['fired'];
32
+ /** How many ticks fired, across every orbital. */
33
+ firedCount: number;
33
34
  folded: number;
34
35
  browserLegs: number;
35
36
  droppedServerEffects: number;
@@ -39,5 +40,5 @@ interface FrameApplied {
39
40
  }
40
41
  declare function applyFrame(json: string | undefined, kernel: LocalFoldKernel, post: FramePostPort | undefined): Promise<FrameApplied>;
41
42
 
42
- export { applyFrame, decodeFrame, isFrameWire };
43
+ export { applyFrame, decodeFrame };
43
44
  export type { FrameApplied, FrameDispatch, FramePostPort, TickEffects };
@@ -1,2 +1 @@
1
- export { applyFrame, decodeFrame, isFrameWire } from '../chunk-4J2QEIUV.js';
2
- import '../chunk-MLKGABMK.js';
1
+ export { applyFrame, decodeFrame } from '../chunk-NTFQ36UN.js';
@@ -1,13 +1,12 @@
1
- import { PageFactField, BrowserPageFacts, PersistenceAdapter, ServiceParams, EventPayload, JsonValue, UserContext, ServiceHostPorts, OnDeviceModelPorts, BrowserTabPort, EventStreamItem } from '@almadar/core';
1
+ import { PageFactField, BrowserPageFacts, PersistenceAdapter, ServiceParams, EventPayload, JsonValue, UserContext, ServiceHostPorts, OnDeviceModelPorts, BrowserTabPort, JsonObject, EventStreamItem, HostAskCompletion } from '@almadar/core';
2
2
  import { InFlightCalls } from '../effects/in-flight-calls.js';
3
3
  import { ServiceCallContext } from '../service/service-provider.js';
4
4
  import { ProgramEffectName, ProgramEffectOutcome } from './program-effects.js';
5
- import { HttpPorts } from './http.js';
6
- import { CallSiteWire, Settled, SubstrateFailureWire, IoRequestWire, IoAnswerWire } from '@almadar/core/kernel-wire';
7
- import { OsHostPort, OsCompletionPort, OsCompletionEvent } from './os-port.js';
8
- import './beacon.js';
9
- import '../credentials/store.js';
10
- import './decode.js';
5
+ import { SecretPorts } from './secret-ports.js';
6
+ import { Settled, EventRequest, CallSiteWire, SubstrateFailureWire, IoAnswerWire, IoRequestWire, OsError } from '@almadar/core/kernel-wire';
7
+ import { KernelGpuHost, KernelModule } from './wire.js';
8
+ import { OsHostPort, OsCompletionPort, OsTlsPort, OsCompletionEvent } from './os-port.js';
9
+ import '../credentials/vault.js';
11
10
 
12
11
  /**
13
12
  * The host half of the kernel path: the I/O the kernel asks for, answered with the runtime's own
@@ -24,15 +23,94 @@ interface DeferredCallOutcome {
24
23
  traitName: string;
25
24
  event: string;
26
25
  payload: EventPayload | undefined;
26
+ /** The payload is held in the kernel under this ticket (a `gpu/` completion): the request names it instead of carrying it. */
27
+ heldPayload?: number;
27
28
  entityId: string | undefined;
28
29
  originClientId: string | undefined;
29
- user: UserContext | undefined;
30
30
  locale: string | undefined;
31
31
  }
32
32
  interface SubstrateStreamSource {
33
33
  subscribe(message: (value: JsonValue) => void, ended: () => void): () => void;
34
34
  }
35
+ /** The `audio/*` asks: a sound or music key, absent where the op names none (stop every sound, stop the music). */
36
+ type HostAudioAsk = {
37
+ op: 'audio/play-sound';
38
+ key: string;
39
+ } | {
40
+ op: 'audio/stop-sound';
41
+ key: string | undefined;
42
+ } | {
43
+ op: 'audio/change-music';
44
+ key: string | undefined;
45
+ } | {
46
+ op: 'audio/stop-music';
47
+ };
48
+ /** The one object `auth/sign-in` takes: the method and the credentials it needs. */
49
+ type HostSignInRequest = {
50
+ method: 'google';
51
+ } | {
52
+ method: 'email';
53
+ email: string;
54
+ password: string;
55
+ } | {
56
+ method: 'emailLink';
57
+ email: string;
58
+ continueUrl: string;
59
+ } | {
60
+ method: 'emailLink';
61
+ email: string;
62
+ link: string;
63
+ } | {
64
+ method: 'customToken';
65
+ token: string;
66
+ };
67
+ /** What a sign-in answers: the viewer, or `{ sent: true }` for an email link that was only sent. */
68
+ type HostSignInAnswer = {
69
+ uid: string;
70
+ email?: string;
71
+ displayName?: string;
72
+ } | {
73
+ sent: true;
74
+ };
75
+ /** The one object `auth/consent` takes: the authorize URL the viewer is sent to. */
76
+ interface HostConsentRequest {
77
+ authorizeUrl: string;
78
+ }
79
+ /** What a consent answers: the `code` and `state` query params of the final redirect URL, read as they are. */
80
+ interface HostConsentAnswer {
81
+ code: string;
82
+ state: string;
83
+ }
84
+ /** Why a host ask failed: the viewer closed it, the provider denied it, the request was malformed, or the host has no such action. */
85
+ type HostAskFailureKind = 'cancelled' | 'denied' | 'invalid' | 'unavailable';
86
+ /** A host action's own failure, carrying the kind the completion reports. */
87
+ declare class HostAskError extends Error {
88
+ readonly kind: HostAskFailureKind;
89
+ constructor(kind: HostAskFailureKind, message: string);
90
+ }
91
+ /** 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. */
92
+ interface KernelHostActions {
93
+ audio?: (ask: HostAudioAsk) => void;
94
+ signOut?: () => void | Promise<void>;
95
+ signIn?: (request: HostSignInRequest) => Promise<HostSignInAnswer>;
96
+ consent?: (request: HostConsentRequest) => Promise<HostConsentAnswer>;
97
+ }
98
+ /** A host ask's answer: the payload of its success route, or the error and kind of its failure route. */
99
+ type HostAskOutcome = {
100
+ ok: JsonObject;
101
+ } | {
102
+ error: string;
103
+ kind: HostAskFailureKind;
104
+ };
105
+ /** The event a host's answer dispatches: to `trait` (on `entityId` when the frame is a row), carrying `payload`. */
106
+ interface HostAskReturn {
107
+ trait: string;
108
+ entityId?: string;
109
+ event: string;
110
+ payload: JsonObject;
111
+ }
35
112
  interface KernelHostPorts {
113
+ hostActions?: KernelHostActions;
36
114
  pageFacts?: (fields: readonly PageFactField[]) => BrowserPageFacts;
37
115
  persistence: PersistenceAdapter;
38
116
  callService: KernelCallService;
@@ -52,8 +130,8 @@ interface KernelHostPorts {
52
130
  }, payload: EventPayload, originClientId: string | undefined) => void;
53
131
  /** Read per call: the sink a follow-on call's outcome runs through, absent when the host cannot deliver it to the tab. */
54
132
  deferCallOutcome: () => ((call: DeferredCallOutcome) => void) | undefined;
55
- /** The `http` effect's ports (kernel builder, secrets, egress); absent, an `http` ask fails as unavailable. */
56
- http?: HttpPorts;
133
+ /** The secret store, CSPRNG and credential administration ports the kernel's secret, random and credential asks use. */
134
+ secretPorts?: SecretPorts;
57
135
  /** The on-device model and embedder; absent, a `browser/prompt` or `browser/embed` ask fails `unconfigured`. */
58
136
  onDevice?: OnDeviceModelPorts;
59
137
  /** The browser's tabs for the `browser/tab-*` effects; absent, a tab ask fails `unavailable`. */
@@ -62,27 +140,81 @@ interface KernelHostPorts {
62
140
  os?: OsHostPort;
63
141
  /** 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. */
64
142
  osCompletions?: OsCompletionPort;
143
+ /** The kernel's TLS state for sockets it owns (EXEC-HTTP-7); absent, a deferred outcome reaches its route as the host gave it. */
144
+ osTls?: OsTlsPort;
145
+ /** The kernel's typed parse of a `program/dispatch` event request; absent, that ask is refused. */
146
+ parseEventRequest?: EventRequestParser;
65
147
  substrateStream?: (op: string, args: readonly JsonValue[], scope: KernelAnswerScope) => SubstrateStreamSource | undefined;
66
148
  substrateMessage?: (site: CallSiteWire, key: string, value: JsonValue) => OsCompletionEvent | null;
67
149
  substrateCompletion?: (site: CallSiteWire, key: string, op: string, args: readonly JsonValue[], outcome: Settled<JsonValue, SubstrateFailureWire>) => OsCompletionEvent | null;
68
150
  /** The host clock in epoch milliseconds, answering the kernel's `clock` ask; absent, the system clock. */
69
151
  now?: () => number;
152
+ /** The browser's GPU answerer, installed into the kernel: every `gpu/` ask is then held and answered there. */
153
+ gpu?: KernelGpuHost;
154
+ /** The GPU answerer installed in the kernel (bound by the engine from `gpu`): it answers a held `gpu` ask by ticket, so its bytes never reach this host. */
155
+ heldGpu?: HeldGpuPort;
156
+ }
157
+ /** A deferred held `gpu/` ask's completion: the route event and the ticket its payload is held under in the kernel. */
158
+ interface HeldGpuCompletion {
159
+ orbital?: string;
160
+ traitName: string;
161
+ entityId?: string;
162
+ event: string;
163
+ heldPayload: number;
164
+ }
165
+ /** The kernel's own GPU answerer (orbital-wasm `Server.answerGpu`), bound to the kernel the host runs. */
166
+ interface HeldGpuPort {
167
+ /** `completed` runs once for a deferred ask: its completion, or `null` when the outcome takes no declared route. */
168
+ answer(ticket: number, completed: (completion: HeldGpuCompletion | null) => void): Promise<IoAnswerWire>;
169
+ /** Drop a held completion payload no request will start. */
170
+ drop(heldPayload: number): void;
70
171
  }
71
172
  /** What one dispatch brings to its answers. */
72
173
  interface KernelAnswerScope {
73
174
  /** The orbital the request is addressed to. */
74
175
  orbital: string;
75
- /** The viewer the dispatch runs as; a substrate operator is called as them. */
76
- user?: UserContext;
77
176
  /** The requesting tab. */
78
177
  originClientId?: string;
79
178
  locale?: string;
80
179
  entityId?: string;
81
- /** Runs `work` with the host's event queue released (a service call must not hold the next event). */
82
- outsideEventQueue?: <T>(work: () => Promise<T>) => Promise<T>;
83
180
  onStream?: (item: EventStreamItem) => void;
84
181
  assertReentry?: () => void;
85
182
  }
183
+ /** The kernel's typed parse of a `program/dispatch` event request: the request, or the reason it is none. */
184
+ type EventRequestParser = (payload: JsonObject, options: JsonObject) => Settled<EventRequest, string>;
185
+ /** The request parser over the kernel module: `EventRequest::from_dispatch`, not copied. */
186
+ declare function kernelEventRequestParser(kernel: Pick<KernelModule, 'parseEventRequest'>): EventRequestParser;
187
+ /** `audio/*` and `auth/sign-out`: one ask each, performed by the host's actions; a host without them refuses by name. */
188
+ declare function performHostAsk(actions: KernelHostActions | undefined, op: string, args: readonly JsonValue[]): Promise<Settled<null, string>>;
189
+ /** The `auth/sign-in` request an ask carries, or why it is refused before the host is asked. */
190
+ declare function parseSignInRequest(args: readonly JsonValue[]): {
191
+ request: HostSignInRequest;
192
+ } | {
193
+ error: string;
194
+ };
195
+ /** The `auth/consent` request an ask carries, or why it is refused before the host is asked. */
196
+ declare function parseConsentRequest(args: readonly JsonValue[]): {
197
+ request: HostConsentRequest;
198
+ } | {
199
+ error: string;
200
+ };
201
+ /** The `code` and `state` query params of a consent's final redirect URL, read as they are; a redirect without both is a denial. */
202
+ declare function consentFromRedirect(redirectUrl: string): HostConsentAnswer;
203
+ /** 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). */
204
+ declare function performHostAnswer(actions: KernelHostActions | undefined, op: string, args: readonly JsonValue[]): Promise<HostAskOutcome>;
205
+ /** The event `outcome` fires on the ask's declared route, or undefined when the ask declared none for it (nothing fires). */
206
+ declare function hostAskReturn(completion: HostAskCompletion, outcome: HostAskOutcome): HostAskReturn | undefined;
207
+ /**
208
+ * A deferred raw `os` outcome that belongs to a TLS operation the kernel parked (EXEC-HTTP-7) is finished in the kernel:
209
+ * it decrypts or encrypts the raw outcome and, while it needs more raw bytes, asks the host's `os` port for them. Any
210
+ * other key's outcome is returned as it stands.
211
+ */
212
+ declare function finishTls(ports: KernelHostPorts, os: OsHostPort, key: string, raw: Settled<JsonValue, OsError>): Promise<Settled<JsonValue, OsError>>;
213
+ /**
214
+ * The same loop, handing the outcome to `finish` in the calling turn whenever the kernel needs no further raw ask
215
+ * (nothing parked, or done at once); only a parked operation's follow-up ask makes it wait (EXEC-QUEUE-10/13).
216
+ */
217
+ declare function completeTls(ports: KernelHostPorts, os: OsHostPort, key: string, raw: Settled<JsonValue, OsError>, finish: (outcome: Settled<JsonValue, OsError>) => void): void;
86
218
  declare function writeRows(persistence: PersistenceAdapter, request: Extract<IoRequestWire, {
87
219
  kind: 'writeRows';
88
220
  }>): Promise<IoAnswerWire>;
@@ -91,5 +223,5 @@ declare function declareCapabilities(persistence: PersistenceAdapter, declare: (
91
223
  /** Answer one request of the kernel; a thrown adapter error becomes the request's declared failure. */
92
224
  declare function answerRequest(ports: KernelHostPorts, request: IoRequestWire, scope: KernelAnswerScope): Promise<IoAnswerWire>;
93
225
 
94
- export { answerRequest, declareCapabilities, writeRows };
95
- export type { DeferredCallOutcome, KernelAnswerScope, KernelCallService, KernelHostPorts, SubstrateStreamSource };
226
+ export { HostAskError, answerRequest, completeTls, consentFromRedirect, declareCapabilities, finishTls, hostAskReturn, kernelEventRequestParser, parseConsentRequest, parseSignInRequest, performHostAnswer, performHostAsk, writeRows };
227
+ export type { DeferredCallOutcome, EventRequestParser, HeldGpuCompletion, HeldGpuPort, HostAskFailureKind, HostAskOutcome, HostAskReturn, HostAudioAsk, HostConsentAnswer, HostConsentRequest, HostSignInAnswer, HostSignInRequest, KernelAnswerScope, KernelCallService, KernelHostActions, KernelHostPorts, SubstrateStreamSource };
@@ -1,9 +1,6 @@
1
- export { answerRequest, declareCapabilities, writeRows } from '../chunk-NATGCIVM.js';
2
- import '../chunk-HNOAZWFH.js';
3
- import '../chunk-YO4LWS3I.js';
4
- import '../chunk-MZKIL5IN.js';
1
+ export { HostAskError, answerRequest, completeTls, consentFromRedirect, declareCapabilities, finishTls, hostAskReturn, kernelEventRequestParser, parseConsentRequest, parseSignInRequest, performHostAnswer, performHostAsk, writeRows } from '../chunk-JVSREWQO.js';
2
+ import '../chunk-WGCWJOT2.js';
3
+ import '../chunk-ZUSM4VW4.js';
5
4
  import '../chunk-FWA5K7Q2.js';
6
- import '../chunk-VMOBW7RK.js';
7
- import '../chunk-RBUMDYFS.js';
8
5
  import '../chunk-HLOUDLPI.js';
9
- import '../chunk-MLKGABMK.js';
6
+ import '../chunk-MZKIL5IN.js';
@@ -1,28 +1,7 @@
1
- interface LaneTurn {
2
- readonly ticket: number;
3
- }
4
1
  declare class LaneHeldByParkedDispatch extends Error {
5
2
  readonly ticket: number;
6
3
  readonly event: string;
7
4
  constructor(ticket: number, event: string);
8
5
  }
9
- interface LaneGuard {
10
- readonly turn: LaneTurn;
11
- park(event: string): void;
12
- resume(): void;
13
- release(): void;
14
- }
15
- declare class DispatchLane {
16
- private nextTicket;
17
- private holder;
18
- private depth;
19
- private parkedEvent;
20
- private readonly waiters;
21
- assertCanReenter(turn: LaneTurn): void;
22
- enter(turn?: LaneTurn): Promise<LaneGuard>;
23
- private take;
24
- private guard;
25
- }
26
6
 
27
- export { DispatchLane, LaneHeldByParkedDispatch };
28
- export type { LaneGuard, LaneTurn };
7
+ export { LaneHeldByParkedDispatch };
@@ -1,2 +1 @@
1
- export { DispatchLane, LaneHeldByParkedDispatch } from '../chunk-53IPZXDP.js';
2
- import '../chunk-MLKGABMK.js';
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-2WCVOMZ2.js';
2
+ import '../chunk-ZUSM4VW4.js';
3
+ import '../chunk-HLOUDLPI.js';