Skip to content

Commit 7f8cece

Browse files
rgarciaclaude
andcommitted
refactor: use SDK Curl method instead of raw HTTP for structured browser curl
Replace the hand-rolled POST /browsers/{id}/curl with the generated BrowserCurlParams/BrowserCurlResponse types from the Stainless preview SDK. The raw/streaming mode (curlRaw) remains custom HTTP as before. Also updates ProxyService.Check interface to match the new SDK signature (added ProxyCheckParams parameter). Uses a temporary replace directive pointing kernel-go-sdk at the stainless-sdks/kernel-go preview module. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 466ed67 commit 7f8cece

8 files changed

Lines changed: 27 additions & 38 deletions

File tree

cmd/browsers.go

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type BrowsersService interface {
3737
Update(ctx context.Context, id string, body kernel.BrowserUpdateParams, opts ...option.RequestOption) (res *kernel.BrowserUpdateResponse, err error)
3838
Delete(ctx context.Context, body kernel.BrowserDeleteParams, opts ...option.RequestOption) (err error)
3939
DeleteByID(ctx context.Context, id string, opts ...option.RequestOption) (err error)
40+
Curl(ctx context.Context, id string, body kernel.BrowserCurlParams, opts ...option.RequestOption) (res *kernel.BrowserCurlResponse, err error)
4041
LoadExtensions(ctx context.Context, id string, body kernel.BrowserLoadExtensionsParams, opts ...option.RequestOption) (err error)
4142
}
4243

@@ -3299,24 +3300,6 @@ type BrowsersCurlInput struct {
32993300
JSON bool
33003301
}
33013302

