@unicity-astrid/sdk 0.1.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 +120 -0
- package/dist/approval.d.ts +23 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +29 -0
- package/dist/approval.js.map +1 -0
- package/dist/capabilities.d.ts +14 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +19 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/capsule.d.ts +39 -0
- package/dist/capsule.d.ts.map +1 -0
- package/dist/capsule.js +67 -0
- package/dist/capsule.js.map +1 -0
- package/dist/contracts.d.ts +1104 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +1 -0
- package/dist/elicit.d.ts +30 -0
- package/dist/elicit.d.ts.map +1 -0
- package/dist/elicit.js +103 -0
- package/dist/elicit.js.map +1 -0
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +27 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +46 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +108 -0
- package/dist/errors.js.map +1 -0
- package/dist/fs.d.ts +135 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +257 -0
- package/dist/fs.js.map +1 -0
- package/dist/http.d.ts +90 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +276 -0
- package/dist/http.js.map +1 -0
- package/dist/identity.d.ts +46 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +69 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors.d.ts +21 -0
- package/dist/interceptors.d.ts.map +1 -0
- package/dist/interceptors.js +22 -0
- package/dist/interceptors.js.map +1 -0
- package/dist/ipc.d.ts +143 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +261 -0
- package/dist/ipc.js.map +1 -0
- package/dist/kv.d.ts +45 -0
- package/dist/kv.d.ts.map +1 -0
- package/dist/kv.js +91 -0
- package/dist/kv.js.map +1 -0
- package/dist/log.d.ts +17 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +40 -0
- package/dist/log.js.map +1 -0
- package/dist/net.d.ts +154 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +421 -0
- package/dist/net.js.map +1 -0
- package/dist/process.d.ts +77 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +128 -0
- package/dist/process.js.map +1 -0
- package/dist/runtime/bridge.d.ts +34 -0
- package/dist/runtime/bridge.d.ts.map +1 -0
- package/dist/runtime/bridge.js +326 -0
- package/dist/runtime/bridge.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/registry.d.ts +58 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/registry.js +129 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/runtime.d.ts +36 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +50 -0
- package/dist/runtime.js.map +1 -0
- package/dist/time.d.ts +29 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +43 -0
- package/dist/time.js.map +1 -0
- package/dist/tool.d.ts +48 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +86 -0
- package/dist/tool.js.map +1 -0
- package/dist/uplink.d.ts +27 -0
- package/dist/uplink.d.ts.map +1 -0
- package/dist/uplink.js +36 -0
- package/dist/uplink.js.map +1 -0
- package/package.json +38 -0
- package/src/approval.ts +38 -0
- package/src/capabilities.ts +22 -0
- package/src/capsule.ts +90 -0
- package/src/contracts.ts +1189 -0
- package/src/elicit.ts +136 -0
- package/src/env.ts +31 -0
- package/src/errors.ts +122 -0
- package/src/fs.ts +357 -0
- package/src/http.ts +345 -0
- package/src/identity.ts +101 -0
- package/src/index.ts +83 -0
- package/src/interceptors.ts +25 -0
- package/src/ipc.ts +354 -0
- package/src/kv.ts +123 -0
- package/src/log.ts +43 -0
- package/src/net.ts +545 -0
- package/src/process.ts +205 -0
- package/src/runtime/bridge.ts +374 -0
- package/src/runtime/index.ts +11 -0
- package/src/runtime/registry.ts +178 -0
- package/src/runtime.ts +70 -0
- package/src/time.ts +48 -0
- package/src/tool.ts +125 -0
- package/src/uplink.ts +49 -0
- package/src/wit-imports.d.ts +689 -0
- package/wit-contracts/astrid-contracts.wit +1266 -0
package/dist/net.js
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Networking — Unix domain sockets, outbound TCP, inbound TCP listeners,
|
|
3
|
+
* UDP, and DNS. Mirrors `astrid_sdk::net`. The kernel pre-binds a single
|
|
4
|
+
* Unix-domain listener per capsule; outbound TCP and UDP are gated by
|
|
5
|
+
* `net_connect` / `net_udp` allowlists and run through the SSRF airlock.
|
|
6
|
+
*
|
|
7
|
+
* Resource handles ({@link UnixListener}, {@link TcpListener}, {@link TcpStream},
|
|
8
|
+
* {@link UdpSocket}) are Component Model resources with automatic Drop. Use
|
|
9
|
+
* `using` for scope-bound cleanup or call `.close()` explicitly.
|
|
10
|
+
*
|
|
11
|
+
* Per-capsule caps: 8 concurrent TCP streams, 4 UDP sockets, 4 TCP listeners.
|
|
12
|
+
*/
|
|
13
|
+
import { bindUnix as hostBindUnix, bindTcp as hostBindTcp, connectTcp as hostConnectTcp, udpBind as hostUdpBind, lookupHost as hostLookupHost, } from "astrid:net/host@1.0.0";
|
|
14
|
+
import { SysError, callHost } from "./errors.js";
|
|
15
|
+
import { sleepMs as hostSleepMs } from "./time.js";
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// mpsc-shaped errors (preserved from pre-migration API)
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
export class RecvError extends Error {
|
|
20
|
+
name = "RecvError";
|
|
21
|
+
code = "EPIPE";
|
|
22
|
+
constructor() {
|
|
23
|
+
super("stream closed");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class SendError extends Error {
|
|
27
|
+
name = "SendError";
|
|
28
|
+
code = "EPIPE";
|
|
29
|
+
constructor() {
|
|
30
|
+
super("stream closed");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Internal helpers
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
function toHostTimeout(timeoutMs) {
|
|
37
|
+
if (timeoutMs === undefined)
|
|
38
|
+
return undefined;
|
|
39
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
40
|
+
throw SysError.api(`timeout must be a positive integer (got ${timeoutMs}); use undefined to clear`);
|
|
41
|
+
}
|
|
42
|
+
return BigInt(Math.floor(timeoutMs));
|
|
43
|
+
}
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Listener handles
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
/** The capsule's pre-bound Unix domain listener. Activated by {@link bindUnix}. */
|
|
48
|
+
export class UnixListener {
|
|
49
|
+
#inner;
|
|
50
|
+
constructor(inner) {
|
|
51
|
+
this.#inner = inner;
|
|
52
|
+
}
|
|
53
|
+
/** Blocking accept. Performs peer-credential verification + session token handshake. */
|
|
54
|
+
accept() {
|
|
55
|
+
const inner = callHost("net.UnixListener.accept", () => this.#requireInner().accept());
|
|
56
|
+
return new TcpStream(inner);
|
|
57
|
+
}
|
|
58
|
+
/** Polling accept with caller-controlled timeout. Returns `undefined` if none arrived. */
|
|
59
|
+
pollAccept(timeoutMs) {
|
|
60
|
+
const ms = toHostTimeout(timeoutMs) ?? 0n;
|
|
61
|
+
const inner = callHost(`net.UnixListener.pollAccept(${timeoutMs}ms)`, () => this.#requireInner().pollAccept(ms));
|
|
62
|
+
return inner === undefined ? undefined : new TcpStream(inner);
|
|
63
|
+
}
|
|
64
|
+
close() {
|
|
65
|
+
if (this.#inner === undefined)
|
|
66
|
+
return;
|
|
67
|
+
const inner = this.#inner;
|
|
68
|
+
this.#inner = undefined;
|
|
69
|
+
try {
|
|
70
|
+
inner[Symbol.dispose]();
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// already released
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
[Symbol.dispose]() {
|
|
77
|
+
this.close();
|
|
78
|
+
}
|
|
79
|
+
#requireInner() {
|
|
80
|
+
if (this.#inner === undefined)
|
|
81
|
+
throw SysError.api("UnixListener is closed");
|
|
82
|
+
return this.#inner;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** A bound TCP listener accepting inbound network connections. Per-capsule cap: 4. */
|
|
86
|
+
export class TcpListener {
|
|
87
|
+
#inner;
|
|
88
|
+
constructor(inner) {
|
|
89
|
+
this.#inner = inner;
|
|
90
|
+
}
|
|
91
|
+
/** Blocking accept. */
|
|
92
|
+
accept() {
|
|
93
|
+
const inner = callHost("net.TcpListener.accept", () => this.#requireInner().accept());
|
|
94
|
+
return new TcpStream(inner);
|
|
95
|
+
}
|
|
96
|
+
/** Polling accept with caller-controlled timeout. */
|
|
97
|
+
pollAccept(timeoutMs) {
|
|
98
|
+
const ms = toHostTimeout(timeoutMs) ?? 0n;
|
|
99
|
+
const inner = callHost(`net.TcpListener.pollAccept(${timeoutMs}ms)`, () => this.#requireInner().pollAccept(ms));
|
|
100
|
+
return inner === undefined ? undefined : new TcpStream(inner);
|
|
101
|
+
}
|
|
102
|
+
localAddr() {
|
|
103
|
+
return callHost("net.TcpListener.localAddr", () => this.#requireInner().localAddr());
|
|
104
|
+
}
|
|
105
|
+
close() {
|
|
106
|
+
if (this.#inner === undefined)
|
|
107
|
+
return;
|
|
108
|
+
const inner = this.#inner;
|
|
109
|
+
this.#inner = undefined;
|
|
110
|
+
try {
|
|
111
|
+
inner[Symbol.dispose]();
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// already released
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
[Symbol.dispose]() {
|
|
118
|
+
this.close();
|
|
119
|
+
}
|
|
120
|
+
#requireInner() {
|
|
121
|
+
if (this.#inner === undefined)
|
|
122
|
+
throw SysError.api("TcpListener is closed");
|
|
123
|
+
return this.#inner;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// TCP stream — bidirectional resource used for both Unix-domain and TCP
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
export class TcpStream {
|
|
130
|
+
#inner;
|
|
131
|
+
constructor(inner) {
|
|
132
|
+
this.#inner = inner;
|
|
133
|
+
}
|
|
134
|
+
// ---- Length-prefixed framed I/O (uplink-proxy use case) -----------------
|
|
135
|
+
/** Non-blocking framed read. Returns Data/Closed/Pending. Max frame: 10 MB. */
|
|
136
|
+
tryRecv() {
|
|
137
|
+
const status = callHost("net.TcpStream.tryRecv", () => this.#requireInner().read());
|
|
138
|
+
switch (status.tag) {
|
|
139
|
+
case "data":
|
|
140
|
+
return status.val;
|
|
141
|
+
case "pending":
|
|
142
|
+
return { kind: "empty" };
|
|
143
|
+
case "closed":
|
|
144
|
+
this.close();
|
|
145
|
+
throw new RecvError();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Blocking framed receive. Spins on `tryRecv` with a 50 ms sleep between
|
|
150
|
+
* polls; StarlingMonkey's syncify makes this a real blocking call from the
|
|
151
|
+
* host's POV. Mirrors the Rust SDK polling-loop shape.
|
|
152
|
+
*/
|
|
153
|
+
recv() {
|
|
154
|
+
while (true) {
|
|
155
|
+
const result = this.tryRecv();
|
|
156
|
+
if (result instanceof Uint8Array)
|
|
157
|
+
return result;
|
|
158
|
+
sleepMs(50);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Write a length-prefixed frame. */
|
|
162
|
+
send(data) {
|
|
163
|
+
try {
|
|
164
|
+
callHost("net.TcpStream.send", () => this.#requireInner().write(data));
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
// Map host errors on send to SendError to mirror Rust SDK.
|
|
168
|
+
if (err instanceof SysError)
|
|
169
|
+
throw new SendError();
|
|
170
|
+
throw err;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// ---- Byte-stream I/O ----------------------------------------------------
|
|
174
|
+
/**
|
|
175
|
+
* Read up to `maxBytes` without length-prefix framing. Empty array = EOF.
|
|
176
|
+
* Honours any timeout set via {@link setReadTimeout}.
|
|
177
|
+
*/
|
|
178
|
+
readBytes(maxBytes) {
|
|
179
|
+
return callHost(`net.TcpStream.readBytes(${maxBytes})`, () => this.#requireInner().readBytes(maxBytes));
|
|
180
|
+
}
|
|
181
|
+
/** Write `data` without framing. Returns bytes written (may be less than `data.length`). */
|
|
182
|
+
writeBytes(data) {
|
|
183
|
+
return callHost("net.TcpStream.writeBytes", () => this.#requireInner().writeBytes(data));
|
|
184
|
+
}
|
|
185
|
+
/** Peek up to `maxBytes` without consuming them. */
|
|
186
|
+
peek(maxBytes) {
|
|
187
|
+
return callHost(`net.TcpStream.peek(${maxBytes})`, () => this.#requireInner().peek(maxBytes));
|
|
188
|
+
}
|
|
189
|
+
/** Half-close the read side, write side, or both. */
|
|
190
|
+
shutdown(how) {
|
|
191
|
+
callHost(`net.TcpStream.shutdown(${how})`, () => this.#requireInner().shutdown(how));
|
|
192
|
+
}
|
|
193
|
+
// ---- Address accessors --------------------------------------------------
|
|
194
|
+
/** Remote peer address as `"ip:port"`. Returns `not-tcp` for Unix-domain streams. */
|
|
195
|
+
peerAddr() {
|
|
196
|
+
return callHost("net.TcpStream.peerAddr", () => this.#requireInner().peerAddr());
|
|
197
|
+
}
|
|
198
|
+
/** Local socket address as `"ip:port"`. */
|
|
199
|
+
localAddr() {
|
|
200
|
+
return callHost("net.TcpStream.localAddr", () => this.#requireInner().localAddr());
|
|
201
|
+
}
|
|
202
|
+
// ---- TCP socket options -------------------------------------------------
|
|
203
|
+
setNodelay(nodelay) {
|
|
204
|
+
callHost(`net.TcpStream.setNodelay(${nodelay})`, () => this.#requireInner().setNodelay(nodelay));
|
|
205
|
+
}
|
|
206
|
+
nodelay() {
|
|
207
|
+
return callHost("net.TcpStream.nodelay", () => this.#requireInner().nodelay());
|
|
208
|
+
}
|
|
209
|
+
setReadTimeout(timeoutMs) {
|
|
210
|
+
const ms = toHostTimeout(timeoutMs);
|
|
211
|
+
callHost(`net.TcpStream.setReadTimeout(${timeoutMs})`, () => this.#requireInner().setReadTimeout(ms));
|
|
212
|
+
}
|
|
213
|
+
readTimeout() {
|
|
214
|
+
const v = callHost("net.TcpStream.readTimeout", () => this.#requireInner().readTimeout());
|
|
215
|
+
return v === undefined ? undefined : Number(v);
|
|
216
|
+
}
|
|
217
|
+
setWriteTimeout(timeoutMs) {
|
|
218
|
+
const ms = toHostTimeout(timeoutMs);
|
|
219
|
+
callHost(`net.TcpStream.setWriteTimeout(${timeoutMs})`, () => this.#requireInner().setWriteTimeout(ms));
|
|
220
|
+
}
|
|
221
|
+
writeTimeout() {
|
|
222
|
+
const v = callHost("net.TcpStream.writeTimeout", () => this.#requireInner().writeTimeout());
|
|
223
|
+
return v === undefined ? undefined : Number(v);
|
|
224
|
+
}
|
|
225
|
+
/** IPv6 hop limit / IPv4 TTL. */
|
|
226
|
+
setHopLimit(hops) {
|
|
227
|
+
callHost(`net.TcpStream.setHopLimit(${hops})`, () => this.#requireInner().setHopLimit(hops));
|
|
228
|
+
}
|
|
229
|
+
hopLimit() {
|
|
230
|
+
return callHost("net.TcpStream.hopLimit", () => this.#requireInner().hopLimit());
|
|
231
|
+
}
|
|
232
|
+
/** TCP keepalive probe interval in seconds (`undefined` disables). */
|
|
233
|
+
setKeepalive(keepaliveSecs) {
|
|
234
|
+
const v = keepaliveSecs === undefined ? undefined : BigInt(Math.max(0, Math.floor(keepaliveSecs)));
|
|
235
|
+
callHost(`net.TcpStream.setKeepalive(${keepaliveSecs})`, () => this.#requireInner().setKeepalive(v));
|
|
236
|
+
}
|
|
237
|
+
keepalive() {
|
|
238
|
+
const v = callHost("net.TcpStream.keepalive", () => this.#requireInner().keepalive());
|
|
239
|
+
return v === undefined ? undefined : Number(v);
|
|
240
|
+
}
|
|
241
|
+
/** SO_LINGER. `undefined` = default; `0` = immediate RST; otherwise drain time in ms. */
|
|
242
|
+
setLinger(lingerMs) {
|
|
243
|
+
const v = lingerMs === undefined ? undefined : BigInt(Math.max(0, Math.floor(lingerMs)));
|
|
244
|
+
callHost(`net.TcpStream.setLinger(${lingerMs})`, () => this.#requireInner().setLinger(v));
|
|
245
|
+
}
|
|
246
|
+
linger() {
|
|
247
|
+
const v = callHost("net.TcpStream.linger", () => this.#requireInner().linger());
|
|
248
|
+
return v === undefined ? undefined : Number(v);
|
|
249
|
+
}
|
|
250
|
+
setReuseaddr(reuse) {
|
|
251
|
+
callHost(`net.TcpStream.setReuseaddr(${reuse})`, () => this.#requireInner().setReuseaddr(reuse));
|
|
252
|
+
}
|
|
253
|
+
reuseaddr() {
|
|
254
|
+
return callHost("net.TcpStream.reuseaddr", () => this.#requireInner().reuseaddr());
|
|
255
|
+
}
|
|
256
|
+
// ---- Lifecycle ----------------------------------------------------------
|
|
257
|
+
close() {
|
|
258
|
+
if (this.#inner === undefined)
|
|
259
|
+
return;
|
|
260
|
+
const inner = this.#inner;
|
|
261
|
+
this.#inner = undefined;
|
|
262
|
+
try {
|
|
263
|
+
inner[Symbol.dispose]();
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
// already released
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
[Symbol.dispose]() {
|
|
270
|
+
this.close();
|
|
271
|
+
}
|
|
272
|
+
/** Async iterator yielding each frame until the peer closes. */
|
|
273
|
+
async *[Symbol.asyncIterator]() {
|
|
274
|
+
try {
|
|
275
|
+
while (this.#inner !== undefined) {
|
|
276
|
+
try {
|
|
277
|
+
yield this.recv();
|
|
278
|
+
}
|
|
279
|
+
catch (err) {
|
|
280
|
+
if (err instanceof RecvError)
|
|
281
|
+
return;
|
|
282
|
+
throw err;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
this.close();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
#requireInner() {
|
|
291
|
+
if (this.#inner === undefined)
|
|
292
|
+
throw SysError.api("TcpStream is closed");
|
|
293
|
+
return this.#inner;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// ---------------------------------------------------------------------------
|
|
297
|
+
// UDP socket
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
/**
|
|
300
|
+
* UDP datagram socket. Two modes: unconnected (`sendTo`/`recvFrom`) and
|
|
301
|
+
* connected (`connect` + `send`/`recv`). Per-capsule cap: 4.
|
|
302
|
+
*/
|
|
303
|
+
export class UdpSocket {
|
|
304
|
+
#inner;
|
|
305
|
+
constructor(inner) {
|
|
306
|
+
this.#inner = inner;
|
|
307
|
+
}
|
|
308
|
+
sendTo(data, peerHost, peerPort) {
|
|
309
|
+
return callHost(`net.UdpSocket.sendTo(${peerHost}:${peerPort})`, () => this.#requireInner().sendTo(data, peerHost, peerPort));
|
|
310
|
+
}
|
|
311
|
+
recvFrom(maxBytes) {
|
|
312
|
+
return callHost(`net.UdpSocket.recvFrom(${maxBytes})`, () => this.#requireInner().recvFrom(maxBytes));
|
|
313
|
+
}
|
|
314
|
+
connect(peerHost, peerPort) {
|
|
315
|
+
callHost(`net.UdpSocket.connect(${peerHost}:${peerPort})`, () => this.#requireInner().connect(peerHost, peerPort));
|
|
316
|
+
}
|
|
317
|
+
disconnect() {
|
|
318
|
+
callHost("net.UdpSocket.disconnect", () => this.#requireInner().disconnect());
|
|
319
|
+
}
|
|
320
|
+
send(data) {
|
|
321
|
+
return callHost("net.UdpSocket.send", () => this.#requireInner().send(data));
|
|
322
|
+
}
|
|
323
|
+
recv(maxBytes) {
|
|
324
|
+
return callHost(`net.UdpSocket.recv(${maxBytes})`, () => this.#requireInner().recv(maxBytes));
|
|
325
|
+
}
|
|
326
|
+
peerAddr() {
|
|
327
|
+
return callHost("net.UdpSocket.peerAddr", () => this.#requireInner().peerAddr());
|
|
328
|
+
}
|
|
329
|
+
setReadTimeout(timeoutMs) {
|
|
330
|
+
const ms = toHostTimeout(timeoutMs);
|
|
331
|
+
callHost(`net.UdpSocket.setReadTimeout(${timeoutMs})`, () => this.#requireInner().setReadTimeout(ms));
|
|
332
|
+
}
|
|
333
|
+
localAddr() {
|
|
334
|
+
return callHost("net.UdpSocket.localAddr", () => this.#requireInner().localAddr());
|
|
335
|
+
}
|
|
336
|
+
close() {
|
|
337
|
+
if (this.#inner === undefined)
|
|
338
|
+
return;
|
|
339
|
+
const inner = this.#inner;
|
|
340
|
+
this.#inner = undefined;
|
|
341
|
+
try {
|
|
342
|
+
inner[Symbol.dispose]();
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
// already released
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
[Symbol.dispose]() {
|
|
349
|
+
this.close();
|
|
350
|
+
}
|
|
351
|
+
#requireInner() {
|
|
352
|
+
if (this.#inner === undefined)
|
|
353
|
+
throw SysError.api("UdpSocket is closed");
|
|
354
|
+
return this.#inner;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
// Pre-migration handle types preserved for source-compatibility — these are
|
|
359
|
+
// now just type aliases over the resource-backed classes above. Callers using
|
|
360
|
+
// the legacy names (`StreamHandle`, `ListenerHandle`) continue to compile.
|
|
361
|
+
// ---------------------------------------------------------------------------
|
|
362
|
+
export { TcpStream as StreamHandle, UnixListener as ListenerHandle };
|
|
363
|
+
// ---------------------------------------------------------------------------
|
|
364
|
+
// Factory functions
|
|
365
|
+
// ---------------------------------------------------------------------------
|
|
366
|
+
/** Bind the kernel-pre-provisioned Unix socket and return a listener. */
|
|
367
|
+
export function bindUnix() {
|
|
368
|
+
const inner = callHost("net.bindUnix", () => hostBindUnix());
|
|
369
|
+
return new UnixListener(inner);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Bind a TCP listener for inbound connections. Gated by `net_tcp_bind`. Port
|
|
373
|
+
* 0 selects an ephemeral port.
|
|
374
|
+
*/
|
|
375
|
+
export function bindTcp(host, port) {
|
|
376
|
+
const inner = callHost(`net.bindTcp(${host}:${port})`, () => hostBindTcp(host, port));
|
|
377
|
+
return new TcpListener(inner);
|
|
378
|
+
}
|
|
379
|
+
/** Block until the next incoming connection on the Unix listener. */
|
|
380
|
+
export function accept(listener) {
|
|
381
|
+
return listener.accept();
|
|
382
|
+
}
|
|
383
|
+
/** Non-blocking accept. Returns `undefined` if none ready. */
|
|
384
|
+
export function tryAccept(listener) {
|
|
385
|
+
return listener.pollAccept(0);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Open an outbound TCP connection to `host:port`. Goes through the SSRF
|
|
389
|
+
* airlock (rejects private/loopback/etc.) and the `net_connect` allowlist.
|
|
390
|
+
*/
|
|
391
|
+
export function connect(host, port) {
|
|
392
|
+
const inner = callHost(`net.connect(${host}:${port})`, () => hostConnectTcp(host, port));
|
|
393
|
+
return new TcpStream(inner);
|
|
394
|
+
}
|
|
395
|
+
/** Alias for {@link connect} matching the WIT name. */
|
|
396
|
+
export const connectTcp = connect;
|
|
397
|
+
/** Bind a UDP socket. */
|
|
398
|
+
export function udpBind(host, port) {
|
|
399
|
+
const inner = callHost(`net.udpBind(${host}:${port})`, () => hostUdpBind(host, port));
|
|
400
|
+
return new UdpSocket(inner);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Resolve a hostname to a list of `"ip:port"` (or `"ip"` if no port in input)
|
|
404
|
+
* strings. SSRF airlock applies — private/loopback/etc. ranges stripped.
|
|
405
|
+
*/
|
|
406
|
+
export function lookupHost(host) {
|
|
407
|
+
return callHost(`net.lookupHost(${host})`, () => hostLookupHost(host));
|
|
408
|
+
}
|
|
409
|
+
// ---------------------------------------------------------------------------
|
|
410
|
+
// Sleep shim — used by the polling recv loop
|
|
411
|
+
// ---------------------------------------------------------------------------
|
|
412
|
+
/**
|
|
413
|
+
* 50 ms host-mediated sleep. Routes through `astrid:sys/host.sleep-ns`
|
|
414
|
+
* so the kernel can cancel the wait when the capsule unloads and
|
|
415
|
+
* account for the wait in audit. Mirrors the Rust SDK switch from
|
|
416
|
+
* `std::thread::sleep` to `crate::time::sleep`.
|
|
417
|
+
*/
|
|
418
|
+
function sleepMs(ms) {
|
|
419
|
+
hostSleepMs(ms);
|
|
420
|
+
}
|
|
421
|
+
//# sourceMappingURL=net.js.map
|
package/dist/net.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"net.js","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,QAAQ,IAAI,YAAY,EACxB,OAAO,IAAI,WAAW,EACtB,UAAU,IAAI,cAAc,EAC5B,OAAO,IAAI,WAAW,EACtB,UAAU,IAAI,cAAc,GAQ7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAInD,8EAA8E;AAC9E,wDAAwD;AACxD,8EAA8E;AAE9E,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChB,IAAI,GAAG,WAAW,CAAC;IAC5B,IAAI,GAAG,OAAgB,CAAC;IACjC;QACE,KAAK,CAAC,eAAe,CAAC,CAAC;IACzB,CAAC;CACF;AAMD,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChB,IAAI,GAAG,WAAW,CAAC;IAC5B,IAAI,GAAG,OAAg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77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host process spawning. Mirrors `astrid_sdk::process`. Capsules need the
|
|
3
|
+
* `host_process` capability for the specific command being invoked; the
|
|
4
|
+
* kernel runs the process under platform sandboxing (sandbox-exec on macOS,
|
|
5
|
+
* bwrap on Linux).
|
|
6
|
+
*
|
|
7
|
+
* Per-capsule cap: 8 concurrent background processes. `ProcessHandle` is a
|
|
8
|
+
* Component Model resource — drop releases the slot and reaps the child.
|
|
9
|
+
*
|
|
10
|
+
* **Desktop-kernel only.** Unikernel targets (hermit-rs, etc.) do not implement
|
|
11
|
+
* this package; capsules importing `astrid:process` will fail to load there.
|
|
12
|
+
*/
|
|
13
|
+
import { type ProcessHandle as WitProcessHandle, type ProcessSignal } from "astrid:process/host@1.0.0";
|
|
14
|
+
export type { ProcessSignal, EnvVar } from "astrid:process/host@1.0.0";
|
|
15
|
+
export interface ProcessResult {
|
|
16
|
+
stdout: string;
|
|
17
|
+
stderr: string;
|
|
18
|
+
/** Exit code if exited normally; `undefined` if killed by signal. */
|
|
19
|
+
exitCode: number | undefined;
|
|
20
|
+
/** Unix signal number if killed by signal; `undefined` otherwise. */
|
|
21
|
+
signal: number | undefined;
|
|
22
|
+
}
|
|
23
|
+
export interface ProcessLogs {
|
|
24
|
+
stdout: string;
|
|
25
|
+
stderr: string;
|
|
26
|
+
running: boolean;
|
|
27
|
+
exitCode: number | undefined;
|
|
28
|
+
signal: number | undefined;
|
|
29
|
+
}
|
|
30
|
+
export interface KillResult {
|
|
31
|
+
killed: boolean;
|
|
32
|
+
exitCode: number | undefined;
|
|
33
|
+
signal: number | undefined;
|
|
34
|
+
stdout: string;
|
|
35
|
+
stderr: string;
|
|
36
|
+
}
|
|
37
|
+
export interface SpawnOptions {
|
|
38
|
+
/** Working directory relative to the workspace. */
|
|
39
|
+
cwd?: string;
|
|
40
|
+
/** Environment variables to pass to the child. */
|
|
41
|
+
env?: Record<string, string>;
|
|
42
|
+
/** Stdin bytes piped to the child on spawn. */
|
|
43
|
+
stdin?: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
/** Spawn a process and block until it exits. */
|
|
46
|
+
export declare function spawn(cmd: string, args?: string[], options?: SpawnOptions): ProcessResult;
|
|
47
|
+
/** Spawn a background process. Returns a resource handle. */
|
|
48
|
+
export declare function spawnBackground(cmd: string, args?: string[], options?: SpawnOptions): BackgroundProcessHandle;
|
|
49
|
+
export declare class BackgroundProcessHandle {
|
|
50
|
+
#private;
|
|
51
|
+
constructor(inner: WitProcessHandle);
|
|
52
|
+
/** Drain buffered stdout/stderr since the last read. */
|
|
53
|
+
readLogs(): ProcessLogs;
|
|
54
|
+
/** Write to stdin. Returns bytes actually written. */
|
|
55
|
+
writeStdin(data: Uint8Array): number;
|
|
56
|
+
/** Close the stdin pipe (child observes EOF). */
|
|
57
|
+
closeStdin(): void;
|
|
58
|
+
/** Send a signal (fire-and-forget). Use {@link kill} for SIGKILL + log drainage. */
|
|
59
|
+
signal(sig: ProcessSignal): void;
|
|
60
|
+
/** Send SIGKILL and drain remaining output. */
|
|
61
|
+
kill(): KillResult;
|
|
62
|
+
/**
|
|
63
|
+
* Wait for the process to exit. `timeoutMs = undefined` waits indefinitely;
|
|
64
|
+
* a bounded value throws `wait-timeout` if the timeout elapses first.
|
|
65
|
+
*/
|
|
66
|
+
wait(timeoutMs?: number): {
|
|
67
|
+
exitCode: number | undefined;
|
|
68
|
+
signal: number | undefined;
|
|
69
|
+
};
|
|
70
|
+
/** Wait for the process AND drain remaining stdout/stderr atomically. */
|
|
71
|
+
waitWithOutput(timeoutMs?: number): ProcessResult;
|
|
72
|
+
/** OS-level PID. Throws if the process has already been reaped. */
|
|
73
|
+
osPid(): number;
|
|
74
|
+
close(): void;
|
|
75
|
+
[Symbol.dispose](): void;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../src/process.ts"],"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AE,MAAM,EAAO,EACnB,OAAO,CAAC,EAAE,YAAY,GACrB,uBAAuB,CAMzB;AAED,qBAAa,uBAAuB;;gBAGtB,KAAK,EAAE,gBAAgB;IAInC,wDAAwD;IACxD,QAAQ,IAAI,WAAW;IAWvB,sDAAsD;IACtD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAIpC,iDAAiD;IACjD,UAAU,IAAI,IAAI;IAIlB,oFAAoF;IACpF,MAAM,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI;IAIhC,+CAA+C;IAC/C,IAAI,IAAI,UAAU;IAWlB;;;OAGG;IACH,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;IAQtF,yEAAyE;IACzE,cAAc,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa;IAYjD,mEAAmE;IACnE,KAAK,IAAI,MAAM;IAIf,KAAK,IAAI,IAAI;IAWb,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAQzB"}
|
package/dist/process.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host process spawning. Mirrors `astrid_sdk::process`. Capsules need the
|
|
3
|
+
* `host_process` capability for the specific command being invoked; the
|
|
4
|
+
* kernel runs the process under platform sandboxing (sandbox-exec on macOS,
|
|
5
|
+
* bwrap on Linux).
|
|
6
|
+
*
|
|
7
|
+
* Per-capsule cap: 8 concurrent background processes. `ProcessHandle` is a
|
|
8
|
+
* Component Model resource — drop releases the slot and reaps the child.
|
|
9
|
+
*
|
|
10
|
+
* **Desktop-kernel only.** Unikernel targets (hermit-rs, etc.) do not implement
|
|
11
|
+
* this package; capsules importing `astrid:process` will fail to load there.
|
|
12
|
+
*/
|
|
13
|
+
import { spawn as hostSpawn, spawnBackground as hostSpawnBackground, } from "astrid:process/host@1.0.0";
|
|
14
|
+
import { SysError, callHost } from "./errors.js";
|
|
15
|
+
function buildSpawnRequest(cmd, args, options) {
|
|
16
|
+
return {
|
|
17
|
+
cmd,
|
|
18
|
+
args,
|
|
19
|
+
stdin: options?.stdin,
|
|
20
|
+
env: options?.env
|
|
21
|
+
? Object.entries(options.env).map(([key, value]) => ({ key, value }))
|
|
22
|
+
: [],
|
|
23
|
+
cwd: options?.cwd,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function unpackExit(exit) {
|
|
27
|
+
return { exitCode: exit.exitCode, signal: exit.signal };
|
|
28
|
+
}
|
|
29
|
+
/** Spawn a process and block until it exits. */
|
|
30
|
+
export function spawn(cmd, args = [], options) {
|
|
31
|
+
const request = buildSpawnRequest(cmd, args, options);
|
|
32
|
+
const result = callHost(`process.spawn(${JSON.stringify(cmd)})`, () => hostSpawn(request));
|
|
33
|
+
return {
|
|
34
|
+
stdout: result.stdout,
|
|
35
|
+
stderr: result.stderr,
|
|
36
|
+
...unpackExit(result.exit),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Spawn a background process. Returns a resource handle. */
|
|
40
|
+
export function spawnBackground(cmd, args = [], options) {
|
|
41
|
+
const request = buildSpawnRequest(cmd, args, options);
|
|
42
|
+
const inner = callHost(`process.spawnBackground(${JSON.stringify(cmd)})`, () => hostSpawnBackground(request));
|
|
43
|
+
return new BackgroundProcessHandle(inner);
|
|
44
|
+
}
|
|
45
|
+
export class BackgroundProcessHandle {
|
|
46
|
+
#inner;
|
|
47
|
+
constructor(inner) {
|
|
48
|
+
this.#inner = inner;
|
|
49
|
+
}
|
|
50
|
+
/** Drain buffered stdout/stderr since the last read. */
|
|
51
|
+
readLogs() {
|
|
52
|
+
const result = callHost("process.readLogs", () => this.#requireInner().readLogs());
|
|
53
|
+
return {
|
|
54
|
+
stdout: result.stdout,
|
|
55
|
+
stderr: result.stderr,
|
|
56
|
+
running: result.running,
|
|
57
|
+
exitCode: result.exit?.exitCode,
|
|
58
|
+
signal: result.exit?.signal,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Write to stdin. Returns bytes actually written. */
|
|
62
|
+
writeStdin(data) {
|
|
63
|
+
return callHost("process.writeStdin", () => this.#requireInner().writeStdin(data));
|
|
64
|
+
}
|
|
65
|
+
/** Close the stdin pipe (child observes EOF). */
|
|
66
|
+
closeStdin() {
|
|
67
|
+
callHost("process.closeStdin", () => this.#requireInner().closeStdin());
|
|
68
|
+
}
|
|
69
|
+
/** Send a signal (fire-and-forget). Use {@link kill} for SIGKILL + log drainage. */
|
|
70
|
+
signal(sig) {
|
|
71
|
+
callHost(`process.signal(${sig})`, () => this.#requireInner().signal(sig));
|
|
72
|
+
}
|
|
73
|
+
/** Send SIGKILL and drain remaining output. */
|
|
74
|
+
kill() {
|
|
75
|
+
const result = callHost("process.kill", () => this.#requireInner().kill());
|
|
76
|
+
return {
|
|
77
|
+
killed: result.killed,
|
|
78
|
+
stdout: result.stdout,
|
|
79
|
+
stderr: result.stderr,
|
|
80
|
+
exitCode: result.exit?.exitCode,
|
|
81
|
+
signal: result.exit?.signal,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Wait for the process to exit. `timeoutMs = undefined` waits indefinitely;
|
|
86
|
+
* a bounded value throws `wait-timeout` if the timeout elapses first.
|
|
87
|
+
*/
|
|
88
|
+
wait(timeoutMs) {
|
|
89
|
+
const ms = timeoutMs === undefined ? undefined : BigInt(Math.max(0, Math.floor(timeoutMs)));
|
|
90
|
+
const exit = callHost(`process.wait(${timeoutMs ?? "∞"})`, () => this.#requireInner().wait(ms));
|
|
91
|
+
return unpackExit(exit);
|
|
92
|
+
}
|
|
93
|
+
/** Wait for the process AND drain remaining stdout/stderr atomically. */
|
|
94
|
+
waitWithOutput(timeoutMs) {
|
|
95
|
+
const ms = timeoutMs === undefined ? undefined : BigInt(Math.max(0, Math.floor(timeoutMs)));
|
|
96
|
+
const result = callHost(`process.waitWithOutput(${timeoutMs ?? "∞"})`, () => this.#requireInner().waitWithOutput(ms));
|
|
97
|
+
return {
|
|
98
|
+
stdout: result.stdout,
|
|
99
|
+
stderr: result.stderr,
|
|
100
|
+
...unpackExit(result.exit),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** OS-level PID. Throws if the process has already been reaped. */
|
|
104
|
+
osPid() {
|
|
105
|
+
return callHost("process.osPid", () => this.#requireInner().osPid());
|
|
106
|
+
}
|
|
107
|
+
close() {
|
|
108
|
+
if (this.#inner === undefined)
|
|
109
|
+
return;
|
|
110
|
+
const inner = this.#inner;
|
|
111
|
+
this.#inner = undefined;
|
|
112
|
+
try {
|
|
113
|
+
inner[Symbol.dispose]();
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// already released
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
[Symbol.dispose]() {
|
|
120
|
+
this.close();
|
|
121
|
+
}
|
|
122
|
+
#requireInner() {
|
|
123
|
+
if (this.#inner === undefined)
|
|
124
|
+
throw SysError.api("ProcessHandle is closed");
|
|
125
|
+
return this.#inner;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,KAAK,IAAI,SAAS,EAClB,eAAe,IAAI,mBAAmB,GAKvC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAsCjD,SAAS,iBAAiB,CACxB,GAAW,EACX,IAAc,EACd,OAAiC;IAEjC,OAAO;QACL,GAAG;QACH,IAAI;QACJ,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,GAAG,EAAE,OAAO,EAAE,GAAG;YACf,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,C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