@cursor/bdk 0.2.3 → 0.2.4

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 (577) hide show
  1. package/dist/bin/agent-serve.js +9 -1
  2. package/dist/channels/slack/attachments.d.ts +2 -1
  3. package/dist/channels/slack/attachments.d.ts.map +1 -1
  4. package/dist/channels/slack/attachments.js +19 -9
  5. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  6. package/dist/channels/slack/dispatch.js +26 -24
  7. package/dist/channels/slack/thread-context.d.ts +21 -11
  8. package/dist/channels/slack/thread-context.d.ts.map +1 -1
  9. package/dist/channels/slack/thread-context.js +75 -27
  10. package/dist/docs/404.html +2 -2
  11. package/dist/docs/assets/{app.BOIHhrKi.js → app.4kQ8Db_q.js} +4 -4
  12. package/dist/docs/assets/chunks/@localSearchIndexroot.CvuAJ0My.js +1 -0
  13. package/dist/docs/assets/chunks/{VPLocalSearchBox.D49zVZqM.js → VPLocalSearchBox.DY1RwB8Q.js} +1 -1
  14. package/dist/docs/assets/chunks/{arc.hmjb-sc4.js → arc.CxE_fSPK.js} +1 -1
  15. package/dist/docs/assets/chunks/{architectureDiagram-Q4EWVU46.CxEI1KqM.js → architectureDiagram-Q4EWVU46.CPX426ui.js} +1 -1
  16. package/dist/docs/assets/chunks/{baseUniq.DHHvBWoV.js → baseUniq.CB52JrKG.js} +1 -1
  17. package/dist/docs/assets/chunks/{blockDiagram-DXYQGD6D.DnXW-3bu.js → blockDiagram-DXYQGD6D.J0cNaQCL.js} +1 -1
  18. package/dist/docs/assets/chunks/{c4Diagram-AHTNJAMY.e-47O2jM.js → c4Diagram-AHTNJAMY.DJn3vEGT.js} +1 -1
  19. package/dist/docs/assets/chunks/channel.BoNycAoN.js +1 -0
  20. package/dist/docs/assets/chunks/{chunk-4BX2VUAB.3ry4pYXB.js → chunk-4BX2VUAB.Dao618F6.js} +1 -1
  21. package/dist/docs/assets/chunks/{chunk-4TB4RGXK.DGIZFRx6.js → chunk-4TB4RGXK.QW8Rhjai.js} +1 -1
  22. package/dist/docs/assets/chunks/{chunk-55IACEB6.DKBnqg9U.js → chunk-55IACEB6.DfRLLKF_.js} +1 -1
  23. package/dist/docs/assets/chunks/{chunk-EDXVE4YY.BIU8Ue5k.js → chunk-EDXVE4YY.CIV2ApKQ.js} +1 -1
  24. package/dist/docs/assets/chunks/{chunk-FMBD7UC4.DP-TFhjI.js → chunk-FMBD7UC4.BEheSuxp.js} +1 -1
  25. package/dist/docs/assets/chunks/{chunk-OYMX7WX6.Ux0OYj5v.js → chunk-OYMX7WX6.CUN88ENB.js} +1 -1
  26. package/dist/docs/assets/chunks/{chunk-QZHKN3VN.BzHMwYox.js → chunk-QZHKN3VN.CgqCs8b_.js} +1 -1
  27. package/dist/docs/assets/chunks/{chunk-YZCP3GAM.D4OGAsSP.js → chunk-YZCP3GAM.iCH0nnTJ.js} +1 -1
  28. package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.C4x07Gkj.js +1 -0
  29. package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.C4x07Gkj.js +1 -0
  30. package/dist/docs/assets/chunks/clone.Db22cH_-.js +1 -0
  31. package/dist/docs/assets/chunks/{cose-bilkent-S5V4N54A.Jq_7BUNx.js → cose-bilkent-S5V4N54A.BLcUxhWE.js} +1 -1
  32. package/dist/docs/assets/chunks/{dagre-KV5264BT.Di-skR2x.js → dagre-KV5264BT.Ep7LofOm.js} +1 -1
  33. package/dist/docs/assets/chunks/{diagram-5BDNPKRD.DeREHIdH.js → diagram-5BDNPKRD.Bzf4GSQ4.js} +1 -1
  34. package/dist/docs/assets/chunks/{diagram-G4DWMVQ6.C7Kcqxro.js → diagram-G4DWMVQ6.DD6Jh-eM.js} +1 -1
  35. package/dist/docs/assets/chunks/{diagram-MMDJMWI5.BK3eohyo.js → diagram-MMDJMWI5.oOIl8bWd.js} +1 -1
  36. package/dist/docs/assets/chunks/{diagram-TYMM5635.C6TyymXT.js → diagram-TYMM5635.DHs85Ade.js} +1 -1
  37. package/dist/docs/assets/chunks/{erDiagram-SMLLAGMA.DYGG-gGx.js → erDiagram-SMLLAGMA.BIb5ghCk.js} +1 -1
  38. package/dist/docs/assets/chunks/{flowDiagram-DWJPFMVM.C9nBcSV4.js → flowDiagram-DWJPFMVM.DV4paY9k.js} +1 -1
  39. package/dist/docs/assets/chunks/{ganttDiagram-T4ZO3ILL.wAg_ymsp.js → ganttDiagram-T4ZO3ILL.AyEKA6_v.js} +1 -1
  40. package/dist/docs/assets/chunks/{gitGraphDiagram-UUTBAWPF.B87j9Oeg.js → gitGraphDiagram-UUTBAWPF.BltiCDFo.js} +1 -1
  41. package/dist/docs/assets/chunks/{graph.CuFMj31w.js → graph.DzuEYGdC.js} +1 -1
  42. package/dist/docs/assets/chunks/{infoDiagram-42DDH7IO.P_mLGumP.js → infoDiagram-42DDH7IO.BV2l981J.js} +1 -1
  43. package/dist/docs/assets/chunks/{ishikawaDiagram-UXIWVN3A.DyuL_MsT.js → ishikawaDiagram-UXIWVN3A.BA4Izf-m.js} +1 -1
  44. package/dist/docs/assets/chunks/{journeyDiagram-VCZTEJTY.CtP09IoJ.js → journeyDiagram-VCZTEJTY.DjaFbFS3.js} +1 -1
  45. package/dist/docs/assets/chunks/{kanban-definition-6JOO6SKY.BoeSYPZo.js → kanban-definition-6JOO6SKY.CfTFieDs.js} +1 -1
  46. package/dist/docs/assets/chunks/{layout.B0lMMtNo.js → layout.DzfWqTBV.js} +1 -1
  47. package/dist/docs/assets/chunks/{linear.HxRBiAFX.js → linear.BO6mpulV.js} +1 -1
  48. package/dist/docs/assets/chunks/{min.BGlFFHwS.js → min.BGgTadgT.js} +1 -1
  49. package/dist/docs/assets/chunks/{mindmap-definition-QFDTVHPH.JyLBD9M8.js → mindmap-definition-QFDTVHPH.DPuIXVWY.js} +1 -1
  50. package/dist/docs/assets/chunks/{pieDiagram-DEJITSTG.DnSmNZF8.js → pieDiagram-DEJITSTG.BOnl3bBg.js} +1 -1
  51. package/dist/docs/assets/chunks/{quadrantDiagram-34T5L4WZ.CUCnbfCa.js → quadrantDiagram-34T5L4WZ.DNB6Ckdc.js} +1 -1
  52. package/dist/docs/assets/chunks/{requirementDiagram-MS252O5E.py0IVUn5.js → requirementDiagram-MS252O5E.D5-Qo7vb.js} +1 -1
  53. package/dist/docs/assets/chunks/{sankeyDiagram-XADWPNL6.Bkc-HWYp.js → sankeyDiagram-XADWPNL6.8t65cesf.js} +1 -1
  54. package/dist/docs/assets/chunks/{sequenceDiagram-FGHM5R23.Dqn8Mlv2.js → sequenceDiagram-FGHM5R23.CaG07BdS.js} +1 -1
  55. package/dist/docs/assets/chunks/{stateDiagram-FHFEXIEX.JikkoQUU.js → stateDiagram-FHFEXIEX.TKOweTB6.js} +1 -1
  56. package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.CuqmyQc4.js +1 -0
  57. package/dist/docs/assets/chunks/{theme.b6HQ6zG_.js → theme.Dx-JhpTB.js} +2 -2
  58. package/dist/docs/assets/chunks/{timeline-definition-GMOUNBTQ.BvpSXiBj.js → timeline-definition-GMOUNBTQ.fE53zQ2s.js} +1 -1
  59. package/dist/docs/assets/chunks/{vennDiagram-DHZGUBPP.CU7MVnZx.js → vennDiagram-DHZGUBPP.DJsZZaJg.js} +1 -1
  60. package/dist/docs/assets/chunks/{wardley-RL74JXVD.BKwC4ctG.js → wardley-RL74JXVD.844kyrjl.js} +1 -1
  61. package/dist/docs/assets/chunks/{wardleyDiagram-NUSXRM2D.BfaF6Uhe.js → wardleyDiagram-NUSXRM2D.CMZ-Ru_t.js} +1 -1
  62. package/dist/docs/assets/chunks/{xychartDiagram-5P7HB3ND.Bg5dcpj4.js → xychartDiagram-5P7HB3ND.XXrhBc7a.js} +1 -1
  63. package/dist/docs/assets/{deployment.md.BJ8i7Q6p.js → deployment.md.UhnJIMr-.js} +2 -2
  64. package/dist/docs/assets/{deployment.md.BJ8i7Q6p.lean.js → deployment.md.UhnJIMr-.lean.js} +1 -1
  65. package/dist/docs/assets/{guides_jev.md.BNDm14Gy.js → guides_jev.md.CRcgmjDb.js} +2 -2
  66. package/dist/docs/assets/{guides_jev.md.BNDm14Gy.lean.js → guides_jev.md.CRcgmjDb.lean.js} +1 -1
  67. package/dist/docs/assets/{reference_agent-config.md.DzGI777n.js → reference_agent-config.md.Cj5uBKp4.js} +1 -1
  68. package/dist/docs/assets/{reference_extensions.md.CPPrkWlJ.js → reference_extensions.md.pa2tN-e4.js} +4 -3
  69. package/dist/docs/assets/{reference_extensions.md.CPPrkWlJ.lean.js → reference_extensions.md.pa2tN-e4.lean.js} +1 -1
  70. package/dist/docs/building-with-agents.html +35 -35
  71. package/dist/docs/deployment.html +37 -37
  72. package/dist/docs/deployment.md +4 -1
  73. package/dist/docs/evals.html +35 -35
  74. package/dist/docs/guides/agent-to-agent.html +35 -35
  75. package/dist/docs/guides/bitbucket.html +35 -35
  76. package/dist/docs/guides/cloud-agents.html +35 -35
  77. package/dist/docs/guides/convert-automation.html +35 -35
  78. package/dist/docs/guides/github.html +35 -35
  79. package/dist/docs/guides/gitlab.html +35 -35
  80. package/dist/docs/guides/grokbot-agents.html +35 -35
  81. package/dist/docs/guides/hooks.html +35 -35
  82. package/dist/docs/guides/improve.html +35 -35
  83. package/dist/docs/guides/jev.html +37 -37
  84. package/dist/docs/guides/jev.md +7 -0
  85. package/dist/docs/guides/mcp-oauth.html +35 -35
  86. package/dist/docs/guides/opentelemetry.html +35 -35
  87. package/dist/docs/guides/slack.html +35 -35
  88. package/dist/docs/guides/webhooks.html +35 -35
  89. package/dist/docs/hashmap.json +1 -1
  90. package/dist/docs/hillclimbing.html +35 -35
  91. package/dist/docs/index.html +35 -35
  92. package/dist/docs/llms-full.txt +25 -2
  93. package/dist/docs/quickstart.html +35 -35
  94. package/dist/docs/reference/agent-config.html +37 -37
  95. package/dist/docs/reference/agent-config.md +1 -1
  96. package/dist/docs/reference/artifacts.html +35 -35
  97. package/dist/docs/reference/channels.html +35 -35
  98. package/dist/docs/reference/cli.html +35 -35
  99. package/dist/docs/reference/connections.html +35 -35
  100. package/dist/docs/reference/evals.html +35 -35
  101. package/dist/docs/reference/extensions.html +39 -38
  102. package/dist/docs/reference/extensions.md +13 -0
  103. package/dist/docs/reference/hooks.html +35 -35
  104. package/dist/docs/reference/http-api.html +35 -35
  105. package/dist/docs/reference/instructions.html +35 -35
  106. package/dist/docs/reference/playground.html +35 -35
  107. package/dist/docs/reference/project-layout.html +35 -35
  108. package/dist/docs/reference/prompt.html +35 -35
  109. package/dist/docs/reference/schedules.html +35 -35
  110. package/dist/docs/reference/sessions.html +35 -35
  111. package/dist/docs/reference/skills.html +35 -35
  112. package/dist/docs/reference/subagents.html +35 -35
  113. package/dist/docs/reference/tools.html +35 -35
  114. package/dist/docs/templates/agentic-owners.html +35 -35
  115. package/dist/docs/templates/security-reviewer.html +35 -35
  116. package/dist/docs/templates/thermo-quality-review.html +35 -35
  117. package/dist/docs/templates/thermo-review.html +35 -35
  118. package/dist/docs/templates/triage.html +35 -35
  119. package/dist/docs/troubleshooting.html +35 -35
  120. package/dist/extensions/jev/extension.d.ts +3 -0
  121. package/dist/extensions/jev/extension.d.ts.map +1 -1
  122. package/dist/extensions/jev/extension.js +10 -1
  123. package/dist/extensions/jev/lib/evaluate.d.ts +4 -0
  124. package/dist/extensions/jev/lib/evaluate.d.ts.map +1 -1
  125. package/dist/extensions/jev/lib/evaluate.js +6 -2
  126. package/dist/extensions.d.ts +4 -2
  127. package/dist/extensions.d.ts.map +1 -1
  128. package/dist/extensions.js +5 -2
  129. package/dist/internal/cli-deploy.d.ts.map +1 -1
  130. package/dist/internal/cli-deploy.js +19 -5
  131. package/dist/internal/discovery/agent-config.d.ts +6 -5
  132. package/dist/internal/discovery/agent-config.d.ts.map +1 -1
  133. package/dist/internal/discovery/agent-config.js +29 -28
  134. package/dist/internal/discovery/agent.js +1 -1
  135. package/dist/internal/discovery/extensions.d.ts.map +1 -1
  136. package/dist/internal/discovery/extensions.js +12 -0
  137. package/dist/internal/hosting.d.ts +8 -0
  138. package/dist/internal/hosting.d.ts.map +1 -1
  139. package/dist/internal/hosting.js +24 -0
  140. package/dist/types.d.ts +18 -2
  141. package/dist/types.d.ts.map +1 -1
  142. package/docs/deployment.md +4 -1
  143. package/docs/guides/jev.md +7 -0
  144. package/docs/reference/agent-config.md +1 -1
  145. package/docs/reference/extensions.md +13 -0
  146. package/package.json +1 -9
  147. package/dist/docs/assets/chunks/@localSearchIndexroot.D5L-b34G.js +0 -1
  148. package/dist/docs/assets/chunks/channel.BbOGaJQP.js +0 -1
  149. package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.Db58HCb1.js +0 -1
  150. package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.Db58HCb1.js +0 -1
  151. package/dist/docs/assets/chunks/clone.Co4MBflG.js +0 -1
  152. package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.CMsKhrW0.js +0 -1
  153. package/src/artifacts.ts +0 -68
  154. package/src/bin/agent-serve.ts +0 -1854
  155. package/src/channels/bitbucket/api.ts +0 -891
  156. package/src/channels/bitbucket/binding.ts +0 -417
  157. package/src/channels/bitbucket/bitbucket-channel.ts +0 -162
  158. package/src/channels/bitbucket/bitbucket-webhook.ts +0 -519
  159. package/src/channels/bitbucket/checks.ts +0 -146
  160. package/src/channels/bitbucket/cursor-account.ts +0 -106
  161. package/src/channels/bitbucket/defaults.ts +0 -100
  162. package/src/channels/bitbucket/events.ts +0 -74
  163. package/src/channels/bitbucket/index.ts +0 -51
  164. package/src/channels/bitbucket/replay.ts +0 -421
  165. package/src/channels/bitbucket/state.ts +0 -59
  166. package/src/channels/bitbucket/types.ts +0 -261
  167. package/src/channels/change-monitors/change-monitors-channel.ts +0 -63
  168. package/src/channels/change-monitors/index.ts +0 -8
  169. package/src/channels/change-monitors/types.ts +0 -42
  170. package/src/channels/checks.ts +0 -185
  171. package/src/channels/deployments/deployments-channel.ts +0 -224
  172. package/src/channels/deployments/index.ts +0 -25
  173. package/src/channels/deployments/types.ts +0 -92
  174. package/src/channels/github/api.ts +0 -526
  175. package/src/channels/github/auth.ts +0 -293
  176. package/src/channels/github/binding.ts +0 -233
  177. package/src/channels/github/checks.ts +0 -145
  178. package/src/channels/github/cursor-account.ts +0 -303
  179. package/src/channels/github/defaults.ts +0 -168
  180. package/src/channels/github/events.ts +0 -67
  181. package/src/channels/github/forward.ts +0 -359
  182. package/src/channels/github/github-channel.ts +0 -2334
  183. package/src/channels/github/index.ts +0 -54
  184. package/src/channels/github/progress.ts +0 -365
  185. package/src/channels/github/replay.ts +0 -372
  186. package/src/channels/github/state.ts +0 -124
  187. package/src/channels/github/types.ts +0 -590
  188. package/src/channels/gitlab/api.ts +0 -329
  189. package/src/channels/gitlab/binding.ts +0 -231
  190. package/src/channels/gitlab/checks.ts +0 -228
  191. package/src/channels/gitlab/cursor-account.ts +0 -105
  192. package/src/channels/gitlab/defaults.ts +0 -80
  193. package/src/channels/gitlab/events.ts +0 -37
  194. package/src/channels/gitlab/gitlab-channel.ts +0 -160
  195. package/src/channels/gitlab/gitlab-webhook.ts +0 -509
  196. package/src/channels/gitlab/index.ts +0 -44
  197. package/src/channels/gitlab/replay.ts +0 -328
  198. package/src/channels/gitlab/state.ts +0 -55
  199. package/src/channels/gitlab/types.ts +0 -247
  200. package/src/channels/issues/index.ts +0 -9
  201. package/src/channels/issues/issues-channel.ts +0 -45
  202. package/src/channels/issues/types.ts +0 -38
  203. package/src/channels/origin/api.ts +0 -507
  204. package/src/channels/origin/binding.ts +0 -114
  205. package/src/channels/origin/checks.ts +0 -250
  206. package/src/channels/origin/cursor-account.ts +0 -58
  207. package/src/channels/origin/defaults.ts +0 -140
  208. package/src/channels/origin/events.ts +0 -35
  209. package/src/channels/origin/index.ts +0 -35
  210. package/src/channels/origin/origin-channel.ts +0 -815
  211. package/src/channels/origin/origin-webhook.ts +0 -296
  212. package/src/channels/origin/reactions.ts +0 -72
  213. package/src/channels/origin/state.ts +0 -54
  214. package/src/channels/origin/types.ts +0 -295
  215. package/src/channels/slack/agentic-delivery.ts +0 -634
  216. package/src/channels/slack/agentic-posted.ts +0 -135
  217. package/src/channels/slack/agentic-signals.ts +0 -231
  218. package/src/channels/slack/api.ts +0 -761
  219. package/src/channels/slack/approvals.ts +0 -279
  220. package/src/channels/slack/assistant.ts +0 -76
  221. package/src/channels/slack/attachments.ts +0 -596
  222. package/src/channels/slack/auth.ts +0 -127
  223. package/src/channels/slack/blocks.ts +0 -131
  224. package/src/channels/slack/bot-mentions.ts +0 -318
  225. package/src/channels/slack/channel-watch.ts +0 -314
  226. package/src/channels/slack/cli-project.ts +0 -249
  227. package/src/channels/slack/code-fences.ts +0 -171
  228. package/src/channels/slack/constants.ts +0 -38
  229. package/src/channels/slack/credentials.ts +0 -88
  230. package/src/channels/slack/defaults.ts +0 -714
  231. package/src/channels/slack/dispatch.ts +0 -1060
  232. package/src/channels/slack/doctor.ts +0 -338
  233. package/src/channels/slack/eval-directive.ts +0 -306
  234. package/src/channels/slack/event-id-dedupe.ts +0 -30
  235. package/src/channels/slack/external-policy.ts +0 -75
  236. package/src/channels/slack/footer.ts +0 -106
  237. package/src/channels/slack/inbound.ts +0 -416
  238. package/src/channels/slack/index.ts +0 -53
  239. package/src/channels/slack/init.ts +0 -169
  240. package/src/channels/slack/interactive.ts +0 -406
  241. package/src/channels/slack/links.ts +0 -23
  242. package/src/channels/slack/live-delivery.ts +0 -489
  243. package/src/channels/slack/log.ts +0 -70
  244. package/src/channels/slack/manifest.ts +0 -240
  245. package/src/channels/slack/message-body.ts +0 -82
  246. package/src/channels/slack/nudge-carrier.ts +0 -224
  247. package/src/channels/slack/nudge-store.ts +0 -334
  248. package/src/channels/slack/paint-start.ts +0 -93
  249. package/src/channels/slack/placeholder.ts +0 -358
  250. package/src/channels/slack/pr-ref.ts +0 -74
  251. package/src/channels/slack/progress-delivery.ts +0 -138
  252. package/src/channels/slack/reasoning-card.ts +0 -125
  253. package/src/channels/slack/reasoning-chip.ts +0 -41
  254. package/src/channels/slack/recording-sink.ts +0 -167
  255. package/src/channels/slack/redact.ts +0 -6
  256. package/src/channels/slack/reply-options.ts +0 -279
  257. package/src/channels/slack/setup.ts +0 -125
  258. package/src/channels/slack/slack-channel.ts +0 -744
  259. package/src/channels/slack/socket-mode.ts +0 -140
  260. package/src/channels/slack/stop.ts +0 -25
  261. package/src/channels/slack/stream.ts +0 -66
  262. package/src/channels/slack/thread-context.ts +0 -485
  263. package/src/channels/slack/tool-approval-events.ts +0 -233
  264. package/src/channels/slack/tool-cards.ts +0 -198
  265. package/src/channels/slack/tool-chip.ts +0 -34
  266. package/src/channels/slack/types.ts +0 -787
  267. package/src/channels/slack/upload.ts +0 -137
  268. package/src/channels.ts +0 -543
  269. package/src/connections.ts +0 -153
  270. package/src/dashboard-session-url.ts +0 -30
  271. package/src/evals/assertions.ts +0 -688
  272. package/src/evals/expect.ts +0 -250
  273. package/src/evals/judge.ts +0 -329
  274. package/src/evals/loaders.ts +0 -111
  275. package/src/evals/matchers.ts +0 -223
  276. package/src/evals/reporters.ts +0 -257
  277. package/src/evals/results.ts +0 -130
  278. package/src/evals/run-facts.ts +0 -306
  279. package/src/evals.ts +0 -709
  280. package/src/extensions/cursor-cloud-agents/extension.ts +0 -131
  281. package/src/extensions/cursor-cloud-agents/lib/backend.ts +0 -386
  282. package/src/extensions/cursor-cloud-agents/lib/channels.ts +0 -11
  283. package/src/extensions/cursor-cloud-agents/lib/fleet.ts +0 -98
  284. package/src/extensions/cursor-cloud-agents/lib/inputs.ts +0 -5
  285. package/src/extensions/cursor-cloud-agents/lib/repos.ts +0 -80
  286. package/src/extensions/cursor-cloud-agents/lib/transcript.ts +0 -19
  287. package/src/extensions/cursor-cloud-agents/skills/handoff.md +0 -37
  288. package/src/extensions/cursor-cloud-agents/tools/cancel.ts +0 -21
  289. package/src/extensions/cursor-cloud-agents/tools/dump.ts +0 -47
  290. package/src/extensions/cursor-cloud-agents/tools/get.ts +0 -18
  291. package/src/extensions/cursor-cloud-agents/tools/launch.ts +0 -62
  292. package/src/extensions/cursor-cloud-agents/tools/list.ts +0 -31
  293. package/src/extensions/cursor-cloud-agents/tools/reply.ts +0 -36
  294. package/src/extensions/cursor-grokbot-agents/extension.ts +0 -132
  295. package/src/extensions/cursor-grokbot-agents/lib/agents.ts +0 -42
  296. package/src/extensions/cursor-grokbot-agents/lib/backend.ts +0 -208
  297. package/src/extensions/cursor-grokbot-agents/lib/contacts.ts +0 -74
  298. package/src/extensions/cursor-grokbot-agents/lib/conversation.ts +0 -260
  299. package/src/extensions/cursor-grokbot-agents/lib/inputs.ts +0 -21
  300. package/src/extensions/cursor-grokbot-agents/lib/lock.ts +0 -26
  301. package/src/extensions/cursor-grokbot-agents/skills/consult.md +0 -40
  302. package/src/extensions/cursor-grokbot-agents/tools/ask.ts +0 -32
  303. package/src/extensions/cursor-grokbot-agents/tools/check.ts +0 -25
  304. package/src/extensions/cursor-grokbot-agents/tools/interrupt.ts +0 -17
  305. package/src/extensions/cursor-grokbot-agents/tools/list.ts +0 -26
  306. package/src/extensions/improve/extension.ts +0 -69
  307. package/src/extensions/improve/skills/yourself.ts +0 -50
  308. package/src/extensions/jev/extension.ts +0 -95
  309. package/src/extensions/jev/lib/evaluate.ts +0 -266
  310. package/src/extensions/jev/skills/gated-write.md +0 -25
  311. package/src/extensions/jev/skills/questions.md +0 -33
  312. package/src/extensions/jev/tools/evaluate.ts +0 -82
  313. package/src/extensions/slack-communication/evals/harness.ts +0 -705
  314. package/src/extensions/slack-communication/evals/slack-communication.eval.ts +0 -830
  315. package/src/extensions/slack-communication/evals/slack-placeholder.eval.ts +0 -172
  316. package/src/extensions/slack-communication/extension.ts +0 -44
  317. package/src/extensions/slack-communication/skills/slack-voice.ts +0 -56
  318. package/src/extensions/slack-communication/tools/delete-message.ts +0 -33
  319. package/src/extensions/slack-communication/tools/edit-message.ts +0 -42
  320. package/src/extensions/slack-communication/tools/post-card.ts +0 -28
  321. package/src/extensions/slack-communication/tools/post-file.ts +0 -82
  322. package/src/extensions/slack-communication/tools/post-update.ts +0 -40
  323. package/src/extensions/slack-communication/tools/react.ts +0 -30
  324. package/src/extensions/slack-communication/tools/set-status.ts +0 -21
  325. package/src/extensions.ts +0 -179
  326. package/src/files-backends/agent-store-presigned-url.ts +0 -11
  327. package/src/files-backends/cursor-hosted.ts +0 -1212
  328. package/src/files-backends/local-fs.ts +0 -163
  329. package/src/files.ts +0 -293
  330. package/src/filesystem.ts +0 -2005
  331. package/src/hooks.ts +0 -30
  332. package/src/index.ts +0 -259
  333. package/src/internal/advertise-tools.ts +0 -370
  334. package/src/internal/approval-gate.ts +0 -103
  335. package/src/internal/artifacts-store.ts +0 -836
  336. package/src/internal/as-of.ts +0 -257
  337. package/src/internal/auth.ts +0 -46
  338. package/src/internal/authored-alias-hooks.ts +0 -138
  339. package/src/internal/authored-loaders.ts +0 -188
  340. package/src/internal/bounded-int.ts +0 -24
  341. package/src/internal/bounded.ts +0 -25
  342. package/src/internal/brand.ts +0 -28
  343. package/src/internal/browser-origin-guard.ts +0 -67
  344. package/src/internal/builtin-tools/artifacts.ts +0 -62
  345. package/src/internal/builtin-tools/index.ts +0 -53
  346. package/src/internal/builtin-tools/reminders.ts +0 -145
  347. package/src/internal/channel-dispatch.ts +0 -129
  348. package/src/internal/channel-route-dispatch.ts +0 -58
  349. package/src/internal/channel-state.ts +0 -83
  350. package/src/internal/chat-client.ts +0 -594
  351. package/src/internal/cli-ax.ts +0 -2318
  352. package/src/internal/cli-bitbucket.ts +0 -438
  353. package/src/internal/cli-convert-automation.ts +0 -335
  354. package/src/internal/cli-cursor.ts +0 -282
  355. package/src/internal/cli-deploy.ts +0 -2519
  356. package/src/internal/cli-docs.ts +0 -192
  357. package/src/internal/cli-github.ts +0 -806
  358. package/src/internal/cli-gitlab.ts +0 -452
  359. package/src/internal/cli-images.ts +0 -672
  360. package/src/internal/cli-manifest.ts +0 -56
  361. package/src/internal/cli-mcp-oauth.ts +0 -396
  362. package/src/internal/cli-mcp.ts +0 -808
  363. package/src/internal/cli-skills.ts +0 -98
  364. package/src/internal/cli-slack-manual.ts +0 -418
  365. package/src/internal/cli-slack.ts +0 -874
  366. package/src/internal/cloud-merge.ts +0 -51
  367. package/src/internal/cloud-turn-cost.ts +0 -159
  368. package/src/internal/connection-env.ts +0 -106
  369. package/src/internal/continuation-channel.ts +0 -233
  370. package/src/internal/continuation-identity.ts +0 -935
  371. package/src/internal/conversation-mirror.ts +0 -423
  372. package/src/internal/convert-automation/convert-workflow.ts +0 -1377
  373. package/src/internal/convert-automation/slug.ts +0 -29
  374. package/src/internal/convert-automation/types.ts +0 -212
  375. package/src/internal/cron.ts +0 -76
  376. package/src/internal/cursor/account-mcp.ts +0 -692
  377. package/src/internal/cursor/backend-client.ts +0 -984
  378. package/src/internal/cursor/bound-secret-file.ts +0 -101
  379. package/src/internal/cursor/credentials.ts +0 -560
  380. package/src/internal/cursor/cursor-api-transport.ts +0 -65
  381. package/src/internal/cursor/github-credentials.ts +0 -228
  382. package/src/internal/cursor/hosted-bound-secrets.ts +0 -71
  383. package/src/internal/cursor/hosted-deployment-secrets.ts +0 -100
  384. package/src/internal/cursor/hosted-store-secrets.ts +0 -152
  385. package/src/internal/cursor/session-token.ts +0 -111
  386. package/src/internal/cursor/store-api-client.ts +0 -323
  387. package/src/internal/cursor-account-mcp-auth.ts +0 -303
  388. package/src/internal/cursor-agent-template.ts +0 -50
  389. package/src/internal/cursor-deployment-relay.ts +0 -315
  390. package/src/internal/cursor-event-relay.ts +0 -675
  391. package/src/internal/cursor-relay-core.ts +0 -563
  392. package/src/internal/deferred-channel-session.ts +0 -61
  393. package/src/internal/deploy-client.ts +0 -1574
  394. package/src/internal/deploy-manifest.ts +0 -361
  395. package/src/internal/deploy-source.ts +0 -144
  396. package/src/internal/describe-error.ts +0 -32
  397. package/src/internal/dev-mode.ts +0 -20
  398. package/src/internal/discovery/agent-config.ts +0 -288
  399. package/src/internal/discovery/agent.ts +0 -381
  400. package/src/internal/discovery/channels.ts +0 -100
  401. package/src/internal/discovery/connections.ts +0 -516
  402. package/src/internal/discovery/context.ts +0 -38
  403. package/src/internal/discovery/cursor-plugin.ts +0 -628
  404. package/src/internal/discovery/extension-overlay.ts +0 -247
  405. package/src/internal/discovery/extensions.ts +0 -490
  406. package/src/internal/discovery/fs.ts +0 -103
  407. package/src/internal/discovery/hooks.ts +0 -63
  408. package/src/internal/discovery/info.ts +0 -174
  409. package/src/internal/discovery/instructions.ts +0 -98
  410. package/src/internal/discovery/modules.ts +0 -107
  411. package/src/internal/discovery/names.ts +0 -45
  412. package/src/internal/discovery/project.ts +0 -319
  413. package/src/internal/discovery/reminders.ts +0 -65
  414. package/src/internal/discovery/runtime.ts +0 -158
  415. package/src/internal/discovery/schedules.ts +0 -120
  416. package/src/internal/discovery/seed-files.ts +0 -34
  417. package/src/internal/discovery/services.ts +0 -151
  418. package/src/internal/discovery/skills.ts +0 -174
  419. package/src/internal/discovery/subagent.ts +0 -138
  420. package/src/internal/discovery/tools.ts +0 -170
  421. package/src/internal/discovery.ts +0 -27
  422. package/src/internal/distribution.ts +0 -126
  423. package/src/internal/docs-site.ts +0 -248
  424. package/src/internal/duration.ts +0 -37
  425. package/src/internal/env-file.ts +0 -83
  426. package/src/internal/eval-judge-model.ts +0 -142
  427. package/src/internal/eval-run-store.ts +0 -585
  428. package/src/internal/eval-runner.ts +0 -823
  429. package/src/internal/evals-client.ts +0 -475
  430. package/src/internal/event-log.ts +0 -342
  431. package/src/internal/event-mapper.ts +0 -811
  432. package/src/internal/expected-delivery-failure.ts +0 -34
  433. package/src/internal/factory-resource-channel.ts +0 -103
  434. package/src/internal/filesystem/errors.ts +0 -207
  435. package/src/internal/filesystem/format.ts +0 -253
  436. package/src/internal/filesystem/merge.ts +0 -192
  437. package/src/internal/filesystem/nearest.ts +0 -112
  438. package/src/internal/filesystem/scratch.ts +0 -239
  439. package/src/internal/filesystem/sdk-schemas.ts +0 -204
  440. package/src/internal/filesystem/tools.ts +0 -804
  441. package/src/internal/filesystem/walk.ts +0 -366
  442. package/src/internal/fixtures/units-server.ts +0 -52
  443. package/src/internal/framework-file-storage.ts +0 -357
  444. package/src/internal/framework-storage-selection.ts +0 -156
  445. package/src/internal/frontmatter.ts +0 -108
  446. package/src/internal/github-fanout.ts +0 -144
  447. package/src/internal/guest-network.ts +0 -391
  448. package/src/internal/handleAgentServeTrigger.ts +0 -286
  449. package/src/internal/host-files.ts +0 -341
  450. package/src/internal/host-kv.ts +0 -81
  451. package/src/internal/host-otel.ts +0 -231
  452. package/src/internal/host-platforms.ts +0 -170
  453. package/src/internal/hosted-admission-adapter.ts +0 -47
  454. package/src/internal/hosted-admission-context.ts +0 -37
  455. package/src/internal/hosted-catch-protocol.ts +0 -112
  456. package/src/internal/hosted-catch.ts +0 -179
  457. package/src/internal/hosted-delivery-protocol.ts +0 -824
  458. package/src/internal/hosted-delivery.ts +0 -1410
  459. package/src/internal/hosted-execution-diag.ts +0 -291
  460. package/src/internal/hosted-execution-flush.ts +0 -136
  461. package/src/internal/hosted-execution-latency.ts +0 -301
  462. package/src/internal/hosted-managed-automation.ts +0 -116
  463. package/src/internal/hosting.ts +0 -114
  464. package/src/internal/http-channel-define.ts +0 -25
  465. package/src/internal/http-channel.ts +0 -669
  466. package/src/internal/http-control-plane-session.ts +0 -110
  467. package/src/internal/ids.ts +0 -39
  468. package/src/internal/incoming-headers-to-fetch.ts +0 -45
  469. package/src/internal/init-interview.ts +0 -360
  470. package/src/internal/init-project.ts +0 -711
  471. package/src/internal/init-scaffold.ts +0 -182
  472. package/src/internal/inline-stdio-define-stub.ts +0 -4
  473. package/src/internal/inline-stdio-mcp.ts +0 -230
  474. package/src/internal/install-cursor-skills.ts +0 -604
  475. package/src/internal/is-record.ts +0 -3
  476. package/src/internal/json-schema.ts +0 -95
  477. package/src/internal/legacy-command-guard.ts +0 -66
  478. package/src/internal/listen-port.ts +0 -85
  479. package/src/internal/local-control-plane.ts +0 -442
  480. package/src/internal/local-env.ts +0 -59
  481. package/src/internal/local-ingress.ts +0 -90
  482. package/src/internal/log-ring.ts +0 -59
  483. package/src/internal/logs-client.ts +0 -477
  484. package/src/internal/map-pool.ts +0 -39
  485. package/src/internal/mcp-endpoint.ts +0 -747
  486. package/src/internal/mcp-host.ts +0 -509
  487. package/src/internal/mcp-oauth-on-demand.ts +0 -337
  488. package/src/internal/mcp-oauth-persist.ts +0 -118
  489. package/src/internal/mcp-oauth.ts +0 -549
  490. package/src/internal/net.ts +0 -29
  491. package/src/internal/open-browser.ts +0 -41
  492. package/src/internal/otel/attrs.ts +0 -16
  493. package/src/internal/otel/collector.ts +0 -937
  494. package/src/internal/otel/config.ts +0 -287
  495. package/src/internal/otel/http.ts +0 -122
  496. package/src/internal/otel/mcp.ts +0 -56
  497. package/src/internal/otel/propagation.ts +0 -17
  498. package/src/internal/otel/runtime.ts +0 -441
  499. package/src/internal/package-inline-stdio.ts +0 -114
  500. package/src/internal/peer-connections.ts +0 -96
  501. package/src/internal/platform-schedule-sync.ts +0 -75
  502. package/src/internal/platform-timers.ts +0 -365
  503. package/src/internal/playground/static.ts +0 -278
  504. package/src/internal/playground/toolchain.ts +0 -270
  505. package/src/internal/playground-proxy.ts +0 -564
  506. package/src/internal/process-memory-telemetry.ts +0 -334
  507. package/src/internal/project-layout.ts +0 -31
  508. package/src/internal/prompt-context.ts +0 -116
  509. package/src/internal/reminder-control-plane-protocol.ts +0 -482
  510. package/src/internal/reminder-runner.ts +0 -1559
  511. package/src/internal/reminder-schedule.ts +0 -104
  512. package/src/internal/reminder-store.ts +0 -176
  513. package/src/internal/request-error-status.ts +0 -95
  514. package/src/internal/request-headers.ts +0 -21
  515. package/src/internal/resolve-prod-target.ts +0 -334
  516. package/src/internal/resolved-connections.ts +0 -190
  517. package/src/internal/router.ts +0 -143
  518. package/src/internal/run-client.ts +0 -354
  519. package/src/internal/runtime-dispatch-runner.ts +0 -50
  520. package/src/internal/sanitize-mcp-tool-name.ts +0 -31
  521. package/src/internal/schedule-runner.ts +0 -154
  522. package/src/internal/scm/pr-url.ts +0 -245
  523. package/src/internal/sdk-runner.ts +0 -959
  524. package/src/internal/serve-restart.ts +0 -113
  525. package/src/internal/server.ts +0 -3147
  526. package/src/internal/session-cost.ts +0 -208
  527. package/src/internal/session-engine.ts +0 -5622
  528. package/src/internal/session-links.ts +0 -84
  529. package/src/internal/session-run-log.ts +0 -535
  530. package/src/internal/session-store.ts +0 -307
  531. package/src/internal/session-urls.ts +0 -32
  532. package/src/internal/sessions-client.ts +0 -239
  533. package/src/internal/skill-catalog.ts +0 -66
  534. package/src/internal/skills-sync.ts +0 -55
  535. package/src/internal/slack-provision-client.ts +0 -544
  536. package/src/internal/slack-thread-key.ts +0 -11
  537. package/src/internal/sleep.ts +0 -3
  538. package/src/internal/start-log-store.ts +0 -164
  539. package/src/internal/steering.ts +0 -17
  540. package/src/internal/storage-coordinator.ts +0 -800
  541. package/src/internal/storage-roles.ts +0 -86
  542. package/src/internal/storage.ts +0 -1
  543. package/src/internal/store-api-protocol.ts +0 -205
  544. package/src/internal/store-mirror.ts +0 -73
  545. package/src/internal/stream-progress.ts +0 -294
  546. package/src/internal/terminal-style.ts +0 -133
  547. package/src/internal/testing/factory-resource-fixtures.ts +0 -84
  548. package/src/internal/testing/scm-continuation-fixtures.ts +0 -285
  549. package/src/internal/tool-catalog.ts +0 -104
  550. package/src/internal/tool-policy.ts +0 -222
  551. package/src/internal/tool-result.ts +0 -50
  552. package/src/internal/trajectory.ts +0 -418
  553. package/src/internal/turn-cost.ts +0 -136
  554. package/src/internal/turn-governor.ts +0 -145
  555. package/src/internal/turn-lease-store.ts +0 -144
  556. package/src/internal/turn-outbox.ts +0 -77
  557. package/src/internal/update-check.ts +0 -517
  558. package/src/internal/v2-hosting.ts +0 -52
  559. package/src/internal/workspace-sync.ts +0 -114
  560. package/src/internal/workspace.ts +0 -505
  561. package/src/kv/memory-kv.ts +0 -94
  562. package/src/kv.ts +0 -18
  563. package/src/memory.ts +0 -487
  564. package/src/otel-public.ts +0 -24
  565. package/src/otel.ts +0 -320
  566. package/src/prompt.ts +0 -80
  567. package/src/reminders.ts +0 -65
  568. package/src/schedules.ts +0 -31
  569. package/src/skills.ts +0 -27
  570. package/src/storage-backends/cursor-hosted-v2.ts +0 -204
  571. package/src/storage-backends/cursor-hosted.ts +0 -388
  572. package/src/storage-backends/file-kv.ts +0 -276
  573. package/src/storage-protocol.ts +0 -261
  574. package/src/storage.ts +0 -408
  575. package/src/tools.ts +0 -166
  576. package/src/types.ts +0 -3776
  577. /package/dist/docs/assets/{reference_agent-config.md.DzGI777n.lean.js → reference_agent-config.md.Cj5uBKp4.lean.js} +0 -0
