-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrowserlog.go
More file actions
83 lines (73 loc) · 2.96 KB
/
browserlog.go
File metadata and controls
83 lines (73 loc) · 2.96 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package kernel
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"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/param"
"github.com/kernel/kernel-go-sdk/packages/ssestream"
"github.com/kernel/kernel-go-sdk/shared"
)
// Stream logs from the browser instance.
//
// BrowserLogService 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 [NewBrowserLogService] method instead.
type BrowserLogService struct {
Options []option.RequestOption
}
// NewBrowserLogService 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 NewBrowserLogService(opts ...option.RequestOption) (r BrowserLogService) {
r = BrowserLogService{}
r.Options = opts
return
}
// Stream log files on the browser instance via SSE
func (r *BrowserLogService) StreamStreaming(ctx context.Context, id string, query BrowserLogStreamParams, opts ...option.RequestOption) (stream *ssestream.Stream[shared.LogEvent]) {
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 ssestream.NewStream[shared.LogEvent](nil, err)
}
path := fmt.Sprintf("browsers/%s/logs/stream", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &raw, opts...)
return ssestream.NewStream[shared.LogEvent](ssestream.NewDecoder(raw), err)
}
type BrowserLogStreamParams struct {
// Any of "path", "supervisor".
Source BrowserLogStreamParamsSource `query:"source,omitzero" api:"required" json:"-"`
Follow param.Opt[bool] `query:"follow,omitzero" json:"-"`
// only required if source is path
Path param.Opt[string] `query:"path,omitzero" json:"-"`
// only required if source is supervisor
SupervisorProcess param.Opt[string] `query:"supervisor_process,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [BrowserLogStreamParams]'s query parameters as `url.Values`.
func (r BrowserLogStreamParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type BrowserLogStreamParamsSource string
const (
BrowserLogStreamParamsSourcePath BrowserLogStreamParamsSource = "path"
BrowserLogStreamParamsSourceSupervisor BrowserLogStreamParamsSource = "supervisor"
)