@papercraneai/sandbox-agent 0.1.11 → 0.1.13
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/index.js +22 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1250,7 +1250,21 @@ app.post("/chat", async (req, res) => {
|
|
|
1250
1250
|
const resultWithModel = { ...msg, model: usedModel };
|
|
1251
1251
|
res.write(`data: ${JSON.stringify(resultWithModel)}\n\n`);
|
|
1252
1252
|
gotResult = true;
|
|
1253
|
-
|
|
1253
|
+
const baseLogCtx = {
|
|
1254
|
+
...ctx,
|
|
1255
|
+
elapsed: Date.now() - requestStartTime,
|
|
1256
|
+
subtype: msg.subtype,
|
|
1257
|
+
num_turns: msg.num_turns,
|
|
1258
|
+
is_error: msg.is_error,
|
|
1259
|
+
cost_usd: msg.total_cost_usd
|
|
1260
|
+
};
|
|
1261
|
+
if (msg.is_error) {
|
|
1262
|
+
const errMsg = msg;
|
|
1263
|
+
log.warn({ ...baseLogCtx, errors: errMsg.errors }, `Query ended with error: ${msg.subtype}`);
|
|
1264
|
+
}
|
|
1265
|
+
else {
|
|
1266
|
+
log.info(baseLogCtx, "Query complete");
|
|
1267
|
+
}
|
|
1254
1268
|
res.write("data: [DONE]\n\n");
|
|
1255
1269
|
res.end();
|
|
1256
1270
|
return;
|
|
@@ -1273,6 +1287,7 @@ app.post("/chat", async (req, res) => {
|
|
|
1273
1287
|
const isAbortError = error instanceof Error &&
|
|
1274
1288
|
(error.name === "AbortError" || error.constructor.name === "AbortError");
|
|
1275
1289
|
if (isAbortError || isAborted) {
|
|
1290
|
+
log.info(ctx, "Chat request aborted by client");
|
|
1276
1291
|
if (!res.writableEnded) {
|
|
1277
1292
|
res.write(`data: ${JSON.stringify({ type: "aborted" })}\n\n`);
|
|
1278
1293
|
res.write("data: [DONE]\n\n");
|
|
@@ -1280,12 +1295,17 @@ app.post("/chat", async (req, res) => {
|
|
|
1280
1295
|
}
|
|
1281
1296
|
return;
|
|
1282
1297
|
}
|
|
1283
|
-
log.error({
|
|
1298
|
+
log.error({
|
|
1299
|
+
...ctx,
|
|
1300
|
+
err: error instanceof Error ? error.message : String(error),
|
|
1301
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
1302
|
+
}, "Unhandled error in chat stream — stream terminated");
|
|
1284
1303
|
if (!res.writableEnded) {
|
|
1285
1304
|
res.write(`data: ${JSON.stringify({
|
|
1286
1305
|
type: "error",
|
|
1287
1306
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
1288
1307
|
})}\n\n`);
|
|
1308
|
+
res.write("data: [DONE]\n\n");
|
|
1289
1309
|
res.end();
|
|
1290
1310
|
}
|
|
1291
1311
|
}
|