@opengeni/contracts 3.1.0-canary.1 → 3.1.2

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 (434) hide show
  1. package/dist/agent-authored-durable-text.d.ts +9 -9
  2. package/dist/agent-config.d.ts +971 -0
  3. package/dist/agent-instruction-changes.d.ts +110 -0
  4. package/dist/agent-learning.d.ts +243 -0
  5. package/dist/allowance-refusal.d.ts +9 -0
  6. package/dist/allowance-refusal.js +50 -0
  7. package/dist/allowance-refusal.js.map +1 -0
  8. package/dist/analytics-consent-report.d.ts +19 -0
  9. package/dist/analytics-consent-report.js +10 -0
  10. package/dist/analytics-consent-report.js.map +1 -0
  11. package/dist/api-key-presets.d.ts +19 -0
  12. package/dist/artifact-catalog.d.ts +188 -0
  13. package/dist/artifacts.d.ts +86 -0
  14. package/dist/atlassian-native-retirement.d.ts +16 -0
  15. package/dist/atlassian-native-retirement.js +30 -0
  16. package/dist/atlassian-native-retirement.js.map +1 -0
  17. package/dist/atlassian.d.ts +1 -0
  18. package/dist/atlassian.js +34 -19
  19. package/dist/browser-storage.d.ts +5 -0
  20. package/dist/browser-storage.js +9 -0
  21. package/dist/browser-storage.js.map +1 -0
  22. package/dist/bundled-skills.d.ts +24 -1
  23. package/dist/canonical-human-identities.js +2 -1
  24. package/dist/chunk-2ZIHHL72.js +153 -0
  25. package/dist/chunk-2ZIHHL72.js.map +1 -0
  26. package/dist/{chunk-5LYFSZ7O.js → chunk-352X6ENP.js} +31 -31
  27. package/dist/chunk-4JGHSSB7.js +11 -0
  28. package/dist/chunk-4JGHSSB7.js.map +1 -0
  29. package/dist/chunk-4QO6GJUX.js +85 -0
  30. package/dist/chunk-4QO6GJUX.js.map +1 -0
  31. package/dist/chunk-4VDMHLLL.js +49 -0
  32. package/dist/chunk-4VDMHLLL.js.map +1 -0
  33. package/dist/chunk-56SNIMDO.js +9 -0
  34. package/dist/chunk-56SNIMDO.js.map +1 -0
  35. package/dist/chunk-6C2HKFTU.js +207 -0
  36. package/dist/chunk-6C2HKFTU.js.map +1 -0
  37. package/dist/chunk-6IXO76Z6.js +72 -0
  38. package/dist/chunk-6IXO76Z6.js.map +1 -0
  39. package/dist/chunk-7272KVWZ.js +60 -0
  40. package/dist/chunk-7272KVWZ.js.map +1 -0
  41. package/dist/{chunk-7ABONTXE.js → chunk-E3GGUBHS.js} +49 -5
  42. package/dist/chunk-E3GGUBHS.js.map +1 -0
  43. package/dist/chunk-EFZYKUE2.js +767 -0
  44. package/dist/chunk-EFZYKUE2.js.map +1 -0
  45. package/dist/chunk-EKWNTOG3.js +154 -0
  46. package/dist/chunk-EKWNTOG3.js.map +1 -0
  47. package/dist/chunk-HABQ7ADB.js +234 -0
  48. package/dist/chunk-HABQ7ADB.js.map +1 -0
  49. package/dist/chunk-HRRU4QPI.js +91 -0
  50. package/dist/chunk-HRRU4QPI.js.map +1 -0
  51. package/dist/{chunk-3SIZGL3O.js → chunk-IK36LXKC.js} +18 -2
  52. package/dist/chunk-IK36LXKC.js.map +1 -0
  53. package/dist/{chunk-TXTQIYCV.js → chunk-ILJ72KPO.js} +56 -3
  54. package/dist/chunk-ILJ72KPO.js.map +1 -0
  55. package/dist/chunk-J4HQ3UKY.js +93 -0
  56. package/dist/chunk-J4HQ3UKY.js.map +1 -0
  57. package/dist/chunk-KHHZTBP7.js +11 -0
  58. package/dist/chunk-KHHZTBP7.js.map +1 -0
  59. package/dist/{chunk-WYBDERIY.js → chunk-LZ2LAHIX.js} +47 -41
  60. package/dist/chunk-LZ2LAHIX.js.map +1 -0
  61. package/dist/chunk-NDZHPTCL.js +400 -0
  62. package/dist/chunk-NDZHPTCL.js.map +1 -0
  63. package/dist/chunk-OF6OKOBF.js +54793 -0
  64. package/dist/chunk-OF6OKOBF.js.map +1 -0
  65. package/dist/chunk-OL23ARTF.js +94 -0
  66. package/dist/chunk-OL23ARTF.js.map +1 -0
  67. package/dist/chunk-PUIUXIOL.js +189 -0
  68. package/dist/chunk-PUIUXIOL.js.map +1 -0
  69. package/dist/{chunk-WBYTNVIW.js → chunk-RKX3NQYS.js} +1 -1
  70. package/dist/{chunk-Y3KNXVTD.js → chunk-RMWXDZEO.js} +128 -21
  71. package/dist/chunk-RMWXDZEO.js.map +1 -0
  72. package/dist/{chunk-MRWYRAS5.js → chunk-SHO4YO4B.js} +27 -35
  73. package/dist/chunk-SHO4YO4B.js.map +1 -0
  74. package/dist/chunk-SWRN2DJ3.js +153 -0
  75. package/dist/chunk-SWRN2DJ3.js.map +1 -0
  76. package/dist/chunk-TCXCRBPF.js +267 -0
  77. package/dist/chunk-TCXCRBPF.js.map +1 -0
  78. package/dist/chunk-TLU3UEMD.js +324 -0
  79. package/dist/chunk-TLU3UEMD.js.map +1 -0
  80. package/dist/chunk-TSWWZMUS.js +186 -0
  81. package/dist/chunk-TSWWZMUS.js.map +1 -0
  82. package/dist/{chunk-PX3VCKAU.js → chunk-WVCFSOUZ.js} +1 -1
  83. package/dist/{chunk-PX3VCKAU.js.map → chunk-WVCFSOUZ.js.map} +1 -1
  84. package/dist/chunk-XDLAGX66.js +127 -0
  85. package/dist/chunk-XDLAGX66.js.map +1 -0
  86. package/dist/chunk-YKZ4WU4P.js +33 -0
  87. package/dist/chunk-YKZ4WU4P.js.map +1 -0
  88. package/dist/{chunk-O5LEQHDM.js → chunk-Z7WEVGCL.js} +3 -3
  89. package/dist/{chunk-YBW5JSA3.js → chunk-ZDCRWCGZ.js} +119 -101
  90. package/dist/chunk-ZDCRWCGZ.js.map +1 -0
  91. package/dist/claude-provider-account-authority.d.ts +18 -0
  92. package/dist/claude-subscription-oauth.d.ts +42 -0
  93. package/dist/claude-subscription-usage.d.ts +159 -0
  94. package/dist/client-error-report.d.ts +158 -0
  95. package/dist/client-error-report.js +164 -0
  96. package/dist/client-error-report.js.map +1 -0
  97. package/dist/code-search.d.ts +52 -0
  98. package/dist/code-search.js +40 -0
  99. package/dist/code-search.js.map +1 -0
  100. package/dist/codex-provider-account-authority.js +20 -12
  101. package/dist/codex-provider-account-authority.js.map +1 -1
  102. package/dist/company-brain.d.ts +19 -81
  103. package/dist/company-profile.d.ts +144 -6
  104. package/dist/connect.d.ts +37 -0
  105. package/dist/connect.js +216 -159
  106. package/dist/connect.js.map +1 -1
  107. package/dist/connection-account-label.d.ts +2 -0
  108. package/dist/connection-account-label.js +35 -0
  109. package/dist/connection-account-label.js.map +1 -0
  110. package/dist/connection-authority.d.ts +9 -317
  111. package/dist/connection-authority.js +37 -42
  112. package/dist/connector-attachments.js +2 -1
  113. package/dist/connector-destinations.js +2 -1
  114. package/dist/connector-tool-permissions.d.ts +137 -0
  115. package/dist/cua-desktop-tools.d.ts +17 -0
  116. package/dist/define-schema.d.ts +8 -0
  117. package/dist/direct-model-provider.d.ts +36 -0
  118. package/dist/editable-artifact-codec-registry.js +5 -5
  119. package/dist/editable-artifact-committed-transaction.js +3 -2
  120. package/dist/editable-artifact-live.js +5 -5
  121. package/dist/editable-artifact-serialized-commit.js +6 -6
  122. package/dist/editable-artifact-versions.d.ts +7 -1
  123. package/dist/editable-artifact-versions.js +1 -1
  124. package/dist/editable-artifacts.js +62 -56
  125. package/dist/event-preview.d.ts +22 -0
  126. package/dist/external-identities.d.ts +174 -0
  127. package/dist/external-identities.js +15 -4
  128. package/dist/first-party-tool-authorization.d.ts +815 -0
  129. package/dist/github-repository-contracts.js +60 -43
  130. package/dist/github-repository-contracts.js.map +1 -1
  131. package/dist/google-drive.d.ts +2 -1
  132. package/dist/google-drive.js +305 -238
  133. package/dist/google-drive.js.map +1 -1
  134. package/dist/host-mcp-bindings.d.ts +39 -10
  135. package/dist/host-mcp-bindings.js +256 -171
  136. package/dist/host-mcp-bindings.js.map +1 -1
  137. package/dist/image-generation.d.ts +1 -0
  138. package/dist/index.d.ts +15715 -3850
  139. package/dist/index.js +2088 -289
  140. package/dist/insights-usage.d.ts +877 -0
  141. package/dist/insights-usage.js +559 -0
  142. package/dist/insights-usage.js.map +1 -0
  143. package/dist/interaction.d.ts +1176 -829
  144. package/dist/knowledge-entries.d.ts +984 -0
  145. package/dist/knowledge-preparation.d.ts +239 -0
  146. package/dist/managed-auth-session-sets.d.ts +7 -0
  147. package/dist/managed-auth-session-sets.js +198 -132
  148. package/dist/managed-auth-session-sets.js.map +1 -1
  149. package/dist/managed-sign-in-methods.d.ts +56 -0
  150. package/dist/managed-sign-in-methods.js +64 -0
  151. package/dist/managed-sign-in-methods.js.map +1 -0
  152. package/dist/mcp-catalog-limits.d.ts +2 -0
  153. package/dist/mcp-endpoint.js +9 -0
  154. package/dist/mcp-endpoint.js.map +1 -0
  155. package/dist/mcp-oauth.d.ts +2 -2
  156. package/dist/mcp-structured-content.d.ts +25 -0
  157. package/dist/modal-native-proof-v2.d.ts +587 -0
  158. package/dist/modal-native-proof-v2.js +38 -0
  159. package/dist/modal-native-proof-v2.js.map +1 -0
  160. package/dist/model-account-choice.d.ts +235 -0
  161. package/dist/model-account-settings.d.ts +422 -0
  162. package/dist/model-availability.d.ts +15 -0
  163. package/dist/model-connection-access.d.ts +13 -0
  164. package/dist/model-context-inspector.d.ts +98 -0
  165. package/dist/model-display.d.ts +43 -0
  166. package/dist/model-display.js +17 -0
  167. package/dist/model-display.js.map +1 -0
  168. package/dist/model-picker-order.d.ts +3 -1
  169. package/dist/model-picker-order.js +3 -0
  170. package/dist/model-picker-order.js.map +1 -1
  171. package/dist/organization-access.d.ts +412 -0
  172. package/dist/organization-access.js +39 -0
  173. package/dist/organization-access.js.map +1 -0
  174. package/dist/organization-integration-policy.d.ts +27 -0
  175. package/dist/organization-membership-lifecycle.d.ts +38 -0
  176. package/dist/organization-model-usage.d.ts +146 -0
  177. package/dist/organization-model-usage.js +78 -0
  178. package/dist/organization-model-usage.js.map +1 -0
  179. package/dist/organization-recovery.js +2 -1
  180. package/dist/organization-usage.d.ts +138 -0
  181. package/dist/permissions.d.ts +18 -0
  182. package/dist/personal-github.d.ts +1 -0
  183. package/dist/personal-github.js +199 -144
  184. package/dist/personal-github.js.map +1 -1
  185. package/dist/plugin-discovery.js +1 -1
  186. package/dist/prepared-mcp-setup.d.ts +54 -0
  187. package/dist/prepared-mcp-setup.js +12 -0
  188. package/dist/prepared-mcp-setup.js.map +1 -0
  189. package/dist/product-analytics.d.ts +116 -0
  190. package/dist/product-lifecycle-facts.d.ts +73 -0
  191. package/dist/remember.d.ts +98 -6
  192. package/dist/retained-output.d.ts +8 -0
  193. package/dist/sandbox-file-artifacts.d.ts +1 -0
  194. package/dist/sandbox-provider-command.d.ts +91 -1
  195. package/dist/sandbox-recovery.d.ts +146 -0
  196. package/dist/secret-generator.d.ts +44 -0
  197. package/dist/secret-references.d.ts +90 -0
  198. package/dist/secret-resolution.d.ts +111 -0
  199. package/dist/secret-totp.d.ts +41 -0
  200. package/dist/session-final-reply.d.ts +6 -0
  201. package/dist/session-final-reply.js +9 -0
  202. package/dist/session-final-reply.js.map +1 -0
  203. package/dist/session-goal-reports.d.ts +21 -0
  204. package/dist/session-history-import.d.ts +1272 -0
  205. package/dist/session-list-entries.d.ts +4 -0
  206. package/dist/session-list-entries.js +56 -0
  207. package/dist/session-list-entries.js.map +1 -0
  208. package/dist/session-mcp-projections.d.ts +6 -0
  209. package/dist/session-mcp-tool-permissions.d.ts +62 -0
  210. package/dist/session-message-search.d.ts +68 -0
  211. package/dist/session-target.d.ts +18 -0
  212. package/dist/session-titles.d.ts +8 -0
  213. package/dist/session-titles.js +5 -1
  214. package/dist/session-usage-limit-refusal.d.ts +34 -0
  215. package/dist/session-usage-limit-refusal.js +15 -0
  216. package/dist/session-usage-limit-refusal.js.map +1 -0
  217. package/dist/session-usage-limits.d.ts +127 -0
  218. package/dist/session-usage-limits.js +41 -0
  219. package/dist/session-usage-limits.js.map +1 -0
  220. package/dist/signup-attribution.d.ts +39 -0
  221. package/dist/site-data.d.ts +286 -0
  222. package/dist/site-operations.d.ts +39 -0
  223. package/dist/site-publishing.d.ts +778 -0
  224. package/dist/site-session-http.d.ts +89 -4
  225. package/dist/site-session-http.js +25 -1
  226. package/dist/site-sql.d.ts +421 -0
  227. package/dist/skill-catalog-context.d.ts +7 -0
  228. package/dist/skill-files.d.ts +1 -1
  229. package/dist/skill-use.d.ts +61 -0
  230. package/dist/skills.d.ts +15 -0
  231. package/dist/slack-bot-scopes.d.ts +17 -12
  232. package/dist/slack-bot-scopes.js +10 -3
  233. package/dist/slack-rest-mcp.d.ts +36 -0
  234. package/dist/slack-rest-mcp.js +25 -0
  235. package/dist/slack-rest-mcp.js.map +1 -0
  236. package/dist/spreadsheet-artifact-commands.d.ts +14 -1
  237. package/dist/spreadsheet-artifact-commands.js +8 -2
  238. package/dist/spreadsheet-artifact-query.d.ts +13 -6
  239. package/dist/spreadsheet-artifact-query.js +3 -3
  240. package/dist/subscription-account-actions.d.ts +64 -0
  241. package/dist/subscription-account-pools.d.ts +292 -0
  242. package/dist/subscription-personal-authority-v2.d.ts +28 -0
  243. package/dist/subscription-personal-authority-v2.js +12 -0
  244. package/dist/subscription-personal-authority-v2.js.map +1 -0
  245. package/dist/tool-action-review.d.ts +132 -0
  246. package/dist/tool-catalog.d.ts +408 -0
  247. package/dist/tool-policy.d.ts +5 -0
  248. package/dist/tool-review-presentation.d.ts +12 -0
  249. package/dist/tool-review-presentation.js +17 -0
  250. package/dist/tool-review-presentation.js.map +1 -0
  251. package/dist/transcription-recordings.d.ts +21 -0
  252. package/dist/turn-serving-policy.d.ts +221 -0
  253. package/dist/usage-allowances.d.ts +314 -0
  254. package/dist/usage-allowances.js +52 -0
  255. package/dist/usage-allowances.js.map +1 -0
  256. package/dist/vaults.d.ts +1286 -0
  257. package/dist/video-generation.d.ts +3 -0
  258. package/dist/video-generation.js +2 -1
  259. package/dist/workspace-instruction-policies.d.ts +13 -0
  260. package/dist/workspace-integration-wire.d.ts +36 -0
  261. package/dist/workspace-integration-wire.js +23 -0
  262. package/dist/workspace-integration-wire.js.map +1 -0
  263. package/dist/workspace-integrations.d.ts +1028 -0
  264. package/dist/workspace-state.d.ts +85 -416
  265. package/dist/xai-provider-account-authority.js +2 -1
  266. package/package.json +98 -2
  267. package/src/agent-authored-durable-text.ts +14 -11
  268. package/src/agent-config.ts +1698 -0
  269. package/src/agent-instruction-changes.ts +115 -0
  270. package/src/agent-learning.ts +188 -0
  271. package/src/agent-topology.ts +57 -52
  272. package/src/allowance-refusal.ts +81 -0
  273. package/src/analytics-consent-report.ts +20 -0
  274. package/src/api-key-presets.ts +28 -0
  275. package/src/artifact-catalog.ts +82 -0
  276. package/src/artifacts.ts +299 -227
  277. package/src/atlassian-native-retirement.ts +33 -0
  278. package/src/atlassian.ts +135 -108
  279. package/src/browser-storage.ts +10 -0
  280. package/src/bundled-skills.ts +60 -17
  281. package/src/canonical-human-identities.ts +60 -58
  282. package/src/claude-provider-account-authority.ts +12 -0
  283. package/src/claude-subscription-oauth.ts +73 -0
  284. package/src/claude-subscription-usage.ts +68 -0
  285. package/src/client-error-report.ts +343 -0
  286. package/src/code-search.ts +105 -0
  287. package/src/codex-provider-account-authority.ts +21 -16
  288. package/src/company-brain-governed-writes.ts +255 -233
  289. package/src/company-brain.ts +164 -153
  290. package/src/company-profile.ts +365 -292
  291. package/src/connect.ts +212 -173
  292. package/src/connection-account-label.ts +46 -0
  293. package/src/connection-authority.ts +183 -364
  294. package/src/connector-attachments.ts +137 -122
  295. package/src/connector-destinations.ts +46 -42
  296. package/src/connector-tool-permissions.ts +117 -0
  297. package/src/cua-desktop-tools.gen.json +6512 -0
  298. package/src/cua-desktop-tools.linux.gen.json +6600 -0
  299. package/src/cua-desktop-tools.ts +36 -0
  300. package/src/cua-desktop-tools.windows.gen.json +6353 -0
  301. package/src/define-schema.ts +10 -0
  302. package/src/direct-model-provider.ts +108 -0
  303. package/src/editable-artifact-committed-transaction.ts +17 -0
  304. package/src/editable-artifact-versions.ts +7 -1
  305. package/src/event-preview.ts +53 -3
  306. package/src/external-identities.ts +262 -145
  307. package/src/feedback.ts +43 -30
  308. package/src/first-party-tool-authorization.ts +356 -0
  309. package/src/github-repository-contracts.ts +78 -64
  310. package/src/google-drive.ts +285 -234
  311. package/src/governed-learning-activation.ts +152 -131
  312. package/src/governed-learning-evaluator.ts +140 -133
  313. package/src/host-mcp-bindings.ts +292 -198
  314. package/src/image-generation.ts +104 -95
  315. package/src/index.ts +13354 -8654
  316. package/src/insights-usage.ts +727 -0
  317. package/src/interaction.ts +3070 -2326
  318. package/src/knowledge-entries.ts +428 -0
  319. package/src/knowledge-preparation.ts +57 -0
  320. package/src/knowledge.ts +246 -213
  321. package/src/managed-auth-session-sets.ts +220 -144
  322. package/src/managed-sign-in-methods.ts +52 -0
  323. package/src/mcp-catalog-limits.ts +2 -0
  324. package/src/mcp-oauth.ts +43 -34
  325. package/src/mcp-receipts.ts +192 -192
  326. package/src/mcp-structured-content.ts +81 -0
  327. package/src/memory-slack-delivery.ts +171 -142
  328. package/src/modal-native-proof-v2.ts +429 -0
  329. package/src/model-account-choice.ts +177 -0
  330. package/src/model-account-settings.ts +210 -0
  331. package/src/model-availability.ts +22 -0
  332. package/src/model-connection-access.ts +61 -14
  333. package/src/model-context-inspector.ts +133 -99
  334. package/src/model-display.ts +221 -0
  335. package/src/model-picker-order.ts +12 -1
  336. package/src/organization-access.ts +217 -0
  337. package/src/organization-integration-policy.ts +63 -0
  338. package/src/organization-membership-lifecycle.ts +528 -382
  339. package/src/organization-model-usage.ts +81 -0
  340. package/src/organization-recovery.ts +147 -135
  341. package/src/organization-usage.ts +94 -0
  342. package/src/permissions.ts +88 -52
  343. package/src/personal-github.ts +210 -171
  344. package/src/preference-registry.ts +314 -258
  345. package/src/prepared-mcp-setup.ts +189 -0
  346. package/src/product-analytics.ts +261 -0
  347. package/src/product-lifecycle-facts.ts +122 -0
  348. package/src/remember.ts +181 -167
  349. package/src/retained-output.ts +194 -165
  350. package/src/sandbox-file-artifacts.ts +60 -47
  351. package/src/sandbox-provider-command.ts +88 -20
  352. package/src/sandbox-recovery.ts +129 -0
  353. package/src/scoped-knowledge.ts +61 -43
  354. package/src/secret-generator.ts +155 -0
  355. package/src/secret-references.ts +414 -0
  356. package/src/secret-resolution.ts +274 -0
  357. package/src/secret-totp.ts +188 -0
  358. package/src/session-final-reply.ts +16 -0
  359. package/src/session-goal-reports.ts +64 -0
  360. package/src/session-history-import.ts +177 -0
  361. package/src/session-list-entries.ts +96 -0
  362. package/src/session-mcp-projections.ts +11 -0
  363. package/src/session-mcp-tool-permissions.ts +108 -0
  364. package/src/session-message-search.ts +61 -0
  365. package/src/session-target.ts +57 -0
  366. package/src/session-titles.ts +80 -10
  367. package/src/session-topology-primitives.ts +19 -12
  368. package/src/session-usage-limit-refusal.ts +101 -0
  369. package/src/session-usage-limits.ts +171 -0
  370. package/src/signup-attribution.ts +86 -0
  371. package/src/site-data.ts +339 -0
  372. package/src/site-operations.ts +154 -0
  373. package/src/site-publishing.ts +876 -0
  374. package/src/site-session-http.ts +294 -16
  375. package/src/site-sql.ts +1123 -0
  376. package/src/skill-catalog-context.ts +50 -0
  377. package/src/skill-files.ts +3 -3
  378. package/src/skill-use.ts +80 -0
  379. package/src/skills.ts +82 -54
  380. package/src/slack-bot-scopes.ts +31 -39
  381. package/src/slack-rest-mcp.ts +222 -0
  382. package/src/slack-task-policy.ts +96 -73
  383. package/src/spreadsheet-artifact-commands.ts +73 -2
  384. package/src/spreadsheet-artifact-query.ts +187 -39
  385. package/src/subscription-account-actions.ts +84 -0
  386. package/src/subscription-account-pools.ts +53 -0
  387. package/src/subscription-personal-authority-v2.ts +66 -0
  388. package/src/task-notes.ts +55 -51
  389. package/src/tool-action-review.ts +258 -0
  390. package/src/tool-catalog.ts +609 -372
  391. package/src/tool-policy.ts +82 -0
  392. package/src/tool-result-spill.ts +12 -9
  393. package/src/tool-review-presentation.ts +385 -0
  394. package/src/transcription-recordings.ts +145 -131
  395. package/src/turn-serving-policy.ts +166 -0
  396. package/src/usage-allowances.ts +248 -0
  397. package/src/vaults.ts +850 -0
  398. package/src/video-generation.ts +385 -360
  399. package/src/work-claims.ts +173 -149
  400. package/src/workspace-instruction-policies.ts +349 -275
  401. package/src/workspace-integration-wire.ts +101 -0
  402. package/src/workspace-integrations.ts +724 -0
  403. package/src/workspace-learning-administration.ts +57 -44
  404. package/src/workspace-learning-policy.ts +127 -96
  405. package/src/workspace-state.ts +253 -333
  406. package/src/xai-provider-account-authority.ts +22 -17
  407. package/dist/chunk-3SIZGL3O.js.map +0 -1
  408. package/dist/chunk-7ABONTXE.js.map +0 -1
  409. package/dist/chunk-BCS7WHCK.js +0 -139
  410. package/dist/chunk-BCS7WHCK.js.map +0 -1
  411. package/dist/chunk-GRG7PHWQ.js +0 -25
  412. package/dist/chunk-GRG7PHWQ.js.map +0 -1
  413. package/dist/chunk-JUFK3T4Q.js +0 -80
  414. package/dist/chunk-JUFK3T4Q.js.map +0 -1
  415. package/dist/chunk-M5ZGRVIQ.js +0 -719
  416. package/dist/chunk-M5ZGRVIQ.js.map +0 -1
  417. package/dist/chunk-MRWYRAS5.js.map +0 -1
  418. package/dist/chunk-OSBYTE3O.js +0 -348
  419. package/dist/chunk-OSBYTE3O.js.map +0 -1
  420. package/dist/chunk-P3HLDT77.js +0 -59
  421. package/dist/chunk-P3HLDT77.js.map +0 -1
  422. package/dist/chunk-TEMFILR7.js +0 -143
  423. package/dist/chunk-TEMFILR7.js.map +0 -1
  424. package/dist/chunk-TXTQIYCV.js.map +0 -1
  425. package/dist/chunk-UR2GFYIE.js +0 -22598
  426. package/dist/chunk-UR2GFYIE.js.map +0 -1
  427. package/dist/chunk-WYBDERIY.js.map +0 -1
  428. package/dist/chunk-Y3KNXVTD.js.map +0 -1
  429. package/dist/chunk-YBW5JSA3.js.map +0 -1
  430. package/dist/chunk-YRXAWWCU.js +0 -45
  431. package/dist/chunk-YRXAWWCU.js.map +0 -1
  432. /package/dist/{chunk-5LYFSZ7O.js.map → chunk-352X6ENP.js.map} +0 -0
  433. /package/dist/{chunk-WBYTNVIW.js.map → chunk-RKX3NQYS.js.map} +0 -0
  434. /package/dist/{chunk-O5LEQHDM.js.map → chunk-Z7WEVGCL.js.map} +0 -0
