@agentstep/agent-sdk 0.4.14 → 0.4.16

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 (138) hide show
  1. package/dist/auth/middleware.js +6 -1
  2. package/dist/auth/passthrough.js +9 -0
  3. package/dist/backends/claude/args.js +2 -2
  4. package/dist/backends/claude/index.js +3 -3
  5. package/dist/backends/codex/auth.js +2 -2
  6. package/dist/backends/codex/index.js +5 -5
  7. package/dist/backends/factory/auth.js +2 -2
  8. package/dist/backends/factory/index.js +9 -9
  9. package/dist/backends/gemini/auth.js +2 -2
  10. package/dist/backends/gemini/index.js +6 -6
  11. package/dist/backends/opencode/auth.js +2 -2
  12. package/dist/backends/opencode/index.js +3 -3
  13. package/dist/backends/pi/auth.js +2 -2
  14. package/dist/backends/pi/index.js +6 -6
  15. package/dist/backends/registry.js +18 -18
  16. package/dist/{chunk-GSODOHNB.js → chunk-3LG7DRJL.js} +1 -1
  17. package/dist/{chunk-HOPCVGWL.js → chunk-3PLJHZFD.js} +1 -1
  18. package/dist/{chunk-UVUSSZ74.js → chunk-5XF65N7J.js} +1 -1
  19. package/dist/{chunk-SS2EEKNM.js → chunk-66CJ6LMV.js} +1 -1
  20. package/dist/{chunk-MFEOQ26S.js → chunk-6RRYNQXP.js} +2 -2
  21. package/dist/{chunk-7GPKEOAO.js → chunk-7CADMELE.js} +8 -7
  22. package/dist/{chunk-CDK25PRU.js → chunk-ACKMNK3C.js} +5 -5
  23. package/dist/{chunk-QICG4KW4.js → chunk-BYWW5GFO.js} +1 -1
  24. package/dist/{chunk-K2ITIAVJ.js → chunk-C4IHTLG2.js} +13 -13
  25. package/dist/{chunk-YJPQFLY3.js → chunk-DHSSHDIG.js} +3 -2
  26. package/dist/{chunk-FVFMYO5W.js → chunk-ECRLACEF.js} +2 -2
  27. package/dist/{chunk-6QQKTF55.js → chunk-EUUDZGUE.js} +6 -6
  28. package/dist/{chunk-PCKFMALU.js → chunk-FB4OSWM2.js} +1 -1
  29. package/dist/{chunk-B47IDF63.js → chunk-FCCWKCGQ.js} +1 -1
  30. package/dist/{chunk-PTGANYUM.js → chunk-FCULDJQO.js} +1 -1
  31. package/dist/{chunk-HE7EOIPA.js → chunk-GJBKDPQD.js} +1 -1
  32. package/dist/{chunk-X37MWWUA.js → chunk-HECQRMDR.js} +1 -1
  33. package/dist/{chunk-R7PAZ5OA.js → chunk-HJGUG7IH.js} +20 -20
  34. package/dist/{chunk-LDKZ2SMC.js → chunk-HKAW5ATE.js} +45 -45
  35. package/dist/{chunk-374KGHBM.js → chunk-HWWCVD2R.js} +4 -4
  36. package/dist/{chunk-MEEY7BYC.js → chunk-IHMQQ43E.js} +1 -1
  37. package/dist/{chunk-42O6EBUN.js → chunk-JNQLE5D7.js} +2 -2
  38. package/dist/{chunk-UF25F3MH.js → chunk-JOAEFGXZ.js} +13 -13
  39. package/dist/{chunk-F7DOI3B5.js → chunk-K62YRMVY.js} +7 -7
  40. package/dist/{chunk-NCUIEBQY.js → chunk-L4T7KCQ2.js} +1 -1
  41. package/dist/{chunk-EDRLRJNT.js → chunk-LJF4GWPJ.js} +1 -1
  42. package/dist/{chunk-PFLR7INE.js → chunk-LJL3DM2L.js} +9 -4
  43. package/dist/{chunk-24NL6GPL.js → chunk-LRPU2HS5.js} +1 -1
  44. package/dist/{chunk-7OAMTB47.js → chunk-M4CTE7EH.js} +1 -1
  45. package/dist/{chunk-V7WEALLX.js → chunk-MA7IO6RU.js} +1 -1
  46. package/dist/{chunk-6NZPNYHA.js → chunk-MD4BZGMS.js} +2 -2
  47. package/dist/{chunk-G37JVAOI.js → chunk-NK2RCTFI.js} +4 -4
  48. package/dist/{chunk-SNZ4PDVT.js → chunk-OFLYKESG.js} +7 -7
  49. package/dist/{chunk-HIDFQDFP.js → chunk-PNYCULIF.js} +3 -3
  50. package/dist/{chunk-GCMYVWZ6.js → chunk-PWWRWR75.js} +41 -2
  51. package/dist/{chunk-TBSWWUJS.js → chunk-PZWVTEL2.js} +1 -1
  52. package/dist/{chunk-MRJMXGCG.js → chunk-QDOCVDWJ.js} +2 -2
  53. package/dist/{chunk-SHKBQQ7W.js → chunk-QFUJDBET.js} +6 -6
  54. package/dist/{chunk-YEUALILD.js → chunk-QH57EOKP.js} +9 -1
  55. package/dist/{chunk-YIYEPKVQ.js → chunk-QLWA4MJ5.js} +15 -4
  56. package/dist/{chunk-LUQP36Y3.js → chunk-QOJMXK4S.js} +1 -1
  57. package/dist/{chunk-M5QX5E5Z.js → chunk-R45W644X.js} +1 -1
  58. package/dist/{chunk-4MHPOB7A.js → chunk-RZMR6H5Y.js} +1 -1
  59. package/dist/{chunk-TJA3RHWR.js → chunk-RZXRMPF4.js} +1 -1
  60. package/dist/{chunk-R6X47I23.js → chunk-S6AM7WVH.js} +1 -1
  61. package/dist/{chunk-MOLWE2ZY.js → chunk-SDLNBA53.js} +1 -1
  62. package/dist/{chunk-A7MX6RSQ.js → chunk-SIKTYKVO.js} +2 -2
  63. package/dist/{chunk-GGYTAWW6.js → chunk-SMKHXHLP.js} +1 -1
  64. package/dist/{chunk-GAFFXICQ.js → chunk-TKV7CFAM.js} +1 -1
  65. package/dist/{chunk-QSYXHYQU.js → chunk-TOKLTGSO.js} +1 -1
  66. package/dist/{chunk-CSNIN5YZ.js → chunk-TPAHUFSM.js} +1 -1
  67. package/dist/{chunk-F6M4RLDQ.js → chunk-TWPTR2C2.js} +1 -1
  68. package/dist/{chunk-B6LPLXPB.js → chunk-U6GNZJGO.js} +16 -7
  69. package/dist/{chunk-HR5YA24J.js → chunk-UJDAT42X.js} +7 -7
  70. package/dist/{chunk-Q3CV35V6.js → chunk-UYNE3WPU.js} +1 -1
  71. package/dist/{chunk-GR4QPRB7.js → chunk-VS7AMAMU.js} +4 -4
  72. package/dist/{chunk-GHDY4DVK.js → chunk-W5KXLYJH.js} +12 -12
  73. package/dist/chunk-W6WKXFHN.js +39 -0
  74. package/dist/{chunk-PGSOOOB4.js → chunk-WWYVMGRP.js} +3 -3
  75. package/dist/{chunk-IEG5LIX7.js → chunk-XPKY3Z54.js} +1 -1
  76. package/dist/{chunk-M674W5NT.js → chunk-XQA62XTJ.js} +1 -1
  77. package/dist/{chunk-J4TYHQQG.js → chunk-ZQGJKPPY.js} +3 -1
  78. package/dist/config/index.js +1 -1
  79. package/dist/containers/client.js +2 -2
  80. package/dist/containers/exec.js +2 -2
  81. package/dist/containers/lifecycle.js +24 -24
  82. package/dist/containers/setup.js +2 -2
  83. package/dist/db/credentials.js +1 -1
  84. package/dist/handlers/agents.js +39 -38
  85. package/dist/handlers/api_keys.js +39 -37
  86. package/dist/handlers/audit.js +39 -37
  87. package/dist/handlers/batch.js +39 -37
  88. package/dist/handlers/credentials.js +40 -38
  89. package/dist/handlers/environments.js +40 -39
  90. package/dist/handlers/events.js +41 -40
  91. package/dist/handlers/files.js +39 -37
  92. package/dist/handlers/index.js +97 -96
  93. package/dist/handlers/license.js +39 -37
  94. package/dist/handlers/memory.js +39 -37
  95. package/dist/handlers/metrics.js +39 -37
  96. package/dist/handlers/models.js +40 -38
  97. package/dist/handlers/openapi.js +2 -2
  98. package/dist/handlers/providers.js +39 -37
  99. package/dist/handlers/resources.js +39 -37
  100. package/dist/handlers/sessions.js +40 -39
  101. package/dist/handlers/settings.js +39 -37
  102. package/dist/handlers/skills-write.js +39 -37
  103. package/dist/handlers/skills.js +40 -38
  104. package/dist/handlers/stream.js +38 -37
  105. package/dist/handlers/tenants.js +39 -37
  106. package/dist/handlers/threads.js +39 -37
  107. package/dist/handlers/traces.js +39 -37
  108. package/dist/handlers/ui.js +1 -1
  109. package/dist/handlers/upstream_keys.js +40 -38
  110. package/dist/handlers/vaults.js +39 -37
  111. package/dist/handlers/whoami.js +39 -37
  112. package/dist/http.js +38 -36
  113. package/dist/index.js +57 -54
  114. package/dist/init.js +34 -34
  115. package/dist/lib/model-registry.js +2 -2
  116. package/dist/lib/skills-cache.js +2 -2
  117. package/dist/observability/otlp.js +4 -4
  118. package/dist/observability/redactor.js +2 -2
  119. package/dist/openapi/spec.js +1 -1
  120. package/dist/providers/fly.js +1 -1
  121. package/dist/providers/modal.js +1 -1
  122. package/dist/providers/registry.js +1 -1
  123. package/dist/providers/sprites.js +3 -3
  124. package/dist/providers/upstream-keys.js +4 -4
  125. package/dist/providers/vercel.js +1 -1
  126. package/dist/proxy/forward.js +2 -2
  127. package/dist/queue/index.js +2 -2
  128. package/dist/sessions/bus.js +2 -2
  129. package/dist/sessions/driver.js +28 -28
  130. package/dist/sessions/grader.js +1 -1
  131. package/dist/sessions/secrets.js +2 -2
  132. package/dist/sessions/sweeper.js +25 -25
  133. package/dist/sessions/threads.js +32 -32
  134. package/dist/shutdown.js +26 -26
  135. package/dist/sync/file-sync.js +7 -7
  136. package/package.json +1 -1
  137. package/dist/{chunk-EOFJ2MWJ.js → chunk-BMPB7XJH.js} +3 -3
  138. /package/dist/{chunk-N2RHTKW7.js → chunk-JSLEB2ED.js} +0 -0
@@ -4,16 +4,16 @@ import {
4
4
  import {
5
5
  buildGeminiAuthEnv,
6
6
  validateGeminiRuntime
7
- } from "./chunk-TJA3RHWR.js";
7
+ } from "./chunk-RZXRMPF4.js";
8
8
  import {
9
9
  prepareGeminiOnSandbox
10
10
  } from "./chunk-XG4UIGDH.js";
11
- import {
12
- createGeminiTranslator
13
- } from "./chunk-S3JRZFF5.js";
14
11
  import {
15
12
  GEMINI_WRAPPER_PATH
16
13
  } from "./chunk-3W6KEDQE.js";
14
+ import {
15
+ createGeminiTranslator
16
+ } from "./chunk-S3JRZFF5.js";
17
17
  import {
18
18
  wrapPromptWithSystem
19
19
  } from "./chunk-DAT55TX2.js";
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  jsonOk,
10
10
  routeWrap
11
- } from "./chunk-PFLR7INE.js";
11
+ } from "./chunk-LJL3DM2L.js";
12
12
  import {
13
13
  badRequest
14
14
  } from "./chunk-EZYKRG4W.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  getModels
3
- } from "./chunk-M5QX5E5Z.js";
3
+ } from "./chunk-R45W644X.js";
4
4
  import {
5
5
  jsonOk,
6
6
  routeWrap
7
- } from "./chunk-PFLR7INE.js";
7
+ } from "./chunk-LJL3DM2L.js";
8
8
 
