@agentstep/agent-sdk 0.4.27 → 0.4.29

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 (73) hide show
  1. package/dist/backends/claude/index.js +2 -2
  2. package/dist/backends/claude/tool-bridge.js +3 -1
  3. package/dist/backends/registry.js +3 -3
  4. package/dist/{chunk-HBERAFEH.js → chunk-2NAUMCWE.js} +1 -1
  5. package/dist/{chunk-WJ2BEGAZ.js → chunk-4DTL7OKD.js} +1 -1
  6. package/dist/chunk-4FDEJHH7.js +128 -0
  7. package/dist/{chunk-Q3NN46KE.js → chunk-4GC7D5GD.js} +1 -1
  8. package/dist/{chunk-DLFZAPUD.js → chunk-AE5JQORN.js} +2 -2
  9. package/dist/{chunk-4ZUORWES.js → chunk-BFXQ3IOS.js} +16 -10
  10. package/dist/{chunk-VZQP2TG2.js → chunk-DT57EZQB.js} +4 -4
  11. package/dist/{chunk-XLAHZKY6.js → chunk-EGCAA6KI.js} +1 -1
  12. package/dist/{chunk-R3NRSPRU.js → chunk-ESXH27JB.js} +1 -1
  13. package/dist/{chunk-KMBQ5U5W.js → chunk-FJAWIVSD.js} +1 -1
  14. package/dist/{chunk-EZCC3VWX.js → chunk-GQFC44YI.js} +1 -1
  15. package/dist/{chunk-R6L3HZP2.js → chunk-HGZ6R6ST.js} +1 -1
  16. package/dist/{chunk-QPI6MKAU.js → chunk-HMBJOI5F.js} +2 -2
  17. package/dist/{chunk-QI2UYVUF.js → chunk-JURAGCGR.js} +1 -1
  18. package/dist/{chunk-QAGHVCOK.js → chunk-KOGG7CSN.js} +1 -1
  19. package/dist/{chunk-BEXPMKTK.js → chunk-KZ4AECAK.js} +104 -9
  20. package/dist/{chunk-KD4GS64M.js → chunk-LLYP77OL.js} +1 -1
  21. package/dist/{chunk-VGEBUTM5.js → chunk-LMHXLYUV.js} +1 -1
  22. package/dist/{chunk-OGARYKIG.js → chunk-LYTHR3HC.js} +1 -1
  23. package/dist/{chunk-OLZ2KIXD.js → chunk-NX6SIEN6.js} +1 -1
  24. package/dist/{chunk-DMFY65GN.js → chunk-O3Z7JWR7.js} +1 -1
  25. package/dist/{chunk-SP2TOQZF.js → chunk-OA3CLTYY.js} +1 -1
  26. package/dist/{chunk-4EXGAKTK.js → chunk-OC2RYYTW.js} +2 -2
  27. package/dist/{chunk-DHROKUFE.js → chunk-OONL25NZ.js} +1 -1
  28. package/dist/{chunk-TTICVJTT.js → chunk-OTLXV4RO.js} +1 -1
  29. package/dist/{chunk-Q2GMMMR3.js → chunk-RK3QBYXO.js} +1 -1
  30. package/dist/{chunk-6VQXN6L3.js → chunk-RZKUB4JQ.js} +5 -5
  31. package/dist/{chunk-QPKMINTD.js → chunk-UIVEK3MD.js} +1 -1
  32. package/dist/{chunk-4ZL36MCY.js → chunk-W26HCKWX.js} +1 -1
  33. package/dist/{chunk-V75I7WMU.js → chunk-WHASPTF3.js} +1 -1
  34. package/dist/{chunk-U7XXWFTQ.js → chunk-XGUSWFDD.js} +1 -1
  35. package/dist/{chunk-T2IKN6LM.js → chunk-XZOBOKL6.js} +1 -1
  36. package/dist/{chunk-RKXJLXPN.js → chunk-YIVJ3JTW.js} +1 -1
  37. package/dist/{chunk-EVZABUMI.js → chunk-ZNQD65DN.js} +1 -1
  38. package/dist/containers/lifecycle.js +4 -4
  39. package/dist/handlers/agents.js +10 -10
  40. package/dist/handlers/api_keys.js +10 -10
  41. package/dist/handlers/audit.js +10 -10
  42. package/dist/handlers/batch.js +10 -10
  43. package/dist/handlers/credentials.js +11 -11
  44. package/dist/handlers/environments.js +10 -10
  45. package/dist/handlers/events.js +10 -10
  46. package/dist/handlers/files.js +10 -10
  47. package/dist/handlers/index.js +34 -34
  48. package/dist/handlers/license.js +10 -10
  49. package/dist/handlers/memory.js +10 -10
  50. package/dist/handlers/metrics.js +10 -10
  51. package/dist/handlers/models.js +10 -10
  52. package/dist/handlers/providers.js +10 -10
  53. package/dist/handlers/resources.js +10 -10
  54. package/dist/handlers/sessions.js +10 -10
  55. package/dist/handlers/settings.js +10 -10
  56. package/dist/handlers/skills-write.js +10 -10
  57. package/dist/handlers/skills.js +10 -10
  58. package/dist/handlers/stream.js +9 -9
  59. package/dist/handlers/tenants.js +10 -10
  60. package/dist/handlers/threads.js +10 -10
  61. package/dist/handlers/traces.js +10 -10
  62. package/dist/handlers/upstream_keys.js +10 -10
  63. package/dist/handlers/vaults.js +10 -10
  64. package/dist/handlers/whoami.js +10 -10
  65. package/dist/http.js +9 -9
  66. package/dist/index.js +9 -9
  67. package/dist/init.js +8 -8
  68. package/dist/sessions/driver.js +11 -7
  69. package/dist/sessions/sweeper.js +5 -5
  70. package/dist/sessions/threads.js +5 -5
  71. package/dist/shutdown.js +6 -6
  72. package/package.json +1 -1
  73. package/dist/chunk-ALVC7G6R.js +0 -187
