@abyss-project/reflex 6.3.0 → 6.6.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 (123) hide show
  1. package/.prettierrc +5 -5
  2. package/dist/api/function-run.api.d.ts +3 -1
  3. package/dist/api/function-run.api.js +5 -1
  4. package/dist/api/function-run.api.js.map +1 -1
  5. package/dist/api/function-settings.api.d.ts +3 -1
  6. package/dist/api/function-settings.api.js +7 -1
  7. package/dist/api/function-settings.api.js.map +1 -1
  8. package/dist/api/index.d.ts +1 -0
  9. package/dist/api/index.js +1 -0
  10. package/dist/api/index.js.map +1 -1
  11. package/dist/api/storage-surplus.admin.api.d.ts +5 -0
  12. package/dist/api/storage-surplus.admin.api.js +17 -0
  13. package/dist/api/storage-surplus.admin.api.js.map +1 -0
  14. package/dist/discord/discord-command-tree.d.ts +5 -0
  15. package/dist/discord/discord-command-tree.js +38 -0
  16. package/dist/discord/discord-command-tree.js.map +1 -0
  17. package/dist/discord/discord-event-filter-cases.js +27 -11
  18. package/dist/discord/discord-event-filter-cases.js.map +1 -1
  19. package/dist/discord/discord-event-filters.js +7 -3
  20. package/dist/discord/discord-event-filters.js.map +1 -1
  21. package/dist/discord/discord-event-intents.d.ts +8 -2
  22. package/dist/discord/discord-event-intents.js +13 -2
  23. package/dist/discord/discord-event-intents.js.map +1 -1
  24. package/dist/discord/index.d.ts +1 -0
  25. package/dist/discord/index.js +1 -0
  26. package/dist/discord/index.js.map +1 -1
  27. package/dist/index.d.ts +17 -0
  28. package/dist/index.js +20 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/types/enum/discord-command-node-type.enum.d.ts +5 -0
  31. package/dist/types/enum/discord-command-node-type.enum.js +10 -0
  32. package/dist/types/enum/discord-command-node-type.enum.js.map +1 -0
  33. package/dist/types/enum/discord-command-type.enum.d.ts +5 -0
  34. package/dist/types/enum/discord-command-type.enum.js +10 -0
  35. package/dist/types/enum/discord-command-type.enum.js.map +1 -0
  36. package/dist/types/enum/discord-event-type.enum.d.ts +3 -1
  37. package/dist/types/enum/discord-event-type.enum.js +2 -0
  38. package/dist/types/enum/discord-event-type.enum.js.map +1 -1
  39. package/dist/types/enum/index.d.ts +2 -0
  40. package/dist/types/enum/index.js +2 -0
  41. package/dist/types/enum/index.js.map +1 -1
  42. package/dist/types/enum/reflex-error-code.enum.d.ts +14 -1
  43. package/dist/types/enum/reflex-error-code.enum.js +13 -0
  44. package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
  45. package/dist/types/interface/api/requests/application-run-settings.request.d.ts +1 -0
  46. package/dist/types/interface/api/requests/function-run.request.d.ts +16 -0
  47. package/dist/types/interface/api/requests/function-settings.request.d.ts +12 -0
  48. package/dist/types/interface/api/requests/index.d.ts +1 -0
  49. package/dist/types/interface/api/requests/index.js +1 -0
  50. package/dist/types/interface/api/requests/index.js.map +1 -1
  51. package/dist/types/interface/api/requests/service-discord.request.d.ts +7 -3
  52. package/dist/types/interface/api/requests/service.request.d.ts +1 -0
  53. package/dist/types/interface/api/requests/storage-surplus.admin.request.d.ts +8 -0
  54. package/dist/types/interface/api/requests/storage-surplus.admin.request.js +3 -0
  55. package/dist/types/interface/api/requests/storage-surplus.admin.request.js.map +1 -0
  56. package/dist/types/interface/api/responses/function-run.response.d.ts +12 -0
  57. package/dist/types/interface/api/responses/function-settings.response.d.ts +5 -1
  58. package/dist/types/interface/api/responses/index.d.ts +1 -0
  59. package/dist/types/interface/api/responses/index.js +1 -0
  60. package/dist/types/interface/api/responses/index.js.map +1 -1
  61. package/dist/types/interface/api/responses/storage-surplus.admin.response.d.ts +8 -0
  62. package/dist/types/interface/api/responses/storage-surplus.admin.response.js +3 -0
  63. package/dist/types/interface/api/responses/storage-surplus.admin.response.js.map +1 -0
  64. package/dist/types/interface/models/index.d.ts +2 -0
  65. package/dist/types/interface/models/index.js +2 -0
  66. package/dist/types/interface/models/index.js.map +1 -1
  67. package/dist/types/interface/models/reflex-discord.model.d.ts +18 -2
  68. package/dist/types/interface/models/reflex-discord.model.js +4 -0
  69. package/dist/types/interface/models/reflex-discord.model.js.map +1 -1
  70. package/dist/types/interface/models/reflex-run-retention.model.d.ts +13 -0
  71. package/dist/types/interface/models/reflex-run-retention.model.js +8 -0
  72. package/dist/types/interface/models/reflex-run-retention.model.js.map +1 -0
  73. package/dist/types/interface/models/reflex-run-settings.model.d.ts +4 -0
  74. package/dist/types/interface/models/reflex-run.model.d.ts +9 -0
  75. package/dist/types/interface/models/reflex-run.model.js +4 -1
  76. package/dist/types/interface/models/reflex-run.model.js.map +1 -1
  77. package/dist/types/interface/models/reflex-service-deployment.model.d.ts +2 -2
  78. package/dist/types/interface/models/reflex-service.model.d.ts +1 -0
  79. package/dist/types/interface/models/reflex-storage-surplus.model.d.ts +11 -0
  80. package/dist/types/interface/models/reflex-storage-surplus.model.js +3 -0
  81. package/dist/types/interface/models/reflex-storage-surplus.model.js.map +1 -0
  82. package/package.json +1 -1
  83. package/src/api/application-run-settings.api.test.ts +62 -51
  84. package/src/api/function-run.api.ts +34 -0
  85. package/src/api/function-settings.api.ts +96 -74
  86. package/src/api/function.api.test.ts +346 -291
  87. package/src/api/index.ts +27 -26
  88. package/src/api/service.api.test.ts +220 -215
  89. package/src/api/storage-surplus.admin.api.test.ts +66 -0
  90. package/src/api/storage-surplus.admin.api.ts +45 -0
  91. package/src/discord/discord-command-tree.test.ts +47 -0
  92. package/src/discord/discord-command-tree.ts +60 -0
  93. package/src/discord/discord-event-filter-cases.ts +54 -16
  94. package/src/discord/discord-event-filters.test.ts +33 -4
  95. package/src/discord/discord-event-filters.ts +13 -5
  96. package/src/discord/discord-event-intents.test.ts +27 -0
  97. package/src/discord/discord-event-intents.ts +31 -6
  98. package/src/discord/index.ts +1 -0
  99. package/src/index.ts +44 -0
  100. package/src/types/enum/discord-command-node-type.enum.ts +10 -0
  101. package/src/types/enum/discord-command-type.enum.ts +9 -0
  102. package/src/types/enum/discord-event-type.enum.ts +4 -0
  103. package/src/types/enum/index.ts +2 -0
  104. package/src/types/enum/reflex-error-code.enum.ts +112 -73
  105. package/src/types/interface/api/requests/application-run-settings.request.ts +13 -11
  106. package/src/types/interface/api/requests/function-run.request.ts +53 -32
  107. package/src/types/interface/api/requests/function-settings.request.ts +50 -34
  108. package/src/types/interface/api/requests/index.ts +25 -24
  109. package/src/types/interface/api/requests/service-discord.request.ts +19 -6
  110. package/src/types/interface/api/requests/service.request.ts +48 -46
  111. package/src/types/interface/api/requests/storage-surplus.admin.request.ts +12 -0
  112. package/src/types/interface/api/responses/function-run.response.ts +35 -18
  113. package/src/types/interface/api/responses/function-settings.response.ts +57 -50
  114. package/src/types/interface/api/responses/index.ts +25 -24
  115. package/src/types/interface/api/responses/storage-surplus.admin.response.ts +10 -0
  116. package/src/types/interface/models/index.ts +29 -27
  117. package/src/types/interface/models/reflex-discord.model.ts +45 -4
  118. package/src/types/interface/models/reflex-run-retention.model.ts +24 -0
  119. package/src/types/interface/models/reflex-run-settings.model.ts +39 -28
  120. package/src/types/interface/models/reflex-run.model.ts +317 -299
  121. package/src/types/interface/models/reflex-service-deployment.model.ts +48 -46
  122. package/src/types/interface/models/reflex-service.model.ts +47 -45
  123. package/src/types/interface/models/reflex-storage-surplus.model.ts +23 -0
