模型实例卡重做:名字不截、密钥不撒谎、不可用就别摆统计;只留 flash 与 pro 两条

三条毛病一次改净:

**① 名字被截断**。用途名是活动里声明的那个名,看不全等于没显示 —— 卡面改成
   40px 图标 + **名字独占一行、折行也不截**(overflow-wrap: anywhere),
   厂商与型号退到第二行小字。

**② 「已绑定」是谎**。种子从前塞一个 `sk-placeholder` 冒充密钥,卡上写着「已绑定」,
   一自检就是 `api key ... is invalid`;抽屉里那格也照「是不是新建」写占位,
   于是没钥匙的实例也显示「已绑定 · 留空保持原值」。现在:
     · 种子**读不到环境密钥就不绑**,如实显示未绑定;
     · 抽屉的占位与判词改看 `keyBound` —— 没绑就写「还没有密钥 —— 不填这条实例调不动」。
   **界面撒谎比缺功能更坏**:缺功能人会去补,撒谎的人会照着假状态做决定。

**③ 不可用还摆一排统计**。没密钥连调都调不起来,「系统用途/端点」那些格没有意义 ——
   未绑定时卡上只剩一句判词 +「去配置」;绑好了才谈端点与「测试」。
   系统用途从卡面撤了(用户:不要管是不是系统用途,两条都能用)。

**只留两条实例**:`deepseek-v4-flash` 与 `deepseek-v4-pro`,都不预设系统用途。
配套两件:
  · `pickSystemUse` 加**回落** —— 没人勾就取第一条能用的(启用且已绑密钥);
    从前非勾不可,没勾那天系统叙述整条哑掉,那是配置疏忽不该变成功能缺失(补了三条测试);
  · 六个活动包里声明的用途名 `quote-extractor` 改指 `deepseek-v4-flash`,各升一个补丁版。

