批次A admin 端点(原本 404 变 200 真实数据):
- GET /admin/llm:读 s.cfg.LLM 组 openai+anthropic 两 provider(enabled=当前 Provider、multimodal=配 VisionModel),APIKey 不进 wire 零泄露。
- GET /admin/automations:*automations.Service.List()(reminders+event rules+cron schedules,cron 加只读登记)。
- GET /admin/users:cfg.AdminUser + *auth.APIKey.List()(密钥掩码);无用户存储,恒先返回当前 admin 账号。
- GET /admin/backthink:*backthink.Backthink.List(ctx,50)。均只读、owner/admin RBAC、{data} 信封。
批次B 视觉真推理 + 语音:
- rest.go chatRequest 加 Image?;流式 publishChatStream 带 image;userChatMessages 构造 ImageMessage(model.go:71)。
- loop/vision.go:ImageResolver 可注入(MVP 先看图再对话);run.go Run 开头 resolveImages,无 resolver 透传直交主模型。
- vision/resolver.go:MessageResolver 调 vision.Router.Route——KindMain 保留图片交主模型多模态、KindVisionTool/OCRTool 经 dispatcher.Invoke 折叠成 [图片内容] 文本、KindUnsupported 记日志保留原图不崩。
- gateway/voice.go:VoiceService 接口 + SetVoice 注入点 + handleVoiceInput(未注入回 error 不崩)+ runVoiceTurn 异步 STT→loop chat→TTS→定向 voice_output 帧。
- ws_hub/ws_route:voice_input 接 handleVoiceInput;前端 ws.ts decodeBase64/playVoiceAudio/case voice_output。
第3步 wire.go 收口(唯一碰 wire.go 的一步):
- Deps 补传 Automations:a.automation / Backthink:a.backthink / Users:auth.NewAPIKey(a.cfg.Auth)(*auth.APIKey 原生满足 UserStore,避免 admin 重复的复合类型)。
- gw.SetVoice(a.voice);loop.Options.Vision = vision.NewMessageResolver(router, info, dispatcher.Invoke)(router=NewRouter(WithVisionTool/WithOCRTool)、info=cfg.LLM.VisionModel)。
实机验证:四 admin 端点 200 真实数据(llm 双 provider 脱敏、users=admin,yeij0942,owner);WS 握手正常。go build/vet/test 全绿 + 前端 tsc。wire.go 557 行。
109 lines
3.5 KiB
Go
109 lines
3.5 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/orchestration"
|
|
)
|
|
|
|
// route dispatches one inbound frame by its type.
|
|
func (c *wsConn) route(in wsInbound) {
|
|
switch in.Type {
|
|
case "mode_switch":
|
|
c.publishPublic("ws.mode_switch", rawData(in.Data))
|
|
case "chat":
|
|
c.publishPublic(wsChatSubject, rawData(in.Data))
|
|
case "voice_input":
|
|
// Voice routes through the injected STT→chat→TTS pipeline. Without a
|
|
// voice service it replies with a clear error rather than dropping the
|
|
// frame. The audio reply is delivered as a voice_output event on the
|
|
// requesting connection.
|
|
c.handleVoiceInput(in)
|
|
case "subagent_ask":
|
|
c.handleSubagentAsk(in)
|
|
case "task_output_query":
|
|
c.handleTaskOutputQuery(in)
|
|
default:
|
|
c.enqueueJSON(wsEvent{Type: "error", Data: map[string]any{"message": "unknown event type"}})
|
|
}
|
|
}
|
|
|
|
// subagentAskRequest is the decoded payload of a subagent_ask frame. Mode selects
|
|
// the audit window (""/full/tail/keyword); n bounds a tail query; query is the
|
|
// keyword for a keyword query.
|
|
type subagentAskRequest struct {
|
|
ID string `json:"id"`
|
|
Mode string `json:"mode"`
|
|
N int `json:"n"`
|
|
Query string `json:"query"`
|
|
}
|
|
|
|
// taskOutputRequest is the decoded payload of a task_output_query frame.
|
|
type taskOutputRequest struct {
|
|
TaskID string `json:"taskId"`
|
|
}
|
|
|
|
// handleSubagentAsk audits a sub-agent's context and replies with a
|
|
// ws.subagent_event frame carrying the real context window. When no auditor is
|
|
// injected (gateway not wired with a scheduler) it replies with a clear error
|
|
// rather than a fabricated "pending" snapshot.
|
|
func (c *wsConn) handleSubagentAsk(in wsInbound) {
|
|
if c.h.auditor == nil {
|
|
c.enqueueJSON(wsEvent{Type: "error", Data: map[string]any{"message": "subagent audit unavailable"}})
|
|
return
|
|
}
|
|
var req subagentAskRequest
|
|
_ = json.Unmarshal(in.Data, &req)
|
|
if req.ID == "" {
|
|
c.enqueueJSON(wsEvent{Type: "error", Data: map[string]any{"message": "subagent id required"}})
|
|
return
|
|
}
|
|
mode := orchestration.AuditMode(req.Mode)
|
|
if mode == "" {
|
|
mode = orchestration.AuditFull
|
|
}
|
|
res, err := c.h.auditor.AuditContext(context.Background(), req.ID, mode, req.N, req.Query)
|
|
if err != nil {
|
|
c.h.log.Debug("subagent audit", "id", req.ID, "err", err)
|
|
c.enqueueJSON(wsEvent{Type: "error", Data: map[string]any{"message": err.Error()}})
|
|
return
|
|
}
|
|
c.enqueueJSON(wsEvent{Type: "subagent_event", Data: res})
|
|
}
|
|
|
|
// handleTaskOutputQuery fetches the real task output for taskId and replies with
|
|
// a ws.task_output frame. When no task store is injected it replies with a clear
|
|
// error rather than an empty {}. A task that is still running returns the output
|
|
// captured so far.
|
|
func (c *wsConn) handleTaskOutputQuery(in wsInbound) {
|
|
if c.h.taskOutputs == nil {
|
|
c.enqueueJSON(wsEvent{Type: "error", Data: map[string]any{"message": "task output unavailable"}})
|
|
return
|
|
}
|
|
var req taskOutputRequest
|
|
_ = json.Unmarshal(in.Data, &req)
|
|
if req.TaskID == "" {
|
|
c.enqueueJSON(wsEvent{Type: "error", Data: map[string]any{"message": "task id required"}})
|
|
return
|
|
}
|
|
ev, err := c.h.taskOutputs.TaskOutput(context.Background(), req.TaskID)
|
|
if err != nil {
|
|
c.h.log.Debug("task output query", "id", req.TaskID, "err", err)
|
|
c.enqueueJSON(wsEvent{Type: "error", Data: map[string]any{"message": err.Error()}})
|
|
return
|
|
}
|
|
text := ev.Output.Stdout
|
|
if ev.Output.Stderr != "" {
|
|
if text != "" {
|
|
text += "\n"
|
|
}
|
|
text += ev.Output.Stderr
|
|
}
|
|
c.enqueueJSON(wsEvent{Type: "task_output", Data: map[string]any{
|
|
"taskId": ev.ID,
|
|
"output": text,
|
|
"status": string(ev.Status),
|
|
}})
|
|
}
|