feat(backthink): 后台自主思考(heartbeat+事件触发 + 打扰决策 fail-closed + 主动推送活跃→IM 兜底 + 限制 + 思考记录)
This commit is contained in:
1 parent
05e23ea590
commit
6f97fded3a
13 files changed
+1968
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package backthink
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/bus"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/iot"
|
||||
)
|
||||
|
||||
// Bus subjects the service subscribes to for event-triggered thinking. They are
|
||||
// the contract defined by design/12 §1: an IoT state change, a reminder firing,
|
||||
// or a generic system event.
|
||||
const (
|
||||
// SubjectReminderTrigger is the bus subject on which reminders fire.
|
||||
SubjectReminderTrigger = "reminder.trigger"
|
||||
// SubjectSystemEvent is the bus subject for generic system events.
|
||||
SubjectSystemEvent = "system.event"
|
||||
)
|
||||
|
||||
// Trigger describes what woke a thinking pass: the source subsystem, a
|
||||
// human-readable summary and the event's estimated importance.
|
||||
type Trigger struct {
|
||||
Source string
|
||||
Summary string
|
||||
Import Importance
|
||||
}
|
||||
|
||||
// heartbeatTrigger is the periodic, low-importance trigger. Low importance means
|
||||
// the pass rarely interrupts the user, honouring "默认不发送 chat 类型消息".
|
||||
func heartbeatTrigger() Trigger {
|
||||
return Trigger{Source: "heartbeat", Summary: "periodic autonomous reflection", Import: ImportanceLow}
|
||||
}
|
||||
|
||||
// triggerForEvent maps a bus event to a Trigger. An IoT device change is treated
|
||||
// as normal importance, a reminder firing as high importance, and a generic
|
||||
// system event as normal importance.
|
||||
func triggerForEvent(e bus.Event) Trigger {
|
||||
switch e.Subject {
|
||||
case iot.DeviceUpdateSubject:
|
||||
if d, ok := e.Payload.(iot.DeviceUpdate); ok {
|
||||
return Trigger{
|
||||
Source: e.Subject,
|
||||
Summary: fmt.Sprintf("device %s (%s) %s", d.Device.ID, d.Device.Type, d.Action),
|
||||
Import: ImportanceNormal,
|
||||
}
|
||||
}
|
||||
return Trigger{Source: e.Subject, Summary: e.Subject, Import: ImportanceNormal}
|
||||
case SubjectReminderTrigger:
|
||||
return Trigger{Source: e.Subject, Summary: e.Subject, Import: ImportanceHigh}
|
||||
case SubjectSystemEvent:
|
||||
return Trigger{Source: e.Subject, Summary: e.Subject, Import: ImportanceNormal}
|
||||
default:
|
||||
return Trigger{Source: e.Subject, Summary: e.Subject, Import: ImportanceNormal}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user