feat(client): record computer tasks for digital employee

This commit is contained in:
baiyanyun
2026-06-05 16:52:19 +08:00
parent 2373e0b5f3
commit 512c7ab095
4 changed files with 246 additions and 1 deletions

View File

@@ -31,6 +31,10 @@ import { firstTokenTrace } from "./engines/perf/firstTokenTrace";
import { checkFileServerHealth } from "./packages/fileServerHealth";
import { LOCALHOST_HOSTNAME } from "./constants";
import { getConfiguredPorts } from "./startupPorts";
import {
recordDigitalEmployeeChatReceived,
recordDigitalEmployeeChatResult,
} from "./digitalEmployee/stateService";
import type {
ComputerChatRequest,
HttpResult,
@@ -406,6 +410,7 @@ async function handleRequest(
let t1: number, t2: number, t3: number, t4: number;
const body = (await parseBody(req)) as ComputerChatRequest;
recordDigitalEmployeeChatReceived(body);
t1 = Date.now();
firstTokenTrace.trace(
"chat.received",
@@ -515,6 +520,11 @@ async function handleRequest(
try {
acpEngine = await agentService.ensureEngineForRequest(body);
} catch (err: any) {
recordDigitalEmployeeChatResult(body, {
success: false,
code: "5000",
message: err.message || "Engine switch failed",
});
log.error("❌ [HTTP] Engine switch failed:", err);
firstTokenTrace.trace(
"chat.failed",
@@ -549,6 +559,11 @@ async function handleRequest(
getPerfLogger().info(`[PERF] /chat.ensureEngine: ${t3 - t2_5}ms`);
if (!acpEngine) {
recordDigitalEmployeeChatResult(body, {
success: false,
code: "5000",
message: "Agent not initialized",
});
log.error("❌ [HTTP] Agent not initialized");
sendJson(res, 200, httpError("5000", "Agent not initialized"));
return;
@@ -556,6 +571,15 @@ async function handleRequest(
// chat() 已返回 HttpResult<ComputerChatResponse> 格式
const result = await acpEngine.chat(body);
recordDigitalEmployeeChatResult(body, {
success: result.success,
code: result.code,
message: result.message,
project_id: result.data?.project_id,
session_id: result.data?.session_id,
request_id: result.data?.request_id || body.request_id,
engine: acpEngine.engineName,
});
t4 = Date.now();
firstTokenTrace.trace(
result.success ? "chat.response.sent" : "chat.failed",