@opencode/codemode 0.0.0-beta-19289 → 0.0.0-beta-19365
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/codemode.d.ts +8 -11
- package/dist/codemode.js +4 -8
- package/dist/data.d.ts +28 -0
- package/dist/data.js +130 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpreter/errors.d.ts +1 -1
- package/dist/interpreter/errors.js +2 -2
- package/dist/interpreter/execute.d.ts +3 -3
- package/dist/interpreter/execute.js +9 -15
- package/dist/interpreter/methods.d.ts +9 -2
- package/dist/interpreter/methods.js +54 -76
- package/dist/interpreter/model.d.ts +12 -32
- package/dist/interpreter/model.js +0 -31
- package/dist/interpreter/promises.d.ts +8 -8
- package/dist/interpreter/promises.js +4 -4
- package/dist/interpreter/references.js +12 -42
- package/dist/interpreter/runtime.d.ts +2 -3
- package/dist/interpreter/runtime.js +255 -311
- package/dist/openapi/spec.js +1 -1
- package/dist/stdlib/console.js +14 -14
- package/dist/stdlib/date.d.ts +2 -2
- package/dist/stdlib/date.js +1 -1
- package/dist/stdlib/json.js +17 -26
- package/dist/stdlib/number.d.ts +1 -1
- package/dist/stdlib/number.js +4 -3
- package/dist/stdlib/object.js +11 -10
- package/dist/stdlib/regexp.d.ts +2 -2
- package/dist/stdlib/regexp.js +3 -3
- package/dist/stdlib/string.d.ts +1 -1
- package/dist/stdlib/string.js +1 -1
- package/dist/stdlib/url.d.ts +3 -3
- package/dist/stdlib/url.js +7 -6
- package/dist/stdlib/value.d.ts +2 -3
- package/dist/stdlib/value.js +14 -15
- package/dist/tool-runtime.d.ts +16 -15
- package/dist/tool-runtime.js +13 -150
- package/dist/values.d.ts +22 -16
- package/dist/values.js +23 -17
- package/package.json +1 -1
package/dist/openapi/spec.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fromSchemaOpenApi3_0, fromSchemaOpenApi3_1 } from "effect/JsonSchema";
|
|
2
|
-
import { isBlockedMember } from "../
|
|
2
|
+
import { isBlockedMember } from "../data.js";
|
|
3
3
|
export const methods = new Set(["get", "put", "post", "delete", "options", "head", "patch", "trace"]);
|
|
4
4
|
const parameterLocations = ["path", "query", "header"];
|
|
5
5
|
const ignoredHeaderParameters = new Set(["accept", "content-type", "authorization"]);
|
package/dist/stdlib/console.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { toData, toProgram } from "../data.js";
|
|
1
2
|
import { containsOpaqueReference, containsRuntimeReference, isRuntimeReference } from "../interpreter/references.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { boundedData, coerceToString } from "./value.js";
|
|
3
|
+
import { Values } from "../values.js";
|
|
4
|
+
import { 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;
|
|
7
7
|
export const formatConsoleMessage = (name, args) => {
|
|
@@ -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)}`;
|
|
@@ -81,7 +81,7 @@ const formatConsoleTable = (value, columnsArgument) => {
|
|
|
81
81
|
return "undefined";
|
|
82
82
|
if (containsOpaqueReference(value))
|
|
83
83
|
return "[opaque reference]";
|
|
84
|
-
const data =
|
|
84
|
+
const data = toProgram(value, "console.table argument");
|
|
85
85
|
const columns = consoleTableColumns(columnsArgument);
|
|
86
86
|
const rows = consoleTableRows(data, columns);
|
|
87
87
|
const keys = columns ?? Array.from(new Set(rows.flatMap((row) => Object.keys(row.values))));
|
|
@@ -96,20 +96,20 @@ const consoleTableColumns = (value) => {
|
|
|
96
96
|
return undefined;
|
|
97
97
|
if (containsRuntimeReference(value))
|
|
98
98
|
return undefined;
|
|
99
|
-
const columns =
|
|
99
|
+
const columns = toData(value, "console.table columns", "result");
|
|
100
100
|
return Array.isArray(columns) ? columns.map((column) => String(column)) : undefined;
|
|
101
101
|
};
|
|
102
102
|
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
|
@@ -2,8 +2,8 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { applyCollectionCallback } from "../interpreter/methods.js";
|
|
3
3
|
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
4
4
|
import { typeofValue } from "../interpreter/references.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { fromData, toData, toProgram } from "../data.js";
|
|
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);
|
|
@@ -14,7 +14,7 @@ const parse = (runner, args, node) => {
|
|
|
14
14
|
throw new InterpreterRuntimeError("JSON.parse expects a string.", node);
|
|
15
15
|
const parsed = (() => {
|
|
16
16
|
try {
|
|
17
|
-
return
|
|
17
|
+
return fromData(JSON.parse(text), "JSON.parse result");
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
20
20
|
throw new InterpreterRuntimeError(`JSON.parse received invalid JSON: ${error instanceof Error ? error.message : String(error)}`, node).as("SyntaxError");
|
|
@@ -54,27 +54,25 @@ const stringify = (runner, args, node) => {
|
|
|
54
54
|
const space = args[2];
|
|
55
55
|
const indent = typeof space === "number" || typeof space === "string" ? space : undefined;
|
|
56
56
|
const replacer = args[1];
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return Effect.succeed(JSON.stringify(copyOut(input, "json"), properties, indent));
|
|
65
|
-
}
|
|
66
|
-
if (!callable) {
|
|
67
|
-
return Effect.succeed(JSON.stringify(copyOut(input, "json"), null, indent));
|
|
57
|
+
if (typeofValue(replacer) !== "function") {
|
|
58
|
+
const properties = Array.isArray(replacer)
|
|
59
|
+
? replacer
|
|
60
|
+
.filter((item) => typeof item === "string" || typeof item === "number")
|
|
61
|
+
.map(String)
|
|
62
|
+
: null;
|
|
63
|
+
return Effect.succeed(JSON.stringify(toData(args[0], "JSON.stringify value"), properties, indent));
|
|
68
64
|
}
|
|
65
|
+
// Validate up front; the replacer walk below reads the original value.
|
|
66
|
+
toProgram(args[0], "JSON.stringify value");
|
|
69
67
|
const apply = applyCollectionCallback(runner, replacer, "JSON.stringify", node);
|
|
70
68
|
const root = Object.create(null);
|
|
71
|
-
root[""] =
|
|
69
|
+
root[""] = args[0];
|
|
72
70
|
const stack = new Set();
|
|
73
71
|
const visit = (holder, key) => Effect.gen(function* () {
|
|
74
72
|
const value = yield* apply([key, toJSONValue(holder[key])]);
|
|
75
73
|
if (value === undefined || typeofValue(value) === "function")
|
|
76
74
|
return undefined;
|
|
77
|
-
|
|
75
|
+
toProgram(value, "JSON.stringify replacer result");
|
|
78
76
|
if (typeof value === "number")
|
|
79
77
|
return Number.isFinite(value) ? value : null;
|
|
80
78
|
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
@@ -107,18 +105,11 @@ const stringify = (runner, args, node) => {
|
|
|
107
105
|
return Effect.map(visit(root, ""), (value) => JSON.stringify(value, null, indent));
|
|
108
106
|
};
|
|
109
107
|
const toJSONValue = (value) => {
|
|
110
|
-
if (value instanceof
|
|
108
|
+
if (value instanceof Values.Date) {
|
|
111
109
|
return Number.isFinite(value.time) ? new Date(value.time).toISOString() : null;
|
|
112
110
|
}
|
|
113
|
-
if (value instanceof
|
|
111
|
+
if (value instanceof Values.URL)
|
|
114
112
|
return value.url.href;
|
|
115
113
|
return value;
|
|
116
114
|
};
|
|
117
|
-
const isPlainObject = (value) => value !== null &&
|
|
118
|
-
typeof value === "object" &&
|
|
119
|
-
!(value instanceof CodeModeDate) &&
|
|
120
|
-
!(value instanceof CodeModeRegExp) &&
|
|
121
|
-
!(value instanceof CodeModeMap) &&
|
|
122
|
-
!(value instanceof CodeModeSet) &&
|
|
123
|
-
!(value instanceof CodeModeURL) &&
|
|
124
|
-
!(value instanceof CodeModeURLSearchParams);
|
|
115
|
+
const isPlainObject = (value) => value !== null && typeof value === "object" && !Values.isValue(value);
|
package/dist/stdlib/number.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type AstNode } from "../interpreter/model.js";
|
|
1
2
|
export declare const numberMethods: Set<string>;
|
|
2
3
|
export declare const numberConstants: Set<string>;
|
|
3
4
|
export declare const numberStatics: Set<string>;
|
|
4
5
|
export declare const invokeNumberMethod: (value: number, name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
5
6
|
export declare const invokeNumberStatic: (name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
6
|
-
import { type AstNode } from "../interpreter/model.js";
|
package/dist/stdlib/number.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
2
|
+
import { toProgram } from "../data.js";
|
|
3
|
+
import { coerceToString } from "./value.js";
|
|
1
4
|
export const numberMethods = new Set(["toFixed", "toPrecision", "toExponential", "toString", "valueOf"]);
|
|
2
5
|
export const numberConstants = new Set([
|
|
3
6
|
"MAX_SAFE_INTEGER",
|
|
@@ -46,7 +49,7 @@ export const invokeNumberMethod = (value, name, args, node) => {
|
|
|
46
49
|
default:
|
|
47
50
|
throw new InterpreterRuntimeError(`Number method '${name}' is not available.`, node);
|
|
48
51
|
}
|
|
49
|
-
return
|
|
52
|
+
return toProgram(result, `Number.${name} result`);
|
|
50
53
|
};
|
|
51
54
|
export const invokeNumberStatic = (name, args, node) => {
|
|
52
55
|
const value = args[0];
|
|
@@ -72,5 +75,3 @@ export const invokeNumberStatic = (name, args, node) => {
|
|
|
72
75
|
throw new InterpreterRuntimeError(`Number.${name} is not available.`, node);
|
|
73
76
|
}
|
|
74
77
|
};
|
|
75
|
-
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
76
|
-
import { boundedData, coerceToString } from "./value.js";
|
package/dist/stdlib/object.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { AsyncIteratorSymbol, InterpreterRuntimeError, IteratorSymbol } from "../interpreter/model.js";
|
|
3
3
|
import { containsOpaqueReference, rejectCircularInsertion } from "../interpreter/references.js";
|
|
4
|
-
import { isBlockedMember } from "../
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { isBlockedMember } from "../data.js";
|
|
5
|
+
import { Values } from "../values.js";
|
|
6
|
+
import { toProgram } from "../data.js";
|
|
7
|
+
import { coerceToString } from "./value.js";
|
|
7
8
|
import { preserveConsumerError } from "../interpreter/iterator.js";
|
|
8
9
|
export const objectMethodsPreservingIdentity = new Set(["assign", "values", "entries", "fromEntries"]);
|
|
9
10
|
export const objectStatics = new Set(["keys", "values", "entries", "hasOwn", "is", "assign", "fromEntries", "groupBy"]);
|
|
@@ -12,9 +13,9 @@ export const invokeObjectMethod = (name, args, node) => {
|
|
|
12
13
|
const input = args[0];
|
|
13
14
|
if (Array.isArray(input))
|
|
14
15
|
return input;
|
|
15
|
-
if (
|
|
16
|
+
if (Values.isValue(input))
|
|
16
17
|
return {};
|
|
17
|
-
if (input instanceof
|
|
18
|
+
if (input instanceof Values.Promise) {
|
|
18
19
|
throw new InterpreterRuntimeError(`Object.${name} received an un-awaited Promise; await it before inspecting the result.`, node, "InvalidDataValue");
|
|
19
20
|
}
|
|
20
21
|
if (input === null || typeof input !== "object") {
|
|
@@ -42,7 +43,7 @@ export const invokeObjectMethod = (name, args, node) => {
|
|
|
42
43
|
return Object.is(args[0], args[1]);
|
|
43
44
|
case "assign": {
|
|
44
45
|
const target = args[0];
|
|
45
|
-
if (target === null || typeof target !== "object" || Array.isArray(target) ||
|
|
46
|
+
if (target === null || typeof target !== "object" || Array.isArray(target) || Values.isValue(target)) {
|
|
46
47
|
throw new InterpreterRuntimeError("Object.assign expects a data object target.", node);
|
|
47
48
|
}
|
|
48
49
|
const out = target;
|
|
@@ -55,7 +56,7 @@ export const invokeObjectMethod = (name, args, node) => {
|
|
|
55
56
|
throw new InterpreterRuntimeError(`Object.assign could not assign property '${String(key)}'.`, node).as("TypeError");
|
|
56
57
|
};
|
|
57
58
|
for (const source of args.slice(1)) {
|
|
58
|
-
if (source === null || source === undefined ||
|
|
59
|
+
if (source === null || source === undefined || Values.isValue(source))
|
|
59
60
|
continue;
|
|
60
61
|
if (typeof source !== "object" || Array.isArray(source)) {
|
|
61
62
|
throw new InterpreterRuntimeError("Object.assign expects data objects.", node);
|
|
@@ -92,13 +93,13 @@ export const invokeObjectFromEntries = (runner, source, node) => {
|
|
|
92
93
|
yield* preserveConsumerError(cursor, Effect.sync(() => {
|
|
93
94
|
if (step.value === null ||
|
|
94
95
|
typeof step.value !== "object" ||
|
|
95
|
-
|
|
96
|
+
Values.isValue(step.value) ||
|
|
96
97
|
containsOpaqueReference(step.value)) {
|
|
97
98
|
throw new InterpreterRuntimeError("Object.fromEntries expects [key, value] entry objects.", node).as("TypeError");
|
|
98
99
|
}
|
|
99
100
|
const entry = step.value;
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
toProgram(entry[0], "Object.fromEntries key");
|
|
102
|
+
toProgram(entry[1], "Object.fromEntries value");
|
|
102
103
|
const key = coerceToString(entry[0]);
|
|
103
104
|
if (isBlockedMember(key))
|
|
104
105
|
throw new InterpreterRuntimeError(`Property '${key}' is not available.`, node);
|
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
|
-
import { isBlockedMember } from "../
|
|
3
|
-
import {
|
|
2
|
+
import { isBlockedMember } from "../data.js";
|
|
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/string.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { type AstNode } from "../interpreter/model.js";
|
|
1
2
|
export declare const stringMethods: Set<string>;
|
|
2
3
|
export declare const stringStatics: Set<string>;
|
|
3
4
|
export declare const invokeStringStatic: (name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
4
|
-
import { type AstNode } from "../interpreter/model.js";
|
package/dist/stdlib/string.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
1
2
|
export const stringMethods = new Set([
|
|
2
3
|
"toLowerCase",
|
|
3
4
|
"toUpperCase",
|
|
@@ -45,4 +46,3 @@ export const invokeStringStatic = (name, args, node) => {
|
|
|
45
46
|
throw new InterpreterRuntimeError(`String.${name} is not available.`, node);
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
|
-
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
package/dist/stdlib/url.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type AstNode, UriFunction } from "../interpreter/model.js";
|
|
2
|
+
import { Values } from "../values.js";
|
|
1
3
|
export declare const urlProperties: Set<string>;
|
|
2
4
|
export declare const urlWritableProperties: Set<string>;
|
|
3
5
|
export declare const urlMethods: Set<string>;
|
|
@@ -7,6 +9,4 @@ export declare const uriArgument: (value: unknown, label: string) => string;
|
|
|
7
9
|
export declare const invokeUriFunction: (ref: UriFunction, args: Array<unknown>, node: AstNode) => string;
|
|
8
10
|
export declare const urlArgument: (value: unknown, label: string) => string;
|
|
9
11
|
export declare const invokeURLStatic: (name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
10
|
-
export declare const invokeURLMethod: (value:
|
|
11
|
-
import { type AstNode, UriFunction } from "../interpreter/model.js";
|
|
12
|
-
import { CodeModeURL } from "../values.js";
|
|
12
|
+
export declare const invokeURLMethod: (value: Values.URL, name: string, node: AstNode) => string;
|
package/dist/stdlib/url.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { InterpreterRuntimeError, UriFunction } from "../interpreter/model.js";
|
|
2
|
+
import { Values } from "../values.js";
|
|
3
|
+
import { toProgram } from "../data.js";
|
|
4
|
+
import { coerceToString } from "./value.js";
|
|
1
5
|
export const urlProperties = new Set([
|
|
2
6
|
"href",
|
|
3
7
|
"origin",
|
|
@@ -39,7 +43,7 @@ export const urlSearchParamsMethods = new Set([
|
|
|
39
43
|
"entries",
|
|
40
44
|
"toString",
|
|
41
45
|
]);
|
|
42
|
-
export const uriArgument = (value, label) => coerceToString(
|
|
46
|
+
export const uriArgument = (value, label) => coerceToString(toProgram(value, label));
|
|
43
47
|
export const invokeUriFunction = (ref, args, node) => {
|
|
44
48
|
const value = uriArgument(args[0], `${ref.name} input`);
|
|
45
49
|
try {
|
|
@@ -58,7 +62,7 @@ export const invokeUriFunction = (ref, args, node) => {
|
|
|
58
62
|
throw new InterpreterRuntimeError(`${ref.name} received malformed URI data: ${error instanceof Error ? error.message : String(error)}`, node).as("URIError");
|
|
59
63
|
}
|
|
60
64
|
};
|
|
61
|
-
export const urlArgument = (value, label) => value instanceof
|
|
65
|
+
export const urlArgument = (value, label) => value instanceof Values.URL ? value.url.href : uriArgument(value, label);
|
|
62
66
|
export const invokeURLStatic = (name, args, node) => {
|
|
63
67
|
if (!urlStatics.has(name))
|
|
64
68
|
throw new InterpreterRuntimeError(`URL.${name} is not available.`, node);
|
|
@@ -68,7 +72,7 @@ export const invokeURLStatic = (name, args, node) => {
|
|
|
68
72
|
const base = args[1] === undefined ? undefined : urlArgument(args[1], `URL.${name} base`);
|
|
69
73
|
try {
|
|
70
74
|
const url = new URL(input, base);
|
|
71
|
-
return name === "canParse" ? true : new
|
|
75
|
+
return name === "canParse" ? true : new Values.URL(url);
|
|
72
76
|
}
|
|
73
77
|
catch {
|
|
74
78
|
return name === "canParse" ? false : null;
|
|
@@ -79,6 +83,3 @@ export const invokeURLMethod = (value, name, node) => {
|
|
|
79
83
|
return value.url.href;
|
|
80
84
|
throw new InterpreterRuntimeError(`URL method '${name}' is not available.`, node);
|
|
81
85
|
};
|
|
82
|
-
import { InterpreterRuntimeError, UriFunction } from "../interpreter/model.js";
|
|
83
|
-
import { CodeModeURL } from "../values.js";
|
|
84
|
-
import { boundedData, coerceToString } from "./value.js";
|
package/dist/stdlib/value.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { type AstNode, CoercionFunction } from "../interpreter/model.js";
|
|
2
|
+
import { type SafeObject } from "../data.js";
|
|
1
3
|
export declare const errorConstructors: Set<string>;
|
|
2
4
|
export declare const valueConstructors: Set<string>;
|
|
3
5
|
export declare const compoundOperators: Set<string>;
|
|
4
6
|
export declare const createErrorValue: (name: string, message: string) => SafeObject;
|
|
5
7
|
export declare const createAggregateErrorValue: (errors: Array<unknown>, message: string) => SafeObject;
|
|
6
8
|
export declare const errorBrandName: (value: unknown) => string | undefined;
|
|
7
|
-
export declare const boundedData: (value: unknown, label: string) => unknown;
|
|
8
9
|
export declare const coerceToString: (value: unknown) => string;
|
|
9
10
|
export declare const coerceToNumber: (value: unknown) => number;
|
|
10
11
|
export declare const invokeCoercion: (ref: CoercionFunction, args: Array<unknown>, node: AstNode) => unknown;
|
|
11
|
-
import { type AstNode, CoercionFunction } from "../interpreter/model.js";
|
|
12
|
-
import { type SafeObject } from "../tool-runtime.js";
|
package/dist/stdlib/value.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { CoercionFunction, InterpreterRuntimeError } from "../interpreter/model.js";
|
|
2
|
+
import { toProgram } from "../data.js";
|
|
3
|
+
import { Values } from "../values.js";
|
|
1
4
|
export const errorConstructors = new Set([
|
|
2
5
|
"Error",
|
|
3
6
|
"TypeError",
|
|
@@ -20,23 +23,22 @@ export const createAggregateErrorValue = (errors, message) => Object.assign(crea
|
|
|
20
23
|
export const errorBrandName = (value) => value !== null && typeof value === "object"
|
|
21
24
|
? value[ErrorBrand]
|
|
22
25
|
: undefined;
|
|
23
|
-
export const boundedData = (value, label) => copyIn(value, label, true);
|
|
24
26
|
export const coerceToString = (value) => {
|
|
25
27
|
if (value === null)
|
|
26
28
|
return "null";
|
|
27
29
|
if (value === undefined)
|
|
28
30
|
return "undefined";
|
|
29
|
-
if (value instanceof
|
|
31
|
+
if (value instanceof Values.Date)
|
|
30
32
|
return Number.isFinite(value.time) ? new Date(value.time).toISOString() : "Invalid Date";
|
|
31
|
-
if (value instanceof
|
|
33
|
+
if (value instanceof Values.RegExp)
|
|
32
34
|
return `/${value.regex.source}/${value.regex.flags}`;
|
|
33
|
-
if (value instanceof
|
|
35
|
+
if (value instanceof Values.Map)
|
|
34
36
|
return "[object Map]";
|
|
35
|
-
if (value instanceof
|
|
37
|
+
if (value instanceof Values.Set)
|
|
36
38
|
return "[object Set]";
|
|
37
|
-
if (value instanceof
|
|
39
|
+
if (value instanceof Values.URL)
|
|
38
40
|
return value.url.href;
|
|
39
|
-
if (value instanceof
|
|
41
|
+
if (value instanceof Values.URLSearchParams)
|
|
40
42
|
return value.params.toString();
|
|
41
43
|
if (errorBrandName(value) !== undefined) {
|
|
42
44
|
// Match Error.prototype.toString: "name: message", or just one when the other is empty.
|
|
@@ -57,9 +59,9 @@ export const coerceToString = (value) => {
|
|
|
57
59
|
return String(value);
|
|
58
60
|
};
|
|
59
61
|
export const coerceToNumber = (value) => {
|
|
60
|
-
if (value instanceof
|
|
62
|
+
if (value instanceof Values.Date)
|
|
61
63
|
return value.time;
|
|
62
|
-
if (
|
|
64
|
+
if (Values.isValue(value))
|
|
63
65
|
return Number.NaN;
|
|
64
66
|
// Arrays coerce through our own string coercion: host Number(array) joins with host
|
|
65
67
|
// ToPrimitive, which throws on the null-prototype objects the interpreter produces.
|
|
@@ -77,10 +79,10 @@ export const invokeCoercion = (ref, args, node) => {
|
|
|
77
79
|
return "";
|
|
78
80
|
}
|
|
79
81
|
const raw = args[0];
|
|
80
|
-
// Error values are plain SafeObjects; the
|
|
82
|
+
// Error values are plain SafeObjects; the toProgram path below would strip their brand.
|
|
81
83
|
if (ref.name === "String" && errorBrandName(raw) !== undefined)
|
|
82
84
|
return coerceToString(raw);
|
|
83
|
-
if (
|
|
85
|
+
if (Values.isValue(raw)) {
|
|
84
86
|
if (ref.name === "Boolean")
|
|
85
87
|
return true;
|
|
86
88
|
if (ref.name === "Number")
|
|
@@ -95,7 +97,7 @@ export const invokeCoercion = (ref, args, node) => {
|
|
|
95
97
|
return parseInt(coerceToString(raw));
|
|
96
98
|
return parseFloat(coerceToString(raw));
|
|
97
99
|
}
|
|
98
|
-
const value =
|
|
100
|
+
const value = toProgram(raw, `${ref.name} input`);
|
|
99
101
|
if (ref.name === "Number")
|
|
100
102
|
return coerceToNumber(value);
|
|
101
103
|
if (ref.name === "Boolean")
|
|
@@ -115,6 +117,3 @@ export const invokeCoercion = (ref, args, node) => {
|
|
|
115
117
|
return parseFloat(coerceToString(value));
|
|
116
118
|
return coerceToString(value);
|
|
117
119
|
};
|
|
118
|
-
import { CoercionFunction, InterpreterRuntimeError } from "../interpreter/model.js";
|
|
119
|
-
import { copyIn } from "../tool-runtime.js";
|
|
120
|
-
import { isCodeModeValue, CodeModeDate, CodeModeMap, CodeModeRegExp, CodeModeSet, CodeModeURL, CodeModeURLSearchParams, } from "../values.js";
|
package/dist/tool-runtime.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import { type Namespace } from "./namespace.js";
|
|
3
|
+
import { type Tool } from "./tool.js";
|
|
2
4
|
import type { Tools } from "./tools.js";
|
|
5
|
+
export declare const compareText: (left: string, right: string) => 0 | 1 | -1;
|
|
3
6
|
export type Services<T> = ServicesOf<T, []>;
|
|
4
7
|
type ServicesOf<T, Depth extends ReadonlyArray<unknown>> = Depth["length"] extends 8 ? never : T extends {
|
|
5
8
|
readonly _tag: "CodeModeTool";
|
|
@@ -22,7 +25,9 @@ export type ToolCallEnded = {
|
|
|
22
25
|
readonly message?: string;
|
|
23
26
|
};
|
|
24
27
|
export type ToolCallHooks<R = never> = {
|
|
28
|
+
/** Observes decoded tool input immediately before tool execution. */
|
|
25
29
|
readonly onToolCallStart?: ((call: ToolCallStarted) => Effect.Effect<void, never, R>) | undefined;
|
|
30
|
+
/** Observes each admitted tool call as it succeeds, fails, or is interrupted. */
|
|
26
31
|
readonly onToolCallEnd?: ((call: ToolCallEnded) => Effect.Effect<void, never, R>) | undefined;
|
|
27
32
|
};
|
|
28
33
|
export type ToolDescription = {
|
|
@@ -30,22 +35,19 @@ export type ToolDescription = {
|
|
|
30
35
|
readonly description: string;
|
|
31
36
|
readonly signature: string;
|
|
32
37
|
};
|
|
33
|
-
export type SafeObject = Record<string, unknown>;
|
|
34
38
|
export declare const toolExpression: (path: string) => string;
|
|
35
39
|
export declare class ToolReference {
|
|
36
40
|
readonly path: ReadonlyArray<string>;
|
|
37
41
|
constructor(path: ReadonlyArray<string>);
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
export declare const copyOut: (value: unknown, mode: CopyOutMode) => unknown;
|
|
48
|
-
export type DiscoveryPlan = {
|
|
43
|
+
type ToolNode<R> = {
|
|
44
|
+
tool?: Tool<R>;
|
|
45
|
+
namespace?: Namespace<R>;
|
|
46
|
+
readonly children: Map<string, ToolNode<R>>;
|
|
47
|
+
};
|
|
48
|
+
/** Tools indexed once per runtime: the lookup trie plus the model-facing catalog and search index. */
|
|
49
|
+
export type Prepared<R = never> = {
|
|
50
|
+
readonly root: ToolNode<R>;
|
|
49
51
|
readonly catalog: ReadonlyArray<ToolDescription>;
|
|
50
52
|
readonly searchIndex: ReadonlyArray<SearchEntry>;
|
|
51
53
|
};
|
|
@@ -55,14 +57,13 @@ export type SearchEntry = {
|
|
|
55
57
|
};
|
|
56
58
|
/** Exact callable signature of the built-in `search` function, for host-owned instructions. */
|
|
57
59
|
export declare const searchSignature: string;
|
|
58
|
-
export declare const
|
|
59
|
-
export declare const prepare: <R>(tools: Tools<R>) => DiscoveryPlan;
|
|
60
|
+
export declare const prepare: <R>(tools: Tools<R>) => Prepared<R>;
|
|
60
61
|
export type ToolRuntime<R = never> = {
|
|
61
|
-
readonly root: ToolReference;
|
|
62
62
|
readonly calls: Array<ToolCall>;
|
|
63
63
|
readonly execute: (path: ReadonlyArray<string>, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>;
|
|
64
64
|
readonly search: (args: Array<unknown>) => Effect.Effect<unknown, unknown, R>;
|
|
65
65
|
readonly keys: (path: ReadonlyArray<string>) => ReadonlyArray<string>;
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
/** Per-execution call state over tools prepared once for the runtime. */
|
|
68
|
+
export declare const make: <R>(prepared: Prepared<R>, maxToolCalls: number | undefined, hooks?: ToolCallHooks<R>) => ToolRuntime<R>;
|
|
68
69
|
export * as ToolRuntime from "./tool-runtime.js";
|