mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-15 09:01:13 +00:00
add logging
This commit is contained in:
parent
0250f72976
commit
8ecd55a522
1 changed files with 24 additions and 0 deletions
|
|
@ -228,6 +228,9 @@ export class GatewayRuntime {
|
||||||
void this.handleHttpRequest(request, response).catch((error) => {
|
void this.handleHttpRequest(request, response).catch((error) => {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
const statusCode = error instanceof HttpError ? error.statusCode : 500;
|
const statusCode = error instanceof HttpError ? error.statusCode : 500;
|
||||||
|
this.log(
|
||||||
|
`[http] <-- ${request.method ?? "GET"} ${request.url ?? "/"} ${statusCode} error: ${message}`,
|
||||||
|
);
|
||||||
if (!response.writableEnded) {
|
if (!response.writableEnded) {
|
||||||
this.writeJson(response, statusCode, { error: message });
|
this.writeJson(response, statusCode, { error: message });
|
||||||
}
|
}
|
||||||
|
|
@ -298,6 +301,9 @@ export class GatewayRuntime {
|
||||||
queuedMessage.request.sessionKey,
|
queuedMessage.request.sessionKey,
|
||||||
);
|
);
|
||||||
if (managedSession.queue.length >= this.config.session.maxQueuePerSession) {
|
if (managedSession.queue.length >= this.config.session.maxQueuePerSession) {
|
||||||
|
this.log(
|
||||||
|
`[queue] session=${queuedMessage.request.sessionKey} queue full (${this.config.session.maxQueuePerSession})`,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
response: "",
|
response: "",
|
||||||
|
|
@ -442,6 +448,9 @@ export class GatewayRuntime {
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
this.log(
|
||||||
|
`[prompt] session=${managedSession.sessionKey} error: ${message}`,
|
||||||
|
);
|
||||||
if (message.includes("aborted")) {
|
if (message.includes("aborted")) {
|
||||||
this.emit(managedSession, {
|
this.emit(managedSession, {
|
||||||
type: "aborted",
|
type: "aborted",
|
||||||
|
|
@ -677,6 +686,8 @@ export class GatewayRuntime {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.log(`[http] --> ${method} ${path}`);
|
||||||
|
|
||||||
if (method === "GET" && path === "/ready") {
|
if (method === "GET" && path === "/ready") {
|
||||||
this.requireAuth(request, response);
|
this.requireAuth(request, response);
|
||||||
if (response.writableEnded) return;
|
if (response.writableEnded) return;
|
||||||
|
|
@ -904,6 +915,9 @@ export class GatewayRuntime {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const preview = text.length > 80 ? `${text.slice(0, 80)}...` : text;
|
||||||
|
this.log(`[chat] session=${sessionKey} text="${preview}"`);
|
||||||
|
|
||||||
// Set up SSE response headers
|
// Set up SSE response headers
|
||||||
response.writeHead(200, {
|
response.writeHead(200, {
|
||||||
"Content-Type": "text/event-stream",
|
"Content-Type": "text/event-stream",
|
||||||
|
|
@ -952,20 +966,27 @@ export class GatewayRuntime {
|
||||||
if (!clientDisconnected) {
|
if (!clientDisconnected) {
|
||||||
stopStreaming();
|
stopStreaming();
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
|
this.log(`[chat] session=${sessionKey} completed ok`);
|
||||||
finishVercelStream(response, "stop");
|
finishVercelStream(response, "stop");
|
||||||
} else {
|
} else {
|
||||||
const isAbort = result.error?.includes("aborted");
|
const isAbort = result.error?.includes("aborted");
|
||||||
|
this.log(
|
||||||
|
`[chat] session=${sessionKey} failed: ${result.error}${isAbort ? " (aborted)" : ""}`,
|
||||||
|
);
|
||||||
if (isAbort) {
|
if (isAbort) {
|
||||||
finishVercelStream(response, "error");
|
finishVercelStream(response, "error");
|
||||||
} else {
|
} else {
|
||||||
errorVercelStream(response, result.error ?? "Unknown error");
|
errorVercelStream(response, result.error ?? "Unknown error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.log(`[chat] session=${sessionKey} client disconnected`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!clientDisconnected) {
|
if (!clientDisconnected) {
|
||||||
stopStreaming();
|
stopStreaming();
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
this.log(`[chat] session=${sessionKey} exception: ${message}`);
|
||||||
errorVercelStream(response, message);
|
errorVercelStream(response, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1008,6 +1029,9 @@ export class GatewayRuntime {
|
||||||
statusCode: number,
|
statusCode: number,
|
||||||
payload: unknown,
|
payload: unknown,
|
||||||
): void {
|
): void {
|
||||||
|
if (statusCode >= 400) {
|
||||||
|
this.log(`[http] <-- ${statusCode} ${JSON.stringify(payload)}`);
|
||||||
|
}
|
||||||
response.statusCode = statusCode;
|
response.statusCode = statusCode;
|
||||||
response.setHeader("content-type", "application/json; charset=utf-8");
|
response.setHeader("content-type", "application/json; charset=utf-8");
|
||||||
response.end(JSON.stringify(payload));
|
response.end(JSON.stringify(payload));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue