@agentstep/agent-sdk 0.4.41 → 0.5.1

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 (197) 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 +8 -8
  4. package/dist/backends/claude/wrapper-script.js +1 -1
  5. package/dist/backends/codex/args.js +1 -1
  6. package/dist/backends/codex/auth.js +6 -6
  7. package/dist/backends/codex/index.js +8 -8
  8. package/dist/backends/factory/args.js +1 -1
  9. package/dist/backends/factory/auth.js +6 -6
  10. package/dist/backends/factory/index.js +8 -8
  11. package/dist/backends/gemini/args.js +1 -1
  12. package/dist/backends/gemini/auth.js +6 -6
  13. package/dist/backends/gemini/index.js +8 -8
  14. package/dist/backends/opencode/args.js +1 -1
  15. package/dist/backends/opencode/auth.js +6 -6
  16. package/dist/backends/opencode/index.js +9 -9
  17. package/dist/backends/opencode/mcp.js +1 -1
  18. package/dist/backends/pi/args.js +1 -1
  19. package/dist/backends/pi/auth.js +6 -6
  20. package/dist/backends/pi/index.js +8 -8
  21. package/dist/backends/registry.js +25 -25
  22. package/dist/{chunk-L2RX552S.js → chunk-22OUZJAV.js} +3 -3
  23. package/dist/{chunk-XWWLMJXT.js → chunk-2YFS435Z.js} +6 -15
  24. package/dist/{chunk-W2NHS4IF.js → chunk-2YIMCZJK.js} +15 -19
  25. package/dist/{chunk-WCDWL6ED.js → chunk-2YZOIFVN.js} +49 -0
  26. package/dist/{chunk-2PPB644A.js → chunk-37C5BNVV.js} +1 -1
  27. package/dist/{chunk-RDGOGAQ5.js → chunk-3FLQ7KZP.js} +1 -1
  28. package/dist/{chunk-2RSL5SO7.js → chunk-3NKK4M23.js} +2 -2
  29. package/dist/{chunk-CHDQ3HIR.js → chunk-3S4CGFKJ.js} +5 -9
  30. package/dist/{chunk-H7UKW666.js → chunk-445EL6J5.js} +1 -1
  31. package/dist/{chunk-FP4E3QUS.js → chunk-4LHJJXH3.js} +2 -2
  32. package/dist/{chunk-ZFJPOQSY.js → chunk-4MKBT3KA.js} +69 -30
  33. package/dist/{chunk-ENGKR2JT.js → chunk-56XDLNEW.js} +1 -1
  34. package/dist/{chunk-Y6SFUNGO.js → chunk-57LAR6EM.js} +4 -4
  35. package/dist/{chunk-JZL4L54R.js → chunk-5M47X54D.js} +2 -2
  36. package/dist/{chunk-MHBLVGRF.js → chunk-5MERXOLJ.js} +4 -4
  37. package/dist/{chunk-E7DD7F7J.js → chunk-5U5LRAFJ.js} +2 -2
  38. package/dist/{chunk-MQQ44IGX.js → chunk-63AKPSCV.js} +3 -3
  39. package/dist/{chunk-T5VRE77P.js → chunk-6KWJASEO.js} +1 -1
  40. package/dist/{chunk-EUINGLHA.js → chunk-6RFQCFL2.js} +30 -20
  41. package/dist/{chunk-V5HWHJ4P.js → chunk-74E7GKUG.js} +1 -1
  42. package/dist/{chunk-DU7LSFQQ.js → chunk-7SY65LWY.js} +6 -9
  43. package/dist/{chunk-JCW3ZRES.js → chunk-A46RUKGA.js} +1 -1
  44. package/dist/{chunk-LZFB3HRK.js → chunk-AQB3P5ZP.js} +5 -10
  45. package/dist/{chunk-RP6WQ4IH.js → chunk-B5EY2VJC.js} +3 -3
  46. package/dist/{chunk-ZTH5JRZG.js → chunk-BCIFFAGW.js} +41 -10
  47. package/dist/{chunk-2Z2KAPUL.js → chunk-BJP5BIHE.js} +3 -3
  48. package/dist/{chunk-5EQJOUWM.js → chunk-C35ZTCBP.js} +2 -2
  49. package/dist/{chunk-OXWELRJL.js → chunk-CBPO2P4I.js} +101 -16
  50. package/dist/{chunk-HH4OXSOV.js → chunk-CE366H6Z.js} +5 -5
  51. package/dist/{chunk-C46UG6GQ.js → chunk-CKFJN5XK.js} +1 -1
  52. package/dist/{chunk-YBZJHDSE.js → chunk-COZG53R3.js} +2 -2
  53. package/dist/{chunk-SV2B3P6B.js → chunk-DBFPJSOY.js} +19 -17
  54. package/dist/{chunk-NQVRZAIX.js → chunk-DMMNAQUM.js} +2 -2
  55. package/dist/{chunk-JWH4OIBP.js → chunk-DRNZ24RF.js} +4 -4
  56. package/dist/{chunk-3FDE3BPB.js → chunk-EDUTIJAU.js} +9 -7
  57. package/dist/{chunk-5EKQBD2H.js → chunk-FCUXFLNK.js} +2 -2
  58. package/dist/{chunk-34EB622U.js → chunk-FYBHPBWY.js} +2 -2
  59. package/dist/{chunk-HOIDGDU5.js → chunk-GD3WXIHX.js} +1 -1
  60. package/dist/{chunk-6IYCBW4J.js → chunk-GIUB2OPA.js} +1 -1
  61. package/dist/{chunk-V7MTIMPB.js → chunk-GQYSSSVA.js} +3 -3
  62. package/dist/{chunk-X6IQ57SC.js → chunk-H6OT5GUL.js} +9 -5
  63. package/dist/{chunk-TPPLYCJF.js → chunk-HMOSAXVZ.js} +2 -2
  64. package/dist/{chunk-L5RW66H5.js → chunk-HVLYE4S5.js} +1 -1
  65. package/dist/{chunk-PIJKJNGB.js → chunk-HZZ6ZLKP.js} +4 -4
  66. package/dist/{chunk-AR2TM7CR.js → chunk-I26QP3A3.js} +1 -1
  67. package/dist/{chunk-D2TRWKVQ.js → chunk-I2WVMCYN.js} +80 -2
  68. package/dist/{chunk-JHGJG2Z2.js → chunk-IBYOMAZ3.js} +1 -1
  69. package/dist/{chunk-SUGSHXND.js → chunk-IEZFRNLC.js} +2 -2
  70. package/dist/{chunk-ZMJ4EP4C.js → chunk-ILHIHMO3.js} +7 -2
  71. package/dist/{chunk-FDBR634Z.js → chunk-IMPLRDOV.js} +6 -6
  72. package/dist/{chunk-ZYISLRS6.js → chunk-JWHSUEDE.js} +114 -37
  73. package/dist/{chunk-TH7WJLZC.js → chunk-KGBKIJPF.js} +3 -3
  74. package/dist/{chunk-3NK6YTA5.js → chunk-KUWJJD6O.js} +42 -8
  75. package/dist/{chunk-2I35VGHX.js → chunk-L35CBI7F.js} +2 -2
  76. package/dist/{chunk-KLN6HPYM.js → chunk-L3IACZ72.js} +1 -1
  77. package/dist/{chunk-MXOG5SAO.js → chunk-LIXSR7BG.js} +11 -14
  78. package/dist/{chunk-7GG3FEK2.js → chunk-MCWCRZM4.js} +4 -4
  79. package/dist/{chunk-V66YKIW6.js → chunk-MXMXJYN4.js} +5 -5
  80. package/dist/{chunk-GVPJL3XS.js → chunk-MZYJFU4K.js} +5 -5
  81. package/dist/{chunk-ZMNQ2YJ6.js → chunk-NBYCX6L4.js} +4 -4
  82. package/dist/{chunk-ZQXBHNEZ.js → chunk-NL4UNA53.js} +2 -2
  83. package/dist/{chunk-WQARLGBG.js → chunk-NRXTWATQ.js} +3 -3
  84. package/dist/{chunk-FXLUSECC.js → chunk-O56RNR7B.js} +1 -1
  85. package/dist/{chunk-3IV56JJW.js → chunk-P56WU3UT.js} +3 -2
  86. package/dist/{chunk-NQX7WBA4.js → chunk-PJYCPDV5.js} +14 -9
  87. package/dist/{chunk-R5T4LJSK.js → chunk-PZNAQBHQ.js} +2 -2
  88. package/dist/{chunk-32XS3Y6P.js → chunk-Q4XF3OBK.js} +8 -8
  89. package/dist/{chunk-IU457W7Q.js → chunk-QBJOYOVF.js} +2 -1
  90. package/dist/{chunk-C6AXM3M7.js → chunk-QJ6QQO6D.js} +3 -3
  91. package/dist/{chunk-2GIX4HAT.js → chunk-R6EXYBCT.js} +2 -2
  92. package/dist/{chunk-RVR6C22M.js → chunk-RT5S5KRX.js} +1 -1
  93. package/dist/{chunk-USYY3L7G.js → chunk-T3FQPTOA.js} +2 -2
  94. package/dist/{chunk-5IGBMS2U.js → chunk-T3HMVHDG.js} +1 -1
  95. package/dist/{chunk-RH4GKU52.js → chunk-T3IGOI6Z.js} +18 -3
  96. package/dist/{chunk-DAVYI5H4.js → chunk-T7BHW3CP.js} +23 -23
  97. package/dist/{chunk-QSUGIJWV.js → chunk-TG3S4RVJ.js} +4 -9
  98. package/dist/{chunk-IAF6VMPO.js → chunk-TPMZO6S2.js} +1 -1
  99. package/dist/{chunk-OGJUSGF7.js → chunk-UMRDMOB6.js} +1 -1
  100. package/dist/{chunk-KKCLTWG7.js → chunk-UMVZZQKD.js} +1 -1
  101. package/dist/{chunk-LAVHQCRP.js → chunk-UQ3LKJPM.js} +3 -3
  102. package/dist/{chunk-P26WOAA3.js → chunk-USIMPXUH.js} +1 -1
  103. package/dist/{chunk-Z25I7DRV.js → chunk-V5DH3OAC.js} +10 -5
  104. package/dist/{chunk-N3QIXC2B.js → chunk-VJWNFMMQ.js} +2 -2
  105. package/dist/{chunk-ZVXIZ2JD.js → chunk-VP527YC5.js} +35 -6
  106. package/dist/{chunk-6POQAFEC.js → chunk-W3JMIUHV.js} +1 -1
  107. package/dist/{chunk-V2R7RWVY.js → chunk-WDACZSRU.js} +1 -1
  108. package/dist/{chunk-FOOH6SCB.js → chunk-WU74DV5R.js} +2 -2
  109. package/dist/{chunk-6GP5IKXE.js → chunk-XSNJ7NT2.js} +1 -1
  110. package/dist/{chunk-S7W3KJYH.js → chunk-YYMUSVUI.js} +9 -4
  111. package/dist/{chunk-CREPPDHX.js → chunk-YZZHDZ7B.js} +1 -1
  112. package/dist/{chunk-LMNFIJ6M.js → chunk-ZWC5V2DB.js} +15 -15
  113. package/dist/{chunk-N76ZVITA.js → chunk-ZY2U24QP.js} +24 -14
  114. package/dist/config/index.js +5 -5
  115. package/dist/containers/client.js +6 -6
  116. package/dist/containers/exec.js +6 -6
  117. package/dist/containers/lifecycle.js +37 -37
  118. package/dist/containers/setup.js +9 -9
  119. package/dist/db/agents.js +8 -6
  120. package/dist/db/api_keys.js +5 -5
  121. package/dist/db/audit.js +3 -3
  122. package/dist/db/batch.js +10 -10
  123. package/dist/db/client.js +2 -2
  124. package/dist/db/credentials.js +3 -3
  125. package/dist/db/drizzle.js +4 -4
  126. package/dist/db/environments.js +6 -6
  127. package/dist/db/events.js +5 -5
  128. package/dist/db/files.js +5 -5
  129. package/dist/db/memory.js +5 -5
  130. package/dist/db/migrations.js +1 -1
  131. package/dist/db/proxy.js +5 -5
  132. package/dist/db/schema.js +1 -1
  133. package/dist/db/session-resources.js +5 -5
  134. package/dist/db/sessions.js +8 -7
  135. package/dist/db/sync.js +5 -5
  136. package/dist/db/tenants.js +3 -3
  137. package/dist/db/traces.js +5 -5
  138. package/dist/db/upstream_keys.js +3 -3
  139. package/dist/db/vaults.js +12 -8
  140. package/dist/handlers/agents.js +57 -53
  141. package/dist/handlers/api_keys.js +54 -54
  142. package/dist/handlers/audit.js +54 -54
  143. package/dist/handlers/batch.js +54 -54
  144. package/dist/handlers/credentials.js +54 -54
  145. package/dist/handlers/environments.js +54 -54
  146. package/dist/handlers/events.js +57 -57
  147. package/dist/handlers/files.js +54 -54
  148. package/dist/handlers/index.js +101 -93
  149. package/dist/handlers/license.js +53 -53
  150. package/dist/handlers/memory.js +54 -54
  151. package/dist/handlers/metrics.js +53 -53
  152. package/dist/handlers/models.js +54 -54
  153. package/dist/handlers/openapi.js +3 -3
  154. package/dist/handlers/providers.js +53 -53
  155. package/dist/handlers/resources.js +53 -53
  156. package/dist/handlers/sessions.js +56 -56
  157. package/dist/handlers/settings.js +53 -53
  158. package/dist/handlers/skills-write.js +53 -53
  159. package/dist/handlers/skills.js +54 -54
  160. package/dist/handlers/stream.js +53 -53
  161. package/dist/handlers/tenants.js +54 -54
  162. package/dist/handlers/threads.js +53 -53
  163. package/dist/handlers/traces.js +54 -54
  164. package/dist/handlers/upstream_keys.js +56 -56
  165. package/dist/handlers/vaults.js +57 -53
  166. package/dist/handlers/whoami.js +53 -53
  167. package/dist/http.js +56 -52
  168. package/dist/index.js +58 -58
  169. package/dist/init.js +49 -49
  170. package/dist/lib/model-registry.js +6 -6
  171. package/dist/lib/skills-cache.js +6 -6
  172. package/dist/observability/otlp.js +12 -12
  173. package/dist/observability/redactor.js +8 -8
  174. package/dist/openapi/schemas.js +3 -1
  175. package/dist/openapi/spec.js +2 -2
  176. package/dist/providers/fly.js +5 -5
  177. package/dist/providers/modal.js +5 -5
  178. package/dist/providers/registry.js +1 -1
  179. package/dist/providers/resolve-secrets.js +7 -7
  180. package/dist/providers/sprites.js +7 -7
  181. package/dist/providers/upstream-keys.js +12 -11
  182. package/dist/providers/vercel.js +5 -5
  183. package/dist/proxy/forward.js +6 -6
  184. package/dist/queue/index.js +6 -6
  185. package/dist/sessions/bus.js +10 -10
  186. package/dist/sessions/driver.js +42 -42
  187. package/dist/sessions/grader.js +5 -5
  188. package/dist/sessions/mcp-auth.js +1 -1
  189. package/dist/sessions/secrets.js +8 -8
  190. package/dist/sessions/sweeper.js +38 -38
  191. package/dist/sessions/threads.js +42 -42
  192. package/dist/shutdown.js +39 -39
  193. package/dist/sync/anthropic.js +11 -11
  194. package/dist/sync/container-file-sync.js +6 -6
  195. package/dist/sync/file-sync.js +17 -17
  196. package/package.json +1 -1
  197. /package/dist/{chunk-WPK4ZPMG.js → chunk-JRQB3SHR.js} +0 -0
