@agentstep/agent-sdk 0.5.27 → 0.5.33

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 (205) hide show
  1. package/dist/auth/middleware.js +8 -8
  2. package/dist/backends/claude/args.js +6 -6
  3. package/dist/backends/claude/index.js +11 -11
  4. package/dist/backends/codex/auth.js +6 -6
  5. package/dist/backends/codex/index.js +10 -10
  6. package/dist/backends/factory/auth.js +6 -6
  7. package/dist/backends/factory/index.js +12 -12
  8. package/dist/backends/gemini/auth.js +6 -6
  9. package/dist/backends/gemini/index.js +13 -13
  10. package/dist/backends/opencode/args.js +1 -1
  11. package/dist/backends/opencode/auth.js +6 -6
  12. package/dist/backends/opencode/index.js +14 -14
  13. package/dist/backends/pi/args.js +1 -1
  14. package/dist/backends/pi/auth.js +6 -6
  15. package/dist/backends/pi/index.js +11 -11
  16. package/dist/backends/registry.js +29 -29
  17. package/dist/{chunk-PZKWZKRP.js → chunk-2KF2TIEY.js} +5 -5
  18. package/dist/{chunk-GPGBT7JD.js → chunk-3B4JRSYA.js} +5 -5
  19. package/dist/{chunk-LJNLU5PQ.js → chunk-3NUTTKE5.js} +2 -2
  20. package/dist/{chunk-MZ6HBYGV.js → chunk-65XY7HRS.js} +7 -7
  21. package/dist/{chunk-US26CY2Y.js → chunk-6EIONZ7F.js} +2 -2
  22. package/dist/{chunk-OQ33WLYG.js → chunk-6RRK27I3.js} +3 -3
  23. package/dist/chunk-6SD6MC2B.js +29 -0
  24. package/dist/{chunk-ENFWZ2QM.js → chunk-6U6HEVSN.js} +7 -3
  25. package/dist/{chunk-J7XHNSPO.js → chunk-7JA6HCMK.js} +2 -2
  26. package/dist/{chunk-7HTCDMOB.js → chunk-7PFDF5PN.js} +7 -7
  27. package/dist/{chunk-UB7GS7XT.js → chunk-A3FQHVUG.js} +7 -7
  28. package/dist/{chunk-ZP5QO5BR.js → chunk-ABUNDZCE.js} +1 -1
  29. package/dist/{chunk-Q62QJXGO.js → chunk-AGIXZFHQ.js} +1 -1
  30. package/dist/{chunk-ELK5PVI3.js → chunk-AK6HMO7I.js} +8 -8
  31. package/dist/{chunk-BYUIOMPX.js → chunk-AKGWEACL.js} +23 -23
  32. package/dist/{chunk-NKOGWVP3.js → chunk-AUEKXYNE.js} +4 -4
  33. package/dist/{chunk-A6FHXGSI.js → chunk-B24Q4CUC.js} +5 -5
  34. package/dist/{chunk-SKVAM5H2.js → chunk-B3W3E5CS.js} +1 -1
  35. package/dist/{chunk-5AV732JY.js → chunk-BKMY6TSV.js} +2 -2
  36. package/dist/{chunk-H5UBRKRU.js → chunk-C3UXUDZS.js} +4 -4
  37. package/dist/{chunk-QQGXM2OQ.js → chunk-C7P2TYOG.js} +1 -1
  38. package/dist/{chunk-VOHHDBIX.js → chunk-CHNJK2KW.js} +2 -2
  39. package/dist/{chunk-A3MNXVCR.js → chunk-CJIGDJIJ.js} +3 -3
  40. package/dist/{chunk-BW6OSLW7.js → chunk-CWB2DQN5.js} +14 -6
  41. package/dist/{chunk-JC2XJBV2.js → chunk-CWVYFBZF.js} +4 -4
  42. package/dist/{chunk-4ENK7S24.js → chunk-CXYMVLYK.js} +4 -0
  43. package/dist/{chunk-LDUQ4FHX.js → chunk-DAOKOXGY.js} +17 -17
  44. package/dist/{chunk-R37QM2U4.js → chunk-DF34ESOO.js} +1 -1
  45. package/dist/{chunk-GKNBECPD.js → chunk-DZKBUOYU.js} +2 -2
  46. package/dist/{chunk-XPPOMXTN.js → chunk-EUMA5Q4U.js} +4 -4
  47. package/dist/{chunk-FC3UAHXM.js → chunk-FDLQ3IUB.js} +1 -1
  48. package/dist/{chunk-FDL2JHXO.js → chunk-GCT7A5KR.js} +2 -2
  49. package/dist/{chunk-Z5XQQN7H.js → chunk-HWWFRSAX.js} +4 -4
  50. package/dist/{chunk-KWG7NGYF.js → chunk-I2RVN7CP.js} +4 -4
  51. package/dist/{chunk-JCIAIJFF.js → chunk-IC2ETYU5.js} +3 -3
  52. package/dist/{chunk-3FLQ7KZP.js → chunk-IMJTHYN3.js} +1 -1
  53. package/dist/{chunk-ISGA4AOC.js → chunk-J6ESQUW6.js} +2 -2
  54. package/dist/{chunk-Y3V4COP7.js → chunk-J7F2OFWQ.js} +5 -5
  55. package/dist/chunk-J7VBHBXL.js +210 -0
  56. package/dist/{chunk-A4GJADRQ.js → chunk-JF777FWD.js} +2 -2
  57. package/dist/{chunk-IDQKHWWN.js → chunk-JFHYXFAL.js} +1 -1
  58. package/dist/{chunk-ZTHH374G.js → chunk-JMDV55BV.js} +2 -2
  59. package/dist/{chunk-WG3N6VUA.js → chunk-JN3DHH7Z.js} +11 -11
  60. package/dist/{chunk-MYRTMYTN.js → chunk-JNLVQGSH.js} +6 -6
  61. package/dist/{chunk-FQQ2R6FA.js → chunk-JNSJKHYX.js} +1 -1
  62. package/dist/{chunk-TJORQTH6.js → chunk-KGOOCFQY.js} +1 -1
  63. package/dist/chunk-KLGAE7V4.js +108 -0
  64. package/dist/{chunk-VEPT2NDJ.js → chunk-KSL2D4AD.js} +3 -3
  65. package/dist/{chunk-MNW6D7T4.js → chunk-M72ERPMT.js} +1 -1
  66. package/dist/{chunk-IC5ZTBAW.js → chunk-MUARVVXF.js} +3 -3
  67. package/dist/{chunk-G6XFFNCQ.js → chunk-N7XSXI5O.js} +18 -18
  68. package/dist/{chunk-NOW46DBT.js → chunk-NLJK7FEN.js} +3 -3
  69. package/dist/{chunk-BRULBMRN.js → chunk-NSUVDKNC.js} +3 -3
  70. package/dist/{chunk-IS6CQPAQ.js → chunk-OEFJPZYH.js} +3 -3
  71. package/dist/{chunk-P56WU3UT.js → chunk-PDWLVL34.js} +8 -5
  72. package/dist/{chunk-I2WVMCYN.js → chunk-PWLWDWRL.js} +1 -1
  73. package/dist/{chunk-JTGISCYV.js → chunk-QCGIYXN4.js} +1 -1
  74. package/dist/{chunk-6B66DQAS.js → chunk-QGPHATO3.js} +2 -2
  75. package/dist/{chunk-YS3W5AQA.js → chunk-REHIJQUD.js} +9 -9
  76. package/dist/{chunk-2K3UO6TC.js → chunk-RES4BCTF.js} +4 -4
  77. package/dist/{chunk-HDLPEXWS.js → chunk-S5CMAWEC.js} +20 -0
  78. package/dist/{chunk-KD5Y4XSU.js → chunk-S6HILC3F.js} +2 -2
  79. package/dist/{chunk-CBPO2P4I.js → chunk-SAI6LBXW.js} +2 -2
  80. package/dist/{chunk-EY7LWGRO.js → chunk-SDTRWSGF.js} +51 -14
  81. package/dist/{chunk-CG2VA2YP.js → chunk-SHUFUWAB.js} +61 -4
  82. package/dist/{chunk-YMKQJY5F.js → chunk-SIO4LO2M.js} +1 -1
  83. package/dist/{chunk-IITCQTBZ.js → chunk-T2PXAQND.js} +1 -1
  84. package/dist/{chunk-HPL2MQGY.js → chunk-T3TNJHED.js} +6 -6
  85. package/dist/{chunk-SBYBNAOU.js → chunk-TKFAWQD7.js} +2 -2
  86. package/dist/{chunk-D3LKWVPA.js → chunk-TTDMQ54U.js} +2 -2
  87. package/dist/{chunk-CPCGFE75.js → chunk-TTZGQIQS.js} +1 -1
  88. package/dist/{chunk-GNXIA5WC.js → chunk-TVV7AE3G.js} +2 -2
  89. package/dist/{chunk-2REGK4VO.js → chunk-U4SVWPLC.js} +11 -11
  90. package/dist/{chunk-5BA36MSQ.js → chunk-UMXXZ6OX.js} +1 -1
  91. package/dist/{chunk-HQQWAVL6.js → chunk-UNO3TSAT.js} +1 -1
  92. package/dist/{chunk-MGSVPAVF.js → chunk-USSUE7J2.js} +5 -5
  93. package/dist/{chunk-WHTGWLGJ.js → chunk-UTGP4X74.js} +1 -1
  94. package/dist/{chunk-XMZQW5G5.js → chunk-V5RHOS43.js} +8 -8
  95. package/dist/{chunk-Z2AVP3QL.js → chunk-VB6GGRIA.js} +16 -3
  96. package/dist/{chunk-RSXTLOY3.js → chunk-VY5XWTW7.js} +1 -1
  97. package/dist/{chunk-VVCRJ46V.js → chunk-WEUPM3IN.js} +4 -4
  98. package/dist/{chunk-RZHIYTI3.js → chunk-WK33IBKY.js} +10 -1
  99. package/dist/{chunk-I2GML5Z7.js → chunk-XOWRUT4X.js} +2 -2
  100. package/dist/{chunk-AZLZOG5N.js → chunk-XYNEAJDF.js} +1 -1
  101. package/dist/{chunk-K7Y3EAGL.js → chunk-Y5RNFM44.js} +2 -2
  102. package/dist/{chunk-GSDVHR43.js → chunk-YJCH35J4.js} +5 -3
  103. package/dist/{chunk-T77N7C3M.js → chunk-YKPRNV6J.js} +2 -2
  104. package/dist/chunk-YOZ6WDP3.js +103 -0
  105. package/dist/{chunk-7DPZMROX.js → chunk-YRFWPBGX.js} +2 -2
  106. package/dist/{chunk-F5SHFZUA.js → chunk-YTBVILAH.js} +1 -1
  107. package/dist/{chunk-IPTEXVQG.js → chunk-Z5IENUYV.js} +3 -3
  108. package/dist/{chunk-MQSTE4WH.js → chunk-ZBWKJ42J.js} +3 -3
  109. package/dist/{chunk-GBJ3OT4D.js → chunk-ZC7OR65K.js} +7 -5
  110. package/dist/{chunk-7U62OZSD.js → chunk-ZDDMPGN4.js} +2 -2
  111. package/dist/{chunk-5DFZE5OJ.js → chunk-ZPKQT6X2.js} +16 -6
  112. package/dist/{chunk-SX34YV6L.js → chunk-ZV5Y5JBE.js} +2 -2
  113. package/dist/config/index.js +5 -5
  114. package/dist/containers/client.js +6 -6
  115. package/dist/containers/exec.js +6 -6
  116. package/dist/containers/lifecycle.js +41 -41
  117. package/dist/containers/setup.js +9 -9
  118. package/dist/db/agents.js +6 -6
  119. package/dist/db/api_keys.js +5 -5
  120. package/dist/db/audit.js +3 -3
  121. package/dist/db/batch.js +10 -10
  122. package/dist/db/client.js +2 -2
  123. package/dist/db/credentials.js +5 -3
  124. package/dist/db/drizzle.js +4 -4
  125. package/dist/db/environments.js +6 -6
  126. package/dist/db/events.js +5 -5
  127. package/dist/db/files.js +5 -5
  128. package/dist/db/memory.js +5 -5
  129. package/dist/db/migrations.js +1 -1
  130. package/dist/db/proxy.js +5 -5
  131. package/dist/db/schema.js +1 -1
  132. package/dist/db/session-resources.js +5 -5
  133. package/dist/db/sessions.js +8 -8
  134. package/dist/db/skills.js +5 -5
  135. package/dist/db/sync.js +5 -5
  136. package/dist/db/tenants.js +3 -3
  137. package/dist/db/threads.js +7 -7
  138. package/dist/db/traces.js +5 -5
  139. package/dist/db/upstream_keys.js +3 -3
  140. package/dist/db/user-profiles.js +17 -0
  141. package/dist/db/vaults.js +6 -6
  142. package/dist/db/work.js +5 -5
  143. package/dist/dreaming/review.js +11 -11
  144. package/dist/handlers/agents.js +58 -57
  145. package/dist/handlers/api_keys.js +59 -58
  146. package/dist/handlers/audit.js +59 -58
  147. package/dist/handlers/batch.js +59 -58
  148. package/dist/handlers/credentials.js +61 -58
  149. package/dist/handlers/enrollment.js +103 -0
  150. package/dist/handlers/environments.js +59 -58
  151. package/dist/handlers/events.js +62 -61
  152. package/dist/handlers/files.js +59 -58
  153. package/dist/handlers/index.js +145 -126
  154. package/dist/handlers/license.js +58 -57
  155. package/dist/handlers/memory.js +60 -59
  156. package/dist/handlers/metrics.js +58 -57
  157. package/dist/handlers/models.js +59 -58
  158. package/dist/handlers/openapi.js +3 -3
  159. package/dist/handlers/providers.js +58 -57
  160. package/dist/handlers/resources.js +58 -57
  161. package/dist/handlers/sessions.js +62 -61
  162. package/dist/handlers/settings.js +58 -57
  163. package/dist/handlers/skills-write.js +59 -58
  164. package/dist/handlers/skills.js +59 -58
  165. package/dist/handlers/stream.js +58 -57
  166. package/dist/handlers/tenants.js +59 -58
  167. package/dist/handlers/threads.js +59 -58
  168. package/dist/handlers/traces.js +59 -58
  169. package/dist/handlers/upstream_keys.js +61 -60
  170. package/dist/handlers/user-profiles.js +107 -0
  171. package/dist/handlers/vaults.js +58 -57
  172. package/dist/handlers/whoami.js +58 -57
  173. package/dist/handlers/work.js +59 -58
  174. package/dist/http.js +57 -56
  175. package/dist/index.js +68 -67
  176. package/dist/init.js +54 -53
  177. package/dist/lib/model-registry.js +6 -6
  178. package/dist/lib/skills-cache.js +6 -6
  179. package/dist/observability/otlp.js +12 -12
  180. package/dist/observability/redactor.js +8 -8
  181. package/dist/openapi/schemas.js +1 -1
  182. package/dist/openapi/spec.js +2 -2
  183. package/dist/providers/fly.js +5 -5
  184. package/dist/providers/modal.js +5 -5
  185. package/dist/providers/registry.js +6 -6
  186. package/dist/providers/resolve-secrets.js +7 -7
  187. package/dist/providers/sprites.js +7 -7
  188. package/dist/providers/upstream-keys.js +12 -12
  189. package/dist/providers/vercel.js +6 -6
  190. package/dist/proxy/forward.js +6 -6
  191. package/dist/queue/index.js +6 -6
  192. package/dist/sessions/bus.js +10 -10
  193. package/dist/sessions/driver.js +47 -46
  194. package/dist/sessions/grader.js +5 -5
  195. package/dist/sessions/secrets.js +9 -8
  196. package/dist/sessions/sweeper.js +42 -42
  197. package/dist/sessions/threads.js +55 -47
  198. package/dist/shutdown.js +43 -43
  199. package/dist/sync/anthropic.js +10 -10
  200. package/dist/sync/container-file-sync.js +6 -6
  201. package/dist/sync/file-sync.js +17 -17
  202. package/dist/workers/runner.js +49 -48
  203. package/package.json +1 -1
  204. package/dist/chunk-6KWJASEO.js +0 -21
  205. package/dist/{dist-EY25RQ2S.js → dist-3ZD3ELTH.js} +3 -3