@@ -2,14 +2,14 @@ import {
2
2
  claudeBackend,
3
3
  installPermissionHook,
4
4
  installToolBridge
5
- } from "../../chunk-6VQXN6L3.js";
5
+ } from "../../chunk-RZKUB4JQ.js";
6
6
  import {
7
7
  buildClaudeArgs,
8
8
  buildClaudeAuthEnv
9
9
  } from "../../chunk-WFIMX3HG.js";
10
10
  import "../../chunk-FVBDEOTZ.js";
11
11
  import "../../chunk-CY6AWCC6.js";
12
- import "../../chunk-ALVC7G6R.js";
12
+ import "../../chunk-4FDEJHH7.js";
13
13
  import {
14
14
  createClaudeTranslator
15
15
  } from "../../chunk-JFYE5BFI.js";
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  TOOL_BRIDGE_DIR,
3
+ TOOL_BRIDGE_MCP_CONFIG_PATH,
3
4
  TOOL_BRIDGE_PENDING_PATH,
4
5
  TOOL_BRIDGE_REQUEST_PATH,
5
6
  TOOL_BRIDGE_RESPONSE_PATH,
@@ -8,10 +9,11 @@ import {
8
9
  buildBridgeMcpConfig,
9
10
  generateBridgeScript,
10
11
  toolsToJson
11
- } from "../../chunk-ALVC7G6R.js";
12
+ } from "../../chunk-4FDEJHH7.js";
12
13
  import "../../chunk-2ESYSVXG.js";
13
14
  export {
14
15
  TOOL_BRIDGE_DIR,
16
+ TOOL_BRIDGE_MCP_CONFIG_PATH,
15
17
  TOOL_BRIDGE_PENDING_PATH,
16
18
  TOOL_BRIDGE_REQUEST_PATH,
17
19
  TOOL_BRIDGE_RESPONSE_PATH,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  listBackends,
3
3
  resolveBackend
4
- } from "../chunk-QAGHVCOK.js";
4
+ } from "../chunk-KOGG7CSN.js";
5
5
  import "../chunk-I44FSUBC.js";
6
6
  import "../chunk-T5VRE77P.js";
7
7
  import "../chunk-TY3HD5I5.js";
@@ -32,11 +32,11 @@ import "../chunk-7TSTCMII.js";
32
32
  import "../chunk-QQDSHL27.js";
33
33
  import "../chunk-IAF6VMPO.js";
34
34
  import "../chunk-OWP537VU.js";
35
- import "../chunk-6VQXN6L3.js";
35
+ import "../chunk-RZKUB4JQ.js";
36
36
  import "../chunk-WFIMX3HG.js";
37
37
  import "../chunk-FVBDEOTZ.js";
38
38
  import "../chunk-CY6AWCC6.js";
39
- import "../chunk-ALVC7G6R.js";
39
+ import "../chunk-4FDEJHH7.js";
40
40
  import "../chunk-JFYE5BFI.js";
41
41
  import "../chunk-NQX7WBA4.js";
42
42
  import "../chunk-XBHDQK4Z.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  jsonOk,
