aec7ad949c
模型配置加"用途"维度:工作主力(chat,要强)与 JARVIS 语音(voice,要快/低时延)各配各激活, 语音任务走语音模型池,未配置则透明回落工作模型——不影响现有功能。 - contract: ConfigKindVoice="voice" + Meta[model_profile]=voice(与 intent==report 同类路由) - gateway: ServeConfig/broadcastActive 循环纳入 voice;submitVoiceTask 打 model_profile=voice 标记 - dispatcher: 第二个 llm.Pool(voicePool)吃 voice 配置热更新;board.useVoice 从 Meta 派生(含快照); Orchestrator.agentPool(b) 按黑板选池——语音且语音池就绪→语音池,否则工作池; agent 生成路径(graph/react/coordinator/compose)全改走 agentPool(b),报告/护栏/记忆固定工作池 - admin: 模型页三 Tab(工作主力/JARVIS语音/向量化),复用 ModelManager;api Kind 加 voice Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
75 lines
3.1 KiB
Go
75 lines
3.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/sundynix/sundynix-gateway/internal/dsl"
|
|
"github.com/sundynix/sundynix-shared/contract"
|
|
)
|
|
|
|
// 语音上行接线:最终转写 → 组 DSL → 复用 preflightCore/launchCore 关卡 → 提交任务 → 回 task_id。
|
|
// 语音只是"嘴替键盘",一行编排/工具/计费逻辑都不新造:走的正是 HTTP SubmitTask 那条关卡
|
|
// (见记忆 execution-single-entry「提交必走 preflight()+launch() 共用关卡」)。
|
|
|
|
// voiceAgentSystem 是语音默认单 agent 的系统提示词:口语化、**极简**、适合朗读(下行要过 TTS)。
|
|
// 语音场景务必短——长答案既拖慢首字出声(要等第一句合成),又让人干听十几秒。
|
|
const voiceAgentSystem = "你是用户的语音助手 JARVIS。这是语音对话,回答必须简短——像真人聊天," +
|
|
"通常一两句话说清重点即可,最多不超过三句,别长篇大论、别列清单、别念代码。" +
|
|
"先直接给结论。口语化、自然、适合朗读。需要更多细节时再由用户追问。"
|
|
|
|
// buildVoiceGraph 把一句转写组成最简可执行图:input(转写) → agent(JARVIS)。
|
|
// 与前端画布 exportDsl 同构(kind=input/agent、config.text/system),dispatcher 直接吃。
|
|
func buildVoiceGraph(query string) json.RawMessage {
|
|
g := map[string]any{
|
|
"version": "voice-1",
|
|
"nodes": []map[string]any{
|
|
{"id": "voice_in", "kind": "input", "config": map[string]any{"text": query}},
|
|
{"id": "voice_agent", "kind": "agent", "config": map[string]any{"system": voiceAgentSystem}},
|
|
},
|
|
"edges": []map[string]any{
|
|
{"source": "voice_in", "target": "voice_agent"},
|
|
},
|
|
}
|
|
b, _ := json.Marshal(g)
|
|
return b
|
|
}
|
|
|
|
// submitVoiceTask 提交一次语音任务。graphOverride 非空时用客户端画布图(语音触发既有编排),
|
|
// 否则用转写现组的单 agent 图。返回 task_id。
|
|
func (s *voiceSession) submitVoiceTask(transcript, graphOverride string) (string, error) {
|
|
transcript = strings.TrimSpace(transcript)
|
|
if transcript == "" && graphOverride == "" {
|
|
return "", fmt.Errorf("空转写")
|
|
}
|
|
ctx := context.Background() // WS 会话长生命周期,不绑单条请求 ctx
|
|
|
|
var raw json.RawMessage
|
|
if strings.TrimSpace(graphOverride) != "" {
|
|
raw = json.RawMessage(graphOverride) // 语音触发画布上的既有编排图
|
|
} else {
|
|
raw = buildVoiceGraph(transcript)
|
|
}
|
|
task, err := dsl.ParseAndAssemble(raw)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
// 共用关卡:预算 / 暂停 / 计费租户 / 积分硬拦截。被拦时把文案上抛(供语音播报/回传)。
|
|
billingTenant, block := s.h.preflightCore(ctx, s.uid, s.tenantID)
|
|
if block != nil {
|
|
return "", fmt.Errorf("%s", block.message())
|
|
}
|
|
task.Meta[contract.MetaUserID] = s.uid
|
|
task.Meta[contract.MetaTenantID] = billingTenant
|
|
task.Meta[contract.MetaSessionID] = s.sessionID
|
|
task.Meta[contract.MetaModelProfile] = contract.ModelProfileVoice // 语音任务走 JARVIS 快模型(未配则回落工作模型)
|
|
|
|
if err := s.h.launchCore(ctx, s.uid, task); err != nil {
|
|
return "", err
|
|
}
|
|
return task.ID, nil
|
|
}
|