Detailed changes
@@ -93,8 +93,8 @@ type ClientInfo struct {
}
// AddEventListener registers a callback for MCP events.
-func AddEventListener(key string, fn func(pubsub.Event[Event])) {
- broker.AddListener(key, fn)
+func AddEventListener(fn func(pubsub.Event[Event])) {
+ broker.AddListener(fn)
}
// GetStates returns the current state of all MCP clients
@@ -38,7 +38,7 @@ func (m *mockPermissionService) SkipRequests() bool {
return false
}
-func (m *mockPermissionService) AddNotificationListener(key string, fn func(pubsub.Event[permission.PermissionNotification])) {
+func (m *mockPermissionService) AddNotificationListener(fn func(pubsub.Event[permission.PermissionNotification])) {
}
type mockHistoryService struct {
@@ -221,7 +221,7 @@ func (app *App) RunNonInteractive(ctx context.Context, output io.Writer, prompt
)
// Register callback to process messages directly.
- app.Messages.AddListener("non-interactive", func(event pubsub.Event[message.Message]) {
+ app.Messages.AddListener(func(event pubsub.Event[message.Message]) {
msg := event.Payload
if msg.SessionID != sess.ID || msg.Role != message.Assistant || len(msg.Parts) == 0 {
return
@@ -321,25 +321,25 @@ func (app *App) Subscribe(program *tea.Program) {
app.program = program
// Register listeners that send directly to the program.
- app.Sessions.AddListener("tui-sessions", func(event pubsub.Event[session.Session]) {
+ app.Sessions.AddListener(func(event pubsub.Event[session.Session]) {
program.Send(event)
})
- app.Messages.AddListener("tui-messages", func(event pubsub.Event[message.Message]) {
+ app.Messages.AddListener(func(event pubsub.Event[message.Message]) {
program.Send(event)
})
- app.Permissions.AddListener("tui-permissions", func(event pubsub.Event[permission.PermissionRequest]) {
+ app.Permissions.AddListener(func(event pubsub.Event[permission.PermissionRequest]) {
program.Send(event)
})
- app.Permissions.AddNotificationListener("tui-permissions-notifications", func(event pubsub.Event[permission.PermissionNotification]) {
+ app.Permissions.AddNotificationListener(func(event pubsub.Event[permission.PermissionNotification]) {
program.Send(event)
})
- app.History.AddListener("tui-history", func(event pubsub.Event[history.File]) {
+ app.History.AddListener(func(event pubsub.Event[history.File]) {
program.Send(event)
})
- mcp.AddEventListener("tui-mcp", func(event pubsub.Event[mcp.Event]) {
+ mcp.AddEventListener(func(event pubsub.Event[mcp.Event]) {
program.Send(event)
})
- AddLSPEventListener("tui-lsp", func(event pubsub.Event[LSPEvent]) {
+ AddLSPEventListener(func(event pubsub.Event[LSPEvent]) {
program.Send(event)
})
}
@@ -42,8 +42,8 @@ var (
)
// AddLSPEventListener registers a callback for LSP events.
-func AddLSPEventListener(key string, fn func(pubsub.Event[LSPEvent])) {
- lspBroker.AddListener(key, fn)
+func AddLSPEventListener(fn func(pubsub.Event[LSPEvent])) {
+ lspBroker.AddListener(fn)
}
// GetLSPStates returns the current state of all LSP clients
@@ -51,7 +51,7 @@ type Service interface {
AutoApproveSession(sessionID string)
SetSkipRequests(skip bool)
SkipRequests() bool
- AddNotificationListener(key string, fn func(pubsub.Event[PermissionNotification]))
+ AddNotificationListener(fn func(pubsub.Event[PermissionNotification]))
}
type permissionService struct {
@@ -222,8 +222,8 @@ func (s *permissionService) AutoApproveSession(sessionID string) {
s.autoApproveSessionsMu.Unlock()
}
-func (s *permissionService) AddNotificationListener(key string, fn func(pubsub.Event[PermissionNotification])) {
- s.notificationBroker.AddListener(key, fn)
+func (s *permissionService) AddNotificationListener(fn func(pubsub.Event[PermissionNotification])) {
+ s.notificationBroker.AddListener(fn)
}
func (s *permissionService) SetSkipRequests(skip bool) {
@@ -116,7 +116,7 @@ func TestPermissionService_SequentialProperties(t *testing.T) {
wg.Add(1)
events := make(chan pubsub.Event[PermissionRequest], 10)
- service.AddListener("test", func(event pubsub.Event[PermissionRequest]) {
+ service.AddListener(func(event pubsub.Event[PermissionRequest]) {
events <- event
})
@@ -160,7 +160,7 @@ func TestPermissionService_SequentialProperties(t *testing.T) {
}
events := make(chan pubsub.Event[PermissionRequest], 10)
- service.AddListener("test", func(event pubsub.Event[PermissionRequest]) {
+ service.AddListener(func(event pubsub.Event[PermissionRequest]) {
events <- event
})
var result1 bool
@@ -194,7 +194,7 @@ func TestPermissionService_SequentialProperties(t *testing.T) {
service := NewPermissionService("/tmp", false, []string{})
events := make(chan pubsub.Event[PermissionRequest], 10)
- service.AddListener("test", func(event pubsub.Event[PermissionRequest]) {
+ service.AddListener(func(event pubsub.Event[PermissionRequest]) {
events <- event
})
@@ -19,10 +19,10 @@ func NewBroker[T any]() *Broker[T] {
}
// AddListener registers a callback for events.
-func (b *Broker[T]) AddListener(key string, fn func(Event[T])) {
+func (b *Broker[T]) AddListener(fn func(Event[T])) {
b.signal.AddListener(func(_ context.Context, event Event[T]) {
fn(event)
- }, key)
+ })
}
// Publish emits an event to all listeners without blocking.
@@ -9,7 +9,7 @@ const (
)
type Subscriber[T any] interface {
- AddListener(key string, fn func(Event[T]))
+ AddListener(fn func(Event[T]))
}
type (