@abyss-project/runtime 3.0.0 → 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.
Files changed (41) hide show
  1. package/README.md +27 -0
  2. package/dist/discord/discord.types.d.ts +123 -0
  3. package/dist/discord/discord.types.js +53 -0
  4. package/dist/discord/discord.types.js.map +1 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +1 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
  9. package/package.json +1 -1
  10. package/scripts/build-engine.cjs +70 -70
  11. package/src/__tests__/engine-bundle.test.ts +121 -121
  12. package/src/cost/__tests__/execution-cost.test.ts +196 -196
  13. package/src/cost/execution-cost.ts +186 -186
  14. package/src/definition/__tests__/validate-definition.test.ts +354 -354
  15. package/src/definition/definition.limits.ts +9 -9
  16. package/src/definition/definition.schema.ts +172 -172
  17. package/src/definition/definition.types.ts +171 -171
  18. package/src/discord/discord.types.ts +155 -0
  19. package/src/engine/__tests__/run-in-isolate.test.ts +468 -468
  20. package/src/engine/engine-entry.ts +3 -3
  21. package/src/engine/engine-global.ts +2 -2
  22. package/src/engine/run-in-isolate.ts +404 -404
  23. package/src/errors/runtime-error-code.enum.ts +37 -37
  24. package/src/index.ts +31 -30
  25. package/src/interpreter/__tests__/interpreter.test.ts +854 -854
  26. package/src/interpreter/__tests__/log-respond-resume.test.ts +223 -223
  27. package/src/interpreter/interpreter.ts +461 -461
  28. package/src/interpreter/interpreter.types.ts +192 -192
  29. package/src/interpreter/test-host.ts +85 -85
  30. package/src/runner-protocol/evaluation.types.ts +21 -21
  31. package/src/runner-protocol/execution-protocol.types.ts +231 -225
  32. package/src/server/__tests__/code-runner-session.test.ts +311 -311
  33. package/src/server/code-runner-error.ts +12 -12
  34. package/src/server/code-runner-session.ts +310 -310
  35. package/src/server/index.ts +11 -11
  36. package/src/steps/__tests__/global-references.test.ts +133 -113
  37. package/src/steps/execute-step.ts +186 -186
  38. package/src/steps/global-references.ts +48 -48
  39. package/src/steps/step-access.ts +56 -56
  40. package/src/steps/step-fields.ts +87 -87
  41. 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
