@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.
- package/dist/auth/middleware.js +6 -1
- package/dist/auth/passthrough.js +9 -0
- package/dist/backends/claude/args.js +2 -2
- package/dist/backends/claude/index.js +3 -3
- package/dist/backends/codex/auth.js +2 -2
- package/dist/backends/codex/index.js +5 -5
- package/dist/backends/factory/auth.js +2 -2
- package/dist/backends/factory/index.js +9 -9
- package/dist/backends/gemini/auth.js +2 -2
- package/dist/backends/gemini/index.js +6 -6
- package/dist/backends/opencode/auth.js +2 -2
- package/dist/backends/opencode/index.js +3 -3
- package/dist/backends/pi/auth.js +2 -2
- package/dist/backends/pi/index.js +6 -6
- package/dist/backends/registry.js +18 -18
- package/dist/{chunk-GSODOHNB.js → chunk-3LG7DRJL.js} +1 -1
- package/dist/{chunk-HOPCVGWL.js → chunk-3PLJHZFD.js} +1 -1
- package/dist/{chunk-UVUSSZ74.js → chunk-5XF65N7J.js} +1 -1
- package/dist/{chunk-SS2EEKNM.js → chunk-66CJ6LMV.js} +1 -1
- package/dist/{chunk-MFEOQ26S.js → chunk-6RRYNQXP.js} +2 -2
- package/dist/{chunk-7GPKEOAO.js → chunk-7CADMELE.js} +8 -7
- package/dist/{chunk-CDK25PRU.js → chunk-ACKMNK3C.js} +5 -5
- package/dist/{chunk-QICG4KW4.js → chunk-BYWW5GFO.js} +1 -1
- package/dist/{chunk-K2ITIAVJ.js → chunk-C4IHTLG2.js} +13 -13
- package/dist/{chunk-YJPQFLY3.js → chunk-DHSSHDIG.js} +3 -2
- package/dist/{chunk-FVFMYO5W.js → chunk-ECRLACEF.js} +2 -2
- package/dist/{chunk-6QQKTF55.js → chunk-EUUDZGUE.js} +6 -6
- package/dist/{chunk-PCKFMALU.js → chunk-FB4OSWM2.js} +1 -1
- package/dist/{chunk-B47IDF63.js → chunk-FCCWKCGQ.js} +1 -1
- package/dist/{chunk-PTGANYUM.js → chunk-FCULDJQO.js} +1 -1
- package/dist/{chunk-HE7EOIPA.js → chunk-GJBKDPQD.js} +1 -1
- package/dist/{chunk-X37MWWUA.js → chunk-HECQRMDR.js} +1 -1
- package/dist/{chunk-R7PAZ5OA.js → chunk-HJGUG7IH.js} +20 -20
- package/dist/{chunk-LDKZ2SMC.js → chunk-HKAW5ATE.js} +45 -45
- package/dist/{chunk-374KGHBM.js → chunk-HWWCVD2R.js} +4 -4
- package/dist/{chunk-MEEY7BYC.js → chunk-IHMQQ43E.js} +1 -1
- package/dist/{chunk-42O6EBUN.js → chunk-JNQLE5D7.js} +2 -2
- package/dist/{chunk-UF25F3MH.js → chunk-JOAEFGXZ.js} +13 -13
- package/dist/{chunk-F7DOI3B5.js → chunk-K62YRMVY.js} +7 -7
- package/dist/{chunk-NCUIEBQY.js → chunk-L4T7KCQ2.js} +1 -1
- package/dist/{chunk-EDRLRJNT.js → chunk-LJF4GWPJ.js} +1 -1
- package/dist/{chunk-PFLR7INE.js → chunk-LJL3DM2L.js} +9 -4
- package/dist/{chunk-24NL6GPL.js → chunk-LRPU2HS5.js} +1 -1
- package/dist/{chunk-7OAMTB47.js → chunk-M4CTE7EH.js} +1 -1
- package/dist/{chunk-V7WEALLX.js → chunk-MA7IO6RU.js} +1 -1
- package/dist/{chunk-6NZPNYHA.js → chunk-MD4BZGMS.js} +2 -2
- package/dist/{chunk-G37JVAOI.js → chunk-NK2RCTFI.js} +4 -4
- package/dist/{chunk-SNZ4PDVT.js → chunk-OFLYKESG.js} +7 -7
- package/dist/{chunk-HIDFQDFP.js → chunk-PNYCULIF.js} +3 -3
- package/dist/{chunk-GCMYVWZ6.js → chunk-PWWRWR75.js} +41 -2
- package/dist/{chunk-TBSWWUJS.js → chunk-PZWVTEL2.js} +1 -1
- package/dist/{chunk-MRJMXGCG.js → chunk-QDOCVDWJ.js} +2 -2
- package/dist/{chunk-SHKBQQ7W.js → chunk-QFUJDBET.js} +6 -6
- package/dist/{chunk-YEUALILD.js → chunk-QH57EOKP.js} +9 -1
- package/dist/{chunk-YIYEPKVQ.js → chunk-QLWA4MJ5.js} +15 -4
- package/dist/{chunk-LUQP36Y3.js → chunk-QOJMXK4S.js} +1 -1
- package/dist/{chunk-M5QX5E5Z.js → chunk-R45W644X.js} +1 -1
- package/dist/{chunk-4MHPOB7A.js → chunk-RZMR6H5Y.js} +1 -1
- package/dist/{chunk-TJA3RHWR.js → chunk-RZXRMPF4.js} +1 -1
- package/dist/{chunk-R6X47I23.js → chunk-S6AM7WVH.js} +1 -1
- package/dist/{chunk-MOLWE2ZY.js → chunk-SDLNBA53.js} +1 -1
- package/dist/{chunk-A7MX6RSQ.js → chunk-SIKTYKVO.js} +2 -2
- package/dist/{chunk-GGYTAWW6.js → chunk-SMKHXHLP.js} +1 -1
- package/dist/{chunk-GAFFXICQ.js → chunk-TKV7CFAM.js} +1 -1
- package/dist/{chunk-QSYXHYQU.js → chunk-TOKLTGSO.js} +1 -1
- package/dist/{chunk-CSNIN5YZ.js → chunk-TPAHUFSM.js} +1 -1
- package/dist/{chunk-F6M4RLDQ.js → chunk-TWPTR2C2.js} +1 -1
- package/dist/{chunk-B6LPLXPB.js → chunk-U6GNZJGO.js} +16 -7
- package/dist/{chunk-HR5YA24J.js → chunk-UJDAT42X.js} +7 -7
- package/dist/{chunk-Q3CV35V6.js → chunk-UYNE3WPU.js} +1 -1
- package/dist/{chunk-GR4QPRB7.js → chunk-VS7AMAMU.js} +4 -4
- package/dist/{chunk-GHDY4DVK.js → chunk-W5KXLYJH.js} +12 -12
- package/dist/chunk-W6WKXFHN.js +39 -0
- package/dist/{chunk-PGSOOOB4.js → chunk-WWYVMGRP.js} +3 -3
- package/dist/{chunk-IEG5LIX7.js → chunk-XPKY3Z54.js} +1 -1
- package/dist/{chunk-M674W5NT.js → chunk-XQA62XTJ.js} +1 -1
- package/dist/{chunk-J4TYHQQG.js → chunk-ZQGJKPPY.js} +3 -1
- package/dist/config/index.js +1 -1
- package/dist/containers/client.js +2 -2
- package/dist/containers/exec.js +2 -2
- package/dist/containers/lifecycle.js +24 -24
- package/dist/containers/setup.js +2 -2
- package/dist/db/credentials.js +1 -1
- package/dist/handlers/agents.js +39 -38
- package/dist/handlers/api_keys.js +39 -37
- package/dist/handlers/audit.js +39 -37
- package/dist/handlers/batch.js +39 -37
- package/dist/handlers/credentials.js +40 -38
- package/dist/handlers/environments.js +40 -39
- package/dist/handlers/events.js +41 -40
- package/dist/handlers/files.js +39 -37
- package/dist/handlers/index.js +97 -96
- package/dist/handlers/license.js +39 -37
- package/dist/handlers/memory.js +39 -37
- package/dist/handlers/metrics.js +39 -37
- package/dist/handlers/models.js +40 -38
- package/dist/handlers/openapi.js +2 -2
- package/dist/handlers/providers.js +39 -37
- package/dist/handlers/resources.js +39 -37
- package/dist/handlers/sessions.js +40 -39
- package/dist/handlers/settings.js +39 -37
- package/dist/handlers/skills-write.js +39 -37
- package/dist/handlers/skills.js +40 -38
- package/dist/handlers/stream.js +38 -37
- package/dist/handlers/tenants.js +39 -37
- package/dist/handlers/threads.js +39 -37
- package/dist/handlers/traces.js +39 -37
- package/dist/handlers/ui.js +1 -1
- package/dist/handlers/upstream_keys.js +40 -38
- package/dist/handlers/vaults.js +39 -37
- package/dist/handlers/whoami.js +39 -37
- package/dist/http.js +38 -36
- package/dist/index.js +57 -54
- package/dist/init.js +34 -34
- package/dist/lib/model-registry.js +2 -2
- package/dist/lib/skills-cache.js +2 -2
- package/dist/observability/otlp.js +4 -4
- package/dist/observability/redactor.js +2 -2
- package/dist/openapi/spec.js +1 -1
- package/dist/providers/fly.js +1 -1
- package/dist/providers/modal.js +1 -1
- package/dist/providers/registry.js +1 -1
- package/dist/providers/sprites.js +3 -3
- package/dist/providers/upstream-keys.js +4 -4
- package/dist/providers/vercel.js +1 -1
- package/dist/proxy/forward.js +2 -2
- package/dist/queue/index.js +2 -2
- package/dist/sessions/bus.js +2 -2
- package/dist/sessions/driver.js +28 -28
- package/dist/sessions/grader.js +1 -1
- package/dist/sessions/secrets.js +2 -2
- package/dist/sessions/sweeper.js +25 -25
- package/dist/sessions/threads.js +32 -32
- package/dist/shutdown.js +26 -26
- package/dist/sync/file-sync.js +7 -7
- package/package.json +1 -1
- package/dist/{chunk-EOFJ2MWJ.js → chunk-BMPB7XJH.js} +3 -3
- /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-
|
|
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";
|
|
@@ -6,7 +6,16 @@ import {
|
|
|
6
6
|
} from "./chunk-RMZRSYIJ.js";
|
|
7
7
|
import {
|
|
8
8
|
appendEvent
|
|
9
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
17
|
+
} from "./chunk-SDLNBA53.js";
|
|
21
18
|
import {
|
|
22
19
|
jsonOk,
|
|
23
20
|
routeWrap
|
|
24
|
-
} from "./chunk-
|
|
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-
|
|
41
|
+
} from "./chunk-JOAEFGXZ.js";
|
|
42
42
|
import {
|
|
43
43
|
appendEvent,
|
|
44
44
|
dropEmitter
|
|
45
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-BMPB7XJH.js";
|
|
46
46
|
import {
|
|
47
47
|
archiveSession,
|
|
48
48
|
createSession,
|
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
recordApiRequest
|
|
4
4
|
} from "./chunk-D2XITRN6.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
} from "./chunk-
|
|
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-
|
|
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
|
|
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(
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
jsonOk,
|
|
3
3
|
routeWrap
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LJL3DM2L.js";
|
|
5
5
|
import {
|
|
6
6
|
readSetting,
|
|
7
7
|
writeSetting
|
|
8
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
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-
|
|
9
|
+
} from "./chunk-JOAEFGXZ.js";
|
|
10
10
|
import {
|
|
11
11
|
appendEvent,
|
|
12
12
|
dropEmitter
|
|
13
|
-
} from "./chunk-
|
|
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-
|
|
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
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SUPPORTED_PROVIDERS
|
|
3
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
3
|
+
} from "./chunk-VS7AMAMU.js";
|
|
4
4
|
import {
|
|
5
5
|
opencodeBackend
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-GJBKDPQD.js";
|
|
7
7
|
import {
|
|
8
8
|
geminiBackend
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-HWWCVD2R.js";
|
|
10
10
|
import {
|
|
11
11
|
codexBackend
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-NK2RCTFI.js";
|
|
13
13
|
import {
|
|
14
14
|
factoryBackend
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-UJDAT42X.js";
|
|
16
16
|
import {
|
|
17
17
|
claudeBackend
|
|
18
|
-
} from "./chunk-
|
|
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-
|
|
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
|
-
|
|
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
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildClaudeArgs,
|
|
3
3
|
buildClaudeAuthEnv
|
|
4
|
-
} from "./chunk-
|
|
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-
|
|
28
|
+
} from "./chunk-QH57EOKP.js";
|
|
29
29
|
|
|
30
30
|
// src/backends/claude/index.ts
|
|
31
31
|
function buildTurn(input) {
|
|
@@ -5,21 +5,21 @@ import {
|
|
|
5
5
|
assertResourceTenant
|
|
6
6
|
} from "./chunk-23UKWXJH.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
} from "./chunk-
|
|
8
|
+
authenticateAndIntercept
|
|
9
|
+
} from "./chunk-PWWRWR75.js";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
11
|
+
forwardToAnthropic
|
|
12
|
+
} from "./chunk-QLWA4MJ5.js";
|
|
13
13
|
import {
|
|
14
14
|
ensureInitialized
|
|
15
|
-
} from "./chunk-
|
|
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-
|
|
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
|
|
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`);
|