3
3
  routeWrap
4
- } from "./chunk-R3NRSPRU.js";
4
+ } from "./chunk-ESXH27JB.js";
5
5
 
6
6
  // src/handlers/whoami.ts
7
7
  function handleWhoami(request) {
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  jsonOk,
17
17
  routeWrap
18
- } from "./chunk-R3NRSPRU.js";
18
+ } from "./chunk-ESXH27JB.js";
19
19
  import {
20
20
  createApiKey,
21
21
  getApiKeyById,
@@ -0,0 +1,128 @@
1
+ // src/backends/claude/tool-bridge.ts
2
+ var TOOL_BRIDGE_DIR = "/tmp/tool-bridge";
3
+ var TOOL_BRIDGE_SCRIPT_PATH = `${TOOL_BRIDGE_DIR}/bridge.sh`;
4
+ var TOOL_BRIDGE_TOOLS_PATH = `${TOOL_BRIDGE_DIR}/tools.json`;
5
+ var TOOL_BRIDGE_REQUEST_PATH = `${TOOL_BRIDGE_DIR}/request.json`;
6
+ var TOOL_BRIDGE_RESPONSE_PATH = `${TOOL_BRIDGE_DIR}/response.json`;
7
+ var TOOL_BRIDGE_MCP_CONFIG_PATH = `${TOOL_BRIDGE_DIR}/mcp.json`;
8
+ var TOOL_BRIDGE_PENDING_PATH = `${TOOL_BRIDGE_DIR}/pending`;
9
+ function generateBridgeScript() {
10
+ return `#!/bin/bash
11
+ # Auto-generated MCP stdio server for custom tool bridge.
12
+ # Pure bash \u2014 no Node.js dependency. Instant startup on Firecracker VMs.
13
+
14
+ TOOLS_PATH="${TOOL_BRIDGE_TOOLS_PATH}"
15
+ REQUEST_PATH="${TOOL_BRIDGE_REQUEST_PATH}"
16
+ RESPONSE_PATH="${TOOL_BRIDGE_RESPONSE_PATH}"
17
+ PENDING_PATH="${TOOL_BRIDGE_PENDING_PATH}"
18
+
19
+ send_response() {
20
+ printf '%s\\n' "$1"
21
+ }
22
+
23
+ TOOLS_LIST_JSON=""
24
+ if [ -f "$TOOLS_PATH" ]; then
25
+ TOOLS_LIST_JSON=$(sed 's/input_schema/inputSchema/g' "$TOOLS_PATH")
26
+ fi
27
+
28
+ handle_request() {
29
+ local body="$1"
30
+ local method id
31
+ method=$(echo "$body" | grep -o '"method":"[^"]*"' | head -1 | cut -d'"' -f4)
32
+ id=$(echo "$body" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
33
+
34
+ case "$method" in
35
+ initialize)
36
+ send_response '{"jsonrpc":"2.0","id":'"$id"',"result":{"protocolVersion":"2025-11-25","capabilities":{"tools":{"listChanged":false}},"serverInfo":{"name":"tool-bridge","version":"1.0.0"}}}'
37
+ ;;
38
+ notifications/initialized) ;;
39
+ tools/list)
40
+ send_response '{"jsonrpc":"2.0","id":'"$id"',"result":{"tools":'"$TOOLS_LIST_JSON"'}}'
41
+ ;;
42
+ tools/call)
43
+ local tool_name tool_args
44
+ tool_name=$(echo "$body" | grep -o '"name":"[^"]*"' | tail -1 | cut -d'"' -f4)
45
+ tool_args=$(echo "$body" | grep -o '"arguments":{[^}]*}' | head -1 | sed 's/^"arguments"://')
46
+ [ -z "$tool_args" ] && tool_args="{}"
47
+
48
+ # Replay case: response.json already exists (--resume re-entry)
49
+ if [ -f "$RESPONSE_PATH" ]; then
50
+ local rdata
51
+ rdata=$(cat "$RESPONSE_PATH" | tr -d '\\n' | sed 's/\\\\/\\\\\\\\/g; s/"/\\\\"/g')
52
+ rm -f "$RESPONSE_PATH"
53
+ send_response '{"jsonrpc":"2.0","id":'"$id"',"result":{"content":[{"type":"text","text":"'"$rdata"'"}],"isError":false}}'
54
+ return
55
+ fi
56
+
57
+ # Write request and create pending sentinel
58
+ printf '{"tool_use_id":%s,"name":"%s","input":%s}' "$id" "$tool_name" "$tool_args" > "$REQUEST_PATH"
59
+ touch "$PENDING_PATH"
60
+
61
+ # Poll for response.json (200ms interval, 5min timeout)
62
+ local elapsed=0
63
+ while [ $elapsed -lt 1500 ]; do
64
+ if [ -f "$RESPONSE_PATH" ]; then
65
+ local rdata
66
+ rdata=$(cat "$RESPONSE_PATH" | tr -d '\\n' | sed 's/\\\\/\\\\\\\\/g; s/"/\\\\"/g')
67
+ rm -f "$RESPONSE_PATH" "$PENDING_PATH"
68
+ send_response '{"jsonrpc":"2.0","id":'"$id"',"result":{"content":[{"type":"text","text":"'"$rdata"'"}],"isError":false}}'
69
+ return
70
+ fi
71
+ sleep 0.2
72
+ elapsed=$((elapsed + 1))
73
+ done
74
+ # Timeout
75
+ rm -f "$PENDING_PATH"
76
+ send_response '{"jsonrpc":"2.0","id":'"$id"',"error":{"code":-32603,"message":"Timeout waiting for tool response"}}'
77
+ ;;
78
+ *)
79
+ [ -n "$id" ] && send_response '{"jsonrpc":"2.0","id":'"$id"',"error":{"code":-32601,"message":"Method not found"}}'
80
+ ;;
81
+ esac
82
+ }
83
+
84
+ # Main loop: handle both raw JSON lines and Content-Length framed messages
85
+ while IFS= read -r line; do
86
+ line=\${line%$'\\r'}
87
+ [ -z "$line" ] && continue
88
+ case "$line" in
89
+ Content-Length:*)
90
+ while IFS= read -r hdr; do hdr=\${hdr%$'\\r'}; [ -z "$hdr" ] && break; done
91
+ body=$(head -c "\${line#Content-Length: }")
92
+ handle_request "$body" ;;
93
+ "{"*) handle_request "$line" ;;
94
+ esac
95
+ done
96
+ `;
97
+ }
98
+ function buildBridgeMcpConfig(existingServers) {
99
+ return {
100
+ ...existingServers,
101
+ "tool-bridge": {
102
+ command: "bash",
103
+ args: [TOOL_BRIDGE_SCRIPT_PATH]
104
+ }
105
+ };
106
+ }
107
+ function toolsToJson(tools) {
108
+ return JSON.stringify(
109
+ tools.map((t) => ({
110
+ name: t.name,
111
+ description: t.description,
112
+ input_schema: t.input_schema
113
+ }))
114
+ );
115
+ }
116
+
117
+ export {
118
+ TOOL_BRIDGE_DIR,
119
+ TOOL_BRIDGE_SCRIPT_PATH,
120
+ TOOL_BRIDGE_TOOLS_PATH,
121
+ TOOL_BRIDGE_REQUEST_PATH,
122
+ TOOL_BRIDGE_RESPONSE_PATH,
123
+ TOOL_BRIDGE_MCP_CONFIG_PATH,
124
+ TOOL_BRIDGE_PENDING_PATH,
125
+ generateBridgeScript,
126
+ buildBridgeMcpConfig,
127
+ toolsToJson
128
+ };
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  jsonOk,
7
7
  routeWrap
8
- } from "./chunk-R3NRSPRU.js";
8
+ } from "./chunk-ESXH27JB.js";
9
9
  import {
10
10
  badRequest
11
11
  } from "./chunk-EZYKRG4W.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  loadVaultForCaller