9
9
  // src/handlers/models.ts
10
10
  function handleListModels(request) {
@@ -6,7 +6,16 @@ import {
6
6
  } from "./chunk-RMZRSYIJ.js";
7
7
  import {
8
8
  appendEvent
9
- } from "./chunk-EOFJ2MWJ.js";
9
+ } from "./chunk-BMPB7XJH.js";
10
+ import {
11
+ getSession,
12
+ getSessionRow,
13
+ setSessionSandbox
14
+ } from "./chunk-I5ZA45YL.js";
15
+ import {
16
+ deleteSprite,
17
+ listSprites
18
+ } from "./chunk-XPKY3Z54.js";
10
19
  import {
11
20
  allSessionSandboxes,
12
21
  countInEnv,
@@ -15,12 +24,7 @@ import {
15
24
  } from "./chunk-EFOIR7R3.js";
16
25
  import {
17
26
  resolveContainerProvider
18
- } from "./chunk-N2RHTKW7.js";
19
- import {
20
- getSession,
21
- getSessionRow,
22
- setSessionSandbox
23
- } from "./chunk-I5ZA45YL.js";
27
+ } from "./chunk-JSLEB2ED.js";
24
28
  import {
25
29
  getEnvironment,
26
30
  getEnvironmentRow
@@ -30,14 +34,10 @@ import {
30
34
  } from "./chunk-JEI7I3EH.js";
31
35
  import {
32
36
  resolveBackend
33
- } from "./chunk-SHKBQQ7W.js";
34
- import {
35
- deleteSprite,
36
- listSprites
37
- } from "./chunk-IEG5LIX7.js";
37
+ } from "./chunk-QFUJDBET.js";
38
38
  import {
39
39
  getConfig
40
- } from "./chunk-YEUALILD.js";
40
+ } from "./chunk-QH57EOKP.js";
41
41
  import {
42
42
  init_clock,
43
43
  nowMs
@@ -12,16 +12,16 @@ import {
12
12
  import {
13
13
  interruptSession
14
14
  } from "./chunk-DC2UMEQH.js";
15
- import {
16
- forwardToAnthropic
17
- } from "./chunk-YIYEPKVQ.js";
18
15
  import {
19
16
  kickoffEnvironmentSetup
20
- } from "./chunk-MOLWE2ZY.js";
17
+ } from "./chunk-SDLNBA53.js";
21
18
  import {
22
19
  jsonOk,
23
20
  routeWrap
24
- } from "./chunk-PFLR7INE.js";
21
+ } from "./chunk-LJL3DM2L.js";
22
+ import {
23
+ forwardToAnthropic
24
+ } from "./chunk-QLWA4MJ5.js";
25
25
  import {
26
26
  errors_exports,
27
27
  init_errors
@@ -38,11 +38,11 @@ import {
38
38
  } from "./chunk-LAWTTG2E.js";
39
39
  import {
40
40
  releaseSession
41
- } from "./chunk-UF25F3MH.js";
41
+ } from "./chunk-JOAEFGXZ.js";
42
42
  import {
43
43
  appendEvent,
44
44
  dropEmitter
45
- } from "./chunk-EOFJ2MWJ.js";
45
+ } from "./chunk-BMPB7XJH.js";
46
46
  import {
47
47
  archiveSession,
48
48
  createSession,
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  jsonOk,
7
7
  routeWrap
8
- } from "./chunk-PFLR7INE.js";
8
+ } from "./chunk-LJL3DM2L.js";
9
9
  import {
10
10
  getSession,
11
11
  listSessions
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-YEUALILD.js";
3
+ } from "./chunk-QH57EOKP.js";
4
4
  import {
5
5
  ApiError
6
6
  } from "./chunk-EZYKRG4W.js";
