@agentstep/agent-sdk 0.5.28 → 0.5.34

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 (209) 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-33QZ6KIY.js → chunk-25E64UIV.js} +5 -5
  18. package/dist/{chunk-PZKWZKRP.js → chunk-2KF2TIEY.js} +5 -5
  19. package/dist/{chunk-CXXL77ER.js → chunk-2R4IT7HG.js} +61 -4
  20. package/dist/{chunk-N627DRI6.js → chunk-3EI7IPMI.js} +3 -3
  21. package/dist/{chunk-Z25QQE5Z.js → chunk-3EWEKBVC.js} +4 -4
  22. package/dist/{chunk-V4DEOZFK.js → chunk-3LYNN5VT.js} +5 -5
  23. package/dist/{chunk-LJNLU5PQ.js → chunk-3NUTTKE5.js} +2 -2
  24. package/dist/{chunk-DI5WC2SQ.js → chunk-4EKHW6VS.js} +2 -2
  25. package/dist/{chunk-MZ6HBYGV.js → chunk-65XY7HRS.js} +7 -7
  26. package/dist/{chunk-KHTLT44I.js → chunk-6CODFATQ.js} +3 -3
  27. package/dist/{chunk-US26CY2Y.js → chunk-6EIONZ7F.js} +2 -2
  28. package/dist/chunk-6NEWWPL4.js +210 -0
  29. package/dist/{chunk-TFTJ734B.js → chunk-6NFK5RJX.js} +2 -2
  30. package/dist/chunk-6SD6MC2B.js +29 -0
  31. package/dist/{chunk-ENFWZ2QM.js → chunk-6U6HEVSN.js} +7 -3
  32. package/dist/{chunk-CXIP6H55.js → chunk-75US4UAE.js} +2 -2
  33. package/dist/{chunk-UB7GS7XT.js → chunk-A3FQHVUG.js} +7 -7
  34. package/dist/{chunk-ZP5QO5BR.js → chunk-ABUNDZCE.js} +1 -1
  35. package/dist/{chunk-QCP37SCU.js → chunk-AD2WPGDN.js} +8 -8
  36. package/dist/{chunk-Q62QJXGO.js → chunk-AGIXZFHQ.js} +1 -1
  37. package/dist/{chunk-NKOGWVP3.js → chunk-AUEKXYNE.js} +4 -4
  38. package/dist/{chunk-SKVAM5H2.js → chunk-B3W3E5CS.js} +1 -1
  39. package/dist/chunk-B5RR422E.js +0 -0
  40. package/dist/{chunk-IWI74DWW.js → chunk-BSAF4YJB.js} +51 -14
  41. package/dist/{chunk-CVYNMYIE.js → chunk-CWB2DQN5.js} +3 -3
  42. package/dist/{chunk-4ENK7S24.js → chunk-CXYMVLYK.js} +4 -0
  43. package/dist/{chunk-MNZB2OWP.js → chunk-CZ4N5FJW.js} +2 -2
  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-CACVB5PH.js → chunk-FCPZF7KJ.js} +1 -1
  47. package/dist/{chunk-FC3UAHXM.js → chunk-FDLQ3IUB.js} +1 -1
  48. package/dist/{chunk-HVCY7DET.js → chunk-FHOJOLXU.js} +2 -2
  49. package/dist/{chunk-5AV732JY.js → chunk-GABMXDZZ.js} +2 -2
  50. package/dist/{chunk-LSMTQBMW.js → chunk-GBBQD6VY.js} +2 -2
  51. package/dist/{chunk-FDL2JHXO.js → chunk-GCT7A5KR.js} +2 -2
  52. package/dist/{chunk-QBZMVYDV.js → chunk-GFZ2WIVH.js} +4 -4
  53. package/dist/{chunk-ANTKOI3K.js → chunk-HHLVVJGT.js} +2 -2
  54. package/dist/{chunk-Z5XQQN7H.js → chunk-HWWFRSAX.js} +4 -4
  55. package/dist/{chunk-KWG7NGYF.js → chunk-I2RVN7CP.js} +4 -4
  56. package/dist/{chunk-JCIAIJFF.js → chunk-IC2ETYU5.js} +3 -3
  57. package/dist/{chunk-3FLQ7KZP.js → chunk-IMJTHYN3.js} +1 -1
  58. package/dist/{chunk-ISGA4AOC.js → chunk-J6ESQUW6.js} +2 -2
  59. package/dist/{chunk-Y3V4COP7.js → chunk-J7F2OFWQ.js} +5 -5
  60. package/dist/{chunk-3V4BPIBU.js → chunk-JDAOTVWV.js} +2 -2
  61. package/dist/{chunk-A4GJADRQ.js → chunk-JF777FWD.js} +2 -2
  62. package/dist/{chunk-IDQKHWWN.js → chunk-JFHYXFAL.js} +1 -1
  63. package/dist/{chunk-WLCI57J6.js → chunk-JIXRTWYL.js} +4 -4
  64. package/dist/{chunk-WG3N6VUA.js → chunk-JN3DHH7Z.js} +11 -11
  65. package/dist/{chunk-FQQ2R6FA.js → chunk-JNSJKHYX.js} +1 -1
  66. package/dist/{chunk-HPL2MQGY.js → chunk-K3LM6O44.js} +6 -6
  67. package/dist/{chunk-7DPZMROX.js → chunk-K5J4IN2S.js} +2 -2
  68. package/dist/{chunk-TJORQTH6.js → chunk-KGOOCFQY.js} +1 -1
  69. package/dist/{chunk-BYUIOMPX.js → chunk-KYKVHH7I.js} +23 -23
  70. package/dist/{chunk-ZM33GAEB.js → chunk-LKHJLSYG.js} +7 -7
  71. package/dist/{chunk-RKPT6O7I.js → chunk-LR6FK2J7.js} +5 -5
  72. package/dist/{chunk-MNW6D7T4.js → chunk-M72ERPMT.js} +1 -1
  73. package/dist/{chunk-IC5ZTBAW.js → chunk-MUARVVXF.js} +3 -3
  74. package/dist/{chunk-RRP4F6XC.js → chunk-NQ6BN7WH.js} +16 -6
  75. package/dist/{chunk-BRULBMRN.js → chunk-NSUVDKNC.js} +3 -3
  76. package/dist/chunk-OANORRFX.js +276 -0
  77. package/dist/{chunk-IS6CQPAQ.js → chunk-OEFJPZYH.js} +3 -3
  78. package/dist/{chunk-4BJTLMHV.js → chunk-OEYLPPID.js} +17 -17
  79. package/dist/{chunk-G6XFFNCQ.js → chunk-P7V3S2T3.js} +18 -18
  80. package/dist/{chunk-P56WU3UT.js → chunk-PDWLVL34.js} +8 -5
  81. package/dist/{chunk-I2WVMCYN.js → chunk-PWLWDWRL.js} +1 -1
  82. package/dist/{chunk-JTGISCYV.js → chunk-QCGIYXN4.js} +1 -1
  83. package/dist/{chunk-YS3W5AQA.js → chunk-REHIJQUD.js} +9 -9
  84. package/dist/{chunk-2K3UO6TC.js → chunk-RES4BCTF.js} +4 -4
  85. package/dist/{chunk-HDLPEXWS.js → chunk-S5CMAWEC.js} +20 -0
  86. package/dist/{chunk-CBPO2P4I.js → chunk-SAI6LBXW.js} +2 -2
  87. package/dist/{chunk-YMKQJY5F.js → chunk-SIO4LO2M.js} +1 -1
  88. package/dist/{chunk-QSRH4XUG.js → chunk-SUEPFZN2.js} +1 -1
  89. package/dist/{chunk-IITCQTBZ.js → chunk-T2PXAQND.js} +1 -1
  90. package/dist/{chunk-D3LKWVPA.js → chunk-TTDMQ54U.js} +2 -2
  91. package/dist/{chunk-GNXIA5WC.js → chunk-TVV7AE3G.js} +2 -2
  92. package/dist/{chunk-5BA36MSQ.js → chunk-UMXXZ6OX.js} +1 -1
  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-TV6QMCDS.js → chunk-VQM2MCQR.js} +3 -3
  97. package/dist/{chunk-RSXTLOY3.js → chunk-VY5XWTW7.js} +1 -1
  98. package/dist/{chunk-VVCRJ46V.js → chunk-WEUPM3IN.js} +4 -4
  99. package/dist/{chunk-RZHIYTI3.js → chunk-WK33IBKY.js} +10 -1
  100. package/dist/{chunk-QQGXM2OQ.js → chunk-XLMNSDUJ.js} +1 -1
  101. package/dist/{chunk-MAN6OCOP.js → chunk-XXAO5YYL.js} +3 -3
  102. package/dist/{chunk-AZLZOG5N.js → chunk-XYNEAJDF.js} +1 -1
  103. package/dist/{chunk-GSDVHR43.js → chunk-YJCH35J4.js} +5 -3
  104. package/dist/{chunk-T77N7C3M.js → chunk-YKPRNV6J.js} +2 -2
  105. package/dist/chunk-YOZ6WDP3.js +103 -0
  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-KD5Y4XSU.js → chunk-ZACPJA3G.js} +2 -2
  109. package/dist/{chunk-NOHH2ZH7.js → chunk-ZAUWB5DQ.js} +6 -6
  110. package/dist/{chunk-MQSTE4WH.js → chunk-ZBWKJ42J.js} +3 -3
  111. package/dist/{chunk-GBJ3OT4D.js → chunk-ZC7OR65K.js} +7 -5
  112. package/dist/{chunk-2REGK4VO.js → chunk-ZCCHLDLC.js} +11 -11
  113. package/dist/{chunk-7U62OZSD.js → chunk-ZDDMPGN4.js} +2 -2
  114. package/dist/chunk-ZHEE6UTX.js +108 -0
  115. package/dist/config/index.js +5 -5
  116. package/dist/containers/client.js +6 -6
  117. package/dist/containers/exec.js +6 -6
  118. package/dist/containers/lifecycle.js +41 -41
  119. package/dist/containers/setup.js +9 -9
  120. package/dist/db/agents.js +6 -6
  121. package/dist/db/api_keys.js +5 -5
  122. package/dist/db/audit.js +3 -3
  123. package/dist/db/batch.js +10 -10
  124. package/dist/db/client.js +2 -2
  125. package/dist/db/credentials.js +5 -3
  126. package/dist/db/drizzle.js +4 -4
  127. package/dist/db/environments.js +6 -6
  128. package/dist/db/events.js +5 -5
  129. package/dist/db/files.js +5 -5
  130. package/dist/db/memory.js +5 -5
  131. package/dist/db/migrations.js +1 -1
  132. package/dist/db/proxy.js +5 -5
  133. package/dist/db/schema.js +1 -1
  134. package/dist/db/session-resources.js +5 -5
  135. package/dist/db/sessions.js +8 -8
  136. package/dist/db/skills.js +5 -5
  137. package/dist/db/sync.js +5 -5
  138. package/dist/db/tenants.js +3 -3
  139. package/dist/db/threads.js +7 -7
  140. package/dist/db/traces.js +5 -5
  141. package/dist/db/upstream_keys.js +3 -3
  142. package/dist/db/user-profiles.js +17 -0
  143. package/dist/db/vaults.js +6 -6
  144. package/dist/db/work.js +5 -5
  145. package/dist/dreaming/review.js +11 -11
  146. package/dist/handlers/agents.js +58 -57
  147. package/dist/handlers/api_keys.js +59 -58
  148. package/dist/handlers/audit.js +59 -58
  149. package/dist/handlers/batch.js +59 -58
  150. package/dist/handlers/credentials.js +61 -58
  151. package/dist/handlers/enrollment.js +103 -0
  152. package/dist/handlers/environments.js +59 -58
  153. package/dist/handlers/events.js +62 -61
  154. package/dist/handlers/files.js +59 -58
  155. package/dist/handlers/google-compat/index.js +101 -0
  156. package/dist/handlers/google-compat/interactions.js +100 -0
  157. package/dist/handlers/google-compat/types.js +0 -0
  158. package/dist/handlers/index.js +150 -126
  159. package/dist/handlers/license.js +58 -57
  160. package/dist/handlers/memory.js +60 -59
  161. package/dist/handlers/metrics.js +58 -57
  162. package/dist/handlers/models.js +59 -58
  163. package/dist/handlers/openapi.js +3 -3
  164. package/dist/handlers/providers.js +58 -57
  165. package/dist/handlers/resources.js +58 -57
  166. package/dist/handlers/sessions.js +62 -61
  167. package/dist/handlers/settings.js +58 -57
  168. package/dist/handlers/skills-write.js +59 -58
  169. package/dist/handlers/skills.js +59 -58
  170. package/dist/handlers/stream.js +58 -57
  171. package/dist/handlers/tenants.js +59 -58
  172. package/dist/handlers/threads.js +59 -58
  173. package/dist/handlers/traces.js +59 -58
  174. package/dist/handlers/upstream_keys.js +61 -60
  175. package/dist/handlers/user-profiles.js +107 -0
  176. package/dist/handlers/vaults.js +58 -57
  177. package/dist/handlers/whoami.js +58 -57
  178. package/dist/handlers/work.js +59 -58
  179. package/dist/http.js +57 -56
  180. package/dist/index.js +68 -67
  181. package/dist/init.js +54 -53
  182. package/dist/lib/model-registry.js +6 -6
  183. package/dist/lib/skills-cache.js +6 -6
  184. package/dist/observability/otlp.js +12 -12
  185. package/dist/observability/redactor.js +8 -8
  186. package/dist/openapi/schemas.js +1 -1
  187. package/dist/openapi/spec.js +2 -2
  188. package/dist/providers/fly.js +5 -5
  189. package/dist/providers/modal.js +5 -5
  190. package/dist/providers/registry.js +6 -6
  191. package/dist/providers/resolve-secrets.js +7 -7
  192. package/dist/providers/sprites.js +7 -7
  193. package/dist/providers/upstream-keys.js +12 -12
  194. package/dist/providers/vercel.js +5 -5
  195. package/dist/proxy/forward.js +6 -6
  196. package/dist/queue/index.js +6 -6
  197. package/dist/sessions/bus.js +10 -10
  198. package/dist/sessions/driver.js +47 -46
  199. package/dist/sessions/grader.js +5 -5
  200. package/dist/sessions/secrets.js +9 -8
  201. package/dist/sessions/sweeper.js +42 -42
  202. package/dist/sessions/threads.js +55 -47
  203. package/dist/shutdown.js +43 -43
  204. package/dist/sync/anthropic.js +10 -10
  205. package/dist/sync/container-file-sync.js +6 -6
  206. package/dist/sync/file-sync.js +17 -17
  207. package/dist/workers/runner.js +49 -48
  208. package/package.json +1 -1
  209. package/dist/chunk-6KWJASEO.js +0 -21
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  jsonOk,
3
3
  routeWrap