@@ -2,10 +2,10 @@ import {
2
2
  reportUpstreamFailure,
3
3
  reportUpstreamSuccess,
4
4
  resolveAnthropicKey
5
- } from "./chunk-Z5XQQN7H.js";
5
+ } from "./chunk-HWWFRSAX.js";
6
6
  import {
7
7
  resolveRemoteSessionId
8
- } from "./chunk-MQSTE4WH.js";
8
+ } from "./chunk-ZBWKJ42J.js";
9
9
  import {
10
10
  assertResourceTenant
11
11
  } from "./chunk-23UKWXJH.js";
@@ -20,53 +20,53 @@ import {
20
20
  listMemoryStores,
21
21
  searchMemories,
22
22
  updateMemory
23
- } from "./chunk-GNXIA5WC.js";
23
+ } from "./chunk-TVV7AE3G.js";
24
24
  import {
25
25
  jsonOk,
26
26
  paginatedOk,
27
27
  routeWrap
28
- } from "./chunk-I2GML5Z7.js";
28
+ } from "./chunk-XOWRUT4X.js";
29
29
  import {
30
30
  forwardToAnthropic
31
- } from "./chunk-IDQKHWWN.js";
32
- import {
33
- enqueueTurn
34
- } from "./chunk-SKVAM5H2.js";
31
+ } from "./chunk-JFHYXFAL.js";
35
32
  import {
36
33
  runTurn,
37
34
  writePermissionResponse
38
- } from "./chunk-BYUIOMPX.js";
35
+ } from "./chunk-AKGWEACL.js";
36
+ import {
37
+ enqueueTurn
38
+ } from "./chunk-B3W3E5CS.js";
39
39
  import {
40
40
  getProxiedTenantId,
41
41
  isProxied
42
- } from "./chunk-GKNBECPD.js";
42
+ } from "./chunk-DZKBUOYU.js";
43
43
  import {
44
44
  getActor
45
45
  } from "./chunk-LAWTTG2E.js";
