@opencode/codemode 0.0.0-dev-1179 → 0.0.0-dev-1189

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 (91) hide show
  1. package/README.md +6 -12
  2. package/dist/codemode.d.ts +7 -21
  3. package/dist/codemode.js +17 -38
  4. package/dist/extension.d.ts +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/scan.js +2 -2
  7. package/dist/tool-runtime.d.ts +8 -11
  8. package/dist/tool-runtime.js +13 -11
  9. package/dist/tool.d.ts +18 -9
  10. package/dist/tool.js +15 -23
  11. package/dist/vm/data.d.ts +1 -1
  12. package/dist/vm/runtime/execute.d.ts +16 -6
  13. package/dist/vm/runtime/execute.js +10 -7
  14. package/dist/vm/snapshot/codec.d.ts +3 -2
  15. package/dist/vm/snapshot/codec.js +3 -2
  16. package/dist/vm/snapshot/snapshot.d.ts +6 -3
  17. package/dist/vm/snapshot/snapshot.js +13 -2
  18. package/dist/vm/vm.d.ts +2 -2
  19. package/package.json +3 -5
  20. package/dist/data.d.ts +0 -21
  21. package/dist/data.js +0 -93
  22. package/dist/interpreter/callback.d.ts +0 -35
  23. package/dist/interpreter/callback.js +0 -98
  24. package/dist/interpreter/errors.d.ts +0 -23
  25. package/dist/interpreter/errors.js +0 -173
  26. package/dist/interpreter/execute.d.ts +0 -14
  27. package/dist/interpreter/execute.js +0 -207
  28. package/dist/interpreter/extensions.d.ts +0 -9
  29. package/dist/interpreter/extensions.js +0 -248
  30. package/dist/interpreter/generators.d.ts +0 -3
  31. package/dist/interpreter/generators.js +0 -168
  32. package/dist/interpreter/globals.d.ts +0 -6
  33. package/dist/interpreter/globals.js +0 -144
  34. package/dist/interpreter/interpreter.d.ts +0 -48
  35. package/dist/interpreter/interpreter.js +0 -2253
  36. package/dist/interpreter/intrinsics.d.ts +0 -15
  37. package/dist/interpreter/intrinsics.js +0 -105
  38. package/dist/interpreter/limits.d.ts +0 -10
  39. package/dist/interpreter/limits.js +0 -19
  40. package/dist/interpreter/model.d.ts +0 -68
  41. package/dist/interpreter/model.js +0 -54
  42. package/dist/interpreter/modules.d.ts +0 -4
  43. package/dist/interpreter/modules.js +0 -33
  44. package/dist/interpreter/native.d.ts +0 -17
  45. package/dist/interpreter/native.js +0 -35
  46. package/dist/interpreter/objects.d.ts +0 -301
  47. package/dist/interpreter/objects.js +0 -592
  48. package/dist/interpreter/promises.d.ts +0 -18
  49. package/dist/interpreter/promises.js +0 -292
  50. package/dist/interpreter/references.d.ts +0 -8
  51. package/dist/interpreter/references.js +0 -51
  52. package/dist/interpreter/runner.d.ts +0 -178
  53. package/dist/interpreter/runner.js +0 -480
  54. package/dist/interpreter/scope.d.ts +0 -16
  55. package/dist/interpreter/scope.js +0 -79
  56. package/dist/stdlib/array.d.ts +0 -11
  57. package/dist/stdlib/array.js +0 -498
  58. package/dist/stdlib/bytes.d.ts +0 -10
  59. package/dist/stdlib/bytes.js +0 -253
  60. package/dist/stdlib/collections.d.ts +0 -7
  61. package/dist/stdlib/collections.js +0 -497
  62. package/dist/stdlib/console.d.ts +0 -6
  63. package/dist/stdlib/console.js +0 -93
  64. package/dist/stdlib/date.d.ts +0 -2
  65. package/dist/stdlib/date.js +0 -132
  66. package/dist/stdlib/headers.d.ts +0 -2
  67. package/dist/stdlib/headers.js +0 -110
  68. package/dist/stdlib/iterator.d.ts +0 -2
  69. package/dist/stdlib/iterator.js +0 -322
  70. package/dist/stdlib/json.d.ts +0 -3
  71. package/dist/stdlib/json.js +0 -58
  72. package/dist/stdlib/math.d.ts +0 -8
  73. package/dist/stdlib/math.js +0 -97
  74. package/dist/stdlib/number.d.ts +0 -3
  75. package/dist/stdlib/number.js +0 -72
  76. package/dist/stdlib/object.d.ts +0 -6
  77. package/dist/stdlib/object.js +0 -219
  78. package/dist/stdlib/regexp.d.ts +0 -7
  79. package/dist/stdlib/regexp.js +0 -114
  80. package/dist/stdlib/string.d.ts +0 -2
  81. package/dist/stdlib/string.js +0 -272
  82. package/dist/stdlib/url.d.ts +0 -13
  83. package/dist/stdlib/url.js +0 -255
  84. package/dist/stdlib/value.d.ts +0 -7
  85. package/dist/stdlib/value.js +0 -33
  86. package/dist/stdlib/web.d.ts +0 -5
  87. package/dist/stdlib/web.js +0 -97
  88. package/dist/suspend-error.d.ts +0 -24
  89. package/dist/suspend-error.js +0 -25
  90. package/dist/vm/index.d.ts +0 -6
  91. package/dist/vm/index.js +0 -6
