@abyss-project/reflex 5.4.0 → 5.5.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 (150) hide show
  1. package/dist/api/function-insights.api.d.ts +2 -0
  2. package/dist/api/function-insights.api.js +7 -0
  3. package/dist/api/function-insights.api.js.map +1 -0
  4. package/dist/api/index.d.ts +3 -0
  5. package/dist/api/index.js +3 -0
  6. package/dist/api/index.js.map +1 -1
  7. package/dist/api/service-discord-event.api.d.ts +6 -0
  8. package/dist/api/service-discord-event.api.js +18 -0
  9. package/dist/api/service-discord-event.api.js.map +1 -0
  10. package/dist/api/service-discord.api.d.ts +3 -1
  11. package/dist/api/service-discord.api.js +5 -1
  12. package/dist/api/service-discord.api.js.map +1 -1
  13. package/dist/api/service-insights.api.d.ts +3 -0
  14. package/dist/api/service-insights.api.js +12 -0
  15. package/dist/api/service-insights.api.js.map +1 -0
  16. package/dist/discord/discord-event-filter-cases.d.ts +15 -0
  17. package/dist/discord/discord-event-filter-cases.js +77 -0
  18. package/dist/discord/discord-event-filter-cases.js.map +1 -0
  19. package/dist/discord/discord-event-filters.d.ts +20 -0
  20. package/dist/discord/discord-event-filters.js +50 -0
  21. package/dist/discord/discord-event-filters.js.map +1 -0
  22. package/dist/discord/discord-event-intents.d.ts +14 -0
  23. package/dist/discord/discord-event-intents.js +38 -0
  24. package/dist/discord/discord-event-intents.js.map +1 -0
  25. package/dist/discord/index.d.ts +3 -0
  26. package/dist/discord/index.js +20 -0
  27. package/dist/discord/index.js.map +1 -0
  28. package/dist/index.d.ts +22 -0
  29. package/dist/index.js +22 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/types/enum/bot-event-block-reason.enum.d.ts +4 -0
  32. package/dist/types/enum/bot-event-block-reason.enum.js +9 -0
  33. package/dist/types/enum/bot-event-block-reason.enum.js.map +1 -0
  34. package/dist/types/enum/discord-event-drop-reason.enum.d.ts +7 -0
  35. package/dist/types/enum/discord-event-drop-reason.enum.js +12 -0
  36. package/dist/types/enum/discord-event-drop-reason.enum.js.map +1 -0
  37. package/dist/types/enum/discord-event-filter-name.enum.d.ts +9 -0
  38. package/dist/types/enum/discord-event-filter-name.enum.js +14 -0
  39. package/dist/types/enum/discord-event-filter-name.enum.js.map +1 -0
  40. package/dist/types/enum/discord-event-status.enum.d.ts +7 -0
  41. package/dist/types/enum/discord-event-status.enum.js +12 -0
  42. package/dist/types/enum/discord-event-status.enum.js.map +1 -0
  43. package/dist/types/enum/discord-event-type.enum.d.ts +6 -0
  44. package/dist/types/enum/discord-event-type.enum.js +11 -0
  45. package/dist/types/enum/discord-event-type.enum.js.map +1 -0
  46. package/dist/types/enum/discord-gateway-failure-code.enum.d.ts +2 -1
  47. package/dist/types/enum/discord-gateway-failure-code.enum.js +1 -0
  48. package/dist/types/enum/discord-gateway-failure-code.enum.js.map +1 -1
  49. package/dist/types/enum/index.d.ts +7 -0
  50. package/dist/types/enum/index.js +7 -0
  51. package/dist/types/enum/index.js.map +1 -1
  52. package/dist/types/enum/insights-period.enum.d.ts +7 -0
  53. package/dist/types/enum/insights-period.enum.js +12 -0
  54. package/dist/types/enum/insights-period.enum.js.map +1 -0
  55. package/dist/types/enum/scheduled-run-failure-code.enum.d.ts +2 -1
  56. package/dist/types/enum/scheduled-run-failure-code.enum.js +1 -0
  57. package/dist/types/enum/scheduled-run-failure-code.enum.js.map +1 -1
  58. package/dist/types/enum/trigger-kind.enum.d.ts +7 -0
  59. package/dist/types/enum/trigger-kind.enum.js +12 -0
  60. package/dist/types/enum/trigger-kind.enum.js.map +1 -0
  61. package/dist/types/interface/api/requests/index.d.ts +2 -0
  62. package/dist/types/interface/api/requests/index.js +2 -0
  63. package/dist/types/interface/api/requests/index.js.map +1 -1
  64. package/dist/types/interface/api/requests/service-discord-event.request.d.ts +51 -0
  65. package/dist/types/interface/api/requests/service-discord-event.request.js +3 -0
  66. package/dist/types/interface/api/requests/service-discord-event.request.js.map +1 -0
  67. package/dist/types/interface/api/requests/service-discord.request.d.ts +22 -1
  68. package/dist/types/interface/api/requests/service-insights.request.d.ts +25 -0
  69. package/dist/types/interface/api/requests/service-insights.request.js +3 -0
  70. package/dist/types/interface/api/requests/service-insights.request.js.map +1 -0
  71. package/dist/types/interface/api/responses/index.d.ts +2 -0
  72. package/dist/types/interface/api/responses/index.js +2 -0
  73. package/dist/types/interface/api/responses/index.js.map +1 -1
  74. package/dist/types/interface/api/responses/service-discord-event.response.d.ts +18 -0
  75. package/dist/types/interface/api/responses/service-discord-event.response.js +3 -0
  76. package/dist/types/interface/api/responses/service-discord-event.response.js.map +1 -0
  77. package/dist/types/interface/api/responses/service-discord.response.d.ts +30 -5
  78. package/dist/types/interface/api/responses/service-insights.response.d.ts +8 -0
  79. package/dist/types/interface/api/responses/service-insights.response.js +3 -0
  80. package/dist/types/interface/api/responses/service-insights.response.js.map +1 -0
  81. package/dist/types/interface/api/responses/service-version.response.d.ts +9 -1
  82. package/dist/types/interface/models/index.d.ts +4 -0
  83. package/dist/types/interface/models/index.js +4 -0
  84. package/dist/types/interface/models/index.js.map +1 -1
  85. package/dist/types/interface/models/reflex-bot-limits.model.d.ts +56 -0
  86. package/dist/types/interface/models/reflex-bot-limits.model.js +16 -0
  87. package/dist/types/interface/models/reflex-bot-limits.model.js.map +1 -0
  88. package/dist/types/interface/models/reflex-discord-event-log.model.d.ts +38 -0
  89. package/dist/types/interface/models/reflex-discord-event-log.model.js +3 -0
  90. package/dist/types/interface/models/reflex-discord-event-log.model.js.map +1 -0
  91. package/dist/types/interface/models/reflex-discord-event.model.d.ts +41 -0
  92. package/dist/types/interface/models/reflex-discord-event.model.js +23 -0
  93. package/dist/types/interface/models/reflex-discord-event.model.js.map +1 -0
  94. package/dist/types/interface/models/reflex-insights.model.d.ts +83 -0
  95. package/dist/types/interface/models/reflex-insights.model.js +16 -0
  96. package/dist/types/interface/models/reflex-insights.model.js.map +1 -0
  97. package/dist/types/interface/models/reflex-run.model.d.ts +2 -0
  98. package/dist/types/interface/models/reflex-service-version.model.d.ts +2 -0
  99. package/package.json +1 -1
  100. package/src/api/function-insights.api.test.ts +27 -0
  101. package/src/api/function-insights.api.ts +18 -0
  102. package/src/api/index.ts +17 -14
  103. package/src/api/service-discord-event.api.test.ts +106 -0
  104. package/src/api/service-discord-event.api.ts +78 -0
  105. package/src/api/service-discord.api.test.ts +197 -170
  106. package/src/api/service-discord.api.ts +241 -203
  107. package/src/api/service-insights.api.test.ts +36 -0
  108. package/src/api/service-insights.api.ts +42 -0
  109. package/src/api/service-task.api.test.ts +140 -140
  110. package/src/api/service-task.api.ts +141 -141
  111. package/src/discord/discord-event-filter-cases.ts +261 -0
  112. package/src/discord/discord-event-filters.test.ts +91 -0
  113. package/src/discord/discord-event-filters.ts +95 -0
  114. package/src/discord/discord-event-intents.test.ts +112 -0
  115. package/src/discord/discord-event-intents.ts +55 -0
  116. package/src/discord/index.ts +3 -0
  117. package/src/index.test.ts +75 -50
  118. package/src/index.ts +46 -0
  119. package/src/types/enum/bot-event-block-reason.enum.ts +7 -0
  120. package/src/types/enum/discord-event-drop-reason.enum.ts +13 -0
  121. package/src/types/enum/discord-event-filter-name.enum.ts +11 -0
  122. package/src/types/enum/discord-event-status.enum.ts +13 -0
  123. package/src/types/enum/discord-event-type.enum.ts +7 -0
  124. package/src/types/enum/discord-gateway-failure-code.enum.ts +11 -9
  125. package/src/types/enum/index.ts +7 -0
  126. package/src/types/enum/insights-period.enum.ts +8 -0
  127. package/src/types/enum/schedule-sync-status.enum.ts +6 -6
  128. package/src/types/enum/scheduled-run-failure-code.enum.ts +2 -0
  129. package/src/types/enum/scheduled-run-origin.enum.ts +5 -5
  130. package/src/types/enum/scheduled-run-status.enum.ts +17 -17
  131. package/src/types/enum/trigger-kind.enum.ts +8 -0
  132. package/src/types/interface/api/requests/index.ts +15 -13
  133. package/src/types/interface/api/requests/service-discord-event.request.ts +68 -0
  134. package/src/types/interface/api/requests/service-discord.request.ts +161 -128
  135. package/src/types/interface/api/requests/service-insights.request.ts +31 -0
  136. package/src/types/interface/api/requests/service-task.request.ts +80 -80
  137. package/src/types/interface/api/responses/index.ts +15 -13
  138. package/src/types/interface/api/responses/service-discord-event.response.ts +24 -0
  139. package/src/types/interface/api/responses/service-discord.response.ts +119 -72
  140. package/src/types/interface/api/responses/service-insights.response.ts +11 -0
  141. package/src/types/interface/api/responses/service-task.response.ts +57 -57
  142. package/src/types/interface/api/responses/service-version.response.ts +106 -91
  143. package/src/types/interface/models/index.ts +19 -15
  144. package/src/types/interface/models/reflex-bot-limits.model.ts +92 -0
  145. package/src/types/interface/models/reflex-discord-event-log.model.ts +58 -0
  146. package/src/types/interface/models/reflex-discord-event.model.ts +77 -0
  147. package/src/types/interface/models/reflex-insights.model.ts +120 -0
  148. package/src/types/interface/models/reflex-run.model.ts +183 -179
  149. package/src/types/interface/models/reflex-service-version.model.ts +61 -58
  150. package/src/types/interface/models/reflex-task.model.ts +97 -97
