Skip to content

Commit ac5cf50

Browse files
feat(api): update via SDK Studio
1 parent 4adc93f commit ac5cf50

4 files changed

Lines changed: 133 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: 10
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-3edc7a0eef4a0d4495782efbdb0d9b777a55aee058dab119f90de56019441326.yml
3-
openapi_spec_hash: dff0b1efa1c1614cf770ed8327cefab2
4-
config_hash: cb04a4d88ee9f530b303ca57ff7090b3
1+
configured_endpoints: 11
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-64ccdff4ca5d73d79d89e817fe83ccfd3d529696df3e6818c3c75e586ae00801.yml
3+
openapi_spec_hash: 21c7b8757fc0cc9415cda1bc06251de6
4+
config_hash: b3fcacd707da56b21d31ce0baf4fb87d

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ Response Types:
2626

2727
- <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#AppInvocationNewResponse">AppInvocationNewResponse</a>
2828
- <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#AppInvocationGetResponse">AppInvocationGetResponse</a>
29+
- <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#AppInvocationUpdateResponse">AppInvocationUpdateResponse</a>
2930

3031
Methods:
3132

3233
- <code title="post /invocations">client.Apps.Invocations.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppInvocationService.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#AppInvocationNewParams">AppInvocationNewParams</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#AppInvocationNewResponse">AppInvocationNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
3334
- <code title="get /invocations/{id}">client.Apps.Invocations.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppInvocationService.Get">Get</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#AppInvocationGetResponse">AppInvocationGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
35+
- <code title="patch /invocations/{id}">client.Apps.Invocations.<a href="https://pkg.go.dev/github.com/onkernel/kernel-go-sdk#AppInvocationService.Update">Update</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>, 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#AppInvocationUpdateParams">AppInvocationUpdateParams</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#AppInvocationUpdateResponse">AppInvocationUpdateResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
3436

3537
# Browsers
3638

appinvocation.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ func (r *AppInvocationService) Get(ctx context.Context, id string, opts ...optio
5555
return
5656
}
5757

