@slock-ai/daemon 0.53.1-alpha.1 → 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.
|
|
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
|
|
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
|
+
});
|
|
1490
1498
|
}
|
|
1491
1499
|
}
|
|
1492
|
-
function
|
|
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 {
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
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
|
-
|
|
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
|
}
|
|
@@ -5889,7 +5917,9 @@ var AgentProcessManager = class _AgentProcessManager {
|
|
|
5889
5917
|
method: input.method,
|
|
5890
5918
|
path: input.pathname,
|
|
5891
5919
|
query_keys: input.queryKeys,
|
|
5892
|
-
|
|
5920
|
+
response_started: input.responseStarted,
|
|
5921
|
+
upstream_status: input.upstreamStatus,
|
|
5922
|
+
error_class: input.errorClass,
|
|
5893
5923
|
error_message: input.errorMessage
|
|
5894
5924
|
}, "error");
|
|
5895
5925
|
}
|
package/dist/core.js
CHANGED
package/dist/index.js
CHANGED