@sentry/junior 0.313.0 → 0.315.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 (652) hide show
  1. package/dist/{channel-access-mt7K6dPh.js → adapter-context-BlSGE44V.js} +46 -7
  2. package/dist/{admin-Cyhb4TwZ.js → admin-5jUYY46p.js} +1 -1
  3. package/dist/agent-runner-C7GNLRB6.js +23438 -0
  4. package/dist/agent-update-delivery-BNEYQsAf.js +149 -0
  5. package/dist/api/schema.d.ts +9500 -2
  6. package/dist/api/schema.js +5 -7
  7. package/dist/api.d.ts +2 -3
  8. package/dist/api.js +1172 -371
  9. package/dist/{app-DA8-hCMj.d.ts → app-D_bAXRDe.d.ts} +312 -48
  10. package/dist/app.d.ts +2 -2
  11. package/dist/app.js +305 -184
  12. package/dist/change-record-Bqsa5ZXE.d.ts +175 -0
  13. package/dist/chat-core-engine-CxkwRpn9.js +123 -0
  14. package/dist/child-message--2G3Ft26.js +19 -0
  15. package/dist/cli/chat.d.ts +4 -1
  16. package/dist/cli/chat.js +40 -25
  17. package/dist/cli/check.js +4 -4
  18. package/dist/cli/main.js +2 -2
  19. package/dist/cli/plugins.js +4 -5
  20. package/dist/cli/run.d.ts +1 -1
  21. package/dist/cli/run.js +1 -1
  22. package/dist/cli/snapshot-create.js +2 -5
  23. package/dist/cli/upgrade.d.ts +1 -1
  24. package/dist/cli/upgrade.js +68 -97
  25. package/dist/{continue-in-slack-CxyFzdlF.js → continue-in-slack-BGKjIdFp.js} +3 -7
  26. package/dist/{conversation-feed-BEXLD3Me.js → conversation-feed-Sl8lKKmR.js} +22 -2
  27. package/dist/{conversation-turn-B35eu0uz.js → conversation-turn-BoLK9i6g.js} +514 -83
  28. package/dist/create-BOycVH9h.js +213 -0
  29. package/dist/{credential-sync-DWTOEQrm.js → credential-sync-Mn4OdkEh.js} +10 -18
  30. package/dist/db-BpxcYXfD.d.ts +2 -0
  31. package/dist/{credentialed-Dyv8b-lu.js → db-DXTOYRzR.js} +22220 -9334
  32. package/dist/deployment-CG3TchWh.js +51 -0
  33. package/dist/direct-url-BYgYfuIy.js +22 -0
  34. package/dist/engine-context-dyWlfNdD.js +1817 -0
  35. package/dist/{html-DidUcRhI.js → html-CfXEwl_h.js} +2 -7
  36. package/dist/instrumentation.js +3 -3
  37. package/dist/job-runner-CySgpi9v.js +1131 -0
  38. package/dist/{lineage-BXplQAVH.js → lineage-tRTOcrsL.js} +1 -2
  39. package/dist/{list-DyIyReSV.js → list-DXBz8SYL.js} +610 -173
  40. package/dist/local-server-CpnGhYml.js +276 -0
  41. package/dist/{logging-DNt-qOIO.js → logging-czs0nqLC.js} +2 -45
  42. package/dist/{turn-membership-DTR3SaKD.js → mailbox-turn-79Nv1JXv.js} +4153 -559
  43. package/dist/markers-CE0HMXWT.js +67 -0
  44. package/dist/{media-B0pZJ0bG.js → media-Cr9pGkzr.js} +701 -41
  45. package/dist/{message-Z5YKC-Af.js → message-BTox2Cmb.js} +25 -36
  46. package/dist/{model-input-BhPJYdSV.js → model-input-IRGa98V7.js} +3 -3
  47. package/dist/nitro.d.ts +8 -4
  48. package/dist/nitro.js +106 -24
  49. package/dist/{oauth-callback-server-ByvDdcdY.js → oauth-callback-server-NXK7AlBp.js} +2 -2
  50. package/dist/{oauth-relay-D-kK0yoN.js → oauth-relay-6NBPSpFE.js} +1 -1
  51. package/dist/{package-discovery-DD9vencX.js → package-discovery-BI6T_RkD.js} +50 -1
  52. package/dist/parent-result-Dg6P6roR.js +323 -0
  53. package/dist/people-Cegp1Iwq.js +81 -0
  54. package/dist/{plugins-Bkk0XRo2.js → plugins-BXMdNdyA.js} +1 -1
  55. package/dist/{conversation-privacy-BrMiDN61.js → proxy-path-Dc-0jXGi.js} +16 -2
  56. package/dist/{resolve-CWtBNSKP.js → resolve-BUFkmxkT.js} +229 -4
  57. package/dist/result-DfATzX77.js +337 -0
  58. package/dist/{runner-CsZ_VRxp.js → runner-CmKP3inb.js} +7 -8
  59. package/dist/{sandbox-egress-signals-FbCk1FkN.js → sandbox-egress-signals-DYo5BsM7.js} +1 -1
  60. package/dist/{schema-DojR2uCL.js → schema-DrBMdPmv.js} +197 -20
  61. package/dist/{service-account-CDYb9hfX.js → service-account-CxTX7nnR.js} +4 -5
  62. package/dist/{skills-B0jP4whm.js → skills-BlHUDj7k.js} +4 -4
  63. package/dist/{slack-conversation-unfurl-D26t9kBC.js → slack-conversation-unfurl-Dhe3lB1U.js} +6 -10
  64. package/dist/{spawn-BjljgExZ.js → spawn-CfvlFdfz.js} +8 -17
  65. package/dist/start-conversation-Uh8Sk1EF.js +162 -0
  66. package/dist/system-prompt-table-CDCYVwqN.js +1169 -0
  67. package/dist/{task-runner--Ke8KSMf.js → task-runner-DcdQJd9e.js} +163 -55
  68. package/dist/{thread-context-B8exINEe.js → thread-context-DF5uDcWN.js} +7 -9
  69. package/dist/topic-CRYYBYp-.js +7 -0
  70. package/dist/transcript-BHhJVY0P.js +410 -0
  71. package/dist/turn-session-routing-GtetHsdO.js +1309 -0
  72. package/dist/turn-wake-um5Ubd4m.js +152 -0
  73. package/dist/user-customization-B27StpVQ.js +9 -0
  74. package/dist/{validation-Ce0qbMlT.js → validation-CJyuOPD2.js} +1 -1
  75. package/dist/{version-DFh4n9nr.js → version-Bhe7RPIe.js} +1 -1
  76. package/dist/version.js +1 -1
  77. package/dist/virtual-module-BeKA_EII.js +12 -0
  78. package/dist/{worker-CDg9Lbpg.js → worker-D8PRgUqr.js} +3 -6
  79. package/migrations/20260711145847_initial/snapshot.json +2103 -0
  80. package/migrations/20260711145900_conversation_metrics/snapshot.json +135 -0
  81. package/migrations/20260712153649_conversation_message_search/snapshot.json +50 -0
  82. package/migrations/20260713040256_peaceful_scalphunter/snapshot.json +42 -0
  83. package/migrations/20260715174202_useful_magus/snapshot.json +42 -0
  84. package/migrations/20260715174203_conversation_events/snapshot.json +539 -0
  85. package/migrations/20260723042835_drop_legacy_conversation_messages/snapshot.json +9 -0
  86. package/migrations/20260723050612_thick_sugar_man/snapshot.json +120 -0
  87. package/migrations/20260727223822_sticky_rage/snapshot.json +274 -0
  88. package/migrations/20260728033158_slippery_harrier/snapshot.json +191 -0
  89. package/migrations/20260728040836_native_conversation_history/snapshot.json +9 -0
  90. package/migrations/20260728204900_sour_golden_guardian/snapshot.json +124 -0
  91. package/migrations/20260730233332_structured_conversation_events/snapshot.json +9 -0
  92. package/migrations/20260731164038_conversation_session_source/snapshot.json +42 -0
  93. package/migrations/20260801230336_source_visibility/snapshot.json +9 -0
  94. package/migrations/20260802023731_magical_ezekiel_stane/snapshot.json +266 -0
  95. package/migrations/20260804015843_neat_the_anarchist/snapshot.json +714 -0
  96. package/migrations/20260804165952_drop_paused_scheduled_tasks/snapshot.json +9 -0
  97. package/migrations/20260804225613_curvy_excalibur/snapshot.json +223 -0
  98. package/migrations/20260805174033_lowly_valkyrie/snapshot.json +344 -0
  99. package/migrations/20260805200301_restrict_task_execution_kinds/snapshot.json +36 -0
  100. package/migrations/20260806030729_first_warhawk/snapshot.json +690 -0
  101. package/migrations/20260807185200_task_execution_status/snapshot.json +92 -0
  102. package/migrations/20260808014743_task_title_columns/snapshot.json +68 -0
  103. package/migrations/20260809220421_misty_typhoid_mary/snapshot.json +191 -0
  104. package/migrations/20260811193709_mcp_credential_subject/snapshot.json +9 -0
  105. package/migrations/20260812032924_conversation_event_actor_and_participants/snapshot.json +393 -0
  106. package/migrations/20260812172418_attachment_storage/snapshot.json +341 -0
  107. package/migrations/20260813230732_artifacts/snapshot.json +349 -0
  108. package/migrations/20260814062905_dizzy_barracuda/snapshot.json +342 -0
  109. package/migrations/20260814231353_drop_workspace_repo_primary/snapshot.json +55 -0
  110. package/migrations/20260815030100_wild_phantom_reporter/snapshot.json +135 -0
  111. package/migrations/20260817082233_workspace_snapshots_table/snapshot.json +625 -0
  112. package/migrations/20260818160339_workspace_snapshot_active_build/snapshot.json +62 -0
  113. package/migrations/20260821180755_strong_randall/snapshot.json +42 -0
  114. package/migrations/20260823030308_workspace_snapshot_size_bytes/snapshot.json +62 -0
  115. package/migrations/20260824190313_complex_rage/snapshot.json +690 -0
  116. package/migrations/20260827233711_conversation_location/snapshot.json +42 -0
  117. package/migrations/20260901224306_event_task_status/snapshot.json +100 -0
  118. package/migrations/20260904153232_attachment_provider/snapshot.json +234 -0
  119. package/migrations/20260909111415_conversation_briefs/snapshot.json +364 -0
  120. package/migrations/20260910144928_automation_outcomes_backfill/snapshot.json +9 -0
  121. package/migrations/20260911184346_conversation_metrics/snapshot.json +226 -0
  122. package/migrations/20260921140842_scheduled_automation_channel_destinations/snapshot.json +9 -0
  123. package/migrations/20260922221709_event_automation_channel_destinations/snapshot.json +9 -0
  124. package/migrations/20261001113455_conversation_forks/snapshot.json +120 -0
  125. package/migrations/20261005161844_automation_versions/snapshot.json +150 -0
  126. package/migrations/20261006152043_user_timezone/snapshot.json +37 -0
  127. package/migrations/20261008200858_user_admin/snapshot.json +37 -0
  128. package/migrations/20261009145407_event_automation_status_reason/snapshot.json +42 -0
  129. package/migrations/20261013160816_agent_invocation_parent_mailbox/snapshot.json +93 -0
  130. package/migrations/20261013215020_agent_invocation_parent_tool_call/snapshot.json +42 -0
  131. package/migrations/20261014011138_agent_invocation_title/snapshot.json +42 -0
  132. package/migrations/20261014211942_conversation_stopped_at/snapshot.json +42 -0
  133. package/migrations/20261015012820_flowery_rage/snapshot.json +42 -0
  134. package/migrations/20261017000924_automations/snapshot.json +790 -0
  135. package/migrations/20261017134736_automation_runs/snapshot.json +474 -0
  136. package/migrations/20261017170250_drop_legacy_automation_tables/snapshot.json +397 -0
  137. package/migrations/20261018134754_automation_creator_identity/snapshot.json +130 -0
  138. package/migrations/20261023071954_automation_run_version/snapshot.json +79 -0
  139. package/migrations/20261025233137_identity_signed_in_at/snapshot.json +42 -0
  140. package/migrations/20261027234315_workspace_vcpus/snapshot.json +37 -0
  141. package/migrations/20261028124242_plugin_report_index/snapshot.json +68 -0
  142. package/migrations/20261028154230_agent_invocation_type/snapshot.json +42 -0
  143. package/migrations/20261030021803_any_resource_event_triggers/snapshot.json +42 -0
  144. package/migrations/20261030234309_user_customization/snapshot.json +37 -0
  145. package/migrations/20261031020656_review_items/snapshot.json +1078 -0
  146. package/migrations/20261031024151_review_item_dedupe_tenant/snapshot.json +62 -0
  147. package/migrations/20261031024246_review_item_slack_cards/snapshot.json +159 -0
  148. package/migrations/20261031155308_system_identity/snapshot.json +9 -0
  149. package/migrations/20261101193952_review_item_foreign_keys/snapshot.json +108 -0
  150. package/migrations/20261102172751_review_item_turn/snapshot.json +42 -0
  151. package/migrations/20261102221411_conversation_read_positions/snapshot.json +190 -0
  152. package/migrations/20261104085028_conversation_quick_question/snapshot.json +42 -0
  153. package/migrations/20261104145136_conversation_participant_pins/snapshot.json +42 -0
  154. package/migrations/20261104164429_conversation_detail_version/snapshot.json +42 -0
  155. package/migrations/20261104172055_conversation_auto_archive/snapshot.json +206 -0
  156. package/migrations/20261105005443_drop_agent_invocation_model_profile/snapshot.json +30 -0
  157. package/migrations/20261105043807_plugin_conversation_index/snapshot.json +76 -0
  158. package/migrations/20261105051837_conversation_event_author_index/snapshot.json +70 -0
  159. package/migrations/20261105182854_conversation_event_latest_message_indexes/snapshot.json +136 -0
  160. package/migrations/20261106011443_conversation_pin_position/snapshot.json +42 -0
  161. package/migrations/20261106095004_push_notifications/snapshot.json +308 -0
  162. package/migrations/20261106162740_conversation_kind/snapshot.json +88 -0
  163. package/migrations/20261107002001_read_position_backfill/snapshot.json +9 -0
  164. package/migrations/20261107025209_child_archived_at/snapshot.json +42 -0
  165. package/migrations/20261107035735_shared_archive/snapshot.json +67 -0
  166. package/migrations/20261107215055_child_location/snapshot.json +9 -0
  167. package/migrations/20261108191927_conversation_unsubscribe/snapshot.json +42 -0
  168. package/migrations/20261109021618_conversation_paused_status/snapshot.json +9 -0
  169. package/migrations/20261109111553_guardian_review_time_index/snapshot.json +54 -0
  170. package/migrations/20261109173130_conversation_participant_unsubscribed_index/snapshot.json +62 -0
  171. package/migrations/20261109182006_turn_metric_actor/snapshot.json +128 -0
  172. package/migrations/20261109202836_participant_root_actor_backfill/snapshot.json +9 -0
  173. package/migrations/20261109232640_conversation_delivery_paused_at/snapshot.json +42 -0
  174. package/migrations/20261110120937_web_linked_slack_identity_repair/snapshot.json +9 -0
  175. package/migrations/20261110175824_automation_task_kind/snapshot.json +145 -0
  176. package/migrations/20261110210242_conversation_kind_automation/snapshot.json +55 -0
  177. package/migrations/20261110222632_review_item_plugin_actions/snapshot.json +37 -0
  178. package/migrations/20261110225157_conversation_last_message_at/snapshot.json +42 -0
  179. package/migrations/20261111013351_automation_task_kind_repair/snapshot.json +9 -0
  180. package/migrations/20261111163126_drop_legacy_columns/snapshot.json +9 -0
  181. package/migrations/20261111170150_code_change_last_activity/snapshot.json +42 -0
  182. package/migrations/20261111191441_agent_invocation_fork/snapshot.json +42 -0
  183. package/migrations/20261112142841_code_change_draft/snapshot.json +37 -0
  184. package/migrations/20261112202901_attachment_uploads/snapshot.json +255 -0
  185. package/migrations/20261112220407_conversation_agent_config/snapshot.json +42 -0
  186. package/migrations/20261113081247_attachment_deferred_download/snapshot.json +52 -0
  187. package/migrations/20261113225551_conversation_embeddings/snapshot.json +203 -0
  188. package/migrations/20261114213238_user_preferences/snapshot.json +37 -0
  189. package/migrations/20261114222527_code_change_repository_state_index/snapshot.json +70 -0
  190. package/migrations/20261115172605_attachment_kinds/snapshot.json +244 -0
  191. package/migrations/20261115173004_attachment_url_fill/snapshot.json +9 -0
  192. package/migrations/20261115180216_attachment_url_index/snapshot.json +62 -0
  193. package/migrations/20261116103700_plan_items/snapshot.json +420 -0
  194. package/migrations/20261117100100_automation_creator_slack_index/snapshot.json +62 -0
  195. package/migrations/20261117132522_conversation_event_search/snapshot.json +396 -0
  196. package/migrations/20261117164007_automation_last_run/snapshot.json +108 -0
  197. package/migrations/20261117164047_automation_last_run_index/snapshot.json +54 -0
  198. package/migrations/20261117210444_money_micro_usd/snapshot.json +68 -0
  199. package/migrations/20261117210505_conversation_cost_micro_usd/snapshot.json +9 -0
  200. package/migrations/20261118081416_people_list_metric_index/snapshot.json +86 -0
  201. package/migrations/20261118095216_automation_rollout_repair/snapshot.json +9 -0
  202. package/migrations/20261118143948_cache_warming_history_reset/snapshot.json +9 -0
  203. package/migrations/20261119040651_artifact_visibility/snapshot.json +132 -0
  204. package/migrations/20261119040715_artifact_public_sha_index/snapshot.json +9 -0
  205. package/migrations/20261119052706_artifact_drop_public/snapshot.json +71 -0
  206. package/migrations/20261119053831_artifact_path/snapshot.json +114 -0
  207. package/migrations/20261119053844_artifact_path_index/snapshot.json +9 -0
  208. package/migrations/20261119091949_review_item_answered_index/snapshot.json +70 -0
  209. package/migrations/20261119100029_review_item_status_index/snapshot.json +54 -0
  210. package/migrations/20261119165607_brief_outcome_status/snapshot.json +42 -0
  211. package/migrations/20261119165622_brief_outcome_status_backfill/snapshot.json +9 -0
  212. package/migrations/20261119213716_brief_created_at_index/snapshot.json +62 -0
  213. package/migrations/20261119222456_slack_person_search_index/snapshot.json +50 -0
  214. package/migrations/20261119225522_code_change_size/snapshot.json +104 -0
  215. package/migrations/20261119232253_merge_conflict_notice_dismiss/snapshot.json +9 -0
  216. package/migrations/20261119235649_inbox_snoozes/snapshot.json +605 -0
  217. package/migrations/20261120093118_code_change_search_index/snapshot.json +89 -0
  218. package/migrations/20261120093452_review_item_owner/snapshot.json +314 -0
  219. package/migrations/20261120185654_review_item_owner_index/snapshot.json +62 -0
  220. package/migrations/20261120185754_memory_core_adoption/snapshot.json +1184 -0
  221. package/migrations/20261120185854_memory_core_indexes/snapshot.json +70 -0
  222. package/migrations/20261120235226_todos/snapshot.json +473 -0
  223. package/migrations/20261121082316_inbox_items/snapshot.json +2026 -0
  224. package/migrations/20261121175651_todo_changed_by_agent/snapshot.json +42 -0
  225. package/migrations/20261121183527_inbox_item_subject_title_parts/snapshot.json +42 -0
  226. package/migrations/20261121194143_inbox_snooze_wake_reason/snapshot.json +42 -0
  227. package/migrations/20261121222400_authorization_request_index/snapshot.json +62 -0
  228. package/migrations/20261121225908_conversation_metadata/snapshot.json +184 -0
  229. package/migrations/20261121225910_conversation_metadata_fill/snapshot.json +9 -0
  230. package/migrations/20261121225913_conversation_search_index/snapshot.json +50 -0
  231. package/migrations/20261122022900_inbox_item_legacy_automation_keys/snapshot.json +9 -0
  232. package/migrations/20261122024454_artifact_expiry/snapshot.json +37 -0
  233. package/migrations/20261122024455_artifact_permanent_sha_index/snapshot.json +62 -0
  234. package/migrations/20261122024457_artifact_drop_public_sha_index/snapshot.json +37 -0
  235. package/migrations/20261122024458_conversation_kind_lead/snapshot.json +55 -0
  236. package/migrations/20261122024459_conversation_lead_actor_index/snapshot.json +54 -0
  237. package/migrations/20261122071549_keep_legacy_archive_columns/snapshot.json +49 -0
  238. package/migrations/20261122191400_conversation_embeddings_fk_validate/snapshot.json +9 -0
  239. package/migrations/20261122204325_money_micro_usd_repair/migration.sql +99 -0
  240. package/migrations/20261122204325_money_micro_usd_repair/snapshot.json +9 -0
  241. package/migrations/20261122204326_agent_config_backfill/migration.sql +34 -0
  242. package/migrations/20261122204326_agent_config_backfill/snapshot.json +143 -0
  243. package/migrations/20261122221456_inbox_item_deliveries/migration.sql +15 -0
  244. package/migrations/20261122221456_inbox_item_deliveries/snapshot.json +301 -0
  245. package/migrations/20261123155735_pg_trgm/migration.sql +2 -0
  246. package/migrations/20261123155735_pg_trgm/snapshot.json +9 -0
  247. package/migrations/20261123155739_search_indexes/migration.sql +4 -0
  248. package/migrations/20261123155739_search_indexes/snapshot.json +167 -0
  249. package/migrations/20261123172647_drop_legacy_archive_columns/migration.sql +4 -0
  250. package/migrations/20261123172647_drop_legacy_archive_columns/snapshot.json +9 -0
  251. package/migrations/20261123192506_memory_prefix_index/migration.sql +1 -0
  252. package/migrations/20261123192506_memory_prefix_index/snapshot.json +69 -0
  253. package/migrations/20261123201740_todo_search_indexes/migration.sql +2 -0
  254. package/migrations/20261123201740_todo_search_indexes/snapshot.json +89 -0
  255. package/migrations/20261123211505_todo_inbox_items/migration.sql +4 -0
  256. package/migrations/20261123211505_todo_inbox_items/snapshot.json +38 -0
  257. package/migrations/20261123214917_drop_code_urls/migration.sql +2 -0
  258. package/migrations/20261123214917_drop_code_urls/snapshot.json +44 -0
  259. package/migrations/20261123224000_code_change_conversations_index/migration.sql +1 -0
  260. package/migrations/20261123224000_code_change_conversations_index/snapshot.json +54 -0
  261. package/migrations/20261124122023_drop_code_change_sizes/migration.sql +4 -0
  262. package/migrations/20261124122023_drop_code_change_sizes/snapshot.json +82 -0
  263. package/migrations/20261124142958_conversation_root_lookup_index/migration.sql +1 -0
  264. package/migrations/20261124142958_conversation_root_lookup_index/snapshot.json +62 -0
  265. package/migrations/20261124183352_legacy_brief_metadata_fill/migration.sql +26 -0
  266. package/migrations/20261124183352_legacy_brief_metadata_fill/snapshot.json +114 -0
  267. package/migrations/20261124202143_drizzle_v1_baseline/migration.sql +5 -0
  268. package/migrations/20261124202143_drizzle_v1_baseline/snapshot.json +2012 -0
  269. package/migrations/20261124221751_spaces/migration.sql +22 -0
  270. package/migrations/20261124221751_spaces/snapshot.json +436 -0
  271. package/migrations/20261124230319_conversation_metrics_utc_day_stats/migration.sql +11 -0
  272. package/migrations/20261124230319_conversation_metrics_utc_day_stats/snapshot.json +9 -0
  273. package/migrations/20261124234024_space_conversations/migration.sql +5 -0
  274. package/migrations/20261124234024_space_conversations/snapshot.json +103 -0
  275. package/migrations/20261124234026_space_conversations_index/migration.sql +1 -0
  276. package/migrations/20261124234026_space_conversations_index/snapshot.json +62 -0
  277. package/migrations/20261125012448_drop_lead_actor_index/migration.sql +3 -0
  278. package/migrations/20261125012448_drop_lead_actor_index/snapshot.json +36 -0
  279. package/migrations/20261125012452_space_lead_index/migration.sql +1 -0
  280. package/migrations/20261125012452_space_lead_index/snapshot.json +54 -0
  281. package/migrations/20261125043821_space_configurations/migration.sql +11 -0
  282. package/migrations/20261125043821_space_configurations/snapshot.json +194 -0
  283. package/migrations/20261125064854_agent_update_done_status/migration.sql +9 -0
  284. package/migrations/20261125064854_agent_update_done_status/snapshot.json +9 -0
  285. package/migrations/20261125073321_turn_engine_tables/migration.sql +75 -0
  286. package/migrations/20261125073321_turn_engine_tables/snapshot.json +1497 -0
  287. package/migrations/20261125073339_turn_inbox_one_source/migration.sql +5 -0
  288. package/migrations/20261125073339_turn_inbox_one_source/snapshot.json +9 -0
  289. package/migrations/20261125124506_versions_notify/migration.sql +27 -0
  290. package/migrations/20261125124506_versions_notify/snapshot.json +9 -0
  291. package/migrations/20261125140339_turn_group_key/migration.sql +14 -0
  292. package/migrations/20261125140339_turn_group_key/snapshot.json +75 -0
  293. package/migrations/20261125140343_turn_group_key_not_null/migration.sql +4 -0
  294. package/migrations/20261125140343_turn_group_key_not_null/snapshot.json +29 -0
  295. package/migrations/20261125142845_code_change_requesters/migration.sql +1 -0
  296. package/migrations/20261125142845_code_change_requesters/snapshot.json +42 -0
  297. package/migrations/20261125142846_code_change_requesters_index/migration.sql +1 -0
  298. package/migrations/20261125142846_code_change_requesters_index/snapshot.json +54 -0
  299. package/migrations/20261125143903_space_visibility/migration.sql +1 -0
  300. package/migrations/20261125143903_space_visibility/snapshot.json +37 -0
  301. package/migrations/20261125154848_merge_leaves/migration.sql +2 -0
  302. package/migrations/20261125154848_merge_leaves/snapshot.json +14 -0
  303. package/package.json +17 -25
  304. package/skills/design-automation-skill/SKILL.md +3 -4
  305. package/dist/actor-BsBdxDXQ.js +0 -208
  306. package/dist/adapter-CYAvJzZS.js +0 -259
  307. package/dist/adapter-context-CVsHoVSf.js +0 -43
  308. package/dist/agent-runner-B5y9MsT-.js +0 -11295
  309. package/dist/background-compaction-queue-iZXadLV3.js +0 -206
  310. package/dist/catalog-runtime-kkE3hvCX.js +0 -6
  311. package/dist/config-CWbwKj0j.js +0 -2331
  312. package/dist/db-DYGcXYl3.d.ts +0 -274
  313. package/dist/db-PwSRzWWn.js +0 -3607
  314. package/dist/executor-CgWyWfYz.js +0 -1858
  315. package/dist/fan-out-Cod-yEHG.js +0 -10
  316. package/dist/history-CYstOMKX.js +0 -577
  317. package/dist/ingest-B0AggUEC.js +0 -7931
  318. package/dist/install-2urLLXNt.js +0 -228
  319. package/dist/proxy-path-BHYoKZdq.js +0 -15
  320. package/dist/registry-POH4bZC4.js +0 -1686
  321. package/dist/request-deadline-BUiRYQYj.js +0 -24
  322. package/dist/rule-DAxQY-1h.js +0 -20
  323. package/dist/schema-DBf18QPS.d.ts +0 -9339
  324. package/dist/service-account-o15pZWcJ.js +0 -931
  325. package/dist/start-conversation-DbVujrwO.js +0 -755
  326. package/dist/state-BTawTCme.js +0 -161
  327. package/dist/statuses-BKwqCPhj.js +0 -69
  328. package/dist/store-CjXrp-Up.js +0 -492
  329. package/dist/task-queue-Cwlatjz3.js +0 -90
  330. package/dist/vercel-queue-q4z8w5QO.js +0 -349
  331. package/dist/warmup-D5hzqTcp.js +0 -12257
  332. package/migrations/meta/0000_snapshot.json +0 -946
  333. package/migrations/meta/0001_snapshot.json +0 -972
  334. package/migrations/meta/0002_snapshot.json +0 -987
  335. package/migrations/meta/0003_snapshot.json +0 -1035
  336. package/migrations/meta/0004_snapshot.json +0 -1041
  337. package/migrations/meta/0005_snapshot.json +0 -948
  338. package/migrations/meta/0006_snapshot.json +0 -948
  339. package/migrations/meta/0007_snapshot.json +0 -1013
  340. package/migrations/meta/0008_snapshot.json +0 -1076
  341. package/migrations/meta/0009_snapshot.json +0 -1146
  342. package/migrations/meta/0010_snapshot.json +0 -1190
  343. package/migrations/meta/0011_snapshot.json +0 -1195
  344. package/migrations/meta/0012_snapshot.json +0 -1244
  345. package/migrations/meta/0013_snapshot.json +0 -1250
  346. package/migrations/meta/0014_snapshot.json +0 -1201
  347. package/migrations/meta/0015_snapshot.json +0 -1360
  348. package/migrations/meta/0016_snapshot.json +0 -1617
  349. package/migrations/meta/0017_snapshot.json +0 -1666
  350. package/migrations/meta/0018_snapshot.json +0 -1756
  351. package/migrations/meta/0019_snapshot.json +0 -1904
  352. package/migrations/meta/0020_snapshot.json +0 -1848
  353. package/migrations/meta/0021_snapshot.json +0 -2176
  354. package/migrations/meta/0022_snapshot.json +0 -2186
  355. package/migrations/meta/0023_snapshot.json +0 -2198
  356. package/migrations/meta/0024_snapshot.json +0 -2275
  357. package/migrations/meta/0025_snapshot.json +0 -2275
  358. package/migrations/meta/0026_snapshot.json +0 -2424
  359. package/migrations/meta/0027_snapshot.json +0 -2554
  360. package/migrations/meta/0028_snapshot.json +0 -2685
  361. package/migrations/meta/0029_snapshot.json +0 -2709
  362. package/migrations/meta/0030_snapshot.json +0 -2799
  363. package/migrations/meta/0031_snapshot.json +0 -2823
  364. package/migrations/meta/0032_snapshot.json +0 -2892
  365. package/migrations/meta/0033_snapshot.json +0 -2914
  366. package/migrations/meta/0034_snapshot.json +0 -3038
  367. package/migrations/meta/0035_snapshot.json +0 -3048
  368. package/migrations/meta/0036_snapshot.json +0 -3186
  369. package/migrations/meta/0037_snapshot.json +0 -3192
  370. package/migrations/meta/0038_snapshot.json +0 -3323
  371. package/migrations/meta/0039_snapshot.json +0 -3368
  372. package/migrations/meta/0040_snapshot.json +0 -3516
  373. package/migrations/meta/0041_snapshot.json +0 -3516
  374. package/migrations/meta/0042_snapshot.json +0 -3610
  375. package/migrations/meta/0043_snapshot.json +0 -3610
  376. package/migrations/meta/0044_snapshot.json +0 -3473
  377. package/migrations/meta/0045_snapshot.json +0 -3503
  378. package/migrations/meta/0046_snapshot.json +0 -3707
  379. package/migrations/meta/0047_snapshot.json +0 -3713
  380. package/migrations/meta/0048_snapshot.json +0 -3720
  381. package/migrations/meta/0049_snapshot.json +0 -3581
  382. package/migrations/meta/0050_snapshot.json +0 -3753
  383. package/migrations/meta/0051_snapshot.json +0 -3759
  384. package/migrations/meta/0052_snapshot.json +0 -3765
  385. package/migrations/meta/0053_snapshot.json +0 -3771
  386. package/migrations/meta/0054_snapshot.json +0 -3777
  387. package/migrations/meta/0055_snapshot.json +0 -3948
  388. package/migrations/meta/0056_snapshot.json +0 -4280
  389. package/migrations/meta/0057_snapshot.json +0 -3618
  390. package/migrations/meta/0058_snapshot.json +0 -3598
  391. package/migrations/meta/0059_snapshot.json +0 -3619
  392. package/migrations/meta/0060_snapshot.json +0 -3465
  393. package/migrations/meta/0061_snapshot.json +0 -3471
  394. package/migrations/meta/0062_snapshot.json +0 -3499
  395. package/migrations/meta/0063_snapshot.json +0 -3505
  396. package/migrations/meta/0064_snapshot.json +0 -3505
  397. package/migrations/meta/0065_snapshot.json +0 -3511
  398. package/migrations/meta/0066_snapshot.json +0 -4099
  399. package/migrations/meta/0067_snapshot.json +0 -3921
  400. package/migrations/meta/0068_snapshot.json +0 -4176
  401. package/migrations/meta/0069_snapshot.json +0 -3979
  402. package/migrations/meta/0070_snapshot.json +0 -3997
  403. package/migrations/meta/0071_snapshot.json +0 -4003
  404. package/migrations/meta/0072_snapshot.json +0 -4064
  405. package/migrations/meta/0073_snapshot.json +0 -4070
  406. package/migrations/meta/0074_snapshot.json +0 -4076
  407. package/migrations/meta/0075_snapshot.json +0 -4083
  408. package/migrations/meta/0076_snapshot.json +0 -4147
  409. package/migrations/meta/0077_snapshot.json +0 -4141
  410. package/migrations/meta/0078_snapshot.json +0 -4175
  411. package/migrations/meta/0079_snapshot.json +0 -4203
  412. package/migrations/meta/0080_snapshot.json +0 -4265
  413. package/migrations/meta/0081_snapshot.json +0 -4271
  414. package/migrations/meta/0082_snapshot.json +0 -4373
  415. package/migrations/meta/0083_snapshot.json +0 -4388
  416. package/migrations/meta/0084_snapshot.json +0 -4388
  417. package/migrations/meta/0085_snapshot.json +0 -4394
  418. package/migrations/meta/0086_snapshot.json +0 -4366
  419. package/migrations/meta/0087_snapshot.json +0 -4366
  420. package/migrations/meta/0088_snapshot.json +0 -4372
  421. package/migrations/meta/0089_snapshot.json +0 -4372
  422. package/migrations/meta/0090_snapshot.json +0 -4388
  423. package/migrations/meta/0091_snapshot.json +0 -4410
  424. package/migrations/meta/0092_snapshot.json +0 -4446
  425. package/migrations/meta/0093_snapshot.json +0 -4446
  426. package/migrations/meta/0094_snapshot.json +0 -4452
  427. package/migrations/meta/0095_snapshot.json +0 -4452
  428. package/migrations/meta/0096_snapshot.json +0 -4490
  429. package/migrations/meta/0097_snapshot.json +0 -4490
  430. package/migrations/meta/0098_snapshot.json +0 -4490
  431. package/migrations/meta/0099_snapshot.json +0 -4496
  432. package/migrations/meta/0100_snapshot.json +0 -4496
  433. package/migrations/meta/0101_snapshot.json +0 -4496
  434. package/migrations/meta/0102_snapshot.json +0 -4502
  435. package/migrations/meta/0103_snapshot.json +0 -4509
  436. package/migrations/meta/0104_snapshot.json +0 -4516
  437. package/migrations/meta/0105_snapshot.json +0 -4611
  438. package/migrations/meta/0106_snapshot.json +0 -4617
  439. package/migrations/meta/0107_snapshot.json +0 -4617
  440. package/migrations/meta/0108_snapshot.json +0 -4688
  441. package/migrations/meta/0109_snapshot.json +0 -4925
  442. package/migrations/meta/0110_snapshot.json +0 -4952
  443. package/migrations/meta/0111_snapshot.json +0 -5011
  444. package/migrations/meta/0112_snapshot.json +0 -5011
  445. package/migrations/meta/0113_snapshot.json +0 -5033
  446. package/migrations/meta/0114_snapshot.json +0 -5203
  447. package/migrations/meta/0115_snapshot.json +0 -5225
  448. package/migrations/meta/0116_snapshot.json +0 -5388
  449. package/migrations/meta/0117_snapshot.json +0 -5413
  450. package/migrations/meta/0118_snapshot.json +0 -5428
  451. package/migrations/meta/0119_snapshot.json +0 -5441
  452. package/migrations/meta/0120_snapshot.json +0 -5441
  453. package/migrations/meta/0121_snapshot.json +0 -5481
  454. package/migrations/meta/0122_snapshot.json +0 -5481
  455. package/migrations/meta/0123_snapshot.json +0 -5481
  456. package/migrations/meta/0124_snapshot.json +0 -5516
  457. package/migrations/meta/0125_snapshot.json +0 -5516
  458. package/migrations/meta/0126_snapshot.json +0 -5488
  459. package/migrations/meta/0127_snapshot.json +0 -5519
  460. package/migrations/meta/0128_snapshot.json +0 -5519
  461. package/migrations/meta/0129_snapshot.json +0 -5547
  462. package/migrations/meta/0130_snapshot.json +0 -5563
  463. package/migrations/meta/0131_snapshot.json +0 -5569
  464. package/migrations/meta/0132_snapshot.json +0 -5569
  465. package/migrations/meta/0133_snapshot.json +0 -5590
  466. package/migrations/meta/0134_snapshot.json +0 -5606
  467. package/migrations/meta/0135_snapshot.json +0 -5624
  468. package/migrations/meta/0136_snapshot.json +0 -5624
  469. package/migrations/meta/0137_snapshot.json +0 -5864
  470. package/migrations/meta/0138_snapshot.json +0 -5894
  471. package/migrations/meta/0139_snapshot.json +0 -5898
  472. package/migrations/meta/0140_snapshot.json +0 -5919
  473. package/migrations/meta/0141_snapshot.json +0 -6429
  474. package/migrations/meta/0142_snapshot.json +0 -6457
  475. package/migrations/meta/0143_snapshot.json +0 -6434
  476. package/migrations/meta/0144_snapshot.json +0 -6434
  477. package/migrations/meta/0145_snapshot.json +0 -6440
  478. package/migrations/meta/0146_snapshot.json +0 -6446
  479. package/migrations/meta/0147_snapshot.json +0 -6452
  480. package/migrations/meta/0148_snapshot.json +0 -6474
  481. package/migrations/meta/0149_snapshot.json +0 -6490
  482. package/migrations/meta/0150_snapshot.json +0 -6490
  483. package/migrations/meta/0151_snapshot.json +0 -6505
  484. package/migrations/meta/0152_snapshot.json +0 -6505
  485. package/migrations/meta/0153_snapshot.json +0 -6511
  486. package/migrations/meta/0154_snapshot.json +0 -6533
  487. package/migrations/meta/0155_snapshot.json +0 -6511
  488. package/migrations/meta/0156_snapshot.json +0 -6511
  489. package/migrations/meta/0157_snapshot.json +0 -6527
  490. package/migrations/meta/0158_snapshot.json +0 -6515
  491. package/migrations/meta/0159_snapshot.json +0 -6515
  492. package/migrations/meta/_journal.json +0 -1126
  493. /package/migrations/{0000_initial.sql → 20260711145847_initial/migration.sql} +0 -0
  494. /package/migrations/{0001_conversation_metrics.sql → 20260711145900_conversation_metrics/migration.sql} +0 -0
  495. /package/migrations/{0002_conversation_message_search.sql → 20260712153649_conversation_message_search/migration.sql} +0 -0
  496. /package/migrations/{0003_peaceful_scalphunter.sql → 20260713040256_peaceful_scalphunter/migration.sql} +0 -0
  497. /package/migrations/{0004_useful_magus.sql → 20260715174202_useful_magus/migration.sql} +0 -0
  498. /package/migrations/{0005_conversation_events.sql → 20260715174203_conversation_events/migration.sql} +0 -0
  499. /package/migrations/{0006_drop_legacy_conversation_messages.sql → 20260723042835_drop_legacy_conversation_messages/migration.sql} +0 -0
  500. /package/migrations/{0007_thick_sugar_man.sql → 20260723050612_thick_sugar_man/migration.sql} +0 -0
  501. /package/migrations/{0008_sticky_rage.sql → 20260727223822_sticky_rage/migration.sql} +0 -0
  502. /package/migrations/{0009_slippery_harrier.sql → 20260728033158_slippery_harrier/migration.sql} +0 -0
  503. /package/migrations/{0010_native_conversation_history.sql → 20260728040836_native_conversation_history/migration.sql} +0 -0
  504. /package/migrations/{0011_sour_golden_guardian.sql → 20260728204900_sour_golden_guardian/migration.sql} +0 -0
  505. /package/migrations/{0012_structured_conversation_events.sql → 20260730233332_structured_conversation_events/migration.sql} +0 -0
  506. /package/migrations/{0013_conversation_session_source.sql → 20260731164038_conversation_session_source/migration.sql} +0 -0
  507. /package/migrations/{0014_source_visibility.sql → 20260801230336_source_visibility/migration.sql} +0 -0
  508. /package/migrations/{0015_magical_ezekiel_stane.sql → 20260802023731_magical_ezekiel_stane/migration.sql} +0 -0
  509. /package/migrations/{0016_neat_the_anarchist.sql → 20260804015843_neat_the_anarchist/migration.sql} +0 -0
  510. /package/migrations/{0017_drop_paused_scheduled_tasks.sql → 20260804165952_drop_paused_scheduled_tasks/migration.sql} +0 -0
  511. /package/migrations/{0018_curvy_excalibur.sql → 20260804225613_curvy_excalibur/migration.sql} +0 -0
  512. /package/migrations/{0019_lowly_valkyrie.sql → 20260805174033_lowly_valkyrie/migration.sql} +0 -0
  513. /package/migrations/{0020_restrict_task_execution_kinds.sql → 20260805200301_restrict_task_execution_kinds/migration.sql} +0 -0
  514. /package/migrations/{0021_first_warhawk.sql → 20260806030729_first_warhawk/migration.sql} +0 -0
  515. /package/migrations/{0022_task_execution_status.sql → 20260807185200_task_execution_status/migration.sql} +0 -0
  516. /package/migrations/{0023_task_title_columns.sql → 20260808014743_task_title_columns/migration.sql} +0 -0
  517. /package/migrations/{0024_misty_typhoid_mary.sql → 20260809220421_misty_typhoid_mary/migration.sql} +0 -0
  518. /package/migrations/{0025_mcp_credential_subject.sql → 20260811193709_mcp_credential_subject/migration.sql} +0 -0
  519. /package/migrations/{0026_conversation_event_actor_and_participants.sql → 20260812032924_conversation_event_actor_and_participants/migration.sql} +0 -0
  520. /package/migrations/{0027_attachment_storage.sql → 20260812172418_attachment_storage/migration.sql} +0 -0
  521. /package/migrations/{0028_artifacts.sql → 20260813230732_artifacts/migration.sql} +0 -0
  522. /package/migrations/{0029_dizzy_barracuda.sql → 20260814062905_dizzy_barracuda/migration.sql} +0 -0
  523. /package/migrations/{0030_drop_workspace_repo_primary.sql → 20260814231353_drop_workspace_repo_primary/migration.sql} +0 -0
  524. /package/migrations/{0031_wild_phantom_reporter.sql → 20260815030100_wild_phantom_reporter/migration.sql} +0 -0
  525. /package/migrations/{0032_workspace_snapshots_table.sql → 20260817082233_workspace_snapshots_table/migration.sql} +0 -0
  526. /package/migrations/{0033_workspace_snapshot_active_build.sql → 20260818160339_workspace_snapshot_active_build/migration.sql} +0 -0
  527. /package/migrations/{0034_strong_randall.sql → 20260821180755_strong_randall/migration.sql} +0 -0
  528. /package/migrations/{0035_workspace_snapshot_size_bytes.sql → 20260823030308_workspace_snapshot_size_bytes/migration.sql} +0 -0
  529. /package/migrations/{0036_complex_rage.sql → 20260824190313_complex_rage/migration.sql} +0 -0
  530. /package/migrations/{0037_conversation_location.sql → 20260827233711_conversation_location/migration.sql} +0 -0
  531. /package/migrations/{0038_event_task_status.sql → 20260901224306_event_task_status/migration.sql} +0 -0
  532. /package/migrations/{0039_attachment_provider.sql → 20260904153232_attachment_provider/migration.sql} +0 -0
  533. /package/migrations/{0040_conversation_briefs.sql → 20260909111415_conversation_briefs/migration.sql} +0 -0
  534. /package/migrations/{0041_automation_outcomes_backfill.sql → 20260910144928_automation_outcomes_backfill/migration.sql} +0 -0
  535. /package/migrations/{0042_conversation_metrics.sql → 20260911184346_conversation_metrics/migration.sql} +0 -0
  536. /package/migrations/{0043_scheduled_automation_channel_destinations.sql → 20260921140842_scheduled_automation_channel_destinations/migration.sql} +0 -0
  537. /package/migrations/{0044_event_automation_channel_destinations.sql → 20260922221709_event_automation_channel_destinations/migration.sql} +0 -0
  538. /package/migrations/{0045_conversation_forks.sql → 20261001113455_conversation_forks/migration.sql} +0 -0
  539. /package/migrations/{0046_automation_versions.sql → 20261005161844_automation_versions/migration.sql} +0 -0
  540. /package/migrations/{0047_user_timezone.sql → 20261006152043_user_timezone/migration.sql} +0 -0
  541. /package/migrations/{0048_user_admin.sql → 20261008200858_user_admin/migration.sql} +0 -0
  542. /package/migrations/{0049_event_automation_status_reason.sql → 20261009145407_event_automation_status_reason/migration.sql} +0 -0
  543. /package/migrations/{0050_agent_invocation_parent_mailbox.sql → 20261013160816_agent_invocation_parent_mailbox/migration.sql} +0 -0
  544. /package/migrations/{0051_agent_invocation_parent_tool_call.sql → 20261013215020_agent_invocation_parent_tool_call/migration.sql} +0 -0
  545. /package/migrations/{0052_agent_invocation_title.sql → 20261014011138_agent_invocation_title/migration.sql} +0 -0
  546. /package/migrations/{0053_conversation_stopped_at.sql → 20261014211942_conversation_stopped_at/migration.sql} +0 -0
  547. /package/migrations/{0054_flowery_rage.sql → 20261015012820_flowery_rage/migration.sql} +0 -0
  548. /package/migrations/{0055_automations.sql → 20261017000924_automations/migration.sql} +0 -0
  549. /package/migrations/{0056_automation_runs.sql → 20261017134736_automation_runs/migration.sql} +0 -0
  550. /package/migrations/{0057_drop_legacy_automation_tables.sql → 20261017170250_drop_legacy_automation_tables/migration.sql} +0 -0
  551. /package/migrations/{0058_automation_creator_identity.sql → 20261018134754_automation_creator_identity/migration.sql} +0 -0
  552. /package/migrations/{0059_automation_run_version.sql → 20261023071954_automation_run_version/migration.sql} +0 -0
  553. /package/migrations/{0060_identity_signed_in_at.sql → 20261025233137_identity_signed_in_at/migration.sql} +0 -0
  554. /package/migrations/{0061_workspace_vcpus.sql → 20261027234315_workspace_vcpus/migration.sql} +0 -0
  555. /package/migrations/{0062_plugin_report_index.sql → 20261028124242_plugin_report_index/migration.sql} +0 -0
  556. /package/migrations/{0063_agent_invocation_type.sql → 20261028154230_agent_invocation_type/migration.sql} +0 -0
  557. /package/migrations/{0064_any_resource_event_triggers.sql → 20261030021803_any_resource_event_triggers/migration.sql} +0 -0
  558. /package/migrations/{0065_user_customization.sql → 20261030234309_user_customization/migration.sql} +0 -0
  559. /package/migrations/{0066_review_items.sql → 20261031020656_review_items/migration.sql} +0 -0
  560. /package/migrations/{0067_review_item_dedupe_tenant.sql → 20261031024151_review_item_dedupe_tenant/migration.sql} +0 -0
  561. /package/migrations/{0068_review_item_slack_cards.sql → 20261031024246_review_item_slack_cards/migration.sql} +0 -0
  562. /package/migrations/{0069_system_identity.sql → 20261031155308_system_identity/migration.sql} +0 -0
  563. /package/migrations/{0070_review_item_foreign_keys.sql → 20261101193952_review_item_foreign_keys/migration.sql} +0 -0
  564. /package/migrations/{0071_review_item_turn.sql → 20261102172751_review_item_turn/migration.sql} +0 -0
  565. /package/migrations/{0072_conversation_read_positions.sql → 20261102221411_conversation_read_positions/migration.sql} +0 -0
  566. /package/migrations/{0073_conversation_quick_question.sql → 20261104085028_conversation_quick_question/migration.sql} +0 -0
  567. /package/migrations/{0074_conversation_participant_pins.sql → 20261104145136_conversation_participant_pins/migration.sql} +0 -0
  568. /package/migrations/{0075_conversation_detail_version.sql → 20261104164429_conversation_detail_version/migration.sql} +0 -0
  569. /package/migrations/{0076_conversation_auto_archive.sql → 20261104172055_conversation_auto_archive/migration.sql} +0 -0
  570. /package/migrations/{0077_drop_agent_invocation_model_profile.sql → 20261105005443_drop_agent_invocation_model_profile/migration.sql} +0 -0
  571. /package/migrations/{0078_plugin_conversation_index.sql → 20261105043807_plugin_conversation_index/migration.sql} +0 -0
  572. /package/migrations/{0079_conversation_event_author_index.sql → 20261105051837_conversation_event_author_index/migration.sql} +0 -0
  573. /package/migrations/{0080_conversation_event_latest_message_indexes.sql → 20261105182854_conversation_event_latest_message_indexes/migration.sql} +0 -0
  574. /package/migrations/{0081_conversation_pin_position.sql → 20261106011443_conversation_pin_position/migration.sql} +0 -0
  575. /package/migrations/{0082_push_notifications.sql → 20261106095004_push_notifications/migration.sql} +0 -0
  576. /package/migrations/{0083_conversation_kind.sql → 20261106162740_conversation_kind/migration.sql} +0 -0
  577. /package/migrations/{0084_read_position_backfill.sql → 20261107002001_read_position_backfill/migration.sql} +0 -0
  578. /package/migrations/{0085_child_archived_at.sql → 20261107025209_child_archived_at/migration.sql} +0 -0
  579. /package/migrations/{0086_shared_archive.sql → 20261107035735_shared_archive/migration.sql} +0 -0
  580. /package/migrations/{0087_child_location.sql → 20261107215055_child_location/migration.sql} +0 -0
  581. /package/migrations/{0088_conversation_unsubscribe.sql → 20261108191927_conversation_unsubscribe/migration.sql} +0 -0
  582. /package/migrations/{0089_conversation_paused_status.sql → 20261109021618_conversation_paused_status/migration.sql} +0 -0
  583. /package/migrations/{0090_guardian_review_time_index.sql → 20261109111553_guardian_review_time_index/migration.sql} +0 -0
  584. /package/migrations/{0091_conversation_participant_unsubscribed_index.sql → 20261109173130_conversation_participant_unsubscribed_index/migration.sql} +0 -0
  585. /package/migrations/{0092_turn_metric_actor.sql → 20261109182006_turn_metric_actor/migration.sql} +0 -0
  586. /package/migrations/{0093_participant_root_actor_backfill.sql → 20261109202836_participant_root_actor_backfill/migration.sql} +0 -0
  587. /package/migrations/{0094_conversation_delivery_paused_at.sql → 20261109232640_conversation_delivery_paused_at/migration.sql} +0 -0
  588. /package/migrations/{0095_web_linked_slack_identity_repair.sql → 20261110120937_web_linked_slack_identity_repair/migration.sql} +0 -0
  589. /package/migrations/{0096_automation_task_kind.sql → 20261110175824_automation_task_kind/migration.sql} +0 -0
  590. /package/migrations/{0097_conversation_kind_automation.sql → 20261110210242_conversation_kind_automation/migration.sql} +0 -0
  591. /package/migrations/{0098_review_item_plugin_actions.sql → 20261110222632_review_item_plugin_actions/migration.sql} +0 -0
  592. /package/migrations/{0099_conversation_last_message_at.sql → 20261110225157_conversation_last_message_at/migration.sql} +0 -0
  593. /package/migrations/{0100_automation_task_kind_repair.sql → 20261111013351_automation_task_kind_repair/migration.sql} +0 -0
  594. /package/migrations/{0101_drop_legacy_columns.sql → 20261111163126_drop_legacy_columns/migration.sql} +0 -0
  595. /package/migrations/{0102_code_change_last_activity.sql → 20261111170150_code_change_last_activity/migration.sql} +0 -0
  596. /package/migrations/{0103_agent_invocation_fork.sql → 20261111191441_agent_invocation_fork/migration.sql} +0 -0
  597. /package/migrations/{0104_code_change_draft.sql → 20261112142841_code_change_draft/migration.sql} +0 -0
  598. /package/migrations/{0105_attachment_uploads.sql → 20261112202901_attachment_uploads/migration.sql} +0 -0
  599. /package/migrations/{0106_conversation_agent_config.sql → 20261112220407_conversation_agent_config/migration.sql} +0 -0
  600. /package/migrations/{0107_attachment_deferred_download.sql → 20261113081247_attachment_deferred_download/migration.sql} +0 -0
  601. /package/migrations/{0108_conversation_embeddings.sql → 20261113225551_conversation_embeddings/migration.sql} +0 -0
  602. /package/migrations/{0109_user_preferences.sql → 20261114213238_user_preferences/migration.sql} +0 -0
  603. /package/migrations/{0110_code_change_repository_state_index.sql → 20261114222527_code_change_repository_state_index/migration.sql} +0 -0
  604. /package/migrations/{0111_attachment_kinds.sql → 20261115172605_attachment_kinds/migration.sql} +0 -0
  605. /package/migrations/{0112_attachment_url_fill.sql → 20261115173004_attachment_url_fill/migration.sql} +0 -0
  606. /package/migrations/{0113_attachment_url_index.sql → 20261115180216_attachment_url_index/migration.sql} +0 -0
  607. /package/migrations/{0114_plan_items.sql → 20261116103700_plan_items/migration.sql} +0 -0
  608. /package/migrations/{0115_automation_creator_slack_index.sql → 20261117100100_automation_creator_slack_index/migration.sql} +0 -0
  609. /package/migrations/{0116_conversation_event_search.sql → 20261117132522_conversation_event_search/migration.sql} +0 -0
  610. /package/migrations/{0117_automation_last_run.sql → 20261117164007_automation_last_run/migration.sql} +0 -0
  611. /package/migrations/{0118_automation_last_run_index.sql → 20261117164047_automation_last_run_index/migration.sql} +0 -0
  612. /package/migrations/{0119_money_micro_usd.sql → 20261117210444_money_micro_usd/migration.sql} +0 -0
  613. /package/migrations/{0120_conversation_cost_micro_usd.sql → 20261117210505_conversation_cost_micro_usd/migration.sql} +0 -0
  614. /package/migrations/{0121_people_list_metric_index.sql → 20261118081416_people_list_metric_index/migration.sql} +0 -0
  615. /package/migrations/{0122_automation_rollout_repair.sql → 20261118095216_automation_rollout_repair/migration.sql} +0 -0
  616. /package/migrations/{0123_cache_warming_history_reset.sql → 20261118143948_cache_warming_history_reset/migration.sql} +0 -0
  617. /package/migrations/{0124_artifact_visibility.sql → 20261119040651_artifact_visibility/migration.sql} +0 -0
  618. /package/migrations/{0125_artifact_public_sha_index.sql → 20261119040715_artifact_public_sha_index/migration.sql} +0 -0
  619. /package/migrations/{0126_artifact_drop_public.sql → 20261119052706_artifact_drop_public/migration.sql} +0 -0
  620. /package/migrations/{0127_artifact_path.sql → 20261119053831_artifact_path/migration.sql} +0 -0
  621. /package/migrations/{0128_artifact_path_index.sql → 20261119053844_artifact_path_index/migration.sql} +0 -0
  622. /package/migrations/{0129_review_item_answered_index.sql → 20261119091949_review_item_answered_index/migration.sql} +0 -0
  623. /package/migrations/{0130_review_item_status_index.sql → 20261119100029_review_item_status_index/migration.sql} +0 -0
  624. /package/migrations/{0131_brief_outcome_status.sql → 20261119165607_brief_outcome_status/migration.sql} +0 -0
  625. /package/migrations/{0132_brief_outcome_status_backfill.sql → 20261119165622_brief_outcome_status_backfill/migration.sql} +0 -0
  626. /package/migrations/{0133_brief_created_at_index.sql → 20261119213716_brief_created_at_index/migration.sql} +0 -0
  627. /package/migrations/{0134_slack_person_search_index.sql → 20261119222456_slack_person_search_index/migration.sql} +0 -0
  628. /package/migrations/{0135_code_change_size.sql → 20261119225522_code_change_size/migration.sql} +0 -0
  629. /package/migrations/{0136_merge_conflict_notice_dismiss.sql → 20261119232253_merge_conflict_notice_dismiss/migration.sql} +0 -0
  630. /package/migrations/{0137_inbox_snoozes.sql → 20261119235649_inbox_snoozes/migration.sql} +0 -0
  631. /package/migrations/{0138_code_change_search_index.sql → 20261120093118_code_change_search_index/migration.sql} +0 -0
  632. /package/migrations/{0139_review_item_owner.sql → 20261120093452_review_item_owner/migration.sql} +0 -0
  633. /package/migrations/{0140_review_item_owner_index.sql → 20261120185654_review_item_owner_index/migration.sql} +0 -0
  634. /package/migrations/{0141_memory_core_adoption.sql → 20261120185754_memory_core_adoption/migration.sql} +0 -0
  635. /package/migrations/{0142_memory_core_indexes.sql → 20261120185854_memory_core_indexes/migration.sql} +0 -0
  636. /package/migrations/{0143_todos.sql → 20261120235226_todos/migration.sql} +0 -0
  637. /package/migrations/{0144_inbox_items.sql → 20261121082316_inbox_items/migration.sql} +0 -0
  638. /package/migrations/{0145_todo_changed_by_agent.sql → 20261121175651_todo_changed_by_agent/migration.sql} +0 -0
  639. /package/migrations/{0146_inbox_item_subject_title_parts.sql → 20261121183527_inbox_item_subject_title_parts/migration.sql} +0 -0
  640. /package/migrations/{0147_inbox_snooze_wake_reason.sql → 20261121194143_inbox_snooze_wake_reason/migration.sql} +0 -0
  641. /package/migrations/{0148_authorization_request_index.sql → 20261121222400_authorization_request_index/migration.sql} +0 -0
  642. /package/migrations/{0149_conversation_metadata.sql → 20261121225908_conversation_metadata/migration.sql} +0 -0
  643. /package/migrations/{0150_conversation_metadata_fill.sql → 20261121225910_conversation_metadata_fill/migration.sql} +0 -0
  644. /package/migrations/{0151_conversation_search_index.sql → 20261121225913_conversation_search_index/migration.sql} +0 -0
  645. /package/migrations/{0152_inbox_item_legacy_automation_keys.sql → 20261122022900_inbox_item_legacy_automation_keys/migration.sql} +0 -0
  646. /package/migrations/{0153_artifact_expiry.sql → 20261122024454_artifact_expiry/migration.sql} +0 -0
  647. /package/migrations/{0154_artifact_permanent_sha_index.sql → 20261122024455_artifact_permanent_sha_index/migration.sql} +0 -0
  648. /package/migrations/{0155_artifact_drop_public_sha_index.sql → 20261122024457_artifact_drop_public_sha_index/migration.sql} +0 -0
  649. /package/migrations/{0156_conversation_kind_lead.sql → 20261122024458_conversation_kind_lead/migration.sql} +0 -0
  650. /package/migrations/{0157_conversation_lead_actor_index.sql → 20261122024459_conversation_lead_actor_index/migration.sql} +0 -0
  651. /package/migrations/{0158_keep_legacy_archive_columns.sql → 20261122071549_keep_legacy_archive_columns/migration.sql} +0 -0
  652. /package/migrations/{0159_conversation_embeddings_fk_validate.sql → 20261122191400_conversation_embeddings_fk_validate/migration.sql} +0 -0
