@oneuptime/common 9.2.16 → 9.2.18

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 (133) hide show
  1. package/Models/DatabaseModels/CodeRepository.ts +664 -0
  2. package/Models/DatabaseModels/Index.ts +8 -0
  3. package/Models/DatabaseModels/LlmLog.ts +818 -0
  4. package/Models/DatabaseModels/LlmProvider.ts +21 -0
  5. package/Models/DatabaseModels/Project.ts +206 -0
  6. package/Models/DatabaseModels/ServiceCatalogCodeRepository.ts +549 -0
  7. package/Server/API/AIBillingAPI.ts +126 -0
  8. package/Server/API/AlertAPI.ts +139 -0
  9. package/Server/API/GitHubAPI.ts +360 -0
  10. package/Server/API/IncidentAPI.ts +258 -0
  11. package/Server/API/ScheduledMaintenanceAPI.ts +164 -0
  12. package/Server/EnvironmentConfig.ts +44 -0
  13. package/Server/Infrastructure/Postgres/SchemaMigrations/1765580181582-MigrationName.ts +79 -0
  14. package/Server/Infrastructure/Postgres/SchemaMigrations/1765633554715-MigrationName.ts +75 -0
  15. package/Server/Infrastructure/Postgres/SchemaMigrations/1765801357168-MigrationName.ts +32 -0
  16. package/Server/Infrastructure/Postgres/SchemaMigrations/1765810218488-MigrationName.ts +69 -0
  17. package/Server/Infrastructure/Postgres/SchemaMigrations/1765830758857-MigrationName.ts +111 -0
  18. package/Server/Infrastructure/Postgres/SchemaMigrations/1765834537501-MigrationName.ts +39 -0
  19. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +12 -0
  20. package/Server/Services/AIBillingService.ts +247 -0
  21. package/Server/Services/AIService.ts +238 -0
  22. package/Server/Services/CodeRepositoryService.ts +10 -0
  23. package/Server/Services/IncidentService.ts +88 -0
  24. package/Server/Services/Index.ts +2 -0
  25. package/Server/Services/LlmLogService.ts +14 -0
  26. package/Server/Services/LlmProviderService.ts +58 -0
  27. package/Server/Services/ServiceCatalogCodeRepositoryService.ts +55 -0
  28. package/Server/Utils/AI/AlertAIContextBuilder.ts +264 -0
  29. package/Server/Utils/AI/IncidentAIContextBuilder.ts +710 -0
  30. package/Server/Utils/AI/ScheduledMaintenanceAIContextBuilder.ts +345 -0
  31. package/Server/Utils/CodeRepository/GitHub/GitHub.ts +226 -0
  32. package/Server/Utils/LLM/LLMService.ts +276 -0
  33. package/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.ts +166 -0
  34. package/Server/Utils/Workspace/Slack/Slack.ts +134 -0
  35. package/Server/Utils/Workspace/Workspace.ts +126 -0
  36. package/Tests/Types/Domain.test.ts +24 -3
  37. package/Types/CodeRepository/CodeRepositoryType.ts +1 -1
  38. package/Types/Domain.ts +21 -24
  39. package/Types/LlmLogStatus.ts +7 -0
  40. package/Types/Permission.ts +87 -0
  41. package/Types/ServiceCatalog/CodeRepositoryImprovementAction.ts +9 -0
  42. package/UI/Components/AI/AILoader.tsx +95 -0
  43. package/UI/Components/AI/GenerateFromAIModal.tsx +432 -0
  44. package/UI/Components/Modal/Modal.tsx +6 -1
  45. package/build/dist/Models/DatabaseModels/CodeRepository.js +689 -0
  46. package/build/dist/Models/DatabaseModels/CodeRepository.js.map +1 -0
  47. package/build/dist/Models/DatabaseModels/Index.js +7 -0
  48. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  49. package/build/dist/Models/DatabaseModels/LlmLog.js +856 -0
  50. package/build/dist/Models/DatabaseModels/LlmLog.js.map +1 -0
  51. package/build/dist/Models/DatabaseModels/LlmProvider.js +22 -0
  52. package/build/dist/Models/DatabaseModels/LlmProvider.js.map +1 -1
  53. package/build/dist/Models/DatabaseModels/Project.js +220 -0
  54. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  55. package/build/dist/Models/DatabaseModels/ServiceCatalogCodeRepository.js +565 -0
  56. package/build/dist/Models/DatabaseModels/ServiceCatalogCodeRepository.js.map +1 -0
  57. package/build/dist/Server/API/AIBillingAPI.js +58 -0
  58. package/build/dist/Server/API/AIBillingAPI.js.map +1 -0
  59. package/build/dist/Server/API/AlertAPI.js +94 -0
  60. package/build/dist/Server/API/AlertAPI.js.map +1 -0
  61. package/build/dist/Server/API/GitHubAPI.js +207 -0
  62. package/build/dist/Server/API/GitHubAPI.js.map +1 -0
  63. package/build/dist/Server/API/IncidentAPI.js +171 -1
  64. package/build/dist/Server/API/IncidentAPI.js.map +1 -1
  65. package/build/dist/Server/API/ScheduledMaintenanceAPI.js +103 -0
  66. package/build/dist/Server/API/ScheduledMaintenanceAPI.js.map +1 -0
  67. package/build/dist/Server/EnvironmentConfig.js +31 -0
  68. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  69. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765580181582-MigrationName.js +34 -0
  70. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765580181582-MigrationName.js.map +1 -0
  71. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765633554715-MigrationName.js +32 -0
  72. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765633554715-MigrationName.js.map +1 -0
  73. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765801357168-MigrationName.js +38 -0
  74. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765801357168-MigrationName.js.map +1 -0
  75. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765810218488-MigrationName.js +30 -0
  76. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765810218488-MigrationName.js.map +1 -0
  77. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765830758857-MigrationName.js +44 -0
  78. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765830758857-MigrationName.js.map +1 -0
  79. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765834537501-MigrationName.js +22 -0
  80. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765834537501-MigrationName.js.map +1 -0
  81. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +12 -0
  82. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  83. package/build/dist/Server/Services/AIBillingService.js +187 -0
  84. package/build/dist/Server/Services/AIBillingService.js.map +1 -0
  85. package/build/dist/Server/Services/AIService.js +184 -0
  86. package/build/dist/Server/Services/AIService.js.map +1 -0
  87. package/build/dist/Server/Services/CodeRepositoryService.js +9 -0
  88. package/build/dist/Server/Services/CodeRepositoryService.js.map +1 -0
  89. package/build/dist/Server/Services/IncidentService.js +60 -0
  90. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  91. package/build/dist/Server/Services/Index.js +2 -0
  92. package/build/dist/Server/Services/Index.js.map +1 -1
  93. package/build/dist/Server/Services/LlmLogService.js +13 -0
  94. package/build/dist/Server/Services/LlmLogService.js.map +1 -0
  95. package/build/dist/Server/Services/LlmProviderService.js +65 -0
  96. package/build/dist/Server/Services/LlmProviderService.js.map +1 -1
  97. package/build/dist/Server/Services/ServiceCatalogCodeRepositoryService.js +54 -0
  98. package/build/dist/Server/Services/ServiceCatalogCodeRepositoryService.js.map +1 -0
  99. package/build/dist/Server/Utils/AI/AlertAIContextBuilder.js +238 -0
  100. package/build/dist/Server/Utils/AI/AlertAIContextBuilder.js.map +1 -0
  101. package/build/dist/Server/Utils/AI/IncidentAIContextBuilder.js +597 -0
  102. package/build/dist/Server/Utils/AI/IncidentAIContextBuilder.js.map +1 -0
  103. package/build/dist/Server/Utils/AI/ScheduledMaintenanceAIContextBuilder.js +311 -0
  104. package/build/dist/Server/Utils/AI/ScheduledMaintenanceAIContextBuilder.js.map +1 -0
  105. package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js +163 -0
  106. package/build/dist/Server/Utils/CodeRepository/GitHub/GitHub.js.map +1 -1
  107. package/build/dist/Server/Utils/LLM/LLMService.js +225 -0
  108. package/build/dist/Server/Utils/LLM/LLMService.js.map +1 -0
  109. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +110 -0
  110. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
  111. package/build/dist/Server/Utils/Workspace/Slack/Slack.js +89 -0
  112. package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
  113. package/build/dist/Server/Utils/Workspace/Workspace.js +80 -0
  114. package/build/dist/Server/Utils/Workspace/Workspace.js.map +1 -1
  115. package/build/dist/Tests/Types/Domain.test.js +19 -3
  116. package/build/dist/Tests/Types/Domain.test.js.map +1 -1
  117. package/build/dist/Types/CodeRepository/CodeRepositoryType.js +1 -1
  118. package/build/dist/Types/CodeRepository/CodeRepositoryType.js.map +1 -1
  119. package/build/dist/Types/Domain.js +18 -16
  120. package/build/dist/Types/Domain.js.map +1 -1
  121. package/build/dist/Types/LlmLogStatus.js +8 -0
  122. package/build/dist/Types/LlmLogStatus.js.map +1 -0
  123. package/build/dist/Types/Permission.js +74 -0
  124. package/build/dist/Types/Permission.js.map +1 -1
  125. package/build/dist/Types/ServiceCatalog/CodeRepositoryImprovementAction.js +10 -0
  126. package/build/dist/Types/ServiceCatalog/CodeRepositoryImprovementAction.js.map +1 -0
  127. package/build/dist/UI/Components/AI/AILoader.js +64 -0
  128. package/build/dist/UI/Components/AI/AILoader.js.map +1 -0
  129. package/build/dist/UI/Components/AI/GenerateFromAIModal.js +320 -0
  130. package/build/dist/UI/Components/AI/GenerateFromAIModal.js.map +1 -0
  131. package/build/dist/UI/Components/Modal/Modal.js +6 -1
  132. package/build/dist/UI/Components/Modal/Modal.js.map +1 -1
  133. package/package.json +1 -1
