@opengeni/api-router 0.30.1 → 1.0.0

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 (436) hide show
  1. package/dist/access-grant-rls.d.ts +3 -0
  2. package/dist/admission-trace.d.ts +8 -0
  3. package/dist/api-websocket.d.ts +18 -0
  4. package/dist/app.d.ts +50 -2
  5. package/dist/app.js +12 -1
  6. package/dist/artifact-catalog-cursor.d.ts +27 -0
  7. package/dist/auth/managed-auth-attempt-context.d.ts +10 -0
  8. package/dist/auth/managed-auth-rate-limits.d.ts +167 -0
  9. package/dist/auth/managed-auth-session-adapter.d.ts +6 -0
  10. package/dist/auth/managed-auth.d.ts +102 -3
  11. package/dist/auth/managed-email.d.ts +29 -0
  12. package/dist/auth/managed-sign-in-notifications.d.ts +4 -0
  13. package/dist/auth/new-signups-gate.d.ts +23 -0
  14. package/dist/auth/organization-user-setup.d.ts +80 -0
  15. package/dist/auth/signup-funnel-metrics.d.ts +44 -0
  16. package/dist/browser-controller-authority.d.ts +1 -61
  17. package/dist/browser-ephemeral.d.ts +5 -0
  18. package/dist/browser-state-authority.d.ts +1 -27
  19. package/dist/chunk-6TZ5LG3O.js +123948 -0
  20. package/dist/chunk-6TZ5LG3O.js.map +1 -0
  21. package/dist/chunk-OGQDXVXY.js +18 -0
  22. package/dist/chunk-OGQDXVXY.js.map +1 -0
  23. package/dist/claude-subscription-account-conflicts.d.ts +1 -0
  24. package/dist/claude-subscription-account-usage.d.ts +39 -0
  25. package/dist/claude-subscription-oauth.d.ts +25 -0
  26. package/dist/claude-subscription-profile.d.ts +9 -0
  27. package/dist/claude-subscription-usage.d.ts +44 -0
  28. package/dist/claude-workspace-connection.d.ts +15 -0
  29. package/dist/codemode.d.ts +32 -1
  30. package/dist/company-brain-okf.d.ts +24 -0
  31. package/dist/connected-machine-computer-access.d.ts +11 -0
  32. package/dist/connection-ownership.d.ts +54 -0
  33. package/dist/controller-data-plane.d.ts +32 -0
  34. package/dist/editable-artifact-office-import.d.ts +7 -4
  35. package/dist/editable-artifact-source-session.d.ts +3 -0
  36. package/dist/editable-artifact-websocket.d.ts +10 -18
  37. package/dist/editable-artifact-workspace-files.d.ts +1 -1
  38. package/dist/fatal-process-boundary.d.ts +25 -0
  39. package/dist/github-access.d.ts +31 -2
  40. package/dist/http/acting-person.d.ts +24 -0
  41. package/dist/http/api-contract-compat.d.ts +19 -0
  42. package/dist/http/api-error.d.ts +27 -1
  43. package/dist/http/cors.d.ts +17 -0
  44. package/dist/http/deprecation.d.ts +42 -0
  45. package/dist/http/interaction-control-error.d.ts +13 -0
  46. package/dist/http/keyed-admission.d.ts +12 -0
  47. package/dist/http/local-browser-boundary.d.ts +72 -0
  48. package/dist/http/metrics-listener.d.ts +22 -0
  49. package/dist/http/path-identifier.d.ts +17 -0
  50. package/dist/http/registered-route-label.d.ts +16 -0
  51. package/dist/http/request-body.d.ts +27 -0
  52. package/dist/http/request-source.d.ts +52 -0
  53. package/dist/http/sse.d.ts +17 -6
  54. package/dist/http/unmatched-route.d.ts +18 -0
  55. package/dist/http/user-content.d.ts +36 -0
  56. package/dist/http/websocket-upgrade-dispatch.d.ts +18 -0
  57. package/dist/index.d.ts +10 -3
  58. package/dist/index.js +1129 -166
  59. package/dist/index.js.map +1 -1
  60. package/dist/integration-endpoint-test.d.ts +20 -0
  61. package/dist/integrations/api-integrations.d.ts +2 -2
  62. package/dist/integrations/atlassian.d.ts +29 -3
  63. package/dist/integrations/connect-authority.d.ts +1 -0
  64. package/dist/integrations/connect-callback-return.d.ts +6 -0
  65. package/dist/integrations/fiken.d.ts +16 -2
  66. package/dist/integrations/github-app-connect.d.ts +47 -0
  67. package/dist/integrations/github-installation-proof.d.ts +3 -0
  68. package/dist/integrations/github-lens-connect.d.ts +116 -0
  69. package/dist/integrations/github-skill-source.d.ts +1 -5
  70. package/dist/integrations/google-drive.d.ts +25 -0
  71. package/dist/integrations/integration-commit-authority.d.ts +13 -0
  72. package/dist/integrations/marketplace-plugin.d.ts +2691 -0
  73. package/dist/integrations/oauth-client.d.ts +178 -18
  74. package/dist/integrations/oauth-profiles.d.ts +222 -0
  75. package/dist/integrations/oauth-return-path.d.ts +1 -0
  76. package/dist/integrations/personal-github-repositories.d.ts +84 -0
  77. package/dist/integrations/personal-github.d.ts +42 -0
  78. package/dist/integrations/pr-review-provider.d.ts +22 -0
  79. package/dist/integrations/provider-oauth.d.ts +19 -1
  80. package/dist/integrations/slack-app-home.d.ts +24 -0
  81. package/dist/integrations/slack-bot.d.ts +367 -12
  82. package/dist/integrations/slack-file-upload-flow.d.ts +62 -0
  83. package/dist/integrations/slack-install.d.ts +20 -0
  84. package/dist/integrations/slack-interactions.d.ts +113 -10
  85. package/dist/integrations/slack-mrkdwn.d.ts +41 -0
  86. package/dist/integrations/slack-routing.d.ts +120 -0
  87. package/dist/integrations/slack-session-defaults.d.ts +58 -0
  88. package/dist/integrations/slack-task-file-upload.d.ts +36 -0
  89. package/dist/integrations/social-oauth.d.ts +7 -0
  90. package/dist/interaction-agent-access.d.ts +15 -0
  91. package/dist/interaction-frame-proxy.d.ts +68 -0
  92. package/dist/interaction-metrics.d.ts +2 -0
  93. package/dist/mcp/action-catalog-types.d.ts +9 -0
  94. package/dist/mcp/action-catalog.gen.d.ts +2 -0
  95. package/dist/mcp/capability-account-readiness.d.ts +7 -0
  96. package/dist/mcp/child-read-evidence.d.ts +9 -0
  97. package/dist/mcp/command-read.d.ts +24 -0
  98. package/dist/mcp/company-profile-agent-admin.d.ts +44 -0
  99. package/dist/mcp/contract-input.d.ts +11 -0
  100. package/dist/mcp/documents.d.ts +7 -5
  101. package/dist/mcp/files.d.ts +2 -2
  102. package/dist/mcp/first-party-tool-permissions.d.ts +650 -0
  103. package/dist/mcp/knowledge-entries.d.ts +5 -0
  104. package/dist/mcp/orchestration-failure-diagnostic.d.ts +43 -0
  105. package/dist/mcp/receipts.d.ts +9 -0
  106. package/dist/mcp/request-abort.d.ts +19 -0
  107. package/dist/mcp/scheduled-task-input.d.ts +1189 -0
  108. package/dist/mcp/scheduled-task-view.d.ts +22 -4
  109. package/dist/mcp/server.d.ts +255 -3
  110. package/dist/mcp/session-event-view.d.ts +94 -0
  111. package/dist/mcp/session-view.d.ts +66 -2
  112. package/dist/mcp/session-wait.d.ts +174 -0
  113. package/dist/mcp-oauth.d.ts +52 -0
  114. package/dist/model-catalog.d.ts +11 -31
  115. package/dist/observability.d.ts +3 -1
  116. package/dist/organization-mcp.d.ts +52 -0
  117. package/dist/organization-recovery-notifications.d.ts +41 -0
  118. package/dist/routes/analytics-consent.d.ts +26 -0
  119. package/dist/routes/api-integrations.d.ts +25 -0
  120. package/dist/routes/api-keys.d.ts +17 -0
  121. package/dist/routes/artifact-catalog.d.ts +6 -0
  122. package/dist/routes/automations.d.ts +19 -0
  123. package/dist/routes/billing.d.ts +49 -0
  124. package/dist/routes/browser-sessions.d.ts +71 -3
  125. package/dist/routes/claude-subscription-accounts.d.ts +3 -0
  126. package/dist/routes/claude-subscription-oauth.d.ts +3 -0
  127. package/dist/routes/client-errors.d.ts +146 -0
  128. package/dist/routes/codex.d.ts +76 -2
  129. package/dist/routes/company-brain.d.ts +3 -0
  130. package/dist/routes/company-profile.d.ts +2 -1
  131. package/dist/routes/computer-sessions.d.ts +14 -0
  132. package/dist/routes/connect.d.ts +5 -0
  133. package/dist/routes/editable-artifacts.d.ts +2 -0
  134. package/dist/routes/external-identity-links.d.ts +6 -0
  135. package/dist/routes/feedback.d.ts +3 -0
  136. package/dist/routes/files.d.ts +4 -0
  137. package/dist/routes/github-browser-pages.d.ts +12 -0
  138. package/dist/routes/github.d.ts +2 -0
  139. package/dist/routes/insights-response-cache.d.ts +10 -0
  140. package/dist/routes/insights-usage.d.ts +12 -0
  141. package/dist/routes/insights.d.ts +30 -1
  142. package/dist/routes/knowledge.d.ts +3 -0
  143. package/dist/routes/managed-auth-session-sets.d.ts +26 -0
  144. package/dist/routes/managed-onboarding.d.ts +29 -0
  145. package/dist/routes/managed-sign-in-methods.d.ts +6 -0
  146. package/dist/routes/model-connection-access.d.ts +3 -0
  147. package/dist/routes/organization-integration-policy.d.ts +3 -0
  148. package/dist/routes/organization-integrations.d.ts +6 -0
  149. package/dist/routes/organization-mcp-connections.d.ts +3 -0
  150. package/dist/routes/organization-model-providers.d.ts +3 -0
  151. package/dist/routes/organization-recovery.d.ts +19 -0
  152. package/dist/routes/organization-service-accounts.d.ts +3 -0
  153. package/dist/routes/organization-sessions.d.ts +26 -0
  154. package/dist/routes/personal-github-git-broker.d.ts +29 -0
  155. package/dist/routes/personal-github.d.ts +3 -0
  156. package/dist/routes/pr-review-github.d.ts +3 -0
  157. package/dist/routes/pr-review.d.ts +3 -0
  158. package/dist/routes/session-artifact-associations.d.ts +4 -0
  159. package/dist/routes/session-history-imports.d.ts +9 -0
  160. package/dist/routes/sessions.d.ts +44 -6
  161. package/dist/routes/skill-content.d.ts +4 -0
  162. package/dist/routes/skill-install-authority.d.ts +6 -0
  163. package/dist/routes/subscription-account-pools.d.ts +34 -0
  164. package/dist/routes/subscription-pool-access.d.ts +16 -0
  165. package/dist/routes/supergrok.d.ts +6 -1
  166. package/dist/routes/usage-allowances.d.ts +12 -0
  167. package/dist/routes/user-resource-authorities.d.ts +3 -0
  168. package/dist/routes/workspace-artifacts.d.ts +2 -1
  169. package/dist/routes/workspace-capture.d.ts +10 -2
  170. package/dist/routes/workspace-integrations.d.ts +35 -0
  171. package/dist/routes/workspace-learning.d.ts +3 -0
  172. package/dist/routes/workspace-model-providers.d.ts +4 -0
  173. package/dist/routes/workspaces.d.ts +29 -0
  174. package/dist/sandbox/auth-callout.d.ts +8 -0
  175. package/dist/sandbox/channel-a.d.ts +19 -1
  176. package/dist/sandbox/connection-authority.d.ts +3 -0
  177. package/dist/sandbox/enrollment.d.ts +9 -1
  178. package/dist/sandbox/machines.d.ts +5 -2
  179. package/dist/sandbox/metrics-ingestion.d.ts +28 -20
  180. package/dist/sandbox/rematerialize.d.ts +2 -0
  181. package/dist/sandbox/session-attach-variable-sets.d.ts +30 -0
  182. package/dist/sandbox/viewer.d.ts +26 -1
  183. package/dist/sandbox-file-artifacts.d.ts +50 -0
  184. package/dist/scheduled-task-deletion.d.ts +13 -0
  185. package/dist/session-create-observability.d.ts +5 -0
  186. package/dist/session-event-view-MPS2OZD3.js +292 -0
  187. package/dist/session-event-view-MPS2OZD3.js.map +1 -0
  188. package/dist/site-session-origin.d.ts +13 -0
  189. package/dist/site-uploads.d.ts +41 -0
  190. package/dist/slack-reaction-files.d.ts +1 -1
  191. package/dist/temporal-schedule-cleanup.d.ts +1 -0
  192. package/dist/temporal-schedule-sync.d.ts +26 -0
  193. package/dist/transcription/providers/xai-subscription.d.ts +1 -0
  194. package/dist/transcription/service.d.ts +2 -1
  195. package/dist/work-discovery-observability.d.ts +33 -0
  196. package/dist/workspace-artifact-content.d.ts +28 -0
  197. package/dist/workspace-artifact-provenance.d.ts +7 -0
  198. package/dist/workspace-delete-observability.d.ts +10 -0
  199. package/dist/workspace-deletion.d.ts +6 -0
  200. package/dist/workspace-state-projection.d.ts +3 -5
  201. package/dist/workspace-tool-gateway-observability.d.ts +17 -0
  202. package/dist/workspace-tool-gateway.d.ts +123 -0
  203. package/dist/workspace-webhook-dispatch.d.ts +26 -0
  204. package/package.json +23 -19
  205. package/src/access-grant-rls.ts +75 -0
  206. package/src/admission-trace.ts +14 -0
  207. package/src/api-websocket.ts +23 -0
  208. package/src/app.ts +1974 -256
  209. package/src/artifact-catalog-cursor.ts +60 -0
  210. package/src/auth/managed-auth-attempt-context.ts +70 -0
  211. package/src/auth/managed-auth-rate-limits.ts +252 -0
  212. package/src/auth/managed-auth-session-adapter.ts +222 -0
  213. package/src/auth/managed-auth.ts +536 -60
  214. package/src/auth/managed-email.ts +174 -0
  215. package/src/auth/managed-sign-in-notifications.ts +81 -0
  216. package/src/auth/new-signups-gate.ts +49 -0
  217. package/src/auth/organization-user-setup.ts +307 -0
  218. package/src/auth/signup-funnel-metrics.ts +164 -0
  219. package/src/browser-controller-authority.ts +1 -186
  220. package/src/browser-ephemeral.ts +39 -0
  221. package/src/browser-state-authority.ts +1 -236
  222. package/src/claude-subscription-account-conflicts.ts +12 -0
  223. package/src/claude-subscription-account-usage.ts +48 -0
  224. package/src/claude-subscription-oauth.ts +362 -0
  225. package/src/claude-subscription-profile.ts +73 -0
  226. package/src/claude-subscription-usage.ts +97 -0
  227. package/src/claude-workspace-connection.ts +82 -0
  228. package/src/codemode.ts +194 -30
  229. package/src/codex-realtime.ts +8 -2
  230. package/src/company-brain-okf.ts +340 -0
  231. package/src/connected-machine-computer-access.ts +33 -0
  232. package/src/connection-ownership.ts +199 -0
  233. package/src/controller-data-plane.ts +81 -0
  234. package/src/editable-artifact-native-kernel.ts +26 -15
  235. package/src/editable-artifact-office-import.ts +77 -9
  236. package/src/editable-artifact-production.ts +23 -7
  237. package/src/editable-artifact-source-session.ts +123 -0
  238. package/src/editable-artifact-websocket.ts +27 -21
  239. package/src/editable-artifact-workspace-files.ts +31 -6
  240. package/src/fatal-process-boundary.ts +246 -0
  241. package/src/gateway-realtime.ts +1 -1
  242. package/src/github-access.ts +147 -5
  243. package/src/http/acting-person.ts +71 -0
  244. package/src/http/api-contract-compat.ts +49 -0
  245. package/src/http/api-error.ts +115 -1
  246. package/src/http/auth.ts +48 -0
  247. package/src/http/cors.ts +67 -0
  248. package/src/http/deprecation.ts +118 -0
  249. package/src/http/interaction-control-error.ts +164 -0
  250. package/src/http/keyed-admission.ts +29 -0
  251. package/src/http/local-browser-boundary.ts +343 -0
  252. package/src/http/metrics-listener.ts +57 -0
  253. package/src/http/path-identifier.ts +54 -0
  254. package/src/http/registered-route-label.ts +34 -0
  255. package/src/http/request-body.ts +127 -0
  256. package/src/http/request-source.ts +178 -0
  257. package/src/http/sse.ts +486 -132
  258. package/src/http/unmatched-route.ts +60 -0
  259. package/src/http/user-content.ts +158 -0
  260. package/src/http/websocket-upgrade-dispatch.ts +29 -0
  261. package/src/index.ts +157 -52
  262. package/src/integration-endpoint-test.ts +291 -0
  263. package/src/integrations/api-integrations.ts +98 -11
  264. package/src/integrations/atlassian.ts +474 -136
  265. package/src/integrations/connect-authority.ts +2 -0
  266. package/src/integrations/connect-callback-return.ts +86 -0
  267. package/src/integrations/fiken.ts +354 -64
  268. package/src/integrations/github-app-connect.ts +435 -0
  269. package/src/integrations/github-installation-proof.ts +60 -0
  270. package/src/integrations/github-lens-connect.ts +76 -0
  271. package/src/integrations/github-skill-source.ts +2 -142
  272. package/src/integrations/google-drive.ts +820 -222
  273. package/src/integrations/integration-commit-authority.ts +69 -0
  274. package/src/integrations/marketplace-plugin.ts +48 -0
  275. package/src/integrations/oauth-client.ts +1356 -459
  276. package/src/integrations/oauth-profiles.ts +537 -0
  277. package/src/integrations/oauth-return-path.ts +18 -0
  278. package/src/integrations/personal-github-repositories.ts +674 -0
  279. package/src/integrations/personal-github.ts +825 -0
  280. package/src/integrations/pr-review-provider.ts +246 -0
  281. package/src/integrations/provider-oauth.ts +250 -22
  282. package/src/integrations/slack-app-home.ts +300 -0
  283. package/src/integrations/slack-bot.ts +963 -239
  284. package/src/integrations/slack-file-upload-flow.ts +147 -0
  285. package/src/integrations/slack-install.ts +83 -0
  286. package/src/integrations/slack-interactions.ts +3170 -474
  287. package/src/integrations/slack-mrkdwn.ts +193 -0
  288. package/src/integrations/slack-routing.ts +337 -0
  289. package/src/integrations/slack-session-defaults.ts +224 -0
  290. package/src/integrations/slack-task-file-upload.ts +323 -0
  291. package/src/integrations/social-oauth.ts +213 -15
  292. package/src/interaction-agent-access.ts +48 -0
  293. package/src/interaction-frame-proxy.ts +409 -0
  294. package/src/interaction-metrics.ts +30 -0
  295. package/src/mcp/action-catalog-types.ts +9 -0
  296. package/src/mcp/action-catalog.gen.ts +6696 -0
  297. package/src/mcp/capability-account-readiness.ts +17 -0
  298. package/src/mcp/child-read-evidence.ts +19 -0
  299. package/src/mcp/command-read.ts +109 -0
  300. package/src/mcp/company-profile-agent-admin.ts +198 -0
  301. package/src/mcp/contract-input.ts +141 -0
  302. package/src/mcp/documents.ts +65 -377
  303. package/src/mcp/editable-artifacts.ts +12 -6
  304. package/src/mcp/files.ts +80 -38
  305. package/src/mcp/first-party-tool-permissions.ts +305 -0
  306. package/src/mcp/knowledge-entries.ts +322 -0
  307. package/src/mcp/orchestration-failure-diagnostic.ts +43 -0
  308. package/src/mcp/receipts.ts +34 -0
  309. package/src/mcp/request-abort.ts +44 -0
  310. package/src/mcp/scheduled-task-input.ts +76 -0
  311. package/src/mcp/scheduled-task-view.ts +44 -3
  312. package/src/mcp/server.ts +3030 -1267
  313. package/src/mcp/session-event-view.ts +383 -0
  314. package/src/mcp/session-view.ts +84 -3
  315. package/src/mcp/session-wait.ts +665 -0
  316. package/src/mcp-oauth.ts +1123 -0
  317. package/src/model-catalog.ts +91 -333
  318. package/src/observability.ts +15 -1
  319. package/src/organization-mcp.ts +397 -0
  320. package/src/organization-recovery-notifications.ts +103 -0
  321. package/src/routes/analytics-consent.ts +123 -0
  322. package/src/routes/api-integrations.ts +364 -74
  323. package/src/routes/api-keys.ts +336 -10
  324. package/src/routes/artifact-catalog.ts +279 -0
  325. package/src/routes/automations.ts +768 -0
  326. package/src/routes/billing.ts +461 -46
  327. package/src/routes/browser-sessions.ts +839 -131
  328. package/src/routes/canonical-human-identities.ts +90 -14
  329. package/src/routes/capabilities.ts +107 -6
  330. package/src/routes/channels.ts +20 -3
  331. package/src/routes/claude-subscription-accounts.ts +334 -0
  332. package/src/routes/claude-subscription-oauth.ts +142 -0
  333. package/src/routes/client-errors.ts +362 -0
  334. package/src/routes/codex.ts +833 -116
  335. package/src/routes/company-brain.ts +322 -0
  336. package/src/routes/company-profile.ts +65 -1
  337. package/src/routes/computer-sessions.ts +557 -106
  338. package/src/routes/connect.ts +1938 -0
  339. package/src/routes/connections.ts +1040 -349
  340. package/src/routes/documents.ts +488 -287
  341. package/src/routes/editable-artifacts.ts +79 -9
  342. package/src/routes/enrollments.ts +135 -39
  343. package/src/routes/environments.ts +154 -58
  344. package/src/routes/external-identity-links.ts +201 -0
  345. package/src/routes/feedback.ts +113 -0
  346. package/src/routes/files.ts +337 -39
  347. package/src/routes/github-browser-pages.ts +162 -0
  348. package/src/routes/github.ts +446 -144
  349. package/src/routes/insights-response-cache.ts +83 -0
  350. package/src/routes/insights-usage.ts +345 -0
  351. package/src/routes/insights.ts +153 -19
  352. package/src/routes/install.ts +133 -38
  353. package/src/routes/integration-facets.ts +107 -33
  354. package/src/routes/interaction-resources.ts +30 -3
  355. package/src/routes/knowledge.ts +488 -0
  356. package/src/routes/machines.ts +313 -15
  357. package/src/routes/managed-auth-session-sets.ts +1218 -0
  358. package/src/routes/managed-onboarding.ts +337 -0
  359. package/src/routes/managed-sign-in-methods.ts +433 -0
  360. package/src/routes/memory-slack-publications.ts +3 -2
  361. package/src/routes/model-connection-access.ts +208 -0
  362. package/src/routes/organization-integration-policy.ts +116 -0
  363. package/src/routes/organization-integrations.ts +326 -0
  364. package/src/routes/organization-mcp-connections.ts +178 -0
  365. package/src/routes/organization-memberships.ts +1019 -27
  366. package/src/routes/organization-model-providers.ts +293 -0
  367. package/src/routes/organization-recovery.ts +325 -0
  368. package/src/routes/organization-service-accounts.ts +128 -0
  369. package/src/routes/organization-sessions.ts +350 -0
  370. package/src/routes/personal-github-git-broker.ts +785 -0
  371. package/src/routes/personal-github.ts +370 -0
  372. package/src/routes/plugins.ts +251 -22
  373. package/src/routes/pr-review-github.ts +881 -0
  374. package/src/routes/pr-review.ts +622 -0
  375. package/src/routes/preference-registry.ts +12 -93
  376. package/src/routes/rigs.ts +167 -50
  377. package/src/routes/scheduled-tasks.ts +346 -41
  378. package/src/routes/session-artifact-associations.ts +87 -0
  379. package/src/routes/session-history-imports.ts +280 -0
  380. package/src/routes/sessions.ts +2306 -264
  381. package/src/routes/skill-content.ts +297 -0
  382. package/src/routes/skill-install-authority.ts +64 -0
  383. package/src/routes/skills.ts +62 -9
  384. package/src/routes/social.ts +46 -18
  385. package/src/routes/subscription-account-pools.ts +436 -0
  386. package/src/routes/subscription-pool-access.ts +126 -0
  387. package/src/routes/supergrok.ts +219 -303
  388. package/src/routes/transcription-recordings.ts +38 -3
  389. package/src/routes/transcriptions.ts +4 -0
  390. package/src/routes/usage-allowances.ts +378 -0
  391. package/src/routes/user-resource-authorities.ts +138 -0
  392. package/src/routes/video-generation.ts +14 -10
  393. package/src/routes/workspace-artifacts.ts +275 -69
  394. package/src/routes/workspace-capture.ts +21 -0
  395. package/src/routes/workspace-integrations.ts +576 -0
  396. package/src/routes/workspace-learning.ts +159 -0
  397. package/src/routes/workspace-model-providers.ts +148 -0
  398. package/src/routes/workspace-state.ts +38 -25
  399. package/src/routes/workspaces.ts +1004 -127
  400. package/src/sandbox/auth-callout.ts +96 -19
  401. package/src/sandbox/channel-a.ts +323 -24
  402. package/src/sandbox/connection-authority.ts +3 -0
  403. package/src/sandbox/enrollment.ts +81 -6
  404. package/src/sandbox/machines.ts +218 -76
  405. package/src/sandbox/metrics-ingestion.ts +411 -62
  406. package/src/sandbox/rematerialize.ts +121 -19
  407. package/src/sandbox/session-attach-variable-sets.ts +131 -0
  408. package/src/sandbox/viewer.ts +280 -25
  409. package/src/sandbox-file-artifacts.ts +413 -0
  410. package/src/scheduled-task-deletion.ts +138 -0
  411. package/src/session-create-observability.ts +46 -0
  412. package/src/session-realtime-context.ts +6 -3
  413. package/src/site-session-origin.ts +48 -0
  414. package/src/site-uploads.ts +224 -0
  415. package/src/slack-reaction-files.ts +16 -5
  416. package/src/temporal-schedule-cleanup.ts +13 -0
  417. package/src/temporal-schedule-sync.ts +74 -0
  418. package/src/transcription/providers/codex-subscription.ts +2 -0
  419. package/src/transcription/providers/openai.ts +1 -0
  420. package/src/transcription/providers/xai-subscription.ts +49 -3
  421. package/src/transcription/segmenter.ts +8 -2
  422. package/src/transcription/service.ts +43 -6
  423. package/src/work-discovery-observability.ts +121 -0
  424. package/src/workspace-artifact-content.ts +144 -0
  425. package/src/workspace-artifact-provenance.ts +104 -0
  426. package/src/workspace-delete-observability.ts +75 -0
  427. package/src/workspace-deletion.ts +73 -0
  428. package/src/workspace-state-projection.ts +18 -148
  429. package/src/workspace-tool-gateway-observability.ts +100 -0
  430. package/src/workspace-tool-gateway.ts +870 -0
  431. package/src/workspace-webhook-dispatch.ts +190 -0
  432. package/src/xai-subscription-auth.ts +9 -2
  433. package/dist/chunk-2PQMSRCB.js +0 -49759
  434. package/dist/chunk-2PQMSRCB.js.map +0 -1
  435. package/dist/routes/packs.d.ts +0 -3
  436. package/src/routes/packs.ts +0 -729