@@ -3,14 +3,14 @@ import {
3
3
  recordApiRequest
4
4
  } from "./chunk-D2XITRN6.js";
5
5
  import {
6
- authenticate
7
- } from "./chunk-GCMYVWZ6.js";
6
+ authenticateAndIntercept
7
+ } from "./chunk-PWWRWR75.js";
8
8
  import {
9
9
  checkAndBump
10
10
  } from "./chunk-HVUWXUUI.js";
11
11
  import {
12
12
  ensureInitialized
13
- } from "./chunk-K2ITIAVJ.js";
13
+ } from "./chunk-C4IHTLG2.js";
14
14
  import {
15
15
  captureException
16
16
  } from "./chunk-3MQ2FWXS.js";
@@ -26,7 +26,12 @@ async function routeWrap(request, handler) {
26
26
  let status = 500;
27
27
  try {
28
28
  await ensureInitialized();
29
- const auth = await authenticate(request);
29
+ const result = await authenticateAndIntercept(request);
30
+ if (result.kind === "response") {
31
+ status = result.response.status;
32
+ return result.response;
33
+ }
34
+ const auth = result.auth;
30
35
  const retryAfter = await checkAndBump(auth.keyId, auth.rateLimitRpm);
31
36
  if (retryAfter != null) {
32
37
  const err = tooManyRequests(
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  jsonOk,
6
6
  routeWrap
7
- } from "./chunk-PFLR7INE.js";
7
+ } from "./chunk-LJL3DM2L.js";
8
8
  import {
9
9
  getProxiedTenantId
10
10
  } from "./chunk-NIOWKTIF.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  listCredentialsWithTokens
3
- } from "./chunk-J4TYHQQG.js";
3
+ } from "./chunk-ZQGJKPPY.js";
4
4
  import {
5
5
  listEntries
6
6
  } from "./chunk-VIGJQU6V.js";
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  jsonOk,
17
17
  routeWrap