@@ -1,97 +0,0 @@
1
- import { fn, methods } from "../interpreter/native.js";
2
- import { typeError } from "../interpreter/model.js";
3
- import { define, entries, get, getOwn, hasOwn, hidden, isRuntimeReference, Arr, Bytes, DateObj, ErrorObj, MapObj, Obj, RegExpObj, SetObj, WeakMapObj, WeakSetObj, coerceToString, } from "../interpreter/objects.js";
4
- import { createErrorValue, isErrorType } from "../interpreter/intrinsics.js";
5
- import { describeValue } from "../interpreter/references.js";
6
- import { ToolReference } from "../tool-runtime.js";
7
- // WebIDL DOMString conversion: a missing argument is a TypeError, anything else stringifies. Invalid input is a
8
- // TypeError as well; browsers throw a DOMException named InvalidCharacterError, which CodeMode does not have.
9
- export const base64Global = (ctx, name) => fn(ctx.builtins, name, 1, (_, args) => {
10
- if (args.length === 0)
11
- throw typeError(`${name} requires 1 argument (a string)`);
12
- const input = coerceToString(args[0]);
13
- try {
14
- return name === "atob" ? atob(input) : btoa(input);
15
- }
16
- catch {
17
- throw typeError("The string contains invalid characters.");
18
- }
19
- });
20
- // HTML structured clone over CodeMode's data kinds. Shared references survive through the memo; prototypes and
21
- // frozen state do not, as in JS. Without a DOMException, DataCloneError is a TypeError carrying that prefix.
22
- export const structuredCloneGlobal = (ctx) => fn(ctx.builtins, "structuredClone", 1, (_, args) => {
23
- if (args.length === 0)
24
- throw typeError("structuredClone requires 1 argument");
25
- const builtins = ctx.builtins;
26
- const memo = new Map();
27
- const clone = (value) => {
28
- if (typeof value === "symbol" || value instanceof ToolReference) {
29
- throw typeError(`DataCloneError: ${describeValue(value)} could not be cloned.`);
30
- }
31
- if (!(value instanceof Obj))
32
- return value;
33
- const seen = memo.get(value);
34
- if (seen !== undefined)
35
- return seen;
36
- const remember = (copy) => {
37
- memo.set(value, copy);
38
- return copy;
39
- };
40
- if (value instanceof MapObj) {
41
- const copy = remember(new MapObj(builtins.Map));
42
- for (const [key, item] of value.map)
43
- copy.map.set(clone(key), clone(item));
44
- return copy;
45
- }
46
- if (value instanceof SetObj) {
47
- const copy = remember(new SetObj(builtins.Set));
48
- for (const item of value.set)
49
- copy.set.add(clone(item));
50
- return copy;
51
- }
52
- if (value instanceof DateObj)
53
- return remember(new DateObj(builtins.Date, value.time));
54
- if (value instanceof RegExpObj) {
55
- return remember(new RegExpObj(builtins.RegExp, value.regex.source, value.regex.flags));
56
- }
57
- if (value instanceof Bytes)
58
- return remember(new Bytes(builtins.Uint8Array, new Uint8Array(value.bytes)));
59
- if (value instanceof ErrorObj) {
60
- const name = get(value, "name");
61
- const message = get(value, "message");
62
- const copy = remember(createErrorValue(builtins[typeof name === "string" && isErrorType(name) ? name : "Error"], message === undefined ? undefined : coerceToString(message)));
63
- const stack = getOwn(value, "stack");
64
- if (typeof stack === "string")
65
- define(copy, "stack", stack, hidden);
66
- if (hasOwn(value, "cause"))
67
- define(copy, "cause", clone(getOwn(value, "cause")), hidden);
68
- return copy;
69
- }
70
- if (isRuntimeReference(value) || value instanceof WeakMapObj || value instanceof WeakSetObj) {
71
- throw typeError(`DataCloneError: ${describeValue(value)} could not be cloned.`);
72
- }
73
- const copy = remember(value instanceof Arr ? new Arr(builtins.Array, new Array(value.items.length)) : new Obj(builtins.Object));
74
- for (const [key, item] of entries(value))
75
- define(copy, key, clone(item));
76
- return copy;
77
- };
78
- return clone(args[0]);
79
- });
80
- export const cryptoGlobal = (ctx) => {
81
- const object = new Obj(ctx.builtins.Object);
82
- methods(ctx.builtins, object, [
83
- ["randomUUID", 0, () => crypto.randomUUID()],
84
- [
85
- "getRandomValues",
86
- 1,
87
- (_, args) => {
88
- if (!(args[0] instanceof Bytes)) {
89
- throw typeError(`crypto.getRandomValues expects a Uint8Array, received ${describeValue(args[0])}.`);
90
- }
91
- crypto.getRandomValues(args[0].bytes);
92
- return args[0];
93
- },
94
- ],
95
- ]);
96
- return object;
97
- };
@@ -1,24 +0,0 @@
1
- import { Schema } from "effect";
2
- import type { Snapshot } from "./vm/snapshot/snapshot.js";
3
- declare const SuspendError_base: Schema.Class<SuspendError, Schema.TaggedStruct<"SuspendError", {
4
- readonly message: Schema.String;
5
- readonly running: Schema.$Array<Schema.Struct<{
6
- readonly key: Schema.String;
7
- readonly path: Schema.String;
8
- }>>;
9
- }>, import("effect/Cause").YieldableError>;
10
- /**
11
- * A suspend that failed, leaving the run running: `running` names each host call that blocked it by its key and its
12
- * path (`tools.x.y`, `search`, or an extension function's path such as `fetch`). Empty when the state couldn't be
13
- * saved or was too large.
14
- */
15
- export declare class SuspendError extends SuspendError_base {
16
- }
17
- export declare class SnapshotError extends Error {
18
- readonly name = "SnapshotError";
19
- }
20
- /** A snapshot as bytes: UTF-8 JSON. */
21
- export declare const toBytes: (snapshot: Snapshot) => Uint8Array;
22
- /** Reads bytes `toBytes` wrote; `restore` checks what they hold. */
23
- export declare const fromBytes: (bytes: Uint8Array) => unknown;
24
- export {};
@@ -1,25 +0,0 @@
1
- import { Schema } from "effect";
2
- /**
3
- * A suspend that failed, leaving the run running: `running` names each host call that blocked it by its key and its
4
- * path (`tools.x.y`, `search`, or an extension function's path such as `fetch`). Empty when the state couldn't be
5
- * saved or was too large.
6
- */
7
- export class SuspendError extends Schema.TaggedError()("SuspendError", {
8
- message: Schema.String,
9
- running: Schema.Array(Schema.Struct({ key: Schema.String, path: Schema.String })),
10
- }) {
11
- }
12
- export class SnapshotError extends Error {
13
- name = "SnapshotError";
14
- }
15
- /** A snapshot as bytes: UTF-8 JSON. */
16
- export const toBytes = (snapshot) => new TextEncoder().encode(JSON.stringify(snapshot));
17
- /** Reads bytes `toBytes` wrote; `restore` checks what they hold. */
18
- export const fromBytes = (bytes) => {
19
- try {
20
- return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
21
- }
22
- catch (error) {
23
- throw new SnapshotError(`Invalid snapshot: the bytes are not UTF-8 JSON (${String(error)}).`);
24
- }
25
- };
@@ -1,6 +0,0 @@
1
- export * as VmEngine from "./index.js";
2
- export { fromJson } from "./data.js";
3
- export { execute, finishExecution, resumeProgram, type Running, type Setup, startProgram } from "./runtime/execute.js";
4
- export { extensionGlobals } from "./runtime/extensions.js";
5
- export { globalNames } from "./runtime/globals.js";
6
- export { fromBytes, type Snapshot, SnapshotError, type SnapshotHeader, toBytes } from "./snapshot/snapshot.js";
package/dist/vm/index.js DELETED
@@ -1,6 +0,0 @@
1
- export * as VmEngine from "./index.js";
2
- export { fromJson } from "./data.js";
3
- export { execute, finishExecution, resumeProgram, startProgram } from "./runtime/execute.js";
4
- export { extensionGlobals } from "./runtime/extensions.js";
5
- export { globalNames } from "./runtime/globals.js";
6
- export { fromBytes, SnapshotError, toBytes } from "./snapshot/snapshot.js";