@@ -27,14 +27,9 @@ const client = new Kernel({
2727 environment: ' development' , // defaults to 'production'
2828});
2929
30- const deployment = await client .apps .deployments .create ({
31- entrypoint_rel_path: ' main.ts' ,
32- file: fs .createReadStream (' path/to/file' ),
33- env_vars: { OPENAI_API_KEY : ' x' },
34- version: ' 1.0.0' ,
35- });
30+ const browser = await client .browsers .create ({ stealth: true });
3631
37- console .log (deployment . apps );
32+ console .log (browser . session_id );
3833```
3934
4035### Request & Response types
@@ -50,10 +45,7 @@ const client = new Kernel({
5045 environment: ' development' , // defaults to 'production'
5146});
5247
53- const params: Kernel .BrowserCreateParams = {
54- invocation_id: ' REPLACE_ME' ,
55- persistence: { id: ' browser-for-user-1234' },
56- };
48+ const params: Kernel .BrowserCreateParams = { stealth: true };
5749const browser: Kernel .BrowserCreateResponse = await client .browsers .create (params );
5850```
5951
@@ -75,32 +67,17 @@ import Kernel, { toFile } from '@onkernel/sdk';
7567const client = new Kernel ();
7668
7769// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
78- await client .apps .deployments .create ({
79- entrypoint_rel_path: ' src/app.py' ,
80- file: fs .createReadStream (' /path/to/file' ),
81- });
70+ await client .deployments .create ({ file: fs .createReadStream (' /path/to/file' ) });
8271
8372// Or if you have the web `File` API you can pass a `File` instance:
84- await client .apps .deployments .create ({
85- entrypoint_rel_path: ' src/app.py' ,
86- file: new File ([' my bytes' ], ' file' ),
87- });
73+ await client .deployments .create ({ file: new File ([' my bytes' ], ' file' ) });
8874
8975// You can also pass a `fetch` `Response`:
90- await client .apps .deployments .create ({
91- entrypoint_rel_path: ' src/app.py' ,
92- file: await fetch (' https://somesite/file' ),
93- });
76+ await client .deployments .create ({ file: await fetch (' https://somesite/file' ) });
9477
9578// Finally, if none of the above are convenient, you can use our `toFile` helper:
96- await client .apps .deployments .create ({
97- entrypoint_rel_path: ' src/app.py' ,
98- file: await toFile (Buffer .from (' my bytes' ), ' file' ),
99- });
100- await client .apps .deployments .create ({
101- entrypoint_rel_path: ' src/app.py' ,
102- file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ),
103- });
79+ await client .deployments .create ({ file: await toFile (Buffer .from (' my bytes' ), ' file' ) });
80+ await client .deployments .create ({ file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ) });
10481```
10582
10683## Handling errors
@@ -111,17 +88,15 @@ a subclass of `APIError` will be thrown:
11188
11289<!-- prettier-ignore -->
11390``` ts
114- const browser = await client .browsers
115- .create ({ invocation_id: ' REPLACE_ME' , persistence: { id: ' browser-for-user-1234' } })
116- .catch (async (err ) => {
117- if (err instanceof Kernel .APIError ) {
118- console .log (err .status ); // 400
119- console .log (err .name ); // BadRequestError
120- console .log (err .headers ); // {server: 'nginx', ...}
121- } else {
122- throw err ;
123- }
124- });
91+ const browser = await client .browsers .create ({ stealth: true }).catch (async (err ) => {
92+ if (err instanceof Kernel .APIError ) {
93+ console .log (err .status ); // 400
94+ console .log (err .name ); // BadRequestError
95+ console .log (err .headers ); // {server: 'nginx', ...}
96+ } else {
97+ throw err ;
98+ }
99+ });
125100```
126101
127102Error codes are as follows:
@@ -153,7 +128,7 @@ const client = new Kernel({
153128});
154129
155130// Or, configure per-request:
156- await client .browsers .create ({ invocation_id : ' REPLACE_ME ' , persistence : { id : ' browser-for-user-1234 ' } }, {
131+ await client .browsers .create ({ stealth : true }, {
157132 maxRetries: 5 ,
158133});
159134```
@@ -170,7 +145,7 @@ const client = new Kernel({
170145});
171146
172147// Override per-request:
173- await client .browsers .create ({ invocation_id: ' REPLACE_ME ' , persistence: { id: ' browser-for-user-1234 ' } }, {
148+ await client .browsers .create ({ stealth: true }, {
174149 timeout: 5 * 1000 ,
175150});
176151```
@@ -179,6 +154,40 @@ On timeout, an `APIConnectionTimeoutError` is thrown.
179154
180155Note that requests which time out will be [ retried twice by default] ( #retries ) .
181156
157+ ## Auto-pagination
158+
159+ List methods in the Kernel API are paginated.
160+ You can use the ` for await … of ` syntax to iterate through items across all pages:
161+
162+ ``` ts
163+ async function fetchAllDeploymentListResponses(params ) {
164+ const allDeploymentListResponses = [];
165+ // Automatically fetches more pages as needed.
166+ for await (const deploymentListResponse of client .deployments .list ({
167+ app_name: ' YOUR_APP' ,
168+ limit: 2 ,
169+ })) {
170+ allDeploymentListResponses .push (deploymentListResponse );
171+ }
172+ return allDeploymentListResponses ;
173+ }
174+ ```
175+
176+ Alternatively, you can request a single page at a time:
177+
178+ ``` ts
179+ let page = await client .deployments .list ({ app_name: ' YOUR_APP' , limit: 2 });
180+ for (const deploymentListResponse of page .items ) {
181+ console .log (deploymentListResponse );
182+ }
183+
184+ // Convenience methods are provided for manually paginating:
185+ while (page .hasNextPage ()) {
186+ page = await page .getNextPage ();
187+ // ...
188+ }
189+ ```
190+
182191## Advanced Usage
183192
184193### Accessing raw Response data (e.g., headers)
@@ -193,14 +202,12 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
193202``` ts
194203const client = new Kernel ();
195204
196- const response = await client .browsers
197- .create ({ invocation_id: ' REPLACE_ME' , persistence: { id: ' browser-for-user-1234' } })
198- .asResponse ();
205+ const response = await client .browsers .create ({ stealth: true }).asResponse ();
199206console .log (response .headers .get (' X-My-Header' ));
200207console .log (response .statusText ); // access the underlying Response object
201208
202209const { data : browser, response : raw } = await client .browsers
203- .create ({ invocation_id: ' REPLACE_ME ' , persistence: { id: ' browser-for-user-1234 ' } })
210+ .create ({ stealth: true })
204211 .withResponse ();
205212console .log (raw .headers .get (' X-My-Header' ));
206213console .log (browser .session_id );
@@ -283,7 +290,7 @@ parameter. This library doesn't validate at runtime that the request matches the
283290send will be sent as-is.
284291
285292``` ts
286- client .apps . deployments .create ({
293+ client .browsers .create ({
287294 // ...
288295 // @ts-expect-error baz is not yet public
289296 baz: ' undocumented option' ,
0 commit comments