@@ -1,931 +0,0 @@
1
- import { b as setSpanAttributes, h as logWarn } from "./logging-DNt-qOIO.js";
2
- import { i as resolvePluginHeaderEnvRefs, l as fetchWithBoundedOAuthErrorBodies } from "./registry-POH4bZC4.js";
3
- import { i as getStateAdapter } from "./adapter-CYAvJzZS.js";
4
- import { I as MUTATION_LOCK_TTL_MS, R as fenceLock, n as botConfig, z as withLock } from "./config-CWbwKj0j.js";
5
- import { n as readEncryptedState, r as findLegacyWebActorUserId, t as createEncryptedState } from "./state-BTawTCme.js";
6
- import { t as mapBounded } from "./fan-out-Cod-yEHG.js";
7
- import * as z from "zod";
8
- import { AsyncLocalStorage } from "node:async_hooks";
9
- import { randomUUID } from "node:crypto";
10
- import { destinationSchema, sourceSchema } from "@sentry/junior-plugin-api";
11
- import { UnauthorizedError, auth } from "@modelcontextprotocol/sdk/client/auth.js";
12
- import { Client } from "@modelcontextprotocol/sdk/client";
13
- import { StreamableHTTPClientTransport, StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
14
- // src/chat/mcp/errors.ts
15
- /** Safe failure at an MCP network or OAuth boundary. */
16
- var McpProviderError = class extends Error {
17
- phase;
18
- provider;
19
- missingSession;
20
- resourceHost;
21
- status;
22
- constructor(details) {
23
- super(`MCP provider ${details.phase.replace("_", " ")} failed`);
24
- this.name = "McpProviderError";
25
- this.phase = details.phase;
26
- this.provider = details.provider;
27
- this.missingSession = details.missingSession;
28
- this.resourceHost = details.resourceHost;
29
- this.status = details.status;
30
- }
31
- };
32
- function providerStatus(error) {
33
- if (!error || typeof error !== "object") return;
34
- const value = error;
35
- const status = typeof value.status === "number" ? value.status : typeof value.code === "number" ? value.code : void 0;
36
- return status !== void 0 && status >= 100 && status <= 599 ? status : void 0;
37
- }
38
- /** Replace an external MCP failure without retaining its provider-controlled cause. */
39
- function toMcpProviderError(error, details) {
40
- if (error instanceof McpProviderError) return error;
41
- return new McpProviderError({
42
- ...details,
43
- status: details.status ?? providerStatus(error)
44
- });
45
- }
46
- /** Return safe MCP provider fields for logs and spans. */
47
- function getMcpProviderErrorAttributes(error) {
48
- if (!(error instanceof McpProviderError)) return {};
49
- return {
50
- "app.credential.provider": error.provider,
51
- "app.mcp.error.phase": error.phase,
52
- ...error.status !== void 0 ? { "http.response.status_code": error.status } : void 0,
53
- ...error.resourceHost ? { "server.address": error.resourceHost } : void 0
54
- };
55
- }
56
- /** Thrown when an MCP failure should be returned as a model-visible tool error. */
57
- var McpToolError = class extends Error {
58
- constructor(message) {
59
- super(message);
60
- this.name = "McpToolError";
61
- }
62
- };
63
- /**
64
- * Thrown when a plugin uses only its service account and no Admin has
65
- * connected it. The model can tell the person to ask an Admin.
66
- */
67
- var McpServiceAccountRequiredError = class extends McpToolError {
68
- provider;
69
- constructor(provider, displayName) {
70
- super(`${displayName} is not available yet. This app uses a shared ${displayName} account for everyone, and an admin must connect it on the dashboard Admin page.`);
71
- this.name = "McpServiceAccountRequiredError";
72
- this.provider = provider;
73
- }
74
- };
75
- /** Return the OpenTelemetry error.type value for MCP-aware tool failures. */
76
- function getMcpAwareErrorType(error, fallback) {
77
- if (error instanceof McpToolError) return "tool_error";
78
- if (error instanceof McpProviderError) return "mcp_provider_error";
79
- return error instanceof Error ? error.name : fallback;
80
- }
81
- /** Return the display-safe error message for MCP-aware tool failures. */
82
- function getMcpAwareErrorMessage(error) {
83
- return error instanceof Error ? error.message : String(error);
84
- }
85
- /** Return an error message safe for logs and span attributes. */
86
- function getMcpAwareTelemetryMessage(error, _privacy) {
87
- if (error instanceof McpToolError) return "MCP tool call failed";
88
- if (error instanceof McpProviderError) return error.message;
89
- return getMcpAwareErrorMessage(error);
90
- }
91
- // src/chat/mcp/auth-store.ts
92
- const MCP_AUTH_SESSION_PREFIX = "junior:mcp_oauth_attempt:v2";
93
- const MCP_AUTH_CREDENTIALS_PREFIX = "junior:mcp_auth_credentials";
94
- const MCP_AUTH_SESSION_INDEX_PREFIX = "junior:mcp_oauth_attempt_index:v2";
95
- const MCP_SERVER_SESSION_PREFIX = "junior:mcp_server_session";
96
- const MCP_AUTH_SESSION_TTL_MS = 864e5;
97
- const MCP_AUTH_CREDENTIALS_TTL_MS = 2592e6;
98
- const MCP_SERVER_SESSION_TTL_MS = 864e5;
99
- function sessionKey(authSessionId) {
100
- return `${MCP_AUTH_SESSION_PREFIX}:${authSessionId}`;
101
- }
102
- function credentialsKey(userId, provider) {
103
- return `${MCP_AUTH_CREDENTIALS_PREFIX}:${userId}:${provider}`;
104
- }
105
- function sessionIndexKey(userId, provider) {
106
- return `${MCP_AUTH_SESSION_INDEX_PREFIX}:${userId}:${provider}`;
107
- }
108
- function serverSessionKey(userId, provider) {
109
- return `${MCP_SERVER_SESSION_PREFIX}:${userId}:${provider}`;
110
- }
111
- function parseSessionIndex(value) {
112
- if (typeof value !== "string") return [];
113
- try {
114
- const parsed = JSON.parse(value);
115
- if (!Array.isArray(parsed)) return [];
116
- return [...new Set(parsed.filter((id) => typeof id === "string"))];
117
- } catch {
118
- return [];
119
- }
120
- }
121
- const optionalStoredString = z.string().optional().catch(void 0);
122
- const mcpAuthSessionSchema = z.object({
123
- schemaVersion: z.literal(2),
124
- authSessionId: z.string(),
125
- provider: z.string(),
126
- userId: z.string(),
127
- conversationId: z.string(),
128
- destination: destinationSchema.optional(),
129
- source: sourceSchema.optional(),
130
- sessionId: z.string(),
131
- userMessage: z.string(),
132
- channelId: optionalStoredString,
133
- threadTs: optionalStoredString,
134
- toolChannelId: optionalStoredString,
135
- configuration: z.record(z.string(), z.unknown()).optional().catch(void 0),
136
- authorizationUrl: optionalStoredString,
137
- codeVerifier: optionalStoredString,
138
- createdAtMs: z.number(),
139
- updatedAtMs: z.number()
140
- });
141
- function parseMcpAuthSession(value) {
142
- const parsed = mcpAuthSessionSchema.safeParse(value);
143
- return parsed.success ? parsed.data : void 0;
144
- }
145
- const serverSessionSchema = z.object({
146
- sessionId: z.string(),
147
- updatedAtMs: z.number()
148
- });
149
- function parseServerSession(value) {
150
- if (typeof value !== "string") return;
151
- try {
152
- const parsed = serverSessionSchema.safeParse(JSON.parse(value));
153
- return parsed.success ? parsed.data : void 0;
154
- } catch {
155
- return;
156
- }
157
- }
158
- const storedOAuthClientInformationSchema$1 = z.custom((value) => typeof value === "object" && value !== null);
159
- const storedOAuthDiscoveryStateSchema$1 = z.custom((value) => typeof value === "object" && value !== null);
160
- const storedOAuthTokensSchema$1 = z.custom((value) => typeof value === "object" && value !== null);
161
- const storedCredentialsSchema = z.object({
162
- clientInformation: storedOAuthClientInformationSchema$1.optional().catch(void 0),
163
- discoveryState: storedOAuthDiscoveryStateSchema$1.optional().catch(void 0),
164
- tokens: storedOAuthTokensSchema$1.optional().catch(void 0)
165
- });
166
- function parseStoredCredentials(value) {
167
- try {
168
- const parsed = storedCredentialsSchema.safeParse(typeof value === "string" ? JSON.parse(value) : value);
169
- return parsed.success ? parsed.data : void 0;
170
- } catch {
171
- return;
172
- }
173
- }
174
- async function readMcpAuthSession(stateAdapter, authSessionId) {
175
- const stored = await readEncryptedState(stateAdapter, sessionKey(authSessionId));
176
- if (stored?.stale && typeof stored.value === "string") try {
177
- return JSON.parse(stored.value);
178
- } catch {
179
- return;
180
- }
181
- return stored?.value;
182
- }
183
- async function getConnectedStateAdapter() {
184
- const stateAdapter = getStateAdapter();
185
- await stateAdapter.connect();
186
- return stateAdapter;
187
- }
188
- async function getMcpAuthSession(authSessionId) {
189
- return parseMcpAuthSession(await readMcpAuthSession(await getConnectedStateAdapter(), authSessionId));
190
- }
191
- async function putMcpAuthSession(session, ttlMs = MCP_AUTH_SESSION_TTL_MS) {
192
- const stateAdapter = await getConnectedStateAdapter();
193
- await createEncryptedState(stateAdapter).set(sessionKey(session.authSessionId), session, ttlMs);
194
- const nextIndex = parseSessionIndex(await stateAdapter.get(sessionIndexKey(session.userId, session.provider)));
195
- if (!nextIndex.includes(session.authSessionId)) nextIndex.push(session.authSessionId);
196
- await stateAdapter.set(sessionIndexKey(session.userId, session.provider), JSON.stringify(nextIndex), ttlMs);
197
- }
198
- async function patchMcpAuthSession(authSessionId, patch) {
199
- const current = await getMcpAuthSession(authSessionId);
200
- if (!current) throw new Error(`Unknown MCP auth session: ${authSessionId}`);
201
- const next = {
202
- ...current,
203
- ...patch,
204
- schemaVersion: 2,
205
- authSessionId: current.authSessionId,
206
- provider: current.provider,
207
- userId: current.userId,
208
- conversationId: current.conversationId,
209
- ...current.destination ? { destination: current.destination } : void 0,
210
- sessionId: current.sessionId,
211
- userMessage: current.userMessage,
212
- createdAtMs: current.createdAtMs,
213
- updatedAtMs: Date.now()
214
- };
215
- await putMcpAuthSession(next);
216
- return next;
217
- }
218
- async function deleteMcpAuthSession(authSessionId) {
219
- const stateAdapter = await getConnectedStateAdapter();
220
- const current = parseMcpAuthSession(await readMcpAuthSession(stateAdapter, authSessionId));
221
- await stateAdapter.delete(sessionKey(authSessionId));
222
- if (!current) return;
223
- const nextIndex = parseSessionIndex(await stateAdapter.get(sessionIndexKey(current.userId, current.provider))).filter((id) => id !== authSessionId);
224
- if (nextIndex.length > 0) {
225
- await stateAdapter.set(sessionIndexKey(current.userId, current.provider), JSON.stringify(nextIndex), MCP_AUTH_SESSION_TTL_MS);
226
- return;
227
- }
228
- await stateAdapter.delete(sessionIndexKey(current.userId, current.provider));
229
- }
230
- async function deleteMcpAuthSessionsForUserProvider(userId, provider) {
231
- const stateAdapter = await getConnectedStateAdapter();
232
- const indexKey = sessionIndexKey(userId, provider);
233
- const authSessionIds = parseSessionIndex(await stateAdapter.get(indexKey));
234
- await mapBounded(authSessionIds, (authSessionId) => stateAdapter.delete(sessionKey(authSessionId)));
235
- await stateAdapter.delete(indexKey);
236
- }
237
- async function getMcpStoredOAuthCredentials(userId, provider) {
238
- const stateAdapter = await getConnectedStateAdapter();
239
- const stored = parseStoredCredentials((await readEncryptedState(stateAdapter, credentialsKey(userId, provider)))?.value);
240
- if (stored) return stored;
241
- const legacyUserId = await findLegacyWebActorUserId(userId);
242
- if (!legacyUserId) return void 0;
243
- const legacyKey = credentialsKey(legacyUserId, provider);
244
- const legacy = parseStoredCredentials((await readEncryptedState(stateAdapter, legacyKey))?.value);
245
- if (!legacy) return void 0;
246
- await putMcpStoredOAuthCredentials(userId, provider, legacy);
247
- await stateAdapter.delete(legacyKey);
248
- return legacy;
249
- }
250
- async function putMcpStoredOAuthCredentials(userId, provider, value, ttlMs = MCP_AUTH_CREDENTIALS_TTL_MS) {
251
- const stateAdapter = await getConnectedStateAdapter();
252
- await createEncryptedState(stateAdapter).set(credentialsKey(userId, provider), value, ttlMs);
253
- }
254
- async function deleteMcpStoredOAuthCredentials(userId, provider) {
255
- const stateAdapter = await getConnectedStateAdapter();
256
- await stateAdapter.delete(credentialsKey(userId, provider));
257
- const legacyUserId = await findLegacyWebActorUserId(userId);
258
- if (legacyUserId) await stateAdapter.delete(credentialsKey(legacyUserId, provider));
259
- }
260
- async function getMcpServerSessionId(userId, provider) {
261
- return parseServerSession(await (await getConnectedStateAdapter()).get(serverSessionKey(userId, provider)))?.sessionId;
262
- }
263
- async function putMcpServerSessionId(userId, provider, sessionId, ttlMs = MCP_SERVER_SESSION_TTL_MS) {
264
- await (await getConnectedStateAdapter()).set(serverSessionKey(userId, provider), JSON.stringify({
265
- sessionId,
266
- updatedAtMs: Date.now()
267
- }), ttlMs);
268
- }
269
- async function deleteMcpServerSessionId(userId, provider) {
270
- await (await getConnectedStateAdapter()).delete(serverSessionKey(userId, provider));
271
- }
272
- // src/chat/mcp/token-refresh.ts
273
- /**
274
- * One MCP token refresh at a time for each person and provider.
275
- *
276
- * Providers such as Notion rotate the refresh token on each refresh and
277
- * revoke the whole grant when a retired refresh token comes back. A Turn
278
- * and a link card read can both find an expired access token at once, so
279
- * every refresh of a stored person login runs under one lock. A caller
280
- * that waited gets the tokens that the first caller saved, and its retired
281
- * refresh token never reaches the provider.
282
- */
283
- const REFRESH_LOCK_TTL_MS = 3e4;
284
- const REFRESH_WAIT_MS = 3e4;
285
- function refreshTokenOf(body) {
286
- const params = body instanceof URLSearchParams ? body : typeof body === "string" ? new URLSearchParams(body) : void 0;
287
- return params?.get("grant_type") === "refresh_token" ? params.get("refresh_token") ?? void 0 : void 0;
288
- }
289
- /**
290
- * Wrap the fetch of an MCP client so that each refresh-token request for
291
- * this login runs under the shared lock. Other requests pass through.
292
- */
293
- function serializeMcpTokenRefresh(owner, fetchFn = globalThis.fetch) {
294
- let sentAccessToken;
295
- return async (input, init) => {
296
- const sentRefreshToken = refreshTokenOf(init?.body);
297
- if (!sentRefreshToken) {
298
- const authorization = new Headers(init?.headers).get("authorization");
299
- if (authorization) sentAccessToken = authorization.replace(/^Bearer\s+/i, "");
300
- return await fetchFn(input, init);
301
- }
302
- const { provider, userId } = await owner();
303
- const state = getStateAdapter();
304
- await state.connect();
305
- const attempt = await withLock(state, `mcp-oauth-refresh:${userId}:${provider}`, async (lock) => {
306
- const stored = await getMcpStoredOAuthCredentials(userId, provider);
307
- const current = stored?.tokens;
308
- if (!current) return Response.json({ error: "invalid_grant" }, { status: 400 });
309
- if (current.refresh_token && current.refresh_token !== sentRefreshToken || sentAccessToken && current.access_token !== sentAccessToken) return Response.json(current);
310
- const response = await fetchFn(input, init);
311
- if (!response.ok) return response;
312
- const tokens = await response.clone().json();
313
- if (typeof tokens["access_token"] !== "string") return response;
314
- await fenceLock(state, lock, REFRESH_LOCK_TTL_MS);
315
- await putMcpStoredOAuthCredentials(userId, provider, {
316
- ...stored,
317
- tokens: {
318
- ...current,
319
- ...tokens,
320
- refresh_token: typeof tokens["refresh_token"] === "string" ? tokens["refresh_token"] : sentRefreshToken
321
- }
322
- });
323
- return response;
324
- }, {
325
- keepAlive: true,
326
- ttlMs: REFRESH_LOCK_TTL_MS,
327
- waitMs: REFRESH_WAIT_MS
328
- });
329
- if (!attempt.acquired) throw new Error(`Timed out waiting for the ${provider} MCP token refresh`);
330
- return attempt.value;
331
- };
332
- }
333
- // src/chat/mcp/client.ts
334
- const MCP_CLIENT_INFO = {
335
- name: "junior-mcp-client",
336
- version: "1.0.0"
337
- };
338
- const MCP_TOOLS_CALL_METHOD = "tools/call";
339
- function getDefaultPort(url) {
340
- if (url.protocol === "https:") return 443;
341
- if (url.protocol === "http:") return 80;
342
- }
343
- function getMcpNetworkAttributes(url) {
344
- const port = url.port ? Number(url.port) : getDefaultPort(url);
345
- return {
346
- "server.address": url.hostname,
347
- ...port !== void 0 ? { "server.port": port } : void 0,
348
- ...url.protocol === "http:" || url.protocol === "https:" ? {
349
- "network.protocol.name": "http",
350
- "network.transport": "tcp"
351
- } : void 0
352
- };
353
- }
354
- var McpAuthorizationRequiredError = class extends Error {
355
- provider;
356
- constructor(provider, message) {
357
- super(message);
358
- this.name = "McpAuthorizationRequiredError";
359
- this.provider = provider;
360
- }
361
- };
362
- function isMissingSessionError(error) {
363
- return error instanceof StreamableHTTPError && (error.code === 404 || /Session not found/i.test(error.message));
364
- }
365
- var PluginMcpClient = class {
366
- client;
367
- clientPromise;
368
- lastAttemptedTransportSessionId;
369
- providerStatusStore = new AsyncLocalStorage();
370
- transport;
371
- listedTools;
372
- resourceHost;
373
- plugin;
374
- options;
375
- constructor(plugin, options = {}) {
376
- this.plugin = plugin;
377
- this.options = options;
378
- const url = plugin.manifest.mcp?.url;
379
- this.resourceHost = url ? new URL(url).hostname : void 0;
380
- }
381
- async listTools() {
382
- if (this.listedTools) return [...this.listedTools];
383
- return await this.withSessionRecovery(async () => {
384
- const client = await this.getClient();
385
- const discovered = [];
386
- const seen = /* @__PURE__ */ new Set();
387
- let cursor;
388
- do {
389
- const result = await this.wrapAuth(() => client.listTools(cursor ? { cursor } : void 0), "list_tools");
390
- await this.syncTransportSessionId();
391
- for (const tool of result.tools) {
392
- if (seen.has(tool.name)) continue;
393
- seen.add(tool.name);
394
- discovered.push(tool);
395
- }
396
- cursor = result.nextCursor;
397
- } while (cursor);
398
- this.listedTools = discovered.sort((left, right) => left.name.localeCompare(right.name));
399
- return [...this.listedTools];
400
- });
401
- }
402
- async callTool(name, args, signal) {
403
- return await this.withSessionRecovery(async () => {
404
- const client = await this.getClient();
405
- const mcp = this.plugin.manifest.mcp;
406
- if (mcp) {
407
- const url = new URL(mcp.url);
408
- setSpanAttributes({
409
- "mcp.method.name": MCP_TOOLS_CALL_METHOD,
410
- "gen_ai.operation.name": "execute_tool",
411
- ...this.transport?.sessionId ? { "mcp.session.id": this.transport.sessionId } : void 0,
412
- ...this.transport?.protocolVersion ? { "mcp.protocol.version": this.transport.protocolVersion } : void 0,
413
- ...getMcpNetworkAttributes(url)
414
- });
415
- }
416
- const result = await this.wrapAuth(() => client.callTool({
417
- name,
418
- arguments: args ?? {}
419
- }, void 0, signal ? { signal } : void 0), "call_tool");
420
- await this.syncTransportSessionId();
421
- return result;
422
- });
423
- }
424
- async close() {
425
- await this.disposeClient();
426
- }
427
- async withSessionRecovery(operation) {
428
- try {
429
- return await operation();
430
- } catch (error) {
431
- await this.syncTransportSessionId();
432
- if (!await this.shouldResetMissingSession(error)) throw error;
433
- await this.clearStoredTransportSessionId();
434
- await this.cleanupClientAfterFailure();
435
- return await operation();
436
- }
437
- }
438
- async getClient() {
439
- if (this.client) return this.client;
440
- if (this.clientPromise) return await this.clientPromise;
441
- const clientPromise = this.connectClient();
442
- this.clientPromise = clientPromise;
443
- try {
444
- return await clientPromise;
445
- } finally {
446
- if (this.clientPromise === clientPromise) this.clientPromise = void 0;
447
- }
448
- }
449
- async connectClient() {
450
- const mcp = this.plugin.manifest.mcp;
451
- if (!mcp) throw new Error(`Plugin "${this.plugin.manifest.name}" does not declare MCP config`);
452
- const headers = mcp.headers ? resolvePluginHeaderEnvRefs(this.plugin.manifest.name, mcp.headers, "MCP header") : void 0;
453
- const sessionId = await this.getStoredTransportSessionId();
454
- this.lastAttemptedTransportSessionId = sessionId;
455
- const loginProvider = this.options.authProvider;
456
- const mcpLoginOwner = loginProvider?.mcpLoginOwner?.bind(loginProvider);
457
- const providerFetch = mcpLoginOwner ? serializeMcpTokenRefresh(mcpLoginOwner, this.options.fetch) : this.options.fetch;
458
- const transport = new StreamableHTTPClientTransport(new URL(mcp.url), {
459
- ...headers ? { requestInit: { headers } } : void 0,
460
- fetch: fetchWithBoundedOAuthErrorBodies(providerFetch, (status) => {
461
- const store = this.providerStatusStore.getStore();
462
- if (store) store.status = status;
463
- }),
464
- ...this.options.authProvider ? { authProvider: this.options.authProvider } : void 0,
465
- ...sessionId ? { sessionId } : void 0
466
- });
467
- const client = new Client(MCP_CLIENT_INFO, { capabilities: {} });
468
- this.transport = transport;
469
- try {
470
- await this.wrapAuth(() => client.connect(transport), "connect");
471
- this.client = client;
472
- await this.syncTransportSessionId();
473
- return client;
474
- } catch (error) {
475
- await this.syncTransportSessionId();
476
- await this.cleanupClientAfterFailure();
477
- throw error;
478
- }
479
- }
480
- async wrapAuth(operation, phase) {
481
- const store = {};
482
- return await this.providerStatusStore.run(store, async () => {
483
- try {
484
- return await operation();
485
- } catch (error) {
486
- if (error instanceof McpAuthorizationRequiredError) throw error;
487
- if (error instanceof UnauthorizedError) throw new McpAuthorizationRequiredError(this.plugin.manifest.name, `MCP authorization required for plugin "${this.plugin.manifest.name}"`);
488
- throw toMcpProviderError(error, {
489
- phase,
490
- provider: this.plugin.manifest.name,
491
- missingSession: isMissingSessionError(error) || void 0,
492
- resourceHost: this.resourceHost,
493
- status: store.status
494
- });
495
- }
496
- });
497
- }
498
- async shouldResetMissingSession(error) {
499
- if (!(error instanceof McpProviderError && error.missingSession || isMissingSessionError(error))) return false;
500
- return Boolean(this.transport?.sessionId ?? this.lastAttemptedTransportSessionId ?? await this.getStoredTransportSessionId());
501
- }
502
- resetClientState() {
503
- const transport = this.transport;
504
- this.listedTools = void 0;
505
- this.transport = void 0;
506
- this.client = void 0;
507
- this.clientPromise = void 0;
508
- return transport;
509
- }
510
- async cleanupClientAfterFailure() {
511
- const transport = this.resetClientState();
512
- if (!transport) return;
513
- try {
514
- await transport.close();
515
- } catch {}
516
- }
517
- async disposeClient() {
518
- const transport = this.resetClientState();
519
- if (transport) try {
520
- await transport.close();
521
- } catch (error) {
522
- throw toMcpProviderError(error, {
523
- phase: "close",
524
- provider: this.plugin.manifest.name,
525
- resourceHost: this.resourceHost
526
- });
527
- }
528
- }
529
- async getStoredTransportSessionId() {
530
- return await this.options.authProvider?.getMcpServerSessionId?.();
531
- }
532
- async clearStoredTransportSessionId() {
533
- const provider = this.options.authProvider;
534
- this.lastAttemptedTransportSessionId = void 0;
535
- await provider?.saveMcpServerSessionId?.(void 0);
536
- }
537
- async syncTransportSessionId() {
538
- const provider = this.options.authProvider;
539
- const sessionId = this.transport?.sessionId;
540
- if (!provider?.saveMcpServerSessionId || !sessionId) return;
541
- this.lastAttemptedTransportSessionId = sessionId;
542
- await provider.saveMcpServerSessionId(sessionId);
543
- }
544
- };
545
- // src/chat/mcp/service-account.ts
546
- /**
547
- * MCP service account credentials.
548
- *
549
- * This is the MCP surface of a plugin's service account. See
550
- * `@/chat/credentials/service-account` for the credential order and the
551
- * policy. An Admin connects the account from the dashboard Admin page, or
552
- * with `junior service-account connect <plugin>`. The credential stays on
553
- * the host. The sandbox and the model never get it.
554
- */
555
- const SERVICE_ACCOUNT_KEY_PREFIX = "junior:mcp_service_account";
556
- const SIGN_IN_KEY_PREFIX = "junior:mcp_service_account_sign_in";
557
- const SIGN_IN_TTL_MS = 6e5;
558
- const UPDATE_LOCK_WAIT_MS = 5e3;
559
- function serviceAccountKey(provider) {
560
- return `${SERVICE_ACCOUNT_KEY_PREFIX}:${provider}`;
561
- }
562
- function updateLockKey(provider) {
563
- return `${serviceAccountKey(provider)}:update`;
564
- }
565
- const storedOAuthClientInformationSchema = z.custom((value) => typeof value === "object" && value !== null);
566
- const storedOAuthDiscoveryStateSchema = z.custom((value) => typeof value === "object" && value !== null);
567
- const storedOAuthTokensSchema = z.custom((value) => typeof value === "object" && value !== null);
568
- const credentialsSchema = z.object({
569
- clientInformation: storedOAuthClientInformationSchema,
570
- connectedAtMs: z.number(),
571
- connectedBy: z.string().optional().catch(void 0),
572
- discoveryState: storedOAuthDiscoveryStateSchema.optional().catch(void 0),
573
- redirectUrl: z.string(),
574
- tokens: storedOAuthTokensSchema
575
- });
576
- function parseCredentials(value) {
577
- try {
578
- const parsed = credentialsSchema.safeParse(typeof value === "string" ? JSON.parse(value) : value);
579
- return parsed.success ? parsed.data : void 0;
580
- } catch {
581
- return;
582
- }
583
- }
584
- /** Read the connected service account for one plugin, if any. */
585
- async function getMcpServiceAccountCredentials(provider) {
586
- const state = getStateAdapter();
587
- const stored = await readEncryptedState(state, serviceAccountKey(provider));
588
- const credentials = parseCredentials(stored?.value);
589
- if (credentials && stored?.stale) await saveStaleCredentials(provider);
590
- return credentials;
591
- }
592
- /**
593
- * Save stale credentials again with the active key. It runs only when the
594
- * update lock is free, so it cannot write back a refresh token that an
595
- * update replaced.
596
- */
597
- async function saveStaleCredentials(provider) {
598
- const state = getStateAdapter();
599
- await withLock(state, updateLockKey(provider), async (lock) => {
600
- const key = serviceAccountKey(provider);
601
- const current = await readEncryptedState(state, key);
602
- const credentials = parseCredentials(current?.value);
603
- if (!current?.stale || !credentials) return;
604
- await fenceLock(state, lock);
605
- await putMcpServiceAccountCredentials(provider, credentials);
606
- }, { ttlMs: MUTATION_LOCK_TTL_MS });
607
- }
608
- /** Save the service account for one plugin. It does not expire. */
609
- async function putMcpServiceAccountCredentials(provider, credentials) {
610
- await createEncryptedState(getStateAdapter()).set(serviceAccountKey(provider), credentials);
611
- }
612
- /** Remove the service account for one plugin. The provider grant stays until the provider revokes it. */
613
- async function deleteMcpServiceAccountCredentials(provider) {
614
- await getStateAdapter().delete(serviceAccountKey(provider));
615
- }
616
- function clientMetadata(redirectUrl) {
617
- return {
618
- client_name: `${botConfig.userName} MCP Service Account`,
619
- redirect_uris: [redirectUrl],
620
- grant_types: ["authorization_code", "refresh_token"],
621
- response_types: ["code"],
622
- token_endpoint_auth_method: "none"
623
- };
624
- }
625
- function reconnectMessage(provider) {
626
- return `The ${provider} service account is not authorized anymore. An admin must run \`junior service-account connect ${provider}\`.`;
627
- }
628
- /**
629
- * Build the OAuth client provider for a connected service account.
630
- *
631
- * It refreshes tokens like a user connection but never starts a new sign-in.
632
- * Many turns share this account, so it reads the store on each request and
633
- * writes each change under a lock. When the provider rejects a refresh token
634
- * that another turn already replaced, it retries with the stored one. It
635
- * deletes the stored grant only when the provider rejected the stored token
636
- * itself, and then throws `McpAuthorizationRequiredError` so the tool manager
637
- * can fall back to Actor auth or report the missing account. A refresh that
638
- * fails for another reason, such as a network error, keeps the account.
639
- */
640
- function createMcpServiceAccountClientProvider(provider, connected) {
641
- let lastRefreshToken = connected.tokens.refresh_token;
642
- let tokensRejected = false;
643
- const withStoreLock = async (run) => {
644
- const state = getStateAdapter();
645
- const result = await withLock(state, updateLockKey(provider), async (lock) => await run(() => fenceLock(state, lock)), {
646
- ttlMs: MUTATION_LOCK_TTL_MS,
647
- waitMs: UPDATE_LOCK_WAIT_MS
648
- });
649
- if (!result.acquired) throw new Error(`Timed out waiting to update the ${provider} service account`);
650
- return result.value;
651
- };
652
- const update = async (patch) => {
653
- await withStoreLock(async (fence) => {
654
- const current = await getMcpServiceAccountCredentials(provider);
655
- if (!current) throw new Error(reconnectMessage(provider));
656
- await fence();
657
- await putMcpServiceAccountCredentials(provider, {
658
- ...current,
659
- ...patch
660
- });
661
- });
662
- };
663
- return {
664
- redirectUrl: connected.redirectUrl,
665
- clientMetadata: clientMetadata(connected.redirectUrl),
666
- clientInformation: async () => (await getMcpServiceAccountCredentials(provider))?.clientInformation,
667
- saveClientInformation: async (clientInformation) => {
668
- await update({ clientInformation });
669
- },
670
- tokens: async () => {
671
- const tokens = (await getMcpServiceAccountCredentials(provider))?.tokens;
672
- if (tokensRejected) {
673
- if (!tokens || tokens.refresh_token === lastRefreshToken) return;
674
- tokensRejected = false;
675
- }
676
- lastRefreshToken = tokens?.refresh_token;
677
- return tokens;
678
- },
679
- saveTokens: async (tokens) => {
680
- tokensRejected = false;
681
- lastRefreshToken = tokens.refresh_token;
682
- await update({ tokens });
683
- },
684
- discoveryState: async () => (await getMcpServiceAccountCredentials(provider))?.discoveryState,
685
- saveDiscoveryState: async (discoveryState) => {
686
- await update({ discoveryState });
687
- },
688
- invalidateCredentials: (scope) => {
689
- if (scope === "all" || scope === "tokens") tokensRejected = true;
690
- },
691
- redirectToAuthorization: async () => {
692
- if (!await withStoreLock(async (fence) => {
693
- const stored = await getMcpServiceAccountCredentials(provider);
694
- if (!stored) return true;
695
- if (!tokensRejected && stored.tokens.refresh_token || stored.tokens.refresh_token !== lastRefreshToken) return false;
696
- await fence();
697
- await deleteMcpServiceAccountCredentials(provider);
698
- logWarn("mcp.service_account.disconnected", { "app.plugin.name": provider });
699
- return true;
700
- })) throw new Error(`The ${provider} service account could not refresh its token. Try again later.`);
701
- throw new McpAuthorizationRequiredError(provider, reconnectMessage(provider));
702
- },
703
- saveCodeVerifier: () => void 0,
704
- codeVerifier: () => {
705
- throw new Error(reconnectMessage(provider));
706
- }
707
- };
708
- }
709
- function signInKey(state) {
710
- return `${SIGN_IN_KEY_PREFIX}:${state}`;
711
- }
712
- const signInSchema = z.object({
713
- clientInformation: storedOAuthClientInformationSchema,
714
- codeVerifier: z.string(),
715
- discoveryState: storedOAuthDiscoveryStateSchema.optional().catch(void 0),
716
- provider: z.string(),
717
- redirectUrl: z.string(),
718
- startedBy: z.string().optional().catch(void 0)
719
- });
720
- function parseSignIn(value) {
721
- const parsed = signInSchema.safeParse(value);
722
- return parsed.success ? parsed.data : void 0;
723
- }
724
- /** Build an OAuth client provider that keeps sign-in state in memory. */
725
- function signInProvider(input) {
726
- const captured = {
727
- clientInformation: input.pending?.clientInformation,
728
- codeVerifier: input.pending?.codeVerifier,
729
- discoveryState: input.pending?.discoveryState
730
- };
731
- return {
732
- captured,
733
- provider: {
734
- redirectUrl: input.redirectUrl,
735
- clientMetadata: clientMetadata(input.redirectUrl),
736
- ...input.state ? { state: () => input.state } : void 0,
737
- clientInformation: () => captured.clientInformation,
738
- saveClientInformation: (next) => {
739
- captured.clientInformation = next;
740
- },
741
- tokens: () => captured.tokens,
742
- saveTokens: (next) => {
743
- captured.tokens = next;
744
- },
745
- discoveryState: () => captured.discoveryState,
746
- saveDiscoveryState: (next) => {
747
- captured.discoveryState = next;
748
- },
749
- redirectToAuthorization: (url) => {
750
- captured.authorizationUrl = url;
751
- },
752
- saveCodeVerifier: (next) => {
753
- captured.codeVerifier = next;
754
- },
755
- codeVerifier: () => {
756
- if (!captured.codeVerifier) throw new Error("Missing MCP OAuth code verifier");
757
- return captured.codeVerifier;
758
- }
759
- }
760
- };
761
- }
762
- function requireServiceAccountMcp(plugin) {
763
- const mcp = plugin.manifest.mcp;
764
- if (!mcp || !plugin.manifest.accounts?.serviceAccount) throw new Error(`Plugin "${plugin.manifest.name}" does not support a service account`);
765
- return mcp;
766
- }
767
- /**
768
- * Start a service account sign-in and return the provider sign-in URL.
769
- *
770
- * The pending sign-in is single use and expires after a short time. Whoever
771
- * signs in decides which account Junior uses, so only Junior admins may start
772
- * it.
773
- */
774
- async function startMcpServiceAccountSignIn(input) {
775
- const mcp = requireServiceAccountMcp(input.plugin);
776
- const provider = input.plugin.manifest.name;
777
- const state = randomUUID();
778
- const signIn = signInProvider({
779
- redirectUrl: input.redirectUrl,
780
- state
781
- });
782
- if (await auth(signIn.provider, { serverUrl: mcp.url }) !== "REDIRECT") throw new Error(`${provider} did not start an OAuth sign-in`);
783
- const { authorizationUrl, clientInformation, codeVerifier, discoveryState } = signIn.captured;
784
- if (!authorizationUrl || !clientInformation || !codeVerifier) throw new Error(`${provider} did not return an authorization URL`);
785
- await createEncryptedState(getStateAdapter()).set(signInKey(state), {
786
- clientInformation,
787
- codeVerifier,
788
- ...discoveryState ? { discoveryState } : void 0,
789
- provider,
790
- redirectUrl: input.redirectUrl,
791
- ...input.startedBy ? { startedBy: input.startedBy } : void 0
792
- }, SIGN_IN_TTL_MS);
793
- return { authorizationUrl };
794
- }
795
- /**
796
- * Finish a service account sign-in from the OAuth callback parameters.
797
- *
798
- * It accepts only a pending sign-in for the same plugin that the same Admin
799
- * started. It then saves the grant as the plugin's service account.
800
- */
801
- async function finishMcpServiceAccountSignIn(input) {
802
- const mcp = requireServiceAccountMcp(input.plugin);
803
- const provider = input.plugin.manifest.name;
804
- const state = input.callback.get("state");
805
- const pending = state ? parseSignIn(await createEncryptedState(getStateAdapter()).get(signInKey(state))) : void 0;
806
- if (!state || !pending || pending.provider !== provider || pending.startedBy !== input.connectedBy) return {
807
- ok: false,
808
- message: "This sign-in expired or did not start here. Start it again."
809
- };
810
- await getStateAdapter().delete(signInKey(state));
811
- const error = input.callback.get("error");
812
- if (error) return {
813
- ok: false,
814
- message: `${provider} did not finish the sign-in (${error}).`
815
- };
816
- const authorizationCode = input.callback.get("code");
817
- if (!authorizationCode) return {
818
- ok: false,
819
- message: `${provider} did not return an authorization code.`
820
- };
821
- const signIn = signInProvider({
822
- pending,
823
- redirectUrl: pending.redirectUrl
824
- });
825
- await auth(signIn.provider, {
826
- serverUrl: mcp.url,
827
- authorizationCode
828
- });
829
- const { clientInformation, discoveryState, tokens } = signIn.captured;
830
- if (!clientInformation || !tokens) throw new Error(`${provider} did not issue tokens`);
831
- const credentials = {
832
- clientInformation,
833
- connectedAtMs: Date.now(),
834
- ...input.connectedBy ? { connectedBy: input.connectedBy } : void 0,
835
- ...discoveryState ? { discoveryState } : void 0,
836
- redirectUrl: pending.redirectUrl,
837
- tokens
838
- };
839
- await putMcpServiceAccountCredentials(provider, credentials);
840
- return {
841
- ok: true,
842
- credentials
843
- };
844
- }
845
- // src/chat/credentials/service-account.ts
846
- /**
847
- * Service accounts.
848
- *
849
- * A plugin's `accounts` block can allow an optional install-wide provider
850
- * account, often a bot, that Junior itself uses. By default, the credential
851
- * order for one request is:
852
- *
853
- * 1. The Actor's own connection, when it exists.
854
- * 2. The plugin's service account, when an Admin connected it and
855
- * `accounts.service-account` lists what the request uses.
856
- * 3. Otherwise, the Actor must connect their own account.
857
- *
858
- * With `accounts.user-oauth: false`, Junior uses only the service account.
859
- * It ignores Actor connections, never asks an Actor to connect, and hides
860
- * what the account does not list. Until an Admin connects the account, the
861
- * plugin is not available.
862
- *
863
- * This module is the one place that decides which requests the service
864
- * account may serve. Each request surface asks it before it uses the shared
865
- * account. Today MCP tools are the only request kind.
866
- *
867
- * This module also owns the connect flow that the dashboard Admin page and
868
- * the `junior service-account` CLI share. Today MCP is the only surface that
869
- * stores a service account.
870
- */
871
- /** Return whether the plugin's service account may serve this request. */
872
- function serviceAccountAllows(manifest, request) {
873
- return manifest.accounts?.serviceAccount?.tools.includes(request.tool) ?? false;
874
- }
875
- /**
876
- * Return whether the plugin uses only its service account.
877
- *
878
- * Then no surface may fall back to an Actor's own connection or ask an
879
- * Actor to connect.
880
- */
881
- function serviceAccountOnly(manifest) {
882
- return manifest.accounts?.userOAuth === false;
883
- }
884
- /** Return the plugins whose `accounts` block allows a service account. */
885
- function serviceAccountPlugins(plugins) {
886
- return plugins.filter((plugin) => plugin.manifest.accounts?.serviceAccount);
887
- }
888
- /** Read the service account status for one plugin. */
889
- async function getServiceAccountStatus(plugin) {
890
- const { manifest } = plugin;
891
- const serviceAccount = manifest.accounts?.serviceAccount;
892
- if (!serviceAccount) throw new Error(`Plugin ${manifest.name} does not allow a service account`);
893
- const credentials = await getMcpServiceAccountCredentials(manifest.name);
894
- return {
895
- provider: manifest.name,
896
- displayName: manifest.displayName,
897
- userOAuth: !serviceAccountOnly(manifest),
898
- tools: serviceAccount.tools,
899
- connected: Boolean(credentials),
900
- ...credentials ? { connectedAt: new Date(credentials.connectedAtMs).toISOString() } : void 0,
901
- ...credentials?.connectedBy ? { connectedBy: credentials.connectedBy } : void 0
902
- };
903
- }
904
- /**
905
- * Start signing in to a plugin's provider as its service account.
906
- *
907
- * Whoever signs in decides which account Junior uses, so only Junior admins
908
- * may start it. `startedBy` binds the sign-in to that Admin.
909
- */
910
- async function startServiceAccountSignIn(input) {
911
- return await startMcpServiceAccountSignIn(input);
912
- }
913
- /**
914
- * Finish a sign-in from its OAuth callback and save the service account.
915
- *
916
- * A failure message is safe to show the Admin. Unexpected provider failures
917
- * throw.
918
- */
919
- async function finishServiceAccountSignIn(input) {
920
- const result = await finishMcpServiceAccountSignIn(input);
921
- return result.ok ? { ok: true } : result;
922
- }
923
- /**
924
- * Remove a plugin's service account from Junior.
925
- *
926
- * The provider grant stays until someone revokes it in the provider.
927
- */
928
- async function disconnectServiceAccount(plugin) {
929
- await deleteMcpServiceAccountCredentials(plugin.manifest.name);
930
- }
931
- export { McpProviderError as C, getMcpAwareTelemetryMessage as D, getMcpAwareErrorType as E, getMcpProviderErrorAttributes as O, putMcpStoredOAuthCredentials as S, McpToolError as T, getMcpServerSessionId as _, serviceAccountOnly as a, putMcpAuthSession as b, createMcpServiceAccountClientProvider as c, PluginMcpClient as d, deleteMcpAuthSession as f, getMcpAuthSession as g, deleteMcpStoredOAuthCredentials as h, serviceAccountAllows as i, toMcpProviderError as k, getMcpServiceAccountCredentials as l, deleteMcpServerSessionId as m, finishServiceAccountSignIn as n, serviceAccountPlugins as o, deleteMcpAuthSessionsForUserProvider as p, getServiceAccountStatus as r, startServiceAccountSignIn as s, disconnectServiceAccount as t, McpAuthorizationRequiredError as u, getMcpStoredOAuthCredentials as v, McpServiceAccountRequiredError as w, putMcpServerSessionId as x, patchMcpAuthSession as y };