Skip to content

Commit e614d58

Browse files
feat(api): adding support for browser profiles
1 parent 2697844 commit e614d58

File tree

9 files changed

+238
-4
lines changed

9 files changed

+238
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 41
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-a7c1df5070fe59642d7a1f168aa902a468227752bfc930cbf38930f7c205dbb6.yml
3-
openapi_spec_hash: eab65e39aef4f0a0952b82adeecf6b5b
4-
config_hash: 5de78bc29ac060562575cb54bb26826c
1+
configured_endpoints: 46
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-e98d46c55826cdf541a9ee0df04ce92806ac6d4d92957ae79f897270b7d85b23.yml
3+
openapi_spec_hash: 8a1af54fc0a4417165b8a52e6354b685
4+
config_hash: 043ddc54629c6d8b889123770cb4769f

api.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Methods:
5959
Types:
6060

6161
- <code><a href="./src/resources/browsers/browsers.ts">BrowserPersistence</a></code>
62+
- <code><a href="./src/resources/browsers/browsers.ts">Profile</a></code>
6263
- <code><a href="./src/resources/browsers/browsers.ts">BrowserCreateResponse</a></code>
6364
- <code><a href="./src/resources/browsers/browsers.ts">BrowserRetrieveResponse</a></code>
6465
- <code><a href="./src/resources/browsers/browsers.ts">BrowserListResponse</a></code>
@@ -145,3 +146,17 @@ Methods:
145146
Methods:
146147

147148
- <code title="get /browsers/{id}/logs/stream">client.browsers.logs.<a href="./src/resources/browsers/logs.ts">stream</a>(id, { ...params }) -> LogEvent</code>
149+
150+
# Profiles
151+
152+
Types:
153+
154+
- <code><a href="./src/resources/profiles.ts">ProfileListResponse</a></code>
155+
156+
Methods:
157+
158+
- <code title="post /profiles">client.profiles.<a href="./src/resources/profiles.ts">create</a>({ ...params }) -> Profile</code>
159+
- <code title="get /profiles/{id_or_name}">client.profiles.<a href="./src/resources/profiles.ts">retrieve</a>(idOrName) -> Profile</code>
160+
- <code title="get /profiles">client.profiles.<a href="./src/resources/profiles.ts">list</a>() -> ProfileListResponse</code>
161+
- <code title="delete /profiles/{id_or_name}">client.profiles.<a href="./src/resources/profiles.ts">delete</a>(idOrName) -> void</code>
162+
- <code title="get /profiles/{id_or_name}/download">client.profiles.<a href="./src/resources/profiles.ts">download</a>(idOrName) -> Response</code>