@@ -1,299 +1,317 @@
1
- import type {
2
- ExecutionMode,
3
- ExecutionProfile,
4
- LogDropCause,
5
- RunLogLevel,
6
- RunMode,
7
- RunStatus,
8
- RunStepStatus,
9
- ScheduledRunOrigin,
10
- TraceEffectType,
11
- } from '../../enum';
12
- import type { IReflexCompletionDelivery } from './reflex-completion-webhook.model';
13
- import type { IReflexContractError } from './reflex-route-contract.model';
14
-
15
- export interface IReflexTraceError {
16
- code: string;
17
- message: string;
18
- }
19
-
20
- /** Where the code of a step failed: the step and the line and column of its source. */
21
- export interface IReflexRunErrorLocation {
22
- stepId: string;
23
- line: number;
24
- column: number;
25
- }
26
-
27
- /** The error of a run: where it failed (`stepId`, `line`, `column`) and the frames of the client code, when known. */
28
- export interface IReflexTraceOutcomeError extends IReflexTraceError {
29
- stepId?: string;
30
- line?: number;
31
- column?: number;
32
- /** Frames of the client code only, `step:<id>:<line>:<column>`, masked. */
33
- stack?: string;
34
- }
35
-
36
- /** The HTTP request a route received, masked. */
37
- export interface IReflexTraceRequest {
38
- method: string;
39
- path: string;
40
- query: Record<string, string | string[]>;
41
- headers: Record<string, string>;
42
- body: unknown;
43
- }
44
-
45
- /** What one step that succeeded returned; `outputTruncated` when the runner cut its output. */
46
- export interface IReflexTraceStep {
47
- stepId: string;
48
- output?: unknown;
49
- outputTruncated: boolean;
50
- }
51
-
52
- /** Bounds of the detail a LIVE run keeps, in bytes of the UTF-8 JSON after masking (the budget is spent in this order). */
53
- export const REFLEX_RUN_DETAIL_LIMITS = {
54
- /** The whole detail. */
55
- totalBytes: 65_536,
56
- /** The error: message and stack. */
57
- errorBytes: 4_096,
58
- /** The request without its body: method, path, query, headers. */
59
- requestMetaBytes: 8_192,
60
- /** The body of the request, or the input of the run. */
61
- requestBodyBytes: 16_384,
62
- /** The response, or the output of the run. */
63
- responseBytes: 16_384,
64
- /** One step output or one effect, until the rest of the budget is spent. */
65
- entryBytes: 4_096,
66
- } as const;
67
-
68
- /**
69
- * One call the run made to the host, in the order they were served. `recorded` is true when the effect
70
- * was recorded instead of executed (a stubbed HTTP call, a Store write kept aside, a wait not waited).
71
- */
72
- export interface IReflexTraceEntry {
73
- stepId: string;
74
- type: TraceEffectType;
75
- /** The host action, for a HOST effect. */
76
- action?: string;
77
- request?: unknown;
78
- response?: unknown;
79
- error?: IReflexTraceError;
80
- recorded: boolean;
81
- }
82
-
83
- /** What the RESPOND step (or `abyss.respond`) built: the response the caller of the route would get. */
84
- export interface IReflexTraceResponse {
85
- status: number;
86
- headers: Record<string, string>;
87
- body: unknown;
88
- }
89
-
90
- /**
91
- * Bounded: past 100 entries, or a value of more than 4 KB, the trace is cut and says so (`truncated`); a LIVE run
92
- * keeps at most `REFLEX_RUN_DETAIL_LIMITS.totalBytes`. Every secret value the run was given or read is masked (`***`).
93
- */
94
- export interface IReflexRunTrace {
95
- /** The HTTP request, for a run a route started. */
96
- request?: IReflexTraceRequest;
97
- /** The payload the function received, for a run a command, a component, a task, a delayed run or an event started. */
98
- input?: unknown;
99
- /** The faults of the request against the contract of its route, for a REFUSED run; absent otherwise. */
100
- requestErrors?: IReflexContractError[];
101
- entries: IReflexTraceEntry[];
102
- /** The output of each step that succeeded, in order. */
103
- steps?: IReflexTraceStep[];
104
- outcome: {
105
- status: RunStatus;
106
- output?: unknown;
107
- error?: IReflexTraceOutcomeError;
108
- };
109
- response?: IReflexTraceResponse;
110
- truncated: boolean;
111
- /** Paths of the fields that were cut, for example `request.body` or `entries[3].response`. */
112
- truncatedFields: string[];
113
- }
114
-
115
- export interface IReflexRun {
116
- id: string;
117
- functionId: string;
118
- versionId: string | null;
119
- /**
120
- * The environment the run took place in: the promoted version's for a LIVE run, the one named in the
121
- * request for a test run. Null only for a test run recorded before test runs named an environment.
122
- */
123
- environmentId: string | null;
124
- mode: RunMode;
125
- status: RunStatus;
126
- durationMs: number;
127
- /** The effects of a test run; null for a LIVE run, which records no trace (nothing of the caller is kept). */
128
- trace: IReflexRunTrace | null;
129
- /** The route that started a LIVE run; null for a test run and for a run a Discord command or component started. */
130
- routeId: string | null;
131
- /** The Discord command that started a LIVE run; null otherwise. */
132
- commandId: string | null;
133
- /** The Discord component that started a LIVE run; null otherwise. */
134
- componentId: string | null;
135
- /** The task that started a LIVE run, by a tick of its cron or a delayed run; null otherwise. */
136
- taskId: string | null;
137
- /** The event trigger that started a LIVE run; null otherwise. */
138
- eventTriggerId: string | null;
139
- /**
140
- * Monitor trace id of the run (32 hex characters; for an event, the id of its inbox row without dashes, the same
141
- * at every attempt); null when the run was not sent to Monitor (non-bot Service, HTTP route).
142
- */
143
- traceId: string | null;
144
- /** How the task started the run: RECURRING for a tick of its cron, DELAYED for a delayed run; null when no task did. */
145
- scheduledRunOrigin: ScheduledRunOrigin | null;
146
- /**
147
- * What started the run, for a screen: `METHOD path` for a route, `/name` for a command, the custom id
148
- * prefix for a component, the name for a task or an event trigger. Null for a test run, and when the route, command,
149
- * component, task or event trigger was deleted.
150
- */
151
- originLabel: string | null;
152
- /** The HTTP status the caller of a LIVE run got; null for a test run. */
153
- httpStatus: number | null;
154
- /**
155
- * The code of the error a failed LIVE run answered (FUNCTION_FAILED, FUNCTION_TIMEOUT, RUNNER_UNAVAILABLE,
156
- * RUNNER_SATURATED, INTERNAL_ERROR), or REQUEST_INVALID for a REFUSED one; null otherwise, an interrupted run included.
157
- */
158
- errorCode: string | null;
159
- /** The message of the error of a failed run, masked, 2048 characters at most; null when none was kept. */
160
- errorMessage: string | null;
161
- /** Where the code of a step failed; null when the error is not one of client code, or none was kept. */
162
- errorLocation: IReflexRunErrorLocation | null;
163
- /** The browser session (Monitor RUM) that sent the request; null when none. */
164
- rumSessionId: string | null;
165
- /** Whether the application sends its runs to Monitor. */
166
- monitorActivated: boolean;
167
- /** The execution mode of the function when a LIVE run started; null for a test run. */
168
- executionMode: ExecutionMode | null;
169
- /** When the caller of a LIVE run got its answer; null for a test run, or before any answer. */
170
- responseSentAt: Date | null;
171
- /**
172
- * What the run consumed and cost: measured by the runner for a live run and for a test run (with the
173
- * function's effective settings in the run's environment, and the network of its stubs); null for a running execution, or a run
174
- * recorded before the measures.
175
- */
176
- metrics: IReflexRunMetrics | null;
177
- /** The consumer whose key called the route; null for a test run, and for a run no `API_KEY` route started. */
178
- consumer: IReflexRunConsumer | null;
179
- /** The faults of the request against the contract of its route, for a REFUSED run; absent otherwise. */
180
- requestErrors?: IReflexContractError[];
181
- /** The answer the function built, for an async LIVE run that finished; absent otherwise. */
182
- completion?: IReflexExecutionCompletion;
183
- /** The completion webhook of an async LIVE run, with its attempts; absent when none was due. */
184
- delivery?: IReflexCompletionDelivery;
185
- createdByUserId: string | null;
186
- createdAt: Date;
187
- }
188
-
189
- /** The consumer of a Service that called a route, as the edge passed it to the function. */
190
- export interface IReflexRunConsumer {
191
- id: string;
192
- name: string;
193
- }
194
-
195
- /**
196
- * The answer the function of an async execution built once it finished: the caller got 202 at once, this is
197
- * what the completion webhook and `_executions` give it.
198
- */
199
- export interface IReflexExecutionCompletion {
200
- httpStatus: number;
201
- /** The body of the answer; null when none, or when it was cut. */
202
- output: unknown | null;
203
- /** True when the output went past `REFLEX_COMPLETION_WEBHOOK_LIMITS.outputMaxBytes`. */
204
- outputTruncated: boolean;
205
- }
206
-
207
- /** What a live execution consumed, and what it costs (ADR-0244). */
208
- export interface IReflexRunMetrics {
209
- /** The profile it ran with, and the memory that profile allocates. */
210
- profile: ExecutionProfile;
211
- memoryLimitMb: number;
212
- /** Measured by the runner in the isolate. */
213
- cpuMs: number;
214
- heapPeakBytes: number;
215
- /** Measured by the host: bytes sent and received by `fetch`, plus the answer sent to the caller. */
216
- netOutBytes: number;
217
- netInBytes: number;
218
- httpCalls: number;
219
- storeWrites: number;
220
- /** In thousandths of a credit; 0 for an interrupted execution, which is offered. */
221
- costMillicredits: number;
222
- }
223
-
224
- /** What one step of a run consumed; its cost is its share of the run's, the fixed price aside. */
225
- export interface IReflexRunStep {
226
- /** 0 for the first step that ran. */
227
- position: number;
228
- stepId: string;
229
- status: RunStepStatus;
230
- durationMs: number;
231
- cpuMs: number;
232
- heapPeakBytes: number;
233
- netOutBytes: number;
234
- netInBytes: number;
235
- httpCalls: number;
236
- storeWrites: number;
237
- costMillicredits: number;
238
- }
239
-
240
- /**
241
- * One log line a run wrote: a LOG step, `abyss.log.*` or `console.*`. Secrets masked (`***`); a message
242
- * is cut at 2048 characters, and data whose JSON is longer becomes `{ truncated: true, preview }`. The lines
243
- * past the cap in force or the technical bound are not kept; `IReflexRunDetail.droppedLogLines` counts them.
244
- */
245
- export interface IReflexRunLog {
246
- /** 0 for the first line. */
247
- position: number;
248
- /** The step that wrote it. */
249
- stepId: string;
250
- level: RunLogLevel;
251
- message: string;
252
- /** The value given with the message; null when none was. */
253
- data: unknown;
254
- loggedAt: Date;
255
- }
256
-
257
- /**
258
- * One run with the steps it ran and the lines it logged, in order. Both are empty for a run recorded
259
- * before the measures (and the steps for a running execution).
260
- */
261
- export interface IReflexRunDetail extends IReflexRun {
262
- steps: IReflexRunStep[];
263
- logs: IReflexRunLog[];
264
- /** The log lines written and not kept in `logs`; 0 when none was dropped. */
265
- droppedLogLines: number;
266
- /** Why lines were dropped; null when none was. */
267
- droppedLogCause: LogDropCause | null;
268
- }
269
-
270
- /**
271
- * The state of a live execution, read by its id (the `executionId` an async route answers with): by a member
272
- * through the API (`function.run.state`), and by the consumer that started it through the edge
273
- * (`GET .../_executions/:executionId`).
274
- */
275
- export interface IReflexExecutionState {
276
- id: string;
277
- status: RunStatus;
278
- executionMode: ExecutionMode;
279
- startedAt: Date;
280
- /** When the caller got its answer; for an async execution, the 202. */
281
- responseSentAt: Date | null;
282
- /** Null while it runs. */
283
- finishedAt: Date | null;
284
- /**
285
- * The status the caller got; for an async execution that finished, the status of the answer the function
286
- * built (202 while it runs).
287
- */
288
- httpStatus: number;
289
- /** Set when the execution failed. */
290
- errorCode: string | null;
291
- /** Null while it runs, or for an execution recorded before the measures. */
292
- costMillicredits: number | null;
293
- /** The body of the answer of an async execution that finished; null otherwise, or when it was cut. */
294
- output: unknown | null;
295
- /** True when the output went past `REFLEX_COMPLETION_WEBHOOK_LIMITS.outputMaxBytes`. */
296
- outputTruncated: boolean;
297
- /** Set when the execution failed. */
298
- error: { code: string; message: string } | null;
299
- }
1
+ import type {
2
+ ExecutionMode,
3
+ ExecutionProfile,
4
+ LogDropCause,
5
+ RunLogLevel,
6
+ RunMode,
7
+ RunStatus,
8
+ RunStepStatus,
9
+ ScheduledRunOrigin,
10
+ TraceEffectType,
11
+ } from '../../enum';
12
+ import type { IReflexCompletionDelivery } from './reflex-completion-webhook.model';
13
+ import type { IReflexContractError } from './reflex-route-contract.model';
14
+
15
+ export interface IReflexTraceError {
16
+ code: string;
17
+ message: string;
18
+ }
19
+
20
+ /** Where the code of a step failed: the step and the line and column of its source. */
21
+ export interface IReflexRunErrorLocation {
22
+ stepId: string;
23
+ line: number;
24
+ column: number;
25
+ }
26
+
27
+ /** The error of a run: where it failed (`stepId`, `line`, `column`) and the frames of the client code, when known. */
28
+ export interface IReflexTraceOutcomeError extends IReflexTraceError {
29
+ stepId?: string;
30
+ line?: number;
31
+ column?: number;
32
+ /** Frames of the client code only, `step:<id>:<line>:<column>`, masked. */
33
+ stack?: string;
34
+ }
35
+
36
+ /** The HTTP request a route received, masked. */
37
+ export interface IReflexTraceRequest {
38
+ method: string;
39
+ path: string;
40
+ query: Record<string, string | string[]>;
41
+ headers: Record<string, string>;
42
+ body: unknown;
43
+ }
44
+
45
+ /** What one step that succeeded returned; `outputTruncated` when the runner cut its output. */
46
+ export interface IReflexTraceStep {
47
+ stepId: string;
48
+ output?: unknown;
49
+ outputTruncated: boolean;
50
+ }
51
+
52
+ /** Bounds of the detail a LIVE run keeps, in bytes of the UTF-8 JSON after masking (the budget is spent in this order). */
53
+ export const REFLEX_RUN_DETAIL_LIMITS = {
54
+ /** The whole detail. */
55
+ totalBytes: 65_536,
56
+ /** The error: message and stack. */
57
+ errorBytes: 4_096,
58
+ /** The request without its body: method, path, query, headers. */
59
+ requestMetaBytes: 8_192,
60
+ /** The body of the request, or the input of the run. */
61
+ requestBodyBytes: 16_384,
62
+ /** The response, or the output of the run. */
63
+ responseBytes: 16_384,
64
+ /** One step output or one effect, until the rest of the budget is spent. */
65
+ entryBytes: 4_096,
66
+ } as const;
67
+
68
+ /**
69
+ * One call the run made to the host, in the order they were served. `recorded` is true when the effect
70
+ * was recorded instead of executed (a stubbed HTTP call, a Store write kept aside, a wait not waited).
71
+ */
72
+ export interface IReflexTraceEntry {
73
+ stepId: string;
74
+ type: TraceEffectType;
75
+ /** The host action, for a HOST effect. */
76
+ action?: string;
77
+ request?: unknown;
78
+ response?: unknown;
79
+ error?: IReflexTraceError;
80
+ recorded: boolean;
81
+ }
82
+
83
+ /** What the RESPOND step (or `abyss.respond`) built: the response the caller of the route would get. */
84
+ export interface IReflexTraceResponse {
85
+ status: number;
86
+ headers: Record<string, string>;
87
+ body: unknown;
88
+ }
89
+
90
+ /**
91
+ * Bounded: past 100 entries, or a value of more than 4 KB, the trace is cut and says so (`truncated`); a LIVE run
92
+ * keeps at most `REFLEX_RUN_DETAIL_LIMITS.totalBytes`. Every secret value the run was given or read is masked (`***`).
93
+ */
94
+ export interface IReflexRunTrace {
95
+ /** The HTTP request, for a run a route started. */
96
+ request?: IReflexTraceRequest;
97
+ /** The payload the function received, for a run a command, a component, a task, a delayed run or an event started. */
98
+ input?: unknown;
99
+ /** The faults of the request against the contract of its route, for a REFUSED run; absent otherwise. */
100
+ requestErrors?: IReflexContractError[];
101
+ entries: IReflexTraceEntry[];
102
+ /** The output of each step that succeeded, in order. */
103
+ steps?: IReflexTraceStep[];
104
+ outcome: {
105
+ status: RunStatus;
106
+ output?: unknown;
107
+ error?: IReflexTraceOutcomeError;
108
+ };
109
+ response?: IReflexTraceResponse;
110
+ truncated: boolean;
111
+ /** Paths of the fields that were cut, for example `request.body` or `entries[3].response`. */
112
+ truncatedFields: string[];
113
+ }
114
+
115
+ /** Bounds of the replay of a run of a Discord event trigger (card 943). */
116
+ export const REFLEX_REPLAY_LIMITS = {
117
+ /** Real replays per bot and environment over a rolling minute. */
118
+ liveReplaysPerMinute: 10,
119
+ } as const;
120
+
121
+ export interface IReflexRun {
122
+ id: string;
123
+ functionId: string;
124
+ versionId: string | null;
125
+ /**
126
+ * The environment the run took place in: the promoted version's for a LIVE run, the one named in the
127
+ * request for a test run. Null only for a test run recorded before test runs named an environment.
128
+ */
129
+ environmentId: string | null;
130
+ mode: RunMode;
131
+ status: RunStatus;
132
+ durationMs: number;
133
+ /** The effects of a test run; null for a LIVE run, which records no trace (nothing of the caller is kept). */
134
+ trace: IReflexRunTrace | null;
135
+ /** The route that started a LIVE run; null for a test run and for a run a Discord command or component started. */
136
+ routeId: string | null;
137
+ /** The Discord command that started a LIVE run; null otherwise. */
138
+ commandId: string | null;
139
+ /** The Discord component that started a LIVE run; null otherwise. */
140
+ componentId: string | null;
141
+ /** The task that started a LIVE run, by a tick of its cron or a delayed run; null otherwise. */
142
+ taskId: string | null;
143
+ /** The event trigger that started a LIVE run; null otherwise. */
144
+ eventTriggerId: string | null;
145
+ /** The live run a real replay re-ran; null for any other run. */
146
+ replayOfRunId: string | null;
147
+ /**
148
+ * Monitor trace id of the run (32 hex characters; for an event, the id of its inbox row without dashes, the same
149
+ * at every attempt); null when the run was not sent to Monitor (non-bot Service, HTTP route).
150
+ */
151
+ traceId: string | null;
152
+ /** How the task started the run: RECURRING for a tick of its cron, DELAYED for a delayed run; null when no task did. */
153
+ scheduledRunOrigin: ScheduledRunOrigin | null;
154
+ /**
155
+ * What started the run, for a screen: `METHOD path` for a route, `/name` for a command, the custom id
156
+ * prefix for a component, the name for a task or an event trigger. Null for a test run, and when the route, command,
157
+ * component, task or event trigger was deleted.
158
+ */
159
+ originLabel: string | null;
160
+ /** The HTTP status the caller of a LIVE run got; null for a test run. */
161
+ httpStatus: number | null;
162
+ /**
163
+ * The code of the error a failed LIVE run answered (FUNCTION_FAILED, FUNCTION_TIMEOUT, RUNNER_UNAVAILABLE,
164
+ * RUNNER_SATURATED, INTERNAL_ERROR), or REQUEST_INVALID for a REFUSED one; null otherwise, an interrupted run included.
165
+ */
166
+ errorCode: string | null;
167
+ /** The message of the error of a failed run, masked, 2048 characters at most; null when none was kept. */
168
+ errorMessage: string | null;
169
+ /** Where the code of a step failed; null when the error is not one of client code, or none was kept. */
170
+ errorLocation: IReflexRunErrorLocation | null;
171
+ /** The browser session (Monitor RUM) that sent the request; null when none. */
172
+ rumSessionId: string | null;
173
+ /** Whether the application sends its runs to Monitor. */
174
+ monitorActivated: boolean;
175
+ /** The execution mode of the function when a LIVE run started; null for a test run. */
176
+ executionMode: ExecutionMode | null;
177
+ /** When the caller of a LIVE run got its answer; null for a test run, or before any answer. */
178
+ responseSentAt: Date | null;
179
+ /**
180
+ * What the run consumed and cost: measured by the runner for a live run and for a test run (with the
181
+ * function's effective settings in the run's environment, and the network of its stubs); null for a running execution, or a run
182
+ * recorded before the measures.
183
+ */
184
+ metrics: IReflexRunMetrics | null;
185
+ /** The consumer whose key called the route; null for a test run, and for a run no `API_KEY` route started. */
186
+ consumer: IReflexRunConsumer | null;
187
+ /** The faults of the request against the contract of its route, for a REFUSED run; absent otherwise. */
188
+ requestErrors?: IReflexContractError[];
189
+ /** The answer the function built, for an async LIVE run that finished; absent otherwise. */
190
+ completion?: IReflexExecutionCompletion;
191
+ /** The completion webhook of an async LIVE run, with its attempts; absent when none was due. */
192
+ delivery?: IReflexCompletionDelivery;
193
+ createdByUserId: string | null;
194
+ createdAt: Date;
195
+ /** When the run is purged (its start plus the retention in force); null for a test run, and while no retention is known. */
196
+ expiresAt: string | null;
197
+ /** A favorite run is never purged. */
198
+ isFavorite: boolean;
199
+ /** The run was recorded while the owner's storage was cut: no detail, steps or log lines were kept. */
200
+ historyMinimal: boolean;
201
+ /** Bytes the run holds online (detail, steps, log lines); null for a test run, and for a run whose size was never computed. */
202
+ storedBytes: number | null;
203
+ /** When the detail, steps and log lines moved to the customer's archive; null while they are online. */
204
+ detailArchivedAt: string | null;
205
+ }
206
+
207
+ /** The consumer of a Service that called a route, as the edge passed it to the function. */
208
+ export interface IReflexRunConsumer {
209
+ id: string;
210
+ name: string;
211
+ }
212
+
213
+ /**
214
+ * The answer the function of an async execution built once it finished: the caller got 202 at once, this is
215
+ * what the completion webhook and `_executions` give it.
216
+ */
217
+ export interface IReflexExecutionCompletion {
218
+ httpStatus: number;
219
+ /** The body of the answer; null when none, or when it was cut. */
220
+ output: unknown | null;
221
+ /** True when the output went past `REFLEX_COMPLETION_WEBHOOK_LIMITS.outputMaxBytes`. */
222
+ outputTruncated: boolean;
223
+ }
224
+
225
+ /** What a live execution consumed, and what it costs (ADR-0244). */
226
+ export interface IReflexRunMetrics {
227
+ /** The profile it ran with, and the memory that profile allocates. */
228
+ profile: ExecutionProfile;
229
+ memoryLimitMb: number;
230
+ /** Measured by the runner in the isolate. */
231
+ cpuMs: number;
232
+ heapPeakBytes: number;
233
+ /** Measured by the host: bytes sent and received by `fetch`, plus the answer sent to the caller. */
234
+ netOutBytes: number;
235
+ netInBytes: number;
236
+ httpCalls: number;
237
+ storeWrites: number;
238
+ /** In thousandths of a credit; 0 for an interrupted execution, which is offered. */
239
+ costMillicredits: number;
240
+ }
241
+
242
+ /** What one step of a run consumed; its cost is its share of the run's, the fixed price aside. */
243
+ export interface IReflexRunStep {
244
+ /** 0 for the first step that ran. */
245
+ position: number;
246
+ stepId: string;
247
+ status: RunStepStatus;
248
+ durationMs: number;
249
+ cpuMs: number;
250
+ heapPeakBytes: number;
251
+ netOutBytes: number;
252
+ netInBytes: number;
253
+ httpCalls: number;
254
+ storeWrites: number;
255
+ costMillicredits: number;
256
+ }
257
+
258
+ /**
259
+ * One log line a run wrote: a LOG step, `abyss.log.*` or `console.*`. Secrets masked (`***`); a message
260
+ * is cut at 2048 characters, and data whose JSON is longer becomes `{ truncated: true, preview }`. The lines
261
+ * past the cap in force or the technical bound are not kept; `IReflexRunDetail.droppedLogLines` counts them.
262
+ */
263
+ export interface IReflexRunLog {
264
+ /** 0 for the first line. */
265
+ position: number;
266
+ /** The step that wrote it. */
267
+ stepId: string;
268
+ level: RunLogLevel;
269
+ message: string;
270
+ /** The value given with the message; null when none was. */
271
+ data: unknown;
272
+ loggedAt: Date;
273
+ }
274
+
275
+ /**
276
+ * One run with the steps it ran and the lines it logged, in order. Both are empty for a run recorded
277
+ * before the measures (and the steps for a running execution).
278
+ */
279
+ export interface IReflexRunDetail extends IReflexRun {
280
+ steps: IReflexRunStep[];
281
+ logs: IReflexRunLog[];
282
+ /** The log lines written and not kept in `logs`; 0 when none was dropped. */
283
+ droppedLogLines: number;
284
+ /** Why lines were dropped; null when none was. */
285
+ droppedLogCause: LogDropCause | null;
286
+ }
287
+
288
+ /**
289
+ * The state of a live execution, read by its id (the `executionId` an async route answers with): by a member
290
+ * through the API (`function.run.state`), and by the consumer that started it through the edge
291
+ * (`GET .../_executions/:executionId`).
292
+ */
293
+ export interface IReflexExecutionState {
294
+ id: string;
295
+ status: RunStatus;
296
+ executionMode: ExecutionMode;
297
+ startedAt: Date;
298
+ /** When the caller got its answer; for an async execution, the 202. */
299
+ responseSentAt: Date | null;
300
+ /** Null while it runs. */
301
+ finishedAt: Date | null;
302
+ /**
303
+ * The status the caller got; for an async execution that finished, the status of the answer the function
304
+ * built (202 while it runs).
305
+ */
306
+ httpStatus: number;
307
+ /** Set when the execution failed. */
308
+ errorCode: string | null;
309
+ /** Null while it runs, or for an execution recorded before the measures. */
310
+ costMillicredits: number | null;
311
+ /** The body of the answer of an async execution that finished; null otherwise, or when it was cut. */
312
+ output: unknown | null;
313
+ /** True when the output went past `REFLEX_COMPLETION_WEBHOOK_LIMITS.outputMaxBytes`. */
314
+ outputTruncated: boolean;
315
+ /** Set when the execution failed. */
316
+ error: { code: string; message: string } | null;
317
+ }