@abyss-project/runtime 1.0.0 → 2.0.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.
- package/README.md +6 -3
- package/dist/cost/execution-cost.d.ts +45 -0
- package/dist/cost/execution-cost.js +114 -0
- package/dist/cost/execution-cost.js.map +1 -0
- package/dist/definition/definition.limits.d.ts +4 -0
- package/dist/definition/definition.limits.js +8 -0
- package/dist/definition/definition.limits.js.map +1 -0
- package/dist/definition/definition.schema.d.ts +2 -2
- package/dist/definition/definition.schema.js +20 -4
- package/dist/definition/definition.schema.js.map +1 -1
- package/dist/definition/definition.types.d.ts +20 -1
- package/dist/definition/definition.types.js +9 -1
- package/dist/definition/definition.types.js.map +1 -1
- package/dist/engine/engine-entry.d.ts +1 -0
- package/dist/engine/engine-entry.js +6 -0
- package/dist/engine/engine-entry.js.map +1 -0
- package/dist/engine/engine-global.d.ts +1 -0
- package/dist/engine/engine-global.js +5 -0
- package/dist/engine/engine-global.js.map +1 -0
- package/dist/engine/engine-source.d.ts +2 -0
- package/dist/engine/engine-source.js +3 -0
- package/dist/engine/run-in-isolate.d.ts +34 -0
- package/dist/engine/run-in-isolate.js +267 -0
- package/dist/engine/run-in-isolate.js.map +1 -0
- package/dist/errors/runtime-error-code.enum.d.ts +2 -2
- package/dist/errors/runtime-error-code.enum.js +1 -1
- package/dist/errors/runtime-error-code.enum.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/interpreter/interpreter.d.ts +27 -1
- package/dist/interpreter/interpreter.js +114 -42
- package/dist/interpreter/interpreter.js.map +1 -1
- package/dist/interpreter/interpreter.types.d.ts +35 -4
- package/dist/interpreter/interpreter.types.js +7 -1
- package/dist/interpreter/interpreter.types.js.map +1 -1
- package/dist/interpreter/test-host.d.ts +4 -2
- package/dist/interpreter/test-host.js +6 -0
- package/dist/interpreter/test-host.js.map +1 -1
- package/dist/runner-protocol/evaluation.types.d.ts +20 -0
- package/dist/runner-protocol/evaluation.types.js +10 -0
- package/dist/runner-protocol/evaluation.types.js.map +1 -0
- package/dist/runner-protocol/execution-protocol.types.d.ts +132 -0
- package/dist/runner-protocol/execution-protocol.types.js +48 -0
- package/dist/runner-protocol/execution-protocol.types.js.map +1 -0
- package/dist/server/code-runner-session.d.ts +28 -0
- package/dist/server/code-runner-session.js +208 -0
- package/dist/server/code-runner-session.js.map +1 -0
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +5 -3
- package/dist/server/index.js.map +1 -1
- package/dist/steps/execute-step.d.ts +12 -2
- package/dist/steps/execute-step.js +37 -0
- package/dist/steps/execute-step.js.map +1 -1
- package/dist/steps/global-references.d.ts +2 -0
- package/dist/steps/global-references.js +28 -0
- package/dist/steps/global-references.js.map +1 -0
- package/dist/steps/step-fields.d.ts +1 -1
- package/dist/steps/step-fields.js +10 -2
- package/dist/steps/step-fields.js.map +1 -1
- package/dist/steps/value-source.d.ts +1 -1
- package/dist/steps/value-source.js +3 -3
- package/dist/steps/value-source.js.map +1 -1
- package/package.json +10 -2
- package/scripts/build-engine.cjs +70 -0
- package/src/__tests__/engine-bundle.test.ts +121 -0
- package/src/cost/__tests__/execution-cost.test.ts +200 -0
- package/src/cost/execution-cost.ts +192 -0
- package/src/definition/__tests__/validate-definition.test.ts +354 -303
- package/src/definition/definition.limits.ts +9 -0
- package/src/definition/definition.schema.ts +172 -139
- package/src/definition/definition.types.ts +171 -143
- package/src/engine/__tests__/run-in-isolate.test.ts +468 -0
- package/src/engine/engine-entry.ts +3 -0
- package/src/engine/engine-global.ts +2 -0
- package/src/engine/run-in-isolate.ts +404 -0
- package/src/errors/runtime-error-code.enum.ts +37 -37
- package/src/index.ts +30 -18
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +223 -0
- package/src/interpreter/interpreter.ts +461 -342
- package/src/interpreter/interpreter.types.ts +192 -140
- package/src/interpreter/test-host.ts +85 -74
- package/src/runner-protocol/evaluation.types.ts +21 -0
- package/src/runner-protocol/execution-protocol.types.ts +221 -0
- package/src/server/__tests__/code-runner-session.test.ts +311 -0
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -0
- package/src/server/index.ts +11 -4
- package/src/steps/__tests__/global-references.test.ts +113 -0
- package/src/steps/execute-step.ts +186 -132
- package/src/steps/global-references.ts +48 -0
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +87 -79
- package/src/steps/value-source.ts +69 -69
- package/dist/runner-protocol/runner-protocol.types.d.ts +0 -92
- package/dist/runner-protocol/runner-protocol.types.js +0 -26
- package/dist/runner-protocol/runner-protocol.types.js.map +0 -1
- package/dist/server/code-runner-client.d.ts +0 -13
- package/dist/server/code-runner-client.js +0 -155
- package/dist/server/code-runner-client.js.map +0 -1
- package/src/runner-protocol/runner-protocol.types.ts +0 -117
- package/src/server/__tests__/code-runner-client.test.ts +0 -262
- package/src/server/code-runner-client.ts +0 -201
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# @abyss-project/runtime
|
|
2
2
|
|
|
3
|
-
Abyss automation core: definitions, interpreter
|
|
3
|
+
Abyss automation core: definitions, interpreter, execution protocol `abyss-runtime.v2` and
|
|
4
|
+
execution cost.
|
|
4
5
|
|
|
5
|
-
The package root (`@abyss-project/runtime`) is browser-compatible. Node-only code (
|
|
6
|
-
|
|
6
|
+
The package root (`@abyss-project/runtime`) is browser-compatible. Node-only code (the
|
|
7
|
+
`CodeRunnerSession` WebSocket client) lives under `@abyss-project/runtime/server`.
|
|
8
|
+
`@abyss-project/runtime/engine` exports `ENGINE_SOURCE`, the interpreter bundled into one
|
|
9
|
+
self-contained script for the code runner's isolate.
|
|
7
10
|
|
|
8
11
|
## Installation
|
|
9
12
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare enum ResourceProfile {
|
|
2
|
+
S = "S",
|
|
3
|
+
M = "M",
|
|
4
|
+
L = "L",
|
|
5
|
+
XL = "XL",
|
|
6
|
+
XXL = "XXL"
|
|
7
|
+
}
|
|
8
|
+
export interface ResourceProfileSpec {
|
|
9
|
+
memoryMb: number;
|
|
10
|
+
cpuCoefficient: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const RESOURCE_PROFILES: Readonly<Record<ResourceProfile, ResourceProfileSpec>>;
|
|
13
|
+
export declare const COST_RATES: {
|
|
14
|
+
readonly executionMillicredits: 10;
|
|
15
|
+
readonly cpuMillicreditsPerSecond: 500;
|
|
16
|
+
readonly guaranteedCpuCoefficient: 1.5;
|
|
17
|
+
readonly memoryMillicreditsPerGbSecond: 100;
|
|
18
|
+
readonly networkOutMillicreditsPerMb: 1000;
|
|
19
|
+
readonly httpCallMillicredits: 10;
|
|
20
|
+
readonly storeWriteMillicredits: 10;
|
|
21
|
+
};
|
|
22
|
+
export declare enum CostedExecutionStatus {
|
|
23
|
+
RAN = "RAN",
|
|
24
|
+
INTERRUPTED = "INTERRUPTED",
|
|
25
|
+
REFUSED = "REFUSED"
|
|
26
|
+
}
|
|
27
|
+
export interface StepUsage {
|
|
28
|
+
cpuMs: number;
|
|
29
|
+
wallMs: number;
|
|
30
|
+
netOutBytes: number;
|
|
31
|
+
httpCalls: number;
|
|
32
|
+
storeWrites: number;
|
|
33
|
+
}
|
|
34
|
+
export interface ExecutionCostInput extends StepUsage {
|
|
35
|
+
status: CostedExecutionStatus;
|
|
36
|
+
profile: ResourceProfile;
|
|
37
|
+
guaranteedCpu: boolean;
|
|
38
|
+
resumedSegment?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface StepCostInput {
|
|
41
|
+
execution: ExecutionCostInput;
|
|
42
|
+
steps: StepUsage[];
|
|
43
|
+
}
|
|
44
|
+
export declare const computeExecutionCost: (input: ExecutionCostInput) => number;
|
|
45
|
+
export declare const computeStepCost: (input: StepCostInput) => number[];
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeStepCost = exports.computeExecutionCost = exports.CostedExecutionStatus = exports.COST_RATES = exports.RESOURCE_PROFILES = exports.ResourceProfile = void 0;
|
|
4
|
+
var ResourceProfile;
|
|
5
|
+
(function (ResourceProfile) {
|
|
6
|
+
ResourceProfile["S"] = "S";
|
|
7
|
+
ResourceProfile["M"] = "M";
|
|
8
|
+
ResourceProfile["L"] = "L";
|
|
9
|
+
ResourceProfile["XL"] = "XL";
|
|
10
|
+
ResourceProfile["XXL"] = "XXL";
|
|
11
|
+
})(ResourceProfile || (exports.ResourceProfile = ResourceProfile = {}));
|
|
12
|
+
exports.RESOURCE_PROFILES = {
|
|
13
|
+
[ResourceProfile.S]: { memoryMb: 128, cpuCoefficient: 1 },
|
|
14
|
+
[ResourceProfile.M]: { memoryMb: 256, cpuCoefficient: 1.05 },
|
|
15
|
+
[ResourceProfile.L]: { memoryMb: 512, cpuCoefficient: 1.1 },
|
|
16
|
+
[ResourceProfile.XL]: { memoryMb: 1024, cpuCoefficient: 1.2 },
|
|
17
|
+
[ResourceProfile.XXL]: { memoryMb: 2048, cpuCoefficient: 1.35 },
|
|
18
|
+
};
|
|
19
|
+
exports.COST_RATES = {
|
|
20
|
+
executionMillicredits: 10,
|
|
21
|
+
cpuMillicreditsPerSecond: 500,
|
|
22
|
+
guaranteedCpuCoefficient: 1.5,
|
|
23
|
+
memoryMillicreditsPerGbSecond: 100,
|
|
24
|
+
networkOutMillicreditsPerMb: 1000,
|
|
25
|
+
httpCallMillicredits: 10,
|
|
26
|
+
storeWriteMillicredits: 10,
|
|
27
|
+
};
|
|
28
|
+
var CostedExecutionStatus;
|
|
29
|
+
(function (CostedExecutionStatus) {
|
|
30
|
+
CostedExecutionStatus["RAN"] = "RAN";
|
|
31
|
+
CostedExecutionStatus["INTERRUPTED"] = "INTERRUPTED";
|
|
32
|
+
CostedExecutionStatus["REFUSED"] = "REFUSED";
|
|
33
|
+
})(CostedExecutionStatus || (exports.CostedExecutionStatus = CostedExecutionStatus = {}));
|
|
34
|
+
const MICROS_PER_SECOND = BigInt(1_000_000);
|
|
35
|
+
const CPU_DENOMINATOR = MICROS_PER_SECOND * BigInt(100) * BigInt(1000);
|
|
36
|
+
const MEMORY_DENOMINATOR = BigInt(1024) * MICROS_PER_SECOND;
|
|
37
|
+
const NETWORK_DENOMINATOR = BigInt(1024 * 1024);
|
|
38
|
+
const UNITS_PER_MILLICREDIT = BigInt(1_048_576) * BigInt(48_828_125);
|
|
39
|
+
const ZERO = BigInt(0);
|
|
40
|
+
const ONE = BigInt(1);
|
|
41
|
+
const TWO = BigInt(2);
|
|
42
|
+
const assertUsage = (usage, subject) => {
|
|
43
|
+
['cpuMs', 'wallMs', 'netOutBytes', 'httpCalls', 'storeWrites'].forEach((key) => {
|
|
44
|
+
const value = usage[key];
|
|
45
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
46
|
+
throw new RangeError(`${subject}.${key} must be a finite number >= 0, got ${value}`);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const micros = (ms) => BigInt(Math.round(ms * 1000));
|
|
51
|
+
const whole = (count) => BigInt(Math.round(count));
|
|
52
|
+
const hundredths = (coefficient) => BigInt(Math.round(coefficient * 100));
|
|
53
|
+
const thousandths = (coefficient) => BigInt(Math.round(coefficient * 1000));
|
|
54
|
+
const variableUnits = (usage, execution) => {
|
|
55
|
+
const profile = exports.RESOURCE_PROFILES[execution.profile];
|
|
56
|
+
const guaranteed = execution.guaranteedCpu ? exports.COST_RATES.guaranteedCpuCoefficient : 1;
|
|
57
|
+
const cpu = (micros(usage.cpuMs) *
|
|
58
|
+
BigInt(exports.COST_RATES.cpuMillicreditsPerSecond) *
|
|
59
|
+
hundredths(profile.cpuCoefficient) *
|
|
60
|
+
thousandths(guaranteed) *
|
|
61
|
+
UNITS_PER_MILLICREDIT) /
|
|
62
|
+
CPU_DENOMINATOR;
|
|
63
|
+
const memory = (BigInt(profile.memoryMb) *
|
|
64
|
+
micros(usage.wallMs) *
|
|
65
|
+
BigInt(exports.COST_RATES.memoryMillicreditsPerGbSecond) *
|
|
66
|
+
UNITS_PER_MILLICREDIT) /
|
|
67
|
+
MEMORY_DENOMINATOR;
|
|
68
|
+
const network = (whole(usage.netOutBytes) *
|
|
69
|
+
BigInt(exports.COST_RATES.networkOutMillicreditsPerMb) *
|
|
70
|
+
UNITS_PER_MILLICREDIT) /
|
|
71
|
+
NETWORK_DENOMINATOR;
|
|
72
|
+
const effects = (whole(usage.httpCalls) * BigInt(exports.COST_RATES.httpCallMillicredits) +
|
|
73
|
+
whole(usage.storeWrites) * BigInt(exports.COST_RATES.storeWriteMillicredits)) *
|
|
74
|
+
UNITS_PER_MILLICREDIT;
|
|
75
|
+
return cpu + memory + network + effects;
|
|
76
|
+
};
|
|
77
|
+
const floorDiv = (numerator, denominator) => {
|
|
78
|
+
const quotient = numerator / denominator;
|
|
79
|
+
return numerator % denominator !== ZERO && numerator < ZERO ? quotient - ONE : quotient;
|
|
80
|
+
};
|
|
81
|
+
const roundHalfUp = (units) => Number(floorDiv(units * TWO + UNITS_PER_MILLICREDIT, UNITS_PER_MILLICREDIT * TWO));
|
|
82
|
+
const isFree = (execution) => execution.status !== CostedExecutionStatus.RAN;
|
|
83
|
+
const executionPrice = (execution) => isFree(execution) || execution.resumedSegment ? 0 : exports.COST_RATES.executionMillicredits;
|
|
84
|
+
const computeExecutionCost = (input) => {
|
|
85
|
+
assertUsage(input, 'execution');
|
|
86
|
+
if (isFree(input)) {
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
return executionPrice(input) + roundHalfUp(variableUnits(input, input));
|
|
90
|
+
};
|
|
91
|
+
exports.computeExecutionCost = computeExecutionCost;
|
|
92
|
+
const computeStepCost = (input) => {
|
|
93
|
+
const { execution, steps } = input;
|
|
94
|
+
assertUsage(execution, 'execution');
|
|
95
|
+
steps.forEach((step, index) => assertUsage(step, `steps[${index}]`));
|
|
96
|
+
if (steps.length === 0) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
if (isFree(execution)) {
|
|
100
|
+
return steps.map(() => 0);
|
|
101
|
+
}
|
|
102
|
+
const total = variableUnits(execution, execution);
|
|
103
|
+
let cumulative = ZERO;
|
|
104
|
+
let assigned = 0;
|
|
105
|
+
return steps.map((step, index) => {
|
|
106
|
+
cumulative = index === steps.length - 1 ? total : cumulative + variableUnits(step, execution);
|
|
107
|
+
const rounded = roundHalfUp(cumulative);
|
|
108
|
+
const cost = rounded - assigned;
|
|
109
|
+
assigned = rounded;
|
|
110
|
+
return cost;
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
exports.computeStepCost = computeStepCost;
|
|
114
|
+
//# sourceMappingURL=execution-cost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-cost.js","sourceRoot":"","sources":["../../src/cost/execution-cost.ts"],"names":[],"mappings":";;;AAIA,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,0BAAO,CAAA;IACP,0BAAO,CAAA;IACP,0BAAO,CAAA;IACP,4BAAS,CAAA;IACT,8BAAW,CAAA;AACb,CAAC,EANW,eAAe,+BAAf,eAAe,QAM1B;AASY,QAAA,iBAAiB,GAA2D;IACvF,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,EAAE;IACzD,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE;IAC5D,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE;IAC3D,CAAC,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE;IAC7D,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EA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,CAAC,UAAU,GAAG,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC9F,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAC;QAChC,QAAQ,GAAG,OAAO,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AApBW,QAAA,eAAe,mBAoB1B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_RESPONSE_STATUS = exports.MIN_RESPONSE_STATUS = exports.MAX_WAIT_DURATION_MS = exports.MAX_HTTP_TIMEOUT_MS = void 0;
|
|
4
|
+
exports.MAX_HTTP_TIMEOUT_MS = 30_000;
|
|
5
|
+
exports.MAX_WAIT_DURATION_MS = 30 * 24 * 60 * 60 * 1000;
|
|
6
|
+
exports.MIN_RESPONSE_STATUS = 100;
|
|
7
|
+
exports.MAX_RESPONSE_STATUS = 599;
|
|
8
|
+
//# sourceMappingURL=definition.limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.limits.js","sourceRoot":"","sources":["../../src/definition/definition.limits.ts"],"names":[],"mappings":";;;AAGa,QAAA,mBAAmB,GAAG,MAAM,CAAC;AAC7B,QAAA,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAGhD,QAAA,mBAAmB,GAAG,GAAG,CAAC;AAC1B,QAAA,mBAAmB,GAAG,GAAG,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Joi from 'joi';
|
|
2
2
|
import { AccessKind } from '../access/access.types';
|
|
3
|
+
import { MAX_HTTP_TIMEOUT_MS, MAX_WAIT_DURATION_MS } from './definition.limits';
|
|
3
4
|
import { StepType } from './definition.types';
|
|
4
|
-
export
|
|
5
|
-
export declare const MAX_WAIT_DURATION_MS: number;
|
|
5
|
+
export { MAX_HTTP_TIMEOUT_MS, MAX_WAIT_DURATION_MS };
|
|
6
6
|
export declare const STEP_SCHEMAS: Record<StepType, Joi.ObjectSchema>;
|
|
7
7
|
export declare const DEFINITION_SCHEMA: Joi.ObjectSchema<any>;
|
|
8
8
|
export declare const ACCESS_SCHEMAS: Record<AccessKind, Joi.ObjectSchema>;
|
|
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ACCESS_SCHEMAS = exports.DEFINITION_SCHEMA = exports.STEP_SCHEMAS = exports.MAX_WAIT_DURATION_MS = exports.MAX_HTTP_TIMEOUT_MS = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
8
|
const access_types_1 = require("../access/access.types");
|
|
9
|
+
const definition_limits_1 = require("./definition.limits");
|
|
10
|
+
Object.defineProperty(exports, "MAX_HTTP_TIMEOUT_MS", { enumerable: true, get: function () { return definition_limits_1.MAX_HTTP_TIMEOUT_MS; } });
|
|
11
|
+
Object.defineProperty(exports, "MAX_WAIT_DURATION_MS", { enumerable: true, get: function () { return definition_limits_1.MAX_WAIT_DURATION_MS; } });
|
|
9
12
|
const definition_types_1 = require("./definition.types");
|
|
10
|
-
exports.MAX_HTTP_TIMEOUT_MS = 30_000;
|
|
11
|
-
exports.MAX_WAIT_DURATION_MS = 30 * 24 * 60 * 60 * 1000;
|
|
12
13
|
const RESERVED_NAMES = ['__proto__', 'constructor', 'prototype'];
|
|
13
14
|
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
14
15
|
const HOST_PATTERN = /^(\*\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
|
|
@@ -20,8 +21,9 @@ const valueSource = () => {
|
|
|
20
21
|
.id(id);
|
|
21
22
|
};
|
|
22
23
|
const valueMap = () => joi_1.default.object().pattern(joi_1.default.string(), valueSource());
|
|
23
|
-
const durationSource = () => joi_1.default.alternatives().try(joi_1.default.number().integer().min(0).max(
|
|
24
|
+
const durationSource = () => joi_1.default.alternatives().try(joi_1.default.number().integer().min(0).max(definition_limits_1.MAX_WAIT_DURATION_MS), joi_1.default.string().allow(''), joi_1.default.object({ $expression: joi_1.default.string().required() }));
|
|
24
25
|
const untilSource = () => joi_1.default.alternatives().try(joi_1.default.string().pattern(/\{\{[\s\S]*?\}\}/), joi_1.default.string().isoDate(), joi_1.default.object({ $expression: joi_1.default.string().required() }));
|
|
26
|
+
const statusSource = () => joi_1.default.alternatives().try(joi_1.default.number().integer().min(definition_limits_1.MIN_RESPONSE_STATUS).max(definition_limits_1.MAX_RESPONSE_STATUS), joi_1.default.string().pattern(/\{\{[\s\S]*?\}\}/), joi_1.default.object({ $expression: joi_1.default.string().required() }));
|
|
25
27
|
const stepBase = {
|
|
26
28
|
id: joi_1.default.string()
|
|
27
29
|
.min(1)
|
|
@@ -74,7 +76,7 @@ exports.STEP_SCHEMAS = {
|
|
|
74
76
|
url: valueSource().required(),
|
|
75
77
|
headers: valueMap(),
|
|
76
78
|
body: valueSource(),
|
|
77
|
-
timeoutMs: joi_1.default.number().integer().min(1).max(
|
|
79
|
+
timeoutMs: joi_1.default.number().integer().min(1).max(definition_limits_1.MAX_HTTP_TIMEOUT_MS),
|
|
78
80
|
}),
|
|
79
81
|
[definition_types_1.StepType.HOST]: joi_1.default.object({
|
|
80
82
|
...stepBase,
|
|
@@ -82,6 +84,20 @@ exports.STEP_SCHEMAS = {
|
|
|
82
84
|
action: joi_1.default.string().min(1).required(),
|
|
83
85
|
input: valueMap().required(),
|
|
84
86
|
}),
|
|
87
|
+
[definition_types_1.StepType.LOG]: joi_1.default.object({
|
|
88
|
+
...stepBase,
|
|
89
|
+
type: joi_1.default.valid(definition_types_1.StepType.LOG).required(),
|
|
90
|
+
level: joi_1.default.valid(...Object.values(definition_types_1.LogLevel)).required(),
|
|
91
|
+
message: valueSource().required(),
|
|
92
|
+
data: valueSource(),
|
|
93
|
+
}),
|
|
94
|
+
[definition_types_1.StepType.RESPOND]: joi_1.default.object({
|
|
95
|
+
...stepBase,
|
|
96
|
+
type: joi_1.default.valid(definition_types_1.StepType.RESPOND).required(),
|
|
97
|
+
status: statusSource().required(),
|
|
98
|
+
headers: valueMap(),
|
|
99
|
+
body: valueSource(),
|
|
100
|
+
}),
|
|
85
101
|
[definition_types_1.StepType.STOP]: joi_1.default.object({
|
|
86
102
|
...stepBase,
|
|
87
103
|
type: joi_1.default.valid(definition_types_1.StepType.STOP).required(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.schema.js","sourceRoot":"","sources":["../../src/definition/definition.schema.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,yDAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"definition.schema.js","sourceRoot":"","sources":["../../src/definition/definition.schema.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,yDAAoD;AACpD,2DAK6B;AASpB,oGAbP,uCAAmB,OAaO;AAAE,qGAX5B,wCAAoB,OAW4B;AARlD,yDAM4B;AAK5B,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;AAEjE,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAChD,MAAM,YAAY,GAAG,2EAA2E,CAAC;AAEjG,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAMzB,MAAM,WAAW,GAAG,GAA2B,EAAE;IAC/C,MAAM,EAAE,GAAG,cAAc,gBAAgB,EAAE,EAAE,CAAC;IAC9C,OAAO,aAAG,CAAC,YAAY,EAAE;SACtB,GAAG,CACF,aAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EACtB,aAAG,CAAC,MAAM,EAAE,EACZ,aAAG,CAAC,OAAO,EAAE,EACb,aAAG,CAAC,KAAK,CAAC,IAAI,CAAC,E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CAAC,CAAC,CAAC,QAAQ,EAAE;KAC/E,CAAC;IACF,CAAC,yBAAU,CAAC,WAAW,CAAC,EAAE,aAAG,CAAC,MAAM,CAAC;QACnC,IAAI,EAAE,aAAG,CAAC,KAAK,CAAC,yBAAU,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE;QAClD,MAAM,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;KACvC,CAAC;CACH,CAAC"}
|
|
@@ -15,8 +15,15 @@ export declare enum StepType {
|
|
|
15
15
|
CODE = "CODE",
|
|
16
16
|
HTTP = "HTTP",
|
|
17
17
|
HOST = "HOST",
|
|
18
|
+
LOG = "LOG",
|
|
19
|
+
RESPOND = "RESPOND",
|
|
18
20
|
STOP = "STOP"
|
|
19
21
|
}
|
|
22
|
+
export declare enum LogLevel {
|
|
23
|
+
INFO = "info",
|
|
24
|
+
WARN = "warn",
|
|
25
|
+
ERROR = "error"
|
|
26
|
+
}
|
|
20
27
|
export declare enum HttpMethod {
|
|
21
28
|
GET = "GET",
|
|
22
29
|
POST = "POST",
|
|
@@ -75,12 +82,24 @@ export interface HostStep extends StepBase {
|
|
|
75
82
|
action: string;
|
|
76
83
|
input: Record<string, ValueSource>;
|
|
77
84
|
}
|
|
85
|
+
export interface LogStep extends StepBase {
|
|
86
|
+
type: StepType.LOG;
|
|
87
|
+
level: LogLevel;
|
|
88
|
+
message: ValueSource;
|
|
89
|
+
data?: ValueSource;
|
|
90
|
+
}
|
|
91
|
+
export interface RespondStep extends StepBase {
|
|
92
|
+
type: StepType.RESPOND;
|
|
93
|
+
status: ValueSource;
|
|
94
|
+
headers?: Record<string, ValueSource>;
|
|
95
|
+
body?: ValueSource;
|
|
96
|
+
}
|
|
78
97
|
export interface StopStep extends StepBase {
|
|
79
98
|
type: StepType.STOP;
|
|
80
99
|
status: StopStatus;
|
|
81
100
|
output?: ValueSource;
|
|
82
101
|
}
|
|
83
|
-
export type Step = ConditionStep | SwitchStep | WaitStep | SetStep | CodeStep | HttpStep | HostStep | StopStep;
|
|
102
|
+
export type Step = ConditionStep | SwitchStep | WaitStep | SetStep | CodeStep | HttpStep | HostStep | LogStep | RespondStep | StopStep;
|
|
84
103
|
export interface RuntimeDefinition {
|
|
85
104
|
formatVersion: typeof CURRENT_FORMAT_VERSION;
|
|
86
105
|
accesses: AccessDeclaration[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StopStatus = exports.HttpMethod = exports.StepType = exports.CURRENT_FORMAT_VERSION = void 0;
|
|
3
|
+
exports.StopStatus = exports.HttpMethod = exports.LogLevel = exports.StepType = exports.CURRENT_FORMAT_VERSION = void 0;
|
|
4
4
|
exports.CURRENT_FORMAT_VERSION = 1;
|
|
5
5
|
var StepType;
|
|
6
6
|
(function (StepType) {
|
|
@@ -11,8 +11,16 @@ var StepType;
|
|
|
11
11
|
StepType["CODE"] = "CODE";
|
|
12
12
|
StepType["HTTP"] = "HTTP";
|
|
13
13
|
StepType["HOST"] = "HOST";
|
|
14
|
+
StepType["LOG"] = "LOG";
|
|
15
|
+
StepType["RESPOND"] = "RESPOND";
|
|
14
16
|
StepType["STOP"] = "STOP";
|
|
15
17
|
})(StepType || (exports.StepType = StepType = {}));
|
|
18
|
+
var LogLevel;
|
|
19
|
+
(function (LogLevel) {
|
|
20
|
+
LogLevel["INFO"] = "info";
|
|
21
|
+
LogLevel["WARN"] = "warn";
|
|
22
|
+
LogLevel["ERROR"] = "error";
|
|
23
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
16
24
|
var HttpMethod;
|
|
17
25
|
(function (HttpMethod) {
|
|
18
26
|
HttpMethod["GET"] = "GET";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.types.js","sourceRoot":"","sources":["../../src/definition/definition.types.ts"],"names":[],"mappings":";;;AAGa,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAmBxC,IAAY,
|
|
1
|
+
{"version":3,"file":"definition.types.js","sourceRoot":"","sources":["../../src/definition/definition.types.ts"],"names":[],"mappings":";;;AAGa,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAmBxC,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,mCAAuB,CAAA;IACvB,6BAAiB,CAAA;IACjB,yBAAa,CAAA;IACb,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,yBAAa,CAAA;IAEb,uBAAW,CAAA;IAEX,+BAAmB,CAAA;IACnB,yBAAa,CAAA;AACf,CAAC,EAbW,QAAQ,wBAAR,QAAQ,QAanB;AAED,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB;AAED,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,6BAAe,CAAA;IACf,+BAAiB,CAAA;AACnB,CAAC,EANW,UAAU,0BAAV,UAAU,QAMrB;AAED,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,qCAAuB,CAAA;IACvB,+BAAiB,CAAA;AACnB,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { runInIsolate } from './run-in-isolate';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runInIsolate = void 0;
|
|
4
|
+
var run_in_isolate_1 = require("./run-in-isolate");
|
|
5
|
+
Object.defineProperty(exports, "runInIsolate", { enumerable: true, get: function () { return run_in_isolate_1.runInIsolate; } });
|
|
6
|
+
//# sourceMappingURL=engine-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-entry.js","sourceRoot":"","sources":["../../src/engine/engine-entry.ts"],"names":[],"mappings":";;;AAEA,mDAAgD;AAAvC,8GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ENGINE_GLOBAL_NAME = "AbyssRuntimeEngine";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-global.js","sourceRoot":"","sources":["../../src/engine/engine-global.ts"],"names":[],"mappings":";;;AACa,QAAA,kBAAkB,GAAG,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ENGINE_SOURCE = "\"use strict\";\nvar AbyssRuntimeEngine = (() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n // src/engine/engine-entry.ts\n var engine_entry_exports = {};\n __export(engine_entry_exports, {\n runInIsolate: () => runInIsolate\n });\n\n // src/errors/runtime-error-code.enum.ts\n var RuntimeErrorCode = /* @__PURE__ */ ((RuntimeErrorCode2) => {\n RuntimeErrorCode2[\"EXPRESSION_ERROR\"] = \"EXPRESSION_ERROR\";\n RuntimeErrorCode2[\"CODE_ERROR\"] = \"CODE_ERROR\";\n RuntimeErrorCode2[\"TIMEOUT\"] = \"TIMEOUT\";\n RuntimeErrorCode2[\"MEMORY_LIMIT\"] = \"MEMORY_LIMIT\";\n RuntimeErrorCode2[\"ACCESS_DENIED\"] = \"ACCESS_DENIED\";\n RuntimeErrorCode2[\"BUDGET_EXCEEDED\"] = \"BUDGET_EXCEEDED\";\n RuntimeErrorCode2[\"HOST_ERROR\"] = \"HOST_ERROR\";\n RuntimeErrorCode2[\"HTTP_ERROR\"] = \"HTTP_ERROR\";\n RuntimeErrorCode2[\"RUNNER_UNAVAILABLE\"] = \"RUNNER_UNAVAILABLE\";\n RuntimeErrorCode2[\"RUNNER_SATURATED\"] = \"RUNNER_SATURATED\";\n RuntimeErrorCode2[\"INVALID_REQUEST\"] = \"INVALID_REQUEST\";\n RuntimeErrorCode2[\"STATE_VERSION_UNSUPPORTED\"] = \"STATE_VERSION_UNSUPPORTED\";\n return RuntimeErrorCode2;\n })(RuntimeErrorCode || {});\n\n // src/definition/definition.limits.ts\n var MAX_WAIT_DURATION_MS = 30 * 24 * 60 * 60 * 1e3;\n var MIN_RESPONSE_STATUS = 100;\n var MAX_RESPONSE_STATUS = 599;\n\n // src/interpreter/interpreter-error.ts\n var InterpreterError = class extends Error {\n constructor(code, message) {\n super(message);\n this.name = \"InterpreterError\";\n this.code = code;\n }\n };\n\n // src/definition/definition.types.ts\n var CURRENT_FORMAT_VERSION = 1;\n\n // src/steps/value-source.ts\n var TEMPLATE_PATTERN = /\\{\\{[\\s\\S]*?\\}\\}/;\n var IDENTIFIER_KEY = /^[A-Za-z_$][\\w$-]*$/;\n var isExpressionValue = (value) => typeof value === \"object\" && value !== null && !Array.isArray(value) && Object.keys(value).length === 1 && typeof value.$expression === \"string\";\n var propertyPath = (base, key) => IDENTIFIER_KEY.test(key) ? `${base}.${key}` : `${base}[${JSON.stringify(key)}]`;\n var indexPath = (base, index) => `${base}[${index}]`;\n var collectItems = (path, source, items) => {\n if (typeof source === \"string\") {\n if (TEMPLATE_PATTERN.test(source)) {\n items.push({ id: path, kind: \"TEMPLATE\" /* TEMPLATE */, source });\n }\n return;\n }\n if (source === null || typeof source !== \"object\") {\n return;\n }\n if (isExpressionValue(source)) {\n items.push({ id: path, kind: \"EXPRESSION\" /* EXPRESSION */, source: source.$expression });\n return;\n }\n if (Array.isArray(source)) {\n source.forEach((entry, index) => collectItems(indexPath(path, index), entry, items));\n return;\n }\n for (const [key, entry] of Object.entries(source)) {\n collectItems(propertyPath(path, key), entry, items);\n }\n };\n var resolveValue = (path, source, results) => {\n if (typeof source === \"string\") {\n return TEMPLATE_PATTERN.test(source) ? results.get(path) : source;\n }\n if (source === null || typeof source !== \"object\") {\n return source;\n }\n if (isExpressionValue(source)) {\n return results.get(path);\n }\n if (Array.isArray(source)) {\n return source.map((entry, index) => resolveValue(indexPath(path, index), entry, results));\n }\n return Object.fromEntries(\n Object.entries(source).map(([key, entry]) => [\n key,\n resolveValue(propertyPath(path, key), entry, results)\n ])\n );\n };\n\n // src/steps/execute-step.ts\n var fail = (message) => ({\n kind: \"FAIL\" /* FAIL */,\n error: { code: \"EXPRESSION_ERROR\" /* EXPRESSION_ERROR */, message }\n });\n var headerValue = (value) => typeof value === \"string\" ? value : JSON.stringify(value) ?? \"\";\n var resolvedRecord = (base, keys, fields) => Object.fromEntries(keys.map((key) => [key, fields.get(propertyPath(base, key))]));\n var executeWait = (step, fields) => {\n if (step.durationMs !== void 0) {\n const durationMs = fields.get(\"durationMs\");\n if (typeof durationMs !== \"number\" || !Number.isInteger(durationMs) || durationMs < 0) {\n return fail(\"Wait duration must resolve to a non-negative integer number of milliseconds\");\n }\n return { kind: \"WAIT\" /* WAIT */, durationMs };\n }\n const until = fields.get(\"until\");\n if (typeof until !== \"string\" || Number.isNaN(Date.parse(until))) {\n return fail(\"Wait date must resolve to an ISO 8601 date\");\n }\n return { kind: \"WAIT\" /* WAIT */, until };\n };\n var executeLog = (step, fields) => {\n const message = fields.get(\"message\");\n const action = {\n kind: \"LOG\" /* LOG */,\n level: step.level,\n message: typeof message === \"string\" ? message : JSON.stringify(message) ?? \"\"\n };\n if (step.data !== void 0) {\n action.data = fields.get(\"data\");\n }\n return action;\n };\n var executeRespond = (step, fields) => {\n const status = fields.get(\"status\");\n if (typeof status !== \"number\" || !Number.isInteger(status) || status < MIN_RESPONSE_STATUS || status > MAX_RESPONSE_STATUS) {\n return fail(\n `Response status must resolve to an integer from ${MIN_RESPONSE_STATUS} to ${MAX_RESPONSE_STATUS}`\n );\n }\n const headers = resolvedRecord(\"headers\", Object.keys(step.headers ?? {}), fields);\n const response = {\n status,\n headers: Object.fromEntries(\n Object.entries(headers).map(([key, value]) => [key, headerValue(value)])\n )\n };\n if (step.body !== void 0) {\n response.body = fields.get(\"body\");\n }\n return { kind: \"RESPOND\" /* RESPOND */, response };\n };\n var executeStep = (step, fields) => {\n switch (step.type) {\n case \"CONDITION\" /* CONDITION */: {\n if (fields.get(\"if\")) {\n return { kind: \"DONE\" /* DONE */, output: \"then\", branch: \"then\" };\n }\n return step.else ? { kind: \"DONE\" /* DONE */, output: \"else\", branch: \"else\" } : { kind: \"DONE\" /* DONE */, output: \"else\" };\n }\n case \"SWITCH\" /* SWITCH */: {\n const value = fields.get(\"value\");\n const index = step.cases.findIndex(\n (_, caseIndex) => fields.get(`cases[${caseIndex}].match`) === value\n );\n if (index >= 0) {\n const branch = `cases[${index}].steps`;\n return { kind: \"DONE\" /* DONE */, output: `cases[${index}]`, branch };\n }\n return step.default ? { kind: \"DONE\" /* DONE */, output: \"default\", branch: \"default\" } : { kind: \"DONE\" /* DONE */, output: null };\n }\n case \"WAIT\" /* WAIT */:\n return executeWait(step, fields);\n case \"SET\" /* SET */: {\n const value = fields.get(\"value\");\n return {\n kind: \"DONE\" /* DONE */,\n output: value,\n variable: { name: step.variable, value }\n };\n }\n case \"CODE\" /* CODE */:\n return { kind: \"DONE\" /* DONE */, output: fields.get(\"source\") };\n case \"HTTP\" /* HTTP */: {\n const url = fields.get(\"url\");\n if (typeof url !== \"string\") {\n return fail(\"HTTP url must resolve to a string\");\n }\n const headers = resolvedRecord(\"headers\", Object.keys(step.headers ?? {}), fields);\n const request = {\n method: step.method,\n url,\n headers: Object.fromEntries(\n Object.entries(headers).map(([key, value]) => [key, headerValue(value)])\n )\n };\n if (step.body !== void 0) {\n request.body = fields.get(\"body\");\n }\n if (step.timeoutMs !== void 0) {\n request.timeoutMs = step.timeoutMs;\n }\n return { kind: \"HTTP\" /* HTTP */, request };\n }\n case \"HOST\" /* HOST */:\n return {\n kind: \"HOST\" /* HOST */,\n action: step.action,\n input: resolvedRecord(\"input\", Object.keys(step.input), fields)\n };\n case \"LOG\" /* LOG */:\n return executeLog(step, fields);\n case \"RESPOND\" /* RESPOND */:\n return executeRespond(step, fields);\n case \"STOP\" /* STOP */:\n return { kind: \"STOP\" /* STOP */, status: step.status, output: fields.get(\"output\") };\n }\n };\n\n // src/steps/step-fields.ts\n var recordFields = (base, record) => Object.entries(record ?? {}).map(([key, source]) => ({ path: propertyPath(base, key), source }));\n var optionalField = (path, source) => source === void 0 ? [] : [{ path, source }];\n var stepFields = (step) => {\n switch (step.type) {\n case \"CONDITION\" /* CONDITION */:\n return [{ path: \"if\", source: step.if }];\n case \"SWITCH\" /* SWITCH */:\n return [\n { path: \"value\", source: step.value },\n ...step.cases.map((switchCase, index) => ({\n path: `cases[${index}].match`,\n source: switchCase.match\n }))\n ];\n case \"WAIT\" /* WAIT */:\n return [\n ...optionalField(\"durationMs\", step.durationMs),\n ...optionalField(\"until\", step.until)\n ];\n case \"SET\" /* SET */:\n return [{ path: \"value\", source: step.value }];\n case \"CODE\" /* CODE */:\n return [];\n case \"HTTP\" /* HTTP */:\n return [\n { path: \"url\", source: step.url },\n ...recordFields(\"headers\", step.headers),\n ...optionalField(\"body\", step.body)\n ];\n case \"HOST\" /* HOST */:\n return recordFields(\"input\", step.input);\n case \"LOG\" /* LOG */:\n return [{ path: \"message\", source: step.message }, ...optionalField(\"data\", step.data)];\n case \"RESPOND\" /* RESPOND */:\n return [\n { path: \"status\", source: step.status },\n ...recordFields(\"headers\", step.headers),\n ...optionalField(\"body\", step.body)\n ];\n case \"STOP\" /* STOP */:\n return optionalField(\"output\", step.output);\n }\n };\n var collectStepItems = (step) => {\n if (step.type === \"CODE\" /* CODE */) {\n return [{ id: \"source\", kind: \"CODE\" /* CODE */, source: step.source }];\n }\n const items = [];\n for (const field of stepFields(step)) {\n collectItems(field.path, field.source, items);\n }\n return items;\n };\n var resolveStepFields = (step, results) => {\n if (step.type === \"CODE\" /* CODE */) {\n return /* @__PURE__ */ new Map([[\"source\", results.get(\"source\")]]);\n }\n return new Map(\n stepFields(step).map((field) => [field.path, resolveValue(field.path, field.source, results)])\n );\n };\n\n // src/interpreter/interpreter.types.ts\n var CURRENT_STATE_VERSION = 1;\n\n // src/interpreter/sequence-path.ts\n var ROOT = \"steps\";\n var SEGMENT = /\\[(\\d+)\\]\\.(?:(then|else|default)|cases\\[(\\d+)\\]\\.steps)/y;\n var corrupted = (path) => new InterpreterError(\n \"INVALID_REQUEST\" /* INVALID_REQUEST */,\n `Run state points outside the definition: ${path}`\n );\n var branchOf = (step, name, caseIndex) => {\n if (step.type === \"CONDITION\" /* CONDITION */) {\n return name === \"then\" ? step.then : name === \"else\" ? step.else : void 0;\n }\n if (step.type === \"SWITCH\" /* SWITCH */) {\n return name === \"default\" ? step.default : caseIndex === void 0 ? void 0 : step.cases[Number(caseIndex)]?.steps;\n }\n return void 0;\n };\n var resolveSequence = (definition, path) => {\n if (!path.startsWith(ROOT)) {\n throw corrupted(path);\n }\n let sequence = definition.steps;\n let position = ROOT.length;\n while (position < path.length) {\n SEGMENT.lastIndex = position;\n const match = SEGMENT.exec(path);\n const next = match ? branchOf(sequence[Number(match[1])], match[2], match[3]) : void 0;\n if (!match || !next) {\n throw corrupted(path);\n }\n sequence = next;\n position = SEGMENT.lastIndex;\n }\n return sequence;\n };\n var resolveStep = (definition, frame) => {\n const step = resolveSequence(definition, frame.sequencePath)[frame.index];\n if (!step) {\n throw corrupted(frame.sequencePath);\n }\n return step;\n };\n var branchPath = (frame, branch) => `${frame.sequencePath}[${frame.index}].${branch}`;\n var ROOT_SEQUENCE_PATH = ROOT;\n\n // src/interpreter/interpreter.ts\n var NO_RESULTS = /* @__PURE__ */ new Map();\n var SILENT_OBSERVER = {\n stepStarted: () => void 0,\n stepFinished: () => void 0\n };\n var invalidRequest = (message) => new InterpreterError(\"INVALID_REQUEST\" /* INVALID_REQUEST */, message);\n var draftOf = (state) => ({\n ...state,\n stack: state.stack.map((frame) => ({ ...frame })),\n outputs: { ...state.outputs },\n vars: { ...state.vars },\n counters: { ...state.counters }\n });\n var setOwn = (target, key, value) => {\n Object.defineProperty(target, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n };\n var topFrame = (draft) => draft.stack[draft.stack.length - 1];\n var advance = (draft) => {\n topFrame(draft).index += 1;\n };\n var settle = (draft, status) => {\n draft.status = status;\n draft.pending = null;\n return { state: draft, effects: [], status };\n };\n var failRun = (context, draft, error, stepId) => {\n draft.outcome = { status: \"FAILED\" /* FAILED */, error: { ...error, stepId } };\n context.observer.stepFinished(stepId, { ok: false, error });\n return settle(draft, \"FAILED\" /* FAILED */);\n };\n var emit = (context, draft, effect) => {\n if (draft.counters.effects + 1 > context.policy.budget.maxEffects) {\n return failRun(\n context,\n draft,\n { code: \"BUDGET_EXCEEDED\" /* BUDGET_EXCEEDED */, message: \"Effect budget exceeded\" },\n effect.stepId\n );\n }\n draft.counters.effects += 1;\n draft.pending = effect;\n draft.status = \"WAITING\" /* WAITING */;\n return { state: draft, effects: [effect], status: \"WAITING\" /* WAITING */ };\n };\n var accessDenied = (verdict, subject) => ({\n code: \"ACCESS_DENIED\" /* ACCESS_DENIED */,\n message: verdict === \"NOT_DECLARED\" /* NOT_DECLARED */ ? `${subject} is not declared by the definition` : `${subject} is not granted to the run`\n });\n var applyAction = (context, draft, step, action) => {\n const { policy, observer } = context;\n switch (action.kind) {\n case \"FAIL\" /* FAIL */:\n return failRun(context, draft, action.error, step.id);\n case \"STOP\" /* STOP */:\n draft.outcome = { status: action.status, output: action.output };\n observer.stepFinished(step.id, { ok: true, output: action.output });\n return settle(\n draft,\n action.status === \"SUCCEEDED\" /* SUCCEEDED */ ? \"SUCCEEDED\" /* SUCCEEDED */ : \"FAILED\" /* FAILED */\n );\n case \"DONE\" /* DONE */: {\n setOwn(draft.outputs, step.id, { output: action.output });\n observer.stepFinished(step.id, { ok: true, output: action.output });\n if (action.variable) {\n setOwn(draft.vars, action.variable.name, action.variable.value);\n }\n if (action.branch === void 0) {\n advance(draft);\n } else {\n draft.stack.push({ sequencePath: branchPath(topFrame(draft), action.branch), index: 0 });\n }\n return null;\n }\n case \"WAIT\" /* WAIT */: {\n const maxWaitMs = Math.min(policy.budget.maxWaitMs, MAX_WAIT_DURATION_MS);\n if (action.durationMs !== void 0 && action.durationMs > maxWaitMs) {\n return failRun(\n context,\n draft,\n {\n code: \"BUDGET_EXCEEDED\" /* BUDGET_EXCEEDED */,\n message: `Wait duration exceeds the budget of ${maxWaitMs} ms`\n },\n step.id\n );\n }\n const effect = { type: \"WAIT\" /* WAIT */, stepId: step.id };\n if (action.durationMs !== void 0) {\n effect.durationMs = action.durationMs;\n }\n if (action.until !== void 0) {\n effect.until = action.until;\n }\n return emit(context, draft, effect);\n }\n case \"HTTP\" /* HTTP */: {\n const verdict = policy.httpAccess(action.request.url);\n if (verdict !== \"ALLOWED\" /* ALLOWED */) {\n return failRun(context, draft, accessDenied(verdict, \"HTTP request host\"), step.id);\n }\n return emit(context, draft, {\n type: \"HTTP\" /* HTTP */,\n stepId: step.id,\n request: action.request\n });\n }\n case \"HOST\" /* HOST */: {\n const verdict = policy.hostActionAccess(action.action);\n if (verdict !== \"ALLOWED\" /* ALLOWED */) {\n return failRun(context, draft, accessDenied(verdict, \"Host action\"), step.id);\n }\n const validated = policy.hostInput(action.action, action.input);\n if (\"error\" in validated) {\n return failRun(context, draft, validated.error, step.id);\n }\n return emit(context, draft, {\n type: \"HOST\" /* HOST */,\n stepId: step.id,\n action: action.action,\n input: validated.input\n });\n }\n // Logging and responding are granted to every run; the host bounds them (one response).\n case \"LOG\" /* LOG */: {\n const effect = {\n type: \"LOG\" /* LOG */,\n stepId: step.id,\n level: action.level,\n message: action.message\n };\n if (\"data\" in action) {\n effect.data = action.data;\n }\n return emit(context, draft, effect);\n }\n case \"RESPOND\" /* RESPOND */:\n return emit(context, draft, {\n type: \"RESPOND\" /* RESPOND */,\n stepId: step.id,\n response: action.response\n });\n }\n };\n var runStep = (context, draft, step, results) => {\n if (results === void 0) {\n const items = collectStepItems(step);\n if (items.length > 0) {\n return emit(context, draft, {\n type: \"EVALUATE\" /* EVALUATE */,\n stepId: step.id,\n items,\n context: { input: draft.input, steps: draft.outputs, vars: draft.vars }\n });\n }\n }\n const fields = resolveStepFields(step, results ?? NO_RESULTS);\n return applyAction(context, draft, step, executeStep(step, fields));\n };\n var drive = (context, draft) => {\n for (; ; ) {\n const frame = topFrame(draft);\n if (!frame) {\n draft.outcome = { status: \"SUCCEEDED\" /* SUCCEEDED */ };\n return settle(draft, \"SUCCEEDED\" /* SUCCEEDED */);\n }\n const sequence = resolveSequence(context.definition, frame.sequencePath);\n if (frame.index >= sequence.length) {\n draft.stack.pop();\n if (draft.stack.length > 0) {\n advance(draft);\n }\n continue;\n }\n const step = sequence[frame.index];\n context.observer.stepStarted(step.id);\n if (draft.counters.steps + 1 > context.policy.budget.maxSteps) {\n return failRun(\n context,\n draft,\n { code: \"BUDGET_EXCEEDED\" /* BUDGET_EXCEEDED */, message: \"Step budget exceeded\" },\n step.id\n );\n }\n draft.counters.steps += 1;\n const result = runStep(context, draft, step, void 0);\n if (result) {\n return result;\n }\n }\n };\n var startRun = (definition, input, policy, observer = SILENT_OBSERVER) => drive(\n { definition, policy, observer },\n {\n stateVersion: CURRENT_STATE_VERSION,\n formatVersion: CURRENT_FORMAT_VERSION,\n status: \"WAITING\" /* WAITING */,\n input,\n stack: [{ sequencePath: ROOT_SEQUENCE_PATH, index: 0 }],\n outputs: {},\n vars: {},\n pending: null,\n counters: { steps: 0, effects: 0 }\n }\n );\n var unexpected = (event, pending) => invalidRequest(`Event ${event.type} does not answer the pending ${pending.type} effect`);\n var readEvaluation = (pending, results) => {\n if (pending.type !== \"EVALUATE\" /* EVALUATE */) {\n throw invalidRequest(\n `Event ${\"EVALUATED\" /* EVALUATED */} does not answer the pending ${pending.type} effect`\n );\n }\n const values = /* @__PURE__ */ new Map();\n for (const item of pending.items) {\n const result = results.find((candidate) => candidate.id === item.id);\n if (!result) {\n throw invalidRequest(\"Evaluation results do not cover every item of the lot\");\n }\n if (!result.ok) {\n return result.error;\n }\n values.set(item.id, result.value);\n }\n return values;\n };\n var complete = (context, draft, step, output) => {\n setOwn(draft.outputs, step.id, { output });\n context.observer.stepFinished(step.id, { ok: true, output });\n advance(draft);\n return drive(context, draft);\n };\n var stepRun = (definition, state, event, policy, observer = SILENT_OBSERVER) => {\n if (state.stateVersion !== CURRENT_STATE_VERSION) {\n throw new InterpreterError(\n \"STATE_VERSION_UNSUPPORTED\" /* STATE_VERSION_UNSUPPORTED */,\n `Run state version ${String(state.stateVersion)} is not supported (this core reads version ${CURRENT_STATE_VERSION})`\n );\n }\n const pending = state.pending;\n if (state.status !== \"WAITING\" /* WAITING */ || !pending) {\n throw invalidRequest(`Event ${event.type} received by a run that waits for nothing`);\n }\n const context = { definition, policy, observer };\n const draft = draftOf(state);\n draft.pending = null;\n const current = resolveStep(definition, topFrame(draft));\n switch (event.type) {\n case \"EVALUATED\" /* EVALUATED */: {\n const values = readEvaluation(pending, event.results);\n if (!(values instanceof Map)) {\n return failRun(context, draft, values, current.id);\n }\n return runStep(context, draft, current, values) ?? drive(context, draft);\n }\n case \"HTTP_COMPLETED\" /* HTTP_COMPLETED */:\n if (pending.type !== \"HTTP\" /* HTTP */) {\n throw unexpected(event, pending);\n }\n return complete(context, draft, current, event.response);\n case \"HOST_COMPLETED\" /* HOST_COMPLETED */:\n if (pending.type !== \"HOST\" /* HOST */) {\n throw unexpected(event, pending);\n }\n return complete(context, draft, current, event.output);\n case \"WAIT_ELAPSED\" /* WAIT_ELAPSED */:\n if (pending.type !== \"WAIT\" /* WAIT */) {\n throw unexpected(event, pending);\n }\n return complete(context, draft, current, null);\n case \"LOG_WRITTEN\" /* LOG_WRITTEN */:\n if (pending.type !== \"LOG\" /* LOG */) {\n throw unexpected(event, pending);\n }\n return complete(context, draft, current, null);\n case \"RESPONSE_SENT\" /* RESPONSE_SENT */:\n if (pending.type !== \"RESPOND\" /* RESPOND */) {\n throw unexpected(event, pending);\n }\n return complete(context, draft, current, null);\n case \"RESUMED\" /* RESUMED */:\n if (pending.type === \"EVALUATE\" /* EVALUATE */) {\n throw unexpected(event, pending);\n }\n return complete(context, draft, current, event.output);\n case \"EFFECT_FAILED\" /* EFFECT_FAILED */:\n return failRun(context, draft, event.error, current.id);\n }\n };\n\n // src/runner-protocol/execution-protocol.types.ts\n var MAX_PROGRESS_OUTPUT_CHARS = 4096;\n\n // src/engine/run-in-isolate.ts\n var RUNTIME_ERROR_CODES = new Set(Object.values(RuntimeErrorCode));\n var rejected = (code, message) => ({\n kind: \"REJECTED\" /* REJECTED */,\n code,\n message\n });\n var finished = (outcome) => ({\n kind: \"FINISHED\" /* FINISHED */,\n outcome\n });\n var isolatePolicy = (request) => {\n const exposed = new Set(request.capabilities);\n const declared = (action) => request.definition.accesses.some(\n (access) => access.kind === \"HOST_ACTION\" /* HOST_ACTION */ && access.action === action\n );\n return {\n // Waits above `suspendWaitAboveMs` suspend; the host bounds the others by the time left.\n budget: { ...request.budget, maxWaitMs: MAX_WAIT_DURATION_MS },\n httpAccess: () => exposed.has(\"http.fetch\" /* HTTP_FETCH */) ? \"ALLOWED\" /* ALLOWED */ : \"NOT_GRANTED\" /* NOT_GRANTED */,\n hostActionAccess: (action) => {\n if (!declared(action)) {\n return \"NOT_DECLARED\" /* NOT_DECLARED */;\n }\n return exposed.has(action) ? \"ALLOWED\" /* ALLOWED */ : \"NOT_GRANTED\" /* NOT_GRANTED */;\n },\n hostInput: (_action, input) => ({ input })\n };\n };\n var outputPreview = (output) => {\n let json;\n try {\n json = JSON.stringify(output);\n } catch {\n return { outputTruncated: true };\n }\n if (json === void 0) {\n return {};\n }\n if (json.length <= MAX_PROGRESS_OUTPUT_CHARS) {\n return { output };\n }\n return { output: json.slice(0, MAX_PROGRESS_OUTPUT_CHARS), outputTruncated: true };\n };\n var progressObserver = (host) => {\n const startedAt = /* @__PURE__ */ new Map();\n const durationOf = (stepId) => {\n const start = startedAt.get(stepId);\n startedAt.delete(stepId);\n return start === void 0 ? 0 : Math.max(0, host.now() - start);\n };\n const observer = {\n stepStarted: (stepId) => {\n startedAt.set(stepId, host.now());\n host.onProgress({ stepId, phase: \"started\" /* STARTED */ });\n },\n stepFinished: (stepId, finish) => {\n const durationMs = durationOf(stepId);\n host.onProgress(\n finish.ok ? {\n stepId,\n phase: \"finished\" /* FINISHED */,\n status: \"SUCCEEDED\" /* SUCCEEDED */,\n durationMs,\n ...outputPreview(finish.output)\n } : {\n stepId,\n phase: \"finished\" /* FINISHED */,\n status: \"FAILED\" /* FAILED */,\n durationMs,\n errorCode: finish.error.code\n }\n );\n }\n };\n const suspended = (stepId) => host.onProgress({\n stepId,\n phase: \"finished\" /* FINISHED */,\n status: \"SUSPENDED\" /* SUSPENDED */,\n durationMs: durationOf(stepId)\n });\n return { observer, suspended };\n };\n var callOf = (effect) => {\n switch (effect.type) {\n case \"HTTP\" /* HTTP */:\n return { capability: \"http.fetch\" /* HTTP_FETCH */, args: effect.request };\n case \"HOST\" /* HOST */:\n return { capability: effect.action, args: effect.input };\n case \"WAIT\" /* WAIT */:\n return {\n capability: \"wait\" /* WAIT */,\n args: effect.durationMs !== void 0 ? { durationMs: effect.durationMs } : { until: effect.until }\n };\n case \"LOG\" /* LOG */: {\n const args = { level: effect.level, message: effect.message };\n if (\"data\" in effect) {\n args.data = effect.data;\n }\n return { capability: \"log.write\" /* LOG_WRITE */, args };\n }\n case \"RESPOND\" /* RESPOND */:\n return { capability: \"http.respond\" /* HTTP_RESPOND */, args: effect.response };\n }\n };\n var completionOf = (effect, value) => {\n switch (effect.type) {\n case \"HTTP\" /* HTTP */:\n return { type: \"HTTP_COMPLETED\" /* HTTP_COMPLETED */, response: value };\n case \"HOST\" /* HOST */:\n return { type: \"HOST_COMPLETED\" /* HOST_COMPLETED */, output: value };\n case \"WAIT\" /* WAIT */:\n return { type: \"WAIT_ELAPSED\" /* WAIT_ELAPSED */ };\n case \"LOG\" /* LOG */:\n return { type: \"LOG_WRITTEN\" /* LOG_WRITTEN */ };\n case \"RESPOND\" /* RESPOND */:\n return { type: \"RESPONSE_SENT\" /* RESPONSE_SENT */ };\n }\n };\n var callFailure = (effect, error) => {\n const fallback = effect.type === \"HTTP\" /* HTTP */ ? \"HTTP_ERROR\" /* HTTP_ERROR */ : \"HOST_ERROR\" /* HOST_ERROR */;\n const detail = {\n code: error.code !== void 0 && RUNTIME_ERROR_CODES.has(error.code) ? error.code : fallback,\n message: error.message\n };\n return { type: \"EFFECT_FAILED\" /* EFFECT_FAILED */, error: detail };\n };\n var waitsAboveThreshold = (effect, request, now) => {\n const threshold = request.suspendWaitAboveMs;\n if (threshold === void 0) {\n return false;\n }\n if (effect.durationMs !== void 0) {\n return effect.durationMs > threshold;\n }\n return effect.until !== void 0 && Date.parse(effect.until) - now > threshold;\n };\n var outcomeOf = (state) => {\n const outcome = state.outcome;\n if (state.status === \"SUCCEEDED\" /* SUCCEEDED */) {\n return outcome?.output === void 0 ? { status: \"SUCCEEDED\" /* SUCCEEDED */ } : { status: \"SUCCEEDED\" /* SUCCEEDED */, output: outcome.output };\n }\n if (outcome?.error) {\n const failure = {\n status: \"FAILED\" /* FAILED */,\n errorCode: outcome.error.code,\n errorMessage: outcome.error.message\n };\n if (outcome.error.stepId !== void 0) {\n failure.stepId = outcome.error.stepId;\n }\n return failure;\n }\n return outcome?.status === \"FAILED\" /* FAILED */ && outcome.output !== void 0 ? { status: \"FAILED\" /* FAILED */, output: outcome.output } : { status: \"FAILED\" /* FAILED */ };\n };\n var resumeRefusal = (state) => {\n if (state.stateVersion !== CURRENT_STATE_VERSION) {\n return rejected(\n \"STATE_VERSION_UNSUPPORTED\" /* STATE_VERSION_UNSUPPORTED */,\n `Run state version ${String(state.stateVersion)} is not supported (this core reads version ${CURRENT_STATE_VERSION})`\n );\n }\n if (state.status !== \"WAITING\" /* WAITING */ || !state.pending) {\n return rejected(\"INVALID_REQUEST\" /* INVALID_REQUEST */, \"The state to resume is not suspended\");\n }\n if (state.pending.type === \"EVALUATE\" /* EVALUATE */) {\n return rejected(\n \"INVALID_REQUEST\" /* INVALID_REQUEST */,\n \"The state to resume waits for an evaluation, which never suspends\"\n );\n }\n return null;\n };\n var runInIsolate = async (request, host) => {\n const { definition, state } = request;\n if (state !== void 0) {\n const refusal = resumeRefusal(state);\n if (refusal) {\n return refusal;\n }\n }\n const policy = isolatePolicy(request);\n const exposed = new Set(request.capabilities);\n const progress = progressObserver(host);\n const suspend = (stepId, suspendedState) => {\n progress.suspended(stepId);\n return finished({ status: \"SUSPENDED\" /* SUSPENDED */, state: suspendedState });\n };\n try {\n let result;\n if (state === void 0) {\n result = startRun(definition, request.input, policy, progress.observer);\n } else {\n progress.observer.stepStarted(state.pending.stepId);\n result = stepRun(\n definition,\n state,\n { type: \"RESUMED\" /* RESUMED */, output: request.resumeInput ?? null },\n policy,\n progress.observer\n );\n }\n while (result.status === \"WAITING\" /* WAITING */) {\n const effect = result.state.pending;\n if (!effect) {\n throw new InterpreterError(\"INVALID_REQUEST\" /* INVALID_REQUEST */, \"Run waits for no effect\");\n }\n let event;\n if (effect.type === \"EVALUATE\" /* EVALUATE */) {\n const results = await host.evaluate(\n effect.items,\n effect.context,\n effect.stepId,\n request.globals\n );\n event = { type: \"EVALUATED\" /* EVALUATED */, results };\n } else if (effect.type === \"WAIT\" /* WAIT */ && waitsAboveThreshold(effect, request, host.now())) {\n return suspend(effect.stepId, result.state);\n } else {\n const { capability, args } = callOf(effect);\n if (!exposed.has(capability)) {\n event = {\n type: \"EFFECT_FAILED\" /* EFFECT_FAILED */,\n error: {\n code: \"ACCESS_DENIED\" /* ACCESS_DENIED */,\n message: `Capability \"${capability}\" is not granted to the execution`\n }\n };\n } else {\n const answer = await host.callHost(effect.stepId, capability, args);\n if (!answer.ok) {\n event = callFailure(effect, answer.error);\n } else if (\"suspend\" in answer) {\n return suspend(effect.stepId, result.state);\n } else {\n event = completionOf(effect, answer.value);\n }\n }\n }\n result = stepRun(definition, result.state, event, policy, progress.observer);\n }\n return finished(outcomeOf(result.state));\n } catch (error) {\n if (error instanceof InterpreterError) {\n return finished({\n status: \"FAILED\" /* FAILED */,\n errorCode: error.code,\n errorMessage: error.message\n });\n }\n throw error;\n }\n };\n return __toCommonJS(engine_entry_exports);\n})();\n";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EvaluationContext } from '../interpreter/interpreter.types';
|
|
2
|
+
import type { EvaluationItem, EvaluationResult } from '../runner-protocol/evaluation.types';
|
|
3
|
+
import type { CallError, ExecuteMessage, ExecutionOutcome, ExecutionRejectionCode, JSONValue, ProgressMessage } from '../runner-protocol/execution-protocol.types';
|
|
4
|
+
export type HostCallAnswer = {
|
|
5
|
+
ok: true;
|
|
6
|
+
value: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
ok: true;
|
|
9
|
+
suspend: true;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
error: CallError;
|
|
13
|
+
};
|
|
14
|
+
export type EngineProgress = Omit<ProgressMessage, 'type' | 'metrics'>;
|
|
15
|
+
export interface EngineHost {
|
|
16
|
+
evaluate: (items: EvaluationItem[], context: EvaluationContext, stepId: string, globals?: Record<string, JSONValue>) => Promise<EvaluationResult[]>;
|
|
17
|
+
callHost: (stepId: string, capability: string, args: unknown) => Promise<HostCallAnswer>;
|
|
18
|
+
onProgress: (progress: EngineProgress) => void;
|
|
19
|
+
now: () => number;
|
|
20
|
+
}
|
|
21
|
+
export type EngineRequest = Pick<ExecuteMessage, 'definition' | 'input' | 'state' | 'resumeInput' | 'capabilities' | 'budget' | 'suspendWaitAboveMs' | 'globals'>;
|
|
22
|
+
export declare enum EngineResultKind {
|
|
23
|
+
FINISHED = "FINISHED",
|
|
24
|
+
REJECTED = "REJECTED"
|
|
25
|
+
}
|
|
26
|
+
export type EngineResult = {
|
|
27
|
+
kind: EngineResultKind.FINISHED;
|
|
28
|
+
outcome: ExecutionOutcome;
|
|
29
|
+
} | {
|
|
30
|
+
kind: EngineResultKind.REJECTED;
|
|
31
|
+
code: ExecutionRejectionCode;
|
|
32
|
+
message: string;
|
|
33
|
+
};
|
|
34
|
+
export declare const runInIsolate: (request: EngineRequest, host: EngineHost) => Promise<EngineResult>;
|