@opencode-ai/codemode 0.0.0-dev-17471
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 +168 -0
- package/dist/codemode.d.ts +148 -0
- package/dist/codemode.js +70 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/interpreter/errors.d.ts +9 -0
- package/dist/interpreter/errors.js +91 -0
- package/dist/interpreter/execute.d.ts +4 -0
- package/dist/interpreter/execute.js +178 -0
- package/dist/interpreter/iterator.d.ts +13 -0
- package/dist/interpreter/iterator.js +4 -0
- package/dist/interpreter/methods.d.ts +17 -0
- package/dist/interpreter/methods.js +1026 -0
- package/dist/interpreter/model.d.ts +151 -0
- package/dist/interpreter/model.js +186 -0
- package/dist/interpreter/promises.d.ts +29 -0
- package/dist/interpreter/promises.js +253 -0
- package/dist/interpreter/references.d.ts +6 -0
- package/dist/interpreter/references.js +114 -0
- package/dist/interpreter/runtime.d.ts +98 -0
- package/dist/interpreter/runtime.js +2351 -0
- package/dist/interpreter/scope.d.ts +15 -0
- package/dist/interpreter/scope.js +79 -0
- package/dist/interpreter/transpile.node.d.ts +5 -0
- package/dist/interpreter/transpile.node.js +19 -0
- package/dist/interpreter/transpile.workerd.d.ts +5 -0
- package/dist/interpreter/transpile.workerd.js +6 -0
- package/dist/openapi/index.d.ts +7 -0
- package/dist/openapi/index.js +101 -0
- package/dist/openapi/runtime.d.ts +4 -0
- package/dist/openapi/runtime.js +283 -0
- package/dist/openapi/spec.d.ts +20 -0
- package/dist/openapi/spec.js +588 -0
- package/dist/openapi/types.d.ts +122 -0
- package/dist/openapi/types.js +2 -0
- package/dist/stdlib/collections.d.ts +4 -0
- package/dist/stdlib/collections.js +57 -0
- package/dist/stdlib/console.d.ts +2 -0
- package/dist/stdlib/console.js +126 -0
- package/dist/stdlib/date.d.ts +7 -0
- package/dist/stdlib/date.js +186 -0
- package/dist/stdlib/json.d.ts +6 -0
- package/dist/stdlib/json.js +124 -0
- package/dist/stdlib/math.d.ts +12 -0
- package/dist/stdlib/math.js +157 -0
- package/dist/stdlib/number.d.ts +6 -0
- package/dist/stdlib/number.js +76 -0
- package/dist/stdlib/object.d.ts +7 -0
- package/dist/stdlib/object.js +100 -0
- package/dist/stdlib/promise.d.ts +2 -0
- package/dist/stdlib/promise.js +1 -0
- package/dist/stdlib/regexp.d.ts +11 -0
- package/dist/stdlib/regexp.js +106 -0
- package/dist/stdlib/string.d.ts +4 -0
- package/dist/stdlib/string.js +48 -0
- package/dist/stdlib/url.d.ts +12 -0
- package/dist/stdlib/url.js +84 -0
- package/dist/stdlib/value.d.ts +12 -0
- package/dist/stdlib/value.js +120 -0
- package/dist/tool-error.d.ts +11 -0
- package/dist/tool-error.js +9 -0
- package/dist/tool-runtime.d.ts +68 -0
- package/dist/tool-runtime.js +390 -0
- package/dist/tool-schema.d.ts +15 -0
- package/dist/tool-schema.js +213 -0
- package/dist/tool.d.ts +55 -0
- package/dist/tool.js +21 -0
- package/dist/tools.d.ts +4 -0
- package/dist/tools.js +1 -0
- package/dist/values.d.ts +31 -0
- package/dist/values.js +50 -0
- package/package.json +46 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { CodeModeFunction, CodeModeGenerator, CoercionFunction, ErrorConstructorReference, GlobalMethodReference, GlobalNamespace, GeneratorMethodReference, InterpreterRuntimeError, IntrinsicReference, JsonMethodReference, PromiseCapabilityFunction, PromiseInstanceMethodReference, PromiseMethodReference, PromiseNamespace, SearchFunction, SymbolNamespace, UriFunction, } from "./model.js";
|
|
2
|
+
import { ToolReference } from "../tool-runtime.js";
|
|
3
|
+
import { isCodeModeValue, CodeModePromise } from "../values.js";
|
|
4
|
+
export const isRuntimeReference = (value) => value instanceof CodeModeFunction ||
|
|
5
|
+
value instanceof CodeModeGenerator ||
|
|
6
|
+
value instanceof GeneratorMethodReference ||
|
|
7
|
+
value instanceof ToolReference ||
|
|
8
|
+
value instanceof IntrinsicReference ||
|
|
9
|
+
value instanceof GlobalNamespace ||
|
|
10
|
+
value instanceof GlobalMethodReference ||
|
|
11
|
+
value instanceof JsonMethodReference ||
|
|
12
|
+
value instanceof PromiseNamespace ||
|
|
13
|
+
value instanceof PromiseMethodReference ||
|
|
14
|
+
value instanceof PromiseInstanceMethodReference ||
|
|
15
|
+
value instanceof CodeModePromise ||
|
|
16
|
+
value instanceof CoercionFunction ||
|
|
17
|
+
value instanceof UriFunction ||
|
|
18
|
+
value instanceof SearchFunction ||
|
|
19
|
+
value instanceof PromiseCapabilityFunction ||
|
|
20
|
+
value instanceof ErrorConstructorReference ||
|
|
21
|
+
value instanceof SymbolNamespace ||
|
|
22
|
+
isCodeModeValue(value);
|
|
23
|
+
function* childValues(value) {
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
const length = value.length;
|
|
26
|
+
for (let index = 0; index < length; index++)
|
|
27
|
+
yield value[index];
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
yield* Object.values(value);
|
|
31
|
+
}
|
|
32
|
+
export const containsRuntimeReference = (value) => {
|
|
33
|
+
const pending = [[value].values()];
|
|
34
|
+
const seen = new Set();
|
|
35
|
+
while (pending.length > 0) {
|
|
36
|
+
const next = pending.at(-1).next();
|
|
37
|
+
if (next.done) {
|
|
38
|
+
pending.pop();
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const current = next.value;
|
|
42
|
+
if (isRuntimeReference(current))
|
|
43
|
+
return true;
|
|
44
|
+
if (current === null || typeof current !== "object" || seen.has(current))
|
|
45
|
+
continue;
|
|
46
|
+
seen.add(current);
|
|
47
|
+
pending.push(childValues(current));
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
// 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 (isCodeModeValue(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
|
+
};
|
|
73
|
+
// Reject cycles before mutation so later boundary walks remain safe.
|
|
74
|
+
export const rejectCircularInsertion = (container, value, label, node) => {
|
|
75
|
+
const pending = [[value].values()];
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
while (pending.length > 0) {
|
|
78
|
+
const next = pending.at(-1).next();
|
|
79
|
+
if (next.done) {
|
|
80
|
+
pending.pop();
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const current = next.value;
|
|
84
|
+
if (current === container)
|
|
85
|
+
throw new InterpreterRuntimeError(`${label} contains a circular value.`, node, "InvalidDataValue");
|
|
86
|
+
if (current === null || typeof current !== "object" || isRuntimeReference(current) || seen.has(current))
|
|
87
|
+
continue;
|
|
88
|
+
seen.add(current);
|
|
89
|
+
pending.push(Array.isArray(current) ? current[Symbol.iterator]() : childValues(current));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export const typeofValue = (value) => {
|
|
93
|
+
if (value instanceof CodeModeFunction ||
|
|
94
|
+
value instanceof GeneratorMethodReference ||
|
|
95
|
+
value instanceof CoercionFunction ||
|
|
96
|
+
value instanceof IntrinsicReference ||
|
|
97
|
+
value instanceof GlobalMethodReference ||
|
|
98
|
+
value instanceof JsonMethodReference ||
|
|
99
|
+
value instanceof PromiseMethodReference ||
|
|
100
|
+
value instanceof PromiseInstanceMethodReference ||
|
|
101
|
+
value instanceof PromiseNamespace ||
|
|
102
|
+
value instanceof PromiseCapabilityFunction ||
|
|
103
|
+
value instanceof ErrorConstructorReference ||
|
|
104
|
+
value instanceof SymbolNamespace)
|
|
105
|
+
return "function";
|
|
106
|
+
if (value instanceof UriFunction || value instanceof SearchFunction)
|
|
107
|
+
return "function";
|
|
108
|
+
if (value instanceof ToolReference)
|
|
109
|
+
return value.path.length > 0 ? "function" : "object";
|
|
110
|
+
if (value instanceof GlobalNamespace) {
|
|
111
|
+
return value.name === "Math" || value.name === "JSON" || value.name === "console" ? "object" : "function";
|
|
112
|
+
}
|
|
113
|
+
return typeof value;
|
|
114
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type ProgramNode } from "./model.js";
|
|
3
|
+
import { PromiseRuntime } from "./promises.js";
|
|
4
|
+
export declare class Interpreter<R> {
|
|
5
|
+
private scopes;
|
|
6
|
+
private readonly executeTool;
|
|
7
|
+
private readonly invokeSearch;
|
|
8
|
+
private readonly toolKeys;
|
|
9
|
+
private readonly logs;
|
|
10
|
+
private readonly promises;
|
|
11
|
+
private generatorState?;
|
|
12
|
+
private generatorAsync;
|
|
13
|
+
private readonly runner;
|
|
14
|
+
constructor(executeTool: (path: ReadonlyArray<string>, args: Array<unknown>) => Effect.Effect<unknown, unknown, R>, invokeSearch: (args: Array<unknown>) => Effect.Effect<unknown, unknown, R>, toolKeys: (path: ReadonlyArray<string>) => ReadonlyArray<string>, promises: PromiseRuntime<R>, logs?: Array<string>);
|
|
15
|
+
run(program: ProgramNode): Effect.Effect<unknown, unknown, R>;
|
|
16
|
+
private createToolCallPromise;
|
|
17
|
+
private createPromise;
|
|
18
|
+
private settlePromise;
|
|
19
|
+
private evaluateStatement;
|
|
20
|
+
private evaluateBlock;
|
|
21
|
+
private createFunction;
|
|
22
|
+
private hoistFunctions;
|
|
23
|
+
private predeclareLexical;
|
|
24
|
+
private predeclarePattern;
|
|
25
|
+
private evaluateIfStatement;
|
|
26
|
+
private evaluateSwitchStatement;
|
|
27
|
+
private evaluateWhileStatement;
|
|
28
|
+
private evaluateDoWhileStatement;
|
|
29
|
+
private evaluateForStatement;
|
|
30
|
+
private evaluateForOfStatement;
|
|
31
|
+
private awaitValue;
|
|
32
|
+
private awaitAsyncFromSyncValue;
|
|
33
|
+
private syncIterator;
|
|
34
|
+
private customIterator;
|
|
35
|
+
private nextIteratorResult;
|
|
36
|
+
private closeIterator;
|
|
37
|
+
private requireIteratorObject;
|
|
38
|
+
private requireIterator;
|
|
39
|
+
private requireIteratorMethod;
|
|
40
|
+
private enumerableKeys;
|
|
41
|
+
private evaluateForInStatement;
|
|
42
|
+
private evaluateBreakStatement;
|
|
43
|
+
private evaluateContinueStatement;
|
|
44
|
+
private evaluateLabeledStatement;
|
|
45
|
+
private evaluateThrowStatement;
|
|
46
|
+
private evaluateTryStatement;
|
|
47
|
+
private evaluateVariableDeclaration;
|
|
48
|
+
private declarePattern;
|
|
49
|
+
private assignPattern;
|
|
50
|
+
private destructureArrayPattern;
|
|
51
|
+
private destructuringPropertyKey;
|
|
52
|
+
private destructuringPropertyValue;
|
|
53
|
+
private evaluateExpression;
|
|
54
|
+
private evaluateNewExpression;
|
|
55
|
+
private constructArray;
|
|
56
|
+
private constructObject;
|
|
57
|
+
private constructDate;
|
|
58
|
+
private toDatePrimitive;
|
|
59
|
+
private constructRegExp;
|
|
60
|
+
private constructMap;
|
|
61
|
+
private constructSet;
|
|
62
|
+
private constructURL;
|
|
63
|
+
private constructURLSearchParams;
|
|
64
|
+
private readURLSearchParamsPair;
|
|
65
|
+
private evaluateBinaryExpression;
|
|
66
|
+
private applyBinaryOperator;
|
|
67
|
+
private evaluateLogicalExpression;
|
|
68
|
+
private evaluateUnaryExpression;
|
|
69
|
+
private evaluateAssignmentExpression;
|
|
70
|
+
private evaluateLogicalAssignment;
|
|
71
|
+
private evaluateUpdateExpression;
|
|
72
|
+
private evaluateCallExpression;
|
|
73
|
+
private invokeCallable;
|
|
74
|
+
private invokeObjectMethodOnTools;
|
|
75
|
+
private invokeConsole;
|
|
76
|
+
private evaluateCallArguments;
|
|
77
|
+
private invokeFunction;
|
|
78
|
+
private createGenerator;
|
|
79
|
+
private completeGeneratorRequests;
|
|
80
|
+
private takeGeneratorRequest;
|
|
81
|
+
private dequeueGeneratorRequest;
|
|
82
|
+
private evaluateYieldExpression;
|
|
83
|
+
private suspendGenerator;
|
|
84
|
+
private delegateYield;
|
|
85
|
+
private evaluateObjectExpression;
|
|
86
|
+
private evaluateArrayExpression;
|
|
87
|
+
private evaluateTemplateLiteral;
|
|
88
|
+
private evaluateConditionalExpression;
|
|
89
|
+
private applyCompoundAssignment;
|
|
90
|
+
private getMemberReference;
|
|
91
|
+
private readMember;
|
|
92
|
+
private writeMember;
|
|
93
|
+
private evaluateDeleteExpression;
|
|
94
|
+
private modifyMember;
|
|
95
|
+
private readReferenceValue;
|
|
96
|
+
private assignToReference;
|
|
97
|
+
private toPropertyKey;
|
|
98
|
+
}
|