3302-
// browserCurlRequest is the JSON body for POST /browsers/{id}/curl.
3303-
type browserCurlRequest struct {
3304-
URL string `json:"url"`
3305-
Method string `json:"method,omitempty"`
3306-
Headers map[string]string `json:"headers,omitempty"`
3307-
Body string `json:"body,omitempty"`
3308-
TimeoutMs int `json:"timeout_ms,omitempty"`
3309-
ResponseEncoding string `json:"response_encoding,omitempty"`
3310-
}
3311-
3312-
// browserCurlResponse is the JSON response from POST /browsers/{id}/curl.
3313-
type browserCurlResponse struct {
3314-
Status int `json:"status"`
3315-
Headers map[string][]string `json:"headers"`
3316-
Body string `json:"body"`
3317-
DurationMs float64 `json:"duration_ms"`
3318-
}
3319-
33203303
func parseCurlHeaders(raw []string) map[string]string {
33213304
if len(raw) == 0 {
33223305
return nil
@@ -3347,28 +3330,24 @@ func (b BrowsersCmd) Curl(ctx context.Context, in BrowsersCurlInput) error {
33473330
body = string(data)
33483331
}
33493332

3350-
reqBody := browserCurlRequest{
3351-
URL: in.URL,
3333+
params := kernel.BrowserCurlParams{
3334+
URL: in.URL,
3335+
Headers: parseCurlHeaders(in.Headers),
33523336
}
33533337
if in.Method != "" {
3354-
reqBody.Method = in.Method
3338+
params.Method = kernel.BrowserCurlParamsMethod(in.Method)
33553339
}
33563340
if in.TimeoutMs != 0 {
3357-
reqBody.TimeoutMs = in.TimeoutMs
3341+
params.TimeoutMs = kernel.Opt(int64(in.TimeoutMs))
33583342
}
33593343
if in.Encoding != "" {
3360-
reqBody.ResponseEncoding = in.Encoding
3344+
params.ResponseEncoding = kernel.BrowserCurlParamsResponseEncoding(in.Encoding)
33613345
}
33623346
if body != "" {
3363-
reqBody.Body = body
3347+
params.Body = kernel.Opt(body)
33643348
}
3365-
reqBody.Headers = parseCurlHeaders(in.Headers)
3366-
3367-
client := b.client
3368-
path := fmt.Sprintf("/browsers/%s/curl", in.Identifier)
33693349

3370-
var result browserCurlResponse
3371-
err := client.Post(ctx, path, reqBody, &result)
3350+
result, err := b.browsers.Curl(ctx, in.Identifier, params)
33723351
if err != nil {
33733352
return util.CleanedUpSdkError{Err: err}
33743353
}

cmd/browsers_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type FakeBrowsersService struct {
6060
UpdateFunc func(ctx context.Context, id string, body kernel.BrowserUpdateParams, opts ...option.RequestOption) (*kernel.BrowserUpdateResponse, error)
6161
DeleteFunc func(ctx context.Context, body kernel.BrowserDeleteParams, opts ...option.RequestOption) error
6262
DeleteByIDFunc func(ctx context.Context, id string, opts ...option.RequestOption) error
63+
CurlFunc func(ctx context.Context, id string, body kernel.BrowserCurlParams, opts ...option.RequestOption) (*kernel.BrowserCurlResponse, error)
6364
LoadExtensionsFunc func(ctx context.Context, id string, body kernel.BrowserLoadExtensionsParams, opts ...option.RequestOption) error
6465
}
6566

@@ -105,6 +106,13 @@ func (f *FakeBrowsersService) DeleteByID(ctx context.Context, id string, opts ..
105106
return nil
106107
}
107108

109+
func (f *FakeBrowsersService) Curl(ctx context.Context, id string, body kernel.BrowserCurlParams, opts ...option.RequestOption) (*kernel.BrowserCurlResponse, error) {
110+
if f.CurlFunc != nil {
111+
return f.CurlFunc(ctx, id, body, opts...)
112+
}
113+
return &kernel.BrowserCurlResponse{}, nil
114+
}
115+
108116
func (f *FakeBrowsersService) LoadExtensions(ctx context.Context, id string, body kernel.BrowserLoadExtensionsParams, opts ...option.RequestOption) error {
109117
if f.LoadExtensionsFunc != nil {
110118
return f.LoadExtensionsFunc(ctx, id, body, opts...)

cmd/proxies/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (p ProxyCmd) Check(ctx context.Context, in ProxyCheckInput) error {
2020
pterm.Info.Printf("Running health check on proxy %s...\n", in.ID)
2121
}
2222

23-
proxy, err := p.proxies.Check(ctx, in.ID)
23+
proxy, err := p.proxies.Check(ctx, in.ID, kernel.ProxyCheckParams{})
2424
if err != nil {
2525
return util.CleanedUpSdkError{Err: err}
2626
}

cmd/proxies/check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestProxyCheck_ShowsBypassHosts(t *testing.T) {
1313
buf := captureOutput(t)
1414

1515
fake := &FakeProxyService{
16-
CheckFunc: func(ctx context.Context, id string, opts ...option.RequestOption) (*kernel.ProxyCheckResponse, error) {
16+
CheckFunc: func(ctx context.Context, id string, body kernel.ProxyCheckParams, opts ...option.RequestOption) (*kernel.ProxyCheckResponse, error) {
1717
return &kernel.ProxyCheckResponse{
1818
ID: id,
1919
Name: "Proxy 1",

cmd/proxies/common_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type FakeProxyService struct {
4141
GetFunc func(ctx context.Context, id string, opts ...option.RequestOption) (*kernel.ProxyGetResponse, error)
4242
NewFunc func(ctx context.Context, body kernel.ProxyNewParams, opts ...option.RequestOption) (*kernel.ProxyNewResponse, error)
4343
DeleteFunc func(ctx context.Context, id string, opts ...option.RequestOption) error
44-
CheckFunc func(ctx context.Context, id string, opts ...option.RequestOption) (*kernel.ProxyCheckResponse, error)
44+
CheckFunc func(ctx context.Context, id string, body kernel.ProxyCheckParams, opts ...option.RequestOption) (*kernel.ProxyCheckResponse, error)
4545
}
4646

4747
func (f *FakeProxyService) List(ctx context.Context, opts ...option.RequestOption) (*[]kernel.ProxyListResponse, error) {
@@ -73,9 +73,9 @@ func (f *FakeProxyService) Delete(ctx context.Context, id string, opts ...option
7373
return nil
7474
}
7575

76-
func (f *FakeProxyService) Check(ctx context.Context, id string, opts ...option.RequestOption) (*kernel.ProxyCheckResponse, error) {
76+
func (f *FakeProxyService) Check(ctx context.Context, id string, body kernel.ProxyCheckParams, opts ...option.RequestOption) (*kernel.ProxyCheckResponse, error) {
7777
if f.CheckFunc != nil {
78-
return f.CheckFunc(ctx, id, opts...)
78+
return f.CheckFunc(ctx, id, body, opts...)
7979
}
8080
return &kernel.ProxyCheckResponse{ID: id, Type: kernel.ProxyCheckResponseTypeDatacenter}, nil
8181
}

cmd/proxies/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type ProxyService interface {
1313
Get(ctx context.Context, id string, opts ...option.RequestOption) (res *kernel.ProxyGetResponse, err error)
1414
New(ctx context.Context, body kernel.ProxyNewParams, opts ...option.RequestOption) (res *kernel.ProxyNewResponse, err error)
1515
Delete(ctx context.Context, id string, opts ...option.RequestOption) (err error)
16-
Check(ctx context.Context, id string, opts ...option.RequestOption) (res *kernel.ProxyCheckResponse, err error)
16+
Check(ctx context.Context, id string, body kernel.ProxyCheckParams, opts ...option.RequestOption) (res *kernel.ProxyCheckResponse, err error)
1717
}
1818

1919
// ProxyCmd handles proxy operations independent of cobra.

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ require (
2222
golang.org/x/sync v0.19.0
2323
)
2424

25+
replace github.com/kernel/kernel-go-sdk => github.com/stainless-sdks/kernel-go v0.0.0-20260410014529-98c58b154bb9
26+
2527
require (
2628
al.essio.dev/pkg/shellescape v1.5.1 // indirect
2729
atomicgo.dev/cursor v0.2.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
6464
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
6565
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
6666
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
67-
github.com/kernel/kernel-go-sdk v0.44.1-0.20260323174449-5e56fc5d99a6 h1:RBlGCN3IagI0b+XrWsb5FOUV/18tniuL6oHFAb7MMHE=
68-
github.com/kernel/kernel-go-sdk v0.44.1-0.20260323174449-5e56fc5d99a6/go.mod h1:EeZzSuHZVeHKxKCPUzxou2bovNGhXaz0RXrSqKNf1AQ=
6967
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
7068
github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
7169
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
@@ -118,6 +116,8 @@ github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
118116
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
119117
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
120118
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
119+
github.com/stainless-sdks/kernel-go v0.0.0-20260410014529-98c58b154bb9 h1:6swlSdr5UYmQbuM3HWM9+1FDMjVHeBqE+ZPUvkDr73I=
120+
github.com/stainless-sdks/kernel-go v0.0.0-20260410014529-98c58b154bb9/go.mod h1:EeZzSuHZVeHKxKCPUzxou2bovNGhXaz0RXrSqKNf1AQ=
121121
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
122122
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
123123
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=

0 commit comments

Comments
 (0)