@@ -1,1574 +0,0 @@
1
- /**
2
- * Thin client for the Agent Serve deployment management API
3
- * (`/internal/agent-serve/deployments` on the Cursor backend) and the v2
4
- * AgentSDK accept path (`/internal/agentsdk/deployments`). Pure
5
- * request/response + error mapping — no console I/O, no polling loops;
6
- * rendering lives in `cli-deploy.ts`.
7
- *
8
- * Auth is the user API key sent directly as the bearer (the routes are
9
- * `wrapUserApiRoute` on the backend); there is no token exchange here.
10
- * The endpoints are gated on the `agent_serve_mvp` Statsig gate and 404
11
- * when it is off — the error mapping says so instead of "not found".
12
- */
13
-
14
- import { z } from "zod";
15
- import {
16
- MAX_SECRET_VALUE_BYTES,
17
- MAX_SECRETS,
18
- validateEgressDomain,
19
- validateSettableSecretName,
20
- } from "./hosting.js";
21
-
22
- export type DeploymentStatus =
23
- | "pending"
24
- | "deploying"
25
- | "running"
26
- | "degraded"
27
- | "failed"
28
- | "stopping"
29
- | "stopped"
30
- | "deleting";
31
-
32
- /** Customer-safe deploy progress (no hosting phase / infra names). */
33
- export type DeploymentProgress =
34
- | "queued"
35
- | "preparing"
36
- | "creating"
37
- | "building"
38
- | "starting"
39
- | "finalizing"
40
- | "running"
41
- | "failed"
42
- | "stopping"
43
- | "stopped"
44
- | "deleting"
45
- | "degraded";
46
-
47
- export const TERMINAL_DEPLOY_STATUSES: ReadonlySet<DeploymentStatus> = new Set([
48
- "running",
49
- "degraded",
50
- "failed",
51
- "stopped",
52
- ]);
53
-
54
- /**
55
- * What gets deployed. Today the control plane builds the engine itself from
56
- * a git ref, so the only member is the slug/git-ref shape. When
57
- * artifact-based deploys ship ("build locally + upload"), add an
58
- * `{ kind: "artifact", ... }` member here and a branch in
59
- * {@link AgentServeDeployClient.deploy} — the command surface and everything
60
- * downstream stays unchanged.
61
- */
62
- export type DeploySource = {
63
- kind: "git-ref";
64
- gitRepoUrl: string;
65
- gitRef?: string;
66
- agentPath?: string;
67
- /** Repos whose SCM events the deployed engine pulls (`owner/name`). */
68
- cursorEventRepos?: string[];
69
- /**
70
- * Egress allowlist for the engine pod.
71
- */
72
- egressAllowedDomains?: string[];
73
- /**
74
- * `/v1/channels/…` subtrees the stable alias serves WITHOUT
75
- * `X-Agent-Alias-Token` (channels authored with `publicEndpoint()`).
76
- */
77
- publicRoutePaths?: string[];
78
- };
79
-
80
- const SLUG_PATTERN = /^[a-z0-9_-]{1,64}$/;
81
-
82
- /** Returns a human error message, or undefined when the slug is valid. */
83
- export function validateDeploymentSlug(slug: string): string | undefined {
84
- if (SLUG_PATTERN.test(slug)) {
85
- return undefined;
86
- }
87
- return `Invalid slug ${JSON.stringify(slug)}: use lowercase letters, digits, '-' or '_' (max 64 chars)`;
88
- }
89
-
90
- /** Derive a valid slug from a directory name, or undefined if impossible. */
91
- export function slugFromDirectoryName(name: string): string | undefined {
92
- const slug = name
93
- .toLowerCase()
94
- .replace(/[^a-z0-9_-]+/g, "-")
95
- .replace(/^-+|-+$/g, "")
96
- .slice(0, 64);
97
- return SLUG_PATTERN.test(slug) ? slug : undefined;
98
- }
99
-
100
- export class DeployApiError extends Error {
101
- constructor(
102
- message: string,
103
- readonly status: number,
104
- /** Seconds to wait before retrying (from `Retry-After` on 429s). */
105
- readonly retryAfterSeconds?: number,
106
- ) {
107
- super(message);
108
- this.name = "DeployApiError";
109
- }
110
- }
111
-
112
- // ============================================================================
113
- // Response shapes (backend `serializeDeployment` + route-specific bodies).
114
- // Interfaces are hand-written (the package compiles with
115
- // --isolatedDeclarations, so exported types cannot be z.infer of an
116
- // unannotated schema); the zod schemas below stay module-internal.
117
- // ============================================================================
118
-
119
- export interface DeployAccepted {
120
- id: number;
121
- slug: string;
122
- teamId: number;
123
- status: string;
124
- generation: number;
125
- deploymentKind: string;
126
- engineAlias: string;
127
- /** Present exactly once, on the deploy that minted the record. */
128
- aliasToken?: string;
129
- }
130
-
131
- export interface Deployment {
132
- id: number;
133
- slug: string;
134
- teamId: number;
135
- deploymentKind: string;
136
- gitRepoUrl?: string | null;
137
- gitRef?: string;
138
- agentPath?: string;
139
- desiredState?: string;
140
- status: DeploymentStatus;
141
- /**
142
- * Customer-safe deploy progress (no hosting internals). Present on newer
143
- * backends; older responses omit it.
144
- */
145
- progress?: DeploymentProgress;
146
- /**
147
- * Live step while the deploy converges (e.g. "Checking out source…").
148
- * Null when running / stopped or when only a failure is on the row.
149
- * Present on newer backends; older responses omit it.
150
- */
151
- statusMessage?: string | null;
152
- generation: number;
153
- observedGeneration?: number | null;
154
- engineGeneration?: number | null;
155
- publicId?: string;
156
- engineUrl?: string | null;
157
- /** Anyrun pod id for the active engine, when coordinates are known. */
158
- enginePodId?: string | null;
159
- lastError?: string | null;
160
- engineAlias: string;
161
- desiredUpdatedAt?: string;
162
- lastReconciledAt?: string | null;
163
- /** SCM-event repos configured on the deployment (`owner/name`). */
164
- cursorEventRepos?: string[];
165
- /** Normalized egress allowlist for the engine pod. */
166
- egressAllowedDomains?: string[];
167
- /** Channel subtrees the alias serves without `X-Agent-Alias-Token`. */
168
- publicRoutePaths?: string[];
169
- /** Service-account id (`sa_…`); null on legacy rows. */
170
- serviceAccountId?: string | number | null;
171
- /**
172
- * The durable file store's address on `/v0/agent-serve-files` (also pinned
173
- * into the pod env as `AGENT_SERVE_STORE_SOURCE_ID`).
174
- */
175
- agentStoreSourceId?: string;
176
- /** Masked pod credential; the raw key is never returned. */
177
- podCredentialMaskedKey?: string | null;
178
- /** Names of the secrets set on the deployment (values never returned). */
179
- secretNames?: string[];
180
- }
181
-
182
- /** Short-lived direct pod access minted by the status route. */
183
- export interface EngineAccess {
184
- url: string;
185
- headers: Record<string, string>;
186
- expiresAt: string;
187
- }
188
-
189
- export interface DeploymentDetail extends Deployment {
190
- engineAccess?: EngineAccess | null;
191
- }
192
-
193
- /**
194
- * The deployment's dedicated service-account id (`sa_…`), or undefined for
195
- * legacy rows that predate service-account-backed deploys. Normalizes the
196
- * wire shape (string in prod, number in old fixtures, null when unset).
197
- */
198
- export function deploymentServiceAccountId(
199
- deployment: Pick<Deployment, "serviceAccountId">,
200
- ): string | undefined {
201
- const raw = deployment.serviceAccountId;
202
- if (raw === null || raw === undefined) {
203
- return undefined;
204
- }
205
- const id = String(raw).trim();
206
- return id === "" ? undefined : id;
207
- }
208
-
209
- export interface StopAccepted {
210
- id: number;
211
- status: string;
212
- }
213
-
214
- export type DeleteAccepted = StopAccepted;
215
-
216
- /**
217
- * `POST /internal/agentsdk/deployments` 202 body. Distinct from v1
218
- * {@link DeployAccepted}: the v2 control plane returns catalog ids, not
219
- * an engine alias or one-shot alias token.
220
- */
221
- export interface AgentkitDeployAccepted {
222
- applicationId: string;
223
- releaseId: string;
224
- status: string;
225
- }
226
-
227
- /**
228
- * One release component of a v2 multi-component deploy: a stable key (the
229
- * child agent's slug) plus that agent's directory relative to the repo
230
- * root.
231
- */
232
- export interface AgentkitDeployComponent {
233
- componentKey: string;
234
- agentPath?: string;
235
- persistent?: boolean;
236
- /** Team container image (`agent-sdk images push`) this component runs in. */
237
- image?: string;
238
- }
239
-
240
- /** Customer-visible v2 deploy status (`GET /internal/agentsdk/deployments/:slug`). */
241
- export type AgentkitCustomerStatus = "pending" | "deploying" | "running" | "failed" | "stopped";
242
-
243
- export type AgentkitDeployProgress =
244
- | "queued"
245
- | "creating"
246
- | "building"
247
- | "starting"
248
- | "finalizing"
249
- | "running"
250
- | "failed"
251
- | "stopped";
252
-
253
- export interface AgentkitDeployStatus {
254
- applicationId: string;
255
- releaseId: string;
256
- slug: string;
257
- teamId: number;
258
- status: AgentkitCustomerStatus;
259
- progress: AgentkitDeployProgress;
260
- statusMessage: string | null;
261
- /** Why the bake failed. Null/absent unless `status` is `failed`. */
262
- lastError?: string | null;
263
- /**
264
- * `owner/name` scopes the deployment's GitHub/Origin channels watch.
265
- * Absent on control planes that predate the field.
266
- */
267
- repositories?: string[];
268
- /** Names of application-scoped secrets (values are never returned). */
269
- secretNames?: string[];
270
- }
271
-
272
- /** One v2 application from `GET /internal/agentsdk/deployments`. */
273
- export interface AgentkitDeploymentListItem {
274
- architecture: "v2";
275
- applicationId: string;
276
- releaseId: string;
277
- slug: string;
278
- teamId: number;
279
- status: AgentkitCustomerStatus;
280
- deployments: Array<{ desiredUpdatedAt: string }>;
281
- }
282
-
283
- export const TERMINAL_AGENTKIT_DEPLOY_STATUSES: ReadonlySet<AgentkitCustomerStatus> = new Set([
284
- "running",
285
- "failed",
286
- "stopped",
287
- ]);
288
-
289
- /**
290
- * `POST /internal/agentsdk/deployments/:slug/stop` 202 body. Like v1
291
- * {@link StopAccepted} but keyed by catalog ids instead of the numeric
292
- * deployment row id.
293
- */
294
- export interface AgentkitStopAccepted {
295
- applicationId: string;
296
- releaseId: string;
297
- status: string;
298
- /**
299
- * `"global"` when the backend stopped every tenant install of a
300
- * multi-tenant app. Resume with `start <slug>`.
301
- */
302
- scope?: "global";
303
- deployLocked?: boolean;
304
- cancellation?: AgentkitCancelRunsResult;
305
- }
306
-
307
- export interface AgentkitGlobalSuspensionAccepted {
308
- applicationId: string;
309
- status: "running" | "stopped";
310
- cancellation?: AgentkitCancelRunsResult;
311
- }
312
-
313
- export interface AgentkitCancelRunsResult {
314
- batchesStarted: number;
315
- failed: number;
316
- sessionsMarkedFailed?: number;
317
- }
318
-
319
- const agentkitCancelRunsResultSchema: z.ZodType<AgentkitCancelRunsResult> = z.object({
320
- batchesStarted: z.number().int().nonnegative(),
321
- failed: z.number().int().nonnegative(),
322
- sessionsMarkedFailed: z.number().int().nonnegative().optional(),
323
- });
324
-
325
- const agentkitEventRepositoriesSchema = z.object({
326
- repositories: z.array(z.string()),
327
- });
328
-
329
- const agentkitInstallReleaseSchema = z.object({
330
- releaseId: z.string(),
331
- });
332
-
333
- /**
334
- * `POST /internal/agentsdk/deployments/:slug/sessions` 202 body. A hosted v2
335
- * session start is a Temporal delivery: a fresh start allocates `ses_…`
336
- * only after admission (poll the session list), so the ack is the delivery
337
- * and workflow ids. `sessionId` is present only when the call resumed one.
338
- */
339
- export interface AgentkitStartSessionAccepted {
340
- deliveryId: string;
341
- workflowId: string;
342
- sessionMode: "event" | "continuation";
343
- sessionId?: string;
344
- dryRun?: true;
345
- asOf?: string;
346
- }
347
-
348
- /**
349
- * One hosted execution of a v2 session: a pod wake that ran (or tried to
350
- * run) a turn. `turnStatus` is the engine's outcome (`finished`, `error`,
351
- * `running`, …); `processDeath` marks an entry flushed from a crash handler.
352
- */
353
- export interface AgentkitSessionRun {
354
- executionId: string;
355
- writtenAt: string;
356
- turnStatus: string;
357
- durationMs: number;
358
- message?: string;
359
- error?: { name: string; message: string; stack?: string };
360
- processDeath?: boolean;
361
- logs: Array<{ index: number; at: string; line: string }>;
362
- }
363
-
364
- /**
365
- * `GET /internal/agentsdk/deployments/:slug/sessions/:sessionId/runs` body.
366
- * A v2 deployment has no resident engine to query, so these durable
367
- * control-plane snapshots are the session's history.
368
- */
369
- export interface AgentkitSessionRuns {
370
- executions: AgentkitSessionRun[];
371
- /** Engine start.log tee; null when the framework store has no snapshot. */
372
- startLog: string | null;
373
- }
374
-
375
- /** One event from the hosted session event poll. */
376
- export interface AgentkitSessionEvent {
377
- index?: number;
378
- type?: string;
379
- }
380
-
381
- /**
382
- * `GET .../sessions/:sessionId/events?afterEventIndex=` body.
383
- * Events land before the run log on a long turn.
384
- */
385
- export interface AgentkitSessionEventPoll {
386
- events: AgentkitSessionEvent[];
387
- execution: { executionId: string; turnStatus: string } | null;
388
- }
389
-
390
- /** One secret's metadata from the list endpoint — names only, never values. */
391
- export interface SecretInfo {
392
- name: string;
393
- createdAt: string;
394
- }
395
-
396
- /** One pushed container image (`agent-sdk images list`). */
397
- export interface ContainerImageInfo {
398
- name: string;
399
- sizeBytes: number;
400
- sha256: string | null;
401
- dockerImageId: string | null;
402
- platform: string | null;
403
- pushedByUserId: number | null;
404
- pushedAt: string;
405
- }
406
-
407
- /** Phase one of `images push`: an open multipart upload and its presigned part URLs. */
408
- export interface ContainerImageUpload {
409
- name: string;
410
- uploadId: string;
411
- partSizeBytes: number;
412
- parts: Array<{ partNumber: number; url: string }>;
413
- expiresAt: string;
414
- }
415
-
416
- /**
417
- * `GET /internal/agent-serve/automations/:uuid/export` response
418
- * (backend `agentServeAutomationExport.ts`). Name + transport references
419
- * only — the backend never exports URLs or credential material.
420
- */
421
- export interface AutomationExportMcpServer {
422
- id?: string;
423
- name: string;
424
- transportType: "http" | "sse" | "stdio";
425
- }
426
-
427
- export interface AutomationExport {
428
- automation: {
429
- uuid: string;
430
- name: string;
431
- enabled: boolean;
432
- scope: string;
433
- webUrl: string;
434
- };
435
- /** The Workflow as generic proto3 JSON. */
436
- workflow: Record<string, unknown>;
437
- mcpServers: AutomationExportMcpServer[];
438
- }
439
-
440
- // All response schemas are `.passthrough()`: the backend keeps growing the
441
- // deployment payload (serviceAccountId, egressAllowedDomains, secret
442
- // metadata, ...) and unknown fields must flow through untouched — both so
443
- // parsing never breaks on a newer backend and so `--json` output stays
444
- // faithful to the API instead of silently dropping fields.
445
- const deployAcceptedSchema = z
446
- .object({
447
- id: z.number(),
448
- slug: z.string(),
449
- teamId: z.number(),
450
- status: z.string(),
451
- generation: z.number(),
452
- deploymentKind: z.string(),
453
- engineAlias: z.string(),
454
- aliasToken: z.string().optional(),
455
- })
456
- .passthrough();
457
-
458
- const agentkitDeployAcceptedSchema = z
459
- .object({
460
- applicationId: z.string().min(1),
461
- releaseId: z.string().min(1),
462
- status: z.string(),
463
- })
464
- .passthrough();
465
-
466
- const agentkitDeployStatusSchema = z
467
- .object({
468
- applicationId: z.string().min(1),
469
- releaseId: z.string().min(1),
470
- slug: z.string().min(1),
471
- teamId: z.number(),
472
- status: z.enum(["pending", "deploying", "running", "failed", "stopped"]),
473
- progress: z.enum([
474
- "queued",
475
- "creating",
476
- "building",
477
- "starting",
478
- "finalizing",
479
- "running",
480
- "failed",
481
- "stopped",
482
- ]),
483
- statusMessage: z.string().nullable(),
484
- // Optional: backends that predate the v2 bake-failure column omit it.
485
- lastError: z.string().nullable().optional(),
486
- secretNames: z.array(z.string()).optional(),
487
- })
488
- .passthrough();
489
-
490
- const agentkitDeploymentListItemSchema = z
491
- .object({
492
- architecture: z.literal("v2"),
493
- applicationId: z.string().min(1),
494
- releaseId: z.string().min(1),
495
- slug: z.string().min(1),
496
- teamId: z.number(),
497
- status: agentkitDeployStatusSchema.shape.status,
498
- deployments: z.array(z.object({ desiredUpdatedAt: z.string() }).passthrough()),
499
- })
500
- .passthrough();
501
-
502
- const agentkitDeploymentListResponseSchema = z.object({
503
- deployments: z.array(agentkitDeploymentListItemSchema),
504
- nextPageToken: z.string().nullable(),
505
- });
506
-
507
- const agentkitStopAcceptedSchema = z
508
- .object({
509
- applicationId: z.string().min(1),
510
- releaseId: z.string().min(1),
511
- status: z.string(),
512
- // Tolerate scope values a newer backend may add: parse only "global",
513
- // drop anything else rather than failing the stop response.
514
- scope: z.literal("global").optional().catch(undefined),
515
- deployLocked: z.boolean().optional(),
516
- cancellation: agentkitCancelRunsResultSchema.optional(),
517
- })
518
- .passthrough();
519
-
520
- const agentkitGlobalSuspensionAcceptedSchema = z
521
- .object({
522
- applicationId: z.string().min(1),
523
- status: z.enum(["running", "stopped"]),
524
- cancellation: agentkitCancelRunsResultSchema.optional(),
525
- })
526
- .passthrough();
527
-
528
- const agentkitStartSessionAcceptedSchema = z
529
- .object({
530
- deliveryId: z.string().min(1),
531
- workflowId: z.string().min(1),
532
- sessionMode: z.enum(["event", "continuation"]),
533
- sessionId: z.string().min(1).optional(),
534
- dryRun: z.literal(true).optional(),
535
- asOf: z.string().min(1).optional(),
536
- })
537
- .passthrough();
538
-
539
- const agentkitSessionRunsSchema = z
540
- .object({
541
- executions: z.array(
542
- z
543
- .object({
544
- executionId: z.string().min(1),
545
- writtenAt: z.string(),
546
- turnStatus: z.string(),
547
- durationMs: z.number().nonnegative(),
548
- message: z.string().optional(),
549
- error: z
550
- .object({
551
- name: z.string(),
552
- message: z.string(),
553
- stack: z.string().optional(),
554
- })
555
- .passthrough()
556
- .optional(),
557
- processDeath: z.boolean().optional(),
558
- logs: z.array(
559
- z
560
- .object({
561
- index: z.number(),
562
- at: z.string(),
563
- line: z.string(),
564
- })
565
- .passthrough(),
566
- ),
567
- })
568
- .passthrough(),
569
- ),
570
- startLog: z.string().nullable(),
571
- })
572
- .passthrough();
573
-
574
- const agentkitSessionEventPollSchema = z
575
- .object({
576
- events: z.array(
577
- z
578
- .object({
579
- index: z.number().optional(),
580
- type: z.string().optional(),
581
- })
582
- .passthrough(),
583
- ),
584
- execution: z
585
- .object({
586
- executionId: z.string(),
587
- turnStatus: z.string(),
588
- })
589
- .nullable(),
590
- })
591
- .passthrough();
592
-
593
- const deploymentSchema = z.object({
594
- id: z.number(),
595
- slug: z.string(),
596
- teamId: z.number(),
597
- deploymentKind: z.string(),
598
- gitRepoUrl: z.string().nullable().optional(),
599
- gitRef: z.string().optional(),
600
- agentPath: z.string().optional(),
601
- desiredState: z.string().optional(),
602
- status: z.enum([
603
- "pending",
604
- "deploying",
605
- "running",
606
- "degraded",
607
- "failed",
608
- "stopping",
609
- "stopped",
610
- "deleting",
611
- ]),
612
- progress: z
613
- .enum([
614
- "queued",
615
- "preparing",
616
- "creating",
617
- "building",
618
- "starting",
619
- "finalizing",
620
- "running",
621
- "failed",
622
- "stopping",
623
- "stopped",
624
- "deleting",
625
- "degraded",
626
- ])
627
- .optional(),
628
- statusMessage: z.string().nullable().optional(),
629
- generation: z.number(),
630
- observedGeneration: z.number().nullable().optional(),
631
- engineGeneration: z.number().nullable().optional(),
632
- publicId: z.string().optional(),
633
- engineUrl: z.string().nullable().optional(),
634
- enginePodId: z.string().nullable().optional(),
635
- lastError: z.string().nullable().optional(),
636
- engineAlias: z.string(),
637
- desiredUpdatedAt: z.string().optional(),
638
- lastReconciledAt: z.string().nullable().optional(),
639
- cursorEventRepos: z.array(z.string()).optional(),
640
- egressAllowedDomains: z.array(z.string()).optional(),
641
- publicRoutePaths: z.array(z.string()).optional(),
642
- // String ids (`sa_…`) in prod; older mocks/fixtures used numbers. Null on
643
- // legacy rows that predate service-account-backed deploys.
644
- serviceAccountId: z.union([z.string(), z.number()]).nullable().optional(),
645
- agentStoreSourceId: z.string().optional(),
646
- podCredentialMaskedKey: z.string().nullable().optional(),
647
- secretNames: z.array(z.string()).optional(),
648
- });
649
-
650
- const deploymentListItemSchema = deploymentSchema.passthrough();
651
-
652
- const deploymentDetailSchema = deploymentSchema
653
- .extend({
654
- engineAccess: z
655
- .object({
656
- url: z.string(),
657
- headers: z.record(z.string()),
658
- expiresAt: z.string(),
659
- })
660
- .nullable()
661
- .optional(),
662
- })
663
- .passthrough();
664
-
665
- const listResponseSchema = z.object({
666
- deployments: z.array(deploymentListItemSchema),
667
- });
668
-
669
- const stopAcceptedSchema = z
670
- .object({
671
- id: z.number(),
672
- status: z.string(),
673
- })
674
- .passthrough();
675
-
676
- const rotateResponseSchema = z
677
- .object({
678
- aliasToken: z.string().min(1),
679
- })
680
- .passthrough();
681
-
682
- const setSecretsResponseSchema = z
683
- .object({
684
- secretNames: z.array(z.string()),
685
- })
686
- .passthrough();
687
-
688
- const listSecretsResponseSchema = z
689
- .object({
690
- secrets: z.array(z.object({ name: z.string(), createdAt: z.string() }).passthrough()),
691
- })
692
- .passthrough();
693
-
694
- const containerImageSchema = z
695
- .object({
696
- name: z.string(),
697
- sizeBytes: z.number(),
698
- sha256: z.string().nullable(),
699
- dockerImageId: z.string().nullable(),
700
- platform: z.string().nullable(),
701
- pushedByUserId: z.number().nullable(),
702
- pushedAt: z.string(),
703
- })
704
- .passthrough();
705
-
706
- const listContainerImagesResponseSchema = z
707
- .object({ images: z.array(containerImageSchema), limit: z.number() })
708
- .passthrough();
709
-
710
- const containerImageUploadSchema = z
711
- .object({
712
- name: z.string(),
713
- uploadId: z.string(),
714
- partSizeBytes: z.number().int().positive(),
715
- parts: z.array(z.object({ partNumber: z.number().int().positive(), url: z.string() })),
716
- expiresAt: z.string(),
717
- })
718
- .passthrough();
719
-
720
- const automationExportSchema = z
721
- .object({
722
- automation: z
723
- .object({
724
- uuid: z.string(),
725
- name: z.string(),
726
- enabled: z.boolean(),
727
- scope: z.string(),
728
- webUrl: z.string(),
729
- })
730
- .passthrough(),
731
- workflow: z.record(z.unknown()),
732
- mcpServers: z.array(
733
- z
734
- .object({
735
- id: z.string().optional(),
736
- name: z.string(),
737
- transportType: z.enum(["http", "sse", "stdio"]),
738
- })
739
- .passthrough(),
740
- ),
741
- })
742
- .passthrough();
743
-
744
- // ============================================================================
745
- // Client
746
- // ============================================================================
747
-
748
- export interface AgentServeDeployClientOptions {
749
- backendUrl: string;
750
- apiKey: string;
751
- /** Test seam; defaults to global fetch. */
752
- fetchImpl?: typeof fetch;
753
- }
754
-
755
- export class AgentServeDeployClient {
756
- private readonly backendUrl: string;
757
- private readonly apiKey: string;
758
- private readonly fetchImpl: typeof fetch;
759
-
760
- constructor(options: AgentServeDeployClientOptions) {
761
- this.backendUrl = options.backendUrl.endsWith("/")
762
- ? options.backendUrl.slice(0, -1)
763
- : options.backendUrl;
764
- this.apiKey = options.apiKey;
765
- this.fetchImpl = options.fetchImpl ?? fetch;
766
- }
767
-
768
- /** Create or redeploy; 202 means accepted, not running (poll status). */
769
- async deploy(args: {
770
- teamId: number;
771
- slug: string;
772
- source: DeploySource;
773
- template?: string;
774
- }): Promise<DeployAccepted> {
775
- const slugError = validateDeploymentSlug(args.slug);
776
- if (slugError !== undefined) {
777
- throw new DeployApiError(slugError, 400);
778
- }
779
- for (const domain of args.source.egressAllowedDomains ?? []) {
780
- const domainError = validateEgressDomain(domain);
781
- if (domainError !== undefined) {
782
- throw new DeployApiError(domainError, 400);
783
- }
784
- }
785
- // Only the git-ref member exists today; a future artifact member would
786
- // upload the build first and post a different body from this branch.
787
- const body: Record<string, unknown> = {
788
- teamId: args.teamId,
789
- slug: args.slug,
790
- gitRepoUrl: args.source.gitRepoUrl,
791
- ...(args.source.gitRef === undefined ? {} : { gitRef: args.source.gitRef }),
792
- ...(args.source.agentPath === undefined ? {} : { agentPath: args.source.agentPath }),
793
- ...(args.source.cursorEventRepos === undefined
794
- ? {}
795
- : { cursorEventRepos: args.source.cursorEventRepos }),
796
- ...(args.source.egressAllowedDomains === undefined
797
- ? {}
798
- : { egressAllowedDomains: args.source.egressAllowedDomains }),
799
- // JSON.stringify drops undefined keys.
800
- publicRoutePaths: args.source.publicRoutePaths,
801
- template: args.template,
802
- };
803
- const send = (): Promise<unknown> =>
804
- this.request({
805
- method: "POST",
806
- path: "/internal/agent-serve/deployments",
807
- body,
808
- context: { verb: "deploy", slug: args.slug },
809
- });
810
- let raw: unknown;
811
- try {
812
- raw = await send();
813
- } catch (error) {
814
- const unsupportedTemplate =
815
- args.template !== undefined &&
816
- error instanceof DeployApiError &&
817
- error.status === 400 &&
818
- error.message.toLowerCase().includes("template") &&
819
- /unrecognized|unknown/i.test(error.message);
820
- if (!unsupportedTemplate) {
821
- throw error;
822
- }
823
- delete body.template;
824
- raw = await send();
825
- }
826
- return deployAcceptedSchema.parse(raw);
827
- }
828
-
829
- /**
830
- * Create or redeploy onto the v2 control plane
831
- * (`POST /internal/agentsdk/deployments`). 202 means accepted; poll
832
- * {@link getAgentkitDeploy} until a terminal status. `components` deploys
833
- * one application with several release components (one per agent
834
- * directory); it is mutually exclusive with `agentPath`.
835
- */
836
- async deployAgentkit(args: {
837
- teamId: number;
838
- slug: string;
839
- gitRepoUrl: string;
840
- gitRef?: string;
841
- agentPath?: string;
842
- components?: AgentkitDeployComponent[];
843
- repositories?: string[];
844
- /** Redeploy an existing Cursor-managed (multi-tenant) product. */
845
- multiTenant?: boolean;
846
- persistent?: boolean;
847
- /** Single-agent `hosting.image`; components carry their own. */
848
- image?: string;
849
- }): Promise<AgentkitDeployAccepted> {
850
- const slugError = validateDeploymentSlug(args.slug);
851
- if (slugError !== undefined) {
852
- throw new DeployApiError(slugError, 400);
853
- }
854
- for (const component of args.components ?? []) {
855
- const keyError = validateDeploymentSlug(component.componentKey);
856
- if (keyError !== undefined) {
857
- throw new DeployApiError(
858
- `Invalid component key ${JSON.stringify(component.componentKey)}: use lowercase letters, digits, '-' or '_' (max 64 chars)`,
859
- 400,
860
- );
861
- }
862
- }
863
- const raw = await this.request({
864
- method: "POST",
865
- path: "/internal/agentsdk/deployments",
866
- body: {
867
- teamId: args.teamId,
868
- slug: args.slug,
869
- gitRepoUrl: args.gitRepoUrl,
870
- gitRef: args.gitRef,
871
- agentPath: args.agentPath,
872
- components: args.components,
873
- repositories:
874
- args.repositories !== undefined && args.repositories.length > 0
875
- ? args.repositories
876
- : undefined,
877
- ...(args.multiTenant === true ? { multiTenant: true } : {}),
878
- persistent: args.persistent,
879
- ...(args.image === undefined ? {} : { image: args.image }),
880
- },
881
- context: { verb: "deploy", slug: args.slug },
882
- });
883
- return agentkitDeployAcceptedSchema.parse(raw);
884
- }
885
-
886
- async getAgentkitDeploy(args: { teamId: number; slug: string }): Promise<AgentkitDeployStatus> {
887
- const raw = await this.request({
888
- method: "GET",
889
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}?teamId=${args.teamId}`,
890
- context: { verb: "get deployment", slug: args.slug },
891
- });
892
- return agentkitDeployStatusSchema.parse(raw);
893
- }
894
-
895
- /**
896
- * Stop a v2 deployment (`POST /internal/agentsdk/deployments/:slug/stop`).
897
- * 202 means accepted; poll {@link getAgentkitDeploy} until `stopped`.
898
- */
899
- async stopAgentkit(args: {
900
- teamId: number;
901
- slug: string;
902
- cancelRuns?: boolean;
903
- }): Promise<AgentkitStopAccepted> {
904
- const raw = await this.request({
905
- method: "POST",
906
- path:
907
- `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/stop?teamId=${args.teamId}` +
908
- (args.cancelRuns === true ? "&cancelRuns=true" : ""),
909
- context: { verb: "stop", slug: args.slug },
910
- });
911
- return agentkitStopAcceptedSchema.parse(raw);
912
- }
913
-
914
- /**
915
- * Start a v2 deployment (`POST /internal/agentsdk/deployments/:slug/start`).
916
- * Older backends only expose `/global-resume`; fall back there.
917
- */
918
- async startAgentkit(args: {
919
- teamId: number;
920
- slug: string;
921
- }): Promise<AgentkitGlobalSuspensionAccepted> {
922
- const encoded = encodeURIComponent(args.slug);
923
- try {
924
- const raw = await this.request({
925
- method: "POST",
926
- path: `/internal/agentsdk/deployments/${encoded}/start?teamId=${args.teamId}`,
927
- context: { verb: "start", slug: args.slug },
928
- });
929
- return agentkitGlobalSuspensionAcceptedSchema.parse(raw);
930
- } catch (error) {
931
- if (!(error instanceof DeployApiError) || error.status !== 404) {
932
- throw error;
933
- }
934
- const raw = await this.request({
935
- method: "POST",
936
- path: `/internal/agentsdk/deployments/${encoded}/global-resume?teamId=${args.teamId}`,
937
- context: { verb: "start", slug: args.slug },
938
- });
939
- return agentkitGlobalSuspensionAcceptedSchema.parse(raw);
940
- }
941
- }
942
-
943
- async setAgentkitGlobalSuspension(args: {
944
- teamId: number;
945
- slug: string;
946
- suspended: boolean;
947
- cancelRuns?: boolean;
948
- }): Promise<AgentkitGlobalSuspensionAccepted> {
949
- const action = args.suspended ? "global-stop" : "global-resume";
950
- const cancelQuery =
951
- args.suspended === true && args.cancelRuns === true ? "&cancelRuns=true" : "";
952
- const raw = await this.request({
953
- method: "POST",
954
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/${action}?teamId=${args.teamId}${cancelQuery}`,
955
- context: {
956
- verb: args.suspended ? "globally stop" : "globally resume",
957
- slug: args.slug,
958
- },
959
- });
960
- return agentkitGlobalSuspensionAcceptedSchema.parse(raw);
961
- }
962
-
963
- async killAgentkit(args: { teamId: number; slug: string }): Promise<AgentkitStopAccepted> {
964
- const raw = await this.request({
965
- method: "POST",
966
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/kill?teamId=${args.teamId}`,
967
- context: { verb: "kill", slug: args.slug },
968
- });
969
- return agentkitStopAcceptedSchema.parse(raw);
970
- }
971
-
972
- async unlockAgentkitDeploys(args: {
973
- teamId: number;
974
- slug: string;
975
- }): Promise<{ applicationId: string; deployLocked: boolean }> {
976
- const raw = await this.request({
977
- method: "POST",
978
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/unlock-deploys?teamId=${args.teamId}`,
979
- context: { verb: "unlock deploys", slug: args.slug },
980
- });
981
- return z
982
- .object({
983
- applicationId: z.string().min(1),
984
- deployLocked: z.literal(false),
985
- })
986
- .parse(raw);
987
- }
988
-
989
- async cancelAgentkitRuns(args: {
990
- teamId: number;
991
- slug: string;
992
- }): Promise<AgentkitCancelRunsResult> {
993
- const raw = await this.request({
994
- method: "POST",
995
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/cancel-runs?teamId=${args.teamId}`,
996
- context: { verb: "cancel runs", slug: args.slug },
997
- });
998
- return agentkitCancelRunsResultSchema.parse(raw);
999
- }
1000
-
1001
- /**
1002
- * Repoint a v2 install's event repositories
1003
- * (`PUT /internal/agentsdk/deployments/:slug/event-repositories`). Deploy
1004
- * cannot carry these for a multi-tenant product.
1005
- */
1006
- async setAgentkitEventRepositories(args: {
1007
- teamId: number;
1008
- slug: string;
1009
- repositories: string[];
1010
- }): Promise<string[]> {
1011
- const raw = await this.request({
1012
- method: "PUT",
1013
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/event-repositories?teamId=${args.teamId}`,
1014
- body: { repositories: args.repositories },
1015
- context: { verb: "set event repositories", slug: args.slug },
1016
- });
1017
- return agentkitEventRepositoriesSchema.parse(raw).repositories;
1018
- }
1019
-
1020
- async upgradeAgentkitInstall(args: {
1021
- teamId: number;
1022
- slug: string;
1023
- releaseId?: string;
1024
- version?: string;
1025
- }): Promise<string> {
1026
- return this.pinAgentkitInstall("upgrade", args);
1027
- }
1028
-
1029
- async rollbackAgentkitInstall(args: {
1030
- teamId: number;
1031
- slug: string;
1032
- releaseId?: string;
1033
- version?: string;
1034
- }): Promise<string> {
1035
- return this.pinAgentkitInstall("rollback", args);
1036
- }
1037
-
1038
- private async pinAgentkitInstall(
1039
- direction: "upgrade" | "rollback",
1040
- args: {
1041
- teamId: number;
1042
- slug: string;
1043
- releaseId?: string;
1044
- version?: string;
1045
- },
1046
- ): Promise<string> {
1047
- const raw = await this.request({
1048
- method: direction === "upgrade" ? "PUT" : "POST",
1049
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/${direction === "upgrade" ? "release" : "rollback"}?teamId=${args.teamId}`,
1050
- body: {
1051
- ...(args.releaseId === undefined ? {} : { releaseId: args.releaseId }),
1052
- ...(args.version === undefined ? {} : { version: args.version }),
1053
- },
1054
- context: {
1055
- verb: direction === "upgrade" ? "upgrade" : "roll back",
1056
- slug: args.slug,
1057
- },
1058
- });
1059
- return agentkitInstallReleaseSchema.parse(raw).releaseId;
1060
- }
1061
-
1062
- /**
1063
- * Delete a v2 deployment (`DELETE /internal/agentsdk/deployments/:slug`).
1064
- * 202 means accepted; poll {@link getAgentkitDeploy} until 404.
1065
- */
1066
- async deleteAgentkit(args: { teamId: number; slug: string }): Promise<AgentkitStopAccepted> {
1067
- const raw = await this.request({
1068
- method: "DELETE",
1069
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}?teamId=${args.teamId}`,
1070
- context: { verb: "delete", slug: args.slug },
1071
- });
1072
- return agentkitStopAcceptedSchema.parse(raw);
1073
- }
1074
-
1075
- /**
1076
- * Start (or, with `sessionId`, resume) a hosted v2 session through the
1077
- * control plane (`POST /internal/agentsdk/deployments/:slug/sessions`).
1078
- * Does not talk to the v1 engine alias or `/engine/*`.
1079
- */
1080
- async startSession(args: {
1081
- teamId: number;
1082
- slug: string;
1083
- message: string;
1084
- sessionId?: string;
1085
- dryRun?: boolean;
1086
- asOf?: string;
1087
- componentKey?: string;
1088
- }): Promise<AgentkitStartSessionAccepted> {
1089
- const raw = await this.request({
1090
- method: "POST",
1091
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/sessions`,
1092
- body: {
1093
- teamId: args.teamId,
1094
- message: args.message,
1095
- sessionId: args.sessionId,
1096
- dryRun: args.dryRun === true ? true : undefined,
1097
- asOf: args.asOf,
1098
- componentKey: args.componentKey,
1099
- },
1100
- context: { verb: "start session", slug: args.slug },
1101
- });
1102
- return agentkitStartSessionAcceptedSchema.parse(raw);
1103
- }
1104
-
1105
- /** Hosted executions and the start-log tee for one v2 session. */
1106
- async getAgentkitSessionRuns(args: {
1107
- teamId: number;
1108
- slug: string;
1109
- sessionId: string;
1110
- }): Promise<AgentkitSessionRuns> {
1111
- const raw = await this.request({
1112
- method: "GET",
1113
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/sessions/${encodeURIComponent(args.sessionId)}/runs?teamId=${args.teamId}`,
1114
- context: { verb: "get session runs", slug: args.slug },
1115
- });
1116
- return agentkitSessionRunsSchema.parse(raw);
1117
- }
1118
-
1119
- /** Events written so far. Pass `afterEventIndex: -1` to read from the start. */
1120
- async getAgentkitSessionEvents(args: {
1121
- teamId: number;
1122
- slug: string;
1123
- sessionId: string;
1124
- afterEventIndex: number;
1125
- }): Promise<AgentkitSessionEventPoll> {
1126
- const raw = await this.request({
1127
- method: "GET",
1128
- path:
1129
- `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}` +
1130
- `/sessions/${encodeURIComponent(args.sessionId)}/events` +
1131
- `?teamId=${args.teamId}&afterEventIndex=${args.afterEventIndex}`,
1132
- context: { verb: "get session events", slug: args.slug },
1133
- });
1134
- return agentkitSessionEventPollSchema.parse(raw);
1135
- }
1136
-
1137
- async listDeployments(args: { teamId: number }): Promise<Deployment[]> {
1138
- const raw = await this.request({
1139
- method: "GET",
1140
- path: `/internal/agent-serve/deployments?teamId=${args.teamId}`,
1141
- context: { verb: "list deployments" },
1142
- });
1143
- return listResponseSchema.parse(raw).deployments;
1144
- }
1145
-
1146
- async listAgentkitDeployments(args: { teamId: number }): Promise<AgentkitDeploymentListItem[]> {
1147
- const deployments: AgentkitDeploymentListItem[] = [];
1148
- let pageToken: string | null = null;
1149
- do {
1150
- const qs =
1151
- `teamId=${args.teamId}&pageSize=100` +
1152
- (pageToken === null ? "" : `&pageToken=${encodeURIComponent(pageToken)}`);
1153
- const page = agentkitDeploymentListResponseSchema.parse(
1154
- await this.request({
1155
- method: "GET",
1156
- path: `/internal/agentsdk/deployments?${qs}`,
1157
- context: { verb: "list architecture v2 deployments" },
1158
- }),
1159
- );
1160
- deployments.push(...page.deployments);
1161
- pageToken = page.nextPageToken;
1162
- } while (pageToken !== null);
1163
- return deployments;
1164
- }
1165
-
1166
- async getDeployment(args: { teamId: number; slug: string }): Promise<DeploymentDetail> {
1167
- const raw = await this.request({
1168
- method: "GET",
1169
- path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}?teamId=${args.teamId}`,
1170
- context: { verb: "get deployment", slug: args.slug },
1171
- });
1172
- return deploymentDetailSchema.parse(raw);
1173
- }
1174
-
1175
- async stopDeployment(args: { teamId: number; slug: string }): Promise<StopAccepted> {
1176
- const raw = await this.request({
1177
- method: "POST",
1178
- path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/stop?teamId=${args.teamId}`,
1179
- context: { verb: "stop", slug: args.slug },
1180
- });
1181
- return stopAcceptedSchema.parse(raw);
1182
- }
1183
-
1184
- async deleteDeployment(args: { teamId: number; slug: string }): Promise<DeleteAccepted> {
1185
- const raw = await this.request({
1186
- method: "DELETE",
1187
- path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}?teamId=${args.teamId}`,
1188
- context: { verb: "delete", slug: args.slug },
1189
- });
1190
- return stopAcceptedSchema.parse(raw);
1191
- }
1192
-
1193
- /** Returns the new alias token exactly once; the old one dies now. */
1194
- async rotateAliasToken(args: { teamId: number; slug: string }): Promise<string> {
1195
- const raw = await this.request({
1196
- method: "POST",
1197
- path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/rotate-alias-token?teamId=${args.teamId}`,
1198
- context: { verb: "rotate alias token", slug: args.slug },
1199
- });
1200
- return rotateResponseSchema.parse(raw).aliasToken;
1201
- }
1202
-
1203
- /** Rotate the alias token on an AgentSDK v2 deployment. */
1204
- async rotateAgentsdkAliasToken(args: { teamId: number; slug: string }): Promise<string> {
1205
- const raw = await this.request({
1206
- method: "POST",
1207
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/rotate-alias-token?teamId=${args.teamId}`,
1208
- context: { verb: "rotate alias token", slug: args.slug },
1209
- });
1210
- return rotateResponseSchema.parse(raw).aliasToken;
1211
- }
1212
-
1213
- /**
1214
- * Upsert secrets by name (unlisted names stay untouched). Returns the
1215
- * post-write union of secret names, sorted. Validates names and value
1216
- * sizes client-side with the backend's grammar before any network call.
1217
- */
1218
- async setSecrets(args: {
1219
- teamId: number;
1220
- slug: string;
1221
- secrets: Array<{ name: string; value: string }>;
1222
- }): Promise<string[]> {
1223
- this.validateSecrets(args.secrets);
1224
- const raw = await this.request({
1225
- method: "PUT",
1226
- path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/secrets`,
1227
- body: { teamId: args.teamId, secrets: args.secrets },
1228
- context: { verb: "set secrets", slug: args.slug },
1229
- });
1230
- return setSecretsResponseSchema.parse(raw).secretNames;
1231
- }
1232
-
1233
- /** Upsert application-scoped secrets on an AgentSDK v2 deployment. */
1234
- async setAgentkitSecrets(args: {
1235
- teamId: number;
1236
- slug: string;
1237
- secrets: Array<{ name: string; value: string }>;
1238
- }): Promise<string[]> {
1239
- this.validateSecrets(args.secrets);
1240
- const raw = await this.request({
1241
- method: "PUT",
1242
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/secrets`,
1243
- body: { teamId: args.teamId, secrets: args.secrets },
1244
- context: { verb: "set secrets", slug: args.slug },
1245
- });
1246
- return setSecretsResponseSchema.parse(raw).secretNames;
1247
- }
1248
-
1249
- /** Secret names + creation times; values are never returned. */
1250
- async listSecrets(args: { teamId: number; slug: string }): Promise<SecretInfo[]> {
1251
- const raw = await this.request({
1252
- method: "GET",
1253
- path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/secrets?teamId=${args.teamId}`,
1254
- context: { verb: "list secrets", slug: args.slug },
1255
- });
1256
- return listSecretsResponseSchema.parse(raw).secrets;
1257
- }
1258
-
1259
- /** Secret names + creation times for an AgentSDK v2 application. */
1260
- async listAgentkitSecrets(args: { teamId: number; slug: string }): Promise<SecretInfo[]> {
1261
- const raw = await this.request({
1262
- method: "GET",
1263
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/secrets?teamId=${args.teamId}`,
1264
- context: { verb: "list secrets", slug: args.slug },
1265
- });
1266
- return listSecretsResponseSchema.parse(raw).secrets;
1267
- }
1268
-
1269
- /** Remove one secret by name; 404 when it is not set. */
1270
- async deleteSecret(args: { teamId: number; slug: string; name: string }): Promise<void> {
1271
- const nameError = validateSettableSecretName(args.name);
1272
- if (nameError !== undefined) {
1273
- throw new DeployApiError(nameError, 400);
1274
- }
1275
- await this.request({
1276
- method: "DELETE",
1277
- path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/secrets/${encodeURIComponent(args.name)}?teamId=${args.teamId}`,
1278
- context: { verb: "unset secret", slug: args.slug },
1279
- });
1280
- }
1281
-
1282
- /** Remove one application-scoped secret from an AgentSDK v2 deployment. */
1283
- async deleteAgentkitSecret(args: { teamId: number; slug: string; name: string }): Promise<void> {
1284
- const nameError = validateSettableSecretName(args.name);
1285
- if (nameError !== undefined) {
1286
- throw new DeployApiError(nameError, 400);
1287
- }
1288
- await this.request({
1289
- method: "DELETE",
1290
- path: `/internal/agentsdk/deployments/${encodeURIComponent(args.slug)}/secrets/${encodeURIComponent(args.name)}?teamId=${args.teamId}`,
1291
- context: { verb: "unset secret", slug: args.slug },
1292
- });
1293
- }
1294
-
1295
- private validateSecrets(secrets: Array<{ name: string; value: string }>): void {
1296
- for (const { name, value } of secrets) {
1297
- const nameError = validateSettableSecretName(name);
1298
- if (nameError !== undefined) {
1299
- throw new DeployApiError(nameError, 400);
1300
- }
1301
- if (Buffer.byteLength(value, "utf8") > MAX_SECRET_VALUE_BYTES) {
1302
- throw new DeployApiError(
1303
- `The value for ${name} is too large (max ${MAX_SECRET_VALUE_BYTES} bytes).`,
1304
- 400,
1305
- );
1306
- }
1307
- }
1308
- if (secrets.length > MAX_SECRETS) {
1309
- throw new DeployApiError(
1310
- `Too many secrets in one request (${secrets.length}); deployments hold at most ${MAX_SECRETS}.`,
1311
- 400,
1312
- );
1313
- }
1314
- }
1315
-
1316
- /**
1317
- * Read an Automation's exported workflow definition for
1318
- * `convert-automation`. Missing, no-access, and gate-off all surface as
1319
- * indistinguishable 404s on the backend, so they map to one message here
1320
- * (the wrong-host 404 hint from {@link mapErrorResponse} passes through).
1321
- */
1322
- async exportAutomation(args: { uuid: string }): Promise<AutomationExport> {
1323
- let raw: unknown;
1324
- try {
1325
- raw = await this.request({
1326
- method: "GET",
1327
- path: `/internal/agent-serve/automations/${encodeURIComponent(args.uuid)}/export`,
1328
- context: { verb: "export automation" },
1329
- });
1330
- } catch (error) {
1331
- if (
1332
- error instanceof DeployApiError &&
1333
- error.status === 404 &&
1334
- !error.message.includes("api.cursor.com")
1335
- ) {
1336
- throw new DeployApiError(
1337
- `Automation ${args.uuid} was not found or you don't have access to it (the agent_serve_mvp feature gate may also be off for your team).`,
1338
- 404,
1339
- );
1340
- }
1341
- throw error;
1342
- }
1343
- return automationExportSchema.parse(raw);
1344
- }
1345
-
1346
- /** Full URL of the stable engine alias for a deployment. */
1347
- aliasUrl(engineAlias: string): string {
1348
- return `${this.backendUrl}${engineAlias}`;
1349
- }
1350
-
1351
- /**
1352
- * Stable remote MCP gateway URL for a deployment, on the user-API-key
1353
- * surface (headless / CLI, `agent-sdk login` credential). The gateway
1354
- * mints/refreshes engineAccess server-side and proxies `/v1/mcp` to the
1355
- * pod, so a signed-in client never sees a pod hostname or port token.
1356
- */
1357
- mcpGatewayUrl(teamId: number, slug: string): string {
1358
- return `${this.backendUrl}/internal/agent-serve/mcp/${teamId}/${encodeURIComponent(slug)}`;
1359
- }
1360
-
1361
- /** Team container images, newest first, with the per-team cap. */
1362
- async listContainerImages(args: {
1363
- teamId: number;
1364
- }): Promise<{ images: ContainerImageInfo[]; limit: number }> {
1365
- const raw = await this.request({
1366
- method: "GET",
1367
- path: `/internal/agentsdk/images?teamId=${args.teamId}`,
1368
- context: { verb: "list images" },
1369
- });
1370
- return listContainerImagesResponseSchema.parse(raw);
1371
- }
1372
-
1373
- /** Start (or restart) the upload for `name`; 409 when a new name would exceed the cap. */
1374
- async beginContainerImageUpload(args: {
1375
- teamId: number;
1376
- name: string;
1377
- sizeBytes: number;
1378
- sha256: string;
1379
- dockerImageId?: string;
1380
- platform?: string;
1381
- }): Promise<ContainerImageUpload> {
1382
- const { name, ...body } = args;
1383
- const raw = await this.request({
1384
- method: "POST",
1385
- path: `/internal/agentsdk/images/${encodeURIComponent(name)}/begin`,
1386
- body,
1387
- context: { verb: "push image" },
1388
- });
1389
- return containerImageUploadSchema.parse(raw);
1390
- }
1391
-
1392
- /** Every part is uploaded: complete the object and mark the image ready. */
1393
- async finalizeContainerImage(args: {
1394
- teamId: number;
1395
- name: string;
1396
- uploadId: string;
1397
- parts: Array<{ partNumber: number; etag: string }>;
1398
- }): Promise<ContainerImageInfo> {
1399
- const raw = await this.request({
1400
- method: "POST",
1401
- path: `/internal/agentsdk/images/${encodeURIComponent(args.name)}/finalize`,
1402
- body: { teamId: args.teamId, uploadId: args.uploadId, parts: args.parts },
1403
- context: { verb: "push image" },
1404
- });
1405
- return z.object({ image: containerImageSchema }).passthrough().parse(raw).image;
1406
- }
1407
-
1408
- /** Remove one image and its tarball; 404 when there is none by that name. */
1409
- async deleteContainerImage(args: { teamId: number; name: string }): Promise<void> {
1410
- await this.request({
1411
- method: "DELETE",
1412
- path: `/internal/agentsdk/images/${encodeURIComponent(args.name)}?teamId=${args.teamId}`,
1413
- context: { verb: "remove image" },
1414
- });
1415
- }
1416
-
1417
- private async request(args: {
1418
- method: "GET" | "POST" | "PUT" | "DELETE";
1419
- path: string;
1420
- body?: unknown;
1421
- context: { verb: string; slug?: string };
1422
- }): Promise<unknown> {
1423
- let response: Response;
1424
- try {
1425
- response = await this.fetchImpl(`${this.backendUrl}${args.path}`, {
1426
- method: args.method,
1427
- headers: {
1428
- accept: "application/json",
1429
- authorization: `Bearer ${this.apiKey}`,
1430
- ...(args.body === undefined ? {} : { "content-type": "application/json" }),
1431
- },
1432
- ...(args.body === undefined ? {} : { body: JSON.stringify(args.body) }),
1433
- signal: AbortSignal.timeout(60_000),
1434
- });
1435
- } catch (error) {
1436
- throw new DeployApiError(
1437
- `Could not reach the Cursor backend at ${this.backendUrl}: ${
1438
- error instanceof Error ? error.message : String(error)
1439
- }`,
1440
- 0,
1441
- );
1442
- }
1443
- const text = await response.text();
1444
- if (!response.ok) {
1445
- throw mapErrorResponse(response, text, args.context);
1446
- }
1447
- try {
1448
- return JSON.parse(text) as unknown;
1449
- } catch {
1450
- throw new DeployApiError(
1451
- `The Cursor backend returned a non-JSON response to ${args.context.verb}.`,
1452
- response.status,
1453
- );
1454
- }
1455
- }
1456
- }
1457
-
1458
- const MCP_GATEWAY_PATH = /^\/internal\/agent-serve\/mcp\/(\d+)\/([^/]+)(?:\/tools)?\/?$/;
1459
-
1460
- /**
1461
- * Inverse of {@link AgentServeDeployClient.mcpGatewayUrl}. Also accepts
1462
- * the hosted `--cloud-tools-url` form (`…/tools`).
1463
- */
1464
- export function parseAgentServeMcpGatewayUrl(
1465
- url: string,
1466
- ): { teamId: number; slug: string } | undefined {
1467
- let parsed: URL;
1468
- try {
1469
- parsed = new URL(url);
1470
- } catch {
1471
- return undefined;
1472
- }
1473
- const match = MCP_GATEWAY_PATH.exec(parsed.pathname);
1474
- if (match === null) {
1475
- return undefined;
1476
- }
1477
- const teamId = Number.parseInt(match[1]!, 10);
1478
- if (!Number.isInteger(teamId) || teamId <= 0) {
1479
- return undefined;
1480
- }
1481
- const slug = decodeURIComponent(match[2]!);
1482
- if (validateDeploymentSlug(slug) !== undefined) {
1483
- return undefined;
1484
- }
1485
- return { teamId, slug };
1486
- }
1487
-
1488
- // ============================================================================
1489
- // Error mapping (HTTP → actionable human messages)
1490
- // ============================================================================
1491
-
1492
- function serverErrorText(bodyText: string): string | undefined {
1493
- try {
1494
- const parsed = JSON.parse(bodyText) as { error?: unknown };
1495
- if (typeof parsed.error === "string" && parsed.error !== "") {
1496
- return parsed.error;
1497
- }
1498
- } catch {
1499
- // Non-JSON body — fall through.
1500
- }
1501
- return undefined;
1502
- }
1503
-
1504
- function mapErrorResponse(
1505
- response: Response,
1506
- bodyText: string,
1507
- context: { verb: string; slug?: string },
1508
- ): DeployApiError {
1509
- const serverError = serverErrorText(bodyText);
1510
- const slugPart = context.slug === undefined ? "" : ` "${context.slug}"`;
1511
- switch (response.status) {
1512
- case 400:
1513
- return new DeployApiError(
1514
- serverError ?? `The ${context.verb} request was rejected as invalid.`,
1515
- 400,
1516
- );
1517
- case 401:
1518
- return new DeployApiError(
1519
- "The Cursor API key was rejected. Run `agent-sdk login` again or update CURSOR_API_KEY.",
1520
- 401,
1521
- );
1522
- case 403:
1523
- return new DeployApiError(
1524
- `${serverError ?? "Not authorized"} — deploying needs team membership and the cloud-agent entitlement on that team.`,
1525
- 403,
1526
- );
1527
- case 404: {
1528
- // Fastify's route-not-found envelope means we hit the wrong host
1529
- // (api2 vs api.cursor.com), not a missing deployment / closed gate.
1530
- if (/Route \S+ not found/i.test(bodyText)) {
1531
- return new DeployApiError(
1532
- `Agent Serve deploy API not found on this host — use the default api.cursor.com (unset CURSOR_API_BASE_URL), or point CURSOR_API_BASE_URL at a backend that mounts /internal/agent-serve/* and /internal/agentsdk/*.`,
1533
- 404,
1534
- );
1535
- }
1536
- return new DeployApiError(
1537
- context.slug === undefined
1538
- ? `Not found — the agent_serve_mvp feature gate may not be enabled for your team.`
1539
- : `Deployment${slugPart} was not found — check the slug and --team, or the agent_serve_mvp feature gate may not be enabled for your team.`,
1540
- 404,
1541
- );
1542
- }
1543
- case 409:
1544
- // The server's 409 body distinguishes real conflicts (CAS races,
1545
- // "still deploying", architecture-v2 slugs on the v1 surface); keep
1546
- // its message when present.
1547
- return new DeployApiError(
1548
- serverError ??
1549
- `A concurrent deploy or stop is changing deployment${slugPart}; retry in a moment.`,
1550
- 409,
1551
- );
1552
- case 429: {
1553
- const retryAfterHeader = response.headers.get("retry-after");
1554
- const retryAfterSeconds =
1555
- retryAfterHeader !== null && /^\d+$/.test(retryAfterHeader)
1556
- ? Number(retryAfterHeader)
1557
- : undefined;
1558
- return new DeployApiError(
1559
- `${serverError ?? "Rate limited"}${
1560
- retryAfterSeconds === undefined ? "" : ` — retry in ${retryAfterSeconds}s`
1561
- }`,
1562
- 429,
1563
- retryAfterSeconds,
1564
- );
1565
- }
1566
- default:
1567
- return new DeployApiError(
1568
- `The ${context.verb} request failed (${response.status}): ${
1569
- serverError ?? bodyText.slice(0, 300) ?? "(empty body)"
1570
- }`,
1571
- response.status,
1572
- );
1573
- }
1574
- }