3
- } from "./chunk-KD4GS64M.js";
3
+ } from "./chunk-LLYP77OL.js";
4
4
  import {
5
5
  jsonOk,
6
6
  routeWrap
7
- } from "./chunk-R3NRSPRU.js";
7
+ } from "./chunk-ESXH27JB.js";
8
8
  import {
9
9
  createCredential,
10
10
  deleteCredential,
@@ -24,7 +24,7 @@ import {
24
24
  import {
25
25
  jsonOk,
26
26
  routeWrap
27
- } from "./chunk-R3NRSPRU.js";
27
+ } from "./chunk-ESXH27JB.js";
28
28
  import {
29
29
  forwardToAnthropic
30
30
  } from "./chunk-T45NOW43.js";
@@ -34,7 +34,7 @@ import {
34
34
  import {
35
35
  runTurn,
36
36
  writePermissionResponse
37
- } from "./chunk-BEXPMKTK.js";
37
+ } from "./chunk-KZ4AECAK.js";
38
38
  import {
39
39
  getProxiedTenantId,
40
40
  isProxied
@@ -544,16 +544,22 @@ function handlePostEvents(request, sessionId) {
544
544
  processedAt: nowMs()
545
545
  });
546
546
  rows.push(row);
547
- const inp = {
548
- kind: "tool_result",
549
- eventId: row.id,
550
- custom_tool_use_id: event.custom_tool_use_id,
551
- content: event.content
552
- };
553
547
  const currentStatus = getSessionRow(sessionId)?.status ?? "idle";
554
- if (currentStatus === "running" || sawInterrupt) {
555
- pushPendingUserInput({ sessionId, input: inp });
548
+ if (currentStatus === "running") {
549
+ const { writeToolBridgeResponse } = await import("./sessions/driver.js");
550
+ void writeToolBridgeResponse(
551
+ sessionId,
552
+ event.content
553
+ ).catch((err) => {
554
+ console.warn(`[events] writeToolBridgeResponse failed:`, err);
555
+ });
556
556
  } else {
557
+ const inp = {
558
+ kind: "tool_result",
559
+ eventId: row.id,
560
+ custom_tool_use_id: event.custom_tool_use_id,
561
+ content: event.content
562
+ };
557
563
  pendingForTurn.push(inp);
558
564
  }
559
565
  continue;
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-AQXCXWAZ.js";
4
4
  import {
5
5
  runTurn
6
- } from "./chunk-BEXPMKTK.js";
6
+ } from "./chunk-KZ4AECAK.js";
7
7
  import {
8
8
  installOtlpExporter
9
9
  } from "./chunk-Y2KDIPCT.js";
@@ -19,14 +19,14 @@ import {
19
19
  } from "./chunk-3MQ2FWXS.js";
20
20
  import {
21
21
  installShutdownHandlers
22
- } from "./chunk-OLZ2KIXD.js";
22
+ } from "./chunk-NX6SIEN6.js";
23
23
  import {
24
24
  runSweep
25
- } from "./chunk-KMBQ5U5W.js";
25
+ } from "./chunk-FJAWIVSD.js";
26
26
  import {
27
27
  reconcileDockerOrphanSandboxes,
28
28
  reconcileOrphanSandboxes
29
- } from "./chunk-U7XXWFTQ.js";
29
+ } from "./chunk-XGUSWFDD.js";
30
30
  import {
31
31
  appendEvent,
32
32
  installPayloadRedactor
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  jsonOk,
10
10
  routeWrap
11
- } from "./chunk-R3NRSPRU.js";
11
+ } from "./chunk-ESXH27JB.js";
12
12
  import {
13
13
  snapshotApiMetrics
14
14
  } from "./chunk-D2XITRN6.js";
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-HVUWXUUI.js";
11
11
  import {
12
12
  ensureInitialized
13
- } from "./chunk-VZQP2TG2.js";
13
+ } from "./chunk-DT57EZQB.js";
14
14
  import {
15
15
  captureException
16
16
  } from "./chunk-3MQ2FWXS.js";
