@standardagents/code-web 0.14.1-issue.663.fd4c3f → 0.14.4-branch.9e48e914.ee06ef

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +9 -1
  2. package/dist/build.json +1 -1
  3. package/dist/licenses/jco-transpile.txt +220 -0
  4. package/dist/manifest.json +1 -1
  5. package/dist/manifest.sig +1 -1
  6. package/dist/pkg/standard_web.d.ts +44 -6
  7. package/dist/pkg/standard_web.js +292 -20
  8. package/dist/pkg/standard_web_bg.wasm +0 -0
  9. package/dist/pkg/standard_web_bg.wasm.d.ts +11 -6
  10. package/dist/plugins/clock-cells/clock_cells.core.wasm +0 -0
  11. package/dist/plugins/clock-cells/clock_cells.wasm +0 -0
  12. package/dist/plugins/clock-cells/standard-plugin.json +11 -0
  13. package/dist/plugins/host/transpile.js +51 -0
  14. package/dist/plugins/host/ui-jspi.js +14851 -0
  15. package/dist/plugins/host/ui.core2.wasm +0 -0
  16. package/dist/plugins/host/ui.core3.wasm +0 -0
  17. package/dist/plugins/host/ui.js +14675 -0
  18. package/dist/plugins/host/world.js +172 -0
  19. package/dist/plugins/jco/cli.js +141 -0
  20. package/dist/plugins/jco/common.js +16 -0
  21. package/dist/plugins/jco/config.js +7 -0
  22. package/dist/plugins/jco/environment.js +24 -0
  23. package/dist/plugins/jco/filesystem.js +339 -0
  24. package/dist/plugins/jco/in-memory-filesystem.js +620 -0
  25. package/dist/plugins/jco/io.js +366 -0
  26. package/dist/plugins/jco/js-component-bindgen-component.core.wasm +0 -0
  27. package/dist/plugins/jco/js-component-bindgen-component.core2.wasm +0 -0
  28. package/dist/plugins/jco/js-component-bindgen-component.js +14272 -0
  29. package/dist/plugins/jco/opfs-filesystem.js +245 -0
  30. package/dist/plugins/jco/random.js +51 -0
  31. package/dist/plugins/plasma-pixels/plasma_pixels.core.wasm +0 -0
  32. package/dist/plugins/plasma-pixels/plasma_pixels.wasm +0 -0
  33. package/dist/plugins/plasma-pixels/standard-plugin.json +11 -0
  34. package/dist/plugins/runtime.js +1044 -0
  35. package/dist/plugins/samples.json +81 -0
  36. package/dist/plugins/worker.js +411 -0
  37. package/package.json +8 -2
