@oneuptime/common 11.3.25 → 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,495 @@
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 AIChatMessageRole from "../../Types/AI/AIChatMessageRole";
23
+ import AIChatMessageStatus from "../../Types/AI/AIChatMessageStatus";
24
+ import {
25
+ AIChatCitation,
26
+ AIChatToolAction,
27
+ AIChatWidget,
28
+ } from "../../Types/AI/AIChatTypes";
29
+
30
+ /*
31
+ * A single message in an AI conversation. Create/update table permissions are
32
+ * deliberately EMPTY: only the server (isRoot) writes message rows. This
33
+ * prevents project members from forging assistant messages with fabricated
34
+ * citations through the auto-generated CRUD API.
35
+ */
36
+ @EnableDocumentation()
37
+ @TableBillingAccessControl({
38
+ create: PlanType.Growth,
39
+ read: PlanType.Free,
40
+ update: PlanType.Growth,
41
+ delete: PlanType.Free,
42
+ })
43
+ @TenantColumn("projectId")
44
+ @CrudApiEndpoint(new Route("/ai-conversation-message"))
45
+ @Entity({
46
+ name: "AIConversationMessage",
47
+ })
48
+ @TableMetadata({
49
+ tableName: "AIConversationMessage",
50
+ singularName: "AI Conversation Message",
51
+ pluralName: "AI Conversation Messages",
52
+ icon: IconProp.ChatBubbleLeft,
53
+ tableDescription:
54
+ "A message in an AI conversation. Assistant messages carry citations, tool events and cost.",
55
+ enableRealtimeEventsOn: {
56
+ create: true,
57
+ update: true,
58
+ },
59
+ })
60
+ @TableAccessControl({
61
+ create: [],
62
+ read: [
63
+ Permission.ProjectOwner,
64
+ Permission.ProjectAdmin,
65
+ Permission.ProjectMember,
66
+ ],
67
+ delete: [],
68
+ update: [],
69
+ })
70
+ export default class AIConversationMessage extends BaseModel {
71
+ @ColumnAccessControl({
72
+ create: [],
73
+ read: [
74
+ Permission.ProjectOwner,
75
+ Permission.ProjectAdmin,
76
+ Permission.ProjectMember,
77
+ ],
78
+ update: [],
79
+ })
80
+ @TableColumn({
81
+ type: TableColumnType.Entity,
82
+ required: true,
83
+ modelType: Project,
84
+ manyToOneRelationColumn: "projectId",
85
+ title: "Project",
86
+ description: "Project this message belongs to.",
87
+ })
88
+ @ManyToOne(
89
+ () => {
90
+ return Project;
91
+ },
92
+ {
93
+ cascade: false,
94
+ eager: false,
95
+ nullable: false,
96
+ onDelete: "CASCADE",
97
+ orphanedRowAction: "nullify",
98
+ },
99
+ )
100
+ @JoinColumn({ name: "projectId" })
101
+ public project?: Project = undefined;
102
+
103
+ @ColumnAccessControl({
104
+ create: [],
105
+ read: [
106
+ Permission.ProjectOwner,
107
+ Permission.ProjectAdmin,
108
+ Permission.ProjectMember,
109
+ ],
110
+ update: [],
111
+ })
112
+ @Index()
113
+ @TableColumn({
114
+ type: TableColumnType.ObjectID,
115
+ required: true,
116
+ canReadOnRelationQuery: true,
117
+ title: "Project ID",
118
+ description: "ID of the project this message belongs to.",
119
+ })
120
+ @Column({
121
+ type: ColumnType.ObjectID,
122
+ nullable: false,
123
+ transformer: ObjectID.getDatabaseTransformer(),
124
+ })
125
+ public projectId?: ObjectID = undefined;
126
+
127
+ @ColumnAccessControl({
128
+ create: [],
129
+ read: [
130
+ Permission.ProjectOwner,
131
+ Permission.ProjectAdmin,
132
+ Permission.ProjectMember,
133
+ ],
134
+ update: [],
135
+ })
136
+ @TableColumn({
137
+ type: TableColumnType.Entity,
138
+ required: true,
139
+ modelType: AIConversation,
140
+ manyToOneRelationColumn: "conversationId",
141
+ title: "Conversation",
142
+ description: "Conversation this message belongs to.",
143
+ })
144
+ @ManyToOne(
145
+ () => {
146
+ return AIConversation;
147
+ },
148
+ {
149
+ cascade: false,
150
+ eager: false,
151
+ nullable: false,
152
+ onDelete: "CASCADE",
153
+ orphanedRowAction: "nullify",
154
+ },
155
+ )
156
+ @JoinColumn({ name: "conversationId" })
157
+ public conversation?: AIConversation = undefined;
158
+
159
+ @ColumnAccessControl({
160
+ create: [],
161
+ read: [
162
+ Permission.ProjectOwner,
163
+ Permission.ProjectAdmin,
164
+ Permission.ProjectMember,
165
+ ],
166
+ update: [],
167
+ })
168
+ @Index()
169
+ @TableColumn({
170
+ type: TableColumnType.ObjectID,
171
+ required: true,
172
+ canReadOnRelationQuery: true,
173
+ title: "Conversation ID",
174
+ description: "ID of the conversation this message belongs to.",
175
+ })
176
+ @Column({
177
+ type: ColumnType.ObjectID,
178
+ nullable: false,
179
+ transformer: ObjectID.getDatabaseTransformer(),
180
+ })
181
+ public conversationId?: ObjectID = undefined;
182
+
183
+ @ColumnAccessControl({
184
+ create: [],
185
+ read: [
186
+ Permission.ProjectOwner,
187
+ Permission.ProjectAdmin,
188
+ Permission.ProjectMember,
189
+ ],
190
+ update: [],
191
+ })
192
+ @TableColumn({
193
+ type: TableColumnType.Entity,
194
+ required: false,
195
+ modelType: User,
196
+ manyToOneRelationColumn: "userId",
197
+ title: "User",
198
+ description: "User who owns the conversation this message belongs to.",
199
+ })
200
+ @ManyToOne(
201
+ () => {
202
+ return User;
203
+ },
204
+ {
205
+ cascade: false,
206
+ eager: false,
207
+ nullable: true,
208
+ onDelete: "SET NULL",
209
+ orphanedRowAction: "nullify",
210
+ },
211
+ )
212
+ @JoinColumn({ name: "userId" })
213
+ public user?: User = undefined;
214
+
215
+ @ColumnAccessControl({
216
+ create: [],
217
+ read: [
218
+ Permission.ProjectOwner,
219
+ Permission.ProjectAdmin,
220
+ Permission.ProjectMember,
221
+ ],
222
+ update: [],
223
+ })
224
+ @Index()
225
+ @TableColumn({
226
+ type: TableColumnType.ObjectID,
227
+ required: false,
228
+ canReadOnRelationQuery: true,
229
+ title: "User ID",
230
+ description: "ID of the user who owns the conversation.",
231
+ })
232
+ @Column({
233
+ type: ColumnType.ObjectID,
234
+ nullable: true,
235
+ transformer: ObjectID.getDatabaseTransformer(),
236
+ })
237
+ public userId?: ObjectID = undefined;
238
+
239
+ @ColumnAccessControl({
240
+ create: [],
241
+ read: [
242
+ Permission.ProjectOwner,
243
+ Permission.ProjectAdmin,
244
+ Permission.ProjectMember,
245
+ ],
246
+ update: [],
247
+ })
248
+ @TableColumn({
249
+ required: true,
250
+ type: TableColumnType.ShortText,
251
+ title: "Role",
252
+ description: "Who authored this message: User or Assistant.",
253
+ canReadOnRelationQuery: true,
254
+ })
255
+ @Column({
256
+ nullable: false,
257
+ type: ColumnType.ShortText,
258
+ length: ColumnLength.ShortText,
259
+ })
260
+ public role?: AIChatMessageRole = undefined;
261
+
262
+ @ColumnAccessControl({
263
+ create: [],
264
+ read: [
265
+ Permission.ProjectOwner,
266
+ Permission.ProjectAdmin,
267
+ Permission.ProjectMember,
268
+ ],
269
+ update: [],
270
+ })
271
+ @TableColumn({
272
+ required: false,
273
+ type: TableColumnType.VeryLongText,
274
+ title: "Content",
275
+ description: "Message content in markdown.",
276
+ })
277
+ @Column({
278
+ nullable: true,
279
+ type: ColumnType.VeryLongText,
280
+ })
281
+ public contentInMarkdown?: string = undefined;
282
+
283
+ @ColumnAccessControl({
284
+ create: [],
285
+ read: [
286
+ Permission.ProjectOwner,
287
+ Permission.ProjectAdmin,
288
+ Permission.ProjectMember,
289
+ ],
290
+ update: [],
291
+ })
292
+ @Index()
293
+ @TableColumn({
294
+ required: true,
295
+ type: TableColumnType.ShortText,
296
+ title: "Status",
297
+ description: "Current status of this message.",
298
+ canReadOnRelationQuery: true,
299
+ })
300
+ @Column({
301
+ nullable: false,
302
+ type: ColumnType.ShortText,
303
+ length: ColumnLength.ShortText,
304
+ default: AIChatMessageStatus.Pending,
305
+ })
306
+ public status?: AIChatMessageStatus = undefined;
307
+
308
+ @ColumnAccessControl({
309
+ create: [],
310
+ read: [
311
+ Permission.ProjectOwner,
312
+ Permission.ProjectAdmin,
313
+ Permission.ProjectMember,
314
+ ],
315
+ update: [],
316
+ })
317
+ @Index()
318
+ @TableColumn({
319
+ type: TableColumnType.ObjectID,
320
+ required: false,
321
+ title: "AI Run ID",
322
+ description: "ID of the AI run that produced this assistant message.",
323
+ })
324
+ @Column({
325
+ type: ColumnType.ObjectID,
326
+ nullable: true,
327
+ transformer: ObjectID.getDatabaseTransformer(),
328
+ })
329
+ public aiRunId?: ObjectID = undefined;
330
+
331
+ @ColumnAccessControl({
332
+ create: [],
333
+ read: [
334
+ Permission.ProjectOwner,
335
+ Permission.ProjectAdmin,
336
+ Permission.ProjectMember,
337
+ ],
338
+ update: [],
339
+ })
340
+ @TableColumn({
341
+ required: false,
342
+ type: TableColumnType.JSON,
343
+ title: "Citations",
344
+ description:
345
+ "Server-minted citations for this assistant message. Each citation records the tool, the exact validated query arguments and the row count.",
346
+ })
347
+ @Column({
348
+ nullable: true,
349
+ type: ColumnType.JSON,
350
+ })
351
+ public citations?: Array<AIChatCitation> = undefined;
352
+
353
+ @ColumnAccessControl({
354
+ create: [],
355
+ read: [
356
+ Permission.ProjectOwner,
357
+ Permission.ProjectAdmin,
358
+ Permission.ProjectMember,
359
+ ],
360
+ update: [],
361
+ })
362
+ @TableColumn({
363
+ required: false,
364
+ type: TableColumnType.JSON,
365
+ title: "Widgets",
366
+ description:
367
+ "Inline widgets (charts, tables, trace waterfalls, resource cards) built from this assistant message's tool results and rendered inline in the chat.",
368
+ })
369
+ @Column({
370
+ nullable: true,
371
+ type: ColumnType.JSON,
372
+ })
373
+ public widgets?: Array<AIChatWidget> = undefined;
374
+
375
+ @ColumnAccessControl({
376
+ create: [],
377
+ read: [
378
+ Permission.ProjectOwner,
379
+ Permission.ProjectAdmin,
380
+ Permission.ProjectMember,
381
+ ],
382
+ update: [],
383
+ })
384
+ @TableColumn({
385
+ required: false,
386
+ type: TableColumnType.JSON,
387
+ title: "Tool Actions",
388
+ description:
389
+ "Mutating actions the agent proposed or performed in this turn, with their approval status (pending, approved, denied, executed).",
390
+ })
391
+ @Column({
392
+ nullable: true,
393
+ type: ColumnType.JSON,
394
+ })
395
+ public toolActions?: Array<AIChatToolAction> = undefined;
396
+
397
+ @ColumnAccessControl({
398
+ create: [],
399
+ read: [
400
+ Permission.ProjectOwner,
401
+ Permission.ProjectAdmin,
402
+ Permission.ProjectMember,
403
+ ],
404
+ update: [],
405
+ })
406
+ @TableColumn({
407
+ required: false,
408
+ type: TableColumnType.LongText,
409
+ title: "Error Message",
410
+ description: "Error message if this message failed to generate.",
411
+ })
412
+ @Column({
413
+ nullable: true,
414
+ type: ColumnType.LongText,
415
+ length: ColumnLength.LongText,
416
+ })
417
+ public errorMessage?: string = undefined;
418
+
419
+ @ColumnAccessControl({
420
+ create: [],
421
+ read: [],
422
+ update: [],
423
+ })
424
+ @TableColumn({ type: TableColumnType.Entity, modelType: User })
425
+ @ManyToOne(
426
+ () => {
427
+ return User;
428
+ },
429
+ {
430
+ cascade: false,
431
+ eager: false,
432
+ nullable: true,
433
+ onDelete: "SET NULL",
434
+ orphanedRowAction: "nullify",
435
+ },
436
+ )
437
+ @JoinColumn({ name: "deletedByUserId" })
438
+ public deletedByUser?: User = undefined;
439
+
440
+ @ColumnAccessControl({
441
+ create: [],
442
+ read: [],
443
+ update: [],
444
+ })
445
+ @TableColumn({
446
+ type: TableColumnType.ObjectID,
447
+ title: "Deleted by User ID",
448
+ description:
449
+ "User ID who deleted this object (if this object was deleted by a User)",
450
+ })
451
+ @Column({
452
+ type: ColumnType.ObjectID,
453
+ nullable: true,
454
+ transformer: ObjectID.getDatabaseTransformer(),
455
+ })
456
+ public deletedByUserId?: ObjectID = undefined;
457
+
458
+ @ColumnAccessControl({
459
+ create: [],
460
+ read: [],
461
+ update: [],
462
+ })
463
+ @TableColumn({ type: TableColumnType.Entity, modelType: User })
464
+ @ManyToOne(
465
+ () => {
466
+ return User;
467
+ },
468
+ {
469
+ eager: false,
470
+ nullable: true,
471
+ onDelete: "SET NULL",
472
+ orphanedRowAction: "nullify",
473
+ },
474
+ )
475
+ @JoinColumn({ name: "createdByUserId" })
476
+ public createdByUser?: User = undefined;
477
+
478
+ @ColumnAccessControl({
479
+ create: [],
480
+ read: [],
481
+ update: [],
482
+ })
483
+ @TableColumn({
484
+ type: TableColumnType.ObjectID,
485
+ title: "Created by User ID",
486
+ description:
487
+ "User ID who created this object (if this object was created by a User)",
488
+ })
489
+ @Column({
490
+ type: ColumnType.ObjectID,
491
+ nullable: true,
492
+ transformer: ObjectID.getDatabaseTransformer(),
493
+ })
494
+ public createdByUserId?: ObjectID = undefined;
495
+ }