forked from ChaiHao/BPOS-MVP
三面拆分⑫:网关去节点化 —— 分支即条件出边,汇合即多入边异或
模型(与 Mastra .branch 同构,条件挂在步与步之间): - routing.selectEdges:多出边一律异或,不分节点种类 —— 条件命中优先(按声明序), 无条件边作默认兜底,恰取一条;单出边直通保留(历史并行网关的遗留通道) - closure:含网关即 gateway-deprecated(历史版本仅可读、不可激活); 「隐式合并」禁令删除(多入边=异或汇合,上游互斥无歧义); 新规:多出边节点的无条件边至多一条,超出报 multi-default-edge - contracts:CLOSURE_VIOLATION_KINDS 去 gateway-unbalanced/join-ambiguous-source, 进 multi-default-edge/gateway-deprecated(下游零引用,api-report 随行) 种子(按用户要求:只留一条流一个版本,图/节点/边全部对账): - MVP_PACKAGE 重写:10 节点 14 边零网关 —— G1/G2 展开为 A1 的三条出边 (选型/直接寻源/默认直接定价)+ A2 的两条,G2J/G3 整颗删除, A5 审批点的两个去向就是自己的两条 verdict 条件出边(驳回边与 reject 声明字字对齐) - 手绘图:顶车道 y30 补画 A1→A3「直接寻源」—— 画布保存只认画出来的边, 不画这条语义边会在首次存盘被静默丢掉(新增图边对账测试卡死这类漏画); 「供应商底价表」标注钉进 y190 车道空档,不再被卡点压住 - 开发库外科手术:清运行数据 + 删 v1–v4,重种为唯一生效版 v1(闭合过闸) UI 与文案同步: - 元素盘/追加盘不再有网关件(画布仍认得历史图);图例删「判断/并行网关」「菱形=网关」 - 新建流程补激活一跳(保存不生效模型下,不激活「建出来就能起单」就是谎言) - 总览四种编排要素、「画图不检查,激活才查完整」贯穿 blueprint/memory/process 文案 测试:closure 43 通过(gateway-deprecated + multi-default-edge 两用例), seed-mvp-flow 8 通过(含图边对账),端到端八例真库全绿(网关从不建实例,断言原样存活); 五闸 typecheck/lint/depcruise/api:check/test 全过(退出码验)。 债:M5-4 AND 并行待「并行组」声明(Mastra .parallel);M5-5 网关运行时兼容三处, 含网关在途流清零后随 schema 一并摘除。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
@@ -1,135 +1,109 @@
|
||||
/**
|
||||
* 流程包 —— 守四件事:拓扑齐、**审批点后面跟网关且两个去向都真的走**、
|
||||
* 网关条件读得到判据、回边标了 reopen。
|
||||
* 流程包(无网关版)—— 守四件事:拓扑齐且零网关、分支即条件出边、
|
||||
* 审批点两个去向都由图表达、回边标了 reopen。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { MVP_PACKAGE } from '../seed-mvp-flow.ts';
|
||||
|
||||
describe('MVP_PACKAGE', () => {
|
||||
it('15 语义节点 · 18 边 · 五网关一审批点双终点', () => {
|
||||
expect(MVP_PACKAGE.nodes).toHaveLength(15);
|
||||
expect(MVP_PACKAGE.edges).toHaveLength(18);
|
||||
expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'end')).toHaveLength(2);
|
||||
expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'gateway')).toHaveLength(5);
|
||||
it('10 语义节点 · 14 边 · 零网关 · 一审批点双终点', () => {
|
||||
expect(MVP_PACKAGE.nodes).toHaveLength(10);
|
||||
expect(MVP_PACKAGE.edges).toHaveLength(14);
|
||||
expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'gateway')).toHaveLength(0);
|
||||
expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'approval')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('分叉必有汇合:G2 的两条互斥分支并回 G2J —— 不给汇合点,A4 会被判隐式合并', () => {
|
||||
const g2j = MVP_PACKAGE.nodes.find((n) => n.id === 'G2J');
|
||||
expect(g2j?.kind).toBe('gateway');
|
||||
if (g2j?.kind !== 'gateway') return;
|
||||
expect(g2j.gateway).toBe('exclusive');
|
||||
expect(g2j.mode).toBe('join');
|
||||
expect(MVP_PACKAGE.edges.filter((e) => e.to === 'G2J')).toHaveLength(2);
|
||||
/*
|
||||
* A4 的**非回边**入边只剩一条 —— 这是发布闸能过的关键。
|
||||
* A4 一共三条入边(G2J 正常来、G3 驳回、G4 有异议),后两条都是 reopen;
|
||||
* 闭合校验的「汇合同名字段来源不明」只看并发入边(回边是重新入场、不参与判定),
|
||||
* 所以 concurrent 长度 1、不触发。任一条回边漏标 reopen,发布立刻被拦。
|
||||
*/
|
||||
expect(MVP_PACKAGE.edges.filter((e) => e.to === 'A4' && !e.reopen)).toHaveLength(1);
|
||||
expect(MVP_PACKAGE.edges.filter((e) => e.to === 'A4')).toHaveLength(3);
|
||||
expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'end')).toHaveLength(2);
|
||||
});
|
||||
|
||||
/*
|
||||
* 审批点后面必然跟一个网关(BPMN 的常规)。
|
||||
*
|
||||
* 这条曾经不成立:G3 被我做掉了,通过走 A5 的唯一出边、驳回藏在 `reject` 声明里,
|
||||
* 图上只有一枚牌子。补回 G3 时还有个坑 —— 若引擎不把裁决放进载荷,
|
||||
* G3 的条件就没东西可读,只能在边上喂一枚常量 `verdict: "pass"` 骗过它;
|
||||
* 那样条件恒真、驳回边永不可达,网关成了摆设。所以这里连**没有常量**一起守。
|
||||
* 分支 = 源节点的多条条件出边,恰取一条;无条件边作默认兜底,至多一条。
|
||||
* 原 G1/G2 合并展开成 A1 的三条出边:选型 / 直接寻源(复合条件)/ 直接定价(默认)。
|
||||
*/
|
||||
it('A5 后面跟着 G3,两个去向都由图表达,且判据不是喂进去的常量', () => {
|
||||
it('A1 三条出边:两条带条件 + 一条默认兜底 —— 原 G1+G2 的展开', () => {
|
||||
const outs = MVP_PACKAGE.edges.filter((e) => e.from === 'A1');
|
||||
expect(outs.map((e) => `${e.to}:${e.condition ?? '(默认)'}`).sort()).toEqual([
|
||||
'A2:needAlternative = true',
|
||||
'A3:needAlternative = false and needSourcing = true',
|
||||
'A4:(默认)',
|
||||
]);
|
||||
});
|
||||
|
||||
it('A5 审批点的两个去向就是它自己的两条条件出边;驳回边与 reject 声明字字对齐', () => {
|
||||
const a5 = MVP_PACKAGE.nodes.find((n) => n.id === 'A5');
|
||||
expect(a5?.kind).toBe('approval');
|
||||
if (a5?.kind !== 'approval') return;
|
||||
expect(a5.approver.position).toBe('PM');
|
||||
if (a5?.kind !== 'approval' || a5.reject.kind !== 'reopen') return;
|
||||
|
||||
// A5 的唯一出边指向网关,而不是直接指向下一个活动
|
||||
const outOfA5 = MVP_PACKAGE.edges.filter((e) => e.from === 'A5');
|
||||
expect(outOfA5).toHaveLength(1);
|
||||
expect(outOfA5[0]?.to).toBe('G3');
|
||||
// 这条边不许带映射:判据由引擎在裁决时放进载荷,不是边喂的常量
|
||||
expect(outOfA5[0]?.mapping).toEqual([]);
|
||||
|
||||
const g3 = MVP_PACKAGE.nodes.find((n) => n.id === 'G3');
|
||||
expect(g3?.kind).toBe('gateway');
|
||||
if (g3?.kind !== 'gateway') return;
|
||||
expect(g3.gateway).toBe('exclusive');
|
||||
expect(g3.mode).toBe('fork');
|
||||
|
||||
const outOfG3 = MVP_PACKAGE.edges.filter((e) => e.from === 'G3');
|
||||
expect(outOfG3).toHaveLength(2);
|
||||
// 异或分叉的每条出边都要带条件 —— 没有无条件兜底边可用
|
||||
for (const e of outOfG3) expect(e.condition, `${e.id} 缺条件`).toBeDefined();
|
||||
expect(outOfG3.map((e) => `${e.to}:${e.condition ?? ''}`).sort()).toEqual([
|
||||
const outs = MVP_PACKAGE.edges.filter((e) => e.from === 'A5');
|
||||
expect(outs.map((e) => `${e.to}:${e.condition ?? ''}`).sort()).toEqual([
|
||||
'A4:verdict = "reject"',
|
||||
'A6:verdict = "pass"',
|
||||
]);
|
||||
const rejectEdge = outs.find((e) => e.to === 'A4')!;
|
||||
expect(rejectEdge.reopen).toBe(true);
|
||||
expect(rejectEdge.to).toBe(a5.reject.nodeId);
|
||||
expect(rejectEdge.mapping).toEqual(a5.reject.mapping);
|
||||
});
|
||||
|
||||
it('G3 的驳回出边与 A5 的 reject 声明字字对齐 —— 引擎先看图,没画边的包才退回声明', () => {
|
||||
const a5 = MVP_PACKAGE.nodes.find((n) => n.id === 'A5');
|
||||
const edge = MVP_PACKAGE.edges.find((e) => e.id === 'e-g3-a4');
|
||||
expect(a5?.kind).toBe('approval');
|
||||
if (a5?.kind !== 'approval' || a5.reject.kind !== 'reopen') return;
|
||||
expect(edge?.to).toBe(a5.reject.nodeId);
|
||||
expect(edge?.reopen).toBe(true);
|
||||
expect(edge?.mapping).toEqual(a5.reject.mapping);
|
||||
/*
|
||||
* A4 的多入边是**异或汇合**:上游互斥(A1/A2/A3 的条件路径),只会来一条,
|
||||
* 同名映射天然无歧义 —— 这正是显式汇合点(G2J)被删掉的原因。
|
||||
* 回边(A5 驳回 / A6 有异议)不算并发入边。
|
||||
*/
|
||||
it('A4 三条正向入边互斥合法,两条回边都标 reopen', () => {
|
||||
const ins = MVP_PACKAGE.edges.filter((e) => e.to === 'A4');
|
||||
expect(ins.filter((e) => !e.reopen).map((e) => e.from).sort()).toEqual(['A1', 'A2', 'A3']);
|
||||
expect(ins.filter((e) => e.reopen).map((e) => e.from).sort()).toEqual(['A5', 'A6']);
|
||||
});
|
||||
|
||||
it('两条回边都标了 reopen:审批驳回与议价有异议,都回 A4 重开', () => {
|
||||
expect(MVP_PACKAGE.edges.filter((e) => e.reopen).map((e) => `${e.from}→${e.to}`).sort()).toEqual([
|
||||
'G3→A4',
|
||||
'G4→A4',
|
||||
it('A6 三条条件出边 —— outcome 由放行选口给出', () => {
|
||||
const outs = MVP_PACKAGE.edges.filter((e) => e.from === 'A6');
|
||||
expect(outs.map((e) => `${e.to}:${e.condition ?? ''}`).sort()).toEqual([
|
||||
'A4:outcome = "revise"',
|
||||
'A7:outcome = "lost"',
|
||||
'end_won:outcome = "won"',
|
||||
]);
|
||||
});
|
||||
|
||||
it('网关条件按判据写:G1/G2 读旗,G3 读裁决,G4 读 outcome', () => {
|
||||
const cond = (from: string, to: string) => MVP_PACKAGE.edges.find((e) => e.from === from && e.to === to)?.condition;
|
||||
expect(cond('G1', 'A2')).toBe('needAlternative = true');
|
||||
expect(cond('G2', 'G2J')).toBe('needSourcing = false');
|
||||
expect(cond('G3', 'A6')).toBe('verdict = "pass"');
|
||||
expect(cond('G4', 'A7')).toBe('outcome = "lost"');
|
||||
});
|
||||
|
||||
it('手绘图存证在包上 —— 15 语义节点 + 两枚卡点', () => {
|
||||
expect(MVP_PACKAGE.diagram).toBeDefined();
|
||||
it('手绘图存证:10 语义节点 + 4 卡点(直达两枚是正向边的呈现,回跳两枚照旧)', () => {
|
||||
const nodes = (MVP_PACKAGE.diagram as { nodes: { id: string; kind: string }[] }).nodes;
|
||||
expect(nodes.filter((n) => n.kind === 'callout')).toHaveLength(2);
|
||||
expect(nodes).toHaveLength(17);
|
||||
// 语义节点在图上一个不少(卡点是呈现,不入语义)
|
||||
expect(nodes.filter((n) => n.kind === 'callout')).toHaveLength(4);
|
||||
expect(nodes).toHaveLength(14);
|
||||
const drawn = new Set(nodes.map((n) => n.id));
|
||||
for (const n of MVP_PACKAGE.nodes) expect(drawn.has(n.id), `图上缺 ${n.id}`).toBe(true);
|
||||
});
|
||||
|
||||
/*
|
||||
* 几何自查:重排的收益要能验证,不能只写在注释里。
|
||||
* 手绘尺寸见 `apps/web/src/shared/gov/flow/flow-layout.ts` 的 MANUAL_SIZES。
|
||||
* 语义边必须**每条都画在图上**(直连线,或指向带 `to` 卡点的线)——
|
||||
* 画布保存由画出来的边反推语义边,没画的那条会在第一次存盘时被静默丢掉
|
||||
* (实测:A1→A3「直接寻源」漏画,mergeGraphIntoPackage 一过就没了)。
|
||||
*/
|
||||
it('几何:坐标吸附 10px 珊格,同带内框不重叠', () => {
|
||||
it('图边对账:每条语义边都有画出来的对应(直连或经卡点)', () => {
|
||||
const dia = MVP_PACKAGE.diagram as {
|
||||
nodes: { id: string; kind: string; to?: string }[];
|
||||
edges: { from: string; to: string }[];
|
||||
};
|
||||
const calloutTo = new Map(dia.nodes.filter((n) => n.kind === 'callout').map((n) => [n.id, n.to]));
|
||||
const drawnPairs = new Set(dia.edges.map((e) => `${e.from}→${calloutTo.get(e.to) ?? e.to}`));
|
||||
for (const e of MVP_PACKAGE.edges) {
|
||||
expect(drawnPairs.has(`${e.from}→${e.to}`), `语义边 ${e.id}(${e.from}→${e.to})没画在图上`).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('几何:坐标吸附 10px 珊格,框不重叠', () => {
|
||||
const nodes = (MVP_PACKAGE.diagram as { nodes: { id: string; kind: string; x: number; y: number }[] }).nodes;
|
||||
const size = (kind: string) =>
|
||||
kind === 'gateway' ? { w: 40, h: 40 }
|
||||
: kind === 'callout' ? { w: 100, h: 30 }
|
||||
: kind === 'activity' ? { w: 100, h: 40 }
|
||||
: { w: 20, h: 20 };
|
||||
|
||||
kind === 'callout' ? { w: 100, h: 30 } : kind === 'activity' ? { w: 100, h: 40 } : { w: 20, h: 20 };
|
||||
for (const n of nodes) {
|
||||
expect(n.x % 10, `${n.id} 的 x 未吸附珊格`).toBe(0);
|
||||
expect(n.y % 10, `${n.id} 的 y 未吸附珊格`).toBe(0);
|
||||
expect(n.x % 10, `${n.id} x`).toBe(0);
|
||||
expect(n.y % 10, `${n.id} y`).toBe(0);
|
||||
}
|
||||
|
||||
// 两两不重叠(轴对齐矩形相交判定)
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
for (let j = i + 1; j < nodes.length; j += 1) {
|
||||
const a = nodes[i]!;
|
||||
const b = nodes[j]!;
|
||||
const sa = size(a.kind);
|
||||
const sb = size(b.kind);
|
||||
const overlap =
|
||||
a.x < b.x + sb.w && a.x + sa.w > b.x && a.y < b.y + sb.h && a.y + sa.h > b.y;
|
||||
expect(overlap, `${a.id} 与 ${b.id} 的框重叠`).toBe(false);
|
||||
const overlap = a.x < b.x + sb.w && a.x + sa.w > b.x && a.y < b.y + sb.h && a.y + sa.h > b.y;
|
||||
expect(overlap, `${a.id} 与 ${b.id} 重叠`).toBe(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+121
-207
@@ -1,25 +1,12 @@
|
||||
/**
|
||||
* 「统一报价」流程包 —— 语义取自 `docs/MVP示例工作流.html` 的 FIG.1,几何**重排过**。
|
||||
* 「统一报价」流程包 —— **无网关**:语义取自 `docs/MVP示例工作流.html`,结构按新模型展开。
|
||||
*
|
||||
* 语义 15 节点:起点 · A1 · G1 · A2 · G2 · A3 · G2J · A4 · **A5 审批点** · G3 · A6 · G4 · A7 · 双终点。
|
||||
* 分支 = 源节点的条件出边(恰取一条,无条件边作默认兜底);汇合 = 多入边异或。
|
||||
* FIG.1 的 G1/G2/G4 各自消失成 A1/A2/A6 的条件出边;G2J 与 G3 整颗不再需要。
|
||||
* 10 节点 14 边;审批点 A5 的两个去向就是它自己的两条条件出边(verdict 由引擎注入)。
|
||||
*
|
||||
* 与 FIG.1 的两处语义差异:
|
||||
* · **多一颗 G2J**:G2 的两条互斥分支必须显式汇合 —— FIG.1 把它画成两条线各扎进 A4,
|
||||
* 语义上那是隐式合并,闭合校验不收(见下 joinNode 注释)。
|
||||
* · **A5 是内置审批点**(审批不是任务,零开发、不入活动库),而 FIG.1 给它配了作业指导书。
|
||||
*
|
||||
* G3「审批结果」曾被我做掉过,理由是「审批点把它吸收了:通过走出边、驳回走 reject 声明」。
|
||||
* **那是错的** —— 审批点的两个去向本该由图决定(BPMN 的常规,也是用户要的)。
|
||||
* 现已补回,并且引擎跟着改成**先看图**:`onApprovalVerdict` 把裁决放进载荷,
|
||||
* 通过与驳回都先试出边,只有没画驳回边的包才退回 `reject` 声明。
|
||||
* 所以 G3 的两条出边都是**真的会走**的,不是摆设 —— 没有给条件喂常量。
|
||||
*
|
||||
* `reject` 声明仍保留:schema 必填,且它是通用机制(不是每个包都把驳回画成边)。
|
||||
* 它与 `e-g3-a4` 必须字字对齐,有测试守着。
|
||||
*
|
||||
* 几何是**重排**,不再逐点等于 SVG:两带换行(受理·选型·寻源 → 定价·审批·议价·成交),
|
||||
* 每带内 x 随推进次序单调递增,全图零连线交叉、零穿框。回跳仍用**卡点**表示(不画长线),
|
||||
* 卡点带 `to`,`mergeGraphIntoPackage` 会把「X → 卡点(to: Y)」还原成语义边,编辑器保存不丢回边。
|
||||
* 几何:两带换行、零交叉;直达与回跳都用**卡点**表达(不画长线)——
|
||||
* 卡点带 `to`,`mergeGraphIntoPackage` 只认语义边已存在的还原,编辑器保存不丢边。
|
||||
*/
|
||||
import { processPackageSchema, triggerConfigSchema } from '@contracts';
|
||||
import type { ProcessPackage } from '@contracts';
|
||||
@@ -46,32 +33,6 @@ const activityNode = (
|
||||
layout: { row, col, x, y },
|
||||
});
|
||||
|
||||
/** 判断网关:异或分叉,判据人读、条件在出边 */
|
||||
const gatewayNode = (id: string, label: string, basis: string, col: number, row: number, x: number, y: number) => ({
|
||||
id,
|
||||
kind: 'gateway' as const,
|
||||
label,
|
||||
gateway: 'exclusive' as const,
|
||||
mode: 'fork' as const,
|
||||
basis,
|
||||
layout: { row, col, x, y },
|
||||
});
|
||||
|
||||
/**
|
||||
* 异或汇合点 —— 两条互斥分支重新并回一条路。
|
||||
*
|
||||
* MVP 图上这里是两条线各自扎进 A4(隐式合并);语义上必须显式:
|
||||
* 不给汇合点,A4 就有两条同名映射的入边,闭合校验按「不做隐式合并」拦下(实测)。
|
||||
* 分叉必有汇合是 BPMN 的正解,本仓 v1 的 G2/G2J 即此先例。
|
||||
*/
|
||||
const joinNode = (id: string, label: string, col: number, row: number, x: number, y: number) => ({
|
||||
id,
|
||||
kind: 'gateway' as const,
|
||||
label,
|
||||
gateway: 'exclusive' as const,
|
||||
mode: 'join' as const,
|
||||
layout: { row, col, x, y },
|
||||
});
|
||||
|
||||
/** 受理口的两枚去向旗与记录 —— A4 重新入场(回边 / 驳回)时照此装配 */
|
||||
const REENTER_A4 = [
|
||||
@@ -99,27 +60,21 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
|
||||
output: { type: 'object', properties: { landingRate: { type: 'number' } } },
|
||||
},
|
||||
/*
|
||||
* 版式:**两带换行**,不回形。`col` 用全局最长路径层级(0..13),每一带内 x 随 col 单调递增,
|
||||
* 所以「左→右、上→下」读出来就是推进次序 —— 图纸不再需要被当成次序的依据
|
||||
* (`advanceOrder` 早已改按边拓扑排,这里让两者一致只是为了不误导人)。
|
||||
* **无网关**(产品决策 2026-07-28):分支 = 源节点的多条条件出边(恰取一条,
|
||||
* 无条件边作默认兜底),汇合 = 多入边异或(上游互斥,只会来一条)。
|
||||
* 与 Mastra 同构:条件挂在步与步之间,步保持纯粹。
|
||||
* FIG.1 的 G1/G2/G4 于是各自消失成 A1/A2/A6 的条件出边;
|
||||
* G2J(当年为绕「隐式合并」禁令而生的显式汇合点)与 G3(审批结果)整颗不再需要 ——
|
||||
* A4 的三条正向入边互斥即合法,A5 的裁决就是它自己的两条条件出边。
|
||||
*
|
||||
* 带 0(y 60..100) start → A1 → G1 → A2 → G2 → A3 → G2J 受理 · 选型 · 寻源
|
||||
* 换行车道 y=190 G2J 右探 40 再降下来,横扫回左,落 A4 北口
|
||||
* 带 1(y 310..350) A4 → A5 → G3 → A6 → G4 → end_won 定价 · 审批 · 议价 · 成交
|
||||
* 卡点车道 y=250..280 两枚回 A4 的牌子同朝向(向上 = 回退)
|
||||
* 带 2(y 410..450) A7 → end_arch 未成交闭环
|
||||
*
|
||||
* 注:工厂的参数序是 **col 在 row 前**(activityNode(..., col, row, x, y))。
|
||||
* 10 节点:start · A1 受理 · A2 选型 · A3 寻源 · A4 定价 · A5 审批 · A6 议价 · A7 归档 · 双终点。
|
||||
*/
|
||||
nodes: [
|
||||
{ id: 'start', kind: 'start', label: '客户RFQ询价', layout: { row: 0, col: 0, x: 30, y: 70 } },
|
||||
activityNode('A1', '客户RFQ受理', 'rfq-intake', 'BD', 1, 0, 90, 60),
|
||||
gatewayNode('G1', '是否需要选型', '受理判定:该条是否要先选替代料(needAlternative)', 2, 0, 250, 60),
|
||||
activityNode('A2', '替代选型', 'alt-selection', 'FAE', 3, 0, 350, 60),
|
||||
gatewayNode('G2', '是否需要寻源', '受理判定:该条是否要向渠道询底价(needSourcing)', 4, 0, 510, 60),
|
||||
activityNode('A3', '寻源询价', 'sourcing-inquiry', 'PRM', 5, 0, 610, 60),
|
||||
joinNode('G2J', '寻源汇合', 6, 0, 770, 60),
|
||||
activityNode('A4', '成本定价', 'cost-pricing', 'BD', 7, 1, 60, 310),
|
||||
activityNode('A1', '客户RFQ受理', 'rfq-intake', 'BD', 1, 0, 110, 60),
|
||||
activityNode('A2', '替代选型', 'alt-selection', 'FAE', 2, 0, 290, 60),
|
||||
activityNode('A3', '寻源询价', 'sourcing-inquiry', 'PRM', 3, 0, 470, 60),
|
||||
activityNode('A4', '成本定价', 'cost-pricing', 'BD', 4, 1, 110, 310),
|
||||
{
|
||||
id: 'A5',
|
||||
kind: 'approval',
|
||||
@@ -128,21 +83,18 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
|
||||
approver: { position: 'PM', strategy: 'sole' },
|
||||
/*
|
||||
* 驳回走向声明式,不由临场决定:退回 A4 重新定价。
|
||||
* 图上由 G3「审批结果」的 `verdict = "reject"` 出边**显式表达同一件事**,
|
||||
* 而引擎现在是**先看图**(见 `onApprovalVerdict`):有这条边就走边,没有才退回本声明。
|
||||
* 两处必须字字对齐 —— 有测试守着。本声明不能删:schema 必填,
|
||||
* 且它是通用机制(不是每个流程包都把驳回画成边)。
|
||||
* 图上由 A5 自己的 `verdict = "reject"` 条件出边**显式表达同一件事**,
|
||||
* 引擎先看图(有边走边,没边才退回本声明),两处须字字对齐 —— 有测试守着。
|
||||
* 本声明不能删:schema 必填,且它是通用机制(不是每条流都把驳回画成边)。
|
||||
*/
|
||||
reject: { kind: 'reopen', nodeId: 'A4', mapping: REENTER_A4 },
|
||||
nudge: { steps: [{ after: 'PT20M', action: 'nudge' }], deadline: 'PT30M' },
|
||||
layout: { row: 1, col: 8, x: 240, y: 310 },
|
||||
layout: { row: 1, col: 5, x: 290, y: 310 },
|
||||
},
|
||||
gatewayNode('G3', '审批结果', 'A5 裁决的去向:通过 / 不通过(verdict)—— 偏离底价 ≤±20% 才放行(底价门禁P-02)', 9, 1, 380, 310),
|
||||
activityNode('A6', '报价议价', 'quote-negotiation', 'BD', 10, 1, 460, 310),
|
||||
gatewayNode('G4', '议价结果', 'A6 办结的去向:成交 / 有异议 / 拒绝或超时(outcome)', 11, 1, 620, 310),
|
||||
activityNode('A7', '情报归档', 'intel-archive', 'BD', 12, 2, 590, 410),
|
||||
{ id: 'end_won', kind: 'end', label: '转订单履约', layout: { row: 1, col: 12, x: 700, y: 320 } },
|
||||
{ id: 'end_arch', kind: 'end', label: '归档闭环', layout: { row: 2, col: 13, x: 730, y: 420 } },
|
||||
activityNode('A6', '报价议价', 'quote-negotiation', 'BD', 6, 1, 470, 310),
|
||||
activityNode('A7', '情报归档', 'intel-archive', 'BD', 7, 2, 630, 410),
|
||||
{ id: 'end_won', kind: 'end', label: '转订单履约', layout: { row: 1, col: 7, x: 630, y: 320 } },
|
||||
{ id: 'end_arch', kind: 'end', label: '归档闭环', layout: { row: 2, col: 8, x: 790, y: 420 } },
|
||||
],
|
||||
edges: [
|
||||
{
|
||||
@@ -152,80 +104,73 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
|
||||
mapping: [
|
||||
{ target: 'customerCode', source: { from: 'initiation', path: 'customerCode' } },
|
||||
{ target: 'rfqRef', source: { from: 'initiation', path: 'rfqRef' } },
|
||||
// 主题与正文是归一步唯一的原始素材:只给单号,模型没有可拆解的东西
|
||||
{ target: 'subject', source: { from: 'initiation', path: 'subject' } },
|
||||
{ target: 'body', source: { from: 'initiation', path: 'body' } },
|
||||
{ target: 'quotedAt', source: { from: 'initiation', path: 'quotedAt' } },
|
||||
],
|
||||
reopen: false,
|
||||
},
|
||||
{ id: 'e-a1-g1', from: 'A1', to: 'G1', mapping: [], label: '统一受理记录', reopen: false },
|
||||
|
||||
/* A1 的三条出边 —— 原 G1「是否需要选型」+ G2「是否需要寻源」在直达路径上的合并展开 */
|
||||
{
|
||||
id: 'e-g1-a2',
|
||||
from: 'G1',
|
||||
id: 'e-a1-a2',
|
||||
from: 'A1',
|
||||
to: 'A2',
|
||||
condition: 'needAlternative = true',
|
||||
label: '需要选型',
|
||||
mapping: [
|
||||
{ target: 'material', source: { from: 'output-port', port: 'intake', path: 'pn' } },
|
||||
// 选型完了还要不要寻源,这枚旗得跟着走 —— G2 在本路径上读的是 A2 的载荷
|
||||
{ target: 'needSourcing', source: { from: 'output-port', port: 'intake', path: 'needSourcing' } },
|
||||
/*
|
||||
* 询价单号也要带上:A2 办结时要把 `needSourcing` 回写「受理结论」那一行,
|
||||
* 而那一行的主键就是询价单号。不带,A2 就只能另起一行(或写出无主键的行,
|
||||
* 合并进正式版时被非空约束挡下)—— 去向便有了两个出处,G2 读哪个都不对。
|
||||
*/
|
||||
{ target: 'rfqRef', source: { from: 'initiation', path: 'rfqRef' } },
|
||||
],
|
||||
reopen: false,
|
||||
},
|
||||
{ id: 'e-g1-g2', from: 'G1', to: 'G2', condition: 'needAlternative = false', label: '不需要选型', mapping: [], reopen: false },
|
||||
{ id: 'e-a2-g2', from: 'A2', to: 'G2', mapping: [], label: '替代对标表', reopen: false },
|
||||
{
|
||||
id: 'e-g2-a3',
|
||||
from: 'G2',
|
||||
id: 'e-a1-a3',
|
||||
from: 'A1',
|
||||
to: 'A3',
|
||||
condition: 'needSourcing = true',
|
||||
label: '需要寻源',
|
||||
condition: 'needAlternative = false and needSourcing = true',
|
||||
label: '直接寻源',
|
||||
mapping: [{ target: 'pn', source: { from: 'output-port', port: 'intake', path: 'pn' } }],
|
||||
reopen: false,
|
||||
},
|
||||
// 默认兜底:不选型不寻源 → 直接定价(条件全不中时走它,旗齐时它就是第三种情形)
|
||||
{ id: 'e-a1-a4', from: 'A1', to: 'A4', label: '直接定价', mapping: REENTER_A4, reopen: false },
|
||||
|
||||
/* A2 的两条出边 —— 原 G2 在选型路径上的那一问 */
|
||||
{
|
||||
id: 'e-g2-j',
|
||||
from: 'G2',
|
||||
to: 'G2J',
|
||||
condition: 'needSourcing = false',
|
||||
label: '不需要寻源',
|
||||
mapping: [],
|
||||
id: 'e-a2-a3',
|
||||
from: 'A2',
|
||||
to: 'A3',
|
||||
condition: 'needSourcing = true',
|
||||
label: '仍需寻源',
|
||||
mapping: [{ target: 'pn', source: { from: 'output-port', port: 'intake', path: 'pn' } }],
|
||||
reopen: false,
|
||||
},
|
||||
{ id: 'e-a3-j', from: 'A3', to: 'G2J', mapping: [], label: '供应商底价表', reopen: false },
|
||||
{ id: 'e-a2-a4', from: 'A2', to: 'A4', label: '选型后定价', mapping: REENTER_A4, reopen: false },
|
||||
|
||||
{
|
||||
id: 'e-j-a4',
|
||||
from: 'G2J',
|
||||
id: 'e-a3-a4',
|
||||
from: 'A3',
|
||||
to: 'A4',
|
||||
label: '供应商底价表',
|
||||
mapping: [
|
||||
...REENTER_A4,
|
||||
// 底价只在寻源那条路上有;直通路径取不到即为空,A4 的 floors 非必填
|
||||
// 底价只在寻源路径上有;A1/A2 直达的两条边不带它,A4 的 floors 非必填
|
||||
{ target: 'floors', source: { from: 'output-port', port: 'compare', path: 'floors' } },
|
||||
],
|
||||
reopen: false,
|
||||
},
|
||||
{ id: 'e-a4-a5', from: 'A4', to: 'A5', mapping: [], label: '报价草案提审', reopen: false },
|
||||
/*
|
||||
* 审批点 → 网关:**审批的两个去向都由图决定**(BPMN 的常规)。
|
||||
* 判据 `verdict` 由引擎在裁决时放进载荷(`onApprovalVerdict`),不是这条边喂的常量 ——
|
||||
* 喂常量能让闸过、让流跑,但那样 G3 的条件恒真、驳回边永不可达,网关就成了摆设。
|
||||
*/
|
||||
{ id: 'e-a5-g3', from: 'A5', to: 'G3', mapping: [], reopen: false },
|
||||
|
||||
/* A5 审批点自己的两条条件出边 —— 裁决(verdict)由引擎在裁决时放进载荷 */
|
||||
{
|
||||
id: 'e-g3-a6',
|
||||
from: 'G3',
|
||||
id: 'e-a5-a6',
|
||||
from: 'A5',
|
||||
to: 'A6',
|
||||
condition: 'verdict = "pass"',
|
||||
label: '通过',
|
||||
tone: 'ok',
|
||||
// 原 e-a5-a6 的装配原样搬来:draft 口是 A4 落的,一直在 record.ports 里
|
||||
mapping: [
|
||||
{ target: 'rows', source: { from: 'output-port', port: 'draft', path: 'rows' } },
|
||||
{ target: 'quote_no', source: { from: 'output-port', port: 'draft', path: 'quote_no' } },
|
||||
@@ -234,25 +179,21 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
|
||||
reopen: false,
|
||||
},
|
||||
{
|
||||
id: 'e-g3-a4',
|
||||
from: 'G3',
|
||||
id: 'e-a5-a4',
|
||||
from: 'A5',
|
||||
to: 'A4',
|
||||
condition: 'verdict = "reject"',
|
||||
label: '不通过',
|
||||
tone: 'bad',
|
||||
mapping: REENTER_A4,
|
||||
/*
|
||||
* 回边:与 A5 的 `reject` 声明同一去向(回 A4 重开新实例),两处须一致。
|
||||
* `reopen` 必须为 true —— 标 false 则 A4 有两条**并发**入边(G2J 与 G3),
|
||||
* records / customerCode 同名双源,闭合校验按「汇合同名字段来源不明」拦下发布;
|
||||
* 拓扑序也会成环,流程链会读反。
|
||||
*/
|
||||
// 回边:与 A5 的 reject 声明同一去向;reopen 必标,否则成环、拓扑序崩
|
||||
reopen: true,
|
||||
},
|
||||
{ id: 'e-a6-g4', from: 'A6', to: 'G4', mapping: [], label: '正式报价单', reopen: false },
|
||||
|
||||
/* A6 的三条条件出边 —— outcome 由放行选口给出(选择组恰选一口) */
|
||||
{
|
||||
id: 'e-g4-won',
|
||||
from: 'G4',
|
||||
id: 'e-a6-won',
|
||||
from: 'A6',
|
||||
to: 'end_won',
|
||||
condition: 'outcome = "won"',
|
||||
label: '成交',
|
||||
@@ -261,25 +202,24 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
|
||||
reopen: false,
|
||||
},
|
||||
{
|
||||
id: 'e-g4-a4',
|
||||
from: 'G4',
|
||||
id: 'e-a6-a4',
|
||||
from: 'A6',
|
||||
to: 'A4',
|
||||
condition: 'outcome = "revise"',
|
||||
label: '有异议',
|
||||
tone: 'bad',
|
||||
mapping: REENTER_A4,
|
||||
// 回边:人裁决后重开新任务实例(同节点、新任务 ID、留痕关联)
|
||||
reopen: true,
|
||||
},
|
||||
{
|
||||
id: 'e-g4-a7',
|
||||
from: 'G4',
|
||||
id: 'e-a6-a7',
|
||||
from: 'A6',
|
||||
to: 'A7',
|
||||
condition: 'outcome = "lost"',
|
||||
label: '拒绝/超时',
|
||||
tone: 'bad',
|
||||
mapping: [
|
||||
// outcome 不是 formal 口声明的字段 —— 它由放行选口注入落地事实,随每个发射口的载荷同行
|
||||
// outcome 由放行选口注入落地事实,随每个发射口的载荷同行(不是 formal 声明的字段)
|
||||
{ target: 'outcome', source: { from: 'output-port', port: 'formal', path: 'outcome' } },
|
||||
{ target: 'quote_no', source: { from: 'output-port', port: 'formal', path: 'quote_no' } },
|
||||
{ target: 'customer_code', source: { from: 'output-port', port: 'formal', path: 'customer_code' } },
|
||||
@@ -291,9 +231,13 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
|
||||
],
|
||||
variables: [],
|
||||
/*
|
||||
* 手绘几何存证 —— 呈现以它为真相(不走自动布局)。
|
||||
* 几何是重排后的两带换行(见 nodes 上方的版式说明),不再逐点等于 MVP 的 SVG;
|
||||
* 卡点是回跳的呈现(带 to,不画长线)。
|
||||
* 手绘几何存证 —— 呈现以它为真相。两带换行、零交叉:
|
||||
* 顶车道 y30:A1「直接寻源」跨过 A2 直达 A3(带上方,不碰任何框)
|
||||
* 带 0(y60) start → A1 → A2 → A3 受理 · 选型 · 寻源
|
||||
* 换行车道 y190:A3 右探下折横扫回左,进 A4 北口
|
||||
* 带 1(y310) A4 → A5 → A6 → end_won 定价 · 审批 · 议价 · 成交
|
||||
* 带 2(y410) A7 → end_arch 未成交闭环
|
||||
* 直达与回跳都用**卡点**表达(不画长线):A1/A2 的「直接定价」牌与 A5/A6 的回 A4 牌。
|
||||
*/
|
||||
diagram: {
|
||||
manual: true,
|
||||
@@ -301,93 +245,63 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
|
||||
anchors: [],
|
||||
nodes: [
|
||||
{ id: 'start', kind: 'start', label: '客户RFQ询价', x: 30, y: 70, lx: 44, ly: 104 },
|
||||
{ id: 'A1', kind: 'activity', label: '客户RFQ受理', code: 'A1', owner: 'BD', x: 90, y: 60 },
|
||||
{ id: 'G1', kind: 'gateway', label: '是否需要选型', mode: 'x', x: 250, y: 60, lx: 270, ly: 112 },
|
||||
{ id: 'A2', kind: 'activity', label: '替代选型', code: 'A2', owner: 'FAE', flavor: 'case', x: 350, y: 60 },
|
||||
// 旁注左偏:正下方 x=530 有「不需要寻源」的竖段穿过
|
||||
{ id: 'G2', kind: 'gateway', label: '是否需要寻源', mode: 'x', x: 510, y: 60, lx: 480, ly: 112 },
|
||||
{ id: 'A3', kind: 'activity', label: '寻源询价', code: 'A3', owner: 'PRM', flavor: 'case', x: 610, y: 60 },
|
||||
{ id: 'G2J', kind: 'gateway', label: '寻源汇合', mode: 'x', x: 770, y: 60, lx: 750, ly: 112 },
|
||||
{ id: 'A4', kind: 'activity', label: '成本定价', code: 'A4', owner: 'BD', x: 60, y: 310 },
|
||||
{ id: 'A5', kind: 'activity', label: '定价审批', code: 'A5', owner: 'PM', flavor: 'approval', x: 240, y: 310 },
|
||||
{ id: 'G3', kind: 'gateway', label: '审批结果', mode: 'x', x: 380, y: 310, lx: 400, ly: 368 },
|
||||
{ id: 'A6', kind: 'activity', label: '报价议价', code: 'A6', owner: 'BD', flavor: 'case', x: 460, y: 310 },
|
||||
// 旁注斜下:G4 四个口全占着线
|
||||
{ id: 'G4', kind: 'gateway', label: '议价结果', mode: 'x', x: 620, y: 310, lx: 590, ly: 368 },
|
||||
{ id: 'A7', kind: 'activity', label: '情报归档', code: 'A7', owner: 'BD', x: 590, y: 410 },
|
||||
{ id: 'end_won', kind: 'end', label: '转订单履约', x: 700, y: 320, lx: 710, ly: 352 },
|
||||
{ id: 'end_arch', kind: 'end-bad', label: '归档闭环', x: 730, y: 420, lx: 740, ly: 452 },
|
||||
// 两枚回 A4 的牌子同一条车道、同朝向(向上 = 回退):G3 上方与 G4 上方
|
||||
{ id: 'c_reject', kind: 'callout', label: '退回调整', to: 'A4', x: 350, y: 250 },
|
||||
{ id: 'c_revise', kind: 'callout', label: '返回调整', to: 'A4', x: 590, y: 250 },
|
||||
{ id: 'A1', kind: 'activity', label: '客户RFQ受理', code: 'A1', owner: 'BD', x: 110, y: 60 },
|
||||
{ id: 'A2', kind: 'activity', label: '替代选型', code: 'A2', owner: 'FAE', flavor: 'case', x: 290, y: 60 },
|
||||
{ id: 'A3', kind: 'activity', label: '寻源询价', code: 'A3', owner: 'PRM', flavor: 'case', x: 470, y: 60 },
|
||||
{ id: 'A4', kind: 'activity', label: '成本定价', code: 'A4', owner: 'BD', x: 110, y: 310 },
|
||||
{ id: 'A5', kind: 'activity', label: '定价审批', code: 'A5', owner: 'PM', flavor: 'approval', x: 290, y: 310 },
|
||||
{ id: 'A6', kind: 'activity', label: '报价议价', code: 'A6', owner: 'BD', flavor: 'case', x: 470, y: 310 },
|
||||
{ id: 'A7', kind: 'activity', label: '情报归档', code: 'A7', owner: 'BD', x: 630, y: 410 },
|
||||
{ id: 'end_won', kind: 'end', label: '转订单履约', x: 630, y: 320, lx: 640, ly: 352 },
|
||||
{ id: 'end_arch', kind: 'end-bad', label: '归档闭环', x: 790, y: 420, lx: 800, ly: 452 },
|
||||
/* 四枚卡点:直达两枚(正向,语义边真实存在)、回跳两枚 —— 全在各自源节点的上下车道 */
|
||||
{ id: 'c_d1', kind: 'callout', label: '直接定价', to: 'A4', x: 110, y: 170 },
|
||||
{ id: 'c_d2', kind: 'callout', label: '选型后定价', to: 'A4', x: 290, y: 170 },
|
||||
{ id: 'c_reject', kind: 'callout', label: '退回调整', to: 'A4', x: 290, y: 240 },
|
||||
{ id: 'c_revise', kind: 'callout', label: '返回调整', to: 'A4', x: 470, y: 240 },
|
||||
],
|
||||
edges: [
|
||||
{ from: 'start', to: 'A1', points: [{ x: 50, y: 80 }, { x: 90, y: 80 }] },
|
||||
{ from: 'A1', to: 'G1', label: '统一受理记录', points: [{ x: 190, y: 80 }, { x: 250, y: 80 }] },
|
||||
{ from: 'G1', to: 'A2', label: '需要选型', points: [{ x: 290, y: 80 }, { x: 350, y: 80 }] },
|
||||
// 不需要选型:从 G1 北口翻过 A2 头顶(y=20 车道)
|
||||
{ from: 'start', to: 'A1', points: [{ x: 50, y: 80 }, { x: 110, y: 80 }] },
|
||||
{ from: 'A1', to: 'A2', label: '需要选型', points: [{ x: 210, y: 80 }, { x: 290, y: 80 }] },
|
||||
// 直接寻源走顶车道 y30(A1 北口 → A3 北口):画布保存只认画出来的边,这条不画就会丢
|
||||
{
|
||||
from: 'G1',
|
||||
to: 'G2',
|
||||
label: '不需要选型',
|
||||
points: [{ x: 270, y: 60 }, { x: 270, y: 20 }, { x: 530, y: 20 }, { x: 530, y: 60 }],
|
||||
},
|
||||
{ from: 'A2', to: 'G2', label: '替代对标表', points: [{ x: 450, y: 80 }, { x: 510, y: 80 }] },
|
||||
{ from: 'G2', to: 'A3', label: '需要寻源', points: [{ x: 550, y: 80 }, { x: 610, y: 80 }] },
|
||||
// 不需要寻源:从 G2 南口穿过 A3 脚下(y=150 车道)扎进 G2J 南口
|
||||
{
|
||||
from: 'G2',
|
||||
to: 'G2J',
|
||||
label: '不需要寻源',
|
||||
points: [{ x: 530, y: 100 }, { x: 530, y: 150 }, { x: 790, y: 150 }, { x: 790, y: 100 }],
|
||||
},
|
||||
{ from: 'A3', to: 'G2J', label: '供应商底价表', points: [{ x: 710, y: 80 }, { x: 770, y: 80 }] },
|
||||
// 换行那一笔:右探 40 → 降到 190 车道 → 横扫回左 → 落 A4 北口
|
||||
{
|
||||
from: 'G2J',
|
||||
to: 'A4',
|
||||
from: 'A1',
|
||||
to: 'A3',
|
||||
label: '直接寻源',
|
||||
points: [
|
||||
{ x: 810, y: 80 },
|
||||
{ x: 850, y: 80 },
|
||||
{ x: 850, y: 190 },
|
||||
{ x: 110, y: 190 },
|
||||
{ x: 110, y: 310 },
|
||||
{ x: 160, y: 60 },
|
||||
{ x: 160, y: 30 },
|
||||
{ x: 520, y: 30 },
|
||||
{ x: 520, y: 60 },
|
||||
],
|
||||
},
|
||||
{ from: 'A4', to: 'A5', label: '报价草案提审', points: [{ x: 160, y: 330 }, { x: 240, y: 330 }] },
|
||||
{ from: 'A5', to: 'G3', points: [{ x: 340, y: 330 }, { x: 380, y: 330 }] },
|
||||
{ from: 'G3', to: 'A6', label: '通过', tone: 'ok', points: [{ x: 420, y: 330 }, { x: 460, y: 330 }] },
|
||||
// 驳回:卡点(不画长线);语义边 e-g3-a4 在包里,存盘会被 mergeGraphIntoPackage 认回
|
||||
{ from: 'A2', to: 'A3', label: '仍需寻源', points: [{ x: 390, y: 80 }, { x: 470, y: 80 }] },
|
||||
// 换行那一笔:A3 右探 → 降到 190 车道 → 横扫回左 → 落 A4 北口
|
||||
{
|
||||
from: 'G3',
|
||||
to: 'c_reject',
|
||||
label: '不通过',
|
||||
tone: 'bad',
|
||||
points: [{ x: 400, y: 310 }, { x: 400, y: 280 }],
|
||||
lx: 370,
|
||||
ly: 296,
|
||||
from: 'A3',
|
||||
to: 'A4',
|
||||
label: '供应商底价表',
|
||||
// 标注钉在 y190 车道的空档(x390–610)—— 默认取折线中点,会被「选型后定价→A4」卡点压住
|
||||
lx: 450,
|
||||
ly: 183,
|
||||
points: [
|
||||
{ x: 570, y: 80 },
|
||||
{ x: 610, y: 80 },
|
||||
{ x: 610, y: 190 },
|
||||
{ x: 160, y: 190 },
|
||||
{ x: 160, y: 310 },
|
||||
],
|
||||
},
|
||||
{ from: 'A6', to: 'G4', label: '正式报价单', points: [{ x: 560, y: 330 }, { x: 620, y: 330 }] },
|
||||
{ from: 'G4', to: 'end_won', label: '成交', tone: 'ok', points: [{ x: 660, y: 330 }, { x: 700, y: 330 }] },
|
||||
{
|
||||
from: 'G4',
|
||||
to: 'c_revise',
|
||||
label: '有异议',
|
||||
tone: 'bad',
|
||||
points: [{ x: 640, y: 310 }, { x: 640, y: 280 }],
|
||||
lx: 610,
|
||||
ly: 296,
|
||||
},
|
||||
{
|
||||
from: 'G4',
|
||||
to: 'A7',
|
||||
label: '拒绝/超时',
|
||||
tone: 'bad',
|
||||
points: [{ x: 640, y: 350 }, { x: 640, y: 410 }],
|
||||
lx: 670,
|
||||
ly: 380,
|
||||
},
|
||||
{ from: 'A7', to: 'end_arch', label: '归档闭环', points: [{ x: 690, y: 430 }, { x: 730, y: 430 }] },
|
||||
// 直达两枚卡点(正向):不选不寻 → 直接定价;选完不寻 → 定价
|
||||
{ from: 'A1', to: 'c_d1', label: '不选不寻', points: [{ x: 160, y: 100 }, { x: 160, y: 170 }] },
|
||||
{ from: 'A2', to: 'c_d2', label: '不再寻源', points: [{ x: 340, y: 100 }, { x: 340, y: 170 }] },
|
||||
{ from: 'A4', to: 'A5', label: '报价草案提审', points: [{ x: 210, y: 330 }, { x: 290, y: 330 }] },
|
||||
{ from: 'A5', to: 'A6', label: '通过', tone: 'ok', points: [{ x: 390, y: 330 }, { x: 470, y: 330 }] },
|
||||
{ from: 'A5', to: 'c_reject', label: '不通过', tone: 'bad', points: [{ x: 340, y: 310 }, { x: 340, y: 270 }], lx: 310, ly: 292 },
|
||||
{ from: 'A6', to: 'end_won', label: '成交', tone: 'ok', points: [{ x: 570, y: 330 }, { x: 630, y: 330 }] },
|
||||
{ from: 'A6', to: 'c_revise', label: '有异议', tone: 'bad', points: [{ x: 520, y: 310 }, { x: 520, y: 270 }], lx: 545, ly: 292 },
|
||||
{ from: 'A6', to: 'A7', label: '拒绝/超时', tone: 'bad', points: [{ x: 520, y: 350 }, { x: 520, y: 430 }, { x: 630, y: 430 }], lx: 545, ly: 388 },
|
||||
{ from: 'A7', to: 'end_arch', label: '归档闭环', points: [{ x: 730, y: 430 }, { x: 790, y: 430 }] },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -25,10 +25,16 @@
|
||||
被依赖: trigger, app(治理台 · 工作流管理)
|
||||
|
||||
不变量(OS 03 / 3.2):
|
||||
- **不闭合不得保存**:未完成边、必填未映射、类型冲突、孤立节点、异或出边缺条件、
|
||||
汇合同名字段来源不明、容忍分支被下游必填依赖 —— 任一即 `closed = false`,`savePackage` 抛 `NotClosedError`
|
||||
- **严格检查 + 保存即生效,没有发布机制**(产品决策 2026-07-28):
|
||||
没有草稿态、没有发布门。保存 = 存为新版 + 即刻生效。
|
||||
- **画图不检查,激活才查完整**(产品决策 2026-07-28):`savePackage` 不跑闭合校验,
|
||||
随手画的半成品也存得进来(存出来即 `retired`,不生效);`setPackageState` 激活时
|
||||
跑 `checkClosure`,不闭合抛 `NotClosedError`(HTTP 412 带整份报告)。
|
||||
违规项:未完成边、必填未映射、类型冲突、孤立节点、多默认出边、含网关、
|
||||
容忍分支被下游必填依赖 —— 任一即 `closed = false`,激活被拒。
|
||||
- **无网关**(产品决策 2026-07-28):分支 = 源节点的多条条件出边(恰取一条,
|
||||
无条件边作默认兜底、至多一条),汇合 = 多入边异或(上游互斥,只会来一条)。
|
||||
schema 仍收 `kind: 'gateway'` 只为读历史版本 —— 在途工作流照走(运行时兼容),
|
||||
但含网关的定义激活即 `gateway-deprecated` 违规,**仅可读,不可激活**。
|
||||
AND 并行暂无声明机制,将来以「并行组」加回(对应 Mastra `.parallel`,见 debt.md)。
|
||||
- **一条流恰一个生效版本**(产品决策 2026-07-28):`setPackageState` 激活即独占
|
||||
(同流其余版本一并停用);停用生效版 = 整条流下线,新起单被拒。
|
||||
起单取**生效版**;在途工作流按启动时钉住的版本号读定义 —— 启停对它们零影响。
|
||||
@@ -45,10 +51,12 @@
|
||||
|
||||
其它不变量:
|
||||
- **流转零 LLM**:选边与条件求值全部经 `@sfeel`;判定依据入事件记录
|
||||
- **XOR 恰取一条**:条件命中优先,无条件的边作默认分支兜底;
|
||||
- **多出边一律异或,不分节点种类**:条件命中优先(按声明序),无条件的边作默认兜底;
|
||||
一条都没中而该节点确有出边 = **死路**,发 `route-dead-end` 事件
|
||||
(哪个节点、各出边的条件、判据里当时有哪些键 —— 只记键名不记值)
|
||||
- **AND 汇合要回齐**:未回齐就不进汇合节点;容忍分支以「已消化」计,不阻汇合
|
||||
(哪个节点、各出边的条件、判据里当时有哪些键 —— 只记键名不记值)。
|
||||
审批点的裁决(`verdict`)由引擎注入判据,两个去向就是它自己的两条条件出边
|
||||
- **异或汇合不等**(`joinReady`):互斥分支结构上只会来一条,等齐 = 等一个不可能
|
||||
到来的分支,流会无声卡死;AND 回齐逻辑仅剩历史版本的并行网关在用,容忍分支以「已消化」计
|
||||
- **流程层不自动重试活动**(过程内重试归 Harness);
|
||||
流级重做一律人裁决后**重开新任务实例**
|
||||
- **驳回走向声明式**:审批点的驳回按 `reject` 声明回指定节点重开新实例,不由临场决定
|
||||
|
||||
@@ -126,7 +126,11 @@ describe('checkClosure —— 不闭合不得激活', () => {
|
||||
expect(violations.filter((v) => v.kind === 'dangling-node').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('异或网关的出边必须有条件 —— 声明式、静态可检', () => {
|
||||
/*
|
||||
* 网关已废除(2026-07-28):含网关的定义一律违规 —— 历史版本仅可读,不可激活。
|
||||
* 分支改由源节点的条件出边表达,见下一用例。
|
||||
*/
|
||||
it('网关节点即违规 —— gateway-deprecated,历史版本不可激活', () => {
|
||||
const withGateway = pkg({
|
||||
nodes: [
|
||||
...pkg().nodes,
|
||||
@@ -136,11 +140,32 @@ describe('checkClosure —— 不闭合不得激活', () => {
|
||||
...pkg().edges,
|
||||
{ id: 'g1', from: 'A4' as never, to: 'G2' as never, mapping: [], reopen: false },
|
||||
{ id: 'g2', from: 'G2' as never, to: 'end' as never, mapping: [], reopen: false },
|
||||
{ id: 'g3', from: 'G2' as never, to: 'end' as never, mapping: [], reopen: false },
|
||||
],
|
||||
});
|
||||
const violations = checkClosure({ pkg: withGateway, contracts, positions }).violations;
|
||||
expect(violations.some((v) => v.message.includes('缺条件'))).toBe(true);
|
||||
expect(violations.filter((v) => v.kind === 'gateway-deprecated').map((v) => v.nodeId)).toEqual(['G2']);
|
||||
});
|
||||
|
||||
it('多出边异或分支:两条无条件出边 = 都想当默认 —— multi-default-edge', () => {
|
||||
const twoDefaults = pkg({
|
||||
nodes: [...pkg().nodes, { id: 'end2' as never, kind: 'end', label: '另一终点' }],
|
||||
edges: [
|
||||
...pkg().edges,
|
||||
// A4 已有一条无条件出边 A4→end;再加一条无条件出边即违规
|
||||
{ id: 'e9', from: 'A4' as never, to: 'end2' as never, mapping: [], reopen: false },
|
||||
],
|
||||
});
|
||||
const violations = checkClosure({ pkg: twoDefaults, contracts, positions }).violations;
|
||||
expect(violations.filter((v) => v.kind === 'multi-default-edge').map((v) => v.nodeId)).toEqual(['A4']);
|
||||
|
||||
// 其中一条补上条件即闭合 —— 条件命中优先,无条件边只作默认兜底
|
||||
const oneDefault = pkg({
|
||||
nodes: twoDefaults.nodes,
|
||||
edges: twoDefaults.edges.map((e) => (e.id === 'e9' ? { ...e, condition: 'ok = true' } : e)),
|
||||
});
|
||||
expect(
|
||||
checkClosure({ pkg: oneDefault, contracts, positions }).violations.filter((v) => v.kind === 'multi-default-edge'),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('容忍分支的输出不得被下游必填依赖', () => {
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
* 「**连线即映射,画图即校验,不闭合不得保存。**
|
||||
* 连一条边即须完成该边映射(必填未映射 = 边未完成),类型兼容依两端契约 schema 当场校验;
|
||||
* 存在未完成边、未满足必填或类型冲突的流程包**存不进来**。
|
||||
* AND 汇合后的同名字段必须**显式指定来源分支**,不做隐式合并。」
|
||||
* 多出边即异或分支(恰取一条,默认兜底至多一条);多入边即异或汇合。」
|
||||
*
|
||||
* 网关已废除(2026-07-28):schema 仍收 gateway 只为读历史 —— 见 checkGateway。
|
||||
*
|
||||
* 原文是「可存草稿、不得发布」——**已不成立**:没有草稿态也没有发布门,
|
||||
* 闸落在保存上(严格检查 + 保存即生效)。画布上的半成品留在浏览器里,存不进库。
|
||||
@@ -69,6 +71,24 @@ export function checkClosure(input: ClosureInput): ClosureReport {
|
||||
if (node.kind === 'gateway') {
|
||||
violations.push(...checkGateway(node, incoming.get(node.id) ?? [], outgoing.get(node.id) ?? []));
|
||||
}
|
||||
|
||||
/*
|
||||
* 多出边 = 异或分支(恰取一条):条件命中优先,无条件边作默认兜底。
|
||||
* 默认兜底**至多一条** —— 两条无条件出边就是「都想当默认」,运行时按声明序
|
||||
* 静默取先者,另一条永远走不到:图上画着、结构上死路,必须在定义期拦下。
|
||||
* 条件不必全覆盖(全不中走默认;连默认都没有则运行时报 route-dead-end)。
|
||||
*/
|
||||
const outs = outgoing.get(node.id) ?? [];
|
||||
if (outs.length > 1) {
|
||||
const defaults = outs.filter((e) => e.condition === undefined || e.condition.trim() === '');
|
||||
if (defaults.length > 1) {
|
||||
violations.push({
|
||||
kind: 'multi-default-edge',
|
||||
nodeId: node.id,
|
||||
message: `节点「${node.label}」有 ${defaults.length} 条无条件出边 —— 默认兜底至多一条,其余必须带条件`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
violations.push(...checkTolerateDependencies(pkg, contracts, byId));
|
||||
@@ -139,22 +159,12 @@ function checkActivityNode(
|
||||
}
|
||||
}
|
||||
|
||||
// AND 汇合后的同名字段必须显式指定来源分支,不做隐式合并。
|
||||
// 回边(reopen)是**重新入场**不是并发汇合 —— 不参与此判定(OS 03 失败走向 / 议价回环)。
|
||||
const concurrent = inbound.filter((e) => !e.reopen);
|
||||
const targets = concurrent.flatMap((e) => e.mapping.map((m) => m.target));
|
||||
const seen = new Set<string>();
|
||||
for (const target of targets) {
|
||||
if (seen.has(target) && concurrent.length > 1) {
|
||||
out.push({
|
||||
kind: 'join-ambiguous-source',
|
||||
nodeId: node.id,
|
||||
field: target,
|
||||
message: `汇合处字段 ${target} 有多个来源分支,须显式指定 —— 不做隐式合并`,
|
||||
});
|
||||
}
|
||||
seen.add(target);
|
||||
}
|
||||
/*
|
||||
* 多入边**不再判「隐式合并」**(产品决策 2026-07-28:网关去节点化)。
|
||||
* 多入边即异或汇合:上游是互斥的条件分支,结构上只会来一条,同名映射天然无歧义 ——
|
||||
* 从前为绕开这条禁令而生的显式汇合点(G2J 之类)正是被删掉的东西。
|
||||
* AND 并行没有声明机制,不存在「并发汇合」;将来加「并行组」时再回来立汇合规则。
|
||||
*/
|
||||
|
||||
return out;
|
||||
}
|
||||
@@ -164,22 +174,21 @@ function checkGateway(
|
||||
inbound: readonly Edge[],
|
||||
outbound: readonly Edge[],
|
||||
): ClosureViolation[] {
|
||||
const out: ClosureViolation[] = [];
|
||||
if (node.mode === 'fork' && outbound.length < 2) {
|
||||
out.push({ kind: 'gateway-unbalanced', nodeId: node.id, message: `分叉网关「${node.label}」出边少于两条` });
|
||||
}
|
||||
if (node.mode === 'join' && inbound.length < 2) {
|
||||
out.push({ kind: 'gateway-unbalanced', nodeId: node.id, message: `汇合网关「${node.label}」入边少于两条` });
|
||||
}
|
||||
// XOR 的每条出边必须有条件(声明式、静态可检,不得内嵌自由逻辑)
|
||||
if (node.gateway === 'exclusive' && node.mode === 'fork') {
|
||||
for (const edge of outbound) {
|
||||
if (edge.condition === undefined || edge.condition.trim() === '') {
|
||||
out.push({ kind: 'edge-unmapped', edgeId: edge.id, nodeId: node.id, message: `异或网关的出边 ${edge.id} 缺条件` });
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
void inbound;
|
||||
void outbound;
|
||||
/*
|
||||
* **网关已废除**(产品决策 2026-07-28):分支 = 源节点的条件出边,汇合 = 多入边异或。
|
||||
* schema 仍收 gateway 只为**读历史版本** —— 在途工作流照走(运行时兼容),
|
||||
* 但含网关的定义不再可激活:这里判违规,激活闸(不闭合不得激活)就会拦下。
|
||||
* 想复用旧图,在生效版上把网关的出边改画成源活动的条件出边即可。
|
||||
*/
|
||||
return [
|
||||
{
|
||||
kind: 'gateway-deprecated',
|
||||
nodeId: node.id,
|
||||
message: `网关「${node.label}」已废除 —— 把分支写成上游节点的条件出边(历史版本仅可读,不可激活)`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,16 +75,27 @@ export function selectEdges(
|
||||
const node = pkg.nodes.find((n) => n.id === fromNodeId);
|
||||
const outgoing = pkg.edges.filter((e) => e.from === fromNodeId);
|
||||
|
||||
if (node?.kind === 'gateway' && node.gateway === 'exclusive' && node.mode === 'fork') {
|
||||
// 判定依据入事件记录;无条件的边作默认分支兜底
|
||||
const hit = outgoing.find((e) => e.condition !== undefined && evaluate(e.condition, scope));
|
||||
const fallback = outgoing.find((e) => e.condition === undefined);
|
||||
const chosen = hit ?? fallback;
|
||||
return chosen === undefined ? [] : [chosen];
|
||||
/*
|
||||
* **多出边一律异或,不分节点种类**(产品决策 2026-07-28:网关去节点化)。
|
||||
*
|
||||
* 分支不再是网关节点的专利 —— 活动/审批点自己的多条条件出边就是分支,
|
||||
* 判据读的是它自己的出参(与 Mastra 的 `.branch` 同构:条件挂在步与步之间)。
|
||||
* 语义与从前的异或网关逐字相同:条件命中优先(按声明序),无条件边作默认兜底,
|
||||
* 恰取一条。并行(AND)没有节点了也没有声明机制 —— 要并行时以「并行组」声明加回
|
||||
* (对应 Mastra 的 `.parallel` 结构块),见债务簿。
|
||||
*
|
||||
* 遗留的网关节点(历史版本里还有)走同一条逻辑 —— 异或网关的语义本来就是这个;
|
||||
* 并行网关分叉的「全发」不再支持,历史包若有,激活时已被闭合校验拦下。
|
||||
*/
|
||||
if (outgoing.length <= 1) {
|
||||
// 并行网关的遗留直通不受损:单出边不判条件,原样走
|
||||
void node;
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
// 并行网关分叉、活动节点、审批点:全部出边
|
||||
return outgoing;
|
||||
const hit = outgoing.find((e) => e.condition !== undefined && evaluate(e.condition, scope));
|
||||
const fallback = outgoing.find((e) => e.condition === undefined);
|
||||
const chosen = hit ?? fallback;
|
||||
return chosen === undefined ? [] : [chosen];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user