4
- } from "./chunk-DI5WC2SQ.js";
4
+ } from "./chunk-4EKHW6VS.js";
5
5
  import {
6
6
  resolveContainerProvider
7
- } from "./chunk-QQGXM2OQ.js";
7
+ } from "./chunk-XLMNSDUJ.js";
8
8
  import {
9
9
  getConfig
10
- } from "./chunk-US26CY2Y.js";
10
+ } from "./chunk-6EIONZ7F.js";
11
11
 
12
12
  // src/handlers/providers.ts
13
13
  var LOCAL_PROVIDERS = ["docker", "apple-container", "podman"];
@@ -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-4EKHW6VS.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
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-23UKWXJH.js";
7
7
  import {
8
8
  recordAudit
9
- } from "./chunk-FC3UAHXM.js";
9
+ } from "./chunk-FDLQ3IUB.js";
10
10
  import {
11
11
  COMMUNITY_LIMITS,
12
12
  hasFeature,
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  jsonOk,
17
17
  routeWrap
18
- } from "./chunk-DI5WC2SQ.js";
18
+ } from "./chunk-4EKHW6VS.js";
19
19
  import {
20
20
  createApiKey,
21
21
  getApiKeyById,
@@ -23,14 +23,14 @@ import {
23
23
  listApiKeys,
24
24
  revokeApiKey,
25
25
  updateApiKeyPermissions
26
- } from "./chunk-LJNLU5PQ.js";
26
+ } from "./chunk-3NUTTKE5.js";
27
27
  import {
28
28
  listSessionsByApiKey
29
- } from "./chunk-GBJ3OT4D.js";
29
+ } from "./chunk-ZC7OR65K.js";
30
30
  import {
31
31
  getDb,
32
32
  init_client
33
- } from "./chunk-Q62QJXGO.js";
33
+ } from "./chunk-AGIXZFHQ.js";
34
34
  import {
35
35
  badRequest,
36
36
  forbidden,
@@ -9,10 +9,10 @@ import {
9
9
  import {
10
10
  getDrizzle,
11
11
  init_drizzle
12
- } from "./chunk-7U62OZSD.js";
12
+ } from "./chunk-ZDDMPGN4.js";
13
13
  import {
14
14
  schema_exports
15
- } from "./chunk-4ENK7S24.js";
15
+ } from "./chunk-CXYMVLYK.js";
16
16
 