@@ -4,33 +4,36 @@ import {
4
4
  tenantFilter
5
5
  } from "./chunk-23UKWXJH.js";
6
6
  import {
7
+ decodeCursor,
7
8
  jsonOk,
9
+ paginatedOk,
8
10
  routeWrap
9
- } from "./chunk-RH4GKU52.js";
11
+ } from "./chunk-T3IGOI6Z.js";
10
12
  import {
11
13
  forwardToAnthropic,
12
14
  validateAnthropicProxy
13
- } from "./chunk-JCW3ZRES.js";
15
+ } from "./chunk-A46RUKGA.js";
14
16
  import {
15
17
  getProxiedTenantId,
16
18
  isProxied,
17
19
  markProxied,
18
20
  unmarkProxied
19
- } from "./chunk-E7DD7F7J.js";
21
+ } from "./chunk-5U5LRAFJ.js";
20
22
  import {
21
23
  archiveAgent,
22
24
  createAgent,
23
25
  getAgent,
26
+ listAgentVersions,
24
27
  listAgents,
25
28
  updateAgent
26
- } from "./chunk-ZTH5JRZG.js";
29
+ } from "./chunk-BCIFFAGW.js";
27
30
  import {
28
31
  resolveBackend
29
- } from "./chunk-FDBR634Z.js";
32
+ } from "./chunk-IMPLRDOV.js";
30
33
  import {
31
34
  getDb,
32
35
  init_client
33
- } from "./chunk-6POQAFEC.js";
36
+ } from "./chunk-W3JMIUHV.js";
34
37
  import {
35
38
  badRequest,
36
39
  conflict,
@@ -77,25 +80,23 @@ var ToolSchema = z.union([
77
80
  input_schema: z.record(z.unknown())
78
81
  })
79
82
  ]);
