fix: migrate legacy boss console state
This commit is contained in:
@@ -2965,9 +2965,64 @@ function normalizeState(raw: Partial<BossState> | undefined): BossState {
|
||||
state.projects.unshift(base.projects[0]);
|
||||
}
|
||||
|
||||
removeLegacyBossConsoleArtifacts(state);
|
||||
return syncDerivedState(state);
|
||||
}
|
||||
|
||||
const LEGACY_BOSS_CONSOLE_PROJECT_ID = "boss-console";
|
||||
const LEGACY_BOSS_CONSOLE_PROJECT_NAME = "Boss 移动控制台";
|
||||
|
||||
function isLegacyBossConsoleRef(value?: string | null) {
|
||||
const normalized = value?.trim();
|
||||
return (
|
||||
normalized === LEGACY_BOSS_CONSOLE_PROJECT_ID ||
|
||||
normalized === LEGACY_BOSS_CONSOLE_PROJECT_NAME
|
||||
);
|
||||
}
|
||||
|
||||
function removeLegacyBossConsoleArtifacts(state: BossState) {
|
||||
state.projects = state.projects.filter((project) => !isLegacyBossConsoleRef(project.id));
|
||||
state.devices = state.devices.map((device) => ({
|
||||
...device,
|
||||
projects: device.projects.filter((project) => !isLegacyBossConsoleRef(project)),
|
||||
}));
|
||||
state.masterAgentMemories = state.masterAgentMemories.filter(
|
||||
(memory) => !isLegacyBossConsoleRef(memory.projectId),
|
||||
);
|
||||
state.userProjectAgentControls = state.userProjectAgentControls.filter(
|
||||
(item) => !isLegacyBossConsoleRef(item.projectId),
|
||||
);
|
||||
state.threadContextSnapshots = state.threadContextSnapshots.filter(
|
||||
(snapshot) => !isLegacyBossConsoleRef(snapshot.projectId),
|
||||
);
|
||||
state.threadHandoffPackages = state.threadHandoffPackages.filter(
|
||||
(item) => !isLegacyBossConsoleRef(item.projectId),
|
||||
);
|
||||
state.threadContextAlerts = state.threadContextAlerts.filter(
|
||||
(item) => !isLegacyBossConsoleRef(item.projectId),
|
||||
);
|
||||
state.opsFaults = state.opsFaults.filter((item) => !isLegacyBossConsoleRef(item.projectId));
|
||||
state.masterAgentTasks = state.masterAgentTasks.filter(
|
||||
(task) =>
|
||||
!isLegacyBossConsoleRef(task.projectId) &&
|
||||
!isLegacyBossConsoleRef(task.targetProjectId) &&
|
||||
!isLegacyBossConsoleRef(task.projectUnderstandingTargetProjectId),
|
||||
);
|
||||
state.dispatchPlans = state.dispatchPlans.filter(
|
||||
(plan) =>
|
||||
!isLegacyBossConsoleRef(plan.groupProjectId) &&
|
||||
!(plan.targets ?? []).some((target) => isLegacyBossConsoleRef(target.projectId)) &&
|
||||
!(plan.confirmedTargetProjectIds ?? []).some((projectId) =>
|
||||
isLegacyBossConsoleRef(projectId),
|
||||
),
|
||||
);
|
||||
state.dispatchExecutions = state.dispatchExecutions.filter(
|
||||
(execution) =>
|
||||
!isLegacyBossConsoleRef(execution.groupProjectId) &&
|
||||
!isLegacyBossConsoleRef(execution.targetProjectId),
|
||||
);
|
||||
}
|
||||
|
||||
function latestProjectTimestamp(state: BossState, projectId: string) {
|
||||
const project = state.projects.find((item) => item.id === projectId);
|
||||
const messageTimes = (project?.messages ?? []).map((message) => messageTimeValue(message.sentAt));
|
||||
|
||||
Reference in New Issue
Block a user