@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
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { RuntimeErrorCode } from '../errors/runtime-error-code.enum';
|
|
2
|
+
import type { RuntimeDefinition } from '../definition/definition.types';
|
|
3
|
+
import type { RunState } from '../interpreter/interpreter.types';
|
|
4
|
+
export declare const EXECUTION_PROTOCOL = "abyss-runtime.v2";
|
|
5
|
+
export declare const MAX_CALL_PAYLOAD_BYTES = 1048576;
|
|
6
|
+
export declare const MAX_PROGRESS_OUTPUT_CHARS = 4096;
|
|
7
|
+
export declare enum CoreCapability {
|
|
8
|
+
HTTP_FETCH = "http.fetch",
|
|
9
|
+
WAIT = "wait",
|
|
10
|
+
LOG_WRITE = "log.write",
|
|
11
|
+
HTTP_RESPOND = "http.respond"
|
|
12
|
+
}
|
|
13
|
+
export declare enum ExecutionMessageType {
|
|
14
|
+
EXECUTE = "execute",
|
|
15
|
+
CALL = "call",
|
|
16
|
+
CALL_RESULT = "callResult",
|
|
17
|
+
PROGRESS = "progress",
|
|
18
|
+
FINISHED = "finished",
|
|
19
|
+
REJECTED = "rejected"
|
|
20
|
+
}
|
|
21
|
+
export type JSONValue = string | number | boolean | null | JSONValue[] | {
|
|
22
|
+
[key: string]: JSONValue;
|
|
23
|
+
};
|
|
24
|
+
export declare const RESERVED_GLOBAL_NAMES: readonly string[];
|
|
25
|
+
export interface ExecutionLimits {
|
|
26
|
+
memoryMb: number;
|
|
27
|
+
cpuTimeMs: number;
|
|
28
|
+
wallTimeMs: number;
|
|
29
|
+
guaranteedCpu: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface ExecutionBudget {
|
|
32
|
+
maxSteps: number;
|
|
33
|
+
maxEffects: number;
|
|
34
|
+
}
|
|
35
|
+
export interface ExecuteMessage {
|
|
36
|
+
type: ExecutionMessageType.EXECUTE;
|
|
37
|
+
executionId: string;
|
|
38
|
+
definition: RuntimeDefinition;
|
|
39
|
+
input: unknown;
|
|
40
|
+
state?: RunState;
|
|
41
|
+
resumeInput?: unknown;
|
|
42
|
+
capabilities: string[];
|
|
43
|
+
limits: ExecutionLimits;
|
|
44
|
+
budget: ExecutionBudget;
|
|
45
|
+
suspendWaitAboveMs?: number;
|
|
46
|
+
globals?: Record<string, JSONValue>;
|
|
47
|
+
}
|
|
48
|
+
export interface ExecutionCallMessage {
|
|
49
|
+
type: ExecutionMessageType.CALL;
|
|
50
|
+
callId: string;
|
|
51
|
+
stepId: string;
|
|
52
|
+
capability: string;
|
|
53
|
+
args: unknown;
|
|
54
|
+
}
|
|
55
|
+
export interface CallError {
|
|
56
|
+
code?: RuntimeErrorCode;
|
|
57
|
+
message: string;
|
|
58
|
+
}
|
|
59
|
+
export type ExecutionCallResultMessage = {
|
|
60
|
+
type: ExecutionMessageType.CALL_RESULT;
|
|
61
|
+
callId: string;
|
|
62
|
+
ok: true;
|
|
63
|
+
value: unknown;
|
|
64
|
+
} | {
|
|
65
|
+
type: ExecutionMessageType.CALL_RESULT;
|
|
66
|
+
callId: string;
|
|
67
|
+
ok: true;
|
|
68
|
+
suspend: true;
|
|
69
|
+
} | {
|
|
70
|
+
type: ExecutionMessageType.CALL_RESULT;
|
|
71
|
+
callId: string;
|
|
72
|
+
ok: false;
|
|
73
|
+
error: CallError;
|
|
74
|
+
};
|
|
75
|
+
export interface StepMetrics {
|
|
76
|
+
cpuMs: number;
|
|
77
|
+
heapPeakBytes: number;
|
|
78
|
+
wallMs: number;
|
|
79
|
+
}
|
|
80
|
+
export interface ExecutionMetrics {
|
|
81
|
+
queueMs: number;
|
|
82
|
+
wallMs: number;
|
|
83
|
+
cpuMs: number;
|
|
84
|
+
heapPeakBytes: number;
|
|
85
|
+
memoryLimitBytes: number;
|
|
86
|
+
}
|
|
87
|
+
export declare enum StepPhase {
|
|
88
|
+
STARTED = "started",
|
|
89
|
+
FINISHED = "finished"
|
|
90
|
+
}
|
|
91
|
+
export declare enum StepStatus {
|
|
92
|
+
SUCCEEDED = "SUCCEEDED",
|
|
93
|
+
FAILED = "FAILED",
|
|
94
|
+
SUSPENDED = "SUSPENDED"
|
|
95
|
+
}
|
|
96
|
+
export interface ProgressMessage {
|
|
97
|
+
type: ExecutionMessageType.PROGRESS;
|
|
98
|
+
stepId: string;
|
|
99
|
+
phase: StepPhase;
|
|
100
|
+
status?: StepStatus;
|
|
101
|
+
durationMs?: number;
|
|
102
|
+
metrics?: StepMetrics;
|
|
103
|
+
output?: unknown;
|
|
104
|
+
outputTruncated?: boolean;
|
|
105
|
+
errorCode?: RuntimeErrorCode;
|
|
106
|
+
}
|
|
107
|
+
export declare enum ExecutionStatus {
|
|
108
|
+
SUCCEEDED = "SUCCEEDED",
|
|
109
|
+
FAILED = "FAILED",
|
|
110
|
+
SUSPENDED = "SUSPENDED"
|
|
111
|
+
}
|
|
112
|
+
export interface ExecutionOutcome {
|
|
113
|
+
status: ExecutionStatus;
|
|
114
|
+
output?: unknown;
|
|
115
|
+
errorCode?: RuntimeErrorCode;
|
|
116
|
+
errorMessage?: string;
|
|
117
|
+
stepId?: string;
|
|
118
|
+
state?: RunState;
|
|
119
|
+
}
|
|
120
|
+
export interface FinishedMessage {
|
|
121
|
+
type: ExecutionMessageType.FINISHED;
|
|
122
|
+
outcome: ExecutionOutcome;
|
|
123
|
+
metrics: ExecutionMetrics;
|
|
124
|
+
}
|
|
125
|
+
export type ExecutionRejectionCode = RuntimeErrorCode.RUNNER_SATURATED | RuntimeErrorCode.INVALID_REQUEST | RuntimeErrorCode.STATE_VERSION_UNSUPPORTED;
|
|
126
|
+
export interface ExecutionRejectedMessage {
|
|
127
|
+
type: ExecutionMessageType.REJECTED;
|
|
128
|
+
code: ExecutionRejectionCode;
|
|
129
|
+
message: string;
|
|
130
|
+
}
|
|
131
|
+
export type ExecutionHostMessage = ExecuteMessage | ExecutionCallResultMessage;
|
|
132
|
+
export type ExecutionRunnerMessage = ExecutionCallMessage | ProgressMessage | FinishedMessage | ExecutionRejectedMessage;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionStatus = exports.StepStatus = exports.StepPhase = exports.RESERVED_GLOBAL_NAMES = exports.ExecutionMessageType = exports.CoreCapability = exports.MAX_PROGRESS_OUTPUT_CHARS = exports.MAX_CALL_PAYLOAD_BYTES = exports.EXECUTION_PROTOCOL = void 0;
|
|
4
|
+
exports.EXECUTION_PROTOCOL = 'abyss-runtime.v2';
|
|
5
|
+
exports.MAX_CALL_PAYLOAD_BYTES = 1_048_576;
|
|
6
|
+
exports.MAX_PROGRESS_OUTPUT_CHARS = 4_096;
|
|
7
|
+
var CoreCapability;
|
|
8
|
+
(function (CoreCapability) {
|
|
9
|
+
CoreCapability["HTTP_FETCH"] = "http.fetch";
|
|
10
|
+
CoreCapability["WAIT"] = "wait";
|
|
11
|
+
CoreCapability["LOG_WRITE"] = "log.write";
|
|
12
|
+
CoreCapability["HTTP_RESPOND"] = "http.respond";
|
|
13
|
+
})(CoreCapability || (exports.CoreCapability = CoreCapability = {}));
|
|
14
|
+
var ExecutionMessageType;
|
|
15
|
+
(function (ExecutionMessageType) {
|
|
16
|
+
ExecutionMessageType["EXECUTE"] = "execute";
|
|
17
|
+
ExecutionMessageType["CALL"] = "call";
|
|
18
|
+
ExecutionMessageType["CALL_RESULT"] = "callResult";
|
|
19
|
+
ExecutionMessageType["PROGRESS"] = "progress";
|
|
20
|
+
ExecutionMessageType["FINISHED"] = "finished";
|
|
21
|
+
ExecutionMessageType["REJECTED"] = "rejected";
|
|
22
|
+
})(ExecutionMessageType || (exports.ExecutionMessageType = ExecutionMessageType = {}));
|
|
23
|
+
exports.RESERVED_GLOBAL_NAMES = [
|
|
24
|
+
'input',
|
|
25
|
+
'steps',
|
|
26
|
+
'vars',
|
|
27
|
+
'fetch',
|
|
28
|
+
'abyss',
|
|
29
|
+
'console',
|
|
30
|
+
];
|
|
31
|
+
var StepPhase;
|
|
32
|
+
(function (StepPhase) {
|
|
33
|
+
StepPhase["STARTED"] = "started";
|
|
34
|
+
StepPhase["FINISHED"] = "finished";
|
|
35
|
+
})(StepPhase || (exports.StepPhase = StepPhase = {}));
|
|
36
|
+
var StepStatus;
|
|
37
|
+
(function (StepStatus) {
|
|
38
|
+
StepStatus["SUCCEEDED"] = "SUCCEEDED";
|
|
39
|
+
StepStatus["FAILED"] = "FAILED";
|
|
40
|
+
StepStatus["SUSPENDED"] = "SUSPENDED";
|
|
41
|
+
})(StepStatus || (exports.StepStatus = StepStatus = {}));
|
|
42
|
+
var ExecutionStatus;
|
|
43
|
+
(function (ExecutionStatus) {
|
|
44
|
+
ExecutionStatus["SUCCEEDED"] = "SUCCEEDED";
|
|
45
|
+
ExecutionStatus["FAILED"] = "FAILED";
|
|
46
|
+
ExecutionStatus["SUSPENDED"] = "SUSPENDED";
|
|
47
|
+
})(ExecutionStatus || (exports.ExecutionStatus = ExecutionStatus = {}));
|
|
48
|
+
//# sourceMappingURL=execution-protocol.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-protocol.types.js","sourceRoot":"","sources":["../../src/runner-protocol/execution-protocol.types.ts"],"names":[],"mappings":";;;AAQa,QAAA,kBAAkB,GAAG,kBAAkB,CAAC;AAGxC,QAAA,sBAAsB,GAAG,SAAS,CAAC;AAGnC,QAAA,yBAAyB,GAAG,KAAK,CAAC;AAM/C,IAAY,cASX;AATD,WAAY,cAAc;IAExB,2CAAyB,CAAA;IAEzB,+BAAa,CAAA;IAEb,yCAAuB,CAAA;IAEvB,+CAA6B,CAAA;AAC/B,CAAC,EATW,cAAc,8BAAd,cAAc,QASzB;AAED,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC9B,2CAAmB,CAAA;IACnB,qCAAa,CAAA;IACb,kDAA0B,CAAA;IAC1B,6CAAqB,CAAA;IACrB,6CAAqB,CAAA;IACrB,6CAAqB,CAAA;AACvB,CAAC,EAPW,oBAAoB,oCAApB,oBAAoB,QAO/B;AAcY,QAAA,qBAAqB,GAAsB;IACtD,OAAO;IACP,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,SAAS;CACV,CAAC;AAqFF,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,gCAAmB,CAAA;IACnB,kCAAqB,CAAA;AACvB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAED,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,qCAAuB,CAAA;IACvB,+BAAiB,CAAA;IAEjB,qCAAuB,CAAA;AACzB,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAuBD,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,oCAAiB,CAAA;IACjB,0CAAuB,CAAA;AACzB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RuntimeErrorCode } from '../errors/runtime-error-code.enum';
|
|
2
|
+
import type { ExecuteMessage, FinishedMessage, ProgressMessage } from '../runner-protocol/execution-protocol.types';
|
|
3
|
+
export interface CodeRunnerSessionOptions {
|
|
4
|
+
url: string;
|
|
5
|
+
token: string;
|
|
6
|
+
connectTimeoutMs: number;
|
|
7
|
+
wallTimeGraceMs: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CapabilityContext {
|
|
10
|
+
stepId: string;
|
|
11
|
+
}
|
|
12
|
+
export type CapabilityHandlers = Record<string, (args: unknown, context: CapabilityContext) => Promise<unknown>>;
|
|
13
|
+
export declare const SUSPEND_EXECUTION: unique symbol;
|
|
14
|
+
export declare class CapabilityError extends Error {
|
|
15
|
+
readonly code: RuntimeErrorCode;
|
|
16
|
+
constructor(code: RuntimeErrorCode, message: string);
|
|
17
|
+
}
|
|
18
|
+
export type ExecutionRequest = Omit<ExecuteMessage, 'type' | 'capabilities'>;
|
|
19
|
+
export interface ExecuteOptions {
|
|
20
|
+
onProgress?: (progress: Omit<ProgressMessage, 'type'>) => void;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export type ExecutionResult = Omit<FinishedMessage, 'type'>;
|
|
24
|
+
export declare class CodeRunnerSession {
|
|
25
|
+
private readonly options;
|
|
26
|
+
constructor(options: CodeRunnerSessionOptions);
|
|
27
|
+
execute(request: ExecutionRequest, handlers: CapabilityHandlers, executeOptions?: ExecuteOptions): Promise<ExecutionResult>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeRunnerSession = exports.CapabilityError = exports.SUSPEND_EXECUTION = void 0;
|
|
4
|
+
const ws_1 = require("ws");
|
|
5
|
+
const runtime_error_code_enum_1 = require("../errors/runtime-error-code.enum");
|
|
6
|
+
const execution_protocol_types_1 = require("../runner-protocol/execution-protocol.types");
|
|
7
|
+
const code_runner_error_1 = require("./code-runner-error");
|
|
8
|
+
exports.SUSPEND_EXECUTION = Symbol('abyss-runtime.suspend-execution');
|
|
9
|
+
class CapabilityError extends Error {
|
|
10
|
+
constructor(code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'CapabilityError';
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.CapabilityError = CapabilityError;
|
|
17
|
+
const REJECTION_CODES = new Set([
|
|
18
|
+
runtime_error_code_enum_1.RuntimeErrorCode.RUNNER_SATURATED,
|
|
19
|
+
runtime_error_code_enum_1.RuntimeErrorCode.INVALID_REQUEST,
|
|
20
|
+
runtime_error_code_enum_1.RuntimeErrorCode.STATE_VERSION_UNSUPPORTED,
|
|
21
|
+
]);
|
|
22
|
+
const EXECUTION_STATUSES = new Set(Object.values(execution_protocol_types_1.ExecutionStatus));
|
|
23
|
+
const STEP_PHASES = new Set(Object.values(execution_protocol_types_1.StepPhase));
|
|
24
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
25
|
+
const malformed = (type) => new Error(`Code runner sent a malformed "${type}" message`);
|
|
26
|
+
const parseRunnerMessage = (raw) => {
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = JSON.parse(raw.toString());
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new Error('Code runner sent a message that is not valid JSON');
|
|
33
|
+
}
|
|
34
|
+
if (!isRecord(parsed)) {
|
|
35
|
+
throw new Error('Code runner sent a message that is not an object');
|
|
36
|
+
}
|
|
37
|
+
switch (parsed.type) {
|
|
38
|
+
case execution_protocol_types_1.ExecutionMessageType.CALL:
|
|
39
|
+
if (typeof parsed.callId !== 'string' ||
|
|
40
|
+
typeof parsed.stepId !== 'string' ||
|
|
41
|
+
typeof parsed.capability !== 'string') {
|
|
42
|
+
throw malformed(parsed.type);
|
|
43
|
+
}
|
|
44
|
+
return parsed;
|
|
45
|
+
case execution_protocol_types_1.ExecutionMessageType.PROGRESS:
|
|
46
|
+
if (typeof parsed.stepId !== 'string' || !STEP_PHASES.has(parsed.phase)) {
|
|
47
|
+
throw malformed(parsed.type);
|
|
48
|
+
}
|
|
49
|
+
return parsed;
|
|
50
|
+
case execution_protocol_types_1.ExecutionMessageType.FINISHED:
|
|
51
|
+
if (!isRecord(parsed.outcome) ||
|
|
52
|
+
!EXECUTION_STATUSES.has(parsed.outcome.status) ||
|
|
53
|
+
!isRecord(parsed.metrics)) {
|
|
54
|
+
throw malformed(parsed.type);
|
|
55
|
+
}
|
|
56
|
+
return parsed;
|
|
57
|
+
case execution_protocol_types_1.ExecutionMessageType.REJECTED:
|
|
58
|
+
if (!REJECTION_CODES.has(parsed.code) || typeof parsed.message !== 'string') {
|
|
59
|
+
throw malformed(parsed.type);
|
|
60
|
+
}
|
|
61
|
+
return parsed;
|
|
62
|
+
default:
|
|
63
|
+
throw new Error('Code runner sent a message of unknown type');
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
67
|
+
const callErrorOf = (error) => error instanceof CapabilityError
|
|
68
|
+
? { code: error.code, message: error.message }
|
|
69
|
+
: { message: errorMessage(error) };
|
|
70
|
+
const abortReason = (signal) => signal.reason ?? new Error('The execution was aborted');
|
|
71
|
+
class CodeRunnerSession {
|
|
72
|
+
constructor(options) {
|
|
73
|
+
this.options = options;
|
|
74
|
+
}
|
|
75
|
+
execute(request, handlers, executeOptions = {}) {
|
|
76
|
+
const { url, token, connectTimeoutMs, wallTimeGraceMs } = this.options;
|
|
77
|
+
const { onProgress, signal } = executeOptions;
|
|
78
|
+
if (signal?.aborted) {
|
|
79
|
+
return Promise.reject(abortReason(signal));
|
|
80
|
+
}
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
let settled = false;
|
|
83
|
+
let wallTimer;
|
|
84
|
+
const ws = new ws_1.WebSocket(url, execution_protocol_types_1.EXECUTION_PROTOCOL, {
|
|
85
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
86
|
+
handshakeTimeout: connectTimeoutMs,
|
|
87
|
+
});
|
|
88
|
+
const onAbort = () => finish(() => reject(abortReason(signal)));
|
|
89
|
+
function finish(outcome) {
|
|
90
|
+
if (settled) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
settled = true;
|
|
94
|
+
clearTimeout(connectTimer);
|
|
95
|
+
clearTimeout(wallTimer);
|
|
96
|
+
signal?.removeEventListener('abort', onAbort);
|
|
97
|
+
if (ws.readyState === ws_1.WebSocket.OPEN) {
|
|
98
|
+
ws.close();
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
ws.terminate();
|
|
102
|
+
}
|
|
103
|
+
outcome();
|
|
104
|
+
}
|
|
105
|
+
const fail = (code, message) => finish(() => reject(new code_runner_error_1.CodeRunnerError(code, message)));
|
|
106
|
+
const unavailable = (message) => fail(runtime_error_code_enum_1.RuntimeErrorCode.RUNNER_UNAVAILABLE, message);
|
|
107
|
+
const connectTimer = setTimeout(() => unavailable(`Code runner did not accept the connection within ${connectTimeoutMs} ms`), connectTimeoutMs);
|
|
108
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
109
|
+
const send = (message) => {
|
|
110
|
+
if (!settled && ws.readyState === ws_1.WebSocket.OPEN) {
|
|
111
|
+
ws.send(JSON.stringify(message));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const serveCall = async (call) => {
|
|
115
|
+
const handler = Object.prototype.hasOwnProperty.call(handlers, call.capability)
|
|
116
|
+
? handlers[call.capability]
|
|
117
|
+
: undefined;
|
|
118
|
+
if (!handler) {
|
|
119
|
+
send({
|
|
120
|
+
type: execution_protocol_types_1.ExecutionMessageType.CALL_RESULT,
|
|
121
|
+
callId: call.callId,
|
|
122
|
+
ok: false,
|
|
123
|
+
error: {
|
|
124
|
+
code: runtime_error_code_enum_1.RuntimeErrorCode.ACCESS_DENIED,
|
|
125
|
+
message: `Capability "${call.capability}" is not granted to the execution`,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const value = await handler(call.args, { stepId: call.stepId });
|
|
132
|
+
send(value === exports.SUSPEND_EXECUTION
|
|
133
|
+
? {
|
|
134
|
+
type: execution_protocol_types_1.ExecutionMessageType.CALL_RESULT,
|
|
135
|
+
callId: call.callId,
|
|
136
|
+
ok: true,
|
|
137
|
+
suspend: true,
|
|
138
|
+
}
|
|
139
|
+
: { type: execution_protocol_types_1.ExecutionMessageType.CALL_RESULT, callId: call.callId, ok: true, value });
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
send({
|
|
143
|
+
type: execution_protocol_types_1.ExecutionMessageType.CALL_RESULT,
|
|
144
|
+
callId: call.callId,
|
|
145
|
+
ok: false,
|
|
146
|
+
error: callErrorOf(error),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
ws.on('unexpected-response', (_request, response) => {
|
|
151
|
+
const status = response.statusCode;
|
|
152
|
+
unavailable(status === 401
|
|
153
|
+
? 'Code runner refused the token (401 Unauthorized)'
|
|
154
|
+
: `Code runner refused the connection (HTTP ${status})`);
|
|
155
|
+
});
|
|
156
|
+
ws.on('error', (error) => unavailable(`Code runner unreachable: ${error.message}`));
|
|
157
|
+
ws.on('close', () => unavailable('Code runner connection closed before the end'));
|
|
158
|
+
ws.on('open', () => {
|
|
159
|
+
clearTimeout(connectTimer);
|
|
160
|
+
const wallLimitMs = request.limits.wallTimeMs + wallTimeGraceMs;
|
|
161
|
+
wallTimer = setTimeout(() => fail(runtime_error_code_enum_1.RuntimeErrorCode.TIMEOUT, `Execution did not finish within ${wallLimitMs} ms`), wallLimitMs);
|
|
162
|
+
send({
|
|
163
|
+
...request,
|
|
164
|
+
type: execution_protocol_types_1.ExecutionMessageType.EXECUTE,
|
|
165
|
+
capabilities: Object.keys(handlers),
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
ws.on('message', (raw) => {
|
|
169
|
+
if (settled) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
let message;
|
|
173
|
+
try {
|
|
174
|
+
message = parseRunnerMessage(raw);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
unavailable(errorMessage(error));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
switch (message.type) {
|
|
181
|
+
case execution_protocol_types_1.ExecutionMessageType.CALL:
|
|
182
|
+
void serveCall(message);
|
|
183
|
+
break;
|
|
184
|
+
case execution_protocol_types_1.ExecutionMessageType.PROGRESS: {
|
|
185
|
+
if (!onProgress) {
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
onProgress(message);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
finish(() => reject(error));
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case execution_protocol_types_1.ExecutionMessageType.FINISHED:
|
|
197
|
+
finish(() => resolve({ outcome: message.outcome, metrics: message.metrics }));
|
|
198
|
+
break;
|
|
199
|
+
case execution_protocol_types_1.ExecutionMessageType.REJECTED:
|
|
200
|
+
fail(message.code, message.message);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.CodeRunnerSession = CodeRunnerSession;
|
|
208
|
+
//# sourceMappingURL=code-runner-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-runner-session.js","sourceRoot":"","sources":["../../src/server/code-runner-session.ts"],"names":[],"mappings":";;;AAAA,2BAA+B;AAE/B,+EAAqE;AACrE,0FAKqD;AAWrD,2DAAsD;AAiCzC,QAAA,iBAAiB,GAAkB,MAAM,CAAC,iCAAiC,CAAC,CAAC;AAG1F,MAAa,eAAgB,SAAQ,KAAK;IAGxC,YAAY,IAAsB,EAAE,OAAe;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IA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,OAAO,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;oBACjC,OAAO;gBACT,CAAC;gBACD,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;oBACrB,KAAK,+CAAoB,CAAC,IAAI;wBAC5B,KAAK,SAAS,CAAC,OAAO,CAAC,CAAC;wBACxB,MAAM;oBACR,KAAK,+CAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACnC,IAAI,CAAC,UAAU,EAAE,CAAC;4BAChB,MAAM;wBACR,CAAC;wBACD,IAAI,CAAC;4BACH,UAAU,CAAC,OAAO,CAAC,CAAC;wBACtB,CAAC;wBAAC,OAAO,KAAK,EAAE,CAAC;4BACf,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;wBAC9B,CAAC;wBACD,MAAM;oBACR,CAAC;oBACD,KAAK,+CAAoB,CAAC,QAAQ;wBAChC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;wBAC9E,MAAM;oBACR,KAAK,+CAAoB,CAAC,QAAQ;wBAChC,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;AAhKD,8CAgKC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { CodeRunnerClient } from './code-runner-client';
|
|
2
|
-
export type { CodeRunnerClientOptions, HostFunctions } from './code-runner-client';
|
|
3
1
|
export { CodeRunnerError } from './code-runner-error';
|
|
2
|
+
export { CapabilityError, CodeRunnerSession, SUSPEND_EXECUTION } from './code-runner-session';
|
|
3
|
+
export type { CapabilityContext, CapabilityHandlers, CodeRunnerSessionOptions, ExecuteOptions, ExecutionRequest, ExecutionResult, } from './code-runner-session';
|
package/dist/server/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var code_runner_client_1 = require("./code-runner-client");
|
|
5
|
-
Object.defineProperty(exports, "CodeRunnerClient", { enumerable: true, get: function () { return code_runner_client_1.CodeRunnerClient; } });
|
|
3
|
+
exports.SUSPEND_EXECUTION = exports.CodeRunnerSession = exports.CapabilityError = exports.CodeRunnerError = void 0;
|
|
6
4
|
var code_runner_error_1 = require("./code-runner-error");
|
|
7
5
|
Object.defineProperty(exports, "CodeRunnerError", { enumerable: true, get: function () { return code_runner_error_1.CodeRunnerError; } });
|
|
6
|
+
var code_runner_session_1 = require("./code-runner-session");
|
|
7
|
+
Object.defineProperty(exports, "CapabilityError", { enumerable: true, get: function () { return code_runner_session_1.CapabilityError; } });
|
|
8
|
+
Object.defineProperty(exports, "CodeRunnerSession", { enumerable: true, get: function () { return code_runner_session_1.CodeRunnerSession; } });
|
|
9
|
+
Object.defineProperty(exports, "SUSPEND_EXECUTION", { enumerable: true, get: function () { return code_runner_session_1.SUSPEND_EXECUTION; } });
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";;;AACA,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AACxB,6DAA8F;AAArF,sHAAA,eAAe,OAAA;AAAE,wHAAA,iBAAiB,OAAA;AAAE,wHAAA,iBAAiB,OAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RuntimeErrorDetail } from '../errors/runtime-error-code.enum';
|
|
2
|
-
import type { Step, StopStatus } from '../definition/definition.types';
|
|
3
|
-
import type { HttpRequest } from '../interpreter/interpreter.types';
|
|
2
|
+
import type { LogLevel, Step, StopStatus } from '../definition/definition.types';
|
|
3
|
+
import type { HttpRequest, HttpResponseToSend } from '../interpreter/interpreter.types';
|
|
4
4
|
import type { ResolvedFields } from './step-fields';
|
|
5
5
|
export declare enum StepActionKind {
|
|
6
6
|
DONE = "DONE",
|
|
@@ -8,6 +8,8 @@ export declare enum StepActionKind {
|
|
|
8
8
|
WAIT = "WAIT",
|
|
9
9
|
HTTP = "HTTP",
|
|
10
10
|
HOST = "HOST",
|
|
11
|
+
LOG = "LOG",
|
|
12
|
+
RESPOND = "RESPOND",
|
|
11
13
|
FAIL = "FAIL"
|
|
12
14
|
}
|
|
13
15
|
export type StepAction = {
|
|
@@ -33,6 +35,14 @@ export type StepAction = {
|
|
|
33
35
|
kind: StepActionKind.HOST;
|
|
34
36
|
action: string;
|
|
35
37
|
input: Record<string, unknown>;
|
|
38
|
+
} | {
|
|
39
|
+
kind: StepActionKind.LOG;
|
|
40
|
+
level: LogLevel;
|
|
41
|
+
message: string;
|
|
42
|
+
data?: unknown;
|
|
43
|
+
} | {
|
|
44
|
+
kind: StepActionKind.RESPOND;
|
|
45
|
+
response: HttpResponseToSend;
|
|
36
46
|
} | {
|
|
37
47
|
kind: StepActionKind.FAIL;
|
|
38
48
|
error: RuntimeErrorDetail;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeStep = exports.StepActionKind = void 0;
|
|
4
4
|
const runtime_error_code_enum_1 = require("../errors/runtime-error-code.enum");
|
|
5
|
+
const definition_limits_1 = require("../definition/definition.limits");
|
|
5
6
|
const definition_types_1 = require("../definition/definition.types");
|
|
6
7
|
const value_source_1 = require("./value-source");
|
|
7
8
|
var StepActionKind;
|
|
@@ -11,6 +12,8 @@ var StepActionKind;
|
|
|
11
12
|
StepActionKind["WAIT"] = "WAIT";
|
|
12
13
|
StepActionKind["HTTP"] = "HTTP";
|
|
13
14
|
StepActionKind["HOST"] = "HOST";
|
|
15
|
+
StepActionKind["LOG"] = "LOG";
|
|
16
|
+
StepActionKind["RESPOND"] = "RESPOND";
|
|
14
17
|
StepActionKind["FAIL"] = "FAIL";
|
|
15
18
|
})(StepActionKind || (exports.StepActionKind = StepActionKind = {}));
|
|
16
19
|
const fail = (message) => ({
|
|
@@ -33,6 +36,36 @@ const executeWait = (step, fields) => {
|
|
|
33
36
|
}
|
|
34
37
|
return { kind: StepActionKind.WAIT, until };
|
|
35
38
|
};
|
|
39
|
+
const executeLog = (step, fields) => {
|
|
40
|
+
const message = fields.get('message');
|
|
41
|
+
const action = {
|
|
42
|
+
kind: StepActionKind.LOG,
|
|
43
|
+
level: step.level,
|
|
44
|
+
message: typeof message === 'string' ? message : JSON.stringify(message) ?? '',
|
|
45
|
+
};
|
|
46
|
+
if (step.data !== undefined) {
|
|
47
|
+
action.data = fields.get('data');
|
|
48
|
+
}
|
|
49
|
+
return action;
|
|
50
|
+
};
|
|
51
|
+
const executeRespond = (step, fields) => {
|
|
52
|
+
const status = fields.get('status');
|
|
53
|
+
if (typeof status !== 'number' ||
|
|
54
|
+
!Number.isInteger(status) ||
|
|
55
|
+
status < definition_limits_1.MIN_RESPONSE_STATUS ||
|
|
56
|
+
status > definition_limits_1.MAX_RESPONSE_STATUS) {
|
|
57
|
+
return fail(`Response status must resolve to an integer from ${definition_limits_1.MIN_RESPONSE_STATUS} to ${definition_limits_1.MAX_RESPONSE_STATUS}`);
|
|
58
|
+
}
|
|
59
|
+
const headers = resolvedRecord('headers', Object.keys(step.headers ?? {}), fields);
|
|
60
|
+
const response = {
|
|
61
|
+
status,
|
|
62
|
+
headers: Object.fromEntries(Object.entries(headers).map(([key, value]) => [key, headerValue(value)])),
|
|
63
|
+
};
|
|
64
|
+
if (step.body !== undefined) {
|
|
65
|
+
response.body = fields.get('body');
|
|
66
|
+
}
|
|
67
|
+
return { kind: StepActionKind.RESPOND, response };
|
|
68
|
+
};
|
|
36
69
|
const executeStep = (step, fields) => {
|
|
37
70
|
switch (step.type) {
|
|
38
71
|
case definition_types_1.StepType.CONDITION: {
|
|
@@ -91,6 +124,10 @@ const executeStep = (step, fields) => {
|
|
|
91
124
|
action: step.action,
|
|
92
125
|
input: resolvedRecord('input', Object.keys(step.input), fields),
|
|
93
126
|
};
|
|
127
|
+
case definition_types_1.StepType.LOG:
|
|
128
|
+
return executeLog(step, fields);
|
|
129
|
+
case definition_types_1.StepType.RESPOND:
|
|
130
|
+
return executeRespond(step, fields);
|
|
94
131
|
case definition_types_1.StepType.STOP:
|
|
95
132
|
return { kind: StepActionKind.STOP, status: step.status, output: fields.get('output') };
|
|
96
133
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-step.js","sourceRoot":"","sources":["../../src/steps/execute-step.ts"],"names":[],"mappings":";;;AAAA,+EAAqE;AAErE,qEAA0D;
|
|
1
|
+
{"version":3,"file":"execute-step.js","sourceRoot":"","sources":["../../src/steps/execute-step.ts"],"names":[],"mappings":";;;AAAA,+EAAqE;AAErE,uEAA2F;AAC3F,qEAA0D;AAU1D,iDAA8C;AAG9C,IAAY,cAUX;AAVD,WAAY,cAAc;IAExB,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,6BAAW,CAAA;IACX,qCAAmB,CAAA;IACnB,+BAAa,CAAA;AACf,CAAC,EAVW,cAAc,8BAAd,cAAc,QAUzB;AAkBD,MAAM,IAAI,GAAG,CAAC,OAAe,EAAc,EAAE,CAAC,CAAC;IAC7C,IAAI,EAAE,cAAc,CAAC,IAAI;IACzB,KAAK,EAAE,EAAE,IAAI,EAAE,0CAAgB,CAAC,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AAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC5F,CAAC;AACH,CAAC,CAAC;AArEW,QAAA,WAAW,eAqEtB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectGlobalReferences = void 0;
|
|
4
|
+
const evaluation_types_1 = require("../runner-protocol/evaluation.types");
|
|
5
|
+
const walk_steps_1 = require("../definition/walk-steps");
|
|
6
|
+
const step_fields_1 = require("./step-fields");
|
|
7
|
+
const PLACEHOLDER = /\{\{([\s\S]*?)\}\}/g;
|
|
8
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
9
|
+
const codeOf = (kind, source) => kind === evaluation_types_1.EvaluationKind.TEMPLATE
|
|
10
|
+
? [...source.matchAll(PLACEHOLDER)].map((match) => match[1])
|
|
11
|
+
: [source];
|
|
12
|
+
const collectGlobalReferences = (definition, globalName) => {
|
|
13
|
+
const name = escapeRegExp(globalName);
|
|
14
|
+
const access = new RegExp(`(?<![\\w$.])${name}\\s*(?:\\??\\.\\s*([A-Za-z_$][\\w$]*)|\\[\\s*(['"])([A-Za-z_$][\\w$]*)\\2\\s*\\])`, 'g');
|
|
15
|
+
const found = new Set();
|
|
16
|
+
(0, walk_steps_1.walkSteps)(definition.steps, (step) => {
|
|
17
|
+
for (const item of (0, step_fields_1.collectStepItems)(step)) {
|
|
18
|
+
for (const code of codeOf(item.kind, item.source)) {
|
|
19
|
+
for (const match of code.matchAll(access)) {
|
|
20
|
+
found.add(match[1] ?? match[3]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return [...found];
|
|
26
|
+
};
|
|
27
|
+
exports.collectGlobalReferences = collectGlobalReferences;
|
|
28
|
+
//# sourceMappingURL=global-references.js.map
|
|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AC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;AACpB,CAAC,CAAC;AArBW,QAAA,uBAAuB,2BAqBlC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EvaluationItem } from '../runner-protocol/
|
|
1
|
+
import type { EvaluationItem } from '../runner-protocol/evaluation.types';
|
|
2
2
|
import type { Step } from '../definition/definition.types';
|
|
3
3
|
export type ResolvedFields = ReadonlyMap<string, unknown>;
|
|
4
4
|
export declare const collectStepItems: (step: Step) => EvaluationItem[];
|