@oneuptime/common 11.3.24 → 11.3.26

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 (189) hide show
  1. package/Models/DatabaseModels/AIConversation.ts +322 -0
  2. package/Models/DatabaseModels/AIConversationMessage.ts +495 -0
  3. package/Models/DatabaseModels/AIRun.ts +584 -0
  4. package/Models/DatabaseModels/AIRunEvent.ts +443 -0
  5. package/Models/DatabaseModels/Index.ts +8 -0
  6. package/Models/DatabaseModels/LlmLog.ts +26 -0
  7. package/Models/DatabaseModels/LlmProvider.ts +2 -2
  8. package/Server/API/AIChatAPI.ts +693 -0
  9. package/Server/API/LlmProviderAPI.ts +169 -0
  10. package/Server/API/MicrosoftTeamsAPI.ts +5 -0
  11. package/Server/API/SlackAPI.ts +663 -0
  12. package/Server/Infrastructure/Postgres/SchemaMigrations/1783363279075-AddAIChatModels.ts +245 -0
  13. package/Server/Infrastructure/Postgres/SchemaMigrations/1783443471795-AddLlmProviderToAIConversation.ts +36 -0
  14. package/Server/Infrastructure/Postgres/SchemaMigrations/1783453297388-AddAIChatWriteActionsAndWidgets.ts +46 -0
  15. package/Server/Infrastructure/Postgres/SchemaMigrations/1783461767405-MigrationName.ts +119 -0
  16. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +8 -0
  17. package/Server/Services/AIConversationMessageService.ts +39 -0
  18. package/Server/Services/AIConversationService.ts +63 -0
  19. package/Server/Services/AIRunEventService.ts +39 -0
  20. package/Server/Services/AIRunService.ts +39 -0
  21. package/Server/Services/AIService.ts +53 -31
  22. package/Server/Services/DatabaseService.ts +19 -0
  23. package/Server/Services/LlmProviderService.ts +110 -0
  24. package/Server/Services/ProjectService.ts +24 -0
  25. package/Server/Types/AnalyticsDatabase/ModelPermission.ts +74 -9
  26. package/Server/Utils/AI/AIChatPrivacyFilter.ts +28 -0
  27. package/Server/Utils/AI/Chat/ChatAgentRunner.ts +1054 -0
  28. package/Server/Utils/AI/Chat/ObservabilityAssistant.ts +239 -0
  29. package/Server/Utils/AI/Chat/ObservabilityChatPrompt.ts +51 -0
  30. package/Server/Utils/AI/Toolbox/AlertTools.ts +201 -0
  31. package/Server/Utils/AI/Toolbox/AlertWriteTools.ts +174 -0
  32. package/Server/Utils/AI/Toolbox/ContextTools.ts +189 -0
  33. package/Server/Utils/AI/Toolbox/ExceptionTools.ts +149 -0
  34. package/Server/Utils/AI/Toolbox/IncidentTools.ts +204 -0
  35. package/Server/Utils/AI/Toolbox/IncidentWriteTools.ts +350 -0
  36. package/Server/Utils/AI/Toolbox/Index.ts +228 -0
  37. package/Server/Utils/AI/Toolbox/LogTools.ts +339 -0
  38. package/Server/Utils/AI/Toolbox/MetricTools.ts +179 -0
  39. package/Server/Utils/AI/Toolbox/MonitorTools.ts +193 -0
  40. package/Server/Utils/AI/Toolbox/Serializer.ts +257 -0
  41. package/Server/Utils/AI/Toolbox/ToolTypes.ts +249 -0
  42. package/Server/Utils/AI/Toolbox/TraceTools.ts +402 -0
  43. package/Server/Utils/AI/Toolbox/WidgetBuilder.ts +189 -0
  44. package/Server/Utils/LLM/LLMService.ts +502 -92
  45. package/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.ts +512 -19
  46. package/Server/Utils/Workspace/Slack/Slack.ts +80 -0
  47. package/Server/Utils/Workspace/Slack/app-manifest.json +16 -1
  48. package/Tests/Server/Utils/AI/AIChatModelACL.test.ts +42 -0
  49. package/Tests/Server/Utils/AI/ChatAgentHelpers.test.ts +89 -0
  50. package/Tests/Server/Utils/AI/LLMServiceBaseUrl.test.ts +139 -0
  51. package/Tests/Server/Utils/AI/LLMServiceToolCalling.test.ts +308 -0
  52. package/Tests/Server/Utils/AI/ToolArgsGetTimeRange.test.ts +62 -0
  53. package/Tests/Server/Utils/AI/ToolArgsScopeServiceIds.test.ts +79 -0
  54. package/Tests/Server/Utils/AI/ToolResultSerializer.test.ts +155 -0
  55. package/Tests/Types/Billing/SubscriptionStatus.test.ts +127 -0
  56. package/Tests/Types/Metrics/RecordingRuleDefinition.test.ts +213 -0
  57. package/Types/AI/AIChatMessageRole.ts +6 -0
  58. package/Types/AI/AIChatMessageStatus.ts +32 -0
  59. package/Types/AI/AIChatPermissionMode.ts +69 -0
  60. package/Types/AI/AIChatTypes.ts +231 -0
  61. package/Types/AI/AIRunEventType.ts +17 -0
  62. package/Types/AI/AIRunStatus.ts +28 -0
  63. package/Types/AI/AIRunType.ts +6 -0
  64. package/Types/LLM/LlmType.ts +6 -0
  65. package/UI/Components/Header/HeaderIconDropdownButton.tsx +22 -12
  66. package/UI/Components/Markdown.tsx/MarkdownViewer.tsx +35 -3
  67. package/UI/Components/Page/Page.tsx +14 -0
  68. package/UI/Utils/LlmTypeDropdownOptions.ts +40 -0
  69. package/UI/Utils/TestLLMProvider.ts +59 -0
  70. package/build/dist/Models/DatabaseModels/AIConversation.js +345 -0
  71. package/build/dist/Models/DatabaseModels/AIConversation.js.map +1 -0
  72. package/build/dist/Models/DatabaseModels/AIConversationMessage.js +521 -0
  73. package/build/dist/Models/DatabaseModels/AIConversationMessage.js.map +1 -0
  74. package/build/dist/Models/DatabaseModels/AIRun.js +619 -0
  75. package/build/dist/Models/DatabaseModels/AIRun.js.map +1 -0
  76. package/build/dist/Models/DatabaseModels/AIRunEvent.js +469 -0
  77. package/build/dist/Models/DatabaseModels/AIRunEvent.js.map +1 -0
  78. package/build/dist/Models/DatabaseModels/Index.js +8 -0
  79. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  80. package/build/dist/Models/DatabaseModels/LlmLog.js +28 -0
  81. package/build/dist/Models/DatabaseModels/LlmLog.js.map +1 -1
  82. package/build/dist/Models/DatabaseModels/LlmProvider.js +2 -2
  83. package/build/dist/Models/DatabaseModels/LlmProvider.js.map +1 -1
  84. package/build/dist/Server/API/AIChatAPI.js +498 -0
  85. package/build/dist/Server/API/AIChatAPI.js.map +1 -0
  86. package/build/dist/Server/API/LlmProviderAPI.js +107 -1
  87. package/build/dist/Server/API/LlmProviderAPI.js.map +1 -1
  88. package/build/dist/Server/API/MicrosoftTeamsAPI.js +4 -0
  89. package/build/dist/Server/API/MicrosoftTeamsAPI.js.map +1 -1
  90. package/build/dist/Server/API/SlackAPI.js +442 -0
  91. package/build/dist/Server/API/SlackAPI.js.map +1 -1
  92. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783363279075-AddAIChatModels.js +96 -0
  93. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783363279075-AddAIChatModels.js.map +1 -0
  94. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783443471795-AddLlmProviderToAIConversation.js +25 -0
  95. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783443471795-AddLlmProviderToAIConversation.js.map +1 -0
  96. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783453297388-AddAIChatWriteActionsAndWidgets.js +31 -0
  97. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783453297388-AddAIChatWriteActionsAndWidgets.js.map +1 -0
  98. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783461767405-MigrationName.js +46 -0
  99. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1783461767405-MigrationName.js.map +1 -0
  100. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +8 -0
  101. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  102. package/build/dist/Server/Services/AIConversationMessageService.js +34 -0
  103. package/build/dist/Server/Services/AIConversationMessageService.js.map +1 -0
  104. package/build/dist/Server/Services/AIConversationService.js +42 -0
  105. package/build/dist/Server/Services/AIConversationService.js.map +1 -0
  106. package/build/dist/Server/Services/AIRunEventService.js +34 -0
  107. package/build/dist/Server/Services/AIRunEventService.js.map +1 -0
  108. package/build/dist/Server/Services/AIRunService.js +34 -0
  109. package/build/dist/Server/Services/AIRunService.js.map +1 -0
  110. package/build/dist/Server/Services/AIService.js +31 -23
  111. package/build/dist/Server/Services/AIService.js.map +1 -1
  112. package/build/dist/Server/Services/DatabaseService.js +10 -0
  113. package/build/dist/Server/Services/DatabaseService.js.map +1 -1
  114. package/build/dist/Server/Services/LlmProviderService.js +108 -0
  115. package/build/dist/Server/Services/LlmProviderService.js.map +1 -1
  116. package/build/dist/Server/Services/ProjectService.js +25 -0
  117. package/build/dist/Server/Services/ProjectService.js.map +1 -1
  118. package/build/dist/Server/Types/AnalyticsDatabase/ModelPermission.js +50 -7
  119. package/build/dist/Server/Types/AnalyticsDatabase/ModelPermission.js.map +1 -1
  120. package/build/dist/Server/Utils/AI/AIChatPrivacyFilter.js +18 -0
  121. package/build/dist/Server/Utils/AI/AIChatPrivacyFilter.js.map +1 -0
  122. package/build/dist/Server/Utils/AI/Chat/ChatAgentRunner.js +745 -0
  123. package/build/dist/Server/Utils/AI/Chat/ChatAgentRunner.js.map +1 -0
  124. package/build/dist/Server/Utils/AI/Chat/ObservabilityAssistant.js +165 -0
  125. package/build/dist/Server/Utils/AI/Chat/ObservabilityAssistant.js.map +1 -0
  126. package/build/dist/Server/Utils/AI/Chat/ObservabilityChatPrompt.js +44 -0
  127. package/build/dist/Server/Utils/AI/Chat/ObservabilityChatPrompt.js.map +1 -0
  128. package/build/dist/Server/Utils/AI/Toolbox/AlertTools.js +167 -0
  129. package/build/dist/Server/Utils/AI/Toolbox/AlertTools.js.map +1 -0
  130. package/build/dist/Server/Utils/AI/Toolbox/AlertWriteTools.js +136 -0
  131. package/build/dist/Server/Utils/AI/Toolbox/AlertWriteTools.js.map +1 -0
  132. package/build/dist/Server/Utils/AI/Toolbox/ContextTools.js +141 -0
  133. package/build/dist/Server/Utils/AI/Toolbox/ContextTools.js.map +1 -0
  134. package/build/dist/Server/Utils/AI/Toolbox/ExceptionTools.js +117 -0
  135. package/build/dist/Server/Utils/AI/Toolbox/ExceptionTools.js.map +1 -0
  136. package/build/dist/Server/Utils/AI/Toolbox/IncidentTools.js +167 -0
  137. package/build/dist/Server/Utils/AI/Toolbox/IncidentTools.js.map +1 -0
  138. package/build/dist/Server/Utils/AI/Toolbox/IncidentWriteTools.js +280 -0
  139. package/build/dist/Server/Utils/AI/Toolbox/IncidentWriteTools.js.map +1 -0
  140. package/build/dist/Server/Utils/AI/Toolbox/Index.js +150 -0
  141. package/build/dist/Server/Utils/AI/Toolbox/Index.js.map +1 -0
  142. package/build/dist/Server/Utils/AI/Toolbox/LogTools.js +246 -0
  143. package/build/dist/Server/Utils/AI/Toolbox/LogTools.js.map +1 -0
  144. package/build/dist/Server/Utils/AI/Toolbox/MetricTools.js +120 -0
  145. package/build/dist/Server/Utils/AI/Toolbox/MetricTools.js.map +1 -0
  146. package/build/dist/Server/Utils/AI/Toolbox/MonitorTools.js +158 -0
  147. package/build/dist/Server/Utils/AI/Toolbox/MonitorTools.js.map +1 -0
  148. package/build/dist/Server/Utils/AI/Toolbox/Serializer.js +188 -0
  149. package/build/dist/Server/Utils/AI/Toolbox/Serializer.js.map +1 -0
  150. package/build/dist/Server/Utils/AI/Toolbox/ToolTypes.js +142 -0
  151. package/build/dist/Server/Utils/AI/Toolbox/ToolTypes.js.map +1 -0
  152. package/build/dist/Server/Utils/AI/Toolbox/TraceTools.js +309 -0
  153. package/build/dist/Server/Utils/AI/Toolbox/TraceTools.js.map +1 -0
  154. package/build/dist/Server/Utils/AI/Toolbox/WidgetBuilder.js +120 -0
  155. package/build/dist/Server/Utils/AI/Toolbox/WidgetBuilder.js.map +1 -0
  156. package/build/dist/Server/Utils/LLM/LLMService.js +372 -88
  157. package/build/dist/Server/Utils/LLM/LLMService.js.map +1 -1
  158. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +378 -15
  159. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
  160. package/build/dist/Server/Utils/Workspace/Slack/Slack.js +59 -0
  161. package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
  162. package/build/dist/Server/Utils/Workspace/Slack/app-manifest.json +16 -1
  163. package/build/dist/Types/AI/AIChatMessageRole.js +7 -0
  164. package/build/dist/Types/AI/AIChatMessageRole.js.map +1 -0
  165. package/build/dist/Types/AI/AIChatMessageStatus.js +27 -0
  166. package/build/dist/Types/AI/AIChatMessageStatus.js.map +1 -0
  167. package/build/dist/Types/AI/AIChatPermissionMode.js +53 -0
  168. package/build/dist/Types/AI/AIChatPermissionMode.js.map +1 -0
  169. package/build/dist/Types/AI/AIChatTypes.js +74 -0
  170. package/build/dist/Types/AI/AIChatTypes.js.map +1 -0
  171. package/build/dist/Types/AI/AIRunEventType.js +18 -0
  172. package/build/dist/Types/AI/AIRunEventType.js.map +1 -0
  173. package/build/dist/Types/AI/AIRunStatus.js +26 -0
  174. package/build/dist/Types/AI/AIRunStatus.js.map +1 -0
  175. package/build/dist/Types/AI/AIRunType.js +7 -0
  176. package/build/dist/Types/AI/AIRunType.js.map +1 -0
  177. package/build/dist/Types/LLM/LlmType.js +6 -0
  178. package/build/dist/Types/LLM/LlmType.js.map +1 -1
  179. package/build/dist/UI/Components/Header/HeaderIconDropdownButton.js +10 -5
  180. package/build/dist/UI/Components/Header/HeaderIconDropdownButton.js.map +1 -1
  181. package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js +18 -4
  182. package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js.map +1 -1
  183. package/build/dist/UI/Components/Page/Page.js +3 -1
  184. package/build/dist/UI/Components/Page/Page.js.map +1 -1
  185. package/build/dist/UI/Utils/LlmTypeDropdownOptions.js +38 -0
  186. package/build/dist/UI/Utils/LlmTypeDropdownOptions.js.map +1 -0
  187. package/build/dist/UI/Utils/TestLLMProvider.js +37 -0
  188. package/build/dist/UI/Utils/TestLLMProvider.js.map +1 -0
  189. package/package.json +1 -1
