feat(client): record computer tasks for digital employee
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { ipcMain } from "electron";
|
||||
import { agentService } from "../services/engines/unifiedAgent";
|
||||
import {
|
||||
recordDigitalEmployeeChatReceived,
|
||||
recordDigitalEmployeeChatResult,
|
||||
} from "../services/digitalEmployee/stateService";
|
||||
import type {
|
||||
ComputerChatRequest,
|
||||
ComputerAgentStatusResponse,
|
||||
@@ -10,11 +14,17 @@ import type {
|
||||
|
||||
export function registerComputerHandlers(): void {
|
||||
ipcMain.handle("computer:chat", async (_, request: ComputerChatRequest) => {
|
||||
recordDigitalEmployeeChatReceived(request);
|
||||
// 与 HTTP 路径一致:按 project_id 路由到对应 AcpEngine
|
||||
let acpEngine;
|
||||
try {
|
||||
acpEngine = await agentService.ensureEngineForRequest(request);
|
||||
} catch (err: any) {
|
||||
recordDigitalEmployeeChatResult(request, {
|
||||
success: false,
|
||||
code: "5000",
|
||||
message: err.message || "Engine switch failed",
|
||||
});
|
||||
return {
|
||||
code: "5000",
|
||||
message: err.message || "Engine switch failed",
|
||||
@@ -24,6 +34,11 @@ export function registerComputerHandlers(): void {
|
||||
} as HttpResult;
|
||||
}
|
||||
if (!acpEngine) {
|
||||
recordDigitalEmployeeChatResult(request, {
|
||||
success: false,
|
||||
code: "5000",
|
||||
message: "Agent not initialized",
|
||||
});
|
||||
return {
|
||||
code: "5000",
|
||||
message: "Agent not initialized",
|
||||
@@ -32,7 +47,17 @@ export function registerComputerHandlers(): void {
|
||||
success: false,
|
||||
} as HttpResult;
|
||||
}
|
||||
return acpEngine.chat(request);
|
||||
const result = await acpEngine.chat(request);
|
||||
recordDigitalEmployeeChatResult(request, {
|
||||
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 || request.request_id,
|
||||
engine: acpEngine.engineName,
|
||||
});
|
||||
return result;
|
||||
});
|
||||
|
||||
ipcMain.handle(
|
||||
|
||||
Reference in New Issue
Block a user