M5(完成): @activity-sdk 与首个活动包 quote-intake

@activity-sdk(§8.2 / ADR-004):
- 基座六件接口(契约 / 交互 / 记忆 / 数据 / 工具 / LLM)—— 活动看到的全部世界
- defineActivity() 的 ABI;本地开发宿主(mock 工具表 + 模拟工位 + 录制夹具),
  宿主自身就守三规矩:裸调用拒发、视图含脚本拒推、监听无时限拒登记

activities/quote-intake —— 统一报价 A1 · RFQ 需求分析(flow):
- 契约七件 / 步序声明五步(LLM 抽取 → 条件跳步补全 → 查历史价 → DMN 打标 → 验收放行)
- 三分类规则 P-03 落 DMN 决策表(C 优先于 A,命中行留痕)
- 台账声明两对象、监听时限必配、SLA 落 Harness

depcruise 实测拦下活动包越界 import(activities → apps 双向隔离),
测试遂按边界拆分:活动侧只用 @sdk/@contracts/@sfeel

358 个测试通过,门禁五道全绿

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
JCAI Main Agent
2026-07-27 02:09:43 +08:00
co-authored by Claude Opus 5
parent 4ad901c452
commit c6cdb4c310
11 changed files with 867 additions and 20 deletions
+63
View File
@@ -0,0 +1,63 @@
/**
* 统一报价 A1 · RFQ 需求分析 —— 活动包代码入口(ADR-004:默认导出 defineActivity 的返回值)。
*
* 这是 **flow** 活动:下一步由步序声明给定,引擎照谱推进;
* 本文件承担声明装不下的那部分 —— 视图流控与纯工具(打标)。
* **零环境能力**:一切能力经基座六件注入。
*/
import { defineActivity } from '@sdk';
import type { ActivityBase, ActivityOutcome } from '@sdk';
const INTAKE = 'quote_intake.record';
const TYPE_TABLE = 'quote_intake.type_table';
export default defineActivity({
name: 'quote-intake',
paradigm: 'flow',
async run(base: ActivityBase): Promise<ActivityOutcome> {
const records = await base.ledger.read(INTAKE, { customer_code: String(base.contract.data['customerCode'] ?? '') });
const typed = await base.ledger.read(TYPE_TABLE);
// 视图流控:按局面推结构化块 —— 内容归活动,容器归系统
await base.interaction.pushView([
{
t: 'kv',
title: '受理概览',
items: [
{ k: '客户', v: String(base.contract.data['customerCode'] ?? '') },
{ k: '已归一', v: `${records.length} 条` },
{ k: '已打标', v: `${typed.length} 条` },
],
},
{
t: 'table',
title: '统一受理记录',
cols: ['PN', '厂牌', 'EAU', 'Type'],
rows: records.map((r) => [
String(r['pn'] ?? ''),
String(r['brand'] ?? ''),
String(r['eau'] ?? ''),
String(r['type_tag'] ?? '未打标'),
]),
},
]);
const untyped = records.filter((r) => r['type_tag'] === undefined || r['type_tag'] === null);
if (untyped.length > 0) {
await base.interaction.say(`还有 ${untyped.length} 条未打标,继续按三分类规则 P-03 判定。`, 'conclusion');
return { kind: 'await', reason: '等待打标步完成' };
}
await base.interaction.say(
`${records.length} 条已全部打标:` +
`A ${count(records, 'A')} 条直通定价,B ${count(records, 'B')} 条转寻源,C ${count(records, 'C')} 条转选型。`,
'criterion',
);
return { kind: 'submit', deliverable: 'intake-record', rationale: '逐条已打标,必交付物齐备' };
},
});
function count(rows: ReadonlyArray<Record<string, unknown>>, tag: string): number {
return rows.filter((r) => r['type_tag'] === tag).length;
}
+268
View File
@@ -0,0 +1,268 @@
/**
* 活动包清单 —— 统一报价 A1 · RFQ 需求分析(受理归一)。
*
* 业务素材出处:docs/MVP示例工作流.html §1.1;按 README《归一化对照表》映射为:
* SOP 节点 → **标准活动(flow)**;作业指导书 S1…S6 → **步序声明**(四种步型);
* 步内判断 D1 完整度 → **条件谓词**;三分类规则 P-03 → **DMN 决策表**;
* SLA(受理<15min、打标<45min)→ Harness 时限与预算。
*/
import type { ActivityManifest, DmnModel } from '@contracts';
import { activityIdSchema } from '@contracts';
const INTAKE_DOMAIN = 'quote_intake';
const ACTIVITY_ID = activityIdSchema.parse('quote-intake');
/**
* 三分类规则 P-03 —— 把「装得下的判断」从 LLM 手里拿走。
* 由纯工具步 `quote-intake.classify` 逐条求值,命中规则行留痕。
*/
export const P03_DMN: DmnModel = {
drd: [{ decision: 'p03-type', requires: [], inputs: ['historyDays', 'marketStable', 'lifecycle'] }],
tables: [{
id: 'p03-type',
label: '三分类规则 P-03',
hitPolicy: 'FIRST' as const,
inputs: [
{ name: 'historyDays', expression: 'historyDays' },
{ name: 'marketStable', expression: 'marketStable' },
{ name: 'lifecycle', expression: 'lifecycle' },
],
outputs: [{ name: 'type' }, { name: 'play' }],
rules: [
{ id: 'p03-c', when: ['-', '-', '"EOL","缺货","要求替代"'], then: ['C', '转案处理'], annotation: 'EOL/缺货/要替代 → C' },
{ id: 'p03-a', when: ['<= 90', 'true', '-'], then: ['A', '直接快答'], annotation: '历史价≤90天且行情稳 → A' },
{ id: 'p03-b', when: ['-', '-', '-'], then: ['B', '重估后报'], annotation: '无历史/过期/波动 → B' },
],
}],
};
export const manifest: ActivityManifest = {
identity: {
activityId: ACTIVITY_ID,
name: 'A1 · RFQ 需求分析',
packageVersion: '0.1.0',
category: '统一报价',
paradigm: 'flow',
sdkVersion: '0.1.0-m5',
checksum: 'dev-checksum-quote-intake',
},
/* 契约七件 */
contract: {
activityId: ACTIVITY_ID,
version: '0.1.0',
input: {
data: {
type: 'object',
required: ['customerCode', 'rfqRef'],
properties: {
customerCode: { type: 'string' },
rfqRef: { type: 'string' },
subject: { type: 'string' },
},
},
messageAllowed: true,
messageHint: '客户口头急单等特殊性写这里',
},
output: {
mandatory: [
{
name: 'intake',
payload: {
type: 'object',
required: ['records'],
properties: { records: { type: 'array' } },
},
description: '统一受理记录(已打标)',
},
],
selective: [],
},
requiredDeliverables: [
{ key: 'intake-record', label: '统一受理记录(打标)' },
{ key: 'type-table', label: '料号分类表' },
],
acceptanceCriteria: [
{ key: 'fields-complete', label: '八字段齐(PN/EAU/交期为必要三要素)', level: 'L1', predicate: 'missingKeyFields = 0' },
{ key: 'typed', label: '每条都已打标 A/B/C', level: 'L2', predicate: 'untyped = 0' },
{ key: 'downgrade-safe', label: '吃不准降 B,不许臆断 A', level: 'L3' },
{ key: 'owner-release', label: 'BD 放行', level: 'L5' },
],
prohibitions: [
{ key: 'no-guess-a', statement: '吃不准的一律降 B,不得臆断为 A' },
{ key: 'no-external-write', statement: '不得在放行前写任何外部系统' },
],
authorization: {
discretion: [{ key: 'ask-back', statement: '缺次要字段可受理并追问,缺 PN/数量/交期必须退回补全' }],
preauthorizedActions: [],
humanCallBudget: 3,
},
resources: {
tools: [{ name: 'crm.history-price-read' }],
skills: [],
models: ['quote-extractor'],
roles: ['BD'],
budget: { steps: 40, tokens: 120_000, activeMinutes: 60, humanCalls: 3 },
},
},
/* 声明 */
declarations: {
models: ['quote-extractor'],
tools: [{ name: 'crm.history-price-read' }],
ledger: [
{
domain: INTAKE_DOMAIN,
object: 'record',
label: '统一受理记录',
fields: [
{ name: 'customer_code', type: 'text', primaryKey: true, masked: false, label: '客户码' },
{ name: 'pn', type: 'text', primaryKey: true, masked: false, label: 'PN' },
{ name: 'brand', type: 'text', primaryKey: false, masked: false, label: '厂牌' },
{ name: 'eau', type: 'integer', primaryKey: false, masked: false, label: 'EAU' },
{ name: 'type_tag', type: 'text', primaryKey: false, masked: false, label: 'Type 标' },
{ name: 'target_price', type: 'number', primaryKey: false, masked: false, label: '目标价' },
{ name: 'lead_time', type: 'text', primaryKey: false, masked: false, label: '交期' },
{ name: 'status', type: 'text', primaryKey: false, masked: false, label: '状态' },
],
},
{
domain: INTAKE_DOMAIN,
object: 'type_table',
label: '料号分类表',
fields: [
{ name: 'pn', type: 'text', primaryKey: true, masked: false },
{ 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: '历史价命中' },
],
},
],
listeners: [
{
origin: 'static',
eventType: 'human',
keyFilter: { kind: 'elicitation' },
semantic: 'complete-step',
// 时限必配 —— 悬空监听安装时拒绝
deadline: 'P1D',
escalation: ['nudge', 'escalate'],
},
],
harness: {
memoryWindow: 20,
// SLA:受理<15min、打标<45min —— 停滞检测按此设
stallAfter: 'PT45M',
nudge: [{ after: 'PT15M', action: 'nudge' }],
retry: { times: 2, backoff: 'PT30S' },
},
},
/* 资产初始版:flow = 步序声明 */
assets: {
businessModel: {
paradigm: 'flow',
steps: [
{
kind: 'llm',
name: 'S3_normalize',
label: 'S3 逐条解析归一',
input: { rfqRef: 'rfqRef', customerCode: 'customerCode' },
output: { domain: INTAKE_DOMAIN, object: 'record', fields: { pn: 'pn', brand: 'brand', eau: 'eau' } },
model: 'quote-extractor',
template:
'按《询价受理规范》把这份 RFQ 拆解为逐条需求,抄录 PN/数量/EAU/厂牌/目标价/交期。' +
'只输出 JSON。RFQ:{{rfqRef}}',
outputSchema: {
type: 'object',
required: ['records'],
properties: {
records: {
type: 'array',
items: {
type: 'object',
required: ['pn'],
properties: {
pn: { type: 'string' },
brand: { type: 'string' },
eau: { type: 'integer' },
targetPrice: { type: 'number' },
leadTime: { type: 'string' },
},
},
},
missingKeyFields: { type: 'integer' },
},
},
failure: { retry: { times: 2, backoff: 'PT30S' }, fallback: { kind: 'human', workOrder: 'execution' } },
},
{
kind: 'human',
name: 'S2_ask_back',
label: 'S2 追问补全信息',
// D1 判断完整度:缺 PN/数量/交期三要素才走补全 —— 条件必谓词,由引擎求值
when: 'missingKeyFields > 0',
input: {},
workOrder: 'execution',
card: { title: '缺关键字段,请向客户追问补全', fields: ['pn', 'eau', 'leadTime'] },
deadline: 'P1D',
failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'tool',
name: 'S4_history',
label: 'S4 查历史价',
input: { pn: 'pn' },
output: { domain: INTAKE_DOMAIN, object: 'type_table', fields: { history_hit: 'hit' } },
tool: 'crm.history-price-read',
failure: { retry: { times: 2, backoff: 'PT1M' }, fallback: { kind: 'human', workOrder: 'execution' } },
},
{
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' } },
tool: 'quote-intake.classify',
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'human',
name: 'S6_release',
label: 'S6 分流复核与派单 · 验收放行',
input: {},
workOrder: 'acceptance',
card: { title: '统一受理记录(打标)请验收' },
deadline: 'P1D',
failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } },
},
],
parallelGroups: [],
},
skills: [],
viewTemplates: [
{
name: 'intake-summary',
html: '<div class="jc-card"><h3>统一受理记录</h3><p>已归一 <b data-slot="count"></b> 条</p></div>',
},
],
cardSchemas: {},
distillHooks: [
{
on: 'terminal',
prompt: '归纳本单受理归一的经验:字段缺口形态、打标依据、被驳回的理由。',
},
],
},
/* 样例集 —— 首装审以静态审 + 样例集替代回放审 */
samples: [
{
name: '车规 Analog 询价',
input: { customerCode: 'C001', rfqRef: 'mail:m-1001', subject: '询价 RFQ - 车规 Analog' },
expect: { ports: ['intake'] },
},
],
entry: { file: 'index.js', checksum: 'dev-entry-quote-intake' },
};