17
17
  // src/db/api_keys.ts
18
18
  init_drizzle();
@@ -4,13 +4,13 @@ import {
4
4
  } from "./chunk-D2XITRN6.js";
5
5
  import {
6
6
  authenticateAndIntercept
7
- } from "./chunk-CVYNMYIE.js";
7
+ } from "./chunk-CWB2DQN5.js";
8
8
  import {
9
9
  checkAndBump
10
10
  } from "./chunk-HVUWXUUI.js";
11
11
  import {
12
12
  ensureInitialized
13
- } from "./chunk-G6XFFNCQ.js";
13
+ } from "./chunk-P7V3S2T3.js";
14
14
  import {
15
15
  captureException
16
16
  } from "./chunk-3MQ2FWXS.js";
@@ -1,3 +1,10 @@
1
+ import {
2
+ buildFactoryArgs
3
+ } from "./chunk-TPMZO6S2.js";
4
+ import {
5
+ buildFactoryAuthEnv,
6
+ validateFactoryRuntime
7
+ } from "./chunk-M72ERPMT.js";
1
8
  import {
2
9
  prepareFactoryOnSandbox
3
10
  } from "./chunk-AQHYCRTO.js";
@@ -7,13 +14,6 @@ import {
7
14
  import {
8
15
  FACTORY_WRAPPER_PATH
9
16
  } from "./chunk-KJ2GJLPQ.js";
10
- import {
11
- buildFactoryArgs
12
- } from "./chunk-TPMZO6S2.js";
13
- import {
14
- buildFactoryAuthEnv,
15
- validateFactoryRuntime
16
- } from "./chunk-MNW6D7T4.js";
17
17
  import {
18
18
  wrapPromptWithSystem
19
19
  } from "./chunk-YE2RMJY7.js";
@@ -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-4EKHW6VS.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
@@ -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/config/index.ts
14
14
  init_drizzle();
@@ -0,0 +1,210 @@
1
+ import {
2
+ tenantFilter
3
+ } from "./chunk-23UKWXJH.js";
4
+ import {
5
+ jsonOk,
6
+ routeWrap
7
+ } from "./chunk-4EKHW6VS.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
+ };
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  jsonOk,
3
3
  routeWrap