@@ -6,7 +6,7 @@ import {
6
6
  reconcileDockerOrphanSandboxes,
7
7
  reconcileOrphanSandboxes,
8
8
  releaseSession
9
- } from "./chunk-U7XXWFTQ.js";
9
+ } from "./chunk-XGUSWFDD.js";
10
10
  import {
11
11
  appendEvent,
12
12
  dropEmitter
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  jsonOk,
7
7
  routeWrap
8
- } from "./chunk-R3NRSPRU.js";
8
+ } from "./chunk-ESXH27JB.js";
9
9
  import {
10
10
  getSession,
11
11
  listSessions
@@ -16,7 +16,7 @@ import {
16
16
  import {
17
17
  jsonOk,
18
18
  routeWrap
19
- } from "./chunk-R3NRSPRU.js";
19
+ } from "./chunk-ESXH27JB.js";
20
20
  import {
21
21
  getDb,
22
22
  init_client
@@ -18,7 +18,7 @@ import {
18
18
  import {
19
19
  jsonOk,
20
20
  routeWrap
21
- } from "./chunk-R3NRSPRU.js";
21
+ } from "./chunk-ESXH27JB.js";
22
22
  import {
23
23
  forwardToAnthropic
24
24
  } from "./chunk-T45NOW43.js";
@@ -38,7 +38,7 @@ import {
38
38
  } from "./chunk-LAWTTG2E.js";
39
39
  import {
40
40
  releaseSession
41
- } from "./chunk-U7XXWFTQ.js";
41
+ } from "./chunk-XGUSWFDD.js";
42
42
  import {
43
43
  appendEvent,
44
44
  dropEmitter
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-T45NOW43.js";
13
13
  import {
14
14
  ensureInitialized
15
- } from "./chunk-VZQP2TG2.js";
15
+ } from "./chunk-DT57EZQB.js";
16
16
  import {
17
17
  getProxiedTenantId,
18
18
  isProxied
@@ -15,7 +15,7 @@ import {
15
15
  } from "./chunk-5D5P37FY.js";
16
16
  import {
17
17
  claudeBackend
18
- } from "./chunk-6VQXN6L3.js";
18
+ } from "./chunk-RZKUB4JQ.js";
19
19
 
20
20
  // src/backends/registry.ts
21
21
  var BACKENDS = {
@@ -30,7 +30,7 @@ import {
30
30
  installSkills,
31
31
  provisionResources,
32
32
  wrapProviderWithSecrets
33
- } from "./chunk-U7XXWFTQ.js";
33
+ } from "./chunk-XGUSWFDD.js";
34
34
  import {
35
35
  BLOCKED_ENV_KEYS,
36
36
  resolveVaultSecrets
@@ -68,12 +68,17 @@ import {
68
68
  } from "./chunk-JEI7I3EH.js";
69
69
  import {
70
70
  resolveBackend
71
- } from "./chunk-QAGHVCOK.js";
71
+ } from "./chunk-KOGG7CSN.js";
72
72
  import {
73
73
  PERMISSION_BRIDGE_PENDING_PATH,
74
74
  PERMISSION_BRIDGE_REQUEST_PATH,
75
75
  PERMISSION_BRIDGE_RESPONSE_PATH
76
76
  } from "./chunk-CY6AWCC6.js";
77
+ import {
78
+ TOOL_BRIDGE_PENDING_PATH,
79
+ TOOL_BRIDGE_REQUEST_PATH,
80
+ TOOL_BRIDGE_RESPONSE_PATH
81
+ } from "./chunk-4FDEJHH7.js";
77
82
  import {
78
83
  resolveToolset
79
84
  } from "./chunk-XBHDQK4Z.js";
@@ -272,6 +277,9 @@ async function runTurn(sessionId, inputs, _depth = 0, parentTrace) {
272
277
  if (freshSession?.resources && freshSession.resources.length > 0) {
273
278
  turnBuild.env.RESOURCES_DIR = "/tmp/resources";
274
279
  }
280
+ if (agent.engine === "claude" && !turnBuild.env.MCP_TIMEOUT) {
281
+ turnBuild.env.MCP_TIMEOUT = "30000";
282
+ }
275
283
  const MCP_KEY_RE = /^MCP_(AUTH|HEADER)_/i;
276
284
  for (const entry of vaultEntries) {
277
285
  if (!BLOCKED_ENV_KEYS.has(entry.key) && !MCP_KEY_RE.test(entry.key)) {
@@ -350,21 +358,21 @@ ${turnBuild.stdin}`;
350
358
  turnSpanId: trace.span_id
351
359
  });
352
360
  if (agent.engine === "claude" && toolResults.length > 0) {
353
- const { TOOL_BRIDGE_RESPONSE_PATH, TOOL_BRIDGE_PENDING_PATH } = await import("./backends/claude/tool-bridge.js");
361
+ const { TOOL_BRIDGE_RESPONSE_PATH: TOOL_BRIDGE_RESPONSE_PATH2, TOOL_BRIDGE_PENDING_PATH: TOOL_BRIDGE_PENDING_PATH2 } = await import("./backends/claude/tool-bridge.js");
354
362
  const sandboxName2 = getSessionRow(sessionId)?.sandbox_name;
355
363
  if (sandboxName2) {
356
364
  for (const r of toolResults) {
357
365
  const responseJson = JSON.stringify({ content: r.content });
358
366
  await provider.exec(
359
367
  sandboxName2,
360
- ["bash", "-c", `cat > ${TOOL_BRIDGE_RESPONSE_PATH}`],
368
+ ["bash", "-c", `cat > ${TOOL_BRIDGE_RESPONSE_PATH2}`],
361
369
  { stdin: responseJson, secrets }
362
370
  ).catch((err) => {
363
371
  console.warn(`[driver] failed to write tool bridge response:`, err);
364
372
  });
365
373
  await provider.exec(
366
374
  sandboxName2,
367
- ["rm", "-f", TOOL_BRIDGE_PENDING_PATH],
375
+ ["rm", "-f", TOOL_BRIDGE_PENDING_PATH2],
368
376
  { secrets }
369
377
  ).catch(() => {
370
378
  });
@@ -409,6 +417,17 @@ ${turnBuild.stdin}`;
409
417
  );
410
418
  }, 2e3);
411
419
  }