46
46
  import {
47
47
  appendEvent
48
- } from "./chunk-2K3UO6TC.js";
48
+ } from "./chunk-RES4BCTF.js";
49
49
  import {
50
50
  bumpSessionStats,
51
51
  getSession,
52
52
  getSessionRow,
53
53
  setOutcomeCriteria,
54
54
  updateSessionMutable
55
- } from "./chunk-GBJ3OT4D.js";
55
+ } from "./chunk-ZC7OR65K.js";
56
56
  import {
57
57
  listEvents,
58
58
  rowToManagedEvent
59
- } from "./chunk-IS6CQPAQ.js";
59
+ } from "./chunk-OEFJPZYH.js";
60
60
  import {
61
61
  getEnvironment,
62
62
  getEnvironmentRow
63
- } from "./chunk-BRULBMRN.js";
63
+ } from "./chunk-NSUVDKNC.js";
64
64
  import {
65
65
  getAgent
66
- } from "./chunk-ENFWZ2QM.js";
66
+ } from "./chunk-6U6HEVSN.js";
67
67
  import {
68
68
  getConfig
69
- } from "./chunk-US26CY2Y.js";
69
+ } from "./chunk-6EIONZ7F.js";
70
70
  import {
71
71
  init_clock,
72
72
  nowMs
@@ -74,7 +74,7 @@ import {
74
74
  import {
75
75
  getDb,
76
76
  init_client
77
- } from "./chunk-Q62QJXGO.js";
77
+ } from "./chunk-AGIXZFHQ.js";
78
78
  import {
79
79
  badRequest,
80
80
  notFound
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  readSetting
3
- } from "./chunk-US26CY2Y.js";
3
+ } from "./chunk-6EIONZ7F.js";
4
4
 
