feat(client): mirror agent events to digital employee
This commit is contained in:
@@ -67,6 +67,16 @@ export interface DigitalEmployeeChatResultRecord {
|
||||
engine?: string;
|
||||
}
|
||||
|
||||
export interface DigitalEmployeeRuntimeEventRecord {
|
||||
kind: string;
|
||||
message?: string;
|
||||
request_id?: string;
|
||||
session_id?: string;
|
||||
project_id?: string;
|
||||
status?: "running" | "completed" | "failed" | "pending";
|
||||
payload?: unknown;
|
||||
}
|
||||
|
||||
function defaultState(): DigitalEmployeeState {
|
||||
return {
|
||||
version: 1,
|
||||
@@ -230,6 +240,66 @@ export function recordDigitalEmployeeChatResult(
|
||||
tx();
|
||||
}
|
||||
|
||||
export function recordDigitalEmployeeRuntimeEvent(
|
||||
event: DigitalEmployeeRuntimeEventRecord,
|
||||
): void {
|
||||
const now = new Date().toISOString();
|
||||
const ids = chatIds({
|
||||
request_id: event.request_id,
|
||||
session_id: event.session_id,
|
||||
project_id: event.project_id,
|
||||
prompt: event.message,
|
||||
});
|
||||
const status = event.status ?? "running";
|
||||
const title = event.message || event.kind;
|
||||
const db = getDb();
|
||||
if (!db) return;
|
||||
|
||||
const tx = db.transaction(() => {
|
||||
upsertPlan({
|
||||
id: ids.planId,
|
||||
title: `运行事件:${title}`,
|
||||
objective: title,
|
||||
status,
|
||||
payload: event.payload ?? event,
|
||||
now,
|
||||
});
|
||||
upsertTask({
|
||||
id: ids.taskId,
|
||||
planId: ids.planId,
|
||||
title,
|
||||
status,
|
||||
assignedSkillId: "qimingclaw-acp-session",
|
||||
payload: event.payload ?? event,
|
||||
now,
|
||||
});
|
||||
upsertRun({
|
||||
id: ids.runId,
|
||||
planId: ids.planId,
|
||||
taskId: ids.taskId,
|
||||
status,
|
||||
payload: event.payload ?? event,
|
||||
now,
|
||||
});
|
||||
if (status === "completed" || status === "failed") {
|
||||
finishRun(ids.runId, status, now);
|
||||
}
|
||||
insertEvent(
|
||||
{
|
||||
event_id: `${ids.runId}:${event.kind}:${Date.now()}`,
|
||||
kind: event.kind,
|
||||
occurred_at: now,
|
||||
message: title,
|
||||
plan_id: ids.planId,
|
||||
task_id: ids.taskId,
|
||||
},
|
||||
ids.runId,
|
||||
event.payload ?? event,
|
||||
);
|
||||
});
|
||||
tx();
|
||||
}
|
||||
|
||||
function persistSnapshotTables(
|
||||
snapshot: DigitalEmployeeSnapshot,
|
||||
event: DigitalEmployeeStateEvent | null,
|
||||
|
||||
Reference in New Issue
Block a user