顺带补 `DELETE /api/gov/llm/:id`(卡上 ⋯ 菜单):还有活动声明着这个用途名就拒(409)——
删了那些活动一调模型就是「用途名未绑定」,而人当时以为只是清一条没用的记录。
实测:用它把库里遗留的 quote-extractor 删掉,现在库里就是那两条,卡上如实写「未绑定密钥 · 不可用」。
五闸绿。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
2026-07-30 01:53:42 +08:00
co-authored by Claude Opus 5
parent fffb46eae7
commit da8ac8f9bc
15 changed files with 276 additions and 80 deletions
+25
View File
@@ -15,6 +15,7 @@ import {
positionIdSchema,
listLlmProvidersRoute,
LLM_PROVIDERS,
deleteLlmInstanceRoute,
probeLlmDraftRoute,
probeLlmInstanceRoute,
saveWorkGroupRoute,
@@ -181,6 +182,30 @@ export function registerGovernanceRoutes(app: Hono<AppEnv>, container: Container
return c.json(await container.llm.upsert(parsed.data));
});
/** 删实例:被活动声明着的用途名不许删(409)—— 反查放这一层,llm 不该知道活动的存在 */
app.delete(deleteLlmInstanceRoute.path, async (c) => {
const denied = await guardSystem(c.get('account'));
if (denied) return c.json(denied, denied.code === 'forbidden' ? 403 : 401);
const id = c.req.param('id');
const target = (await container.llm.list()).find((i) => i.id === id);
if (target === undefined) {
const body: ApiError = { code: 'not-found', message: '实例不存在' };
return c.json(body, 404);
}
const cards = await container.registry.list();
const manifests = await Promise.all(cards.map((a) => container.registry.manifestOf(a.activityId)));
const users = manifests.filter((m) => m.declarations.models.includes(target.name));
if (users.length > 0) {
const body: ApiError = {
code: 'conflict',
message: `还有 ${users.length} 个活动声明着用途名「${target.name}」—— 先改那些活动的声明再删`,
};
return c.json(body, 409);
}
await container.llm.remove(id);
return c.json({ ok: true });
});
/** 测试连接(草稿):只测不存 —— 必须排在 `/:id/probe` 之前,否则会被那条路由吃掉 */
app.post(probeLlmDraftRoute.path, async (c) => {
const denied = await guardSystem(c.get('account'));
+20 -16
View File
@@ -123,24 +123,28 @@ export async function seedMvp(container: Container): Promise<void> {
* ① 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],
/*
* 密钥**只从环境读**;读不到就**不绑**(2026-07-30):从前塞一个 `sk-placeholder`
* 冒充已绑定,治理台上写着「密钥已绑定」,一自检就是 `api key ... is invalid` ——
* 界面撒谎比缺功能更坏。没钥匙就如实显示未绑定,人去抽屉里补。
*/
const apiKey = process.env['JCAI_DEEPSEEK_API_KEY'] ?? process.env['JCAI_LLM_API_KEY'];
for (const [name, model] of [
['deepseek-v4-flash', 'deepseek-v4-flash'],
['deepseek-v4-pro', 'deepseek-v4-pro'],
] as const) {
await container.llm.upsert({ name, provider: 'deepseek', baseUrl: '', model, apiKey, systemUse, enabled: true });
await container.llm.upsert({
name,
provider: 'deepseek',
baseUrl: process.env['JCAI_LLM_BASE_URL'] ?? '',
model,
...(apiKey === undefined ? {} : { apiKey }),
// 系统用途不预设:两条都能用,系统叙述回落到第一条可用的(pickSystemUse)
systemUse: false,
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,系统用途)');
log(`① LLM 实例已绑定:deepseek-v4-flash · deepseek-v4-pro${apiKey === undefined ? '(环境无密钥 —— 两条都是未绑定,去治理台补)' : ''}`);
/* ② 功能工具注册两审 + 逐槽位白名单 */
for (const contract of [HISTORY_TOOL, MAIL_TOOL, PLACEHOLDER_TOOL]) {
@@ -111,3 +111,31 @@ describe('stableStringify —— 键排序,指纹不随属性顺序漂移', () =
expect(stableStringify(3)).toBe('3');
});
});
describe('系统用途:没人勾也要有着落(2026-07-30)', () => {
const mk = (over: Partial<Parameters<typeof pickSystemUse>[0][number]>) => ({
id: 'x',
name: 'n',
provider: 'deepseek' as const,
baseUrl: 'https://api.deepseek.com',
model: 'm',
apiKeyCipher: 'cipher',
systemUse: false,
enabled: true,
...over,
});
it('勾了的优先', () => {
const flagged = mk({ id: 'flagged', systemUse: true });
expect(pickSystemUse([mk({ id: 'first' }), flagged])?.id).toBe('flagged');
});
it('一个没勾 → 取第一条能用的(启用且已绑密钥)', () => {
const picked = pickSystemUse([mk({ id: 'nokey', apiKeyCipher: undefined }), mk({ id: 'off', enabled: false }), mk({ id: 'ok' })]);
expect(picked?.id, '未绑密钥与已停用的都不算数').toBe('ok');
});
it('一条能用的都没有 → 如实返回 undefined,不硬凑一条', () => {
expect(pickSystemUse([mk({ apiKeyCipher: undefined })])).toBeUndefined();
});
});
@@ -65,7 +65,13 @@ export function toPublicView(binding: ModelBinding): {
};
}
/** 系统用途模型:叙述性小结 / 汇报生成 / 蒸馏钩子 —— 计量入系统账、不占活动预算 */
/**
* 系统用途模型:叙述性小结 / 汇报生成 / 蒸馏钩子 —— 计量入系统账、不占活动预算。
*
* **没人勾也要有着落**(2026-07-30 用户定「不要管是不是系统用途,都能用」):
* 勾了的优先;一个没勾就取第一条**能用的**(启用且已绑密钥)。
* 从前非勾不可,于是没勾的那天系统叙述整条哑掉 —— 那是配置疏忽,不该变成功能缺失。
*/
export function pickSystemUse(bindings: readonly ModelBinding[]): ModelBinding | undefined {
return bindings.find((b) => b.systemUse && b.enabled);
return bindings.find((b) => b.systemUse && b.enabled) ?? bindings.find((b) => b.enabled && isBound(b));
}