@@ -0,0 +1,225 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import HTTPErrorResponse from "../../../Types/API/HTTPErrorResponse";
11
+ import URL from "../../../Types/API/URL";
12
+ import API from "../../../Utils/API";
13
+ import LlmType from "../../../Types/LLM/LlmType";
14
+ import BadDataException from "../../../Types/Exception/BadDataException";
15
+ import logger from "../Logger";
16
+ import CaptureSpan from "../Telemetry/CaptureSpan";
17
+ export default class LLMService {
18
+ static async getCompletion(request) {
19
+ const config = request.llmProviderConfig;
20
+ switch (config.llmType) {
21
+ case LlmType.OpenAI:
22
+ return await this.getOpenAICompletion(config, request);
23
+ case LlmType.Anthropic:
24
+ return await this.getAnthropicCompletion(config, request);
25
+ case LlmType.Ollama:
26
+ return await this.getOllamaCompletion(config, request);
27
+ default:
28
+ throw new BadDataException(`Unsupported LLM type: ${config.llmType}`);
29
+ }
30
+ }
31
+ static async getOpenAICompletion(config, request) {
32
+ var _a;
33
+ if (!config.apiKey) {
34
+ throw new BadDataException("OpenAI API key is required");
35
+ }
36
+ const baseUrl = config.baseUrl || "https://api.openai.com/v1";
37
+ const modelName = config.modelName || "gpt-4o";
38
+ const response = await API.post({
39
+ url: URL.fromString(`${baseUrl}/chat/completions`),
40
+ data: {
41
+ model: modelName,
42
+ messages: request.messages.map((msg) => {
43
+ return {
44
+ role: msg.role,
45
+ content: msg.content,
46
+ };
47
+ }),
48
+ temperature: (_a = request.temperature) !== null && _a !== void 0 ? _a : 0.7,
49
+ },
50
+ headers: {
51
+ Authorization: `Bearer ${config.apiKey}`,
52
+ "Content-Type": "application/json",
53
+ },
54
+ options: {
55
+ retries: 2,
56
+ exponentialBackoff: true,
57
+ timeout: 120000, // 2 minutes timeout for LLM calls
58
+ },
59
+ });
60
+ if (response instanceof HTTPErrorResponse) {
61
+ logger.error("Error from OpenAI API:");
62
+ logger.error(response);
63
+ throw new BadDataException(`OpenAI API error: ${JSON.stringify(response.jsonData)}`);
64
+ }
65
+ const jsonData = response.jsonData;
66
+ const choices = jsonData["choices"];
67
+ if (!choices || choices.length === 0) {
68
+ throw new BadDataException("No response from OpenAI");
69
+ }
70
+ const message = choices[0]["message"];
71
+ const usage = jsonData["usage"];
72
+ return {
73
+ content: message["content"],
74
+ usage: usage
75
+ ? {
76
+ promptTokens: usage["prompt_tokens"],
77
+ completionTokens: usage["completion_tokens"],
78
+ totalTokens: usage["total_tokens"],
79
+ }
80
+ : undefined,
81
+ };
82
+ }
83
+ static async getAnthropicCompletion(config, request) {
84
+ var _a;
85
+ if (!config.apiKey) {
86
+ throw new BadDataException("Anthropic API key is required");
87
+ }
88
+ const baseUrl = config.baseUrl || "https://api.anthropic.com/v1";
89
+ const modelName = config.modelName || "claude-sonnet-4-20250514";
90
+ // Anthropic requires system message to be separate
91
+ let systemMessage = "";
92
+ const userMessages = [];
93
+ for (const msg of request.messages) {
94
+ if (msg.role === "system") {
95
+ systemMessage = msg.content;
96
+ }
97
+ else {
98
+ userMessages.push({
99
+ role: msg.role,
100
+ content: msg.content,
101
+ });
102
+ }
103
+ }
104
+ const requestData = {
105
+ model: modelName,
106
+ messages: userMessages,
107
+ temperature: (_a = request.temperature) !== null && _a !== void 0 ? _a : 0.7,
108
+ };
109
+ if (systemMessage) {
110
+ requestData["system"] = systemMessage;
111
+ }
112
+ const response = await API.post({
113
+ url: URL.fromString(`${baseUrl}/messages`),
114
+ data: requestData,
115
+ headers: {
116
+ "x-api-key": config.apiKey,
117
+ "anthropic-version": "2023-06-01",
118
+ "Content-Type": "application/json",
119
+ },
120
+ options: {
121
+ retries: 2,
122
+ exponentialBackoff: true,
123
+ timeout: 120000,
124
+ },
125
+ });
126
+ if (response instanceof HTTPErrorResponse) {
127
+ logger.error("Error from Anthropic API:");
128
+ logger.error(response);
129
+ throw new BadDataException(`Anthropic API error: ${JSON.stringify(response.jsonData)}`);
130
+ }
131
+ const jsonData = response.jsonData;
132
+ const content = jsonData["content"];
133
+ if (!content || content.length === 0) {
134
+ throw new BadDataException("No response from Anthropic");
135
+ }
136
+ const textContent = content.find((c) => {
137
+ return c["type"] === "text";
138
+ });
139
+ if (!textContent) {
140
+ throw new BadDataException("No text content in Anthropic response");
141
+ }
142
+ const usage = jsonData["usage"];
143
+ return {
144
+ content: textContent["text"],
145
+ usage: usage
146
+ ? {
147
+ promptTokens: usage["input_tokens"],
148
+ completionTokens: usage["output_tokens"],
149
+ totalTokens: (usage["input_tokens"] || 0) +
150
+ (usage["output_tokens"] || 0),
151
+ }
152
+ : undefined,
153
+ };
154
+ }
155
+ static async getOllamaCompletion(config, request) {
156
+ var _a;
157
+ if (!config.baseUrl) {
158
+ throw new BadDataException("Ollama base URL is required");
159
+ }
160
+ const modelName = config.modelName || "llama2";
161
+ const response = await API.post({
162
+ url: URL.fromString(`${config.baseUrl}/api/chat`),
163
+ data: {
164
+ model: modelName,
165
+ messages: request.messages.map((msg) => {
166
+ return {
167
+ role: msg.role,
168
+ content: msg.content,
169
+ };
170
+ }),
171
+ stream: false,
172
+ options: {
173
+ temperature: (_a = request.temperature) !== null && _a !== void 0 ? _a : 0.7,
174
+ },
175
+ },
176
+ headers: {
177
+ "Content-Type": "application/json",
178
+ },
179
+ options: {
180
+ retries: 2,
181
+ exponentialBackoff: true,
182
+ timeout: 300000, // 5 minutes for Ollama as it may be slower
183
+ },
184
+ });
185
+ if (response instanceof HTTPErrorResponse) {
186
+ logger.error("Error from Ollama API:");
187
+ logger.error(response);
188
+ throw new BadDataException(`Ollama API error: ${JSON.stringify(response.jsonData)}`);
189
+ }
190
+ const jsonData = response.jsonData;
191
+ const message = jsonData["message"];
192
+ if (!message) {
193
+ throw new BadDataException("No response from Ollama");
194
+ }
195
+ return {
196
+ content: message["content"],
197
+ usage: undefined, // Ollama doesn't provide token usage in the same way
198
+ };
199
+ }
200
+ }
201
+ __decorate([
202
+ CaptureSpan(),
203
+ __metadata("design:type", Function),
204
+ __metadata("design:paramtypes", [Object]),
205
+ __metadata("design:returntype", Promise)
206
+ ], LLMService, "getCompletion", null);
207
+ __decorate([
208
+ CaptureSpan(),
209
+ __metadata("design:type", Function),
210
+ __metadata("design:paramtypes", [Object, Object]),
211
+ __metadata("design:returntype", Promise)
212
+ ], LLMService, "getOpenAICompletion", null);
213
+ __decorate([
214
+ CaptureSpan(),
215
+ __metadata("design:type", Function),
216
+ __metadata("design:paramtypes", [Object, Object]),
217
+ __metadata("design:returntype", Promise)
218
+ ], LLMService, "getAnthropicCompletion", null);
219
+ __decorate([
220
+ CaptureSpan(),
221
+ __metadata("design:type", Function),
222
+ __metadata("design:paramtypes", [Object, Object]),
223
+ __metadata("design:returntype", Promise)
224
+ ], LLMService, "getOllamaCompletion", null);
225
+ //# sourceMappingURL=LLMService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LLMService.js","sourceRoot":"","sources":["../../../../../Server/Utils/LLM/LLMService.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,iBAAiB,MAAM,sCAAsC,CAAC;AAErE,OAAO,GAAG,MAAM,wBAAwB,CAAC;AAEzC,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,OAAO,MAAM,4BAA4B,CAAC;AACjD,OAAO,gBAAgB,MAAM,2CAA2C,CAAC;AACzE,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,WAAW,MAAM,0BAA0B,CAAC;AA+BnD,MAAM,CAAC,OAAO,OAAO,UAAU;IAET,AAAb,MAAM,CAAC,KAAK,CAAC,aAAa,CAC/B,OAA6B;QAE7B,MAAM,MAAM,GAAsB,OAAO,CAAC,iBAAiB,CAAC;QAE5D,QAAQ,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,KAAK,OAAO,CAAC,MAAM;gBACjB,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACzD,KAAK,OAAO,CAAC,SAAS;gBAC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W;YACrC,KAAK,EAAE,SAAS,EAAE,qDAAqD;SACxE,CAAC;IACJ,CAAC;CACF;AA1OqB;IADnB,WAAW,EAAE;;;;qCAgBb;AAGoB;IADpB,WAAW,EAAE;;;;2CAgEb;AAGoB;IADpB,WAAW,EAAE;;;;8CA4Fb;AAGoB;IADpB,WAAW,EAAE;;;;2CAwDb"}
@@ -2121,6 +2121,110 @@ All monitoring checks are passing normally.`;
2121
2121
  throw error;
2122
2122
  }
2123
2123
  }
2124
+ static async getChannelMessages(params) {
2125
+ const messages = [];
2126
+ try {
2127
+ // Get valid access token
2128
+ const projectAuth = await WorkspaceProjectAuthTokenService.getProjectAuth({
2129
+ projectId: params.projectId,
2130
+ workspaceType: WorkspaceType.MicrosoftTeams,
2131
+ });
2132
+ if (!projectAuth || !projectAuth.miscData) {
2133
+ logger.error("Microsoft Teams integration not found for this project");
2134
+ return messages;
2135
+ }
2136
+ const miscData = projectAuth.miscData;
2137
+ const accessToken = miscData["appAccessToken"];
2138
+ const tokenExpiresAt = miscData["appAccessTokenExpiresAt"];
2139
+ // Check if token is expired
2140
+ if (!accessToken ||
2141
+ (tokenExpiresAt &&
2142
+ OneUptimeDate.isInThePast(OneUptimeDate.fromString(tokenExpiresAt)))) {
2143
+ logger.debug("Microsoft Teams access token expired or missing, skipping message fetch");
2144
+ return messages;
2145
+ }
2146
+ // Fetch messages from Microsoft Teams channel
2147
+ let nextLink = undefined;
2148
+ const maxMessages = params.limit || 1000;
2149
+ const maxPages = 10;
2150
+ let pageCount = 0;
2151
+ do {
2152
+ let requestUrl;
2153
+ if (nextLink) {
2154
+ requestUrl = nextLink;
2155
+ }
2156
+ else {
2157
+ requestUrl = `https://graph.microsoft.com/v1.0/teams/${params.teamId}/channels/${params.channelId}/messages`;
2158
+ requestUrl += `?$top=${Math.min(50, maxMessages - messages.length)}`;
2159
+ }
2160
+ const response = await API.get({
2161
+ url: URL.fromString(requestUrl),
2162
+ headers: {
2163
+ Authorization: `Bearer ${accessToken}`,
2164
+ "Content-Type": "application/json",
2165
+ },
2166
+ options: {
2167
+ retries: 2,
2168
+ exponentialBackoff: true,
2169
+ },
2170
+ });
2171
+ if (response instanceof HTTPErrorResponse) {
2172
+ logger.error("Error response from Microsoft Teams API for channel messages:");
2173
+ logger.error(response);
2174
+ break;
2175
+ }
2176
+ const jsonData = response.jsonData;
2177
+ const teamsMessages = jsonData["value"] || [];
2178
+ for (const msg of teamsMessages) {
2179
+ // Skip system messages
2180
+ if (msg["messageType"] !== "message") {
2181
+ continue;
2182
+ }
2183
+ const body = msg["body"];
2184
+ let text = (body === null || body === void 0 ? void 0 : body["content"]) || "";
2185
+ // Remove HTML tags if present (Teams uses HTML)
2186
+ text = text.replace(/<[^>]*>/g, "");
2187
+ text = text.trim();
2188
+ // Skip empty messages
2189
+ if (!text) {
2190
+ continue;
2191
+ }
2192
+ const from = msg["from"];
2193
+ const user = from === null || from === void 0 ? void 0 : from["user"];
2194
+ const isBot = Boolean(from === null || from === void 0 ? void 0 : from["application"]);
2195
+ const createdDateTime = msg["createdDateTime"];
2196
+ const timestamp = createdDateTime
2197
+ ? new Date(createdDateTime)
2198
+ : new Date();
2199
+ // Check if message is older than the oldest timestamp filter
2200
+ if (params.oldestTimestamp && timestamp < params.oldestTimestamp) {
2201
+ continue;
2202
+ }
2203
+ messages.push({
2204
+ messageId: msg["id"],
2205
+ text: text,
2206
+ userId: user === null || user === void 0 ? void 0 : user["id"],
2207
+ username: user === null || user === void 0 ? void 0 : user["displayName"],
2208
+ timestamp: timestamp,
2209
+ isBot: isBot,
2210
+ });
2211
+ }
2212
+ nextLink = jsonData["@odata.nextLink"];
2213
+ pageCount++;
2214
+ } while (nextLink &&
2215
+ messages.length < maxMessages &&
2216
+ pageCount < maxPages);
2217
+ logger.debug(`Retrieved ${messages.length} messages from Microsoft Teams channel ${params.channelId}`);
2218
+ // Sort by timestamp (oldest first)
2219
+ messages.sort((a, b) => {
2220
+ return a.timestamp.getTime() - b.timestamp.getTime();
2221
+ });
2222
+ }
2223
+ catch (error) {
2224
+ logger.error(`Error fetching Microsoft Teams channel messages: ${error}`);
2225
+ }
2226
+ return messages;
2227
+ }
2124
2228
  }
2125
2229
  MicrosoftTeamsUtil.cachedAdapter = null;
2126
2230
  MicrosoftTeamsUtil.WELCOME_CARD_STATE_KEY = "oneuptime.microsoftTeams.welcomeCardSent";
@@ -2365,4 +2469,10 @@ __decorate([
2365
2469
  __metadata("design:paramtypes", [String]),
2366
2470
  __metadata("design:returntype", Promise)
2367
2471
  ], MicrosoftTeamsUtil, "getUserJoinedTeams", null);
2472
+ __decorate([
2473
+ CaptureSpan(),
2474
+ __metadata("design:type", Function),
2475
+ __metadata("design:paramtypes", [Object]),
2476
+ __metadata("design:returntype", Promise)
2477
+ ], MicrosoftTeamsUtil, "getChannelMessages", null);
2368
2478
  //# sourceMappingURL=MicrosoftTeams.js.map