agentbox-sdk 0.1.305 → 0.1.306

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Agent
3
- } from "../chunk-KRSY52XS.js";
3
+ } from "../chunk-7CLAJTFC.js";
4
4
  import "../chunk-ZDSHOGJ4.js";
5
5
  import {
6
6
  AGENT_RESERVED_PORTS,
@@ -1595,7 +1595,7 @@ function extractOpenCodeCostData(events) {
1595
1595
  }
1596
1596
 
1597
1597
  // src/agents/providers/claude-code.ts
1598
- var DAEMON_PROTOCOL_VERSION = "1";
1598
+ var DAEMON_PROTOCOL_VERSION = "2";
1599
1599
  var DAEMON_PORT = 43180;
1600
1600
  var DAEMON_PATH = "/tmp/agentbox/claude-code/daemon.mjs";
1601
1601
  var DAEMON_LOG_PATH = "/tmp/agentbox/claude-code/daemon.log";
@@ -1688,7 +1688,7 @@ function createClaudeCodeDaemonScript() {
1688
1688
  return `import http from "node:http";
1689
1689
  import { execSync } from "node:child_process";
1690
1690
  import { existsSync } from "node:fs";
1691
- import { query } from "@anthropic-ai/claude-agent-sdk";
1691
+ import { query, getSessionInfo } from "@anthropic-ai/claude-agent-sdk";
1692
1692
 
1693
1693
  const VERSION = ${version};
1694
1694
  const port = Number(process.argv[2] ?? "${DAEMON_PORT}");
@@ -1787,6 +1787,16 @@ async function handleStart(req, res, runId) {
1787
1787
  "x-daemon-version": VERSION,
1788
1788
  });
1789
1789
 
1790
+ // Heartbeat: write a blank NDJSON line every 15s so HTTPS proxies
1791
+ // (Modal/Daytona tunnels, intermediate LBs) don't idle-kill the
1792
+ // stream during long blocking tool calls (e.g. TaskOutput block:true).
1793
+ // The host's parseNdjsonStream skips empty lines, so this is a no-op
1794
+ // for consumers but keeps the underlying TCP stream warm.
1795
+ const heartbeat = setInterval(() => {
1796
+ if (!res.writableEnded) res.write("\\n");
1797
+ }, 15000);
1798
+ if (typeof heartbeat.unref === "function") heartbeat.unref();
1799
+
1790
1800
  const opts = { ...(options || {}) };
1791
1801
  const autoApprove = !!opts.autoApproveTools;
1792
1802
  delete opts.autoApproveTools;
@@ -1794,6 +1804,36 @@ async function handleStart(req, res, runId) {
1794
1804
  opts.pathToClaudeCodeExecutable,
1795
1805
  );
1796
1806
 
1807
+ // Resume-if-exists gate. \`claude --resume <id>\` errors hard with "No
1808
+ // conversation found with session ID" when the local session jsonl is
1809
+ // missing \u2014 most often because a prior post-task snapshot failed and the
1810
+ // sandbox state we resumed from doesn't have it. Probe the session
1811
+ // store; if the id isn't there, drop \`resume\` (and its companions) and
1812
+ // reuse the same UUID via \`sessionId\` so the host's pre-minted session
1813
+ // id stays consistent with what claude-agent-sdk actually emits.
1814
+ if (opts.resume) {
1815
+ let sessionExists = false;
1816
+ try {
1817
+ const info = await getSessionInfo(opts.resume, opts.cwd ? { dir: opts.cwd } : undefined);
1818
+ sessionExists = info !== undefined;
1819
+ } catch {
1820
+ sessionExists = false;
1821
+ }
1822
+ if (!sessionExists) {
1823
+ const orphanedId = opts.resume;
1824
+ delete opts.resume;
1825
+ delete opts.resumeSessionAt;
1826
+ delete opts.forkSession;
1827
+ opts.sessionId = orphanedId;
1828
+ res.write(
1829
+ JSON.stringify({
1830
+ _notice: "resume_session_missing",
1831
+ sessionId: orphanedId,
1832
+ }) + "\\n",
1833
+ );
1834
+ }
1835
+ }
1836
+
1797
1837
  let queryHandle;
1798
1838
  try {
1799
1839
  queryHandle = query({
@@ -1804,6 +1844,7 @@ async function handleStart(req, res, runId) {
1804
1844
  },
1805
1845
  });
1806
1846
  } catch (e) {
1847
+ clearInterval(heartbeat);
1807
1848
  res.write(JSON.stringify({ _error: String(e?.message ?? e) }) + "\\n");
1808
1849
  res.end();
1809
1850
  return;
@@ -1813,6 +1854,7 @@ async function handleStart(req, res, runId) {
1813
1854
 
1814
1855
  // Client disconnected (e.g. host process killed) \u2192 tear down.
1815
1856
  req.on("close", () => {
1857
+ clearInterval(heartbeat);
1816
1858
  if (!liveRuns.has(runId)) return;
1817
1859
  liveRuns.delete(runId);
1818
1860
  promptStream.end();
@@ -1827,6 +1869,7 @@ async function handleStart(req, res, runId) {
1827
1869
  } catch (e) {
1828
1870
  res.write(JSON.stringify({ _error: String(e?.message ?? e) }) + "\\n");
1829
1871
  } finally {
1872
+ clearInterval(heartbeat);
1830
1873
  liveRuns.delete(runId);
1831
1874
  promptStream.end();
1832
1875
  res.end();
@@ -2243,10 +2286,24 @@ var ClaudeCodeAgentAdapter = class {
2243
2286
  const rawPayloads = [];
2244
2287
  try {
2245
2288
  for await (const item of parseNdjsonStream(response.body)) {
2246
- if (item && typeof item === "object" && "_error" in item) {
2247
- throw new Error(
2248
- String(item._error ?? "daemon error")
2249
- );
2289
+ if (item && typeof item === "object") {
2290
+ const ctrl = item;
2291
+ if ("_error" in ctrl) {
2292
+ throw new Error(
2293
+ String(item._error ?? "daemon error")
2294
+ );
2295
+ }
2296
+ if ("_notice" in ctrl) {
2297
+ debugClaude("daemon notice: %o", ctrl);
2298
+ sink.emitRaw(
2299
+ toRawEvent(
2300
+ request.runId,
2301
+ ctrl,
2302
+ `daemon.${String(ctrl._notice ?? "notice")}`
2303
+ )
2304
+ );
2305
+ continue;
2306
+ }
2250
2307
  }
2251
2308
  const message = item;
2252
2309
  rawPayloads.push(message);
@@ -2357,7 +2414,11 @@ var ClaudeCodeAgentAdapter = class {
2357
2414
  Date.now() - executeStartedAt,
2358
2415
  lastTerminalReason
2359
2416
  );
2360
- sink.fail(new Error(finalText || `claude-code run failed (terminal_reason: ${lastTerminalReason})`));
2417
+ sink.fail(
2418
+ new Error(
2419
+ finalText || `claude-code run failed (terminal_reason: ${lastTerminalReason})`
2420
+ )
2421
+ );
2361
2422
  } else {
2362
2423
  debugClaude(
2363
2424
  "\u2605 run.completed (%dms since execute start) chars=%d",
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Agent
3
- } from "./chunk-KRSY52XS.js";
3
+ } from "./chunk-7CLAJTFC.js";
4
4
  import {
5
5
  ProviderLogAssembler,
6
6
  createNormalizedEvent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentbox-sdk",
3
- "version": "0.1.305",
3
+ "version": "0.1.306",
4
4
  "description": "Swappable coding agents and sandbox providers for Bun and TypeScript.",
5
5
  "license": "MIT",
6
6
  "repository": {