@agentstep/agent-sdk 0.5.28 → 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-33QZ6KIY.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-TV6QMCDS.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-CXIP6H55.js → chunk-7JA6HCMK.js} +2 -2
  26. package/dist/{chunk-ZM33GAEB.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-QCP37SCU.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-RKPT6O7I.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-WLCI57J6.js → chunk-C3UXUDZS.js} +4 -4
  37. package/dist/{chunk-QQGXM2OQ.js → chunk-C7P2TYOG.js} +1 -1
  38. package/dist/{chunk-HVCY7DET.js → chunk-CHNJK2KW.js} +2 -2
  39. package/dist/{chunk-MAN6OCOP.js → chunk-CJIGDJIJ.js} +3 -3
  40. package/dist/{chunk-CVYNMYIE.js → chunk-CWB2DQN5.js} +3 -3
  41. package/dist/{chunk-QBZMVYDV.js → chunk-CWVYFBZF.js} +4 -4
  42. package/dist/{chunk-4ENK7S24.js → chunk-CXYMVLYK.js} +4 -0
  43. package/dist/{chunk-4BJTLMHV.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-Z25QQE5Z.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-ANTKOI3K.js → chunk-JMDV55BV.js} +2 -2
  59. package/dist/{chunk-WG3N6VUA.js → chunk-JN3DHH7Z.js} +11 -11
  60. package/dist/{chunk-NOHH2ZH7.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-KHTLT44I.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-N627DRI6.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-3V4BPIBU.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-IWI74DWW.js → chunk-SDTRWSGF.js} +51 -14
  81. package/dist/{chunk-CXXL77ER.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-MNZB2OWP.js → chunk-TKFAWQD7.js} +2 -2
  86. package/dist/{chunk-D3LKWVPA.js → chunk-TTDMQ54U.js} +2 -2
  87. package/dist/{chunk-CACVB5PH.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-QSRH4XUG.js → chunk-UNO3TSAT.js} +1 -1
  92. package/dist/{chunk-V4DEOZFK.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-DI5WC2SQ.js → chunk-XOWRUT4X.js} +2 -2
  100. package/dist/{chunk-AZLZOG5N.js → chunk-XYNEAJDF.js} +1 -1
  101. package/dist/{chunk-TFTJ734B.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-RRP4F6XC.js → chunk-ZPKQT6X2.js} +16 -6
  112. package/dist/{chunk-LSMTQBMW.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
@@ -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-DI5WC2SQ.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-DI5WC2SQ.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-DI5WC2SQ.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() {
@@ -0,0 +1,108 @@
1
+ import {
2
+ resolveCreateTenant,
3
+ tenantFilter
4
+ } from "./chunk-23UKWXJH.js";
5
+ import {
6
+ jsonOk,
7
+ paginatedOk,
8
+ routeWrap
9
+ } from "./chunk-XOWRUT4X.js";
10
+ import {
11
+ createUserProfile,
12
+ getUserProfile,
13
+ listUserProfiles,
14
+ updateUserProfile
15
+ } from "./chunk-YOZ6WDP3.js";
16
+ import {
17
+ badRequest,
18
+ notFound
19
+ } from "./chunk-EZYKRG4W.js";
20
+
21
+ // src/handlers/user-profiles.ts
22
+ import { z } from "zod";
23
+ var TrustGrantSchema = z.object({
24
+ type: z.literal("vault_credential"),
25
+ vault_id: z.string().min(1),
26
+ credential_id: z.string().min(1)
27
+ });
28
+ var CreateSchema = z.object({
29
+ external_id: z.string().max(256).optional(),
30
+ display_name: z.string().max(256).optional(),
31
+ trust_grants: z.array(TrustGrantSchema).max(50).optional()
32
+ });
33
+ var UpdateSchema = z.object({
34
+ external_id: z.string().max(256).nullish(),
35
+ display_name: z.string().max(256).nullish(),
36
+ trust_grants: z.array(TrustGrantSchema).max(50).optional()
37
+ });
38
+ function handleCreateUserProfile(request) {
39
+ return routeWrap(request, async ({ auth }) => {
40
+ const body = await request.json().catch(() => null);
41
+ const parsed = CreateSchema.safeParse(body);
42
+ if (!parsed.success) {
43
+ throw badRequest(`invalid body: ${parsed.error.issues.map((i) => i.message).join("; ")}`);
44
+ }
45
+ const tenantId = resolveCreateTenant(auth, void 0);
46
+ const profile = createUserProfile({
47
+ external_id: parsed.data.external_id,
48
+ display_name: parsed.data.display_name,
49
+ trust_grants: parsed.data.trust_grants,
50
+ tenant_id: tenantId
51
+ });
52
+ return jsonOk(profile, 201);
53
+ });
54
+ }
55
+ function handleListUserProfiles(request) {
56
+ return routeWrap(request, async ({ auth }) => {
57
+ const url = new URL(request.url);
58
+ const limit = Math.min(Number(url.searchParams.get("limit") ?? 50), 100);
59
+ const afterId = url.searchParams.get("after_id") ?? void 0;
60
+ const filter = tenantFilter(auth);
61
+ const result = listUserProfiles({
62
+ tenant_id: filter ?? void 0,
63
+ limit,
64
+ after_id: afterId
65
+ });
66
+ return paginatedOk(result.data, limit);
67
+ });
68
+ }
69
+ function handleGetUserProfile(request, id) {
70
+ return routeWrap(request, async ({ auth }) => {
71
+ const profile = getUserProfile(id);
72
+ if (!profile) throw notFound(`user profile not found: ${id}`);
73
+ const filter = tenantFilter(auth);
74
+ if (filter && profile.tenant_id !== filter) {
75
+ throw notFound(`user profile not found: ${id}`);
76
+ }
77
+ return jsonOk(profile);
78
+ });
79
+ }
80
+ function handleUpdateUserProfile(request, id) {
81
+ return routeWrap(request, async ({ auth }) => {
82
+ const existing = getUserProfile(id);
83
+ if (!existing) throw notFound(`user profile not found: ${id}`);
84
+ const filter = tenantFilter(auth);
85
+ if (filter && existing.tenant_id !== filter) {
86
+ throw notFound(`user profile not found: ${id}`);
87
+ }
88
+ const body = await request.json().catch(() => null);
89
+ const parsed = UpdateSchema.safeParse(body);
90
+ if (!parsed.success) {
91
+ throw badRequest(`invalid body: ${parsed.error.issues.map((i) => i.message).join("; ")}`);
92
+ }
93
+ const updated = updateUserProfile(id, {
94
+ external_id: parsed.data.external_id,
95
+ display_name: parsed.data.display_name,
96
+ trust_grants: parsed.data.trust_grants
97
+ });
98
+ if (!updated) throw notFound(`user profile not found: ${id}`);
99
+ return jsonOk(updated);
100
+ });
101
+ }
102
+
103
+ export {
104
+ handleCreateUserProfile,
105
+ handleListUserProfiles,
106
+ handleGetUserProfile,
107
+ handleUpdateUserProfile
108
+ };
@@ -7,16 +7,16 @@ import {
7
7
  pollWorkItem,
8
8
  stopWorkItem,
9
9
  updateWorkItemMetadata
10
- } from "./chunk-A4GJADRQ.js";
10
+ } from "./chunk-JF777FWD.js";
11
11
  import {
12
12
  decodeCursor,
13
13
  jsonOk,
14
14
  paginatedOk,
15
15
  routeWrap
16
- } from "./chunk-DI5WC2SQ.js";
16
+ } from "./chunk-XOWRUT4X.js";
17
17
  import {
18
18
  getEnvironment
19
- } from "./chunk-BRULBMRN.js";
19
+ } from "./chunk-NSUVDKNC.js";
20
20
  import {
21
21
  badRequest,
22
22
  notFound
@@ -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/factory/auth.ts
6
6
  function buildFactoryAuthEnv() {
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-AIBH32FN.js";
5
5
  import {
6
6
  DEFAULT_TENANT_ID
7
- } from "./chunk-F5SHFZUA.js";
7
+ } from "./chunk-YTBVILAH.js";
8
8
  import {
9
9
  init_ids,
10
10
  newId
@@ -17,10 +17,10 @@ import {
17
17
  import {
18
18
  getDrizzle,
19
19
  init_drizzle
20
- } from "./chunk-7U62OZSD.js";
20
+ } from "./chunk-ZDDMPGN4.js";
21
21
  import {
22
22
  schema_exports
23
- } from "./chunk-4ENK7S24.js";
23
+ } from "./chunk-CXYMVLYK.js";
24
24
 
25
25
  // src/db/vaults.ts
26
26
  init_drizzle();