Skip to content

Commit 4a12204

Browse files
feat(api): update via SDK Studio
1 parent 5adf2a6 commit 4a12204

8 files changed

Lines changed: 629 additions & 4 deletions

File tree

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 5
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-3b19f5e2b96ede3193aa7a24d3f82d1406b8a16ea25e98ba3956e4a1a2376ad7.yml
3-
openapi_spec_hash: b62a6e73ddcec71674973f795a5790ac
4-
config_hash: df889df131f7438197abd59faace3c77
1+
configured_endpoints: 7
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-c9d64df733f286f09d2203f4e3d820ce57e8d4c629c5e2db4e2bfac91fbc1598.yml
3+
openapi_spec_hash: fa407611fc566d55f403864fbfaa6c23
4+
config_hash: 7f67c5b95af1e4b39525515240b72275

api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
# Apps
22

3+
Response Types:
4+
5+
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppListResponse">AppListResponse</a>
6+
7+
Methods:
8+
9+
- <code title="get /apps">client.Apps.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppListParams">AppListParams</a>) ([]<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppListResponse">AppListResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
10+
311
## Deployments
412

513
Response Types:
614

715
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppDeploymentNewResponse">AppDeploymentNewResponse</a>
16+
- <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppDeploymentFollowResponseUnion">AppDeploymentFollowResponseUnion</a>
817

918
Methods:
1019

1120
- <code title="post /deploy">client.Apps.Deployments.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppDeploymentService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppDeploymentNewParams">AppDeploymentNewParams</a>) (<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppDeploymentNewResponse">AppDeploymentNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
21+
- <code title="get /apps/{id}/events">client.Apps.Deployments.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppDeploymentService.Follow">Follow</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) ([]<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk">kernel</a>.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppDeploymentFollowResponseUnion">AppDeploymentFollowResponseUnion</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
1222

1323
## Invocations
1424

app.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
package kernel
44

55
import (
6+
"context"
7+
"net/http"
8+
"net/url"
9+
10+
"github.com/onkernel/kernel-go-sdk/internal/apijson"
11+
"github.com/onkernel/kernel-go-sdk/internal/apiquery"
12+
"github.com/onkernel/kernel-go-sdk/internal/requestconfig"
613
"github.com/onkernel/kernel-go-sdk/option"
14+
"github.com/onkernel/kernel-go-sdk/packages/param"
15+
"github.com/onkernel/kernel-go-sdk/packages/respjson"
716
)
817

918
// AppService contains methods and other services that help with interacting with
@@ -28,3 +37,58 @@ func NewAppService(opts ...option.RequestOption) (r AppService) {
2837
r.Invocations = NewAppInvocationService(opts...)
2938
return
3039
}
40+
41+
// List application versions for the authenticated user. Optionally filter by app
42+
// name and/or version label.
43+
func (r *AppService) List(ctx context.Context, query AppListParams, opts ...option.RequestOption) (res *[]AppListResponse, err error) {
44+
opts = append(r.Options[:], opts...)
45+
path := "apps"
46+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
47+
return
48+
}
49+
50+
// Summary of an application version.
51+
type AppListResponse struct {
52+
// Unique identifier for the app version
53+
ID string `json:"id,required"`
54+
// Name of the application
55+
AppName string `json:"app_name,required"`
56+
// Deployment region code
57+
Region string `json:"region,required"`
58+
// Version label for the application
59+
Version string `json:"version,required"`
60+
// Environment variables configured for this app version
61+
EnvVars map[string]string `json:"env_vars"`
62+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
63+
JSON struct {
64+
ID respjson.Field
65+
AppName respjson.Field
66+
Region respjson.Field
67+
Version respjson.Field
68+
EnvVars respjson.Field
69+
ExtraFields map[string]respjson.Field
70+
raw string
71+
} `json:"-"`
72+
}
73+
74+
// Returns the unmodified JSON received from the API
75+
func (r AppListResponse) RawJSON() string { return r.JSON.raw }
76+
func (r *AppListResponse) UnmarshalJSON(data []byte) error {
77+
return apijson.UnmarshalRoot(data, r)
78+
}
79+
80+
type AppListParams struct {
81+
// Filter results by application name.
82+
AppName param.Opt[string] `query:"app_name,omitzero" json:"-"`
83+
// Filter results by version label.
84+
Version param.Opt[string] `query:"version,omitzero" json:"-"`
85+
paramObj
86+
}
87+
88+
// URLQuery serializes [AppListParams]'s query parameters as `url.Values`.
89+
func (r AppListParams) URLQuery() (v url.Values, err error) {
90+
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
91+
ArrayFormat: apiquery.ArrayQueryFormatComma,
92+
NestedFormat: apiquery.NestedQueryFormatBrackets,
93+
})
94+
}

