@abyss-project/runtime 2.0.1 → 3.1.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 +27 -0
- package/dist/cost/execution-cost.d.ts +0 -2
- package/dist/cost/execution-cost.js +2 -6
- package/dist/cost/execution-cost.js.map +1 -1
- package/dist/discord/discord.types.d.ts +123 -0
- package/dist/discord/discord.types.js +53 -0
- package/dist/discord/discord.types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/runner-protocol/execution-protocol.types.d.ts +0 -1
- package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
- package/package.json +1 -1
- package/scripts/build-engine.cjs +70 -70
- package/src/__tests__/engine-bundle.test.ts +121 -121
- package/src/cost/__tests__/execution-cost.test.ts +196 -200
- package/src/cost/execution-cost.ts +186 -192
- package/src/definition/__tests__/validate-definition.test.ts +354 -354
- package/src/definition/definition.limits.ts +9 -9
- package/src/definition/definition.schema.ts +172 -172
- package/src/definition/definition.types.ts +171 -171
- package/src/discord/discord.types.ts +155 -0
- package/src/engine/__tests__/run-in-isolate.test.ts +468 -468
- package/src/engine/engine-entry.ts +3 -3
- package/src/engine/engine-global.ts +2 -2
- package/src/engine/run-in-isolate.ts +404 -404
- package/src/errors/runtime-error-code.enum.ts +37 -37
- package/src/index.ts +31 -30
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +223 -223
- package/src/interpreter/interpreter.ts +461 -461
- package/src/interpreter/interpreter.types.ts +192 -192
- package/src/interpreter/test-host.ts +85 -85
- package/src/runner-protocol/evaluation.types.ts +21 -21
- package/src/runner-protocol/execution-protocol.types.ts +231 -221
- 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 +133 -113
- package/src/steps/execute-step.ts +186 -186
- package/src/steps/global-references.ts +48 -48
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +87 -87
- package/src/steps/value-source.ts +69 -69
package/README.md
CHANGED
|
@@ -8,6 +8,33 @@ The package root (`@abyss-project/runtime`) is browser-compatible. Node-only cod
|
|
|
8
8
|
`@abyss-project/runtime/engine` exports `ENGINE_SOURCE`, the interpreter bundled into one
|
|
9
9
|
self-contained script for the code runner's isolate.
|
|
10
10
|
|
|
11
|
+
## Host globals
|
|
12
|
+
|
|
13
|
+
`ExecuteMessage.globals` gives the client code read-only globals: each top-level key becomes a
|
|
14
|
+
frozen global. Two keys are conventional: `secrets` (`{{ secrets.NAME }}` / `secrets.NAME`, masked
|
|
15
|
+
by the host) and `config` (`Record<string, string>`, the non-secret per-environment variables:
|
|
16
|
+
`{{ config.NAME }}` / `config.NAME`, not masked). A name the host did not send is `undefined`.
|
|
17
|
+
The host sends the names `collectGlobalReferences(definition, 'config')` finds.
|
|
18
|
+
|
|
19
|
+
## Discord helpers
|
|
20
|
+
|
|
21
|
+
A host that grants the `DiscordCapability` names (`discord.reply`, `discord.update`,
|
|
22
|
+
`discord.showModal`, `discord.followUp`, `discord.sendMessage`, `discord.editMessage`,
|
|
23
|
+
`discord.deleteMessage`, `discord.addRole`, `discord.removeRole`, `discord.sendDirectMessage`) gives
|
|
24
|
+
the client code `abyss.discord.<name>(...)`, one helper per granted capability:
|
|
25
|
+
|
|
26
|
+
- `reply(message)`, `update(message)`, `followUp(message)`, `showModal({ customId, title, fields })`
|
|
27
|
+
- `sendMessage(channelId, message)`, `editMessage(channelId, messageId, message)`,
|
|
28
|
+
`deleteMessage(channelId, messageId)`, `sendDirectMessage(userId, message)`
|
|
29
|
+
- `addRole(guildId, userId, roleId)`, `removeRole(guildId, userId, roleId)`
|
|
30
|
+
|
|
31
|
+
`message` is a `DiscordMessage` (`{ content?, embeds?, components?, ephemeral? }`). The `args` of
|
|
32
|
+
each host `call` are the types `Discord*Args` (a `DiscordMessage` itself for `reply`, `update`,
|
|
33
|
+
`followUp`). A host failing a call with the message `<DiscordErrorCode>: <detail>` (or the bare
|
|
34
|
+
code) makes the helper throw an `Error` named `DiscordError` with `code` and `message` set; any
|
|
35
|
+
other failure is thrown unchanged. `DiscordInteractionInput` types the `input` of a function
|
|
36
|
+
triggered by a Discord interaction.
|
|
37
|
+
|
|
11
38
|
## Installation
|
|
12
39
|
|
|
13
40
|
```bash
|
|
@@ -13,7 +13,6 @@ export declare const RESOURCE_PROFILES: Readonly<Record<ResourceProfile, Resourc
|
|
|
13
13
|
export declare const COST_RATES: {
|
|
14
14
|
readonly executionMillicredits: 10;
|
|
15
15
|
readonly cpuMillicreditsPerSecond: 500;
|
|
16
|
-
readonly guaranteedCpuCoefficient: 1.5;
|
|
17
16
|
readonly memoryMillicreditsPerGbSecond: 100;
|
|
18
17
|
readonly networkOutMillicreditsPerMb: 1000;
|
|
19
18
|
readonly httpCallMillicredits: 10;
|
|
@@ -34,7 +33,6 @@ export interface StepUsage {
|
|
|
34
33
|
export interface ExecutionCostInput extends StepUsage {
|
|
35
34
|
status: CostedExecutionStatus;
|
|
36
35
|
profile: ResourceProfile;
|
|
37
|
-
guaranteedCpu: boolean;
|
|
38
36
|
resumedSegment?: boolean;
|
|
39
37
|
}
|
|
40
38
|
export interface StepCostInput {
|
|
@@ -19,7 +19,6 @@ exports.RESOURCE_PROFILES = {
|
|
|
19
19
|
exports.COST_RATES = {
|
|
20
20
|
executionMillicredits: 10,
|
|
21
21
|
cpuMillicreditsPerSecond: 500,
|
|
22
|
-
guaranteedCpuCoefficient: 1.5,
|
|
23
22
|
memoryMillicreditsPerGbSecond: 100,
|
|
24
23
|
networkOutMillicreditsPerMb: 1000,
|
|
25
24
|
httpCallMillicredits: 10,
|
|
@@ -32,10 +31,10 @@ var CostedExecutionStatus;
|
|
|
32
31
|
CostedExecutionStatus["REFUSED"] = "REFUSED";
|
|
33
32
|
})(CostedExecutionStatus || (exports.CostedExecutionStatus = CostedExecutionStatus = {}));
|
|
34
33
|
const MICROS_PER_SECOND = BigInt(1_000_000);
|
|
35
|
-
const CPU_DENOMINATOR = MICROS_PER_SECOND * BigInt(100)
|
|
34
|
+
const CPU_DENOMINATOR = MICROS_PER_SECOND * BigInt(100);
|
|
36
35
|
const MEMORY_DENOMINATOR = BigInt(1024) * MICROS_PER_SECOND;
|
|
37
36
|
const NETWORK_DENOMINATOR = BigInt(1024 * 1024);
|
|
38
|
-
const UNITS_PER_MILLICREDIT = BigInt(1_048_576) * BigInt(
|
|
37
|
+
const UNITS_PER_MILLICREDIT = BigInt(1_048_576) * BigInt(390_625);
|
|
39
38
|
const ZERO = BigInt(0);
|
|
40
39
|
const ONE = BigInt(1);
|
|
41
40
|
const TWO = BigInt(2);
|
|
@@ -50,14 +49,11 @@ const assertUsage = (usage, subject) => {
|
|
|
50
49
|
const micros = (ms) => BigInt(Math.round(ms * 1000));
|
|
51
50
|
const whole = (count) => BigInt(Math.round(count));
|
|
52
51
|
const hundredths = (coefficient) => BigInt(Math.round(coefficient * 100));
|
|
53
|
-
const thousandths = (coefficient) => BigInt(Math.round(coefficient * 1000));
|
|
54
52
|
const variableUnits = (usage, execution) => {
|
|
55
53
|
const profile = exports.RESOURCE_PROFILES[execution.profile];
|
|
56
|
-
const guaranteed = execution.guaranteedCpu ? exports.COST_RATES.guaranteedCpuCoefficient : 1;
|
|
57
54
|
const cpu = (micros(usage.cpuMs) *
|
|
58
55
|
BigInt(exports.COST_RATES.cpuMillicreditsPerSecond) *
|
|
59
56
|
hundredths(profile.cpuCoefficient) *
|
|
60
|
-
thousandths(guaranteed) *
|
|
61
57
|
UNITS_PER_MILLICREDIT) /
|
|
62
58
|
CPU_DENOMINATOR;
|
|
63
59
|
const memory = (BigInt(profile.memoryMb) *
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-cost.js","sourceRoot":"","sources":["../../src/cost/execution-cost.ts"],"names":[],"mappings":";;;AAI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AC9F,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,123 @@
|
|
|
1
|
+
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
+
export declare enum DiscordCapability {
|
|
3
|
+
REPLY = "discord.reply",
|
|
4
|
+
UPDATE = "discord.update",
|
|
5
|
+
SHOW_MODAL = "discord.showModal",
|
|
6
|
+
FOLLOW_UP = "discord.followUp",
|
|
7
|
+
SEND_MESSAGE = "discord.sendMessage",
|
|
8
|
+
EDIT_MESSAGE = "discord.editMessage",
|
|
9
|
+
DELETE_MESSAGE = "discord.deleteMessage",
|
|
10
|
+
ADD_ROLE = "discord.addRole",
|
|
11
|
+
REMOVE_ROLE = "discord.removeRole",
|
|
12
|
+
SEND_DIRECT_MESSAGE = "discord.sendDirectMessage"
|
|
13
|
+
}
|
|
14
|
+
export declare enum DiscordErrorCode {
|
|
15
|
+
MODAL_TOO_LATE = "MODAL_TOO_LATE",
|
|
16
|
+
DISCORD_TOKEN_INVALID = "DISCORD_TOKEN_INVALID",
|
|
17
|
+
DISCORD_FORBIDDEN = "DISCORD_FORBIDDEN",
|
|
18
|
+
DISCORD_NOT_FOUND = "DISCORD_NOT_FOUND",
|
|
19
|
+
DISCORD_RATE_LIMITED = "DISCORD_RATE_LIMITED"
|
|
20
|
+
}
|
|
21
|
+
export type DiscordJsonObject = {
|
|
22
|
+
[key: string]: JSONValue;
|
|
23
|
+
};
|
|
24
|
+
export interface DiscordMessage {
|
|
25
|
+
content?: string;
|
|
26
|
+
embeds?: DiscordJsonObject[];
|
|
27
|
+
components?: DiscordJsonObject[];
|
|
28
|
+
ephemeral?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare enum DiscordModalFieldStyle {
|
|
31
|
+
SHORT = "SHORT",
|
|
32
|
+
PARAGRAPH = "PARAGRAPH"
|
|
33
|
+
}
|
|
34
|
+
export interface DiscordModalField {
|
|
35
|
+
customId: string;
|
|
36
|
+
label: string;
|
|
37
|
+
style?: DiscordModalFieldStyle;
|
|
38
|
+
required?: boolean;
|
|
39
|
+
placeholder?: string;
|
|
40
|
+
value?: string;
|
|
41
|
+
minLength?: number;
|
|
42
|
+
maxLength?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface DiscordShowModalArgs {
|
|
45
|
+
customId: string;
|
|
46
|
+
title: string;
|
|
47
|
+
fields: DiscordModalField[];
|
|
48
|
+
}
|
|
49
|
+
export interface DiscordSendMessageArgs {
|
|
50
|
+
channelId: string;
|
|
51
|
+
message: DiscordMessage;
|
|
52
|
+
}
|
|
53
|
+
export interface DiscordEditMessageArgs {
|
|
54
|
+
channelId: string;
|
|
55
|
+
messageId: string;
|
|
56
|
+
message: DiscordMessage;
|
|
57
|
+
}
|
|
58
|
+
export interface DiscordDeleteMessageArgs {
|
|
59
|
+
channelId: string;
|
|
60
|
+
messageId: string;
|
|
61
|
+
}
|
|
62
|
+
export interface DiscordRoleArgs {
|
|
63
|
+
guildId: string;
|
|
64
|
+
userId: string;
|
|
65
|
+
roleId: string;
|
|
66
|
+
}
|
|
67
|
+
export interface DiscordSendDirectMessageArgs {
|
|
68
|
+
userId: string;
|
|
69
|
+
message: DiscordMessage;
|
|
70
|
+
}
|
|
71
|
+
export declare enum DiscordInteractionKind {
|
|
72
|
+
COMMAND = "COMMAND",
|
|
73
|
+
COMPONENT = "COMPONENT",
|
|
74
|
+
MODAL = "MODAL"
|
|
75
|
+
}
|
|
76
|
+
export declare enum DiscordInteractionType {
|
|
77
|
+
PING = 1,
|
|
78
|
+
APPLICATION_COMMAND = 2,
|
|
79
|
+
MESSAGE_COMPONENT = 3,
|
|
80
|
+
MODAL_SUBMIT = 5
|
|
81
|
+
}
|
|
82
|
+
export declare enum DiscordCallbackType {
|
|
83
|
+
PONG = 1,
|
|
84
|
+
CHANNEL_MESSAGE_WITH_SOURCE = 4,
|
|
85
|
+
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5,
|
|
86
|
+
DEFERRED_UPDATE_MESSAGE = 6,
|
|
87
|
+
UPDATE_MESSAGE = 7,
|
|
88
|
+
MODAL = 9
|
|
89
|
+
}
|
|
90
|
+
export declare const EPHEMERAL_FLAG = 64;
|
|
91
|
+
export interface DiscordInteractionInput {
|
|
92
|
+
kind: DiscordInteractionKind;
|
|
93
|
+
command?: {
|
|
94
|
+
name: string;
|
|
95
|
+
options: Record<string, string | number | boolean>;
|
|
96
|
+
};
|
|
97
|
+
component?: {
|
|
98
|
+
customId: string;
|
|
99
|
+
values?: string[];
|
|
100
|
+
};
|
|
101
|
+
modal?: {
|
|
102
|
+
customId: string;
|
|
103
|
+
fields: Record<string, string>;
|
|
104
|
+
};
|
|
105
|
+
user: {
|
|
106
|
+
id: string;
|
|
107
|
+
username: string;
|
|
108
|
+
globalName: string | null;
|
|
109
|
+
};
|
|
110
|
+
member?: {
|
|
111
|
+
roles: string[];
|
|
112
|
+
permissions: string;
|
|
113
|
+
};
|
|
114
|
+
guildId?: string;
|
|
115
|
+
channelId?: string;
|
|
116
|
+
locale: string;
|
|
117
|
+
interaction: {
|
|
118
|
+
id: string;
|
|
119
|
+
applicationId: string;
|
|
120
|
+
type: number;
|
|
121
|
+
data: JSONValue;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EPHEMERAL_FLAG = exports.DiscordCallbackType = exports.DiscordInteractionType = exports.DiscordInteractionKind = exports.DiscordModalFieldStyle = exports.DiscordErrorCode = exports.DiscordCapability = void 0;
|
|
4
|
+
var DiscordCapability;
|
|
5
|
+
(function (DiscordCapability) {
|
|
6
|
+
DiscordCapability["REPLY"] = "discord.reply";
|
|
7
|
+
DiscordCapability["UPDATE"] = "discord.update";
|
|
8
|
+
DiscordCapability["SHOW_MODAL"] = "discord.showModal";
|
|
9
|
+
DiscordCapability["FOLLOW_UP"] = "discord.followUp";
|
|
10
|
+
DiscordCapability["SEND_MESSAGE"] = "discord.sendMessage";
|
|
11
|
+
DiscordCapability["EDIT_MESSAGE"] = "discord.editMessage";
|
|
12
|
+
DiscordCapability["DELETE_MESSAGE"] = "discord.deleteMessage";
|
|
13
|
+
DiscordCapability["ADD_ROLE"] = "discord.addRole";
|
|
14
|
+
DiscordCapability["REMOVE_ROLE"] = "discord.removeRole";
|
|
15
|
+
DiscordCapability["SEND_DIRECT_MESSAGE"] = "discord.sendDirectMessage";
|
|
16
|
+
})(DiscordCapability || (exports.DiscordCapability = DiscordCapability = {}));
|
|
17
|
+
var DiscordErrorCode;
|
|
18
|
+
(function (DiscordErrorCode) {
|
|
19
|
+
DiscordErrorCode["MODAL_TOO_LATE"] = "MODAL_TOO_LATE";
|
|
20
|
+
DiscordErrorCode["DISCORD_TOKEN_INVALID"] = "DISCORD_TOKEN_INVALID";
|
|
21
|
+
DiscordErrorCode["DISCORD_FORBIDDEN"] = "DISCORD_FORBIDDEN";
|
|
22
|
+
DiscordErrorCode["DISCORD_NOT_FOUND"] = "DISCORD_NOT_FOUND";
|
|
23
|
+
DiscordErrorCode["DISCORD_RATE_LIMITED"] = "DISCORD_RATE_LIMITED";
|
|
24
|
+
})(DiscordErrorCode || (exports.DiscordErrorCode = DiscordErrorCode = {}));
|
|
25
|
+
var DiscordModalFieldStyle;
|
|
26
|
+
(function (DiscordModalFieldStyle) {
|
|
27
|
+
DiscordModalFieldStyle["SHORT"] = "SHORT";
|
|
28
|
+
DiscordModalFieldStyle["PARAGRAPH"] = "PARAGRAPH";
|
|
29
|
+
})(DiscordModalFieldStyle || (exports.DiscordModalFieldStyle = DiscordModalFieldStyle = {}));
|
|
30
|
+
var DiscordInteractionKind;
|
|
31
|
+
(function (DiscordInteractionKind) {
|
|
32
|
+
DiscordInteractionKind["COMMAND"] = "COMMAND";
|
|
33
|
+
DiscordInteractionKind["COMPONENT"] = "COMPONENT";
|
|
34
|
+
DiscordInteractionKind["MODAL"] = "MODAL";
|
|
35
|
+
})(DiscordInteractionKind || (exports.DiscordInteractionKind = DiscordInteractionKind = {}));
|
|
36
|
+
var DiscordInteractionType;
|
|
37
|
+
(function (DiscordInteractionType) {
|
|
38
|
+
DiscordInteractionType[DiscordInteractionType["PING"] = 1] = "PING";
|
|
39
|
+
DiscordInteractionType[DiscordInteractionType["APPLICATION_COMMAND"] = 2] = "APPLICATION_COMMAND";
|
|
40
|
+
DiscordInteractionType[DiscordInteractionType["MESSAGE_COMPONENT"] = 3] = "MESSAGE_COMPONENT";
|
|
41
|
+
DiscordInteractionType[DiscordInteractionType["MODAL_SUBMIT"] = 5] = "MODAL_SUBMIT";
|
|
42
|
+
})(DiscordInteractionType || (exports.DiscordInteractionType = DiscordInteractionType = {}));
|
|
43
|
+
var DiscordCallbackType;
|
|
44
|
+
(function (DiscordCallbackType) {
|
|
45
|
+
DiscordCallbackType[DiscordCallbackType["PONG"] = 1] = "PONG";
|
|
46
|
+
DiscordCallbackType[DiscordCallbackType["CHANNEL_MESSAGE_WITH_SOURCE"] = 4] = "CHANNEL_MESSAGE_WITH_SOURCE";
|
|
47
|
+
DiscordCallbackType[DiscordCallbackType["DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE"] = 5] = "DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE";
|
|
48
|
+
DiscordCallbackType[DiscordCallbackType["DEFERRED_UPDATE_MESSAGE"] = 6] = "DEFERRED_UPDATE_MESSAGE";
|
|
49
|
+
DiscordCallbackType[DiscordCallbackType["UPDATE_MESSAGE"] = 7] = "UPDATE_MESSAGE";
|
|
50
|
+
DiscordCallbackType[DiscordCallbackType["MODAL"] = 9] = "MODAL";
|
|
51
|
+
})(DiscordCallbackType || (exports.DiscordCallbackType = DiscordCallbackType = {}));
|
|
52
|
+
exports.EPHEMERAL_FLAG = 64;
|
|
53
|
+
//# sourceMappingURL=discord.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discord.types.js","sourceRoot":"","sources":["../../src/discord/discord.types.ts"],"names":[],"mappings":";;;AAOA,IAAY,iBAqBX;AArBD,WAAY,iBAAiB;IAE3B,4CAAuB,CAAA;IAEvB,8CAAyB,CAAA;IAEzB,qDAAgC,CAAA;IAEhC,mDAA8B,CAAA;IAE9B,yDAAoC,CAAA;IAEpC,yDAAoC,CAAA;IAEpC,6DAAwC,CAAA;IAExC,iDAA4B,CAAA;IAE5B,uDAAkC,CAAA;IAElC,sEAAiD,CAAA;AACnD,CAAC,EArBW,iBAAiB,iCAAjB,iBAAiB,QAqB5B;AAOD,IAAY,gBAWX;AAXD,WAAY,gBAAgB;IAE1B,qDAAiC,CAAA;IAEjC,mEAA+C,CAAA;IAE/C,2DAAuC,CAAA;IAEvC,2DAAuC,CAAA;IAEvC,iEAA6C,CAAA;AAC/C,CAAC,EAXW,gBAAgB,gCAAhB,gBAAgB,QAW3B;AAcD,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,iDAAuB,CAAA;AACzB,CAAC,EAHW,sBAAsB,sCAAtB,sBAAsB,QAGjC;AA+CD,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAChC,6CAAmB,CAAA;IACnB,iDAAuB,CAAA;IACvB,yCAAe,CAAA;AACjB,CAAC,EAJW,sBAAsB,sCAAtB,sBAAsB,QAIjC;AAGD,IAAY,sBAKX;AALD,WAAY,sBAAsB;IAChC,mEAAQ,CAAA;IACR,iGAAuB,CAAA;IACvB,6FAAqB,CAAA;IACrB,mFAAgB,CAAA;AAClB,CAAC,EALW,sBAAsB,sCAAtB,sBAAsB,QAKjC;AAGD,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,6DAAQ,CAAA;IACR,2GAA+B,CAAA;IAC/B,6HAAwC,CAAA;IACxC,mGAA2B,CAAA;IAC3B,iFAAkB,CAAA;IAClB,+DAAS,CAAA;AACX,CAAC,EAPW,mBAAmB,mCAAnB,mBAAmB,QAO9B;AAGY,QAAA,cAAc,GAAG,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { start, step } from './interpreter/interpreter';
|
|
|
12
12
|
export { InterpreterError } from './interpreter/interpreter-error';
|
|
13
13
|
export { runToCompletion } from './interpreter/test-host';
|
|
14
14
|
export type { TestHostHandlers, TestRunResult } from './interpreter/test-host';
|
|
15
|
+
export * from './discord/discord.types';
|
|
15
16
|
export * from './runner-protocol/evaluation.types';
|
|
16
17
|
export * from './runner-protocol/execution-protocol.types';
|
|
17
18
|
export { runInIsolate, EngineResultKind } from './engine/run-in-isolate';
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ var interpreter_error_1 = require("./interpreter/interpreter-error");
|
|
|
34
34
|
Object.defineProperty(exports, "InterpreterError", { enumerable: true, get: function () { return interpreter_error_1.InterpreterError; } });
|
|
35
35
|
var test_host_1 = require("./interpreter/test-host");
|
|
36
36
|
Object.defineProperty(exports, "runToCompletion", { enumerable: true, get: function () { return test_host_1.runToCompletion; } });
|
|
37
|
+
__exportStar(require("./discord/discord.types"), exports);
|
|
37
38
|
__exportStar(require("./runner-protocol/evaluation.types"), exports);
|
|
38
39
|
__exportStar(require("./runner-protocol/execution-protocol.types"), exports);
|
|
39
40
|
var run_in_isolate_1 = require("./engine/run-in-isolate");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,mEAAiD;AACjD,wDAAsC;AACtC,kDAAkD;AAAzC,yGAAA,WAAW,OAAA;AACpB,gEAA8C;AAC9C,wEAAsE;AAA7D,yHAAA,kBAAkB,OAAA;AAE3B,oEAAsE;AAA7D,yHAAA,oBAAoB,OAAA;AAC7B,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAElB,kEAAgD;AAChD,yDAAwD;AAA/C,oGAAA,KAAK,OAAA;AAAE,mGAAA,IAAI,OAAA;AACpB,qEAAmE;AAA1D,qHAAA,gBAAgB,OAAA;AACzB,qDAA0D;AAAjD,4GAAA,eAAe,OAAA;AAExB,qEAAmD;AACnD,6EAA2D;AAC3D,0DAAyE;AAAhE,8GAAA,YAAY,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AAQvC,wDAA4D;AAAnD,mHAAA,kBAAkB,OAAA;AAC3B,+DAAoE;AAA3D,4HAAA,uBAAuB,OAAA;AAChC,wDAAsC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,mEAAiD;AACjD,wDAAsC;AACtC,kDAAkD;AAAzC,yGAAA,WAAW,OAAA;AACpB,gEAA8C;AAC9C,wEAAsE;AAA7D,yHAAA,kBAAkB,OAAA;AAE3B,oEAAsE;AAA7D,yHAAA,oBAAoB,OAAA;AAC7B,sDAAoD;AAA3C,uGAAA,SAAS,OAAA;AAElB,kEAAgD;AAChD,yDAAwD;AAA/C,oGAAA,KAAK,OAAA;AAAE,mGAAA,IAAI,OAAA;AACpB,qEAAmE;AAA1D,qHAAA,gBAAgB,OAAA;AACzB,qDAA0D;AAAjD,4GAAA,eAAe,OAAA;AAExB,0DAAwC;AACxC,qEAAmD;AACnD,6EAA2D;AAC3D,0DAAyE;AAAhE,8GAAA,YAAY,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AAQvC,wDAA4D;AAAnD,mHAAA,kBAAkB,OAAA;AAC3B,+DAAoE;AAA3D,4HAAA,uBAAuB,OAAA;AAChC,wDAAsC"}
|
|
@@ -1 +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;
|
|
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;AA+FF,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"}
|
package/package.json
CHANGED
package/scripts/build-engine.cjs
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* build-engine.cjs — bundles the isolate engine (ADR-0238) into one self-contained script and
|
|
4
|
-
* ships it as a string: `@abyss-project/runtime/engine` exports `ENGINE_SOURCE`.
|
|
5
|
-
*
|
|
6
|
-
* The script is an IIFE that defines one global (`ENGINE_GLOBAL_NAME`, `{ runInIsolate }`).
|
|
7
|
-
* `platform: 'neutral'` resolves no Node built-in: an import of `fs`, `net`... fails the build
|
|
8
|
-
* instead of slipping into the isolate. Runs after `tsc`, which emits the rest of `dist`.
|
|
9
|
-
*
|
|
10
|
-
* USAGE (from the package directory, what `build` does)
|
|
11
|
-
* node scripts/build-engine.cjs
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/* eslint-disable no-console */
|
|
15
|
-
'use strict';
|
|
16
|
-
|
|
17
|
-
const fs = require('fs');
|
|
18
|
-
const path = require('path');
|
|
19
|
-
const esbuild = require('esbuild');
|
|
20
|
-
|
|
21
|
-
const PACKAGE_DIR = path.resolve(__dirname, '..');
|
|
22
|
-
const ENTRY = path.join(PACKAGE_DIR, 'src', 'engine', 'engine-entry.ts');
|
|
23
|
-
const OUT_DIR = path.join(PACKAGE_DIR, 'dist', 'engine');
|
|
24
|
-
|
|
25
|
-
/** The engine script, as a string; `globalName` is the global it defines. */
|
|
26
|
-
function bundleEngine(globalName) {
|
|
27
|
-
const result = esbuild.buildSync({
|
|
28
|
-
entryPoints: [ENTRY],
|
|
29
|
-
bundle: true,
|
|
30
|
-
format: 'iife',
|
|
31
|
-
globalName,
|
|
32
|
-
platform: 'neutral',
|
|
33
|
-
target: 'es2021',
|
|
34
|
-
write: false,
|
|
35
|
-
legalComments: 'none',
|
|
36
|
-
logLevel: 'silent',
|
|
37
|
-
});
|
|
38
|
-
return result.outputFiles[0].text;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function main() {
|
|
42
|
-
const globalPath = path.join(OUT_DIR, 'engine-global.js');
|
|
43
|
-
if (!fs.existsSync(globalPath)) {
|
|
44
|
-
throw new Error(`${globalPath} is missing: run tsc before this script`);
|
|
45
|
-
}
|
|
46
|
-
const { ENGINE_GLOBAL_NAME } = require(globalPath);
|
|
47
|
-
const source = bundleEngine(ENGINE_GLOBAL_NAME);
|
|
48
|
-
fs.writeFileSync(
|
|
49
|
-
path.join(OUT_DIR, 'engine-source.js'),
|
|
50
|
-
`"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\n` +
|
|
51
|
-
`exports.ENGINE_SOURCE = ${JSON.stringify(source)};\n`,
|
|
52
|
-
);
|
|
53
|
-
fs.writeFileSync(
|
|
54
|
-
path.join(OUT_DIR, 'engine-source.d.ts'),
|
|
55
|
-
'/** The isolate engine script: evaluating it defines the global `ENGINE_GLOBAL_NAME`. */\n' +
|
|
56
|
-
'export declare const ENGINE_SOURCE: string;\n',
|
|
57
|
-
);
|
|
58
|
-
console.log(`engine bundle: ${source.length} characters in dist/engine/engine-source.js`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (require.main === module) {
|
|
62
|
-
try {
|
|
63
|
-
main();
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error(error instanceof Error ? error.message : error);
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
module.exports = { bundleEngine };
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* build-engine.cjs — bundles the isolate engine (ADR-0238) into one self-contained script and
|
|
4
|
+
* ships it as a string: `@abyss-project/runtime/engine` exports `ENGINE_SOURCE`.
|
|
5
|
+
*
|
|
6
|
+
* The script is an IIFE that defines one global (`ENGINE_GLOBAL_NAME`, `{ runInIsolate }`).
|
|
7
|
+
* `platform: 'neutral'` resolves no Node built-in: an import of `fs`, `net`... fails the build
|
|
8
|
+
* instead of slipping into the isolate. Runs after `tsc`, which emits the rest of `dist`.
|
|
9
|
+
*
|
|
10
|
+
* USAGE (from the package directory, what `build` does)
|
|
11
|
+
* node scripts/build-engine.cjs
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/* eslint-disable no-console */
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const esbuild = require('esbuild');
|
|
20
|
+
|
|
21
|
+
const PACKAGE_DIR = path.resolve(__dirname, '..');
|
|
22
|
+
const ENTRY = path.join(PACKAGE_DIR, 'src', 'engine', 'engine-entry.ts');
|
|
23
|
+
const OUT_DIR = path.join(PACKAGE_DIR, 'dist', 'engine');
|
|
24
|
+
|
|
25
|
+
/** The engine script, as a string; `globalName` is the global it defines. */
|
|
26
|
+
function bundleEngine(globalName) {
|
|
27
|
+
const result = esbuild.buildSync({
|
|
28
|
+
entryPoints: [ENTRY],
|
|
29
|
+
bundle: true,
|
|
30
|
+
format: 'iife',
|
|
31
|
+
globalName,
|
|
32
|
+
platform: 'neutral',
|
|
33
|
+
target: 'es2021',
|
|
34
|
+
write: false,
|
|
35
|
+
legalComments: 'none',
|
|
36
|
+
logLevel: 'silent',
|
|
37
|
+
});
|
|
38
|
+
return result.outputFiles[0].text;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function main() {
|
|
42
|
+
const globalPath = path.join(OUT_DIR, 'engine-global.js');
|
|
43
|
+
if (!fs.existsSync(globalPath)) {
|
|
44
|
+
throw new Error(`${globalPath} is missing: run tsc before this script`);
|
|
45
|
+
}
|
|
46
|
+
const { ENGINE_GLOBAL_NAME } = require(globalPath);
|
|
47
|
+
const source = bundleEngine(ENGINE_GLOBAL_NAME);
|
|
48
|
+
fs.writeFileSync(
|
|
49
|
+
path.join(OUT_DIR, 'engine-source.js'),
|
|
50
|
+
`"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\n` +
|
|
51
|
+
`exports.ENGINE_SOURCE = ${JSON.stringify(source)};\n`,
|
|
52
|
+
);
|
|
53
|
+
fs.writeFileSync(
|
|
54
|
+
path.join(OUT_DIR, 'engine-source.d.ts'),
|
|
55
|
+
'/** The isolate engine script: evaluating it defines the global `ENGINE_GLOBAL_NAME`. */\n' +
|
|
56
|
+
'export declare const ENGINE_SOURCE: string;\n',
|
|
57
|
+
);
|
|
58
|
+
console.log(`engine bundle: ${source.length} characters in dist/engine/engine-source.js`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (require.main === module) {
|
|
62
|
+
try {
|
|
63
|
+
main();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(error instanceof Error ? error.message : error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { bundleEngine };
|