18
- } from "./chunk-PFLR7INE.js";
18
+ } from "./chunk-LJL3DM2L.js";
19
19
  import {
20
20
  createApiKey,
21
21
  getApiKeyById,
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  jsonOk,
3
3
  routeWrap
4
- } from "./chunk-PFLR7INE.js";
4
+ } from "./chunk-LJL3DM2L.js";
5
5
  import {
6
6
  readSetting,
7
7
  writeSetting
8
- } from "./chunk-YEUALILD.js";
8
+ } from "./chunk-QH57EOKP.js";
9
9
  import {
10
10
  badRequest
11
11
  } from "./chunk-EZYKRG4W.js";
@@ -1,3 +1,7 @@
1
+ import {
2
+ buildCodexAuthEnv,
3
+ validateCodexRuntime
4
+ } from "./chunk-5XF65N7J.js";
1
5
  import {
2
6
  prepareCodexOnSandbox
3
7
  } from "./chunk-7LQN7NVU.js";
@@ -13,10 +17,6 @@ import {
13
17
  import {
14
18
  buildCodexArgs
15
19
  } from "./chunk-NQX7WBA4.js";
16
- import {
17
- buildCodexAuthEnv,
18
- validateCodexRuntime
19
- } from "./chunk-UVUSSZ74.js";
20
20
  import {
21
21
  ApiError
22
22
  } from "./chunk-EZYKRG4W.js";
@@ -3,14 +3,14 @@ import {
3
3
  resolveCreateTenant,
4
4
  tenantFilter
5
5
  } from "./chunk-23UKWXJH.js";
6
- import {
7
- forwardToAnthropic,
8
- validateAnthropicProxy
9
- } from "./chunk-YIYEPKVQ.js";
10
6
  import {
11
7
  jsonOk,
12
8
  routeWrap
13
- } from "./chunk-PFLR7INE.js";
9
+ } from "./chunk-LJL3DM2L.js";
10
+ import {
11
+ forwardToAnthropic,
12
+ validateAnthropicProxy
13
+ } from "./chunk-QLWA4MJ5.js";
14
14
  import {
15
15
  getProxiedTenantId,
16
16
  isProxied,
@@ -26,7 +26,7 @@ import {
26
26
  } from "./chunk-JEI7I3EH.js";
27
27
  import {
28
28
  resolveBackend
29
- } from "./chunk-SHKBQQ7W.js";
29
+ } from "./chunk-QFUJDBET.js";
30
30
  import {
31
31
  getDb,
32
32
  init_client
@@ -190,7 +190,7 @@ function handleCreateAgent(request) {
190
190
  name: parsed.data.name,
191
191
  model: parsed.data.model,
192
192
  system: parsed.data.system ?? null,
193
- tools: parsed.data.tools ?? [],
193
+ tools: parsed.data.tools ?? [{ type: "agent_toolset_20260401" }],
194
194
  mcp_servers: parsed.data.mcp_servers ?? {},
195
195
  backend: backendName,
196
196
  webhook_url: parsed.data.webhook_url ?? null,
@@ -6,11 +6,11 @@ import {
6
6
  reconcileDockerOrphanSandboxes,
7
7
  reconcileOrphanSandboxes,
8
8
  releaseSession
9
- } from "./chunk-UF25F3MH.js";
9
+ } from "./chunk-JOAEFGXZ.js";
10
10
  import {
11
11
  appendEvent,
12
12
  dropEmitter
13
- } from "./chunk-EOFJ2MWJ.js";
13
+ } from "./chunk-BMPB7XJH.js";
14
14
  import {
15
15
  archiveSession,
16
16
  getSessionRow,
@@ -19,7 +19,7 @@ import {
19
19
  } from "./chunk-I5ZA45YL.js";
20
20
  import {
21
21
  getConfig
22
- } from "./chunk-YEUALILD.js";
22
+ } from "./chunk-QH57EOKP.js";
23
23
  import {
24
24
  init_clock,
25
25
  nowMs
@@ -1,7 +1,17 @@
1
+ import {
2
+ forwardToAnthropic
3
+ } from "./chunk-QLWA4MJ5.js";
4
+ import {
5
+ isAnthropicApiKey,
6
+ isPassthroughAllowedPath
7
+ } from "./chunk-W6WKXFHN.js";
1
8
  import {
2
9
  findByRawKey,
3
10
  hydratePermissions
4
11
  } from "./chunk-ADK2TYO4.js";
12
+ import {
13
+ getConfig
14
+ } from "./chunk-QH57EOKP.js";
5
15
  import {
6
16
  unauthorized
7
17
  } from "./chunk-EZYKRG4W.js";
@@ -19,6 +29,21 @@ async function authenticate(request) {
19
29
  const key = extractKey(request);
20
30
  if (!key) throw unauthorized();
21
31
  const row = findByRawKey(key);
32
+ if (isAnthropicApiKey(key)) {
33
+ if (!getConfig().anthropicPassthroughEnabled) throw unauthorized();
34
+ return {
35
+ keyId: "passthrough",
36
+ name: "anthropic-passthrough",
37
+ permissions: { admin: false, scope: null },
38
+ tenantId: null,
39
+ isGlobalAdmin: false,
40
+ budgetUsd: null,
41
+ rateLimitRpm: null,
42
+ spentUsd: 0,
43
+ mode: "passthrough",
44
+ passthroughKey: key
45
+ };
46
+ }
22
47
  if (!row) throw unauthorized();
23
48
  const permissions = hydratePermissions(row.permissions_json);
24
49
  return {
@@ -34,11 +59,25 @@ async function authenticate(request) {
34
59
  isGlobalAdmin: row.tenant_id === null && permissions.admin,
35
60
  budgetUsd: row.budget_usd ?? null,
36
61
  rateLimitRpm: row.rate_limit_rpm ?? null,
37
- spentUsd: row.spent_usd ?? 0
62
+ spentUsd: row.spent_usd ?? 0,
63
+ mode: "gateway"
38
64
  };
39
65
  }
66
+ async function authenticateAndIntercept(request) {
67
+ const auth = await authenticate(request);
68
+ if (auth.mode !== "passthrough") return { kind: "auth", auth };
69
+ const url = new URL(request.url);
70
+ if (!isPassthroughAllowedPath(url.pathname)) {
71
+ throw unauthorized();
72
+ }
73
+ const response = await forwardToAnthropic(request, url.pathname, {
74
+ apiKey: auth.passthroughKey
75
+ });
76
+ return { kind: "response", response };
77
+ }
40
78
 
41
79
  export {
42
80
  extractKey,
43
- authenticate
81
+ authenticate,
82
+ authenticateAndIntercept
44
83
  };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-XBHDQK4Z.js";
4
4
  import {
5
5
  getConfig
6
- } from "./chunk-YEUALILD.js";
6
+ } from "./chunk-QH57EOKP.js";
7
7
 
8
8
  // src/backends/claude/args.ts
9
9
  function buildClaudeArgs(input) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SUPPORTED_PROVIDERS
3
- } from "./chunk-GSODOHNB.js";
3
+ } from "./chunk-3LG7DRJL.js";
4
4
  import {
5
5
  addUpstreamKey,
6
6
  deleteUpstreamKey,
@@ -21,7 +21,7 @@ import {
21
21
  import {
22
22
  jsonOk,
23
23
  routeWrap
24
- } from "./chunk-PFLR7INE.js";
24
+ } from "./chunk-LJL3DM2L.js";
25
25
  import {
26
26
  badRequest,
27
27
  notFound
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  piBackend
3
- } from "./chunk-GR4QPRB7.js";
3
+ } from "./chunk-VS7AMAMU.js";
4
4
  import {
5
5
  opencodeBackend
6
- } from "./chunk-HE7EOIPA.js";
6
+ } from "./chunk-GJBKDPQD.js";
7
7
  import {
8
8
  geminiBackend
9
- } from "./chunk-374KGHBM.js";
9
+ } from "./chunk-HWWCVD2R.js";
10
10
  import {
11
11
  codexBackend
12
- } from "./chunk-G37JVAOI.js";
12
+ } from "./chunk-NK2RCTFI.js";
13
13
  import {
14
14
  factoryBackend
15
- } from "./chunk-HR5YA24J.js";
15
+ } from "./chunk-UJDAT42X.js";
16
16
  import {
17
17
  claudeBackend
18
- } from "./chunk-A7MX6RSQ.js";
18
+ } from "./chunk-SIKTYKVO.js";
19
19
 
