@executor-js/codemode-core 0.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export declare const recoverExecutionBody: (code: string) => string;
2
+ //# sourceMappingURL=code-recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-recovery.d.ts","sourceRoot":"","sources":["../src/code-recovery.ts"],"names":[],"mappings":"AAuIA,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,MASnD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=code-recovery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-recovery.test.d.ts","sourceRoot":"","sources":["../src/code-recovery.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ declare const KernelCoreEffectError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
2
+ readonly _tag: "KernelCoreEffectError";
3
+ } & Readonly<A>;
4
+ export declare class KernelCoreEffectError extends KernelCoreEffectError_base<{
5
+ readonly module: string;
6
+ readonly message: string;
7
+ }> {
8
+ }
9
+ export declare const kernelCoreEffectError: (module: string, message: string) => KernelCoreEffectError;
10
+ export {};
11
+ //# sourceMappingURL=effect-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-errors.d.ts","sourceRoot":"","sources":["../src/effect-errors.ts"],"names":[],"mappings":";;;AAEA,qBAAa,qBAAsB,SAAQ,2BAA0C;IACnF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;CAAG;AAEL,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,EAAE,SAAS,MAAM,0BACrB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./types";
2
+ export * from "./validation";
3
+ export * from "./json-schema";
4
+ export * from "./effect-errors";
5
+ export * from "./code-recovery";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,227 @@
1
+ // src/types.ts
2
+ var asToolPath = (value) => value;
3
+ var unknownInputSchema = {
4
+ "~standard": {
5
+ version: 1,
6
+ vendor: "@executor-js/codemode-core",
7
+ validate: (value) => ({
8
+ value
9
+ })
10
+ }
11
+ };
12
+
13
+ // src/validation.ts
14
+ import * as Effect from "effect/Effect";
15
+
16
+ // src/effect-errors.ts
17
+ import * as Data from "effect/Data";
18
+ var KernelCoreEffectError = class extends Data.TaggedError("KernelCoreEffectError") {
19
+ };
20
+ var kernelCoreEffectError = (module, message) => new KernelCoreEffectError({ module, message });
21
+
22
+ // src/validation.ts
23
+ var getSchemaValidator = (schema) => {
24
+ if (!schema || typeof schema !== "object" && typeof schema !== "function") {
25
+ return null;
26
+ }
27
+ const standard = schema["~standard"];
28
+ if (!standard || typeof standard !== "object") {
29
+ return null;
30
+ }
31
+ const validate = standard.validate;
32
+ return typeof validate === "function" ? validate : null;
33
+ };
34
+ var formatIssuePath = (path) => {
35
+ if (!path || path.length === 0) {
36
+ return "$";
37
+ }
38
+ return path.map(
39
+ (segment) => typeof segment === "object" && segment !== null && "key" in segment ? String(segment.key) : String(segment)
40
+ ).join(".");
41
+ };
42
+ var formatIssues = (issues) => issues.map((issue) => `${formatIssuePath(issue.path)}: ${issue.message}`).join("; ");
43
+ var validateInput = (input) => {
44
+ const validate = getSchemaValidator(input.schema);
45
+ if (!validate) {
46
+ return Effect.fail(
47
+ kernelCoreEffectError(
48
+ "validation",
49
+ `Tool ${input.path} has no Standard Schema validator on inputSchema`
50
+ )
51
+ );
52
+ }
53
+ return Effect.tryPromise({
54
+ try: () => Promise.resolve(validate(input.value)),
55
+ catch: (cause) => kernelCoreEffectError("validation", `Validation error for ${input.path}: ${String(cause)}`)
56
+ }).pipe(
57
+ Effect.flatMap((result) => {
58
+ if ("issues" in result && result.issues) {
59
+ return Effect.fail(
60
+ kernelCoreEffectError(
61
+ "validation",
62
+ `Input validation failed for ${input.path}: ${formatIssues(result.issues)}`
63
+ )
64
+ );
65
+ }
66
+ return Effect.succeed(result.value);
67
+ })
68
+ );
69
+ };
70
+
71
+ // src/json-schema.ts
72
+ import Ajv2020 from "ajv/dist/2020";
73
+ import addFormats from "ajv-formats";
74
+ var ajv = new Ajv2020({
75
+ allErrors: true,
76
+ strict: false,
77
+ validateSchema: false,
78
+ allowUnionTypes: true
79
+ });
80
+ addFormats(ajv);
81
+ var decodePointerSegment = (segment) => {
82
+ const decoded = segment.replaceAll("~1", "/").replaceAll("~0", "~");
83
+ return /^\d+$/.test(decoded) ? Number(decoded) : decoded;
84
+ };
85
+ var pointerToPath = (pointer) => {
86
+ if (!pointer || pointer.length === 0 || pointer === "/") {
87
+ return void 0;
88
+ }
89
+ return pointer.split("/").slice(1).filter((segment) => segment.length > 0).map(decodePointerSegment);
90
+ };
91
+ var toIssueMessage = (error) => {
92
+ const keyword = error.keyword.trim();
93
+ const message = (error.message ?? "Invalid value").trim();
94
+ return keyword.length > 0 ? `${keyword}: ${message}` : message;
95
+ };
96
+ var standardSchemaFromJsonSchema = (schema, options) => {
97
+ try {
98
+ const validate = ajv.compile(schema);
99
+ return {
100
+ "~standard": {
101
+ version: 1,
102
+ vendor: options?.vendor ?? "json-schema",
103
+ validate: (value) => {
104
+ const valid = validate(value);
105
+ if (valid) {
106
+ return { value };
107
+ }
108
+ const issues = (validate.errors ?? []).map((error) => ({
109
+ message: toIssueMessage(error),
110
+ path: pointerToPath(error.instancePath)
111
+ }));
112
+ return {
113
+ issues: issues.length > 0 ? issues : [{ message: "Invalid value" }]
114
+ };
115
+ }
116
+ }
117
+ };
118
+ } catch {
119
+ return options?.fallback ?? unknownInputSchema;
120
+ }
121
+ };
122
+
123
+ // src/code-recovery.ts
124
+ import { parse } from "@babel/parser";
125
+ var FENCED_CODE_BLOCK = /```(?:[^\n`]*)?\s*\n([\s\S]*?)```/i;
126
+ var FUNCTION_DECLARATION = /^(?:async\s+)?function(?:\s+([a-zA-Z_$][a-zA-Z0-9_$]*))?\s*\(/;
127
+ var CALLABLE_ERROR = "Code must evaluate to a function";
128
+ var extractCandidateSource = (code) => {
129
+ const trimmed = code.trim();
130
+ if (!trimmed) return "";
131
+ const fenced = trimmed.match(FENCED_CODE_BLOCK)?.[1];
132
+ return (fenced ?? trimmed).trim();
133
+ };
134
+ var wrapCallableBody = (source) => [
135
+ "const __fn = (",
136
+ source,
137
+ ");",
138
+ `if (typeof __fn !== "function") throw new Error(${JSON.stringify(CALLABLE_ERROR)});`,
139
+ "return await __fn();"
140
+ ].join("\n");
141
+ var wrapNamedFunctionBody = (source, name) => [source, `return await ${name}();`].join("\n");
142
+ var wrapAnonymousFunctionBody = (source) => `return await (${source})();`;
143
+ var sliceNode = (source, node) => {
144
+ const start = node.start ?? 0;
145
+ const end = node.end ?? source.length;
146
+ return source.slice(start, end);
147
+ };
148
+ var unwrapExpression = (expression) => {
149
+ switch (expression.type) {
150
+ case "ParenthesizedExpression":
151
+ case "TSAsExpression":
152
+ case "TSSatisfiesExpression":
153
+ case "TSTypeAssertion":
154
+ case "TSNonNullExpression":
155
+ case "TSInstantiationExpression":
156
+ return expression.expression ? unwrapExpression(expression.expression) : expression;
157
+ default:
158
+ return expression;
159
+ }
160
+ };
161
+ var renderExportDefaultBody = (source, declaration) => {
162
+ if (declaration.type === "FunctionDeclaration") {
163
+ const fnSource = sliceNode(source, declaration);
164
+ const name = declaration.id?.name;
165
+ return name ? wrapNamedFunctionBody(fnSource, name) : wrapAnonymousFunctionBody(fnSource);
166
+ }
167
+ const expression = unwrapExpression(declaration);
168
+ const expressionSource = sliceNode(source, declaration);
169
+ if (expression?.type === "ArrowFunctionExpression" || expression?.type === "FunctionExpression") {
170
+ return wrapCallableBody(expressionSource);
171
+ }
172
+ return `return (${expressionSource});`;
173
+ };
174
+ var renderParsedBody = (source) => {
175
+ const program = parse(source, {
176
+ sourceType: "module",
177
+ allowAwaitOutsideFunction: true,
178
+ allowReturnOutsideFunction: true,
179
+ allowImportExportEverywhere: true,
180
+ plugins: ["typescript"]
181
+ }).program;
182
+ if (program.body.length !== 1) return source;
183
+ const [statement] = program.body;
184
+ if (!statement) return source;
185
+ switch (statement.type) {
186
+ case "ExpressionStatement": {
187
+ const expression = unwrapExpression(statement.expression);
188
+ return expression?.type === "ArrowFunctionExpression" || expression?.type === "FunctionExpression" ? wrapCallableBody(source) : source;
189
+ }
190
+ case "FunctionDeclaration":
191
+ return statement.id?.name ? wrapNamedFunctionBody(source, statement.id.name) : source;
192
+ case "ExportDefaultDeclaration":
193
+ return renderExportDefaultBody(source, statement.declaration);
194
+ default:
195
+ return source;
196
+ }
197
+ };
198
+ var renderHeuristicBody = (source) => {
199
+ const withoutDefaultExport = source.replace(/^export\s+default\s+/, "").trim();
200
+ if ((withoutDefaultExport.startsWith("async") || withoutDefaultExport.startsWith("(")) && withoutDefaultExport.includes("=>")) {
201
+ return wrapCallableBody(withoutDefaultExport);
202
+ }
203
+ if (FUNCTION_DECLARATION.test(withoutDefaultExport)) {
204
+ const name = withoutDefaultExport.match(FUNCTION_DECLARATION)?.[1];
205
+ return name ? wrapNamedFunctionBody(withoutDefaultExport, name) : wrapAnonymousFunctionBody(withoutDefaultExport);
206
+ }
207
+ return withoutDefaultExport;
208
+ };
209
+ var recoverExecutionBody = (code) => {
210
+ const source = extractCandidateSource(code);
211
+ if (!source) return "";
212
+ try {
213
+ return renderParsedBody(source);
214
+ } catch {
215
+ return renderHeuristicBody(source);
216
+ }
217
+ };
218
+ export {
219
+ KernelCoreEffectError,
220
+ asToolPath,
221
+ kernelCoreEffectError,
222
+ recoverExecutionBody,
223
+ standardSchemaFromJsonSchema,
224
+ unknownInputSchema,
225
+ validateInput
226
+ };
227
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../src/validation.ts","../src/effect-errors.ts","../src/json-schema.ts","../src/code-recovery.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type * as Effect from \"effect/Effect\";\n\n/** Branded tool path */\nexport type ToolPath = string & { readonly __toolPath: unique symbol };\n\nexport const asToolPath = (value: string): ToolPath => value as ToolPath;\n\n/** Standard Schema alias */\nexport type StandardSchema<Input = unknown, Output = unknown> = StandardSchemaV1<Input, Output>;\n\n/** A tool that can be invoked */\nexport interface Tool {\n readonly path: ToolPath;\n readonly description?: string;\n readonly inputSchema: StandardSchema;\n readonly outputSchema?: StandardSchema;\n readonly execute: (input: unknown) => unknown | Promise<unknown>;\n}\n\n/** Invoke a tool by path from inside a sandbox */\nexport interface SandboxToolInvoker {\n invoke(input: { path: string; args: unknown }): Effect.Effect<unknown, unknown>;\n}\n\n/** Result of executing code in a sandbox */\nexport type ExecuteResult = {\n result: unknown;\n error?: string;\n logs?: string[];\n};\n\n/** Executes code in a sandboxed runtime with tool access */\nexport interface CodeExecutor {\n execute(code: string, toolInvoker: SandboxToolInvoker): Effect.Effect<ExecuteResult, unknown>;\n}\n\n/** Accept-anything schema for tools with no input validation */\nexport const unknownInputSchema: StandardSchema = {\n \"~standard\": {\n version: 1,\n vendor: \"@executor/codemode-core\",\n validate: (value: unknown) => ({\n value,\n }),\n },\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport * as Effect from \"effect/Effect\";\n\nimport { kernelCoreEffectError } from \"./effect-errors\";\n\nconst getSchemaValidator = (\n schema: unknown,\n):\n | ((\n value: unknown,\n ) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>)\n | null => {\n if (!schema || (typeof schema !== \"object\" && typeof schema !== \"function\")) {\n return null;\n }\n\n const standard = (schema as { \"~standard\"?: unknown })[\"~standard\"];\n if (!standard || typeof standard !== \"object\") {\n return null;\n }\n\n const validate = (standard as { validate?: unknown }).validate;\n return typeof validate === \"function\"\n ? (validate as (\n value: unknown,\n ) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>)\n : null;\n};\n\nconst formatIssuePath = (\n path: ReadonlyArray<PropertyKey | StandardSchemaV1.PathSegment> | undefined,\n): string => {\n if (!path || path.length === 0) {\n return \"$\";\n }\n\n return path\n .map((segment) =>\n typeof segment === \"object\" && segment !== null && \"key\" in segment\n ? String(segment.key)\n : String(segment),\n )\n .join(\".\");\n};\n\nconst formatIssues = (issues: ReadonlyArray<StandardSchemaV1.Issue>): string =>\n issues.map((issue) => `${formatIssuePath(issue.path)}: ${issue.message}`).join(\"; \");\n\n/** Validate a value against a Standard Schema */\nexport const validateInput = (input: {\n schema: unknown;\n value: unknown;\n path: string;\n}): Effect.Effect<unknown, Error> => {\n const validate = getSchemaValidator(input.schema);\n if (!validate) {\n return Effect.fail(\n kernelCoreEffectError(\n \"validation\",\n `Tool ${input.path} has no Standard Schema validator on inputSchema`,\n ),\n );\n }\n\n return Effect.tryPromise({\n try: () => Promise.resolve(validate(input.value)),\n catch: (cause) =>\n kernelCoreEffectError(\"validation\", `Validation error for ${input.path}: ${String(cause)}`),\n }).pipe(\n Effect.flatMap((result) => {\n if (\"issues\" in result && result.issues) {\n return Effect.fail(\n kernelCoreEffectError(\n \"validation\",\n `Input validation failed for ${input.path}: ${formatIssues(result.issues)}`,\n ),\n );\n }\n return Effect.succeed(result.value);\n }),\n );\n};\n","import * as Data from \"effect/Data\";\n\nexport class KernelCoreEffectError extends Data.TaggedError(\"KernelCoreEffectError\")<{\n readonly module: string;\n readonly message: string;\n}> {}\n\nexport const kernelCoreEffectError = (module: string, message: string) =>\n new KernelCoreEffectError({ module, message });\n","import type { ErrorObject } from \"ajv\";\nimport Ajv2020 from \"ajv/dist/2020\";\nimport addFormats from \"ajv-formats\";\n\nimport type { StandardSchema } from \"./types\";\nimport { unknownInputSchema } from \"./types\";\n\nconst ajv = new Ajv2020({\n allErrors: true,\n strict: false,\n validateSchema: false,\n allowUnionTypes: true,\n});\n\naddFormats(ajv);\n\nconst decodePointerSegment = (segment: string): PropertyKey => {\n const decoded = segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n return /^\\d+$/.test(decoded) ? Number(decoded) : decoded;\n};\n\nconst pointerToPath = (pointer: string | undefined): ReadonlyArray<PropertyKey> | undefined => {\n if (!pointer || pointer.length === 0 || pointer === \"/\") {\n return undefined;\n }\n\n return pointer\n .split(\"/\")\n .slice(1)\n .filter((segment) => segment.length > 0)\n .map(decodePointerSegment);\n};\n\nconst toIssueMessage = (error: ErrorObject): string => {\n const keyword = error.keyword.trim();\n const message = (error.message ?? \"Invalid value\").trim();\n return keyword.length > 0 ? `${keyword}: ${message}` : message;\n};\n\nexport const standardSchemaFromJsonSchema = (\n schema: unknown,\n options?: {\n vendor?: string;\n fallback?: StandardSchema;\n },\n): StandardSchema => {\n try {\n const validate = ajv.compile(schema as Record<string, unknown>);\n\n return {\n \"~standard\": {\n version: 1,\n vendor: options?.vendor ?? \"json-schema\",\n validate: (value: unknown) => {\n const valid = validate(value);\n if (valid) {\n return { value };\n }\n\n const issues = (validate.errors ?? []).map((error) => ({\n message: toIssueMessage(error),\n path: pointerToPath(error.instancePath),\n }));\n\n return {\n issues: issues.length > 0 ? issues : [{ message: \"Invalid value\" }],\n };\n },\n },\n };\n } catch {\n return options?.fallback ?? unknownInputSchema;\n }\n};\n","import { parse } from \"@babel/parser\";\n\nconst FENCED_CODE_BLOCK = /```(?:[^\\n`]*)?\\s*\\n([\\s\\S]*?)```/i;\nconst FUNCTION_DECLARATION =\n /^(?:async\\s+)?function(?:\\s+([a-zA-Z_$][a-zA-Z0-9_$]*))?\\s*\\(/;\nconst CALLABLE_ERROR = \"Code must evaluate to a function\";\n\nconst extractCandidateSource = (code: string): string => {\n const trimmed = code.trim();\n if (!trimmed) return \"\";\n\n const fenced = trimmed.match(FENCED_CODE_BLOCK)?.[1];\n return (fenced ?? trimmed).trim();\n};\n\nconst wrapCallableBody = (source: string): string =>\n [\n \"const __fn = (\",\n source,\n \");\",\n `if (typeof __fn !== \"function\") throw new Error(${JSON.stringify(CALLABLE_ERROR)});`,\n \"return await __fn();\",\n ].join(\"\\n\");\n\nconst wrapNamedFunctionBody = (source: string, name: string): string =>\n [source, `return await ${name}();`].join(\"\\n\");\n\nconst wrapAnonymousFunctionBody = (source: string): string => `return await (${source})();`;\n\nconst sliceNode = (\n source: string,\n node: {\n start?: number | null;\n end?: number | null;\n },\n): string => {\n const start = node.start ?? 0;\n const end = node.end ?? source.length;\n return source.slice(start, end);\n};\n\nconst unwrapExpression = (expression: { type: string; expression?: unknown }): unknown => {\n switch (expression.type) {\n case \"ParenthesizedExpression\":\n case \"TSAsExpression\":\n case \"TSSatisfiesExpression\":\n case \"TSTypeAssertion\":\n case \"TSNonNullExpression\":\n case \"TSInstantiationExpression\":\n return expression.expression ? unwrapExpression(expression.expression as { type: string }) : expression;\n default:\n return expression;\n }\n};\n\nconst renderExportDefaultBody = (\n source: string,\n declaration: {\n type: string;\n start?: number | null;\n end?: number | null;\n id?: { name?: string | null } | null;\n expression?: unknown;\n },\n): string => {\n if (declaration.type === \"FunctionDeclaration\") {\n const fnSource = sliceNode(source, declaration);\n const name = declaration.id?.name;\n return name ? wrapNamedFunctionBody(fnSource, name) : wrapAnonymousFunctionBody(fnSource);\n }\n\n const expression = unwrapExpression(declaration as { type: string; expression?: unknown }) as {\n type?: string;\n };\n const expressionSource = sliceNode(source, declaration);\n\n if (expression?.type === \"ArrowFunctionExpression\" || expression?.type === \"FunctionExpression\") {\n return wrapCallableBody(expressionSource);\n }\n\n return `return (${expressionSource});`;\n};\n\nconst renderParsedBody = (source: string): string => {\n const program = parse(source, {\n sourceType: \"module\",\n allowAwaitOutsideFunction: true,\n allowReturnOutsideFunction: true,\n allowImportExportEverywhere: true,\n plugins: [\"typescript\"],\n }).program;\n\n if (program.body.length !== 1) return source;\n\n const [statement] = program.body;\n if (!statement) return source;\n\n switch (statement.type) {\n case \"ExpressionStatement\": {\n const expression = unwrapExpression(statement.expression as { type: string; expression?: unknown }) as {\n type?: string;\n };\n return expression?.type === \"ArrowFunctionExpression\" || expression?.type === \"FunctionExpression\"\n ? wrapCallableBody(source)\n : source;\n }\n case \"FunctionDeclaration\":\n return statement.id?.name ? wrapNamedFunctionBody(source, statement.id.name) : source;\n case \"ExportDefaultDeclaration\":\n return renderExportDefaultBody(source, statement.declaration as never);\n default:\n return source;\n }\n};\n\nconst renderHeuristicBody = (source: string): string => {\n const withoutDefaultExport = source.replace(/^export\\s+default\\s+/, \"\").trim();\n\n if (\n (withoutDefaultExport.startsWith(\"async\") || withoutDefaultExport.startsWith(\"(\")) &&\n withoutDefaultExport.includes(\"=>\")\n ) {\n return wrapCallableBody(withoutDefaultExport);\n }\n\n if (FUNCTION_DECLARATION.test(withoutDefaultExport)) {\n const name = withoutDefaultExport.match(FUNCTION_DECLARATION)?.[1];\n return name\n ? wrapNamedFunctionBody(withoutDefaultExport, name)\n : wrapAnonymousFunctionBody(withoutDefaultExport);\n }\n\n return withoutDefaultExport;\n};\n\nexport const recoverExecutionBody = (code: string): string => {\n const source = extractCandidateSource(code);\n if (!source) return \"\";\n\n try {\n return renderParsedBody(source);\n } catch {\n return renderHeuristicBody(source);\n }\n};\n"],"mappings":";AAMO,IAAM,aAAa,CAAC,UAA4B;AAgChD,IAAM,qBAAqC;AAAA,EAChD,aAAa;AAAA,IACX,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,UAAU,CAAC,WAAoB;AAAA,MAC7B;AAAA,IACF;AAAA,EACF;AACF;;;AC7CA,YAAY,YAAY;;;ACDxB,YAAY,UAAU;AAEf,IAAM,wBAAN,cAAyC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wBAAwB,EAAE,EAAE,KAAK;AAE7E,OACG,qBAAqB,WAAW,OAAO,KAAK,qBAAqB,WAAW,GAAG,MAChF,qBAAqB,SAAS,IAAI,GAClC;AACA,WAAO,iBAAiB,oBAAoB;AAAA,EAC9C;AAEA,MAAI,qBAAqB,KAAK,oBAAoB,GAAG;AACnD,UAAM,OAAO,qBAAqB,MAAM,oBAAoB,IAAI,CAAC;AACjE,WAAO,OACH,sBAAsB,sBAAsB,IAAI,IAChD,0BAA0B,oBAAoB;AAAA,EACpD;AAEA,SAAO;AACT;AAEO,IAAM,uBAAuB,CAAC,SAAyB;AAC5D,QAAM,SAAS,uBAAuB,IAAI;AAC1C,MAAI,CAAC,OAAQ,QAAO;AAEpB,MAAI;AACF,WAAO,iBAAiB,MAAM;AAAA,EAChC,QAAQ;AACN,WAAO,oBAAoB,MAAM;AAAA,EACnC;AACF;","names":[]}
@@ -0,0 +1,6 @@
1
+ import type { StandardSchema } from "./types";
2
+ export declare const standardSchemaFromJsonSchema: (schema: unknown, options?: {
3
+ vendor?: string;
4
+ fallback?: StandardSchema;
5
+ }) => StandardSchema;
6
+ //# sourceMappingURL=json-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAmC9C,eAAO,MAAM,4BAA4B,GACvC,QAAQ,OAAO,EACf,UAAU;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,KACA,cA4BF,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import type * as Effect from "effect/Effect";
3
+ /** Branded tool path */
4
+ export type ToolPath = string & {
5
+ readonly __toolPath: unique symbol;
6
+ };
7
+ export declare const asToolPath: (value: string) => ToolPath;
8
+ /** Standard Schema alias */
9
+ export type StandardSchema<Input = unknown, Output = unknown> = StandardSchemaV1<Input, Output>;
10
+ /** A tool that can be invoked */
11
+ export interface Tool {
12
+ readonly path: ToolPath;
13
+ readonly description?: string;
14
+ readonly inputSchema: StandardSchema;
15
+ readonly outputSchema?: StandardSchema;
16
+ readonly execute: (input: unknown) => unknown | Promise<unknown>;
17
+ }
18
+ /** Invoke a tool by path from inside a sandbox */
19
+ export interface SandboxToolInvoker {
20
+ invoke(input: {
21
+ path: string;
22
+ args: unknown;
23
+ }): Effect.Effect<unknown, unknown>;
24
+ }
25
+ /** Result of executing code in a sandbox */
26
+ export type ExecuteResult = {
27
+ result: unknown;
28
+ error?: string;
29
+ logs?: string[];
30
+ };
31
+ /** Executes code in a sandboxed runtime with tool access */
32
+ export interface CodeExecutor {
33
+ execute(code: string, toolInvoker: SandboxToolInvoker): Effect.Effect<ExecuteResult, unknown>;
34
+ }
35
+ /** Accept-anything schema for tools with no input validation */
36
+ export declare const unknownInputSchema: StandardSchema;
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C,wBAAwB;AACxB,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAEvE,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,QAA6B,CAAC;AAEzE,4BAA4B;AAC5B,MAAM,MAAM,cAAc,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAEhG,iCAAiC;AACjC,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;IACrC,QAAQ,CAAC,YAAY,CAAC,EAAE,cAAc,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAClE;AAED,kDAAkD;AAClD,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CACjF;AAED,4CAA4C;AAC5C,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,4DAA4D;AAC5D,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;CAC/F;AAED,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,EAAE,cAQhC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import * as Effect from "effect/Effect";
2
+ /** Validate a value against a Standard Schema */
3
+ export declare const validateInput: (input: {
4
+ schema: unknown;
5
+ value: unknown;
6
+ path: string;
7
+ }) => Effect.Effect<unknown, Error>;
8
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AA+CxC,iDAAiD;AACjD,eAAO,MAAM,aAAa,GAAI,OAAO;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CA4B/B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@executor-js/codemode-core",
3
+ "version": "0.0.1-beta.0",
4
+ "homepage": "https://github.com/RhysSullivan/executor/tree/main/packages/kernel/core",
5
+ "bugs": {
6
+ "url": "https://github.com/RhysSullivan/executor/issues"
7
+ },
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/RhysSullivan/executor.git",
12
+ "directory": "packages/kernel/core"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ }
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup && (tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src || true)",
31
+ "typecheck": "tsgo --noEmit",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest",
34
+ "typecheck:slow": "bunx tsc --noEmit -p tsconfig.json"
35
+ },
36
+ "dependencies": {
37
+ "@babel/parser": "^7.29.2",
38
+ "@standard-schema/spec": "^1.0.0",
39
+ "ajv": "^8.17.1",
40
+ "ajv-formats": "^3.0.1",
41
+ "effect": "^3.21.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^24.3.1",
45
+ "bun-types": "^1.2.22",
46
+ "tsup": "^8.5.0",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^4.1.3"
49
+ }
50
+ }