Archived
范式退役:活动只剩一种、只跑 Loop;审批活动可管;活动库重做
用户定的两件,一并落地。
**一、活动不再分 flow 和 loop —— 彻底退役 flow**
· `flow-engine` 模块整个删除(runner 379 行 + step-sequence 184 行 + 测试);
· `paradigm` 从清单身份、`activity_package`/`task` 两张表、任务卡与活动库一并退场;
`businessModel` 不再是判别联合 —— 只有案例模型(CMMN + 说明书 + DMN)一形;
· task 的引擎分派从「按 paradigm 取两个之一」收成**唯一的引擎**;
· `activities/` 四个 flow 活动(A1 受理 / A4 定价 / A6 议价 / A7 归档)各写了一份
案例模型:阶段照原来的步分,触达世界的项一律 manualActivationRule,
能算的交 DMN(A1 的三分类 P-03、A4 的 P-01/P-02)不交 Agent;
· 六个占位槽位的骨架从「机器步落台账 + 一张验收单」改成案例骨架,包版本 0.8.0 → 0.9.0。
**代价写在明处,不假装没有**:`turn-runner` 每一拍都要 `agent.decide` ——
环境里没有模型 key,案例活动一步也走不动。三套端到端(统一报价 / 新建流程包 / 测试台
Trace)整套跳过,文件头写明恢复条件:①有可用模型 ②走法改写成按 Enabled 集推进。
**不许把断言改松让它变绿** —— 绿得不诚实比红着更坏。debt.md 已记。
**二、审批活动可管**(新能力)
· `sys.approval_template`:审批点**可复用的那一半** —— 审批人看哪几项、按什么名字看、
怎么催、说什么话。谁来审不在里面(与活动点同口径,运营时轮值);驳回回哪个节点
也不在里面(那是每张图自己的事,留在节点上);
· 三条路由 + 引用反查:还被审批点引着就不许删(409),删了那些节点会**静默**退回旧行为;
· 运行时 `basisOf`:引了模板就按模板筛与改名,没引即旧行为(载荷全摊开)。
模板改了只影响新发出的审批单 —— 在途单的依据在发出那一刻已定形。
**三、活动库重做**:一区两格 —— 「活动(装进来的)」与「审批活动(配出来的)」,
都用流程卡那套两段式卡片(头 + 四格数据板),幽灵卡当入口(装入活动 / 新建审批活动);
「标准/案例」那一维随范式一起撤,业务分类成了唯一的一维,以行内小签呈现。
迁移 0020:两张表 drop paradigm、建 approval_template。已在开发库跑过并重播种。
实测(丁子乔账号):建「定价审批」模板 → 流程包 A5 属性里选得到 → 引用反查计数正确。
四闸绿(api:check 随本提交)。
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
@@ -19,6 +19,21 @@ export const processPackageTable = sys.table(
|
||||
(t) => [primaryKey({ columns: [t.id, t.version] }), index('process_package_state_idx').on(t.state)],
|
||||
);
|
||||
|
||||
/**
|
||||
* 审批模板(2026-07-29)—— 审批活动的可复用那一半:看什么 / 怎么催 / 说什么。
|
||||
* 不长版本:模板是运营配置,改了即刻对**新起的审批单**生效,在途单不受影响
|
||||
* (在途单的依据在发出那一刻已经定形,存在审批单自己身上)。
|
||||
*/
|
||||
export const approvalTemplateTable = sys.table('approval_template', {
|
||||
id: text('id').primaryKey(),
|
||||
name: text('name').notNull(),
|
||||
/** [{ field, label }] —— 空数组即旧行为:载荷全摊开 */
|
||||
basis: jsonb('basis').notNull().default([]),
|
||||
nudge: jsonb('nudge'),
|
||||
message: text('message'),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const workflowTable = sys.table(
|
||||
'workflow',
|
||||
{
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
*/
|
||||
import { and, asc, desc, eq, isNull } from 'drizzle-orm';
|
||||
import type { ProcessPackage, TerminalState, WorkflowState } from '@contracts';
|
||||
import { processPackageSchema } from '@contracts';
|
||||
import { approvalTemplateSchema, processPackageSchema } from '@contracts';
|
||||
import type { Db } from '@shared/db.ts';
|
||||
import type { ProcessStore, WorkflowRecord } from '../../port.ts';
|
||||
import type { NodeInstance } from '../domain/owner-resolution.ts';
|
||||
import { nodeInstanceTable, processPackageTable, workflowTable, nodeOwnerTable } from './process-schema.ts';
|
||||
import { approvalTemplateTable, nodeInstanceTable, processPackageTable, workflowTable, nodeOwnerTable } from './process-schema.ts';
|
||||
|
||||
type WorkflowRow = typeof workflowTable.$inferSelect;
|
||||
|
||||
@@ -98,6 +98,36 @@ export function createProcessStore(db: Db): ProcessStore {
|
||||
.where(and(eq(workflowTable.packageId, id), eq(workflowTable.packageVersion, from)));
|
||||
},
|
||||
|
||||
async listApprovalTemplates() {
|
||||
const rows = await db.select().from(approvalTemplateTable).orderBy(asc(approvalTemplateTable.name));
|
||||
return rows.map((r) => approvalTemplateSchema.parse({
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
basis: r.basis,
|
||||
...(r.nudge === null ? {} : { nudge: r.nudge }),
|
||||
...(r.message === null ? {} : { message: r.message }),
|
||||
}));
|
||||
},
|
||||
|
||||
async upsertApprovalTemplate(template) {
|
||||
const values = {
|
||||
id: template.id,
|
||||
name: template.name,
|
||||
basis: template.basis,
|
||||
nudge: template.nudge ?? null,
|
||||
message: template.message ?? null,
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
await db.insert(approvalTemplateTable).values(values).onConflictDoUpdate({
|
||||
target: approvalTemplateTable.id,
|
||||
set: { name: values.name, basis: values.basis, nudge: values.nudge, message: values.message, updatedAt: values.updatedAt },
|
||||
});
|
||||
},
|
||||
|
||||
async deleteApprovalTemplate(id) {
|
||||
await db.delete(approvalTemplateTable).where(eq(approvalTemplateTable.id, id));
|
||||
},
|
||||
|
||||
async getPackage(id, version) {
|
||||
const conditions = [eq(processPackageTable.id, id)];
|
||||
if (version !== undefined) conditions.push(eq(processPackageTable.version, version));
|
||||
|
||||
@@ -56,6 +56,22 @@ export function createSelfHostedRuntime(deps: SelfHostedRuntimeDeps): FlowRuntim
|
||||
}
|
||||
|
||||
/** 起一个节点:活动 → 起单;审批点 → 卡工位;终点 → 收束 */
|
||||
/**
|
||||
* 审批单上给人看什么 —— 引了模板就按模板筛与改名,没引就把载荷全摊开(旧行为)。
|
||||
* 模板里点名的字段载荷里没有,如实写「—」:漏一项比编一项好。
|
||||
*/
|
||||
async function basisOf(
|
||||
node: Extract<ProcessNode, { kind: 'approval' }> | undefined,
|
||||
payload: Record<string, unknown>,
|
||||
): Promise<Array<{ k: string; v: string }>> {
|
||||
if (node?.templateId === undefined) return Object.entries(payload).map(([k, v]) => ({ k, v: String(v) }));
|
||||
const template = (await deps.store.listApprovalTemplates()).find((t) => t.id === node.templateId);
|
||||
if (template === undefined || template.basis.length === 0) {
|
||||
return Object.entries(payload).map(([k, v]) => ({ k, v: String(v) }));
|
||||
}
|
||||
return template.basis.map((b) => ({ k: b.label, v: payload[b.field] === undefined ? '—' : String(payload[b.field]) }));
|
||||
}
|
||||
|
||||
async function enter(
|
||||
record: WorkflowRecord,
|
||||
pkg: ProcessPackage,
|
||||
@@ -163,7 +179,12 @@ export function createSelfHostedRuntime(deps: SelfHostedRuntimeDeps): FlowRuntim
|
||||
nodeId: node.id,
|
||||
approverId: resolution.staffId as StaffId,
|
||||
subject: dispatch.node.label,
|
||||
basis: Object.entries(payload).map(([k, v]) => ({ k, v: String(v) })),
|
||||
/*
|
||||
* 审批依据:引了模板就按模板筛与改名(审批人只看该看的、按人话看);
|
||||
* 没引模板即旧行为 —— 把载荷全摊开。模板改了只影响**新发出的**审批单,
|
||||
* 在途单的依据在发出那一刻已经定形,存在审批单自己身上。
|
||||
*/
|
||||
basis: await basisOf(node.kind === 'approval' ? node : undefined, payload),
|
||||
});
|
||||
await deps.store.insertInstance(record.id, {
|
||||
nodeId: node.id,
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
NotClosedError,
|
||||
PinnedVersionError,
|
||||
StaleVersionError,
|
||||
TemplateInUseError,
|
||||
VersionTakenError,
|
||||
} from '../../contract.ts';
|
||||
import type {
|
||||
@@ -193,6 +194,35 @@ export function createProcessService(deps: ProcessServiceDeps): ProcessService {
|
||||
return deps.store.listPackages();
|
||||
},
|
||||
|
||||
async approvalTemplates() {
|
||||
const [templates, packages] = await Promise.all([
|
||||
deps.store.listApprovalTemplates(),
|
||||
deps.store.listPackages(),
|
||||
]);
|
||||
// 引用反查:哪个包的哪个审批点引着它 —— 删之前要能看见,不能删完才发现
|
||||
return templates.map((t) => ({
|
||||
...t,
|
||||
usedBy: packages.flatMap((pkg) =>
|
||||
pkg.nodes
|
||||
.filter((n) => n.kind === 'approval' && n.templateId === t.id)
|
||||
.map((n) => ({ packageId: pkg.id, nodeId: n.id })),
|
||||
),
|
||||
}));
|
||||
},
|
||||
|
||||
async saveApprovalTemplate(template) {
|
||||
await deps.store.upsertApprovalTemplate(template);
|
||||
return template;
|
||||
},
|
||||
|
||||
async deleteApprovalTemplate(id) {
|
||||
const all = await this.approvalTemplates();
|
||||
const hit = all.find((t) => t.id === id);
|
||||
if (hit === undefined) throw new Error(`审批模板不存在:${id}`);
|
||||
if (hit.usedBy.length > 0) throw new TemplateInUseError(id, hit.usedBy);
|
||||
await deps.store.deleteApprovalTemplate(id);
|
||||
},
|
||||
|
||||
async editVersion(id, version, patch) {
|
||||
const one = await deps.store.getPackage(id, version);
|
||||
if (one === undefined) throw new StaleVersionError(id, version);
|
||||
|
||||
Reference in New Issue
Block a user