智能体支持独立模型与语音(留空继承全局)
用户需求 A。规则是**智能体 > 全局**:智能体自己配了 provider / model / baseUrl / ttsEngine / ttsVoice / ttsSpeed 就用它的,留空(空串 / null / 0) 就沿用全局设置。 这样"代码搭子走 DeepSeek、文案师换个音色"只改那一个智能体, 而全局设置仍然是没配过的智能体的默认值。 【内核】 - store.provider_info(settings, agent):provider/model/baseUrl 三层解析 (智能体 > 全局 > 预设) - speech.voice_for(settings, agent):音色解析,只有这一份实现 —— 别在别处再抄一遍规则,两处不一致最难查 - agent_loop 用解析后的 provider 发请求(以前永远走全局) - /api/tts 和 /api/tts/stream 接受 agentId;流式的"是不是系统引擎" 判断也要用**智能体覆盖后**的那套 —— 某个智能体单独配了云端音色、 全局是"设备自带"时,不能因为全局是 system 就把它的流式挡掉 【关键设计:多人会议靠它区分谁在说话】 四个智能体一个嗓子的话,会议模式根本没法听。所以音色必须能按智能体覆盖 —— 这是会议模式的前置依赖,先做掉。 【测试抓到的两个真 bug】 1. store.create_agent / update_agent 用的是**硬编码字段白名单**, ttsVoice 这些新字段直接被丢掉 —— 表现就是"界面上填了、保存后又变空"。 两份内核都有这个问题。现在字段表提成常量(AGENT_FIELDS), create / update 共用,加字段不会再漏改一处。 2. Node 的 /api/tts/stream 忘了给 synthesizeStream 传 agent。 这两条都是新加的回归断言抓到的 —— 不是我看代码看出来的。 【顺带】 - store.py 少了 PROVIDER_PRESETS 的 import(一跑内核就 NameError) - 排查时手滑把 VOLC_TTS_URL 的定义删了(node --check 查不出运行时错误, 是导入模块才暴露的) 回归:语音验收 36 → 41 项(新增 5 条智能体音色断言: 带 agentId 用自己的、不传回落全局、智能体没配则继承全局), 两份内核各 41/41;Markdown 对拍 19/19。 【这一轮之后还剩】 - B 的界面部分:可搜索的全量音色选择器(内核数据已就位) - A 的界面部分:智能体编辑页的模型/语音选择 - C 会议模式(节点+连线编排)—— 最大的一块,下一轮开始
This commit is contained in:
@@ -184,6 +184,69 @@ check('鉴权头是 Bearer; 分号形式', /Authorization="Bearer;tok-abc"/.test
|
||||
check('body 有 app/user/audio/request 四层', /app\.appid=app-123/.test(volcLine) && /request\.text_type=plain/.test(volcLine) && /request\.operation=query/.test(volcLine), '');
|
||||
check('返回按 code=3000 判定', ttsVolc.ok === true && ttsVolc.engine === 'volc', `engine=${ttsVolc.engine}`);
|
||||
|
||||
/* ---------------- 3.5 智能体独立音色(会议模式的基础) ---------------- */
|
||||
/* 规则是"智能体 > 全局",留空继承。多人会议里几个智能体要发出不同声音,
|
||||
否则四个人一个嗓子根本听不出谁在说话 —— 这条链路断了会议模式就是残的。 */
|
||||
console.log('\n=== 3.5 智能体独立音色(智能体 > 全局)');
|
||||
|
||||
// 全局先设成一个明确的音色
|
||||
await api('/api/settings', {
|
||||
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
speech: {
|
||||
ttsEngine: 'volc', volcAppId: 'app-123', volcToken: 'tok-abc',
|
||||
ttsVoice: 'BV001_streaming', volcEncoding: 'mp3',
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
// 建一个配了独立音色的智能体
|
||||
const agentA = (await api('/api/agents', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: '音色测试A', ttsVoice: 'BV002_streaming' }),
|
||||
})).agent || {};
|
||||
check('能建带独立音色的智能体', !!agentA.id, JSON.stringify(agentA).slice(0, 120));
|
||||
|
||||
// 用它朗读 → mock 收到的 voice_type 应该是智能体那个,不是全局的
|
||||
mockLog = '';
|
||||
const ttsAgent = await api('/api/tts', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text: '智能体音色测试', agentId: agentA.id }),
|
||||
});
|
||||
const agentLine = (mockLog.match(/\[mock\]\[volc-tts\][^\n]*/) || ['(mock 没收到请求)'])[0];
|
||||
check('带 agentId 时用智能体自己的音色', /voice_type=BV002_streaming/.test(agentLine),
|
||||
agentLine.slice(0, 160));
|
||||
check('智能体朗读成功', ttsAgent.ok === true, ttsAgent.error || '');
|
||||
|
||||
// 不传 agentId → 回落到全局
|
||||
mockLog = '';
|
||||
await api('/api/tts', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text: '全局音色测试' }),
|
||||
});
|
||||
const globalLine = (mockLog.match(/\[mock\]\[volc-tts\][^\n]*/) || ['(mock 没收到请求)'])[0];
|
||||
check('不带 agentId 时回落到全局音色', /voice_type=BV001_streaming/.test(globalLine),
|
||||
globalLine.slice(0, 160));
|
||||
|
||||
// 建一个**没配**音色的智能体 → 也该回落全局(留空 = 继承)
|
||||
const agentB = (await api('/api/agents', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: '音色测试B' }),
|
||||
})).agent || {};
|
||||
mockLog = '';
|
||||
await api('/api/tts', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text: '继承测试', agentId: agentB.id }),
|
||||
});
|
||||
const inheritLine = (mockLog.match(/\[mock\]\[volc-tts\][^\n]*/) || ['(mock 没收到请求)'])[0];
|
||||
check('智能体没配音色时继承全局', /voice_type=BV001_streaming/.test(inheritLine),
|
||||
inheritLine.slice(0, 160));
|
||||
|
||||
// 清掉测试用的智能体,别污染后面的用例
|
||||
for (const a of [agentA, agentB]) {
|
||||
if (a.id) await api(`/api/agents/${a.id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
/* ---------------- 4. 火山缺凭据 ---------------- */
|
||||
console.log('\n=== 4. 失败路径:火山没填 AppID ===');
|
||||
await api('/api/settings', {
|
||||
|
||||
Reference in New Issue
Block a user