420
+ const customToolNames = resolveToolset(agent.tools).customToolNames;
421
+ let toolBridgePollTimer = null;
422
+ if (agent.engine === "claude" && customToolNames.size > 0) {
423
+ toolBridgePollTimer = setInterval(() => {
424
+ void checkToolBridgeSentinel(sessionId, sandboxName, provider, secrets, trace).catch(
425
+ (err) => {
426
+ console.warn(`[driver] tool bridge sentinel check failed:`, err);
427
+ }
428
+ );
429
+ }, 1e3);
430
+ }
412
431
  try {
413
432
  const reader = exec.stdout.getReader();
414
433
  const decoder = new TextDecoder();
@@ -504,6 +523,8 @@ ${turnBuild.stdin}`;
504
523
  }
505
524
  } finally {
506
525
  if (permissionPollTimer) clearInterval(permissionPollTimer);
526
+ if (toolBridgePollTimer) clearInterval(toolBridgePollTimer);
527
+ getPendingToolBridgeCalls().delete(sessionId);
507
528
  runtime.inFlightRuns.delete(sessionId);
508
529
  }
509
530
  if (aborted) {
@@ -563,7 +584,7 @@ ${turnBuild.stdin}`;
563
584
  );
564
585
  emit("session.status_idle", { stop_reason: formatStopReason("custom_tool_call", customToolEventIds) }, { at: now });
