@abyss-project/runtime 3.11.0 → 3.13.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/.eslintrc.js +32 -32
- package/dist/definition/definition.schema.js +6 -0
- package/dist/definition/definition.schema.js.map +1 -1
- package/dist/definition/definition.types.d.ts +11 -0
- package/dist/definition/definition.types.js +6 -1
- package/dist/definition/definition.types.js.map +1 -1
- package/dist/engine/engine-source.js +1 -1
- package/dist/errors/runtime-error-code.enum.d.ts +1 -0
- package/dist/errors/runtime-error-code.enum.js +1 -0
- package/dist/errors/runtime-error-code.enum.js.map +1 -1
- package/dist/runner-protocol/evaluation.types.d.ts +1 -0
- package/dist/steps/global-references.js +7 -0
- package/dist/steps/global-references.js.map +1 -1
- package/dist/steps/step-fields.js +10 -0
- package/dist/steps/step-fields.js.map +1 -1
- package/jest.config.ts +11 -11
- package/package.json +1 -1
- package/scripts/build-engine.cjs +70 -70
- package/src/__tests__/engine-bundle.test.ts +121 -121
- package/src/__tests__/surface.test.ts +81 -81
- package/src/access/__tests__/host-match.test.ts +24 -24
- package/src/access/access.types.ts +25 -25
- package/src/access/host-match.ts +13 -13
- package/src/cost/__tests__/execution-cost.test.ts +249 -249
- package/src/cost/execution-cost.ts +203 -203
- package/src/definition/__tests__/code-step.test.ts +56 -0
- package/src/definition/__tests__/validate-definition.test.ts +354 -354
- package/src/definition/definition.limits.ts +9 -9
- package/src/definition/definition.schema.ts +7 -0
- package/src/definition/definition.types.ts +21 -1
- package/src/definition/validate-definition.ts +206 -206
- package/src/definition/walk-steps.ts +44 -44
- package/src/discord/__tests__/discord-event-input.test.ts +90 -90
- package/src/discord/discord.types.ts +696 -696
- package/src/engine/__tests__/run-in-isolate.test.ts +519 -519
- package/src/engine/engine-entry.ts +3 -3
- package/src/engine/engine-global.ts +2 -2
- package/src/engine/run-in-isolate.ts +462 -462
- package/src/errors/runtime-error-code.enum.ts +5 -0
- package/src/index.ts +32 -32
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +271 -271
- package/src/interpreter/interpreter-error.ts +12 -12
- package/src/interpreter/interpreter.ts +483 -483
- package/src/interpreter/interpreter.types.ts +204 -204
- package/src/interpreter/sequence-path.ts +67 -67
- package/src/interpreter/test-host.ts +85 -85
- package/src/runner-protocol/__tests__/file-payload.test.ts +26 -26
- package/src/runner-protocol/evaluation.types.ts +2 -0
- package/src/runner-protocol/execution-protocol.types.ts +297 -297
- package/src/schedule/schedule.types.ts +100 -100
- package/src/server/__tests__/code-runner-session.test.ts +311 -311
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -310
- package/src/server/index.ts +11 -11
- package/src/steps/__tests__/global-references.test.ts +140 -124
- package/src/steps/__tests__/step-fields.test.ts +58 -0
- package/src/steps/execute-step.ts +186 -186
- package/src/steps/global-references.ts +56 -48
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +10 -0
- package/src/steps/value-source.ts +69 -69
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +35 -35
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import type { RuntimeDefinition } from '../definition/definition.types';
|
|
2
|
-
import { start, step } from './interpreter';
|
|
3
|
-
import { EffectType, RunEventType } from './interpreter.types';
|
|
4
|
-
import type {
|
|
5
|
-
Effect,
|
|
6
|
-
EvaluateEffect,
|
|
7
|
-
HostEffect,
|
|
8
|
-
HttpEffect,
|
|
9
|
-
HttpResponse,
|
|
10
|
-
LogEffect,
|
|
11
|
-
RespondEffect,
|
|
12
|
-
RunEvent,
|
|
13
|
-
RunOptions,
|
|
14
|
-
RunState,
|
|
15
|
-
StepResult,
|
|
16
|
-
WaitEffect,
|
|
17
|
-
} from './interpreter.types';
|
|
18
|
-
import type { EvaluationResult } from '../runner-protocol/evaluation.types';
|
|
19
|
-
|
|
20
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* How a simulated host answers each effect. `evaluate` is mandatory: the package evaluates no
|
|
24
|
-
* JavaScript. The other handlers default to an empty answer; `wait` always elapses at once,
|
|
25
|
-
* `log` and `respond` default to accepting the line or the response.
|
|
26
|
-
*/
|
|
27
|
-
export interface TestHostHandlers {
|
|
28
|
-
evaluate: (effect: EvaluateEffect) => MaybePromise<EvaluationResult[]>;
|
|
29
|
-
http?: (effect: HttpEffect) => MaybePromise<HttpResponse>;
|
|
30
|
-
host?: (effect: HostEffect) => MaybePromise<unknown>;
|
|
31
|
-
wait?: (effect: WaitEffect) => MaybePromise<void>;
|
|
32
|
-
log?: (effect: LogEffect) => MaybePromise<void>;
|
|
33
|
-
respond?: (effect: RespondEffect) => MaybePromise<void>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface TestRunResult {
|
|
37
|
-
state: RunState;
|
|
38
|
-
/** Every effect the interpreter emitted, in order. */
|
|
39
|
-
effects: Effect[];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const DEFAULT_HTTP_RESPONSE: HttpResponse = { status: 200, headers: {}, body: null };
|
|
43
|
-
|
|
44
|
-
const answer = async (effect: Effect, handlers: TestHostHandlers): Promise<RunEvent> => {
|
|
45
|
-
switch (effect.type) {
|
|
46
|
-
case EffectType.EVALUATE:
|
|
47
|
-
return { type: RunEventType.EVALUATED, results: await handlers.evaluate(effect) };
|
|
48
|
-
case EffectType.HTTP:
|
|
49
|
-
return {
|
|
50
|
-
type: RunEventType.HTTP_COMPLETED,
|
|
51
|
-
response: handlers.http ? await handlers.http(effect) : DEFAULT_HTTP_RESPONSE,
|
|
52
|
-
};
|
|
53
|
-
case EffectType.HOST:
|
|
54
|
-
return {
|
|
55
|
-
type: RunEventType.HOST_COMPLETED,
|
|
56
|
-
output: handlers.host ? await handlers.host(effect) : null,
|
|
57
|
-
};
|
|
58
|
-
case EffectType.WAIT:
|
|
59
|
-
await handlers.wait?.(effect);
|
|
60
|
-
return { type: RunEventType.WAIT_ELAPSED };
|
|
61
|
-
case EffectType.LOG:
|
|
62
|
-
await handlers.log?.(effect);
|
|
63
|
-
return { type: RunEventType.LOG_WRITTEN };
|
|
64
|
-
case EffectType.RESPOND:
|
|
65
|
-
await handlers.respond?.(effect);
|
|
66
|
-
return { type: RunEventType.RESPONSE_SENT };
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/** Runs a definition to its end, answering every effect with `handlers` and executing nothing. */
|
|
71
|
-
export const runToCompletion = async (
|
|
72
|
-
definition: RuntimeDefinition,
|
|
73
|
-
input: unknown,
|
|
74
|
-
options: RunOptions,
|
|
75
|
-
handlers: TestHostHandlers,
|
|
76
|
-
): Promise<TestRunResult> => {
|
|
77
|
-
const effects: Effect[] = [];
|
|
78
|
-
let result: StepResult = start(definition, input, options);
|
|
79
|
-
while (result.effects.length > 0) {
|
|
80
|
-
const [effect] = result.effects;
|
|
81
|
-
effects.push(effect);
|
|
82
|
-
result = step(definition, result.state, await answer(effect, handlers), options);
|
|
83
|
-
}
|
|
84
|
-
return { state: result.state, effects };
|
|
85
|
-
};
|
|
1
|
+
import type { RuntimeDefinition } from '../definition/definition.types';
|
|
2
|
+
import { start, step } from './interpreter';
|
|
3
|
+
import { EffectType, RunEventType } from './interpreter.types';
|
|
4
|
+
import type {
|
|
5
|
+
Effect,
|
|
6
|
+
EvaluateEffect,
|
|
7
|
+
HostEffect,
|
|
8
|
+
HttpEffect,
|
|
9
|
+
HttpResponse,
|
|
10
|
+
LogEffect,
|
|
11
|
+
RespondEffect,
|
|
12
|
+
RunEvent,
|
|
13
|
+
RunOptions,
|
|
14
|
+
RunState,
|
|
15
|
+
StepResult,
|
|
16
|
+
WaitEffect,
|
|
17
|
+
} from './interpreter.types';
|
|
18
|
+
import type { EvaluationResult } from '../runner-protocol/evaluation.types';
|
|
19
|
+
|
|
20
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How a simulated host answers each effect. `evaluate` is mandatory: the package evaluates no
|
|
24
|
+
* JavaScript. The other handlers default to an empty answer; `wait` always elapses at once,
|
|
25
|
+
* `log` and `respond` default to accepting the line or the response.
|
|
26
|
+
*/
|
|
27
|
+
export interface TestHostHandlers {
|
|
28
|
+
evaluate: (effect: EvaluateEffect) => MaybePromise<EvaluationResult[]>;
|
|
29
|
+
http?: (effect: HttpEffect) => MaybePromise<HttpResponse>;
|
|
30
|
+
host?: (effect: HostEffect) => MaybePromise<unknown>;
|
|
31
|
+
wait?: (effect: WaitEffect) => MaybePromise<void>;
|
|
32
|
+
log?: (effect: LogEffect) => MaybePromise<void>;
|
|
33
|
+
respond?: (effect: RespondEffect) => MaybePromise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TestRunResult {
|
|
37
|
+
state: RunState;
|
|
38
|
+
/** Every effect the interpreter emitted, in order. */
|
|
39
|
+
effects: Effect[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const DEFAULT_HTTP_RESPONSE: HttpResponse = { status: 200, headers: {}, body: null };
|
|
43
|
+
|
|
44
|
+
const answer = async (effect: Effect, handlers: TestHostHandlers): Promise<RunEvent> => {
|
|
45
|
+
switch (effect.type) {
|
|
46
|
+
case EffectType.EVALUATE:
|
|
47
|
+
return { type: RunEventType.EVALUATED, results: await handlers.evaluate(effect) };
|
|
48
|
+
case EffectType.HTTP:
|
|
49
|
+
return {
|
|
50
|
+
type: RunEventType.HTTP_COMPLETED,
|
|
51
|
+
response: handlers.http ? await handlers.http(effect) : DEFAULT_HTTP_RESPONSE,
|
|
52
|
+
};
|
|
53
|
+
case EffectType.HOST:
|
|
54
|
+
return {
|
|
55
|
+
type: RunEventType.HOST_COMPLETED,
|
|
56
|
+
output: handlers.host ? await handlers.host(effect) : null,
|
|
57
|
+
};
|
|
58
|
+
case EffectType.WAIT:
|
|
59
|
+
await handlers.wait?.(effect);
|
|
60
|
+
return { type: RunEventType.WAIT_ELAPSED };
|
|
61
|
+
case EffectType.LOG:
|
|
62
|
+
await handlers.log?.(effect);
|
|
63
|
+
return { type: RunEventType.LOG_WRITTEN };
|
|
64
|
+
case EffectType.RESPOND:
|
|
65
|
+
await handlers.respond?.(effect);
|
|
66
|
+
return { type: RunEventType.RESPONSE_SENT };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** Runs a definition to its end, answering every effect with `handlers` and executing nothing. */
|
|
71
|
+
export const runToCompletion = async (
|
|
72
|
+
definition: RuntimeDefinition,
|
|
73
|
+
input: unknown,
|
|
74
|
+
options: RunOptions,
|
|
75
|
+
handlers: TestHostHandlers,
|
|
76
|
+
): Promise<TestRunResult> => {
|
|
77
|
+
const effects: Effect[] = [];
|
|
78
|
+
let result: StepResult = start(definition, input, options);
|
|
79
|
+
while (result.effects.length > 0) {
|
|
80
|
+
const [effect] = result.effects;
|
|
81
|
+
effects.push(effect);
|
|
82
|
+
result = step(definition, result.state, await answer(effect, handlers), options);
|
|
83
|
+
}
|
|
84
|
+
return { state: result.state, effects };
|
|
85
|
+
};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { REFLEX_ATTACHMENT_MAX_BYTES_BOUND } from '../../discord/discord.types';
|
|
2
|
-
import {
|
|
3
|
-
MAX_CALL_PAYLOAD_BYTES,
|
|
4
|
-
MAX_FILE_CALL_PAYLOAD_BYTES,
|
|
5
|
-
filePayloadBytesFor,
|
|
6
|
-
} from '../execution-protocol.types';
|
|
7
|
-
|
|
8
|
-
describe('filePayloadBytesFor', () => {
|
|
9
|
-
it('is the base64 size of the attachment plus 64 KiB of envelope', () => {
|
|
10
|
-
expect(filePayloadBytesFor(3)).toBe(4 + 65_536);
|
|
11
|
-
expect(filePayloadBytesFor(2 * 1024 * 1024)).toBe(
|
|
12
|
-
Math.ceil((2 * 1024 * 1024 * 4) / 3) + 65_536,
|
|
13
|
-
);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('rounds the base64 size up', () => {
|
|
17
|
-
expect(filePayloadBytesFor(1)).toBe(2 + 65_536);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('gives the highest grantable budget for the attachment bound', () => {
|
|
21
|
-
expect(MAX_FILE_CALL_PAYLOAD_BYTES).toBe(
|
|
22
|
-
filePayloadBytesFor(REFLEX_ATTACHMENT_MAX_BYTES_BOUND),
|
|
23
|
-
);
|
|
24
|
-
expect(MAX_FILE_CALL_PAYLOAD_BYTES).toBeGreaterThan(MAX_CALL_PAYLOAD_BYTES);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
1
|
+
import { REFLEX_ATTACHMENT_MAX_BYTES_BOUND } from '../../discord/discord.types';
|
|
2
|
+
import {
|
|
3
|
+
MAX_CALL_PAYLOAD_BYTES,
|
|
4
|
+
MAX_FILE_CALL_PAYLOAD_BYTES,
|
|
5
|
+
filePayloadBytesFor,
|
|
6
|
+
} from '../execution-protocol.types';
|
|
7
|
+
|
|
8
|
+
describe('filePayloadBytesFor', () => {
|
|
9
|
+
it('is the base64 size of the attachment plus 64 KiB of envelope', () => {
|
|
10
|
+
expect(filePayloadBytesFor(3)).toBe(4 + 65_536);
|
|
11
|
+
expect(filePayloadBytesFor(2 * 1024 * 1024)).toBe(
|
|
12
|
+
Math.ceil((2 * 1024 * 1024 * 4) / 3) + 65_536,
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('rounds the base64 size up', () => {
|
|
17
|
+
expect(filePayloadBytesFor(1)).toBe(2 + 65_536);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('gives the highest grantable budget for the attachment bound', () => {
|
|
21
|
+
expect(MAX_FILE_CALL_PAYLOAD_BYTES).toBe(
|
|
22
|
+
filePayloadBytesFor(REFLEX_ATTACHMENT_MAX_BYTES_BOUND),
|
|
23
|
+
);
|
|
24
|
+
expect(MAX_FILE_CALL_PAYLOAD_BYTES).toBeGreaterThan(MAX_CALL_PAYLOAD_BYTES);
|
|
25
|
+
});
|
|
26
|
+
});
|