@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
package/src/embedded.ts
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import type { HostOptions } from "./authoring/types.ts";
|
|
2
|
-
import {
|
|
3
|
-
Code,
|
|
4
|
-
HookCapability,
|
|
5
|
-
Lifetime,
|
|
6
|
-
Reason,
|
|
7
|
-
ReloadStatus,
|
|
8
|
-
Status,
|
|
9
|
-
} from "./bridge/identifiers.ts";
|
|
10
|
-
import { jsonCodec } from "./codecs/json.ts";
|
|
11
|
-
import { failure, TembraError } from "./error.ts";
|
|
12
|
-
import { ContextKey, ContextKind, opaqueFrom } from "./context-key.ts";
|
|
13
|
-
import { Errors } from "./errors.ts";
|
|
14
|
-
import { Host } from "./host.ts";
|
|
15
|
-
import { Context } from "./runtime/context.ts";
|
|
16
|
-
import { KernelOp } from "./bridge/protocol.ts";
|
|
17
|
-
import type { Invocation } from "./bridge/kernel.ts";
|
|
18
|
-
|
|
19
|
-
declare const Deno: {
|
|
20
|
-
core: {
|
|
21
|
-
ops: Record<string, (...args: any[]) => any>;
|
|
22
|
-
unrefOpPromise(promise: Promise<unknown>): void;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
const ops = Deno.core.ops;
|
|
26
|
-
const globals = globalThis as any;
|
|
27
|
-
|
|
28
|
-
// Embedded V8 has no browser or Node dependency. Scheduling belongs to this adapter.
|
|
29
|
-
globals.queueMicrotask ??= (callback: () => void) => Promise.resolve().then(callback);
|
|
30
|
-
globals.performance ??= {
|
|
31
|
-
/** Use the Rust runtime's monotonic clock. */
|
|
32
|
-
now: () => ops.op_tembra_now!(),
|
|
33
|
-
};
|
|
34
|
-
globals.AbortController ??= class {
|
|
35
|
-
signal = {
|
|
36
|
-
aborted: false,
|
|
37
|
-
reason: undefined as unknown,
|
|
38
|
-
listeners: new Set<any>(),
|
|
39
|
-
/** Retain a cancellation listener until it is removed or fired. */
|
|
40
|
-
addEventListener(_type: string, callback: any) {
|
|
41
|
-
this.listeners.add(callback);
|
|
42
|
-
},
|
|
43
|
-
/** Release a cancellation listener without invoking it. */
|
|
44
|
-
removeEventListener(_type: string, callback: any) {
|
|
45
|
-
this.listeners.delete(callback);
|
|
46
|
-
},
|
|
47
|
-
/** Reject work after cancellation has been signalled. */
|
|
48
|
-
throwIfAborted() {
|
|
49
|
-
if (this.aborted) throw this.reason;
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/** Signal cancellation once without waiting for physical work. */
|
|
54
|
-
abort(reason: unknown = new Error("Aborted")) {
|
|
55
|
-
if (this.signal.aborted) return;
|
|
56
|
-
this.signal.aborted = true;
|
|
57
|
-
this.signal.reason = reason;
|
|
58
|
-
for (const callback of [...this.signal.listeners]) callback();
|
|
59
|
-
this.signal.listeners.clear();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
let nextTimer = 0;
|
|
63
|
-
const timers = new Set<number>();
|
|
64
|
-
globals.setTimeout ??= (callback: (...args: unknown[]) => void, delay = 0, ...args: unknown[]) => {
|
|
65
|
-
const id = ++nextTimer;
|
|
66
|
-
timers.add(id);
|
|
67
|
-
void ops.op_tembra_sleep!(id, Math.max(0, Math.min(0x7fff_ffff, delay))).then(() => {
|
|
68
|
-
if (timers.delete(id)) callback(...args);
|
|
69
|
-
});
|
|
70
|
-
return id;
|
|
71
|
-
};
|
|
72
|
-
globals.clearTimeout ??= (id: number) => {
|
|
73
|
-
if (timers.delete(id)) ops.op_tembra_clear_timer!(id);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/** The same JS adapter used by Node and browsers, backed by injected Rust operations. */
|
|
77
|
-
function createHost(options: Omit<HostOptions, "kernel" | "native"> = {}): Host {
|
|
78
|
-
const codec = options.serialization ?? jsonCodec;
|
|
79
|
-
if (codec.id !== ops.op_tembra_codec!())
|
|
80
|
-
throw new TembraError(Errors.Conflict.Codec, "The Rust and JS host codecs must agree");
|
|
81
|
-
/** Decode native callback results with the agreed host codec. */
|
|
82
|
-
function answer(bytes: Uint8Array): any {
|
|
83
|
-
const envelope = codec.deserialize(bytes) as any;
|
|
84
|
-
if (envelope.error) throw new TembraError(envelope.error);
|
|
85
|
-
return envelope.ok;
|
|
86
|
-
}
|
|
87
|
-
const cooperative = ops.op_tembra_driver_enabled?.() ?? false;
|
|
88
|
-
const pending = new Map<
|
|
89
|
-
number,
|
|
90
|
-
{ resolve(value: unknown): void; reject(error: unknown): void }
|
|
91
|
-
>();
|
|
92
|
-
globals.__tembraDeliver = (batch: [number, Uint8Array | string, boolean][]) => {
|
|
93
|
-
for (const [id, payload, success] of batch) {
|
|
94
|
-
const waiter = pending.get(id);
|
|
95
|
-
if (!waiter) throw new Error("unknown native completion");
|
|
96
|
-
pending.delete(id);
|
|
97
|
-
try {
|
|
98
|
-
if (!success) throw new Error(payload as string);
|
|
99
|
-
waiter.resolve(answer(payload as Uint8Array));
|
|
100
|
-
} catch (error) {
|
|
101
|
-
waiter.reject(error);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
function submit(operation: string, payload: Uint8Array): Promise<any> {
|
|
106
|
-
const id = ops.op_tembra_submit!(operation, payload);
|
|
107
|
-
return new Promise((resolve, reject) => pending.set(id, { resolve, reject }));
|
|
108
|
-
}
|
|
109
|
-
const host = new Host({
|
|
110
|
-
...options,
|
|
111
|
-
clockOrigin: 0,
|
|
112
|
-
kernel: {
|
|
113
|
-
/** Exchange kernel metadata without encoding JS payload values. */
|
|
114
|
-
request: (metadata) => ops.op_tembra_kernel!(metadata),
|
|
115
|
-
},
|
|
116
|
-
native: {
|
|
117
|
-
...(cooperative
|
|
118
|
-
? {
|
|
119
|
-
admit: (reference: number, method: string, ctx: Context) => {
|
|
120
|
-
const result = JSON.parse(
|
|
121
|
-
ops.op_tembra_admit!(
|
|
122
|
-
JSON.stringify({
|
|
123
|
-
reference,
|
|
124
|
-
method,
|
|
125
|
-
root: ctx.root,
|
|
126
|
-
context: ctx.frame,
|
|
127
|
-
parent: ctx.invocation?.id,
|
|
128
|
-
}),
|
|
129
|
-
),
|
|
130
|
-
) as any;
|
|
131
|
-
if (result.error) throw new TembraError(result.error);
|
|
132
|
-
return result.ok;
|
|
133
|
-
},
|
|
134
|
-
finish: (call: number, now: number) => {
|
|
135
|
-
const result = JSON.parse(ops.op_tembra_finish!(call, String(now))) as any;
|
|
136
|
-
if (result.error) throw new TembraError(result.error);
|
|
137
|
-
return result.ok;
|
|
138
|
-
},
|
|
139
|
-
}
|
|
140
|
-
: {}),
|
|
141
|
-
rootEnded: (root) => ops.op_tembra_end_context!(root),
|
|
142
|
-
access: (orb, service, principal) =>
|
|
143
|
-
JSON.parse(ops.op_tembra_access!(orb, service, principal)) ?? undefined,
|
|
144
|
-
settled: () => ops.op_tembra_settled!(),
|
|
145
|
-
notify: (action) => ops.op_tembra_notify!(JSON.stringify(action)),
|
|
146
|
-
hasContribution: (operation) => ops.op_tembra_has_contribution?.(operation) ?? false,
|
|
147
|
-
contribute: async (operation, ctx, input) => {
|
|
148
|
-
const result = answer(
|
|
149
|
-
await ops.op_tembra_native!(
|
|
150
|
-
"contribute",
|
|
151
|
-
codec.serialize({
|
|
152
|
-
operation,
|
|
153
|
-
root: ctx.root,
|
|
154
|
-
frame: ctx.frame,
|
|
155
|
-
...(input === undefined ? {} : { input }),
|
|
156
|
-
}),
|
|
157
|
-
),
|
|
158
|
-
);
|
|
159
|
-
return result.value;
|
|
160
|
-
},
|
|
161
|
-
/** Check whether this realm must delegate the orb to Rust. */
|
|
162
|
-
hasOrb: (id) => ops.op_tembra_has_orb!(id),
|
|
163
|
-
/** Declare native scopes before the shared kernel activates them. */
|
|
164
|
-
activate: async (object, orb, service) => {
|
|
165
|
-
answer(await ops.op_tembra_native!("activate", codec.serialize({ object, orb, service })));
|
|
166
|
-
},
|
|
167
|
-
/** Encode only the call arguments that cross into Rust. */
|
|
168
|
-
invoke: async (invocation, arguments_) =>
|
|
169
|
-
cooperative
|
|
170
|
-
? submit("invoke", codec.serialize({ invocation, arguments: arguments_ }))
|
|
171
|
-
: answer(
|
|
172
|
-
await ops.op_tembra_native!(
|
|
173
|
-
"invoke",
|
|
174
|
-
codec.serialize({ invocation, arguments: arguments_ }),
|
|
175
|
-
),
|
|
176
|
-
),
|
|
177
|
-
/** Release native object storage after shared scope cleanup. */
|
|
178
|
-
dispose: async (object) => {
|
|
179
|
-
answer(await ops.op_tembra_native!("dispose", codec.serialize({ object })));
|
|
180
|
-
},
|
|
181
|
-
/** Delegate callback execution while Rust retains lifecycle ordering. */
|
|
182
|
-
effect: async (effect) =>
|
|
183
|
-
answer(await ops.op_tembra_native!("effect", codec.serialize(effect))),
|
|
184
|
-
/** Signal native cancellation without acknowledging physical settlement. */
|
|
185
|
-
cancelEffect: async (effect) => {
|
|
186
|
-
answer(await ops.op_tembra_native!("cancel-effect", codec.serialize(effect)));
|
|
187
|
-
},
|
|
188
|
-
/** Decode one native bridge value with the agreed codec. */
|
|
189
|
-
value: (id) => answer(ops.op_tembra_value!(id)),
|
|
190
|
-
/** Release the native value selected by a kernel action. */
|
|
191
|
-
dropValue: (id) => ops.op_tembra_drop_value!(id),
|
|
192
|
-
},
|
|
193
|
-
});
|
|
194
|
-
if (ops.op_tembra_callback_next) {
|
|
195
|
-
// Receiving is idle infrastructure; each callback is separately tracked physical work.
|
|
196
|
-
void (async () => {
|
|
197
|
-
for (;;) {
|
|
198
|
-
const receiving = ops.op_tembra_callback_next!();
|
|
199
|
-
Deno.core.unrefOpPromise(receiving);
|
|
200
|
-
const packet = (await receiving) as Uint8Array;
|
|
201
|
-
if (!packet.length) return;
|
|
202
|
-
const header = new DataView(packet.buffer, packet.byteOffset, 9);
|
|
203
|
-
const kind = header.getUint8(0);
|
|
204
|
-
const id = header.getUint32(1, true) + header.getUint32(5, true) * 2 ** 32;
|
|
205
|
-
if (kind !== 0) {
|
|
206
|
-
if (kind === 2) host.session.calls.releaseRoot(id);
|
|
207
|
-
if (kind === 3) host.session.handles.revoke(id);
|
|
208
|
-
host.session.lifecycle.flush();
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
let request: any;
|
|
212
|
-
try {
|
|
213
|
-
request = codec.deserialize(packet.subarray(9));
|
|
214
|
-
} catch (error) {
|
|
215
|
-
const { code, reason, message } = failure(error);
|
|
216
|
-
ops.op_tembra_callback_error!(id, JSON.stringify({ code, reason, message }), true);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
host.session.track(
|
|
220
|
-
(async () => {
|
|
221
|
-
let envelope: unknown;
|
|
222
|
-
try {
|
|
223
|
-
let result: unknown;
|
|
224
|
-
if (request.kind === "activate") {
|
|
225
|
-
await host.session.handles.activateAcquired(
|
|
226
|
-
request.acquired,
|
|
227
|
-
request.address,
|
|
228
|
-
request.methods,
|
|
229
|
-
);
|
|
230
|
-
result = null;
|
|
231
|
-
} else {
|
|
232
|
-
const call = request.call;
|
|
233
|
-
const invocation = host.session.kernel.command<Invocation>(KernelOp.Invocation, {
|
|
234
|
-
call,
|
|
235
|
-
});
|
|
236
|
-
const ctx = new Context(host.session, invocation.root, invocation, request.frame);
|
|
237
|
-
if (request.kind === "invoke") {
|
|
238
|
-
const object = host.session.objects.get(invocation.object);
|
|
239
|
-
const environment = object?.versions.get(invocation.orb);
|
|
240
|
-
const handle =
|
|
241
|
-
environment?.orb.definition.services?.[object!.address.service]?.methods[
|
|
242
|
-
invocation.method
|
|
243
|
-
];
|
|
244
|
-
if (!handle || !environment) throw new TembraError(Errors.Gone.Implementation);
|
|
245
|
-
result = await host.session.calls.execute(() =>
|
|
246
|
-
handle(environment.value, ctx, ...request.input),
|
|
247
|
-
);
|
|
248
|
-
} else {
|
|
249
|
-
result = await host.session.orbs.runContribution(
|
|
250
|
-
request.operation,
|
|
251
|
-
ctx,
|
|
252
|
-
request.input,
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
envelope = result === undefined ? {} : { value: result };
|
|
257
|
-
} catch (error) {
|
|
258
|
-
const normalized = failure(error);
|
|
259
|
-
envelope = {
|
|
260
|
-
error: {
|
|
261
|
-
code: normalized.code,
|
|
262
|
-
reason: normalized.reason,
|
|
263
|
-
message: normalized.message,
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
try {
|
|
268
|
-
ops.op_tembra_callback_complete!(id, codec.serialize(envelope));
|
|
269
|
-
} catch (error) {
|
|
270
|
-
const { code, reason, message } = failure(error);
|
|
271
|
-
ops.op_tembra_callback_error!(id, JSON.stringify({ code, reason, message }), false);
|
|
272
|
-
}
|
|
273
|
-
})(),
|
|
274
|
-
true,
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
})();
|
|
278
|
-
}
|
|
279
|
-
return host;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
globals.Tembra = Object.freeze({
|
|
283
|
-
/** Drain terminal cleanup after the embedding has interrupted and unwound JavaScript. */
|
|
284
|
-
closeInterrupted: (host: Host) => {
|
|
285
|
-
host.session.kernel.command(KernelOp.Close);
|
|
286
|
-
host.session.calls.interrupt();
|
|
287
|
-
return host.close();
|
|
288
|
-
},
|
|
289
|
-
ContextKey,
|
|
290
|
-
ContextKind,
|
|
291
|
-
opaqueFrom,
|
|
292
|
-
createHost,
|
|
293
|
-
jsonCodec,
|
|
294
|
-
Code,
|
|
295
|
-
Reason,
|
|
296
|
-
Lifetime,
|
|
297
|
-
Status,
|
|
298
|
-
ReloadStatus,
|
|
299
|
-
HookCapability,
|
|
300
|
-
Errors,
|
|
301
|
-
});
|