diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 8f3e0a4..b4e9013 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.15.0" + ".": "0.16.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index b4dc606..8cd6a7c 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 64 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-e21f0324774a1762bc2bba0da3a8a6b0d0e74720d7a1c83dec813f9e027fcf58.yml -openapi_spec_hash: f1b636abfd6cb8e7c2ba7ffb8e53b9ba -config_hash: 09a2df23048cb16689c9a390d9e5bc47 +configured_endpoints: 65 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-ecf484375ede1edd7754779ad8beeebd4ba9118152fe6cd65772dc7245a19dee.yml +openapi_spec_hash: b1f3f05005f75cbf5b82299459e2aa9b +config_hash: 3ded7a0ed77b1bfd68eabc6763521fe8 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0155032..b2ffbc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.16.0 (2025-10-27) + +Full Changelog: [v0.15.0...v0.16.0](https://github.com/onkernel/kernel-go-sdk/compare/v0.15.0...v0.16.0) + +### Features + +* ad hoc playwright code exec AP| ([8589fb2](https://github.com/onkernel/kernel-go-sdk/commit/8589fb22265ec8ad4c5a02b7a485c78e8a5f45da)) + ## 0.15.0 (2025-10-17) Full Changelog: [v0.14.2...v0.15.0](https://github.com/onkernel/kernel-go-sdk/compare/v0.14.2...v0.15.0) diff --git a/README.md b/README.md index ba522c0..c95919f 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Or to pin the version: ```sh -go get -u 'github.com/onkernel/kernel-go-sdk@v0.15.0' +go get -u 'github.com/onkernel/kernel-go-sdk@v0.16.0' ``` diff --git a/api.md b/api.md index 906226c..533c147 100644 --- a/api.md +++ b/api.md @@ -164,6 +164,16 @@ Methods: - client.Browsers.Computer.Scroll(ctx context.Context, id string, body kernel.BrowserComputerScrollParams) error - client.Browsers.Computer.TypeText(ctx context.Context, id string, body kernel.BrowserComputerTypeTextParams) error +## Playwright + +Response Types: + +- kernel.BrowserPlaywrightExecuteResponse + +Methods: + +- client.Browsers.Playwright.Execute(ctx context.Context, id string, body kernel.BrowserPlaywrightExecuteParams) (kernel.BrowserPlaywrightExecuteResponse, error) + # Profiles Methods: diff --git a/browser.go b/browser.go index 6e067e8..dc3cbbd 100644 --- a/browser.go +++ b/browser.go @@ -31,12 +31,13 @@ import ( // automatically. You should not instantiate this service directly, and instead use // the [NewBrowserService] method instead. type BrowserService struct { - Options []option.RequestOption - Replays BrowserReplayService - Fs BrowserFService - Process BrowserProcessService - Logs BrowserLogService - Computer BrowserComputerService + Options []option.RequestOption + Replays BrowserReplayService + Fs BrowserFService + Process BrowserProcessService + Logs BrowserLogService + Computer BrowserComputerService + Playwright BrowserPlaywrightService } // NewBrowserService generates a new service that applies the given options to each @@ -50,6 +51,7 @@ func NewBrowserService(opts ...option.RequestOption) (r BrowserService) { r.Process = NewBrowserProcessService(opts...) r.Logs = NewBrowserLogService(opts...) r.Computer = NewBrowserComputerService(opts...) + r.Playwright = NewBrowserPlaywrightService(opts...) return } diff --git a/browserplaywright.go b/browserplaywright.go new file mode 100644 index 0000000..f66cd57 --- /dev/null +++ b/browserplaywright.go @@ -0,0 +1,101 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel + +import ( + "context" + "errors" + "fmt" + "net/http" + "slices" + + "github.com/onkernel/kernel-go-sdk/internal/apijson" + "github.com/onkernel/kernel-go-sdk/internal/requestconfig" + "github.com/onkernel/kernel-go-sdk/option" + "github.com/onkernel/kernel-go-sdk/packages/param" + "github.com/onkernel/kernel-go-sdk/packages/respjson" +) + +// BrowserPlaywrightService contains methods and other services that help with +// interacting with the kernel API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewBrowserPlaywrightService] method instead. +type BrowserPlaywrightService struct { + Options []option.RequestOption +} + +// NewBrowserPlaywrightService generates a new service that applies the given +// options to each request. These options are applied after the parent client's +// options (if there is one), and before any request-specific options. +func NewBrowserPlaywrightService(opts ...option.RequestOption) (r BrowserPlaywrightService) { + r = BrowserPlaywrightService{} + r.Options = opts + return +} + +// Execute arbitrary Playwright code in a fresh execution context against the +// browser. The code runs in the same VM as the browser, minimizing latency and +// maximizing throughput. It has access to 'page', 'context', and 'browser' +// variables. It can `return` a value, and this value is returned in the response. +func (r *BrowserPlaywrightService) Execute(ctx context.Context, id string, body BrowserPlaywrightExecuteParams, opts ...option.RequestOption) (res *BrowserPlaywrightExecuteResponse, err error) { + opts = slices.Concat(r.Options, opts) + if id == "" { + err = errors.New("missing required id parameter") + return + } + path := fmt.Sprintf("browsers/%s/playwright/execute", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + +// Result of Playwright code execution +type BrowserPlaywrightExecuteResponse struct { + // Whether the code executed successfully + Success bool `json:"success,required"` + // Error message if execution failed + Error string `json:"error"` + // The value returned by the code (if any) + Result any `json:"result"` + // Standard error from the execution + Stderr string `json:"stderr"` + // Standard output from the execution + Stdout string `json:"stdout"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Success respjson.Field + Error respjson.Field + Result respjson.Field + Stderr respjson.Field + Stdout respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r BrowserPlaywrightExecuteResponse) RawJSON() string { return r.JSON.raw } +func (r *BrowserPlaywrightExecuteResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type BrowserPlaywrightExecuteParams struct { + // TypeScript/JavaScript code to execute. The code has access to 'page', 'context', + // and 'browser' variables. It runs within a function, so you can use a return + // statement at the end to return a value. This value is returned as the `result` + // property in the response. Example: "await page.goto('https://example.com'); + // return await page.title();" + Code string `json:"code,required"` + // Maximum execution time in seconds. Default is 60. + TimeoutSec param.Opt[int64] `json:"timeout_sec,omitzero"` + paramObj +} + +func (r BrowserPlaywrightExecuteParams) MarshalJSON() (data []byte, err error) { + type shadow BrowserPlaywrightExecuteParams + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *BrowserPlaywrightExecuteParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} diff --git a/browserplaywright_test.go b/browserplaywright_test.go new file mode 100644 index 0000000..a7f2fe3 --- /dev/null +++ b/browserplaywright_test.go @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package kernel_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/onkernel/kernel-go-sdk" + "github.com/onkernel/kernel-go-sdk/internal/testutil" + "github.com/onkernel/kernel-go-sdk/option" +) + +func TestBrowserPlaywrightExecuteWithOptionalParams(t *testing.T) { + t.Skip("Prism tests are disabled") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := kernel.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Browsers.Playwright.Execute( + context.TODO(), + "id", + kernel.BrowserPlaywrightExecuteParams{ + Code: "code", + TimeoutSec: kernel.Int(1), + }, + ) + if err != nil { + var apierr *kernel.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/internal/version.go b/internal/version.go index 1f338c3..16d4c3d 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "0.15.0" // x-release-please-version +const PackageVersion = "0.16.0" // x-release-please-version