80
- var McpServerSchema = z.record(
81
- z.object({
82
- type: z.enum(["stdio", "http", "sse"]).optional(),
83
- url: z.string().optional(),
84
- command: z.union([z.string(), z.array(z.string())]).optional(),
85
- args: z.array(z.string()).optional(),
86
- headers: z.record(z.string()).optional(),
87
- env: z.record(z.string()).optional()
88
- })
89
- );
90
83
  var ModelConfigSchema = z.object({
91
84
  speed: z.enum(["standard", "fast"]).optional()
92
85
  });
93
86
  var CreateSchema = z.object({
94
87
  name: z.string().min(1),
95
- model: z.string().min(1),
88
+ model: z.object({ id: z.string().min(1), speed: z.enum(["standard", "fast"]).optional() }),
89
+ description: z.string().max(2048).optional(),
90
+ metadata: z.record(z.string(), z.string().max(512)).optional(),
96
91
  system: z.string().nullish(),
97
92
  tools: z.array(ToolSchema).optional(),
98
- mcp_servers: McpServerSchema.optional(),
93
+ mcp_servers: z.array(
94
+ z.object({
95
+ name: z.string(),
96
+ type: z.string().optional(),
97
+ url: z.string().optional()
98
+ }).passthrough()
99
+ ).optional(),
99
100
  engine: z.enum(["claude", "opencode", "codex", "anthropic", "gemini", "factory", "pi"]).optional(),
100
101
  webhook_url: z.string().url().optional(),
101
102
  webhook_events: z.array(z.string()).optional(),
@@ -117,16 +118,28 @@ var CreateSchema = z.object({
117
118
  /** v0.5: required for global admin, ignored for tenant users. */
118
119
  tenant_id: z.string().optional()
119
120
  }).refine((data) => {
121
+ if (!data.metadata) return true;
122
+ return Object.keys(data.metadata).length <= 16;
123
+ }, "metadata exceeds 16 key limit").refine((data) => {
120
124
  if (!data.skills) return true;
121
125
  const total = data.skills.reduce((sum, s) => sum + s.content.length, 0);
122
126
  return total <= 1024 * 1024;
123
127
  }, "Total skills content exceeds 1MB limit");
124
128
  var UpdateSchema = z.object({
129
+ version: z.number().int().min(1),
125
130
  name: z.string().min(1).optional(),
126
- model: z.string().min(1).optional(),
131
+ model: z.object({ id: z.string().min(1), speed: z.enum(["standard", "fast"]).optional() }).optional(),
132
+ description: z.string().max(2048).optional(),
133
+ metadata: z.record(z.string(), z.string().max(512)).optional(),
127
134
  system: z.string().nullish(),
128
135
  tools: z.array(z.unknown()).optional(),
129
- mcp_servers: z.record(z.unknown()).optional(),
136
+ mcp_servers: z.array(
137
+ z.object({
138
+ name: z.string(),
139
+ type: z.string().optional(),
140
+ url: z.string().optional()
141
+ }).passthrough()
142
+ ).optional(),
130
143
  webhook_url: z.string().url().nullish(),
131
144
  webhook_events: z.array(z.string()).optional(),
132
145
  /** Null clears the secret (unsigned webhooks); string rotates it. */
@@ -140,6 +153,9 @@ var UpdateSchema = z.object({
140
153
  skills: z.array(SkillSchema).max(20).optional(),
141
154
  model_config: ModelConfigSchema.optional()
142
155
  }).refine((data) => {
156
+ if (!data.metadata) return true;
157
+ return Object.keys(data.metadata).length <= 16;
158
+ }, "metadata exceeds 16 key limit").refine((data) => {
143
159
  if (!data.skills) return true;
144
160
  const total = data.skills.reduce((sum, s) => sum + s.content.length, 0);
145
161
  return total <= 1024 * 1024;
@@ -172,10 +188,12 @@ function handleCreateAgent(request) {
172
188
  return proxyRes;
173
189
  }
174
190
  const backend = resolveBackend(backendName);
191
+ const modelId = parsed.data.model.id;
192
+ const modelSpeed = parsed.data.model.speed;
175
193
  const { isValidModelForEngine, FALLBACK_MODELS } = await import("./backends/models.js");
176
- if (!isValidModelForEngine(backendName, parsed.data.model)) {
194
+ if (!isValidModelForEngine(backendName, modelId)) {
177
195
  throw badRequest(
178
- `Model "${parsed.data.model}" is not supported by the ${backendName} engine. Supported models: ${(FALLBACK_MODELS[backendName] ?? []).join(", ")}`
196
+ `Model "${modelId}" is not supported by the ${backendName} engine. Supported models: ${(FALLBACK_MODELS[backendName] ?? []).join(", ")}`
179
197
  );
180
198
  }
181
199
  if (backendName !== "claude" && parsed.data.tools && parsed.data.tools.length > 0) {
@@ -185,13 +203,27 @@ function handleCreateAgent(request) {
185
203
  }
186
204
  const createErr = backend.validateAgentCreation?.();
187
205
  if (createErr) throw badRequest(createErr);
206
+ const mcpInput = parsed.data.mcp_servers;
207
+ let mcpRecord = {};
208
+ if (mcpInput) {
209
+ for (const s of mcpInput) {
210
+ const { name, ...rest } = s;
211
+ mcpRecord[name] = { type: rest.type ?? "url", ...rest };
212
+ }
213
+ }
214
+ const mergedModelConfig = {
215
+ ...parsed.data.model_config ?? {},
216
+ ...modelSpeed ? { speed: modelSpeed } : {}
217
+ };
188
218
  const nowIso = (/* @__PURE__ */ new Date()).toISOString();
189
219
  const agent = createAgent({
190
220
  name: parsed.data.name,
191
- model: parsed.data.model,
221
+ model: modelId,
222
+ description: parsed.data.description,
223
+ metadata: parsed.data.metadata,
192
224
  system: parsed.data.system ?? null,
193
225
  tools: parsed.data.tools ?? [{ type: "agent_toolset_20260401" }],
194
- mcp_servers: parsed.data.mcp_servers ?? {},
226
+ mcp_servers: mcpRecord,
195
227
  backend: backendName,
196
228
  webhook_url: parsed.data.webhook_url ?? null,
197
229
  webhook_events: parsed.data.webhook_events,
@@ -203,7 +235,7 @@ function handleCreateAgent(request) {
203
235
  ...s,
204
236
  installed_at: s.installed_at ?? nowIso
205
237
  })),
206
- model_config: parsed.data.model_config,
238
+ model_config: mergedModelConfig,
207
239
  tenant_id: createTenantId
208
240
  });
209
241
  return jsonOk(agent, 201);
@@ -215,7 +247,7 @@ function handleListAgents(request) {
215
247
  const limit = url.searchParams.get("limit");
216
248
  const order = url.searchParams.get("order");
217
249
  const includeArchived = url.searchParams.get("include_archived") === "true";
218
- const cursor = url.searchParams.get("page") ?? void 0;
250
+ const cursor = decodeCursor(url.searchParams.get("page"));
219
251
  const requestedLimit = limit ? Number(limit) : 20;
220
252
  const data = listAgents({
221
253
  limit: requestedLimit,
@@ -224,12 +256,7 @@ function handleListAgents(request) {
224
256
  cursor,
225
257
  tenantFilter: tenantFilter(auth)
226
258
  });
227
- return jsonOk({
228
- data,
229
- has_more: data.length === requestedLimit,
230
- first_id: data.length > 0 ? data[0].id : null,
231
- last_id: data.length > 0 ? data[data.length - 1].id : null
232
- });
259
+ return paginatedOk(data, requestedLimit);
233
260
  });
234
261
  }
235
262
  function handleGetAgent(request, id) {
@@ -251,20 +278,36 @@ function handleUpdateAgent(request, id) {
251
278
  assertProxiedAgentTenant(auth, id);
252
279
  return forwardToAnthropic(request, `/v1/agents/${id}`);
253
280
  }
254
- loadAgentForCaller(auth, id);
281
+ const current = loadAgentForCaller(auth, id);
255
282
  const body = await request.json().catch(() => null);
256
283
  if (body && typeof body === "object" && "backend" in body) {
257
284
  throw badRequest("backend cannot be changed after agent creation");
258
285
  }
259
286
  const parsed = UpdateSchema.safeParse(body);
260
287
  if (!parsed.success) throw badRequest(parsed.error.message);
288
+ if (current.version !== parsed.data.version) {
289
+ throw conflict(`Version mismatch: expected ${current.version}, got ${parsed.data.version}`);
290
+ }
291
+ const modelId = parsed.data.model?.id;
292
+ const modelSpeed = parsed.data.model?.speed;
293
+ let mcpRecord;
294
+ if (parsed.data.mcp_servers !== void 0) {
295
+ mcpRecord = {};
296
+ for (const s of parsed.data.mcp_servers) {
297
+ const { name, ...rest } = s;
298
+ mcpRecord[name] = { type: rest.type ?? "url", ...rest };
299
+ }
300
+ }
301
+ const mergedModelConfig = parsed.data.model_config || modelSpeed ? { ...parsed.data.model_config ?? {}, ...modelSpeed ? { speed: modelSpeed } : {} } : void 0;
261
302
  const nowIso = (/* @__PURE__ */ new Date()).toISOString();
262
303
  const updated = updateAgent(id, {
263
304
  name: parsed.data.name,
264
- model: parsed.data.model,
305
+ model: modelId,
306
+ description: parsed.data.description,
307
+ metadata: parsed.data.metadata,
265
308
  system: parsed.data.system,
266
309
  tools: parsed.data.tools,
267
- mcp_servers: parsed.data.mcp_servers,
310
+ mcp_servers: mcpRecord,
268
311
  webhook_url: parsed.data.webhook_url,
269
312
  webhook_events: parsed.data.webhook_events,
270
313
  webhook_secret: parsed.data.webhook_secret,
@@ -274,7 +317,7 @@ function handleUpdateAgent(request, id) {
274
317
  ...s,
275
318
  installed_at: s.installed_at ?? nowIso
276
319
  })),
277
- model_config: parsed.data.model_config
320
+ model_config: mergedModelConfig
278
321
  });
279
322
  if (!updated) throw notFound(`agent ${id} not found`);
280
323
  return jsonOk(updated);
@@ -294,11 +337,45 @@ function handleDeleteAgent(request, id) {
294
337
  return jsonOk({ id, type: "agent_deleted" });
295
338
  });
296
339
  }
340
+ function handleArchiveAgent(request, id) {
341
+ return routeWrap(request, async ({ auth }) => {
342
+ if (isProxied(id)) {
343
+ assertProxiedAgentTenant(auth, id);
344
+ const res = await forwardToAnthropic(request, `/v1/agents/${id}/archive`);
345
+ if (res.ok) unmarkProxied(id);
346
+ return res;
347
+ }
348
+ loadAgentForCaller(auth, id);
349
+ const ok = archiveAgent(id);
350
+ if (!ok) throw notFound(`agent ${id} not found`);
351
+ const agent = getAgent(id);
352
+ return jsonOk(agent);
353
+ });
354
+ }
355
+ function handleListAgentVersions(request, id) {
356
+ return routeWrap(request, async ({ auth, request: req }) => {
357
+ loadAgentForCaller(auth, id);
358
+ const url = new URL(req.url);
359
+ const limit = url.searchParams.get("limit");
360
+ const cursorRaw = decodeCursor(url.searchParams.get("page"));
361
+ const cursor = cursorRaw ? Number(cursorRaw) : void 0;
362
+ const requestedLimit = limit ? Number(limit) : 20;
363
+ const data = listAgentVersions(id, {
364
+ limit: requestedLimit,
365
+ cursor
366
+ });
367
+ const hasMore = data.length === requestedLimit;
368
+ const nextPage = hasMore && data.length > 0 ? Buffer.from(String(data[data.length - 1].version)).toString("base64url") : null;
369
+ return jsonOk({ data, next_page: nextPage });
370
+ });
371
+ }
297
372
 
298
373
  export {
299
374
  handleCreateAgent,
300
375
  handleListAgents,
301
376
  handleGetAgent,
302
377
  handleUpdateAgent,
303
- handleDeleteAgent
378
+ handleDeleteAgent,
379
+ handleArchiveAgent,
380
+ handleListAgentVersions
304
381
  };
@@ -10,14 +10,14 @@ import {
10
10
  import {
11
11
  getDrizzle,
12
12
  init_drizzle
13
- } from "./chunk-R5T4LJSK.js";
13
+ } from "./chunk-PZNAQBHQ.js";
14
14
  import {
15
15
  schema_exports
16
- } from "./chunk-ZMJ4EP4C.js";
16
+ } from "./chunk-ILHIHMO3.js";
17
17
  import {
18
18
  getDb,
19
19
  init_client
20
- } from "./chunk-6POQAFEC.js";
20
+ } from "./chunk-W3JMIUHV.js";
21
21
 
