Files
JX-BPOS/apps/api/src/app/seed-mvp.ts
T
ChaiHaoandClaude Opus 5 8cb00d1ff6 三面拆分⑫:设计台九区一级目录 —— 一区一内容,测试台收成单例仿真
设计中心从「蓝图 + 四库」摊成九区,顺序即设计的次序:
蓝图 → 触发器 → 流程包 → 活动库 → 工具箱 → 数据域 → 知识库 → 大模型 → 测试台。
触发器与大模型从「并进流程包 / 塞在系统区」里拿出来独立成区 —— 前者与流程包平级
(不入包结构、不随包版本),后者是设计者天天要碰的东西;知识库先立个诚实的空占位。

一区一内容,于是区内页签栏整条删掉(壳层在只剩一格时收起):
  · 流程包:总览的三枚计数并进货架顶端
  · 测试台:入站邮件演练移到触发器区就地验(它验的正是那一区定的规则)
  · 大模型:从系统区拆出,系统区只剩通道实例

测试台一次只跑一条流。起单前先销毁上一单,刷新页面能认回在跑的那一单,
「停止仿真」把工作流连同它派出的任务、工单、实例、留痕一并拔掉 ——
不留半单挂在别人工作台上。实测:起单 → 1 单落到 AI 工作台 → 停止 → 库里零残留。

功能工具补中文名(migration 0018,读回退到逻辑名),治理台一律主显示中文名。
顺带清掉几处说教式文案(「这些是工具,不是模型 —— 模型是它们跑在上面的发动机…」那类)。

五闸:typecheck / lint / depcruise / test 绿;api:check 快照随本提交入库。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
2026-07-29 04:35:36 +08:00

175 lines
7.1 KiB
TypeScript