app_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package kernel_test
4+
5+
import (
6+
"context"
7+
"errors"
8+
"os"
9+
"testing"
10+
11+
"github.com/onkernel/kernel-go-sdk"
12+
"github.com/onkernel/kernel-go-sdk/internal/testutil"
13+
"github.com/onkernel/kernel-go-sdk/option"
14+
)
15+
16+
func TestAppListWithOptionalParams(t *testing.T) {
17+
t.Skip("skipped: tests are disabled for the time being")
18+
baseURL := "http://localhost:4010"
19+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
20+
baseURL = envURL
21+
}
22+
if !testutil.CheckTestServer(t, baseURL) {
23+
return
24+
}
25+
client := kernel.NewClient(
26+
option.WithBaseURL(baseURL),
27+
option.WithAPIKey("My API Key"),
28+
)
29+
_, err := client.Apps.List(context.TODO(), kernel.AppListParams{
30+
AppName: kernel.String("app_name"),
31+
Version: kernel.String("version"),
32+
})
33+
if err != nil {
34+
var apierr *kernel.Error
35+
if errors.As(err, &apierr) {
36+
t.Log(string(apierr.DumpRequest(true)))
37+
}
38+
t.Fatalf("err should be nil: %s", err.Error())
39+
}
40+
}

appdeployment.go

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ package kernel
55
import (
66
"bytes"
77
"context"
8+
"encoding/json"
9+
"errors"
10+
"fmt"
811
"io"
912
"mime/multipart"
1013
"net/http"
14+
"time"
1115

1216
"github.com/onkernel/kernel-go-sdk/internal/apiform"
1317
"github.com/onkernel/kernel-go-sdk/internal/apijson"
1418
"github.com/onkernel/kernel-go-sdk/internal/requestconfig"
1519
"github.com/onkernel/kernel-go-sdk/option"
1620
"github.com/onkernel/kernel-go-sdk/packages/param"
1721
"github.com/onkernel/kernel-go-sdk/packages/respjson"
22+
"github.com/onkernel/kernel-go-sdk/packages/ssestream"
23+
"github.com/onkernel/kernel-go-sdk/shared/constant"
1824
)
1925

2026
// AppDeploymentService contains methods and other services that help with
@@ -44,6 +50,25 @@ func (r *AppDeploymentService) New(ctx context.Context, body AppDeploymentNewPar
4450
return
4551
}
4652