@@ -0,0 +1,366 @@
1
+ import { checkedU64AsNumber } from "./common.js";
2
+ let id = 0;
3
+ const symbolDispose = Symbol.dispose || Symbol.for("dispose");
4
+ const checkedLength = (len, name = "length") => checkedU64AsNumber(len, name);
5
+ function closed() {
6
+ throw { tag: "closed" };
7
+ }
8
+ class IoError extends Error {
9
+ toDebugString() {
10
+ return this.message;
11
+ }
12
+ }
13
+ export const ioErrorCreate = (message) => new IoError(message);
14
+ class InputStream {
15
+ id;
16
+ handler;
17
+ #open = true;
18
+ #children = new Set();
19
+ static _create(handler) {
20
+ const stream = new InputStream();
21
+ if (!handler) {
22
+ console.trace("no handler");
23
+ }
24
+ stream.id = ++id;
25
+ stream.handler = handler;
26
+ return stream;
27
+ }
28
+ read(len) {
29
+ checkedLength(len);
30
+ if (!this.#open) {
31
+ closed();
32
+ }
33
+ if (this.handler.read) {
34
+ return this.handler.read.call(this, len);
35
+ }
36
+ return this.handler.blockingRead.call(this, len);
37
+ }
38
+ blockingRead(len) {
39
+ checkedLength(len);
40
+ if (!this.#open) {
41
+ closed();
42
+ }
43
+ return this.handler.blockingRead.call(this, len);
44
+ }
45
+ skip(len) {
46
+ checkedLength(len);
47
+ if (!this.#open) {
48
+ closed();
49
+ }
50
+ if (this.handler.skip) {
51
+ return this.handler.skip.call(this, len);
52
+ }
53
+ if (this.handler.read) {
54
+ const bytes = this.handler.read.call(this, len);
55
+ return BigInt(bytes.byteLength);
56
+ }
57
+ return this.blockingSkip.call(this, len);
58
+ }
59
+ blockingSkip(len) {
60
+ checkedLength(len);
61
+ if (!this.#open) {
62
+ closed();
63
+ }
64
+ if (this.handler.blockingSkip) {
65
+ return this.handler.blockingSkip.call(this, len);
66
+ }
67
+ const bytes = this.handler.blockingRead.call(this, len);
68
+ return BigInt(bytes.byteLength);
69
+ }
70
+ subscribe() {
71
+ if (!this.#open) {
72
+ return pollableCreate();
73
+ }
74
+ const pollable = this.handler.subscribe
75
+ ? this.handler.subscribe.call(this)
76
+ : pollableCreate();
77
+ if (pollable instanceof Pollable) {
78
+ this.#children.add(pollable);
79
+ pollable._onDispose(() => this.#children.delete(pollable));
80
+ }
81
+ return pollable;
82
+ }
83
+ [symbolDispose]() {
84
+ if (!this.#open) {
85
+ return;
86
+ }
87
+ this.#open = false;
88
+ for (const child of this.#children) {
89
+ child._invalidate();
90
+ }
91
+ this.#children.clear();
92
+ if (this.handler.drop) {
93
+ this.handler.drop.call(this);
94
+ }
95
+ }
96
+ }
97
+ export const inputStreamCreate = InputStream._create;
98
+ // @ts-expect-error - Deleting static method
99
+ delete InputStream._create;
100
+ class OutputStream {
101
+ id;
102
+ open;
103
+ handler;
104
+ #permit = 0n;
105
+ #children = new Set();
106
+ static _create(handler) {
107
+ const stream = new OutputStream();
108
+ if (!handler) {
109
+ console.trace("no handler");
110
+ }
111
+ stream.id = ++id;
112
+ stream.open = true;
113
+ stream.handler = handler;
114
+ return stream;
115
+ }
116
+ checkWrite() {
117
+ if (!this.open) {
118
+ closed();
119
+ }
120
+ if (this.handler.checkWrite) {
121
+ const permit = this.handler.checkWrite.call(this);
122
+ checkedLength(permit, "write permit");
123
+ this.#permit = permit;
124
+ return permit;
125
+ }
126
+ this.#permit = 1000000n;
127
+ return this.#permit;
128
+ }
129
+ write(buf) {
130
+ if (!this.open) {
131
+ closed();
132
+ }
133
+ if (BigInt(buf.byteLength) > this.#permit) {
134
+ throw new Error("write exceeds the permit returned by checkWrite");
135
+ }
136
+ this.#permit -= BigInt(buf.byteLength);
137
+ this.handler.write.call(this, buf);
138
+ }
139
+ blockingWriteAndFlush(buf) {
140
+ if (!this.open) {
141
+ closed();
142
+ }
143
+ if (buf.byteLength > 4096) {
144
+ throw new RangeError("blockingWriteAndFlush accepts at most 4096 bytes");
145
+ }
146
+ if (this.handler.blockingWriteAndFlush) {
147
+ return this.handler.blockingWriteAndFlush.call(this, buf);
148
+ }
149
+ this.handler.write.call(this, buf);
150
+ if (this.handler.blockingFlush) {
151
+ this.handler.blockingFlush.call(this);
152
+ }
153
+ else {
154
+ this.handler.flush?.call(this);
155
+ }
156
+ }
157
+ flush() {
158
+ if (!this.open) {
159
+ closed();
160
+ }
161
+ this.#permit = 0n;
162
+ if (this.handler.flush) {
163
+ this.handler.flush.call(this);
164
+ }
165
+ }
166
+ blockingFlush() {
167
+ if (!this.open) {
168
+ closed();
169
+ }
170
+ if (this.handler.blockingFlush) {
171
+ this.handler.blockingFlush.call(this);
172
+ }
173
+ else {
174
+ this.handler.flush?.call(this);
175
+ }
176
+ }
177
+ writeZeroes(len) {
178
+ const length = checkedLength(len);
179
+ if (len > this.#permit) {
180
+ throw new Error("write exceeds the permit returned by checkWrite");
181
+ }
182
+ this.write.call(this, new Uint8Array(length));
183
+ }
184
+ blockingWriteZeroesAndFlush(len) {
185
+ const length = checkedLength(len);
186
+ if (length > 4096) {
187
+ throw new RangeError("blockingWriteZeroesAndFlush accepts at most 4096 bytes");
188
+ }
189
+ this.blockingWriteAndFlush.call(this, new Uint8Array(length));
190
+ }
191
+ splice(src, len) {
192
+ const spliceLen = Math.min(checkedLength(len), Number(this.checkWrite.call(this)));
193
+ const bytes = src.read(BigInt(spliceLen));
194
+ this.write.call(this, bytes);
195
+ return BigInt(bytes.byteLength);
196
+ }
197
+ blockingSplice(src, len) {
198
+ const spliceLen = Math.min(checkedLength(len), Number(this.checkWrite.call(this)));
199
+ const bytes = src.blockingRead(BigInt(spliceLen));
200
+ this.write.call(this, bytes);
201
+ return BigInt(bytes.byteLength);
202
+ }
203
+ subscribe() {
204
+ if (!this.open) {
205
+ return pollableCreate();
206
+ }
207
+ const pollable = this.handler.subscribe
208
+ ? this.handler.subscribe.call(this)
209
+ : pollableCreate();
210
+ if (pollable instanceof Pollable) {
211
+ this.#children.add(pollable);
212
+ pollable._onDispose(() => this.#children.delete(pollable));
213
+ }
214
+ return pollable;
215
+ }
216
+ [symbolDispose]() {
217
+ if (!this.open) {
218
+ return;
219
+ }
220
+ this.open = false;
221
+ this.#permit = 0n;
222
+ for (const child of this.#children) {
223
+ child._invalidate();
224
+ }
225
+ this.#children.clear();
226
+ this.handler.drop?.call(this);
227
+ }
228
+ }
229
+ export const outputStreamCreate = OutputStream._create;
230
+ // @ts-expect-error - Deleting static method
231
+ delete OutputStream._create;
232
+ export const error = {
233
+ Error: IoError,
234
+ };
235
+ export const streams = { InputStream, OutputStream };
236
+ class Pollable {
237
+ #source = { ready: () => true, wait: () => Promise.resolve() };
238
+ #invalid = false;
239
+ #disposed = false;
240
+ #wait = null;
241
+ #disposeCallbacks = [];
242
+ #wakeUnusable;
243
+ #unusable = new Promise((resolve) => (this.#wakeUnusable = resolve));
244
+ static _create(source) {
245
+ const pollable = new Pollable();
246
+ if (source instanceof Promise) {
247
+ let ready = false;
248
+ const wait = source.then(() => {
249
+ ready = true;
250
+ }, () => {
251
+ ready = true;
252
+ });
253
+ pollable.#source = { ready: () => ready, wait: () => wait };
254
+ }
255
+ else if (source) {
256
+ pollable.#source = source;
257
+ }
258
+ return pollable;
259
+ }
260
+ ready() {
261
+ this.#assertUsable();
262
+ return this.#source.ready();
263
+ }
264
+ block() {
265
+ this.#assertUsable();
266
+ if (this.#source.ready()) {
267
+ return Promise.resolve();
268
+ }
269
+ // Deduplicate simultaneous waiters, but discard a completed wait so a
270
+ // level-triggered source can be polled again after its event is consumed.
271
+ if (!this.#wait) {
272
+ this.#wait = Promise.race([
273
+ Promise.resolve(this.#source.wait()),
274
+ this.#unusable.then(() => this.#assertUsable()),
275
+ ]).finally(() => {
276
+ this.#wait = null;
277
+ });
278
+ }
279
+ return this.#wait;
280
+ }
281
+ _onDispose(callback) {
282
+ if (this.#disposed) {
283
+ callback();
284
+ }
285
+ else {
286
+ this.#disposeCallbacks.push(callback);
287
+ }
288
+ }
289
+ _invalidate() {
290
+ if (this.#invalid || this.#disposed) {
291
+ return;
292
+ }
293
+ this.#invalid = true;
294
+ this.#wakeUnusable();
295
+ }
296
+ #assertUsable() {
297
+ if (this.#disposed) {
298
+ throw new Error("pollable has been disposed");
299
+ }
300
+ if (this.#invalid) {
301
+ throw new Error("pollable's parent resource has been disposed");
302
+ }
303
+ }
304
+ [symbolDispose]() {
305
+ if (this.#disposed) {
306
+ return;
307
+ }
308
+ this.#disposed = true;
309
+ this.#wakeUnusable();
310
+ for (const callback of this.#disposeCallbacks.splice(0)) {
311
+ callback();
312
+ }
313
+ }
314
+ }
315
+ export const pollableCreate = Pollable._create;
316
+ // @ts-expect-error - Deleting static method
317
+ delete Pollable._create;
318
+ function pollList(list) {
319
+ if (list.length === 0) {
320
+ throw new Error("poll list must not be empty");
321
+ }
322
+ if (list.length > 0xffffffff) {
323
+ throw new Error("poll list length exceeds u32 index range");
324
+ }
325
+ const ready = [];
326
+ for (let i = 0; i < list.length; i++) {
327
+ if (list[i].ready()) {
328
+ ready.push(i);
329
+ }
330
+ }
331
+ if (ready.length > 0) {
332
+ // Browser guests commonly use an immediately-ready timer alongside an
333
+ // asynchronous Web API pollable. Yield a host task so Fetch, timers, and
334
+ // other event sources can progress instead of starving in a sync loop.
335
+ return new Promise((resolve) => setTimeout(() => {
336
+ const result = [];
337
+ for (let i = 0; i < list.length; i++) {
338
+ if (list[i].ready()) {
339
+ result.push(i);
340
+ }
341
+ }
342
+ resolve(new Uint32Array(result));
343
+ }, 0));
344
+ }
345
+ // None ready synchronously. Wait for the first to resolve via Promise.race,
346
+ // then sweep for any others that became ready concurrently.
347
+ return Promise.race(list.map((pollable) => pollable.block())).then(() => {
348
+ const result = [];
349
+ for (let i = 0; i < list.length; i++) {
350
+ if (list[i].ready()) {
351
+ result.push(i);
352
+ }
353
+ }
354
+ return new Uint32Array(result);
355
+ });
356
+ }
357
+ function pollOne(poll) {
358
+ return poll.block();
359
+ }
360
+ export const poll = {
361
+ Pollable,
362
+ pollList,
363
+ pollOne,
364
+ // @ts-expect-error Not matching signature from WIT
365
+ poll: pollList,
366
+ };