20
20
  // src/backends/registry.ts
21
21
  var BACKENDS = {
@@ -50,9 +50,17 @@ function loadConfig() {
50
50
  otlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTLP_ENDPOINT || readSetting("otlp_endpoint") || void 0,
51
51
  otlpAuthorization: process.env.OTEL_EXPORTER_OTLP_HEADERS_AUTHORIZATION || process.env.OTLP_AUTHORIZATION || readSetting("otlp_authorization") || void 0,
52
52
  redactEnvKeys: (process.env.OBS_REDACT_KEYS || readSetting("obs_redact_keys") || "").split(",").map((s) => s.trim()).filter(Boolean),
53
- ollamaUrl: process.env.OLLAMA_URL || readSetting("ollama_url") || "http://localhost:11434"
53
+ ollamaUrl: process.env.OLLAMA_URL || readSetting("ollama_url") || "http://localhost:11434",
54
+ anthropicPassthroughEnabled: parseBool(
55
+ process.env.ANTHROPIC_PASSTHROUGH_ENABLED ?? readSetting("anthropic_passthrough_enabled")
56
+ )
54
57
  };
55
58
  }
59
+ function parseBool(v) {
60
+ if (!v) return false;
61
+ const s = v.toLowerCase();
62
+ return s === "1" || s === "true" || s === "yes";
63
+ }
56
64
  function getConfig() {
57
65
  const now = nowMs();
58
66
  if (g.__caConfigCache && now - g.__caConfigCache.at < CACHE_MS) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-YEUALILD.js";
3
+ } from "./chunk-QH57EOKP.js";
4
4
  import {
5
5
  ApiError
6
6
  } from "./chunk-EZYKRG4W.js";