/**
* MVP 底座的治理台配置 —— 四件事一次做完(README《MVP 完成判据》第 1 条的机器形态):
*
* ① 绑定 LLM 实例(四元绑定;活动只见逻辑名)
* ② 注册功能工具并逐活动给白名单(授权在白名单与契约,不在活动代码)
* ③ **经安装通道**装入六个活动槽位 —— 声明顺带把四域十八对象物化出来
* ④ 编排「统一报价」流程包 v1 并发布 + 触发器与邮件通道
*
* 活动与工具的解耦就在②③之间:槽位只声明工具**名**,注册、连接值、白名单全在这里。
*/
import type { Container } from './container.ts';
import { installSlots } from './seed-mvp-slots.ts';
import { seedMvpFlow } from './seed-mvp-flow.ts';
/** 第一方功能工具:查历史价 —— MVP 用录制回放替身代真 CRM(README:mock 只在外界) */
const HISTORY_TOOL = {
name: 'crm.history-price-read',
displayName: '历史价查询',
version: '1.0.0',
description: '读取历史价格情报:某 PN 最近一次报价距今天数、行情是否平稳、生命周期状态',
input: { type: 'object', required: ['pn'], properties: { pn: { type: 'string' } } },
output: {
type: 'object',
properties: {
historyDays: { type: 'integer' },
marketStable: { type: 'boolean' },
lifecycle: { type: 'string' },
hit: { type: 'boolean' },
},
},
effect: 'read' as const,
errors: [{ code: 'not-found', retryable: false, message: '无历史价' }],
idempotent: true,
timeoutMs: 10_000,
retries: 2,
connectionKeys: ['endpoint'],
};
/** 出站邮件 —— **写类**:过程中登记为动作意向,放行后由系统执行落地 */
const MAIL_TOOL = {
...HISTORY_TOOL,
name: 'mail.send',
displayName: '发送邮件',
description: '发出邮件(报价单 / 询价函 / 催办):写类动作,放行时才真正触达世界',
input: {
type: 'object',
required: ['to', 'subject'],
properties: { to: { type: 'string' }, subject: { type: 'string' }, body: { type: 'string' } },
},
output: { type: 'object', properties: { queued: { type: 'boolean' } } },
effect: 'write' as const,
idempotent: true,
connectionKeys: ['endpoint'],
};
/**
* 活动槽位的占位产出 —— **编排层跑通期专用的纯工具**。
*
* 六个活动只有契约面。出口载荷只从落地事实推导,不写台账就发不出口、
* 网关判不了、流走不出第一个活动。这枚工具把契约要求的字段落成一行,只为让编排层能被走通。
* 它**不含任何业务判断**(实现见 `tools/first-party.ts` 的 `slotPlaceholder`);
* 真开发某个活动时,那个活动的步序整个换掉,这枚工具从它的白名单里摘掉。
*/
const PLACEHOLDER_TOOL = {
name: 'slot.placeholder',
displayName: '槽位占位产出',
version: '0.1.0',
description: '活动槽位占位产出:把契约要求的字段落成一行(不做业务判断;真实现后摘除)',
input: {
type: 'object',
properties: {
rfqRef: { type: 'string' },
customerCode: { type: 'string' },
pn: { type: 'string' },
supplier: { type: 'string' },
quotedAt: { type: 'string' },
needAlternative: { type: 'boolean' },
needSourcing: { type: 'boolean' },
},
},
output: {
type: 'object',
properties: {
placeholder: { type: 'boolean' },
status: { type: 'string' },
rfqRef: { type: 'string' },
customerCode: { type: 'string' },
pn: { type: 'string' },
supplier: { type: 'string' },
period: { type: 'string' },
needAlternative: { type: 'boolean' },
needSourcing: { type: 'boolean' },
floorPrice: { type: 'number' },
quotePrice: { type: 'number' },
proposedPrice: { type: 'number' },
unitPrice: { type: 'number' },
landingRate: { type: 'number' },
},
},
// 纯工具:无外效应、无连接配置 —— 同输入必同出参
effect: 'read' as const,
errors: [],
idempotent: true,
timeoutMs: 5_000,
retries: 0,
connectionKeys: [] as string[],
};
/** 白名单:逐槽位授权 —— 谁能调什么,治理台说了算,活动代码里看不到这张表 */
const ALLOWLIST: Readonly<Record<string, readonly string[]>> = {
'rfq-intake': [HISTORY_TOOL.name, PLACEHOLDER_TOOL.name],
'alt-selection': [HISTORY_TOOL.name, PLACEHOLDER_TOOL.name],
'sourcing-inquiry': [HISTORY_TOOL.name, MAIL_TOOL.name, PLACEHOLDER_TOOL.name],
'cost-pricing': [HISTORY_TOOL.name, PLACEHOLDER_TOOL.name],
'quote-negotiation': [HISTORY_TOOL.name, MAIL_TOOL.name, PLACEHOLDER_TOOL.name],
'intel-archive': [PLACEHOLDER_TOOL.name],
};
export async function seedMvp(container: Container): Promise<void> {
const log = (line: string) => process.stdout.write(line + '\n');
/*
* ① LLM 实例:四元绑定(Provider / URL / Key / Model),活动只见自定义模型名。
* 密钥**只从环境读**,不入源码、不入包、不入留痕(OS 7.3 凭证隔离 / ADR-009)。
*/
const apiKey = process.env['JCAI_DEEPSEEK_API_KEY'] ?? process.env['JCAI_LLM_API_KEY'] ?? 'sk-placeholder';
for (const [name, model, systemUse] of [
['deepseek-v4-flash', 'deepseek-v4-flash', false],
['deepseek-v4-pro', 'deepseek-v4-pro', false],
] as const) {
await container.llm.upsert({ name, provider: 'deepseek', baseUrl: '', model, apiKey, systemUse, enabled: true });
}
// 用途名,不是型号名:换档只改这一处绑定,活动一行不动。系统用途(小结/汇报/蒸馏)也走它
await container.llm.upsert({
name: 'quote-extractor',
provider: 'deepseek',
baseUrl: process.env['JCAI_LLM_BASE_URL'] ?? '',
model: process.env['JCAI_LLM_MODEL'] ?? 'deepseek-v4-flash',
apiKey,
systemUse: true,
enabled: true,
});
log('① LLM 实例已绑定:deepseek-v4-flash · deepseek-v4-pro · quote-extractor(→ flash,系统用途)');
/* ② 功能工具注册两审 + 逐槽位白名单 */
for (const contract of [HISTORY_TOOL, MAIL_TOOL, PLACEHOLDER_TOOL]) {
const verdict = await container.toolbox.register({
contract,
samples: [
{
// 样例集一份喂三件工具:并集覆盖各家必填
input: { pn: 'LM358DR', to: 'x@y.com', subject: '询价' },
expectShape: { type: 'object' },
},
],
// 占位工具是纯工具,没有连接目标 —— 与真工具同门过两审,但不给它端点
...(contract.connectionKeys.length === 0 ? {} : { connectionValues: { endpoint: 'replay://crm' } }),
});
if (!verdict.accepted) {
log(' 工具 ' + contract.name + ' 未过两审:' + verdict.staticFindings.map((f) => f.message).join('; '));
}
}
for (const [activityId, tools] of Object.entries(ALLOWLIST)) {
await container.toolbox.setAllowlist(activityId, tools);
}
log('② 功能工具已注册并入白名单(读类 1 · 写类 1 · 占位纯工具 1,逐槽位授权)');
/* ③ 六个活动槽位经安装通道装入 —— 声明物化把四域十八对象建出来 */
await installSlots(container);
log('③ 六个活动槽位已装入(契约就绪,实现留白)');
/* ④ 流程包 1:1 + 触发器 + 通道 */
await seedMvpFlow(container);
}