22
22
  // src/db/events.ts
23
23
  init_client();
@@ -1,10 +1,13 @@
1
1
  import {
2
2
  init_session_resources,
3
3
  session_resources_exports
4
- } from "./chunk-5EKQBD2H.js";
4
+ } from "./chunk-FCUXFLNK.js";
5
+ import {
6
+ getAgent
7
+ } from "./chunk-BCIFFAGW.js";
5
8
  import {
6
9
  DEFAULT_TENANT_ID
7
- } from "./chunk-AR2TM7CR.js";
10
+ } from "./chunk-I26QP3A3.js";
8
11
  import {
9
12
  init_ids,
10
13
  newId
@@ -17,19 +20,19 @@ import {
17
20
  import {
18
21
  getDrizzle,
19
22
  init_drizzle
20
- } from "./chunk-R5T4LJSK.js";
23
+ } from "./chunk-PZNAQBHQ.js";
21
24
  import {
22
25
  schema_exports
23
- } from "./chunk-ZMJ4EP4C.js";
26
+ } from "./chunk-ILHIHMO3.js";
24
27
  import {
25
28
  __toCommonJS
26
29
  } from "./chunk-2ESYSVXG.js";
27
30
 
28
31
  // src/db/sessions.ts
29
32
  init_drizzle();
