@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.
- 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 -3332
- 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 -3310
- 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 -3321
- 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 +7 -6
- 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 +213 -90
- 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 -301
|
@@ -180,6 +180,8 @@ export const Reason = Object.freeze({
|
|
|
180
180
|
ValueGone: "value_gone",
|
|
181
181
|
ValuesExhausted: "values_exhausted",
|
|
182
182
|
Views: "views",
|
|
183
|
+
WasmExecutor: "wasm_executor",
|
|
184
|
+
WasmExecutorQuarantined: "wasm_executor_quarantined",
|
|
183
185
|
} as const);
|
|
184
186
|
export type Reason = ValueOf<typeof Reason>;
|
|
185
187
|
|
package/src/bridge/kernel.ts
CHANGED
|
@@ -1,101 +1,56 @@
|
|
|
1
1
|
import { TembraError } from "../error.ts";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
KernelOp,
|
|
4
|
+
type EmptyInput,
|
|
5
|
+
type Features,
|
|
6
|
+
type KernelInput,
|
|
7
|
+
type KernelOutcome,
|
|
8
|
+
type KernelOutput,
|
|
9
|
+
} from "./commands.ts";
|
|
4
10
|
|
|
5
|
-
/**
|
|
11
|
+
/** Kernel metadata shapes, generated from the Rust command table. */
|
|
12
|
+
export type {
|
|
13
|
+
Acquisition,
|
|
14
|
+
Action,
|
|
15
|
+
Diagnostics,
|
|
16
|
+
Effect,
|
|
17
|
+
HookObservation,
|
|
18
|
+
Invocation,
|
|
19
|
+
KernelCommands,
|
|
20
|
+
KernelError,
|
|
21
|
+
KernelInput,
|
|
22
|
+
KernelOrb,
|
|
23
|
+
KernelOutcome,
|
|
24
|
+
KernelOutput,
|
|
25
|
+
OrbDeclaration,
|
|
26
|
+
Owner,
|
|
27
|
+
Reload,
|
|
28
|
+
Snapshot,
|
|
29
|
+
Step,
|
|
30
|
+
} from "./commands.ts";
|
|
31
|
+
|
|
32
|
+
/** Implemented by Node-API and browser Wasm bindings, and by string-only platform adapters. */
|
|
6
33
|
export interface KernelPort {
|
|
7
|
-
/**
|
|
8
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Execute one closed kernel operation on structured metadata.
|
|
36
|
+
* Kernel failures are returned as `{ error }`, never thrown.
|
|
37
|
+
*/
|
|
38
|
+
command<K extends KernelOp>(op: K, input: KernelInput<K>): KernelOutcome<KernelOutput<K>>;
|
|
39
|
+
|
|
40
|
+
/** A fixed scalar scope check; only failures carry encoded error metadata. */
|
|
41
|
+
check(root: number, call?: number): string | null | undefined;
|
|
9
42
|
|
|
10
43
|
/** Release the platform binding after host shutdown. */
|
|
11
44
|
free?(): void;
|
|
12
45
|
}
|
|
13
46
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
| { kind: typeof OwnerKind.Host }
|
|
22
|
-
| { kind: typeof OwnerKind.Orb | typeof OwnerKind.Object; id: number };
|
|
23
|
-
export interface KernelOrb {
|
|
24
|
-
id: number;
|
|
25
|
-
owner: number;
|
|
26
|
-
codeVersion: number;
|
|
27
|
-
name: string;
|
|
28
|
-
apiVersion: number;
|
|
29
|
-
services: { name: string; methods: string[]; lifetime: Lifetime; linger: number }[];
|
|
30
|
-
hooks: string[];
|
|
31
|
-
requires: {
|
|
32
|
-
orb: string;
|
|
33
|
-
apiVersion: number;
|
|
34
|
-
services: Record<string, string[]>;
|
|
35
|
-
hooks: string[];
|
|
36
|
-
}[];
|
|
37
|
-
}
|
|
38
|
-
export interface Acquisition {
|
|
39
|
-
reference: number;
|
|
40
|
-
object: number;
|
|
41
|
-
orb: number;
|
|
42
|
-
codeVersion: number;
|
|
43
|
-
activate: boolean;
|
|
44
|
-
}
|
|
45
|
-
export interface Invocation {
|
|
46
|
-
id: number;
|
|
47
|
-
root: number;
|
|
48
|
-
object: number;
|
|
49
|
-
orb: number;
|
|
50
|
-
codeVersion: number;
|
|
51
|
-
method: string;
|
|
52
|
-
}
|
|
53
|
-
export interface HookObservation {
|
|
54
|
-
invocation: Invocation;
|
|
55
|
-
plan: number[];
|
|
56
|
-
}
|
|
57
|
-
export interface Snapshot {
|
|
58
|
-
value: number;
|
|
59
|
-
revision: string;
|
|
60
|
-
version: number;
|
|
61
|
-
}
|
|
62
|
-
export interface Reload {
|
|
63
|
-
id: number;
|
|
64
|
-
codeVersion: number;
|
|
65
|
-
orbs: KernelOrb[];
|
|
66
|
-
objects: number[];
|
|
67
|
-
providers: Record<string, number>;
|
|
68
|
-
}
|
|
69
|
-
export interface Effect {
|
|
70
|
-
type: EffectType;
|
|
71
|
-
scope?: number;
|
|
72
|
-
previous?: number | null;
|
|
73
|
-
resource?: number;
|
|
74
|
-
value?: number | null;
|
|
75
|
-
version?: number;
|
|
76
|
-
keepListeners?: boolean;
|
|
77
|
-
replacements?: { previous: number | null; next: number | null }[];
|
|
78
|
-
}
|
|
79
|
-
export interface Action {
|
|
80
|
-
type: ActionType;
|
|
81
|
-
id: number;
|
|
82
|
-
revision?: string;
|
|
83
|
-
effects?: Effect[];
|
|
84
|
-
payload?: number;
|
|
85
|
-
operation?: number;
|
|
86
|
-
error?: { code: Code; reason: string; message: string } | null;
|
|
87
|
-
}
|
|
88
|
-
export interface Diagnostics {
|
|
89
|
-
objects: number;
|
|
90
|
-
references: number;
|
|
91
|
-
roots: number;
|
|
92
|
-
calls: number;
|
|
93
|
-
resources: number;
|
|
94
|
-
tasks: number;
|
|
95
|
-
orbs: number;
|
|
96
|
-
closing: boolean;
|
|
97
|
-
codeVersion: number;
|
|
98
|
-
}
|
|
47
|
+
export type KernelFeatures = Features;
|
|
48
|
+
|
|
49
|
+
/** Operations without fields take no input argument. */
|
|
50
|
+
export type KernelArguments<K extends KernelOp> =
|
|
51
|
+
KernelInput<K> extends EmptyInput ? [input?: EmptyInput] : [input: KernelInput<K>];
|
|
52
|
+
|
|
53
|
+
const empty: EmptyInput = Object.freeze({});
|
|
99
54
|
|
|
100
55
|
export class Kernel {
|
|
101
56
|
readonly features: KernelFeatures;
|
|
@@ -105,13 +60,16 @@ export class Kernel {
|
|
|
105
60
|
this.features = this.command(KernelOp.Features);
|
|
106
61
|
}
|
|
107
62
|
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
63
|
+
/** The hot scope check has no input object or success envelope to marshal. */
|
|
64
|
+
check(root: number, call?: number): void {
|
|
65
|
+
const error = this.port.check(root, call);
|
|
66
|
+
if (error !== undefined && error !== null) throw new TembraError(JSON.parse(error));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Execute one operation; its result type is determined by the operation. */
|
|
70
|
+
command<K extends KernelOp>(op: K, ...[input]: KernelArguments<K>): KernelOutput<K> {
|
|
71
|
+
const outcome = this.port.command(op, input ?? (empty as KernelInput<K>));
|
|
72
|
+
if (outcome.error) throw new TembraError(outcome.error);
|
|
73
|
+
return outcome.ok as KernelOutput<K>;
|
|
116
74
|
}
|
|
117
75
|
}
|
package/src/bridge/protocol.ts
CHANGED
|
@@ -1,141 +1,8 @@
|
|
|
1
1
|
/** Closed adapter vocabulary. Strings are retained only as the wire representation. */
|
|
2
2
|
type ValueOf<T> = T[keyof T];
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ContextValue: "context-value",
|
|
7
|
-
ContextStats: "context-stats",
|
|
8
|
-
Allocate: "allocate",
|
|
9
|
-
ScopeRegister: "scope-register",
|
|
10
|
-
ScopeExists: "scope-exists",
|
|
11
|
-
ScopesForOwner: "scopes-for-owner",
|
|
12
|
-
ScopesForOrb: "scopes-for-orb",
|
|
13
|
-
ScopeAddResource: "scope-add-resource",
|
|
14
|
-
ScopeActivate: "scope-activate",
|
|
15
|
-
ScopesCleanup: "scopes-cleanup",
|
|
16
|
-
ScopesReloadRegistered: "scopes-reload-registered",
|
|
17
|
-
ScopesReload: "scopes-reload",
|
|
18
|
-
ProgramRun: "program-run",
|
|
19
|
-
ProgramNext: "program-next",
|
|
20
|
-
ProgramCompleteStep: "program-complete-step",
|
|
21
|
-
ProgramCommit: "program-commit",
|
|
22
|
-
ProgramAbort: "program-abort",
|
|
23
|
-
ProgramForget: "program-forget",
|
|
24
|
-
Features: "features",
|
|
25
|
-
Prepare: "prepare",
|
|
26
|
-
Gate: "gate",
|
|
27
|
-
GateOrbs: "gate-orbs",
|
|
28
|
-
Commit: "commit",
|
|
29
|
-
Abort: "abort",
|
|
30
|
-
Orbs: "orbs",
|
|
31
|
-
Orb: "orb",
|
|
32
|
-
OrbNamed: "orb-named",
|
|
33
|
-
NextDeadline: "next-deadline",
|
|
34
|
-
Address: "address",
|
|
35
|
-
Acquire: "acquire",
|
|
36
|
-
Ready: "ready",
|
|
37
|
-
Dependency: "dependency",
|
|
38
|
-
Undepend: "undepend",
|
|
39
|
-
Fail: "fail",
|
|
40
|
-
Status: "status",
|
|
41
|
-
Release: "release",
|
|
42
|
-
Forget: "forget",
|
|
43
|
-
Root: "root",
|
|
44
|
-
CleanupRoot: "cleanup-root",
|
|
45
|
-
RootPrincipal: "root-principal",
|
|
46
|
-
CheckContext: "check-context",
|
|
47
|
-
CheckRoot: "check-root",
|
|
48
|
-
EndRoot: "end-root",
|
|
49
|
-
CancelRoot: "cancel-root",
|
|
50
|
-
BeginCall: "begin-call",
|
|
51
|
-
BeginOperation: "begin-operation",
|
|
52
|
-
BeginHookObservation: "begin-hook-observation",
|
|
53
|
-
FinishCall: "finish-call",
|
|
54
|
-
Invocation: "invocation",
|
|
55
|
-
StateInit: "state-init",
|
|
56
|
-
Snapshot: "snapshot",
|
|
57
|
-
StateAdopt: "state-adopt",
|
|
58
|
-
Task: "task",
|
|
59
|
-
TaskRoot: "task-root",
|
|
60
|
-
StopTask: "stop-task",
|
|
61
|
-
FinishTask: "finish-task",
|
|
62
|
-
Resource: "resource",
|
|
63
|
-
ResourceOpened: "resource-opened",
|
|
64
|
-
ResourceValue: "resource-value",
|
|
65
|
-
CloseResource: "close-resource",
|
|
66
|
-
ResourceClosed: "resource-closed",
|
|
67
|
-
Disposed: "disposed",
|
|
68
|
-
Tick: "tick",
|
|
69
|
-
NextWake: "next-wake",
|
|
70
|
-
NextIdle: "next-idle",
|
|
71
|
-
Close: "close",
|
|
72
|
-
FinishClose: "finish-close",
|
|
73
|
-
Diagnostics: "diagnostics",
|
|
74
|
-
Drain: "drain",
|
|
75
|
-
Restrict: "restrict",
|
|
76
|
-
Contribute: "contribute",
|
|
77
|
-
ContributionOrdinal: "contribution-ordinal",
|
|
78
|
-
HookPlan: "hook-plan",
|
|
79
|
-
Listen: "listen",
|
|
80
|
-
Subscribe: "subscribe",
|
|
81
|
-
Enqueue: "enqueue",
|
|
82
|
-
NextDelivery: "next-delivery",
|
|
83
|
-
FinishDelivery: "finish-delivery",
|
|
84
|
-
Unsubscribe: "unsubscribe",
|
|
85
|
-
} as const);
|
|
86
|
-
export type KernelOp = ValueOf<typeof KernelOp>;
|
|
87
|
-
|
|
88
|
-
export const ActionType = Object.freeze({
|
|
89
|
-
Execute: "execute",
|
|
90
|
-
CancelEffects: "cancel-effects",
|
|
91
|
-
ProgramPrepared: "program-prepared",
|
|
92
|
-
ProgramComplete: "program-complete",
|
|
93
|
-
Dispose: "dispose",
|
|
94
|
-
CloseResource: "close-resource",
|
|
95
|
-
DropValue: "drop-value",
|
|
96
|
-
CancelRoot: "cancel-root",
|
|
97
|
-
CancelTask: "cancel-task",
|
|
98
|
-
RetireOrb: "retire-orb",
|
|
99
|
-
State: "state",
|
|
100
|
-
SubscriptionFailed: "subscription-failed",
|
|
101
|
-
DetachSubscription: "detach-subscription",
|
|
102
|
-
Deliver: "deliver",
|
|
103
|
-
} as const);
|
|
104
|
-
export type ActionType = ValueOf<typeof ActionType>;
|
|
105
|
-
|
|
106
|
-
export const EffectType = Object.freeze({
|
|
107
|
-
Stop: "stop",
|
|
108
|
-
Open: "open",
|
|
109
|
-
Close: "close",
|
|
110
|
-
Restore: "restore",
|
|
111
|
-
Prepare: "prepare",
|
|
112
|
-
Validate: "validate",
|
|
113
|
-
Initialize: "initialize",
|
|
114
|
-
Migrate: "migrate",
|
|
115
|
-
Adopt: "adopt",
|
|
116
|
-
Start: "start",
|
|
117
|
-
Drop: "drop",
|
|
118
|
-
} as const);
|
|
119
|
-
export type EffectType = ValueOf<typeof EffectType>;
|
|
120
|
-
|
|
121
|
-
export const StepType = Object.freeze({
|
|
122
|
-
Execute: "execute",
|
|
123
|
-
Wait: "wait",
|
|
124
|
-
Prepared: "prepared",
|
|
125
|
-
Complete: "complete",
|
|
126
|
-
Failed: "failed",
|
|
127
|
-
} as const);
|
|
128
|
-
export type StepType = ValueOf<typeof StepType>;
|
|
129
|
-
|
|
130
|
-
export const NativeOp = Object.freeze({
|
|
131
|
-
Activate: "activate",
|
|
132
|
-
Dispose: "dispose",
|
|
133
|
-
CancelEffect: "cancel-effect",
|
|
134
|
-
Effect: "effect",
|
|
135
|
-
Invoke: "invoke",
|
|
136
|
-
Contribute: "contribute",
|
|
137
|
-
} as const);
|
|
138
|
-
export type NativeOp = ValueOf<typeof NativeOp>;
|
|
4
|
+
/** Kernel, native, ownership and lifecycle names are generated from Rust. */
|
|
5
|
+
export { ActionType, EffectType, KernelOp, NativeOp, OwnerKind, StepType } from "./commands.ts";
|
|
139
6
|
|
|
140
7
|
export const RpcOp = Object.freeze({
|
|
141
8
|
Describe: "describe",
|
|
@@ -143,6 +10,7 @@ export const RpcOp = Object.freeze({
|
|
|
143
10
|
Release: "release",
|
|
144
11
|
Call: "call",
|
|
145
12
|
Cancel: "cancel",
|
|
13
|
+
Accept: "accept",
|
|
146
14
|
} as const);
|
|
147
15
|
export type RpcOp = ValueOf<typeof RpcOp>;
|
|
148
16
|
|
|
@@ -151,13 +19,6 @@ export const RpcEvent = Object.freeze({
|
|
|
151
19
|
} as const);
|
|
152
20
|
export type RpcEvent = ValueOf<typeof RpcEvent>;
|
|
153
21
|
|
|
154
|
-
export const OwnerKind = Object.freeze({
|
|
155
|
-
Host: "host",
|
|
156
|
-
Orb: "orb",
|
|
157
|
-
Object: "object",
|
|
158
|
-
} as const);
|
|
159
|
-
export type OwnerKind = ValueOf<typeof OwnerKind>;
|
|
160
|
-
|
|
161
22
|
export const EnvironmentPhase = Object.freeze({
|
|
162
23
|
Declaring: "declaring",
|
|
163
24
|
Prepared: "prepared",
|
package/src/browser.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { isolate, type AdaptedHostOptions } from "#tembra-adapters";
|
|
2
|
+
import type { BrowserExecution, BrowserInterpreterOptions } from "./interpreter/browser.ts";
|
|
3
|
+
import { preparedRegistry } from "./interpreter/component/prepared.ts";
|
|
1
4
|
import { orb } from "./authoring/orb.ts";
|
|
2
5
|
import type { HostOptions } from "./authoring/types.ts";
|
|
3
6
|
import type { KernelPort } from "./bridge/kernel.ts";
|
|
@@ -9,13 +12,16 @@ export interface WasmModule {
|
|
|
9
12
|
}
|
|
10
13
|
export type BrowserHostOptions = Omit<HostOptions, "kernel"> & {
|
|
11
14
|
kernel?: KernelPort;
|
|
15
|
+
isolated?: BrowserInterpreterOptions;
|
|
12
16
|
wasm?: WasmModule | (() => Promise<WasmModule>);
|
|
13
17
|
wasmInput?: unknown;
|
|
14
18
|
baseURL?: string | URL;
|
|
15
19
|
};
|
|
16
20
|
|
|
17
|
-
/**
|
|
21
|
+
/** Configure a browser host with lazily loaded isolated execution for Wasm Orbs. */
|
|
18
22
|
export async function createHost(options: BrowserHostOptions = {}): Promise<Host> {
|
|
23
|
+
// Refuse unprepared or foreign component registrations before any Orb is loaded.
|
|
24
|
+
preparedRegistry(options.isolated?.components);
|
|
19
25
|
let kernel = options.kernel;
|
|
20
26
|
if (!kernel) {
|
|
21
27
|
const supplied = options.wasm;
|
|
@@ -26,20 +32,37 @@ export async function createHost(options: BrowserHostOptions = {}): Promise<Host
|
|
|
26
32
|
await module.default?.(options.wasmInput);
|
|
27
33
|
kernel = new module.WasmKernel();
|
|
28
34
|
}
|
|
35
|
+
let execution: Promise<BrowserExecution> | undefined;
|
|
36
|
+
const backend = () => {
|
|
37
|
+
if (!execution) {
|
|
38
|
+
const opening = import("./interpreter/browser.ts").then((module) =>
|
|
39
|
+
module.createExecution(options.isolated ?? {}),
|
|
40
|
+
);
|
|
41
|
+
execution = opening;
|
|
42
|
+
opening.catch(() => {
|
|
43
|
+
if (execution === opening) execution = undefined;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return execution;
|
|
47
|
+
};
|
|
29
48
|
return new Host({
|
|
49
|
+
[isolate]: async (definition) => (await backend()).materialize(definition),
|
|
30
50
|
...options,
|
|
31
51
|
kernel,
|
|
32
52
|
load:
|
|
33
53
|
options.load ??
|
|
34
|
-
(async (location) => {
|
|
54
|
+
(async (location, registration) => {
|
|
35
55
|
const base = options.baseURL ?? globalThis.location?.href;
|
|
36
56
|
const url =
|
|
37
57
|
location instanceof URL ? location : base ? new URL(location, base) : new URL(location);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
58
|
+
if (!url.pathname.endsWith(".wasm"))
|
|
59
|
+
throw new Error("Orb loading requires a built .wasm artifact");
|
|
60
|
+
const response = await fetch(url);
|
|
61
|
+
if (!response.ok) throw new Error(`Orb request failed: ${response.status}`);
|
|
62
|
+
const source = new Uint8Array(await response.arrayBuffer());
|
|
63
|
+
return { ...registration, artifact: source };
|
|
41
64
|
}),
|
|
42
|
-
});
|
|
65
|
+
} as AdaptedHostOptions);
|
|
43
66
|
}
|
|
44
67
|
|
|
45
68
|
export { orb };
|
|
@@ -56,4 +79,65 @@ export {
|
|
|
56
79
|
|
|
57
80
|
export { Errors, type ErrorDescriptor } from "./errors.ts";
|
|
58
81
|
|
|
82
|
+
export {
|
|
83
|
+
HttpHandlerError,
|
|
84
|
+
type HandleHttpOptions,
|
|
85
|
+
type HttpHandlerResponse,
|
|
86
|
+
type IncomingHttpRequest,
|
|
87
|
+
} from "./interpreter/http-ingress.ts";
|
|
88
|
+
|
|
59
89
|
export { ContextKey, ContextKind, opaqueFrom, type OpaqueContextValue } from "./context-key.ts";
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
memoryFilesystem,
|
|
93
|
+
opfsFilesystem,
|
|
94
|
+
FilesystemError,
|
|
95
|
+
type FilesystemErrorCode,
|
|
96
|
+
type FilesystemProvider,
|
|
97
|
+
type FileStat,
|
|
98
|
+
type MountedFilesystem,
|
|
99
|
+
type FileDescriptor,
|
|
100
|
+
type DirectoryDescriptor,
|
|
101
|
+
type Descriptor,
|
|
102
|
+
type DirectoryEntry,
|
|
103
|
+
type EntryType,
|
|
104
|
+
type OpenOptions,
|
|
105
|
+
} from "./interpreter/filesystem.ts";
|
|
106
|
+
export type { BrowserInterpreterOptions as IsolatedOptions } from "./interpreter/browser.ts";
|
|
107
|
+
/** Used by modules that Tembra tooling generates for compiled Orbs (`browser: true`). */
|
|
108
|
+
export {
|
|
109
|
+
BrowserPlatformError,
|
|
110
|
+
preparedComponent,
|
|
111
|
+
type PreparedComponent,
|
|
112
|
+
type PreparedComponentSource,
|
|
113
|
+
} from "./interpreter/component/prepared.ts";
|
|
114
|
+
export type { Grants, CliOptions } from "./authoring/types.ts";
|
|
115
|
+
|
|
116
|
+
export { fetchHttpProvider, FETCH_BODY_BYTES } from "./interpreter/fetch-http-provider.ts";
|
|
117
|
+
export {
|
|
118
|
+
HttpProviderError,
|
|
119
|
+
type HttpField,
|
|
120
|
+
type HttpProvider,
|
|
121
|
+
type HttpProviderRequest,
|
|
122
|
+
type HttpProviderResponse,
|
|
123
|
+
type HttpTimeouts,
|
|
124
|
+
} from "./interpreter/http-provider.ts";
|
|
125
|
+
export {
|
|
126
|
+
NameLookupError,
|
|
127
|
+
SocketProviderError,
|
|
128
|
+
type SocketOptions,
|
|
129
|
+
type SocketProvider,
|
|
130
|
+
type TcpBackend,
|
|
131
|
+
type TcpConnection,
|
|
132
|
+
type TcpListener,
|
|
133
|
+
type TcpOptions,
|
|
134
|
+
type UdpBackend,
|
|
135
|
+
type UdpOptions,
|
|
136
|
+
} from "./interpreter/socket-provider.ts";
|
|
137
|
+
export type { ClockProvider, ClockInstant, RandomProvider } from "./interpreter/standard-system.ts";
|
|
138
|
+
export type {
|
|
139
|
+
StdioProvider,
|
|
140
|
+
StdioStreams,
|
|
141
|
+
StdioInput,
|
|
142
|
+
StdioOutput,
|
|
143
|
+
} from "./interpreter/standard-cli.ts";
|
package/src/context-key.ts
CHANGED
|
@@ -64,20 +64,17 @@ export function readContextValue<T>(
|
|
|
64
64
|
key: ContextKey<T>,
|
|
65
65
|
frame: number,
|
|
66
66
|
): T | undefined {
|
|
67
|
-
const entry = ctx.session.kernel.command
|
|
68
|
-
kind: ContextKind;
|
|
69
|
-
value?: T;
|
|
70
|
-
source?: number;
|
|
71
|
-
} | null>(KernelOp.ContextValue, {
|
|
67
|
+
const entry = ctx.session.kernel.command(KernelOp.ContextValue, {
|
|
72
68
|
root: ctx.root,
|
|
73
69
|
context: frame,
|
|
74
70
|
call: ctx.invocation?.id,
|
|
75
71
|
key,
|
|
76
72
|
});
|
|
77
73
|
if (!entry) return undefined;
|
|
78
|
-
|
|
74
|
+
// SAFETY: Rust matched the scalar binding kind to the supplied typed key.
|
|
75
|
+
if (entry.kind !== ContextKind.Opaque) return entry.value as T;
|
|
79
76
|
const token = Object.freeze({ opaque: true as const });
|
|
80
|
-
ctx.session.contextTokens.set(token, { root: ctx.root, source: entry.source
|
|
77
|
+
ctx.session.contextTokens.set(token, { root: ctx.root, source: entry.source });
|
|
81
78
|
// SAFETY: Rust matched the opaque binding to the supplied typed key.
|
|
82
79
|
return token as T;
|
|
83
80
|
}
|
package/src/error.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Errors, type ErrorDescriptor } from "./errors.ts";
|
|
|
4
4
|
const codes: ReadonlySet<unknown> = new Set(Object.values(Code));
|
|
5
5
|
|
|
6
6
|
/** Check for a structured error descriptor. */
|
|
7
|
-
function isDescriptor(value: unknown): value is ErrorDescriptor {
|
|
7
|
+
export function isDescriptor(value: unknown): value is ErrorDescriptor {
|
|
8
8
|
return (
|
|
9
9
|
typeof value === "object" &&
|
|
10
10
|
value !== null &&
|
package/src/errors.ts
CHANGED
|
@@ -167,6 +167,7 @@ export const Errors = Object.freeze({
|
|
|
167
167
|
Reason.JsonValue,
|
|
168
168
|
"This JSON codec requires explicit portable values",
|
|
169
169
|
),
|
|
170
|
+
LocalValue: define(Code.Invalid, Reason.LocalValue, "This host-local value is not portable"),
|
|
170
171
|
Method: define(Code.Invalid, Reason.Method, "Methods must be functions"),
|
|
171
172
|
NextUsed: define(Code.Invalid, Reason.NextUsed, "Invalid next used"),
|
|
172
173
|
Priority: define(Code.Invalid, Reason.Priority, "Invalid priority"),
|
|
@@ -219,6 +220,12 @@ export const Errors = Object.freeze({
|
|
|
219
220
|
OrbScope: define(Code.Unavailable, Reason.OrbScope, "The orb scope is unavailable"),
|
|
220
221
|
NotReady: define(Code.Unavailable, Reason.NotReady, "The object is not ready"),
|
|
221
222
|
Route: define(Code.Unavailable, Reason.Route, "The route is unavailable"),
|
|
223
|
+
WasmExecutor: define(Code.Unavailable, Reason.WasmExecutor, "The component executor failed"),
|
|
224
|
+
WasmExecutorQuarantined: define(
|
|
225
|
+
Code.Unavailable,
|
|
226
|
+
Reason.WasmExecutorQuarantined,
|
|
227
|
+
"The component revision is quarantined after a trap",
|
|
228
|
+
),
|
|
222
229
|
}),
|
|
223
230
|
Unsupported: Object.freeze({
|
|
224
231
|
EngineEffect: define(
|