@abyss-project/reflex 5.3.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 (161) 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/api/service-task.api.d.ts +2 -1
  17. package/dist/api/service-task.api.js +3 -1
  18. package/dist/api/service-task.api.js.map +1 -1
  19. package/dist/discord/discord-event-filter-cases.d.ts +15 -0
  20. package/dist/discord/discord-event-filter-cases.js +77 -0
  21. package/dist/discord/discord-event-filter-cases.js.map +1 -0
  22. package/dist/discord/discord-event-filters.d.ts +20 -0
  23. package/dist/discord/discord-event-filters.js +50 -0
  24. package/dist/discord/discord-event-filters.js.map +1 -0
  25. package/dist/discord/discord-event-intents.d.ts +14 -0
  26. package/dist/discord/discord-event-intents.js +38 -0
  27. package/dist/discord/discord-event-intents.js.map +1 -0
  28. package/dist/discord/index.d.ts +3 -0
  29. package/dist/discord/index.js +20 -0
  30. package/dist/discord/index.js.map +1 -0
  31. package/dist/index.d.ts +25 -0
  32. package/dist/index.js +25 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/types/enum/bot-event-block-reason.enum.d.ts +4 -0
  35. package/dist/types/enum/bot-event-block-reason.enum.js +9 -0
  36. package/dist/types/enum/bot-event-block-reason.enum.js.map +1 -0
  37. package/dist/types/enum/discord-event-drop-reason.enum.d.ts +7 -0
  38. package/dist/types/enum/discord-event-drop-reason.enum.js +12 -0
  39. package/dist/types/enum/discord-event-drop-reason.enum.js.map +1 -0
  40. package/dist/types/enum/discord-event-filter-name.enum.d.ts +9 -0
  41. package/dist/types/enum/discord-event-filter-name.enum.js +14 -0
  42. package/dist/types/enum/discord-event-filter-name.enum.js.map +1 -0
  43. package/dist/types/enum/discord-event-status.enum.d.ts +7 -0
  44. package/dist/types/enum/discord-event-status.enum.js +12 -0
  45. package/dist/types/enum/discord-event-status.enum.js.map +1 -0
  46. package/dist/types/enum/discord-event-type.enum.d.ts +6 -0
  47. package/dist/types/enum/discord-event-type.enum.js +11 -0
  48. package/dist/types/enum/discord-event-type.enum.js.map +1 -0
  49. package/dist/types/enum/discord-gateway-failure-code.enum.d.ts +2 -1
  50. package/dist/types/enum/discord-gateway-failure-code.enum.js +1 -0
  51. package/dist/types/enum/discord-gateway-failure-code.enum.js.map +1 -1
  52. package/dist/types/enum/index.d.ts +9 -0
  53. package/dist/types/enum/index.js +9 -0
  54. package/dist/types/enum/index.js.map +1 -1
  55. package/dist/types/enum/insights-period.enum.d.ts +7 -0
  56. package/dist/types/enum/insights-period.enum.js +12 -0
  57. package/dist/types/enum/insights-period.enum.js.map +1 -0
  58. package/dist/types/enum/scheduled-run-failure-code.enum.d.ts +5 -0
  59. package/dist/types/enum/scheduled-run-failure-code.enum.js +10 -0
  60. package/dist/types/enum/scheduled-run-failure-code.enum.js.map +1 -0
  61. package/dist/types/enum/scheduled-run-status.enum.d.ts +9 -0
  62. package/dist/types/enum/scheduled-run-status.enum.js +14 -0
  63. package/dist/types/enum/scheduled-run-status.enum.js.map +1 -0
  64. package/dist/types/enum/trigger-kind.enum.d.ts +7 -0
  65. package/dist/types/enum/trigger-kind.enum.js +12 -0
  66. package/dist/types/enum/trigger-kind.enum.js.map +1 -0
  67. package/dist/types/interface/api/requests/index.d.ts +2 -0
  68. package/dist/types/interface/api/requests/index.js +2 -0
  69. package/dist/types/interface/api/requests/index.js.map +1 -1
  70. package/dist/types/interface/api/requests/service-discord-event.request.d.ts +51 -0
  71. package/dist/types/interface/api/requests/service-discord-event.request.js +3 -0
  72. package/dist/types/interface/api/requests/service-discord-event.request.js.map +1 -0
  73. package/dist/types/interface/api/requests/service-discord.request.d.ts +22 -1
  74. package/dist/types/interface/api/requests/service-insights.request.d.ts +25 -0
  75. package/dist/types/interface/api/requests/service-insights.request.js +3 -0
  76. package/dist/types/interface/api/requests/service-insights.request.js.map +1 -0
  77. package/dist/types/interface/api/requests/service-task.request.d.ts +10 -0
  78. package/dist/types/interface/api/responses/index.d.ts +2 -0
  79. package/dist/types/interface/api/responses/index.js +2 -0
  80. package/dist/types/interface/api/responses/index.js.map +1 -1
  81. package/dist/types/interface/api/responses/service-discord-event.response.d.ts +18 -0
  82. package/dist/types/interface/api/responses/service-discord-event.response.js +3 -0
  83. package/dist/types/interface/api/responses/service-discord-event.response.js.map +1 -0
  84. package/dist/types/interface/api/responses/service-discord.response.d.ts +30 -5
  85. package/dist/types/interface/api/responses/service-insights.response.d.ts +8 -0
  86. package/dist/types/interface/api/responses/service-insights.response.js +3 -0
  87. package/dist/types/interface/api/responses/service-insights.response.js.map +1 -0
  88. package/dist/types/interface/api/responses/service-task.response.d.ts +6 -1
  89. package/dist/types/interface/api/responses/service-version.response.d.ts +9 -1
  90. package/dist/types/interface/models/index.d.ts +4 -0
  91. package/dist/types/interface/models/index.js +4 -0
  92. package/dist/types/interface/models/index.js.map +1 -1
  93. package/dist/types/interface/models/reflex-bot-limits.model.d.ts +56 -0
  94. package/dist/types/interface/models/reflex-bot-limits.model.js +16 -0
  95. package/dist/types/interface/models/reflex-bot-limits.model.js.map +1 -0
  96. package/dist/types/interface/models/reflex-discord-event-log.model.d.ts +38 -0
  97. package/dist/types/interface/models/reflex-discord-event-log.model.js +3 -0
  98. package/dist/types/interface/models/reflex-discord-event-log.model.js.map +1 -0
  99. package/dist/types/interface/models/reflex-discord-event.model.d.ts +41 -0
  100. package/dist/types/interface/models/reflex-discord-event.model.js +23 -0
  101. package/dist/types/interface/models/reflex-discord-event.model.js.map +1 -0
  102. package/dist/types/interface/models/reflex-insights.model.d.ts +83 -0
  103. package/dist/types/interface/models/reflex-insights.model.js +16 -0
  104. package/dist/types/interface/models/reflex-insights.model.js.map +1 -0
  105. package/dist/types/interface/models/reflex-run.model.d.ts +2 -0
  106. package/dist/types/interface/models/reflex-service-version.model.d.ts +2 -0
  107. package/dist/types/interface/models/reflex-task.model.d.ts +13 -0
  108. package/dist/types/interface/models/reflex-task.model.js +1 -0
  109. package/dist/types/interface/models/reflex-task.model.js.map +1 -1
  110. package/package.json +1 -1
  111. package/src/api/function-insights.api.test.ts +27 -0
  112. package/src/api/function-insights.api.ts +18 -0
  113. package/src/api/index.ts +17 -14
  114. package/src/api/service-discord-event.api.test.ts +106 -0
  115. package/src/api/service-discord-event.api.ts +78 -0
  116. package/src/api/service-discord.api.test.ts +197 -170
  117. package/src/api/service-discord.api.ts +241 -203
  118. package/src/api/service-insights.api.test.ts +36 -0
  119. package/src/api/service-insights.api.ts +42 -0
  120. package/src/api/service-task.api.test.ts +140 -124
  121. package/src/api/service-task.api.ts +141 -122
  122. package/src/discord/discord-event-filter-cases.ts +261 -0
  123. package/src/discord/discord-event-filters.test.ts +91 -0
  124. package/src/discord/discord-event-filters.ts +95 -0
  125. package/src/discord/discord-event-intents.test.ts +112 -0
  126. package/src/discord/discord-event-intents.ts +55 -0
  127. package/src/discord/index.ts +3 -0
  128. package/src/index.test.ts +75 -50
  129. package/src/index.ts +317 -264
  130. package/src/types/enum/bot-event-block-reason.enum.ts +7 -0
  131. package/src/types/enum/discord-event-drop-reason.enum.ts +13 -0
  132. package/src/types/enum/discord-event-filter-name.enum.ts +11 -0
  133. package/src/types/enum/discord-event-status.enum.ts +13 -0
  134. package/src/types/enum/discord-event-type.enum.ts +7 -0
  135. package/src/types/enum/discord-gateway-failure-code.enum.ts +11 -9
  136. package/src/types/enum/index.ts +40 -31
  137. package/src/types/enum/insights-period.enum.ts +8 -0
  138. package/src/types/enum/schedule-sync-status.enum.ts +6 -6
  139. package/src/types/enum/scheduled-run-failure-code.enum.ts +12 -0
  140. package/src/types/enum/scheduled-run-origin.enum.ts +5 -5
  141. package/src/types/enum/scheduled-run-status.enum.ts +17 -0
  142. package/src/types/enum/trigger-kind.enum.ts +8 -0
  143. package/src/types/interface/api/requests/index.ts +15 -13
  144. package/src/types/interface/api/requests/service-discord-event.request.ts +68 -0
  145. package/src/types/interface/api/requests/service-discord.request.ts +161 -128
  146. package/src/types/interface/api/requests/service-insights.request.ts +31 -0
  147. package/src/types/interface/api/requests/service-task.request.ts +80 -66
  148. package/src/types/interface/api/responses/index.ts +15 -13
  149. package/src/types/interface/api/responses/service-discord-event.response.ts +24 -0
  150. package/src/types/interface/api/responses/service-discord.response.ts +119 -72
  151. package/src/types/interface/api/responses/service-insights.response.ts +11 -0
  152. package/src/types/interface/api/responses/service-task.response.ts +57 -48
  153. package/src/types/interface/api/responses/service-version.response.ts +106 -91
  154. package/src/types/interface/models/index.ts +19 -15
  155. package/src/types/interface/models/reflex-bot-limits.model.ts +92 -0
  156. package/src/types/interface/models/reflex-discord-event-log.model.ts +58 -0
  157. package/src/types/interface/models/reflex-discord-event.model.ts +77 -0
  158. package/src/types/interface/models/reflex-insights.model.ts +120 -0
  159. package/src/types/interface/models/reflex-run.model.ts +183 -179
  160. package/src/types/interface/models/reflex-service-version.model.ts +61 -58
  161. package/src/types/interface/models/reflex-task.model.ts +97 -61
