-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinvocation.go
More file actions
717 lines (658 loc) · 27.2 KB
/
invocation.go
File metadata and controls
717 lines (658 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package kernel
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/kernel/kernel-go-sdk/internal/apijson"
"github.com/kernel/kernel-go-sdk/internal/apiquery"
"github.com/kernel/kernel-go-sdk/internal/requestconfig"
"github.com/kernel/kernel-go-sdk/option"
"github.com/kernel/kernel-go-sdk/packages/pagination"
"github.com/kernel/kernel-go-sdk/packages/param"
"github.com/kernel/kernel-go-sdk/packages/respjson"
"github.com/kernel/kernel-go-sdk/packages/ssestream"
"github.com/kernel/kernel-go-sdk/shared"
"github.com/kernel/kernel-go-sdk/shared/constant"
)
// Invoke actions and stream or query invocation status and events.
//
// InvocationService 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 [NewInvocationService] method instead.
type InvocationService struct {
Options []option.RequestOption
}
// NewInvocationService 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 NewInvocationService(opts ...option.RequestOption) (r InvocationService) {
r = InvocationService{}
r.Options = opts
return
}
// Invoke an action.
func (r *InvocationService) New(ctx context.Context, body InvocationNewParams, opts ...option.RequestOption) (res *InvocationNewResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "invocations"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get details about an invocation's status and output.
func (r *InvocationService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *InvocationGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("invocations/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Update an invocation's status or output. This can be used to cancel an
// invocation by setting the status to "failed".
func (r *InvocationService) Update(ctx context.Context, id string, body InvocationUpdateParams, opts ...option.RequestOption) (res *InvocationUpdateResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("invocations/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// List invocations. Optionally filter by application name, action name, status,
// deployment ID, or start time.
func (r *InvocationService) List(ctx context.Context, query InvocationListParams, opts ...option.RequestOption) (res *pagination.OffsetPagination[InvocationListResponse], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "invocations"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List invocations. Optionally filter by application name, action name, status,
// deployment ID, or start time.
func (r *InvocationService) ListAutoPaging(ctx context.Context, query InvocationListParams, opts ...option.RequestOption) *pagination.OffsetPaginationAutoPager[InvocationListResponse] {
return pagination.NewOffsetPaginationAutoPager(r.List(ctx, query, opts...))
}
// Delete all browser sessions created within the specified invocation.
func (r *InvocationService) DeleteBrowsers(ctx context.Context, id string, opts ...option.RequestOption) (err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("invocations/%s/browsers", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
return
}
// Establishes a Server-Sent Events (SSE) stream that delivers real-time logs and
// status updates for an invocation. The stream terminates automatically once the
// invocation reaches a terminal state.
func (r *InvocationService) FollowStreaming(ctx context.Context, id string, query InvocationFollowParams, opts ...option.RequestOption) (stream *ssestream.Stream[InvocationFollowResponseUnion]) {
var (
raw *http.Response
err error
)
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "text/event-stream")}, opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("invocations/%s/events", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &raw, opts...)
return ssestream.NewStream[InvocationFollowResponseUnion](ssestream.NewDecoder(raw), err)
}
// Returns all active browser sessions created within the specified invocation.
func (r *InvocationService) ListBrowsers(ctx context.Context, id string, opts ...option.RequestOption) (res *InvocationListBrowsersResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("invocations/%s/browsers", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// An event representing the current state of an invocation.
type InvocationStateEvent struct {
// Event type identifier (always "invocation_state").
Event constant.InvocationState `json:"event" api:"required"`
Invocation InvocationStateEventInvocation `json:"invocation" api:"required"`
// Time the state was reported.
Timestamp time.Time `json:"timestamp" api:"required" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Event respjson.Field
Invocation respjson.Field
Timestamp respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r InvocationStateEvent) RawJSON() string { return r.JSON.raw }
func (r *InvocationStateEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type InvocationStateEventInvocation struct {
// ID of the invocation
ID string `json:"id" api:"required"`
// Name of the action invoked
ActionName string `json:"action_name" api:"required"`
// Name of the application
AppName string `json:"app_name" api:"required"`
// RFC 3339 Nanoseconds timestamp when the invocation started
StartedAt time.Time `json:"started_at" api:"required" format:"date-time"`
// Status of the invocation
//
// Any of "queued", "running", "succeeded", "failed".
Status string `json:"status" api:"required"`
// Version label for the application
Version string `json:"version" api:"required"`
// RFC 3339 Nanoseconds timestamp when the invocation finished (null if still
// running)
FinishedAt time.Time `json:"finished_at" api:"nullable" format:"date-time"`
// Output produced by the action, rendered as a JSON string. This could be: string,
// number, boolean, array, object, or null.
Output string `json:"output"`
// Payload provided to the invocation. This is a string that can be parsed as JSON.
Payload string `json:"payload"`
// Status reason
StatusReason string `json:"status_reason"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ActionName respjson.Field
AppName respjson.Field
StartedAt respjson.Field
Status respjson.Field
Version respjson.Field
FinishedAt respjson.Field
Output respjson.Field
Payload respjson.Field
StatusReason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r InvocationStateEventInvocation) RawJSON() string { return r.JSON.raw }
func (r *InvocationStateEventInvocation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type InvocationNewResponse struct {
// ID of the invocation
ID string `json:"id" api:"required"`
// Name of the action invoked
ActionName string `json:"action_name" api:"required"`
// Status of the invocation
//
// Any of "queued", "running", "succeeded", "failed".
Status InvocationNewResponseStatus `json:"status" api:"required"`
// The return value of the action that was invoked, rendered as a JSON string. This
// could be: string, number, boolean, array, object, or null.
Output string `json:"output"`
// Status reason
StatusReason string `json:"status_reason"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ActionName respjson.Field
Status respjson.Field
Output respjson.Field
StatusReason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r InvocationNewResponse) RawJSON() string { return r.JSON.raw }
func (r *InvocationNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Status of the invocation
type InvocationNewResponseStatus string
const (
InvocationNewResponseStatusQueued InvocationNewResponseStatus = "queued"
InvocationNewResponseStatusRunning InvocationNewResponseStatus = "running"
InvocationNewResponseStatusSucceeded InvocationNewResponseStatus = "succeeded"
InvocationNewResponseStatusFailed InvocationNewResponseStatus = "failed"
)
type InvocationGetResponse struct {
// ID of the invocation
ID string `json:"id" api:"required"`
// Name of the action invoked
ActionName string `json:"action_name" api:"required"`
// Name of the application
AppName string `json:"app_name" api:"required"`
// RFC 3339 Nanoseconds timestamp when the invocation started
StartedAt time.Time `json:"started_at" api:"required" format:"date-time"`
// Status of the invocation
//
// Any of "queued", "running", "succeeded", "failed".
Status InvocationGetResponseStatus `json:"status" api:"required"`
// Version label for the application
Version string `json:"version" api:"required"`
// RFC 3339 Nanoseconds timestamp when the invocation finished (null if still
// running)
FinishedAt time.Time `json:"finished_at" api:"nullable" format:"date-time"`
// Output produced by the action, rendered as a JSON string. This could be: string,
// number, boolean, array, object, or null.
Output string `json:"output"`
// Payload provided to the invocation. This is a string that can be parsed as JSON.
Payload string `json:"payload"`
// Status reason
StatusReason string `json:"status_reason"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ActionName respjson.Field
AppName respjson.Field
StartedAt respjson.Field
Status respjson.Field
Version respjson.Field
FinishedAt respjson.Field
Output respjson.Field
Payload respjson.Field
StatusReason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r InvocationGetResponse) RawJSON() string { return r.JSON.raw }
func (r *InvocationGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Status of the invocation
type InvocationGetResponseStatus string
const (
InvocationGetResponseStatusQueued InvocationGetResponseStatus = "queued"
InvocationGetResponseStatusRunning InvocationGetResponseStatus = "running"
InvocationGetResponseStatusSucceeded InvocationGetResponseStatus = "succeeded"
InvocationGetResponseStatusFailed InvocationGetResponseStatus = "failed"
)
type InvocationUpdateResponse struct {
// ID of the invocation
ID string `json:"id" api:"required"`
// Name of the action invoked
ActionName string `json:"action_name" api:"required"`
// Name of the application
AppName string `json:"app_name" api:"required"`
// RFC 3339 Nanoseconds timestamp when the invocation started
StartedAt time.Time `json:"started_at" api:"required" format:"date-time"`
// Status of the invocation
//
// Any of "queued", "running", "succeeded", "failed".
Status InvocationUpdateResponseStatus `json:"status" api:"required"`
// Version label for the application
Version string `json:"version" api:"required"`
// RFC 3339 Nanoseconds timestamp when the invocation finished (null if still
// running)
FinishedAt time.Time `json:"finished_at" api:"nullable" format:"date-time"`
// Output produced by the action, rendered as a JSON string. This could be: string,
// number, boolean, array, object, or null.
Output string `json:"output"`
// Payload provided to the invocation. This is a string that can be parsed as JSON.
Payload string `json:"payload"`
// Status reason
StatusReason string `json:"status_reason"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ActionName respjson.Field
AppName respjson.Field
StartedAt respjson.Field
Status respjson.Field
Version respjson.Field
FinishedAt respjson.Field
Output respjson.Field
Payload respjson.Field
StatusReason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r InvocationUpdateResponse) RawJSON() string { return r.JSON.raw }
func (r *InvocationUpdateResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Status of the invocation
type InvocationUpdateResponseStatus string
const (
InvocationUpdateResponseStatusQueued InvocationUpdateResponseStatus = "queued"
InvocationUpdateResponseStatusRunning InvocationUpdateResponseStatus = "running"
InvocationUpdateResponseStatusSucceeded InvocationUpdateResponseStatus = "succeeded"
InvocationUpdateResponseStatusFailed InvocationUpdateResponseStatus = "failed"
)
type InvocationListResponse struct {
// ID of the invocation
ID string `json:"id" api:"required"`
// Name of the action invoked
ActionName string `json:"action_name" api:"required"`
// Name of the application
AppName string `json:"app_name" api:"required"`
// RFC 3339 Nanoseconds timestamp when the invocation started
StartedAt time.Time `json:"started_at" api:"required" format:"date-time"`
// Status of the invocation
//
// Any of "queued", "running", "succeeded", "failed".
Status InvocationListResponseStatus `json:"status" api:"required"`
// Version label for the application
Version string `json:"version" api:"required"`
// RFC 3339 Nanoseconds timestamp when the invocation finished (null if still
// running)
FinishedAt time.Time `json:"finished_at" api:"nullable" format:"date-time"`
// Output produced by the action, rendered as a JSON string. This could be: string,
// number, boolean, array, object, or null.
Output string `json:"output"`
// Payload provided to the invocation. This is a string that can be parsed as JSON.
Payload string `json:"payload"`
// Status reason
StatusReason string `json:"status_reason"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ActionName respjson.Field
AppName respjson.Field
StartedAt respjson.Field
Status respjson.Field
Version respjson.Field
FinishedAt respjson.Field
Output respjson.Field
Payload respjson.Field
StatusReason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r InvocationListResponse) RawJSON() string { return r.JSON.raw }
func (r *InvocationListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Status of the invocation
type InvocationListResponseStatus string
const (
InvocationListResponseStatusQueued InvocationListResponseStatus = "queued"
InvocationListResponseStatusRunning InvocationListResponseStatus = "running"
InvocationListResponseStatusSucceeded InvocationListResponseStatus = "succeeded"
InvocationListResponseStatusFailed InvocationListResponseStatus = "failed"
)
// InvocationFollowResponseUnion contains all possible properties and values from
// [shared.LogEvent], [InvocationStateEvent], [shared.ErrorEvent],
// [shared.HeartbeatEvent].
//
// Use the [InvocationFollowResponseUnion.AsAny] method to switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type InvocationFollowResponseUnion struct {
// Any of "log", "invocation_state", "error", "sse_heartbeat".
Event string `json:"event"`
// This field is from variant [shared.LogEvent].
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
// This field is from variant [InvocationStateEvent].
Invocation InvocationStateEventInvocation `json:"invocation"`
// This field is from variant [shared.ErrorEvent].
Error shared.ErrorModel `json:"error"`
JSON struct {
Event respjson.Field
Message respjson.Field
Timestamp respjson.Field
Invocation respjson.Field
Error respjson.Field
raw string
} `json:"-"`
}
// anyInvocationFollowResponse is implemented by each variant of
// [InvocationFollowResponseUnion] to add type safety for the return type of
// [InvocationFollowResponseUnion.AsAny]
type anyInvocationFollowResponse interface {
ImplInvocationFollowResponseUnion()
}
func (InvocationStateEvent) ImplInvocationFollowResponseUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := InvocationFollowResponseUnion.AsAny().(type) {
// case shared.LogEvent:
// case kernel.InvocationStateEvent:
// case shared.ErrorEvent:
// case shared.HeartbeatEvent:
// default:
// fmt.Errorf("no variant present")
// }
func (u InvocationFollowResponseUnion) AsAny() anyInvocationFollowResponse {
switch u.Event {
case "log":
return u.AsLog()
case "invocation_state":
return u.AsInvocationState()
case "error":
return u.AsError()
case "sse_heartbeat":
return u.AsSseHeartbeat()
}
return nil
}
func (u InvocationFollowResponseUnion) AsLog() (v shared.LogEvent) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u InvocationFollowResponseUnion) AsInvocationState() (v InvocationStateEvent) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u InvocationFollowResponseUnion) AsError() (v shared.ErrorEvent) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u InvocationFollowResponseUnion) AsSseHeartbeat() (v shared.HeartbeatEvent) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u InvocationFollowResponseUnion) RawJSON() string { return u.JSON.raw }
func (r *InvocationFollowResponseUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type InvocationListBrowsersResponse struct {
Browsers []InvocationListBrowsersResponseBrowser `json:"browsers" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Browsers respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r InvocationListBrowsersResponse) RawJSON() string { return r.JSON.raw }
func (r *InvocationListBrowsersResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type InvocationListBrowsersResponseBrowser struct {
// Websocket URL for Chrome DevTools Protocol connections to the browser session
CdpWsURL string `json:"cdp_ws_url" api:"required"`
// When the browser session was created.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// Whether the browser session is running in headless mode.
Headless bool `json:"headless" api:"required"`
// Unique identifier for the browser session
SessionID string `json:"session_id" api:"required"`
// Whether the browser session is running in stealth mode.
Stealth bool `json:"stealth" api:"required"`
// The number of seconds of inactivity before the browser session is terminated.
TimeoutSeconds int64 `json:"timeout_seconds" api:"required"`
// Remote URL for live viewing the browser session. Only available for non-headless
// browsers.
BrowserLiveViewURL string `json:"browser_live_view_url"`
// When the browser session was soft-deleted. Only present for deleted sessions.
DeletedAt time.Time `json:"deleted_at" format:"date-time"`
// Whether the browser session has hardware-accelerated GPU rendering.
GPU bool `json:"gpu"`
// Whether the browser session is running in kiosk mode.
KioskMode bool `json:"kiosk_mode"`
// DEPRECATED: Use timeout_seconds (up to 72 hours) and Profiles instead.
//
// Deprecated: deprecated
Persistence BrowserPersistence `json:"persistence"`
// Browser pool this session was acquired from, if any.
Pool BrowserPoolRef `json:"pool"`
// Browser profile metadata.
Profile Profile `json:"profile"`
// ID of the proxy associated with this browser session, if any.
ProxyID string `json:"proxy_id"`
// Session usage metrics.
Usage BrowserUsage `json:"usage"`
// Initial browser window size in pixels with optional refresh rate. If omitted,
// image defaults apply (1920x1080@25). Arbitrary viewport dimensions are accepted,
// but the following configurations are known-good and fully tested: 2560x1440@10,
// 1920x1080@25, 1920x1200@25, 1440x900@25, 1280x800@60, 1024x768@60, 1200x800@60.
// Viewports outside this list may exhibit unstable live view or recording
// behavior. If refresh_rate is not provided, it will be automatically determined
// based on the resolution (higher resolutions use lower refresh rates to keep
// bandwidth reasonable).
Viewport shared.BrowserViewport `json:"viewport"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CdpWsURL respjson.Field
CreatedAt respjson.Field
Headless respjson.Field
SessionID respjson.Field
Stealth respjson.Field
TimeoutSeconds respjson.Field
BrowserLiveViewURL respjson.Field
DeletedAt respjson.Field
GPU respjson.Field
KioskMode respjson.Field
Persistence respjson.Field
Pool respjson.Field
Profile respjson.Field
ProxyID respjson.Field
Usage respjson.Field
Viewport respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r InvocationListBrowsersResponseBrowser) RawJSON() string { return r.JSON.raw }
func (r *InvocationListBrowsersResponseBrowser) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type InvocationNewParams struct {
// Name of the action to invoke
ActionName string `json:"action_name" api:"required"`
// Name of the application
AppName string `json:"app_name" api:"required"`
// Version of the application
Version string `json:"version" api:"required"`
// If true, invoke asynchronously. When set, the API responds 202 Accepted with
// status "queued".
Async param.Opt[bool] `json:"async,omitzero"`
// Timeout in seconds for async invocations (min 10, max 3600). Only applies when
// async is true.
AsyncTimeoutSeconds param.Opt[int64] `json:"async_timeout_seconds,omitzero"`
// Input data for the action, sent as a JSON string.
Payload param.Opt[string] `json:"payload,omitzero"`
paramObj
}
func (r InvocationNewParams) MarshalJSON() (data []byte, err error) {
type shadow InvocationNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *InvocationNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type InvocationUpdateParams struct {
// New status for the invocation.
//
// Any of "succeeded", "failed".
Status InvocationUpdateParamsStatus `json:"status,omitzero" api:"required"`
// Updated output of the invocation rendered as JSON string.
Output param.Opt[string] `json:"output,omitzero"`
paramObj
}
func (r InvocationUpdateParams) MarshalJSON() (data []byte, err error) {
type shadow InvocationUpdateParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *InvocationUpdateParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// New status for the invocation.
type InvocationUpdateParamsStatus string
const (
InvocationUpdateParamsStatusSucceeded InvocationUpdateParamsStatus = "succeeded"
InvocationUpdateParamsStatusFailed InvocationUpdateParamsStatus = "failed"
)
type InvocationListParams struct {
// Filter results by action name.
ActionName param.Opt[string] `query:"action_name,omitzero" json:"-"`
// Filter results by application name.
AppName param.Opt[string] `query:"app_name,omitzero" json:"-"`
// Filter results by deployment ID.
DeploymentID param.Opt[string] `query:"deployment_id,omitzero" json:"-"`
// Limit the number of invocations to return.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Offset the number of invocations to return.
Offset param.Opt[int64] `query:"offset,omitzero" json:"-"`
// Show invocations that have started since the given time (RFC timestamps or
// durations like 5m).
Since param.Opt[string] `query:"since,omitzero" json:"-"`
// Filter results by application version.
Version param.Opt[string] `query:"version,omitzero" json:"-"`
// Filter results by invocation status.
//
// Any of "queued", "running", "succeeded", "failed".
Status InvocationListParamsStatus `query:"status,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [InvocationListParams]'s query parameters as `url.Values`.
func (r InvocationListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Filter results by invocation status.
type InvocationListParamsStatus string
const (
InvocationListParamsStatusQueued InvocationListParamsStatus = "queued"
InvocationListParamsStatusRunning InvocationListParamsStatus = "running"
InvocationListParamsStatusSucceeded InvocationListParamsStatus = "succeeded"
InvocationListParamsStatusFailed InvocationListParamsStatus = "failed"
)
type InvocationFollowParams struct {
// Show logs since the given time (RFC timestamps or durations like 5m).
Since param.Opt[string] `query:"since,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [InvocationFollowParams]'s query parameters as `url.Values`.
func (r InvocationFollowParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}