src/client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
InvocationUpdateResponse,
4040
Invocations,
4141
} from './resources/invocations';
42+
import { ProfileCreateParams, ProfileListResponse, Profiles } from './resources/profiles';
4243
import {
4344
BrowserCreateParams,
4445
BrowserCreateResponse,
@@ -47,6 +48,7 @@ import {
4748
BrowserPersistence,
4849
BrowserRetrieveResponse,
4950
Browsers,
51+
Profile,
5052
} from './resources/browsers/browsers';
5153
import { type Fetch } from './internal/builtin-types';
5254
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
@@ -795,12 +797,14 @@ export class Kernel {
795797
apps: API.Apps = new API.Apps(this);
796798
invocations: API.Invocations = new API.Invocations(this);
797799
browsers: API.Browsers = new API.Browsers(this);
800+
profiles: API.Profiles = new API.Profiles(this);
798801
}
799802

800803
Kernel.Deployments = Deployments;
801804
Kernel.Apps = Apps;
802805
Kernel.Invocations = Invocations;
803806
Kernel.Browsers = Browsers;
807+
Kernel.Profiles = Profiles;
804808

805809
export declare namespace Kernel {
806810
export type RequestOptions = Opts.RequestOptions;
@@ -833,13 +837,20 @@ export declare namespace Kernel {
833837
export {
834838
Browsers as Browsers,
835839
type BrowserPersistence as BrowserPersistence,
840+
type Profile as Profile,
836841
type BrowserCreateResponse as BrowserCreateResponse,
837842
type BrowserRetrieveResponse as BrowserRetrieveResponse,
838843
type BrowserListResponse as BrowserListResponse,
839844
type BrowserCreateParams as BrowserCreateParams,
840845
type BrowserDeleteParams as BrowserDeleteParams,
841846
};
842847

848+
export {
849+
Profiles as Profiles,
850+
type ProfileListResponse as ProfileListResponse,
851+
type ProfileCreateParams as ProfileCreateParams,
852+
};
853+
843854
export type AppAction = API.AppAction;
844855
export type ErrorDetail = API.ErrorDetail;
845856
export type ErrorEvent = API.ErrorEvent;

src/resources/browsers/browsers.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,36 @@ export interface BrowserPersistence {
146146
id: string;
147147
}
148148

149+
/**
150+
* Browser profile metadata.
151+
*/
152+
export interface Profile {
153+
/**
154+
* Unique identifier for the profile
155+
*/
156+
id: string;
157+
158+
/**
159+
* Timestamp when the profile was created
160+
*/
161+
created_at: string;
162+
163+
/**
164+
* Timestamp when the profile was last used
165+
*/
166+
last_used_at?: string;
167+
168+
/**
169+
* Optional, easier-to-reference name for the profile
170+
*/
171+
name?: string | null;
172+
173+
/**
174+
* Timestamp when the profile was last updated
175+
*/
176+
updated_at?: string;
177+
}
178+
149179
export interface BrowserCreateResponse {
150180
/**
151181
* Websocket URL for Chrome DevTools Protocol connections to the browser session
@@ -187,6 +217,11 @@ export interface BrowserCreateResponse {
187217
* Optional persistence configuration for the browser session.
188218
*/
189219
persistence?: BrowserPersistence;
220+
221+
/**
222+
* Browser profile metadata.
223+
*/
224+
profile?: Profile;
190225
}
191226

192227
export interface BrowserRetrieveResponse {
@@ -230,6 +265,11 @@ export interface BrowserRetrieveResponse {
230265
* Optional persistence configuration for the browser session.
231266
*/
232267
persistence?: BrowserPersistence;
268+
269+
/**
270+
* Browser profile metadata.
271+
*/
272+
profile?: Profile;
233273
}
234274

235275
export type BrowserListResponse = Array<BrowserListResponse.BrowserListResponseItem>;
@@ -276,6 +316,11 @@ export namespace BrowserListResponse {
276316
* Optional persistence configuration for the browser session.
277317
*/
278318
persistence?: BrowsersAPI.BrowserPersistence;
319+
320+
/**
321+
* Browser profile metadata.
322+
*/
323+
profile?: BrowsersAPI.Profile;
279324
}
280325
}
281326

@@ -296,6 +341,13 @@ export interface BrowserCreateParams {
296341
*/
297342
persistence?: BrowserPersistence;
298343

344+
/**
345+
* Profile selection for the browser session. Provide either id or name. If
346+
* specified, the matching profile will be loaded into the browser session.
347+
* Profiles must be created beforehand.
348+
*/
349+
profile?: BrowserCreateParams.Profile;
350+
299351
/**
300352
* If true, launches the browser in stealth mode to reduce detection by anti-bot
301353
* mechanisms.
@@ -310,6 +362,32 @@ export interface BrowserCreateParams {
310362
timeout_seconds?: number;
311363
}
312364

365+
export namespace BrowserCreateParams {
366+
/**
367+
* Profile selection for the browser session. Provide either id or name. If
368+
* specified, the matching profile will be loaded into the browser session.
369+
* Profiles must be created beforehand.
370+
*/
371+
export interface Profile {
372+
/**
373+
* Profile ID to load for this browser session
374+
*/
375+
id?: string;
376+
377+
/**
378+
* Profile name to load for this browser session (instead of id). Must be 1-255
379+
* characters, using letters, numbers, dots, underscores, or hyphens.
380+
*/
381+
name?: string;
382+
383+
/**
384+
* If true, save changes made during the session back to the profile when the
385+
* session ends.
386+
*/
387+
save_changes?: boolean;
388+
}
389+
}
390+
313391
export interface BrowserDeleteParams {
314392
/**
315393
* Persistent browser identifier
@@ -325,6 +403,7 @@ Browsers.Logs = Logs;
325403
export declare namespace Browsers {
326404
export {
327405
type BrowserPersistence as BrowserPersistence,
406+
type Profile as Profile,
328407
type BrowserCreateResponse as BrowserCreateResponse,
329408
type BrowserRetrieveResponse as BrowserRetrieveResponse,
330409
type BrowserListResponse as BrowserListResponse,

src/resources/browsers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export {
44
Browsers,
55
type BrowserPersistence,
6+
type Profile,
67
type BrowserCreateResponse,
78
type BrowserRetrieveResponse,
89
type BrowserListResponse,

src/resources/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { Apps, type AppListResponse, type AppListParams } from './apps';
55
export {
66
Browsers,
77
type BrowserPersistence,
8+
type Profile,
89
type BrowserCreateResponse,
910
type BrowserRetrieveResponse,
1011
type BrowserListResponse,
@@ -32,3 +33,4 @@ export {
3233
type InvocationCreateParams,
3334
type InvocationUpdateParams,
3435
} from './invocations';
36+
export { Profiles, type ProfileListResponse, type ProfileCreateParams } from './profiles';

src/resources/profiles.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../core/resource';
4+
import * as BrowsersAPI from './browsers/browsers';
5+
import { APIPromise } from '../core/api-promise';
6+
import { buildHeaders } from '../internal/headers';
7+
import { RequestOptions } from '../internal/request-options';
8+
import { path } from '../internal/utils/path';
9+
10+
export class Profiles extends APIResource {
11+
/**
12+
* Create a browser profile that can be used to load state into future browser
13+
* sessions.
14+
*/
15+
create(body: ProfileCreateParams, options?: RequestOptions): APIPromise<BrowsersAPI.Profile> {
16+
return this._client.post('/profiles', { body, ...options });
17+
}
18+
19+
/**
20+
* Retrieve details for a single profile by its ID or name.
21+
*/
22+
retrieve(idOrName: string, options?: RequestOptions): APIPromise<BrowsersAPI.Profile> {
23+
return this._client.get(path`/profiles/${idOrName}`, options);
24+
}
25+
26+
/**
27+
* List profiles with optional filtering and pagination.
28+
*/
29+
list(options?: RequestOptions): APIPromise<ProfileListResponse> {
30+
return this._client.get('/profiles', options);
31+
}
32+
33+
/**
34+
* Delete a profile by its ID or by its name.
35+
*/
36+
delete(idOrName: string, options?: RequestOptions): APIPromise<void> {
37+
return this._client.delete(path`/profiles/${idOrName}`, {
38+
...options,
39+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
40+
});
41+
}
42+
43+
/**
44+
* Download the profile. Profiles are JSON files containing the pieces of state
45+
* that we save.
46+
*/
47+
download(idOrName: string, options?: RequestOptions): APIPromise<Response> {
48+
return this._client.get(path`/profiles/${idOrName}/download`, {
49+
...options,
50+
headers: buildHeaders([{ Accept: 'application/octet-stream' }, options?.headers]),
51+
__binaryResponse: true,
52+
});
53+
}
54+
}
55+
56+
export type ProfileListResponse = Array<BrowsersAPI.Profile>;
57+
58+
export interface ProfileCreateParams {
59+
/**
60+
* Optional name of the profile. Must be unique within the organization.
61+
*/
62+
name?: string;
63+
}
64+
65+
export declare namespace Profiles {
66+
export { type ProfileListResponse as ProfileListResponse, type ProfileCreateParams as ProfileCreateParams };
67+
}

tests/api-resources/browsers/browsers.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('resource browsers', () => {
2929
headless: false,
3030
invocation_id: 'rr33xuugxj9h0bkf1rdt2bet',
3131
persistence: { id: 'my-awesome-browser-for-user-1234' },
32+
profile: { id: 'id', name: 'name', save_changes: true },
3233
stealth: true,
3334
timeout_seconds: 0,
3435
},
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
8+
});
9+
10+
describe('resource profiles', () => {
11+
// Prism tests are disabled
12+
test.skip('create', async () => {
13+
const responsePromise = client.profiles.create({});
14+
const rawResponse = await responsePromise.asResponse();
15+
expect(rawResponse).toBeInstanceOf(Response);
16+
const response = await responsePromise;
17+
expect(response).not.toBeInstanceOf(Response);
18+
const dataAndResponse = await responsePromise.withResponse();
19+
expect(dataAndResponse.data).toBe(response);
20+
expect(dataAndResponse.response).toBe(rawResponse);
21+
});
22+
23+
// Prism tests are disabled
24+
test.skip('retrieve', async () => {
25+
const responsePromise = client.profiles.retrieve('id_or_name');
26+
const rawResponse = await responsePromise.asResponse();
27+
expect(rawResponse).toBeInstanceOf(Response);
28+
const response = await responsePromise;
29+
expect(response).not.toBeInstanceOf(Response);
30+
const dataAndResponse = await responsePromise.withResponse();
31+
expect(dataAndResponse.data).toBe(response);
32+
expect(dataAndResponse.response).toBe(rawResponse);
33+
});
34+
35+
// Prism tests are disabled
36+
test.skip('list', async () => {
37+
const responsePromise = client.profiles.list();
38+
const rawResponse = await responsePromise.asResponse();
39+
expect(rawResponse).toBeInstanceOf(Response);
40+
const response = await responsePromise;
41+
expect(response).not.toBeInstanceOf(Response);
42+
const dataAndResponse = await responsePromise.withResponse();
43+
expect(dataAndResponse.data).toBe(response);
44+
expect(dataAndResponse.response).toBe(rawResponse);
45+
});
46+
47+
// Prism tests are disabled
48+
test.skip('delete', async () => {
49+
const responsePromise = client.profiles.delete('id_or_name');
50+
const rawResponse = await responsePromise.asResponse();
51+
expect(rawResponse).toBeInstanceOf(Response);
52+
const response = await responsePromise;
53+
expect(response).not.toBeInstanceOf(Response);
54+
const dataAndResponse = await responsePromise.withResponse();
55+
expect(dataAndResponse.data).toBe(response);
56+
expect(dataAndResponse.response).toBe(rawResponse);
57+
});
58+
});

0 commit comments

Comments
 (0)