@@ -2,6 +2,7 @@ import type { Settings } from "@opengeni/config";
2
2
  import { type Session } from "@opengeni/contracts";
3
3
  import { type Database, type LeaseSnapshot, type SandboxRecord } from "@opengeni/db";
4
4
  import { type EventBus } from "@opengeni/events";
5
+ import type { ObjectStorage } from "@opengeni/storage";
5
6
  import { establishSandboxSessionFromEnvelope, type EstablishedSandboxSession } from "@opengeni/runtime/sandbox";
6
7
  /** The minimal services a viewer op needs: the DB + settings (lease cadence +
7
8
  * the sandbox client construction the leaf reads from settings). The bus is
@@ -11,6 +12,7 @@ export type ViewerServices = {
11
12
  db: Database;
12
13
  settings: Settings;
13
14
  bus?: EventBus;
15
+ objectStorage?: ObjectStorage | null;
14
16
  /** Provider-establish dependency used by API-direct readiness and stream
15
17
  * operations. Production uses the runtime leaf; isolated tests may supply a
16
18
  * deterministic provider without replacing a process-global module. */
@@ -51,7 +53,10 @@ export type ViewerAttachResult = {
51
53
  * cannot change manifest environment variables" whenever a viewer attach (an open
52
54
  * session page) won the cold-create race against the first turn.
