基线:鉴权会话+工作组+工作台三区修复+编排工作区+产品设计文档
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
@@ -4,16 +4,19 @@
|
||||
* 「web 是纯呈现与输入面」:这里出的每一样都是服务端投影,前端零过程状态、刷新即重建(§9.2)。
|
||||
*/
|
||||
import type { Hono } from 'hono';
|
||||
import type { ApiError, ChatMessage, TaskCard, ViewBlock } from '@contracts';
|
||||
import type { ApiError, ChainNode, ChatMessage, Deliverable, FileDoc, TaskCard, ViewBlock } from '@contracts';
|
||||
import {
|
||||
ATTRIBUTION_SIDE_LABEL,
|
||||
answerMessageRoute,
|
||||
chatCardReplySchema,
|
||||
listMessagesRoute,
|
||||
markMessageReadRoute,
|
||||
listTasksRoute,
|
||||
replyChatCardRoute,
|
||||
replyWorkOrderRoute,
|
||||
sayRoute,
|
||||
taskDetailRoute,
|
||||
staffIdSchema,
|
||||
taskIdSchema,
|
||||
workOrderReplySchema,
|
||||
} from '@contracts';
|
||||
@@ -62,6 +65,79 @@ export function registerDeskRoutes(app: Hono<AppEnv>, container: Container): voi
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 流程链 —— 人要看见自己在整条流程的哪一环,以及前后是谁。
|
||||
* 别人负责的节点在链上只读呈现,不进任务清单(清单只装我负责的)。
|
||||
*/
|
||||
async function toChain(task: Awaited<ReturnType<Container['task']['get']>>): Promise<ChainNode[]> {
|
||||
if (task.workflowId === undefined) return [];
|
||||
const workflow = await container.process.getWorkflow(task.workflowId).catch(() => undefined);
|
||||
if (workflow === undefined) return [];
|
||||
const pkg = await container.process.getPackage(workflow.packageId, workflow.packageVersion);
|
||||
|
||||
/*
|
||||
* 链的呈现顺序:**按流程列位排,同列按节点编号排** —— 不吃 `nodes` 数组的书写顺序。
|
||||
*
|
||||
* 并行分支(如 G2 分出的 A2 / A3)在图上本无先后,链却必须挑一个顺序。
|
||||
* 挑「作者数组里怎么写」是最不稳的:换个人写包,链的读法就变了。
|
||||
* 列位 `layout.col` 是流程的推进次序(拓扑的可视化),同列的并行支再按编号定 ——
|
||||
* 于是链永远读作 A1 → A2 → A3 → A4,与人对活动编号的预期一致。
|
||||
* `layout` 声明为「不影响语义」,这里也只拿它排**呈现**,不参与任何流转判断。
|
||||
*/
|
||||
const declared = (pkg?.nodes ?? []).filter((n) => n.kind === 'activity' || n.kind === 'approval');
|
||||
const nodes = declared
|
||||
.map((n, index) => ({ n, index }))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
(a.n.layout?.col ?? a.index) - (b.n.layout?.col ?? b.index) ||
|
||||
(a.n.id < b.n.id ? -1 : a.n.id > b.n.id ? 1 : 0),
|
||||
)
|
||||
.map((x) => x.n);
|
||||
|
||||
/*
|
||||
* 状态取**真实的节点实例**,不按下标推。
|
||||
* 按下标推(「排在当前之前的就算做完」)在并行支上会说谎:人在 A3 时 A2 可能还在跑,
|
||||
* 却被标成已完成。宁可把在跑的并行支报作待办(少报),也不能把没做完的说成做完了。
|
||||
*/
|
||||
const instances = await container.process.instancesOf(workflow.id).catch(() => []);
|
||||
const finished = new Set(instances.filter((x) => x.terminal !== undefined).map((x) => x.nodeId));
|
||||
|
||||
return await Promise.all(
|
||||
nodes.map(async (n) => {
|
||||
const spec = n.kind === 'approval' ? n.approver : n.owner;
|
||||
|
||||
/*
|
||||
* 报谁,要和**真正派单时的口径一致**(ADR-011:绑定先于策略)。
|
||||
* 只按岗位报人的话,装了工作组的单会当面说谎:整条流实际都归起单人,
|
||||
* 链上却写着各岗位的常驻人。所以这里也先看工作组绑定,再退回岗位解析。
|
||||
*/
|
||||
const bound = workflow.workGroup?.[spec.position];
|
||||
const boundStaff =
|
||||
bound === undefined
|
||||
? undefined
|
||||
: await container.org.getStaff(staffIdSchema.parse(bound)).catch(() => undefined);
|
||||
|
||||
// 岗位唯一解析(sole)即报人名;否则只报岗位 —— 不编造具体承接人
|
||||
const holders =
|
||||
boundStaff !== undefined ? [] : await container.org.staffOfPosition(spec.position).catch(() => []);
|
||||
const who = boundStaff ?? (holders.length === 1 ? holders[0] : undefined);
|
||||
return {
|
||||
nodeId: n.id,
|
||||
label: n.label,
|
||||
kind: n.kind === 'approval' ? ('approval' as const) : ('activity' as const),
|
||||
ownerName: who?.name ?? spec.position,
|
||||
ownerRole: who?.position.name ?? spec.position,
|
||||
state:
|
||||
n.id === task.nodeId
|
||||
? ('current' as const)
|
||||
: finished.has(n.id)
|
||||
? ('done' as const)
|
||||
: ('todo' as const),
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
app.get(listTasksRoute.path, async (c) => {
|
||||
const staff = await me(c.get('account'));
|
||||
if (staff === undefined) {
|
||||
@@ -83,12 +159,49 @@ export function registerDeskRoutes(app: Hono<AppEnv>, container: Container): voi
|
||||
const task = await container.task.get(taskId);
|
||||
|
||||
const [workOrders, chat, lines, pushed] = await Promise.all([
|
||||
container.humanTool.openWorkOrders(taskId),
|
||||
// 全部工单:待处理要翻页办,已办结要回看定稿报告 —— 两摞同源
|
||||
container.humanTool.allWorkOrders(taskId),
|
||||
container.interaction.timeline(taskId),
|
||||
container.memory.taskLog(taskId),
|
||||
container.interaction.viewOf(taskId),
|
||||
]);
|
||||
const cards = await container.humanTool.chatCards(taskId);
|
||||
const chain = await toChain(task);
|
||||
|
||||
/*
|
||||
* 工作成果 = 一组**文件**,大部分是 HTML 汇报报告。
|
||||
* 两处来源:
|
||||
* ① 活动推的那一屏 —— 它就是这单当下的汇报报告(AM 07);
|
||||
* ② 过程成果里声明的 `files` 块 —— 活动按需生成的目标输出(报价单 / 台账 / 档案)。
|
||||
* 活动尚未产出文件时给空列表,界面落空态,不编造条目。
|
||||
*/
|
||||
/*
|
||||
* 过程成果尚无来源:活动还不发布 deliverable(一个个活动开发时逐步补上)。
|
||||
* 先声明出来并接进成果文件的装配 —— 活动一开始产出,文件列表就自动有了。
|
||||
*/
|
||||
const deliverables: Deliverable[] = [];
|
||||
|
||||
const results: Array<{ label: string; desc: string; at?: string; file: FileDoc }> = [];
|
||||
if (pushed?.html !== undefined) {
|
||||
results.push({
|
||||
label: `${task.title} · 汇报报告`,
|
||||
desc: 'HTML · 活动按当下局面组织的一屏',
|
||||
file: { kind: 'html', name: `${task.activityId}-report.html`, html: pushed.html },
|
||||
});
|
||||
}
|
||||
for (const deliverable of deliverables) {
|
||||
for (const block of deliverable.blocks) {
|
||||
if (block.t !== 'files') continue;
|
||||
for (const item of block.items) {
|
||||
results.push({
|
||||
label: item.label,
|
||||
desc: item.desc,
|
||||
...(deliverable.at === undefined ? {} : { at: deliverable.at }),
|
||||
file: item.file,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 对话流 = 时间线 + 对话卡族,按时间全序 —— 与任务记忆同源、不同筛选
|
||||
const merged: ChatMessage[] = [...chat, ...cards].sort((a, b) => (a.at < b.at ? -1 : a.at > b.at ? 1 : 0));
|
||||
@@ -111,6 +224,8 @@ export function registerDeskRoutes(app: Hono<AppEnv>, container: Container): voi
|
||||
return c.json({
|
||||
card: await toCard(task),
|
||||
goal: task.title,
|
||||
owner: { name: staff.name, role: staff.position.name },
|
||||
chain,
|
||||
budget: {
|
||||
steps: `${task.used.steps}/${task.caps.steps}`,
|
||||
tokens: `${task.used.tokens}/${task.caps.tokens}`,
|
||||
@@ -118,7 +233,8 @@ export function registerDeskRoutes(app: Hono<AppEnv>, container: Container): voi
|
||||
humanCalls: `${task.used.humanCalls}/${task.caps.humanCalls}`,
|
||||
},
|
||||
stages: [],
|
||||
deliverables: [],
|
||||
deliverables,
|
||||
results,
|
||||
workOrders,
|
||||
chat: merged,
|
||||
view: pushed?.blocks !== undefined ? [...pushed.blocks] : view,
|
||||
@@ -159,6 +275,34 @@ export function registerDeskRoutes(app: Hono<AppEnv>, container: Container): voi
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 对话卡回传(决策 / 补全 / 评价)。
|
||||
* 与工单回传同一条规矩:校验用**同 schema**,拒收由 human-tool 判定并给出违规明细。
|
||||
*/
|
||||
app.post(replyChatCardRoute.path, async (c) => {
|
||||
const staff = await me(c.get('account'));
|
||||
if (staff === undefined) {
|
||||
const body: ApiError = { code: 'unauthenticated', message: '会话无效' };
|
||||
return c.json(body, 401);
|
||||
}
|
||||
const parsed = chatCardReplySchema.safeParse((await c.req.json())['reply']);
|
||||
if (!parsed.success) {
|
||||
const body: ApiError = { code: 'validation-failed', message: '回传不合协议', detail: parsed.error.issues };
|
||||
return c.json(body, 400);
|
||||
}
|
||||
try {
|
||||
await container.humanTool.replyChatCard(parsed.data, staff.id);
|
||||
return c.json({ ok: true });
|
||||
} catch (error) {
|
||||
if (error instanceof ReplyRejectedError) {
|
||||
// 补全两条路必走其一 / 已答不得再答 —— 三规矩的回传面
|
||||
const body: ApiError = { code: 'validation-failed', message: error.message, detail: error.violations };
|
||||
return c.json(body, 400);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
/** 自由输入 —— 人事件的第二形态:写入任务记忆,loop 作为观察;不驱动 flow 步 */
|
||||
app.post(sayRoute.path, async (c) => {
|
||||
const staff = await me(c.get('account'));
|
||||
|
||||
Reference in New Issue
Block a user