@@ -0,0 +1,584 @@
1
+ import AIConversation from "./AIConversation";
2
+ import Project from "./Project";
3
+ import User from "./User";
4
+ import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
5
+ import Route from "../../Types/API/Route";
6
+ import { PlanType } from "../../Types/Billing/SubscriptionPlan";
7
+ import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
8
+ import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
9
+ import TableBillingAccessControl from "../../Types/Database/AccessControl/TableBillingAccessControl";
10
+ import ColumnLength from "../../Types/Database/ColumnLength";
11
+ import ColumnType from "../../Types/Database/ColumnType";
12
+ import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
13
+ import TableColumn from "../../Types/Database/TableColumn";
14
+ import TableColumnType from "../../Types/Database/TableColumnType";
15
+ import TableMetadata from "../../Types/Database/TableMetadata";
16
+ import TenantColumn from "../../Types/Database/TenantColumn";
17
+ import IconProp from "../../Types/Icon/IconProp";
18
+ import ObjectID from "../../Types/ObjectID";
19
+ import Permission from "../../Types/Permission";
20
+ import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
21
+ import EnableDocumentation from "../../Types/Database/EnableDocumentation";
22
+ import AIRunType from "../../Types/AI/AIRunType";
23
+ import AIRunStatus from "../../Types/AI/AIRunStatus";
24
+ import {
25
+ AIRunEgressManifest,
26
+ AIRunPausedState,
27
+ } from "../../Types/AI/AIChatTypes";
28
+
29
+ /*
30
+ * One AI agent execution (a chat turn today; an investigation later). Runs
31
+ * are written only by the server (empty create/update table permissions) and
32
+ * carry cost, token counts, a heartbeat for stale-run detection and the
33
+ * per-run egress manifest.
34
+ */
35
+ @EnableDocumentation()
36
+ @TableBillingAccessControl({
37
+ create: PlanType.Growth,
38
+ read: PlanType.Free,
39
+ update: PlanType.Growth,
40
+ delete: PlanType.Free,
41
+ })
42
+ @TenantColumn("projectId")
43
+ @CrudApiEndpoint(new Route("/ai-run"))
44
+ @Entity({
45
+ name: "AIRun",
46
+ })
47
+ @TableMetadata({
48
+ tableName: "AIRun",
49
+ singularName: "AI Run",
50
+ pluralName: "AI Runs",
51
+ icon: IconProp.Bolt,
52
+ tableDescription:
53
+ "One AI agent execution: LLM calls, tool calls, cost, and the egress manifest of what was sent to the LLM.",
54
+ enableRealtimeEventsOn: {
55
+ create: true,
56
+ update: true,
57
+ },
58
+ })
59
+ @TableAccessControl({
60
+ create: [],
61
+ read: [
62
+ Permission.ProjectOwner,
63
+ Permission.ProjectAdmin,
64
+ Permission.ProjectMember,
65
+ ],
66
+ delete: [],
67
+ update: [],
68
+ })
69
+ export default class AIRun extends BaseModel {
70
+ @ColumnAccessControl({
71
+ create: [],
72
+ read: [
73
+ Permission.ProjectOwner,
74
+ Permission.ProjectAdmin,
75
+ Permission.ProjectMember,
76
+ ],
77
+ update: [],
78
+ })
79
+ @TableColumn({
80
+ type: TableColumnType.Entity,
81
+ required: true,
82
+ modelType: Project,
83
+ manyToOneRelationColumn: "projectId",
84
+ title: "Project",
85
+ description: "Project this run belongs to.",
86
+ })
87
+ @ManyToOne(
88
+ () => {
89
+ return Project;
90
+ },
91
+ {
92
+ cascade: false,
93
+ eager: false,
94
+ nullable: false,
95
+ onDelete: "CASCADE",
96
+ orphanedRowAction: "nullify",
97
+ },
98
+ )
99
+ @JoinColumn({ name: "projectId" })
100
+ public project?: Project = undefined;
101
+
102
+ @ColumnAccessControl({
103
+ create: [],
104
+ read: [
105
+ Permission.ProjectOwner,
106
+ Permission.ProjectAdmin,
107
+ Permission.ProjectMember,
108
+ ],
109
+ update: [],
110
+ })
111
+ @Index()
112
+ @TableColumn({
113
+ type: TableColumnType.ObjectID,
114
+ required: true,
115
+ canReadOnRelationQuery: true,
116
+ title: "Project ID",
117
+ description: "ID of the project this run belongs to.",
118
+ })
119
+ @Column({
120
+ type: ColumnType.ObjectID,
121
+ nullable: false,
122
+ transformer: ObjectID.getDatabaseTransformer(),
123
+ })
124
+ public projectId?: ObjectID = undefined;
125
+
126
+ @ColumnAccessControl({
127
+ create: [],
128
+ read: [
129
+ Permission.ProjectOwner,
130
+ Permission.ProjectAdmin,
131
+ Permission.ProjectMember,
132
+ ],
133
+ update: [],
134
+ })
135
+ @Index()
136
+ @TableColumn({
137
+ required: true,
138
+ type: TableColumnType.ShortText,
139
+ title: "Run Type",
140
+ description: "Type of AI run: Chat or Investigation.",
141
+ canReadOnRelationQuery: true,
142
+ })
143
+ @Column({
144
+ nullable: false,
145
+ type: ColumnType.ShortText,
146
+ length: ColumnLength.ShortText,
147
+ })
148
+ public runType?: AIRunType = undefined;
149
+
150
+ @ColumnAccessControl({
151
+ create: [],
152
+ read: [
153
+ Permission.ProjectOwner,
154
+ Permission.ProjectAdmin,
155
+ Permission.ProjectMember,
156
+ ],
157
+ update: [],
158
+ })
159
+ @Index()
160
+ @TableColumn({
161
+ required: true,
162
+ type: TableColumnType.ShortText,
163
+ title: "Status",
164
+ description: "Current status of this run.",
165
+ canReadOnRelationQuery: true,
166
+ })
167
+ @Column({
168
+ nullable: false,
169
+ type: ColumnType.ShortText,
170
+ length: ColumnLength.ShortText,
171
+ default: AIRunStatus.Running,
172
+ })
173
+ public status?: AIRunStatus = undefined;
174
+
175
+ @ColumnAccessControl({
176
+ create: [],
177
+ read: [
178
+ Permission.ProjectOwner,
179
+ Permission.ProjectAdmin,
180
+ Permission.ProjectMember,
181
+ ],
182
+ update: [],
183
+ })
184
+ @TableColumn({
185
+ type: TableColumnType.Entity,
186
+ required: false,
187
+ modelType: User,
188
+ manyToOneRelationColumn: "userId",
189
+ title: "User",
190
+ description: "User who triggered this run.",
191
+ })
192
+ @ManyToOne(
193
+ () => {
194
+ return User;
195
+ },
196
+ {
197
+ cascade: false,
198
+ eager: false,
199
+ nullable: true,
200
+ onDelete: "SET NULL",
201
+ orphanedRowAction: "nullify",
202
+ },
203
+ )
204
+ @JoinColumn({ name: "userId" })
205
+ public user?: User = undefined;
206
+
207
+ @ColumnAccessControl({
208
+ create: [],
209
+ read: [
210
+ Permission.ProjectOwner,
211
+ Permission.ProjectAdmin,
212
+ Permission.ProjectMember,
213
+ ],
214
+ update: [],
215
+ })
216
+ @Index()
217
+ @TableColumn({
218
+ type: TableColumnType.ObjectID,
219
+ required: false,
220
+ canReadOnRelationQuery: true,
221
+ title: "User ID",
222
+ description: "ID of the user who triggered this run.",
223
+ })
224
+ @Column({
225
+ type: ColumnType.ObjectID,
226
+ nullable: true,
227
+ transformer: ObjectID.getDatabaseTransformer(),
228
+ })
229
+ public userId?: ObjectID = undefined;
230
+
231
+ @ColumnAccessControl({
232
+ create: [],
233
+ read: [
234
+ Permission.ProjectOwner,
235
+ Permission.ProjectAdmin,
236
+ Permission.ProjectMember,
237
+ ],
238
+ update: [],
239
+ })
240
+ @TableColumn({
241
+ type: TableColumnType.Entity,
242
+ required: false,
243
+ modelType: AIConversation,
244
+ manyToOneRelationColumn: "conversationId",
245
+ title: "Conversation",
246
+ description: "Conversation this run belongs to (for chat runs).",
247
+ })
248
+ @ManyToOne(
249
+ () => {
250
+ return AIConversation;
251
+ },
252
+ {
253
+ cascade: false,
254
+ eager: false,
255
+ nullable: true,
256
+ onDelete: "CASCADE",
257
+ orphanedRowAction: "nullify",
258
+ },
259
+ )
260
+ @JoinColumn({ name: "conversationId" })
261
+ public conversation?: AIConversation = undefined;
262
+
263
+ @ColumnAccessControl({
264
+ create: [],
265
+ read: [
266
+ Permission.ProjectOwner,
267
+ Permission.ProjectAdmin,
268
+ Permission.ProjectMember,
269
+ ],
270
+ update: [],
271
+ })
272
+ @Index()
273
+ @TableColumn({
274
+ type: TableColumnType.ObjectID,
275
+ required: false,
276
+ canReadOnRelationQuery: true,
277
+ title: "Conversation ID",
278
+ description: "ID of the conversation this run belongs to.",
279
+ })
280
+ @Column({
281
+ type: ColumnType.ObjectID,
282
+ nullable: true,
283
+ transformer: ObjectID.getDatabaseTransformer(),
284
+ })
285
+ public conversationId?: ObjectID = undefined;
286
+
287
+ @ColumnAccessControl({
288
+ create: [],
289
+ read: [
290
+ Permission.ProjectOwner,
291
+ Permission.ProjectAdmin,
292
+ Permission.ProjectMember,
293
+ ],
294
+ update: [],
295
+ })
296
+ @TableColumn({
297
+ required: false,
298
+ type: TableColumnType.Date,
299
+ title: "Started At",
300
+ description: "When the run started.",
301
+ })
302
+ @Column({
303
+ nullable: true,
304
+ type: ColumnType.Date,
305
+ })
306
+ public startedAt?: Date = undefined;
307
+
308
+ @ColumnAccessControl({
309
+ create: [],
310
+ read: [
311
+ Permission.ProjectOwner,
312
+ Permission.ProjectAdmin,
313
+ Permission.ProjectMember,
314
+ ],
315
+ update: [],
316
+ })
317
+ @TableColumn({
318
+ required: false,
319
+ type: TableColumnType.Date,
320
+ title: "Completed At",
321
+ description: "When the run completed.",
322
+ })
323
+ @Column({
324
+ nullable: true,
325
+ type: ColumnType.Date,
326
+ })
327
+ public completedAt?: Date = undefined;
328
+
329
+ @ColumnAccessControl({
330
+ create: [],
331
+ read: [
332
+ Permission.ProjectOwner,
333
+ Permission.ProjectAdmin,
334
+ Permission.ProjectMember,
335
+ ],
336
+ update: [],
337
+ })
338
+ @TableColumn({
339
+ required: false,
340
+ type: TableColumnType.Date,
341
+ title: "Last Heartbeat At",
342
+ description:
343
+ "Last time the run reported progress. Used to detect and fail stale runs.",
344
+ })
345
+ @Column({
346
+ nullable: true,
347
+ type: ColumnType.Date,
348
+ })
349
+ public lastHeartbeatAt?: Date = undefined;
350
+
351
+ @ColumnAccessControl({
352
+ create: [],
353
+ read: [
354
+ Permission.ProjectOwner,
355
+ Permission.ProjectAdmin,
356
+ Permission.ProjectMember,
357
+ ],
358
+ update: [],
359
+ })
360
+ @TableColumn({
361
+ required: false,
362
+ type: TableColumnType.Number,
363
+ title: "LLM Call Count",
364
+ description: "Number of LLM calls made during this run.",
365
+ })
366
+ @Column({
367
+ type: ColumnType.Number,
368
+ nullable: true,
369
+ default: 0,
370
+ })
371
+ public llmCallCount?: number = undefined;
372
+
373
+ @ColumnAccessControl({
374
+ create: [],
375
+ read: [
376
+ Permission.ProjectOwner,
377
+ Permission.ProjectAdmin,
378
+ Permission.ProjectMember,
379
+ ],
380
+ update: [],
381
+ })
382
+ @TableColumn({
383
+ required: false,
384
+ type: TableColumnType.Number,
385
+ title: "Tool Call Count",
386
+ description: "Number of tool calls executed during this run.",
387
+ })
388
+ @Column({
389
+ type: ColumnType.Number,
390
+ nullable: true,
391
+ default: 0,
392
+ })
393
+ public toolCallCount?: number = undefined;
394
+
395
+ @ColumnAccessControl({
396
+ create: [],
397
+ read: [
398
+ Permission.ProjectOwner,
399
+ Permission.ProjectAdmin,
400
+ Permission.ProjectMember,
401
+ ],
402
+ update: [],
403
+ })
404
+ @TableColumn({
405
+ required: false,
406
+ type: TableColumnType.Number,
407
+ title: "Total Tokens",
408
+ description: "Total LLM tokens used during this run.",
409
+ })
410
+ @Column({
411
+ type: ColumnType.Number,
412
+ nullable: true,
413
+ default: 0,
414
+ })
415
+ public totalTokens?: number = undefined;
416
+
417
+ @ColumnAccessControl({
418
+ create: [],
419
+ read: [
420
+ Permission.ProjectOwner,
421
+ Permission.ProjectAdmin,
422
+ Permission.ProjectMember,
423
+ ],
424
+ update: [],
425
+ })
426
+ @TableColumn({
427
+ required: false,
428
+ type: TableColumnType.Number,
429
+ title: "Total Cost (USD Cents)",
430
+ description: "Total billed cost of this run in USD cents.",
431
+ })
432
+ @Column({
433
+ type: ColumnType.Number,
434
+ nullable: true,
435
+ default: 0,
436
+ })
437
+ public totalCostInUSDCents?: number = undefined;
438
+
439
+ @ColumnAccessControl({
440
+ create: [],
441
+ read: [
442
+ Permission.ProjectOwner,
443
+ Permission.ProjectAdmin,
444
+ Permission.ProjectMember,
445
+ ],
446
+ update: [],
447
+ })
448
+ @TableColumn({
449
+ required: false,
450
+ type: TableColumnType.JSON,
451
+ title: "Egress Manifest",
452
+ description:
453
+ "What data was sent to which LLM during this run: provider, model, and per-tool row/byte/redaction counts.",
454
+ })
455
+ @Column({
456
+ nullable: true,
457
+ type: ColumnType.JSON,
458
+ })
459
+ public egressManifest?: AIRunEgressManifest = undefined;
460
+
461
+ /*
462
+ * The serialized in-flight state of a turn that paused to wait for tool
463
+ * approval (see AIRunPausedState). Server-only: it carries the full LLM
464
+ * conversation for this turn, so it is never exposed through the CRUD API
465
+ * (empty read ACL). ChatAgentRunner.resumeTurn reads it with isRoot to
466
+ * continue the loop, and clears it once the run finalizes.
467
+ */
468
+ @ColumnAccessControl({
469
+ create: [],
470
+ read: [],
471
+ update: [],
472
+ })
473
+ @TableColumn({
474
+ required: false,
475
+ type: TableColumnType.JSON,
476
+ title: "Paused State",
477
+ description:
478
+ "Internal: the serialized turn state saved while waiting for tool approval.",
479
+ })
480
+ @Column({
481
+ nullable: true,
482
+ type: ColumnType.JSON,
483
+ })
484
+ public pausedState?: AIRunPausedState = undefined;
485
+
486
+ @ColumnAccessControl({
487
+ create: [],
488
+ read: [
489
+ Permission.ProjectOwner,
490
+ Permission.ProjectAdmin,
491
+ Permission.ProjectMember,
492
+ ],
493
+ update: [],
494
+ })
495
+ @TableColumn({
496
+ required: false,
497
+ type: TableColumnType.LongText,
498
+ title: "Error Message",
499
+ description: "Error message if the run failed.",
500
+ })
501
+ @Column({
502
+ nullable: true,
503
+ type: ColumnType.LongText,
504
+ length: ColumnLength.LongText,
505
+ })
506
+ public errorMessage?: string = undefined;
507
+
508
+ @ColumnAccessControl({
509
+ create: [],
510
+ read: [],
511
+ update: [],
512
+ })
513
+ @TableColumn({ type: TableColumnType.Entity, modelType: User })
514
+ @ManyToOne(
515
+ () => {
516
+ return User;
517
+ },
518
+ {
519
+ cascade: false,
520
+ eager: false,
521
+ nullable: true,
522
+ onDelete: "SET NULL",
523
+ orphanedRowAction: "nullify",
524
+ },
525
+ )
526
+ @JoinColumn({ name: "deletedByUserId" })
527
+ public deletedByUser?: User = undefined;
528
+
529
+ @ColumnAccessControl({
530
+ create: [],
531
+ read: [],
532
+ update: [],
533
+ })
534
+ @TableColumn({
535
+ type: TableColumnType.ObjectID,
536
+ title: "Deleted by User ID",
537
+ description:
538
+ "User ID who deleted this object (if this object was deleted by a User)",
539
+ })
540
+ @Column({
541
+ type: ColumnType.ObjectID,
542
+ nullable: true,
543
+ transformer: ObjectID.getDatabaseTransformer(),
544
+ })
545
+ public deletedByUserId?: ObjectID = undefined;
546
+
547
+ @ColumnAccessControl({
548
+ create: [],
549
+ read: [],
550
+ update: [],
551
+ })
552
+ @TableColumn({ type: TableColumnType.Entity, modelType: User })
553
+ @ManyToOne(
554
+ () => {
555
+ return User;
556
+ },
557
+ {
558
+ eager: false,
559
+ nullable: true,
560
+ onDelete: "SET NULL",
561
+ orphanedRowAction: "nullify",
562
+ },
563
+ )
564
+ @JoinColumn({ name: "createdByUserId" })
565
+ public createdByUser?: User = undefined;
566
+
567
+ @ColumnAccessControl({
568
+ create: [],
569
+ read: [],
570
+ update: [],
571
+ })
572
+ @TableColumn({
573
+ type: TableColumnType.ObjectID,
574
+ title: "Created by User ID",
575
+ description:
576
+ "User ID who created this object (if this object was created by a User)",
577
+ })
578
+ @Column({
579
+ type: ColumnType.ObjectID,
580
+ nullable: true,
581
+ transformer: ObjectID.getDatabaseTransformer(),
582
+ })
583
+ public createdByUserId?: ObjectID = undefined;
584
+ }