@syntropika/tembra-sdk 0.2.2 → 0.3.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 (241) hide show
  1. package/README.md +43 -17
  2. package/dist/authoring/types.d.ts +64 -3
  3. package/dist/authoring/wit.d.ts +6 -0
  4. package/dist/bridge/commands.d.ts +1190 -0
  5. package/dist/bridge/identifiers.d.ts +2 -0
  6. package/dist/bridge/kernel.d.ts +18 -107
  7. package/dist/bridge/protocol.d.ts +3 -138
  8. package/dist/browser.d.ts +14 -1
  9. package/dist/browser.js +141 -3332
  10. package/dist/chunks/browser-b8jamxw2.js +3399 -0
  11. package/dist/chunks/execution-nsqc6nrt.js +1419 -0
  12. package/dist/chunks/index-01zk0xqx.js +160 -0
  13. package/dist/chunks/index-3fjdfdfd.js +152 -0
  14. package/dist/chunks/index-aaymjn7v.js +787 -0
  15. package/dist/chunks/index-c1w7z9hx.js +356 -0
  16. package/dist/chunks/index-h8t0n42q.js +738 -0
  17. package/dist/chunks/index-hfds9mzp.js +308 -0
  18. package/dist/chunks/index-kr4x67wt.js +177 -0
  19. package/dist/chunks/index-kr6bnh34.js +117 -0
  20. package/dist/chunks/index-kyt9dj0a.js +1421 -0
  21. package/dist/chunks/index-n1wxzc9w.js +830 -0
  22. package/dist/chunks/index-pvac426d.js +74 -0
  23. package/dist/chunks/index-smyds5ce.js +3234 -0
  24. package/dist/chunks/index-sse8aapb.js +121 -0
  25. package/dist/chunks/index-v6heph77.js +643 -0
  26. package/dist/chunks/index-xrdvnv37.js +3448 -0
  27. package/dist/chunks/index-za4mg94e.js +26 -0
  28. package/dist/chunks/index-zkqmnjj8.js +167 -0
  29. package/dist/coordinator.js +9 -500
  30. package/dist/error.d.ts +2 -0
  31. package/dist/errors.d.ts +3 -0
  32. package/dist/guest.d.ts +173 -0
  33. package/dist/guest.js +26 -0
  34. package/dist/host.d.ts +36 -30
  35. package/dist/host.js +37 -3310
  36. package/dist/http/bytes.d.ts +8 -0
  37. package/dist/http/events.d.ts +7 -0
  38. package/dist/http.d.ts +45 -0
  39. package/dist/http.js +291 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.js +49 -862
  42. package/dist/infrastructure/rpc/client.d.ts +2 -1
  43. package/dist/infrastructure/rpc/resources.d.ts +28 -0
  44. package/dist/interpreter/abi.d.ts +54 -0
  45. package/dist/interpreter/acquire.d.ts +18 -0
  46. package/dist/interpreter/browser-network.d.ts +52 -0
  47. package/dist/interpreter/browser-port.d.ts +55 -0
  48. package/dist/interpreter/browser.d.ts +79 -0
  49. package/dist/interpreter/cli.d.ts +5 -0
  50. package/dist/interpreter/codec.d.ts +42 -0
  51. package/dist/interpreter/component/execution.d.ts +42 -0
  52. package/dist/interpreter/component/host.d.ts +69 -0
  53. package/dist/interpreter/component/instance.d.ts +40 -0
  54. package/dist/interpreter/component/kernel.d.ts +120 -0
  55. package/dist/interpreter/component/names.d.ts +5 -0
  56. package/dist/interpreter/component/port.d.ts +85 -0
  57. package/dist/interpreter/component/prepared.d.ts +97 -0
  58. package/dist/interpreter/component/resources.d.ts +45 -0
  59. package/dist/interpreter/component/revision.d.ts +87 -0
  60. package/dist/interpreter/component/scope.d.ts +116 -0
  61. package/dist/interpreter/component/streams.d.ts +28 -0
  62. package/dist/interpreter/component/values.d.ts +79 -0
  63. package/dist/interpreter/component/wasi-filesystem.d.ts +21 -0
  64. package/dist/interpreter/component/wasi-host.d.ts +64 -0
  65. package/dist/interpreter/component/wasi-http.d.ts +33 -0
  66. package/dist/interpreter/component/wasi-sockets.d.ts +183 -0
  67. package/dist/interpreter/component/wasi.d.ts +41 -0
  68. package/dist/interpreter/core.d.ts +64 -0
  69. package/dist/interpreter/fetch-http-provider.d.ts +17 -0
  70. package/dist/interpreter/filesystem/contract.d.ts +85 -0
  71. package/dist/interpreter/filesystem/memory.d.ts +3 -0
  72. package/dist/interpreter/filesystem/opfs.d.ts +3 -0
  73. package/dist/interpreter/filesystem/scope.d.ts +35 -0
  74. package/dist/interpreter/filesystem.d.ts +8 -0
  75. package/dist/interpreter/gate.d.ts +6 -0
  76. package/dist/interpreter/host-protocol.d.ts +100 -0
  77. package/dist/interpreter/http-ingress-fetch.d.ts +7 -0
  78. package/dist/interpreter/http-ingress.d.ts +96 -0
  79. package/dist/interpreter/http-provider.d.ts +85 -0
  80. package/dist/interpreter/io.d.ts +20 -0
  81. package/dist/interpreter/mobile.d.ts +149 -0
  82. package/dist/interpreter/native-ingress.d.ts +95 -0
  83. package/dist/interpreter/node-port.d.ts +25 -0
  84. package/dist/interpreter/node.d.ts +36 -0
  85. package/dist/interpreter/revision.d.ts +64 -0
  86. package/dist/interpreter/scope.d.ts +89 -0
  87. package/dist/interpreter/socket-addresses.d.ts +50 -0
  88. package/dist/interpreter/socket-provider.d.ts +110 -0
  89. package/dist/interpreter/standard-cli.d.ts +34 -0
  90. package/dist/interpreter/standard-codec.d.ts +96 -0
  91. package/dist/interpreter/standard-filesystem.d.ts +47 -0
  92. package/dist/interpreter/standard-host.d.ts +71 -0
  93. package/dist/interpreter/standard-http-values.d.ts +159 -0
  94. package/dist/interpreter/standard-http.d.ts +9 -0
  95. package/dist/interpreter/standard-ingress.d.ts +63 -0
  96. package/dist/interpreter/standard-sockets.d.ts +177 -0
  97. package/dist/interpreter/standard-streams.d.ts +218 -0
  98. package/dist/interpreter/standard-system.d.ts +35 -0
  99. package/dist/interpreter/standard-utf8.d.ts +4 -0
  100. package/dist/interpreter/standard.d.ts +18 -0
  101. package/dist/interpreter/types.d.ts +152 -0
  102. package/dist/interpreter/wit-shape.d.ts +92 -0
  103. package/dist/manager.js +5 -332
  104. package/dist/msgpack.js +9 -615
  105. package/dist/node.d.ts +8 -1
  106. package/dist/node.js +248 -3321
  107. package/dist/rpc.js +196 -699
  108. package/dist/runtime/adapters.d.ts +120 -0
  109. package/dist/runtime/adapters.js +38 -0
  110. package/dist/runtime/calls.d.ts +7 -6
  111. package/dist/runtime/lifecycle.d.ts +3 -1
  112. package/dist/runtime/orbs.d.ts +5 -4
  113. package/dist/runtime/references.d.ts +27 -1
  114. package/dist/runtime/reload.d.ts +5 -3
  115. package/dist/runtime/scopes.d.ts +1 -1
  116. package/dist/runtime/signals.d.ts +4 -0
  117. package/dist/runtime/wit-client.d.ts +38 -0
  118. package/dist/telemetry.js +4 -25
  119. package/dist/tooling/build.d.ts +2 -2
  120. package/dist/tooling/client-resources.d.ts +23 -0
  121. package/dist/tooling/client.d.ts +10 -0
  122. package/dist/tooling/component-glue.d.ts +17 -0
  123. package/dist/tooling/component.d.ts +11 -0
  124. package/dist/tooling/index.d.ts +3 -1
  125. package/dist/tooling/index.js +1155 -102
  126. package/dist/tooling/resolver.d.ts +4 -4
  127. package/dist/tooling/typecheck.d.ts +2 -1
  128. package/dist/tooling/types.d.ts +27 -12
  129. package/dist/tooling/wit.d.ts +9 -0
  130. package/dist/wasi/wasi-clocks-types.d.ts +2 -0
  131. package/dist/wasi/wasi-http-client.d.ts +5 -0
  132. package/dist/wasi/wasi-http-types.d.ts +285 -0
  133. package/dist/wasi/wasi-sockets-ip-name-lookup.d.ts +23 -0
  134. package/dist/wasi/wasi-sockets-types.d.ts +146 -0
  135. package/package.json +62 -35
  136. package/src/authoring/declaration.ts +1 -1
  137. package/src/authoring/types.ts +53 -3
  138. package/src/authoring/wit.ts +15 -0
  139. package/src/bridge/commands.ts +1105 -0
  140. package/src/bridge/identifiers.ts +2 -0
  141. package/src/bridge/kernel.ts +56 -98
  142. package/src/bridge/protocol.ts +3 -142
  143. package/src/browser.ts +90 -6
  144. package/src/context-key.ts +4 -7
  145. package/src/error.ts +1 -1
  146. package/src/errors.ts +7 -0
  147. package/src/guest.ts +327 -0
  148. package/src/host.ts +128 -23
  149. package/src/http/bytes.ts +87 -0
  150. package/src/http/events.ts +34 -0
  151. package/src/http.ts +272 -0
  152. package/src/index.ts +3 -0
  153. package/src/infrastructure/rpc/client.ts +136 -17
  154. package/src/infrastructure/rpc/resources.ts +123 -0
  155. package/src/interpreter/abi.ts +69 -0
  156. package/src/interpreter/acquire.ts +58 -0
  157. package/src/interpreter/browser-network.ts +170 -0
  158. package/src/interpreter/browser-port.ts +425 -0
  159. package/src/interpreter/browser.ts +340 -0
  160. package/src/interpreter/cli.ts +30 -0
  161. package/src/interpreter/codec.ts +298 -0
  162. package/src/interpreter/component/execution.ts +264 -0
  163. package/src/interpreter/component/host.ts +409 -0
  164. package/src/interpreter/component/instance.ts +138 -0
  165. package/src/interpreter/component/kernel.ts +611 -0
  166. package/src/interpreter/component/names.ts +13 -0
  167. package/src/interpreter/component/port.ts +598 -0
  168. package/src/interpreter/component/prepared.ts +194 -0
  169. package/src/interpreter/component/resources.ts +345 -0
  170. package/src/interpreter/component/revision.ts +702 -0
  171. package/src/interpreter/component/scope.ts +447 -0
  172. package/src/interpreter/component/streams.ts +180 -0
  173. package/src/interpreter/component/values.ts +254 -0
  174. package/src/interpreter/component/wasi-filesystem.ts +472 -0
  175. package/src/interpreter/component/wasi-host.ts +197 -0
  176. package/src/interpreter/component/wasi-http.ts +939 -0
  177. package/src/interpreter/component/wasi-sockets.ts +958 -0
  178. package/src/interpreter/component/wasi.ts +238 -0
  179. package/src/interpreter/core.ts +386 -0
  180. package/src/interpreter/fetch-http-provider.ts +98 -0
  181. package/src/interpreter/filesystem/contract.ts +138 -0
  182. package/src/interpreter/filesystem/memory.ts +180 -0
  183. package/src/interpreter/filesystem/opfs.ts +294 -0
  184. package/src/interpreter/filesystem/scope.ts +390 -0
  185. package/src/interpreter/filesystem.ts +20 -0
  186. package/src/interpreter/gate.ts +55 -0
  187. package/src/interpreter/host-protocol.ts +242 -0
  188. package/src/interpreter/http-ingress-fetch.ts +133 -0
  189. package/src/interpreter/http-ingress.ts +203 -0
  190. package/src/interpreter/http-provider.ts +105 -0
  191. package/src/interpreter/io.ts +66 -0
  192. package/src/interpreter/mobile.ts +385 -0
  193. package/src/interpreter/native-ingress.ts +550 -0
  194. package/src/interpreter/node-port.ts +218 -0
  195. package/src/interpreter/node.ts +114 -0
  196. package/src/interpreter/revision.ts +450 -0
  197. package/src/interpreter/scope.ts +453 -0
  198. package/src/interpreter/socket-addresses.ts +246 -0
  199. package/src/interpreter/socket-provider.ts +126 -0
  200. package/src/interpreter/standard-cli.ts +184 -0
  201. package/src/interpreter/standard-codec.ts +403 -0
  202. package/src/interpreter/standard-filesystem.ts +545 -0
  203. package/src/interpreter/standard-host.ts +840 -0
  204. package/src/interpreter/standard-http-values.ts +624 -0
  205. package/src/interpreter/standard-http.ts +622 -0
  206. package/src/interpreter/standard-ingress.ts +344 -0
  207. package/src/interpreter/standard-sockets.ts +847 -0
  208. package/src/interpreter/standard-streams.ts +710 -0
  209. package/src/interpreter/standard-system.ts +182 -0
  210. package/src/interpreter/standard-utf8.ts +72 -0
  211. package/src/interpreter/standard.ts +283 -0
  212. package/src/interpreter/types.ts +163 -0
  213. package/src/interpreter/wit-shape.ts +175 -0
  214. package/src/node.ts +43 -14
  215. package/src/runtime/activities.ts +6 -6
  216. package/src/runtime/adapters.ts +314 -0
  217. package/src/runtime/calls.ts +213 -90
  218. package/src/runtime/context.ts +7 -7
  219. package/src/runtime/lifecycle.ts +36 -17
  220. package/src/runtime/orbs.ts +81 -39
  221. package/src/runtime/programs.ts +16 -8
  222. package/src/runtime/references.ts +128 -11
  223. package/src/runtime/reload.ts +71 -30
  224. package/src/runtime/resources.ts +2 -2
  225. package/src/runtime/scopes.ts +17 -17
  226. package/src/runtime/session.ts +3 -1
  227. package/src/runtime/signals.ts +31 -0
  228. package/src/runtime/wit-client.ts +228 -0
  229. package/src/tooling/build.ts +152 -54
  230. package/src/tooling/client-resources.ts +74 -0
  231. package/src/tooling/client.ts +531 -0
  232. package/src/tooling/component-glue.ts +288 -0
  233. package/src/tooling/component.ts +225 -0
  234. package/src/tooling/index.ts +3 -7
  235. package/src/tooling/resolver.ts +42 -25
  236. package/src/tooling/typecheck.ts +59 -4
  237. package/src/tooling/types.ts +27 -12
  238. package/src/tooling/wit.ts +188 -0
  239. package/dist/embedded.d.ts +0 -1
  240. package/dist/embedded.js +0 -1
  241. package/src/embedded.ts +0 -301
