@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
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { EvaluationKind } from '../runner-protocol/
|
|
2
|
-
import type { EvaluationItem } from '../runner-protocol/
|
|
3
|
-
import type { ExpressionValue, ValueSource } from '../definition/definition.types';
|
|
4
|
-
|
|
5
|
-
const TEMPLATE_PATTERN = /\{\{[\s\S]*?\}\}/;
|
|
6
|
-
const IDENTIFIER_KEY = /^[A-Za-z_$][\w$-]*$/;
|
|
7
|
-
|
|
8
|
-
export const isExpressionValue = (value: ValueSource): value is ExpressionValue =>
|
|
9
|
-
typeof value === 'object' &&
|
|
10
|
-
value !== null &&
|
|
11
|
-
!Array.isArray(value) &&
|
|
12
|
-
Object.keys(value).length === 1 &&
|
|
13
|
-
typeof (value as ExpressionValue).$expression === 'string';
|
|
14
|
-
|
|
15
|
-
/** Field path of a property, unambiguous whatever the key: `a.b`, `a["x.y"]`. */
|
|
16
|
-
export const propertyPath = (base: string, key: string): string =>
|
|
17
|
-
IDENTIFIER_KEY.test(key) ? `${base}.${key}` : `${base}[${JSON.stringify(key)}]`;
|
|
18
|
-
|
|
19
|
-
const indexPath = (base: string, index: number): string => `${base}[${index}]`;
|
|
20
|
-
|
|
21
|
-
/** Appends one item per non-literal value found in `source`; the item id is its field path. */
|
|
22
|
-
export const collectItems = (path: string, source: ValueSource, items: EvaluationItem[]): void => {
|
|
23
|
-
if (typeof source === 'string') {
|
|
24
|
-
if (TEMPLATE_PATTERN.test(source)) {
|
|
25
|
-
items.push({ id: path, kind: EvaluationKind.TEMPLATE, source });
|
|
26
|
-
}
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (source === null || typeof source !== 'object') {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (isExpressionValue(source)) {
|
|
33
|
-
items.push({ id: path, kind: EvaluationKind.EXPRESSION, source: source.$expression });
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (Array.isArray(source)) {
|
|
37
|
-
source.forEach((entry, index) => collectItems(indexPath(path, index), entry, items));
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
for (const [key, entry] of Object.entries(source)) {
|
|
41
|
-
collectItems(propertyPath(path, key), entry, items);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/** Rebuilds `source` with every non-literal value replaced by its evaluated result. */
|
|
46
|
-
export const resolveValue = (
|
|
47
|
-
path: string,
|
|
48
|
-
source: ValueSource,
|
|
49
|
-
results: ReadonlyMap<string, unknown>,
|
|
50
|
-
): unknown => {
|
|
51
|
-
if (typeof source === 'string') {
|
|
52
|
-
return TEMPLATE_PATTERN.test(source) ? results.get(path) : source;
|
|
53
|
-
}
|
|
54
|
-
if (source === null || typeof source !== 'object') {
|
|
55
|
-
return source;
|
|
56
|
-
}
|
|
57
|
-
if (isExpressionValue(source)) {
|
|
58
|
-
return results.get(path);
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(source)) {
|
|
61
|
-
return source.map((entry, index) => resolveValue(indexPath(path, index), entry, results));
|
|
62
|
-
}
|
|
63
|
-
return Object.fromEntries(
|
|
64
|
-
Object.entries(source).map(([key, entry]) => [
|
|
65
|
-
key,
|
|
66
|
-
resolveValue(propertyPath(path, key), entry, results),
|
|
67
|
-
]),
|
|
68
|
-
);
|
|
69
|
-
};
|
|
1
|
+
import { EvaluationKind } from '../runner-protocol/evaluation.types';
|
|
2
|
+
import type { EvaluationItem } from '../runner-protocol/evaluation.types';
|
|
3
|
+
import type { ExpressionValue, ValueSource } from '../definition/definition.types';
|
|
4
|
+
|
|
5
|
+
const TEMPLATE_PATTERN = /\{\{[\s\S]*?\}\}/;
|
|
6
|
+
const IDENTIFIER_KEY = /^[A-Za-z_$][\w$-]*$/;
|
|
7
|
+
|
|
8
|
+
export const isExpressionValue = (value: ValueSource): value is ExpressionValue =>
|
|
9
|
+
typeof value === 'object' &&
|
|
10
|
+
value !== null &&
|
|
11
|
+
!Array.isArray(value) &&
|
|
12
|
+
Object.keys(value).length === 1 &&
|
|
13
|
+
typeof (value as ExpressionValue).$expression === 'string';
|
|
14
|
+
|
|
15
|
+
/** Field path of a property, unambiguous whatever the key: `a.b`, `a["x.y"]`. */
|
|
16
|
+
export const propertyPath = (base: string, key: string): string =>
|
|
17
|
+
IDENTIFIER_KEY.test(key) ? `${base}.${key}` : `${base}[${JSON.stringify(key)}]`;
|
|
18
|
+
|
|
19
|
+
const indexPath = (base: string, index: number): string => `${base}[${index}]`;
|
|
20
|
+
|
|
21
|
+
/** Appends one item per non-literal value found in `source`; the item id is its field path. */
|
|
22
|
+
export const collectItems = (path: string, source: ValueSource, items: EvaluationItem[]): void => {
|
|
23
|
+
if (typeof source === 'string') {
|
|
24
|
+
if (TEMPLATE_PATTERN.test(source)) {
|
|
25
|
+
items.push({ id: path, kind: EvaluationKind.TEMPLATE, source });
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (source === null || typeof source !== 'object') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (isExpressionValue(source)) {
|
|
33
|
+
items.push({ id: path, kind: EvaluationKind.EXPRESSION, source: source.$expression });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(source)) {
|
|
37
|
+
source.forEach((entry, index) => collectItems(indexPath(path, index), entry, items));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
for (const [key, entry] of Object.entries(source)) {
|
|
41
|
+
collectItems(propertyPath(path, key), entry, items);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Rebuilds `source` with every non-literal value replaced by its evaluated result. */
|
|
46
|
+
export const resolveValue = (
|
|
47
|
+
path: string,
|
|
48
|
+
source: ValueSource,
|
|
49
|
+
results: ReadonlyMap<string, unknown>,
|
|
50
|
+
): unknown => {
|
|
51
|
+
if (typeof source === 'string') {
|
|
52
|
+
return TEMPLATE_PATTERN.test(source) ? results.get(path) : source;
|
|
53
|
+
}
|
|
54
|
+
if (source === null || typeof source !== 'object') {
|
|
55
|
+
return source;
|
|
56
|
+
}
|
|
57
|
+
if (isExpressionValue(source)) {
|
|
58
|
+
return results.get(path);
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(source)) {
|
|
61
|
+
return source.map((entry, index) => resolveValue(indexPath(path, index), entry, results));
|
|
62
|
+
}
|
|
63
|
+
return Object.fromEntries(
|
|
64
|
+
Object.entries(source).map(([key, entry]) => [
|
|
65
|
+
key,
|
|
66
|
+
resolveValue(propertyPath(path, key), entry, results),
|
|
67
|
+
]),
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { RuntimeErrorCode, RuntimeErrorDetail } from '../errors/runtime-error-code.enum';
|
|
2
|
-
export declare const RUNNER_PROTOCOL = "abyss-runtime.v1";
|
|
3
|
-
export declare enum EvaluationKind {
|
|
4
|
-
EXPRESSION = "EXPRESSION",
|
|
5
|
-
TEMPLATE = "TEMPLATE",
|
|
6
|
-
CODE = "CODE"
|
|
7
|
-
}
|
|
8
|
-
export interface EvaluationItem {
|
|
9
|
-
id: string;
|
|
10
|
-
kind: EvaluationKind;
|
|
11
|
-
source: string;
|
|
12
|
-
}
|
|
13
|
-
export type EvaluationResult = {
|
|
14
|
-
id: string;
|
|
15
|
-
ok: true;
|
|
16
|
-
value: unknown;
|
|
17
|
-
} | {
|
|
18
|
-
id: string;
|
|
19
|
-
ok: false;
|
|
20
|
-
error: RuntimeErrorDetail;
|
|
21
|
-
};
|
|
22
|
-
export interface RunnerLimits {
|
|
23
|
-
timeoutMs: number;
|
|
24
|
-
cpuTimeMs: number;
|
|
25
|
-
memoryMb: number;
|
|
26
|
-
}
|
|
27
|
-
export declare const DEFAULT_RUNNER_LIMITS: RunnerLimits;
|
|
28
|
-
export declare const MAX_HOST_CALLS_PER_LOT = 50;
|
|
29
|
-
export declare const MAX_HOST_CALL_BYTES = 1048576;
|
|
30
|
-
export declare enum RunnerMessageType {
|
|
31
|
-
RUN = "run",
|
|
32
|
-
CALL = "call",
|
|
33
|
-
CALL_RESULT = "callResult",
|
|
34
|
-
RESULT = "result",
|
|
35
|
-
REJECTED = "rejected"
|
|
36
|
-
}
|
|
37
|
-
export interface RunMessage {
|
|
38
|
-
type: RunnerMessageType.RUN;
|
|
39
|
-
lotId: string;
|
|
40
|
-
items: EvaluationItem[];
|
|
41
|
-
context: Record<string, unknown>;
|
|
42
|
-
functions: string[];
|
|
43
|
-
limits: RunnerLimits;
|
|
44
|
-
}
|
|
45
|
-
export interface CallMessage {
|
|
46
|
-
type: RunnerMessageType.CALL;
|
|
47
|
-
callId: string;
|
|
48
|
-
name: string;
|
|
49
|
-
args: unknown[];
|
|
50
|
-
}
|
|
51
|
-
export type CallResultMessage = {
|
|
52
|
-
type: RunnerMessageType.CALL_RESULT;
|
|
53
|
-
callId: string;
|
|
54
|
-
ok: true;
|
|
55
|
-
value: unknown;
|
|
56
|
-
} | {
|
|
57
|
-
type: RunnerMessageType.CALL_RESULT;
|
|
58
|
-
callId: string;
|
|
59
|
-
ok: false;
|
|
60
|
-
error: {
|
|
61
|
-
message: string;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
export interface LotDurations {
|
|
65
|
-
queueMs: number;
|
|
66
|
-
wallMs: number;
|
|
67
|
-
cpuMs: number;
|
|
68
|
-
}
|
|
69
|
-
export interface ResultMessage {
|
|
70
|
-
type: RunnerMessageType.RESULT;
|
|
71
|
-
lotId: string;
|
|
72
|
-
items: EvaluationResult[];
|
|
73
|
-
durations: LotDurations;
|
|
74
|
-
}
|
|
75
|
-
export interface RejectedMessage {
|
|
76
|
-
type: RunnerMessageType.REJECTED;
|
|
77
|
-
lotId: string;
|
|
78
|
-
code: RuntimeErrorCode.RUNNER_SATURATED | RuntimeErrorCode.INVALID_REQUEST;
|
|
79
|
-
message: string;
|
|
80
|
-
}
|
|
81
|
-
export type CallerMessage = RunMessage | CallResultMessage;
|
|
82
|
-
export type RunnerMessage = CallMessage | ResultMessage | RejectedMessage;
|
|
83
|
-
export interface Lot {
|
|
84
|
-
lotId: string;
|
|
85
|
-
items: EvaluationItem[];
|
|
86
|
-
context: Record<string, unknown>;
|
|
87
|
-
limits: RunnerLimits;
|
|
88
|
-
}
|
|
89
|
-
export interface LotResult {
|
|
90
|
-
items: EvaluationResult[];
|
|
91
|
-
durations: LotDurations;
|
|
92
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RunnerMessageType = exports.MAX_HOST_CALL_BYTES = exports.MAX_HOST_CALLS_PER_LOT = exports.DEFAULT_RUNNER_LIMITS = exports.EvaluationKind = exports.RUNNER_PROTOCOL = void 0;
|
|
4
|
-
exports.RUNNER_PROTOCOL = 'abyss-runtime.v1';
|
|
5
|
-
var EvaluationKind;
|
|
6
|
-
(function (EvaluationKind) {
|
|
7
|
-
EvaluationKind["EXPRESSION"] = "EXPRESSION";
|
|
8
|
-
EvaluationKind["TEMPLATE"] = "TEMPLATE";
|
|
9
|
-
EvaluationKind["CODE"] = "CODE";
|
|
10
|
-
})(EvaluationKind || (exports.EvaluationKind = EvaluationKind = {}));
|
|
11
|
-
exports.DEFAULT_RUNNER_LIMITS = {
|
|
12
|
-
timeoutMs: 5_000,
|
|
13
|
-
cpuTimeMs: 10_000,
|
|
14
|
-
memoryMb: 128,
|
|
15
|
-
};
|
|
16
|
-
exports.MAX_HOST_CALLS_PER_LOT = 50;
|
|
17
|
-
exports.MAX_HOST_CALL_BYTES = 1_048_576;
|
|
18
|
-
var RunnerMessageType;
|
|
19
|
-
(function (RunnerMessageType) {
|
|
20
|
-
RunnerMessageType["RUN"] = "run";
|
|
21
|
-
RunnerMessageType["CALL"] = "call";
|
|
22
|
-
RunnerMessageType["CALL_RESULT"] = "callResult";
|
|
23
|
-
RunnerMessageType["RESULT"] = "result";
|
|
24
|
-
RunnerMessageType["REJECTED"] = "rejected";
|
|
25
|
-
})(RunnerMessageType || (exports.RunnerMessageType = RunnerMessageType = {}));
|
|
26
|
-
//# sourceMappingURL=runner-protocol.types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner-protocol.types.js","sourceRoot":"","sources":["../../src/runner-protocol/runner-protocol.types.ts"],"names":[],"mappings":";;;AAGa,QAAA,eAAe,GAAG,kBAAkB,CAAC;AAElD,IAAY,cAOX;AAPD,WAAY,cAAc;IAExB,2CAAyB,CAAA;IAEzB,uCAAqB,CAAA;IAErB,+BAAa,CAAA;AACf,CAAC,EAPW,cAAc,8BAAd,cAAc,QAOzB;AAuBY,QAAA,qBAAqB,GAAiB;IACjD,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,MAAM;IACjB,QAAQ,EAAE,GAAG;CACd,CAAC;AAGW,QAAA,sBAAsB,GAAG,EAAE,CAAC;AAG5B,QAAA,mBAAmB,GAAG,SAAS,CAAC;AAE7C,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,gCAAW,CAAA;IACX,kCAAa,CAAA;IACb,+CAA0B,CAAA;IAC1B,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;AACvB,CAAC,EANW,iBAAiB,iCAAjB,iBAAiB,QAM5B"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Lot, LotResult } from '../runner-protocol/runner-protocol.types';
|
|
2
|
-
export type HostFunctions = Record<string, (...args: unknown[]) => Promise<unknown>>;
|
|
3
|
-
export interface CodeRunnerClientOptions {
|
|
4
|
-
url: string;
|
|
5
|
-
token: string;
|
|
6
|
-
connectTimeoutMs: number;
|
|
7
|
-
lotTimeoutMs: number;
|
|
8
|
-
}
|
|
9
|
-
export declare class CodeRunnerClient {
|
|
10
|
-
private readonly options;
|
|
11
|
-
constructor(options: CodeRunnerClientOptions);
|
|
12
|
-
evaluate(lot: Lot, functions: HostFunctions): Promise<LotResult>;
|
|
13
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CodeRunnerClient = void 0;
|
|
4
|
-
const ws_1 = require("ws");
|
|
5
|
-
const runtime_error_code_enum_1 = require("../errors/runtime-error-code.enum");
|
|
6
|
-
const runner_protocol_types_1 = require("../runner-protocol/runner-protocol.types");
|
|
7
|
-
const code_runner_error_1 = require("./code-runner-error");
|
|
8
|
-
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
9
|
-
const parseRunnerMessage = (raw) => {
|
|
10
|
-
let parsed;
|
|
11
|
-
try {
|
|
12
|
-
parsed = JSON.parse(raw.toString());
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
throw new Error('Code runner sent a message that is not valid JSON');
|
|
16
|
-
}
|
|
17
|
-
if (!isRecord(parsed)) {
|
|
18
|
-
throw new Error('Code runner sent a message that is not an object');
|
|
19
|
-
}
|
|
20
|
-
switch (parsed.type) {
|
|
21
|
-
case runner_protocol_types_1.RunnerMessageType.CALL:
|
|
22
|
-
if (typeof parsed.callId !== 'string' ||
|
|
23
|
-
typeof parsed.name !== 'string' ||
|
|
24
|
-
!Array.isArray(parsed.args)) {
|
|
25
|
-
throw new Error('Code runner sent a malformed "call" message');
|
|
26
|
-
}
|
|
27
|
-
return parsed;
|
|
28
|
-
case runner_protocol_types_1.RunnerMessageType.RESULT:
|
|
29
|
-
if (!Array.isArray(parsed.items) || !isRecord(parsed.durations)) {
|
|
30
|
-
throw new Error('Code runner sent a malformed "result" message');
|
|
31
|
-
}
|
|
32
|
-
return parsed;
|
|
33
|
-
case runner_protocol_types_1.RunnerMessageType.REJECTED:
|
|
34
|
-
if ((parsed.code !== runtime_error_code_enum_1.RuntimeErrorCode.RUNNER_SATURATED &&
|
|
35
|
-
parsed.code !== runtime_error_code_enum_1.RuntimeErrorCode.INVALID_REQUEST) ||
|
|
36
|
-
typeof parsed.message !== 'string') {
|
|
37
|
-
throw new Error('Code runner sent a malformed "rejected" message');
|
|
38
|
-
}
|
|
39
|
-
return parsed;
|
|
40
|
-
default:
|
|
41
|
-
throw new Error('Code runner sent a message of unknown type');
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
45
|
-
class CodeRunnerClient {
|
|
46
|
-
constructor(options) {
|
|
47
|
-
this.options = options;
|
|
48
|
-
}
|
|
49
|
-
evaluate(lot, functions) {
|
|
50
|
-
const { url, token, connectTimeoutMs, lotTimeoutMs } = this.options;
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
let settled = false;
|
|
53
|
-
const ws = new ws_1.WebSocket(url, runner_protocol_types_1.RUNNER_PROTOCOL, {
|
|
54
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
55
|
-
handshakeTimeout: connectTimeoutMs,
|
|
56
|
-
});
|
|
57
|
-
const finish = (outcome) => {
|
|
58
|
-
if (settled) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
settled = true;
|
|
62
|
-
clearTimeout(lotTimer);
|
|
63
|
-
if (ws.readyState === ws_1.WebSocket.OPEN) {
|
|
64
|
-
ws.close();
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
ws.terminate();
|
|
68
|
-
}
|
|
69
|
-
outcome();
|
|
70
|
-
};
|
|
71
|
-
const fail = (code, message) => finish(() => reject(new code_runner_error_1.CodeRunnerError(code, message)));
|
|
72
|
-
const unavailable = (message) => fail(runtime_error_code_enum_1.RuntimeErrorCode.RUNNER_UNAVAILABLE, message);
|
|
73
|
-
const lotTimer = setTimeout(() => unavailable(`Code runner did not answer within ${lotTimeoutMs} ms`), lotTimeoutMs);
|
|
74
|
-
const send = (message) => {
|
|
75
|
-
if (ws.readyState === ws_1.WebSocket.OPEN) {
|
|
76
|
-
ws.send(JSON.stringify(message));
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const serveCall = async (call) => {
|
|
80
|
-
const fn = Object.prototype.hasOwnProperty.call(functions, call.name)
|
|
81
|
-
? functions[call.name]
|
|
82
|
-
: undefined;
|
|
83
|
-
if (!fn) {
|
|
84
|
-
send({
|
|
85
|
-
type: runner_protocol_types_1.RunnerMessageType.CALL_RESULT,
|
|
86
|
-
callId: call.callId,
|
|
87
|
-
ok: false,
|
|
88
|
-
error: { message: `Unknown host function "${call.name}"` },
|
|
89
|
-
});
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
const value = await fn(...call.args);
|
|
94
|
-
send({ type: runner_protocol_types_1.RunnerMessageType.CALL_RESULT, callId: call.callId, ok: true, value });
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
send({
|
|
98
|
-
type: runner_protocol_types_1.RunnerMessageType.CALL_RESULT,
|
|
99
|
-
callId: call.callId,
|
|
100
|
-
ok: false,
|
|
101
|
-
error: { message: errorMessage(error) },
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
ws.on('unexpected-response', (_request, response) => {
|
|
106
|
-
const status = response.statusCode;
|
|
107
|
-
unavailable(status === 401
|
|
108
|
-
? 'Code runner refused the token (401 Unauthorized)'
|
|
109
|
-
: `Code runner refused the connection (HTTP ${status})`);
|
|
110
|
-
});
|
|
111
|
-
ws.on('error', (error) => unavailable(`Code runner unreachable: ${error.message}`));
|
|
112
|
-
ws.on('close', () => unavailable('Code runner connection closed before the result'));
|
|
113
|
-
ws.on('open', () => {
|
|
114
|
-
send({
|
|
115
|
-
type: runner_protocol_types_1.RunnerMessageType.RUN,
|
|
116
|
-
lotId: lot.lotId,
|
|
117
|
-
items: lot.items,
|
|
118
|
-
context: lot.context,
|
|
119
|
-
functions: Object.keys(functions),
|
|
120
|
-
limits: lot.limits,
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
ws.on('message', (raw) => {
|
|
124
|
-
if (settled) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
let message;
|
|
128
|
-
try {
|
|
129
|
-
message = parseRunnerMessage(raw);
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
unavailable(errorMessage(error));
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
switch (message.type) {
|
|
136
|
-
case runner_protocol_types_1.RunnerMessageType.CALL:
|
|
137
|
-
void serveCall(message);
|
|
138
|
-
break;
|
|
139
|
-
case runner_protocol_types_1.RunnerMessageType.RESULT:
|
|
140
|
-
if (message.lotId !== lot.lotId) {
|
|
141
|
-
unavailable(`Code runner answered lot "${message.lotId}" instead of lot "${lot.lotId}"`);
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
finish(() => resolve({ items: message.items, durations: message.durations }));
|
|
145
|
-
break;
|
|
146
|
-
case runner_protocol_types_1.RunnerMessageType.REJECTED:
|
|
147
|
-
fail(message.code, message.message);
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.CodeRunnerClient = CodeRunnerClient;
|
|
155
|
-
//# sourceMappingURL=code-runner-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code-runner-client.js","sourceRoot":"","sources":["../../src/server/code-runner-client.ts"],"names":[],"mappings":";;;AAAA,2BAA+B;AAE/B,+EAAqE;AACrE,oFAA8F;AAW9F,2DAAsD;AAetD,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,MAAM,kBAAkB,GAAG,CAAC,GAAY,EAAiB,EAAE;IACzD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,yCAAiB,CAAC,IAAI;YACzB,IACE,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;gBACjC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;gBAC/B,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAC3B,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,MAAgC,CAAC;QAC1C,KAAK,yCAAiB,CAAC,MAAM;YAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,M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KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;wBAC9E,MAAM;oBACR,KAAK,yCAAiB,CAAC,QAAQ;wBAC7B,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;wBACpC,MAAM;gBACV,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7HD,4CA6HC"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { RuntimeErrorCode, RuntimeErrorDetail } from '../errors/runtime-error-code.enum';
|
|
2
|
-
|
|
3
|
-
/** WebSocket sub-protocol; a new version is a new name, never a silent change. */
|
|
4
|
-
export const RUNNER_PROTOCOL = 'abyss-runtime.v1';
|
|
5
|
-
|
|
6
|
-
export enum EvaluationKind {
|
|
7
|
-
/** A full JavaScript expression. */
|
|
8
|
-
EXPRESSION = 'EXPRESSION',
|
|
9
|
-
/** A string with `{{ … }}` placeholders; a lone placeholder keeps its value's type. */
|
|
10
|
-
TEMPLATE = 'TEMPLATE',
|
|
11
|
-
/** JavaScript statements; the value of their `return` is the result. */
|
|
12
|
-
CODE = 'CODE',
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface EvaluationItem {
|
|
16
|
-
/** Unique within the lot. */
|
|
17
|
-
id: string;
|
|
18
|
-
kind: EvaluationKind;
|
|
19
|
-
source: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type EvaluationResult =
|
|
23
|
-
| { id: string; ok: true; value: unknown }
|
|
24
|
-
| { id: string; ok: false; error: RuntimeErrorDetail };
|
|
25
|
-
|
|
26
|
-
export interface RunnerLimits {
|
|
27
|
-
/** Wall-clock limit per item. */
|
|
28
|
-
timeoutMs: number;
|
|
29
|
-
/** CPU time limit per item. */
|
|
30
|
-
cpuTimeMs: number;
|
|
31
|
-
/** Heap limit of the lot's isolate. */
|
|
32
|
-
memoryMb: number;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** The limits AbyssFlow applies today (abyss-console workflow.constants.ts). */
|
|
36
|
-
export const DEFAULT_RUNNER_LIMITS: RunnerLimits = {
|
|
37
|
-
timeoutMs: 5_000,
|
|
38
|
-
cpuTimeMs: 10_000,
|
|
39
|
-
memoryMb: 128,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/** Upper bound on `fn.*` calls during one lot. */
|
|
43
|
-
export const MAX_HOST_CALLS_PER_LOT = 50;
|
|
44
|
-
|
|
45
|
-
/** Upper bound, in JSON bytes, on the arguments of one `fn.*` call and on the value of its result. */
|
|
46
|
-
export const MAX_HOST_CALL_BYTES = 1_048_576;
|
|
47
|
-
|
|
48
|
-
export enum RunnerMessageType {
|
|
49
|
-
RUN = 'run',
|
|
50
|
-
CALL = 'call',
|
|
51
|
-
CALL_RESULT = 'callResult',
|
|
52
|
-
RESULT = 'result',
|
|
53
|
-
REJECTED = 'rejected',
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Caller → runner: the lot to evaluate. One lot per connection. */
|
|
57
|
-
export interface RunMessage {
|
|
58
|
-
type: RunnerMessageType.RUN;
|
|
59
|
-
lotId: string;
|
|
60
|
-
items: EvaluationItem[];
|
|
61
|
-
/** JSON data exposed to every item; copied once per lot. */
|
|
62
|
-
context: Record<string, unknown>;
|
|
63
|
-
/** Names the caller can serve; exposed in the isolate as `fn.<name>(...args)`. */
|
|
64
|
-
functions: string[];
|
|
65
|
-
limits: RunnerLimits;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Runner → caller: an item awaits `fn.<name>(...args)`. */
|
|
69
|
-
export interface CallMessage {
|
|
70
|
-
type: RunnerMessageType.CALL;
|
|
71
|
-
callId: string;
|
|
72
|
-
name: string;
|
|
73
|
-
args: unknown[];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Caller → runner: the answer to one `call`. */
|
|
77
|
-
export type CallResultMessage =
|
|
78
|
-
| { type: RunnerMessageType.CALL_RESULT; callId: string; ok: true; value: unknown }
|
|
79
|
-
| { type: RunnerMessageType.CALL_RESULT; callId: string; ok: false; error: { message: string } };
|
|
80
|
-
|
|
81
|
-
export interface LotDurations {
|
|
82
|
-
queueMs: number;
|
|
83
|
-
wallMs: number;
|
|
84
|
-
cpuMs: number;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Runner → caller: one result per item, in the order of the items. Closes the lot. */
|
|
88
|
-
export interface ResultMessage {
|
|
89
|
-
type: RunnerMessageType.RESULT;
|
|
90
|
-
lotId: string;
|
|
91
|
-
items: EvaluationResult[];
|
|
92
|
-
durations: LotDurations;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** Runner → caller: the lot was not run at all. */
|
|
96
|
-
export interface RejectedMessage {
|
|
97
|
-
type: RunnerMessageType.REJECTED;
|
|
98
|
-
lotId: string;
|
|
99
|
-
code: RuntimeErrorCode.RUNNER_SATURATED | RuntimeErrorCode.INVALID_REQUEST;
|
|
100
|
-
message: string;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export type CallerMessage = RunMessage | CallResultMessage;
|
|
104
|
-
export type RunnerMessage = CallMessage | ResultMessage | RejectedMessage;
|
|
105
|
-
|
|
106
|
-
/** What a caller hands over; the client turns it into a `RunMessage`. */
|
|
107
|
-
export interface Lot {
|
|
108
|
-
lotId: string;
|
|
109
|
-
items: EvaluationItem[];
|
|
110
|
-
context: Record<string, unknown>;
|
|
111
|
-
limits: RunnerLimits;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface LotResult {
|
|
115
|
-
items: EvaluationResult[];
|
|
116
|
-
durations: LotDurations;
|
|
117
|
-
}
|