@@ -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;AAyFF,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"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abyss-project/runtime",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Abyss automation core: definitions, interpreter, runner protocol",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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 };
@@ -1,121 +1,121 @@
1
- import * as vm from 'vm';
2
- import { AccessKind } from '../access/access.types';
3
- import {
4
- CURRENT_FORMAT_VERSION,
5
- HttpMethod,
6
- LogLevel,
7
- StepType,
8
- StopStatus,
9
- } from '../definition/definition.types';
10
- import type { RuntimeDefinition } from '../definition/definition.types';
11
- import { ENGINE_GLOBAL_NAME } from '../engine/engine-global';
12
- import { EngineResultKind } from '../engine/run-in-isolate';
13
- import type { EngineHost, EngineRequest, EngineResult } from '../engine/run-in-isolate';
14
- import type { EvaluationItem } from '../runner-protocol/evaluation.types';
15
- import { CoreCapability, ExecutionStatus } from '../runner-protocol/execution-protocol.types';
16
-
17
- // The build script is plain CommonJS, shared with `build`: the test bundles exactly what ships.
18
- // eslint-disable-next-line @typescript-eslint/no-require-imports
19
- const { bundleEngine } = require('../../scripts/build-engine.cjs') as {
20
- bundleEngine: (globalName: string) => string;
21
- };
22
-
23
- type Engine = { runInIsolate: (request: EngineRequest, host: EngineHost) => Promise<EngineResult> };
24
-
25
- const definition: RuntimeDefinition = {
26
- formatVersion: CURRENT_FORMAT_VERSION,
27
- accesses: [{ kind: AccessKind.HTTP, hosts: ['api.example.com'] }],
28
- steps: [
29
- { id: 'double', type: StepType.SET, variable: 'n', value: { $expression: 'input.n * 2' } },
30
- {
31
- id: 'fetch',
32
- type: StepType.HTTP,
33
- method: HttpMethod.GET,
34
- url: 'https://api.example.com/{{ vars.n }}',
35
- },
36
- { id: 'note', type: StepType.LOG, level: LogLevel.INFO, message: 'fetched' },
37
- {
38
- id: 'end',
39
- type: StepType.STOP,
40
- status: StopStatus.SUCCEEDED,
41
- output: { $expression: 'vars.n' },
42
- },
43
- ],
44
- };
45
-
46
- describe('isolate engine bundle', () => {
47
- let source: string;
48
-
49
- beforeAll(() => {
50
- source = bundleEngine(ENGINE_GLOBAL_NAME);
51
- });
52
-
53
- it('carries no module loader and no Joi', () => {
54
- expect(source).not.toMatch(/\brequire\s*\(/);
55
- expect(source).not.toMatch(/joi/i);
56
- });
57
-
58
- it('loads in a bare context and runs a definition with a fake evaluate and callHost', async () => {
59
- // No `require`, `process`, `URL`, timers nor console: only the language built-ins.
60
- const context = vm.createContext({});
61
- vm.runInContext(source, context);
62
- expect(vm.runInContext('typeof require + typeof process + typeof URL', context)).toBe(
63
- 'undefinedundefinedundefined',
64
- );
65
- const engine = (context as Record<string, unknown>)[ENGINE_GLOBAL_NAME] as Engine;
66
- expect(typeof engine.runInIsolate).toBe('function');
67
-
68
- const values: Record<string, unknown> = {
69
- 'input.n * 2': 42,
70
- 'https://api.example.com/{{ vars.n }}': 'https://api.example.com/42',
71
- 'vars.n': 42,
72
- };
73
- const calls: Array<{ stepId: string; capability: string; args: unknown }> = [];
74
- const progress: string[] = [];
75
- const host: EngineHost = {
76
- evaluate: async (items: EvaluationItem[]) =>
77
- items.map((item) => ({ id: item.id, ok: true as const, value: values[item.source] })),
78
- callHost: async (stepId, capability, args) => {
79
- calls.push({ stepId, capability, args });
80
- return {
81
- ok: true,
82
- value:
83
- capability === CoreCapability.HTTP_FETCH
84
- ? { status: 200, headers: {}, body: null }
85
- : null,
86
- };
87
- },
88
- onProgress: (p) => progress.push(`${p.stepId}:${p.phase}`),
89
- now: () => 0,
90
- };
91
-
92
- const result = await engine.runInIsolate(
93
- {
94
- definition,
95
- input: { n: 21 },
96
- capabilities: [CoreCapability.HTTP_FETCH, CoreCapability.LOG_WRITE],
97
- budget: { maxSteps: 10, maxEffects: 10 },
98
- },
99
- host,
100
- );
101
-
102
- // Values built in the other realm: compare their JSON.
103
- expect(JSON.parse(JSON.stringify(result))).toEqual({
104
- kind: EngineResultKind.FINISHED,
105
- outcome: { status: ExecutionStatus.SUCCEEDED, output: 42 },
106
- });
107
- expect(JSON.parse(JSON.stringify(calls))).toEqual([
108
- {
109
- stepId: 'fetch',
110
- capability: CoreCapability.HTTP_FETCH,
111
- args: { method: 'GET', url: 'https://api.example.com/42', headers: {} },
112
- },
113
- {
114
- stepId: 'note',
115
- capability: CoreCapability.LOG_WRITE,
116
- args: { level: LogLevel.INFO, message: 'fetched' },
117
- },
118
- ]);
119
- expect(progress).toHaveLength(8);
120
- });
121
- });
1
+ import * as vm from 'vm';
2
+ import { AccessKind } from '../access/access.types';
3
+ import {
4
+ CURRENT_FORMAT_VERSION,
5
+ HttpMethod,
6
+ LogLevel,
7
+ StepType,
8
+ StopStatus,
9
+ } from '../definition/definition.types';
10
+ import type { RuntimeDefinition } from '../definition/definition.types';
11
+ import { ENGINE_GLOBAL_NAME } from '../engine/engine-global';
12
+ import { EngineResultKind } from '../engine/run-in-isolate';
13
+ import type { EngineHost, EngineRequest, EngineResult } from '../engine/run-in-isolate';
14
+ import type { EvaluationItem } from '../runner-protocol/evaluation.types';
15
+ import { CoreCapability, ExecutionStatus } from '../runner-protocol/execution-protocol.types';
16
+
17
+ // The build script is plain CommonJS, shared with `build`: the test bundles exactly what ships.
18
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
19
+ const { bundleEngine } = require('../../scripts/build-engine.cjs') as {
20
+ bundleEngine: (globalName: string) => string;
21
+ };
22
+
23
+ type Engine = { runInIsolate: (request: EngineRequest, host: EngineHost) => Promise<EngineResult> };
24
+
25
+ const definition: RuntimeDefinition = {
26
+ formatVersion: CURRENT_FORMAT_VERSION,
27
+ accesses: [{ kind: AccessKind.HTTP, hosts: ['api.example.com'] }],
28
+ steps: [
29
+ { id: 'double', type: StepType.SET, variable: 'n', value: { $expression: 'input.n * 2' } },
30
+ {
31
+ id: 'fetch',
32
+ type: StepType.HTTP,
33
+ method: HttpMethod.GET,
34
+ url: 'https://api.example.com/{{ vars.n }}',
35
+ },
36
+ { id: 'note', type: StepType.LOG, level: LogLevel.INFO, message: 'fetched' },
37
+ {
38
+ id: 'end',
39
+ type: StepType.STOP,
40
+ status: StopStatus.SUCCEEDED,
41
+ output: { $expression: 'vars.n' },
42
+ },
43
+ ],
44
+ };
45
+
46
+ describe('isolate engine bundle', () => {
47
+ let source: string;
48
+
49
+ beforeAll(() => {
50
+ source = bundleEngine(ENGINE_GLOBAL_NAME);
51
+ });
52
+
53
+ it('carries no module loader and no Joi', () => {
54
+ expect(source).not.toMatch(/\brequire\s*\(/);
55
+ expect(source).not.toMatch(/joi/i);
56
+ });
57
+
58
+ it('loads in a bare context and runs a definition with a fake evaluate and callHost', async () => {
59
+ // No `require`, `process`, `URL`, timers nor console: only the language built-ins.
60
+ const context = vm.createContext({});
61
+ vm.runInContext(source, context);
62
+ expect(vm.runInContext('typeof require + typeof process + typeof URL', context)).toBe(
63
+ 'undefinedundefinedundefined',
64
+ );
65
+ const engine = (context as Record<string, unknown>)[ENGINE_GLOBAL_NAME] as Engine;
66
+ expect(typeof engine.runInIsolate).toBe('function');
67
+
68
+ const values: Record<string, unknown> = {
69
+ 'input.n * 2': 42,
70
+ 'https://api.example.com/{{ vars.n }}': 'https://api.example.com/42',
71
+ 'vars.n': 42,
72
+ };
73
+ const calls: Array<{ stepId: string; capability: string; args: unknown }> = [];
74
+ const progress: string[] = [];
75
+ const host: EngineHost = {
76
+ evaluate: async (items: EvaluationItem[]) =>
77
+ items.map((item) => ({ id: item.id, ok: true as const, value: values[item.source] })),
78
+ callHost: async (stepId, capability, args) => {
79
+ calls.push({ stepId, capability, args });
80
+ return {
81
+ ok: true,
82
+ value:
83
+ capability === CoreCapability.HTTP_FETCH
84
+ ? { status: 200, headers: {}, body: null }
85
+ : null,
86
+ };
87
+ },
88
+ onProgress: (p) => progress.push(`${p.stepId}:${p.phase}`),
89
+ now: () => 0,
90
+ };
91
+
92
+ const result = await engine.runInIsolate(
93
+ {
94
+ definition,
95
+ input: { n: 21 },
96
+ capabilities: [CoreCapability.HTTP_FETCH, CoreCapability.LOG_WRITE],
97
+ budget: { maxSteps: 10, maxEffects: 10 },
98
+ },
99
+ host,
100
+ );
101
+
102
+ // Values built in the other realm: compare their JSON.
103
+ expect(JSON.parse(JSON.stringify(result))).toEqual({
104
+ kind: EngineResultKind.FINISHED,
105
+ outcome: { status: ExecutionStatus.SUCCEEDED, output: 42 },
106
+ });
107
+ expect(JSON.parse(JSON.stringify(calls))).toEqual([
108
+ {
109
+ stepId: 'fetch',
110
+ capability: CoreCapability.HTTP_FETCH,
111
+ args: { method: 'GET', url: 'https://api.example.com/42', headers: {} },
112
+ },
113
+ {
114
+ stepId: 'note',
115
+ capability: CoreCapability.LOG_WRITE,
116
+ args: { level: LogLevel.INFO, message: 'fetched' },
117
+ },
118
+ ]);
119
+ expect(progress).toHaveLength(8);
120
+ });
121
+ });