refactor: remove stale import understanding surfaces
This commit is contained in:
@@ -7332,55 +7332,7 @@ export async function getLatestDeviceImportDraft(deviceId: string) {
|
||||
item.deviceImportDraftId === draft.draftId,
|
||||
) ?? null
|
||||
: null;
|
||||
const understandingTasks = draft
|
||||
? listDeviceImportUnderstandingTasks(state, draft.draftId)
|
||||
: [];
|
||||
const projectUnderstandings = draft
|
||||
? deriveDeviceImportProjectUnderstandings(state, draft.draftId)
|
||||
: [];
|
||||
return { draft, resolution, reviewTask, understandingTasks, projectUnderstandings };
|
||||
}
|
||||
|
||||
function listDeviceImportUnderstandingTasks(state: BossState, draftId: string) {
|
||||
const latestByCandidate = new Map<string, MasterAgentTask>();
|
||||
for (const task of state.masterAgentTasks) {
|
||||
if (
|
||||
task.taskType !== "conversation_reply" ||
|
||||
task.deviceImportDraftId !== draftId ||
|
||||
!task.deviceImportCandidateId
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const existing = latestByCandidate.get(task.deviceImportCandidateId);
|
||||
if (!existing || existing.requestedAt < task.requestedAt) {
|
||||
latestByCandidate.set(task.deviceImportCandidateId, task);
|
||||
}
|
||||
}
|
||||
return [...latestByCandidate.values()].map((task) => ({
|
||||
taskId: task.taskId,
|
||||
candidateId: task.deviceImportCandidateId ?? "",
|
||||
threadDisplayName: task.targetThreadDisplayName ?? "",
|
||||
folderName: task.deviceImportCandidateFolderName ?? "",
|
||||
status: task.status,
|
||||
updatedAt: task.completedAt ?? task.claimedAt ?? task.requestedAt,
|
||||
}));
|
||||
}
|
||||
|
||||
function parseDeviceImportUnderstandingReply(
|
||||
task: Pick<MasterAgentTask, "replyBody" | "deviceImportCandidateId" | "targetThreadDisplayName" | "deviceImportCandidateFolderName" | "taskId" | "completedAt" | "requestedAt">,
|
||||
): DeviceImportProjectUnderstanding | null {
|
||||
const understanding = parseStructuredProjectUnderstandingReply(task);
|
||||
const candidateId = task.deviceImportCandidateId?.trim();
|
||||
if (!candidateId || !understanding) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
candidateId,
|
||||
threadDisplayName: task.targetThreadDisplayName?.trim() || "未命名线程",
|
||||
folderName: task.deviceImportCandidateFolderName?.trim() || "",
|
||||
...understanding,
|
||||
};
|
||||
return { draft, resolution, reviewTask };
|
||||
}
|
||||
|
||||
function parseStructuredProjectUnderstandingReply(
|
||||
@@ -7429,29 +7381,6 @@ function parseStructuredProjectUnderstandingReply(
|
||||
};
|
||||
}
|
||||
|
||||
function deriveDeviceImportProjectUnderstandings(state: BossState, draftId: string) {
|
||||
const latestByCandidate = new Map<string, DeviceImportProjectUnderstanding>();
|
||||
for (const task of state.masterAgentTasks) {
|
||||
if (
|
||||
task.taskType !== "conversation_reply" ||
|
||||
task.deviceImportDraftId !== draftId ||
|
||||
task.status !== "completed" ||
|
||||
!task.deviceImportCandidateId
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const understanding = parseDeviceImportUnderstandingReply(task);
|
||||
if (!understanding) {
|
||||
continue;
|
||||
}
|
||||
const existing = latestByCandidate.get(understanding.candidateId);
|
||||
if (!existing || existing.updatedAt < understanding.updatedAt) {
|
||||
latestByCandidate.set(understanding.candidateId, understanding);
|
||||
}
|
||||
}
|
||||
return [...latestByCandidate.values()];
|
||||
}
|
||||
|
||||
function applyProjectUnderstandingSnapshotInState(
|
||||
state: BossState,
|
||||
input: {
|
||||
@@ -8085,9 +8014,6 @@ function applyDeviceImportResolutionInState(
|
||||
const selectedCandidates = draft.candidates.filter((candidate) =>
|
||||
draft.selectedCandidateIds.includes(candidate.candidateId),
|
||||
);
|
||||
const understandingsByCandidate = new Map(
|
||||
deriveDeviceImportProjectUnderstandings(state, draft.draftId).map((item) => [item.candidateId, item] as const),
|
||||
);
|
||||
const importedProjects: Project[] = [];
|
||||
for (const item of resolution.items) {
|
||||
const candidate = draft.candidates.find((entry) => entry.candidateId === item.candidateId);
|
||||
@@ -8132,25 +8058,6 @@ function applyDeviceImportResolutionInState(
|
||||
targetProject.preview = `已导入 ${candidate.threadDisplayName}`;
|
||||
targetProject.updatedAt = nowIso();
|
||||
targetProject.lastMessageAt = targetProject.updatedAt;
|
||||
const understanding = understandingsByCandidate.get(candidate.candidateId);
|
||||
if (understanding) {
|
||||
applyProjectUnderstandingSnapshotInState(state, {
|
||||
projectId: targetProject.id,
|
||||
account: device.account,
|
||||
snapshot: {
|
||||
projectGoal: understanding.projectGoal,
|
||||
currentProgress: understanding.currentProgress,
|
||||
technicalArchitecture: understanding.technicalArchitecture,
|
||||
currentBlockers: understanding.currentBlockers,
|
||||
recommendedNextStep: understanding.recommendedNextStep,
|
||||
sourceTaskId: understanding.sourceTaskId,
|
||||
updatedAt: understanding.updatedAt,
|
||||
sourceKind: "device_import",
|
||||
},
|
||||
sourceMessageId: understanding.sourceTaskId,
|
||||
sourceKind: "device_import",
|
||||
});
|
||||
}
|
||||
importedProjects.push({ ...targetProject });
|
||||
}
|
||||
|
||||
|
||||
@@ -1795,7 +1795,6 @@ export async function queueDeviceImportResolutionTask(params: {
|
||||
const selectedCandidates = draft.candidates.filter((candidate) =>
|
||||
draft.selectedCandidateIds.includes(candidate.candidateId),
|
||||
);
|
||||
const understandingTasks: Array<Awaited<ReturnType<typeof queueMasterAgentTask>>> = [];
|
||||
const task = await queueMasterAgentTask({
|
||||
projectId: "master-agent",
|
||||
taskType: "device_import_resolution",
|
||||
@@ -1836,13 +1835,6 @@ export async function queueDeviceImportResolutionTask(params: {
|
||||
deviceImportDraftId: task.deviceImportDraftId,
|
||||
},
|
||||
draft: latest.draft ?? undefined,
|
||||
understandingTasks: understandingTasks.map((item) => ({
|
||||
taskId: item.taskId,
|
||||
taskType: item.taskType,
|
||||
status: item.status,
|
||||
candidateId: item.deviceImportCandidateId,
|
||||
threadDisplayName: item.targetThreadDisplayName,
|
||||
})),
|
||||
...(latest.resolution ? { resolution: latest.resolution } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user