Skip to content

Commit 578390d

Browse files
committed
feat: configuration via env variables
1 parent 7c6d16e commit 578390d

File tree

5 files changed

+125
-30
lines changed

5 files changed

+125
-30
lines changed

cmd/server/server.go

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212

1313
"github.com/spf13/cobra"
14+
"github.com/spf13/viper"
1415
"golang.org/x/xerrors"
1516

1617
"github.com/coder/agentapi/lib/httpapi"
@@ -19,15 +20,6 @@ import (
1920
"github.com/coder/agentapi/lib/termexec"
2021
)
2122

22-
var (
23-
agentTypeVar string
24-
port int
25-
printOpenAPI bool
26-
chatBasePath string
27-
termWidth uint16
28-
termHeight uint16
29-
)
30-
3123
type AgentType = msgfmt.AgentType
3224

3325
const (
@@ -68,11 +60,15 @@ func parseAgentType(firstArg string, agentTypeVar string) (AgentType, error) {
6860

6961
func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) error {
7062
agent := argsToPass[0]
71-
agentType, err := parseAgentType(agent, agentTypeVar)
63+
agentTypeValue := viper.GetString(FlagType)
64+
agentType, err := parseAgentType(agent, agentTypeValue)
7265
if err != nil {
7366
return xerrors.Errorf("failed to parse agent type: %w", err)
7467
}
7568

69+
termWidth := viper.GetUint16(FlagTermWidth)
70+
termHeight := viper.GetUint16(FlagTermHeight)
71+
7672
if termWidth < 10 {
7773
return xerrors.Errorf("term width must be at least 10")
7874
}
@@ -83,6 +79,7 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
8379
termHeight = 930 // codex has a bug where the TUI distorts the screen if the height is too large, see: https://github.com/openai/codex/issues/1608
8480
}
8581

82+
printOpenAPI := viper.GetBool(FlagPrintOpenAPI)
8683
var process *termexec.Process
8784
if printOpenAPI {
8885
process = nil
@@ -97,7 +94,13 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
9794
return xerrors.Errorf("failed to setup process: %w", err)
9895
}
9996
}
100-
srv := httpapi.NewServer(ctx, agentType, process, port, chatBasePath)
97+
port := viper.GetInt(FlagPort)
98+
srv := httpapi.NewServer(ctx, httpapi.ServerConfig{
99+
AgentType: agentType,
100+
Process: process,
101+
Port: port,
102+
ChatBasePath: viper.GetString(FlagChatBasePath),
103+
})
101104
if printOpenAPI {
102105
fmt.Println(srv.GetOpenAPI())
103106
return nil
@@ -153,11 +156,50 @@ var ServerCmd = &cobra.Command{
153156
},
154157
}
155158

159+
type flagSpec struct {
160+
name string
161+
shorthand string
162+
defaultValue any
163+
usage string
164+
flagType string
165+
}
166+
167+
const (
168+
FlagType = "type"
169+
FlagPort = "port"
170+
FlagPrintOpenAPI = "print-openapi"
171+
FlagChatBasePath = "chat-base-path"
172+
FlagTermWidth = "term-width"
173+
FlagTermHeight = "term-height"
174+
)
175+
156176
func init() {
157-
ServerCmd.Flags().StringVarP(&agentTypeVar, "type", "t", "", fmt.Sprintf("Override the agent type (one of: %s, custom)", strings.Join(agentNames, ", ")))
158-
ServerCmd.Flags().IntVarP(&port, "port", "p", 3284, "Port to run the server on")
159-
ServerCmd.Flags().BoolVarP(&printOpenAPI, "print-openapi", "P", false, "Print the OpenAPI schema to stdout and exit")
160-
ServerCmd.Flags().StringVarP(&chatBasePath, "chat-base-path", "c", "/chat", "Base path for assets and routes used in the static files of the chat interface")
161-
ServerCmd.Flags().Uint16VarP(&termWidth, "term-width", "W", 80, "Width of the emulated terminal")
162-
ServerCmd.Flags().Uint16VarP(&termHeight, "term-height", "H", 1000, "Height of the emulated terminal")
177+
flagSpecs := []flagSpec{
178+
{FlagType, "t", "", fmt.Sprintf("Override the agent type (one of: %s, custom)", strings.Join(agentNames, ", ")), "string"},
179+
{FlagPort, "p", 3284, "Port to run the server on", "int"},
180+
{FlagPrintOpenAPI, "P", false, "Print the OpenAPI schema to stdout and exit", "bool"},
181+
{FlagChatBasePath, "c", "/chat", "Base path for assets and routes used in the static files of the chat interface", "string"},
182+
{FlagTermWidth, "W", uint16(80), "Width of the emulated terminal", "uint16"},
183+
{FlagTermHeight, "H", uint16(1000), "Height of the emulated terminal", "uint16"},
184+
}
185+
186+
for _, spec := range flagSpecs {
187+
switch spec.flagType {
188+
case "string":
189+
ServerCmd.Flags().StringP(spec.name, spec.shorthand, spec.defaultValue.(string), spec.usage)
190+
case "int":
191+
ServerCmd.Flags().IntP(spec.name, spec.shorthand, spec.defaultValue.(int), spec.usage)
192+
case "bool":
193+
ServerCmd.Flags().BoolP(spec.name, spec.shorthand, spec.defaultValue.(bool), spec.usage)
194+
case "uint16":
195+
ServerCmd.Flags().Uint16P(spec.name, spec.shorthand, spec.defaultValue.(uint16), spec.usage)
196+
default:
197+
panic(fmt.Sprintf("unknown flag type: %s", spec.flagType))
198+
}
199+
viper.BindPFlag(spec.name, ServerCmd.Flags().Lookup(spec.name))
200+
}
201+
202+
viper.SetEnvPrefix("AGENTAPI")
203+
viper.AutomaticEnv()
204+
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
163205
}

