@parcha/agentrun-dsl 0.1.0-beta.123 → 0.1.0-beta.125
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/code-exec.d.ts +8 -13
- package/dist/code-exec.js +35 -37
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/code-exec.d.ts
CHANGED
|
@@ -8,13 +8,7 @@ export declare function deniedGlobalReferences(src: string): string[];
|
|
|
8
8
|
* Syntax validity does not prove that the expression produces a function or a valid patch. */
|
|
9
9
|
export declare function compileTransformSyntax(src: string): void;
|
|
10
10
|
export declare function compileTransform(src: string): (value: any, ctx?: any) => any;
|
|
11
|
-
/**
|
|
12
|
-
export declare const TRANSFORM_FILES: {
|
|
13
|
-
readonly program: "run.mjs";
|
|
14
|
-
readonly input: "in.json";
|
|
15
|
-
readonly output: "out.json";
|
|
16
|
-
};
|
|
17
|
-
/** What a code node's program writes to its output file: the function's value (`undefined: true` for undefined, which
|
|
11
|
+
/** What a code node's script answers (transformScript): the function's value (`undefined: true` for undefined, which
|
|
18
12
|
* JSON has no word for), or the error it threw, in compileTransform's words. */
|
|
19
13
|
export type TransformOutcome = {
|
|
20
14
|
readonly ok: true;
|
|
@@ -25,10 +19,11 @@ export type TransformOutcome = {
|
|
|
25
19
|
readonly error: string;
|
|
26
20
|
};
|
|
27
21
|
/**
|
|
28
|
-
* A code node as a
|
|
29
|
-
* rather than in its own process.
|
|
30
|
-
* the function exactly as compileTransform does (the same factory text,
|
|
31
|
-
*
|
|
32
|
-
* cycle, or a function or symbol, which JSON would drop without a word) is an error.
|
|
22
|
+
* A code node as one script for a JavaScript engine of the host's own, for a host that runs code nodes in an isolated
|
|
23
|
+
* engine (a WebAssembly one) rather than in its own process. The script is a function expression: called with one
|
|
24
|
+
* string, the JSON of `{ state, ctx }`, it builds the function exactly as compileTransform does (the same factory text,
|
|
25
|
+
* denied globals and synchronous checks), calls it once, and returns one string, the JSON of a TransformOutcome. A value
|
|
26
|
+
* JSON can't carry (a BigInt, a cycle, or a function or symbol, which JSON would drop without a word) is an error. It
|
|
27
|
+
* uses only the language itself: no module, no host object, nothing in or out but the two strings.
|
|
33
28
|
*/
|
|
34
|
-
export declare function
|
|
29
|
+
export declare function transformScript(src: string): string;
|
package/dist/code-exec.js
CHANGED
|
@@ -140,9 +140,9 @@ const EMPTY_SOURCE = "code transform source must be a non-empty string";
|
|
|
140
140
|
const ASYNC_FUNCTION = "code transforms are synchronous; async functions are not supported";
|
|
141
141
|
const THENABLE = "code transforms are synchronous; returned a Promise or thenable";
|
|
142
142
|
/** The start of the error a code node's program gives for a value JSON would drop silently (a function, a symbol). */
|
|
143
|
-
const NOT_JSON = "a code node
|
|
143
|
+
const NOT_JSON = "a code node must return JSON data, and its value holds a ";
|
|
144
144
|
/** The factory's body: `src` evaluated once, strict, under the denied globals' parameters. Both compileTransform and
|
|
145
|
-
*
|
|
145
|
+
* transformScript build their function from this one text, so a code node means the same wherever it runs. */
|
|
146
146
|
const factoryBody = (src) => `"use strict";\nconst __fn = (${src});\nif (typeof __fn !== "function") throw new Error("code must evaluate to a single (value) => value function");\nreturn __fn;`;
|
|
147
147
|
function createTransformFactory(src) {
|
|
148
148
|
if (typeof src !== "string" || !src.trim())
|
|
@@ -177,46 +177,44 @@ export function compileTransform(src) {
|
|
|
177
177
|
return result;
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
/** The files a code node's program reads and writes, in the directory it runs in (transformProgram). */
|
|
181
|
-
export const TRANSFORM_FILES = { program: "run.mjs", input: "in.json", output: "out.json" };
|
|
182
180
|
/**
|
|
183
|
-
* A code node as a
|
|
184
|
-
* rather than in its own process.
|
|
185
|
-
* the function exactly as compileTransform does (the same factory text,
|
|
186
|
-
*
|
|
187
|
-
* cycle, or a function or symbol, which JSON would drop without a word) is an error.
|
|
181
|
+
* A code node as one script for a JavaScript engine of the host's own, for a host that runs code nodes in an isolated
|
|
182
|
+
* engine (a WebAssembly one) rather than in its own process. The script is a function expression: called with one
|
|
183
|
+
* string, the JSON of `{ state, ctx }`, it builds the function exactly as compileTransform does (the same factory text,
|
|
184
|
+
* denied globals and synchronous checks), calls it once, and returns one string, the JSON of a TransformOutcome. A value
|
|
185
|
+
* JSON can't carry (a BigInt, a cycle, or a function or symbol, which JSON would drop without a word) is an error. It
|
|
186
|
+
* uses only the language itself: no module, no host object, nothing in or out but the two strings.
|
|
188
187
|
*/
|
|
189
|
-
export function
|
|
188
|
+
export function transformScript(src) {
|
|
190
189
|
if (typeof src !== "string" || !src.trim())
|
|
191
190
|
throw new Error(EMPTY_SOURCE);
|
|
192
191
|
const text = JSON.stringify;
|
|
193
192
|
return [
|
|
194
|
-
`
|
|
195
|
-
`
|
|
196
|
-
`
|
|
197
|
-
`
|
|
198
|
-
`
|
|
199
|
-
`
|
|
200
|
-
`
|
|
201
|
-
`
|
|
202
|
-
`
|
|
203
|
-
`
|
|
204
|
-
`
|
|
205
|
-
`
|
|
206
|
-
`
|
|
207
|
-
`
|
|
208
|
-
`
|
|
209
|
-
`
|
|
210
|
-
`
|
|
211
|
-
`
|
|
212
|
-
`
|
|
213
|
-
`
|
|
214
|
-
`
|
|
215
|
-
`
|
|
216
|
-
`} catch (e) {`,
|
|
217
|
-
`
|
|
218
|
-
`}`,
|
|
219
|
-
`
|
|
220
|
-
``,
|
|
193
|
+
`(function (input) {`,
|
|
194
|
+
` "use strict";`,
|
|
195
|
+
` var DENIED = ${text(DENIED_GLOBALS)};`,
|
|
196
|
+
` var MakeFunction = Function, OwnPromise = Promise, stringify = JSON.stringify, parse = JSON.parse;`,
|
|
197
|
+
` var AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;`,
|
|
198
|
+
` var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;`,
|
|
199
|
+
` try {`,
|
|
200
|
+
` var given = parse(input);`,
|
|
201
|
+
` var factory;`,
|
|
202
|
+
` try { factory = MakeFunction.apply(null, DENIED.concat([${text(factoryBody(src))}])); }`,
|
|
203
|
+
` catch (e) { throw new Error("code transform failed to compile: " + ((e && e.message) || e)); }`,
|
|
204
|
+
` var fn = factory.apply(null, DENIED.map(function () { return undefined; }));`,
|
|
205
|
+
` if (fn instanceof AsyncFunction || fn instanceof AsyncGeneratorFunction) throw new Error(${text(ASYNC_FUNCTION)});`,
|
|
206
|
+
` var result = fn(given.state, given.ctx);`,
|
|
207
|
+
` if (result instanceof OwnPromise) { OwnPromise.prototype.then.call(result, undefined, function () {}); throw new Error(${text(THENABLE)}); }`,
|
|
208
|
+
` if (result && typeof result.then === "function") throw new Error(${text(THENABLE)});`,
|
|
209
|
+
` var kept = result === undefined ? { ok: true, undefined: true } : { ok: true, value: result };`,
|
|
210
|
+
` return stringify(kept, function (key, value) {`,
|
|
211
|
+
` if (typeof value !== "function" && typeof value !== "symbol") return value;`,
|
|
212
|
+
` var where = this === kept && key === "value" ? "" : " at " + stringify(key);`,
|
|
213
|
+
` throw new Error(${text(NOT_JSON)} + typeof value + where);`,
|
|
214
|
+
` });`,
|
|
215
|
+
` } catch (e) {`,
|
|
216
|
+
` return stringify({ ok: false, error: String(e && e.message !== undefined ? e.message : e) });`,
|
|
217
|
+
` }`,
|
|
218
|
+
`})`,
|
|
221
219
|
].join("\n");
|
|
222
220
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type { DecisionProvider, DecisionCapabilities, DecisionInput, DecisionReq
|
|
|
16
16
|
export { inspectWorkflow, formatWorkflowTree } from "./inspection.js";
|
|
17
17
|
export type { WorkflowInspection, WorkflowInspectionNode } from "./inspection.js";
|
|
18
18
|
export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA, childSteps, declaredWrites, artifactNodeIsProse, schemaProblems, HOST_STATE_KEY, normalizeStringNullsForSchema, placeholderValue, placeholdersOf, } from "./workflow.js";
|
|
19
|
-
export { compileTransform, compileTransformSyntax, deniedGlobalReferences,
|
|
19
|
+
export { compileTransform, compileTransformSyntax, deniedGlobalReferences, type TransformOutcome, transformScript } from "./code-exec.js";
|
|
20
20
|
export { resolveSchemaForWorkflow } from "./schema-references.js";
|
|
21
21
|
export { patternRisk, PATTERN_SCREEN_LIMITS } from "./pattern-screen.js";
|
|
22
22
|
export { submitParameters } from "./submit-envelope.js";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ childSteps, declaredWrites, artifactNodeIsProse, schemaProblems, HOST_STATE_KEY,
|
|
|
14
14
|
normalizeStringNullsForSchema,
|
|
15
15
|
// Interpolation's placeholders in a string and its lookup order for one, for a host check of what a step reads.
|
|
16
16
|
placeholderValue, placeholdersOf, } from "./workflow.js";
|
|
17
|
-
export { compileTransform, compileTransformSyntax, deniedGlobalReferences,
|
|
17
|
+
export { compileTransform, compileTransformSyntax, deniedGlobalReferences, transformScript } from "./code-exec.js";
|
|
18
18
|
export { resolveSchemaForWorkflow } from "./schema-references.js";
|
|
19
19
|
export { patternRisk, PATTERN_SCREEN_LIMITS } from "./pattern-screen.js";
|
|
20
20
|
export { submitParameters } from "./submit-envelope.js";
|