5
5
  // src/lib/skills-cache.ts
6
6
  var DEFAULT_FEED_URL = "https://www.agentstep.com/v1/skills/feed";
@@ -5,10 +5,10 @@ import {
5
5
  import {
6
6
  getDrizzle,
7
7
  init_drizzle
8
- } from "./chunk-7U62OZSD.js";
8
+ } from "./chunk-ZDDMPGN4.js";
9
9
  import {
10
10
  schema_exports
11
- } from "./chunk-4ENK7S24.js";
11
+ } from "./chunk-CXYMVLYK.js";
12
12
 
13
13
  // src/db/proxy.ts
14
14
  init_drizzle();
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  listTraces
3
- } from "./chunk-5BA36MSQ.js";
3
+ } from "./chunk-UMXXZ6OX.js";
4
4
  import {
5
5
  jsonOk,
6
6
  routeWrap
7
- } from "./chunk-I2GML5Z7.js";
7
+ } from "./chunk-XOWRUT4X.js";
8
8
  import {
9
9
  exportTrace
10
- } from "./chunk-PZKWZKRP.js";
10
+ } from "./chunk-2KF2TIEY.js";
11
11
  import {
12
12
  listEventsByTrace,
13
13
  rowToManagedEvent
14
- } from "./chunk-IS6CQPAQ.js";
14
+ } from "./chunk-OEFJPZYH.js";
15
15
  import {
16
16
  badRequest,
17
17
  notFound
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  getDb,
16
16
  init_client
17
- } from "./chunk-Q62QJXGO.js";
17
+ } from "./chunk-AGIXZFHQ.js";
18
18
 
