@@ -7,8 +7,10 @@ import (
77 "errors"
88 "fmt"
99 "net/http"
10+ "net/url"
1011
1112 "github.com/onkernel/kernel-go-sdk/internal/apijson"
13+ "github.com/onkernel/kernel-go-sdk/internal/apiquery"
1214 "github.com/onkernel/kernel-go-sdk/internal/requestconfig"
1315 "github.com/onkernel/kernel-go-sdk/option"
1416 "github.com/onkernel/kernel-go-sdk/packages/param"
@@ -54,6 +56,80 @@ func (r *BrowserService) Get(ctx context.Context, id string, opts ...option.Requ
5456 return
5557}
5658
59+ // List active browser sessions for the authenticated user
60+ func (r * BrowserService ) List (ctx context.Context , opts ... option.RequestOption ) (res * []BrowserListResponse , err error ) {
61+ opts = append (r .Options [:], opts ... )
62+ path := "browsers"
63+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , nil , & res , opts ... )
64+ return
65+ }
66+
67+ // Delete a persistent browser session by persistent_id query parameter.
68+ func (r * BrowserService ) Delete (ctx context.Context , body BrowserDeleteParams , opts ... option.RequestOption ) (err error ) {
69+ opts = append (r .Options [:], opts ... )
70+ opts = append ([]option.RequestOption {option .WithHeader ("Accept" , "" )}, opts ... )
71+ path := "browsers"
72+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodDelete , path , body , nil , opts ... )
73+ return
74+ }
75+
76+ // Delete Browser Session by ID
77+ func (r * BrowserService ) DeleteByID (ctx context.Context , id string , opts ... option.RequestOption ) (err error ) {
78+ opts = append (r .Options [:], opts ... )
79+ opts = append ([]option.RequestOption {option .WithHeader ("Accept" , "" )}, opts ... )
80+ if id == "" {
81+ err = errors .New ("missing required id parameter" )
82+ return
83+ }
84+ path := fmt .Sprintf ("browsers/%s" , id )
85+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodDelete , path , nil , nil , opts ... )
86+ return
87+ }
88+
89+ // Optional persistence configuration for the browser session.
90+ type BrowserPersistence struct {
91+ // Unique identifier for the persistent browser session.
92+ ID string `json:"id,required"`
93+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
94+ JSON struct {
95+ ID respjson.Field
96+ ExtraFields map [string ]respjson.Field
97+ raw string
98+ } `json:"-"`
99+ }
100+
101+ // Returns the unmodified JSON received from the API
102+ func (r BrowserPersistence ) RawJSON () string { return r .JSON .raw }
103+ func (r * BrowserPersistence ) UnmarshalJSON (data []byte ) error {
104+ return apijson .UnmarshalRoot (data , r )
105+ }
106+
107+ // ToParam converts this BrowserPersistence to a BrowserPersistenceParam.
108+ //
109+ // Warning: the fields of the param type will not be present. ToParam should only
110+ // be used at the last possible moment before sending a request. Test for this with
111+ // BrowserPersistenceParam.Overrides()
112+ func (r BrowserPersistence ) ToParam () BrowserPersistenceParam {
113+ return param.Override [BrowserPersistenceParam ](r .RawJSON ())
114+ }
115+
116+ // Optional persistence configuration for the browser session.
117+ //
118+ // The property ID is required.
119+ type BrowserPersistenceParam struct {
120+ // Unique identifier for the persistent browser session.
121+ ID string `json:"id,required"`
122+ paramObj
123+ }
124+
125+ func (r BrowserPersistenceParam ) MarshalJSON () (data []byte , err error ) {
126+ type shadow BrowserPersistenceParam
127+ return param .MarshalObject (r , (* shadow )(& r ))
128+ }
129+ func (r * BrowserPersistenceParam ) UnmarshalJSON (data []byte ) error {
130+ return apijson .UnmarshalRoot (data , r )
131+ }
132+
57133type BrowserNewResponse struct {
58134 // Remote URL for live viewing the browser session
59135 BrowserLiveViewURL string `json:"browser_live_view_url,required"`
@@ -62,7 +138,7 @@ type BrowserNewResponse struct {
62138 // Unique identifier for the browser session
63139 SessionID string `json:"session_id,required"`
64140 // Optional persistence configuration for the browser session.
65- Persistence BrowserNewResponsePersistence `json:"persistence"`
141+ Persistence BrowserPersistence `json:"persistence"`
66142 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
67143 JSON struct {
68144 BrowserLiveViewURL respjson.Field
@@ -80,24 +156,6 @@ func (r *BrowserNewResponse) UnmarshalJSON(data []byte) error {
80156 return apijson .UnmarshalRoot (data , r )
81157}
82158
83- // Optional persistence configuration for the browser session.
84- type BrowserNewResponsePersistence struct {
85- // Unique identifier for the persistent browser session.
86- ID string `json:"id,required"`
87- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
88- JSON struct {
89- ID respjson.Field
90- ExtraFields map [string ]respjson.Field
91- raw string
92- } `json:"-"`
93- }
94-
95- // Returns the unmodified JSON received from the API
96- func (r BrowserNewResponsePersistence ) RawJSON () string { return r .JSON .raw }
97- func (r * BrowserNewResponsePersistence ) UnmarshalJSON (data []byte ) error {
98- return apijson .UnmarshalRoot (data , r )
99- }
100-
101159type BrowserGetResponse struct {
102160 // Remote URL for live viewing the browser session
103161 BrowserLiveViewURL string `json:"browser_live_view_url,required"`
@@ -106,7 +164,7 @@ type BrowserGetResponse struct {
106164 // Unique identifier for the browser session
107165 SessionID string `json:"session_id,required"`
108166 // Optional persistence configuration for the browser session.
109- Persistence BrowserGetResponsePersistence `json:"persistence"`
167+ Persistence BrowserPersistence `json:"persistence"`
110168 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
111169 JSON struct {
112170 BrowserLiveViewURL respjson.Field
@@ -124,29 +182,37 @@ func (r *BrowserGetResponse) UnmarshalJSON(data []byte) error {
124182 return apijson .UnmarshalRoot (data , r )
125183}
126184
127- // Optional persistence configuration for the browser session.
128- type BrowserGetResponsePersistence struct {
129- // Unique identifier for the persistent browser session.
130- ID string `json:"id,required"`
185+ type BrowserListResponse struct {
186+ // Remote URL for live viewing the browser session
187+ BrowserLiveViewURL string `json:"browser_live_view_url,required"`
188+ // Websocket URL for Chrome DevTools Protocol connections to the browser session
189+ CdpWsURL string `json:"cdp_ws_url,required"`
190+ // Unique identifier for the browser session
191+ SessionID string `json:"session_id,required"`
192+ // Optional persistence configuration for the browser session.
193+ Persistence BrowserPersistence `json:"persistence"`
131194 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
132195 JSON struct {
133- ID respjson.Field
134- ExtraFields map [string ]respjson.Field
135- raw string
196+ BrowserLiveViewURL respjson.Field
197+ CdpWsURL respjson.Field
198+ SessionID respjson.Field
199+ Persistence respjson.Field
200+ ExtraFields map [string ]respjson.Field
201+ raw string
136202 } `json:"-"`
137203}
138204
139205// Returns the unmodified JSON received from the API
140- func (r BrowserGetResponsePersistence ) RawJSON () string { return r .JSON .raw }
141- func (r * BrowserGetResponsePersistence ) UnmarshalJSON (data []byte ) error {
206+ func (r BrowserListResponse ) RawJSON () string { return r .JSON .raw }
207+ func (r * BrowserListResponse ) UnmarshalJSON (data []byte ) error {
142208 return apijson .UnmarshalRoot (data , r )
143209}
144210
145211type BrowserNewParams struct {
146212 // action invocation ID
147213 InvocationID string `json:"invocation_id,required"`
148214 // Optional persistence configuration for the browser session.
149- Persistence BrowserNewParamsPersistence `json:"persistence,omitzero"`
215+ Persistence BrowserPersistenceParam `json:"persistence,omitzero"`
150216 paramObj
151217}
152218
@@ -158,19 +224,16 @@ func (r *BrowserNewParams) UnmarshalJSON(data []byte) error {
158224 return apijson .UnmarshalRoot (data , r )
159225}
160226
161- // Optional persistence configuration for the browser session.
162- //
163- // The property ID is required.
164- type BrowserNewParamsPersistence struct {
165- // Unique identifier for the persistent browser session.
166- ID string `json:"id,required"`
227+ type BrowserDeleteParams struct {
228+ // Persistent browser identifier
229+ PersistentID string `query:"persistent_id,required" json:"-"`
167230 paramObj
168231}
169232
170- func ( r BrowserNewParamsPersistence ) MarshalJSON () ( data [] byte , err error ) {
171- type shadow BrowserNewParamsPersistence
172- return param . MarshalObject (r , ( * shadow )( & r ))
173- }
174- func ( r * BrowserNewParamsPersistence ) UnmarshalJSON ( data [] byte ) error {
175- return apijson . UnmarshalRoot ( data , r )
233+ // URLQuery serializes [BrowserDeleteParams]'s query parameters as `url.Values`.
234+ func ( r BrowserDeleteParams ) URLQuery () ( v url. Values , err error ) {
235+ return apiquery . MarshalWithSettings (r , apiquery. QuerySettings {
236+ ArrayFormat : apiquery . ArrayQueryFormatComma ,
237+ NestedFormat : apiquery . NestedQueryFormatBrackets ,
238+ } )
176239}
0 commit comments