Skip to content

Commit 3d18f71

Browse files
committed
address Danielle's comments
1 parent 03025a6 commit 3d18f71

6 files changed

Lines changed: 52 additions & 37 deletions

File tree

cmd/attach/attach.go

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,40 +129,31 @@ func WriteRawInputOverHTTP(ctx context.Context, url string, msg string) error {
129129
return nil
130130
}
131131

132-
// statusResponse is used to parse the /status endpoint response.
133-
type statusResponse struct {
134-
Status string `json:"status"`
135-
AgentType string `json:"agent_type"`
136-
Backend string `json:"backend"`
137-
}
138-
139-
func checkACPMode(remoteUrl string) error {
140-
resp, err := http.Get(remoteUrl + "/status")
132+
func checkACPMode(remoteURL string) (bool, error) {
133+
resp, err := http.Get(remoteURL + "/status")
141134
if err != nil {
142-
return xerrors.Errorf("failed to check server status: %w", err)
135+
return false, xerrors.Errorf("failed to check server status: %w", err)
143136
}
144137
defer func() { _ = resp.Body.Close() }()
145138

146139
if resp.StatusCode != http.StatusOK {
147-
return xerrors.Errorf("unexpected %d response from server: %s", resp.StatusCode, resp.Status)
140+
return false, xerrors.Errorf("unexpected %d response from server: %s", resp.StatusCode, resp.Status)
148141
}
149142

150-
var status statusResponse
151-
if err := json.NewDecoder(resp.Body).Decode(&status); err != nil {
152-
return xerrors.Errorf("failed to decode server status: %w", err)
143+
var status httpapi.StatusResponse
144+
if err := json.NewDecoder(resp.Body).Decode(&status.Body); err != nil {
145+
return false, xerrors.Errorf("failed to decode server status: %w", err)
153146
}
154147

155-
if status.Backend == "acp" {
156-
return xerrors.New("attach is not supported in ACP mode. The server is running with --experimental-acp which uses JSON-RPC instead of terminal emulation.")
157-
}
158-
159-
return nil
148+
return status.Body.Transport == httpapi.TransportACP, nil
160149
}
161150

162-
func runAttach(remoteUrl string) error {
151+
func runAttach(remoteURL string) error {
163152
// Check if server is running in ACP mode (attach not supported)
164-
if err := checkACPMode(remoteUrl); err != nil {
165-
return err
153+
if isACP, err := checkACPMode(remoteURL); err != nil {
154+
_, _ = fmt.Fprintf(os.Stderr, "WARN: Unable to check server: %s", err.Error())
155+
} else if isACP {
156+
return xerrors.New("attach is not yet supported in ACP mode")
166157
}
167158

168159
ctx, cancel := context.WithCancel(context.Background())
@@ -187,7 +178,7 @@ func runAttach(remoteUrl string) error {
187178
readScreenErrCh := make(chan error, 1)
188179
go func() {
189180
defer close(readScreenErrCh)
190-
if err := ReadScreenOverHTTP(ctx, remoteUrl+"/internal/screen", screenCh); err != nil {
181+
if err := ReadScreenOverHTTP(ctx, remoteURL+"/internal/screen", screenCh); err != nil {
191182
if errors.Is(err, context.Canceled) {
192183
return
193184
}
@@ -210,7 +201,7 @@ func runAttach(remoteUrl string) error {
210201
if input == "\x03" {
211202
continue
212203
}
213-
if err := WriteRawInputOverHTTP(ctx, remoteUrl+"/message", input); err != nil {
204+
if err := WriteRawInputOverHTTP(ctx, remoteURL+"/message", input); err != nil {
214205
writeRawInputErrCh <- xerrors.Errorf("failed to write raw input: %w", err)
215206
return
216207
}

cmd/server/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
112112
}
113113

114114
var agentIO st.AgentIO
115-
var transport = "pty"
115+
transport := "pty"
116116
var process *termexec.Process
117117
var acpResult *httpapi.SetupACPResult
118118

@@ -148,7 +148,7 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
148148
srv, err := httpapi.NewServer(ctx, httpapi.ServerConfig{
149149
AgentType: agentType,
150150
AgentIO: agentIO,
151-
Transport: transport,
151+
Transport: httpapi.Transport(transport),
152152
Port: port,
153153
ChatBasePath: viper.GetString(FlagChatBasePath),
154154
AllowedHosts: viper.GetStringSlice(FlagAllowedHosts),

lib/httpapi/models.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ func (m MessageType) Schema(r huma.Registry) *huma.Schema {
2525
return util.OpenAPISchema(r, "MessageType", MessageTypeValues)
2626
}
2727

28+
type Transport string
29+
30+
const (
31+
TransportPTY Transport = "pty"
32+
TransportACP Transport = "acp"
33+
)
34+
35+
var TransportValues = []Transport{
36+
TransportPTY,
37+
TransportACP,
38+
}
39+
40+
func (tr Transport) Schema(r huma.Registry) *huma.Schema {
41+
return util.OpenAPISchema(r, "Transport", TransportValues)
42+
}
43+
2844
// Message represents a message
2945
type Message struct {
3046
Id int `json:"id" doc:"Unique identifier for the message. This identifier also represents the order of the message in the conversation history."`
@@ -38,7 +54,7 @@ type StatusResponse struct {
3854
Body struct {
3955
Status AgentStatus `json:"status" doc:"Current agent status. 'running' means that the agent is processing a message, 'stable' means that the agent is idle and waiting for input."`
4056
AgentType mf.AgentType `json:"agent_type" doc:"Type of the agent being used by the server."`
41-
Backend string `json:"backend" doc:"Backend transport being used ('acp' or 'pty')."`
57+
Transport Transport `json:"transport" doc:"Backend transport being used ('acp' or 'pty')."`
4258
}
4359
}
4460

lib/httpapi/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Server struct {
4949
chatBasePath string
5050
tempDir string
5151
clock quartz.Clock
52-
transport string
52+
transport Transport
5353
}
5454

5555
func (s *Server) NormalizeSchema(schema any) any {
@@ -101,7 +101,7 @@ const snapshotInterval = 25 * time.Millisecond
101101
type ServerConfig struct {
102102
AgentType mf.AgentType
103103
AgentIO st.AgentIO
104-
Transport string
104+
Transport Transport
105105
Port int
106106
ChatBasePath string
107107
AllowedHosts []string
@@ -437,7 +437,7 @@ func (s *Server) getStatus(ctx context.Context, input *struct{}) (*StatusRespons
437437
resp := &StatusResponse{}
438438
resp.Body.Status = agentStatus
439439
resp.Body.AgentType = s.agentType
440-
resp.Body.Backend = s.transport
440+
resp.Body.Transport = s.transport
441441

442442
return resp, nil
443443
}

lib/httpapi/setup.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,3 @@ func SetupACP(ctx context.Context, config SetupACPConfig) (*SetupACPResult, erro
133133
Done: done,
134134
}, nil
135135
}
136-

openapi.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,31 @@
269269
"description": "Type of the agent being used by the server.",
270270
"type": "string"
271271
},
272-
"backend": {
273-
"description": "Backend transport being used ('acp' or 'pty').",
274-
"type": "string"
275-
},
276272
"status": {
277273
"$ref": "#/components/schemas/AgentStatus",
278274
"description": "Current agent status. 'running' means that the agent is processing a message, 'stable' means that the agent is idle and waiting for input."
275+
},
276+
"transport": {
277+
"$ref": "#/components/schemas/Transport",
278+
"description": "Backend transport being used ('acp' or 'pty')."
279279
}
280280
},
281281
"required": [
282282
"agent_type",
283-
"backend",
284-
"status"
283+
"status",
284+
"transport"
285285
],
286286
"type": "object"
287287
},
288+
"Transport": {
289+
"enum": [
290+
"acp",
291+
"pty"
292+
],
293+
"example": "pty",
294+
"title": "Transport",
295+
"type": "string"
296+
},
288297
"UploadResponseBody": {
289298
"additionalProperties": false,
290299
"properties": {

0 commit comments

Comments
 (0)