@@ -34,16 +34,27 @@ async function forwardToAnthropic(request, path, opts) {
34
34
  if (idem) headers.set("idempotency-key", idem);
35
35
  const accept = request.headers.get("accept");
36
36
  if (accept) headers.set("accept", accept);
37
+ const isMultipart = (ct ?? "").toLowerCase().startsWith("multipart/");
37
38
  let body;
38
39
  if (request.method !== "GET" && request.method !== "HEAD") {
39
- body = opts?.body ?? await request.text();
40
+ if (opts?.body !== void 0) {
41
+ body = opts.body;
42
+ } else if (isMultipart && request.body) {
43
+ body = request.body;
44
+ } else {
45
+ body = await request.text();
46
+ }
40
47
  }
41
- const res = await fetch(url.toString(), {
48
+ const fetchInit = {
42
49
  method: request.method,
43
50
  headers,
44
51
  body,
45
52
  signal: request.signal
46
- });
53
+ };
54
+ if (body && typeof body !== "string") {
55
+ fetchInit.duplex = "half";
56
+ }
57
+ const res = await fetch(url.toString(), fetchInit);
47
58
  const HOP_BY_HOP = /* @__PURE__ */ new Set([
48
59
  "connection",
49
60
  "keep-alive",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildOpenApiDocument
3
- } from "./chunk-YJPQFLY3.js";
3
+ } from "./chunk-DHSSHDIG.js";
4
4
 
5
5
  // src/handlers/openapi.ts
6
6
  function originFromRequest(request) {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  getConfig,
6
6
  readSetting
7
- } from "./chunk-YEUALILD.js";
7
+ } from "./chunk-QH57EOKP.js";
8
8
  import {
9
9
  __commonJS
10
10
  } from "./chunk-2ESYSVXG.js";
@@ -16,7 +16,7 @@ import {
16
16
  import {
17
17
  jsonOk,
18
18
  routeWrap
19
- } from "./chunk-PFLR7INE.js";
19
+ } from "./chunk-LJL3DM2L.js";
20
20
  import {
21
21
  getDb,
22
22
  init_client
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConfig
3
- } from "./chunk-YEUALILD.js";
3
+ } from "./chunk-QH57EOKP.js";
4
4
 
5
5
  // src/backends/gemini/auth.ts