53
55
  */
54
- export declare function sessionAttachEnvironment(services: ViewerServices, workspaceId: string, session: Session): Promise<Record<string, string>>;
56
+ export declare function sessionAttachEnvironment(services: ViewerServices, workspaceId: string, session: Session,
57
+ /** The authenticated route subject driving this attach (0282); recorded on
58
+ * the materialization audit fact. Null records the legacy service sentinel. */
59
+ attachSubjectId: string | null): Promise<Record<string, string>>;
55
60
  /**
56
61
  * Acquire a `viewer` holder on the group lease, spinning up the box IN-PROCESS
57
62
  * when cold. Mirrors the worker's resumeBoxForTurn spawner/attached branches,
@@ -65,6 +70,9 @@ export declare function attachViewer(services: ViewerServices, input: {
65
70
  workspaceId: string;
66
71
  session: Session;
67
72
  viewerId?: string;
73
+ /** The authenticated subject attaching this viewer (0281): recorded on
74
+ * the holder row together with the live session authority epoch. */
75
+ viewerSubjectId?: string;
68
76
  /** Cancel lifecycle waiting when the originating HTTP request disconnects. */
69
77
  waitSignal?: AbortSignal;
70
78
  }): Promise<ViewerAttachResult>;
@@ -84,6 +92,10 @@ export declare function ensureSessionGroupReady(services: ViewerServices, input:
84
92
  accountId: string;
85
93
  workspaceId: string;
86
94
  session: Session;
95
+ /** The authenticated subject driving the fleet attach/swap (0282): recorded
96
+ * on the viewer holder and the materialization audit fact. Omitting it
97
+ * records the explicit service sentinel, so forward the route subject. */
98
+ subjectId?: string | null;
87
99
  }): Promise<SessionGroupReadinessHold>;