565
586
  updateSessionStatus(sessionId, "idle", "custom_tool_call");
566
- const { TOOL_BRIDGE_RESPONSE_PATH, TOOL_BRIDGE_PENDING_PATH } = await import("./backends/claude/tool-bridge.js");
587
+ const { TOOL_BRIDGE_RESPONSE_PATH: TOOL_BRIDGE_RESPONSE_PATH2, TOOL_BRIDGE_PENDING_PATH: TOOL_BRIDGE_PENDING_PATH2 } = await import("./backends/claude/tool-bridge.js");
567
588
  const sprName = getSessionRow(sessionId)?.sandbox_name;
568
589
  if (sprName) {
569
590
  const responseJson = JSON.stringify({ content: [{ type: "text", text: serverToolResult.text }] });
@@ -572,14 +593,14 @@ ${turnBuild.stdin}`;
572
593
  const reentrySecrets = getBySession(sessionId)?.vaultSecrets;
573
594
  await providerForReentry.exec(
574
595
  sprName,
575
- ["bash", "-c", `cat > ${TOOL_BRIDGE_RESPONSE_PATH}`],
596
+ ["bash", "-c", `cat > ${TOOL_BRIDGE_RESPONSE_PATH2}`],
576
597
  { stdin: responseJson, secrets: reentrySecrets }
577
598
  ).catch((err) => {
578
599
  console.warn(`[driver] failed to write spawn_agent response:`, err);
579
600
  });
580
601
  await providerForReentry.exec(
581
602
  sprName,
582
- ["rm", "-f", TOOL_BRIDGE_PENDING_PATH],
603
+ ["rm", "-f", TOOL_BRIDGE_PENDING_PATH2],
583
604
  { secrets: reentrySecrets }
584
605
  ).catch(() => {
585
606
  });
@@ -772,8 +793,82 @@ async function writePermissionResponse(sessionId, result, denyMessage) {
772
793
  }
773
794
  getPendingConfirmations().delete(sessionId);
774
795
  }
796
+ var pendingToolBridgeCalls = /* @__PURE__ */ new Set();
797
+ function getPendingToolBridgeCalls() {
798
+ return pendingToolBridgeCalls;
799
+ }
800
+ async function checkToolBridgeSentinel(sessionId, sandboxName, provider, secrets, trace) {
801
+ if (pendingToolBridgeCalls.has(sessionId)) return;
802
+ try {
803
+ const result = await provider.exec(
804
+ sandboxName,
805
+ ["test", "-f", TOOL_BRIDGE_PENDING_PATH],
806
+ { secrets }
807
+ );
808
+ if (result.exit_code !== 0) return;
809
+ } catch {
810
+ return;
811
+ }
812
+ let request;
813
+ try {
814
+ const result = await provider.exec(
815
+ sandboxName,
816
+ ["cat", TOOL_BRIDGE_REQUEST_PATH],
817
+ { secrets }
818
+ );
819
+ const clean = result.stdout.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "");
820
+ request = JSON.parse(clean);
821
+ } catch (err) {
822
+ console.warn(`[driver] failed to read tool bridge request for ${sessionId}:`, err);
823
+ return;
824
+ }
825
+ pendingToolBridgeCalls.add(sessionId);
826
+ console.log(`[driver] ${sessionId} custom tool call: ${request.name} (${request.tool_use_id})`);
827
+ appendEvent(sessionId, {
828
+ type: "agent.custom_tool_use",
829
+ payload: {
830
+ tool_use_id: request.tool_use_id ?? "",
831
+ name: request.name ?? "unknown",
832
+ input: request.input ?? {}
833
+ },
834
+ origin: "server",
835
+ processedAt: nowMs(),
836
+ traceId: trace.trace_id,
837
+ spanId: trace.span_id,
838
+ parentSpanId: trace.parent_span_id
839
+ });
840
+ }
841
+ async function writeToolBridgeResponse(sessionId, content) {
842
+ const row = getSessionRow(sessionId);
843
+ if (!row?.sandbox_name) {
844
+ console.warn(`[driver] no sandbox for session ${sessionId}, cannot write tool bridge response`);
845
+ return;
846
+ }
847
+ const env = getEnvironment(row.environment_id);
848
+ const provider = await resolveContainerProvider(env?.config?.provider);
849
+ const bridgeSecrets = getBySession(sessionId)?.vaultSecrets;
850
+ const response = JSON.stringify({ content });
851
+ try {
852
+ await provider.exec(
853
+ row.sandbox_name,
854
+ ["sh", "-c", `cat > ${TOOL_BRIDGE_RESPONSE_PATH}`],
855
+ { stdin: response, secrets: bridgeSecrets }
856
+ );
857
+ await provider.exec(
858
+ row.sandbox_name,
859
+ ["rm", "-f", TOOL_BRIDGE_PENDING_PATH],
860
+ { secrets: bridgeSecrets }
861
+ );
862
+ console.log(`[driver] ${sessionId} tool bridge response written`);
863
+ } catch (err) {
864
+ console.warn(`[driver] failed to write tool bridge response for ${sessionId}:`, err);
865
+ }
866
+ pendingToolBridgeCalls.delete(sessionId);
867
+ }
775
868
 
776
869
  export {
777
870
  runTurn,
778
- writePermissionResponse
871
+ writePermissionResponse,
872
+ getPendingToolBridgeCalls,
873
+ writeToolBridgeResponse
779
874
  };
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  jsonOk,
8
8
  routeWrap
9
- } from "./chunk-R3NRSPRU.js";
9
+ } from "./chunk-ESXH27JB.js";
10
10
  import {
11
11
  createVault,
12
12
  deleteEntry,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  jsonOk,
3
3
  routeWrap
4
- } from "./chunk-R3NRSPRU.js";
4
+ } from "./chunk-ESXH27JB.js";
5
5
  import {
6
6
  readSetting,
7
7
  writeSetting
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  routeWrap
3
- } from "./chunk-R3NRSPRU.js";
3
+ } from "./chunk-ESXH27JB.js";
4
4
  import {
5
5
  ApiError
6
6
  } from "./chunk-EZYKRG4W.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  markStopping
3
- } from "./chunk-KMBQ5U5W.js";
3
+ } from "./chunk-FJAWIVSD.js";
4
4
  import {
5
5
  closeDb,
6
6
  init_client,
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  jsonOk,
10
10
  routeWrap
11
- } from "./chunk-R3NRSPRU.js";
11
+ } from "./chunk-ESXH27JB.js";
12
12
  import {
13
13
  badRequest
14
14
  } from "./chunk-EZYKRG4W.js";
@@ -18,7 +18,7 @@ import {
18
18
  import {
19
19
  jsonOk,
20
20
  routeWrap
21
- } from "./chunk-R3NRSPRU.js";
21
+ } from "./chunk-ESXH27JB.js";
22
22
  import {
23
23
  getDb,
24
24
  init_client
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  jsonOk,
8
8
  routeWrap
9
- } from "./chunk-R3NRSPRU.js";
9
+ } from "./chunk-ESXH27JB.js";
10
10
  import {
11
11
  forwardToAnthropic,
12
12
  validateAnthropicProxy
@@ -26,7 +26,7 @@ import {
26
26
  } from "./chunk-JEI7I3EH.js";
27
27
  import {
28
28
  resolveBackend
29
- } from "./chunk-QAGHVCOK.js";
29
+ } from "./chunk-KOGG7CSN.js";
30
30
  import {
31
31
  getDb,
32
32
  init_client