@opencode/codemode 0.0.0-dev-19329 → 0.0.0-dev-19335
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/dist/interpreter/methods.d.ts +7 -0
- package/dist/interpreter/methods.js +26 -49
- package/dist/interpreter/model.d.ts +1 -1
- package/dist/interpreter/references.js +9 -39
- package/dist/interpreter/runtime.d.ts +0 -1
- package/dist/interpreter/runtime.js +2 -23
- package/dist/stdlib/json.js +1 -8
- package/dist/stdlib/number.d.ts +1 -1
- package/dist/stdlib/number.js +2 -2
- package/dist/stdlib/string.d.ts +1 -1
- package/dist/stdlib/string.js +1 -1
- package/dist/stdlib/url.d.ts +2 -2
- package/dist/stdlib/url.js +3 -3
- package/dist/stdlib/value.d.ts +2 -2
- package/dist/stdlib/value.js +3 -3
- package/dist/tool-runtime.d.ts +4 -2
- package/dist/tool-runtime.js +4 -12
- package/package.json +1 -1
|
@@ -10,6 +10,13 @@ export type CallbackRunner<R> = {
|
|
|
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;
|
|
12
12
|
export declare const invokeIntrinsic: <R>(runner: CallbackRunner<R>, ref: IntrinsicReference, args: Array<unknown>, node: AstNode) => Effect.Effect<unknown, unknown, R>;
|
|
13
|
+
/**
|
|
14
|
+
* ToPrimitive: tries an object's own `valueOf`/`toString` in hint order and returns the first
|
|
15
|
+
* primitive result. Runtime values behave like their JS counterparts (Date yields its time under a
|
|
16
|
+
* number hint; the rest yield their string form). An inherited `toString` yields the default
|
|
17
|
+
* string form, so plain objects become "[object Object]" and arrays join.
|
|
18
|
+
*/
|
|
19
|
+
export declare const toPrimitive: <R>(runner: CallbackRunner<R>, value: unknown, hint: "number" | "string", node: AstNode) => Effect.Effect<unknown, unknown, R>;
|
|
13
20
|
export declare const invokeGlobalMethod: (ref: GlobalMethodReference, args: Array<unknown>, node: AstNode) => unknown;
|
|
14
21
|
export declare const arrayStatics: Set<string>;
|
|
15
22
|
export declare const invokeArrayFrom: <R>(runner: CallbackRunner<R> & SyncIteratorRunner<R>, args: Array<unknown>, node: AstNode) => Effect.Effect<unknown, unknown, R>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
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
|
-
import { isBlockedMember } from "../tool-runtime.js";
|
|
4
|
+
import { compareText, isBlockedMember } from "../tool-runtime.js";
|
|
5
5
|
import { Values } from "../values.js";
|
|
6
6
|
import { dateSetterArgumentCount, invokeDateMethod, invokeDateStatic } from "../stdlib/date.js";
|
|
7
7
|
import { invokeMathMethod } from "../stdlib/math.js";
|
|
@@ -69,32 +69,36 @@ export const invokeIntrinsic = (runner, ref, args, node) => {
|
|
|
69
69
|
}
|
|
70
70
|
throw new InterpreterRuntimeError(`Method '${ref.name}' is not available.`, node);
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
/**
|
|
73
|
+
* ToPrimitive: tries an object's own `valueOf`/`toString` in hint order and returns the first
|
|
74
|
+
* primitive result. Runtime values behave like their JS counterparts (Date yields its time under a
|
|
75
|
+
* number hint; the rest yield their string form). An inherited `toString` yields the default
|
|
76
|
+
* string form, so plain objects become "[object Object]" and arrays join.
|
|
77
|
+
*/
|
|
78
|
+
export const toPrimitive = (runner, value, hint, node) => {
|
|
79
|
+
if (value === null || typeof value !== "object")
|
|
80
|
+
return Effect.succeed(value);
|
|
81
|
+
if (Values.isValue(value)) {
|
|
82
|
+
return Effect.succeed(value instanceof Values.Date && hint === "number" ? value.time : coerceToString(value));
|
|
75
83
|
}
|
|
76
84
|
const object = value;
|
|
85
|
+
const order = hint === "number" ? ["valueOf", "toString"] : ["toString", "valueOf"];
|
|
77
86
|
return Effect.gen(function* () {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (typeofValue(object.toString) === "function") {
|
|
87
|
-
const result = yield* runner.invokeCallable(object.toString, [], node);
|
|
88
|
-
if (result === null || (typeof result !== "object" && typeof result !== "function")) {
|
|
89
|
-
return coerceToNumber(result);
|
|
90
|
-
}
|
|
87
|
+
for (const method of order) {
|
|
88
|
+
if (method === "toString" && !Object.hasOwn(object, "toString"))
|
|
89
|
+
return coerceToString(value);
|
|
90
|
+
if (!Object.hasOwn(object, method) || typeofValue(object[method]) !== "function")
|
|
91
|
+
continue;
|
|
92
|
+
const result = yield* runner.invokeCallable(object[method], [], node);
|
|
93
|
+
if (result === null || (typeof result !== "object" && typeof result !== "function"))
|
|
94
|
+
return result;
|
|
91
95
|
}
|
|
92
96
|
throw new InterpreterRuntimeError("Cannot convert object to primitive value.", node).as("TypeError");
|
|
93
97
|
});
|
|
94
98
|
};
|
|
99
|
+
const coerceNumericArgument = (runner, value, node) => Effect.map(toPrimitive(runner, value, "number", node), coerceToNumber);
|
|
100
|
+
// console is intercepted by the interpreter before reaching here.
|
|
95
101
|
export const invokeGlobalMethod = (ref, args, node) => {
|
|
96
|
-
if (ref.namespace === "console")
|
|
97
|
-
throw new InterpreterRuntimeError(`console.${ref.name} is not available.`, node);
|
|
98
102
|
if (ref.namespace === "Object")
|
|
99
103
|
return invokeObjectMethod(ref.name, args, node);
|
|
100
104
|
if (ref.namespace === "Math")
|
|
@@ -111,9 +115,6 @@ export const invokeGlobalMethod = (ref, args, node) => {
|
|
|
111
115
|
return invokeDateStatic(ref.name, args, node);
|
|
112
116
|
if (ref.namespace === "RegExp")
|
|
113
117
|
return invokeRegExpStatic(ref.name, args, node);
|
|
114
|
-
if (ref.namespace === "Map" || ref.namespace === "Set" || ref.namespace === "URLSearchParams") {
|
|
115
|
-
throw new InterpreterRuntimeError(`${ref.namespace}.${ref.name} is not available.`, node);
|
|
116
|
-
}
|
|
117
118
|
throw new InterpreterRuntimeError(`${ref.namespace}.${ref.name} is not available.`, node);
|
|
118
119
|
};
|
|
119
120
|
const requireDataArgument = (name, index, arg, node) => {
|
|
@@ -384,32 +385,12 @@ export const invokeGroupBy = (runner, namespace, args, node) => {
|
|
|
384
385
|
});
|
|
385
386
|
};
|
|
386
387
|
const coerceGroupByPropertyKey = (runner, value, node) => {
|
|
387
|
-
if (value === null || typeof value !== "object" || Array.isArray(value) || Values.isValue(value)) {
|
|
388
|
-
return Effect.succeed(coerceToString(value));
|
|
389
|
-
}
|
|
390
388
|
if (value instanceof Values.Promise)
|
|
391
389
|
return Effect.succeed("[object Promise]");
|
|
392
|
-
if (isRuntimeReference(value)) {
|
|
390
|
+
if (!Values.isValue(value) && isRuntimeReference(value)) {
|
|
393
391
|
throw new InterpreterRuntimeError("Object.groupBy callback must return a data value.", node, "InvalidDataValue");
|
|
394
392
|
}
|
|
395
|
-
|
|
396
|
-
if (!Object.hasOwn(object, "toString"))
|
|
397
|
-
return Effect.succeed(coerceToString(value));
|
|
398
|
-
return Effect.gen(function* () {
|
|
399
|
-
if (typeofValue(object.toString) === "function") {
|
|
400
|
-
const result = yield* runner.invokeCallable(object.toString, [], node);
|
|
401
|
-
if (result === null || (typeof result !== "object" && typeof result !== "function")) {
|
|
402
|
-
return coerceToString(result);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
if (Object.hasOwn(object, "valueOf") && typeofValue(object.valueOf) === "function") {
|
|
406
|
-
const result = yield* runner.invokeCallable(object.valueOf, [], node);
|
|
407
|
-
if (result === null || (typeof result !== "object" && typeof result !== "function")) {
|
|
408
|
-
return coerceToString(result);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
throw new InterpreterRuntimeError("Cannot convert object to primitive value.", node).as("TypeError");
|
|
412
|
-
});
|
|
393
|
+
return Effect.map(toPrimitive(runner, value, "string", node), coerceToString);
|
|
413
394
|
};
|
|
414
395
|
const invokeStringReplacer = (runner, value, name, args, node) => {
|
|
415
396
|
const apply = applyCollectionCallback(runner, args[1], `String.${name}`, node);
|
|
@@ -992,11 +973,7 @@ const invokeArrayMethod = (runner, target, name, args, node) => {
|
|
|
992
973
|
};
|
|
993
974
|
const sortArray = (runner, target, comparator, name, node) => {
|
|
994
975
|
if (comparator === undefined) {
|
|
995
|
-
return Effect.sync(() => [...target].sort((a, b) =>
|
|
996
|
-
const left = coerceToString(a);
|
|
997
|
-
const right = coerceToString(b);
|
|
998
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
999
|
-
}));
|
|
976
|
+
return Effect.sync(() => [...target].sort((a, b) => compareText(coerceToString(a), coerceToString(b))));
|
|
1000
977
|
}
|
|
1001
978
|
const apply = applyCollectionCallback(runner, comparator, name, node);
|
|
1002
979
|
const mergeSort = (items) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Effect } from "effect";
|
|
2
|
+
import type { DiagnosticKind } from "../codemode.js";
|
|
2
3
|
import type { SafeObject } from "../tool-runtime.js";
|
|
3
4
|
import type { Values } from "../values.js";
|
|
4
5
|
export type SourcePosition = {
|
|
@@ -125,7 +126,6 @@ export declare class ErrorConstructorReference {
|
|
|
125
126
|
readonly name: string;
|
|
126
127
|
constructor(name: string);
|
|
127
128
|
}
|
|
128
|
-
export type DiagnosticKind = "ParseError" | "UnsupportedSyntax" | "UnknownTool" | "InvalidToolInput" | "InvalidToolOutput" | "InvalidDataValue" | "ToolCallLimitExceeded" | "TimeoutExceeded" | "ToolFailure" | "ExecutionFailure";
|
|
129
129
|
export declare const OptionalShortCircuit: unique symbol;
|
|
130
130
|
export declare const supportedSyntaxMessage = "Supported orchestration syntax: tools.* calls (they return promises - resolve them with await), data literals, destructuring, optional chaining, template literals, conditionals, switch, loops (incl. for...of and for...in over object/array/tools keys), arrow functions, spread, try/catch, array methods (map/filter/find/findIndex/some/every/reduce/flatMap/forEach/sort/slice/concat/indexOf/lastIndexOf/at/flat/reverse/includes/join), string methods (incl. match/matchAll/replace/split with regular expressions), Date/RegExp/Map/Set/URL/URLSearchParams, URI encoding helpers, Object/Math/JSON helpers, captured console.log/warn/error/dir/table, Promise.all/allSettled/race/any/resolve/reject over arrays mixing promises and plain values for parallel tool calls, promise chaining with .then/.catch/.finally, and new Promise((resolve, reject) => ...) construction.";
|
|
131
131
|
export declare class InterpreterRuntimeError extends Error {
|
|
@@ -29,9 +29,9 @@ function* childValues(value) {
|
|
|
29
29
|
yield Reflect.get(value, key);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
// Depth-first search over a value tree. `match` stops the walk; `skip` prunes a subtree without matching it.
|
|
33
|
+
const find = (value, match, skip, seen) => {
|
|
33
34
|
const pending = [[value].values()];
|
|
34
|
-
const seen = new Set();
|
|
35
35
|
while (pending.length > 0) {
|
|
36
36
|
const next = pending.at(-1).next();
|
|
37
37
|
if (next.done) {
|
|
@@ -39,53 +39,23 @@ export const containsRuntimeReference = (value) => {
|
|
|
39
39
|
continue;
|
|
40
40
|
}
|
|
41
41
|
const current = next.value;
|
|
42
|
-
if (
|
|
42
|
+
if (match(current))
|
|
43
43
|
return true;
|
|
44
|
-
if (current === null || typeof current !== "object" || seen.has(current))
|
|
44
|
+
if (current === null || typeof current !== "object" || skip(current) || seen.has(current))
|
|
45
45
|
continue;
|
|
46
46
|
seen.add(current);
|
|
47
47
|
pending.push(childValues(current));
|
|
48
48
|
}
|
|
49
49
|
return false;
|
|
50
50
|
};
|
|
51
|
+
const never = () => false;
|
|
52
|
+
export const containsRuntimeReference = (value) => find(value, isRuntimeReference, never, new Set());
|
|
51
53
|
// CodeMode values are data here, not opaque interpreter references.
|
|
52
|
-
export const containsOpaqueReference = (value) =>
|
|
53
|
-
const pending = [[value].values()];
|
|
54
|
-
const seen = new Set();
|
|
55
|
-
while (pending.length > 0) {
|
|
56
|
-
const next = pending.at(-1).next();
|
|
57
|
-
if (next.done) {
|
|
58
|
-
pending.pop();
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const current = next.value;
|
|
62
|
-
if (Values.isValue(current))
|
|
63
|
-
continue;
|
|
64
|
-
if (isRuntimeReference(current))
|
|
65
|
-
return true;
|
|
66
|
-
if (current === null || typeof current !== "object" || seen.has(current))
|
|
67
|
-
continue;
|
|
68
|
-
seen.add(current);
|
|
69
|
-
pending.push(childValues(current));
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
};
|
|
54
|
+
export const containsOpaqueReference = (value) => find(value, (current) => !Values.isValue(current) && isRuntimeReference(current), Values.isValue, new Set());
|
|
73
55
|
// Reject cycles before mutation so later boundary walks remain safe.
|
|
74
56
|
export const rejectCircularInsertion = (container, value, label, node, seen = new Set()) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const next = pending.at(-1).next();
|
|
78
|
-
if (next.done) {
|
|
79
|
-
pending.pop();
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
const current = next.value;
|
|
83
|
-
if (current === container)
|
|
84
|
-
throw new InterpreterRuntimeError(`${label} contains a circular value.`, node, "InvalidDataValue");
|
|
85
|
-
if (current === null || typeof current !== "object" || isRuntimeReference(current) || seen.has(current))
|
|
86
|
-
continue;
|
|
87
|
-
seen.add(current);
|
|
88
|
-
pending.push(childValues(current));
|
|
57
|
+
if (find(value, (current) => current === container, isRuntimeReference, seen)) {
|
|
58
|
+
throw new InterpreterRuntimeError(`${label} contains a circular value.`, node, "InvalidDataValue");
|
|
89
59
|
}
|
|
90
60
|
};
|
|
91
61
|
export const typeofValue = (value) => {
|
|
@@ -2,7 +2,7 @@ import { Cause, Deferred, Effect, Exit } from "effect";
|
|
|
2
2
|
import { isBlockedMember, ToolReference, ToolRuntimeError } from "../tool-runtime.js";
|
|
3
3
|
import { AsyncIteratorSymbol, asNode, CodeModeFunction, CodeModeGenerator, CoercionFunction, ComputedValue, ErrorConstructorReference, GlobalMethodReference, GlobalNamespace, GeneratorMethodReference, GeneratorReturn, getArray, getBoolean, getNode, getOptionalNode, getString, IntrinsicReference, InterpreterRuntimeError, isRecord, IteratorSymbol, IteratorSymbols, JsonMethodReference, OptionalShortCircuit, PromiseCapabilityFunction, PromiseInstanceMethodReference, PromiseMethodReference, PromiseNamespace, ProgramThrow, SearchFunction, SymbolNamespace, unsupportedSyntax, UriFunction, } from "./model.js";
|
|
4
4
|
import { caughtErrorValue, constructAggregateErrorValue, constructErrorValue } from "./errors.js";
|
|
5
|
-
import { arrayStatics, invokeArrayFrom, invokeGlobalMethod, invokeGroupBy, invokeIntrinsic, } from "./methods.js";
|
|
5
|
+
import { arrayStatics, invokeArrayFrom, invokeGlobalMethod, invokeGroupBy, invokeIntrinsic, toPrimitive, } from "./methods.js";
|
|
6
6
|
import { preserveConsumerError } from "./iterator.js";
|
|
7
7
|
import { constructPromise, invokePromiseInstanceMethod, invokePromiseMethod, PromiseRuntime, resolvePromise, resolvePromiseValue, } from "./promises.js";
|
|
8
8
|
import { containsOpaqueReference, isRuntimeReference, rejectCircularInsertion, typeofValue } from "./references.js";
|
|
@@ -1167,34 +1167,13 @@ export class Interpreter {
|
|
|
1167
1167
|
const arg = args[0];
|
|
1168
1168
|
if (arg instanceof Values.Date)
|
|
1169
1169
|
return Effect.succeed(new Values.Date(arg.time));
|
|
1170
|
-
return Effect.map(this.
|
|
1170
|
+
return Effect.map(toPrimitive(this.runner, arg, "number", node), (value) => typeof value === "string"
|
|
1171
1171
|
? new Values.Date(Date.parse(value))
|
|
1172
1172
|
: new Values.Date(new Date(coerceToNumber(value)).getTime()));
|
|
1173
1173
|
}
|
|
1174
1174
|
const parts = args.map((arg) => coerceToNumber(arg));
|
|
1175
1175
|
return Effect.succeed(new Values.Date(new Date(...parts).getTime()));
|
|
1176
1176
|
}
|
|
1177
|
-
toDatePrimitive(value, node) {
|
|
1178
|
-
if (value === null || (typeof value !== "object" && typeof value !== "function"))
|
|
1179
|
-
return Effect.succeed(value);
|
|
1180
|
-
const object = value;
|
|
1181
|
-
const self = this;
|
|
1182
|
-
return Effect.gen(function* () {
|
|
1183
|
-
if (Object.hasOwn(object, "valueOf") && typeofValue(object.valueOf) === "function") {
|
|
1184
|
-
const result = yield* self.runner.invokeCallable(object.valueOf, [], node);
|
|
1185
|
-
if (result === null || (typeof result !== "object" && typeof result !== "function"))
|
|
1186
|
-
return result;
|
|
1187
|
-
}
|
|
1188
|
-
if (!Object.hasOwn(object, "toString"))
|
|
1189
|
-
return coerceToString(value);
|
|
1190
|
-
if (typeofValue(object.toString) === "function") {
|
|
1191
|
-
const result = yield* self.runner.invokeCallable(object.toString, [], node);
|
|
1192
|
-
if (result === null || (typeof result !== "object" && typeof result !== "function"))
|
|
1193
|
-
return result;
|
|
1194
|
-
}
|
|
1195
|
-
throw new InterpreterRuntimeError("Cannot convert object to primitive value.", node).as("TypeError");
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
1177
|
constructRegExp(args, node) {
|
|
1199
1178
|
const first = args[0];
|
|
1200
1179
|
const pattern = first instanceof Values.RegExp ? first.regex.source : first === undefined ? "" : coerceToString(first);
|
package/dist/stdlib/json.js
CHANGED
|
@@ -114,11 +114,4 @@ const toJSONValue = (value) => {
|
|
|
114
114
|
return value.url.href;
|
|
115
115
|
return value;
|
|
116
116
|
};
|
|
117
|
-
const isPlainObject = (value) => value !== null &&
|
|
118
|
-
typeof value === "object" &&
|
|
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);
|
|
117
|
+
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,5 @@
|
|
|
1
|
+
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
2
|
+
import { boundedData, coerceToString } from "./value.js";
|
|
1
3
|
export const numberMethods = new Set(["toFixed", "toPrecision", "toExponential", "toString", "valueOf"]);
|
|
2
4
|
export const numberConstants = new Set([
|
|
3
5
|
"MAX_SAFE_INTEGER",
|
|
@@ -72,5 +74,3 @@ export const invokeNumberStatic = (name, args, node) => {
|
|
|
72
74
|
throw new InterpreterRuntimeError(`Number.${name} is not available.`, node);
|
|
73
75
|
}
|
|
74
76
|
};
|
|
75
|
-
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
76
|
-
import { boundedData, coerceToString } from "./value.js";
|
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>;
|
|
@@ -8,5 +10,3 @@ export declare const invokeUriFunction: (ref: UriFunction, args: Array<unknown>,
|
|
|
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
12
|
export declare const invokeURLMethod: (value: Values.URL, name: string, node: AstNode) => string;
|
|
11
|
-
import { type AstNode, UriFunction } from "../interpreter/model.js";
|
|
12
|
-
import { Values } from "../values.js";
|
package/dist/stdlib/url.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { InterpreterRuntimeError, UriFunction } from "../interpreter/model.js";
|
|
2
|
+
import { Values } from "../values.js";
|
|
3
|
+
import { boundedData, coerceToString } from "./value.js";
|
|
1
4
|
export const urlProperties = new Set([
|
|
2
5
|
"href",
|
|
3
6
|
"origin",
|
|
@@ -79,6 +82,3 @@ export const invokeURLMethod = (value, name, node) => {
|
|
|
79
82
|
return value.url.href;
|
|
80
83
|
throw new InterpreterRuntimeError(`URL method '${name}' is not available.`, node);
|
|
81
84
|
};
|
|
82
|
-
import { InterpreterRuntimeError, UriFunction } from "../interpreter/model.js";
|
|
83
|
-
import { Values } from "../values.js";
|
|
84
|
-
import { boundedData, coerceToString } from "./value.js";
|
package/dist/stdlib/value.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type AstNode, CoercionFunction } from "../interpreter/model.js";
|
|
2
|
+
import { type SafeObject } from "../tool-runtime.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>;
|
|
@@ -8,5 +10,3 @@ export declare const boundedData: (value: unknown, label: string) => unknown;
|
|
|
8
10
|
export declare const coerceToString: (value: unknown) => string;
|
|
9
11
|
export declare const coerceToNumber: (value: unknown) => number;
|
|
10
12
|
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 { copyIn } from "../tool-runtime.js";
|
|
3
|
+
import { Values } from "../values.js";
|
|
1
4
|
export const errorConstructors = new Set([
|
|
2
5
|
"Error",
|
|
3
6
|
"TypeError",
|
|
@@ -115,6 +118,3 @@ export const invokeCoercion = (ref, args, node) => {
|
|
|
115
118
|
return parseFloat(coerceToString(value));
|
|
116
119
|
return coerceToString(value);
|
|
117
120
|
};
|
|
118
|
-
import { CoercionFunction, InterpreterRuntimeError } from "../interpreter/model.js";
|
|
119
|
-
import { copyIn } from "../tool-runtime.js";
|
|
120
|
-
import { Values } from "../values.js";
|
package/dist/tool-runtime.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import type { DiagnosticKind } from "./codemode.js";
|
|
2
3
|
import type { Tools } from "./tools.js";
|
|
4
|
+
export declare const compareText: (left: string, right: string) => 0 | 1 | -1;
|
|
3
5
|
export type Services<T> = ServicesOf<T, []>;
|
|
4
6
|
type ServicesOf<T, Depth extends ReadonlyArray<unknown>> = Depth["length"] extends 8 ? never : T extends {
|
|
5
7
|
readonly _tag: "CodeModeTool";
|
|
@@ -37,9 +39,9 @@ export declare class ToolReference {
|
|
|
37
39
|
constructor(path: ReadonlyArray<string>);
|
|
38
40
|
}
|
|
39
41
|
export declare class ToolRuntimeError extends Error {
|
|
40
|
-
readonly kind: "UnknownTool" | "InvalidToolInput" | "InvalidToolOutput" | "InvalidDataValue" | "ToolCallLimitExceeded"
|
|
42
|
+
readonly kind: Extract<DiagnosticKind, "UnknownTool" | "InvalidToolInput" | "InvalidToolOutput" | "InvalidDataValue" | "ToolCallLimitExceeded">;
|
|
41
43
|
readonly suggestions: ReadonlyArray<string>;
|
|
42
|
-
constructor(kind: "UnknownTool" | "InvalidToolInput" | "InvalidToolOutput" | "InvalidDataValue" | "ToolCallLimitExceeded"
|
|
44
|
+
constructor(kind: Extract<DiagnosticKind, "UnknownTool" | "InvalidToolInput" | "InvalidToolOutput" | "InvalidDataValue" | "ToolCallLimitExceeded">, message: string, suggestions?: ReadonlyArray<string>);
|
|
43
45
|
}
|
|
44
46
|
export declare const isBlockedMember: (name: string) => boolean;
|
|
45
47
|
export declare const copyIn: (value: unknown, label: string, preserveCodeModeValues?: boolean) => unknown;
|
package/dist/tool-runtime.js
CHANGED
|
@@ -4,7 +4,7 @@ import { decodeInput as decodeToolInput, decodeOutput as decodeToolOutput, ident
|
|
|
4
4
|
import { isNamespace } from "./namespace.js";
|
|
5
5
|
import { isTool } from "./tool.js";
|
|
6
6
|
import { Values } from "./values.js";
|
|
7
|
-
const compareText = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
|
|
7
|
+
export 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));
|
|
10
10
|
const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
@@ -68,14 +68,8 @@ const copyBounded = (value, label, depth, seen, preserveCodeModeValues) => {
|
|
|
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 (
|
|
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) {
|
|
71
|
+
if (Values.isValue(value))
|
|
77
72
|
return value;
|
|
78
|
-
}
|
|
79
73
|
if (value instanceof Date)
|
|
80
74
|
return new Values.Date(value.getTime());
|
|
81
75
|
if (value instanceof RegExp)
|
|
@@ -108,10 +102,8 @@ const copyBounded = (value, label, depth, seen, preserveCodeModeValues) => {
|
|
|
108
102
|
return value.url.href;
|
|
109
103
|
if (value instanceof URL)
|
|
110
104
|
return value.href;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
value instanceof Values.Set ||
|
|
114
|
-
value instanceof Values.URLSearchParams ||
|
|
105
|
+
// Remaining runtime values and their host counterparts serialize as empty objects, like JSON.stringify.
|
|
106
|
+
if (Values.isValue(value) ||
|
|
115
107
|
value instanceof RegExp ||
|
|
116
108
|
value instanceof Map ||
|
|
117
109
|
value instanceof Set ||
|
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-19335",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|