@slock-ai/daemon 0.53.1-alpha.0 → 0.53.1-alpha.2

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.
@@ -1376,7 +1376,14 @@ function allocatePort() {
1376
1376
  function ensureServer(port) {
1377
1377
  if (servers.has(port)) return;
1378
1378
  const server = http.createServer((req, res) => {
1379
- void handleProxyRequest(req, res);
1379
+ void handleProxyRequest(req, res).catch((err) => {
1380
+ logger.error(`[Agent Credential Proxy] unhandled local proxy error: ${err.message}`);
1381
+ writeProxyFailureResponse(res, {
1382
+ error: "failed to proxy local agent request",
1383
+ code: "agent_proxy_failed",
1384
+ detail: truncateProxyErrorMessage(err.message)
1385
+ });
1386
+ });
1380
1387
  });
1381
1388
  server.on("error", (err) => {
1382
1389
  logger.warn(`[Agent Credential Proxy] local proxy on port ${port} failed: ${err.message}`);
@@ -1404,6 +1411,7 @@ async function handleProxyRequest(req, res) {
1404
1411
  }
1405
1412
  const method = req.method ?? "GET";
1406
1413
  let target;
1414
+ let upstreamStatus = null;
1407
1415
  try {
1408
1416
  target = new URL2(req.url ?? "/", registration.serverUrl);
1409
1417
  const headers = new Headers();
@@ -1453,6 +1461,7 @@ async function handleProxyRequest(req, res) {
1453
1461
  // Required by undici when forwarding a Node stream.
1454
1462
  duplex: body ? "half" : void 0
1455
1463
  });
1464
+ upstreamStatus = upstream.status;
1456
1465
  if (shouldBufferJsonResponse(upstream, target.pathname, registration)) {
1457
1466
  const responseText = await upstream.text();
1458
1467
  consumeVisibleResponse(registration, target, sendTarget, responseText);
@@ -1476,26 +1485,45 @@ async function handleProxyRequest(req, res) {
1476
1485
  res.end();
1477
1486
  }
1478
1487
  } catch (err) {
1479
- const failure = proxyFailureForError(method, target, err);
1488
+ const failure = proxyFailureForError(method, target, res, upstreamStatus, err);
1480
1489
  logger.warn(
1481
- `[Agent Credential Proxy] request failed (agent=${registration.agentId}, launch=${registration.launchId ?? "none"}, method=${failure.method}, path=${failure.pathname}, query_keys=${failure.queryKeys.join(",") || "none"}): ${failure.errorName}: ${failure.errorMessage}`
1490
+ `[Agent Credential Proxy] request failed (agent=${registration.agentId}, launch=${registration.launchId ?? "none"}, method=${failure.method}, path=${failure.pathname}, query_keys=${failure.queryKeys.join(",") || "none"}): ${failure.errorClass}: ${failure.errorMessage}`
1482
1491
  );
1483
1492
  registration.inboxCoordinator?.recordProxyFailure?.(failure);
1484
- res.writeHead(502, { "content-type": "application/json" });
1485
- res.end(JSON.stringify({
1493
+ writeProxyFailureResponse(res, {
1486
1494
  error: "failed to proxy local agent request",
1487
1495
  code: "agent_proxy_failed",
1488
1496
  detail: failure.errorMessage
1489
- }));
1497
+ });
1498
+ }
1499
+ }
1500
+ function writeProxyFailureResponse(res, body) {
1501
+ if (res.destroyed || res.writableEnded) return;
1502
+ if (proxyResponseStarted(res)) {
1503
+ try {
1504
+ res.end();
1505
+ } catch {
1506
+ }
1507
+ return;
1508
+ }
1509
+ try {
1510
+ res.writeHead(502, { "content-type": "application/json" });
1511
+ res.end(JSON.stringify(body));
1512
+ } catch {
1490
1513
  }
1491
1514
  }
1492
- function proxyFailureForError(method, target, err) {
1515
+ function proxyResponseStarted(res) {
1516
+ return res.headersSent || res.writableEnded;
1517
+ }
1518
+ function proxyFailureForError(method, target, res, upstreamStatus, err) {
1493
1519
  const queryKeys = target ? [.../* @__PURE__ */ new Set([...target.searchParams.keys()])].sort() : [];
1494
1520
  return {
1495
1521
  method,
1496
1522
  pathname: target?.pathname ?? "unknown",
1497
1523
  queryKeys,
1498
- errorName: err instanceof Error ? err.name : typeof err,
1524
+ responseStarted: proxyResponseStarted(res),
1525
+ upstreamStatus,
1526
+ errorClass: err instanceof Error ? err.name : typeof err,
1499
1527
  errorMessage: truncateProxyErrorMessage(err instanceof Error ? err.message : String(err))
1500
1528
  };
1501
1529
  }
@@ -3458,6 +3486,9 @@ function buildGeminiSpawnEnv(ctx, platform = process.platform) {
3458
3486
  if (!Object.prototype.hasOwnProperty.call(ctx.config.envVars ?? {}, "GEMINI_CLI_TRUST_WORKSPACE")) {
3459
3487
  spawnEnv.GEMINI_CLI_TRUST_WORKSPACE = "true";
3460
3488
  }
3489
+ if (platform === "win32" && !Object.prototype.hasOwnProperty.call(ctx.config.envVars ?? {}, "GEMINI_PTY_INFO")) {
3490
+ spawnEnv.GEMINI_PTY_INFO = "child_process";
3491
+ }
3461
3492
  return spawnEnv;
3462
3493
  }
3463
3494
  function normalizeExecOutput2(raw) {
@@ -5886,7 +5917,9 @@ var AgentProcessManager = class _AgentProcessManager {
5886
5917
  method: input.method,
5887
5918
  path: input.pathname,
5888
5919
  query_keys: input.queryKeys,
5889
- error_name: input.errorName,
5920
+ response_started: input.responseStarted,
5921
+ upstream_status: input.upstreamStatus,
5922
+ error_class: input.errorClass,
5890
5923
  error_message: input.errorMessage
5891
5924
  }, "error");
5892
5925
  }
package/dist/core.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  resolveSlockCliPath,
10
10
  resolveWorkspaceDirectoryPath,
11
11
  scanWorkspaceDirectories
12
- } from "./chunk-NF7BBN64.js";
12
+ } from "./chunk-RFGC74KF.js";
13
13
  import {
14
14
  subscribeDaemonLogs
15
15
  } from "./chunk-KNMCE6WB.js";
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  DAEMON_CLI_USAGE,
4
4
  DaemonCore,
5
5
  parseDaemonCliArgs
6
- } from "./chunk-NF7BBN64.js";
6
+ } from "./chunk-RFGC74KF.js";
7
7
  import "./chunk-KNMCE6WB.js";
8
8
 
9
9
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slock-ai/daemon",
3
- "version": "0.53.1-alpha.0",
3
+ "version": "0.53.1-alpha.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "slock-daemon": "dist/index.js"