go.mod

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@ require (
99
github.com/go-chi/chi/v5 v5.2.2
1010
github.com/go-chi/cors v1.2.1
1111
github.com/spf13/cobra v1.9.1
12+
github.com/spf13/viper v1.20.1
1213
github.com/stretchr/testify v1.10.0
1314
github.com/tmaxmax/go-sse v0.10.0
1415
golang.org/x/term v0.30.0
1516
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da
1617
)
1718

19+
require (
20+
github.com/fsnotify/fsnotify v1.8.0 // indirect
21+
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
22+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
23+
github.com/sagikazarmark/locafero v0.7.0 // indirect
24+
github.com/sourcegraph/conc v0.3.0 // indirect
25+
github.com/spf13/cast v1.7.1 // indirect
26+
github.com/subosito/gotenv v1.6.0 // indirect
27+
go.uber.org/atomic v1.9.0 // indirect
28+
go.uber.org/multierr v1.9.0 // indirect
29+
)
30+
1831
require (
1932
github.com/ActiveState/termtest/conpty v0.5.0 // indirect
2033
github.com/ActiveState/vt10x v1.3.1 // indirect
@@ -29,7 +42,6 @@ require (
2942
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
3043
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3144
github.com/kr/pty v1.1.8 // indirect
32-
github.com/kr/text v0.1.0 // indirect
3345
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
3446
github.com/mattn/go-isatty v0.0.20 // indirect
3547
github.com/mattn/go-localereader v0.0.1 // indirect
@@ -45,6 +57,5 @@ require (
4557
golang.org/x/sync v0.12.0 // indirect
4658
golang.org/x/sys v0.31.0 // indirect
4759
golang.org/x/text v0.23.0 // indirect
48-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
4960
gopkg.in/yaml.v3 v3.0.1 // indirect
5061
)

go.sum

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
3333
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3434
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
3535
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
36+
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
37+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
38+
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
39+
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
3640
github.com/gdamore/encoding v0.0.0-20151215212835-b23993cbb635/go.mod h1:yrQYJKKDTrHmbYxI7CYi+/hbdiDT2m4Hj+t0ikCjsrQ=
3741
github.com/gdamore/tcell v1.0.1-0.20180608172421-b3cebc399d6f/go.mod h1:tqyG50u7+Ctv1w5VX67kLzKcj9YXR/JSBZQq/+mLl1A=
3842
github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
3943
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
4044
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
4145
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
46+
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
47+
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
48+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
49+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
4250
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4351
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
4452
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
@@ -51,8 +59,8 @@ github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3x
5159
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
5260
github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI=
5361
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
54-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
55-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
62+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
63+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
5664
github.com/lucasb-eyer/go-colorful v0.0.0-20180526135729-345fbb3dbcdb/go.mod h1:NXg0ArsFk0Y01623LgUqoqcouGDB+PwCCQlrwrG6xJ4=
5765
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
5866
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
@@ -69,6 +77,8 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU
6977
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
7078
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
7179
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
80+
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
81+
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
7282
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7383
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7484
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
@@ -77,21 +87,36 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
7787
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
7888
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
7989
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
90+
github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo=
91+
github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k=
8092
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
8193
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
94+
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
95+
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
8296
github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA=
8397
github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo=
98+
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
99+
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
84100
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
85101
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
86102
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
87103
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
104+
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
105+
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
88106
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
89107
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
108+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
90109
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
91110
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
92111
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
112+
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
113+
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
93114
github.com/tmaxmax/go-sse v0.10.0 h1:j9F93WB4Hxt8wUf6oGffMm4dutALvUPoDDxfuDQOSqA=
94115
github.com/tmaxmax/go-sse v0.10.0/go.mod h1:u/2kZQR1tyngo1lKaNCj1mJmhXGZWS1Zs5yiSOD+Eg8=
116+
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
117+
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
118+
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
119+
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
95120
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
96121
golang.org/x/crypto v0.0.0-20200427165652-729f1e841bcc/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
97122
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=

lib/httpapi/server.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ func (s *Server) GetOpenAPI() string {
5959
// because the action of taking a snapshot takes time too.
6060
const snapshotInterval = 25 * time.Millisecond
6161

62+
type ServerConfig struct {
63+
AgentType mf.AgentType
64+
Process *termexec.Process
65+
Port int
66+
ChatBasePath string
67+
}
68+
6269
// NewServer creates a new server instance
63-
func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Process, port int, chatBasePath string) *Server {
70+
func NewServer(ctx context.Context, config ServerConfig) *Server {
6471
router := chi.NewMux()
6572

6673
corsMiddleware := cors.New(cors.Options{
@@ -77,10 +84,10 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
7784
humaConfig.Info.Description = "HTTP API for Claude Code, Goose, and Aider.\n\nhttps://github.com/coder/agentapi"
7885
api := humachi.New(router, humaConfig)
7986
formatMessage := func(message string, userInput string) string {
80-
return mf.FormatAgentMessage(agentType, message, userInput)
87+
return mf.FormatAgentMessage(config.AgentType, message, userInput)
8188
}
8289
conversation := st.NewConversation(ctx, st.ConversationConfig{
83-
AgentIO: process,
90+
AgentIO: config.Process,
8491
GetTime: func() time.Time {
8592
return time.Now()
8693
},
@@ -92,13 +99,13 @@ func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Pr
9299
s := &Server{
93100
router: router,
94101
api: api,
95-
port: port,
102+
port: config.Port,
96103
conversation: conversation,
97104
logger: logctx.From(ctx),
98-
agentio: process,
99-
agentType: agentType,
105+
agentio: config.Process,
106+
agentType: config.AgentType,
100107
emitter: emitter,
101-
chatBasePath: strings.TrimSuffix(chatBasePath, "/"),
108+
chatBasePath: strings.TrimSuffix(config.ChatBasePath, "/"),
102109
}
103110

104111
// Register API routes

lib/httpapi/server_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ func TestOpenAPISchema(t *testing.T) {
4646
t.Parallel()
4747

4848
ctx := logctx.WithLogger(context.Background(), slog.New(slog.NewTextHandler(os.Stdout, nil)))
49-
srv := httpapi.NewServer(ctx, msgfmt.AgentTypeClaude, nil, 0, "/chat")
49+
srv := httpapi.NewServer(ctx, httpapi.ServerConfig{
50+
AgentType: msgfmt.AgentTypeClaude,
51+
Process: nil,
52+
Port: 0,
53+
ChatBasePath: "/chat",
54+
})
5055
currentSchemaStr := srv.GetOpenAPI()
5156
var currentSchema any
5257
if err := json.Unmarshal([]byte(currentSchemaStr), &currentSchema); err != nil {
@@ -90,7 +95,12 @@ func TestServer_redirectToChat(t *testing.T) {
9095
t.Run(tc.name, func(t *testing.T) {
9196
t.Parallel()
9297
tCtx := logctx.WithLogger(context.Background(), slog.New(slog.NewTextHandler(os.Stdout, nil)))
93-
s := httpapi.NewServer(tCtx, msgfmt.AgentTypeClaude, nil, 0, tc.chatBasePath)
98+
s := httpapi.NewServer(tCtx, httpapi.ServerConfig{
99+
AgentType: msgfmt.AgentTypeClaude,
100+
Process: nil,
101+
Port: 0,
102+
ChatBasePath: tc.chatBasePath,
103+
})
94104
tsServer := httptest.NewServer(s.Handler())
95105
t.Cleanup(tsServer.Close)
96106

0 commit comments

Comments
 (0)