feat(gateway): 地基③ 打通实时信号 producer→前端WS + loop 真流式 + 上行路由补全
打通前端 ws.ts 里那批死消费者事件(thinking/mood/tool_used/subagent_event/
task_output/device_update/reminder/backthink),并给 loop 接真 token 流式。
- wire.go:loop 建时传 OnStream(streamChunk 闭包把 delta 发 bus ws.stream_chunk);
gateway.Deps 注入 Scheduler/Tasks/Streaming;iot 接共享总线 iot.WithBus(a.bus)。
- ws_bridge.go:hub 额外订阅 iot.>/task.>/automation.>/reminder.>/cyrene.agent.*.event,
normalizeEvent 归一为 ws.*(device_update/task_output/task_done/automation_result/
reminder/subagent_event);不订阅 cyrene.agent.> 以免 ask/reply 内部事件进 relay。
- ws_route.go:voice_input→ws.voice_input;subagent_ask→Scheduler.AuditContext(真实
上下文审计,替换 pending stub);task_output_query→Manager.TaskOutput(真实输出,
替换空 {})。
- server.go:新增 SubagentAuditor/TaskOutputStore 接口 + Deps.Scheduler/Tasks/Streaming。
- orchestration/auditcontext.go:Scheduler.AuditContext(full/tail/keyword)。
- task/manager.go:Manager.TaskOutput(id)。
- backthink:record() 补发 ws.backthink 事件。
- json tag 修正(device_update/reminder/task output 结构体加小写 tag + DeviceUpdate
补 message),使前端分支能真正渲染。
实机验证:WS 握手 101、task manager ready、iot manager initialized(WithBus 生效)。
go build/vet/test 全绿;TestHubBridgeDeviceUpdate/TestHubBridgeSubagentProgress 覆盖
映射。dev 推至后续版本。
This commit is contained in:
1 parent
04bfa2c7a7
commit
9b207a31e8
14 files changed
+673
-109
No files matched your search
@@ -82,11 +82,14 @@ func (d Device) Clone() Device {
|
||||
// state transitions, typically as the result of a Control call.
|
||||
type DeviceUpdate struct {
|
||||
// Provider is the name of the provider that owns the device.
|
||||
Provider string
|
||||
Provider string `json:"provider"`
|
||||
// Device is the post-transition device snapshot.
|
||||
Device Device
|
||||
Device Device `json:"device"`
|
||||
// Action is the control action that produced the transition.
|
||||
Action string
|
||||
Action string `json:"action"`
|
||||
// Params are the optional control parameters.
|
||||
Params map[string]any
|
||||
Params map[string]any `json:"params,omitempty"`
|
||||
// Message is a human-readable summary of the transition, surfaced to the
|
||||
// frontend device_update feed.
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
+17
-1
@@ -22,6 +22,17 @@ type Manager struct {
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// Option customizes a Manager built by New.
|
||||
type Option func(*Manager)
|
||||
|
||||
// WithBus injects an existing bus instead of letting the Manager create one. It
|
||||
// mirrors the other subsystems so iot.device_update flows on the shared bus and
|
||||
// reaches the gateway hub / background-trigger subscribers rather than staying
|
||||
// on an isolated manager-owned bus.
|
||||
func WithBus(b bus.Bus) Option {
|
||||
return func(m *Manager) { m.bus = b }
|
||||
}
|
||||
|
||||
// New builds a Manager from cfg, selecting the device Provider by cfg.Provider.
|
||||
//
|
||||
// Supported providers: "" or "mock" registers the built-in mock provider with
|
||||
@@ -31,11 +42,14 @@ type Manager struct {
|
||||
//
|
||||
// log may be nil; it is replaced with a discard logger. The Manager owns a
|
||||
// fresh, isolated bus exposed via Bus for subscribers to attach to.
|
||||
func New(cfg config.IoTConfig, log *slog.Logger) (*Manager, error) {
|
||||
func New(cfg config.IoTConfig, log *slog.Logger, opts ...Option) (*Manager, error) {
|
||||
m := &Manager{
|
||||
bus: bus.New(),
|
||||
log: logger.WithSource(discardLogger(log), "iot/manager"),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
switch strings.TrimSpace(cfg.Provider) {
|
||||
case "", "mock":
|
||||
mp, err := newMockProvider(log)
|
||||
@@ -142,11 +156,13 @@ func (m *Manager) Status(ctx context.Context, deviceID string) (*Device, error)
|
||||
// changed, and control should not be reported as failed because an observer did
|
||||
// not receive the event.
|
||||
func (m *Manager) publishUpdate(ctx context.Context, provider string, d Device, action string, params map[string]any) {
|
||||
msg := fmt.Sprintf("设备 %s · %s(%s)", d.Name, action, provider)
|
||||
if err := m.bus.Publish(ctx, DeviceUpdateSubject, DeviceUpdate{
|
||||
Provider: provider,
|
||||
Device: d,
|
||||
Action: action,
|
||||
Params: params,
|
||||
Message: msg,
|
||||
}); err != nil {
|
||||
m.log.Error("iot publish device update", "device", d.ID, "action", action, "error", err)
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user