4
- } from "./chunk-DI5WC2SQ.js";
4
+ } from "./chunk-4EKHW6VS.js";
5
5
  import {
6
6
  readSetting,
7
7
  writeSetting
8
- } from "./chunk-US26CY2Y.js";
8
+ } from "./chunk-6EIONZ7F.js";
9
9
  import {
10
10
  badRequest
11
11
  } from "./chunk-EZYKRG4W.js";
@@ -0,0 +1,29 @@
1
+ // src/backends/pi/args.ts
2
+ function normalizePiModel(model) {
3
+ if (model.includes("/")) return model;
4
+ if (model.startsWith("gemini-")) return `google/${model}`;
5
+ if (model.startsWith("claude-")) return `anthropic/${model}`;
6
+ if (model.startsWith("gpt-") || model.startsWith("o1-") || model.startsWith("o3-") || model.startsWith("o4-") || model.startsWith("chatgpt-")) return `openai/${model}`;
7
+ return model;
8
+ }
9
+ function buildPiArgs(input) {
10
+ const args = [
11
+ "-p",
12
+ "--mode",
13
+ "json",
14
+ "--no-extensions"
15
+ ];
16
+ if (input.backendSessionId) {
17
+ args.push("--session", input.backendSessionId);
18
+ }
19
+ if (input.agent.model) {
20
+ const modelId = typeof input.agent.model === "string" ? input.agent.model : input.agent.model.id;
21
+ if (modelId) args.push("--model", normalizePiModel(modelId));
22
+ }
23
+ args.push(input.prompt);
24
+ return args;
25
+ }
26
+
27
+ export {
28
+ buildPiArgs
29
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_TENANT_ID
3
- } from "./chunk-F5SHFZUA.js";
3
+ } from "./chunk-YTBVILAH.js";
4
4
  import {
5
5
  init_ids,
6
6
  newId
@@ -13,10 +13,10 @@ import {
13
13
  import {
14
14
  getDrizzle,
15
15
  init_drizzle
16
- } from "./chunk-7U62OZSD.js";
16
+ } from "./chunk-ZDDMPGN4.js";
17
17
  import {
18
18
  schema_exports
19
- } from "./chunk-4ENK7S24.js";
19
+ } from "./chunk-CXYMVLYK.js";
20
20
 