58+
// Update invocation status or output
59+
func (r *AppInvocationService) Update(ctx context.Context, id string, body AppInvocationUpdateParams, opts ...option.RequestOption) (res *AppInvocationUpdateResponse, err error) {
60+
opts = append(r.Options[:], opts...)
61+
if id == "" {
62+
err = errors.New("missing required id parameter")
63+
return
64+
}
65+
path := fmt.Sprintf("invocations/%s", id)
66+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
67+
return
68+
}
69+
5870
type AppInvocationNewResponse struct {
5971
// ID of the invocation
6072
ID string `json:"id,required"`
@@ -149,13 +161,71 @@ const (
149161
AppInvocationGetResponseStatusFailed AppInvocationGetResponseStatus = "failed"
150162
)
151163

164+
type AppInvocationUpdateResponse struct {
165+
// ID of the invocation
166+
ID string `json:"id,required"`
167+
// Name of the action invoked
168+
ActionName string `json:"action_name,required"`
169+
// Name of the application
170+
AppName string `json:"app_name,required"`
171+
// RFC 3339 Nanoseconds timestamp when the invocation started
172+
StartedAt time.Time `json:"started_at,required" format:"date-time"`
173+
// Status of the invocation
174+
//
175+
// Any of "queued", "running", "succeeded", "failed".
176+
Status AppInvocationUpdateResponseStatus `json:"status,required"`
177+
// RFC 3339 Nanoseconds timestamp when the invocation finished (null if still
178+
// running)
179+
FinishedAt time.Time `json:"finished_at,nullable" format:"date-time"`
180+
// Output produced by the action, rendered as a JSON string. This could be: string,
181+
// number, boolean, array, object, or null.
182+
Output string `json:"output"`
183+
// Payload provided to the invocation. This is a string that can be parsed as JSON.
184+
Payload string `json:"payload"`
185+
// Status reason
186+
StatusReason string `json:"status_reason"`
187+
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
188+
JSON struct {
189+
ID respjson.Field
190+
ActionName respjson.Field
191+
AppName respjson.Field
192+
StartedAt respjson.Field
193+
Status respjson.Field
194+
FinishedAt respjson.Field
195+
Output respjson.Field
196+
Payload respjson.Field
197+
StatusReason respjson.Field
198+
ExtraFields map[string]respjson.Field
199+
raw string
200+
} `json:"-"`
201+
}
202+
203+
// Returns the unmodified JSON received from the API
204+
func (r AppInvocationUpdateResponse) RawJSON() string { return r.JSON.raw }
205+
func (r *AppInvocationUpdateResponse) UnmarshalJSON(data []byte) error {
206+
return apijson.UnmarshalRoot(data, r)
207+
}
208+
209+
// Status of the invocation
210+
type AppInvocationUpdateResponseStatus string
211+
212+
const (
213+
AppInvocationUpdateResponseStatusQueued AppInvocationUpdateResponseStatus = "queued"
214+
AppInvocationUpdateResponseStatusRunning AppInvocationUpdateResponseStatus = "running"
215+
AppInvocationUpdateResponseStatusSucceeded AppInvocationUpdateResponseStatus = "succeeded"
216+
AppInvocationUpdateResponseStatusFailed AppInvocationUpdateResponseStatus = "failed"
217+
)
218+
152219
type AppInvocationNewParams struct {
153220
// Name of the action to invoke
154221
ActionName string `json:"action_name,required"`
155222
// Name of the application
156223
AppName string `json:"app_name,required"`
157224
// Version of the application
158225
Version string `json:"version,required"`
226+
// If true, invoke asynchronously. When set, the API responds 202 Accepted with
227+
// status "queued".
228+
Async param.Opt[bool] `json:"async,omitzero"`
159229
// Input data for the action, sent as a JSON string.
160230
Payload param.Opt[string] `json:"payload,omitzero"`
161231
paramObj
@@ -168,3 +238,29 @@ func (r AppInvocationNewParams) MarshalJSON() (data []byte, err error) {
168238
func (r *AppInvocationNewParams) UnmarshalJSON(data []byte) error {
169239
return apijson.UnmarshalRoot(data, r)
170240
}
241+
242+
type AppInvocationUpdateParams struct {
243+
// New status for the invocation.
244+
//
245+
// Any of "succeeded", "failed".
246+
Status AppInvocationUpdateParamsStatus `json:"status,omitzero,required"`
247+
// Updated output of the invocation rendered as JSON string.
248+
Output param.Opt[string] `json:"output,omitzero"`
249+
paramObj
250+
}
251+
252+
func (r AppInvocationUpdateParams) MarshalJSON() (data []byte, err error) {
253+
type shadow AppInvocationUpdateParams
254+
return param.MarshalObject(r, (*shadow)(&r))
255+
}
256+
func (r *AppInvocationUpdateParams) UnmarshalJSON(data []byte) error {
257+
return apijson.UnmarshalRoot(data, r)
258+
}
259+
260+
// New status for the invocation.
261+
type AppInvocationUpdateParamsStatus string
262+
263+
const (
264+
AppInvocationUpdateParamsStatusSucceeded AppInvocationUpdateParamsStatus = "succeeded"
265+
AppInvocationUpdateParamsStatusFailed AppInvocationUpdateParamsStatus = "failed"
266+
)

appinvocation_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAppInvocationNewWithOptionalParams(t *testing.T) {
3030
ActionName: "analyze",
3131
AppName: "my-app",
3232
Version: "1.0.0",
33+
Async: kernel.Bool(true),
3334
Payload: kernel.String(`{"data":"example input"}`),
3435
})
3536
if err != nil {
@@ -63,3 +64,33 @@ func TestAppInvocationGet(t *testing.T) {
6364
t.Fatalf("err should be nil: %s", err.Error())
6465
}
6566
}
67+
68+
func TestAppInvocationUpdateWithOptionalParams(t *testing.T) {
69+
t.Skip("skipped: tests are disabled for the time being")
70+
baseURL := "http://localhost:4010"
71+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
72+
baseURL = envURL
73+
}
74+
if !testutil.CheckTestServer(t, baseURL) {
75+
return
76+
}
77+
client := kernel.NewClient(
78+
option.WithBaseURL(baseURL),
79+
option.WithAPIKey("My API Key"),
80+
)
81+
_, err := client.Apps.Invocations.Update(
82+
context.TODO(),
83+
"id",
84+
kernel.AppInvocationUpdateParams{
85+
Status: kernel.AppInvocationUpdateParamsStatusSucceeded,
86+
Output: kernel.String("output"),
87+
},
88+
)
89+
if err != nil {
90+
var apierr *kernel.Error
91+
if errors.As(err, &apierr) {
92+
t.Log(string(apierr.DumpRequest(true)))
93+
}
94+
t.Fatalf("err should be nil: %s", err.Error())
95+
}
96+
}

0 commit comments

Comments
 (0)