19
19
  // src/db/audit.ts
20
20
  init_client();
@@ -10,10 +10,10 @@ import {
10
10
  import {
11
11
  getDrizzle,
12
12
  init_drizzle
13
- } from "./chunk-7U62OZSD.js";
13
+ } from "./chunk-ZDDMPGN4.js";
14
14
  import {
15
15
  schema_exports
16
- } from "./chunk-4ENK7S24.js";
16
+ } from "./chunk-CXYMVLYK.js";
17
17
  import {
18
18
  __esm,
19
19
  __export
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  disableUpstreamKey,
3
3
  selectNextUpstreamKey
4
- } from "./chunk-ZP5QO5BR.js";
4
+ } from "./chunk-ABUNDZCE.js";
5
5
  import {
6
6
  listEntries
7
- } from "./chunk-IC5ZTBAW.js";
7
+ } from "./chunk-MUARVVXF.js";
8
8
  import {
9
9
  getSession
10
- } from "./chunk-GBJ3OT4D.js";
10
+ } from "./chunk-ZC7OR65K.js";
11
11
  import {
12
12
  getConfig
13
- } from "./chunk-US26CY2Y.js";
13
+ } from "./chunk-6EIONZ7F.js";
14
14
 
15
15
  // src/providers/upstream-keys.ts
16
16
  var CONSECUTIVE_FAIL_THRESHOLD = 3;
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  createSession
3
- } from "./chunk-GBJ3OT4D.js";
3
+ } from "./chunk-ZC7OR65K.js";
4
4
  import {
5
5
  createEnvironment,
6
6
  deleteEnvironment,
7
7
  getEnvironment
8
- } from "./chunk-BRULBMRN.js";
8
+ } from "./chunk-NSUVDKNC.js";
9
9
  import {
10
10
  archiveAgent,
11
11
  createAgent,
12
12
  getAgent
13
- } from "./chunk-ENFWZ2QM.js";
13
+ } from "./chunk-6U6HEVSN.js";
14
14
  import {
15
15
  getDrizzle,
16
16
  init_drizzle
17
- } from "./chunk-7U62OZSD.js";
17
+ } from "./chunk-ZDDMPGN4.js";
18
18
 
19
19
  // src/db/batch.ts
20
20
  init_drizzle();
@@ -8,13 +8,13 @@ import {
8
8
  getMemoryByPath,
9
9
  getMemoryStore,
10
10
  listMemories
11
- } from "./chunk-GNXIA5WC.js";
11
+ } from "./chunk-TVV7AE3G.js";
12
12
  import {
13
13
  listSessions
14
- } from "./chunk-GBJ3OT4D.js";
14
+ } from "./chunk-ZC7OR65K.js";
15
15
  import {
16
16
  listEvents
17
- } from "./chunk-IS6CQPAQ.js";
17
+ } from "./chunk-OEFJPZYH.js";
18
18
  import {
19
19
  init_clock,
20
20
  nowMs
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildOpenApiDocument
3
- } from "./chunk-I2WVMCYN.js";
3
+ } from "./chunk-PWLWDWRL.js";
4
4
 
5
5
  // src/handlers/openapi.ts