33
+ import { eq, and, isNull, lt, gt, gte, lte, inArray, sql } from "drizzle-orm";
30
34
  init_ids();
31
35
  init_clock();
32
- import { eq, and, isNull, lt, gt, gte, lte, sql } from "drizzle-orm";
33
36
  function hydrateSession(row) {
34
37
  let resources;
35
38
  try {
@@ -60,10 +63,34 @@ function hydrateSession(row) {
60
63
  } catch {
61
64
  resources = row.resources_json ? JSON.parse(row.resources_json) : [];
62
65
  }
66
+ const agentObj = getAgent(row.agent_id, row.agent_version);
67
+ const agentEmbed = agentObj ? {
68
+ type: "agent",
69
+ id: agentObj.id,
70
+ version: agentObj.version,
71
+ name: agentObj.name,
72
+ description: agentObj.description,
73
+ model: agentObj.model,
74
+ system: agentObj.system,
75
+ tools: agentObj.tools,
76
+ mcp_servers: agentObj.mcp_servers,
77
+ skills: agentObj.skills
78
+ } : {
79
+ type: "agent",
80
+ id: row.agent_id,
81
+ version: row.agent_version,
82
+ name: "",
83
+ description: "",
84
+ model: { id: "" },
85
+ system: null,
86
+ tools: [],
87
+ mcp_servers: [],
88
+ skills: []
89
+ };
63
90
  return {
64
91
  id: row.id,
65
92
  type: "session",
66
- agent: { type: "agent", id: row.agent_id, version: row.agent_version },
93
+ agent: agentEmbed,
67
94
  environment_id: row.environment_id,
68
95
  status: row.status,
69
96
  stop_reason: row.stop_reason,
@@ -87,7 +114,10 @@ function hydrateSession(row) {
87
114
  input_tokens: row.usage_input_tokens,
88
115
  output_tokens: row.usage_output_tokens,
89
116
  cache_read_input_tokens: row.usage_cache_read_input_tokens,
90
- cache_creation_input_tokens: row.usage_cache_creation_input_tokens,
117
+ cache_creation: {
118
+ ephemeral_5m_input_tokens: row.usage_cache_creation_input_tokens,
119
+ ephemeral_1h_input_tokens: 0
120
+ },
91
121
  cost_usd: row.usage_cost_usd
92
122
  },
93
123
  created_at: toIso(row.created_at),
@@ -209,7 +239,11 @@ function listSessions(opts) {
209
239
  if (opts.agent_version != null) conditions.push(eq(schema_exports.sessions.agent_version, opts.agent_version));
210
240
  if (opts.environmentId) conditions.push(eq(schema_exports.sessions.environment_id, opts.environmentId));
211
241
  if (opts.parent_session_id) conditions.push(eq(schema_exports.sessions.parent_session_id, opts.parent_session_id));
212
- if (opts.status) conditions.push(eq(schema_exports.sessions.status, opts.status));
242
+ if (opts.statuses?.length) {
243
+ conditions.push(inArray(schema_exports.sessions.status, opts.statuses));
244
+ } else if (opts.status) {
245
+ conditions.push(eq(schema_exports.sessions.status, opts.status));
246
+ }
213
247
  if (!includeArchived) conditions.push(isNull(schema_exports.sessions.archived_at));
214
248
  if (opts.createdGt != null) conditions.push(gt(schema_exports.sessions.created_at, opts.createdGt));
215
249
  if (opts.createdGte != null) conditions.push(gte(schema_exports.sessions.created_at, opts.createdGte));
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  buildCodexArgs
3
- } from "./chunk-NQX7WBA4.js";
3
+ } from "./chunk-PJYCPDV5.js";
4
4
  import {
5
5
  buildCodexAuthEnv,
6
6
  validateCodexRuntime
7
- } from "./chunk-6IYCBW4J.js";
7
+ } from "./chunk-GIUB2OPA.js";
8
8
  import {
9
9
  prepareCodexOnSandbox
10
10
  } from "./chunk-M2LUXIXU.js";
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  getDb,
16
16
  init_client
17
- } from "./chunk-6POQAFEC.js";
17
+ } from "./chunk-W3JMIUHV.js";
18
18
 