21
21
  // src/db/agents.ts
22
22
  init_drizzle();
@@ -38,6 +38,7 @@ function hydrate(row, ver) {
38
38
  threadsEnabled = true;
39
39
  callableAgents = multiagent.agents.filter((a) => a.type === "agent").map((a) => ({ type: "agent", id: a.id, version: a.version }));
40
40
  }
41
+ const permissionPolicy = ver.permission_policy_json ? JSON.parse(ver.permission_policy_json) : null;
41
42
  return {
42
43
  type: "agent",
43
44
  id: row.id,
@@ -57,6 +58,7 @@ function hydrate(row, ver) {
57
58
  confirmation_mode: Boolean(ver.confirmation_mode),
58
59
  callable_agents: callableAgents,
59
60
  multiagent,
61
+ permission_policy: permissionPolicy,
60
62
  skills: ver.skills_json ? JSON.parse(ver.skills_json) : [],
61
63
  model_config: modelConfig,
62
64
  fallback_json: row.fallback_json ?? null,
@@ -95,6 +97,7 @@ function createAgent(input) {
95
97
  confirmation_mode: input.confirmation_mode ? 1 : 0,
96
98
  callable_agents_json: input.callable_agents?.length ? JSON.stringify(input.callable_agents) : null,
97
99
  multiagent_json: input.multiagent ? JSON.stringify(input.multiagent) : null,
100
+ permission_policy_json: input.permission_policy ? JSON.stringify(input.permission_policy) : null,
98
101
  skills_json: JSON.stringify(input.skills ?? []),
99
102
  model_config_json: JSON.stringify(input.model_config ?? {}),
100
103
  created_at: now
@@ -148,6 +151,7 @@ function updateAgent(id, input) {
148
151
  confirmation_mode: input.confirmation_mode !== void 0 ? input.confirmation_mode ? 1 : 0 : existing.confirmation_mode ? 1 : 0,
149
152
  callable_agents_json: input.callable_agents !== void 0 ? input.callable_agents.length ? JSON.stringify(input.callable_agents) : null : existing.callable_agents.length ? JSON.stringify(existing.callable_agents) : null,
150
153
  multiagent_json: input.multiagent !== void 0 ? input.multiagent ? JSON.stringify(input.multiagent) : null : existing.multiagent ? JSON.stringify(existing.multiagent) : null,
154
+ permission_policy_json: input.permission_policy !== void 0 ? input.permission_policy ? JSON.stringify(input.permission_policy) : null : existing.permission_policy ? JSON.stringify(existing.permission_policy) : null,
151
155
  skills_json: JSON.stringify(input.skills ?? existing.skills),
152
156
  model_config_json: JSON.stringify(input.model_config !== void 0 ? input.model_config : existing.model_config),
153
157
  created_at: now
@@ -6,7 +6,7 @@ import {
6
6
  getSkill,
7
7
  getSkillVersion,
8
8
  listSkillVersions
9
- } from "./chunk-D3LKWVPA.js";
9
+ } from "./chunk-TTDMQ54U.js";
10
10
  import {
11
11
  resolveCreateTenant
12
12
  } from "./chunk-23UKWXJH.js";
@@ -15,7 +15,7 @@ import {
15
15
  jsonOk,
16
16
  paginatedOk,
17
17
  routeWrap
18
- } from "./chunk-DI5WC2SQ.js";
18
+ } from "./chunk-4EKHW6VS.js";
19
19
  import {
20
20
  badRequest,
21
21
  notFound
@@ -1,19 +1,19 @@
1
- import {
2
- createGeminiTranslator
3
- } from "./chunk-S3JRZFF5.js";
4
- import {
5
- buildGeminiArgs
6
- } from "./chunk-IBYOMAZ3.js";
7
1
  import {
8
2
  buildGeminiAuthEnv,
9
3
  validateGeminiRuntime
10
- } from "./chunk-TJORQTH6.js";
4
+ } from "./chunk-KGOOCFQY.js";
11
5
  import {
12
6
  prepareGeminiOnSandbox
13
7
  } from "./chunk-PAQ2JFVD.js";
8
+ import {
9
+ createGeminiTranslator
10
+ } from "./chunk-S3JRZFF5.js";
14
11
  import {
15
12
  GEMINI_WRAPPER_PATH
16
13
  } from "./chunk-PZ5EGY64.js";
14
+ import {
15
+ buildGeminiArgs
16
+ } from "./chunk-IBYOMAZ3.js";
17
17
  import {
18
18
  wrapPromptWithSystem
19
19
  } from "./chunk-YE2RMJY7.js";
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  getDb,
15
15
  init_client
16
- } from "./chunk-Q62QJXGO.js";
16
+ } from "./chunk-AGIXZFHQ.js";
17
17
 