6
6
  function originFromRequest(request) {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  listEntries
3
- } from "./chunk-IC5ZTBAW.js";
3
+ } from "./chunk-MUARVVXF.js";
4
4
  import {
5
5
  getConfig
6
- } from "./chunk-US26CY2Y.js";
6
+ } from "./chunk-6EIONZ7F.js";
7
7
 
8
8
  // src/observability/redactor.ts
9
9
  var REDACTED = "[REDACTED]";
@@ -1,16 +1,16 @@
1
+ import {
2
+ createPiTranslator
3
+ } from "./chunk-B6E6BVNK.js";
1
4
  import {
2
5
  buildPiArgs
3
- } from "./chunk-6KWJASEO.js";
6
+ } from "./chunk-6SD6MC2B.js";
4
7
  import {
5
8
  buildPiAuthEnv,
6
9
  validatePiRuntime
7
- } from "./chunk-IITCQTBZ.js";
10
+ } from "./chunk-T2PXAQND.js";
8
11
  import {
9
12
  preparePiOnSandbox
10
13
  } from "./chunk-CMOU2OFW.js";
11
- import {
12
- createPiTranslator
13
- } from "./chunk-B6E6BVNK.js";
14
14
  import {
15
15
  PI_WRAPPER_PATH
16
16
  } from "./chunk-OGA7KDQZ.js";
