refactor(mcp): expose channel callback subsystem contract

Make the func-based channel wiring contract explicit instead of relying on an anonymous interface inside New(). This keeps the extension point discoverable and aligned with the repository's AX-style API clarity.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 14:43:06 +00:00
parent 94cf1c0ba7
commit 555f9ec614
2 changed files with 13 additions and 5 deletions

View file

@ -123,11 +123,8 @@ func New(opts Options) (*Service, error) {
if sn, ok := sub.(SubsystemWithNotifier); ok {
sn.SetNotifier(s)
}
// Wire channel callback for subsystems that use func-based notification
type channelWirer interface {
OnChannel(func(ctx context.Context, channel string, data any))
}
if cw, ok := sub.(channelWirer); ok {
// Wire channel callback for subsystems that use func-based notification.
if cw, ok := sub.(SubsystemWithChannelCallback); ok {
svc := s // capture for closure
cw.OnChannel(func(ctx context.Context, channel string, data any) {
svc.ChannelSend(ctx, channel, data)

View file

@ -63,3 +63,14 @@ type SubsystemWithNotifier interface {
Subsystem
SetNotifier(n Notifier)
}
// SubsystemWithChannelCallback extends Subsystem for implementations that
// expose an OnChannel callback instead of a Notifier interface.
//
// brain.OnChannel(func(ctx context.Context, channel string, data any) {
// mcpService.ChannelSend(ctx, channel, data)
// })
type SubsystemWithChannelCallback interface {
Subsystem
OnChannel(func(ctx context.Context, channel string, data any))
}