@oneuptime/common 14.0.96 → 14.0.98

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 (271) hide show
  1. package/Models/AnalyticsModels/NetworkFlow.d.mts +4 -0
  2. package/Models/AnalyticsModels/NetworkFlow.d.ts +4 -0
  3. package/Models/AnalyticsModels/NetworkFlow.js +50 -0
  4. package/Models/DatabaseModels/Alert.d.mts +2 -0
  5. package/Models/DatabaseModels/Alert.d.ts +2 -0
  6. package/Models/DatabaseModels/Alert.js +63 -0
  7. package/Models/DatabaseModels/CodeRepository.d.mts +3 -0
  8. package/Models/DatabaseModels/CodeRepository.d.ts +3 -0
  9. package/Models/DatabaseModels/CodeRepository.js +104 -0
  10. package/Models/DatabaseModels/Incident.d.mts +2 -0
  11. package/Models/DatabaseModels/Incident.d.ts +2 -0
  12. package/Models/DatabaseModels/Incident.js +63 -0
  13. package/Models/DatabaseModels/Index.js +12 -0
  14. package/Models/DatabaseModels/NetworkAddressName.d.mts +14 -0
  15. package/Models/DatabaseModels/NetworkAddressName.d.ts +14 -0
  16. package/Models/DatabaseModels/NetworkAddressName.js +300 -0
  17. package/Models/DatabaseModels/NetworkAddressName.mjs +2 -0
  18. package/Models/DatabaseModels/NetworkDevice.d.mts +1 -0
  19. package/Models/DatabaseModels/NetworkDevice.d.ts +1 -0
  20. package/Models/DatabaseModels/NetworkDevice.js +38 -0
  21. package/Models/DatabaseModels/SecurityCase.d.mts +8 -0
  22. package/Models/DatabaseModels/SecurityCase.d.ts +8 -0
  23. package/Models/DatabaseModels/SecurityCase.js +145 -0
  24. package/Models/DatabaseModels/SecurityCaseEvidence.d.mts +32 -0
  25. package/Models/DatabaseModels/SecurityCaseEvidence.d.ts +32 -0
  26. package/Models/DatabaseModels/SecurityCaseEvidence.js +548 -0
  27. package/Models/DatabaseModels/SecurityCaseEvidence.mjs +2 -0
  28. package/Models/DatabaseModels/SecurityCaseFeed.d.mts +4 -1
  29. package/Models/DatabaseModels/SecurityCaseFeed.d.ts +4 -1
  30. package/Models/DatabaseModels/SecurityCaseFeed.js +6 -0
  31. package/Models/DatabaseModels/SecurityCasePriority.d.mts +2 -0
  32. package/Models/DatabaseModels/SecurityCasePriority.d.ts +2 -0
  33. package/Models/DatabaseModels/SecurityCasePriority.js +44 -0
  34. package/Models/DatabaseModels/SecurityCaseTask.d.mts +22 -0
  35. package/Models/DatabaseModels/SecurityCaseTask.d.ts +22 -0
  36. package/Models/DatabaseModels/SecurityCaseTask.js +467 -0
  37. package/Models/DatabaseModels/SecurityCaseTask.mjs +2 -0
  38. package/Models/DatabaseModels/SecurityHunt.d.mts +34 -0
  39. package/Models/DatabaseModels/SecurityHunt.d.ts +34 -0
  40. package/Models/DatabaseModels/SecurityHunt.js +608 -0
  41. package/Models/DatabaseModels/SecurityHunt.mjs +2 -0
  42. package/Models/DatabaseModels/SecurityWatchlist.d.mts +22 -0
  43. package/Models/DatabaseModels/SecurityWatchlist.d.ts +22 -0
  44. package/Models/DatabaseModels/SecurityWatchlist.js +411 -0
  45. package/Models/DatabaseModels/SecurityWatchlist.mjs +2 -0
  46. package/Models/DatabaseModels/SecurityWatchlistItem.d.mts +17 -0
  47. package/Models/DatabaseModels/SecurityWatchlistItem.d.ts +17 -0
  48. package/Models/DatabaseModels/SecurityWatchlistItem.js +321 -0
  49. package/Models/DatabaseModels/SecurityWatchlistItem.mjs +2 -0
  50. package/Types/AI/AIChatTypes.d.mts +1 -0
  51. package/Types/AI/AIChatTypes.d.ts +1 -0
  52. package/Types/AI/AIRunEventType.d.mts +1 -0
  53. package/Types/AI/AIRunEventType.d.ts +1 -0
  54. package/Types/AI/AIRunEventType.js +8 -0
  55. package/Types/AI/AiAffectedResources.d.mts +2 -1
  56. package/Types/AI/AiAffectedResources.d.ts +2 -1
  57. package/Types/AI/AiAffectedResources.js +12 -1
  58. package/Types/AI/AiTokenCount.d.mts +22 -1
  59. package/Types/AI/AiTokenCount.d.ts +22 -1
  60. package/Types/AI/AiTokenCount.js +126 -57
  61. package/Types/AI/AiTokenCount.mjs +2 -0
  62. package/Types/AI/CodeFixTaskContext.d.mts +1 -0
  63. package/Types/AI/CodeFixTaskContext.d.ts +1 -0
  64. package/Types/AffectedResources/AffectedResourceSearch.d.mts +53 -0
  65. package/Types/AffectedResources/AffectedResourceSearch.d.ts +53 -0
  66. package/Types/AffectedResources/AffectedResourceSearch.js +224 -0
  67. package/Types/AffectedResources/AffectedResourceSearch.mjs +11 -0
  68. package/Types/ArchivableValue/ArchivableValueUsage.d.mts +21 -2
  69. package/Types/ArchivableValue/ArchivableValueUsage.d.ts +21 -2
  70. package/Types/ArchivableValue/ArchivableValueUsage.js +91 -12
  71. package/Types/ArchivableValue/ArchivableValueUsage.mjs +1 -0
  72. package/Types/CodeRepository/CodeRepositorySetting.d.mts +1 -0
  73. package/Types/CodeRepository/CodeRepositorySetting.d.ts +1 -0
  74. package/Types/CodeRepository/CodeRepositorySetting.js +2 -0
  75. package/Types/Color.d.mts +0 -2
  76. package/Types/Color.d.ts +0 -2
  77. package/Types/Color.js +0 -14
  78. package/Types/Database/DatabaseProperty.d.mts +0 -2
  79. package/Types/Database/DatabaseProperty.d.ts +0 -2
  80. package/Types/Database/DatabaseProperty.js +0 -3
  81. package/Types/Date.d.mts +0 -2
  82. package/Types/Date.d.ts +0 -2
  83. package/Types/Date.js +0 -23
  84. package/Types/Domain.d.mts +0 -2
  85. package/Types/Domain.d.ts +0 -2
  86. package/Types/Domain.js +0 -14
  87. package/Types/Email/EmailTemplateType.d.mts +3 -0
  88. package/Types/Email/EmailTemplateType.d.ts +3 -0
  89. package/Types/Email/EmailTemplateType.js +4 -0
  90. package/Types/Email.d.mts +0 -2
  91. package/Types/Email.d.ts +0 -2
  92. package/Types/Email.js +0 -15
  93. package/Types/IP/IP.d.mts +0 -2
  94. package/Types/IP/IP.d.ts +0 -2
  95. package/Types/IP/IP.js +0 -14
  96. package/Types/Link.d.mts +1 -0
  97. package/Types/Link.d.ts +1 -0
  98. package/Types/Monitor/CriteriaAlert.d.mts +0 -2
  99. package/Types/Monitor/CriteriaAlert.d.ts +0 -2
  100. package/Types/Monitor/CriteriaAlert.js +0 -18
  101. package/Types/Monitor/CriteriaAlert.mjs +1 -2
  102. package/Types/Monitor/CriteriaFilter.d.mts +0 -2
  103. package/Types/Monitor/CriteriaFilter.d.ts +0 -2
  104. package/Types/Monitor/CriteriaFilter.js +1 -42
  105. package/Types/Monitor/CriteriaFilter.mjs +0 -1
  106. package/Types/Monitor/CriteriaIncident.d.mts +0 -2
  107. package/Types/Monitor/CriteriaIncident.d.ts +0 -2
  108. package/Types/Monitor/CriteriaIncident.js +0 -23
  109. package/Types/Monitor/CriteriaIncident.mjs +1 -2
  110. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.d.mts +0 -2
  111. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.d.ts +0 -2
  112. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.js +0 -11
  113. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.mjs +1 -2
  114. package/Types/Monitor/MonitorCriteria.d.mts +0 -2
  115. package/Types/Monitor/MonitorCriteria.d.ts +0 -2
  116. package/Types/Monitor/MonitorCriteria.js +0 -21
  117. package/Types/Monitor/MonitorCriteriaInstance.d.mts +0 -2
  118. package/Types/Monitor/MonitorCriteriaInstance.d.ts +0 -2
  119. package/Types/Monitor/MonitorCriteriaInstance.js +0 -54
  120. package/Types/Monitor/MonitorStep.d.mts +0 -2
  121. package/Types/Monitor/MonitorStep.d.ts +0 -2
  122. package/Types/Monitor/MonitorStep.js +0 -80
  123. package/Types/Monitor/MonitorSteps.d.mts +0 -2
  124. package/Types/Monitor/MonitorSteps.d.ts +0 -2
  125. package/Types/Monitor/MonitorSteps.js +0 -31
  126. package/Types/Name.d.mts +0 -2
  127. package/Types/Name.d.ts +0 -2
  128. package/Types/Name.js +0 -14
  129. package/Types/NetFlow/NetworkAddressName.d.mts +30 -0
  130. package/Types/NetFlow/NetworkAddressName.d.ts +30 -0
  131. package/Types/NetFlow/NetworkAddressName.js +149 -0
  132. package/Types/NetFlow/NetworkAddressName.mjs +6 -0
  133. package/Types/NetFlow/NetworkTraffic.d.mts +20 -0
  134. package/Types/NetFlow/NetworkTraffic.d.ts +20 -0
  135. package/Types/NetFlow/NetworkTraffic.js +5 -1
  136. package/Types/NetFlow/NetworkTraffic.mjs +2 -0
  137. package/Types/NetworkController/NetworkControllerReadSummary.d.mts +2 -0
  138. package/Types/NetworkController/NetworkControllerReadSummary.d.ts +2 -0
  139. package/Types/NetworkController/NetworkControllerReadSummary.js +7 -1
  140. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.d.mts +47 -1
  141. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.d.ts +47 -1
  142. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.js +173 -8
  143. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.mjs +7 -0
  144. package/Types/NotificationSetting/NotificationEmailRollupCategory.d.mts +1 -0
  145. package/Types/NotificationSetting/NotificationEmailRollupCategory.d.ts +1 -0
  146. package/Types/NotificationSetting/NotificationEmailRollupCategory.js +12 -0
  147. package/Types/NotificationSetting/NotificationEmailRollupPolicy.js +6 -0
  148. package/Types/NotificationSetting/NotificationSettingEventType.d.mts +3 -0
  149. package/Types/NotificationSetting/NotificationSettingEventType.d.ts +3 -0
  150. package/Types/NotificationSetting/NotificationSettingEventType.js +15 -0
  151. package/Types/ObjectID.d.mts +0 -1
  152. package/Types/ObjectID.d.ts +0 -1
  153. package/Types/ObjectID.js +0 -9
  154. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.d.mts +4 -0
  155. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.d.ts +4 -0
  156. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.js +25 -1
  157. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.mjs +4 -0
  158. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.d.mts +15 -0
  159. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.d.ts +15 -0
  160. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.js +118 -0
  161. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.mjs +9 -0
  162. package/Types/Permission.d.mts +8 -0
  163. package/Types/Permission.d.ts +8 -0
  164. package/Types/Permission.js +87 -3
  165. package/Types/Phone.d.mts +0 -2
  166. package/Types/Phone.d.ts +0 -2
  167. package/Types/Phone.js +0 -14
  168. package/Types/Port.d.mts +0 -2
  169. package/Types/Port.d.ts +0 -2
  170. package/Types/Port.js +0 -14
  171. package/Types/ProviderLogo/ProviderLogo.d.mts +8 -1
  172. package/Types/ProviderLogo/ProviderLogo.d.ts +8 -1
  173. package/Types/ProviderLogo/ProviderLogo.js +14 -0
  174. package/Types/SecurityCase/SecurityCaseEventEvidence.d.mts +67 -0
  175. package/Types/SecurityCase/SecurityCaseEventEvidence.d.ts +67 -0
  176. package/Types/SecurityCase/SecurityCaseEventEvidence.js +271 -0
  177. package/Types/SecurityCase/SecurityCaseEventEvidence.mjs +13 -0
  178. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.mts +8 -0
  179. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.ts +8 -0
  180. package/Types/SecurityCase/SecurityCaseEvidenceKind.js +34 -0
  181. package/Types/SecurityCase/SecurityCaseEvidenceKind.mjs +4 -0
  182. package/Types/SecurityEvent/SecurityHunt.d.mts +122 -0
  183. package/Types/SecurityEvent/SecurityHunt.d.ts +122 -0
  184. package/Types/SecurityEvent/SecurityHunt.js +391 -0
  185. package/Types/SecurityEvent/SecurityHunt.mjs +32 -0
  186. package/Types/SecurityEvent/SecurityWatchlist.d.mts +167 -0
  187. package/Types/SecurityEvent/SecurityWatchlist.d.ts +167 -0
  188. package/Types/SecurityEvent/SecurityWatchlist.js +648 -0
  189. package/Types/SecurityEvent/SecurityWatchlist.mjs +51 -0
  190. package/Types/SecurityEvent/SigmaRule.d.mts +2 -0
  191. package/Types/SecurityEvent/SigmaRule.d.ts +2 -0
  192. package/Types/SecurityEvent/SigmaRule.js +5 -0
  193. package/Types/Telemetry/OpenTelemetryGuides.js +177 -5
  194. package/Types/Version.d.mts +0 -2
  195. package/Types/Version.d.ts +0 -2
  196. package/Types/Version.js +0 -14
  197. package/Types/Workflow/AffectedResourcesSetting.d.mts +13 -0
  198. package/Types/Workflow/AffectedResourcesSetting.d.ts +13 -0
  199. package/Types/Workflow/AffectedResourcesSetting.js +120 -0
  200. package/Types/Workflow/AffectedResourcesSetting.mjs +8 -0
  201. package/Types/Workflow/Components/BaseModel.js +15 -3
  202. package/Types/Workflow/Documentation/DatabaseDocumentation.js +36 -0
  203. package/Types/Workflow/RunRecord.d.mts +3 -14
  204. package/Types/Workflow/RunRecord.d.ts +3 -14
  205. package/Types/Workflow/RunRecord.js +10 -51
  206. package/Utils/AI/InvestigationLogStall.d.mts +38 -0
  207. package/Utils/AI/InvestigationLogStall.d.ts +38 -0
  208. package/Utils/AI/InvestigationLogStall.js +163 -0
  209. package/Utils/AI/InvestigationLogStall.mjs +11 -0
  210. package/Utils/Inventory/AssetFactSource.d.mts +6 -2
  211. package/Utils/Inventory/AssetFactSource.d.ts +6 -2
  212. package/Utils/Inventory/AssetFactSource.js +18 -1
  213. package/Utils/Inventory/AssetFactSource.mjs +1 -0
  214. package/Utils/Markdown/FeedLead.d.mts +10 -0
  215. package/Utils/Markdown/FeedLead.d.ts +10 -0
  216. package/Utils/Markdown/FeedLead.js +198 -0
  217. package/Utils/Markdown/FeedLead.mjs +8 -0
  218. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.d.mts +9 -1
  219. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.d.ts +9 -1
  220. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.js +139 -18
  221. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.mjs +1 -0
  222. package/Utils/NetworkDevice/NetworkDeviceRefresh.d.mts +88 -0
  223. package/Utils/NetworkDevice/NetworkDeviceRefresh.d.ts +88 -0
  224. package/Utils/NetworkDevice/NetworkDeviceRefresh.js +232 -0
  225. package/Utils/NetworkDevice/NetworkDeviceRefresh.mjs +16 -0
  226. package/Utils/NetworkTraffic/NetworkAddressBlock.d.mts +20 -0
  227. package/Utils/NetworkTraffic/NetworkAddressBlock.d.ts +20 -0
  228. package/Utils/NetworkTraffic/NetworkAddressBlock.js +264 -0
  229. package/Utils/NetworkTraffic/NetworkAddressBlock.mjs +3 -0
  230. package/Utils/Project/RecordNumber.d.mts +43 -0
  231. package/Utils/Project/RecordNumber.d.ts +43 -0
  232. package/Utils/Project/RecordNumber.js +151 -0
  233. package/Utils/Project/RecordNumber.mjs +6 -0
  234. package/Utils/Schema/MonitorSchemas.d.mts +9 -0
  235. package/Utils/Schema/MonitorSchemas.d.ts +9 -0
  236. package/Utils/Schema/MonitorSchemas.js +291 -0
  237. package/Utils/Schema/MonitorSchemas.mjs +9 -0
  238. package/Utils/Schema/TypeSchemas.d.mts +12 -0
  239. package/Utils/Schema/TypeSchemas.d.ts +12 -0
  240. package/Utils/Schema/TypeSchemas.js +176 -0
  241. package/Utils/Schema/TypeSchemas.mjs +11 -0
  242. package/Utils/Schema/Zod.js +17 -17
  243. package/Utils/SecurityCase/SecurityCaseMarkdown.d.mts +43 -0
  244. package/Utils/SecurityCase/SecurityCaseMarkdown.d.ts +43 -0
  245. package/Utils/SecurityCase/SecurityCaseMarkdown.js +89 -0
  246. package/Utils/SecurityCase/SecurityCaseMarkdown.mjs +11 -0
  247. package/Utils/SecurityCase/SecurityCasePriorities.d.mts +2 -0
  248. package/Utils/SecurityCase/SecurityCasePriorities.d.ts +2 -0
  249. package/Utils/SecurityCase/SecurityCasePriorities.js +15 -1
  250. package/Utils/SecurityCase/SecurityCaseTargets.d.mts +128 -0
  251. package/Utils/SecurityCase/SecurityCaseTargets.d.ts +128 -0
  252. package/Utils/SecurityCase/SecurityCaseTargets.js +482 -0
  253. package/Utils/SecurityCase/SecurityCaseTargets.mjs +28 -0
  254. package/Utils/SecurityEvent/SecurityEventSearch.d.mts +56 -0
  255. package/Utils/SecurityEvent/SecurityEventSearch.d.ts +56 -0
  256. package/Utils/SecurityEvent/SecurityEventSearch.js +422 -0
  257. package/Utils/SecurityEvent/SecurityEventSearch.mjs +21 -0
  258. package/Utils/SecurityEvent/SecurityHuntSearch.d.mts +12 -0
  259. package/Utils/SecurityEvent/SecurityHuntSearch.d.ts +12 -0
  260. package/Utils/SecurityEvent/SecurityHuntSearch.js +51 -0
  261. package/Utils/SecurityEvent/SecurityHuntSearch.mjs +3 -0
  262. package/Utils/SecurityEvent/Sigma/SigmaRuleParser.js +22 -0
  263. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.d.mts +24 -0
  264. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.d.ts +24 -0
  265. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.js +183 -0
  266. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.mjs +9 -0
  267. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.mts +9 -0
  268. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.ts +9 -0
  269. package/Utils/Suggestions/TracePerformanceFixSuggestion.js +69 -1
  270. package/Utils/Suggestions/TracePerformanceFixSuggestion.mjs +4 -0
  271. package/package.json +1 -1