@@ -1,6 +1,7 @@
1
1
  import type { DynamicReference } from "../../authoring/types.ts";
2
2
  import { RpcOp } from "../../bridge/protocol.ts";
3
3
  import { Channel, type Limits, type Transport } from "./channel.ts";
4
+ import type { AcquisitionOptions } from "../../authoring/types.ts";
4
5
  /** A lost connection revokes its references. Reconnect by creating a peer and acquiring current state. */
5
6
  export declare class RemoteHost {
6
7
  #private;
@@ -12,7 +13,7 @@ export declare class RemoteHost {
12
13
  /** Request remote orb metadata without service activation. */
13
14
  installedOrbs(): Promise<unknown>;
14
15
  /** Acquire a remote reference and its current state snapshot. */
15
- get(service: string, key: string | readonly string[], options?: {
16
+ get(service: string, key: string | readonly string[], options?: AcquisitionOptions & {
16
17
  signal?: AbortSignal;
17
18
  }): Promise<DynamicReference>;
18
19
  /** Close the connection and reject pending requests. */
@@ -0,0 +1,28 @@
1
+ import type { CapturedInvocation } from "../../runtime/adapters.ts";
2
+ import type { WitClientBackend, WitClientSchema } from "../../runtime/wit-client.ts";
3
+ /** A descriptor is useful only on its original connection and never replaces host admission. */
4
+ export interface RpcResource {
5
+ readonly reference: number;
6
+ readonly token: string;
7
+ readonly interface: string;
8
+ readonly name: string;
9
+ readonly revision: string;
10
+ }
11
+ /** Validate server descriptors before giving the existing SDK owner authority to release them. */
12
+ export declare function resource(value: unknown): RpcResource;
13
+ /** The RemoteHost supplies ordinary request, release and connection operations. */
14
+ interface RemoteDelivery {
15
+ readonly identity: object;
16
+ readonly reference: number;
17
+ readonly resources: unknown;
18
+ readonly signature: unknown;
19
+ /** Check service release only for calls that have no independent resource receiver. */
20
+ check(): void;
21
+ /** Correlate captured delivery with the existing RPC cancellation path. */
22
+ request(payload: unknown, capture: CapturedInvocation, received: (value: unknown) => void, signal?: AbortSignal): Promise<unknown>;
23
+ /** Release through the existing connection claim table. */
24
+ release(resource: RpcResource): void;
25
+ }
26
+ /** Bind one generated client without a browser component or a second ownership implementation. */
27
+ export declare function resourceBackend(remote: RemoteDelivery, schema: WitClientSchema): WitClientBackend;
28
+ export {};
@@ -0,0 +1,54 @@
1
+ export declare const IMPORT_MODULE = "tembra-interpreter-v13-d82248b7b421e5294c2536726adcbbe2c178bc87142fc7ee04faf691081c101b";
2
+ export declare const SYNC_IMPORT = "sync";
3
+ export declare const SYNC_READ_IMPORT = "sync_read";
4
+ export declare const MEMORY_MODULE = "env";
5
+ export declare const MEMORY_IMPORT = "memory";
6
+ export declare const INITIALIZE_EXPORT = "_initialize";
7
+ export declare const ALLOC_EXPORT = "tembra_alloc";
8
+ export declare const CALL_EXPORT = "tembra_call";
9
+ export declare const WASI_MODULE = "wasi_snapshot_preview1";
10
+ export declare const SYNC_ERROR = 2147483648;
11
+ export declare const STANDARD_PACKET = 0;
12
+ export declare const MEMORY_INITIAL_PAGES = 32;
13
+ export declare const PAGE_BYTES = 65536;
14
+ export declare const LENGTH_LIMIT = 2147483647;
15
+ export declare const EFFECT_LIMIT = 128;
16
+ export declare const IDENTITY_LIMIT = 9007199254740991;
17
+ export declare const REPLY_HEADER_BYTES = 20;
18
+ export declare const EFFECT_RECORD_BYTES = 12;
19
+ export declare const COMPLETION_HEADER_BYTES = 4;
20
+ export declare const COMPLETION_RECORD_BYTES = 16;
21
+ export declare const ERRNO_SUCCESS = 0;
22
+ export declare const ERRNO_BADF = 8;
23
+ export declare const ERRNO_FAULT = 21;
24
+ export declare const ERRNO_INVAL = 28;
25
+ export declare const ERRNO_NOTDIR = 54;
26
+ export declare const ERRNO_SPIPE = 70;
27
+ export declare const CLOCK_REALTIME = 0;
28
+ export declare const CLOCK_MONOTONIC = 1;
29
+ export declare const STDIO_DESCRIPTORS = 3;
30
+ export declare const FILETYPE_CHARACTER_DEVICE = 2;
31
+ export declare const RIGHT_FD_WRITE = 64;
32
+ export declare const FDSTAT_BYTES = 24;
33
+ export declare const STDIO_LIMIT = 4096;
34
+ export declare const WASI_IMPORTS: readonly ["clock_time_get", "environ_get", "environ_sizes_get", "fd_close", "fd_fdstat_get", "fd_prestat_dir_name", "fd_prestat_get", "fd_seek", "fd_write", "path_open", "proc_exit"];
35
+ export declare const Operation: Readonly<{
36
+ readonly Load: 0;
37
+ readonly Declare: 1;
38
+ readonly Start: 2;
39
+ readonly Resume: 3;
40
+ readonly Cancel: 4;
41
+ readonly Capture: 5;
42
+ }>;
43
+ export type Operation = (typeof Operation)[keyof typeof Operation];
44
+ export declare const ReplyKind: Readonly<{
45
+ readonly Pending: 0;
46
+ readonly Ok: 1;
47
+ readonly Error: 2;
48
+ }>;
49
+ export type ReplyKind = (typeof ReplyKind)[keyof typeof ReplyKind];
50
+ export declare const Status: Readonly<{
51
+ readonly Ok: 0;
52
+ readonly Error: 1;
53
+ }>;
54
+ export type Status = (typeof Status)[keyof typeof Status];
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `Context.get` acquisition shared by source scopes and compiled component scopes.
3
+ *
4
+ * The guest names only an import binding (already resolved to its qualified service) and a key.
5
+ * The host resolves the installed requirement's API version and methods, acquires under the
6
+ * admitted invocation's root (and therefore its principal), and awaits readiness under the
7
+ * callback's cancellation. A claim whose wait, authority or publication fails is released before
8
+ * any guest handle exists; the runtime's root claim list releases a published claim when its root
9
+ * ends.
10
+ */
11
+ import type { Declaration } from "../authoring/declaration.ts";
12
+ import type { DynamicReference } from "../authoring/types.ts";
13
+ import type { Context } from "../runtime/context.ts";
14
+ /**
15
+ * Acquire `service` at `key` for the admitted invocation of `context` and publish it with
16
+ * `publish` once ready. `ended` is the issuing callback's own lifetime.
17
+ */
18
+ export declare function acquireReference<T>(declaration: Declaration, service: string, key: readonly string[], context: Context, ended: AbortSignal, publish: (reference: DynamicReference) => T): Promise<T>;
@@ -0,0 +1,52 @@
1
+ import type { Grants } from "../authoring/types.ts";
2
+ import type { HttpProvider } from "./http-provider.ts";
3
+ import { type Address } from "./socket-addresses.ts";
4
+ import type { SocketProvider } from "./socket-provider.ts";
5
+ import type { HttpClient } from "./standard-http.ts";
6
+ export interface BrowserNetworkProviders {
7
+ http?: Readonly<Record<string, HttpProvider>>;
8
+ network?: Readonly<Record<string, SocketProvider>>;
9
+ }
10
+ /** Address uses checked before a socket side effect, as upstream `SocketAddrUse`. */
11
+ export type SocketUse = "tcp-bind" | "tcp-listen" | "tcp-accept" | "tcp-connect" | "udp-bind" | "udp-send" | "udp-receive";
12
+ /**
13
+ * The socket and lookup authority of exactly one provider: the grants naming that provider,
14
+ * never another provider's. Rules mirror native `Sockets::allows`.
15
+ */
16
+ export declare class SocketGrants {
17
+ #private;
18
+ readonly resolve: boolean;
19
+ constructor(grants: Grants, provider: string);
20
+ /** Any TCP authority (`allow_tcp`). */
21
+ get tcp(): boolean;
22
+ /** Any UDP authority (`allow_udp`). */
23
+ get udp(): boolean;
24
+ allows(address: Address, use: SocketUse): boolean;
25
+ }
26
+ /** The provider and authority behind one Orb's `wasi:sockets` import. */
27
+ export interface SocketAccess {
28
+ /** `undefined` when the bound provider name has no registered socket provider. */
29
+ readonly provider: SocketProvider | undefined;
30
+ readonly grants: SocketGrants;
31
+ }
32
+ /**
33
+ * Granted network selections of one Orb:
34
+ * - HTTP is served only through standard `wasi:http` (`provider`, checked by the standard host
35
+ * before any provider call);
36
+ * - sockets and name lookup use the providers bound to the Orb's exact WIT imports (`sockets`).
37
+ */
38
+ export declare class BrowserNetwork implements HttpClient {
39
+ #private;
40
+ readonly grants: Grants;
41
+ readonly providers: BrowserNetworkProviders;
42
+ constructor(grants: Grants, providers: BrowserNetworkProviders);
43
+ /**
44
+ * The provider granted for exactly `url`'s origin. Standard `wasi:http` sends call this before
45
+ * any provider work; HTTP grants never follow raw socket grants or the reverse.
46
+ */
47
+ provider(url: URL): HttpProvider | undefined;
48
+ /** The socket provider and authority for the provider name an import binding selected. */
49
+ sockets(provider: string | undefined): SocketAccess | undefined;
50
+ /** Physical sockets are owned and closed by the revision's standard host. */
51
+ dispose(): void;
52
+ }
@@ -0,0 +1,55 @@
1
+ import type { Guest } from "./core.ts";
2
+ import { type HostRequest } from "./host-protocol.ts";
3
+ import type { StandardHost } from "./standard-host.ts";
4
+ import type { ExecutionScope, IngressDispatch, InterpreterPort } from "./types.ts";
5
+ import type { IngressExchange } from "./http-ingress.ts";
6
+ /** A serialized Wasm heap yields data; host promises never enter its execution stack. */
7
+ export declare class BrowserPort implements InterpreterPort {
8
+ #private;
9
+ readonly timeout: number;
10
+ readonly dispose: () => Promise<void>;
11
+ readonly log: (record: Extract<HostRequest, {
12
+ operation: "console";
13
+ }>) => void;
14
+ readonly packetBytes: number;
15
+ guest: Guest | undefined;
16
+ /** Revision-owned standard WASI host; absent until installation opens it. */
17
+ standard: StandardHost | undefined;
18
+ /** Retain per-installation I/O and logging independently of callback authority. */
19
+ constructor(timeout: number, dispose: () => Promise<void>, log: (record: Extract<HostRequest, {
20
+ operation: "console";
21
+ }>) => void, packetBytes?: number);
22
+ /** UTF-8 uses at most three bytes per UTF-16 code unit; only large packets need encoding. */
23
+ private bounded;
24
+ /** Bound a binary packet or reply by its exact length. */
25
+ private boundedBytes;
26
+ /** Decode once and invoke the current host-owned scope without an event envelope. */
27
+ sync(packet: string): string;
28
+ sync(packet: Uint8Array): Uint8Array;
29
+ /** Observe cleanup and interruption in the same export result as the callback. */
30
+ private value;
31
+ /** Preserve the bounded result bytes for the prepared contract to check before decoding. */
32
+ private text;
33
+ /** Any exception leaving the guest is a trap; the instance is never entered again. */
34
+ private guard;
35
+ /** Refuse reuse until the previous stack and its I/O have physically returned. */
36
+ private enter;
37
+ /** Initialize one revision before issuing any guest execution scope. */
38
+ load(packet: string): Promise<void>;
39
+ /** Read the validated source callback metadata once. */
40
+ description(): string;
41
+ /** Factories receive only the synchronous declaration scope. */
42
+ declare(packet: string, scope: ExecutionScope): Promise<unknown>;
43
+ /**
44
+ * Serve one incoming HTTP request: issue its request handle, then run the handler callback.
45
+ * The callback (and so this call) lasts until the response delivery ended; whatever the
46
+ * delivery had not finished when it ends is aborted with the callback's failure.
47
+ */
48
+ ingress(dispatch: IngressDispatch, exchange: IngressExchange, scope: ExecutionScope): Promise<void>;
49
+ /** Wait between steps in the host, preserving Promise.race and concurrent effect completion. */
50
+ execute(packet: string, scope: ExecutionScope): Promise<string>;
51
+ /** Pure guest cleanup needs no execution capability after the environment ends. */
52
+ release(environment: number): Promise<void>;
53
+ /** Dispose mounted providers only after their last physical operation has settled. */
54
+ close(): Promise<void>;
55
+ }
@@ -0,0 +1,79 @@
1
+ import type { OrbDefinition, OrbArtifact } from "../authoring/types.ts";
2
+ import type { BrowserNetworkProviders } from "./browser-network.ts";
3
+ import type { FilesystemProvider } from "./filesystem.ts";
4
+ import type { SystemProviders } from "./standard-system.ts";
5
+ import type { StdioProvider } from "./standard-cli.ts";
6
+ import { type ContractPort } from "./types.ts";
7
+ import type { PreparedContract } from "./component/execution.ts";
8
+ import { type PreparedComponent } from "./component/prepared.ts";
9
+ export interface BrowserInterpreterOptions {
10
+ /** URL of the interpreter core module; defaults to the packaged `interpreter.wasm`. */
11
+ engine?: string | URL;
12
+ providers?: BrowserNetworkProviders & SystemProviders & {
13
+ filesystem?: Readonly<Record<string, FilesystemProvider>>;
14
+ stdio?: StdioProvider;
15
+ };
16
+ limits?: {
17
+ /**
18
+ * Guest linear memory of one instance in bytes. A compiled component spends whole 64 KiB
19
+ * pages: initial memories of every core instantiation plus `memory.grow`.
20
+ */
21
+ memoryBytes?: number;
22
+ /** Wall time of one guest callback, including its host work until physical completion. */
23
+ timeoutMs?: number;
24
+ instructionTicks?: number;
25
+ packetBytes?: number;
26
+ /**
27
+ * Compiled components: fuel of one admitted callback, and separately of instantiation
28
+ * (function entries and loop iterations). Exhaustion traps and quarantines the revision.
29
+ */
30
+ fuel?: number;
31
+ };
32
+ /**
33
+ * Application-owned adapters generated by Tembra tooling (`browser: true`) for the compiled
34
+ * Orbs this host may install. Source Orbs need none.
35
+ */
36
+ components?: readonly PreparedComponent[];
37
+ onLog?: (record: {
38
+ orb: string;
39
+ level: string;
40
+ message: string;
41
+ }) => void;
42
+ contractsInput?: unknown;
43
+ }
44
+ interface BrowserArtifact extends ContractPort {
45
+ description(): string;
46
+ source(): string;
47
+ free(): void;
48
+ }
49
+ interface ContractModule {
50
+ WasmArtifact: new (bytes: Uint8Array) => BrowserArtifact;
51
+ WasmPreparedComponent: new (bytes: Uint8Array, digests: string[]) => PreparedContract & {
52
+ free(): void;
53
+ };
54
+ compiledArtifact(bytes: Uint8Array): boolean;
55
+ default(input?: unknown): Promise<unknown>;
56
+ }
57
+ /** A browser backend instantiates one isolated core module, memory and heap per Orb. */
58
+ export declare class BrowserExecution {
59
+ #private;
60
+ readonly options: BrowserInterpreterOptions;
61
+ readonly contracts: ContractModule;
62
+ /** Keep the prepared-contract validator and trusted engine out of metadata-only hosts. */
63
+ constructor(options: BrowserInterpreterOptions, contracts: ContractModule);
64
+ /** Share compiled code between installations; every instance still owns its state. */
65
+ private engine;
66
+ /** Own one checked contract for exactly one installed revision. */
67
+ materialize(definition: OrbArtifact): Promise<OrbDefinition>;
68
+ /**
69
+ * A compiled Orb runs only through an application-registered prepared adapter. The verifier
70
+ * hashes the actual uploaded bytes and accepts their metadata only for a registered digest;
71
+ * the execution code loads on the first such installation.
72
+ */
73
+ private compiled;
74
+ /** Check installation authority before creating any guest heap or filesystem descriptors. */
75
+ private open;
76
+ }
77
+ /** Load the optional interpreter assets and prepared-contract validator behind Tembra's facade. */
78
+ export declare function createExecution(options: BrowserInterpreterOptions): Promise<BrowserExecution>;
79
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { CliOptions } from "../authoring/types.ts";
2
+ /** Capture installation data before asynchronous preparation can observe caller mutations. */
3
+ export declare function captureCli(options: CliOptions): CliOptions;
4
+ /** Copy explicitly configured stdin once into the native installation's data configuration. */
5
+ export declare function cliPacket(options: CliOptions | undefined): string;
@@ -0,0 +1,42 @@
1
+ import type { ContractPort } from "./types.ts";
2
+ import { type Shape } from "./wit-shape.ts";
3
+ /** Default ceiling for one captured value, matching the default interpreter packet bound. */
4
+ export declare const VALUE_LIMIT: number;
5
+ /** Container nesting accepted before the Rust validator's own type-depth limit applies. */
6
+ export declare const VALUE_DEPTH = 64;
7
+ /**
8
+ * JSON text captured by `encode`. The constructor refuses foreign callers, so raw strings cannot
9
+ * be spliced into interpreter packets without passing through this module.
10
+ */
11
+ export declare class Encoded {
12
+ #private;
13
+ /** Only this module can issue captured text. */
14
+ constructor(token: symbol, text: string);
15
+ /** Read captured text; the private-field access rejects forged instances. */
16
+ get text(): string;
17
+ }
18
+ /**
19
+ * Capture `value` once, bounded by UTF-16 length and container depth. `shape` (from the prepared
20
+ * signature) marks WIT `u64`/`s64` positions; without one, the walk is the untyped capture.
21
+ */
22
+ export declare function encode(value: unknown, limit?: number, shape?: Shape): Encoded;
23
+ /**
24
+ * Check captured bytes through a slot bound at installation. The same `Encoded` instance is then
25
+ * the only value that may be spliced into a packet, so no second serialization can diverge.
26
+ */
27
+ export declare function check(contract: ContractPort, slot: number, arguments_: boolean, value: Encoded): Encoded;
28
+ /** Check the guest's original bytes before decoding them into the outer JavaScript heap. */
29
+ export declare function checkedResult(contract: ContractPort, slot: number, text: string): Encoded;
30
+ /** Host replies preserve an already checked capture rather than decoding and serializing it. */
31
+ export declare function reply(value: unknown): string;
32
+ /**
33
+ * A host refusal as the native worker reads it: a structured error with its code and reason, which
34
+ * the guest's request answers; any other failure as its text, which the worker answers as
35
+ * `invalid/platform_reply`, the host refusing the request itself.
36
+ */
37
+ export declare function refusal(error: unknown): string;
38
+ /**
39
+ * Build a guest packet from fixed control fields and one captured value. Control values are
40
+ * primitives encoded by the platform JSON writer; the value is spliced only from `Encoded`.
41
+ */
42
+ export declare function packet(control: Readonly<Record<string, string | number | null>>, field: string, value: Encoded): string;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Installation of a compiled Orb through its application-owned prepared adapter.
3
+ *
4
+ * Loaded lazily: hosts running only source Orbs never fetch this code. The artifact's metadata
5
+ * was accepted only because the browser verifier hashed its actual bytes to the adapter's digest
6
+ * (see `prepared.ts`). Every installation receives a fresh instance: JCO state, memories,
7
+ * tables, resources, WASI import objects, providers and limit globals.
8
+ */
9
+ import type { LoadOptions, OrbDefinition } from "../../authoring/types.ts";
10
+ import type { BrowserNetworkProviders } from "../browser-network.ts";
11
+ import type { FilesystemProvider } from "../filesystem.ts";
12
+ import type { StdioProvider } from "../standard-cli.ts";
13
+ import { type SystemProviders } from "../standard-system.ts";
14
+ import { type ContractPort } from "../types.ts";
15
+ import type { PreparedRecord } from "./prepared.ts";
16
+ import type { LogObserver } from "./kernel.ts";
17
+ /** Browser options a compiled installation reads. */
18
+ export interface ComponentOptions {
19
+ providers?: BrowserNetworkProviders & SystemProviders & {
20
+ filesystem?: Readonly<Record<string, FilesystemProvider>>;
21
+ stdio?: StdioProvider;
22
+ };
23
+ limits?: {
24
+ memoryBytes?: number;
25
+ timeoutMs?: number;
26
+ fuel?: number;
27
+ };
28
+ /** Receives the Orb's `tembra:guest/context` log records, as a source Orb's console. */
29
+ onLog?: LogObserver;
30
+ }
31
+ /** The verifier's digest-bound metadata of one compiled artifact. */
32
+ export interface PreparedContract extends ContractPort {
33
+ description(): string;
34
+ contributions(): string;
35
+ /** Declared hooks and their composition, by interface identity, as a JSON object. */
36
+ hooks(): string;
37
+ /** Service lifetimes and lingers, by interface identity, as a JSON object. */
38
+ services(): string;
39
+ digest(): string;
40
+ }
41
+ /** Install one compiled Orb; `release` frees the verifier handle exactly once. */
42
+ export declare function openComponent(record: PreparedRecord, contract: PreparedContract, installation: LoadOptions, options: ComponentOptions, release: () => void): Promise<OrbDefinition>;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Typed Orb dependency imports of a compiled component.
3
+ *
4
+ * Each call acts for the callback that owns the guest's current root export task (read
5
+ * synchronously at import entry) and stays physically accounted to that callback until it
6
+ * settles. A plain import targets the root environment's default `main` reference; a reference
7
+ * view's methods target the claim their receiver names. Infrastructure failures (refusal,
8
+ * cancellation, a provider failure, a stale or foreign receiver) reject, which the generated
9
+ * suspending import turns into a trap: only the function's own WIT `result` is recoverable. A
10
+ * view's acquisition is the exception: its key is request data, so any failure to acquire is
11
+ * its WIT `err`, never a trap.
12
+ */
13
+ import type { ResourceCapability } from "#tembra-adapters";
14
+ import { type ComponentPort } from "./port.ts";
15
+ import type { Described } from "./revision.ts";
16
+ import type { ReferenceBinding } from "../types.ts";
17
+ import type { FunctionValues, GraphFunction } from "./values.ts";
18
+ import type { Nominal } from "./resources.ts";
19
+ interface ImportedResource {
20
+ wrap(owner: ResourceCapability): object;
21
+ move(value: object): ResourceCapability;
22
+ }
23
+ /** Resolve only the defining import's instance-specific class and ownership table. */
24
+ export declare function importedResource(port: ComponentPort, nominal: Nominal): ImportedResource;
25
+ /** One typed import function and its conversions. */
26
+ export interface ImportedFunction {
27
+ /** The WIT function name. */
28
+ readonly name: string;
29
+ /** The JavaScript spelling the generated bindings call. */
30
+ readonly spelling: string;
31
+ readonly values: FunctionValues;
32
+ }
33
+ /** The import object of one Orb dependency binding. */
34
+ export declare function dependencyImport(port: ComponentPort, binding: string, functions: readonly ImportedFunction[]): Record<string, unknown>;
35
+ /**
36
+ * A view method's data signature: the implicit `self` receiver names a host-local reference and
37
+ * never travels as data, while the method keeps its original WIT slot.
38
+ */
39
+ export declare function viewMethod<F extends {
40
+ readonly params: readonly unknown[];
41
+ }>(fn: F): F;
42
+ /** The checked shape of one reference-view import, with its generated JavaScript spellings. */
43
+ export interface ReferenceView {
44
+ /** The generated binding's name of the view's host resource class. */
45
+ readonly resource: string;
46
+ /** The acquisition function; its conversions cover only the key parameter. */
47
+ readonly acquire: ImportedFunction;
48
+ /** Methods by original WIT name, with conversions of their data parameters (no `self`). */
49
+ readonly methods: readonly ImportedFunction[];
50
+ }
51
+ /**
52
+ * The generated spellings and data conversions of one checked reference view: the resource
53
+ * class, the acquisition function (its key only) and each method without its `self` receiver.
54
+ */
55
+ export declare function referenceView(graph: Described, binding: string, view: ReferenceBinding, convert: (fn: GraphFunction) => FunctionValues): ReferenceView;
56
+ /**
57
+ * The import object of one reference-view binding: its acquisition function and the host
58
+ * resource class the generated bindings require.
59
+ *
60
+ * An instance is a host-local capability living only in this instance's generated handle table:
61
+ * it names one root claim and is never an inter-Orb guest resource. The guest dropping its own
62
+ * handle releases the claim; the claim's root ending invalidates it.
63
+ */
64
+ export declare function referenceImport(port: ComponentPort, binding: string, view: ReferenceView): Record<string, unknown>;
65
+ /** Ordinary provider-owned WIT resources; keyed reference views use their separate adapter. */
66
+ export declare function resourceImport(port: ComponentPort, binding: string, functions: readonly (ImportedFunction & {
67
+ readonly roles: import("./resources.ts").ResourceRoles;
68
+ })[], types?: readonly Nominal[]): Record<string, unknown>;
69
+ export {};
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Instantiation of a prepared component: no generator, parser or encoder runs here.
3
+ *
4
+ * Compiled `WebAssembly.Module`s are shared by every installation of one adapter. Each
5
+ * installation still runs the generated factory once, so JCO state, memories, tables, resource
6
+ * tables and every host import object are its own. Component core modules were instrumented at
7
+ * build time; this module only checks that they import the private limit globals and debits each
8
+ * instantiation's initial pages from the installation's shared budget before it starts.
9
+ */
10
+ import { type PreparedRecord } from "./prepared.ts";
11
+ /** Lifecycle notifications of one instance from the instrumented trusted glue. */
12
+ export interface TaskObserver {
13
+ /** Called once at instantiation with an accessor valid only synchronously at host-import entry. */
14
+ attach(access: {
15
+ currentRootTask(): number | null;
16
+ }): void;
17
+ taskStarted(task: {
18
+ id: number;
19
+ entry: string;
20
+ isAsync: boolean;
21
+ }): void;
22
+ taskExited(task: {
23
+ id: number;
24
+ rejected?: boolean;
25
+ error?: unknown;
26
+ }): void;
27
+ trapped(error: unknown): void;
28
+ }
29
+ /**
30
+ * The per-instance limits shared by all its core modules: `fuel` is debited at function entries
31
+ * and loop headers (a trap at zero), `pages` by every instantiation and `memory.grow`.
32
+ */
33
+ export interface CoreLimits {
34
+ readonly fuel: WebAssembly.Global;
35
+ readonly pages: WebAssembly.Global;
36
+ }
37
+ /** Refuse before any work when the engine lacks JSPI, which the generated glue requires. */
38
+ export declare function requireJspi(): void;
39
+ /** Instantiate one isolated instance of a prepared component. */
40
+ export declare function instantiate(record: PreparedRecord, imports: Record<string, unknown>, observer: TaskObserver, limits: CoreLimits): Promise<Record<string, unknown>>;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * The kernel's own interfaces (`tembra:guest`) for a prepared component.
3
+ *
4
+ * A compiled Orb keeps kernel-managed state, opens root resources, declares hooks and reads its
5
+ * call's context through the bundled `tembra:guest` package. Native hosts serve it by turning
6
+ * each operation into the private host request a source Orb issues (`state.declare`,
7
+ * `resource.declare`, `hook.declare`, `hook.run`, ...), answered by the same code as for a
8
+ * source Orb: the native executor on Rust hosts, the interpreter `Scope` on Node and mobile. A
9
+ * prepared browser component makes the same translation and lends its tables to that same
10
+ * `Scope`, so one Orb keeps one behavior on every host:
11
+ *
12
+ * - While each environment is declared, the root binds the hooks this Orb runs and declares the
13
+ * resources its component lists, with callback numbers of its own; a service object declares
14
+ * the resources and the state its component describes for its service. The address of each
15
+ * environment is read then.
16
+ * - The kernel later opens and closes resources through those numbers and, before a reload
17
+ * adopts a retained state, asks the replacement component to validate it.
18
+ * - Imports issue `state.read`, `state.update`, `resource.read`, the context requests and
19
+ * `hook.run` under the authority of the callback that physically issued them; a refusal
20
+ * rejects the suspending import, which traps the guest.
21
+ *
22
+ * Mirrors the component worker of `crates/executor-wasm/src/component/worker.rs`.
23
+ */
24
+ import type { Declaration } from "../../authoring/declaration.ts";
25
+ import type { Gate } from "../gate.ts";
26
+ import { Scope } from "../scope.ts";
27
+ import type { ContractPort, ExecutionScope, HookBinding } from "../types.ts";
28
+ import { type Signature } from "../wit-shape.ts";
29
+ import type { ComponentPort } from "./port.ts";
30
+ import type { Described } from "./revision.ts";
31
+ import type { ComponentScope } from "./scope.ts";
32
+ /** Kernel interface identities; `crates/contracts/src/guest.rs` names the same. */
33
+ export declare const STATE = "tembra:guest/state@1.0.0";
34
+ export declare const STATE_INIT = "tembra:guest/state-init@1.0.0";
35
+ export declare const RESOURCES = "tembra:guest/resources@1.0.0";
36
+ export declare const RESOURCES_INIT = "tembra:guest/resources-init@1.0.0";
37
+ export declare const SERVICE_RESOURCES_INIT = "tembra:guest/service-resources-init@1.0.0";
38
+ export declare const CONTEXT = "tembra:guest/context@1.0.0";
39
+ /** Whether an interface identity belongs to the namespace reserved for the kernel. */
40
+ export declare function isKernel(contract: string | null | undefined): boolean;
41
+ /** The kernel handles of one environment, issued from its own `Scope` table. */
42
+ export interface KernelTable {
43
+ /** Serves the environment's requests exactly as for a source Orb. */
44
+ readonly scope: Scope;
45
+ /** The Orb root's table, which owns the resources and hooks; the root's own for the root. */
46
+ readonly root: KernelTable;
47
+ /** The state handle of a service object that declared state. */
48
+ state?: number;
49
+ /** The resources this environment declared by name: the root's, or a service object's own. */
50
+ readonly resources: Map<string, number>;
51
+ /** The root's hook handles by the import binding that runs each hook. */
52
+ readonly hooks: Map<string, number>;
53
+ /** Where the environment's object lives, read while it was declared. */
54
+ address?: unknown;
55
+ /** Whether the component imports the context interface: an admitted call reads its principal. */
56
+ readonly context: boolean;
57
+ }
58
+ /** One callback's access to its environment's table, under the callback's own authority. */
59
+ export interface KernelAccess {
60
+ readonly table: KernelTable;
61
+ readonly execution: ExecutionScope;
62
+ /**
63
+ * The principal of an admitted call, read when the call was admitted, for a component importing
64
+ * the context interface: the kernel refuses to read it once the call is cancelled, and it never
65
+ * changes. A resource's opener and closer run as "host".
66
+ */
67
+ readonly principal?: string | undefined;
68
+ }
69
+ /** What the kernel reads of its component revision. */
70
+ export interface KernelOwner {
71
+ readonly port: ComponentPort;
72
+ readonly contract: ContractPort;
73
+ readonly gate: Gate;
74
+ readonly graph: Described;
75
+ readonly signatures: Map<number, Signature>;
76
+ readonly scopes: ReadonlyMap<number, ComponentScope>;
77
+ }
78
+ /** Where a compiled Orb's diagnostic records go, as for a source Orb's console. */
79
+ export type LogObserver = (record: {
80
+ orb: string;
81
+ level: string;
82
+ message: string;
83
+ }) => void;
84
+ /**
85
+ * The value an opener of the resource `name` answered in its `result<u32, string>`: its `err`
86
+ * fails this open with the message, `unavailable/resource` as a native opener's, so the kernel
87
+ * closes what already opened; an answer that is no such result fails this open the same way,
88
+ * naming the resource, and never the component. Mirrors `opened` in the native worker.
89
+ */
90
+ export declare function opened(name: string, answer: unknown): unknown;
91
+ /** The kernel's interfaces for one prepared component revision. */
92
+ export declare class ComponentKernel {
93
+ #private;
94
+ readonly owner: KernelOwner;
95
+ readonly orb: string;
96
+ readonly log: LogObserver | undefined;
97
+ constructor(owner: KernelOwner, orb: string, log: LogObserver | undefined);
98
+ /**
99
+ * Adopt the hooks the checked implementation found this Orb declaring, with their callback
100
+ * signatures, and the import that runs each one (a hook without one is never run by its Orb).
101
+ */
102
+ declareHooks(hooks: readonly HookBinding[], signature: (hook: HookBinding) => Signature): void;
103
+ /**
104
+ * Declare one environment's kernel handles while its factory runs, as the native component
105
+ * worker does: the root reads its address, binds the hooks this Orb runs and declares the
106
+ * resources its component lists; a service object reads its address and declares the resources
107
+ * and the state its component describes for the service interface `contract`.
108
+ */
109
+ declare(environment: ComponentScope, declaration: Declaration, service: string | null, contract: string | undefined): Promise<void>;
110
+ /** Ask the component whether it accepts the retained state a reload would hand to it. */
111
+ validate(environment: ComponentScope, value: unknown): Promise<void>;
112
+ /** Forget an environment's table and the numbers it issued once the kernel released it. */
113
+ release(environment: number): void;
114
+ /**
115
+ * The import object of a kernel interface, or of the import that runs a hook this Orb
116
+ * declares; built before instantiation, it resolves the hook when the guest calls it. Each
117
+ * function serves the callback owning the guest's current root task.
118
+ */
119
+ imports(binding: string): Record<string, unknown>;
120
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The generated bindings' spelling of one WIT identifier: kebab-case words, each entirely lower
3
+ * or upper case, joined in lower (functions, methods) or upper (resource classes) camel case.
4
+ */
5
+ export declare function bindingName(name: string, upper: boolean): string;