feat: 公共平台最小化打扰(design/12 §6)——5条策略: 分级+轻思考+限流+审查剔噪
降噪A(策略一/二/五): - channelbridge/light.go: 非owner分级门——小事件当系统消息登记(不进loop)、非owner轻响应(她判断回/不回,规则优先mention/关键词+轻LLM兜底fail-closed静默) - backthink 触发降噪: SubjectSystemEvent 低价值不唤醒thinking(仅高价值/owner才think), iot/reminder不受影响 - quiet hours: 安静时段非owner无信号静默,被@才回(非硬性静默); config QUIET_START/END_HOUR 单源共用 限流B(策略三/四): - adapter/flowgate.go: per-adapter 滑窗限流器+总上限+审查剔噪闸门(Admit两连:速率+上限/审查), owner私聊绕过 - channelbridge/flowgate.go: onMessage入站最前挂闸, 超限/被剔不占worker槽; 审查模型NewLLMReviewer复用model.Adapter(仅>80%阈值触发+跨分钟节流,失败回退FIFO,绝不判身份) - config: ChannelAccount 加 GroupMsgPerMin(默认6)/MsgPerMin/MaxMessages(默认50), CHANNELS_JSON每账号, 向后兼容 - 被剔消息走OnRejected审计不静默丢 main wire接线: 加modelAdapter字段+Review注入(reviewFor nil-safe,无LLM回退FIFO) 全仓 go build/vet/test 绿(53包)+交叉编译, 零新依赖, 前端无涉
This commit is contained in:
1 parent
764d592859
commit
8cde0162e6
16 files changed
+1750
-28
No files matched your search
+13
-1
@@ -110,13 +110,19 @@ type namedAdapter struct {
|
||||
denyGroups []string
|
||||
allowUsers []string
|
||||
denyUsers []string
|
||||
// flow limits (design/12 §6 策略三/四). They are always surfaced through
|
||||
// Config() so the bridge can build a per-account ingress gate; the bridge maps
|
||||
// the zero default to the protective values and a negative value to "off".
|
||||
groupMsgPerMin int
|
||||
msgPerMin int
|
||||
maxMessages int
|
||||
}
|
||||
|
||||
func (n *namedAdapter) Name() string { return n.name }
|
||||
|
||||
func (n *namedAdapter) Config() map[string]any {
|
||||
cfg := n.PlatformAdapter.Config()
|
||||
out := make(map[string]any, len(cfg)+4)
|
||||
out := make(map[string]any, len(cfg)+7)
|
||||
for k, v := range cfg {
|
||||
out[k] = v
|
||||
}
|
||||
@@ -124,6 +130,9 @@ func (n *namedAdapter) Config() map[string]any {
|
||||
out["denyGroups"] = n.denyGroups
|
||||
out["allowUsers"] = n.allowUsers
|
||||
out["denyUsers"] = n.denyUsers
|
||||
out["groupMsgPerMin"] = n.groupMsgPerMin
|
||||
out["msgPerMin"] = n.msgPerMin
|
||||
out["maxMessages"] = n.maxMessages
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -182,6 +191,9 @@ func buildAccountAdapter(platform string, acct config.ChannelAccount, log *slog.
|
||||
denyGroups: acct.DenyGroups,
|
||||
allowUsers: acct.AllowUsers,
|
||||
denyUsers: acct.DenyUsers,
|
||||
groupMsgPerMin: acct.GroupMsgPerMin,
|
||||
msgPerMin: acct.MsgPerMin,
|
||||
maxMessages: acct.MaxMessages,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
+24
-5
@@ -76,6 +76,7 @@ type app struct {
|
||||
log *slog.Logger
|
||||
db *sql.DB
|
||||
bus bus.Bus
|
||||
modelAdapter model.Adapter
|
||||
personas *personareg.Registry
|
||||
caps *registry.Registry
|
||||
dispatcher *tool.Dispatcher
|
||||
@@ -263,6 +264,9 @@ func (a *app) wireRuntime() error {
|
||||
a.log.Warn("llm adapter unavailable", "error", aerr)
|
||||
adapter = nil
|
||||
}
|
||||
// Keep the model adapter for cross-function use (e.g. the channel-bridge
|
||||
// review model that prunes low-value messages, design/12 §6 策略四).
|
||||
a.modelAdapter = adapter
|
||||
router := model.NewRouter(model.DefaultModelForProvider(a.cfg.LLM),
|
||||
model.WithVisionModel(a.cfg.LLM.VisionModel))
|
||||
|
||||
@@ -484,11 +488,16 @@ func (a *app) wireChannels() error {
|
||||
}
|
||||
|
||||
bridge, berr := channelbridge.New(channelbridge.Options{
|
||||
Log: logger.WithSource(a.log, "services/channelbridge"),
|
||||
Loop: a.loop,
|
||||
Sessions: a.sessions,
|
||||
Owner: a.owner,
|
||||
History: a.history,
|
||||
Log: logger.WithSource(a.log, "services/channelbridge"),
|
||||
Loop: a.loop,
|
||||
Sessions: a.sessions,
|
||||
Owner: a.owner,
|
||||
History: a.history,
|
||||
QuietStartHour: a.cfg.Background.QuietStartHour,
|
||||
QuietEndHour: a.cfg.Background.QuietEndHour,
|
||||
// Optional review model prunes low-value queued messages near the per-adapter
|
||||
// cap (design/12 §6 策略四). Nil adapter → the gate falls back to FIFO evict.
|
||||
Review: reviewFor(a.modelAdapter, logger.WithSource(a.log, "services/channelbridge/review")),
|
||||
})
|
||||
if berr != nil {
|
||||
return fmt.Errorf("channel bridge: %w", berr)
|
||||
@@ -652,3 +661,13 @@ func resolveSQLitePath(cfg *config.Config, dataDir string) string {
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// reviewFor builds the channel-bridge review model (design/12 §6 策略四), or nil
|
||||
// when no model adapter is available so the gate falls back to FIFO eviction — the
|
||||
// reviewer is never invoked with a nil adapter (which would panic on .Chat).
|
||||
func reviewFor(llm model.Adapter, log *slog.Logger) adapter.Reviewer {
|
||||
if llm == nil {
|
||||
return nil
|
||||
}
|
||||
return channelbridge.NewLLMReviewer(llm, log)
|
||||
}
|
||||
Reference in new issue
Block a user