@@ -1,55 +1,43 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_CACHE_TOKEN_WEIGHTS = exports.FRESH_TOKEN_WEIGHT = exports.CACHE_WRITE_TOKEN_WEIGHT = exports.CACHE_READ_TOKEN_WEIGHT = void 0;
4
+ const LlmCostCatalog_1 = require("../Telemetry/LlmCostCatalog");
2
5
  /*
3
- * How OneUptime counts the tokens of its own AI calls (issue #5073): the
4
- * "Tokens Used" of the AI Logs, the tokens of each AI run (an
5
- * investigation, an Ask AI answer, a fix), the project's daily AI token
6
- * limit and the incident and alert ones, and the AI credits a call through
7
- * the OneUptime-hosted provider is charged.
8
- *
9
- * A token counts for what it costs. A token the model reads fresh, and every
10
- * token it writes, counts as one. A token the provider serves from its prompt
11
- * cache - a token the model already read on an earlier call of the same
12
- * investigation or chat, sent again with the conversation - costs a tenth of
13
- * a fresh one at Anthropic (less on its newest models) and on OpenAI's
14
- * current models, and counts as a tenth. A token written to the cache costs a
15
- * quarter more than a fresh one at Anthropic (its 5-minute cache, the one
16
- * OneUptime asks for), and counts as one and a quarter. Without the cache an
17
- * agent loop pays for its whole conversation again on every call, so counting
18
- * every cached token as a fresh one made AI work count several times what it
19
- * cost - and the more OneUptime caches, the further apart the two would grow.
20
- *
21
- * The providers report cached tokens two ways, and both are counted alike:
22
- *
23
- * - The OpenAI wire (OpenAI, Azure OpenAI, Groq, Mistral, OpenAI-compatible
24
- * servers) counts them inside prompt_tokens, and reports how many in
25
- * prompt_tokens_details.cached_tokens. It never reports a cache write:
26
- * writing costs nothing extra there.
27
- * - Anthropic reports input_tokens WITHOUT them, and cache_read_input_tokens
28
- * and cache_creation_input_tokens apart; LLMService adds them back.
29
- *
30
- * Either way totalTokens holds every token of the call (LlmLog.totalTokens,
31
- * as the provider counted them), and the cached ones are a part of it.
32
- *
33
- * Pure and free of React and server code: the server counts with it, and the
34
- * dashboard's AI Logs show the same count.
6
+ * A token read from the provider's prompt cache counts as a tenth of a
7
+ * token, for a model the cost catalog lists no cache price for.
35
8
  */
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.CACHE_WRITE_TOKEN_WEIGHT = exports.CACHE_READ_TOKEN_WEIGHT = void 0;
38
- // A token read from the provider's prompt cache counts as a tenth of a token.
39
9
  exports.CACHE_READ_TOKEN_WEIGHT = {
40
10
  numerator: 1,
41
11
  denominator: 10,
42
12
  };
