M5/M6 修复串:判据 ③ 全链路跑通 —— 六处「声明与引擎对不上」
判据 ③ 现在从入站到 released 一路走通:步序推进 → LLM 步(密钥是占位符,
按声明降级为人兜底)→ 台账草稿层 → D1 条件跳步 → S4 工具 → S5 DMN 三分类
(LM358DR → Type A · 直接快答)→ 验收放行 → 草稿合并正式版 2 行 → 输出口
intake 发射 → 终态 released。
沿路修掉的六处,每一处都是「声明是这么写的,引擎不这么读」:
1. 人兜底卡只问一个笼统「结果」框 → 改问**这一步声明的出参字段**。
出参契约属于步、不属于执行者:同一步谁做完,落进作用域的形状都得一样。
2. 人事件的载荷是回传协议壳 `{mode,workOrderId,values}`,
引擎把整个壳当出参写 → 取 `values`。
3. 引擎作用域是 `{'域.对象': 行数组}`,而所有活动的步声明写的都是裸字段名 →
任务视图三层铺开:起单入参在底、各对象最新行的字段铺顶层、地址式整表保留。
4. 起单入参从不落库、也进不了作用域 → task 存 `input_data`,断点续跑后仍在。
5. 步出参无法声明**写哪一行** → 出参加 `key`(主键列 → 作用域路径);
六个活动包的每处出参补上键。台账几乎都有主键,不声明键就只能写无主键行。
6. `tick` 不处理 `finished`:谱走完仍按 running 一拍拍推,把预算烧到 exhausted,
把「没人裁」误报成「跑爆了」→ 放行通过则落地收敛后 released;未放行则挂起等人。
`flow.advance` 据末步验收裁决报 released —— **完成只出自放行通过**。
另两处装配缺口:
· `release.land()` 实现完整却无人调用 —— 放行后从不落地。经 LandingGateway 接上。
· `process.onTaskTerminal()` 实现完整却无人调用 —— 任务终态报不到流程层,
流就停在那个节点上,既不流转也不走失败走向。task 在 L6 不得反向依赖 L7,
这一跳由 app 缝合(延后绑定,同 container 里 TriggerMatcher 的手法)。
还有一处版本化缺陷:资产播种恒用 v1,`shouldSeedAsset` 一比就跳过 ——
只有**第一个**包版本的资产此生有效,之后装什么都跑旧的。改为播下一版;
进化管线放行出的更高版仍不被盖过;同版重复安装不再播种。
gates: tsc / eslint / depcruise(317 模块)/ api-report / 393 测试 全绿
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-005@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727C 求报价",
|
||||
"body": "客户编码 C001,询价单号 RFQ-20260727C。\nLM358DR TI 年用量 12000 目标价 8.20 交期 10w",
|
||||
"receivedAt": "2026-07-27T04:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-006@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727D 求报价",
|
||||
"body": "客户编码 C001,询价单号 RFQ-20260727D。\nLM358DR TI 年用量 12000 目标价 8.20 交期 10w",
|
||||
"receivedAt": "2026-07-27T05:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-007@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727E 求报价",
|
||||
"body": "客户编码 C001,询价单号 RFQ-20260727E。\nLM358DR TI 年用量 12000 目标价 8.20 交期 10w",
|
||||
"receivedAt": "2026-07-27T06:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-008@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727F 求报价",
|
||||
"body": "客户编码 C001,询价单号 RFQ-20260727F。\nLM358DR TI 年用量 12000 目标价 8.20 交期 10w",
|
||||
"receivedAt": "2026-07-27T07:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-009@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727G 求报价",
|
||||
"body": "客户编码 C001,询价单号 RFQ-20260727G。\nLM358DR TI 年用量 12000 目标价 8.20 交期 10w",
|
||||
"receivedAt": "2026-07-27T08:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-010@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727H 求报价",
|
||||
"body": "客户编码 C001,询价单号 RFQ-20260727H。\nLM358DR TI 年用量 12000 目标价 8.20 交期 10w",
|
||||
"receivedAt": "2026-07-27T09:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-011@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727J 求报价",
|
||||
"body": "客户编码 C001,询价单号 RFQ-20260727J。\nLM358DR TI 年用量 12000 目标价 8.20 交期 10w",
|
||||
"receivedAt": "2026-07-27T10:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-2026-07-27-002@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】ACME PN-9001 / PN-9002 求报价 RFQ-2026-0727",
|
||||
"body": "您好,\n我司需求如下:\nPN-9001 TI 年用量 12000 目标价 8.20 交期 10w\nPN-9002 ADI 年用量 3000 目标价 21.00 交期 12w\nRFQ 编号 RFQ-2026-0727,请于本周内回复。\n谢谢!",
|
||||
"receivedAt": "2026-07-27T02:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-2026-07-27-003@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727A 求报价",
|
||||
"body": "您好,\n客户编码 C001,询价单号 RFQ-20260727A。\n需求如下:\nPN-9001 TI 年用量 12000 目标价 8.20 交期 10w\n请于本周内回复。谢谢!",
|
||||
"receivedAt": "2026-07-27T02:10:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"messageId": "rfq-2026-07-27-004@acme.com",
|
||||
"from": "buyer@acme.com",
|
||||
"to": [
|
||||
"rfq@we.com"
|
||||
],
|
||||
"cc": [],
|
||||
"subject": "【询价】客户 C001 RFQ-20260727B 求报价",
|
||||
"body": "客户编码 C001,询价单号 RFQ-20260727B。\nPN-9001 TI 年用量 12000 目标价 8.20 交期 10w",
|
||||
"receivedAt": "2026-07-27T03:00:00.000Z",
|
||||
"attachments": []
|
||||
}
|
||||
@@ -13,7 +13,7 @@ export const manifest: ActivityManifest = {
|
||||
identity: {
|
||||
activityId: ACTIVITY_ID,
|
||||
name: 'A7 · 情报归档',
|
||||
packageVersion: '0.1.0',
|
||||
packageVersion: '0.1.1',
|
||||
category: '统一报价',
|
||||
paradigm: 'flow',
|
||||
sdkVersion: '0.1.0-m5',
|
||||
@@ -118,7 +118,12 @@ export const manifest: ActivityManifest = {
|
||||
name: 'S1_log_result',
|
||||
label: 'S1 结果登记(拒绝原因 / 竞对价位)',
|
||||
input: { reason: 'reason', quoteNo: 'quoteNo' },
|
||||
output: { domain: 'shared', object: 'history_price', fields: { lost_reason: 'lostReason' } },
|
||||
output: {
|
||||
domain: 'shared',
|
||||
object: 'history_price',
|
||||
key: { pn: 'pn', quoted_at: 'quotedAt' },
|
||||
fields: { lost_reason: 'lostReason' },
|
||||
},
|
||||
model: 'quote-extractor',
|
||||
template: '从跟进反馈里抽出拒绝原因与竞对价位。只输出 JSON。反馈:{{reason}}',
|
||||
outputSchema: {
|
||||
@@ -132,7 +137,12 @@ export const manifest: ActivityManifest = {
|
||||
name: 'S2_profile',
|
||||
label: 'S2 画像更新(供 P-01 的客户等级因子取用)',
|
||||
input: { customerCode: 'customerCode', reason: 'reason' },
|
||||
output: { domain: 'shared', object: 'customer', fields: { profile_tags: 'tags' } },
|
||||
output: {
|
||||
domain: 'shared',
|
||||
object: 'customer',
|
||||
key: { customer_code: 'customerCode' },
|
||||
fields: { profile_tags: 'tags' },
|
||||
},
|
||||
tool: 'quote-archive.profile',
|
||||
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
|
||||
},
|
||||
@@ -141,7 +151,12 @@ export const manifest: ActivityManifest = {
|
||||
name: 'S3_landing_rate',
|
||||
label: 'S3 落地率统计',
|
||||
input: {},
|
||||
output: { domain: 'shared', object: 'landing_stats', fields: { landing_rate: 'landingRate' } },
|
||||
output: {
|
||||
domain: 'shared',
|
||||
object: 'landing_stats',
|
||||
key: { period: 'period' },
|
||||
fields: { landing_rate: 'landingRate' },
|
||||
},
|
||||
tool: 'quote-archive.landing-rate',
|
||||
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
|
||||
},
|
||||
|
||||
@@ -40,7 +40,7 @@ export const manifest: ActivityManifest = {
|
||||
identity: {
|
||||
activityId: ACTIVITY_ID,
|
||||
name: 'A1 · RFQ 需求分析',
|
||||
packageVersion: '0.1.0',
|
||||
packageVersion: '0.1.2',
|
||||
category: '统一报价',
|
||||
paradigm: 'flow',
|
||||
sdkVersion: '0.1.0-m5',
|
||||
@@ -135,6 +135,10 @@ export const manifest: ActivityManifest = {
|
||||
{ name: 'type_tag', type: 'text', primaryKey: false, masked: false },
|
||||
{ name: 'basis', type: 'text', primaryKey: false, masked: false, label: '分级依据' },
|
||||
{ name: 'history_hit', type: 'boolean', primaryKey: false, masked: false, label: '历史价命中' },
|
||||
// 打标的三个判据必须落表:S5 的 DMN 从这里读,不落就无米下锅
|
||||
{ name: 'history_days', type: 'integer', primaryKey: false, masked: false, label: '距上次报价天数' },
|
||||
{ name: 'market_stable', type: 'boolean', primaryKey: false, masked: false, label: '行情稳定' },
|
||||
{ name: 'lifecycle', type: 'text', primaryKey: false, masked: false, label: '生命周期' },
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -168,7 +172,12 @@ export const manifest: ActivityManifest = {
|
||||
name: 'S3_normalize',
|
||||
label: 'S3 逐条解析归一',
|
||||
input: { rfqRef: 'rfqRef', customerCode: 'customerCode' },
|
||||
output: { domain: INTAKE_DOMAIN, object: 'record', fields: { pn: 'pn', brand: 'brand', eau: 'eau' } },
|
||||
output: {
|
||||
domain: INTAKE_DOMAIN,
|
||||
object: 'record',
|
||||
key: { customer_code: 'customerCode', pn: 'pn' },
|
||||
fields: { pn: 'pn', brand: 'brand', eau: 'eau' },
|
||||
},
|
||||
model: 'quote-extractor',
|
||||
template:
|
||||
'按《询价受理规范》把这份 RFQ 拆解为逐条需求,抄录 PN/数量/EAU/厂牌/目标价/交期。' +
|
||||
@@ -213,7 +222,18 @@ export const manifest: ActivityManifest = {
|
||||
name: 'S4_history',
|
||||
label: 'S4 查历史价',
|
||||
input: { pn: 'pn' },
|
||||
output: { domain: INTAKE_DOMAIN, object: 'type_table', fields: { history_hit: 'hit' } },
|
||||
// 情报四件全部落表:S5 打标要的就是这三件,只落 hit 会让下一步无米下锅
|
||||
output: {
|
||||
domain: INTAKE_DOMAIN,
|
||||
object: 'type_table',
|
||||
key: { pn: 'pn' },
|
||||
fields: {
|
||||
history_hit: 'hit',
|
||||
history_days: 'historyDays',
|
||||
market_stable: 'marketStable',
|
||||
lifecycle: 'lifecycle',
|
||||
},
|
||||
},
|
||||
tool: 'crm.history-price-read',
|
||||
failure: { retry: { times: 2, backoff: 'PT1M' }, fallback: { kind: 'human', workOrder: 'execution' } },
|
||||
},
|
||||
@@ -221,8 +241,14 @@ export const manifest: ActivityManifest = {
|
||||
kind: 'pure-tool',
|
||||
name: 'S5_classify',
|
||||
label: 'S5 逐条打标(DMN · 三分类规则 P-03)',
|
||||
input: { historyDays: 'historyDays', marketStable: 'marketStable', lifecycle: 'lifecycle' },
|
||||
output: { domain: INTAKE_DOMAIN, object: 'type_table', fields: { type_tag: 'type', basis: 'play' } },
|
||||
// 入参名 ← 作用域路径:作用域里是 S4 落表后的字段名
|
||||
input: { historyDays: 'history_days', marketStable: 'market_stable', lifecycle: 'lifecycle' },
|
||||
output: {
|
||||
domain: INTAKE_DOMAIN,
|
||||
object: 'type_table',
|
||||
key: { pn: 'pn' },
|
||||
fields: { type_tag: 'type', basis: 'play' },
|
||||
},
|
||||
tool: 'quote-intake.classify',
|
||||
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
|
||||
},
|
||||
|
||||
@@ -15,7 +15,7 @@ export const manifest: ActivityManifest = {
|
||||
identity: {
|
||||
activityId: ACTIVITY_ID,
|
||||
name: 'A6 · 报价议价',
|
||||
packageVersion: '0.1.0',
|
||||
packageVersion: '0.1.1',
|
||||
category: '统一报价',
|
||||
paradigm: 'flow',
|
||||
sdkVersion: '0.1.0-m5',
|
||||
@@ -135,7 +135,12 @@ export const manifest: ActivityManifest = {
|
||||
name: 'S1_compose',
|
||||
label: 'S1 生成正式报价单',
|
||||
input: { items: 'items', customerCode: 'customerCode' },
|
||||
output: { domain: DOMAIN, object: 'formal_quote', fields: { unit_price: 'unitPrice', lead_time: 'leadTime' } },
|
||||
output: {
|
||||
domain: DOMAIN,
|
||||
object: 'formal_quote',
|
||||
key: { quote_no: 'quoteNo', pn: 'pn' },
|
||||
fields: { unit_price: 'unitPrice', lead_time: 'leadTime' },
|
||||
},
|
||||
model: 'quote-extractor',
|
||||
template:
|
||||
'把已批准的报价草案排版为正式报价单条目(单价CNY/交期/SPQ/MOQ/贸易条款),' +
|
||||
|
||||
@@ -59,7 +59,7 @@ export const manifest: ActivityManifest = {
|
||||
identity: {
|
||||
activityId: ACTIVITY_ID,
|
||||
name: 'A4 · 成本定价',
|
||||
packageVersion: '0.1.0',
|
||||
packageVersion: '0.1.1',
|
||||
category: '统一报价',
|
||||
paradigm: 'flow',
|
||||
sdkVersion: '0.1.0-m5',
|
||||
@@ -167,7 +167,7 @@ export const manifest: ActivityManifest = {
|
||||
label: 'S1 取价基准',
|
||||
// Type A 取历史价近期价;B/C 取供应商底价表(C 类参考替代对标表)
|
||||
input: { pn: 'pn' },
|
||||
output: { domain: DOMAIN, object: 'draft', fields: { deviation: 'deviation' } },
|
||||
output: { domain: DOMAIN, object: 'draft', key: { pn: 'pn' }, fields: { deviation: 'deviation' } },
|
||||
tool: 'crm.history-price-read',
|
||||
failure: { retry: { times: 2, backoff: 'PT1M' }, fallback: { kind: 'human', workOrder: 'execution' } },
|
||||
},
|
||||
@@ -176,7 +176,12 @@ export const manifest: ActivityManifest = {
|
||||
name: 'S2_price',
|
||||
label: 'S2 逐条定价(DMN · 利润模型 P-01)',
|
||||
input: { customerGrade: 'customerGrade', materialType: 'materialType', volumeTier: 'volumeTier' },
|
||||
output: { domain: DOMAIN, object: 'draft', fields: { margin: 'marginLow', quoted_price: 'quotedPrice' } },
|
||||
output: {
|
||||
domain: DOMAIN,
|
||||
object: 'draft',
|
||||
key: { pn: 'pn' },
|
||||
fields: { margin: 'marginLow', quoted_price: 'quotedPrice' },
|
||||
},
|
||||
tool: 'quote-pricing.margin',
|
||||
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
|
||||
},
|
||||
@@ -185,7 +190,7 @@ export const manifest: ActivityManifest = {
|
||||
name: 'S3_floor_gate',
|
||||
label: 'S3 底价自检(DMN · 底价门禁 P-02)',
|
||||
input: { deviation: 'deviation' },
|
||||
output: { domain: DOMAIN, object: 'draft', fields: { disposition: 'disposition' } },
|
||||
output: { domain: DOMAIN, object: 'draft', key: { pn: 'pn' }, fields: { disposition: 'disposition' } },
|
||||
tool: 'quote-pricing.floor-gate',
|
||||
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
|
||||
},
|
||||
|
||||
@@ -10,7 +10,8 @@ export type IdGenerator = {
|
||||
next(): string;
|
||||
};
|
||||
export type RegistryStore = {
|
||||
savePackage(manifest: ActivityManifest, artifact: string): Promise<void>;
|
||||
/** 返回是否新增了这一包版本(同版重复安装返回 false) */
|
||||
savePackage(manifest: ActivityManifest, artifact: string): Promise<boolean>;
|
||||
listPackages(activityId?: string): Promise<PackageVersion[]>;
|
||||
manifest(activityId: string, packageVersion?: string): Promise<ActivityManifest | undefined>;
|
||||
artifact(activityId: string, packageVersion: string): Promise<string | undefined>;
|
||||
|
||||
@@ -32,6 +32,8 @@ export type Task = {
|
||||
readonly reason?: string;
|
||||
/** 装载信封:包版本 + 各资产生效版 —— 行为可归因 */
|
||||
readonly envelope: Readonly<Record<string, unknown>>;
|
||||
/** 起单入参:契约的 data —— 引擎求值的作用域底料 */
|
||||
readonly data: Readonly<Record<string, unknown>>;
|
||||
readonly caps: BudgetCaps;
|
||||
readonly used: Consumption;
|
||||
readonly startedAt: string;
|
||||
|
||||
+21
-6
@@ -40,17 +40,32 @@ export type SchemaValidator = {
|
||||
/** 范式引擎 —— loop / flow 在此汇流;对上层不可区分(§9 双层边界) */
|
||||
export type ParadigmEngine = {
|
||||
load(taskId: TaskId, model: unknown): Promise<void>;
|
||||
advance(taskId: TaskId): Promise<{
|
||||
status: 'running' | 'awaiting' | 'submitted' | 'finished' | 'blocked';
|
||||
reason?: string;
|
||||
}>;
|
||||
advance(taskId: TaskId): Promise<EngineOutcome>;
|
||||
onEvent(taskId: TaskId, event: {
|
||||
kind: 'data' | 'time' | 'human' | 'control';
|
||||
ref: string;
|
||||
payload: Record<string, unknown>;
|
||||
}): Promise<EngineOutcome>;
|
||||
};
|
||||
export type EngineOutcome = {
|
||||
readonly status: 'running' | 'awaiting' | 'submitted' | 'finished' | 'blocked';
|
||||
readonly reason?: string;
|
||||
/** 谱走完时:放行是否通过 —— **完成只出自放行通过**,引擎不自行宣布完成 */
|
||||
readonly released?: boolean;
|
||||
};
|
||||
/**
|
||||
* 落地收敛 —— app 注入 `release`(L4)。
|
||||
* 放行通过的那一刻才落地:草稿合并入正式版、动作意向执行、收敛后才发射输出口。
|
||||
*/
|
||||
export type LandingGateway = {
|
||||
land(input: {
|
||||
taskId: TaskId;
|
||||
ownerId: StaffId;
|
||||
humanCallCap: number;
|
||||
}): Promise<{
|
||||
status: 'running' | 'awaiting' | 'submitted' | 'finished' | 'blocked';
|
||||
reason?: string;
|
||||
converged: boolean;
|
||||
emittedPorts: readonly string[];
|
||||
ledgerRowsMerged: number;
|
||||
}>;
|
||||
};
|
||||
export type MemoryRecorder = {
|
||||
|
||||
+20
@@ -146,6 +146,7 @@ export declare const flowStepSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -175,6 +176,7 @@ export declare const flowStepSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -207,6 +209,7 @@ export declare const flowStepSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -234,6 +237,7 @@ export declare const flowStepSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -265,6 +269,7 @@ export declare const flowModelSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -294,6 +299,7 @@ export declare const flowModelSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -326,6 +332,7 @@ export declare const flowModelSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -353,6 +360,7 @@ export declare const flowModelSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -514,6 +522,7 @@ export declare const businessModelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -543,6 +552,7 @@ export declare const businessModelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -575,6 +585,7 @@ export declare const businessModelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -602,6 +613,7 @@ export declare const businessModelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -686,6 +698,7 @@ export declare const manifestAssetsSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -715,6 +728,7 @@ export declare const manifestAssetsSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -747,6 +761,7 @@ export declare const manifestAssetsSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -774,6 +789,7 @@ export declare const manifestAssetsSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -1034,6 +1050,7 @@ export declare const activityManifestSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -1063,6 +1080,7 @@ export declare const activityManifestSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -1095,6 +1113,7 @@ export declare const activityManifestSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
@@ -1122,6 +1141,7 @@ export declare const activityManifestSchema: z.ZodObject<{
|
||||
output: z.ZodOptional<z.ZodObject<{
|
||||
domain: z.ZodString;
|
||||
object: z.ZodString;
|
||||
key: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
||||
fields: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, z.core.$strip>>;
|
||||
when: z.ZodOptional<z.ZodString>;
|
||||
|
||||
@@ -86,6 +86,20 @@ const sfeel = {
|
||||
},
|
||||
};
|
||||
|
||||
/** 延后绑定的流程层引用 —— 只用到「任务终态上报」这一件 */
|
||||
function createDeferredProcess(): {
|
||||
onTaskTerminal: ProcessService['onTaskTerminal'];
|
||||
bind(real: ProcessService): void;
|
||||
} {
|
||||
let real: ProcessService | undefined;
|
||||
return {
|
||||
onTaskTerminal: async (taskId, terminal, ports) => real?.onTaskTerminal(taskId, terminal, ports),
|
||||
bind(next) {
|
||||
real = next;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
const { db, clock, ids } = deps;
|
||||
|
||||
@@ -101,10 +115,22 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
|
||||
/* ── 任务数据:引擎读**任务视图** = 正式版 + 本任务草稿层 ───────── */
|
||||
const taskData = {
|
||||
/**
|
||||
* 任务视图 = 正式版 + 本任务草稿层(AM 4.2),再叠上起单入参。
|
||||
*
|
||||
* 作用域的**形状要对得上声明的写法**:步声明里写的是裸字段名
|
||||
* (`input: { pn: 'pn' }`),不是 `域.对象.行号.字段`。所以这里三层铺开:
|
||||
* ① 起单入参在底 —— 契约的 data 是这单的出发事实;
|
||||
* ② 各对象**最新一行**的字段名铺到顶层 —— 过程工作区的数据形态即草稿层;
|
||||
* ③ `域.对象` 仍保留整表,要整表的照样取得到。
|
||||
* 顶层同名以「后写的赢」为准:草稿层是这一单最新的过程事实,盖过起单入参。
|
||||
*/
|
||||
async view(taskId: TaskId) {
|
||||
// 引擎对任务视图求值,不依赖事件(AM 4.2)
|
||||
const task = await taskStore.get(taskId);
|
||||
if (task === undefined) throw new Error(`任务不存在:${taskId}`);
|
||||
const objects = await deps.ledger.listObjects();
|
||||
const scope: Record<string, unknown> = {};
|
||||
const scope: Record<string, unknown> = { ...task.data };
|
||||
|
||||
for (const address of objects) {
|
||||
const page = await deps.ledger.taskView(taskId, {
|
||||
address,
|
||||
@@ -114,6 +140,12 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
offset: 0,
|
||||
});
|
||||
scope[`${address.domain}.${address.object}`] = page.rows;
|
||||
const latest = page.rows[page.rows.length - 1];
|
||||
if (latest === undefined) continue;
|
||||
for (const [field, value] of Object.entries(latest)) {
|
||||
// 空值不盖掉已有事实:没写进去的字段不该把起单入参抹成 undefined
|
||||
if (value !== null && value !== undefined) scope[field] = value;
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
},
|
||||
@@ -295,6 +327,29 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
clock,
|
||||
});
|
||||
|
||||
/**
|
||||
* process 晚于 task 构造 —— 延后绑定(与 container 里 `TriggerMatcher` 同一手法)。
|
||||
* 未绑定时静默不报:装配尚未完成的那一瞬没有任务会终态。
|
||||
*/
|
||||
const processRef = createDeferredProcess();
|
||||
|
||||
/** 任务的输出口载荷:活动声明的必交付输出口 → 该任务视图上的字段 */
|
||||
async function outputPortsOf(taskId: TaskId): Promise<Record<string, Record<string, unknown>>> {
|
||||
const task = await taskStore.get(taskId);
|
||||
if (task === undefined) return {};
|
||||
const manifest = await deps.registry.manifestOf(task.activityId);
|
||||
const scope = await taskData.view(taskId);
|
||||
const ports: Record<string, Record<string, unknown>> = {};
|
||||
for (const port of manifest.contract.output.mandatory) {
|
||||
const payload = port.payload as { properties?: Record<string, unknown> };
|
||||
const fields = Object.keys(payload.properties ?? {});
|
||||
ports[port.name] = Object.fromEntries(
|
||||
fields.filter((f) => scope[f] !== undefined).map((f) => [f, scope[f]]),
|
||||
);
|
||||
}
|
||||
return ports;
|
||||
}
|
||||
|
||||
/* ── task(L6):范式在此汇流,对上层不可区分 ──────────────────── */
|
||||
const task = createTaskService({
|
||||
store: taskStore,
|
||||
@@ -330,7 +385,12 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
load: (taskId, model) => flow.load(taskId, model as never).then(() => undefined),
|
||||
advance: async (taskId) => {
|
||||
const outcome = await flow.advance(taskId);
|
||||
return { status: outcome.status, ...(outcome.blockedReason === undefined ? {} : { reason: outcome.blockedReason }) };
|
||||
return {
|
||||
status: outcome.status,
|
||||
...(outcome.blockedReason === undefined ? {} : { reason: outcome.blockedReason }),
|
||||
// 谱走完时把放行裁决带上来 —— 完成只出自放行通过
|
||||
...(outcome.released === undefined ? {} : { released: outcome.released }),
|
||||
};
|
||||
},
|
||||
onEvent: async (taskId, event) => {
|
||||
const outcome = await flow.resume(taskId, {
|
||||
@@ -342,6 +402,22 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
},
|
||||
},
|
||||
},
|
||||
landing: {
|
||||
/** 放行通过即刻落地:草稿合并 + 动作执行(附幂等键)→ 收敛才发射输出口(OS 7.3) */
|
||||
async land(input) {
|
||||
const outcome = await deps.release.land({
|
||||
taskId: input.taskId,
|
||||
ownerId: input.ownerId,
|
||||
humanCallCap: input.humanCallCap,
|
||||
selectedPorts: {},
|
||||
});
|
||||
return {
|
||||
converged: outcome.verdict.kind === 'converged',
|
||||
emittedPorts: outcome.emittedPorts,
|
||||
ledgerRowsMerged: outcome.ledgerRowsMerged,
|
||||
};
|
||||
},
|
||||
},
|
||||
memory: {
|
||||
append: memoryRecorder.append as never,
|
||||
seal: (taskId) => deps.memory.seal(taskId),
|
||||
@@ -375,6 +451,17 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
occurredAt: clock.now().toISOString(),
|
||||
source: { kind: 'engine', detail: 'task' },
|
||||
});
|
||||
|
||||
/*
|
||||
* 任务终态到达 → 通知流程层(L7)。
|
||||
*
|
||||
* task 在 L6、process 在 L7,task 不得反向依赖 process —— 这一跳由 app 这层缝合。
|
||||
* 「工作流状态是聚合投影」的前提是节点实例的终态**报得上去**:不报,
|
||||
* 流就停在那个节点上,既不流转也不走失败走向。
|
||||
* 用延后绑定是因为 process 在本函数里晚于 task 构造。
|
||||
*/
|
||||
const ports = await outputPortsOf(taskId);
|
||||
await processRef.onTaskTerminal(taskId, terminal, ports);
|
||||
},
|
||||
},
|
||||
notifier: {
|
||||
@@ -395,7 +482,7 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
});
|
||||
|
||||
/* ── process(L7) ─────────────────────────────────────────────── */
|
||||
const process = createProcessService({
|
||||
const process: ProcessService = createProcessService({
|
||||
store: createProcessStore(db),
|
||||
activities: {
|
||||
async faces() {
|
||||
@@ -556,5 +643,8 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring {
|
||||
ids,
|
||||
});
|
||||
|
||||
// 延后绑定落定:此后任务终态才报得到流程层
|
||||
processRef.bind(process);
|
||||
|
||||
return { task, process, trigger };
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
mayTakeEffect,
|
||||
shouldSeedAsset,
|
||||
} from '../internal/domain/versioning.ts';
|
||||
import type { AssetVersion, PackageVersion, ReplayCase } from '../internal/domain/versioning.ts';
|
||||
import type { AssetKind, AssetVersion, PackageVersion, ReplayCase } from '../internal/domain/versioning.ts';
|
||||
import { scanArtifact } from '../internal/domain/static-audit.ts';
|
||||
|
||||
const pkg: PackageVersion = {
|
||||
@@ -150,3 +150,31 @@ describe('scanArtifact —— 活动包零环境能力(ADR-004)', () => {
|
||||
expect(scanArtifact('import fs from "node:fs";').capabilities).toContain('node:fs');
|
||||
});
|
||||
});
|
||||
|
||||
describe('包新版携带的资产:播下一版,不恒播 v1', () => {
|
||||
const asset = (kind: AssetKind, version: number): AssetVersion => ({
|
||||
activityId: 'a1',
|
||||
kind,
|
||||
version,
|
||||
effective: version === 1,
|
||||
source: 'package-seed',
|
||||
createdAt: '2026-07-27T00:00:00.000Z',
|
||||
});
|
||||
|
||||
it('库里已有 v1 时,新包的资产应播 v2 —— 否则只有首版资产此生有效', () => {
|
||||
const existing = [asset('business-model', 1)];
|
||||
expect(shouldSeedAsset(existing, 'business-model', 2)).toBe(true);
|
||||
// 恒播 v1 就会被这条挡掉,新包的业务模型永远进不来
|
||||
expect(shouldSeedAsset(existing, 'business-model', 1)).toBe(false);
|
||||
});
|
||||
|
||||
it('进化管线放行出的更高版不被播种盖过', () => {
|
||||
const existing = [asset('business-model', 1), asset('business-model', 5)];
|
||||
expect(shouldSeedAsset(existing, 'business-model', 2)).toBe(false);
|
||||
expect(shouldSeedAsset(existing, 'business-model', 6)).toBe(true);
|
||||
});
|
||||
|
||||
it('库里没有该类资产时从 v1 起播', () => {
|
||||
expect(shouldSeedAsset([], 'dmn', 1)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ import { activityAssetTable, activityPackageTable, assetIncrementTable } from '.
|
||||
export function createRegistryStore(db: Db): RegistryStore {
|
||||
return {
|
||||
async savePackage(manifest: ActivityManifest, artifact: string) {
|
||||
await db
|
||||
const inserted = await db
|
||||
.insert(activityPackageTable)
|
||||
.values({
|
||||
activityId: manifest.identity.activityId,
|
||||
@@ -25,7 +25,10 @@ export function createRegistryStore(db: Db): RegistryStore {
|
||||
state: 'active',
|
||||
enabled: true,
|
||||
})
|
||||
.onConflictDoNothing();
|
||||
.onConflictDoNothing()
|
||||
.returning({ version: activityPackageTable.version });
|
||||
// 回报是否**真的新增了这一版**:重复安装同版不该再播一次资产
|
||||
return inserted.length > 0;
|
||||
},
|
||||
|
||||
async listPackages(activityId) {
|
||||
|
||||
@@ -89,23 +89,35 @@ export function createRegistryService(deps: RegistryServiceDeps): ActivityRegist
|
||||
if (!verdict.accepted) throw new InstallRejectedError(verdict);
|
||||
|
||||
// 安装恒为新增、版本并存;在途任务按其启动时版本跑完
|
||||
await deps.store.savePackage(manifest, artifact);
|
||||
const isNewPackageVersion = await deps.store.savePackage(manifest, artifact);
|
||||
|
||||
// 资产初始版随包播种 —— **不覆盖已有更高的资产版**
|
||||
/*
|
||||
* 资产初始版随包播种。
|
||||
*
|
||||
* 播的是**下一个**资产版,不是恒定的 v1:包版本与资产版本是两条序列,
|
||||
* 但新包携带的初始资产同样过了安装两审,理应可用 —— 若恒播 v1,
|
||||
* 就只有第一个包版本的资产此生有效,之后再装什么都跑旧的。
|
||||
* 「不覆盖已有更高的资产版」仍然成立:进化管线放行出来的版本号更高,播种不会盖过它。
|
||||
* 同版重复安装不再播种;在途任务按启动时版本跑完,不受影响。
|
||||
*/
|
||||
const existing = await deps.store.listAssets(manifest.identity.activityId);
|
||||
const now = deps.clock.now().toISOString();
|
||||
if (isNewPackageVersion) {
|
||||
for (const kind of SEED_KINDS) {
|
||||
if (!shouldSeedAsset(existing, kind, 1)) continue;
|
||||
const highest = existing.filter((a) => a.kind === kind).reduce((max, a) => Math.max(max, a.version), 0);
|
||||
const seedVersion = highest + 1;
|
||||
if (!shouldSeedAsset(existing, kind, seedVersion)) continue;
|
||||
const asset: AssetVersion = {
|
||||
activityId: manifest.identity.activityId,
|
||||
kind,
|
||||
version: 1,
|
||||
version: seedVersion,
|
||||
effective: true,
|
||||
source: 'package-seed',
|
||||
createdAt: now,
|
||||
};
|
||||
await deps.store.saveAsset(asset, serializeAsset(manifest, kind));
|
||||
}
|
||||
}
|
||||
|
||||
return verdict;
|
||||
},
|
||||
|
||||
@@ -8,7 +8,8 @@ export type Clock = { now(): Date };
|
||||
export type IdGenerator = { next(): string };
|
||||
|
||||
export type RegistryStore = {
|
||||
savePackage(manifest: ActivityManifest, artifact: string): Promise<void>;
|
||||
/** 返回是否新增了这一包版本(同版重复安装返回 false) */
|
||||
savePackage(manifest: ActivityManifest, artifact: string): Promise<boolean>;
|
||||
listPackages(activityId?: string): Promise<PackageVersion[]>;
|
||||
manifest(activityId: string, packageVersion?: string): Promise<ActivityManifest | undefined>;
|
||||
artifact(activityId: string, packageVersion: string): Promise<string | undefined>;
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/** flow 步序:声明校验 / 失败走向 / 兜底出参 —— domain 测试零 mock(AM 12.3) */
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { flowStepSchema } from '@contracts';
|
||||
import type { FlowStep } from '@contracts';
|
||||
import {
|
||||
checkDeclaration,
|
||||
fallbackFields,
|
||||
failureAction,
|
||||
initialPosition,
|
||||
lastStepIsAcceptance,
|
||||
markStep,
|
||||
parallelGroupComplete,
|
||||
} from '../internal/domain/step-sequence.ts';
|
||||
|
||||
const llmStep = (over: Record<string, unknown> = {}): FlowStep =>
|
||||
flowStepSchema.parse({
|
||||
kind: 'llm',
|
||||
name: 'S3',
|
||||
label: 'S3 逐条解析归一',
|
||||
input: { rfqRef: 'rfqRef' },
|
||||
output: { domain: 'quote_intake', object: 'record', fields: { pn: 'pn', brand: 'brand', eau: 'eau' } },
|
||||
model: 'quote-extractor',
|
||||
template: '解析 {{rfqRef}}',
|
||||
outputSchema: { type: 'object' },
|
||||
failure: { retry: { times: 2, backoff: 'PT30S' }, fallback: { kind: 'human', workOrder: 'execution' } },
|
||||
...over,
|
||||
});
|
||||
|
||||
describe('人兜底:出参契约属于步,不属于执行者', () => {
|
||||
it('兜底卡问的字段 = 这一步声明的出参 —— 人填完能落进作用域', () => {
|
||||
// 若只给一个笼统的「结果」框,下游按 output.fields 取值会取空,在下一步崩
|
||||
expect(fallbackFields(llmStep())).toEqual(['pn', 'brand', 'eau']);
|
||||
});
|
||||
|
||||
it('无出参声明的步不凭空造字段', () => {
|
||||
const step = flowStepSchema.parse({
|
||||
kind: 'llm',
|
||||
name: 'S9',
|
||||
label: '只说不写的一步',
|
||||
input: {},
|
||||
model: 'm',
|
||||
template: 't',
|
||||
outputSchema: { type: 'object' },
|
||||
failure: { retry: { times: 0, backoff: 'PT1S' }, fallback: { kind: 'blocked' } },
|
||||
});
|
||||
expect(fallbackFields(step)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('失败走向声明给定,不临场发明', () => {
|
||||
it('重试次数未用尽 → retry', () => {
|
||||
expect(failureAction(llmStep(), 1).kind).toBe('retry');
|
||||
});
|
||||
|
||||
it('重试用尽 → 按声明的 fallback 转人', () => {
|
||||
const action = failureAction(llmStep(), 2);
|
||||
expect(action.kind).toBe('human');
|
||||
});
|
||||
|
||||
it('声明 blocked 的步不转人 —— 走向是声明的,不是猜的', () => {
|
||||
const step = llmStep({ failure: { retry: { times: 0, backoff: 'PT1S' }, fallback: { kind: 'blocked' } } });
|
||||
expect(failureAction(step, 0).kind).toBe('blocked');
|
||||
});
|
||||
});
|
||||
|
||||
describe('步序位置', () => {
|
||||
it('初始位置每步待跑', () => {
|
||||
const position = initialPosition([llmStep(), llmStep({ name: 'S4' })]);
|
||||
expect(position.index).toBe(0);
|
||||
expect(position.steps.map((s) => s.state)).toEqual(['pending', 'pending']);
|
||||
});
|
||||
|
||||
it('markStep 只改那一步,其余原样', () => {
|
||||
const position = initialPosition([llmStep(), llmStep({ name: 'S4' })]);
|
||||
const next = markStep(position, 1, { state: 'done' });
|
||||
expect(next.steps.map((s) => s.state)).toEqual(['pending', 'done']);
|
||||
});
|
||||
|
||||
it('并行组要全完成才算完成', () => {
|
||||
const position = markStep(initialPosition([llmStep(), llmStep({ name: 'S4' })]), 0, { state: 'done' });
|
||||
expect(parallelGroupComplete(position, ['S3', 'S4'])).toBe(false);
|
||||
expect(parallelGroupComplete(markStep(position, 1, { state: 'done' }), ['S3', 'S4'])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('声明校验', () => {
|
||||
it('步名重复即拒', () => {
|
||||
expect(checkDeclaration([llmStep(), llmStep()]).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('末步是验收工单可辨', () => {
|
||||
const acceptance: FlowStep = flowStepSchema.parse({
|
||||
kind: 'human',
|
||||
name: 'S6',
|
||||
label: '验收',
|
||||
input: {},
|
||||
workOrder: 'acceptance',
|
||||
card: {},
|
||||
deadline: 'P1D',
|
||||
failure: { retry: { times: 0, backoff: 'PT1S' }, fallback: { kind: 'blocked' } },
|
||||
});
|
||||
expect(lastStepIsAcceptance([llmStep(), acceptance])).toBe(true);
|
||||
expect(lastStepIsAcceptance([llmStep()])).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,8 @@ export type StepRuntime = {
|
||||
readonly attempt: number;
|
||||
readonly output?: Record<string, unknown>;
|
||||
readonly error?: string;
|
||||
/** 验收工单的放行裁决:pass / 驳回类别 —— 末步据此定终局 */
|
||||
readonly verdict?: string;
|
||||
};
|
||||
|
||||
export type FlowPosition = {
|
||||
@@ -121,3 +123,25 @@ export function parallelGroupComplete(position: FlowPosition, members: readonly
|
||||
return runtime?.state === 'done' || runtime?.state === 'skipped';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 人兜底时要回填的字段 —— 取自这一步**声明的出参**。
|
||||
*
|
||||
* 出参契约属于**步**,不属于执行者:同一步无论由 LLM、工具还是人做完,
|
||||
* 落进作用域的形状必须一致。若兜底卡只给一个笼统的「结果」文本框,
|
||||
* 人填了也落不进去 —— 下游按 `output.fields` 取值,取不到就在下一步崩。
|
||||
*
|
||||
* 返回键名数组,与 human 步的 `card.fields` 同形:卡的渲染只有一套。
|
||||
*/
|
||||
export function fallbackFields(step: FlowStep): readonly string[] {
|
||||
return step.output === undefined ? [] : Object.values(step.output.fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 末步的放行裁决是否「通过」—— **完成只出自放行通过**(OS 05)。
|
||||
* 驳回(重做 / 迭代)不是完成:谱虽走完,任务不得进 released。
|
||||
*/
|
||||
export function lastVerdictPassed(position: FlowPosition): boolean {
|
||||
const last = position.steps[position.steps.length - 1];
|
||||
return last?.verdict === 'pass';
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ import type {
|
||||
import type { FlowPosition } from '../domain/step-sequence.ts';
|
||||
import {
|
||||
checkDeclaration,
|
||||
fallbackFields,
|
||||
lastStepIsAcceptance,
|
||||
lastVerdictPassed,
|
||||
failureAction,
|
||||
initialPosition,
|
||||
markStep,
|
||||
@@ -52,15 +55,29 @@ export function createFlowRunner(deps: FlowRunnerDeps): FlowEngineService {
|
||||
for (const [field, path] of Object.entries(step.output.fields)) {
|
||||
patch[field] = output[path] ?? output[field];
|
||||
}
|
||||
// 写哪一行:主键取自出参,取不到再回作用域(起单入参往往就带着主键)
|
||||
const scope = await deps.data.view(taskId);
|
||||
const key: Record<string, string | number> = {};
|
||||
for (const [column, path] of Object.entries(step.output.key)) {
|
||||
const value = output[path] ?? scope[path];
|
||||
// 主键值只能是标量;取不到就不填,让台账的非空约束在合并时如实报出来
|
||||
if (typeof value === 'string' || typeof value === 'number') key[column] = value;
|
||||
}
|
||||
await deps.data.draftWrite({
|
||||
taskId,
|
||||
domain: step.output.domain,
|
||||
object: step.output.object,
|
||||
key: {},
|
||||
key,
|
||||
patch,
|
||||
});
|
||||
}
|
||||
|
||||
/** 回传协议 → 出参:取 `values`;非回传形状的人事件按原样当出参 */
|
||||
function replyValuesOf(payload: Record<string, unknown>): Record<string, unknown> {
|
||||
const values = payload['values'];
|
||||
return typeof values === 'object' && values !== null ? (values as Record<string, unknown>) : payload;
|
||||
}
|
||||
|
||||
function inputOf(step: FlowStep, scope: Record<string, unknown>): Record<string, unknown> {
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const [key, path] of Object.entries(step.input)) {
|
||||
@@ -188,7 +205,13 @@ export function createFlowRunner(deps: FlowRunnerDeps): FlowEngineService {
|
||||
ownerId: context.ownerId,
|
||||
humanCallCap: context.humanCallCap,
|
||||
workOrder: action.workOrder,
|
||||
card: { title: `步「${step.label}」重试仍败,转人兜底`, reason: error },
|
||||
card: {
|
||||
title: `步「${step.label}」重试仍败,转人兜底`,
|
||||
reason: error,
|
||||
// 兜底的人要交的东西,和这一步**本来该产出的东西**同形:
|
||||
// 出参契约是步的契约,不因换谁来做而变(统一执行契约)。
|
||||
fields: fallbackFields(step),
|
||||
},
|
||||
});
|
||||
await deps.listeners.register({
|
||||
taskId,
|
||||
@@ -231,8 +254,10 @@ export function createFlowRunner(deps: FlowRunnerDeps): FlowEngineService {
|
||||
|
||||
switch (action.kind) {
|
||||
case 'finished': {
|
||||
// 末步是验收工单时,终态由其裁决给出;此处只报「谱走完」
|
||||
return { position, status: 'finished', released: false };
|
||||
// 末步是验收工单时,终态由其**裁决**给出 —— 完成只出自放行通过。
|
||||
// 裁决记在末步的 runtime 上(resume 时落笔),谱走完在这里读出来。
|
||||
const released = lastStepIsAcceptance(model.steps) && lastVerdictPassed(position);
|
||||
return { position, status: 'finished', released };
|
||||
}
|
||||
case 'skip': {
|
||||
await deps.memory.append({
|
||||
@@ -268,10 +293,14 @@ export function createFlowRunner(deps: FlowRunnerDeps): FlowEngineService {
|
||||
title: `事件到达,步 ${index + 1} 完成条件满足(${event.kind})`,
|
||||
detail: { ref: event.ref },
|
||||
});
|
||||
// 放行裁决落笔在这一步的运行时上:谱走完时据此定终局
|
||||
const verdict = event.kind === 'human' ? String(event.payload['verdict'] ?? '') : '';
|
||||
if (step !== undefined && event.kind === 'human') {
|
||||
await writeOutput(taskId, step, event.payload);
|
||||
// 人事件的载荷是**回传协议**的形状(`{mode, workOrderId, values}`),
|
||||
// 出参在 `values` 里;直接把整个载荷当出参写,落进去的会是协议壳而不是答案。
|
||||
await writeOutput(taskId, step, replyValuesOf(event.payload));
|
||||
}
|
||||
const next = markStep(position, index, { state: 'done' });
|
||||
const next = markStep(position, index, verdict === '' ? { state: 'done' } : { state: 'done', verdict });
|
||||
await deps.state.save(taskId, model, next);
|
||||
return { position: next, status: 'running' };
|
||||
},
|
||||
|
||||
@@ -55,6 +55,8 @@ export type Task = {
|
||||
readonly reason?: string;
|
||||
/** 装载信封:包版本 + 各资产生效版 —— 行为可归因 */
|
||||
readonly envelope: Readonly<Record<string, unknown>>;
|
||||
/** 起单入参:契约的 data —— 引擎求值的作用域底料 */
|
||||
readonly data: Readonly<Record<string, unknown>>;
|
||||
readonly caps: BudgetCaps;
|
||||
readonly used: Consumption;
|
||||
readonly startedAt: string;
|
||||
|
||||
@@ -21,6 +21,8 @@ export const taskTable = sys.table(
|
||||
reason: text('reason'),
|
||||
/** 装载信封:包版本 + 各资产生效版 —— 行为可归因 */
|
||||
envelope: jsonb('envelope').notNull(),
|
||||
/** 起单入参 —— 步序声明按字段名读它;不存下来,断点续跑后作用域就空了 */
|
||||
inputData: jsonb('input_data').notNull().default({}),
|
||||
caps: jsonb('caps').notNull(),
|
||||
usedSteps: integer('used_steps').notNull().default(0),
|
||||
usedTokens: integer('used_tokens').notNull().default(0),
|
||||
|
||||
@@ -24,6 +24,7 @@ function toTask(row: Row): Task {
|
||||
...(row.terminal === null ? {} : { terminal: row.terminal as TerminalState }),
|
||||
...(row.reason === null ? {} : { reason: row.reason }),
|
||||
envelope: row.envelope as Record<string, unknown>,
|
||||
data: row.inputData as Record<string, unknown>,
|
||||
caps: row.caps as BudgetCaps,
|
||||
used: {
|
||||
steps: row.usedSteps,
|
||||
@@ -49,6 +50,7 @@ export function createTaskStore(db: Db): TaskStore {
|
||||
title: task.title,
|
||||
runtime: task.runtime,
|
||||
envelope: task.envelope,
|
||||
inputData: task.data,
|
||||
caps: task.caps,
|
||||
startedAt: new Date(task.startedAt),
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
Clock,
|
||||
IdGenerator,
|
||||
InteractionPhaseSetter,
|
||||
LandingGateway,
|
||||
ListenerProbe,
|
||||
MemoryRecorder,
|
||||
ParadigmEngine,
|
||||
@@ -31,6 +32,8 @@ export type TaskServiceDeps = {
|
||||
/** 范式引擎按 paradigm 分派 —— 对上层不可区分 */
|
||||
readonly engines: Readonly<Record<'loop' | 'flow', ParadigmEngine>>;
|
||||
readonly memory: MemoryRecorder;
|
||||
/** 落地收敛 —— 放行通过的那一刻才碰事实 */
|
||||
readonly landing: LandingGateway;
|
||||
readonly listeners: ListenerProbe;
|
||||
readonly persistence: PersistenceProbe;
|
||||
readonly events: TaskEventPublisher;
|
||||
@@ -80,6 +83,7 @@ export function createTaskService(deps: TaskServiceDeps): TaskService {
|
||||
ownerId: input.ownerId,
|
||||
title: input.title,
|
||||
runtime: 'running',
|
||||
data: input.data,
|
||||
envelope: loaded.envelope,
|
||||
caps: loaded.caps,
|
||||
used: ZERO_CONSUMPTION,
|
||||
@@ -147,6 +151,38 @@ export function createTaskService(deps: TaskServiceDeps): TaskService {
|
||||
const finished = await this.finish(taskId, { kind: 'blocked', reason: outcome.reason ?? '无法推进' });
|
||||
return { task: finished, verdict, progressed: true };
|
||||
}
|
||||
|
||||
/*
|
||||
* 谱走完了。**完成只出自放行通过**(OS 05):
|
||||
* · 放行通过 → 落地收敛(草稿合并 + 动作执行 → 收敛才发射输出口)→ released;
|
||||
* · 未放行(还没裁 / 驳回)→ 不是完成,也**不再空推** —— 挂起等人,
|
||||
* 否则推进器会一拍一拍把预算烧到 exhausted,把「没人裁」误报成「跑爆了」。
|
||||
*/
|
||||
if (outcome.status === 'finished') {
|
||||
if (outcome.released !== true) {
|
||||
const waiting = await deps.store.update(taskId, { runtime: 'awaiting-human' });
|
||||
await deps.interaction.setPhase(taskId, 'awaiting-event');
|
||||
return { task: waiting, verdict, progressed: false };
|
||||
}
|
||||
const landed = await deps.landing.land({
|
||||
taskId,
|
||||
ownerId: task.ownerId,
|
||||
humanCallCap: task.caps.humanCalls,
|
||||
});
|
||||
if (!landed.converged) {
|
||||
// 落地未收敛:输出口不得发射,任务受阻待人(落地失败卡已发)
|
||||
const blocked = await this.finish(taskId, { kind: 'blocked', reason: '落地未收敛,输出口未发射' });
|
||||
return { task: blocked, verdict, progressed: true };
|
||||
}
|
||||
await deps.memory.append({
|
||||
taskId,
|
||||
kind: 'engine-transition',
|
||||
title: `落地收敛:合并 ${landed.ledgerRowsMerged} 行,发射输出口 ${landed.emittedPorts.join('、') || '—'}`,
|
||||
});
|
||||
const finished = await this.finish(taskId, { kind: 'released' });
|
||||
return { task: finished, verdict, progressed: true };
|
||||
}
|
||||
|
||||
return { task: updated, verdict, progressed: true };
|
||||
},
|
||||
|
||||
|
||||
@@ -38,11 +38,30 @@ export type SchemaValidator = {
|
||||
/** 范式引擎 —— loop / flow 在此汇流;对上层不可区分(§9 双层边界) */
|
||||
export type ParadigmEngine = {
|
||||
load(taskId: TaskId, model: unknown): Promise<void>;
|
||||
advance(taskId: TaskId): Promise<{ status: 'running' | 'awaiting' | 'submitted' | 'finished' | 'blocked'; reason?: string }>;
|
||||
advance(taskId: TaskId): Promise<EngineOutcome>;
|
||||
onEvent(
|
||||
taskId: TaskId,
|
||||
event: { kind: 'data' | 'time' | 'human' | 'control'; ref: string; payload: Record<string, unknown> },
|
||||
): Promise<{ status: 'running' | 'awaiting' | 'submitted' | 'finished' | 'blocked'; reason?: string }>;
|
||||
): Promise<EngineOutcome>;
|
||||
};
|
||||
|
||||
export type EngineOutcome = {
|
||||
readonly status: 'running' | 'awaiting' | 'submitted' | 'finished' | 'blocked';
|
||||
readonly reason?: string;
|
||||
/** 谱走完时:放行是否通过 —— **完成只出自放行通过**,引擎不自行宣布完成 */
|
||||
readonly released?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* 落地收敛 —— app 注入 `release`(L4)。
|
||||
* 放行通过的那一刻才落地:草稿合并入正式版、动作意向执行、收敛后才发射输出口。
|
||||
*/
|
||||
export type LandingGateway = {
|
||||
land(input: { taskId: TaskId; ownerId: StaffId; humanCallCap: number }): Promise<{
|
||||
converged: boolean;
|
||||
emittedPorts: readonly string[];
|
||||
ledgerRowsMerged: number;
|
||||
}>;
|
||||
};
|
||||
|
||||
export type MemoryRecorder = {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE "sys"."task" ADD COLUMN "input_data" jsonb DEFAULT '{}'::jsonb NOT NULL;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -64,6 +64,13 @@
|
||||
"when": 1785094481010,
|
||||
"tag": "0008_strange_quasar",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 9,
|
||||
"version": "7",
|
||||
"when": 1785096293279,
|
||||
"tag": "0009_cute_bromley",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -93,8 +93,19 @@ const stepBase = {
|
||||
label: z.string().min(1),
|
||||
/** 入参映射:取自任务数据 / 上步出参 */
|
||||
input: z.record(z.string(), z.string()).default({}),
|
||||
/** 出参写入:落任务数据(草稿态) */
|
||||
output: z.object({ domain: z.string(), object: z.string(), fields: z.record(z.string(), z.string()) }).optional(),
|
||||
/**
|
||||
* 出参写入:落任务数据(草稿态)。
|
||||
* `key` 指明**写哪一行**(主键列 → 作用域路径)—— 台账对象几乎都有主键,
|
||||
* 不声明键就只能写出无主键的行,合并进正式版时必被非空约束挡下。
|
||||
*/
|
||||
output: z
|
||||
.object({
|
||||
domain: z.string(),
|
||||
object: z.string(),
|
||||
key: z.record(z.string(), z.string()).default({}),
|
||||
fields: z.record(z.string(), z.string()),
|
||||
})
|
||||
.optional(),
|
||||
/** 条件跳步:任务数据上的确定性谓词(S-FEEL),零 LLM */
|
||||
when: z.string().optional(),
|
||||
failure: stepFailurePolicySchema,
|
||||
|
||||
Reference in New Issue
Block a user