-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathagent.go
More file actions
33 lines (27 loc) · 991 Bytes
/
agent.go
File metadata and controls
33 lines (27 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package acp
import (
"context"
"io"
"log/slog"
"sync"
)
// AgentSideConnection represents the agent's view of a connection to a client.
type AgentSideConnection struct {
conn *Connection
agent Agent
mu sync.Mutex
sessionCancels map[string]context.CancelFunc
}
// NewAgentSideConnection creates a new agent-side connection bound to the
// provided Agent implementation.
func NewAgentSideConnection(agent Agent, peerInput io.Writer, peerOutput io.Reader) *AgentSideConnection {
asc := &AgentSideConnection{}
asc.agent = agent
asc.sessionCancels = make(map[string]context.CancelFunc)
asc.conn = NewConnection(asc.handleWithExtensions, peerInput, peerOutput)
return asc
}
// Done exposes a channel that closes when the peer disconnects.
func (c *AgentSideConnection) Done() <-chan struct{} { return c.conn.Done() }
// SetLogger directs connection diagnostics to the provided logger.
func (c *AgentSideConnection) SetLogger(l *slog.Logger) { c.conn.SetLogger(l) }