19
19
  // src/db/audit.ts
20
20
  init_client();
@@ -5,23 +5,25 @@ import {
5
5
  } from "./chunk-23UKWXJH.js";
6
6
  import {
7
7
  kickoffEnvironmentSetup
8
- } from "./chunk-C6AXM3M7.js";
8
+ } from "./chunk-QJ6QQO6D.js";
9
9
  import {
10
+ decodeCursor,
10
11
  jsonOk,
12
+ paginatedOk,
11
13
  routeWrap
12
- } from "./chunk-RH4GKU52.js";
14
+ } from "./chunk-T3IGOI6Z.js";
13
15
  import {
14
16
  forwardToAnthropic
15
- } from "./chunk-JCW3ZRES.js";
17
+ } from "./chunk-A46RUKGA.js";
16
18
  import {
17
19
  getProxiedTenantId,
18
20
  isProxied,
19
21
  markProxied,
20
22
  unmarkProxied
21
- } from "./chunk-E7DD7F7J.js";
23
+ } from "./chunk-5U5LRAFJ.js";
22
24
  import {
23
25
  resolveContainerProvider
24
- } from "./chunk-WPK4ZPMG.js";
26
+ } from "./chunk-JRQB3SHR.js";
25
27
  import {
26
28
  archiveEnvironment,
27
29
  createEnvironment,
@@ -30,11 +32,11 @@ import {
30
32
  hasSessionsAttached,
31
33
  listEnvironments,
32
34
  updateEnvironment
33
- } from "./chunk-X6IQ57SC.js";
35
+ } from "./chunk-H6OT5GUL.js";
34
36
  import {
35
37
  getDb,
36
38
  init_client
37
- } from "./chunk-6POQAFEC.js";
39
+ } from "./chunk-W3JMIUHV.js";
38
40
  import {
39
41
  badRequest,
40
42
  conflict,
@@ -155,7 +157,7 @@ function handleListEnvironments(request) {
155
157
  const limit = url.searchParams.get("limit");
156
158
  const order = url.searchParams.get("order");
157
159
  const includeArchived = url.searchParams.get("include_archived") === "true";
158
- const cursor = url.searchParams.get("page") ?? void 0;
160
+ const cursor = decodeCursor(url.searchParams.get("page"));
159
161
  const requestedLimit = limit ? Number(limit) : 20;
160
162
  const data = listEnvironments({
161
163
  limit: requestedLimit,
@@ -164,12 +166,7 @@ function handleListEnvironments(request) {
164
166
  cursor,
165
167
  tenantFilter: tenantFilter(auth)
166
168
  });
167
- return jsonOk({
168
- data,
169
- has_more: data.length === requestedLimit,
170
- first_id: data.length > 0 ? data[0].id : null,
171
- last_id: data.length > 0 ? data[data.length - 1].id : null
172
- });
169
+ return paginatedOk(data, requestedLimit);
173
170
  });
174
171
  }