@@ -0,0 +1,210 @@
1
+ import {
2
+ tenantFilter
3
+ } from "./chunk-23UKWXJH.js";
4
+ import {
5
+ jsonOk,
6
+ routeWrap
7
+ } from "./chunk-XOWRUT4X.js";
8
+ import {
9
+ getUserProfile,
10
+ updateUserProfile
11
+ } from "./chunk-YOZ6WDP3.js";
12
+ import {
13
+ createCredential,
14
+ getCredential,
15
+ updateCredential
16
+ } from "./chunk-WK33IBKY.js";
17
+ import {
18
+ badRequest,
19
+ notFound
20
+ } from "./chunk-EZYKRG4W.js";
21
+
22
+ // src/handlers/enrollment.ts
23
+ import { z } from "zod";
24
+ import { randomBytes } from "crypto";
25
+ var pendingEnrollments = /* @__PURE__ */ new Map();
26
+ setInterval(() => {
27
+ const cutoff = Date.now() - 10 * 6e4;
28
+ for (const [state, enrollment] of pendingEnrollments) {
29
+ if (enrollment.createdAt < cutoff) pendingEnrollments.delete(state);
30
+ }
31
+ }, 6e4);
32
+ var EnrollmentSchema = z.object({
33
+ vault_id: z.string().min(1),
34
+ credential_id: z.string().optional(),
35
+ // update existing credential, or omit to create new
36
+ display_name: z.string().min(1).optional(),
37
+ // required when creating new
38
+ authorize_url: z.string().url(),
39
+ token_endpoint: z.string().url(),
40
+ client_id: z.string().min(1),
41
+ client_secret: z.string().optional(),
42
+ scope: z.string().optional(),
43
+ redirect_uri: z.string().url().optional()
44
+ });
45
+ function handleEnrollmentUrl(request, profileId) {
46
+ return routeWrap(request, async ({ auth }) => {
47
+ const profile = getUserProfile(profileId);
48
+ if (!profile) throw notFound(`user profile not found: ${profileId}`);
49
+ const filter = tenantFilter(auth);
50
+ if (filter && profile.tenant_id !== filter) {
51
+ throw notFound(`user profile not found: ${profileId}`);
52
+ }
53
+ const body = await request.json().catch(() => null);
54
+ const parsed = EnrollmentSchema.safeParse(body);
55
+ if (!parsed.success) {
56
+ throw badRequest(`invalid body: ${parsed.error.issues.map((i) => i.message).join("; ")}`);
57
+ }
58
+ const data = parsed.data;
59
+ if (data.credential_id) {
60
+ const cred = getCredential(data.credential_id);
61
+ if (!cred || cred.vault_id !== data.vault_id) {
62
+ throw badRequest(`credential not found: ${data.credential_id}`);
63
+ }
64
+ } else if (!data.display_name) {
65
+ throw badRequest("display_name is required when creating a new credential");
66
+ }
67
+ const state = randomBytes(32).toString("hex");
68
+ const reqUrl = new URL(request.url);
69
+ const redirectUri = data.redirect_uri || `${reqUrl.origin}/v1/oauth/callback`;
70
+ pendingEnrollments.set(state, {
71
+ profileId,
72
+ vaultId: data.vault_id,
73
+ credentialId: data.credential_id ?? null,
74
+ tokenEndpoint: data.token_endpoint,
75
+ clientId: data.client_id,
76
+ clientSecret: data.client_secret,
77
+ scope: data.scope,
78
+ redirectUri,
79
+ createdAt: Date.now()
80
+ });
81
+ const params = new URLSearchParams({
82
+ response_type: "code",
83
+ client_id: data.client_id,
84
+ redirect_uri: redirectUri,
85
+ state,
86
+ ...data.scope ? { scope: data.scope } : {}
87
+ });
88
+ const url = `${data.authorize_url}?${params.toString()}`;
89
+ return jsonOk({
90
+ type: "enrollment_url",
91
+ url,
92
+ state,
93
+ redirect_uri: redirectUri,
94
+ expires_in: 600
95
+ // 10 minutes
96
+ });
97
+ });
98
+ }
99
+ async function handleOAuthCallback(request) {
100
+ const { ensureInitialized } = await import("./init.js");
101
+ await ensureInitialized();
102
+ try {
103
+ const url = new URL(request.url);
104
+ const code = url.searchParams.get("code");
105
+ const state = url.searchParams.get("state");
106
+ const error = url.searchParams.get("error");
107
+ if (error) {
108
+ return new Response(
109
+ `<html><body><h2>Authorization failed</h2><p>${error}</p></body></html>`,
110
+ { status: 400, headers: { "Content-Type": "text/html" } }
111
+ );
112
+ }
113
+ if (!code || !state) {
114
+ return new Response(
115
+ `<html><body><h2>Missing code or state parameter</h2></body></html>`,
116
+ { status: 400, headers: { "Content-Type": "text/html" } }
117
+ );
118
+ }
119
+ const enrollment = pendingEnrollments.get(state);
120
+ if (!enrollment) {
121
+ return new Response(
122
+ `<html><body><h2>Invalid or expired enrollment state</h2><p>Please restart the enrollment process.</p></body></html>`,
123
+ { status: 400, headers: { "Content-Type": "text/html" } }
124
+ );
125
+ }
126
+ pendingEnrollments.delete(state);
127
+ const body = new URLSearchParams({
128
+ grant_type: "authorization_code",
129
+ code,
130
+ client_id: enrollment.clientId,
131
+ redirect_uri: enrollment.redirectUri,
132
+ ...enrollment.scope ? { scope: enrollment.scope } : {}
133
+ });
134
+ if (enrollment.clientSecret) {
135
+ body.set("client_secret", enrollment.clientSecret);
136
+ }
137
+ const tokenRes = await fetch(enrollment.tokenEndpoint, {
138
+ method: "POST",
139
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
140
+ body: body.toString(),
141
+ signal: AbortSignal.timeout(15e3)
142
+ });
143
+ if (!tokenRes.ok) {
144
+ const errText = await tokenRes.text().catch(() => "");
145
+ return new Response(
146
+ `<html><body><h2>Token exchange failed</h2><p>${tokenRes.status}: ${errText.slice(0, 200)}</p></body></html>`,
147
+ { status: 502, headers: { "Content-Type": "text/html" } }
148
+ );
149
+ }
150
+ const tokens = await tokenRes.json();
151
+ let credentialId;
152
+ const expiresAt = tokens.expires_in ? new Date(Date.now() + tokens.expires_in * 1e3).toISOString() : null;
153
+ const refreshConfig = tokens.refresh_token ? {
154
+ token_endpoint: enrollment.tokenEndpoint,
155
+ client_id: enrollment.clientId,
156
+ scope: enrollment.scope ?? tokens.scope,
157
+ refresh_token: tokens.refresh_token,
158
+ ...enrollment.clientSecret ? { token_endpoint_auth: { type: "client_secret_post", client_secret: enrollment.clientSecret } } : {}
159
+ } : null;
160
+ if (enrollment.credentialId) {
161
+ updateCredential(enrollment.credentialId, {
162
+ auth_type: "mcp_oauth",
163
+ token: tokens.access_token,
164
+ expires_at: expiresAt,
165
+ refresh_config: refreshConfig
166
+ });
167
+ credentialId = enrollment.credentialId;
168
+ } else {
169
+ const profile2 = getUserProfile(enrollment.profileId);
170
+ const displayName = `oauth-${enrollment.clientId}-${Date.now()}`;
171
+ const cred = createCredential({
172
+ vault_id: enrollment.vaultId,
173
+ display_name: displayName,
174
+ auth_type: "mcp_oauth",
175
+ token: tokens.access_token,
176
+ expires_at: expiresAt,
177
+ refresh_config: refreshConfig
178
+ });
179
+ credentialId = cred.id;
180
+ }
181
+ const profile = getUserProfile(enrollment.profileId);
182
+ if (profile) {
183
+ const existingGrant = profile.trust_grants.find(
184
+ (g) => g.vault_id === enrollment.vaultId && g.credential_id === credentialId
185
+ );
186
+ if (!existingGrant) {
187
+ const newGrants = [
188
+ ...profile.trust_grants,
189
+ { type: "vault_credential", vault_id: enrollment.vaultId, credential_id: credentialId }
190
+ ];
191
+ updateUserProfile(enrollment.profileId, { trust_grants: newGrants });
192
+ }
193
+ }
194
+ return new Response(
195
+ `<html><body><h2>Enrollment complete</h2><p>Credential ${credentialId} has been linked to your profile. You can close this window.</p></body></html>`,
196
+ { status: 200, headers: { "Content-Type": "text/html" } }
197
+ );
198
+ } catch (err) {
199
+ const msg = err instanceof Error ? err.message : String(err);
200
+ return new Response(
201
+ `<html><body><h2>Enrollment error</h2><p>${msg}</p></body></html>`,
202
+ { status: 500, headers: { "Content-Type": "text/html" } }
203
+ );
204
+ }
205
+ }
206
+
207
+ export {
208
+ handleEnrollmentUrl,
209
+ handleOAuthCallback
210
+ };
@@ -10,10 +10,10 @@ import {
10
10
  import {
11
11
  getDrizzle,
12
12
  init_drizzle
13
- } from "./chunk-7U62OZSD.js";
13
+ } from "./chunk-ZDDMPGN4.js";
14
14
  import {
15
15
  schema_exports
16
- } from "./chunk-4ENK7S24.js";
16
+ } from "./chunk-CXYMVLYK.js";
17
17
 
