Skip to content

Commit 3094578

Browse files
feat(api): update via SDK Studio
1 parent 0fec1e5 commit 3094578

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 15
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-b1b412b00906fca75bfa73cff7267dbb5bf975581778072e0a90c73ad7ba9cb1.yml
3-
openapi_spec_hash: 9b7a1b29bcb4963fe6da37005c357d27
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-5d4e11bc46eeecee7363d56a9dfe946acee997d5b352c2b0a50c20e742c54d2d.yml
3+
openapi_spec_hash: 333e53ad9c706296b9afdb8ff73bec8f
44
config_hash: df959c379e1145106030a4869b006afe

invocation.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,17 @@ const (
308308
)
309309

310310
// InvocationFollowResponseUnion contains all possible properties and values from
311-
// [shared.LogEvent], [DeploymentStateEvent], [InvocationStateEvent],
312-
// [shared.ErrorEvent].
311+
// [shared.LogEvent], [InvocationStateEvent], [shared.ErrorEvent].
313312
//
314313
// Use the [InvocationFollowResponseUnion.AsAny] method to switch on the variant.
315314
//
316315
// Use the methods beginning with 'As' to cast the union to one of its variants.
317316
type InvocationFollowResponseUnion struct {
318-
// Any of "log", nil, "invocation_state", "error".
317+
// Any of "log", "invocation_state", "error".
319318
Event string `json:"event"`
320319
// This field is from variant [shared.LogEvent].
321320
Message string `json:"message"`
322321
Timestamp time.Time `json:"timestamp"`
323-
// This field is from variant [DeploymentStateEvent].
324-
Deployment DeploymentStateEventDeployment `json:"deployment"`
325322
// This field is from variant [InvocationStateEvent].
326323
Invocation InvocationStateEventInvocation `json:"invocation"`
327324
// This field is from variant [shared.ErrorEvent].
@@ -330,19 +327,43 @@ type InvocationFollowResponseUnion struct {
330327
Event respjson.Field
331328
Message respjson.Field
332329
Timestamp respjson.Field
333-
Deployment respjson.Field
334330
Invocation respjson.Field
335331
Error respjson.Field
336332
raw string
337333
} `json:"-"`
338334
}
339335

340-
func (u InvocationFollowResponseUnion) AsLog() (v shared.LogEvent) {
341-
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
342-
return
336+
// anyInvocationFollowResponse is implemented by each variant of
337+
// [InvocationFollowResponseUnion] to add type safety for the return type of
338+
// [InvocationFollowResponseUnion.AsAny]
339+
type anyInvocationFollowResponse interface {
340+
ImplInvocationFollowResponseUnion()
343341
}
344342

345-
func (u InvocationFollowResponseUnion) AsDeploymentStateEvent() (v DeploymentStateEvent) {
343+
func (InvocationStateEvent) ImplInvocationFollowResponseUnion() {}
344+
345+
// Use the following switch statement to find the correct variant
346+
//
347+
// switch variant := InvocationFollowResponseUnion.AsAny().(type) {
348+
// case shared.LogEvent:
349+
// case kernel.InvocationStateEvent:
350+
// case shared.ErrorEvent:
351+
// default:
352+
// fmt.Errorf("no variant present")
353+
// }
354+
func (u InvocationFollowResponseUnion) AsAny() anyInvocationFollowResponse {
355+
switch u.Event {
356+
case "log":
357+
return u.AsLog()
358+
case "invocation_state":
359+
return u.AsInvocationState()
360+
case "error":
361+
return u.AsError()
362+
}
363+
return nil
364+
}
365+
366+
func (u InvocationFollowResponseUnion) AsLog() (v shared.LogEvent) {
346367
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
347368
return
348369
}

shared/shared.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ func (r *ErrorEvent) UnmarshalJSON(data []byte) error {
8585
return apijson.UnmarshalRoot(data, r)
8686
}
8787

88+
func (ErrorEvent) ImplInvocationFollowResponseUnion() {}
89+
8890
// A log entry from the application.
8991
type LogEvent struct {
9092
// Event type identifier (always "log").
@@ -110,3 +112,4 @@ func (r *LogEvent) UnmarshalJSON(data []byte) error {
110112
}
111113

112114
func (LogEvent) ImplAppDeploymentFollowResponseUnion() {}
115+
func (LogEvent) ImplInvocationFollowResponseUnion() {}

0 commit comments

Comments
 (0)