@@ -0,0 +1,727 @@
1
+ import { defineSchema } from "./define-schema";
2
+ // Deliberately exported only from @opengeni/contracts/insights-usage. Importing
3
+ // these schemas must not pull in the root contracts index or its browser graph.
4
+ import { z } from "zod";
5
+
6
+ const SafeCount = /* @__PURE__ */ defineSchema(() =>
7
+ z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
8
+ );
9
+ const UtcDateTime = /* @__PURE__ */ defineSchema(() => z.string().datetime());
10
+ const Identifier = /* @__PURE__ */ defineSchema(() => z.string().uuid());
11
+ const OpaqueKey = /* @__PURE__ */ defineSchema(() => z.string().min(1));
12
+
13
+ export const InsightsUsageRange = /* @__PURE__ */ defineSchema(() =>
14
+ z.enum(["today", "week", "month", "30d", "90d", "ytd", "custom"]),
15
+ );
16
+ export type InsightsUsageRange = z.infer<typeof InsightsUsageRange>;
17
+
18
+ export const InsightsUsageGroupBy = /* @__PURE__ */ defineSchema(() =>
19
+ z.enum([
20
+ "model",
21
+ "provider",
22
+ "payer",
23
+ "plan",
24
+ "workspace",
25
+ "project",
26
+ "session",
27
+ "rootSession",
28
+ "person",
29
+ "schedule",
30
+ "source",
31
+ ]),
32
+ );
33
+ export type InsightsUsageGroupBy = z.infer<typeof InsightsUsageGroupBy>;
34
+
35
+ /** Recorded entry surface only; API includes SDK/embed. Missing provenance is other. */
36
+ export const InsightsUsageSource = /* @__PURE__ */ defineSchema(() =>
37
+ z.enum(["web", "api", "slack", "schedule", "agent", "other"]),
38
+ );
39
+ export type InsightsUsageSource = z.infer<typeof InsightsUsageSource>;
40
+
41
+ const UtcDay = /* @__PURE__ */ defineSchema(() =>
42
+ z
43
+ .string()
44
+ .regex(/^\d{4}-\d{2}-\d{2}$/)
45
+ .refine((value) => {
46
+ const instant = Date.parse(`${value}T00:00:00Z`);
47
+ return (
48
+ !value.startsWith("0000-") &&
49
+ Number.isFinite(instant) &&
50
+ new Date(instant).toISOString().slice(0, 10) === value
51
+ );
52
+ }, "Expected a real UTC calendar date in years 0001 through 9999 (YYYY-MM-DD)"),
53
+ );
54
+ const CustomUtcDateTime = /* @__PURE__ */ defineSchema(() =>
55
+ UtcDateTime.refine(
56
+ (value) => !value.startsWith("0000-"),
57
+ "Custom UTC boundaries must use years 0001 through 9999",
58
+ ),
59
+ );
60
+ const DAY_MS = 86_400_000;
61
+ const CUSTOM_MAX_DAYS = 370;
62
+
63
+ function customWindow(from: string, to: string) {
64
+ if (!UtcDay.safeParse(from).success || !UtcDay.safeParse(to).success) return undefined;
65
+ const start = Date.parse(`${from}T00:00:00Z`);
66
+ const end = Date.parse(`${to}T00:00:00Z`) + DAY_MS;
67
+ if (start >= end || end - start > CUSTOM_MAX_DAYS * DAY_MS) return undefined;
68
+ const priorStart = start - (end - start);
69
+ const windows = {
70
+ windowStart: new Date(start).toISOString(),
71
+ windowEnd: new Date(end).toISOString(),
72
+ priorWindowStart: new Date(priorStart).toISOString(),
73
+ priorWindowEnd: new Date(start).toISOString(),
74
+ };
75
+ // Four-digit AD years must also represent the prior and exclusive end.
76
+ // PostgreSQL has no year zero even though ISO/Zod datetime permits it.
77
+ if (!Object.values(windows).every((value) => CustomUtcDateTime.safeParse(value).success))
78
+ return undefined;
79
+ return { ...windows, bucket: end - start <= 2 * DAY_MS ? ("hour" as const) : ("day" as const) };
80
+ }
81
+
82
+ const CustomDates = /* @__PURE__ */ defineSchema(() =>
83
+ z
84
+ .object({ from: UtcDay, to: UtcDay })
85
+ .strict()
86
+ .refine(
87
+ (value) => customWindow(value.from, value.to) !== undefined,
88
+ "Custom days must be ordered, span at most 370 days and have representable current/prior windows",
89
+ ),
90
+ );
91
+
92
+ /** At most 370 inclusive UTC days; exclusive end and equally long immediate prior. */
93
+ export function resolveInsightsUsageCustomWindow(dates: { from: string; to: string }) {
94
+ const parsed = CustomDates.parse(dates);
95
+ return customWindow(parsed.from, parsed.to)!;
96
+ }
97
+
98
+ function validateWindowQuery(
99
+ value: { range: InsightsUsageRange; from?: string | undefined; to?: string | undefined },
100
+ context: z.RefinementCtx,
101
+ ) {
102
+ if (value.range === "custom") {
103
+ if (value.from === undefined || value.to === undefined) {
104
+ context.addIssue({
105
+ code: "custom",
106
+ path: [value.from === undefined ? "from" : "to"],
107
+ message: "Custom range requires both from and to",
108
+ });
109
+ } else if (customWindow(value.from, value.to) === undefined) {
110
+ context.addIssue({
111
+ code: "custom",
112
+ path: ["to"],
113
+ message:
114
+ "Custom days must be ordered, span at most 370 days and have representable current/prior windows",
115
+ });
116
+ }
117
+ } else if (value.from !== undefined || value.to !== undefined) {
118
+ context.addIssue({
119
+ code: "custom",
120
+ path: ["range"],
121
+ message: "from/to are only valid with range=custom",
122
+ });
123
+ }
124
+ }
125
+
126
+ // Literal union avoids replacing existing, structurally identical named enum
127
+ // fingerprints in the additive public-API inventory.
128
+ export const InsightsUsagePayer = /* @__PURE__ */ defineSchema(() =>
129
+ z.union([z.literal("opengeni_credits"), z.literal("subscription"), z.literal("own_key")]),
130
+ );
131
+ export type InsightsUsagePayer = z.infer<typeof InsightsUsagePayer>;
132
+
133
+ /** Split at the FIRST slash: model IDs themselves may contain slashes. */
134
+ export const InsightsUsageModelKey = /* @__PURE__ */ defineSchema(() =>
135
+ z.string().regex(/^[^/\s]+\/\S+$/),
136
+ );
137
+ export type InsightsUsageModelKey = z.infer<typeof InsightsUsageModelKey>;
138
+
139
+ function repeated<T extends z.ZodType>(item: T) {
140
+ return z
141
+ .union([z.string(), z.array(z.string()).min(1)])
142
+ .transform((value, context) => {
143
+ const entries = (Array.isArray(value) ? value : [value]).flatMap((part) =>
144
+ part.split(",").map((entry) => entry.trim()),
145
+ );
146
+ const parsed = z.array(item).min(1).safeParse(entries);
147
+ if (!parsed.success) {
148
+ for (const issue of parsed.error.issues) {
149
+ context.addIssue({ code: "custom", path: issue.path, message: issue.message });
150
+ }
151
+ return z.NEVER;
152
+ }
153
+ return parsed.data;
154
+ })
155
+ .optional();
156
+ }
157
+
158
+ function queryLimit(max: number) {
159
+ return z
160
+ .union([z.number(), z.string().regex(/^\d+$/).transform(Number)])
161
+ .pipe(SafeCount.min(1).max(max))
162
+ .default(50);
163
+ }
164
+
165
+ const QueryBoolean = /* @__PURE__ */ defineSchema(() =>
166
+ z
167
+ .union([z.boolean(), z.enum(["true", "false"])])
168
+ .transform((value) => value === true || value === "true"),
169
+ );
170
+
171
+ // Repeated, comma-separated, and mixed values: AND across fields, OR within a
172
+ // field. Empty segments are rejected, never silently widened to all records.
173
+ const Filters = {
174
+ range: InsightsUsageRange.default("week"),
175
+ from: UtcDay.optional(),
176
+ to: UtcDay.optional(),
177
+ /** At workspace scope this intersects the path workspace; it never expands scope. */
178
+ workspaceId: repeated(Identifier),
179
+ provider: repeated(OpaqueKey),
180
+ model: repeated(InsightsUsageModelKey),
181
+ payer: repeated(InsightsUsagePayer),
182
+ /** Recorded opaque plan key; missing historical snapshots use unknown, not today's plan. */
183
+ plan: repeated(OpaqueKey),
184
+ source: repeated(InsightsUsageSource),
185
+ projectId: repeated(z.union([Identifier, z.literal("unfiled")])),
186
+ /** Authorized owner/member facet key, not a hidden causal initiator. */
187
+ person: repeated(OpaqueKey),
188
+ /** Leaf session and root chat selectors are deliberately separate. */
189
+ sessionId: repeated(Identifier),
190
+ rootSessionId: repeated(Identifier),
191
+ scheduleId: repeated(Identifier),
192
+ };
193
+
194
+ export const WorkspaceInsightsUsageQuery = /* @__PURE__ */ defineSchema(() =>
195
+ z
196
+ .object({
197
+ ...Filters,
198
+ groupBy: InsightsUsageGroupBy.default("model"),
199
+ seriesGroups: QueryBoolean.optional(),
200
+ limit: queryLimit(200),
201
+ })
202
+ .strict()
203
+ .superRefine(validateWindowQuery),
204
+ );
205
+ export type WorkspaceInsightsUsageQuery = z.infer<typeof WorkspaceInsightsUsageQuery>;
206
+ export type WorkspaceInsightsUsageQueryInput = z.input<typeof WorkspaceInsightsUsageQuery>;
207
+
208
+ export const OrganizationInsightsUsageQuery = /* @__PURE__ */ defineSchema(() =>
209
+ z
210
+ .object({
211
+ ...Filters,
212
+ groupBy: InsightsUsageGroupBy.default("model"),
213
+ seriesGroups: QueryBoolean.optional(),
214
+ limit: queryLimit(200),
215
+ })
216
+ .strict()
217
+ .superRefine(validateWindowQuery),
218
+ );
219
+ export type OrganizationInsightsUsageQuery = z.infer<typeof OrganizationInsightsUsageQuery>;
220
+ export type OrganizationInsightsUsageQueryInput = z.input<typeof OrganizationInsightsUsageQuery>;
221
+
222
+ /** Organization-capable shared shape; use the workspace parser at workspace scope. */
223
+ export const InsightsUsageQuery = OrganizationInsightsUsageQuery;
224
+ export type InsightsUsageQuery = OrganizationInsightsUsageQuery;
225
+ export type InsightsUsageQueryInput = OrganizationInsightsUsageQueryInput;
226
+
227
+ export const WorkspaceInsightsCallsQuery = /* @__PURE__ */ defineSchema(() =>
228
+ z
229
+ .object({
230
+ ...Filters,
231
+ cursor: OpaqueKey.optional(),
232
+ limit: queryLimit(100),
233
+ })
234
+ .strict()
235
+ .superRefine(validateWindowQuery),
236
+ );
237
+ export type WorkspaceInsightsCallsQuery = z.infer<typeof WorkspaceInsightsCallsQuery>;
238
+ export type WorkspaceInsightsCallsQueryInput = z.input<typeof WorkspaceInsightsCallsQuery>;
239
+
240
+ export const OrganizationInsightsCallsQuery = WorkspaceInsightsCallsQuery;
241
+ export type OrganizationInsightsCallsQuery = z.infer<typeof OrganizationInsightsCallsQuery>;
242
+ export type OrganizationInsightsCallsQueryInput = z.input<typeof OrganizationInsightsCallsQuery>;
243
+ export const InsightsCallsQuery = OrganizationInsightsCallsQuery;
244
+ export type InsightsCallsQuery = OrganizationInsightsCallsQuery;
245
+ export type InsightsCallsQueryInput = OrganizationInsightsCallsQueryInput;
246
+
247
+ /** Missing historical token classes are represented by known-call counters, not guessed zeroes. */
248
+ export const InsightsUsageTokens = /* @__PURE__ */ defineSchema(() =>
249
+ z
250
+ .object({
251
+ uncachedInput: SafeCount,
252
+ cacheRead: SafeCount,
253
+ cacheWrite: SafeCount,
254
+ output: SafeCount,
255
+ reasoning: SafeCount,
256
+ })
257
+ .strict(),
258
+ );
259
+ export type InsightsUsageTokens = z.infer<typeof InsightsUsageTokens>;
260
+
261
+ /**
262
+ * List-price classes only: exact write-time snapshots or flagged historical
263
+ * allocations of each call's recorded total, never repricing that total.
264
+ * chargedMicros is the actual debit-ledger total and has no class split.
265
+ */
266
+ export const InsightsUsageClassMicros = /* @__PURE__ */ defineSchema(() =>
267
+ z
268
+ .object({
269
+ uncachedInput: SafeCount,
270
+ cacheRead: SafeCount,
271
+ cacheWrite: SafeCount,
272
+ output: SafeCount,
273
+ })
274
+ .strict(),
275
+ );
276
+ export type InsightsUsageClassMicros = z.infer<typeof InsightsUsageClassMicros>;
277
+
278
+ const PayerMeasures = /* @__PURE__ */ defineSchema(() =>
279
+ z
280
+ .object({
281
+ calls: SafeCount,
282
+ chargedMicros: SafeCount,
283
+ listMicros: SafeCount,
284
+ })
285
+ .strict(),
286
+ );
287
+
288
+ function classTotal(value: InsightsUsageClassMicros): bigint {
289
+ return (
290
+ BigInt(value.uncachedInput) +
291
+ BigInt(value.cacheRead) +
292
+ BigInt(value.cacheWrite) +
293
+ BigInt(value.output)
294
+ );
295
+ }
296
+
297
+ export const InsightsUsageMeasures = /* @__PURE__ */ defineSchema(() =>
298
+ z
299
+ .object({
300
+ calls: SafeCount,
301
+ tokenKnownCalls: SafeCount,
302
+ cacheKnownCalls: SafeCount,
303
+ cacheWriteKnownCalls: SafeCount,
304
+ /** Priced calls covered by exact snapshots OR flagged recorded-total allocations. */
305
+ listClassKnownCalls: SafeCount,
306
+ tokens: InsightsUsageTokens,
307
+ /** Actual debit ledger, not a model price that may exceed a clipped debit. */
308
+ chargedMicros: SafeCount,
309
+ listMicros: SafeCount,
310
+ listByClassMicros: InsightsUsageClassMicros.nullable(),
311
+ /** True when any covered class values allocate a historical recorded total. */
312
+ listByClassApprox: z.boolean(),
313
+ pricedCalls: SafeCount,
314
+ byPayer: z
315
+ .object({
316
+ opengeni_credits: PayerMeasures,
317
+ subscription: PayerMeasures,
318
+ own_key: PayerMeasures,
319
+ })
320
+ .strict(),
321
+ })
322
+ .strict()
323
+ .superRefine((value, context) => {
324
+ for (const field of [
325
+ "tokenKnownCalls",
326
+ "cacheKnownCalls",
327
+ "cacheWriteKnownCalls",
328
+ "pricedCalls",
329
+ ] as const) {
330
+ if (value[field] > value.calls) {
331
+ context.addIssue({
332
+ code: "custom",
333
+ path: [field],
334
+ message: "Known calls cannot exceed calls",
335
+ });
336
+ }
337
+ }
338
+ if (value.listClassKnownCalls > value.pricedCalls) {
339
+ context.addIssue({
340
+ code: "custom",
341
+ path: ["listClassKnownCalls"],
342
+ message: "Class coverage cannot exceed priced calls",
343
+ });
344
+ }
345
+ if (value.listByClassMicros !== null) {
346
+ const coveredTotal = classTotal(value.listByClassMicros);
347
+ if (
348
+ coveredTotal > BigInt(value.listMicros) ||
349
+ (value.listClassKnownCalls === value.pricedCalls &&
350
+ coveredTotal !== BigInt(value.listMicros))
351
+ ) {
352
+ context.addIssue({
353
+ code: "custom",
354
+ path: ["listByClassMicros"],
355
+ message:
356
+ "Covered classes cannot exceed the recorded total; complete coverage must preserve it exactly",
357
+ });
358
+ }
359
+ }
360
+ for (const field of ["calls", "chargedMicros", "listMicros"] as const) {
361
+ const total = Object.values(value.byPayer).reduce(
362
+ (sum, payer) => sum + BigInt(payer[field]),
363
+ 0n,
364
+ );
365
+ if (total !== BigInt(value[field])) {
366
+ context.addIssue({
367
+ code: "custom",
368
+ path: ["byPayer"],
369
+ message: `Payer ${field} must sum to the total`,
370
+ });
371
+ }
372
+ }
373
+ }),
374
+ );
375
+ export type InsightsUsageMeasures = z.infer<typeof InsightsUsageMeasures>;
376
+
377
+ export const InsightsUsageScope = /* @__PURE__ */ defineSchema(() =>
378
+ z.discriminatedUnion("kind", [
379
+ z
380
+ .object({ kind: z.literal("workspace"), accountId: Identifier, workspaceId: Identifier })
381
+ .strict(),
382
+ z
383
+ .object({ kind: z.literal("organization"), accountId: Identifier, workspaceId: z.null() })
384
+ .strict(),
385
+ ]),
386
+ );
387
+ export type InsightsUsageScope = z.infer<typeof InsightsUsageScope>;
388
+
389
+ export const InsightsUsageGroup = /* @__PURE__ */ defineSchema(() =>
390
+ z
391
+ .object({
392
+ /** Private/personal keys remain kind-scoped; named source keys are the source value. */
393
+ key: OpaqueKey,
394
+ kind: z.enum([
395
+ "item",
396
+ "other",
397
+ "deleted",
398
+ "private",
399
+ "personal",
400
+ "unfiled",
401
+ "service",
402
+ "restricted",
403
+ ]),
404
+ label: z.string(),
405
+ provider: OpaqueKey.optional(),
406
+ model: OpaqueKey.optional(),
407
+ workspaceId: Identifier.optional(),
408
+ /** Only an already-authorized people facet key; permits person-only amount selection. */
409
+ personKey: OpaqueKey.optional(),
410
+ you: z.boolean().optional(),
411
+ measures: InsightsUsageMeasures,
412
+ })
413
+ .strict(),
414
+ );
415
+ export type InsightsUsageGroup = z.infer<typeof InsightsUsageGroup>;
416
+
417
+ const SeriesGroup = /* @__PURE__ */ defineSchema(() =>
418
+ z
419
+ .object({
420
+ chargedMicros: SafeCount,
421
+ listMicros: SafeCount,
422
+ tokens: InsightsUsageTokens,
423
+ calls: SafeCount,
424
+ byPayer: InsightsUsageMeasures.shape.byPayer,
425
+ })
426
+ .strict()
427
+ .superRefine((value, context) => {
428
+ for (const field of ["calls", "chargedMicros", "listMicros"] as const) {
429
+ const total = Object.values(value.byPayer).reduce(
430
+ (sum, payer) => sum + BigInt(payer[field]),
431
+ 0n,
432
+ );
433
+ if (total !== BigInt(value[field])) {
434
+ context.addIssue({
435
+ code: "custom",
436
+ path: ["byPayer"],
437
+ message: `Payer ${field} must sum to the total`,
438
+ });
439
+ }
440
+ }
441
+ }),
442
+ );
443
+
444
+ export const InsightsUsageSeriesPoint = /* @__PURE__ */ defineSchema(() =>
445
+ z
446
+ .object({
447
+ start: UtcDateTime,
448
+ measures: InsightsUsageMeasures,
449
+ /** Top six active groups plus remainder; source uses other:folded to avoid other collisions. */
450
+ groups: z
451
+ .record(z.string(), SeriesGroup)
452
+ .refine(
453
+ (value) =>
454
+ Object.keys(value).length <= 7 &&
455
+ Object.keys(value).filter((key) => key !== "other" && key !== "other:folded").length <=
456
+ 6,
457
+ {
458
+ message: "Series may include at most six groups plus other",
459
+ },
460
+ )
461
+ .optional(),
462
+ })
463
+ .strict(),
464
+ );
465
+ export type InsightsUsageSeriesPoint = z.infer<typeof InsightsUsageSeriesPoint>;
466
+
467
+ /** Range/scope-only authorized metadata, not hidden row IDs or unconditional profile hydration. */
468
+ export const InsightsUsageFacets = /* @__PURE__ */ defineSchema(() =>
469
+ z
470
+ .object({
471
+ workspaces: z.array(
472
+ z.object({ id: Identifier, name: z.string(), personal: z.boolean() }).strict(),
473
+ ),
474
+ providers: z.array(OpaqueKey),
475
+ models: z.array(z.object({ provider: OpaqueKey, model: OpaqueKey }).strict()),
476
+ payers: z.array(OpaqueKey),
477
+ /** Recorded opaque plan keys, with unknown for absent snapshots. */
478
+ plans: z.array(OpaqueKey).default([]),
479
+ /** Capability marker: omit until source/custom support is actually implemented. */
480
+ sources: z.array(InsightsUsageSource).optional(),
481
+ projects: z.array(z.object({ id: Identifier, name: z.string() }).strict()),
482
+ people: z.array(
483
+ z.object({ key: OpaqueKey, name: z.string().nullable(), you: z.boolean() }).strict(),
484
+ ),
485
+ schedules: z.array(z.object({ id: Identifier, name: z.string() }).strict()),
486
+ })
487
+ .strict(),
488
+ );
489
+ export type InsightsUsageFacets = z.infer<typeof InsightsUsageFacets>;
490
+
491
+ export const InsightsUsageResponse = /* @__PURE__ */ defineSchema(() =>
492
+ z
493
+ .object({
494
+ scope: InsightsUsageScope,
495
+ range: InsightsUsageRange,
496
+ windowStart: UtcDateTime,
497
+ windowEnd: UtcDateTime,
498
+ priorWindowStart: UtcDateTime,
499
+ priorWindowEnd: UtcDateTime,
500
+ bucket: z.enum(["hour", "day"]),
501
+ generatedAt: UtcDateTime,
502
+ dataThrough: UtcDateTime.nullable(),
503
+ totals: InsightsUsageMeasures,
504
+ /** Null for truly empty prior windows; ledger-only money survives missing call facts. */
505
+ prior: InsightsUsageMeasures.nullable(),
506
+ groupBy: InsightsUsageGroupBy,
507
+ groups: z.array(InsightsUsageGroup),
508
+ groupCount: SafeCount,
509
+ groupsTruncated: z.boolean(),
510
+ series: z.array(InsightsUsageSeriesPoint),
511
+ facets: InsightsUsageFacets,
512
+ })
513
+ .strict()
514
+ .superRefine((value, context) => {
515
+ const windowStart = Date.parse(value.windowStart);
516
+ const windowEnd = Date.parse(value.windowEnd);
517
+ const priorWindowStart = Date.parse(value.priorWindowStart);
518
+ const priorWindowEnd = Date.parse(value.priorWindowEnd);
519
+ if (windowStart > windowEnd) {
520
+ context.addIssue({
521
+ code: "custom",
522
+ path: ["windowEnd"],
523
+ message: "Window end must not precede start",
524
+ });
525
+ }
526
+ if (priorWindowStart > priorWindowEnd) {
527
+ context.addIssue({
528
+ code: "custom",
529
+ path: ["priorWindowEnd"],
530
+ message: "Prior window end must not precede start",
531
+ });
532
+ }
533
+ // At an exact UTC range boundary, elapsed current/prior windows can be
534
+ // zero-length. Preserve that canonical window instead of inventing a future end.
535
+ if (windowStart === windowEnd) {
536
+ if (
537
+ value.totals.calls !== 0 ||
538
+ value.totals.chargedMicros !== 0 ||
539
+ value.totals.listMicros !== 0 ||
540
+ Object.values(value.totals.tokens).some((tokens) => tokens !== 0)
541
+ ) {
542
+ context.addIssue({
543
+ code: "custom",
544
+ path: ["totals"],
545
+ message: "Zero-length windows must have empty measures",
546
+ });
547
+ }
548
+ if (value.groups.length !== 0 || value.groupCount !== 0 || value.groupsTruncated) {
549
+ context.addIssue({
550
+ code: "custom",
551
+ path: ["groups"],
552
+ message: "Zero-length windows must have no groups",
553
+ });
554
+ }
555
+ if (value.series.length !== 0) {
556
+ context.addIssue({
557
+ code: "custom",
558
+ path: ["series"],
559
+ message: "Zero-length windows must have no series points",
560
+ });
561
+ }
562
+ }
563
+ if (priorWindowStart === priorWindowEnd && value.prior !== null) {
564
+ context.addIssue({
565
+ code: "custom",
566
+ path: ["prior"],
567
+ message: "Zero-length prior windows must have null measures",
568
+ });
569
+ }
570
+ const expectedBucket =
571
+ value.range === "custom"
572
+ ? windowEnd - windowStart <= 2 * DAY_MS
573
+ ? "hour"
574
+ : "day"
575
+ : value.range === "today"
576
+ ? "hour"
577
+ : "day";
578
+ if (value.bucket !== expectedBucket) {
579
+ context.addIssue({
580
+ code: "custom",
581
+ path: ["bucket"],
582
+ message: "Bucket is automatic for the range",
583
+ });
584
+ }
585
+ // Model-call facts can soft-fail after money is recorded. Preserve those
586
+ // amounts without inventing calls or known token/class coverage.
587
+ if (
588
+ value.prior?.calls === 0 &&
589
+ value.prior.chargedMicros === 0 &&
590
+ value.prior.listMicros === 0
591
+ ) {
592
+ context.addIssue({
593
+ code: "custom",
594
+ path: ["prior"],
595
+ message: "Prior without recorded calls or money must be null",
596
+ });
597
+ }
598
+ if (value.range === "custom") {
599
+ for (const field of [
600
+ "windowStart",
601
+ "windowEnd",
602
+ "priorWindowStart",
603
+ "priorWindowEnd",
604
+ ] as const) {
605
+ if (!CustomUtcDateTime.safeParse(value[field]).success) {
606
+ context.addIssue({
607
+ code: "custom",
608
+ path: [field],
609
+ message: "Custom UTC boundaries must use years 0001 through 9999",
610
+ });
611
+ }
612
+ }
613
+ if (
614
+ windowStart === windowEnd ||
615
+ windowEnd - windowStart > CUSTOM_MAX_DAYS * DAY_MS ||
616
+ windowStart % DAY_MS !== 0 ||
617
+ windowEnd % DAY_MS !== 0 ||
618
+ priorWindowStart !== windowStart - (windowEnd - windowStart) ||
619
+ priorWindowEnd !== windowStart
620
+ ) {
621
+ context.addIssue({
622
+ code: "custom",
623
+ path: ["windowEnd"],
624
+ message:
625
+ "Custom windows must span at most 370 complete UTC days with an immediate equal-duration prior",
626
+ });
627
+ }
628
+ }
629
+ if (value.groupBy === "source") {
630
+ for (const [index, group] of value.groups.entries()) {
631
+ if (group.kind === "item" && !InsightsUsageSource.safeParse(group.key).success) {
632
+ context.addIssue({
633
+ code: "custom",
634
+ path: ["groups", index, "key"],
635
+ message: "Named source keys must equal their source value",
636
+ });
637
+ }
638
+ if (group.kind === "other" && group.key !== "other:folded") {
639
+ context.addIssue({
640
+ code: "custom",
641
+ path: ["groups", index, "key"],
642
+ message: "Source remainder must use other:folded, distinct from the other source",
643
+ });
644
+ }
645
+ }
646
+ for (const [index, point] of value.series.entries()) {
647
+ if (
648
+ point.groups &&
649
+ Object.keys(point.groups).filter((key) => key !== "other:folded").length > 6
650
+ ) {
651
+ context.addIssue({
652
+ code: "custom",
653
+ path: ["series", index, "groups"],
654
+ message: "Source series permits six named groups plus other:folded",
655
+ });
656
+ }
657
+ }
658
+ }
659
+ const peopleKeys = new Set(value.facets.people.map((person) => person.key));
660
+ for (const [index, group] of value.groups.entries()) {
661
+ if (group.personKey !== undefined && !peopleKeys.has(group.personKey)) {
662
+ context.addIssue({
663
+ code: "custom",
664
+ path: ["groups", index, "personKey"],
665
+ message: "Person amount keys must come from the authorized people facets",
666
+ });
667
+ }
668
+ }
669
+ }),
670
+ );
671
+ export type InsightsUsageResponse = z.infer<typeof InsightsUsageResponse>;
672
+
673
+ /** Backend must omit unreadable calls entirely; this schema grants no access. */
674
+ export const InsightsCall = /* @__PURE__ */ defineSchema(() =>
675
+ z
676
+ .object({
677
+ id: Identifier,
678
+ occurredAt: UtcDateTime,
679
+ workspaceId: Identifier,
680
+ sessionId: Identifier.nullable(),
681
+ sessionTitle: z.string().nullable(),
682
+ sessionKind: z.enum(["visible", "private", "deleted"]),
683
+ personKey: OpaqueKey.nullable(),
684
+ provider: OpaqueKey,
685
+ model: OpaqueKey,
686
+ payer: InsightsUsagePayer,
687
+ tokens: InsightsUsageTokens.nullable(),
688
+ chargedMicros: SafeCount,
689
+ listMicros: SafeCount.nullable(),
690
+ listByClassMicros: InsightsUsageClassMicros.nullable(),
691
+ })
692
+ .strict()
693
+ .superRefine((value, context) => {
694
+ if (
695
+ value.sessionKind === "private" &&
696
+ (value.sessionId !== null || value.sessionTitle !== null)
697
+ ) {
698
+ context.addIssue({
699
+ code: "custom",
700
+ path: ["sessionKind"],
701
+ message: "Private calls expose no session id or title",
702
+ });
703
+ }
704
+ if (
705
+ value.listByClassMicros !== null &&
706
+ (value.listMicros === null ||
707
+ classTotal(value.listByClassMicros) !== BigInt(value.listMicros))
708
+ ) {
709
+ context.addIssue({
710
+ code: "custom",
711
+ path: ["listByClassMicros"],
712
+ message: "Call list classes must sum to its recorded listMicros",
713
+ });
714
+ }
715
+ }),
716
+ );
717
+ export type InsightsCall = z.infer<typeof InsightsCall>;
718
+
719
+ export const InsightsCallsResponse = /* @__PURE__ */ defineSchema(() =>
720
+ z
721
+ .object({
722
+ calls: z.array(InsightsCall).max(100),
723
+ nextCursor: OpaqueKey.nullable(),
724
+ })
725
+ .strict(),
726
+ );
727
+ export type InsightsCallsResponse = z.infer<typeof InsightsCallsResponse>;