18
18
  // src/db/upstream_keys.ts
19
19
  init_client();
@@ -1,32 +1,32 @@
1
1
  import {
2
2
  resolveRemoteSessionId
3
- } from "./chunk-MQSTE4WH.js";
3
+ } from "./chunk-ZBWKJ42J.js";
4
4
  import {
5
5
  assertResourceTenant
6
6
  } from "./chunk-23UKWXJH.js";
7
7
  import {
8
8
  authenticateAndIntercept
9
- } from "./chunk-CVYNMYIE.js";
9
+ } from "./chunk-CWB2DQN5.js";
10
10
  import {
11
11
  forwardToAnthropic
12
- } from "./chunk-IDQKHWWN.js";
12
+ } from "./chunk-JFHYXFAL.js";
13
13
  import {
14
14
  ensureInitialized
15
- } from "./chunk-G6XFFNCQ.js";
15
+ } from "./chunk-P7V3S2T3.js";
16
16
  import {
17
17
  getProxiedTenantId,
18
18
  isProxied
19
- } from "./chunk-GKNBECPD.js";
19
+ } from "./chunk-DZKBUOYU.js";
20
20
  import {
21
21
  subscribe
22
- } from "./chunk-2K3UO6TC.js";
22
+ } from "./chunk-RES4BCTF.js";
23
23
  import {
24
24
  getSession
25
- } from "./chunk-GBJ3OT4D.js";
25
+ } from "./chunk-ZC7OR65K.js";
26
26
  import {
27
27
  getDb,
28
28
  init_client
29
- } from "./chunk-Q62QJXGO.js";
29
+ } from "./chunk-AGIXZFHQ.js";
30
30
  import {
31
31
  notFound,
32
32
  toResponse
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  init_migrations,
3
3
  runMigrations
4
- } from "./chunk-HDLPEXWS.js";
4
+ } from "./chunk-S5CMAWEC.js";
5
5
  import {
6
6
  __esm
7
7
  } from "./chunk-2ESYSVXG.js";
@@ -2,19 +2,19 @@ import {
2
2
  getSyncRow,
3
3
  getSyncedRemoteId,
4
4
  upsertSync
5
- } from "./chunk-MQSTE4WH.js";
5
+ } from "./chunk-ZBWKJ42J.js";
6
6
  import {
7
7
  injectMcpAuthHeaders
8
8
  } from "./chunk-DBFPJSOY.js";
9
9
  import {
10
10
  listEntries
11
- } from "./chunk-IC5ZTBAW.js";
11
+ } from "./chunk-MUARVVXF.js";
12
12
  import {
13
13
  getEnvironment
14
- } from "./chunk-BRULBMRN.js";
14
+ } from "./chunk-NSUVDKNC.js";
15
15
  import {
16
16
  getAgent
17
- } from "./chunk-ENFWZ2QM.js";
17
+ } from "./chunk-6U6HEVSN.js";
18
18
 
19
19
  // src/sync/anthropic.ts
20
20
  import { createHash } from "crypto";
@@ -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
  serverBusy
6
6
  } from "./chunk-EZYKRG4W.js";
File without changes