@@ -1,91 +1,106 @@
1
- import type { ServiceVersionChangeKind } from '../../../enum';
2
- import type {
3
- IReflexDiscordCommandSnapshot,
4
- IReflexDiscordComponentSnapshot,
5
- IReflexServiceVersion,
6
- IReflexServiceVersionRoute,
7
- IReflexTaskSnapshot,
8
- } from '../../models';
9
- import type { IResponse } from '../response';
10
-
11
- /** How one route differs from the previous version, matched by route id. */
12
- export interface IReflexServiceVersionRouteChange {
13
- routeId: string;
14
- kind: ServiceVersionChangeKind;
15
- /** The route in the previous version; null when ADDED. */
16
- before: IReflexServiceVersionRoute | null;
17
- /** The route in this version; null when REMOVED. */
18
- after: IReflexServiceVersionRoute | null;
19
- }
20
-
21
- /** How one command of a Discord bot differs from the previous version, matched by command id. */
22
- export interface IReflexServiceVersionCommandChange {
23
- commandId: string;
24
- kind: ServiceVersionChangeKind;
25
- /** The command in the previous version; null when ADDED. */
26
- before: IReflexDiscordCommandSnapshot | null;
27
- /** The command in this version; null when REMOVED. */
28
- after: IReflexDiscordCommandSnapshot | null;
29
- }
30
-
31
- /** How one component of a Discord bot differs from the previous version, matched by component id. */
32
- export interface IReflexServiceVersionComponentChange {
33
- componentId: string;
34
- kind: ServiceVersionChangeKind;
35
- /** The component in the previous version; null when ADDED. */
36
- before: IReflexDiscordComponentSnapshot | null;
37
- /** The component in this version; null when REMOVED. */
38
- after: IReflexDiscordComponentSnapshot | null;
39
- }
40
-
41
- /** How one task of the Service differs from the previous version, matched by task id. */
42
- export interface IReflexServiceVersionTaskChange {
43
- taskId: string;
44
- kind: ServiceVersionChangeKind;
45
- /** The task in the previous version; null when ADDED. */
46
- before: IReflexTaskSnapshot | null;
47
- /** The task in this version; null when REMOVED. */
48
- after: IReflexTaskSnapshot | null;
49
- }
50
-
51
- export interface IListServiceVersionData {
52
- /** Newest first. */
53
- versions: IReflexServiceVersion[];
54
- }
55
- export type IListServiceVersionResponse = IResponse<IListServiceVersionData>;
56
-
57
- export interface ICreateServiceVersionData {
58
- version: IReflexServiceVersion;
59
- }
60
- export type ICreateServiceVersionResponse = IResponse<ICreateServiceVersionData>;
61
-
62
- export interface IGetServiceVersionDraftStatusData {
63
- /**
64
- * How many functions of the Service a version created now would freeze at a version other than the one
65
- * the last Service version froze: a function new to the Service, a draft that differs from its last
66
- * version (an invalid draft counts), or a function version published since. Same rule as
67
- * `POST .../version`; 0 for a Service without functions.
68
- */
69
- changedFunctions: number;
70
- /**
71
- * How many tasks of the draft differ from the last Service version: added, modified (function, name,
72
- * cron or time zone) or removed. 0 for a Service without tasks.
73
- */
74
- changedTasks: number;
75
- }
76
- export type IGetServiceVersionDraftStatusResponse = IResponse<IGetServiceVersionDraftStatusData>;
77
-
78
- export interface IGetServiceVersionData {
79
- version: IReflexServiceVersion;
80
- /** The version just before; null for the first one. */
81
- previousVersion: IReflexServiceVersion | null;
82
- /** The routes added, removed or modified since `previousVersion` (every route is ADDED for the first one). */
83
- routeChanges: IReflexServiceVersionRouteChange[];
84
- /** The commands added, removed or modified since `previousVersion`; empty for a Service that is not a Discord bot. */
85
- commandChanges: IReflexServiceVersionCommandChange[];
86
- /** The components added, removed or modified since `previousVersion`; empty for a Service that is not a Discord bot. */
87
- componentChanges: IReflexServiceVersionComponentChange[];
88
- /** The tasks added, removed or modified since `previousVersion` (every task is ADDED for the first one). */
89
- taskChanges: IReflexServiceVersionTaskChange[];
90
- }
91
- export type IGetServiceVersionResponse = IResponse<IGetServiceVersionData>;
1
+ import type { ServiceVersionChangeKind } from '../../../enum';
2
+ import type {
3
+ IReflexDiscordCommandSnapshot,
4
+ IReflexDiscordComponentSnapshot,
5
+ IReflexDiscordEventSnapshot,
6
+ IReflexServiceVersion,
7
+ IReflexServiceVersionRoute,
8
+ IReflexTaskSnapshot,
9
+ } from '../../models';
10
+ import type { IResponse } from '../response';
11
+
12
+ /** How one route differs from the previous version, matched by route id. */
13
+ export interface IReflexServiceVersionRouteChange {
14
+ routeId: string;
15
+ kind: ServiceVersionChangeKind;
16
+ /** The route in the previous version; null when ADDED. */
17
+ before: IReflexServiceVersionRoute | null;
18
+ /** The route in this version; null when REMOVED. */
19
+ after: IReflexServiceVersionRoute | null;
20
+ }
21
+
22
+ /** How one command of a Discord bot differs from the previous version, matched by command id. */
23
+ export interface IReflexServiceVersionCommandChange {
24
+ commandId: string;
25
+ kind: ServiceVersionChangeKind;
26
+ /** The command in the previous version; null when ADDED. */
27
+ before: IReflexDiscordCommandSnapshot | null;
28
+ /** The command in this version; null when REMOVED. */
29
+ after: IReflexDiscordCommandSnapshot | null;
30
+ }
31
+
32
+ /** How one component of a Discord bot differs from the previous version, matched by component id. */
33
+ export interface IReflexServiceVersionComponentChange {
34
+ componentId: string;
35
+ kind: ServiceVersionChangeKind;
36
+ /** The component in the previous version; null when ADDED. */
37
+ before: IReflexDiscordComponentSnapshot | null;
38
+ /** The component in this version; null when REMOVED. */
39
+ after: IReflexDiscordComponentSnapshot | null;
40
+ }
41
+
42
+ /** How one event trigger of a Discord bot differs from the previous version, matched by trigger id. */
43
+ export interface IReflexServiceVersionEventChange {
44
+ eventId: string;
45
+ kind: ServiceVersionChangeKind;
46
+ /** The trigger in the previous version; null when ADDED. */
47
+ before: IReflexDiscordEventSnapshot | null;
48
+ /** The trigger in this version; null when REMOVED. */
49
+ after: IReflexDiscordEventSnapshot | null;
50
+ }
51
+
52
+ /** How one task of the Service differs from the previous version, matched by task id. */
53
+ export interface IReflexServiceVersionTaskChange {
54
+ taskId: string;
55
+ kind: ServiceVersionChangeKind;
56
+ /** The task in the previous version; null when ADDED. */
57
+ before: IReflexTaskSnapshot | null;
58
+ /** The task in this version; null when REMOVED. */
59
+ after: IReflexTaskSnapshot | null;
60
+ }
61
+
62
+ export interface IListServiceVersionData {
63
+ /** Newest first. */
64
+ versions: IReflexServiceVersion[];
65
+ }
66
+ export type IListServiceVersionResponse = IResponse<IListServiceVersionData>;
67
+
68
+ export interface ICreateServiceVersionData {
69
+ version: IReflexServiceVersion;
70
+ }
71
+ export type ICreateServiceVersionResponse = IResponse<ICreateServiceVersionData>;
72
+
73
+ export interface IGetServiceVersionDraftStatusData {
74
+ /**
75
+ * How many functions of the Service a version created now would freeze at a version other than the one
76
+ * the last Service version froze: a function new to the Service, a draft that differs from its last
77
+ * version (an invalid draft counts), or a function version published since. Same rule as
78
+ * `POST .../version`; 0 for a Service without functions.
79
+ */
80
+ changedFunctions: number;
81
+ /**
82
+ * How many tasks of the draft differ from the last Service version: added, modified (function, name,
83
+ * cron or time zone) or removed. 0 for a Service without tasks.
84
+ */
85
+ changedTasks: number;
86
+ /** How many event triggers of the draft differ from the last Service version: added, modified or removed. 0 for a Service that is not a Discord bot. */
87
+ changedEvents: number;
88
+ }
89
+ export type IGetServiceVersionDraftStatusResponse = IResponse<IGetServiceVersionDraftStatusData>;
90
+
91
+ export interface IGetServiceVersionData {
92
+ version: IReflexServiceVersion;
93
+ /** The version just before; null for the first one. */
94
+ previousVersion: IReflexServiceVersion | null;
95
+ /** The routes added, removed or modified since `previousVersion` (every route is ADDED for the first one). */
96
+ routeChanges: IReflexServiceVersionRouteChange[];
97
+ /** The commands added, removed or modified since `previousVersion`; empty for a Service that is not a Discord bot. */
98
+ commandChanges: IReflexServiceVersionCommandChange[];
99
+ /** The components added, removed or modified since `previousVersion`; empty for a Service that is not a Discord bot. */
100
+ componentChanges: IReflexServiceVersionComponentChange[];
101
+ /** The event triggers added, removed or modified since `previousVersion`; empty for a Service that is not a Discord bot. */
102
+ eventChanges: IReflexServiceVersionEventChange[];
103
+ /** The tasks added, removed or modified since `previousVersion` (every task is ADDED for the first one). */
104
+ taskChanges: IReflexServiceVersionTaskChange[];
105
+ }
106
+ export type IGetServiceVersionResponse = IResponse<IGetServiceVersionData>;
@@ -1,15 +1,19 @@
1
- export * from './reflex-definition.model';
2
- export * from './reflex-function.model';
3
- export * from './reflex-function-version.model';
4
- export * from './reflex-access-grant.model';
5
- export * from './reflex-run.model';
6
- export * from './reflex-execution-settings.model';
7
- export * from './reflex-step-stats.model';
8
- export * from './reflex-price-list.model';
9
- export * from './reflex-service.model';
10
- export * from './reflex-route.model';
11
- export * from './reflex-service-version.model';
12
- export * from './reflex-service-deployment.model';
13
- export * from './reflex-service-configuration.model';
14
- export * from './reflex-discord.model';
15
- export * from './reflex-task.model';
1
+ export * from './reflex-definition.model';
2
+ export * from './reflex-function.model';
3
+ export * from './reflex-function-version.model';
4
+ export * from './reflex-access-grant.model';
5
+ export * from './reflex-run.model';
6
+ export * from './reflex-execution-settings.model';
7
+ export * from './reflex-step-stats.model';
8
+ export * from './reflex-price-list.model';
9
+ export * from './reflex-service.model';
10
+ export * from './reflex-route.model';
11
+ export * from './reflex-service-version.model';
12
+ export * from './reflex-service-deployment.model';
13
+ export * from './reflex-service-configuration.model';
14
+ export * from './reflex-discord.model';
15
+ export * from './reflex-task.model';
16
+ export * from './reflex-discord-event.model';
17
+ export * from './reflex-bot-limits.model';
18
+ export * from './reflex-insights.model';
19
+ export * from './reflex-discord-event-log.model';
@@ -0,0 +1,92 @@
1
+ import type { BotEventBlockReason } from '../../enum';
2
+
3
+ /** Bounds of the per-bot limits and of their alerts. */
4
+ export const REFLEX_BOT_LIMITS = {
5
+ /** Events per minute added by one lot of the `reflex-bot-events` module. */
6
+ eventsPerMinutePerLot: 500,
7
+ /** Monthly spend cap, in cents: 10 EUR by default, from 1 to 500 EUR. */
8
+ monthlySpendCapDefaultCents: 1000,
9
+ monthlySpendCapMinCents: 100,
10
+ monthlySpendCapMaxCents: 50000,
11
+ /** Alert thresholds: at most 5 values, each from 1 to 100 (percent). */
12
+ alertThresholdsMax: 5,
13
+ alertThresholdMin: 1,
14
+ alertThresholdMax: 100,
15
+ /** Thresholds a bot starts with, for the monthly spend cap. */
16
+ spendCapDefaultThresholds: [80, 100],
17
+ /** Rate alert: minutes of the UTC day above `rateAlertDefaultPercent` of the rate, by default. */
18
+ rateAlertDefaultMinutes: 5,
19
+ rateAlertDefaultPercent: 80,
20
+ } as const;
21
+
22
+ /** The events per minute of a bot in one environment: the plan base plus the lots allocated to it. */
23
+ export interface IReflexBotEventRate {
24
+ /** From the plan of the organization (100, 250 or 500). */
25
+ baseEventsPerMinute: number;
26
+ /** Lots of 500 allocated to this bot, from 0 to `lotsMax`. */
27
+ lots: number;
28
+ lotsMax: number;
29
+ /** `baseEventsPerMinute + 500 * lots`. */
30
+ eventsPerMinute: number;
31
+ /** Event runs at once: `min(maxConcurrencyPerBot, ceil(eventsPerMinute / runsPerSlotPerMinute))`. */
32
+ concurrency: number;
33
+ /** Lots of the reserve of the organization nobody holds yet. */
34
+ reserveLotsFree: number;
35
+ }
36
+
37
+ /** The lots of the reserve of the organization a bot holds in one environment. */
38
+ export interface IReflexBotEventRateAllocation {
39
+ serviceId: string;
40
+ environmentId: string;
41
+ lots: number;
42
+ updatedAt: Date;
43
+ }
44
+
45
+ /** A bot going past its rate, as the Gateway counted it. */
46
+ export interface IReflexBotRateExcess {
47
+ /** Minutes of the UTC day spent above the alert percent of the rate. */
48
+ minutesAboveAlertToday: number;
49
+ /** Highest count of retained events in one minute, over the period. */
50
+ peakPerMinute: number;
51
+ /** Minutes in which at least one event was rejected for the rate. */
52
+ minutesAtCap: number;
53
+ }
54
+
55
+ /** The monthly spend cap of a bot: all its consumption of the month, included credits too, at the price of the lot. */
56
+ export interface IReflexBotMonthlySpendCap {
57
+ capCents: number;
58
+ spentCents: number;
59
+ /** `spentCents / capCents`, in percent; may go past 100. */
60
+ usedPercent: number;
61
+ }
62
+
63
+ /** Credits of the month a bot consumed, and its overage setting. */
64
+ export interface IReflexBotCredits {
65
+ /** `YYYY-MM`. */
66
+ month: string;
67
+ consumedMillicredits: number;
68
+ /** True when the bot bills overage past the credits of the organization. */
69
+ overageEnabled: boolean;
70
+ /** True when the organization allows overage of the credits metric at all. */
71
+ overageAllowedByOrganization: boolean;
72
+ }
73
+
74
+ /** Alert settings of one limit of a bot. */
75
+ export interface IReflexBotAlertSettings {
76
+ /** Percent values, at most 5, each from 1 to 100. */
77
+ thresholds: number[];
78
+ email: boolean;
79
+ inApp: boolean;
80
+ }
81
+
82
+ /** Alert settings of a bot in one environment. */
83
+ export interface IReflexBotAlerts {
84
+ rate: IReflexBotAlertSettings;
85
+ monthlySpendCap: IReflexBotAlertSettings;
86
+ }
87
+
88
+ /** What stops the events of a bot at the Gateway. */
89
+ export interface IReflexBotBlock {
90
+ reason: BotEventBlockReason;
91
+ since: Date;
92
+ }
@@ -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
+ }