-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_impl.go
More file actions
109 lines (88 loc) · 3.6 KB
/
client_impl.go
File metadata and controls
109 lines (88 loc) · 3.6 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package codexsdk
import (
"context"
"iter"
"github.com/ethpandaops/codex-agent-sdk-go/internal/client"
"github.com/ethpandaops/codex-agent-sdk-go/internal/message"
)
// clientWrapper wraps the internal client to adapt it to the public interface.
type clientWrapper struct {
impl *client.Client
}
// Compile-time check that *clientWrapper implements the Client interface.
var _ Client = (*clientWrapper)(nil)
// newClientImpl creates the internal client implementation.
func newClientImpl() Client {
return &clientWrapper{impl: client.New()}
}
// Start establishes a connection to the Codex CLI.
func (c *clientWrapper) Start(ctx context.Context, opts ...Option) error {
return c.impl.Start(ctx, applyAgentOptions(opts))
}
// StartWithContent establishes a connection and immediately sends an initial message.
func (c *clientWrapper) StartWithContent(ctx context.Context, content UserMessageContent, opts ...Option) error {
return c.impl.StartWithContent(ctx, content, applyAgentOptions(opts))
}
// StartWithStream establishes a connection and streams initial messages.
func (c *clientWrapper) StartWithStream(
ctx context.Context,
messages iter.Seq[StreamingMessage],
opts ...Option,
) error {
convertedMessages := func(yield func(message.StreamingMessage) bool) {
for msg := range messages {
if !yield(msg) {
return
}
}
}
return c.impl.StartWithStream(ctx, convertedMessages, applyAgentOptions(opts))
}
// Query sends user content to the agent.
func (c *clientWrapper) Query(ctx context.Context, content UserMessageContent, sessionID ...string) error {
return c.impl.Query(ctx, content, sessionID...)
}
// ReceiveMessages returns an iterator that yields messages indefinitely.
func (c *clientWrapper) ReceiveMessages(ctx context.Context) iter.Seq2[Message, error] {
return c.impl.ReceiveMessages(ctx)
}
// ReceiveResponse returns an iterator that yields messages until a ResultMessage is received.
func (c *clientWrapper) ReceiveResponse(ctx context.Context) iter.Seq2[Message, error] {
return c.impl.ReceiveResponse(ctx)
}
// Interrupt sends an interrupt signal to stop the agent's current processing.
func (c *clientWrapper) Interrupt(ctx context.Context) error {
return c.impl.Interrupt(ctx)
}
// SetPermissionMode changes the permission mode during conversation.
func (c *clientWrapper) SetPermissionMode(ctx context.Context, mode string) error {
return c.impl.SetPermissionMode(ctx, mode)
}
// SetModel changes the AI model during conversation.
func (c *clientWrapper) SetModel(ctx context.Context, model *string) error {
return c.impl.SetModel(ctx, model)
}
// GetServerInfo returns server initialization info including available commands.
func (c *clientWrapper) GetServerInfo() map[string]any {
return c.impl.GetServerInfo()
}
// GetMCPStatus queries the CLI for live MCP server connection status.
func (c *clientWrapper) GetMCPStatus(ctx context.Context) (*MCPStatus, error) {
return c.impl.GetMCPStatus(ctx)
}
// ListModels queries the CLI for available models.
func (c *clientWrapper) ListModels(ctx context.Context) ([]ModelInfo, error) {
return c.impl.ListModels(ctx)
}
// ListModelsResponse queries the CLI for the full model list payload.
func (c *clientWrapper) ListModelsResponse(ctx context.Context) (*ModelListResponse, error) {
return c.impl.ListModelsResponse(ctx)
}
// RewindFiles rewinds tracked files to their state at a specific user message.
func (c *clientWrapper) RewindFiles(ctx context.Context, userMessageID string) error {
return c.impl.RewindFiles(ctx, userMessageID)
}
// Close terminates the session and cleans up resources.
func (c *clientWrapper) Close() error {
return c.impl.Close()
}