@opencode/codemode 2.2.7 → 2.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 +11 -13
- package/dist/{vm/async.d.ts → async.d.ts} +1 -1
- package/dist/codemode.d.ts +8 -22
- package/dist/codemode.js +17 -38
- package/dist/data.d.ts +4 -19
- package/dist/data.js +1 -82
- package/dist/extension.d.ts +8 -2
- package/dist/extension.js +9 -0
- package/dist/{vm/host.d.ts → host.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{vm/opcodes.d.ts → opcodes.d.ts} +1 -1
- package/dist/{vm/prelude → prelude}/helpers.js +1 -1
- package/dist/{vm/runtime → runtime}/driver.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/driver.js +1 -1
- package/dist/{vm/runtime → runtime}/errors.js +2 -2
- package/dist/{vm/runtime → runtime}/execute.d.ts +17 -8
- package/dist/{vm/runtime → runtime}/execute.js +11 -9
- package/dist/{vm/runtime → runtime}/extensions.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/extensions.js +39 -4
- package/dist/{vm/runtime → runtime}/globals.js +1 -1
- package/dist/{vm/runtime → runtime}/interpreter.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/model.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/objects.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/objects.js +1 -1
- package/dist/{vm/runtime → runtime}/operations.d.ts +1 -1
- package/dist/{vm/runtime → runtime}/operations.js +1 -1
- package/dist/scan.js +2 -2
- package/dist/{vm/scheduler.d.ts → scheduler.d.ts} +1 -1
- package/dist/{vm/snapshot → snapshot}/codec.d.ts +6 -5
- package/dist/{vm/snapshot → snapshot}/codec.js +12 -5
- package/dist/{vm/snapshot → snapshot}/snapshot.d.ts +8 -5
- package/dist/{vm/snapshot → snapshot}/snapshot.js +14 -3
- package/dist/{vm/snapshot.js → snapshot.js} +1 -1
- package/dist/stdlib/array.d.ts +14 -9
- package/dist/stdlib/array.js +89 -276
- package/dist/stdlib/bytes.d.ts +11 -7
- package/dist/stdlib/bytes.js +112 -79
- package/dist/stdlib/collections.d.ts +7 -7
- package/dist/stdlib/collections.js +30 -339
- package/dist/stdlib/console.d.ts +2 -2
- package/dist/stdlib/console.js +3 -3
- package/dist/stdlib/date.d.ts +2 -2
- package/dist/stdlib/date.js +21 -30
- package/dist/stdlib/headers.d.ts +2 -2
- package/dist/stdlib/headers.js +15 -33
- package/dist/stdlib/iterator.d.ts +2 -2
- package/dist/stdlib/iterator.js +10 -302
- package/dist/stdlib/json.d.ts +2 -2
- package/dist/stdlib/json.js +15 -31
- package/dist/stdlib/math.d.ts +2 -7
- package/dist/stdlib/math.js +6 -30
- package/dist/stdlib/number.d.ts +3 -3
- package/dist/stdlib/number.js +8 -8
- package/dist/stdlib/object.d.ts +4 -4
- package/dist/stdlib/object.js +12 -30
- package/dist/stdlib/regexp.d.ts +6 -5
- package/dist/stdlib/regexp.js +18 -13
- package/dist/stdlib/string.d.ts +2 -2
- package/dist/stdlib/string.js +53 -53
- package/dist/stdlib/url.d.ts +21 -9
- package/dist/stdlib/url.js +55 -55
- package/dist/stdlib/value.d.ts +3 -4
- package/dist/stdlib/value.js +5 -6
- package/dist/stdlib/web.d.ts +4 -4
- package/dist/stdlib/web.js +7 -7
- package/dist/tool-runtime.d.ts +14 -13
- package/dist/tool-runtime.js +245 -53
- package/dist/tool-schema.d.ts +5 -0
- package/dist/tool-schema.js +36 -16
- package/dist/tool.d.ts +24 -9
- package/dist/tool.js +15 -22
- package/dist/{vm/vm.d.ts → vm.d.ts} +3 -3
- package/dist/{vm/vm.js → vm.js} +1 -1
- package/package.json +3 -5
- package/dist/interpreter/callback.d.ts +0 -35
- package/dist/interpreter/callback.js +0 -98
- package/dist/interpreter/errors.js +0 -173
- package/dist/interpreter/execute.d.ts +0 -14
- package/dist/interpreter/execute.js +0 -207
- package/dist/interpreter/extensions.d.ts +0 -9
- package/dist/interpreter/extensions.js +0 -248
- package/dist/interpreter/generators.d.ts +0 -3
- package/dist/interpreter/generators.js +0 -168
- package/dist/interpreter/globals.js +0 -144
- package/dist/interpreter/interpreter.d.ts +0 -48
- package/dist/interpreter/interpreter.js +0 -2253
- package/dist/interpreter/intrinsics.d.ts +0 -15
- package/dist/interpreter/intrinsics.js +0 -105
- package/dist/interpreter/model.d.ts +0 -68
- package/dist/interpreter/model.js +0 -54
- package/dist/interpreter/native.d.ts +0 -17
- package/dist/interpreter/native.js +0 -35
- package/dist/interpreter/objects.d.ts +0 -301
- package/dist/interpreter/objects.js +0 -592
- package/dist/interpreter/promises.d.ts +0 -18
- package/dist/interpreter/promises.js +0 -292
- package/dist/interpreter/runner.d.ts +0 -178
- package/dist/interpreter/runner.js +0 -480
- package/dist/interpreter/scope.d.ts +0 -16
- package/dist/interpreter/scope.js +0 -79
- package/dist/suspend-error.d.ts +0 -24
- package/dist/suspend-error.js +0 -25
- package/dist/vm/data.d.ts +0 -7
- package/dist/vm/data.js +0 -13
- package/dist/vm/index.d.ts +0 -6
- package/dist/vm/index.js +0 -6
- package/dist/vm/runtime/errors.d.ts +0 -23
- package/dist/vm/runtime/globals.d.ts +0 -6
- package/dist/vm/runtime/limits.d.ts +0 -10
- package/dist/vm/runtime/limits.js +0 -19
- package/dist/vm/runtime/modules.d.ts +0 -4
- package/dist/vm/runtime/modules.js +0 -33
- package/dist/vm/runtime/references.d.ts +0 -8
- package/dist/vm/runtime/references.js +0 -51
- package/dist/vm/stdlib/array.d.ts +0 -16
- package/dist/vm/stdlib/array.js +0 -311
- package/dist/vm/stdlib/bytes.d.ts +0 -11
- package/dist/vm/stdlib/bytes.js +0 -222
- package/dist/vm/stdlib/collections.d.ts +0 -7
- package/dist/vm/stdlib/collections.js +0 -188
- package/dist/vm/stdlib/console.d.ts +0 -6
- package/dist/vm/stdlib/console.js +0 -93
- package/dist/vm/stdlib/date.d.ts +0 -2
- package/dist/vm/stdlib/date.js +0 -123
- package/dist/vm/stdlib/headers.d.ts +0 -2
- package/dist/vm/stdlib/headers.js +0 -92
- package/dist/vm/stdlib/iterator.d.ts +0 -2
- package/dist/vm/stdlib/iterator.js +0 -30
- package/dist/vm/stdlib/json.d.ts +0 -3
- package/dist/vm/stdlib/json.js +0 -42
- package/dist/vm/stdlib/math.d.ts +0 -3
- package/dist/vm/stdlib/math.js +0 -73
- package/dist/vm/stdlib/number.d.ts +0 -3
- package/dist/vm/stdlib/number.js +0 -72
- package/dist/vm/stdlib/object.d.ts +0 -6
- package/dist/vm/stdlib/object.js +0 -201
- package/dist/vm/stdlib/regexp.d.ts +0 -8
- package/dist/vm/stdlib/regexp.js +0 -119
- package/dist/vm/stdlib/string.d.ts +0 -2
- package/dist/vm/stdlib/string.js +0 -272
- package/dist/vm/stdlib/url.d.ts +0 -25
- package/dist/vm/stdlib/url.js +0 -255
- package/dist/vm/stdlib/value.d.ts +0 -6
- package/dist/vm/stdlib/value.js +0 -32
- package/dist/vm/stdlib/web.d.ts +0 -5
- package/dist/vm/stdlib/web.js +0 -97
- /package/dist/{vm/async.js → async.js} +0 -0
- /package/dist/{vm/code.d.ts → code.d.ts} +0 -0
- /package/dist/{vm/code.js → code.js} +0 -0
- /package/dist/{vm/compiler → compiler}/compile.d.ts +0 -0
- /package/dist/{vm/compiler → compiler}/compile.js +0 -0
- /package/dist/{vm/compiler → compiler}/scope.d.ts +0 -0
- /package/dist/{vm/compiler → compiler}/scope.js +0 -0
- /package/dist/{vm/generators.d.ts → generators.d.ts} +0 -0
- /package/dist/{vm/generators.js → generators.js} +0 -0
- /package/dist/{vm/host.js → host.js} +0 -0
- /package/dist/{vm/internal-prelude.d.ts → internal-prelude.d.ts} +0 -0
- /package/dist/{vm/internal-prelude.js → internal-prelude.js} +0 -0
- /package/dist/{vm/opcodes.js → opcodes.js} +0 -0
- /package/dist/{vm/prelude → prelude}/bytecode.d.ts +0 -0
- /package/dist/{vm/prelude → prelude}/bytecode.js +0 -0
- /package/dist/{vm/prelude → prelude}/bytecode.json +0 -0
- /package/dist/{vm/prelude → prelude}/helpers.d.ts +0 -0
- /package/dist/{vm/prelude → prelude}/prelude.d.ts +0 -0
- /package/dist/{vm/prelude → prelude}/prelude.js +0 -0
- /package/dist/{vm/prelude → prelude}/source.d.ts +0 -0
- /package/dist/{vm/prelude → prelude}/source.js +0 -0
- /package/dist/{vm/runtime → runtime}/callback.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/callback.js +0 -0
- /package/dist/{interpreter → runtime}/errors.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/generators.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/generators.js +0 -0
- /package/dist/{interpreter → runtime}/globals.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/interpreter.js +0 -0
- /package/dist/{vm/runtime → runtime}/intrinsic-names.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/intrinsic-names.js +0 -0
- /package/dist/{vm/runtime → runtime}/intrinsics.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/intrinsics.js +0 -0
- /package/dist/{interpreter → runtime}/limits.d.ts +0 -0
- /package/dist/{interpreter → runtime}/limits.js +0 -0
- /package/dist/{vm/runtime → runtime}/model.js +0 -0
- /package/dist/{interpreter → runtime}/modules.d.ts +0 -0
- /package/dist/{interpreter → runtime}/modules.js +0 -0
- /package/dist/{vm/runtime → runtime}/native.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/native.js +0 -0
- /package/dist/{vm/runtime → runtime}/promises.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/promises.js +0 -0
- /package/dist/{interpreter → runtime}/references.d.ts +0 -0
- /package/dist/{interpreter → runtime}/references.js +0 -0
- /package/dist/{vm/runtime → runtime}/signals.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/signals.js +0 -0
- /package/dist/{vm/runtime → runtime}/source.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/source.js +0 -0
- /package/dist/{vm/runtime → runtime}/table.d.ts +0 -0
- /package/dist/{vm/runtime → runtime}/table.js +0 -0
- /package/dist/{vm/scheduler.js → scheduler.js} +0 -0
- /package/dist/{vm/snapshot.d.ts → snapshot.d.ts} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { isAsync } from "
|
|
3
|
-
import { hooked } from "
|
|
2
|
+
import { isAsync, StreamingResponse } from "../extension.js";
|
|
3
|
+
import { hooked } from "../tool-runtime.js";
|
|
4
4
|
import { errorMessage, errorType } from "./errors.js";
|
|
5
5
|
import { createErrorValue } from "./intrinsics.js";
|
|
6
6
|
import { MAX_ARRAY_LENGTH, MAX_VALUE_DEPTH } from "./limits.js";
|
|
7
|
-
import { PendingThrow, rangeError, Throw, typeError } from "./model.js";
|
|
7
|
+
import { AsyncIteratorSymbol, PendingThrow, rangeError, Throw, typeError } from "./model.js";
|
|
8
8
|
import { native } from "./native.js";
|
|
9
|
-
import { define, get, has, hidden, keys, Arr, Bytes, DateObj, ErrorObj, HeadersObj, PromiseObj, MapObj, Obj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, coerceToString, } from "./objects.js";
|
|
9
|
+
import { define, defineAccessor, get, has, hidden, keys, Arr, Bytes, DateObj, ErrorObj, HeadersObj, PromiseObj, MapObj, Obj, RegExpObj, SetObj, URLObj, URLSearchParamsObj, coerceToString, } from "./objects.js";
|
|
10
10
|
import { describeValue, isOpaque } from "./references.js";
|
|
11
11
|
import { Push } from "./signals.js";
|
|
12
12
|
import { SnapshotError } from "../snapshot/codec.js";
|
|
@@ -74,6 +74,41 @@ export const extensionGlobals = (ctx, extensions) => {
|
|
|
74
74
|
// method could hand back host storage or an object (`getTime`, `slice`, `map`), its internal data is read.
|
|
75
75
|
if (value instanceof Date)
|
|
76
76
|
return new DateObj(builtins.Date, Date.prototype.getTime.call(value));
|
|
77
|
+
if (value instanceof StreamingResponse) {
|
|
78
|
+
const response = value.response;
|
|
79
|
+
const body = response.body;
|
|
80
|
+
const stream = new Obj(builtins.Object);
|
|
81
|
+
if (body) {
|
|
82
|
+
defineAccessor(stream, "locked", () => body.locked);
|
|
83
|
+
define(stream, "cancel", next(async (reason) => body.cancel(reason), `${label}.body.cancel`));
|
|
84
|
+
define(stream, "getReader", next((options) => {
|
|
85
|
+
if (options?.mode !== undefined)
|
|
86
|
+
throw new TypeError("Only the default stream reader is supported.");
|
|
87
|
+
const reader = body.getReader();
|
|
88
|
+
return {
|
|
89
|
+
read: async () => reader.read(),
|
|
90
|
+
cancel: async (reason) => reader.cancel(reason),
|
|
91
|
+
releaseLock: () => reader.releaseLock(),
|
|
92
|
+
};
|
|
93
|
+
}, `${label}.body.getReader`));
|
|
94
|
+
define(stream, AsyncIteratorSymbol, next(() => {
|
|
95
|
+
const iterator = body.values();
|
|
96
|
+
return {
|
|
97
|
+
next: async () => iterator.next(),
|
|
98
|
+
return: async () => iterator.return(),
|
|
99
|
+
};
|
|
100
|
+
}, `${label}.body[Symbol.asyncIterator]`));
|
|
101
|
+
}
|
|
102
|
+
const result = new Obj(builtins.Object);
|
|
103
|
+
for (const key of ["url", "status", "statusText", "ok", "headers"])
|
|
104
|
+
define(result, key, next(response[key], `${label}.${key}`));
|
|
105
|
+
define(result, "redirected", value.redirected);
|
|
106
|
+
define(result, "body", body ? stream : null);
|
|
107
|
+
defineAccessor(result, "bodyUsed", () => response.bodyUsed);
|
|
108
|
+
for (const key of ["text", "json", "bytes", "arrayBuffer"])
|
|
109
|
+
define(result, key, next(async () => response[key](), `${label}.${key}`));
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
77
112
|
if (value instanceof RegExp)
|
|
78
113
|
return new RegExpObj(builtins.RegExp, value.source, value.flags);
|
|
79
114
|
if (value instanceof Uint8Array)
|
|
@@ -15,7 +15,7 @@ import { headersGlobal } from "../stdlib/headers.js";
|
|
|
15
15
|
import { iteratorGlobals } from "../stdlib/iterator.js";
|
|
16
16
|
import { coercion } from "../stdlib/value.js";
|
|
17
17
|
import { base64Global, cryptoGlobal, structuredCloneGlobal } from "../stdlib/web.js";
|
|
18
|
-
import { ToolReference } from "
|
|
18
|
+
import { ToolReference } from "../tool-runtime.js";
|
|
19
19
|
import { errorGlobal } from "./errors.js";
|
|
20
20
|
import { errorTypes } from "./intrinsics.js";
|
|
21
21
|
import { constants, constructor, methods, native, receiver } from "./native.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Node } from "acorn";
|
|
2
2
|
import type { ErrorType } from "./intrinsics.js";
|
|
3
|
-
import type { DiagnosticKind } from "
|
|
3
|
+
import type { DiagnosticKind } from "../codemode.js";
|
|
4
4
|
import type { ErrorObj, Value } from "./objects.js";
|
|
5
5
|
/** Any parsed node; the compiler narrows on `type`, and diagnostics read `loc`. */
|
|
6
6
|
export type AstNode = Node;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToolReference } from "
|
|
1
|
+
import { ToolReference } from "../tool-runtime.js";
|
|
2
2
|
import type { Builtins } from "./intrinsics.js";
|
|
3
3
|
import { type AstNode, type PendingThrow } from "./model.js";
|
|
4
4
|
import { type Convert, type GeneratorRequest, Invoke, type Push, type Resume } from "./signals.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToolReference } from "
|
|
1
|
+
import { ToolReference } from "../tool-runtime.js";
|
|
2
2
|
import { checkArrayLength } from "./limits.js";
|
|
3
3
|
import { AsyncIteratorSymbol, IteratorSymbol, rangeError, Throw, typeError, } from "./model.js";
|
|
4
4
|
import { Invoke } from "./signals.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Expression, MemberExpression, NewExpression, Super } from "acorn";
|
|
2
|
-
import { ToolReference } from "
|
|
2
|
+
import { ToolReference } from "../tool-runtime.js";
|
|
3
3
|
import { type AstNode } from "./model.js";
|
|
4
4
|
import { type Builtins } from "./intrinsics.js";
|
|
5
5
|
import { type Cursor, Obj, type Value } from "./objects.js";
|
package/dist/scan.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Result } from "effect";
|
|
2
|
-
import { parseProgram } from "./
|
|
3
|
-
import { formatLocation } from "./
|
|
2
|
+
import { parseProgram } from "./runtime/execute.js";
|
|
3
|
+
import { formatLocation } from "./runtime/model.js";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts every `tools.<path>` referenced by a Code Mode program, in first-seen order. Fails on syntax errors,
|
|
6
6
|
* dynamic bracket access (`tools[name]`), or aliasing/passing `tools` rather than calling `tools.<path>(...)` directly.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Json } from "./data.js";
|
|
2
|
-
import type { ExtensionInvocation } from "
|
|
2
|
+
import type { ExtensionInvocation } from "./tool-runtime.js";
|
|
3
3
|
import type { AstNode } from "./runtime/model.js";
|
|
4
4
|
import type { Callable, Cursor, GeneratorObj, Obj, PromiseObj, Value } from "./runtime/objects.js";
|
|
5
5
|
import type { Completion } from "./runtime/signals.js";
|
|
@@ -12,7 +12,7 @@ export type Json = null | boolean | number | string | ReadonlyArray<Json> | {
|
|
|
12
12
|
* - `["s", name]` an interpreter symbol;
|
|
13
13
|
* - `["i", name]` a built-in or host global, unchanged since the runtime was made;
|
|
14
14
|
* - `["a", source, index]` an AST node (a call site, an error's location);
|
|
15
|
-
* - `["x", data]` something the
|
|
15
|
+
* - `["x", data]` something the VM names itself (compiled code, by source and function index);
|
|
16
16
|
* - `["r", id]` another record.
|
|
17
17
|
*/
|
|
18
18
|
export type Encoded = string | number | boolean | null | ReadonlyArray<Json>;
|
|
@@ -22,8 +22,9 @@ export type Record = {
|
|
|
22
22
|
readonly [field: string]: Json;
|
|
23
23
|
};
|
|
24
24
|
/** A saved state can't be read, or doesn't fit this runtime. */
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
export declare class SnapshotError extends Error {
|
|
26
|
+
readonly name = "SnapshotError";
|
|
27
|
+
}
|
|
27
28
|
/**
|
|
28
29
|
* Where a function inside a value an extension returned came from, so a saved state can name it instead of losing it:
|
|
29
30
|
* the extension, the value its function returned (`root`), which the extension's `snapshot` hooks save, and the path
|
|
@@ -65,9 +66,9 @@ export type EncodeEnv = {
|
|
|
65
66
|
readonly lost: Array<string>;
|
|
66
67
|
readonly strict: boolean;
|
|
67
68
|
readonly hosts?: HostBridge | undefined;
|
|
68
|
-
/** More classes to save
|
|
69
|
+
/** More classes to save (the VM's frames and closures), after the built-in ones. */
|
|
69
70
|
readonly specs?: ReadonlyArray<ClassSpec> | undefined;
|
|
70
|
-
/** The data
|
|
71
|
+
/** The data the VM names an object or symbol by, saved as `["x", data]`, instead of copying it. */
|
|
71
72
|
readonly external?: ((value: object | symbol) => Json | undefined) | undefined;
|
|
72
73
|
};
|
|
73
74
|
/** What the decoder asks of the fresh runtime it restores into. */
|
|
@@ -6,11 +6,12 @@ import { deleted, OrderedTable } from "../runtime/table.js";
|
|
|
6
6
|
import { AsyncFromSyncIterator } from "../generators.js";
|
|
7
7
|
import { HostCall, Resolving } from "../scheduler.js";
|
|
8
8
|
import { TextDecoderObj } from "../stdlib/bytes.js";
|
|
9
|
-
import { ToolError, toolError } from "
|
|
10
|
-
import { ToolReference, ToolRuntimeError } from "
|
|
9
|
+
import { ToolError, toolError } from "../tool-error.js";
|
|
10
|
+
import { ToolReference, ToolRuntimeError } from "../tool-runtime.js";
|
|
11
11
|
/** A saved state can't be read, or doesn't fit this runtime. */
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export class SnapshotError extends Error {
|
|
13
|
+
name = "SnapshotError";
|
|
14
|
+
}
|
|
14
15
|
// --- Registries ---
|
|
15
16
|
const symbols = new Map([
|
|
16
17
|
["iterator", IteratorSymbol],
|
|
@@ -84,7 +85,13 @@ const builtinSpecs = () => [
|
|
|
84
85
|
{ name: "HeadersObj", ctor: HeadersObj, fields: ["headers"], obj: true, constants: { tag: "Headers" } },
|
|
85
86
|
{ name: "URLObj", ctor: URLObj, fields: ["searchParams", "url"], obj: true, constants: { tag: "URL" } },
|
|
86
87
|
{ name: "Bytes", ctor: Bytes, fields: ["bytes"], obj: true, constants: { tag: "Uint8Array" } },
|
|
87
|
-
{
|
|
88
|
+
{
|
|
89
|
+
name: "TextDecoderObj",
|
|
90
|
+
ctor: TextDecoderObj,
|
|
91
|
+
fields: ["decoder", "ignoreBOM", "queued", "seen"],
|
|
92
|
+
obj: true,
|
|
93
|
+
constants: { tag: "Object" },
|
|
94
|
+
},
|
|
88
95
|
{
|
|
89
96
|
name: "AsyncFromSyncIterator",
|
|
90
97
|
ctor: AsyncFromSyncIterator,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { Interpreter } from "../runtime/interpreter.js";
|
|
2
|
-
import type { ToolCall } from "
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import type { ToolCall } from "../tool-runtime.js";
|
|
3
|
+
import { type Encoded, type Record, SnapshotError } from "./codec.js";
|
|
4
|
+
export { SnapshotError };
|
|
5
|
+
/** A snapshot as bytes: UTF-8 JSON. */
|
|
6
|
+
export declare const toBytes: (snapshot: Snapshot) => Uint8Array;
|
|
7
|
+
/** Reads bytes `toBytes` wrote; `restore` checks what they hold. */
|
|
8
|
+
export declare const fromBytes: (bytes: Uint8Array) => unknown;
|
|
9
|
+
/** The snapshot format this build writes and reads (see `src/snapshot.ts`). */
|
|
7
10
|
export declare const FORMAT = 2;
|
|
8
11
|
/**
|
|
9
12
|
* A suspended run's whole state as JSON: a header that says which build and sources it belongs to and what budget it
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
/**
|
|
1
|
+
import { SnapshotError } from "./codec.js";
|
|
2
|
+
export { SnapshotError };
|
|
3
|
+
/** A snapshot as bytes: UTF-8 JSON. */
|
|
4
|
+
export const toBytes = (snapshot) => new TextEncoder().encode(JSON.stringify(snapshot));
|
|
5
|
+
/** Reads bytes `toBytes` wrote; `restore` checks what they hold. */
|
|
6
|
+
export const fromBytes = (bytes) => {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
throw new SnapshotError(`Invalid snapshot: the bytes are not UTF-8 JSON (${String(error)}).`);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** The snapshot format this build writes and reads (see `src/snapshot.ts`). */
|
|
4
15
|
export const FORMAT = 2;
|
|
5
16
|
export const hostsId = (ctx) => hash([
|
|
6
17
|
...ctx.intrinsics.hosts(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import packageJson from "
|
|
1
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
2
2
|
import { staticNames, unchanged } from "./runtime/intrinsic-names.js";
|
|
3
3
|
import { Fn, Obj } from "./runtime/objects.js";
|
|
4
4
|
import { nodeId } from "./runtime/source.js";
|
package/dist/stdlib/array.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type { Interpreter } from "../
|
|
5
|
-
|
|
6
|
-
export
|
|
1
|
+
import { Invoke } from "../runtime/signals.js";
|
|
2
|
+
import type { Builtins } from "../runtime/intrinsics.js";
|
|
3
|
+
import { Arr, Bytes, type Value } from "../runtime/objects.js";
|
|
4
|
+
import type { Interpreter } from "../runtime/interpreter.js";
|
|
5
|
+
/** Where a sort puts its result: back into an array or bytes, or into a new array. */
|
|
6
|
+
export type SortInto = "Array.sort" | "Array.toSorted" | "Uint8Array.sort";
|
|
7
|
+
/** The most values the default sort sorts in one native call; more sort in bounded steps (see `sortDefault`). */
|
|
8
|
+
export declare const SORT_RUN = 4096;
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* Sorts `target`'s values: at once without a comparator, unless there are many, otherwise in the prelude
|
|
11
|
+
* (`sortWith`), which calls it. The merges of a top-down merge sort are planned here, in post-order, so the prelude
|
|
12
|
+
* compares in the same order as the recursive sort. Holes and undefined values sort last without being compared.
|
|
10
13
|
*/
|
|
11
|
-
export declare const
|
|
14
|
+
export declare const sortArray: <R>(ctx: Interpreter<R>, target: Arr | Bytes, comparator: Value, into: SortInto) => Value | Invoke;
|
|
15
|
+
export declare const sorted: (builtins: Builtins, target: Arr | Bytes, into: SortInto, holes: number, result: Array<Value>) => Arr | Bytes;
|
|
16
|
+
export declare const arrayGlobal: <R>(ctx: Interpreter<R>) => import("../runtime/objects.js").Native;
|