Files
deerflow-code/frontend-web/src/position-roundtable/lib/mock-task-source.ts
T

73 lines
2.6 KiB
TypeScript

/**
* Temporary task source for the standalone position-collaboration workspace.
*
* The real task-system adapter should replace only this module. The page and
* Session API consume the normalized `PositionTask` shape, so they do not need
* to know whether data came from an external task platform or this local demo.
*/
export interface PositionTask {
id: string;
title: string;
description: string;
direction: string;
source: "mock";
}
export const MOCK_POSITION_TASKS: readonly PositionTask[] = [
{
id: "mock-position-task-001",
title: "重点区域态势研判与协同处置方案",
description:
"围绕重点区域近期态势,梳理风险信号、影响范围与处置约束,形成可执行的协同方案及评估建议。",
direction: "态势研判",
source: "mock",
},
{
id: "mock-position-task-002",
title: "重大活动保障资源统筹任务",
description:
"针对重大活动保障场景,识别关键保障目标、现有资源和跨部门协同难点,输出分阶段资源统筹方案。",
direction: "组织筹划",
source: "mock",
},
{
id: "mock-position-task-003",
title: "专项行动效果复盘与优化建议",
description:
"汇总专项行动过程信息与阶段产物,研判实际效果、剩余风险和优化路径,形成后续行动建议。",
direction: "综合评估",
source: "mock",
},
] as const;
export const DEFAULT_MOCK_POSITION_TASK_ID = MOCK_POSITION_TASKS[0].id;
export function getMockPositionTask(taskId?: string | null): PositionTask {
return (
MOCK_POSITION_TASKS.find((task) => task.id === taskId) ??
MOCK_POSITION_TASKS[0]
);
}
/** Normalizes a persisted Session task snapshot without exposing source internals. */
export function taskFromPositionSnapshot(
snapshot: Record<string, unknown> | null | undefined,
fallback: PositionTask,
): PositionTask {
if (!snapshot || Object.keys(snapshot).length === 0) return fallback;
const value = (keys: string[], defaultValue: string) => {
const found = keys
.map((key) => snapshot[key])
.find((item) => typeof item === "string" && item.trim());
return typeof found === "string" ? found : defaultValue;
};
return {
id: value(["id", "taskId", "externalTaskId"], fallback.id),
title: value(["title", "taskName", "name"], fallback.title),
description: value(["description", "taskContent", "overview", "content"], fallback.description),
direction: value(["direction", "taskDirection", "category"], fallback.direction),
source: "mock",
};
}