@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
@@ -0,0 +1,33 @@
1
+ import { type HttpProvider } from "../http-provider.ts";
2
+ import { type IncomingHttpRequest, type IngressExchange } from "../http-ingress.ts";
3
+ import { type WasiHost, type WasiInterfaces } from "./wasi-host.ts";
4
+ /** Grant-checked selection of the host transport. */
5
+ export interface HttpClient {
6
+ /** The provider granted for exactly this URL's origin, or `undefined` to deny. */
7
+ provider(url: URL): HttpProvider | undefined;
8
+ }
9
+ /**
10
+ * The per-instance incoming bridge for `wasi:http/handler` (private; wired by the revision). It
11
+ * issues this instance's own `request` resource for an incoming request and delivers the
12
+ * `response` the handler returned. Everything stays within the standard resources, streams and
13
+ * futures; the application side is the existing `IngressExchange` carrier.
14
+ */
15
+ export interface IngressBridge {
16
+ /**
17
+ * This instance's `request` for `incoming` (from `exchange.own()`); the guest owns it. Invalid
18
+ * input throws a `TypeError` after closing the request body it already owns.
19
+ */
20
+ request(incoming: IncomingHttpRequest): unknown;
21
+ /**
22
+ * Publish the handler's `response` (this instance's class; anything else is refused) through
23
+ * `exchange.respond` and deliver its body and trailers as the application reads them. Settles
24
+ * when the delivery ended: resolves at the end of the body and trailers or when the application
25
+ * stopped reading (its client disconnected); rejects on a body or trailers failure and when the
26
+ * revision retired first.
27
+ */
28
+ respond(response: unknown, exchange: IngressExchange): Promise<void>;
29
+ }
30
+ /** The `wasi:http/types` and `client` import objects of one instance. */
31
+ export declare function httpImports(host: WasiHost, client: HttpClient | undefined): WasiInterfaces<"types" | "client"> & {
32
+ ingress: IngressBridge;
33
+ };
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Standard `wasi:sockets` (TCP, UDP) and `wasi:sockets/ip-name-lookup` for the browser
3
+ * standard host, over an injected `SocketProvider` (`socket-provider.ts`). Browsers have no
4
+ * ambient sockets.
5
+ *
6
+ * Every call follows one order, so a refusal never reaches the provider:
7
+ * 1. argument and state checks, as pinned upstream `wasmtime-wasi` 51.0.0-rc.1;
8
+ * 2. the exact grant of the provider bound to that WIT import (`access-denied`);
9
+ * 3. provider capability (`not-supported`; name lookup `permanent-resolver-failure`);
10
+ * 4. the provider call.
11
+ *
12
+ * Ownership follows WASI's shared model: a socket handle and each stream derived from it hold
13
+ * one reference to the provider backend. Dropping the handle leaves its streams working; a
14
+ * dropped receive stream shuts down reads; the last reference closes the backend. Accepted
15
+ * sockets are independent. Every closing promise is physical work tracked by the host.
16
+ */
17
+ import type { ErrorCode, IpAddressFamily, IpSocketAddress } from "../../wasi/wasi-sockets-types.js";
18
+ import type { SocketAccess } from "../browser-network.ts";
19
+ import { type TcpBackend, type TcpConnection, type UdpBackend } from "../socket-provider.ts";
20
+ import { type WasiHost, type WasiInterfaces } from "./wasi-host.ts";
21
+ /** The host and cancellation of the callback serving one socket operation. */
22
+ interface StandardCall {
23
+ readonly host: WasiHost;
24
+ readonly signal: AbortSignal | undefined;
25
+ }
26
+ type Result<T, E> = {
27
+ tag: "ok";
28
+ val: T;
29
+ } | {
30
+ tag: "err";
31
+ val: E;
32
+ };
33
+ /** The providers bound to this revision's socket and lookup imports. */
34
+ export interface SocketBindings {
35
+ readonly types?: SocketAccess | undefined;
36
+ readonly lookup?: SocketAccess | undefined;
37
+ }
38
+ /**
39
+ * One provider backend shared by a socket handle and its streams; the last user closes it. A
40
+ * backend the guest still holds when the revision retires (quarantine or disposal) is closed
41
+ * then. Closing always waits for the backend's pending operations (a connect) to settle first,
42
+ * so a late result is handled before the backend goes away.
43
+ */
44
+ declare class Shared<B extends {
45
+ close(): Promise<void>;
46
+ }> {
47
+ #private;
48
+ readonly host: WasiHost;
49
+ readonly backend: B;
50
+ constructor(host: WasiHost, backend: B);
51
+ /** Keep the backend open until `operation` settled. */
52
+ busy(operation: Promise<unknown>): void;
53
+ retain(): void;
54
+ release(): void;
55
+ }
56
+ /** Handle-table reference counting, as for every standard resource. */
57
+ declare abstract class SocketResource {
58
+ #private;
59
+ retain(): void;
60
+ release(): void;
61
+ protected abstract close(): void;
62
+ /** The guest dropped its handle. */
63
+ [Symbol.dispose](): void;
64
+ }
65
+ /** `wasi:sockets/types#tcp-socket`. */
66
+ export declare class TcpSocket extends SocketResource {
67
+ #private;
68
+ readonly access: SocketAccess;
69
+ readonly family: IpAddressFamily;
70
+ readonly shared: Shared<TcpBackend>;
71
+ constructor(access: SocketAccess, family: IpAddressFamily, shared: Shared<TcpBackend>, connection?: TcpConnection);
72
+ protected close(): void;
73
+ bind(local: IpSocketAddress): Result<void, ErrorCode>;
74
+ connect(remote: IpSocketAddress, call?: StandardCall): Promise<Result<void, ErrorCode>>;
75
+ listen(call?: StandardCall): Result<AsyncIterableIterator<unknown>, ErrorCode>;
76
+ send(stream: unknown, call?: StandardCall): Promise<Result<void, ErrorCode>>;
77
+ receive(call?: StandardCall): [AsyncIterableIterator<Uint8Array>, Promise<Result<void, ErrorCode>>];
78
+ getLocalAddress(): Result<IpSocketAddress, ErrorCode>;
79
+ getRemoteAddress(): Result<IpSocketAddress, ErrorCode>;
80
+ getIsListening(): boolean;
81
+ getAddressFamily(): IpAddressFamily;
82
+ setListenBacklogSize(value: bigint): Result<void, ErrorCode>;
83
+ getKeepAliveEnabled(): Result<boolean, ErrorCode>;
84
+ setKeepAliveEnabled(value: boolean): {
85
+ tag: "err";
86
+ val: ErrorCode;
87
+ } | {
88
+ tag: "ok";
89
+ val: void;
90
+ };
91
+ getKeepAliveIdleTime(): Result<bigint, ErrorCode>;
92
+ setKeepAliveIdleTime(value: bigint): {
93
+ tag: "err";
94
+ val: ErrorCode;
95
+ } | {
96
+ tag: "ok";
97
+ val: void;
98
+ };
99
+ getKeepAliveInterval(): Result<bigint, ErrorCode>;
100
+ setKeepAliveInterval(value: bigint): {
101
+ tag: "err";
102
+ val: ErrorCode;
103
+ } | {
104
+ tag: "ok";
105
+ val: void;
106
+ };
107
+ getKeepAliveCount(): Result<number, ErrorCode>;
108
+ setKeepAliveCount(value: number): {
109
+ tag: "err";
110
+ val: ErrorCode;
111
+ } | {
112
+ tag: "ok";
113
+ val: void;
114
+ };
115
+ getHopLimit(): Result<number, ErrorCode>;
116
+ setHopLimit(value: number): {
117
+ tag: "err";
118
+ val: ErrorCode;
119
+ } | {
120
+ tag: "ok";
121
+ val: void;
122
+ };
123
+ getReceiveBufferSize(): Result<bigint, ErrorCode>;
124
+ setReceiveBufferSize(value: bigint): {
125
+ tag: "err";
126
+ val: ErrorCode;
127
+ } | {
128
+ tag: "ok";
129
+ val: void;
130
+ };
131
+ getSendBufferSize(): Result<bigint, ErrorCode>;
132
+ setSendBufferSize(value: bigint): {
133
+ tag: "err";
134
+ val: ErrorCode;
135
+ } | {
136
+ tag: "ok";
137
+ val: void;
138
+ };
139
+ }
140
+ /** `wasi:sockets/types#udp-socket`. Peer association and receive filtering are host state. */
141
+ export declare class UdpSocket extends SocketResource {
142
+ #private;
143
+ readonly access: SocketAccess;
144
+ readonly family: IpAddressFamily;
145
+ readonly shared: Shared<UdpBackend>;
146
+ constructor(access: SocketAccess, family: IpAddressFamily, shared: Shared<UdpBackend>);
147
+ protected close(): void;
148
+ bind(local: IpSocketAddress): Result<void, ErrorCode>;
149
+ connect(remote: IpSocketAddress): Result<void, ErrorCode>;
150
+ disconnect(): Result<void, ErrorCode>;
151
+ send(data: Uint8Array, remote: IpSocketAddress | undefined, call?: StandardCall): Promise<Result<void, ErrorCode>>;
152
+ receive(call?: StandardCall): Promise<Result<[Uint8Array, IpSocketAddress], ErrorCode>>;
153
+ getLocalAddress(): Result<IpSocketAddress, ErrorCode>;
154
+ getRemoteAddress(): Result<IpSocketAddress, ErrorCode>;
155
+ getAddressFamily(): IpAddressFamily;
156
+ getUnicastHopLimit(): Result<number, ErrorCode>;
157
+ setUnicastHopLimit(value: number): {
158
+ tag: "err";
159
+ val: ErrorCode;
160
+ } | {
161
+ tag: "ok";
162
+ val: void;
163
+ };
164
+ getReceiveBufferSize(): Result<bigint, ErrorCode>;
165
+ setReceiveBufferSize(value: bigint): {
166
+ tag: "err";
167
+ val: ErrorCode;
168
+ } | {
169
+ tag: "ok";
170
+ val: void;
171
+ };
172
+ getSendBufferSize(): Result<bigint, ErrorCode>;
173
+ setSendBufferSize(value: bigint): {
174
+ tag: "err";
175
+ val: ErrorCode;
176
+ } | {
177
+ tag: "ok";
178
+ val: void;
179
+ };
180
+ }
181
+ /** The `wasi:sockets` import objects of one instance; resource classes are per instance. */
182
+ export declare function socketImports(host: WasiHost, bindings: SocketBindings): WasiInterfaces<"types" | "ip-name-lookup">;
183
+ export {};
@@ -0,0 +1,41 @@
1
+ /**
2
+ * WASI 0.3 for trusted prepared component bindings.
3
+ *
4
+ * `publicWasi` serves the WASI 0.3 interfaces a compiled component imports from the
5
+ * installation's granted providers, with JCO's component-model async conventions (the same
6
+ * conventions as `@bytecodealliance/preview3-shim`, whose global singletons cannot carry
7
+ * per-installation grants). Every instance receives fresh import objects and resources.
8
+ */
9
+ import type { CliOptions } from "../../authoring/types.ts";
10
+ import type { StdioStreams } from "../standard-cli.ts";
11
+ import type { ClockProvider, RandomProvider } from "../standard-system.ts";
12
+ import { type StandardMount } from "./wasi-filesystem.ts";
13
+ import { type WasiHost } from "./wasi-host.ts";
14
+ import { type HttpClient } from "./wasi-http.ts";
15
+ import { type SocketBindings } from "./wasi-sockets.ts";
16
+ /** Granted providers of one installation for the public WASI 0.3 surface. */
17
+ export interface PublicProviders {
18
+ readonly clocks?: ClockProvider | undefined;
19
+ readonly random?: RandomProvider | undefined;
20
+ /** Present only with the `cli` grant. */
21
+ readonly cli?: {
22
+ readonly options: Readonly<CliOptions>;
23
+ readonly stdio: StdioStreams;
24
+ };
25
+ /** Granted filesystem mounts, in grant order. */
26
+ readonly mounts: () => readonly StandardMount[];
27
+ /** Physical accounting and retirement of this instance. */
28
+ readonly host: WasiHost;
29
+ /** Receives the instance's incoming-HTTP bridge, when the HTTP adapter provides one. */
30
+ readonly ingress?: (bridge: unknown) => void;
31
+ /** Exact-origin HTTP grants; `undefined` denies every request. */
32
+ readonly http: HttpClient | undefined;
33
+ /** The socket provider and grants selected by each sockets import binding. */
34
+ readonly sockets: SocketBindings;
35
+ }
36
+ /** Interfaces with a browser implementation; anything else imported is refused. */
37
+ export declare const BROWSER_WASI: ReadonlySet<string>;
38
+ /** Refuse, before instantiation, a public WASI import this backend cannot serve yet. */
39
+ export declare function checkPublicWasi(names: readonly string[]): void;
40
+ /** The granted public WASI 0.3 imports of one installation, keyed by exact import name. */
41
+ export declare function publicWasi(names: readonly string[], providers: PublicProviders): Record<string, unknown>;
@@ -0,0 +1,64 @@
1
+ /** Host-only termination that must trap the instance instead of becoming a catchable reply. */
2
+ export declare class GuestTrap extends Error {
3
+ }
4
+ export interface Outcome {
5
+ ok: boolean;
6
+ value: string;
7
+ interrupted: boolean;
8
+ }
9
+ /** A JSON host request, or a binary standard WASI packet (first byte `STANDARD_PACKET`). */
10
+ export interface Effect {
11
+ id: number;
12
+ packet: string | Uint8Array;
13
+ }
14
+ /** Successful standard results are bytes; JSON results and every error are text. */
15
+ export interface Completion {
16
+ id: number;
17
+ ok: boolean;
18
+ value: string | Uint8Array;
19
+ }
20
+ export interface Progress {
21
+ outcome?: Outcome;
22
+ effects: Effect[];
23
+ }
24
+ /** Logical interpreter operations driven by the browser port. */
25
+ export interface Guest {
26
+ load(packet: string): Outcome;
27
+ declare(packet: string): Outcome;
28
+ start(packet: string): Progress;
29
+ resume(completed: Completion[]): Progress;
30
+ cancel(): Outcome;
31
+ }
32
+ /**
33
+ * Host services supplied to one instance; `sync` throws to report an error message.
34
+ * Binary standard packets arrive and reply as bytes; JSON packets stay text.
35
+ */
36
+ export interface GuestHost {
37
+ sync(packet: string | Uint8Array): string | Uint8Array;
38
+ log(level: "log" | "error", message: string): void;
39
+ /** Granted per-revision clock; absence exposes a fixed zero to interpreter libc. */
40
+ clock?(clock: number): bigint;
41
+ }
42
+ /** Refuse engines whose imports or exports differ from the private ABI before instantiation. */
43
+ export declare function checkInterpreter(module: WebAssembly.Module): void;
44
+ /** One isolated interpreter instance with a host-bounded linear memory. */
45
+ export declare class CoreGuest implements Guest {
46
+ #private;
47
+ readonly memory: WebAssembly.Memory;
48
+ readonly host: GuestHost;
49
+ private constructor();
50
+ /** Instantiate a checked module with a fresh memory whose maximum is the configured bound. */
51
+ static create(module: WebAssembly.Module, memoryBytes: number, host: GuestHost): Promise<CoreGuest>;
52
+ /** A trapped instance is never entered again. */
53
+ get trapped(): boolean;
54
+ load(packet: string): Outcome;
55
+ declare(packet: string): Outcome;
56
+ start(packet: string): Progress;
57
+ /** Encode settled effects in one batch; identities stay JavaScript-safe integers. */
58
+ resume(completed: Completion[]): Progress;
59
+ cancel(): Outcome;
60
+ /** Capture idle heap bytes; durable continuation restore is a separate host protocol. */
61
+ capture(): Uint8Array;
62
+ }
63
+ /** Restricted WASI preview 1 functions mirroring `crates/executor-wasm/src/worker/wasi.rs`. */
64
+ export declare function wasi(memory: WebAssembly.Memory, host: GuestHost): Record<string, Function>;
@@ -0,0 +1,17 @@
1
+ /** WHATWG Fetch implementation of the host HTTP contract, with explicit platform limits. */
2
+ import { type HttpProvider } from "./http-provider.ts";
3
+ /** The largest request body `fetchHttpProvider` buffers before calling Fetch. */
4
+ export declare const FETCH_BODY_BYTES: number;
5
+ /**
6
+ * Adapt Fetch (by default the global one) to `HttpProvider`. Fetch owns DNS, TLS and
7
+ * connections. Its platform limits are explicit errors, never emulation:
8
+ * - the upload is buffered (at most `FETCH_BODY_BYTES`) and sent after its trailers settled,
9
+ * so there is no duplex; non-empty request trailers are refused;
10
+ * - responses have no trailers, and Fetch combines duplicate response fields;
11
+ * - there is no separate connect phase: a `connect` timeout is refused;
12
+ * - `redirect: "manual"` never follows a redirect, and the opaque result is refused;
13
+ * - `CONNECT`/`TRACE`/`TRACK`, and a body with `GET` or `HEAD`, are refused;
14
+ * - credentials are omitted, and browsers silently drop their forbidden request fields;
15
+ * - Fetch sends `request.url`, whose path is WHATWG-normalized, not the raw `pathWithQuery`.
16
+ */
17
+ export declare function fetchHttpProvider(fetch?: (input: URL, init: RequestInit) => Promise<Response>): HttpProvider;
@@ -0,0 +1,85 @@
1
+ /** Every standard `wasi:filesystem` `error-code` case except `other`; other failures surface as `io`. */
2
+ export type FilesystemErrorCode = "access" | "already" | "bad-descriptor" | "busy" | "deadlock" | "quota" | "exist" | "file-too-large" | "illegal-byte-sequence" | "in-progress" | "interrupted" | "invalid" | "io" | "is-directory" | "loop" | "too-many-links" | "message-size" | "name-too-long" | "no-device" | "no-entry" | "no-lock" | "insufficient-memory" | "insufficient-space" | "not-directory" | "not-empty" | "not-recoverable" | "unsupported" | "no-tty" | "no-such-device" | "overflow" | "not-permitted" | "pipe" | "read-only" | "invalid-seek" | "text-file-busy" | "cross-device";
3
+ /** A provider failure carrying the WASI `error-code` that standard filesystem calls return. */
4
+ export declare class FilesystemError extends Error {
5
+ readonly code: FilesystemErrorCode;
6
+ constructor(code: FilesystemErrorCode, message?: string);
7
+ }
8
+ export type EntryType = "file" | "directory";
9
+ /** Metadata of one entry; `modified` is milliseconds since the Unix epoch when known. */
10
+ export interface FileStat {
11
+ readonly type: EntryType;
12
+ readonly size: bigint;
13
+ readonly modified?: number;
14
+ }
15
+ export interface DirectoryEntry {
16
+ readonly name: string;
17
+ readonly type: EntryType;
18
+ }
19
+ /** `open-at` flags plus the requested write right (`write` or `mutate-directory`). */
20
+ export interface OpenOptions {
21
+ readonly create?: boolean;
22
+ readonly exclusive?: boolean;
23
+ readonly truncate?: boolean;
24
+ readonly directory?: boolean;
25
+ readonly write?: boolean;
26
+ }
27
+ interface DescriptorBase {
28
+ readonly type: EntryType;
29
+ /** Write (file) or mutate-directory (directory) right of this descriptor. */
30
+ readonly writable: boolean;
31
+ stat(): Promise<FileStat>;
32
+ isSameObject(other: Descriptor): Promise<boolean>;
33
+ sync(): Promise<void>;
34
+ /** Idempotent; later calls fail with `bad-descriptor` while in-flight calls settle normally. */
35
+ close(): void;
36
+ }
37
+ /** An opened regular file; it follows its entry across rename where the platform allows. */
38
+ export interface FileDescriptor extends DescriptorBase {
39
+ readonly type: "file";
40
+ /** Read at most `length` bytes at `offset`; an empty result is end of file. */
41
+ read(offset: bigint, length: number): Promise<Uint8Array>;
42
+ /** Write every byte at `offset`, zero-filling any gap; `data` must stay unchanged until settled. */
43
+ write(offset: bigint, data: Uint8Array): Promise<void>;
44
+ /** Write every byte at the current end of file. */
45
+ append(data: Uint8Array): Promise<void>;
46
+ /** Truncate or zero-extend. */
47
+ setSize(size: bigint): Promise<void>;
48
+ /**
49
+ * Optional; built-in providers implement it. Write sequential chunks from `offset`, or from the
50
+ * end of file when it is absent (`append-via-stream`). The next chunk is requested only after
51
+ * the previous one is written; early exits call the iterator's `return()`. Accepted chunks are
52
+ * kept when the producer fails or the descriptor closes. OPFS commits once when the iterable
53
+ * ends, and readers observe the previous committed content until then.
54
+ */
55
+ writeStream?(chunks: AsyncIterable<Uint8Array>, offset?: bigint): Promise<void>;
56
+ }
57
+ /** An opened directory; relative paths resolve from it and never above it. */
58
+ export interface DirectoryDescriptor extends DescriptorBase {
59
+ readonly type: "directory";
60
+ openAt(path: string, options?: OpenOptions): Promise<Descriptor>;
61
+ statAt(path: string): Promise<FileStat>;
62
+ /** Lazy entries in platform order, without `.` and `..`. */
63
+ readDirectory(): AsyncIterableIterator<DirectoryEntry>;
64
+ createDirectoryAt(path: string): Promise<void>;
65
+ removeDirectoryAt(path: string): Promise<void>;
66
+ unlinkFileAt(path: string): Promise<void>;
67
+ /** POSIX `renameat`; `newDirectory` must be an open descriptor of the same storage. */
68
+ renameAt(oldPath: string, newDirectory: DirectoryDescriptor, newPath: string): Promise<void>;
69
+ }
70
+ export type Descriptor = FileDescriptor | DirectoryDescriptor;
71
+ /** One grant's permission and lifetime scope over the provider's shared storage. */
72
+ export interface MountedFilesystem {
73
+ readonly writable: boolean;
74
+ /** A new owned descriptor for the mount root. */
75
+ openRoot(): DirectoryDescriptor;
76
+ /** Close every descriptor of this scope now; settles after its in-flight calls settle. */
77
+ dispose(): Promise<void>;
78
+ }
79
+ export interface FilesystemProvider {
80
+ /** Open independent permission and lifetime scopes over explicitly shared storage. */
81
+ open(mount: string, writable: boolean): MountedFilesystem;
82
+ }
83
+ /** Throw the standard error for `code`; shared by the private provider modules. */
84
+ export declare function fail(code: FilesystemErrorCode, message?: string): never;
85
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type FilesystemProvider } from "./contract.ts";
2
+ /** Supply shared ephemeral storage without granting any Orb access automatically. */
3
+ export declare function memoryFilesystem(files?: Readonly<Record<string, string | Uint8Array>>): FilesystemProvider;
@@ -0,0 +1,3 @@
1
+ import { type FilesystemProvider } from "./contract.ts";
2
+ /** Resolve every operation from the directory handle supplied by the embedding host. */
3
+ export declare function opfsFilesystem(directory: FileSystemDirectoryHandle): Promise<FilesystemProvider>;
@@ -0,0 +1,35 @@
1
+ import { type DirectoryEntry, type EntryType, type FileStat, type FilesystemProvider } from "./contract.ts";
2
+ /**
3
+ * Node-level primitives of one storage. Names are single, already confined components; the
4
+ * scope layer owns rights, lifetime, path resolution and argument validation.
5
+ */
6
+ export interface Store<N> {
7
+ readonly root: N;
8
+ /** Largest file size in bytes. */
9
+ readonly limit: number;
10
+ type(node: N): EntryType;
11
+ /** An existing child, trying `expected` first where lookups are type-specific. */
12
+ lookup(parent: N, name: string, expected?: EntryType): Promise<N>;
13
+ /** Create a new child; `exist` when any entry already has the name. */
14
+ create(parent: N, name: string, type: EntryType): Promise<N>;
15
+ /** Canonical node retained by a descriptor until `release`. */
16
+ retain(node: N): Promise<N>;
17
+ release(node: N): void;
18
+ stat(node: N): Promise<FileStat>;
19
+ same(a: N, b: N): Promise<boolean>;
20
+ entries(directory: N): AsyncIterator<DirectoryEntry>;
21
+ read(file: N, offset: number, length: number): Promise<Uint8Array>;
22
+ /** Write at `offset`, or append when it is undefined. */
23
+ write(file: N, offset: number | undefined, data: Uint8Array): Promise<void>;
24
+ resize(file: N, size: number): Promise<void>;
25
+ /**
26
+ * Optional one-writer stream at `offset` (append when undefined). The chunks are validated,
27
+ * non-empty and re-check the descriptor; without it, chunks go through `write` one by one.
28
+ */
29
+ writeStream?(file: N, offset: number | undefined, chunks: AsyncIterable<Uint8Array>): Promise<void>;
30
+ sync(node: N): Promise<void>;
31
+ remove(parent: N, name: string, type: EntryType): Promise<void>;
32
+ rename(from: N, fromName: string, to: N, toName: string): Promise<void>;
33
+ }
34
+ /** Expose one storage as a provider whose every `open` is an independent scope. */
35
+ export declare function provider<N>(store: Store<N>): FilesystemProvider;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Public browser filesystem provider API. The implementation lives in private modules:
3
+ * `filesystem/contract.ts` (types and errors), `filesystem/scope.ts` (rights, lifetime and path
4
+ * confinement), `filesystem/memory.ts` and `filesystem/opfs.ts` (storage backends).
5
+ */
6
+ export { type Descriptor, type DirectoryDescriptor, type DirectoryEntry, type EntryType, type FileDescriptor, type FileStat, FilesystemError, type FilesystemErrorCode, type FilesystemProvider, type MountedFilesystem, type OpenOptions, } from "./filesystem/contract.ts";
7
+ export { memoryFilesystem } from "./filesystem/memory.ts";
8
+ export { opfsFilesystem } from "./filesystem/opfs.ts";
@@ -0,0 +1,6 @@
1
+ /** Serialize one VM while allowing independent VMs and host callbacks to make progress. */
2
+ export declare class Gate {
3
+ #private;
4
+ /** Ordinary contention waits for ownership; only factories need a bounded causal admission wait. */
5
+ enter(milliseconds?: number, signal?: AbortSignal): Promise<() => void>;
6
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Private host-operation protocol between the interpreter guest and the SDK host.
3
+ * Mirrors `crates/executor-wasm/src/protocol.rs`: unknown operation names are unsupported,
4
+ * while a known operation with missing, mistyped or extra fields is malformed.
5
+ * Payloads (`initial`, `value`, `args`) stay JSON because the WIT contract validates them.
6
+ * Snapshot reads may name the revision the guest already retains (`known`); the host then
7
+ * answers with the current identity and omits a value that has not changed.
8
+ */
9
+ /** Handle issued by one environment table; `scope` selects the table, never an authority. */
10
+ export interface Handle {
11
+ readonly scope?: number;
12
+ readonly id: number;
13
+ }
14
+ /** A snapshot read optionally names the kernel revision whose value the guest already holds. */
15
+ export interface SnapshotRead extends Handle {
16
+ readonly known?: string;
17
+ }
18
+ export type LogLevel = "log" | "debug" | "info" | "warn" | "error";
19
+ /** Synchronous host operations. */
20
+ export type HostRequest = {
21
+ readonly operation: "console";
22
+ readonly level: LogLevel;
23
+ readonly message: string;
24
+ } | {
25
+ readonly operation: "address";
26
+ } | {
27
+ readonly operation: "orb";
28
+ } | {
29
+ readonly operation: "signal.cancelled";
30
+ } | {
31
+ readonly operation: "context.check";
32
+ } | {
33
+ readonly operation: "context.principal";
34
+ } | {
35
+ readonly operation: "context.cancel";
36
+ } | {
37
+ readonly operation: "state.declare";
38
+ readonly initial: unknown;
39
+ readonly version: number;
40
+ readonly validate: number | null;
41
+ } | ({
42
+ readonly operation: "state.read";
43
+ } & SnapshotRead) | ({
44
+ readonly operation: "state.update";
45
+ readonly value: unknown;
46
+ } & Handle) | {
47
+ readonly operation: "reference.declare";
48
+ readonly service: string;
49
+ readonly key: readonly string[];
50
+ } | ({
51
+ readonly operation: "reference.release";
52
+ } & Handle) | ({
53
+ readonly operation: "reference.status";
54
+ } & Handle) | ({
55
+ readonly operation: "reference.state";
56
+ } & SnapshotRead) | {
57
+ readonly operation: "resource.declare";
58
+ readonly name: string;
59
+ readonly version: number;
60
+ readonly open: number;
61
+ readonly close: number;
62
+ readonly dependencies: readonly Handle[];
63
+ } | ({
64
+ readonly operation: "resource.read";
65
+ } & Handle) | {
66
+ readonly operation: "hook.declare";
67
+ readonly name: string;
68
+ };
69
+ /** Asynchronous host operations, awaited outside the guest heap. */
70
+ export type AsyncHostRequest = ({
71
+ readonly operation: "hook.run";
72
+ readonly value: unknown;
73
+ } & Handle) | ({
74
+ readonly operation: "reference.ready";
75
+ } & Handle)
76
+ /**
77
+ * `Context.get`: the guest names only a selected import binding and key; the host supplies the
78
+ * invocation, principal and requirement. Source handles use their environment's table;
79
+ * checked compiled reference views use their Orb table, shared by the Store's environments.
80
+ */
81
+ | {
82
+ readonly operation: "reference.acquire";
83
+ readonly service: string;
84
+ readonly key: readonly string[];
85
+ } | ({
86
+ readonly operation: "reference.call";
87
+ readonly method: string;
88
+ readonly args: unknown;
89
+ } & Handle) | {
90
+ readonly operation: "wait";
91
+ readonly milliseconds: number;
92
+ };
93
+ /** Longest cooperative timer a callback may request. */
94
+ export declare const WAIT_LIMIT_MILLISECONDS = 5000;
95
+ /** Decode one synchronous packet into a typed request. */
96
+ export declare function decodeHostRequest(packet: string): HostRequest;
97
+ /** Decode one asynchronous packet into a typed request. */
98
+ export declare function decodeAsyncHostRequest(packet: string): AsyncHostRequest;
99
+ /** Diagnostics and reads of already issued values stay usable after cancellation. */
100
+ export declare function survivesCancellation(request: HostRequest): boolean;
@@ -0,0 +1,7 @@
1
+ import type { HttpHandlerResponse, IncomingHttpRequest } from "./http-ingress.ts";
2
+ /** Whether `value` is a WHATWG `Request` of this realm. */
3
+ export declare function isFetchRequest(value: unknown): value is Request;
4
+ /** The raw request a WHATWG `Request` describes. */
5
+ export declare function fromFetchRequest(request: Request): IncomingHttpRequest;
6
+ /** The WHATWG `Response` for a handler response, or a refusal. */
7
+ export declare function toFetchResponse(response: HttpHandlerResponse): Response;