175
172
  function handleGetEnvironment(request, id) {
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  createSession
3
- } from "./chunk-3NK6YTA5.js";
3
+ } from "./chunk-KUWJJD6O.js";
4
4
  import {
5
5
  createEnvironment,
6
6
  deleteEnvironment,
7
7
  getEnvironment
8
- } from "./chunk-X6IQ57SC.js";
8
+ } from "./chunk-H6OT5GUL.js";
9
9
  import {
10
10
  archiveAgent,
11
11
  createAgent,
12
12
  getAgent
13
- } from "./chunk-ZTH5JRZG.js";
13
+ } from "./chunk-BCIFFAGW.js";
14
14
  import {
15
15
  getDrizzle,
16
16
  init_drizzle
17
- } from "./chunk-R5T4LJSK.js";
17
+ } from "./chunk-PZNAQBHQ.js";
18
18
 
19
19
  // src/db/batch.ts
20
20
  init_drizzle();
@@ -4,14 +4,14 @@ import {
4
4
  import {
5
5
  jsonOk,
6
6
  routeWrap
7
- } from "./chunk-RH4GKU52.js";
7
+ } from "./chunk-T3IGOI6Z.js";
8
8
  import {
9
9
  getProxiedTenantId
10
- } from "./chunk-E7DD7F7J.js";
10
+ } from "./chunk-5U5LRAFJ.js";
11
11
  import {
12
12
  getSession,
13
13
  updateSessionResources
14
- } from "./chunk-3NK6YTA5.js";
14
+ } from "./chunk-KUWJJD6O.js";
15
15
  import {
16
16
  countResources,
17
17
  createResource,
@@ -19,11 +19,11 @@ import {
19
19
  getResource,
20
20
  init_session_resources,
21
21
  listResources
22
- } from "./chunk-5EKQBD2H.js";
22
+ } from "./chunk-FCUXFLNK.js";
23
23
  import {
24
24
  getDb,
25
25
  init_client
26
- } from "./chunk-6POQAFEC.js";
26
+ } from "./chunk-W3JMIUHV.js";
27
27
  import {
28
28
  badRequest,
29
29
  notFound
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  onAfterCommit
3
- } from "./chunk-MHBLVGRF.js";
3
+ } from "./chunk-5MERXOLJ.js";
4
4
  import {
5
5
  getSessionRow
6
- } from "./chunk-3NK6YTA5.js";
6
+ } from "./chunk-KUWJJD6O.js";
7
7
  import {
8
8
  listEventsByTrace
9
- } from "./chunk-TH7WJLZC.js";
9
+ } from "./chunk-KGBKIJPF.js";
10
10
  import {
11
11
  getAgent
12
- } from "./chunk-ZTH5JRZG.js";
12
+ } from "./chunk-BCIFFAGW.js";
13
13
  import {
14
14
  getConfig
15
- } from "./chunk-V7MTIMPB.js";
15
+ } from "./chunk-GQYSSSVA.js";
16
16
 