6
6
  function buildGeminiAuthEnv() {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  markStopping
3
- } from "./chunk-HIDFQDFP.js";
3
+ } from "./chunk-PNYCULIF.js";
4
4
  import {
5
5
  closeDb,
6
6
  init_client,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveContainerProvider
3
- } from "./chunk-N2RHTKW7.js";
3
+ } from "./chunk-JSLEB2ED.js";
4
4
  import {
5
5
  getEnvironmentRow,
6
6
  updateEnvironmentState
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildClaudeArgs,
3
3
  buildClaudeAuthEnv
4
- } from "./chunk-TBSWWUJS.js";
4
+ } from "./chunk-PZWVTEL2.js";
5
5
  import {
6
6
  PERMISSION_BRIDGE_DIR,
7
7
  PERMISSION_HOOK_SCRIPT_PATH,
@@ -25,7 +25,7 @@ import {
25
25
  } from "./chunk-IU457W7Q.js";
26
26
  import {
27
27
  getConfig
28
- } from "./chunk-YEUALILD.js";
28
+ } from "./chunk-QH57EOKP.js";
29
29
 
30
30
  // src/backends/claude/index.ts
31
31
  function buildTurn(input) {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  jsonOk,
6
6
  routeWrap
7
- } from "./chunk-PFLR7INE.js";
7
+ } from "./chunk-LJL3DM2L.js";
8
8
 
9
9
  // src/handlers/license.ts
10
10
  function handleGetLicense(request) {
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  jsonOk,
12
12
  routeWrap
13
- } from "./chunk-PFLR7INE.js";
13
+ } from "./chunk-LJL3DM2L.js";
14
14
  import {
15
15
  archiveTenant,
16
16
  createTenant,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  jsonOk,
3
3
  routeWrap
4
- } from "./chunk-PFLR7INE.js";
4
+ } from "./chunk-LJL3DM2L.js";
5
5
 
6
6
  // src/handlers/whoami.ts
7
7
  function handleWhoami(request) {
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  jsonOk,
7
7
  routeWrap
8
- } from "./chunk-PFLR7INE.js";
8
+ } from "./chunk-LJL3DM2L.js";
9
9
  import {
10
10
  badRequest
11
11
  } from "./chunk-EZYKRG4W.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-VIGJQU6V.js";
4
4
  import {
5
5
  getConfig
6
- } from "./chunk-YEUALILD.js";
6
+ } from "./chunk-QH57EOKP.js";
7
7
 
8
8
  // src/observability/redactor.ts
9
9
  var REDACTED = "[REDACTED]";
@@ -5,21 +5,21 @@ import {
5
5
  assertResourceTenant
6
6
  } from "./chunk-23UKWXJH.js";
7
7
  import {
8
- forwardToAnthropic
9
- } from "./chunk-YIYEPKVQ.js";
8
+ authenticateAndIntercept
9
+ } from "./chunk-PWWRWR75.js";
10
10
  import {
11
- authenticate
12
- } from "./chunk-GCMYVWZ6.js";
11
+ forwardToAnthropic
12
+ } from "./chunk-QLWA4MJ5.js";
13
13
  import {
14
14
  ensureInitialized
15
- } from "./chunk-K2ITIAVJ.js";
15
+ } from "./chunk-C4IHTLG2.js";
16
16
  import {
17
17
  getProxiedTenantId,
18
18
  isProxied
19
19
  } from "./chunk-NIOWKTIF.js";
20
20
  import {
21
21
  subscribe
22
- } from "./chunk-EOFJ2MWJ.js";
22
+ } from "./chunk-BMPB7XJH.js";
23
23
  import {
24
24
  getSession
25
25
  } from "./chunk-I5ZA45YL.js";
@@ -37,7 +37,16 @@ init_client();
37
37
  async function prepareSessionStream(request, sessionId) {
38
38
  try {
39
39
  await ensureInitialized();
40
- const auth = await authenticate(request);
40
+ const result = await authenticateAndIntercept(request);
41
+ if (result.kind === "response") {
42
+ const headers = new Headers(result.response.headers);
43
+ headers.set("X-Accel-Buffering", "no");
44
+ return new Response(result.response.body, {
45
+ status: result.response.status,
46
+ headers
47
+ });
48
+ }
49
+ const auth = result.auth;
41
50
  const tenantRow = getDb().prepare(`SELECT tenant_id FROM sessions WHERE id = ?`).get(sessionId);
42
51
  if (tenantRow) {
43
52
  assertResourceTenant(auth, tenantRow.tenant_id, `session ${sessionId} not found`);