53+
// Establishes a Server-Sent Events (SSE) stream that delivers real-time logs and
54+
// status updates for a deployed application. The stream terminates automatically
55+
// once the application reaches a terminal state.
56+
func (r *AppDeploymentService) FollowStreaming(ctx context.Context, id string, opts ...option.RequestOption) (stream *ssestream.Stream[[]AppDeploymentFollowResponseUnion]) {
57+
var (
58+
raw *http.Response
59+
err error
60+
)
61+
opts = append(r.Options[:], opts...)
62+
opts = append([]option.RequestOption{option.WithHeader("Accept", "text/event-stream")}, opts...)
63+
if id == "" {
64+
err = errors.New("missing required id parameter")
65+
return
66+
}
67+
path := fmt.Sprintf("apps/%s/events", id)
68+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &raw, opts...)
69+
return ssestream.NewStream[[]AppDeploymentFollowResponseUnion](ssestream.NewDecoder(raw), err)
70+
}
71+
4772
type AppDeploymentNewResponse struct {
4873
// List of apps deployed
4974
Apps []AppDeploymentNewResponseApp `json:"apps,required"`
@@ -119,6 +144,156 @@ const (
119144
AppDeploymentNewResponseStatusFailed AppDeploymentNewResponseStatus = "failed"
120145
)
121146

147+
// AppDeploymentFollowResponseUnion contains all possible properties and values
148+
// from [AppDeploymentFollowResponseState],
149+
// [AppDeploymentFollowResponseStateUpdate], [AppDeploymentFollowResponseLog].
150+
//
151+
// Use the [AppDeploymentFollowResponseUnion.AsAny] method to switch on the
152+
// variant.
153+
//
154+
// Use the methods beginning with 'As' to cast the union to one of its variants.
155+
type AppDeploymentFollowResponseUnion struct {
156+
// Any of "state", "state_update", "log".
157+
Event string `json:"event"`
158+
State string `json:"state"`
159+
Timestamp time.Time `json:"timestamp"`
160+
// This field is from variant [AppDeploymentFollowResponseLog].
161+
Message string `json:"message"`
162+
JSON struct {
163+
Event respjson.Field
164+
State respjson.Field
165+
Timestamp respjson.Field
166+
Message respjson.Field
167+
raw string
168+
} `json:"-"`
169+
}
170+
171+
// anyAppDeploymentFollowResponse is implemented by each variant of
172+
// [AppDeploymentFollowResponseUnion] to add type safety for the return type of
173+
// [AppDeploymentFollowResponseUnion.AsAny]
174+
type anyAppDeploymentFollowResponse interface {
175+
implAppDeploymentFollowResponseUnion()
176+
}
177+
178+
func (AppDeploymentFollowResponseState) implAppDeploymentFollowResponseUnion() {}
179+
func (AppDeploymentFollowResponseStateUpdate) implAppDeploymentFollowResponseUnion() {}
180+
func (AppDeploymentFollowResponseLog) implAppDeploymentFollowResponseUnion() {}
181+
182+
// Use the following switch statement to find the correct variant
183+
//
184+
// switch variant := AppDeploymentFollowResponseUnion.AsAny().(type) {
185+
// case kernel.AppDeploymentFollowResponseState:
186+
// case kernel.AppDeploymentFollowResponseStateUpdate:
187+
// case kernel.AppDeploymentFollowResponseLog:
188+
// default:
189+
// fmt.Errorf("no variant present")
190+
// }
191+
func (u AppDeploymentFollowResponseUnion) AsAny() anyAppDeploymentFollowResponse {
192+
switch u.Event {
193+
case "state":
194+
return u.AsState()
195+
case "state_update":
196+
return u.AsStateUpdate()
197+
case "log":
198+
return u.AsLog()
199+
}
200+
return nil
201+
}
202+
203+
func (u AppDeploymentFollowResponseUnion) AsState() (v AppDeploymentFollowResponseState) {
204+
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
205+
return
206+
}
207+
208+
func (u AppDeploymentFollowResponseUnion) AsStateUpdate() (v AppDeploymentFollowResponseStateUpdate) {
209+
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
210+
return
211+
}
212+
213+
func (u AppDeploymentFollowResponseUnion) AsLog() (v AppDeploymentFollowResponseLog) {
214+
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
215+
return
216+
}
217+
218+
// Returns the unmodified JSON received from the API
219+
func (u AppDeploymentFollowResponseUnion) RawJSON() string { return u.JSON.raw }
220+
221+
func (r *AppDeploymentFollowResponseUnion) UnmarshalJSON(data []byte) error {
222+
return apijson.UnmarshalRoot(data, r)
223+
}
224+
225+
// Initial state of the application, emitted once when subscribing.
226+
type AppDeploymentFollowResponseState struct {
227+
// Event type identifier (always "state").
228+
Event constant.State `json:"event,required"`
229+
// Current application state (e.g., "deploying", "running", "succeeded", "failed").
230+
State string `json:"state,required"`
231+
// Time the state was reported.
232+
Timestamp time.Time `json:"timestamp" format:"date-time"`
233+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
234+
JSON struct {
235+
Event respjson.Field
236+
State respjson.Field
237+
Timestamp respjson.Field
238+
ExtraFields map[string]respjson.Field
239+
raw string
240+
} `json:"-"`
241+
}
242+
243+
// Returns the unmodified JSON received from the API
244+
func (r AppDeploymentFollowResponseState) RawJSON() string { return r.JSON.raw }
245+
func (r *AppDeploymentFollowResponseState) UnmarshalJSON(data []byte) error {
246+
return apijson.UnmarshalRoot(data, r)
247+
}
248+
249+
// An update emitted when the application's state changes.
250+
type AppDeploymentFollowResponseStateUpdate struct {
251+
// Event type identifier (always "state_update").
252+
Event constant.StateUpdate `json:"event,required"`
253+
// New application state (e.g., "running", "succeeded", "failed").
254+
State string `json:"state,required"`
255+
// Time the state change occurred.
256+
Timestamp time.Time `json:"timestamp" format:"date-time"`
257+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
258+
JSON struct {
259+
Event respjson.Field
260+
State respjson.Field
261+
Timestamp respjson.Field
262+
ExtraFields map[string]respjson.Field
263+
raw string
264+
} `json:"-"`
265+
}
266+
267+
// Returns the unmodified JSON received from the API
268+
func (r AppDeploymentFollowResponseStateUpdate) RawJSON() string { return r.JSON.raw }
269+
func (r *AppDeploymentFollowResponseStateUpdate) UnmarshalJSON(data []byte) error {
270+
return apijson.UnmarshalRoot(data, r)
271+
}
272+
273+
// A log entry from the application.
274+
type AppDeploymentFollowResponseLog struct {
275+
// Event type identifier (always "log").
276+
Event constant.Log `json:"event,required"`
277+
// Log message text.
278+
Message string `json:"message,required"`
279+
// Time the log entry was produced.
280+
Timestamp time.Time `json:"timestamp" format:"date-time"`
281+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
282+
JSON struct {
283+
Event respjson.Field
284+
Message respjson.Field
285+
Timestamp respjson.Field
286+
ExtraFields map[string]respjson.Field
287+
raw string
288+
} `json:"-"`
289+
}
290+
291+
// Returns the unmodified JSON received from the API
292+
func (r AppDeploymentFollowResponseLog) RawJSON() string { return r.JSON.raw }
293+
func (r *AppDeploymentFollowResponseLog) UnmarshalJSON(data []byte) error {
294+
return apijson.UnmarshalRoot(data, r)
295+
}
296+
122297
type AppDeploymentNewParams struct {
123298
// Relative path to the entrypoint of the application
124299
EntrypointRelPath string `json:"entrypoint_rel_path,required"`

0 commit comments

Comments
 (0)