吸收数字员工产物交付状态
This commit is contained in:
@@ -1402,7 +1402,9 @@ export function recordDigitalEmployeeRuntimeEvent(
|
||||
if (status === "completed" || status === "failed") {
|
||||
finishRun(ids.runId, status, now);
|
||||
}
|
||||
persistPayloadArtifactsAndApprovals(ids, event.payload ?? event, now);
|
||||
persistPayloadArtifactsAndApprovals(ids, event.payload ?? event, now, {
|
||||
sourceEventKind: event.kind,
|
||||
});
|
||||
insertEvent(
|
||||
{
|
||||
event_id: `${ids.runId}:${event.kind}:${Date.now()}`,
|
||||
@@ -3592,9 +3594,10 @@ function persistPayloadArtifactsAndApprovals(
|
||||
ids: { planId: string; taskId: string; runId: string },
|
||||
payload: unknown,
|
||||
now: string,
|
||||
context: ArtifactExtractionContext = {},
|
||||
): void {
|
||||
const sources = payloadSources(payload);
|
||||
const artifacts = sources.flatMap((source) => extractArtifacts(source));
|
||||
const artifacts = sources.flatMap((source) => extractArtifacts(source, context));
|
||||
const approvals = sources.flatMap((source) => extractApprovals(source));
|
||||
|
||||
dedupeByKey(artifacts, (artifact) => artifact.key).slice(0, 20).forEach((artifact, index) => {
|
||||
@@ -3645,12 +3648,34 @@ interface ExtractedArtifact {
|
||||
payload: unknown;
|
||||
}
|
||||
|
||||
function extractArtifacts(payload: unknown): ExtractedArtifact[] {
|
||||
interface ArtifactExtractionContext {
|
||||
sourceEventKind?: string;
|
||||
}
|
||||
|
||||
interface DeliveryMetadata {
|
||||
stage: string;
|
||||
status: string | null;
|
||||
workspace_id: string | null;
|
||||
project_id: string | null;
|
||||
file_id: string | null;
|
||||
version: string | null;
|
||||
filename: string | null;
|
||||
size: number | null;
|
||||
uri: string | null;
|
||||
error: string | null;
|
||||
source_tool: string | null;
|
||||
source_event_kind: string | null;
|
||||
}
|
||||
|
||||
function extractArtifacts(payload: unknown, context: ArtifactExtractionContext = {}): ExtractedArtifact[] {
|
||||
const record = objectRecord(payload);
|
||||
if (!record) return typeof payload === "string" && looksLikeArtifactUri(payload)
|
||||
? [artifactFromValue(payload, 0)]
|
||||
: [];
|
||||
|
||||
const fileServerArtifacts = extractFileServerArtifacts(record, context);
|
||||
if (fileServerArtifacts.length > 0) return fileServerArtifacts;
|
||||
|
||||
const values = [
|
||||
...unknownArray(record.artifacts),
|
||||
...unknownArray(record.outputs),
|
||||
@@ -3691,6 +3716,152 @@ function artifactFromValue(value: unknown, index: number): ExtractedArtifact {
|
||||
};
|
||||
}
|
||||
|
||||
const FILE_SERVER_TOOLS = new Set([
|
||||
"create_workspace",
|
||||
"create_workspace_v2",
|
||||
"push_skills_to_workspace",
|
||||
"push_skills_to_workspace_v2",
|
||||
"get_file_list",
|
||||
"files_update",
|
||||
"upload_file",
|
||||
"upload_files",
|
||||
"download_all_files",
|
||||
"create_project",
|
||||
"upload_project",
|
||||
"get_project_content",
|
||||
"get_project_content_by_version",
|
||||
"backup_current_version",
|
||||
"export_project",
|
||||
"delete_project",
|
||||
"upload_attachment_file",
|
||||
"copy_project",
|
||||
]);
|
||||
|
||||
function extractFileServerArtifacts(
|
||||
record: Record<string, unknown>,
|
||||
context: ArtifactExtractionContext,
|
||||
): ExtractedArtifact[] {
|
||||
const sourceTool = normalizeFileServerTool(record);
|
||||
if (!isFileServerPayload(record, sourceTool, context)) return [];
|
||||
|
||||
const values = [
|
||||
...unknownArray(record.artifacts),
|
||||
...unknownArray(record.outputs),
|
||||
...unknownArray(record.files),
|
||||
...unknownArray(record.attachments),
|
||||
];
|
||||
if (values.length === 0) values.push(record);
|
||||
|
||||
return values.map((value, index) => {
|
||||
const item = objectRecord(value);
|
||||
return fileServerArtifactFromRecord(item ? { ...record, ...item } : record, sourceTool, context, index);
|
||||
}).filter((artifact) => artifact.name || artifact.uri);
|
||||
}
|
||||
|
||||
function fileServerArtifactFromRecord(
|
||||
record: Record<string, unknown>,
|
||||
sourceTool: string,
|
||||
context: ArtifactExtractionContext,
|
||||
index: number,
|
||||
): ExtractedArtifact {
|
||||
const delivery = buildFileServerDelivery(record, sourceTool, context);
|
||||
const name = delivery.filename
|
||||
|| stringValue(record.name ?? record.title ?? record.projectName ?? record.project_name)
|
||||
|| delivery.workspace_id
|
||||
|| artifactName(delivery.uri || "")
|
||||
|| `File Server 产物 ${index + 1}`;
|
||||
return {
|
||||
key: delivery.file_id
|
||||
|| stringValue(record.id ?? record.artifact_id)
|
||||
|| delivery.uri
|
||||
|| `${delivery.stage}:${delivery.workspace_id || delivery.project_id || name}`,
|
||||
kind: delivery.stage,
|
||||
name,
|
||||
uri: delivery.uri,
|
||||
payload: {
|
||||
...record,
|
||||
delivery,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function buildFileServerDelivery(
|
||||
record: Record<string, unknown>,
|
||||
sourceTool: string,
|
||||
context: ArtifactExtractionContext,
|
||||
): DeliveryMetadata {
|
||||
const uri = stringValue(
|
||||
record.downloadUrl
|
||||
?? record.download_url
|
||||
?? record.exportPath
|
||||
?? record.export_path
|
||||
?? record.uri
|
||||
?? record.url
|
||||
?? record.path
|
||||
?? record.filePath
|
||||
?? record.file_path
|
||||
?? record.outputPath
|
||||
?? record.output_path,
|
||||
);
|
||||
return {
|
||||
stage: fileServerDeliveryStage(sourceTool),
|
||||
status: stringValue(record.status ?? record.deliveryStatus ?? record.delivery_status) || null,
|
||||
workspace_id: stringValue(record.workspaceId ?? record.workspace_id ?? record.workspace) || null,
|
||||
project_id: stringValue(record.projectId ?? record.project_id ?? record.project) || null,
|
||||
file_id: stringValue(record.fileId ?? record.file_id ?? record.id ?? record.artifact_id) || null,
|
||||
version: stringValue(record.version ?? record.fileVersion ?? record.file_version) || null,
|
||||
filename: stringValue(record.filename ?? record.fileName ?? record.file_name ?? record.name) || artifactName(uri) || null,
|
||||
size: numberValue(record.size ?? record.fileSize ?? record.file_size ?? record.bytes),
|
||||
uri: uri || null,
|
||||
error: stringValue(record.error ?? record.message_error ?? record.lastError ?? record.last_error) || null,
|
||||
source_tool: sourceTool || null,
|
||||
source_event_kind: context.sourceEventKind || null,
|
||||
};
|
||||
}
|
||||
|
||||
function isFileServerPayload(
|
||||
record: Record<string, unknown>,
|
||||
sourceTool: string,
|
||||
context: ArtifactExtractionContext,
|
||||
): boolean {
|
||||
if (sourceTool && FILE_SERVER_TOOLS.has(sourceTool)) return true;
|
||||
const text = [
|
||||
record.source,
|
||||
record.service,
|
||||
record.provider,
|
||||
record.server,
|
||||
context.sourceEventKind,
|
||||
].map((value) => stringValue(value).toLowerCase()).join(" ");
|
||||
return text.includes("qiming-file-server")
|
||||
|| text.includes("qiming_file_server")
|
||||
|| text.includes("file_server")
|
||||
|| text.includes("file-server");
|
||||
}
|
||||
|
||||
function normalizeFileServerTool(record: Record<string, unknown>): string {
|
||||
return stringValue(record.toolName ?? record.tool_name ?? record.tool ?? record.action ?? record.command)
|
||||
.toLowerCase()
|
||||
.replace(/-/g, "_");
|
||||
}
|
||||
|
||||
function fileServerDeliveryStage(tool: string): string {
|
||||
if (tool.includes("workspace")) return "workspace";
|
||||
if (tool.includes("download")) return "download";
|
||||
if (tool.includes("export")) return "export";
|
||||
if (tool.includes("upload") || tool.includes("push_skills")) return "upload";
|
||||
if (tool.includes("files_update") || tool.includes("file_list") || tool.includes("project_content")) return "file_update";
|
||||
return "artifact";
|
||||
}
|
||||
|
||||
function numberValue(value: unknown): number | null {
|
||||
if (typeof value === "number" && Number.isFinite(value)) return value;
|
||||
if (typeof value === "string" && value.trim()) {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
interface ExtractedApproval {
|
||||
key: string;
|
||||
title: string;
|
||||
|
||||
Reference in New Issue
Block a user