43
- // A token written to the provider's prompt cache counts as one and a quarter.
13
+ /*
14
+ * A token written to the provider's prompt cache counts as one and a
15
+ * quarter, for a model the cost catalog lists no cache price for.
16
+ */
44
17
  exports.CACHE_WRITE_TOKEN_WEIGHT = {
45
18
  numerator: 5,
46
19
  denominator: 4,
47
20
  };
21
+ // A token that counts for exactly what a fresh one does.
22
+ exports.FRESH_TOKEN_WEIGHT = {
23
+ numerator: 1,
24
+ denominator: 1,
25
+ };
26
+ /*
27
+ * A model's weights are its prices to a millionth of a token: finer than any
28
+ * price list is written, and whole numbers either way.
29
+ */
30
+ const MODEL_WEIGHT_DENOMINATOR = 1000000;
31
+ exports.DEFAULT_CACHE_TOKEN_WEIGHTS = {
32
+ read: exports.CACHE_READ_TOKEN_WEIGHT,
33
+ write: exports.CACHE_WRITE_TOKEN_WEIGHT,
34
+ isModelPriced: false,
35
+ };
48
36
  class AiTokenCount {
49
37
  /*
50
- * What a call - or a sum of calls - counts as: its fresh tokens, a tenth
51
- * of the tokens read from the prompt cache and one and a quarter of the
52
- * tokens written to it, each weighted part rounded up to a whole token.
38
+ * What a call - or a sum of calls of one model - counts as: its fresh
39
+ * tokens, and the tokens read from and written to the prompt cache at the
40
+ * model's weights, each weighted part rounded up to a whole token.
53
41
  */
54
42
  static count(usage) {
55
43
  return this.getBreakdown(usage).countedTokens;
@@ -64,8 +52,9 @@ class AiTokenCount {
64
52
  const cacheReadTokens = this.toTokenCount(usage.cachedInputTokens);
65
53
  const cacheWriteTokens = this.toTokenCount(usage.cacheCreationTokens);
66
54
  const freshTokens = Math.max(0, totalTokens - cacheReadTokens - cacheWriteTokens);
67
- const countedCacheReadTokens = this.weigh(cacheReadTokens, exports.CACHE_READ_TOKEN_WEIGHT);
68
- const countedCacheWriteTokens = this.weigh(cacheWriteTokens, exports.CACHE_WRITE_TOKEN_WEIGHT);
55
+ const cacheWeights = this.getCacheWeights(usage.modelName);
56
+ const countedCacheReadTokens = this.weigh(cacheReadTokens, cacheWeights.read);
57
+ const countedCacheWriteTokens = this.weigh(cacheWriteTokens, cacheWeights.write);
69
58
  return {
70
59
  countedTokens: freshTokens + countedCacheReadTokens + countedCacheWriteTokens,
71
60
  totalTokens,
@@ -74,29 +63,76 @@ class AiTokenCount {
74
63
  countedCacheReadTokens,
75
64
  cacheWriteTokens,
76
65
  countedCacheWriteTokens,
66
+ cacheWeights,
77
67
  };
78
68
  }
79
69
  /*
80
- * The tokens of several calls added up, part by part - what a day of AI
81
- * Logs rows sums to before it is counted.
70
+ * What a model's cached tokens count as: the price its provider charges
71
+ * for a token read from, and one written to, its prompt cache, over the
72
+ * price of a fresh input token - the model's list prices in the cost
73
+ * catalog, at their standard tier (every long-prompt tier keeps the same
74
+ * shares). A model the catalog has no cache price for counts them as a
75
+ * tenth and one and a quarter; a model it has a read price but no write
76
+ * price for is not charged extra for a write, which counts as one.
82
77
  */
83
- static add(usages) {
84
- const sum = {
85
- total: 0,
86
- read: 0,
87
- write: 0,
88
- };
89
- for (const usage of usages) {
90
- sum.total += this.toTokenCount(usage.totalTokens);
91
- sum.read += this.toTokenCount(usage.cachedInputTokens);
92
- sum.write += this.toTokenCount(usage.cacheCreationTokens);
78
+ static getCacheWeights(modelName) {
79
+ const name = typeof modelName === "string" ? modelName.trim() : "";
80
+ if (!name) {
81
+ return exports.DEFAULT_CACHE_TOKEN_WEIGHTS;
82
+ }
83
+ const price = LlmCostCatalog_1.LlmCostCatalogUtil.findPriceForModel(name);
84
+ if (!price ||
85
+ !this.isPrice(price.inputPricePerMillionTokensInUSD) ||
86
+ price.inputPricePerMillionTokensInUSD <= 0 ||
87
+ !this.isPrice(price.cacheReadPricePerMillionTokensInUSD)) {
88
+ return exports.DEFAULT_CACHE_TOKEN_WEIGHTS;
93
89
  }
90
+ const inputPrice = price.inputPricePerMillionTokensInUSD;
94
91
  return {
95
- totalTokens: sum.total,
96
- cachedInputTokens: sum.read,
97
- cacheCreationTokens: sum.write,
92
+ read: this.toWeight(price.cacheReadPricePerMillionTokensInUSD, inputPrice),
93
+ write: this.isPrice(price.cacheWritePricePerMillionTokensInUSD)
94
+ ? this.toWeight(price.cacheWritePricePerMillionTokensInUSD, inputPrice)
95
+ : exports.FRESH_TOKEN_WEIGHT,
96
+ isModelPriced: true,
98
97
  };
99
98
  }
99
+ /*
100
+ * The tokens of several calls added up, part by part, one sum for each
101
+ * model - what a day of AI Logs rows sums to before it is counted, in the
102
+ * order each model first appears.
103
+ */
104
+ static sumByModel(usages) {
105
+ const sums = new Map();
106
+ for (const usage of usages) {
107
+ const modelName = this.toModelName(usage.modelName);
108
+ const key = modelName === null ? "" : `model:${modelName}`;
109
+ let sum = sums.get(key);
110
+ if (!sum) {
111
+ sum = {
112
+ totalTokens: 0,
113
+ cachedInputTokens: 0,
114
+ cacheCreationTokens: 0,
115
+ modelName,
116
+ };
117
+ sums.set(key, sum);
118
+ }
119
+ sum.totalTokens += this.toTokenCount(usage.totalTokens);
120
+ sum.cachedInputTokens += this.toTokenCount(usage.cachedInputTokens);
121
+ sum.cacheCreationTokens += this.toTokenCount(usage.cacheCreationTokens);
122
+ }
123
+ return Array.from(sums.values());
124
+ }
125
+ /*
126
+ * What several calls count as together: each model's sum counted at that
127
+ * model's weights, and the counts added up. A model's weighted parts are
128
+ * rounded up once for all its calls, where the AI Logs round each call's,
129
+ * so the sum can count a token or so per call less than its rows add up to.
130
+ */
131
+ static countAll(usages) {
132
+ return this.sumByModel(usages).reduce((total, sum) => {
133
+ return total + this.count(sum);
134
+ }, 0);
135
+ }
100
136
  /*
101
137
  * A token count as a whole, non-negative number: a count reported as a
102
138
  * string (a SQL sum), a fraction, a negative number or anything else that
@@ -113,9 +149,42 @@ class AiTokenCount {
113
149
  }
114
150
  return Math.floor(parsed);
115
151
  }
152
+ // A model's name as a sum keeps it: trimmed, or null when it names none.
153
+ static toModelName(value) {
154
+ if (typeof value !== "string") {
155
+ return null;
156
+ }
157
+ const trimmed = value.trim();
158
+ return trimmed.length > 0 ? trimmed : null;
159
+ }
160
+ static isPrice(value) {
161
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
162
+ }
163
+ // A price over the input price, as a whole-number fraction in lowest terms.
164
+ static toWeight(price, inputPrice) {
165
+ const numerator = Math.round((price / inputPrice) * MODEL_WEIGHT_DENOMINATOR);
166
+ if (numerator <= 0) {
167
+ return { numerator: 0, denominator: 1 };
168
+ }
169
+ const divisor = this.greatestCommonDivisor(numerator, MODEL_WEIGHT_DENOMINATOR);
170
+ return {
171
+ numerator: numerator / divisor,
172
+ denominator: MODEL_WEIGHT_DENOMINATOR / divisor,
173
+ };
174
+ }
175
+ static greatestCommonDivisor(a, b) {
176
+ let x = a;
177
+ let y = b;
178
+ while (y !== 0) {
179
+ const rest = x % y;
180
+ x = y;
181
+ y = rest;
182
+ }
183
+ return x;
184
+ }
116
185
  // Tokens times a weight, rounded up to a whole token, in whole numbers.
117
186
  static weigh(tokens, weight) {
118
- if (tokens <= 0) {
187
+ if (tokens <= 0 || weight.numerator <= 0) {
119
188
  return 0;
120
189
  }
121
190
  return Math.ceil((tokens * weight.numerator) / weight.denominator);
@@ -2,3 +2,5 @@ import commonJsModule from "./AiTokenCount.js";
2
2
  export default commonJsModule.default;
3
3
  export const CACHE_READ_TOKEN_WEIGHT = commonJsModule.CACHE_READ_TOKEN_WEIGHT;
4
4
  export const CACHE_WRITE_TOKEN_WEIGHT = commonJsModule.CACHE_WRITE_TOKEN_WEIGHT;
5
+ export const DEFAULT_CACHE_TOKEN_WEIGHTS = commonJsModule.DEFAULT_CACHE_TOKEN_WEIGHTS;
6
+ export const FRESH_TOKEN_WEIGHT = commonJsModule.FRESH_TOKEN_WEIGHT;
@@ -84,6 +84,7 @@ export interface CodeFixTaskContext {
84
84
  request?: CodeTaskRequest | undefined;
85
85
  productionReview?: ProductionReviewTaskContext | undefined;
86
86
  allowedCodeRepositoryIds?: Array<string> | undefined;
87
+ pickedCodeRepositoryId?: string | undefined;
87
88
  }
88
89
  export declare function getProductionReviewTaskContext(taskContext: CodeFixTaskContext | null | undefined): ProductionReviewTaskContext | null;
89
90
  export declare function getCodeTaskRequest(taskContext: CodeFixTaskContext | null | undefined): CodeTaskRequest | null;
@@ -84,6 +84,7 @@ export interface CodeFixTaskContext {
84
84
  request?: CodeTaskRequest | undefined;
85
85
  productionReview?: ProductionReviewTaskContext | undefined;
86
86
  allowedCodeRepositoryIds?: Array<string> | undefined;
87
+ pickedCodeRepositoryId?: string | undefined;
87
88
  }
88
89
  export declare function getProductionReviewTaskContext(taskContext: CodeFixTaskContext | null | undefined): ProductionReviewTaskContext | null;
89
90
  export declare function getCodeTaskRequest(taskContext: CodeFixTaskContext | null | undefined): CodeTaskRequest | null;
@@ -0,0 +1,53 @@
1
+ import { JSONObject } from "../JSON.mjs";
2
+ export declare enum AffectedResourceKind {
3
+ Monitor = "Monitor",
4
+ Host = "Host",
5
+ NetworkDevice = "NetworkDevice",
6
+ KubernetesCluster = "KubernetesCluster",
7
+ DockerHost = "DockerHost",
8
+ PodmanHost = "PodmanHost",
9
+ ProxmoxCluster = "ProxmoxCluster",
10
+ VMwareVCenter = "VMwareVCenter",
11
+ CephCluster = "CephCluster",
12
+ StorageArray = "StorageArray",
13
+ DockerSwarmCluster = "DockerSwarmCluster",
14
+ IoTFleet = "IoTFleet",
15
+ DatabaseServer = "DatabaseServer",
16
+ CloudResource = "CloudResource",
17
+ NetworkSite = "NetworkSite",
18
+ Service = "Service"
19
+ }
20
+ export declare const AFFECTED_RESOURCE_KINDS: ReadonlyArray<AffectedResourceKind>;
21
+ export declare const AFFECTED_RESOURCE_SEARCH_ROUTE: string;
22
+ export declare const AFFECTED_RESOURCE_SEARCH_DEFAULT_LIMIT: number;
23
+ export declare const AFFECTED_RESOURCE_SEARCH_MAX_LIMIT: number;
24
+ export declare const AFFECTED_RESOURCE_SEARCH_MAX_TEXT_LENGTH: number;
25
+ export interface AffectedResourceSearchRequest {
26
+ search: string;
27
+ kinds: Array<AffectedResourceKind>;
28
+ limitPerKind: number;
29
+ countKinds: Array<AffectedResourceKind>;
30
+ }
31
+ export interface AffectedResourceSearchMatch {
32
+ _id: string;
33
+ name: string;
34
+ detail?: string | undefined;
35
+ }
36
+ export interface AffectedResourceSearchKindResult {
37
+ kind: AffectedResourceKind;
38
+ count: number;
39
+ matches: Array<AffectedResourceSearchMatch>;
40
+ }
41
+ export interface AffectedResourceSearchCount {
42
+ kind: AffectedResourceKind;
43
+ count: number;
44
+ }
45
+ export interface AffectedResourceSearchResult {
46
+ kinds: Array<AffectedResourceSearchKindResult>;
47
+ counts: Array<AffectedResourceSearchCount>;
48
+ unreadableKinds: Array<AffectedResourceKind>;
49
+ }
50
+ export declare function isAffectedResourceKind(value: unknown): value is AffectedResourceKind;
51
+ export declare function readAffectedResourceSearchRequest(body: unknown): AffectedResourceSearchRequest;
52
+ export declare function readAffectedResourceSearchResult(data: unknown): AffectedResourceSearchResult;
53
+ export declare function toAffectedResourceSearchResultJSON(result: AffectedResourceSearchResult): JSONObject;
@@ -0,0 +1,53 @@
1
+ import { JSONObject } from "../JSON";
2
+ export declare enum AffectedResourceKind {
3
+ Monitor = "Monitor",
4
+ Host = "Host",
5
+ NetworkDevice = "NetworkDevice",
6
+ KubernetesCluster = "KubernetesCluster",
7
+ DockerHost = "DockerHost",
8
+ PodmanHost = "PodmanHost",
9
+ ProxmoxCluster = "ProxmoxCluster",
10
+ VMwareVCenter = "VMwareVCenter",
11
+ CephCluster = "CephCluster",
12
+ StorageArray = "StorageArray",
13
+ DockerSwarmCluster = "DockerSwarmCluster",
14
+ IoTFleet = "IoTFleet",
15
+ DatabaseServer = "DatabaseServer",
16
+ CloudResource = "CloudResource",
17
+ NetworkSite = "NetworkSite",
18
+ Service = "Service"
19
+ }
20
+ export declare const AFFECTED_RESOURCE_KINDS: ReadonlyArray<AffectedResourceKind>;
21
+ export declare const AFFECTED_RESOURCE_SEARCH_ROUTE: string;
22
+ export declare const AFFECTED_RESOURCE_SEARCH_DEFAULT_LIMIT: number;
23
+ export declare const AFFECTED_RESOURCE_SEARCH_MAX_LIMIT: number;
24
+ export declare const AFFECTED_RESOURCE_SEARCH_MAX_TEXT_LENGTH: number;
25
+ export interface AffectedResourceSearchRequest {
26
+ search: string;
27
+ kinds: Array<AffectedResourceKind>;
28
+ limitPerKind: number;
29
+ countKinds: Array<AffectedResourceKind>;
30
+ }
31
+ export interface AffectedResourceSearchMatch {
32
+ _id: string;
33
+ name: string;
34
+ detail?: string | undefined;
35
+ }
36
+ export interface AffectedResourceSearchKindResult {
37
+ kind: AffectedResourceKind;
38
+ count: number;
39
+ matches: Array<AffectedResourceSearchMatch>;
40
+ }
41
+ export interface AffectedResourceSearchCount {
42
+ kind: AffectedResourceKind;
43
+ count: number;
44
+ }
45
+ export interface AffectedResourceSearchResult {
46
+ kinds: Array<AffectedResourceSearchKindResult>;
47
+ counts: Array<AffectedResourceSearchCount>;
48
+ unreadableKinds: Array<AffectedResourceKind>;
49
+ }
50
+ export declare function isAffectedResourceKind(value: unknown): value is AffectedResourceKind;
51
+ export declare function readAffectedResourceSearchRequest(body: unknown): AffectedResourceSearchRequest;
52
+ export declare function readAffectedResourceSearchResult(data: unknown): AffectedResourceSearchResult;
53
+ export declare function toAffectedResourceSearchResultJSON(result: AffectedResourceSearchResult): JSONObject;
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AFFECTED_RESOURCE_SEARCH_MAX_TEXT_LENGTH = exports.AFFECTED_RESOURCE_SEARCH_MAX_LIMIT = exports.AFFECTED_RESOURCE_SEARCH_DEFAULT_LIMIT = exports.AFFECTED_RESOURCE_SEARCH_ROUTE = exports.AFFECTED_RESOURCE_KINDS = exports.AffectedResourceKind = void 0;
7
+ exports.isAffectedResourceKind = isAffectedResourceKind;
8
+ exports.readAffectedResourceSearchRequest = readAffectedResourceSearchRequest;
9
+ exports.readAffectedResourceSearchResult = readAffectedResourceSearchResult;
10
+ exports.toAffectedResourceSearchResultJSON = toAffectedResourceSearchResultJSON;
11
+ const BadDataException_1 = __importDefault(require("../Exception/BadDataException"));
12
+ const ObjectID_1 = __importDefault(require("../ObjectID"));
13
+ /*
14
+ * ONE SEARCH ACROSS EVERY KIND OF RESOURCE AN INCIDENT, AN ALERT OR A
15
+ * MAINTENANCE EVENT CAN AFFECT.
16
+ *
17
+ * Issue #5341: a customer read the Affected Resources picker as "a lookup
18
+ * against Hosts" - a project with hosts and network devices found its
19
+ * hosts, and nothing else, because routers and switches could not be
20
+ * linked at all, and every kind the picker did search was asked for twice
21
+ * per keystroke (its name, then its description), about thirty requests a
22
+ * letter. The picker now asks once (POST /affected-resources/search), and
23
+ * the server reads each kind with the person's own rights: a kind they may
24
+ * not read is named, never listed, and labels and owned scope narrow the
25
+ * rest as a list of that kind would.
26
+ *
27
+ * This module is the request and the answer, read the same way on both
28
+ * sides: the kinds (the picker's AffectedResourceType values), the limits,
29
+ * and the parsers that keep a malformed request out of the server and a
30
+ * malformed answer out of the picker. React-free and server-free.
31
+ */
32
+ var AffectedResourceKind;
33
+ (function (AffectedResourceKind) {
34
+ AffectedResourceKind["Monitor"] = "Monitor";
35
+ AffectedResourceKind["Host"] = "Host";
36
+ AffectedResourceKind["NetworkDevice"] = "NetworkDevice";
37
+ AffectedResourceKind["KubernetesCluster"] = "KubernetesCluster";
38
+ AffectedResourceKind["DockerHost"] = "DockerHost";
39
+ AffectedResourceKind["PodmanHost"] = "PodmanHost";
40
+ AffectedResourceKind["ProxmoxCluster"] = "ProxmoxCluster";
41
+ AffectedResourceKind["VMwareVCenter"] = "VMwareVCenter";
42
+ AffectedResourceKind["CephCluster"] = "CephCluster";
43
+ AffectedResourceKind["StorageArray"] = "StorageArray";
44
+ AffectedResourceKind["DockerSwarmCluster"] = "DockerSwarmCluster";
45
+ AffectedResourceKind["IoTFleet"] = "IoTFleet";
46
+ AffectedResourceKind["DatabaseServer"] = "DatabaseServer";
47
+ AffectedResourceKind["CloudResource"] = "CloudResource";
48
+ AffectedResourceKind["NetworkSite"] = "NetworkSite";
49
+ AffectedResourceKind["Service"] = "Service";
50
+ })(AffectedResourceKind || (exports.AffectedResourceKind = AffectedResourceKind = {}));
51
+ // Every kind, in the order the enum lists them.
52
+ exports.AFFECTED_RESOURCE_KINDS = Object.values(AffectedResourceKind);
53
+ // The route the picker, the API and an API key ask.
54
+ exports.AFFECTED_RESOURCE_SEARCH_ROUTE = "/affected-resources/search";
55
+ /*
56
+ * How many of each kind one answer lists: a page of suggestions per kind
57
+ * while every kind is shown, more once the person narrows to one.
58
+ */
59
+ exports.AFFECTED_RESOURCE_SEARCH_DEFAULT_LIMIT = 15;
60
+ exports.AFFECTED_RESOURCE_SEARCH_MAX_LIMIT = 50;
61
+ /*
62
+ * The longest text searched for. A name is at most a few hundred
63
+ * characters; anything longer is cut rather than refused, so a pasted line
64
+ * still finds the resource it starts with.
65
+ */
66
+ exports.AFFECTED_RESOURCE_SEARCH_MAX_TEXT_LENGTH = 200;
67
+ function isAffectedResourceKind(value) {
68
+ return (typeof value === "string" &&
69
+ exports.AFFECTED_RESOURCE_KINDS.includes(value));
70
+ }
71
+ // Each kind once, in the order first given.
72
+ function readKinds(value, name) {
73
+ var _a;
74
+ if (value === undefined || value === null) {
75
+ return [];
76
+ }
77
+ if (!Array.isArray(value)) {
78
+ throw new BadDataException_1.default(`${name} must be a list of resource kinds.`);
79
+ }
80
+ const kinds = [];
81
+ for (const item of value) {
82
+ if (!isAffectedResourceKind(item)) {
83
+ throw new BadDataException_1.default(`${name} lists ${((_a = JSON.stringify(item)) === null || _a === void 0 ? void 0 : _a.substring(0, 60)) || "nothing"}, which is not a kind of resource. Use one of: ${exports.AFFECTED_RESOURCE_KINDS.join(", ")}.`);
84
+ }
85
+ if (!kinds.includes(item)) {
86
+ kinds.push(item);
87
+ }
88
+ }
89
+ return kinds;
90
+ }
91
+ /*
92
+ * A request as the server takes it: the kinds checked (an unknown one is
93
+ * refused, naming the ones there are), each kind once, the text trimmed and
94
+ * cut to its limit, the limit held between 1 and the maximum, and a kind
95
+ * both listed and counted listed only.
96
+ */
97
+ function readAffectedResourceSearchRequest(body) {
98
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
99
+ throw new BadDataException_1.default("The search must be a JSON object with search and kinds.");
100
+ }
101
+ const json = body;
102
+ const rawSearch = json["search"];
103
+ if (rawSearch !== undefined &&
104
+ rawSearch !== null &&
105
+ typeof rawSearch !== "string") {
106
+ throw new BadDataException_1.default("search must be text.");
107
+ }
108
+ const search = (typeof rawSearch === "string" ? rawSearch : "")
109
+ .trim()
110
+ .substring(0, exports.AFFECTED_RESOURCE_SEARCH_MAX_TEXT_LENGTH)
111
+ .trim();
112
+ const kinds = readKinds(json["kinds"], "kinds");
113
+ if (kinds.length === 0) {
114
+ throw new BadDataException_1.default("kinds must name at least one kind of resource to search.");
115
+ }
116
+ const countKinds = readKinds(json["countKinds"], "countKinds").filter((kind) => {
117
+ return !kinds.includes(kind);
118
+ });
119
+ const rawLimit = json["limitPerKind"];
120
+ let limitPerKind = exports.AFFECTED_RESOURCE_SEARCH_DEFAULT_LIMIT;
121
+ if (rawLimit !== undefined && rawLimit !== null) {
122
+ const parsed = typeof rawLimit === "number" ? rawLimit : Number(rawLimit);
123
+ if (!Number.isFinite(parsed)) {
124
+ throw new BadDataException_1.default("limitPerKind must be a number.");
125
+ }
126
+ limitPerKind = Math.min(exports.AFFECTED_RESOURCE_SEARCH_MAX_LIMIT, Math.max(1, Math.floor(parsed)));
127
+ }
128
+ return { search, kinds, limitPerKind, countKinds };
129
+ }
130
+ function readCount(value) {
131
+ return typeof value === "number" && Number.isFinite(value) && value > 0
132
+ ? Math.floor(value)
133
+ : 0;
134
+ }
135
+ /*
136
+ * An answer as the picker reads it: an entry it cannot read (no kind, no
137
+ * id) is dropped rather than shown half, and a count is never below the
138
+ * matches listed.
139
+ */
140
+ function readAffectedResourceSearchResult(data) {
141
+ const json = data && typeof data === "object" && !Array.isArray(data)
142
+ ? data
143
+ : {};
144
+ const kinds = [];
145
+ for (const entry of Array.isArray(json["kinds"]) ? json["kinds"] : []) {
146
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
147
+ continue;
148
+ }
149
+ const kindJson = entry;
150
+ const kind = kindJson["kind"];
151
+ if (!isAffectedResourceKind(kind)) {
152
+ continue;
153
+ }
154
+ const matches = [];
155
+ const rawMatches = kindJson["matches"];
156
+ for (const match of Array.isArray(rawMatches) ? rawMatches : []) {
157
+ if (!match || typeof match !== "object" || Array.isArray(match)) {
158
+ continue;
159
+ }
160
+ const matchJson = match;
161
+ const id = matchJson["_id"];
162
+ if (typeof id !== "string" || !ObjectID_1.default.isValidUUID(id)) {
163
+ continue;
164
+ }
165
+ const name = matchJson["name"];
166
+ const detail = matchJson["detail"];
167
+ const read = {
168
+ _id: id,
169
+ name: typeof name === "string" ? name : "",
170
+ };
171
+ if (typeof detail === "string" && detail.trim()) {
172
+ read.detail = detail.trim();
173
+ }
174
+ matches.push(read);
175
+ }
176
+ kinds.push({
177
+ kind: kind,
178
+ count: Math.max(readCount(kindJson["count"]), matches.length),
179
+ matches: matches,
180
+ });
181
+ }
182
+ const counts = [];
183
+ for (const entry of Array.isArray(json["counts"]) ? json["counts"] : []) {
184
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
185
+ continue;
186
+ }
187
+ const countJson = entry;
188
+ const kind = countJson["kind"];
189
+ if (isAffectedResourceKind(kind)) {
190
+ counts.push({ kind: kind, count: readCount(countJson["count"]) });
191
+ }
192
+ }
193
+ const unreadableKinds = [];
194
+ for (const kind of Array.isArray(json["unreadableKinds"])
195
+ ? json["unreadableKinds"]
196
+ : []) {
197
+ if (isAffectedResourceKind(kind) && !unreadableKinds.includes(kind)) {
198
+ unreadableKinds.push(kind);
199
+ }
200
+ }
201
+ return { kinds, counts, unreadableKinds };
202
+ }
203
+ // The answer as JSON, as the route sends it.
204
+ function toAffectedResourceSearchResultJSON(result) {
205
+ return {
206
+ kinds: result.kinds.map((kind) => {
207
+ return {
208
+ kind: kind.kind,
209
+ count: kind.count,
210
+ matches: kind.matches.map((match) => {
211
+ const json = { _id: match._id, name: match.name };
212
+ if (match.detail) {
213
+ json["detail"] = match.detail;
214
+ }
215
+ return json;
216
+ }),
217
+ };
218
+ }),
219
+ counts: result.counts.map((count) => {
220
+ return { kind: count.kind, count: count.count };
221
+ }),
222
+ unreadableKinds: [...result.unreadableKinds],
223
+ };
224
+ }
@@ -0,0 +1,11 @@
1
+ import commonJsModule from "./AffectedResourceSearch.js";
2
+ export const AFFECTED_RESOURCE_KINDS = commonJsModule.AFFECTED_RESOURCE_KINDS;
3
+ export const AFFECTED_RESOURCE_SEARCH_DEFAULT_LIMIT = commonJsModule.AFFECTED_RESOURCE_SEARCH_DEFAULT_LIMIT;
4
+ export const AFFECTED_RESOURCE_SEARCH_MAX_LIMIT = commonJsModule.AFFECTED_RESOURCE_SEARCH_MAX_LIMIT;
5
+ export const AFFECTED_RESOURCE_SEARCH_MAX_TEXT_LENGTH = commonJsModule.AFFECTED_RESOURCE_SEARCH_MAX_TEXT_LENGTH;
6
+ export const AFFECTED_RESOURCE_SEARCH_ROUTE = commonJsModule.AFFECTED_RESOURCE_SEARCH_ROUTE;
7
+ export const AffectedResourceKind = commonJsModule.AffectedResourceKind;
8
+ export const isAffectedResourceKind = commonJsModule.isAffectedResourceKind;
9
+ export const readAffectedResourceSearchRequest = commonJsModule.readAffectedResourceSearchRequest;
10
+ export const readAffectedResourceSearchResult = commonJsModule.readAffectedResourceSearchResult;
11
+ export const toAffectedResourceSearchResultJSON = commonJsModule.toAffectedResourceSearchResultJSON;
@@ -1,4 +1,4 @@
1
- import { JSONArray } from "../JSON.mjs";
1
+ import { JSONArray, JSONObject } from "../JSON.mjs";
2
2
  export declare enum ArchivableValueDeleteEffect {
3
3
  Refused = "Refused",
4
4
  Deleted = "Deleted",
@@ -8,7 +8,8 @@ export declare enum ArchivableValueDeleteEffect {
8
8
  }
9
9
  export declare enum ArchivableValueUsageKind {
10
10
  Records = "Records",
11
- Settings = "Settings"
11
+ Settings = "Settings",
12
+ Personal = "Personal"
12
13
  }
13
14
  export interface ArchivableValueUsageItem {
14
15
  tableName: string;
@@ -16,12 +17,30 @@ export interface ArchivableValueUsageItem {
16
17
  singularTitle: string;
17
18
  count: number;
18
19
  isCountCapped: boolean;
20
+ totalCount?: number | undefined;
21
+ isTotalCountCapped?: boolean | undefined;
19
22
  effect: ArchivableValueDeleteEffect;
20
23
  kind: ArchivableValueUsageKind;
21
24
  }
25
+ export declare enum ArchivableValuesUsagePurpose {
26
+ Archive = "Archive",
27
+ Delete = "Delete"
28
+ }
29
+ export interface ArchivableValuesUsage {
30
+ usage: Array<ArchivableValueUsageItem>;
31
+ refusedValueIds: Array<string>;
32
+ refusedUsage: Array<ArchivableValueUsageItem>;
33
+ }
22
34
  export default class ArchivableValueUsage {
23
35
  static toJSONArray(items: Array<ArchivableValueUsageItem>): JSONArray;
24
36
  static fromJSONArray(value: unknown): Array<ArchivableValueUsageItem>;
37
+ static valuesUsageToJSON(usage: ArchivableValuesUsage): JSONObject;
38
+ static valuesUsageFromJSON(value: unknown): ArchivableValuesUsage;
25
39
  static isDeleteRefused(items: Array<ArchivableValueUsageItem>): boolean;
26
40
  static getSettings(items: Array<ArchivableValueUsageItem>): Array<ArchivableValueUsageItem>;
41
+ static getPersonal(items: Array<ArchivableValueUsageItem>): Array<ArchivableValueUsageItem>;
42
+ static getTotalCount(item: ArchivableValueUsageItem): {
43
+ count: number;
44
+ isCountCapped: boolean;
45
+ };
27
46
  }