88
100
  /**
89
101
  * Refresh a viewer holder's TTL (the app-level viewer heartbeat). Epoch-fenced:
@@ -148,6 +160,11 @@ export type DesktopStreamMint = {
148
160
  export type MintDesktopStreamInput = {
149
161
  accountId: string;
150
162
  workspaceId: string;
163
+ resourceSubjectId?: string;
164
+ /** True when the route grant is a signed delegated token (metadata.delegated):
165
+ * its authority is the token, not membership rows, so the mint-time
166
+ * live-authority recheck does not apply. */
167
+ resourceSubjectDelegated?: boolean;
151
168
  session: Session;
152
169
  /** The viewer holder id the scoped token is minted for. */
153
170
  viewerId: string;
@@ -197,6 +214,9 @@ type SelfhostedStreamMint = Omit<TerminalStreamMint, "transport">;
197
214
  export type MintTerminalStreamInput = {
198
215
  accountId: string;
199
216
  workspaceId: string;
217
+ resourceSubjectId?: string;
218
+ /** See MintDesktopStreamInput.resourceSubjectDelegated. */
219
+ resourceSubjectDelegated?: boolean;
200
220
  session: Session;
201
221
  /** The viewer holder / principal id the scoped token is minted for. */
202
222
  viewerId: string;
@@ -233,6 +253,11 @@ export type MintSelfhostedStreamInput = {
233
253
  * THIS as its leaseEpoch claim so the relay rejects a stale-epoch (swapped-away)
234
254
  * viewer. */
235
255
  activeEpoch: number;
256
+ /** 0281 viewer authority claims stamped into the relay stream token. */
257
+ viewerAuthority?: {
258
+ subjectId?: string;
259
+ authorityEpoch: number;
260
+ };
236
261
  /** The exposed stream port (6080 desktop / 7681 terminal). */
237
262
  port: number;
238
263
  /** The resolvable selfhosted session (the routing proxy resolves the active
@@ -0,0 +1,50 @@
1
+ import { SandboxFileArtifactReceipt, type AccessGrant, type Session } from "@opengeni/contracts";
2
+ import { type ApiRouteDeps, type AccessGrantAuthorization } from "@opengeni/core";
3
+ import { getFile } from "@opengeni/db";
4
+ import { type SandboxChannelAService } from "@opengeni/runtime/sandbox";
5
+ /** Original bytes inherit the already-authorized source session's ownership. */
6
+ export declare function publishSandboxFileArtifact(deps: ApiRouteDeps, input: Parameters<typeof publishSandboxFileArtifactInScope>[1]): Promise<SandboxFileArtifactReceipt>;
7
+ declare function publishSandboxFileArtifactInScope(deps: ApiRouteDeps, input: {
8
+ grant: AccessGrant;
9
+ authorization?: AccessGrantAuthorization;
10
+ session: Session;
11
+ path: string;
12
+ signal?: AbortSignal | undefined;
13
+ }): Promise<SandboxFileArtifactReceipt>;
14
+ /** Use the root captured by the same fenced Channel-A service that reads bytes,
15
+ * not the session's placement-home label or a caller-supplied root. */
16
+ export declare function readSandboxArtifactFile(service: Pick<SandboxChannelAService, "capabilities" | "fsRead">, value: string, maxBytes: number): Promise<{
17
+ path: string;
18
+ sandboxPath: string;
19
+ read: {
20
+ path: string;
21
+ encoding: "base64" | "utf8";
22
+ content: string;
23
+ sizeBytes: number;
24
+ truncated: boolean;
25
+ isBinary: boolean;
26
+ revision: number;
27
+ };
28
+ }>;
29
+ export declare function sandboxArtifactRelativePath(value: string, workspaceRoot?: string): string;
30
+ export declare function sandboxArtifactSafeFilename(filename: string): string;
31
+ export declare function sandboxFileContentType(filename: string): string;
32
+ export declare function sandboxArtifactIdentity(input: {
33
+ workspaceId: string;
34
+ sessionId: string;
35
+ path: string;
36
+ sha256: string;
37
+ }): {
38
+ fileId: string;
39
+ uploadId: string;
40
+ };
41
+ export declare function assertSandboxArtifactFile(file: NonNullable<Awaited<ReturnType<typeof getFile>>>, expected: {
42
+ filename: string;
43
+ safeFilename: string;
44
+ contentType: string;
45
+ sizeBytes: number;
46
+ sha256: string;
47
+ bucket: string;
48
+ objectKey: string;
49
+ }): void;
50
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { AccessGrant, ScheduledTask as ScheduledTaskValue } from "@opengeni/contracts";
2
+ import { type ApiRouteDeps } from "@opengeni/core";
3
+ import type { TemporalScheduleCleanupClaim } from "@opengeni/db";
4
+ /** Execute one exact connector obligation frozen into the tombstone outbox row. */
5
+ export declare function cleanupScheduledTaskConnectorAuthorization(deps: ApiRouteDeps, claim: TemporalScheduleCleanupClaim): Promise<void>;
6
+ /** Shared HTTP/MCP domain operation: authorize, tombstone, persist, then accelerate cleanup. */
7
+ export declare function deleteScheduledTaskWithDurableCleanup(deps: ApiRouteDeps, request: {
8
+ grant: AccessGrant;
9
+ taskId: string;
10
+ }): Promise<{
11
+ task: ScheduledTaskValue;
12
+ changed: boolean;
13
+ }>;
@@ -0,0 +1,5 @@
1
+ import { type Observability } from "@opengeni/observability";
2
+ type SessionCreatePhase = "authorization" | "body_read" | "site_origin" | "core_create" | "response_projection";
3
+ /** Content-free child boundaries within the existing HTTP request span. */
4
+ export declare function measureSessionCreatePhase<T>(observability: Pick<Observability, "startSpan"> | null | undefined, phase: SessionCreatePhase, work: () => Promise<T>): Promise<T>;
5
+ export {};
@@ -0,0 +1,292 @@
1
+ import "./chunk-OGQDXVXY.js";
2
+
3
+ // src/mcp/session-event-view.ts
4
+ import { z } from "zod";
5
+ import {
6
+ assistantMessagePhase
7
+ } from "@opengeni/contracts";
8
+ var SESSION_EVENT_VIEW_MAX_BYTES = 16 * 1024;
9
+ var selectionSchema = z.object({
10
+ sessionId: z.string().uuid(),
11
+ view: z.enum(["conversation", "results", "tools"]),
12
+ includeArguments: z.boolean(),
13
+ includeOutput: z.boolean(),
14
+ callId: z.string().max(512).refine(
15
+ (value) => Buffer.byteLength(JSON.stringify(value), "utf8") <= 2048,
16
+ "callId exceeds the encoded cursor budget"
17
+ ).nullable(),
18
+ toolName: z.string().min(1).max(256).refine(
19
+ (value) => Buffer.byteLength(JSON.stringify(value), "utf8") <= 512,
20
+ "toolName exceeds the encoded cursor budget"
21
+ ).nullable().default(null),
22
+ limit: z.number().int().min(1).max(50).optional(),
23
+ direction: z.enum(["before", "after"]),
24
+ after: z.number().int().nonnegative(),
25
+ before: z.number().int().positive().nullable()
26
+ });
27
+ var cursorSchema = z.object({
28
+ v: z.union([z.literal(1), z.literal(2)]),
29
+ selection: selectionSchema,
30
+ sequence: z.number().int().positive().nullable(),
31
+ offset: z.number().int().nonnegative().max(2147483647)
32
+ });
33
+ var types = {
34
+ conversation: ["user.message", "agent.message.completed"],
35
+ // Final turn output is authoritative: do not repeat message.completed text.
36
+ results: ["turn.completed", "turn.failed", "goal.completed", "goal.paused", "tool.auth_needed"],
37
+ tools: ["agent.toolCall.created", "agent.toolCall.output"]
38
+ };
39
+ var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
40
+ var bytes = (value) => Buffer.byteLength(JSON.stringify(value, null, 2), "utf8");
41
+ var encode = (selection, sequence = null, offset = 0, v = 2) => Buffer.from(JSON.stringify({ v, selection, sequence, offset })).toString("base64url");
42
+ function resolveSessionEventView(input) {
43
+ let continuation = null;
44
+ if (input.cursor !== void 0) {
45
+ if (input.cursor.length > 4096)
46
+ throw new Error("session_events cursor exceeds 4096 characters");
47
+ try {
48
+ continuation = cursorSchema.parse(
49
+ JSON.parse(Buffer.from(input.cursor, "base64url").toString())
50
+ );
51
+ } catch {
52
+ throw new Error("Invalid session_events cursor");
53
+ }
54
+ const previous = continuation.selection;
55
+ for (const key of [
56
+ "sessionId",
57
+ "view",
58
+ "includeArguments",
59
+ "includeOutput",
60
+ "callId",
61
+ "toolName",
62
+ "direction",
63
+ "after",
64
+ "before"
65
+ ]) {
66
+ if (input[key] !== void 0 && input[key] !== previous[key]) {
67
+ throw new Error(`session_events cursor cannot change ${key}`);
68
+ }
69
+ }
70
+ }
71
+ const selection = continuation?.selection ?? selectionSchema.parse({
72
+ sessionId: input.sessionId,
73
+ view: input.view ?? "conversation",
74
+ includeArguments: input.includeArguments ?? false,
75
+ includeOutput: input.includeOutput ?? false,
76
+ callId: input.callId ?? null,
77
+ toolName: input.toolName ?? null,
78
+ direction: input.direction ?? (input.before !== void 0 || input.after === void 0 ? "before" : "after"),
79
+ after: input.after ?? 0,
80
+ before: input.before ?? null
81
+ });
82
+ selection.limit = z.number().int().min(1).max(50).parse(input.limit ?? selection.limit ?? 10);
83
+ if (selection.toolName && selection.includeOutput)
84
+ throw new Error(
85
+ "toolName selects named calls. Read a result with its callId and includeOutput=true."
86
+ );
87
+ if (selection.view !== "tools" && (selection.callId || selection.toolName || selection.includeArguments || selection.includeOutput)) {
88
+ throw new Error("callId/toolName/includeArguments/includeOutput require view=tools");
89
+ }
90
+ if (continuation && (continuation.sequence === null && continuation.offset !== 0 || continuation.sequence !== null && (continuation.sequence <= selection.after || selection.before !== null && continuation.sequence >= selection.before)))
91
+ throw new Error("Invalid session_events cursor position");
92
+ return { selection, continuation };
93
+ }
94
+ function project(event, selection) {
95
+ if (event.duplicateOfEventId || event.turnAssociation && event.turnAssociation !== "current")
96
+ return null;
97
+ const p = record(event.payload);
98
+ const base = { sequence: event.sequence, ...event.turnId ? { turnId: event.turnId } : {} };
99
+ if (selection.view === "conversation") {
100
+ const phase = event.type === "agent.message.completed" ? assistantMessagePhase(p) : null;
101
+ return typeof p.text === "string" && p.text.length > 0 ? {
102
+ ...base,
103
+ role: event.type === "user.message" ? "user" : "assistant",
104
+ ...phase ? { phase } : {},
105
+ text: p.text
106
+ } : null;
107
+ }
108
+ if (selection.view === "results") {
109
+ if (event.type === "turn.completed" && ("maintenance" in p || "segmentLimit" in p)) return null;
110
+ const value2 = event.type === "turn.completed" ? p.output ?? p.result : p;
111
+ if (value2 === void 0 || value2 === "") return null;
112
+ return {
113
+ ...base,
114
+ type: event.type,
115
+ text: typeof value2 === "string" ? value2 : JSON.stringify(value2)
116
+ };
117
+ }
118
+ if (selection.toolName && (event.type !== "agent.toolCall.created" || p.name !== selection.toolName))
119
+ return null;
120
+ const callId = p.callId ?? p.call_id ?? p.id;
121
+ if (selection.callId !== null && selection.callId !== callId) return null;
122
+ const output = event.type === "agent.toolCall.output";
123
+ const value = output ? p.output : p.arguments ?? p.args;
124
+ return {
125
+ ...base,
126
+ callId,
127
+ kind: output ? "result" : "call",
128
+ ...typeof p.name === "string" ? { name: p.name } : {},
129
+ ...p.identityOmitted === true ? { identityOmitted: true } : {},
130
+ ...p.isError === true || record(value).isError === true ? { isError: true } : {},
131
+ ...(output ? selection.includeOutput : selection.includeArguments) && value !== void 0 ? {
132
+ text: typeof value === "string" ? value : JSON.stringify(value),
133
+ encoding: typeof value === "string" ? "text" : "json"
134
+ } : {}
135
+ };
136
+ }
137
+ async function readSessionEventView(input, read) {
138
+ const { selection, continuation } = resolveSessionEventView(input);
139
+ const limit = selection.limit;
140
+ let after = continuation?.sequence && selection.direction === "after" ? continuation.sequence - 1 : selection.after;
141
+ let before = continuation?.sequence && selection.direction === "before" ? continuation.sequence + 1 : selection.before;
142
+ const events = [];
143
+ let hasMore = false;
144
+ let nextCursor = null;
145
+ let sourceExact = true;
146
+ let edge = null;
147
+ let legacyActive = continuation?.v === 1 && continuation.sequence !== null;
148
+ const page = () => ({
149
+ view: selection.view,
150
+ effectiveLimit: limit,
151
+ direction: selection.direction,
152
+ events,
153
+ nextAfter: selection.direction === "after" ? edge ?? selection.after : null,
154
+ nextBefore: selection.direction === "before" ? edge ?? selection.before : null,
155
+ hasMore,
156
+ nextCursor,
157
+ sourceExact,
158
+ ...!sourceExact ? {
159
+ sourceLoss: {
160
+ reason: "structured_value_exceeds_budget",
161
+ completeTextAvailable: false,
162
+ message: "An oversized structured value was omitted. Scalar text remains retrievable through continuation; omitted structured values are not complete JSON results."
163
+ }
164
+ } : {},
165
+ maxBytes: SESSION_EVENT_VIEW_MAX_BYTES
166
+ });
167
+ const resume = (sequence, offset = 0) => {
168
+ hasMore = true;
169
+ nextCursor = encode(
170
+ { ...selection, after, before },
171
+ sequence,
172
+ offset,
173
+ legacyActive && sequence === continuation?.sequence ? 1 : 2
174
+ );
175
+ };
176
+ for (let scan = 0; scan < 64; scan += 1) {
177
+ const source = await read({
178
+ after,
179
+ ...before === null ? {} : { before },
180
+ direction: selection.direction,
181
+ limit: 8,
182
+ includeTypes: selection.toolName ? ["agent.toolCall.created"] : types[selection.view],
183
+ ...selection.toolName ? { toolName: selection.toolName } : {},
184
+ ...selection.callId ? { callId: selection.callId } : {},
185
+ payloadMode: "full",
186
+ excludeUnclaimedHumanPrompts: true,
187
+ maxBytes: 1024 * 1024,
188
+ legacyUtf16: legacyActive,
189
+ view: selection.view,
190
+ includeArguments: selection.includeArguments,
191
+ includeOutput: selection.includeOutput,
192
+ ...continuation?.sequence ? { sourceSequence: continuation.sequence, sourceOffset: continuation.offset } : {}
193
+ });
194
+ sourceExact &&= source.fullPayloadsExact;
195
+ const ordered = selection.direction === "before" ? [...source.events].reverse() : source.events;
196
+ for (const event of ordered) {
197
+ const slice = source.slices?.[event.sequence];
198
+ const item = project(event, selection);
199
+ if (item) {
200
+ const offset = continuation?.sequence === event.sequence ? continuation.offset : 0;
201
+ if (slice?.omitted) {
202
+ delete item.text;
203
+ item.sourceOmitted = { reason: "structured_value_exceeds_budget", complete: false };
204
+ }
205
+ const advance = (text) => slice?.unit === "codepoint" ? Array.from(text).length : text.length;
206
+ if (!slice && offset > (item.text?.length ?? 0))
207
+ throw new Error("Invalid message continuation offset");
208
+ if (!slice && offset > 0 && item.text && /[\uD800-\uDBFF]/.test(item.text[offset - 1]) && /[\uDC00-\uDFFF]/.test(item.text[offset] ?? "")) {
209
+ throw new Error("Invalid message continuation offset: splits a surrogate pair");
210
+ }
211
+ if (!slice && offset > 0 && item.text) item.text = item.text.slice(offset);
212
+ events.push(item);
213
+ if (bytes(page()) > SESSION_EVENT_VIEW_MAX_BYTES - 4096) {
214
+ events.pop();
215
+ if (events.length > 0) {
216
+ resume(event.sequence, offset);
217
+ if (selection.direction === "before") events.reverse();
218
+ return page();
219
+ }
220
+ if (!item.text) throw new Error("Session event identity exceeds page budget");
221
+ const text = item.text;
222
+ let low = 0;
223
+ let high = text.length;
224
+ while (low < high) {
225
+ const mid = Math.ceil((low + high) / 2);
226
+ if (bytes({ ...item, text: text.slice(0, mid) }) <= SESSION_EVENT_VIEW_MAX_BYTES - 6e3)
227
+ low = mid;
228
+ else high = mid - 1;
229
+ }
230
+ if (low > 0 && /[\uD800-\uDBFF]/.test(text[low - 1])) low -= 1;
231
+ if (low === 0) throw new Error("Session event identity exceeds page budget");
232
+ events.push({
233
+ ...item,
234
+ text: text.slice(0, low),
235
+ fragment: {
236
+ offset,
237
+ nextOffset: offset + advance(text.slice(0, low)),
238
+ complete: false,
239
+ unit: slice?.unit ?? "utf16"
240
+ }
241
+ });
242
+ resume(event.sequence, offset + advance(text.slice(0, low)));
243
+ return page();
244
+ }
245
+ const nextOffset = offset + advance(item.text ?? "");
246
+ if (slice && !slice.omitted && nextOffset < slice.total) {
247
+ item.fragment = { offset, nextOffset, complete: false, unit: slice.unit };
248
+ resume(event.sequence, nextOffset);
249
+ if (selection.direction === "before") events.reverse();
250
+ return page();
251
+ }
252
+ if (offset > 0)
253
+ item.fragment = {
254
+ offset,
255
+ nextOffset,
256
+ complete: true,
257
+ unit: slice?.unit ?? "utf16"
258
+ };
259
+ }
260
+ edge = event.sequence;
261
+ legacyActive = false;
262
+ if (selection.direction === "after") after = event.sequence;
263
+ else before = event.sequence;
264
+ if (events.length >= limit) {
265
+ hasMore = source.hasMore || event !== ordered.at(-1);
266
+ nextCursor = hasMore ? encode({ ...selection, after, before }) : null;
267
+ if (selection.direction === "before") events.reverse();
268
+ return page();
269
+ }
270
+ }
271
+ if (source.coveredSequence) {
272
+ if (selection.direction === "after") after = Math.max(after, source.coveredSequence.last);
273
+ else before = Math.min(before ?? Infinity, source.coveredSequence.first);
274
+ }
275
+ if (!source.hasMore) {
276
+ hasMore = false;
277
+ nextCursor = null;
278
+ if (selection.direction === "before") events.reverse();
279
+ return page();
280
+ }
281
+ hasMore = true;
282
+ nextCursor = encode({ ...selection, after, before });
283
+ }
284
+ if (selection.direction === "before") events.reverse();
285
+ return page();
286
+ }
287
+ export {
288
+ SESSION_EVENT_VIEW_MAX_BYTES,
289
+ readSessionEventView,
290
+ resolveSessionEventView
291
+ };
292
+ //# sourceMappingURL=session-event-view-MPS2OZD3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp/session-event-view.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n assistantMessagePhase,\n type SessionEvent,\n type SessionEventType,\n} from \"@opengeni/contracts\";\nimport type {\n SessionEventSliceOptions,\n SessionEventSlicePage,\n} from \"@opengeni/db/session-event-slices\";\n\nexport const SESSION_EVENT_VIEW_MAX_BYTES = 16 * 1024;\nconst selectionSchema = z.object({\n sessionId: z.string().uuid(),\n view: z.enum([\"conversation\", \"results\", \"tools\"]),\n includeArguments: z.boolean(),\n includeOutput: z.boolean(),\n callId: z\n .string()\n .max(512)\n .refine(\n (value) => Buffer.byteLength(JSON.stringify(value), \"utf8\") <= 2048,\n \"callId exceeds the encoded cursor budget\",\n )\n .nullable(),\n toolName: z\n .string()\n .min(1)\n .max(256)\n .refine(\n (value) => Buffer.byteLength(JSON.stringify(value), \"utf8\") <= 512,\n \"toolName exceeds the encoded cursor budget\",\n )\n .nullable()\n .default(null),\n limit: z.number().int().min(1).max(50).optional(),\n direction: z.enum([\"before\", \"after\"]),\n after: z.number().int().nonnegative(),\n before: z.number().int().positive().nullable(),\n});\nconst cursorSchema = z.object({\n v: z.union([z.literal(1), z.literal(2)]),\n selection: selectionSchema,\n sequence: z.number().int().positive().nullable(),\n offset: z.number().int().nonnegative().max(2_147_483_647),\n});\ntype Selection = z.infer<typeof selectionSchema>;\nexport type SessionEventViewInput = {\n sessionId: string;\n view?: Selection[\"view\"] | undefined;\n after?: number | undefined;\n before?: number | undefined;\n direction?: Selection[\"direction\"] | undefined;\n limit?: number | undefined;\n cursor?: string | undefined;\n callId?: string | undefined;\n toolName?: string | undefined;\n includeArguments?: boolean | undefined;\n includeOutput?: boolean | undefined;\n};\ntype Item = { sequence: number; turnId?: string; role?: string; text?: string } & Record<\n string,\n unknown\n>;\ntype ReadPage = (options: SessionEventSliceOptions) => Promise<SessionEventSlicePage>;\nconst types: Record<Selection[\"view\"], SessionEventType[]> = {\n conversation: [\"user.message\", \"agent.message.completed\"],\n // Final turn output is authoritative: do not repeat message.completed text.\n results: [\"turn.completed\", \"turn.failed\", \"goal.completed\", \"goal.paused\", \"tool.auth_needed\"],\n tools: [\"agent.toolCall.created\", \"agent.toolCall.output\"],\n};\nconst record = (value: unknown): Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : {};\nconst bytes = (value: unknown) => Buffer.byteLength(JSON.stringify(value, null, 2), \"utf8\");\nconst encode = (selection: Selection, sequence: number | null = null, offset = 0, v = 2) =>\n Buffer.from(JSON.stringify({ v, selection, sequence, offset })).toString(\"base64url\");\n\n/** A cursor is a bounded selector, never authority. The caller reauthorizes every read. */\nexport function resolveSessionEventView(input: SessionEventViewInput) {\n let continuation: z.infer<typeof cursorSchema> | null = null;\n if (input.cursor !== undefined) {\n if (input.cursor.length > 4096)\n throw new Error(\"session_events cursor exceeds 4096 characters\");\n try {\n continuation = cursorSchema.parse(\n JSON.parse(Buffer.from(input.cursor, \"base64url\").toString()),\n );\n } catch {\n throw new Error(\"Invalid session_events cursor\");\n }\n const previous = continuation.selection;\n for (const key of [\n \"sessionId\",\n \"view\",\n \"includeArguments\",\n \"includeOutput\",\n \"callId\",\n \"toolName\",\n \"direction\",\n \"after\",\n \"before\",\n ] as const) {\n if (input[key] !== undefined && input[key] !== previous[key]) {\n throw new Error(`session_events cursor cannot change ${key}`);\n }\n }\n }\n const selection =\n continuation?.selection ??\n selectionSchema.parse({\n sessionId: input.sessionId,\n view: input.view ?? \"conversation\",\n includeArguments: input.includeArguments ?? false,\n includeOutput: input.includeOutput ?? false,\n callId: input.callId ?? null,\n toolName: input.toolName ?? null,\n direction:\n input.direction ??\n (input.before !== undefined || input.after === undefined ? \"before\" : \"after\"),\n after: input.after ?? 0,\n before: input.before ?? null,\n });\n selection.limit = z\n .number()\n .int()\n .min(1)\n .max(50)\n .parse(input.limit ?? selection.limit ?? 10);\n if (selection.toolName && selection.includeOutput)\n throw new Error(\n \"toolName selects named calls. Read a result with its callId and includeOutput=true.\",\n );\n if (\n selection.view !== \"tools\" &&\n (selection.callId ||\n selection.toolName ||\n selection.includeArguments ||\n selection.includeOutput)\n ) {\n throw new Error(\"callId/toolName/includeArguments/includeOutput require view=tools\");\n }\n if (\n continuation &&\n ((continuation.sequence === null && continuation.offset !== 0) ||\n (continuation.sequence !== null &&\n (continuation.sequence <= selection.after ||\n (selection.before !== null && continuation.sequence >= selection.before))))\n )\n throw new Error(\"Invalid session_events cursor position\");\n return { selection, continuation };\n}\n\nfunction project(event: SessionEvent, selection: Selection): Item | null {\n if (event.duplicateOfEventId || (event.turnAssociation && event.turnAssociation !== \"current\"))\n return null;\n const p = record(event.payload);\n const base = { sequence: event.sequence, ...(event.turnId ? { turnId: event.turnId } : {}) };\n if (selection.view === \"conversation\") {\n // Commentary stays in the conversation, labelled so a reader can tell a\n // progress note from an answer.\n const phase = event.type === \"agent.message.completed\" ? assistantMessagePhase(p) : null;\n return typeof p.text === \"string\" && p.text.length > 0\n ? {\n ...base,\n role: event.type === \"user.message\" ? \"user\" : \"assistant\",\n ...(phase ? { phase } : {}),\n text: p.text,\n }\n : null;\n }\n if (selection.view === \"results\") {\n if (event.type === \"turn.completed\" && (\"maintenance\" in p || \"segmentLimit\" in p)) return null;\n const value = event.type === \"turn.completed\" ? (p.output ?? p.result) : p;\n if (value === undefined || value === \"\") return null;\n return {\n ...base,\n type: event.type,\n text: typeof value === \"string\" ? value : JSON.stringify(value),\n };\n }\n if (\n selection.toolName &&\n (event.type !== \"agent.toolCall.created\" || p.name !== selection.toolName)\n )\n return null;\n const callId = p.callId ?? p.call_id ?? p.id;\n if (selection.callId !== null && selection.callId !== callId) return null;\n const output = event.type === \"agent.toolCall.output\";\n // Choose one canonical slot. Never ship the raw receipt beside its parsed copy.\n const value = output ? p.output : (p.arguments ?? p.args);\n return {\n ...base,\n callId,\n kind: output ? \"result\" : \"call\",\n ...(typeof p.name === \"string\" ? { name: p.name } : {}),\n ...(p.identityOmitted === true ? { identityOmitted: true } : {}),\n ...(p.isError === true || record(value).isError === true ? { isError: true } : {}),\n ...((output ? selection.includeOutput : selection.includeArguments) && value !== undefined\n ? {\n text: typeof value === \"string\" ? value : JSON.stringify(value),\n encoding: typeof value === \"string\" ? \"text\" : \"json\",\n }\n : {}),\n };\n}\n\n/** Read-only projection over the existing RLS/audit query. No command observations. */\nexport async function readSessionEventView(input: SessionEventViewInput, read: ReadPage) {\n const { selection, continuation } = resolveSessionEventView(input);\n const limit = selection.limit!;\n let after =\n continuation?.sequence && selection.direction === \"after\"\n ? continuation.sequence - 1\n : selection.after;\n let before =\n continuation?.sequence && selection.direction === \"before\"\n ? continuation.sequence + 1\n : selection.before;\n const events: Item[] = [];\n let hasMore = false;\n let nextCursor: string | null = null;\n let sourceExact = true;\n let edge: number | null = null;\n let legacyActive = continuation?.v === 1 && continuation.sequence !== null;\n const page = () => ({\n view: selection.view,\n effectiveLimit: limit,\n direction: selection.direction,\n events,\n nextAfter: selection.direction === \"after\" ? (edge ?? selection.after) : null,\n nextBefore: selection.direction === \"before\" ? (edge ?? selection.before) : null,\n hasMore,\n nextCursor,\n sourceExact,\n ...(!sourceExact\n ? {\n sourceLoss: {\n reason: \"structured_value_exceeds_budget\" as const,\n completeTextAvailable: false as const,\n message:\n \"An oversized structured value was omitted. Scalar text remains retrievable through continuation; omitted structured values are not complete JSON results.\",\n },\n }\n : {}),\n maxBytes: SESSION_EVENT_VIEW_MAX_BYTES,\n });\n const resume = (sequence: number, offset = 0) => {\n hasMore = true;\n nextCursor = encode(\n { ...selection, after, before },\n sequence,\n offset,\n legacyActive && sequence === continuation?.sequence ? 1 : 2,\n );\n };\n // Bound work even when a sparse exact callId lookup matches nothing. The\n // returned cursor advances the scan without claiming the lookup is exhausted.\n for (let scan = 0; scan < 64; scan += 1) {\n const source = await read({\n after,\n ...(before === null ? {} : { before }),\n direction: selection.direction,\n limit: 8,\n includeTypes: selection.toolName ? [\"agent.toolCall.created\"] : types[selection.view],\n ...(selection.toolName ? { toolName: selection.toolName } : {}),\n ...(selection.callId ? { callId: selection.callId } : {}),\n payloadMode: \"full\",\n excludeUnclaimedHumanPrompts: true,\n maxBytes: 1024 * 1024,\n legacyUtf16: legacyActive,\n view: selection.view,\n includeArguments: selection.includeArguments,\n includeOutput: selection.includeOutput,\n ...(continuation?.sequence\n ? { sourceSequence: continuation.sequence, sourceOffset: continuation.offset }\n : {}),\n });\n sourceExact &&= source.fullPayloadsExact;\n const ordered = selection.direction === \"before\" ? [...source.events].reverse() : source.events;\n for (const event of ordered) {\n const slice = source.slices?.[event.sequence];\n const item = project(event, selection);\n if (item) {\n const offset = continuation?.sequence === event.sequence ? continuation.offset : 0;\n if (slice?.omitted) {\n delete item.text;\n item.sourceOmitted = { reason: \"structured_value_exceeds_budget\", complete: false };\n }\n const advance = (text: string) =>\n slice?.unit === \"codepoint\" ? Array.from(text).length : text.length;\n if (!slice && offset > (item.text?.length ?? 0))\n throw new Error(\"Invalid message continuation offset\");\n if (\n !slice &&\n offset > 0 &&\n item.text &&\n /[\\uD800-\\uDBFF]/.test(item.text[offset - 1]!) &&\n /[\\uDC00-\\uDFFF]/.test(item.text[offset] ?? \"\")\n ) {\n throw new Error(\"Invalid message continuation offset: splits a surrogate pair\");\n }\n if (!slice && offset > 0 && item.text) item.text = item.text.slice(offset);\n events.push(item);\n // Reserve enough for the bounded cursor and fragment facts.\n if (bytes(page()) > SESSION_EVENT_VIEW_MAX_BYTES - 4096) {\n events.pop();\n if (events.length > 0) {\n resume(event.sequence, offset);\n if (selection.direction === \"before\") events.reverse();\n return page();\n }\n if (!item.text) throw new Error(\"Session event identity exceeds page budget\");\n const text = item.text;\n let low = 0;\n let high = text.length;\n while (low < high) {\n const mid = Math.ceil((low + high) / 2);\n if (bytes({ ...item, text: text.slice(0, mid) }) <= SESSION_EVENT_VIEW_MAX_BYTES - 6000)\n low = mid;\n else high = mid - 1;\n }\n // Do not split a UTF-16 surrogate pair (UTF-8 remains lossless).\n if (low > 0 && /[\\uD800-\\uDBFF]/.test(text[low - 1]!)) low -= 1;\n if (low === 0) throw new Error(\"Session event identity exceeds page budget\");\n events.push({\n ...item,\n text: text.slice(0, low),\n fragment: {\n offset,\n nextOffset: offset + advance(text.slice(0, low)),\n complete: false,\n unit: slice?.unit ?? \"utf16\",\n },\n });\n resume(event.sequence, offset + advance(text.slice(0, low)));\n return page();\n }\n const nextOffset = offset + advance(item.text ?? \"\");\n if (slice && !slice.omitted && nextOffset < slice.total) {\n item.fragment = { offset, nextOffset, complete: false, unit: slice.unit };\n resume(event.sequence, nextOffset);\n if (selection.direction === \"before\") events.reverse();\n return page();\n }\n if (offset > 0)\n item.fragment = {\n offset,\n nextOffset,\n complete: true,\n unit: slice?.unit ?? \"utf16\",\n };\n }\n edge = event.sequence;\n legacyActive = false;\n if (selection.direction === \"after\") after = event.sequence;\n else before = event.sequence;\n if (events.length >= limit) {\n hasMore = source.hasMore || event !== ordered.at(-1);\n nextCursor = hasMore ? encode({ ...selection, after, before }) : null;\n if (selection.direction === \"before\") events.reverse();\n return page();\n }\n }\n // Metadata selection can advance over stale/duplicate rows without a\n // projected payload. Use its covered edge rather than repeating the page.\n if (source.coveredSequence) {\n if (selection.direction === \"after\") after = Math.max(after, source.coveredSequence.last);\n else before = Math.min(before ?? Infinity, source.coveredSequence.first);\n }\n if (!source.hasMore) {\n hasMore = false;\n nextCursor = null;\n if (selection.direction === \"before\") events.reverse();\n return page();\n }\n hasMore = true;\n nextCursor = encode({ ...selection, after, before });\n }\n if (selection.direction === \"before\") events.reverse();\n return page();\n}\n"],"mappings":";;;AAAA,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,OAGK;AAMA,IAAM,+BAA+B,KAAK;AACjD,IAAM,kBAAkB,EAAE,OAAO;AAAA,EAC/B,WAAW,EAAE,OAAO,EAAE,KAAK;AAAA,EAC3B,MAAM,EAAE,KAAK,CAAC,gBAAgB,WAAW,OAAO,CAAC;AAAA,EACjD,kBAAkB,EAAE,QAAQ;AAAA,EAC5B,eAAe,EAAE,QAAQ;AAAA,EACzB,QAAQ,EACL,OAAO,EACP,IAAI,GAAG,EACP;AAAA,IACC,CAAC,UAAU,OAAO,WAAW,KAAK,UAAU,KAAK,GAAG,MAAM,KAAK;AAAA,IAC/D;AAAA,EACF,EACC,SAAS;AAAA,EACZ,UAAU,EACP,OAAO,EACP,IAAI,CAAC,EACL,IAAI,GAAG,EACP;AAAA,IACC,CAAC,UAAU,OAAO,WAAW,KAAK,UAAU,KAAK,GAAG,MAAM,KAAK;AAAA,IAC/D;AAAA,EACF,EACC,SAAS,EACT,QAAQ,IAAI;AAAA,EACf,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA,EAChD,WAAW,EAAE,KAAK,CAAC,UAAU,OAAO,CAAC;AAAA,EACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY;AAAA,EACpC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS;AAC/C,CAAC;AACD,IAAM,eAAe,EAAE,OAAO;AAAA,EAC5B,GAAG,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,EA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AQ;AACrD,SAAO,KAAK;AACd;","names":["value"]}
@@ -0,0 +1,13 @@
1
+ import { type ApiRouteDeps } from "@opengeni/core";
2
+ /** Validates a caller-asserted Site association, not browser execution or authority. */
3
+ export declare function resolveSiteSessionOrigin(db: ApiRouteDeps["db"], workspaceId: string, siteId?: string, versionId?: string): Promise<{
4
+ siteId: string;
5
+ title: string;
6
+ } | null>;
7
+ /**
8
+ * Run a follow-up command (Send or Steer) inside the request's Site scope when
9
+ * the published Site bridge supplied a valid origin, so its turn records the
10
+ * `site` surface. Provenance only: a missing or unverifiable origin leaves the
11
+ * command unscoped instead of rejecting a message that is otherwise valid.
12
+ */
13
+ export declare function withOptionalSiteCommandOrigin<T>(db: ApiRouteDeps["db"], workspaceId: string, siteId: string | undefined, versionId: string | undefined, run: () => Promise<T>): Promise<T>;
@@ -0,0 +1,41 @@
1
+ import { type AccessGrant } from "@opengeni/contracts";
2
+ import type { ApiRouteDeps, ObjectStorageDependency } from "@opengeni/core";
3
+ import { prepareWorkspaceArtifactContent, type PreparedWorkspaceArtifactContent } from "./workspace-artifact-content.js";
4
+ type Storage = NonNullable<ObjectStorageDependency>;
5
+ export declare const MAX_SITE_SOURCE_BYTES: number;
6
+ export declare function validateSiteSource(storage: Storage, key: string, sizeBytes: number): Promise<void>;
7
+ export declare function prepareWorkspaceArtifactUpload(deps: ApiRouteDeps, grant: AccessGrant): Promise<{
8
+ uploadId: string;
9
+ html: {
10
+ putUrl: string;
11
+ requiredHeaders: Record<string, string>;
12
+ };
13
+ source: {
14
+ putUrl: string;
15
+ requiredHeaders: Record<string, string>;
16
+ };
17
+ expiresAt: string;
18
+ }>;
19
+ /** Provider version-pinned reads, without Site SHA checks or full HTML buffering. */
20
+ export declare function readArtifactObject(storage: Storage, key: string, expectedHead?: Awaited<ReturnType<NonNullable<Storage["headObject"]>>>): AsyncGenerator<Uint8Array<ArrayBufferLike>, void, unknown>;
21
+ type Input = Partial<Parameters<typeof prepareWorkspaceArtifactContent>[2]> & {
22
+ uploadId?: string;
23
+ };
24
+ export declare function prepareWorkspaceArtifactPublication(deps: ApiRouteDeps, grant: AccessGrant, input: Input): Promise<PreparedWorkspaceArtifactContent & {
25
+ uploadId?: string;
26
+ }>;
27
+ export declare function workspaceArtifactDownloads(storage: Storage, ref: {
28
+ contentKey: string;
29
+ sourceKey: string | null;
30
+ }, audience: "sandbox" | "public"): Promise<{
31
+ html: {
32
+ url: string;
33
+ expiresAt: Date;
34
+ };
35
+ source: {
36
+ url: string;
37
+ expiresAt: Date;
38
+ format: string;
39
+ } | null;
40
+ }>;
41
+ export {};
@@ -1,6 +1,6 @@
1
1
  import type { FileResourceRef } from "@opengeni/contracts";
2
2
  import { completeFileUpload, prepareGeneratedWorkspaceFile, type Database } from "@opengeni/db";
3
- import type { ObjectStorage } from "@opengeni/storage";
3
+ import { type ObjectStorage } from "@opengeni/storage";
4
4
  import type { DownloadedSlackReactionImage } from "./integrations/slack-bot.js";
5
5
  export type SlackReactionImageImportSource = Readonly<{
6
6
  accountId: string;
@@ -2,6 +2,7 @@ import { type Database, type TemporalScheduleCleanupClaim } from "@opengeni/db";
2
2
  import type { Observability } from "@opengeni/observability";
3
3
  type TemporalScheduleCleanupDependencies = {
4
4
  db: Database;
5
+ cleanupConnectorAuthorization?: (claim: TemporalScheduleCleanupClaim) => Promise<void>;
5
6
  deleteSchedule: (temporalScheduleId: string) => Promise<void>;
6
7
  observability?: Pick<Observability, "info" | "warn" | "error">;
7
8
  };
@@ -0,0 +1,26 @@
1
+ import type { ScheduledTask } from "@opengeni/contracts";
2
+ import { type Database } from "@opengeni/db";
3
+ type TemporalScheduleSyncDependencies = {
4
+ db: Database;
5
+ withDeadline<T>(deadline: number, work: () => Promise<T>): Promise<T>;
6
+ upsert(task: ScheduledTask): Promise<void>;
7
+ /** Idempotent: an absent Temporal schedule is already removed. */
8
+ remove(temporalScheduleId: string): Promise<void>;
9
+ };
10
+ /**
11
+ * Serialize external writes across API replicas, independently of task edits.
12
+ * A queued sync rereads the newest committed row after acquiring this lock;
13
+ * input snapshots never become desired state. Cleanup uses the same key, so
14
+ * an in-flight upsert finishes before its tombstone's external deletion.
15
+ * Failure compensation commits before releasing the lock, so a queued writer
16
+ * cannot read the row being restored and then publish that failed edit.
17
+ *
18
+ * Deadlines bound both lock admission and network occupancy. A thrown network
19
+ * error retains its unknown-outcome semantics; this is not durable recovery
20
+ * for a process crash or a lost Temporal acknowledgement.
21
+ */
22
+ export declare function createTemporalScheduleSynchronizer(deps: TemporalScheduleSyncDependencies): {
23
+ sync(task: Pick<ScheduledTask, "id" | "workspaceId" | "temporalScheduleId">, onFailure?: (tx: Database, error: unknown) => Promise<Error>): Promise<void>;
24
+ remove(temporalScheduleId: string): Promise<void>;
25
+ };
26
+ export {};
@@ -6,3 +6,4 @@ export declare function createXaiSubscriptionTranscriptionProvider(input: {
6
6
  db: Database;
7
7
  fetch?: typeof fetch;
8
8
  }): TranscriptionProvider;
9
+ export declare function isXaiInvalidCredentialResponse(response: Response): Promise<boolean>;
@@ -1,5 +1,5 @@
1
1
  import { type Settings } from "@opengeni/config";
2
- import { type TranscriptionAvailabilityContext, type TranscriptionService } from "@opengeni/core";
2
+ import { type TranscriptionAvailabilityContext, type TranscriptionProvider, type TranscriptionService } from "@opengeni/core";
3
3
  import type { Database } from "@opengeni/db";
4
4
  export declare function createTranscriptionService(input: {
5
5
  settings: Settings;
@@ -13,3 +13,4 @@ export declare function createTranscriptionService(input: {
13
13
  now?: () => Date;
14
14
  }): TranscriptionService;
15
15
  export declare function remainingTranscriptionProviderRequestMilliseconds(providerDeadlineAt: Date, now: Date): number;
16
+ export declare function orderedProviders(providers: readonly TranscriptionProvider[], context: TranscriptionAvailabilityContext): TranscriptionProvider[];
@@ -0,0 +1,33 @@
1
+ import type { WorkDiscoveryMatchClass } from "@opengeni/contracts";
2
+ import type { Observability } from "@opengeni/observability";
3
+ export type WorkDiscoverySurface = "first_party_mcp" | "agent_topology";
4
+ export type WorkDiscoveryMode = "browse" | "query" | "subject";
5
+ export type WorkDiscoveryOutcome = "ok" | "empty" | "disabled" | "error";
6
+ export type WorkDiscoveryAuthorizationScope = "workspace" | "scoped";
7
+ export type WorkDiscoveryObservation = {
8
+ surface: WorkDiscoverySurface;
9
+ mode: WorkDiscoveryMode;
10
+ outcome: WorkDiscoveryOutcome;
11
+ authorizationScope: WorkDiscoveryAuthorizationScope;
12
+ durationMs: number;
13
+ responseBytes: number;
14
+ resultCount: number;
15
+ overlapCount: number;
16
+ matchCounts: Partial<Record<WorkDiscoveryMatchClass, number>>;
17
+ };
18
+ type WorkDiscoveryObservedRow = {
19
+ relatedWork?: {
20
+ match: {
21
+ class: WorkDiscoveryMatchClass;
22
+ } | null;
23
+ possibleOverlap: boolean;
24
+ };
25
+ };
26
+ export declare function summarizeWorkDiscoveryRows(rows: readonly WorkDiscoveryObservedRow[]): Pick<WorkDiscoveryObservation, "resultCount" | "overlapCount" | "matchCounts">;
27
+ /**
28
+ * Low-cardinality work-discovery telemetry. Identifiers, search text, subject
29
+ * keys, titles, goals, claim labels, versions, and provenance are excluded by
30
+ * construction. An observability failure never changes product behavior.
31
+ */
32
+ export declare function observeWorkDiscovery(observability: Observability | null | undefined, observation: WorkDiscoveryObservation): void;
33
+ export {};