@syntropika/tembra-sdk 0.2.1 → 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.
- package/README.md +43 -17
- package/dist/authoring/types.d.ts +64 -3
- package/dist/authoring/wit.d.ts +6 -0
- package/dist/bridge/commands.d.ts +1190 -0
- package/dist/bridge/identifiers.d.ts +2 -0
- package/dist/bridge/kernel.d.ts +18 -107
- package/dist/bridge/protocol.d.ts +3 -138
- package/dist/browser.d.ts +14 -1
- package/dist/browser.js +141 -3298
- package/dist/chunks/browser-b8jamxw2.js +3399 -0
- package/dist/chunks/execution-nsqc6nrt.js +1419 -0
- package/dist/chunks/index-01zk0xqx.js +160 -0
- package/dist/chunks/index-3fjdfdfd.js +152 -0
- package/dist/chunks/index-aaymjn7v.js +787 -0
- package/dist/chunks/index-c1w7z9hx.js +356 -0
- package/dist/chunks/index-h8t0n42q.js +738 -0
- package/dist/chunks/index-hfds9mzp.js +308 -0
- package/dist/chunks/index-kr4x67wt.js +177 -0
- package/dist/chunks/index-kr6bnh34.js +117 -0
- package/dist/chunks/index-kyt9dj0a.js +1421 -0
- package/dist/chunks/index-n1wxzc9w.js +830 -0
- package/dist/chunks/index-pvac426d.js +74 -0
- package/dist/chunks/index-smyds5ce.js +3234 -0
- package/dist/chunks/index-sse8aapb.js +121 -0
- package/dist/chunks/index-v6heph77.js +643 -0
- package/dist/chunks/index-xrdvnv37.js +3448 -0
- package/dist/chunks/index-za4mg94e.js +26 -0
- package/dist/chunks/index-zkqmnjj8.js +167 -0
- package/dist/coordinator.js +9 -500
- package/dist/error.d.ts +2 -0
- package/dist/errors.d.ts +3 -0
- package/dist/guest.d.ts +173 -0
- package/dist/guest.js +26 -0
- package/dist/host.d.ts +36 -30
- package/dist/host.js +37 -3276
- package/dist/http/bytes.d.ts +8 -0
- package/dist/http/events.d.ts +7 -0
- package/dist/http.d.ts +45 -0
- package/dist/http.js +291 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49 -862
- package/dist/infrastructure/rpc/client.d.ts +2 -1
- package/dist/infrastructure/rpc/resources.d.ts +28 -0
- package/dist/interpreter/abi.d.ts +54 -0
- package/dist/interpreter/acquire.d.ts +18 -0
- package/dist/interpreter/browser-network.d.ts +52 -0
- package/dist/interpreter/browser-port.d.ts +55 -0
- package/dist/interpreter/browser.d.ts +79 -0
- package/dist/interpreter/cli.d.ts +5 -0
- package/dist/interpreter/codec.d.ts +42 -0
- package/dist/interpreter/component/execution.d.ts +42 -0
- package/dist/interpreter/component/host.d.ts +69 -0
- package/dist/interpreter/component/instance.d.ts +40 -0
- package/dist/interpreter/component/kernel.d.ts +120 -0
- package/dist/interpreter/component/names.d.ts +5 -0
- package/dist/interpreter/component/port.d.ts +85 -0
- package/dist/interpreter/component/prepared.d.ts +97 -0
- package/dist/interpreter/component/resources.d.ts +45 -0
- package/dist/interpreter/component/revision.d.ts +87 -0
- package/dist/interpreter/component/scope.d.ts +116 -0
- package/dist/interpreter/component/streams.d.ts +28 -0
- package/dist/interpreter/component/values.d.ts +79 -0
- package/dist/interpreter/component/wasi-filesystem.d.ts +21 -0
- package/dist/interpreter/component/wasi-host.d.ts +64 -0
- package/dist/interpreter/component/wasi-http.d.ts +33 -0
- package/dist/interpreter/component/wasi-sockets.d.ts +183 -0
- package/dist/interpreter/component/wasi.d.ts +41 -0
- package/dist/interpreter/core.d.ts +64 -0
- package/dist/interpreter/fetch-http-provider.d.ts +17 -0
- package/dist/interpreter/filesystem/contract.d.ts +85 -0
- package/dist/interpreter/filesystem/memory.d.ts +3 -0
- package/dist/interpreter/filesystem/opfs.d.ts +3 -0
- package/dist/interpreter/filesystem/scope.d.ts +35 -0
- package/dist/interpreter/filesystem.d.ts +8 -0
- package/dist/interpreter/gate.d.ts +6 -0
- package/dist/interpreter/host-protocol.d.ts +100 -0
- package/dist/interpreter/http-ingress-fetch.d.ts +7 -0
- package/dist/interpreter/http-ingress.d.ts +96 -0
- package/dist/interpreter/http-provider.d.ts +85 -0
- package/dist/interpreter/io.d.ts +20 -0
- package/dist/interpreter/mobile.d.ts +149 -0
- package/dist/interpreter/native-ingress.d.ts +95 -0
- package/dist/interpreter/node-port.d.ts +25 -0
- package/dist/interpreter/node.d.ts +36 -0
- package/dist/interpreter/revision.d.ts +64 -0
- package/dist/interpreter/scope.d.ts +89 -0
- package/dist/interpreter/socket-addresses.d.ts +50 -0
- package/dist/interpreter/socket-provider.d.ts +110 -0
- package/dist/interpreter/standard-cli.d.ts +34 -0
- package/dist/interpreter/standard-codec.d.ts +96 -0
- package/dist/interpreter/standard-filesystem.d.ts +47 -0
- package/dist/interpreter/standard-host.d.ts +71 -0
- package/dist/interpreter/standard-http-values.d.ts +159 -0
- package/dist/interpreter/standard-http.d.ts +9 -0
- package/dist/interpreter/standard-ingress.d.ts +63 -0
- package/dist/interpreter/standard-sockets.d.ts +177 -0
- package/dist/interpreter/standard-streams.d.ts +218 -0
- package/dist/interpreter/standard-system.d.ts +35 -0
- package/dist/interpreter/standard-utf8.d.ts +4 -0
- package/dist/interpreter/standard.d.ts +18 -0
- package/dist/interpreter/types.d.ts +152 -0
- package/dist/interpreter/wit-shape.d.ts +92 -0
- package/dist/manager.js +5 -332
- package/dist/msgpack.js +9 -615
- package/dist/node.d.ts +8 -1
- package/dist/node.js +248 -3287
- package/dist/rpc.js +196 -699
- package/dist/runtime/adapters.d.ts +120 -0
- package/dist/runtime/adapters.js +38 -0
- package/dist/runtime/calls.d.ts +9 -3
- package/dist/runtime/lifecycle.d.ts +3 -1
- package/dist/runtime/orbs.d.ts +5 -4
- package/dist/runtime/references.d.ts +27 -1
- package/dist/runtime/reload.d.ts +5 -3
- package/dist/runtime/scopes.d.ts +1 -1
- package/dist/runtime/signals.d.ts +4 -0
- package/dist/runtime/wit-client.d.ts +38 -0
- package/dist/telemetry.js +4 -25
- package/dist/tooling/build.d.ts +2 -2
- package/dist/tooling/client-resources.d.ts +23 -0
- package/dist/tooling/client.d.ts +10 -0
- package/dist/tooling/component-glue.d.ts +17 -0
- package/dist/tooling/component.d.ts +11 -0
- package/dist/tooling/index.d.ts +3 -1
- package/dist/tooling/index.js +1155 -102
- package/dist/tooling/resolver.d.ts +4 -4
- package/dist/tooling/typecheck.d.ts +2 -1
- package/dist/tooling/types.d.ts +27 -12
- package/dist/tooling/wit.d.ts +9 -0
- package/dist/wasi/wasi-clocks-types.d.ts +2 -0
- package/dist/wasi/wasi-http-client.d.ts +5 -0
- package/dist/wasi/wasi-http-types.d.ts +285 -0
- package/dist/wasi/wasi-sockets-ip-name-lookup.d.ts +23 -0
- package/dist/wasi/wasi-sockets-types.d.ts +146 -0
- package/package.json +62 -35
- package/src/authoring/declaration.ts +1 -1
- package/src/authoring/types.ts +53 -3
- package/src/authoring/wit.ts +15 -0
- package/src/bridge/commands.ts +1105 -0
- package/src/bridge/identifiers.ts +2 -0
- package/src/bridge/kernel.ts +56 -98
- package/src/bridge/protocol.ts +3 -142
- package/src/browser.ts +90 -6
- package/src/context-key.ts +4 -7
- package/src/error.ts +1 -1
- package/src/errors.ts +7 -0
- package/src/guest.ts +327 -0
- package/src/host.ts +128 -23
- package/src/http/bytes.ts +87 -0
- package/src/http/events.ts +34 -0
- package/src/http.ts +272 -0
- package/src/index.ts +3 -0
- package/src/infrastructure/rpc/client.ts +136 -17
- package/src/infrastructure/rpc/resources.ts +123 -0
- package/src/interpreter/abi.ts +69 -0
- package/src/interpreter/acquire.ts +58 -0
- package/src/interpreter/browser-network.ts +170 -0
- package/src/interpreter/browser-port.ts +425 -0
- package/src/interpreter/browser.ts +340 -0
- package/src/interpreter/cli.ts +30 -0
- package/src/interpreter/codec.ts +298 -0
- package/src/interpreter/component/execution.ts +264 -0
- package/src/interpreter/component/host.ts +409 -0
- package/src/interpreter/component/instance.ts +138 -0
- package/src/interpreter/component/kernel.ts +611 -0
- package/src/interpreter/component/names.ts +13 -0
- package/src/interpreter/component/port.ts +598 -0
- package/src/interpreter/component/prepared.ts +194 -0
- package/src/interpreter/component/resources.ts +345 -0
- package/src/interpreter/component/revision.ts +702 -0
- package/src/interpreter/component/scope.ts +447 -0
- package/src/interpreter/component/streams.ts +180 -0
- package/src/interpreter/component/values.ts +254 -0
- package/src/interpreter/component/wasi-filesystem.ts +472 -0
- package/src/interpreter/component/wasi-host.ts +197 -0
- package/src/interpreter/component/wasi-http.ts +939 -0
- package/src/interpreter/component/wasi-sockets.ts +958 -0
- package/src/interpreter/component/wasi.ts +238 -0
- package/src/interpreter/core.ts +386 -0
- package/src/interpreter/fetch-http-provider.ts +98 -0
- package/src/interpreter/filesystem/contract.ts +138 -0
- package/src/interpreter/filesystem/memory.ts +180 -0
- package/src/interpreter/filesystem/opfs.ts +294 -0
- package/src/interpreter/filesystem/scope.ts +390 -0
- package/src/interpreter/filesystem.ts +20 -0
- package/src/interpreter/gate.ts +55 -0
- package/src/interpreter/host-protocol.ts +242 -0
- package/src/interpreter/http-ingress-fetch.ts +133 -0
- package/src/interpreter/http-ingress.ts +203 -0
- package/src/interpreter/http-provider.ts +105 -0
- package/src/interpreter/io.ts +66 -0
- package/src/interpreter/mobile.ts +385 -0
- package/src/interpreter/native-ingress.ts +550 -0
- package/src/interpreter/node-port.ts +218 -0
- package/src/interpreter/node.ts +114 -0
- package/src/interpreter/revision.ts +450 -0
- package/src/interpreter/scope.ts +453 -0
- package/src/interpreter/socket-addresses.ts +246 -0
- package/src/interpreter/socket-provider.ts +126 -0
- package/src/interpreter/standard-cli.ts +184 -0
- package/src/interpreter/standard-codec.ts +403 -0
- package/src/interpreter/standard-filesystem.ts +545 -0
- package/src/interpreter/standard-host.ts +840 -0
- package/src/interpreter/standard-http-values.ts +624 -0
- package/src/interpreter/standard-http.ts +622 -0
- package/src/interpreter/standard-ingress.ts +344 -0
- package/src/interpreter/standard-sockets.ts +847 -0
- package/src/interpreter/standard-streams.ts +710 -0
- package/src/interpreter/standard-system.ts +182 -0
- package/src/interpreter/standard-utf8.ts +72 -0
- package/src/interpreter/standard.ts +283 -0
- package/src/interpreter/types.ts +163 -0
- package/src/interpreter/wit-shape.ts +175 -0
- package/src/node.ts +43 -14
- package/src/runtime/activities.ts +6 -6
- package/src/runtime/adapters.ts +314 -0
- package/src/runtime/calls.ts +218 -56
- package/src/runtime/context.ts +7 -7
- package/src/runtime/lifecycle.ts +36 -17
- package/src/runtime/orbs.ts +81 -39
- package/src/runtime/programs.ts +16 -8
- package/src/runtime/references.ts +128 -11
- package/src/runtime/reload.ts +71 -30
- package/src/runtime/resources.ts +2 -2
- package/src/runtime/scopes.ts +17 -17
- package/src/runtime/session.ts +3 -1
- package/src/runtime/signals.ts +31 -0
- package/src/runtime/wit-client.ts +228 -0
- package/src/tooling/build.ts +152 -54
- package/src/tooling/client-resources.ts +74 -0
- package/src/tooling/client.ts +531 -0
- package/src/tooling/component-glue.ts +288 -0
- package/src/tooling/component.ts +225 -0
- package/src/tooling/index.ts +3 -7
- package/src/tooling/resolver.ts +42 -25
- package/src/tooling/typecheck.ts +59 -4
- package/src/tooling/types.ts +27 -12
- package/src/tooling/wit.ts +188 -0
- package/dist/embedded.d.ts +0 -1
- package/dist/embedded.js +0 -1
- package/src/embedded.ts +0 -293
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incoming HTTP for `Host.handleHttp`: the raw request and response shapes, the handler's error
|
|
3
|
+
* and the private exchange that carries one request into an Orb's `wasi:http/handler` export.
|
|
4
|
+
*
|
|
5
|
+
* The raw shapes are lossless: field values are bytes, order and duplicates are kept, the
|
|
6
|
+
* request target is passed verbatim, and both sides carry trailers. Bodies are
|
|
7
|
+
* `AsyncIterable<Uint8Array>`, so nothing here needs WHATWG streams; `return()` on the response
|
|
8
|
+
* body's iterator is the client disconnect. Nothing in this module performs I/O.
|
|
9
|
+
*/
|
|
10
|
+
import type { ErrorCode } from "../wasi/wasi-http-types.js";
|
|
11
|
+
import type { HttpField } from "./http-provider.ts";
|
|
12
|
+
/** The exact standard export an Orb serves incoming HTTP through. */
|
|
13
|
+
export declare const HTTP_HANDLER = "wasi:http/handler@0.3.0";
|
|
14
|
+
/** One request as the host received it; the application owns listening, routing and auth. */
|
|
15
|
+
export interface IncomingHttpRequest {
|
|
16
|
+
/** `GET`, `POST`, … or an extension token, verbatim. */
|
|
17
|
+
readonly method: string;
|
|
18
|
+
/** `http`, `https` or another scheme; absent when the request has none. */
|
|
19
|
+
readonly scheme?: string | undefined;
|
|
20
|
+
readonly authority?: string | undefined;
|
|
21
|
+
/** The origin-form path and query exactly as received. */
|
|
22
|
+
readonly pathWithQuery?: string | undefined;
|
|
23
|
+
/** Lowercase names and raw value bytes, in order, duplicates kept. */
|
|
24
|
+
readonly fields: readonly HttpField[];
|
|
25
|
+
/**
|
|
26
|
+
* The request contents, pulled as the handler reads, or `null` for none. The host calls its
|
|
27
|
+
* iterator's `return()` once, without awaiting it, when the handler drops the body early, the
|
|
28
|
+
* client disconnects, the call ends, or the call fails before the handler received it.
|
|
29
|
+
*/
|
|
30
|
+
readonly body: AsyncIterable<Uint8Array> | null;
|
|
31
|
+
/** Trailers, read after the body ended; absent means none. */
|
|
32
|
+
readonly trailers?: PromiseLike<readonly HttpField[] | undefined> | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** The handler's response; the head arrives before the body is produced. */
|
|
35
|
+
export interface HttpHandlerResponse {
|
|
36
|
+
/** 100..=599. */
|
|
37
|
+
readonly status: number;
|
|
38
|
+
readonly fields: readonly HttpField[];
|
|
39
|
+
/**
|
|
40
|
+
* The contents, produced while they are read; read once. Reading to the end and then the
|
|
41
|
+
* trailers completes the transmission. Calling `return()` on its iterator (or abandoning a
|
|
42
|
+
* `for await` loop) is the client disconnect: the handler sees `connection-terminated`, its
|
|
43
|
+
* request body is closed and its next write fails.
|
|
44
|
+
*/
|
|
45
|
+
readonly body: AsyncIterable<Uint8Array>;
|
|
46
|
+
/**
|
|
47
|
+
* Settles after the body ended: `undefined` for none. Rejects with an `HttpHandlerError` when
|
|
48
|
+
* the handler failed its body or trailers, or when the delivery ended early.
|
|
49
|
+
*/
|
|
50
|
+
readonly trailers: Promise<readonly HttpField[] | undefined>;
|
|
51
|
+
}
|
|
52
|
+
export interface HandleHttpOptions {
|
|
53
|
+
/** Cancels the call, as cancelling its root does; the response body then ends. */
|
|
54
|
+
readonly signal?: AbortSignal | undefined;
|
|
55
|
+
/** The principal of the root this request runs in; defaults to the host's. */
|
|
56
|
+
readonly principal?: string | undefined;
|
|
57
|
+
}
|
|
58
|
+
/** The handler (or the delivery of its response) ended with a standard `error-code`. */
|
|
59
|
+
export declare class HttpHandlerError extends Error {
|
|
60
|
+
readonly code: ErrorCode;
|
|
61
|
+
constructor(code: ErrorCode, message?: string);
|
|
62
|
+
}
|
|
63
|
+
/** The transmission result the handler sees when its client disconnected. */
|
|
64
|
+
export declare const CONNECTION_TERMINATED: ErrorCode;
|
|
65
|
+
/**
|
|
66
|
+
* One request travelling into one handler call. The head resolves as soon as the handler
|
|
67
|
+
* published its response; a failure before that is reported only once the call physically
|
|
68
|
+
* settled.
|
|
69
|
+
*/
|
|
70
|
+
export declare class IngressExchange {
|
|
71
|
+
#private;
|
|
72
|
+
readonly request: IncomingHttpRequest;
|
|
73
|
+
readonly head: Promise<HttpHandlerResponse>;
|
|
74
|
+
constructor(request: IncomingHttpRequest);
|
|
75
|
+
/** Whether the handler's result (a response or its error) was published. */
|
|
76
|
+
get published(): boolean;
|
|
77
|
+
/** The handler returned a response: release the head now. */
|
|
78
|
+
respond(response: HttpHandlerResponse): void;
|
|
79
|
+
/** The handler returned its `error-code`: reported once the call settled. */
|
|
80
|
+
refuse(code: ErrorCode): void;
|
|
81
|
+
/**
|
|
82
|
+
* A port takes the request: from now on it alone pulls and closes the body. Called exactly
|
|
83
|
+
* where a port's own end-of-call cleanup starts to cover the body.
|
|
84
|
+
*/
|
|
85
|
+
own(): IncomingHttpRequest;
|
|
86
|
+
/**
|
|
87
|
+
* The call physically settled; without a published response, report why. A body no port
|
|
88
|
+
* ever took (the call failed before any port saw it) is closed here, once; its `return()` is
|
|
89
|
+
* not awaited and an application failure there cannot affect the report.
|
|
90
|
+
*/
|
|
91
|
+
settle(failure?: unknown): void;
|
|
92
|
+
/** Take the exchange for the handler call; a host-local value enters exactly one call. */
|
|
93
|
+
static claim(value: unknown): IngressExchange;
|
|
94
|
+
}
|
|
95
|
+
/** Check the raw request's shape before any work starts; semantics are checked by the host. */
|
|
96
|
+
export declare function checkedRequest(request: IncomingHttpRequest): IncomingHttpRequest;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host transport contract behind standard `wasi:http`, independent of a platform adapter.
|
|
3
|
+
*
|
|
4
|
+
* An `HttpProvider` receives one grant-checked request with raw byte fields, a pull-based body
|
|
5
|
+
* stream and a trailers promise, and returns raw response fields, a body stream and optional
|
|
6
|
+
* trailers. Mocks and alternate transports implement the full WASI semantics through it
|
|
7
|
+
* (duplicate raw fields, trailers both ways, uploads that stream while the response is read).
|
|
8
|
+
* The browser Fetch adapter is implemented separately in `fetch-http-provider.ts`.
|
|
9
|
+
*/
|
|
10
|
+
import type { ErrorCode } from "../wasi/wasi-http-types.js";
|
|
11
|
+
/** One field: a lowercase name and its raw value bytes. Order and duplicates are significant. */
|
|
12
|
+
export type HttpField = readonly [name: string, value: Uint8Array];
|
|
13
|
+
/** WASI `request-options` durations in nanoseconds; absent means no timeout was requested. */
|
|
14
|
+
export interface HttpTimeouts {
|
|
15
|
+
readonly connect?: bigint | undefined;
|
|
16
|
+
readonly firstByte?: bigint | undefined;
|
|
17
|
+
readonly betweenBytes?: bigint | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One outgoing request. The host enforces `firstByte` (until the response promise settles) and
|
|
21
|
+
* `betweenBytes` (per response body read) for every provider; `connect` is the provider's to
|
|
22
|
+
* honor or refuse.
|
|
23
|
+
*/
|
|
24
|
+
export interface HttpProviderRequest {
|
|
25
|
+
/**
|
|
26
|
+
* The granted canonical origin with the WHATWG-normalized path, for URL-based transports
|
|
27
|
+
* such as Fetch (which resolve dot segments and backslashes and escape some characters).
|
|
28
|
+
*/
|
|
29
|
+
readonly url: URL;
|
|
30
|
+
/** The request target exactly as the guest validated it (origin-form path and query). */
|
|
31
|
+
readonly pathWithQuery: string;
|
|
32
|
+
/** `GET`, `POST`, … or an extension token verbatim. */
|
|
33
|
+
readonly method: string;
|
|
34
|
+
readonly fields: readonly HttpField[];
|
|
35
|
+
/**
|
|
36
|
+
* The request contents, pulled one bounded chunk at a time from the guest (no read-ahead), or
|
|
37
|
+
* `null` when the request has none. It closes only after the whole upload, including a
|
|
38
|
+
* declared `Content-Length` and the trailers result, succeeded; a failed or abandoned upload
|
|
39
|
+
* errors it with an `HttpProviderError` and never closes it, so a provider cannot commit a
|
|
40
|
+
* truncated body. A provider that will not read it must cancel it; the host ends it
|
|
41
|
+
* anyway when the response is released early or fails, or the revision retires. Cancelling
|
|
42
|
+
* it stops the guest's upload.
|
|
43
|
+
*/
|
|
44
|
+
readonly body: ReadableStream<Uint8Array> | null;
|
|
45
|
+
/**
|
|
46
|
+
* Trailers, settled once the body ended: `undefined` for none. Rejects with the upload's
|
|
47
|
+
* `HttpProviderError` when the upload fails.
|
|
48
|
+
*/
|
|
49
|
+
readonly trailers: Promise<readonly HttpField[] | undefined>;
|
|
50
|
+
readonly timeouts: HttpTimeouts;
|
|
51
|
+
/**
|
|
52
|
+
* Aborts when the originating callback is cancelled or the first-byte timeout expires before
|
|
53
|
+
* the response promise settled, and when the host releases the response early (dropped before
|
|
54
|
+
* its end, a body failure, or retirement before its end). A cleanly ended response body does
|
|
55
|
+
* not abort it. Retirement still errors any unfinished upload body and its trailers.
|
|
56
|
+
*/
|
|
57
|
+
readonly signal: AbortSignal;
|
|
58
|
+
}
|
|
59
|
+
/** One response, revision-owned by the host once returned. */
|
|
60
|
+
export interface HttpProviderResponse {
|
|
61
|
+
/** 100..=999. */
|
|
62
|
+
readonly status: number;
|
|
63
|
+
readonly fields: readonly HttpField[];
|
|
64
|
+
/**
|
|
65
|
+
* The response contents, or `null` for none. Empty chunks are allowed. The host reads it only
|
|
66
|
+
* as the guest reads, enforces a declared `Content-Length` (except for `HEAD`, 1xx, 204 and
|
|
67
|
+
* 304), and cancels it once when it releases the response early; that cancel promise is the
|
|
68
|
+
* physical acknowledgement the host waits for.
|
|
69
|
+
*/
|
|
70
|
+
readonly body: ReadableStream<Uint8Array> | null;
|
|
71
|
+
/** Trailers, read after the body ended; absent means none. */
|
|
72
|
+
readonly trailers?: Promise<readonly HttpField[] | undefined>;
|
|
73
|
+
}
|
|
74
|
+
/** A host HTTP transport. The promise is physical work: the host tracks it until it settles. */
|
|
75
|
+
export interface HttpProvider {
|
|
76
|
+
send(request: HttpProviderRequest): Promise<HttpProviderResponse>;
|
|
77
|
+
}
|
|
78
|
+
/** A transport failure with a standard `error-code`; any other failure maps to `internal-error`. */
|
|
79
|
+
export declare class HttpProviderError extends Error {
|
|
80
|
+
readonly code: ErrorCode;
|
|
81
|
+
constructor(code: ErrorCode, message?: string);
|
|
82
|
+
}
|
|
83
|
+
/** Field values are byte strings; Fetch carries them as one UTF-16 unit per byte. */
|
|
84
|
+
export declare function byteString(bytes: Uint8Array): string;
|
|
85
|
+
export declare function bytesOf(text: string): Uint8Array;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BrowserNetwork, type BrowserNetworkProviders } from "./browser-network.ts";
|
|
2
|
+
import type { FilesystemProvider } from "./filesystem.ts";
|
|
3
|
+
import type { StandardMount } from "./standard-filesystem.ts";
|
|
4
|
+
import type { Grants } from "../authoring/types.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Installed grants remain host capabilities. Filesystem mounts, HTTP and sockets are reached
|
|
7
|
+
* only through the standard WASI host; there is no other host I/O channel.
|
|
8
|
+
*/
|
|
9
|
+
export declare class BrowserCapabilities {
|
|
10
|
+
#private;
|
|
11
|
+
readonly network: BrowserNetwork;
|
|
12
|
+
private constructor();
|
|
13
|
+
static open(grants: Grants, providers: BrowserNetworkProviders & {
|
|
14
|
+
filesystem?: Readonly<Record<string, FilesystemProvider>>;
|
|
15
|
+
}): Promise<BrowserCapabilities>;
|
|
16
|
+
/** Mounts in grant order for standard `wasi:filesystem` preopens. */
|
|
17
|
+
get mounts(): readonly StandardMount[];
|
|
18
|
+
/** Called after the transport has awaited every physically admitted host operation. */
|
|
19
|
+
dispose(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { HostOptions } from "../authoring/types.ts";
|
|
2
|
+
import { Host } from "../host.ts";
|
|
3
|
+
import { type ContractPort, type DirectoryFilesystem, type ExecutionScope, type InterpreterPort } from "./types.ts";
|
|
4
|
+
/** Platform-owned objects retain all native handles behind the mobile facade. */
|
|
5
|
+
export interface MobileArtifact extends ContractPort {
|
|
6
|
+
description(): string;
|
|
7
|
+
free(): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The native UniFFI incoming HTTP carrier (`begin_ingress`, `receive_ingress`, `supply_request`,
|
|
11
|
+
* `pull_response`, `disconnect`) in lowerCamelCase. Bytes are typed `Uint8Array`s end to end:
|
|
12
|
+
* a bridge that cannot carry binary data (number arrays, base64) must not provide this group.
|
|
13
|
+
*/
|
|
14
|
+
export interface MobileField {
|
|
15
|
+
name: string;
|
|
16
|
+
value: Uint8Array;
|
|
17
|
+
}
|
|
18
|
+
export interface MobileRequestHead {
|
|
19
|
+
method: string;
|
|
20
|
+
/** Present exactly when `authority` is. */
|
|
21
|
+
scheme?: string;
|
|
22
|
+
authority?: string;
|
|
23
|
+
pathWithQuery?: string;
|
|
24
|
+
fields: MobileField[];
|
|
25
|
+
}
|
|
26
|
+
/** The answer to one `requestPull`. */
|
|
27
|
+
export type MobileRequestChunk = {
|
|
28
|
+
kind: "data";
|
|
29
|
+
bytes: Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
/** The end of the request body; `[]` for no trailers. */
|
|
32
|
+
| {
|
|
33
|
+
kind: "end";
|
|
34
|
+
trailers: MobileField[];
|
|
35
|
+
} | {
|
|
36
|
+
kind: "error";
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
export type MobileIngressEvent = {
|
|
40
|
+
kind: "host";
|
|
41
|
+
id: number;
|
|
42
|
+
asynchronous: boolean;
|
|
43
|
+
packet: string;
|
|
44
|
+
}
|
|
45
|
+
/** The completion envelope JSON; `finish` follows. */
|
|
46
|
+
| {
|
|
47
|
+
kind: "complete";
|
|
48
|
+
result: string;
|
|
49
|
+
} | {
|
|
50
|
+
kind: "head";
|
|
51
|
+
status: number;
|
|
52
|
+
fields: MobileField[];
|
|
53
|
+
} | {
|
|
54
|
+
kind: "requestPull";
|
|
55
|
+
} | {
|
|
56
|
+
kind: "data";
|
|
57
|
+
bytes: Uint8Array;
|
|
58
|
+
} | {
|
|
59
|
+
kind: "trailers";
|
|
60
|
+
fields: MobileField[];
|
|
61
|
+
} | {
|
|
62
|
+
kind: "end";
|
|
63
|
+
} | {
|
|
64
|
+
kind: "error";
|
|
65
|
+
message: string;
|
|
66
|
+
}
|
|
67
|
+
/** The handler's WIT `error-code` in the standard binary codec; never with a head. */
|
|
68
|
+
| {
|
|
69
|
+
kind: "refused";
|
|
70
|
+
code: Uint8Array;
|
|
71
|
+
};
|
|
72
|
+
/** The whole carrier, or nothing: a port either serves incoming HTTP or does not. */
|
|
73
|
+
export interface MobileIngressCarrier {
|
|
74
|
+
/** Start the exchange; its events then come only from `receiveIngress`. */
|
|
75
|
+
beginIngress(packet: string, head: MobileRequestHead): void;
|
|
76
|
+
/** The single receive loop of the active exchange. */
|
|
77
|
+
receiveIngress(): Promise<MobileIngressEvent>;
|
|
78
|
+
/** `false` when the answer is no longer wanted. */
|
|
79
|
+
supplyRequest(chunk: MobileRequestChunk): boolean;
|
|
80
|
+
pullResponse(): void;
|
|
81
|
+
disconnect(): void;
|
|
82
|
+
}
|
|
83
|
+
export interface MobilePort {
|
|
84
|
+
description(): string;
|
|
85
|
+
begin(packet: string, declaration: boolean): void;
|
|
86
|
+
receive(): Promise<string>;
|
|
87
|
+
reply(id: number, packet: string): boolean;
|
|
88
|
+
finish(): void;
|
|
89
|
+
abort(): Promise<void>;
|
|
90
|
+
release(environment: number): void;
|
|
91
|
+
/** Cancel standard WASI work owned by the active callback. */
|
|
92
|
+
cancel(): void;
|
|
93
|
+
close(): void;
|
|
94
|
+
/**
|
|
95
|
+
* The typed incoming HTTP carrier, absent where the platform bridge cannot carry raw bytes;
|
|
96
|
+
* `Host.handleHttp` is then refused for this port's Orbs.
|
|
97
|
+
*/
|
|
98
|
+
readonly ingress?: MobileIngressCarrier | undefined;
|
|
99
|
+
}
|
|
100
|
+
export interface MobileBackend {
|
|
101
|
+
artifact(bytes: Uint8Array): MobileArtifact;
|
|
102
|
+
/** Open a source or compiled revision; both answer the same scoped host requests. */
|
|
103
|
+
open(artifact: MobileArtifact, bindings: string, grants: string, cli: string): Promise<MobilePort>;
|
|
104
|
+
}
|
|
105
|
+
export interface MobileExecutionOptions {
|
|
106
|
+
onLog?: (record: {
|
|
107
|
+
orb: string;
|
|
108
|
+
level: string;
|
|
109
|
+
message: string;
|
|
110
|
+
}) => void;
|
|
111
|
+
providers?: {
|
|
112
|
+
filesystem?: Readonly<Record<string, DirectoryFilesystem>>;
|
|
113
|
+
network?: readonly string[];
|
|
114
|
+
};
|
|
115
|
+
limits?: {
|
|
116
|
+
memoryBytes?: number;
|
|
117
|
+
fuel?: number;
|
|
118
|
+
packetBytes?: number;
|
|
119
|
+
timeoutMs?: number;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** Adapt asynchronous platform delivery while guest factories remain strictly synchronous. */
|
|
123
|
+
export declare class MobileDriver implements InterpreterPort {
|
|
124
|
+
readonly port: MobilePort;
|
|
125
|
+
readonly dispose: () => void;
|
|
126
|
+
/** Present only when the port provides the complete typed carrier. */
|
|
127
|
+
readonly ingress?: NonNullable<InterpreterPort["ingress"]>;
|
|
128
|
+
constructor(port: MobilePort, dispose: () => void);
|
|
129
|
+
/** Return already checked executable metadata. */
|
|
130
|
+
description(): string;
|
|
131
|
+
/** Drop guest bookkeeping only after the environment has drained. */
|
|
132
|
+
release(environment: number): void;
|
|
133
|
+
/** Keep declaration requests attached to their issued factory authority. */
|
|
134
|
+
declare(packet: string, scope: ExecutionScope): Promise<unknown>;
|
|
135
|
+
/** Retain captured result bytes until the shared contract validator checks them. */
|
|
136
|
+
execute(packet: string, scope: ExecutionScope): Promise<string>;
|
|
137
|
+
/** Release the native revision and its prepared artifact together. */
|
|
138
|
+
close(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Serve one incoming HTTP request over the typed carrier: one receive loop feeds the shared
|
|
141
|
+
* exchange protocol until `complete`; a broken receive ends both bodies, drains admitted host
|
|
142
|
+
* work and quarantines the native exchange, exactly as an ordinary callback does.
|
|
143
|
+
*/
|
|
144
|
+
private serve;
|
|
145
|
+
/** Drain every admitted host operation before reopening the physical guest ticket. */
|
|
146
|
+
private drive;
|
|
147
|
+
}
|
|
148
|
+
/** Connect native execution to the existing host without copying lifecycle or permission rules. */
|
|
149
|
+
export declare function createMobileHost(options: HostOptions, backend: MobileBackend, isolated: MobileExecutionOptions): Host;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ErrorCode } from "../wasi/wasi-http-types.js";
|
|
2
|
+
import { type IncomingHttpRequest, type IngressExchange } from "./http-ingress.ts";
|
|
3
|
+
import type { HttpField } from "./http-provider.ts";
|
|
4
|
+
import type { ExecutionScope, IngressDispatch } from "./types.ts";
|
|
5
|
+
/** Carrier events in the SDK's byte form. */
|
|
6
|
+
export type CarrierEvent = {
|
|
7
|
+
kind: "host";
|
|
8
|
+
id: number;
|
|
9
|
+
asynchronous: boolean;
|
|
10
|
+
packet: string;
|
|
11
|
+
}
|
|
12
|
+
/** The completion envelope JSON: `{"ok":…}` or `{"error":{code,reason,message}}`. */
|
|
13
|
+
| {
|
|
14
|
+
kind: "complete";
|
|
15
|
+
result: string;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "head";
|
|
18
|
+
status: number;
|
|
19
|
+
fields: readonly HttpField[];
|
|
20
|
+
} | {
|
|
21
|
+
kind: "request-pull";
|
|
22
|
+
} | {
|
|
23
|
+
kind: "data";
|
|
24
|
+
data: Uint8Array;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "trailers";
|
|
27
|
+
fields: readonly HttpField[];
|
|
28
|
+
} | {
|
|
29
|
+
kind: "end";
|
|
30
|
+
} | {
|
|
31
|
+
kind: "error";
|
|
32
|
+
message: string;
|
|
33
|
+
}
|
|
34
|
+
/** The handler returned its `error-code` (standard binary codec bytes); never with a head. */
|
|
35
|
+
| {
|
|
36
|
+
kind: "refused";
|
|
37
|
+
code: Uint8Array;
|
|
38
|
+
};
|
|
39
|
+
/** The answer to one `request-pull`: a chunk, the end with its trailers, or an error. */
|
|
40
|
+
export type RequestAnswer = {
|
|
41
|
+
kind: "data";
|
|
42
|
+
data: Uint8Array;
|
|
43
|
+
} | {
|
|
44
|
+
kind: "end";
|
|
45
|
+
trailers: readonly HttpField[];
|
|
46
|
+
} | {
|
|
47
|
+
kind: "error";
|
|
48
|
+
message: string;
|
|
49
|
+
};
|
|
50
|
+
/** The native exchange's control calls; each may throw, none is called after `complete`. */
|
|
51
|
+
export interface CarrierTransport {
|
|
52
|
+
/** Answer the pending request pull; `false` when the answer is no longer wanted. */
|
|
53
|
+
supply(answer: RequestAnswer): boolean;
|
|
54
|
+
/** Ask for one response frame. */
|
|
55
|
+
pull(): void;
|
|
56
|
+
/** The client went away. */
|
|
57
|
+
disconnect(): void;
|
|
58
|
+
/** The caller cancelled the call. */
|
|
59
|
+
cancel(): void;
|
|
60
|
+
reply(id: number, packet: string): boolean;
|
|
61
|
+
/** Release the native ticket after `complete`. */
|
|
62
|
+
finish(): void;
|
|
63
|
+
}
|
|
64
|
+
/** The control packet that starts the handler callback; the request travels typed. */
|
|
65
|
+
export declare function ingressPacket(dispatch: IngressDispatch): string;
|
|
66
|
+
/** Encode one host reply without throwing through a native callback frame. */
|
|
67
|
+
export declare function respond(operation: () => unknown): string;
|
|
68
|
+
/** Decode a native `refused` event: exactly one WIT `error-code` in the standard binary codec. */
|
|
69
|
+
export declare function refusedCode(bytes: Uint8Array): ErrorCode;
|
|
70
|
+
/** One exchange's protocol state; created per request, never reused. */
|
|
71
|
+
export declare class NativeIngress {
|
|
72
|
+
#private;
|
|
73
|
+
readonly transport: CarrierTransport;
|
|
74
|
+
readonly exchange: IngressExchange;
|
|
75
|
+
readonly scope: ExecutionScope;
|
|
76
|
+
/** Settles after `complete`, the drain of admitted host work and `finish()`. */
|
|
77
|
+
readonly settled: Promise<void>;
|
|
78
|
+
constructor(transport: CarrierTransport, exchange: IngressExchange, scope: ExecutionScope);
|
|
79
|
+
/** The request as the application supplied it. */
|
|
80
|
+
get request(): IncomingHttpRequest;
|
|
81
|
+
/** The native exchange has begun: connect the caller's cancellation to it. */
|
|
82
|
+
begun(): void;
|
|
83
|
+
/** Handle one carrier event; never throws, so a native callback frame is never unwound. */
|
|
84
|
+
event(event: CarrierEvent): void;
|
|
85
|
+
/**
|
|
86
|
+
* The transport failed (its event stream broke): end both bodies, revoke and drain host work,
|
|
87
|
+
* and reject. The platform adapter then quarantines its native exchange; `finish` is not called.
|
|
88
|
+
*/
|
|
89
|
+
abandon(error: unknown): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* A failure inside this adapter or its platform mapping: keep it for the completion, and free
|
|
92
|
+
* the guest from anything it waits on (disconnect, then cancel). The exchange still finishes.
|
|
93
|
+
*/
|
|
94
|
+
fail(error: unknown): void;
|
|
95
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { NodeInterpreterPort } from "@syntropika/tembra-engine-node";
|
|
2
|
+
import type { IngressExchange } from "./http-ingress.ts";
|
|
3
|
+
import { type ExecutionScope, type IngressDispatch, type InterpreterPort } from "./types.ts";
|
|
4
|
+
/** Native worker events cross a thread; browser execution uses the same scope directly. */
|
|
5
|
+
export declare class NodePort implements InterpreterPort {
|
|
6
|
+
readonly transport: NodeInterpreterPort;
|
|
7
|
+
/** Retain one native transport until the revision physically closes. */
|
|
8
|
+
constructor(transport: NodeInterpreterPort);
|
|
9
|
+
/** Read the validated source metadata once. */
|
|
10
|
+
description(): string;
|
|
11
|
+
/** Release only guest-owned bookkeeping after its host environment ends. */
|
|
12
|
+
release(environment: number): void;
|
|
13
|
+
/** Keep factory calls synchronous while decoding each host request once. */
|
|
14
|
+
declare(packet: string, scope: ExecutionScope): unknown;
|
|
15
|
+
/** Finish the native ticket only after admitted host operations physically settle. */
|
|
16
|
+
execute(packet: string, scope: ExecutionScope): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Serve one incoming HTTP request through the typed NAPI carrier. Bytes cross as `Buffer`s;
|
|
19
|
+
* the head is published early and this resolves only after `complete`, the drain of admitted
|
|
20
|
+
* host work and `finish()`.
|
|
21
|
+
*/
|
|
22
|
+
ingress(dispatch: IngressDispatch, exchange: IngressExchange, scope: ExecutionScope): Promise<void>;
|
|
23
|
+
/** Drop an idle native Store after the common lifecycle releases its scopes. */
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { OrbDefinition, OrbArtifact } from "../authoring/types.ts";
|
|
2
|
+
import { type DirectoryFilesystem } from "./types.ts";
|
|
3
|
+
export type { DirectoryFilesystem } from "./types.ts";
|
|
4
|
+
/** Register a system directory without granting an Orb access to it. */
|
|
5
|
+
export declare function directoryFilesystem(path: string): DirectoryFilesystem;
|
|
6
|
+
export interface InterpreterOptions {
|
|
7
|
+
engine?: Uint8Array;
|
|
8
|
+
providers?: {
|
|
9
|
+
filesystem?: Readonly<Record<string, DirectoryFilesystem>>;
|
|
10
|
+
network?: readonly string[];
|
|
11
|
+
};
|
|
12
|
+
limits?: {
|
|
13
|
+
memoryBytes?: number;
|
|
14
|
+
fuel?: number;
|
|
15
|
+
packetBytes?: number;
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
};
|
|
18
|
+
onLog?: (record: {
|
|
19
|
+
orb: string;
|
|
20
|
+
level: string;
|
|
21
|
+
message: string;
|
|
22
|
+
}) => void;
|
|
23
|
+
}
|
|
24
|
+
/** Platform transport owns Stores; the common host still owns every lifecycle decision. */
|
|
25
|
+
export declare class NodeExecution {
|
|
26
|
+
#private;
|
|
27
|
+
readonly options: InterpreterOptions;
|
|
28
|
+
/** Register host configuration without compiling an interpreter for metadata-only hosts. */
|
|
29
|
+
constructor(options: InterpreterOptions);
|
|
30
|
+
/** Materialize source bytes supplied directly through an Orb declaration. */
|
|
31
|
+
materialize(definition: OrbArtifact): Promise<OrbDefinition>;
|
|
32
|
+
/** Lazily share compiled engine code while keeping provider tables local to this host. */
|
|
33
|
+
private backend;
|
|
34
|
+
/** Resolve grants once, then adapt the opaque artifact through the common lifecycle. */
|
|
35
|
+
private open;
|
|
36
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ReferenceBinding } from "./types.ts";
|
|
2
|
+
import type { OrbDefinition, HookDefinition } from "../authoring/types.ts";
|
|
3
|
+
import { Gate } from "./gate.ts";
|
|
4
|
+
import { Scope } from "./scope.ts";
|
|
5
|
+
import { type ContractPort, type ExportedInterface, type HookBinding, type InstallationPlan, type InterpreterPort, type ExecutionScope } from "./types.ts";
|
|
6
|
+
import { type Signature } from "./wit-shape.ts";
|
|
7
|
+
/**
|
|
8
|
+
* Build the interpreter Load's exported-function table from the prepared contract, exactly as the
|
|
9
|
+
* native host does (`adapter::exported_functions`): every function of an exported interface with
|
|
10
|
+
* an identity, under the export slot `bind` returns for it. The incoming HTTP handler is served
|
|
11
|
+
* only through `ingress`, so it has no id.
|
|
12
|
+
*/
|
|
13
|
+
export declare function exportedFunctions(description: {
|
|
14
|
+
readonly javascriptNames: Readonly<Record<string, string>>;
|
|
15
|
+
readonly exports: readonly {
|
|
16
|
+
readonly contract?: string | null;
|
|
17
|
+
readonly functions?: Readonly<Record<string, unknown>>;
|
|
18
|
+
}[];
|
|
19
|
+
}, contract: Pick<ContractPort, "bind">): ExportedInterface[];
|
|
20
|
+
/**
|
|
21
|
+
* One definition per hook a checked implementation declares, composed as it declares: shared by
|
|
22
|
+
* source revisions and prepared components, so a hook composes alike whatever declared it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function declaredHooks(bindings: readonly HookBinding[]): Record<string, HookDefinition>;
|
|
25
|
+
/** One isolated revision translates callbacks into ordinary SDK declarations and calls. */
|
|
26
|
+
export declare class Revision {
|
|
27
|
+
#private;
|
|
28
|
+
readonly port: InterpreterPort;
|
|
29
|
+
readonly contract: ContractPort;
|
|
30
|
+
readonly timeout: number;
|
|
31
|
+
readonly gate: Gate;
|
|
32
|
+
readonly imports: Map<string, string>;
|
|
33
|
+
/** Checked reference views use the Orb table, shared by the compiled Store. */
|
|
34
|
+
readonly views: Map<string, ReferenceBinding>;
|
|
35
|
+
readonly importSignatures: Map<string, string>;
|
|
36
|
+
readonly importMethods: Map<string, Map<string, {
|
|
37
|
+
name: string;
|
|
38
|
+
slot: number;
|
|
39
|
+
}>>;
|
|
40
|
+
readonly hooks: Map<string, HookBinding>;
|
|
41
|
+
/** Where WIT `u64`/`s64` occur in each bound slot's arguments and result. */
|
|
42
|
+
readonly signatures: Map<number, Signature>;
|
|
43
|
+
readonly scopes: Map<number, Scope>;
|
|
44
|
+
active: boolean;
|
|
45
|
+
/** Both transports share the resolved Rust contract; the SDK remains the sole lifecycle adapter. */
|
|
46
|
+
constructor(port: InterpreterPort, contract: ContractPort, timeout: number);
|
|
47
|
+
/** Run pure synchronous guest work only while its enclosing factory owns admission. */
|
|
48
|
+
private declare;
|
|
49
|
+
/**
|
|
50
|
+
* Run same-revision resource callbacks and decode their reply after physical settlement.
|
|
51
|
+
* Cross-revision methods use executeText and check the original bytes before decoding.
|
|
52
|
+
*/
|
|
53
|
+
execute(command: string, scope: ExecutionScope): Promise<unknown>;
|
|
54
|
+
/** Retain the original reply until its prepared result signature has checked the bytes. */
|
|
55
|
+
private executeText;
|
|
56
|
+
/**
|
|
57
|
+
* The host-local incoming HTTP service. It has no contract signature, so no WIT dependency can
|
|
58
|
+
* bind it, and its method accepts only an exchange issued by `Host.handleHttp`. One request is
|
|
59
|
+
* one callback of this revision: it holds the gate until the response delivery ended.
|
|
60
|
+
*/
|
|
61
|
+
private ingress;
|
|
62
|
+
/** Build callback definitions from WIT rather than asking consumers to repeat service metadata. */
|
|
63
|
+
definition(identity: Pick<OrbDefinition, "name" | "apiVersion">, installation: InstallationPlan): OrbDefinition;
|
|
64
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Declaration } from "../authoring/declaration.ts";
|
|
2
|
+
import type { DynamicReference, Resource } from "../authoring/types.ts";
|
|
3
|
+
import type { Context } from "../runtime/context.ts";
|
|
4
|
+
import type { State } from "../state.ts";
|
|
5
|
+
import type { ExecutionScope } from "./types.ts";
|
|
6
|
+
import type { Revision } from "./revision.ts";
|
|
7
|
+
/** The host-issued authority one callback's requests are served under. */
|
|
8
|
+
export type Authority = {
|
|
9
|
+
declaration: Declaration;
|
|
10
|
+
} | {
|
|
11
|
+
context: Context;
|
|
12
|
+
} | {
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
} | {
|
|
15
|
+
validation: true;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The revision tables and callback executor a scope serves requests with. A source revision is
|
|
19
|
+
* one; a prepared browser component lends its own for the kernel interfaces its Orb imports
|
|
20
|
+
* (`component/kernel.ts`), so both answer the same requests with this same code.
|
|
21
|
+
*/
|
|
22
|
+
export type ScopeRevision = Pick<Revision, "contract" | "scopes" | "views" | "imports" | "importMethods" | "importSignatures" | "hooks" | "signatures"> & {
|
|
23
|
+
/**
|
|
24
|
+
* Run a resource callback the guest numbered with the scope its `authority` issued. A source
|
|
25
|
+
* revision needs only the scope; a prepared component also admits its dependency calls with
|
|
26
|
+
* the authority itself, which stays on the host.
|
|
27
|
+
*/
|
|
28
|
+
execute(command: string, scope: ExecutionScope, authority: Authority): Promise<unknown>;
|
|
29
|
+
};
|
|
30
|
+
/** Host-owned tables restrict guest numbers to one environment and its explicit Orb parent. */
|
|
31
|
+
export declare class Scope {
|
|
32
|
+
#private;
|
|
33
|
+
readonly revision: ScopeRevision;
|
|
34
|
+
readonly declaration: Declaration;
|
|
35
|
+
readonly service: string | null;
|
|
36
|
+
readonly id: number;
|
|
37
|
+
readonly parent: Scope | undefined;
|
|
38
|
+
readonly validators: number[];
|
|
39
|
+
readonly states: Map<number, State<unknown>>;
|
|
40
|
+
/**
|
|
41
|
+
* Declared references belong to this environment. A `root` marks a `Context.get` handle: the
|
|
42
|
+
* runtime's root claim list owns it and releases it when that root ends.
|
|
43
|
+
*/
|
|
44
|
+
readonly references: Map<number, {
|
|
45
|
+
reference: DynamicReference;
|
|
46
|
+
binding: string;
|
|
47
|
+
root?: number;
|
|
48
|
+
}>;
|
|
49
|
+
readonly resources: Map<number, Resource<number>>;
|
|
50
|
+
readonly hooks: Map<number, {
|
|
51
|
+
handle: ReturnType<Declaration["hook"]>;
|
|
52
|
+
binding: import("./types.ts").HookBinding;
|
|
53
|
+
}>;
|
|
54
|
+
/** Retain only issued declarations; service scopes inherit their own revision's Orb resources. */
|
|
55
|
+
constructor(revision: ScopeRevision, declaration: Declaration, service: string | null);
|
|
56
|
+
/** Adapt an issued host authority to the interpreter transport without serializing it. */
|
|
57
|
+
exchange(authority: Authority): ExecutionScope;
|
|
58
|
+
/** Require the actual admitted call for writes and dependent invocations. */
|
|
59
|
+
private context;
|
|
60
|
+
/** Reject declarations outside the original synchronous pass. */
|
|
61
|
+
private factory;
|
|
62
|
+
/** Select this table or the issued parent's; a scope is a table selector, never an authority. */
|
|
63
|
+
private selected;
|
|
64
|
+
/** Resolve only handles issued from the selected host table. */
|
|
65
|
+
private handle;
|
|
66
|
+
/** Match the native u32 handle space and never reuse an expired handle's identity. */
|
|
67
|
+
private allocate;
|
|
68
|
+
/**
|
|
69
|
+
* Return the kernel's snapshot revision rather than inventing guest state identities. When the
|
|
70
|
+
* guest already retains the current revision, only the identity crosses back; the protected value
|
|
71
|
+
* is omitted because a revision never names two different values.
|
|
72
|
+
*/
|
|
73
|
+
private snapshot;
|
|
74
|
+
/** Service synchronous requests against one immutable authority selected by the host callback. */
|
|
75
|
+
private sync;
|
|
76
|
+
/**
|
|
77
|
+
* Resolve a reference handle and its WIT binding for the current callback. Declared handles come
|
|
78
|
+
* from this table or the issued parent's. A `Context.get` handle resolves only in the table that
|
|
79
|
+
* issued it, for a callback of the root owning its claim, and only while that root lasts.
|
|
80
|
+
*/
|
|
81
|
+
private reference;
|
|
82
|
+
/**
|
|
83
|
+
* `Context.get`: acquire a selected WIT Orb import for the active invocation (see
|
|
84
|
+
* `acquire.ts`). Only a ready claim receives a handle, filed with the root owning it.
|
|
85
|
+
*/
|
|
86
|
+
private acquire;
|
|
87
|
+
/** Await only issued references and bounded cooperative timers. */
|
|
88
|
+
private async;
|
|
89
|
+
}
|