@@ -0,0 +1,58 @@
1
+ import type {
2
+ DiscordEventDropReason,
3
+ DiscordEventFilterName,
4
+ DiscordEventStatus,
5
+ DiscordEventType,
6
+ } from '../../enum';
7
+
8
+ /** A retained event, from the inbox of the execution plane. */
9
+ export interface IReflexDiscordEventLogRetained {
10
+ id: string;
11
+ eventType: DiscordEventType;
12
+ guildId: string | null;
13
+ channelId: string | null;
14
+ authorId: string | null;
15
+ receivedAt: Date;
16
+ status: DiscordEventStatus;
17
+ triggerId: string;
18
+ /** The name of the trigger in the version in service; null when that version no longer has it. */
19
+ triggerName: string | null;
20
+ functionId: string | null;
21
+ /** The execution it started; null before it ran. */
22
+ liveRunId: string | null;
23
+ durationMs: number | null;
24
+ costMillicredits: number | null;
25
+ /** Failure code of a FAILED event: `EVENT_TRIGGER_REMOVED` or the error code of the run; null otherwise. */
26
+ failureCode: string | null;
27
+ /** The id of its inbox row without dashes. */
28
+ traceId: string;
29
+ }
30
+
31
+ /** A dropped event, from the sample kept per bot and per reason. */
32
+ export interface IReflexDiscordEventLogDropped {
33
+ id: string;
34
+ eventType: DiscordEventType;
35
+ guildId: string | null;
36
+ channelId: string | null;
37
+ authorId: string | null;
38
+ receivedAt: Date;
39
+ reason: DiscordEventDropReason;
40
+ /** The filter that rejected it, when `reason` is FILTERED; null otherwise. */
41
+ filterName: DiscordEventFilterName | null;
42
+ }
43
+
44
+ /** Shown instead of the events when Discord refused the intents (close code 4014): it sends none, so none can be listed. */
45
+ export interface IReflexDiscordEventLogIntentsRefused {
46
+ since: Date;
47
+ /** The privileged intents the version in service asks for, as Discord intent bits. */
48
+ privilegedIntents: number[];
49
+ }
50
+
51
+ /** One page of the event log of a bot in one environment. */
52
+ export interface IReflexDiscordEventLogPage {
53
+ retained: IReflexDiscordEventLogRetained[];
54
+ dropped: IReflexDiscordEventLogDropped[];
55
+ /** Null unless the bot is refused its intents. */
56
+ intentsRefused: IReflexDiscordEventLogIntentsRefused | null;
57
+ nextCursor: string | null;
58
+ }
@@ -0,0 +1,77 @@
1
+ import type { DiscordEventType } from '../../enum';
2
+
3
+ /** Bounds of the Discord event triggers of a bot; the API, the Gateway and their databases apply the same ones. */
4
+ export const REFLEX_DISCORD_EVENT_LIMITS = {
5
+ /** `^[-_a-z0-9]{1,32}$`: the name of a trigger, unique within the Service. */
6
+ namePattern: /^[-_a-z0-9]{1,32}$/,
7
+ nameMaxLength: 32,
8
+ maxTriggersPerService: 25,
9
+ guildIdsMax: 25,
10
+ channelIdsMax: 50,
11
+ roleIdsMax: 25,
12
+ contentPrefixMaxLength: 32,
13
+ /** Characters of the payload of a retained event, serialized to JSON. */
14
+ payloadMaxLength: 8192,
15
+ /** Characters of the summary kept with an event, retained or dropped. */
16
+ summaryMaxLength: 512,
17
+ /** Dropped events kept as a sample, per bot and per reason. */
18
+ dropSamplesPerReason: 200,
19
+ /** Lateness past which a retained event is EXPIRED instead of run. */
20
+ toleranceMinutes: 15,
21
+ } as const;
22
+
23
+ /**
24
+ * What one bot can take in (decision 6 of the J2 spec). Provisional until the capacity measure on staging (C1)
25
+ * sets `runsPerSlotPerMinute` and `maxConcurrencyPerBot`; `lotsMax` is then recalibrated to
26
+ * `min(lotsMaxCeiling, floor((maxConcurrencyPerBot * runsPerSlotPerMinute - base) / 500))`, never above it.
27
+ */
28
+ export const REFLEX_BOT_EVENT_CAPACITY = {
29
+ /** Events per minute one execution slot handles (reference duration 300 ms, margin included). */
30
+ runsPerSlotPerMinute: 100,
31
+ /** `maxReplicas` (3) times the ceiling per pod (10) of the edge fleet. */
32
+ maxConcurrencyPerBot: 30,
33
+ /** The most lots of 500 events per minute a bot can be allocated, whatever the measure says. */
34
+ lotsMaxCeiling: 40,
35
+ /** Provisional: the most lots a bot can be allocated until the measure recalibrates it. */
36
+ lotsMax: 40,
37
+ } as const;
38
+
39
+ /** Optional filters of a trigger, combined with AND. An absent or empty list is no filter. */
40
+ export interface IReflexDiscordEventFilters {
41
+ /** 25 at most, every type. */
42
+ guildIds?: string[];
43
+ /** 50 at most, message and reaction. */
44
+ channelIds?: string[];
45
+ /** 25 at most, member arrival, message and reaction: the member has one of these roles. */
46
+ roleIds?: string[];
47
+ /** 32 characters at most, message: the content starts with it; needs the MESSAGE_CONTENT intent. */
48
+ contentPrefix?: string;
49
+ /** True when absent: an author or member that is a bot is ignored. */
50
+ ignoreBots?: boolean;
51
+ /** True when absent, message and reaction: the bot itself is ignored. */
52
+ ignoreSelf?: boolean;
53
+ }
54
+
55
+ /** A Discord event trigger of the draft of a bot Service: a named target of one event type. */
56
+ export interface IReflexDiscordEvent {
57
+ id: string;
58
+ serviceId: string;
59
+ /** A function of the same Service. */
60
+ functionId: string;
61
+ /** Unique within the Service. */
62
+ name: string;
63
+ eventType: DiscordEventType;
64
+ filters: IReflexDiscordEventFilters;
65
+ /** True by default: events of one channel (or one server for member events) run one after the other. */
66
+ ordered: boolean;
67
+ /** False by default, MESSAGE_CREATE only: the function receives the message content. */
68
+ includeContent: boolean;
69
+ createdAt: Date;
70
+ updatedAt: Date;
71
+ }
72
+
73
+ /** A Discord event trigger as a version of the Service froze it. */
74
+ export type IReflexDiscordEventSnapshot = Pick<
75
+ IReflexDiscordEvent,
76
+ 'id' | 'functionId' | 'name' | 'eventType' | 'filters' | 'ordered' | 'includeContent'
77
+ >;
@@ -0,0 +1,120 @@
1
+ import { InsightsPeriod } from '../../enum';
2
+ import type { TriggerKind } from '../../enum';
3
+
4
+ /** The width of one point of a dashboard, by period. */
5
+ export const REFLEX_INSIGHTS_PERIOD_STEP_SECONDS: Record<InsightsPeriod, number> = {
6
+ [InsightsPeriod.HOUR_1]: 60,
7
+ [InsightsPeriod.HOURS_24]: 300,
8
+ [InsightsPeriod.DAYS_7]: 3600,
9
+ [InsightsPeriod.DAYS_30]: 21600,
10
+ [InsightsPeriod.DAYS_90]: 86400,
11
+ };
12
+
13
+ /** Upper bounds, in thousandths of a credit, of the cost histogram buckets; one open bucket follows (10 in all). */
14
+ export const REFLEX_COST_HISTOGRAM_UPPER_BOUNDS = [
15
+ 10, 25, 50, 100, 250, 500, 1000, 2500, 5000,
16
+ ] as const;
17
+
18
+ /** A trigger is labeled heavy past this multiple of the median cost per run of the Service. */
19
+ export const REFLEX_HEAVY_TRIGGER_FACTOR = 5;
20
+
21
+ /** A value over the period and over the one just before it; `previous` is null without data before. */
22
+ export interface IReflexInsightsTile {
23
+ value: number;
24
+ previous: number | null;
25
+ }
26
+
27
+ export interface IReflexInsightsTiles {
28
+ runs: IReflexInsightsTile;
29
+ failed: IReflexInsightsTile;
30
+ cpuMs: IReflexInsightsTile;
31
+ heapPeakBytesMax: IReflexInsightsTile;
32
+ netBytes: IReflexInsightsTile;
33
+ costMillicredits: IReflexInsightsTile;
34
+ }
35
+
36
+ /** One point of the series; `at` is the start of its step. */
37
+ export interface IReflexInsightsPoint {
38
+ at: Date;
39
+ runs: number;
40
+ failed: number;
41
+ durationMsSum: number;
42
+ cpuMsSum: number;
43
+ netInBytes: number;
44
+ netOutBytes: number;
45
+ costMillicredits: number;
46
+ /** Mean cost of a run, in thousandths of a credit; null when no run. */
47
+ costMeanMillicredits: number | null;
48
+ /** 95th percentile of the cost of a run: upper bound of the histogram bucket holding it; null when no run. */
49
+ costP95Millicredits: number | null;
50
+ }
51
+
52
+ /** Runs of one kind of trigger, over the period. */
53
+ export interface IReflexInsightsKindShare {
54
+ kind: TriggerKind;
55
+ runs: number;
56
+ failed: number;
57
+ }
58
+
59
+ /** One row of the ranking of the triggers. */
60
+ export interface IReflexInsightsRankingRow {
61
+ kind: TriggerKind;
62
+ triggerId: string;
63
+ /** `/name`, `METHOD path`, a prefix or a name; null when the trigger was deleted. */
64
+ label: string | null;
65
+ runs: number;
66
+ failed: number;
67
+ costMillicreditsTotal: number;
68
+ costMillicreditsPerRun: number;
69
+ cpuMsMean: number;
70
+ durationMsMean: number;
71
+ /** Cost per run past `REFLEX_HEAVY_TRIGGER_FACTOR` times the median of the Service. */
72
+ heavy: boolean;
73
+ }
74
+
75
+ /** The dashboard of a Service or of a function. */
76
+ export interface IReflexInsights {
77
+ period: InsightsPeriod;
78
+ from: Date;
79
+ to: Date;
80
+ stepSeconds: number;
81
+ tiles: IReflexInsightsTiles;
82
+ series: IReflexInsightsPoint[];
83
+ byKind: IReflexInsightsKindShare[];
84
+ /** Top 10 of the triggers, by total credits; the screen sorts the rows it holds. */
85
+ ranking: IReflexInsightsRankingRow[];
86
+ }
87
+
88
+ /** Events received by the Gateway in one step, with the reason of each one it did not keep. */
89
+ export interface IReflexEventInsightsPoint {
90
+ at: Date;
91
+ received: number;
92
+ queued: number;
93
+ executed: number;
94
+ failed: number;
95
+ duplicates: number;
96
+ filtered: number;
97
+ droppedRate: number;
98
+ droppedMonthlyCap: number;
99
+ droppedCredits: number;
100
+ expired: number;
101
+ /** Events rejected by each filter, by filter name. */
102
+ filteredBy: Record<string, number>;
103
+ }
104
+
105
+ /** The dashboard of the events of a bot. */
106
+ export interface IReflexEventInsights {
107
+ period: InsightsPeriod;
108
+ from: Date;
109
+ to: Date;
110
+ stepSeconds: number;
111
+ series: IReflexEventInsightsPoint[];
112
+ /** The rate of the bot, for the rate line. */
113
+ eventsPerMinute: number;
114
+ peakPerMinute: number;
115
+ minutesAtCap: number;
116
+ /** Credits of the month and the spend of the month against the cap. */
117
+ creditsMonthMillicredits: number;
118
+ spendCents: number;
119
+ monthlySpendCapCents: number;
120
+ }
@@ -1,179 +1,183 @@
1
- import type {
2
- ExecutionMode,
3
- ExecutionProfile,
4
- RunLogLevel,
5
- RunMode,
6
- RunStatus,
7
- RunStepStatus,
8
- ScheduledRunOrigin,
9
- TraceEffectType,
10
- } from '../../enum';
11
-
12
- export interface IReflexTraceError {
13
- code: string;
14
- message: string;
15
- }
16
-
17
- /**
18
- * One call the run made to the host, in the order they were served. `recorded` is true when the effect
19
- * was recorded instead of executed (a stubbed HTTP call, a Store write kept aside, a wait not waited).
20
- */
21
- export interface IReflexTraceEntry {
22
- stepId: string;
23
- type: TraceEffectType;
24
- /** The host action, for a HOST effect. */
25
- action?: string;
26
- request?: unknown;
27
- response?: unknown;
28
- error?: IReflexTraceError;
29
- recorded: boolean;
30
- }
31
-
32
- /** What the RESPOND step (or `abyss.respond`) built: the response the caller of the route would get. */
33
- export interface IReflexTraceResponse {
34
- status: number;
35
- headers: Record<string, string>;
36
- body: unknown;
37
- }
38
-
39
- /**
40
- * Bounded: past 100 entries, or a value of more than 4 KB, the trace is cut and says so (`truncated`).
41
- * Every secret value the run was given or read is masked (`***`).
42
- */
43
- export interface IReflexRunTrace {
44
- entries: IReflexTraceEntry[];
45
- outcome: {
46
- status: RunStatus;
47
- output?: unknown;
48
- error?: IReflexTraceError & { stepId?: string };
49
- };
50
- response?: IReflexTraceResponse;
51
- truncated: boolean;
52
- }
53
-
54
- export interface IReflexRun {
55
- id: string;
56
- functionId: string;
57
- versionId: string | null;
58
- /**
59
- * The environment the run took place in: the promoted version's for a LIVE run, the one named in the
60
- * request for a test run. Null only for a test run recorded before test runs named an environment.
61
- */
62
- environmentId: string | null;
63
- mode: RunMode;
64
- status: RunStatus;
65
- durationMs: number;
66
- /** The effects of a test run; null for a LIVE run, which records no trace (nothing of the caller is kept). */
67
- trace: IReflexRunTrace | null;
68
- /** The route that started a LIVE run; null for a test run and for a run a Discord command or component started. */
69
- routeId: string | null;
70
- /** The Discord command that started a LIVE run; null otherwise. */
71
- commandId: string | null;
72
- /** The Discord component that started a LIVE run; null otherwise. */
73
- componentId: string | null;
74
- /** The task that started a LIVE run, by a tick of its cron or a delayed run; null otherwise. */
75
- taskId: string | null;
76
- /** How the task started the run: RECURRING for a tick of its cron, DELAYED for a delayed run; null when no task did. */
77
- scheduledRunOrigin: ScheduledRunOrigin | null;
78
- /**
79
- * What started the run, for a screen: `METHOD path` for a route, `/name` for a command, the custom id
80
- * prefix for a component, the name for a task. Null for a test run, and when the route, command,
81
- * component or task was deleted.
82
- */
83
- originLabel: string | null;
84
- /** The HTTP status the caller of a LIVE run got; null for a test run. */
85
- httpStatus: number | null;
86
- /** The code of the error a failed LIVE run answered (FUNCTION_FAILED, FUNCTION_TIMEOUT, RUNNER_UNAVAILABLE, RUNNER_SATURATED, INTERNAL_ERROR); null otherwise, an interrupted run included. */
87
- errorCode: string | null;
88
- /** The execution mode of the function when a LIVE run started; null for a test run. */
89
- executionMode: ExecutionMode | null;
90
- /** When the caller of a LIVE run got its answer; null for a test run, or before any answer. */
91
- responseSentAt: Date | null;
92
- /**
93
- * What the run consumed and cost: measured by the runner for a live run and for a test run (with the
94
- * function's effective settings in the run's environment, and the network of its stubs); null for a running execution, or a run
95
- * recorded before the measures.
96
- */
97
- metrics: IReflexRunMetrics | null;
98
- createdByUserId: string | null;
99
- createdAt: Date;
100
- }
101
-
102
- /** What a live execution consumed, and what it costs (ADR-0244). */
103
- export interface IReflexRunMetrics {
104
- /** The profile it ran with, and the memory that profile allocates. */
105
- profile: ExecutionProfile;
106
- memoryLimitMb: number;
107
- /** Measured by the runner in the isolate. */
108
- cpuMs: number;
109
- heapPeakBytes: number;
110
- /** Measured by the host: bytes sent and received by `fetch`, plus the answer sent to the caller. */
111
- netOutBytes: number;
112
- netInBytes: number;
113
- httpCalls: number;
114
- storeWrites: number;
115
- /** In thousandths of a credit; 0 for an interrupted execution, which is offered. */
116
- costMillicredits: number;
117
- }
118
-
119
- /** What one step of a run consumed; its cost is its share of the run's, the fixed price aside. */
120
- export interface IReflexRunStep {
121
- /** 0 for the first step that ran. */
122
- position: number;
123
- stepId: string;
124
- status: RunStepStatus;
125
- durationMs: number;
126
- cpuMs: number;
127
- heapPeakBytes: number;
128
- netOutBytes: number;
129
- netInBytes: number;
130
- httpCalls: number;
131
- storeWrites: number;
132
- costMillicredits: number;
133
- }
134
-
135
- /**
136
- * One log line a run wrote: a LOG step, `abyss.log.*` or `console.*`. Secrets masked (`***`); a message
137
- * is cut at 2048 characters, and data whose JSON is longer becomes `{ truncated: true, preview }`. At most
138
- * 100 lines per run are kept; `IReflexRunDetail.droppedLogLines` counts the others.
139
- */
140
- export interface IReflexRunLog {
141
- /** 0 for the first line. */
142
- position: number;
143
- /** The step that wrote it. */
144
- stepId: string;
145
- level: RunLogLevel;
146
- message: string;
147
- /** The value given with the message; null when none was. */
148
- data: unknown;
149
- loggedAt: Date;
150
- }
151
-
152
- /**
153
- * One run with the steps it ran and the lines it logged, in order. Both are empty for a run recorded
154
- * before the measures (and the steps for a running execution).
155
- */
156
- export interface IReflexRunDetail extends IReflexRun {
157
- steps: IReflexRunStep[];
158
- logs: IReflexRunLog[];
159
- /** The log lines written past the 100 kept in `logs`; 0 when none was dropped. */
160
- droppedLogLines: number;
161
- }
162
-
163
- /** The state of a live execution, read by its id (the `executionId` an async route answers with). */
164
- export interface IReflexExecutionState {
165
- id: string;
166
- status: RunStatus;
167
- executionMode: ExecutionMode;
168
- startedAt: Date;
169
- /** When the caller got its answer; for an async execution, the 202. */
170
- responseSentAt: Date | null;
171
- /** Null while it runs. */
172
- finishedAt: Date | null;
173
- /** The status the caller got. */
174
- httpStatus: number;
175
- /** Set when the execution failed. */
176
- errorCode: string | null;
177
- /** Null while it runs, or for an execution recorded before the measures. */
178
- costMillicredits: number | null;
179
- }
1
+ import type {
2
+ ExecutionMode,
3
+ ExecutionProfile,
4
+ RunLogLevel,
5
+ RunMode,
6
+ RunStatus,
7
+ RunStepStatus,
8
+ ScheduledRunOrigin,
9
+ TraceEffectType,
10
+ } from '../../enum';
11
+
12
+ export interface IReflexTraceError {
13
+ code: string;
14
+ message: string;
15
+ }
16
+
17
+ /**
18
+ * One call the run made to the host, in the order they were served. `recorded` is true when the effect
19
+ * was recorded instead of executed (a stubbed HTTP call, a Store write kept aside, a wait not waited).
20
+ */
21
+ export interface IReflexTraceEntry {
22
+ stepId: string;
23
+ type: TraceEffectType;
24
+ /** The host action, for a HOST effect. */
25
+ action?: string;
26
+ request?: unknown;
27
+ response?: unknown;
28
+ error?: IReflexTraceError;
29
+ recorded: boolean;
30
+ }
31
+
32
+ /** What the RESPOND step (or `abyss.respond`) built: the response the caller of the route would get. */
33
+ export interface IReflexTraceResponse {
34
+ status: number;
35
+ headers: Record<string, string>;
36
+ body: unknown;
37
+ }
38
+
39
+ /**
40
+ * Bounded: past 100 entries, or a value of more than 4 KB, the trace is cut and says so (`truncated`).
41
+ * Every secret value the run was given or read is masked (`***`).
42
+ */
43
+ export interface IReflexRunTrace {
44
+ entries: IReflexTraceEntry[];
45
+ outcome: {
46
+ status: RunStatus;
47
+ output?: unknown;
48
+ error?: IReflexTraceError & { stepId?: string };
49
+ };
50
+ response?: IReflexTraceResponse;
51
+ truncated: boolean;
52
+ }
53
+
54
+ export interface IReflexRun {
55
+ id: string;
56
+ functionId: string;
57
+ versionId: string | null;
58
+ /**
59
+ * The environment the run took place in: the promoted version's for a LIVE run, the one named in the
60
+ * request for a test run. Null only for a test run recorded before test runs named an environment.
61
+ */
62
+ environmentId: string | null;
63
+ mode: RunMode;
64
+ status: RunStatus;
65
+ durationMs: number;
66
+ /** The effects of a test run; null for a LIVE run, which records no trace (nothing of the caller is kept). */
67
+ trace: IReflexRunTrace | null;
68
+ /** The route that started a LIVE run; null for a test run and for a run a Discord command or component started. */
69
+ routeId: string | null;
70
+ /** The Discord command that started a LIVE run; null otherwise. */
71
+ commandId: string | null;
72
+ /** The Discord component that started a LIVE run; null otherwise. */
73
+ componentId: string | null;
74
+ /** The task that started a LIVE run, by a tick of its cron or a delayed run; null otherwise. */
75
+ taskId: string | null;
76
+ /** The event trigger that started a LIVE run; null otherwise. */
77
+ eventTriggerId: string | null;
78
+ /** Trace id of an execution of an event: the id of its inbox row without dashes, the same at every attempt; null for the other origins. */
79
+ traceId: string | null;
80
+ /** How the task started the run: RECURRING for a tick of its cron, DELAYED for a delayed run; null when no task did. */
81
+ scheduledRunOrigin: ScheduledRunOrigin | null;
82
+ /**
83
+ * What started the run, for a screen: `METHOD path` for a route, `/name` for a command, the custom id
84
+ * prefix for a component, the name for a task or an event trigger. Null for a test run, and when the route, command,
85
+ * component, task or event trigger was deleted.
86
+ */
87
+ originLabel: string | null;
88
+ /** The HTTP status the caller of a LIVE run got; null for a test run. */
89
+ httpStatus: number | null;
90
+ /** The code of the error a failed LIVE run answered (FUNCTION_FAILED, FUNCTION_TIMEOUT, RUNNER_UNAVAILABLE, RUNNER_SATURATED, INTERNAL_ERROR); null otherwise, an interrupted run included. */
91
+ errorCode: string | null;
92
+ /** The execution mode of the function when a LIVE run started; null for a test run. */
93
+ executionMode: ExecutionMode | null;
94
+ /** When the caller of a LIVE run got its answer; null for a test run, or before any answer. */
95
+ responseSentAt: Date | null;
96
+ /**
97
+ * What the run consumed and cost: measured by the runner for a live run and for a test run (with the
98
+ * function's effective settings in the run's environment, and the network of its stubs); null for a running execution, or a run
99
+ * recorded before the measures.
100
+ */
101
+ metrics: IReflexRunMetrics | null;
102
+ createdByUserId: string | null;
103
+ createdAt: Date;
104
+ }
105
+
106
+ /** What a live execution consumed, and what it costs (ADR-0244). */
107
+ export interface IReflexRunMetrics {
108
+ /** The profile it ran with, and the memory that profile allocates. */
109
+ profile: ExecutionProfile;
110
+ memoryLimitMb: number;
111
+ /** Measured by the runner in the isolate. */
112
+ cpuMs: number;
113
+ heapPeakBytes: number;
114
+ /** Measured by the host: bytes sent and received by `fetch`, plus the answer sent to the caller. */
115
+ netOutBytes: number;
116
+ netInBytes: number;
117
+ httpCalls: number;
118
+ storeWrites: number;
119
+ /** In thousandths of a credit; 0 for an interrupted execution, which is offered. */
120
+ costMillicredits: number;
121
+ }
122
+
123
+ /** What one step of a run consumed; its cost is its share of the run's, the fixed price aside. */
124
+ export interface IReflexRunStep {
125
+ /** 0 for the first step that ran. */
126
+ position: number;
127
+ stepId: string;
128
+ status: RunStepStatus;
129
+ durationMs: number;
130
+ cpuMs: number;
131
+ heapPeakBytes: number;
132
+ netOutBytes: number;
133
+ netInBytes: number;
134
+ httpCalls: number;
135
+ storeWrites: number;
136
+ costMillicredits: number;
137
+ }
138
+
139
+ /**
140
+ * One log line a run wrote: a LOG step, `abyss.log.*` or `console.*`. Secrets masked (`***`); a message
141
+ * is cut at 2048 characters, and data whose JSON is longer becomes `{ truncated: true, preview }`. At most
142
+ * 100 lines per run are kept; `IReflexRunDetail.droppedLogLines` counts the others.
143
+ */
144
+ export interface IReflexRunLog {
145
+ /** 0 for the first line. */
146
+ position: number;
147
+ /** The step that wrote it. */
148
+ stepId: string;
149
+ level: RunLogLevel;
150
+ message: string;
151
+ /** The value given with the message; null when none was. */
152
+ data: unknown;
153
+ loggedAt: Date;
154
+ }
155
+
156
+ /**
157
+ * One run with the steps it ran and the lines it logged, in order. Both are empty for a run recorded
158
+ * before the measures (and the steps for a running execution).
159
+ */
160
+ export interface IReflexRunDetail extends IReflexRun {
161
+ steps: IReflexRunStep[];
162
+ logs: IReflexRunLog[];
163
+ /** The log lines written past the 100 kept in `logs`; 0 when none was dropped. */
164
+ droppedLogLines: number;
165
+ }
166
+
167
+ /** The state of a live execution, read by its id (the `executionId` an async route answers with). */
168
+ export interface IReflexExecutionState {
169
+ id: string;
170
+ status: RunStatus;
171
+ executionMode: ExecutionMode;
172
+ startedAt: Date;
173
+ /** When the caller got its answer; for an async execution, the 202. */
174
+ responseSentAt: Date | null;
175
+ /** Null while it runs. */
176
+ finishedAt: Date | null;
177
+ /** The status the caller got. */
178
+ httpStatus: number;
179
+ /** Set when the execution failed. */
180
+ errorCode: string | null;
181
+ /** Null while it runs, or for an execution recorded before the measures. */
182
+ costMillicredits: number | null;
183
+ }