@opencode/codemode 0.0.0-dev-19326 → 0.0.0-dev-19329
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 +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpreter/methods.d.ts +2 -2
- package/dist/interpreter/methods.js +22 -22
- package/dist/interpreter/model.d.ts +4 -4
- package/dist/interpreter/promises.d.ts +8 -8
- package/dist/interpreter/promises.js +4 -4
- package/dist/interpreter/references.js +4 -4
- package/dist/interpreter/runtime.js +53 -53
- package/dist/stdlib/console.js +10 -10
- package/dist/stdlib/date.d.ts +2 -2
- package/dist/stdlib/date.js +1 -1
- package/dist/stdlib/json.js +9 -9
- package/dist/stdlib/object.js +6 -6
- package/dist/stdlib/regexp.d.ts +2 -2
- package/dist/stdlib/regexp.js +2 -2
- package/dist/stdlib/url.d.ts +2 -2
- package/dist/stdlib/url.js +3 -3
- package/dist/stdlib/value.js +10 -10
- package/dist/tool-runtime.js +20 -20
- package/dist/values.d.ts +22 -16
- package/dist/values.js +23 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,6 +91,12 @@ runtime.execute(source) // Effect<CodeMode.Result, never, ToolServices>
|
|
|
91
91
|
The Effect environment is inferred from the supplied tools. `onToolCallStart` observes admitted calls with decoded
|
|
92
92
|
input; `onToolCallEnd` observes settled outcomes and duration. Both hooks return Effects and must not fail.
|
|
93
93
|
|
|
94
|
+
### `Values`
|
|
95
|
+
|
|
96
|
+
`Values` exports the runtime's non-JSON value classes: `Values.URL`, `Values.URLSearchParams`, `Values.Date`,
|
|
97
|
+
`Values.RegExp`, `Values.Map`, `Values.Set`, and `Values.Promise`. The interpreter recognizes these by class; a
|
|
98
|
+
program's `new URL(...)` is a `Values.URL` wrapping the host `URL`. `Values.isValue` narrows to the data-like kinds.
|
|
99
|
+
|
|
94
100
|
### OpenAPI tools
|
|
95
101
|
|
|
96
102
|
`OpenAPI.fromSpec` converts an OpenAPI 3.x document into one tool per supported operation. Dotted `operationId` values
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export * as CodeMode from "./codemode.js";
|
|
|
2
2
|
export * as Namespace from "./namespace.js";
|
|
3
3
|
export * as Tool from "./tool.js";
|
|
4
4
|
export * as OpenAPI from "./openapi/index.js";
|
|
5
|
+
export { Values } from "./values.js";
|
|
5
6
|
export { searchSignature, toolExpression } from "./codemode.js";
|
|
6
7
|
export { ToolError, toolError } from "./tool-error.js";
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,6 @@ export * as CodeMode from "./codemode.js";
|
|
|
2
2
|
export * as Namespace from "./namespace.js";
|
|
3
3
|
export * as Tool from "./tool.js";
|
|
4
4
|
export * as OpenAPI from "./openapi/index.js";
|
|
5
|
+
export { Values } from "./values.js";
|
|
5
6
|
export { searchSignature, toolExpression } from "./codemode.js";
|
|
6
7
|
export { ToolError, toolError } from "./tool-error.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { type AstNode, CodeModeFunction, CoercionFunction, ErrorConstructorReference, GlobalMethodReference, GlobalNamespace, IntrinsicReference, JsonMethodReference, PromiseCapabilityFunction, PromiseNamespace, UriFunction } from "./model.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Values } from "../values.js";
|
|
4
4
|
import { type SyncIteratorRunner } from "./iterator.js";
|
|
5
5
|
export type CallbackRunner<R> = {
|
|
6
6
|
readonly invokeFunction: (fn: CodeModeFunction, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>;
|
|
7
7
|
readonly invokeCallable: (callable: unknown, args: Array<unknown>, node: AstNode) => Effect.Effect<unknown, unknown, R>;
|
|
8
|
-
readonly settlePromise: (promise:
|
|
8
|
+
readonly settlePromise: (promise: Values.Promise) => Effect.Effect<unknown, unknown, never>;
|
|
9
9
|
};
|
|
10
10
|
export type SupportedCallback = CodeModeFunction | CoercionFunction | UriFunction | PromiseCapabilityFunction | GlobalMethodReference | JsonMethodReference | IntrinsicReference | ErrorConstructorReference | GlobalNamespace | PromiseNamespace;
|
|
11
11
|
export declare const isSupportedCallback: (value: unknown) => value is SupportedCallback;
|
|
@@ -2,7 +2,7 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { CodeModeFunction, CodeModeGenerator, CoercionFunction, ErrorConstructorReference, GlobalMethodReference, GlobalNamespace, IntrinsicReference, InterpreterRuntimeError, JsonMethodReference, PromiseCapabilityFunction, PromiseNamespace, UriFunction, } from "./model.js";
|
|
3
3
|
import { containsOpaqueReference, isRuntimeReference, rejectCircularInsertion, typeofValue } from "./references.js";
|
|
4
4
|
import { isBlockedMember } from "../tool-runtime.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Values } from "../values.js";
|
|
6
6
|
import { dateSetterArgumentCount, invokeDateMethod, invokeDateStatic } from "../stdlib/date.js";
|
|
7
7
|
import { invokeMathMethod } from "../stdlib/math.js";
|
|
8
8
|
import { invokeNumberMethod, invokeNumberStatic } from "../stdlib/number.js";
|
|
@@ -41,7 +41,7 @@ export const invokeIntrinsic = (runner, ref, args, node) => {
|
|
|
41
41
|
if (Array.isArray(ref.receiver)) {
|
|
42
42
|
return invokeArrayMethod(runner, ref.receiver, ref.name, args, node);
|
|
43
43
|
}
|
|
44
|
-
if (ref.receiver instanceof
|
|
44
|
+
if (ref.receiver instanceof Values.Date) {
|
|
45
45
|
const target = ref.receiver;
|
|
46
46
|
const argumentCount = dateSetterArgumentCount(ref.name);
|
|
47
47
|
if (argumentCount === undefined)
|
|
@@ -52,25 +52,25 @@ export const invokeIntrinsic = (runner, ref, args, node) => {
|
|
|
52
52
|
concurrency: 1,
|
|
53
53
|
}), (values) => invokeDateMethod(target, ref.name, values, node, initialTime));
|
|
54
54
|
}
|
|
55
|
-
if (ref.receiver instanceof
|
|
55
|
+
if (ref.receiver instanceof Values.RegExp) {
|
|
56
56
|
return Effect.succeed(invokeRegExpMethod(ref.receiver, ref.name, args, node));
|
|
57
57
|
}
|
|
58
|
-
if (ref.receiver instanceof
|
|
58
|
+
if (ref.receiver instanceof Values.Map) {
|
|
59
59
|
return invokeMapMethod(runner, ref.receiver, ref.name, args, node);
|
|
60
60
|
}
|
|
61
|
-
if (ref.receiver instanceof
|
|
61
|
+
if (ref.receiver instanceof Values.Set) {
|
|
62
62
|
return invokeSetMethod(runner, ref.receiver, ref.name, args, node);
|
|
63
63
|
}
|
|
64
|
-
if (ref.receiver instanceof
|
|
64
|
+
if (ref.receiver instanceof Values.URL) {
|
|
65
65
|
return Effect.succeed(invokeURLMethod(ref.receiver, ref.name, node));
|
|
66
66
|
}
|
|
67
|
-
if (ref.receiver instanceof
|
|
67
|
+
if (ref.receiver instanceof Values.URLSearchParams) {
|
|
68
68
|
return invokeURLSearchParamsMethod(runner, ref.receiver, ref.name, args, node);
|
|
69
69
|
}
|
|
70
70
|
throw new InterpreterRuntimeError(`Method '${ref.name}' is not available.`, node);
|
|
71
71
|
};
|
|
72
72
|
const coerceNumericArgument = (runner, value, node) => {
|
|
73
|
-
if (value === null || typeof value !== "object" || Array.isArray(value) ||
|
|
73
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || Values.isValue(value)) {
|
|
74
74
|
return Effect.succeed(coerceToNumber(value));
|
|
75
75
|
}
|
|
76
76
|
const object = value;
|
|
@@ -129,7 +129,7 @@ const invokeStringMethod = (value, name, args, node) => {
|
|
|
129
129
|
const optNum = (index) => (args[index] === undefined ? undefined : num(index));
|
|
130
130
|
const optStr = (index) => (args[index] === undefined ? undefined : str(index));
|
|
131
131
|
const rejectRegex = () => {
|
|
132
|
-
if (args[0] instanceof
|
|
132
|
+
if (args[0] instanceof Values.RegExp) {
|
|
133
133
|
throw new InterpreterRuntimeError(`String.${name} cannot take a regular expression; use regex.test(string) or String.search instead.`, node).as("TypeError");
|
|
134
134
|
}
|
|
135
135
|
};
|
|
@@ -172,7 +172,7 @@ const invokeStringMethod = (value, name, args, node) => {
|
|
|
172
172
|
result = requestedLimit !== undefined && requestedLimit >>> 0 === 0 ? [] : [value];
|
|
173
173
|
break;
|
|
174
174
|
}
|
|
175
|
-
if (args[0] instanceof
|
|
175
|
+
if (args[0] instanceof Values.RegExp) {
|
|
176
176
|
result = value.split(args[0].regex, optNum(1));
|
|
177
177
|
break;
|
|
178
178
|
}
|
|
@@ -203,7 +203,7 @@ const invokeStringMethod = (value, name, args, node) => {
|
|
|
203
203
|
break;
|
|
204
204
|
case "replace":
|
|
205
205
|
case "replaceAll": {
|
|
206
|
-
if (args[0] instanceof
|
|
206
|
+
if (args[0] instanceof Values.RegExp) {
|
|
207
207
|
const pattern = args[0].regex;
|
|
208
208
|
const replacement = str(1);
|
|
209
209
|
if (name === "replaceAll" && !pattern.global) {
|
|
@@ -292,7 +292,7 @@ const invokeArrayStatic = (name, args, node) => {
|
|
|
292
292
|
}
|
|
293
293
|
};
|
|
294
294
|
const arrayLikeSource = (source, node) => {
|
|
295
|
-
if (source instanceof
|
|
295
|
+
if (source instanceof Values.Promise) {
|
|
296
296
|
throw new InterpreterRuntimeError("Array.from received an un-awaited Promise; await it before creating the array.", node, "InvalidDataValue");
|
|
297
297
|
}
|
|
298
298
|
if (source !== null &&
|
|
@@ -347,7 +347,7 @@ export const invokeGroupBy = (runner, namespace, args, node) => {
|
|
|
347
347
|
throw new InterpreterRuntimeError(`${namespace}.groupBy expects an iterable collection.`, node).as("TypeError");
|
|
348
348
|
}
|
|
349
349
|
if (namespace === "Map") {
|
|
350
|
-
const result = new
|
|
350
|
+
const result = new Values.Map();
|
|
351
351
|
let index = 0;
|
|
352
352
|
while (true) {
|
|
353
353
|
const step = yield* cursor.next;
|
|
@@ -384,10 +384,10 @@ export const invokeGroupBy = (runner, namespace, args, node) => {
|
|
|
384
384
|
});
|
|
385
385
|
};
|
|
386
386
|
const coerceGroupByPropertyKey = (runner, value, node) => {
|
|
387
|
-
if (value === null || typeof value !== "object" || Array.isArray(value) ||
|
|
387
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || Values.isValue(value)) {
|
|
388
388
|
return Effect.succeed(coerceToString(value));
|
|
389
389
|
}
|
|
390
|
-
if (value instanceof
|
|
390
|
+
if (value instanceof Values.Promise)
|
|
391
391
|
return Effect.succeed("[object Promise]");
|
|
392
392
|
if (isRuntimeReference(value)) {
|
|
393
393
|
throw new InterpreterRuntimeError("Object.groupBy callback must return a data value.", node, "InvalidDataValue");
|
|
@@ -434,7 +434,7 @@ const invokeStringReplacer = (runner, value, name, args, node) => {
|
|
|
434
434
|
return match;
|
|
435
435
|
};
|
|
436
436
|
const pattern = args[0];
|
|
437
|
-
if (pattern instanceof
|
|
437
|
+
if (pattern instanceof Values.RegExp) {
|
|
438
438
|
if (name === "replaceAll" && !pattern.regex.global) {
|
|
439
439
|
throw new InterpreterRuntimeError(`String.replaceAll requires a regular expression with the global (g) flag: write /${pattern.regex.source}/${pattern.regex.flags}g, or use String.replace to replace only the first match.`, node);
|
|
440
440
|
}
|
|
@@ -456,7 +456,7 @@ const invokeStringReplacer = (runner, value, name, args, node) => {
|
|
|
456
456
|
for (const match of matches) {
|
|
457
457
|
const replacement = yield* apply(match.args);
|
|
458
458
|
// Error values are branded plain objects; boundedData would strip the brand before coercion.
|
|
459
|
-
output.push(value.slice(end, match.offset), replacement instanceof
|
|
459
|
+
output.push(value.slice(end, match.offset), replacement instanceof Values.Promise
|
|
460
460
|
? "[object Promise]"
|
|
461
461
|
: errorBrandName(replacement)
|
|
462
462
|
? coerceToString(replacement)
|
|
@@ -562,7 +562,7 @@ const invokeSetOperation = (runner, target, name, source, node) => Effect.gen(fu
|
|
|
562
562
|
return result;
|
|
563
563
|
}
|
|
564
564
|
if (name === "intersection") {
|
|
565
|
-
const result = new
|
|
565
|
+
const result = new Values.Set();
|
|
566
566
|
if (target.set.size <= other.size) {
|
|
567
567
|
for (const item of target.set.values()) {
|
|
568
568
|
if (yield* other.has(item))
|
|
@@ -631,27 +631,27 @@ const invokeSetOperation = (runner, target, name, source, node) => Effect.gen(fu
|
|
|
631
631
|
return true;
|
|
632
632
|
});
|
|
633
633
|
const copySet = (source) => {
|
|
634
|
-
const result = new
|
|
634
|
+
const result = new Values.Set();
|
|
635
635
|
for (const item of source.set.values())
|
|
636
636
|
result.set.add(item);
|
|
637
637
|
return result;
|
|
638
638
|
};
|
|
639
639
|
const loadSetRecord = (runner, source, name, node) => {
|
|
640
|
-
if (source instanceof
|
|
640
|
+
if (source instanceof Values.Set) {
|
|
641
641
|
return Effect.succeed({
|
|
642
642
|
size: source.set.size,
|
|
643
643
|
has: (item) => Effect.succeed(source.set.has(item)),
|
|
644
644
|
keys: () => Effect.succeed(source.set.values()),
|
|
645
645
|
});
|
|
646
646
|
}
|
|
647
|
-
if (source instanceof
|
|
647
|
+
if (source instanceof Values.Map) {
|
|
648
648
|
return Effect.succeed({
|
|
649
649
|
size: source.map.size,
|
|
650
650
|
has: (item) => Effect.succeed(source.map.has(item)),
|
|
651
651
|
keys: () => Effect.succeed(source.map.keys()),
|
|
652
652
|
});
|
|
653
653
|
}
|
|
654
|
-
if (source === null || typeof source !== "object" ||
|
|
654
|
+
if (source === null || typeof source !== "object" || Values.isValue(source)) {
|
|
655
655
|
throw new InterpreterRuntimeError(`Set.${name} expects a Set-like object.`, node).as("TypeError");
|
|
656
656
|
}
|
|
657
657
|
const object = source;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Effect } from "effect";
|
|
2
2
|
import type { SafeObject } from "../tool-runtime.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Values } from "../values.js";
|
|
4
4
|
export type SourcePosition = {
|
|
5
5
|
line: number;
|
|
6
6
|
column: number;
|
|
@@ -36,7 +36,7 @@ export type StatementResult = {
|
|
|
36
36
|
label?: string;
|
|
37
37
|
};
|
|
38
38
|
export type MemberReference = {
|
|
39
|
-
target: SafeObject | Array<unknown> |
|
|
39
|
+
target: SafeObject | Array<unknown> | Values.RegExp | Values.URL;
|
|
40
40
|
key: PropertyKey;
|
|
41
41
|
};
|
|
42
42
|
export declare class CodeModeFunction {
|
|
@@ -81,9 +81,9 @@ export declare class PromiseMethodReference {
|
|
|
81
81
|
}
|
|
82
82
|
export type PromiseInstanceMethodName = "then" | "catch" | "finally";
|
|
83
83
|
export declare class PromiseInstanceMethodReference {
|
|
84
|
-
readonly promise:
|
|
84
|
+
readonly promise: Values.Promise;
|
|
85
85
|
readonly name: PromiseInstanceMethodName;
|
|
86
|
-
constructor(promise:
|
|
86
|
+
constructor(promise: Values.Promise, name: PromiseInstanceMethodName);
|
|
87
87
|
}
|
|
88
88
|
export declare class PromiseCapabilityFunction {
|
|
89
89
|
readonly settle: (value: unknown) => void;
|
|
@@ -2,7 +2,7 @@ import { Effect, Exit, Scope } from "effect";
|
|
|
2
2
|
import type { Diagnostic } from "../codemode.js";
|
|
3
3
|
import { type AstNode, InterpreterRuntimeError, PromiseInstanceMethodReference, PromiseMethodReference } from "./model.js";
|
|
4
4
|
import { type CallbackRunner } from "./methods.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Values } from "../values.js";
|
|
6
6
|
import type { SyncIteratorRunner } from "./iterator.js";
|
|
7
7
|
export declare class PromiseRuntime<R> {
|
|
8
8
|
private readonly scope;
|
|
@@ -12,18 +12,18 @@ export declare class PromiseRuntime<R> {
|
|
|
12
12
|
private readonly failures;
|
|
13
13
|
private nextID;
|
|
14
14
|
constructor(scope: Scope.Scope);
|
|
15
|
-
create(effect: Effect.Effect<unknown, unknown, R>): Effect.Effect<
|
|
16
|
-
markObserved(promise:
|
|
17
|
-
await(promise:
|
|
15
|
+
create(effect: Effect.Effect<unknown, unknown, R>): Effect.Effect<Values.Promise, never, R>;
|
|
16
|
+
markObserved(promise: Values.Promise): void;
|
|
17
|
+
await(promise: Values.Promise): Effect.Effect<Exit.Exit<unknown, unknown>>;
|
|
18
18
|
fork(effect: Effect.Effect<unknown, unknown, R>): Effect.Effect<void, never, R>;
|
|
19
19
|
diagnostics(): Array<Diagnostic>;
|
|
20
20
|
interrupt(): Effect.Effect<Array<Diagnostic>>;
|
|
21
21
|
}
|
|
22
22
|
export declare const selfResolutionError: (node?: AstNode) => InterpreterRuntimeError;
|
|
23
23
|
export declare const resolvePromiseValue: <R>(runner: CallbackRunner<R>, value: unknown, node: AstNode, own?: {
|
|
24
|
-
promise?:
|
|
24
|
+
promise?: Values.Promise;
|
|
25
25
|
}) => Effect.Effect<unknown, unknown, R>;
|
|
26
|
-
export declare const resolvePromise: <R>(runner: CallbackRunner<R>, promises: PromiseRuntime<R>, value: unknown, node: AstNode) => Effect.Effect<
|
|
26
|
+
export declare const resolvePromise: <R>(runner: CallbackRunner<R>, promises: PromiseRuntime<R>, value: unknown, node: AstNode) => Effect.Effect<Values.Promise, never, R>;
|
|
27
27
|
export declare const invokePromiseMethod: <R>(runner: CallbackRunner<R> & SyncIteratorRunner<R>, promises: PromiseRuntime<R>, ref: PromiseMethodReference, args: Array<unknown>, node: AstNode) => Effect.Effect<unknown, unknown, R>;
|
|
28
|
-
export declare const invokePromiseInstanceMethod: <R>(runner: CallbackRunner<R>, promises: PromiseRuntime<R>, ref: PromiseInstanceMethodReference, args: Array<unknown>, node: AstNode) => Effect.Effect<
|
|
29
|
-
export declare const constructPromise: <R>(runner: CallbackRunner<R>, promises: PromiseRuntime<R>, executor: unknown, node: AstNode) => Effect.Effect<
|
|
28
|
+
export declare const invokePromiseInstanceMethod: <R>(runner: CallbackRunner<R>, promises: PromiseRuntime<R>, ref: PromiseInstanceMethodReference, args: Array<unknown>, node: AstNode) => Effect.Effect<Values.Promise, never, R>;
|
|
29
|
+
export declare const constructPromise: <R>(runner: CallbackRunner<R>, promises: PromiseRuntime<R>, executor: unknown, node: AstNode) => Effect.Effect<Values.Promise, unknown, R>;
|
|
@@ -4,7 +4,7 @@ import { caughtErrorValue, normalizeError } from "./errors.js";
|
|
|
4
4
|
import { applyCollectionCallback, isSupportedCallback } from "./methods.js";
|
|
5
5
|
import { typeofValue } from "./references.js";
|
|
6
6
|
import { createAggregateErrorValue } from "../stdlib/value.js";
|
|
7
|
-
import {
|
|
7
|
+
import { Values } from "../values.js";
|
|
8
8
|
// Observation only controls rejection reporting; program completion interrupts all promise work.
|
|
9
9
|
export class PromiseRuntime {
|
|
10
10
|
scope;
|
|
@@ -21,7 +21,7 @@ export class PromiseRuntime {
|
|
|
21
21
|
// Allocate before forking so reruns get distinct IDs and diagnostics retain creation order.
|
|
22
22
|
const id = this.nextID++;
|
|
23
23
|
return Effect.map(Effect.forkIn(effect, this.scope, { startImmediately: true }), (fiber) => {
|
|
24
|
-
const promise = new
|
|
24
|
+
const promise = new Values.Promise(fiber);
|
|
25
25
|
this.active.add(promise);
|
|
26
26
|
this.ids.set(promise, id);
|
|
27
27
|
fiber.addObserver((exit) => {
|
|
@@ -72,7 +72,7 @@ export const selfResolutionError = (node) => new InterpreterRuntimeError("Chaini
|
|
|
72
72
|
export const resolvePromiseValue = (runner, value, node, own) => {
|
|
73
73
|
if (own?.promise !== undefined && value === own.promise)
|
|
74
74
|
return Effect.fail(selfResolutionError(node));
|
|
75
|
-
if (value instanceof
|
|
75
|
+
if (value instanceof Values.Promise)
|
|
76
76
|
return runner.settlePromise(value);
|
|
77
77
|
if (value === null || typeof value !== "object" || !Object.hasOwn(value, "then"))
|
|
78
78
|
return Effect.succeed(value);
|
|
@@ -99,7 +99,7 @@ export const resolvePromiseValue = (runner, value, node, own) => {
|
|
|
99
99
|
});
|
|
100
100
|
};
|
|
101
101
|
export const resolvePromise = (runner, promises, value, node) => {
|
|
102
|
-
if (value instanceof
|
|
102
|
+
if (value instanceof Values.Promise)
|
|
103
103
|
return Effect.succeed(value);
|
|
104
104
|
const box = {};
|
|
105
105
|
return Effect.map(promises.create(resolvePromiseValue(runner, value, node, box)), (promise) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncIteratorSymbol, CodeModeFunction, CodeModeGenerator, CoercionFunction, ErrorConstructorReference, GlobalMethodReference, GlobalNamespace, GeneratorMethodReference, InterpreterRuntimeError, IntrinsicReference, IteratorSymbol, JsonMethodReference, PromiseCapabilityFunction, PromiseInstanceMethodReference, PromiseMethodReference, PromiseNamespace, SearchFunction, SymbolNamespace, UriFunction, } from "./model.js";
|
|
2
2
|
import { ToolReference } from "../tool-runtime.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Values } from "../values.js";
|
|
4
4
|
export const isRuntimeReference = (value) => value instanceof CodeModeFunction ||
|
|
5
5
|
value instanceof CodeModeGenerator ||
|
|
6
6
|
value instanceof GeneratorMethodReference ||
|
|
@@ -12,14 +12,14 @@ export const isRuntimeReference = (value) => value instanceof CodeModeFunction |
|
|
|
12
12
|
value instanceof PromiseNamespace ||
|
|
13
13
|
value instanceof PromiseMethodReference ||
|
|
14
14
|
value instanceof PromiseInstanceMethodReference ||
|
|
15
|
-
value instanceof
|
|
15
|
+
value instanceof Values.Promise ||
|
|
16
16
|
value instanceof CoercionFunction ||
|
|
17
17
|
value instanceof UriFunction ||
|
|
18
18
|
value instanceof SearchFunction ||
|
|
19
19
|
value instanceof PromiseCapabilityFunction ||
|
|
20
20
|
value instanceof ErrorConstructorReference ||
|
|
21
21
|
value instanceof SymbolNamespace ||
|
|
22
|
-
|
|
22
|
+
Values.isValue(value);
|
|
23
23
|
function* childValues(value) {
|
|
24
24
|
for (const key of Reflect.ownKeys(value)) {
|
|
25
25
|
if (!Object.prototype.propertyIsEnumerable.call(value, key))
|
|
@@ -59,7 +59,7 @@ export const containsOpaqueReference = (value) => {
|
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
61
61
|
const current = next.value;
|
|
62
|
-
if (
|
|
62
|
+
if (Values.isValue(current))
|
|
63
63
|
continue;
|
|
64
64
|
if (isRuntimeReference(current))
|
|
65
65
|
return true;
|
|
@@ -19,7 +19,7 @@ import { escapeRegexHint, regexpMethods, regexpProperties, regexpStatics, regexF
|
|
|
19
19
|
import { stringMethods, stringStatics } from "../stdlib/string.js";
|
|
20
20
|
import { urlMethods, urlProperties, urlSearchParamsMethods, urlStatics, urlWritableProperties, invokeUriFunction, uriArgument, urlArgument, } from "../stdlib/url.js";
|
|
21
21
|
import { boundedData, coerceToNumber, coerceToString, compoundOperators, errorBrandName, errorConstructors, invokeCoercion, valueConstructors, } from "../stdlib/value.js";
|
|
22
|
-
import {
|
|
22
|
+
import { Values } from "../values.js";
|
|
23
23
|
const globalStaticMembers = {
|
|
24
24
|
Object: objectStatics,
|
|
25
25
|
Math: mathMethods,
|
|
@@ -62,17 +62,17 @@ const instanceofValue = (lhs, rhs, node) => {
|
|
|
62
62
|
if (rhs instanceof GlobalNamespace) {
|
|
63
63
|
switch (rhs.name) {
|
|
64
64
|
case "Date":
|
|
65
|
-
return lhs instanceof
|
|
65
|
+
return lhs instanceof Values.Date;
|
|
66
66
|
case "RegExp":
|
|
67
|
-
return lhs instanceof
|
|
67
|
+
return lhs instanceof Values.RegExp;
|
|
68
68
|
case "Map":
|
|
69
|
-
return lhs instanceof
|
|
69
|
+
return lhs instanceof Values.Map;
|
|
70
70
|
case "Set":
|
|
71
|
-
return lhs instanceof
|
|
71
|
+
return lhs instanceof Values.Set;
|
|
72
72
|
case "URL":
|
|
73
|
-
return lhs instanceof
|
|
73
|
+
return lhs instanceof Values.URL;
|
|
74
74
|
case "URLSearchParams":
|
|
75
|
-
return lhs instanceof
|
|
75
|
+
return lhs instanceof Values.URLSearchParams;
|
|
76
76
|
case "Array":
|
|
77
77
|
return Array.isArray(lhs);
|
|
78
78
|
case "Object":
|
|
@@ -80,7 +80,7 @@ const instanceofValue = (lhs, rhs, node) => {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
if (rhs instanceof PromiseNamespace)
|
|
83
|
-
return lhs instanceof
|
|
83
|
+
return lhs instanceof Values.Promise;
|
|
84
84
|
if (rhs instanceof CoercionFunction && (rhs.name === "Number" || rhs.name === "String" || rhs.name === "Boolean")) {
|
|
85
85
|
return false;
|
|
86
86
|
}
|
|
@@ -594,11 +594,11 @@ export class Interpreter {
|
|
|
594
594
|
? value[Symbol.iterator]()
|
|
595
595
|
: typeof value === "string"
|
|
596
596
|
? value[Symbol.iterator]()
|
|
597
|
-
: value instanceof
|
|
597
|
+
: value instanceof Values.Map
|
|
598
598
|
? value.map.entries()
|
|
599
|
-
: value instanceof
|
|
599
|
+
: value instanceof Values.Set
|
|
600
600
|
? value.set.values()
|
|
601
|
-
: value instanceof
|
|
601
|
+
: value instanceof Values.URLSearchParams
|
|
602
602
|
? value.params.entries()
|
|
603
603
|
: undefined;
|
|
604
604
|
if (iterator !== undefined) {
|
|
@@ -1162,17 +1162,17 @@ export class Interpreter {
|
|
|
1162
1162
|
}
|
|
1163
1163
|
constructDate(args, node) {
|
|
1164
1164
|
if (args.length === 0)
|
|
1165
|
-
return Effect.succeed(new
|
|
1165
|
+
return Effect.succeed(new Values.Date(Date.now()));
|
|
1166
1166
|
if (args.length === 1) {
|
|
1167
1167
|
const arg = args[0];
|
|
1168
|
-
if (arg instanceof
|
|
1169
|
-
return Effect.succeed(new
|
|
1168
|
+
if (arg instanceof Values.Date)
|
|
1169
|
+
return Effect.succeed(new Values.Date(arg.time));
|
|
1170
1170
|
return Effect.map(this.toDatePrimitive(arg, node), (value) => typeof value === "string"
|
|
1171
|
-
? new
|
|
1172
|
-
: new
|
|
1171
|
+
? new Values.Date(Date.parse(value))
|
|
1172
|
+
: new Values.Date(new Date(coerceToNumber(value)).getTime()));
|
|
1173
1173
|
}
|
|
1174
1174
|
const parts = args.map((arg) => coerceToNumber(arg));
|
|
1175
|
-
return Effect.succeed(new
|
|
1175
|
+
return Effect.succeed(new Values.Date(new Date(...parts).getTime()));
|
|
1176
1176
|
}
|
|
1177
1177
|
toDatePrimitive(value, node) {
|
|
1178
1178
|
if (value === null || (typeof value !== "object" && typeof value !== "function"))
|
|
@@ -1197,14 +1197,14 @@ export class Interpreter {
|
|
|
1197
1197
|
}
|
|
1198
1198
|
constructRegExp(args, node) {
|
|
1199
1199
|
const first = args[0];
|
|
1200
|
-
const pattern = first instanceof
|
|
1200
|
+
const pattern = first instanceof Values.RegExp ? first.regex.source : first === undefined ? "" : coerceToString(first);
|
|
1201
1201
|
const flagsArg = args[1];
|
|
1202
1202
|
if (flagsArg !== undefined && typeof flagsArg !== "string") {
|
|
1203
1203
|
throw new InterpreterRuntimeError(`RegExp flags must be a string of flag characters (e.g. "g", "gi"), not ${flagsArg === null ? "null" : typeof flagsArg}.`, node).as("SyntaxError");
|
|
1204
1204
|
}
|
|
1205
|
-
const flags = flagsArg ?? (first instanceof
|
|
1205
|
+
const flags = flagsArg ?? (first instanceof Values.RegExp ? first.regex.flags : "");
|
|
1206
1206
|
try {
|
|
1207
|
-
return new
|
|
1207
|
+
return new Values.RegExp(pattern, flags);
|
|
1208
1208
|
}
|
|
1209
1209
|
catch (error) {
|
|
1210
1210
|
const reason = regexFailureReason(error);
|
|
@@ -1214,7 +1214,7 @@ export class Interpreter {
|
|
|
1214
1214
|
}
|
|
1215
1215
|
}
|
|
1216
1216
|
constructMap(init, node) {
|
|
1217
|
-
const target = new
|
|
1217
|
+
const target = new Values.Map();
|
|
1218
1218
|
if (init === undefined || init === null)
|
|
1219
1219
|
return Effect.succeed(target);
|
|
1220
1220
|
const self = this;
|
|
@@ -1237,7 +1237,7 @@ export class Interpreter {
|
|
|
1237
1237
|
});
|
|
1238
1238
|
}
|
|
1239
1239
|
constructSet(init, node) {
|
|
1240
|
-
const target = new
|
|
1240
|
+
const target = new Values.Set();
|
|
1241
1241
|
if (init === undefined || init === null)
|
|
1242
1242
|
return Effect.succeed(target);
|
|
1243
1243
|
const self = this;
|
|
@@ -1261,7 +1261,7 @@ export class Interpreter {
|
|
|
1261
1261
|
const input = urlArgument(args[0], "new URL input");
|
|
1262
1262
|
const base = args[1] === undefined ? undefined : urlArgument(args[1], "new URL base");
|
|
1263
1263
|
try {
|
|
1264
|
-
return new
|
|
1264
|
+
return new Values.URL(new URL(input, base));
|
|
1265
1265
|
}
|
|
1266
1266
|
catch {
|
|
1267
1267
|
throw new InterpreterRuntimeError(`new URL(...) received an invalid URL${base === undefined ? "" : " or base URL"}.`, node).as("TypeError");
|
|
@@ -1269,14 +1269,14 @@ export class Interpreter {
|
|
|
1269
1269
|
}
|
|
1270
1270
|
constructURLSearchParams(init, node) {
|
|
1271
1271
|
if (init === undefined)
|
|
1272
|
-
return Effect.succeed(new
|
|
1273
|
-
if (init instanceof
|
|
1274
|
-
return Effect.succeed(new
|
|
1272
|
+
return Effect.succeed(new Values.URLSearchParams(new URLSearchParams()));
|
|
1273
|
+
if (init instanceof Values.URLSearchParams) {
|
|
1274
|
+
return Effect.succeed(new Values.URLSearchParams(new URLSearchParams(init.params)));
|
|
1275
1275
|
}
|
|
1276
1276
|
if (typeof init === "string")
|
|
1277
|
-
return Effect.succeed(new
|
|
1277
|
+
return Effect.succeed(new Values.URLSearchParams(new URLSearchParams(init)));
|
|
1278
1278
|
if (init === null || typeof init === "number" || typeof init === "boolean") {
|
|
1279
|
-
return Effect.succeed(new
|
|
1279
|
+
return Effect.succeed(new Values.URLSearchParams(new URLSearchParams(coerceToString(init))));
|
|
1280
1280
|
}
|
|
1281
1281
|
const self = this;
|
|
1282
1282
|
return Effect.gen(function* () {
|
|
@@ -1289,7 +1289,7 @@ export class Interpreter {
|
|
|
1289
1289
|
if (entries.some((entry) => entry.length !== 2)) {
|
|
1290
1290
|
throw new InterpreterRuntimeError("new URLSearchParams(...) expects iterable [name, value] pairs.", node).as("TypeError");
|
|
1291
1291
|
}
|
|
1292
|
-
return new
|
|
1292
|
+
return new Values.URLSearchParams(new URLSearchParams(entries.map((entry) => [entry[0] ?? "", entry[1] ?? ""])));
|
|
1293
1293
|
}
|
|
1294
1294
|
entries.push(yield* preserveConsumerError(cursor, self.readURLSearchParamsPair(step.value, node)));
|
|
1295
1295
|
}
|
|
@@ -1297,13 +1297,13 @@ export class Interpreter {
|
|
|
1297
1297
|
if (isRuntimeReference(init)) {
|
|
1298
1298
|
throw new InterpreterRuntimeError("new URLSearchParams(...) expects a query string, data object, or synchronous iterable pairs.", node).as("TypeError");
|
|
1299
1299
|
}
|
|
1300
|
-
if (
|
|
1301
|
-
return new
|
|
1300
|
+
if (Values.isValue(init))
|
|
1301
|
+
return new Values.URLSearchParams(new URLSearchParams());
|
|
1302
1302
|
const data = boundedData(init, "new URLSearchParams input");
|
|
1303
1303
|
if (data === null || typeof data !== "object") {
|
|
1304
1304
|
throw new InterpreterRuntimeError("new URLSearchParams(...) expects a query string, data object, iterable pairs, or URLSearchParams.", node).as("TypeError");
|
|
1305
1305
|
}
|
|
1306
|
-
return new
|
|
1306
|
+
return new Values.URLSearchParams(new URLSearchParams(Object.fromEntries(Object.entries(data).map(([key, value]) => [key, coerceToString(value)]))));
|
|
1307
1307
|
});
|
|
1308
1308
|
}
|
|
1309
1309
|
readURLSearchParamsPair(value, node) {
|
|
@@ -1344,7 +1344,7 @@ export class Interpreter {
|
|
|
1344
1344
|
// Null-prototype data needs explicit primitive coercion; identity and `in` retain raw objects.
|
|
1345
1345
|
// Dates use their default string hint for addition and loose equality, and epoch time elsewhere.
|
|
1346
1346
|
const coerceOperand = (operand) => {
|
|
1347
|
-
if (operand instanceof
|
|
1347
|
+
if (operand instanceof Values.Date) {
|
|
1348
1348
|
return operator === "+" || operator === "==" || operator === "!=" ? coerceToString(operand) : operand.time;
|
|
1349
1349
|
}
|
|
1350
1350
|
return operand !== null && typeof operand === "object" ? coerceToString(operand) : operand;
|
|
@@ -1432,7 +1432,7 @@ export class Interpreter {
|
|
|
1432
1432
|
if (containsOpaqueReference(value)) {
|
|
1433
1433
|
throw new InterpreterRuntimeError("Unary operators require data values.", node, "InvalidDataValue");
|
|
1434
1434
|
}
|
|
1435
|
-
const operand = value instanceof
|
|
1435
|
+
const operand = value instanceof Values.Date
|
|
1436
1436
|
? value.time
|
|
1437
1437
|
: value !== null && typeof value === "object"
|
|
1438
1438
|
? coerceToString(value)
|
|
@@ -1870,9 +1870,9 @@ export class Interpreter {
|
|
|
1870
1870
|
return Effect.gen(function* () {
|
|
1871
1871
|
if (Array.isArray(value) ||
|
|
1872
1872
|
typeof value === "string" ||
|
|
1873
|
-
value instanceof
|
|
1874
|
-
value instanceof
|
|
1875
|
-
value instanceof
|
|
1873
|
+
value instanceof Values.Map ||
|
|
1874
|
+
value instanceof Values.Set ||
|
|
1875
|
+
value instanceof Values.URLSearchParams) {
|
|
1876
1876
|
const cursor = yield* self.syncIterator(value, node);
|
|
1877
1877
|
if (!cursor)
|
|
1878
1878
|
throw new InterpreterRuntimeError("Built-in iterator is unavailable.", node);
|
|
@@ -1947,7 +1947,7 @@ export class Interpreter {
|
|
|
1947
1947
|
const property = asNode(propertyValue, "properties");
|
|
1948
1948
|
if (property.type === "SpreadElement") {
|
|
1949
1949
|
const spread = yield* self.evaluateExpression(getNode(property, "argument"));
|
|
1950
|
-
if (spread === null || spread === undefined ||
|
|
1950
|
+
if (spread === null || spread === undefined || Values.isValue(spread))
|
|
1951
1951
|
continue;
|
|
1952
1952
|
if (typeof spread !== "object" || Array.isArray(spread) || isRuntimeReference(spread)) {
|
|
1953
1953
|
throw new InterpreterRuntimeError("Object spread requires a data object.", property, "InvalidDataValue");
|
|
@@ -2139,12 +2139,12 @@ export class Interpreter {
|
|
|
2139
2139
|
}
|
|
2140
2140
|
return new ComputedValue(undefined);
|
|
2141
2141
|
}
|
|
2142
|
-
if (objectValue instanceof
|
|
2142
|
+
if (objectValue instanceof Values.Date) {
|
|
2143
2143
|
if (typeof key === "string" && dateMethods.has(key))
|
|
2144
2144
|
return new IntrinsicReference(objectValue, key);
|
|
2145
2145
|
return new ComputedValue(undefined);
|
|
2146
2146
|
}
|
|
2147
|
-
if (objectValue instanceof
|
|
2147
|
+
if (objectValue instanceof Values.RegExp) {
|
|
2148
2148
|
if (key === "lastIndex")
|
|
2149
2149
|
return { target: objectValue, key };
|
|
2150
2150
|
if (typeof key === "string" && regexpProperties.has(key)) {
|
|
@@ -2154,21 +2154,21 @@ export class Interpreter {
|
|
|
2154
2154
|
return new IntrinsicReference(objectValue, key);
|
|
2155
2155
|
return new ComputedValue(undefined);
|
|
2156
2156
|
}
|
|
2157
|
-
if (objectValue instanceof
|
|
2157
|
+
if (objectValue instanceof Values.Map) {
|
|
2158
2158
|
if (key === "size")
|
|
2159
2159
|
return new ComputedValue(objectValue.map.size);
|
|
2160
2160
|
if (typeof key === "string" && mapMethods.has(key))
|
|
2161
2161
|
return new IntrinsicReference(objectValue, key);
|
|
2162
2162
|
return new ComputedValue(undefined);
|
|
2163
2163
|
}
|
|
2164
|
-
if (objectValue instanceof
|
|
2164
|
+
if (objectValue instanceof Values.Set) {
|
|
2165
2165
|
if (key === "size")
|
|
2166
2166
|
return new ComputedValue(objectValue.set.size);
|
|
2167
2167
|
if (typeof key === "string" && setMethods.has(key))
|
|
2168
2168
|
return new IntrinsicReference(objectValue, key);
|
|
2169
2169
|
return new ComputedValue(undefined);
|
|
2170
2170
|
}
|
|
2171
|
-
if (objectValue instanceof
|
|
2171
|
+
if (objectValue instanceof Values.URL) {
|
|
2172
2172
|
if (key === "searchParams") {
|
|
2173
2173
|
return new ComputedValue(objectValue.searchParams);
|
|
2174
2174
|
}
|
|
@@ -2178,7 +2178,7 @@ export class Interpreter {
|
|
|
2178
2178
|
return { target: objectValue, key };
|
|
2179
2179
|
return new ComputedValue(undefined);
|
|
2180
2180
|
}
|
|
2181
|
-
if (objectValue instanceof
|
|
2181
|
+
if (objectValue instanceof Values.URLSearchParams) {
|
|
2182
2182
|
if (key === "size")
|
|
2183
2183
|
return new ComputedValue(objectValue.params.size);
|
|
2184
2184
|
if (typeof key === "string" && urlSearchParamsMethods.has(key)) {
|
|
@@ -2187,7 +2187,7 @@ export class Interpreter {
|
|
|
2187
2187
|
return new ComputedValue(undefined);
|
|
2188
2188
|
}
|
|
2189
2189
|
// Reject unknown promise properties so a missing await cannot hide.
|
|
2190
|
-
if (objectValue instanceof
|
|
2190
|
+
if (objectValue instanceof Values.Promise) {
|
|
2191
2191
|
if (key === "then" || key === "catch" || key === "finally") {
|
|
2192
2192
|
return new PromiseInstanceMethodReference(objectValue, key);
|
|
2193
2193
|
}
|
|
@@ -2242,9 +2242,9 @@ export class Interpreter {
|
|
|
2242
2242
|
return new IntrinsicReference(reference.target, reference.key);
|
|
2243
2243
|
return Reflect.get(reference.target, reference.key);
|
|
2244
2244
|
}
|
|
2245
|
-
if (reference.target instanceof
|
|
2245
|
+
if (reference.target instanceof Values.RegExp)
|
|
2246
2246
|
return reference.target.lastIndex;
|
|
2247
|
-
if (reference.target instanceof
|
|
2247
|
+
if (reference.target instanceof Values.URL) {
|
|
2248
2248
|
return Reflect.get(reference.target.url, reference.key);
|
|
2249
2249
|
}
|
|
2250
2250
|
return Reflect.get(reference.target, reference.key);
|
|
@@ -2264,10 +2264,10 @@ export class Interpreter {
|
|
|
2264
2264
|
if (reference instanceof ComputedValue ||
|
|
2265
2265
|
reference === undefined ||
|
|
2266
2266
|
isOpaqueMemberReference(reference) ||
|
|
2267
|
-
reference.target instanceof
|
|
2267
|
+
reference.target instanceof Values.URL) {
|
|
2268
2268
|
throw new InterpreterRuntimeError("Only data fields may be deleted.", target, "InvalidDataValue");
|
|
2269
2269
|
}
|
|
2270
|
-
if (reference.target instanceof
|
|
2270
|
+
if (reference.target instanceof Values.RegExp) {
|
|
2271
2271
|
return Reflect.deleteProperty(reference.target.regex, reference.key);
|
|
2272
2272
|
}
|
|
2273
2273
|
return Reflect.deleteProperty(reference.target, reference.key);
|
|
@@ -2299,10 +2299,10 @@ export class Interpreter {
|
|
|
2299
2299
|
});
|
|
2300
2300
|
}
|
|
2301
2301
|
readReferenceValue(reference, key) {
|
|
2302
|
-
if (reference.target instanceof
|
|
2302
|
+
if (reference.target instanceof Values.URL) {
|
|
2303
2303
|
return Reflect.get(reference.target.url, key);
|
|
2304
2304
|
}
|
|
2305
|
-
if (reference.target instanceof
|
|
2305
|
+
if (reference.target instanceof Values.RegExp)
|
|
2306
2306
|
return reference.target.lastIndex;
|
|
2307
2307
|
return Reflect.get(reference.target, key);
|
|
2308
2308
|
}
|
|
@@ -2316,7 +2316,7 @@ export class Interpreter {
|
|
|
2316
2316
|
target[key] = next;
|
|
2317
2317
|
return;
|
|
2318
2318
|
}
|
|
2319
|
-
if (reference.target instanceof
|
|
2319
|
+
if (reference.target instanceof Values.URL) {
|
|
2320
2320
|
const property = key;
|
|
2321
2321
|
if (!urlWritableProperties.has(property)) {
|
|
2322
2322
|
throw new InterpreterRuntimeError(`URL.${property} is read-only.`, node).as("TypeError");
|
|
@@ -2332,7 +2332,7 @@ export class Interpreter {
|
|
|
2332
2332
|
throw new InterpreterRuntimeError(`URL.${property} received an invalid value.`, node).as("TypeError");
|
|
2333
2333
|
}
|
|
2334
2334
|
}
|
|
2335
|
-
if (reference.target instanceof
|
|
2335
|
+
if (reference.target instanceof Values.RegExp) {
|
|
2336
2336
|
reference.target.lastIndex = next;
|
|
2337
2337
|
return;
|
|
2338
2338
|
}
|
package/dist/stdlib/console.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { containsOpaqueReference, containsRuntimeReference, isRuntimeReference } from "../interpreter/references.js";
|
|
2
2
|
import { copyIn, copyOut } from "../tool-runtime.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Values } from "../values.js";
|
|
4
4
|
import { boundedData, coerceToString } from "./value.js";
|
|
5
5
|
export const consoleMethods = new Set(["log", "info", "debug", "warn", "error", "dir", "table"]);
|
|
6
6
|
const MAX_CONSOLE_DEPTH = 32;
|
|
@@ -28,21 +28,21 @@ const formatConsoleValue = (value, seen, depth) => {
|
|
|
28
28
|
return String(value);
|
|
29
29
|
if (typeof value !== "object")
|
|
30
30
|
return String(value);
|
|
31
|
-
if (value instanceof
|
|
31
|
+
if (value instanceof Values.Promise)
|
|
32
32
|
return "[Promise (await it to get its value)]";
|
|
33
|
-
if (value instanceof
|
|
33
|
+
if (value instanceof Values.Date)
|
|
34
34
|
return coerceToString(value);
|
|
35
|
-
if (value instanceof
|
|
35
|
+
if (value instanceof Values.RegExp)
|
|
36
36
|
return coerceToString(value);
|
|
37
|
-
if (value instanceof
|
|
37
|
+
if (value instanceof Values.URL)
|
|
38
38
|
return coerceToString(value);
|
|
39
|
-
if (value instanceof
|
|
39
|
+
if (value instanceof Values.URLSearchParams)
|
|
40
40
|
return coerceToString(value);
|
|
41
41
|
if (depth > MAX_CONSOLE_DEPTH)
|
|
42
42
|
return "...";
|
|
43
43
|
if (seen.has(value))
|
|
44
44
|
return "[Circular]";
|
|
45
|
-
if (value instanceof
|
|
45
|
+
if (value instanceof Values.Map) {
|
|
46
46
|
seen.add(value);
|
|
47
47
|
try {
|
|
48
48
|
const entries = Array.from(value.map.entries(), ([key, item]) => [key, item]);
|
|
@@ -52,7 +52,7 @@ const formatConsoleValue = (value, seen, depth) => {
|
|
|
52
52
|
seen.delete(value);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
if (value instanceof
|
|
55
|
+
if (value instanceof Values.Set) {
|
|
56
56
|
seen.add(value);
|
|
57
57
|
try {
|
|
58
58
|
return `Set(${value.set.size}) ${formatConsoleValue(Array.from(value.set.values()), seen, depth + 1)}`;
|
|
@@ -103,13 +103,13 @@ const consoleTableRows = (data, columns) => {
|
|
|
103
103
|
if (Array.isArray(data)) {
|
|
104
104
|
return data.map((item, index) => ({ index: String(index), values: consoleTableValues(item, columns) }));
|
|
105
105
|
}
|
|
106
|
-
if (data !== null && typeof data === "object" && !
|
|
106
|
+
if (data !== null && typeof data === "object" && !Values.isValue(data)) {
|
|
107
107
|
return Object.entries(data).map(([index, item]) => ({ index, values: consoleTableValues(item, columns) }));
|
|
108
108
|
}
|
|
109
109
|
return [{ index: "0", values: { Value: data } }];
|
|
110
110
|
};
|
|
111
111
|
const consoleTableValues = (value, columns) => {
|
|
112
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value) && !
|
|
112
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && !Values.isValue(value)) {
|
|
113
113
|
const source = value;
|
|
114
114
|
if (columns !== undefined)
|
|
115
115
|
return Object.fromEntries(columns.map((column) => [column, source[column]]));
|
package/dist/stdlib/date.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AstNode } from "../interpreter/model.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Values } from "../values.js";
|
|
3
3
|
export declare const dateMethods: Set<string>;
|
|
4
4
|
export declare const dateStatics: Set<string>;
|
|
5
5
|
export declare const invokeDateStatic: (name: string, args: Array<unknown>, node: AstNode) => number;
|
|
6
6
|
export declare const dateSetterArgumentCount: (name: string) => number | undefined;
|
|
7
|
-
export declare const invokeDateMethod: (value:
|
|
7
|
+
export declare const invokeDateMethod: (value: Values.Date, name: string, args: Array<number>, node: AstNode, initialTime?: number) => unknown;
|
package/dist/stdlib/date.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Values } from "../values.js";
|
|
3
3
|
import { coerceToNumber, coerceToString } from "./value.js";
|
|
4
4
|
const dateSetterArguments = new Map([
|
|
5
5
|
["setTime", 1],
|
package/dist/stdlib/json.js
CHANGED
|
@@ -3,7 +3,7 @@ import { applyCollectionCallback } from "../interpreter/methods.js";
|
|
|
3
3
|
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
4
4
|
import { typeofValue } from "../interpreter/references.js";
|
|
5
5
|
import { copyIn, copyOut } from "../tool-runtime.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Values } from "../values.js";
|
|
7
7
|
export const jsonStatics = new Set(["parse", "stringify"]);
|
|
8
8
|
export const invokeJsonMethod = (runner, name, args, node) => {
|
|
9
9
|
return name === "parse" ? parse(runner, args, node) : stringify(runner, args, node);
|
|
@@ -107,18 +107,18 @@ const stringify = (runner, args, node) => {
|
|
|
107
107
|
return Effect.map(visit(root, ""), (value) => JSON.stringify(value, null, indent));
|
|
108
108
|
};
|
|
109
109
|
const toJSONValue = (value) => {
|
|
110
|
-
if (value instanceof
|
|
110
|
+
if (value instanceof Values.Date) {
|
|
111
111
|
return Number.isFinite(value.time) ? new Date(value.time).toISOString() : null;
|
|
112
112
|
}
|
|
113
|
-
if (value instanceof
|
|
113
|
+
if (value instanceof Values.URL)
|
|
114
114
|
return value.url.href;
|
|
115
115
|
return value;
|
|
116
116
|
};
|
|
117
117
|
const isPlainObject = (value) => value !== null &&
|
|
118
118
|
typeof value === "object" &&
|
|
119
|
-
!(value instanceof
|
|
120
|
-
!(value instanceof
|
|
121
|
-
!(value instanceof
|
|
122
|
-
!(value instanceof
|
|
123
|
-
!(value instanceof
|
|
124
|
-
!(value instanceof
|
|
119
|
+
!(value instanceof Values.Date) &&
|
|
120
|
+
!(value instanceof Values.RegExp) &&
|
|
121
|
+
!(value instanceof Values.Map) &&
|
|
122
|
+
!(value instanceof Values.Set) &&
|
|
123
|
+
!(value instanceof Values.URL) &&
|
|
124
|
+
!(value instanceof Values.URLSearchParams);
|
package/dist/stdlib/object.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { AsyncIteratorSymbol, InterpreterRuntimeError, IteratorSymbol } from "../interpreter/model.js";
|
|
3
3
|
import { containsOpaqueReference, rejectCircularInsertion } from "../interpreter/references.js";
|
|
4
4
|
import { isBlockedMember } from "../tool-runtime.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Values } from "../values.js";
|
|
6
6
|
import { boundedData, coerceToString } from "./value.js";
|
|
7
7
|
import { preserveConsumerError } from "../interpreter/iterator.js";
|
|
8
8
|
export const objectMethodsPreservingIdentity = new Set(["assign", "values", "entries", "fromEntries"]);
|
|
@@ -12,9 +12,9 @@ export const invokeObjectMethod = (name, args, node) => {
|
|
|
12
12
|
const input = args[0];
|
|
13
13
|
if (Array.isArray(input))
|
|
14
14
|
return input;
|
|
15
|
-
if (
|
|
15
|
+
if (Values.isValue(input))
|
|
16
16
|
return {};
|
|
17
|
-
if (input instanceof
|
|
17
|
+
if (input instanceof Values.Promise) {
|
|
18
18
|
throw new InterpreterRuntimeError(`Object.${name} received an un-awaited Promise; await it before inspecting the result.`, node, "InvalidDataValue");
|
|
19
19
|
}
|
|
20
20
|
if (input === null || typeof input !== "object") {
|
|
@@ -42,7 +42,7 @@ export const invokeObjectMethod = (name, args, node) => {
|
|
|
42
42
|
return Object.is(args[0], args[1]);
|
|
43
43
|
case "assign": {
|
|
44
44
|
const target = args[0];
|
|
45
|
-
if (target === null || typeof target !== "object" || Array.isArray(target) ||
|
|
45
|
+
if (target === null || typeof target !== "object" || Array.isArray(target) || Values.isValue(target)) {
|
|
46
46
|
throw new InterpreterRuntimeError("Object.assign expects a data object target.", node);
|
|
47
47
|
}
|
|
48
48
|
const out = target;
|
|
@@ -55,7 +55,7 @@ export const invokeObjectMethod = (name, args, node) => {
|
|
|
55
55
|
throw new InterpreterRuntimeError(`Object.assign could not assign property '${String(key)}'.`, node).as("TypeError");
|
|
56
56
|
};
|
|
57
57
|
for (const source of args.slice(1)) {
|
|
58
|
-
if (source === null || source === undefined ||
|
|
58
|
+
if (source === null || source === undefined || Values.isValue(source))
|
|
59
59
|
continue;
|
|
60
60
|
if (typeof source !== "object" || Array.isArray(source)) {
|
|
61
61
|
throw new InterpreterRuntimeError("Object.assign expects data objects.", node);
|
|
@@ -92,7 +92,7 @@ export const invokeObjectFromEntries = (runner, source, node) => {
|
|
|
92
92
|
yield* preserveConsumerError(cursor, Effect.sync(() => {
|
|
93
93
|
if (step.value === null ||
|
|
94
94
|
typeof step.value !== "object" ||
|
|
95
|
-
|
|
95
|
+
Values.isValue(step.value) ||
|
|
96
96
|
containsOpaqueReference(step.value)) {
|
|
97
97
|
throw new InterpreterRuntimeError("Object.fromEntries expects [key, value] entry objects.", node).as("TypeError");
|
|
98
98
|
}
|
package/dist/stdlib/regexp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AstNode } from "../interpreter/model.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Values } from "../values.js";
|
|
3
3
|
export declare const regexpMethods: Set<string>;
|
|
4
4
|
export declare const regexpStatics: Set<string>;
|
|
5
5
|
export declare const regexpProperties: Set<string>;
|
|
@@ -8,4 +8,4 @@ export declare const escapeRegexHint = "To match special characters like ( ) [ ]
|
|
|
8
8
|
export declare const toHostRegex: (arg: unknown, method: string, node: AstNode, extraFlags?: string) => RegExp;
|
|
9
9
|
export declare const matchToValue: (match: RegExpMatchArray) => Array<unknown>;
|
|
10
10
|
export declare const invokeRegExpStatic: (name: string, args: Array<unknown>, node: AstNode) => string;
|
|
11
|
-
export declare const invokeRegExpMethod: (value:
|
|
11
|
+
export declare const invokeRegExpMethod: (value: Values.RegExp, name: string, args: Array<unknown>, node: AstNode) => unknown;
|
package/dist/stdlib/regexp.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
2
2
|
import { isBlockedMember } from "../tool-runtime.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Values } from "../values.js";
|
|
4
4
|
import { coerceToNumber, coerceToString } from "./value.js";
|
|
5
5
|
export const regexpMethods = new Set(["test", "exec", "toString"]);
|
|
6
6
|
export const regexpStatics = new Set(["escape"]);
|
|
@@ -23,7 +23,7 @@ export const toHostRegex = (arg, method, node, extraFlags = "") => {
|
|
|
23
23
|
// Native parity: an undefined pattern behaves as an empty pattern.
|
|
24
24
|
if (arg === undefined)
|
|
25
25
|
return new RegExp("", extraFlags);
|
|
26
|
-
if (arg instanceof
|
|
26
|
+
if (arg instanceof Values.RegExp)
|
|
27
27
|
return arg.regex;
|
|
28
28
|
if (typeof arg === "string") {
|
|
29
29
|
try {
|
package/dist/stdlib/url.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ export declare const uriArgument: (value: unknown, label: string) => string;
|
|
|
7
7
|
export declare const invokeUriFunction: (ref: UriFunction, args: Array<unknown>, node: AstNode) => string;
|
|
8
8
|
export declare const urlArgument: (value: unknown, label: string) => string;
|
|
9
9
|
export declare const invokeURLStatic: (name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
10
|
-
export declare const invokeURLMethod: (value:
|
|
10
|
+
export declare const invokeURLMethod: (value: Values.URL, name: string, node: AstNode) => string;
|
|
11
11
|
import { type AstNode, UriFunction } from "../interpreter/model.js";
|
|
12
|
-
import {
|
|
12
|
+
import { Values } from "../values.js";
|
package/dist/stdlib/url.js
CHANGED
|
@@ -58,7 +58,7 @@ export const invokeUriFunction = (ref, args, node) => {
|
|
|
58
58
|
throw new InterpreterRuntimeError(`${ref.name} received malformed URI data: ${error instanceof Error ? error.message : String(error)}`, node).as("URIError");
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
export const urlArgument = (value, label) => value instanceof
|
|
61
|
+
export const urlArgument = (value, label) => value instanceof Values.URL ? value.url.href : uriArgument(value, label);
|
|
62
62
|
export const invokeURLStatic = (name, args, node) => {
|
|
63
63
|
if (!urlStatics.has(name))
|
|
64
64
|
throw new InterpreterRuntimeError(`URL.${name} is not available.`, node);
|
|
@@ -68,7 +68,7 @@ export const invokeURLStatic = (name, args, node) => {
|
|
|
68
68
|
const base = args[1] === undefined ? undefined : urlArgument(args[1], `URL.${name} base`);
|
|
69
69
|
try {
|
|
70
70
|
const url = new URL(input, base);
|
|
71
|
-
return name === "canParse" ? true : new
|
|
71
|
+
return name === "canParse" ? true : new Values.URL(url);
|
|
72
72
|
}
|
|
73
73
|
catch {
|
|
74
74
|
return name === "canParse" ? false : null;
|
|
@@ -80,5 +80,5 @@ export const invokeURLMethod = (value, name, node) => {
|
|
|
80
80
|
throw new InterpreterRuntimeError(`URL method '${name}' is not available.`, node);
|
|
81
81
|
};
|
|
82
82
|
import { InterpreterRuntimeError, UriFunction } from "../interpreter/model.js";
|
|
83
|
-
import {
|
|
83
|
+
import { Values } from "../values.js";
|
|
84
84
|
import { boundedData, coerceToString } from "./value.js";
|
package/dist/stdlib/value.js
CHANGED
|
@@ -26,17 +26,17 @@ export const coerceToString = (value) => {
|
|
|
26
26
|
return "null";
|
|
27
27
|
if (value === undefined)
|
|
28
28
|
return "undefined";
|
|
29
|
-
if (value instanceof
|
|
29
|
+
if (value instanceof Values.Date)
|
|
30
30
|
return Number.isFinite(value.time) ? new Date(value.time).toISOString() : "Invalid Date";
|
|
31
|
-
if (value instanceof
|
|
31
|
+
if (value instanceof Values.RegExp)
|
|
32
32
|
return `/${value.regex.source}/${value.regex.flags}`;
|
|
33
|
-
if (value instanceof
|
|
33
|
+
if (value instanceof Values.Map)
|
|
34
34
|
return "[object Map]";
|
|
35
|
-
if (value instanceof
|
|
35
|
+
if (value instanceof Values.Set)
|
|
36
36
|
return "[object Set]";
|
|
37
|
-
if (value instanceof
|
|
37
|
+
if (value instanceof Values.URL)
|
|
38
38
|
return value.url.href;
|
|
39
|
-
if (value instanceof
|
|
39
|
+
if (value instanceof Values.URLSearchParams)
|
|
40
40
|
return value.params.toString();
|
|
41
41
|
if (errorBrandName(value) !== undefined) {
|
|
42
42
|
// Match Error.prototype.toString: "name: message", or just one when the other is empty.
|
|
@@ -57,9 +57,9 @@ export const coerceToString = (value) => {
|
|
|
57
57
|
return String(value);
|
|
58
58
|
};
|
|
59
59
|
export const coerceToNumber = (value) => {
|
|
60
|
-
if (value instanceof
|
|
60
|
+
if (value instanceof Values.Date)
|
|
61
61
|
return value.time;
|
|
62
|
-
if (
|
|
62
|
+
if (Values.isValue(value))
|
|
63
63
|
return Number.NaN;
|
|
64
64
|
// Arrays coerce through our own string coercion: host Number(array) joins with host
|
|
65
65
|
// ToPrimitive, which throws on the null-prototype objects the interpreter produces.
|
|
@@ -80,7 +80,7 @@ export const invokeCoercion = (ref, args, node) => {
|
|
|
80
80
|
// Error values are plain SafeObjects; the boundedData path below would strip their brand.
|
|
81
81
|
if (ref.name === "String" && errorBrandName(raw) !== undefined)
|
|
82
82
|
return coerceToString(raw);
|
|
83
|
-
if (
|
|
83
|
+
if (Values.isValue(raw)) {
|
|
84
84
|
if (ref.name === "Boolean")
|
|
85
85
|
return true;
|
|
86
86
|
if (ref.name === "Number")
|
|
@@ -117,4 +117,4 @@ export const invokeCoercion = (ref, args, node) => {
|
|
|
117
117
|
};
|
|
118
118
|
import { CoercionFunction, InterpreterRuntimeError } from "../interpreter/model.js";
|
|
119
119
|
import { copyIn } from "../tool-runtime.js";
|
|
120
|
-
import {
|
|
120
|
+
import { Values } from "../values.js";
|
package/dist/tool-runtime.js
CHANGED
|
@@ -3,7 +3,7 @@ import { toolError } from "./tool-error.js";
|
|
|
3
3
|
import { decodeInput as decodeToolInput, decodeOutput as decodeToolOutput, identifierSegment, inputProperties, inputTypeScript, isEmptyInput, outputTypeScript, } from "./tool-schema.js";
|
|
4
4
|
import { isNamespace } from "./namespace.js";
|
|
5
5
|
import { isTool } from "./tool.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Values } from "./values.js";
|
|
7
7
|
const compareText = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
|
|
8
8
|
const defaultSearchLimit = 10;
|
|
9
9
|
const PositiveInt = Schema.Int.check(Schema.isGreaterThan(0));
|
|
@@ -64,54 +64,54 @@ const copyBounded = (value, label, depth, seen, preserveCodeModeValues) => {
|
|
|
64
64
|
if (typeof value !== "object") {
|
|
65
65
|
throw new ToolRuntimeError("InvalidDataValue", `${label} must contain data only.`);
|
|
66
66
|
}
|
|
67
|
-
if (value instanceof
|
|
67
|
+
if (value instanceof Values.Promise) {
|
|
68
68
|
throw new ToolRuntimeError("InvalidDataValue", `${label} contains an un-awaited Promise; await tool calls (e.g. \`const result = await tools.ns.tool(...)\`) before using their results.`);
|
|
69
69
|
}
|
|
70
70
|
if (preserveCodeModeValues) {
|
|
71
|
-
if (value instanceof
|
|
72
|
-
value instanceof
|
|
73
|
-
value instanceof
|
|
74
|
-
value instanceof
|
|
75
|
-
value instanceof
|
|
76
|
-
value instanceof
|
|
71
|
+
if (value instanceof Values.Date ||
|
|
72
|
+
value instanceof Values.RegExp ||
|
|
73
|
+
value instanceof Values.Map ||
|
|
74
|
+
value instanceof Values.Set ||
|
|
75
|
+
value instanceof Values.URL ||
|
|
76
|
+
value instanceof Values.URLSearchParams) {
|
|
77
77
|
return value;
|
|
78
78
|
}
|
|
79
79
|
if (value instanceof Date)
|
|
80
|
-
return new
|
|
80
|
+
return new Values.Date(value.getTime());
|
|
81
81
|
if (value instanceof RegExp)
|
|
82
|
-
return new
|
|
82
|
+
return new Values.RegExp(value.source, value.flags);
|
|
83
83
|
if (value instanceof Map) {
|
|
84
|
-
const wrapped = new
|
|
84
|
+
const wrapped = new Values.Map();
|
|
85
85
|
for (const [key, item] of value.entries()) {
|
|
86
86
|
wrapped.map.set(copyBounded(key, label, depth + 1, seen, true), copyBounded(item, label, depth + 1, seen, true));
|
|
87
87
|
}
|
|
88
88
|
return wrapped;
|
|
89
89
|
}
|
|
90
90
|
if (value instanceof Set) {
|
|
91
|
-
const wrapped = new
|
|
91
|
+
const wrapped = new Values.Set();
|
|
92
92
|
for (const item of value.values())
|
|
93
93
|
wrapped.set.add(copyBounded(item, label, depth + 1, seen, true));
|
|
94
94
|
return wrapped;
|
|
95
95
|
}
|
|
96
96
|
if (value instanceof URL)
|
|
97
|
-
return new
|
|
97
|
+
return new Values.URL(new URL(value.href));
|
|
98
98
|
if (value instanceof URLSearchParams)
|
|
99
|
-
return new
|
|
99
|
+
return new Values.URLSearchParams(new URLSearchParams(value));
|
|
100
100
|
}
|
|
101
|
-
if (value instanceof
|
|
101
|
+
if (value instanceof Values.Date) {
|
|
102
102
|
return Number.isFinite(value.time) ? new Date(value.time).toISOString() : null;
|
|
103
103
|
}
|
|
104
104
|
if (value instanceof Date) {
|
|
105
105
|
return Number.isFinite(value.getTime()) ? value.toISOString() : null;
|
|
106
106
|
}
|
|
107
|
-
if (value instanceof
|
|
107
|
+
if (value instanceof Values.URL)
|
|
108
108
|
return value.url.href;
|
|
109
109
|
if (value instanceof URL)
|
|
110
110
|
return value.href;
|
|
111
|
-
if (value instanceof
|
|
112
|
-
value instanceof
|
|
113
|
-
value instanceof
|
|
114
|
-
value instanceof
|
|
111
|
+
if (value instanceof Values.RegExp ||
|
|
112
|
+
value instanceof Values.Map ||
|
|
113
|
+
value instanceof Values.Set ||
|
|
114
|
+
value instanceof Values.URLSearchParams ||
|
|
115
115
|
value instanceof RegExp ||
|
|
116
116
|
value instanceof Map ||
|
|
117
117
|
value instanceof Set ||
|
package/dist/values.d.ts
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
|
+
export * as Values from "./values.js";
|
|
1
2
|
import type { Fiber } from "effect";
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Runtime values the interpreter recognizes by class. Each wraps the host value it stands for,
|
|
5
|
+
* so hosts construct these to hand a value to a program and receive them back unchanged.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Promise {
|
|
3
8
|
readonly fiber: Fiber.Fiber<unknown, unknown>;
|
|
4
9
|
constructor(fiber: Fiber.Fiber<unknown, unknown>);
|
|
5
10
|
}
|
|
6
|
-
export declare class
|
|
11
|
+
export declare class Date {
|
|
7
12
|
time: number;
|
|
8
13
|
constructor(time: number);
|
|
9
14
|
}
|
|
10
|
-
export declare class
|
|
11
|
-
readonly regex: RegExp;
|
|
15
|
+
export declare class RegExp {
|
|
16
|
+
readonly regex: globalThis.RegExp;
|
|
12
17
|
constructor(pattern: string, flags: string);
|
|
13
18
|
get lastIndex(): unknown;
|
|
14
19
|
set lastIndex(value: unknown);
|
|
15
20
|
}
|
|
16
|
-
export declare class
|
|
17
|
-
readonly map: Map<unknown, unknown>;
|
|
21
|
+
export declare class Map {
|
|
22
|
+
readonly map: globalThis.Map<unknown, unknown>;
|
|
18
23
|
}
|
|
19
|
-
export declare class
|
|
20
|
-
readonly set: Set<unknown>;
|
|
24
|
+
export declare class Set {
|
|
25
|
+
readonly set: globalThis.Set<unknown>;
|
|
21
26
|
}
|
|
22
|
-
export declare class
|
|
23
|
-
readonly params: URLSearchParams;
|
|
24
|
-
constructor(params: URLSearchParams);
|
|
27
|
+
export declare class URLSearchParams {
|
|
28
|
+
readonly params: globalThis.URLSearchParams;
|
|
29
|
+
constructor(params: globalThis.URLSearchParams);
|
|
25
30
|
}
|
|
26
|
-
export declare class
|
|
27
|
-
readonly url: URL;
|
|
28
|
-
readonly searchParams:
|
|
29
|
-
constructor(url: URL);
|
|
31
|
+
export declare class URL {
|
|
32
|
+
readonly url: globalThis.URL;
|
|
33
|
+
readonly searchParams: URLSearchParams;
|
|
34
|
+
constructor(url: globalThis.URL);
|
|
30
35
|
}
|
|
31
|
-
|
|
36
|
+
/** Data-like runtime values; excludes Promise, which never crosses a boundary. */
|
|
37
|
+
export declare const isValue: (value: unknown) => value is Date | RegExp | Map | Set | URL | URLSearchParams;
|
package/dist/values.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * as Values from "./values.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime values the interpreter recognizes by class. Each wraps the host value it stands for,
|
|
4
|
+
* so hosts construct these to hand a value to a program and receive them back unchanged.
|
|
5
|
+
*/
|
|
6
|
+
export class Promise {
|
|
2
7
|
fiber;
|
|
3
8
|
constructor(fiber) {
|
|
4
9
|
this.fiber = fiber;
|
|
5
10
|
}
|
|
6
11
|
}
|
|
7
|
-
export class
|
|
12
|
+
export class Date {
|
|
8
13
|
time;
|
|
9
14
|
constructor(time) {
|
|
10
15
|
this.time = time;
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
|
-
export class
|
|
18
|
+
export class RegExp {
|
|
14
19
|
regex;
|
|
15
20
|
constructor(pattern, flags) {
|
|
16
|
-
this.regex = new RegExp(pattern, flags);
|
|
21
|
+
this.regex = new globalThis.RegExp(pattern, flags);
|
|
17
22
|
}
|
|
18
23
|
get lastIndex() {
|
|
19
24
|
return Reflect.get(this.regex, "lastIndex");
|
|
@@ -22,29 +27,30 @@ export class CodeModeRegExp {
|
|
|
22
27
|
Reflect.set(this.regex, "lastIndex", value);
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
|
-
export class
|
|
26
|
-
map = new Map();
|
|
30
|
+
export class Map {
|
|
31
|
+
map = new globalThis.Map();
|
|
27
32
|
}
|
|
28
|
-
export class
|
|
29
|
-
set = new Set();
|
|
33
|
+
export class Set {
|
|
34
|
+
set = new globalThis.Set();
|
|
30
35
|
}
|
|
31
|
-
export class
|
|
36
|
+
export class URLSearchParams {
|
|
32
37
|
params;
|
|
33
38
|
constructor(params) {
|
|
34
39
|
this.params = params;
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
|
-
export class
|
|
42
|
+
export class URL {
|
|
38
43
|
url;
|
|
39
44
|
searchParams;
|
|
40
45
|
constructor(url) {
|
|
41
46
|
this.url = url;
|
|
42
|
-
this.searchParams = new
|
|
47
|
+
this.searchParams = new URLSearchParams(url.searchParams);
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
value instanceof
|
|
48
|
-
value instanceof
|
|
49
|
-
value instanceof
|
|
50
|
-
value instanceof
|
|
50
|
+
/** Data-like runtime values; excludes Promise, which never crosses a boundary. */
|
|
51
|
+
export const isValue = (value) => value instanceof Date ||
|
|
52
|
+
value instanceof RegExp ||
|
|
53
|
+
value instanceof Map ||
|
|
54
|
+
value instanceof Set ||
|
|
55
|
+
value instanceof URL ||
|
|
56
|
+
value instanceof URLSearchParams;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/codemode",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-19329",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|