18
18
  // src/db/work.ts
19
19
  init_drizzle();
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-US26CY2Y.js";
3
+ } from "./chunk-6EIONZ7F.js";
4
4
  import {
5
5
  ApiError
6
6
  } from "./chunk-EZYKRG4W.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  BatchError,
3
3
  executeBatch
4
- } from "./chunk-KWG7NGYF.js";
4
+ } from "./chunk-I2RVN7CP.js";
5
5
  import {
6
6
  jsonOk,
7
7
  routeWrap
8
- } from "./chunk-I2GML5Z7.js";
8
+ } from "./chunk-XOWRUT4X.js";
9
9
  import {
10
10
  badRequest
11
11
  } from "./chunk-EZYKRG4W.js";
@@ -1,13 +1,3 @@
1
- import {
2
- buildClaudeArgs,
3
- buildClaudeAuthEnv
4
- } from "./chunk-GSDVHR43.js";
5
- import {
6
- PERMISSION_BRIDGE_DIR,
7
- PERMISSION_HOOK_SCRIPT_PATH,
8
- buildPermissionHooksConfig,
9
- generatePermissionHookScript
10
- } from "./chunk-CY6AWCC6.js";
11
1
  import {
12
2
  TOOL_BRIDGE_DIR,
13
3
  TOOL_BRIDGE_SCRIPT_PATH,
@@ -19,13 +9,23 @@ import {
19
9
  import {
20
10
  createClaudeTranslator
21
11
  } from "./chunk-D6RQPBRG.js";
12
+ import {
13
+ buildClaudeArgs,
14
+ buildClaudeAuthEnv
15
+ } from "./chunk-YJCH35J4.js";
16
+ import {
17
+ PERMISSION_BRIDGE_DIR,
18
+ PERMISSION_HOOK_SCRIPT_PATH,
19
+ buildPermissionHooksConfig,
20
+ generatePermissionHookScript
21
+ } from "./chunk-CY6AWCC6.js";
22
22
  import {
23
23
  CLAUDE_WRAPPER_PATH,
24
24
  installClaudeWrapper
25
25
  } from "./chunk-J6T3W6RY.js";
26
26
  import {
27
27
  getConfig
28
- } from "./chunk-US26CY2Y.js";
28
+ } from "./chunk-6EIONZ7F.js";
29
29
 
30
30
  // src/backends/claude/index.ts
31
31
  function buildTurn(input) {
@@ -2,7 +2,7 @@ import {
2
2
  archiveThread,
3
3
  getThread,
4
4
  listThreads
5
- } from "./chunk-IPTEXVQG.js";
5
+ } from "./chunk-Z5IENUYV.js";
6
6
  import {
7
7
  assertResourceTenant
8
8
  } from "./chunk-23UKWXJH.js";
@@ -10,21 +10,21 @@ import {
10
10
  jsonOk,
11
11
  paginatedOk,
12
12
  routeWrap
13
- } from "./chunk-I2GML5Z7.js";
13
+ } from "./chunk-XOWRUT4X.js";
14
14
  import {
15
15
  subscribe
16
- } from "./chunk-2K3UO6TC.js";
16
+ } from "./chunk-RES4BCTF.js";
17
17
  import {
18
18
  getSession
19
- } from "./chunk-GBJ3OT4D.js";
19
+ } from "./chunk-ZC7OR65K.js";
20
20
  import {
21
21
  listEvents,
22
22
  rowToManagedEvent
23
- } from "./chunk-IS6CQPAQ.js";
23
+ } from "./chunk-OEFJPZYH.js";
24
24
  import {
25
25
  getDb,
26
26
  init_client
27
- } from "./chunk-Q62QJXGO.js";
27
+ } from "./chunk-AGIXZFHQ.js";
28
28
  import {
29
29
  badRequest,
30
30
  notFound
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  listEntries
3
- } from "./chunk-IC5ZTBAW.js";
3
+ } from "./chunk-MUARVVXF.js";
4
4
 
5
5
  // src/providers/resolve-secrets.ts
6
6
  var BLOCKED_ENV_KEYS = /* @__PURE__ */ new Set([
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-US26CY2Y.js";
3
+ } from "./chunk-6EIONZ7F.js";
4
4
 
5
5
  // src/backends/gemini/auth.ts
6
6
  function buildGeminiAuthEnv() {