17
17
  // src/observability/otlp.ts
18
18
  import { createHash } from "crypto";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildClaudeArgs,
3
3
  buildClaudeAuthEnv
4
- } from "./chunk-S7W3KJYH.js";
4
+ } from "./chunk-YYMUSVUI.js";
5
5
  import {
6
6
  PERMISSION_BRIDGE_DIR,
7
7
  PERMISSION_HOOK_SCRIPT_PATH,
@@ -22,10 +22,10 @@ import {
22
22
  import {
23
23
  CLAUDE_WRAPPER_PATH,
24
24
  installClaudeWrapper
25
- } from "./chunk-IU457W7Q.js";
25
+ } from "./chunk-QBJOYOVF.js";
26
26
  import {
27
27
  getConfig
28
- } from "./chunk-V7MTIMPB.js";
28
+ } from "./chunk-GQYSSSVA.js";
29
29
 
30
30
  // src/backends/claude/index.ts
31
31
  function buildTurn(input) {
@@ -38,7 +38,7 @@ function buildTurn(input) {
38
38
  const env = buildClaudeAuthEnv();
39
39
  const customTools = agent.tools.filter((t) => t.type === "custom");
40
40
  const hasBridgeTools = customTools.length > 0 || agent.threads_enabled;
41
- if (hasBridgeTools || agent.mcp_servers && Object.keys(agent.mcp_servers).length > 0) {
41
+ if (hasBridgeTools || agent.mcp_servers && agent.mcp_servers.length > 0) {
42
42
  const mcpIdx = argsBase.indexOf("--mcp-config");
43
43
  let existingServers = {};
44
44
  if (mcpIdx >= 0 && mcpIdx + 1 < argsBase.length) {
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  jsonOk,
3
3
  routeWrap
4
- } from "./chunk-RH4GKU52.js";
4
+ } from "./chunk-T3IGOI6Z.js";
5
5
  import {
6
6
  readSetting,
7
7
  writeSetting
8
- } from "./chunk-V7MTIMPB.js";
8
+ } from "./chunk-GQYSSSVA.js";
9
9
  import {
10
10
  badRequest
11
11
  } from "./chunk-EZYKRG4W.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  forwardToAnthropic
3
- } from "./chunk-JCW3ZRES.js";
3
+ } from "./chunk-A46RUKGA.js";
4
4
  import {
5
5
  isAnthropicApiKey,
6
6
  isPassthroughAllowedPath
@@ -8,10 +8,10 @@ import {
8
8
  import {
9
9
  findByRawKey,
10
10
  hydratePermissions
11
- } from "./chunk-USYY3L7G.js";
11
+ } from "./chunk-T3FQPTOA.js";
12
12
  import {
13
13
  getConfig
14
- } from "./chunk-V7MTIMPB.js";
14
+ } from "./chunk-GQYSSSVA.js";
15
15
  import {
16
16
  unauthorized
17
17
  } from "./chunk-EZYKRG4W.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-V7MTIMPB.js";
3
+ } from "./chunk-GQYSSSVA.js";
4
4
  import {
5
5
  ApiError
6
6
  } from "./chunk-EZYKRG4W.js";
@@ -5,9 +5,10 @@ function buildOpencodeArgs(input) {
5
5
  args.push("--session", input.backendSessionId);
6
6
  }
7
7
  if (input.agent.model) {
8
+ const modelId = input.agent.model.id;
8
9
  const cloudPrefixes = ["claude-", "gpt-", "o1-", "o3-", "o4-", "codex-", "chatgpt-", "gemini-"];
9
- const isOllama = !input.agent.model.includes("/") && !cloudPrefixes.some((p) => input.agent.model.startsWith(p));
10
- const modelArg = isOllama ? `ollama/${input.agent.model}` : input.agent.model;
10
+ const isOllama = !modelId.includes("/") && !cloudPrefixes.some((p) => modelId.startsWith(p));
11
+ const modelArg = isOllama ? `ollama/${modelId}` : modelId;
11
12
  args.push("--model", modelArg);
12
13
  }
13
14
  return args;