@@ -28,13 +28,13 @@ const client = new Kernel({
2828});
2929
3030async function main () {
31- const response = await client .apps .deploy ({
32- entrypointRelPath : ' app.py ' ,
31+ const deployment = await client .apps .deployments . create ({
32+ entrypoint_rel_path : ' main.ts ' ,
3333 file: fs .createReadStream (' path/to/file' ),
34- version: ' REPLACE_ME ' ,
34+ version: ' 1.0.0 ' ,
3535 });
3636
37- console .log (response .apps );
37+ console .log (deployment .apps );
3838}
3939
4040main ();
@@ -54,12 +54,8 @@ const client = new Kernel({
5454});
5555
5656async function main() {
57- const params: Kernel .AppDeployParams = {
58- entrypointRelPath: ' app.py' ,
59- file: fs .createReadStream (' path/to/file' ),
60- version: ' REPLACE_ME' ,
61- };
62- const response: Kernel .AppDeployResponse = await client .apps .deploy (params );
57+ const params: Kernel .BrowserCreateParams = { invocation_id: ' REPLACE_ME' };
58+ const browser: Kernel .BrowserCreateResponse = await client .browsers .create (params );
6359}
6460
6561main ();
@@ -83,21 +79,30 @@ import Kernel, { toFile } from '@onkernel/sdk';
8379const client = new Kernel ();
8480
8581// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
86- await client .apps .deploy ({ entrypointRelPath: ' app.py' , file: fs .createReadStream (' /path/to/file' ) });
82+ await client .apps .deployments .create ({
83+ entrypoint_rel_path: ' src/app.py' ,
84+ file: fs .createReadStream (' /path/to/file' ),
85+ });
8786
8887// Or if you have the web `File` API you can pass a `File` instance:
89- await client .apps .deploy ({ entrypointRelPath: ' app.py' , file: new File ([' my bytes' ], ' file' ) });
88+ await client .apps .deployments .create ({
89+ entrypoint_rel_path: ' src/app.py' ,
90+ file: new File ([' my bytes' ], ' file' ),
91+ });
9092
9193// You can also pass a `fetch` `Response`:
92- await client .apps .deploy ({ entrypointRelPath: ' app.py' , file: await fetch (' https://somesite/file' ) });
94+ await client .apps .deployments .create ({
95+ entrypoint_rel_path: ' src/app.py' ,
96+ file: await fetch (' https://somesite/file' ),
97+ });
9398
9499// Finally, if none of the above are convenient, you can use our `toFile` helper:
95- await client .apps .deploy ({
96- entrypointRelPath : ' app.py' ,
100+ await client .apps .deployments . create ({
101+ entrypoint_rel_path : ' src/ app.py' ,
97102 file: await toFile (Buffer .from (' my bytes' ), ' file' ),
98103});
99- await client .apps .deploy ({
100- entrypointRelPath : ' app.py' ,
104+ await client .apps .deployments . create ({
105+ entrypoint_rel_path : ' src/ app.py' ,
101106 file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ),
102107});
103108```
@@ -111,17 +116,15 @@ a subclass of `APIError` will be thrown:
111116<!-- prettier-ignore -->
112117``` ts
113118async function main() {
114- const response = await client .apps
115- .deploy ({ entrypointRelPath: ' app.py' , file: fs .createReadStream (' path/to/file' ), version: ' REPLACE_ME' })
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- });
119+ const browser = await client .browsers .create ({ invocation_id: ' REPLACE_ME' }).catch (async (err ) => {
120+ if (err instanceof Kernel .APIError ) {
121+ console .log (err .status ); // 400
122+ console .log (err .name ); // BadRequestError
123+ console .log (err .headers ); // {server: 'nginx', ...}
124+ } else {
125+ throw err ;
126+ }
127+ });
125128}
126129
127130main ();
@@ -156,7 +159,7 @@ const client = new Kernel({
156159});
157160
158161// Or, configure per-request:
159- await client .apps . deploy ({ entrypointRelPath : ' app.py ' , file : fs . createReadStream ( ' path/to/file ' ), version : ' REPLACE_ME' }, {
162+ await client .browsers . create ({ invocation_id : ' REPLACE_ME' }, {
160163 maxRetries: 5 ,
161164});
162165```
@@ -173,7 +176,7 @@ const client = new Kernel({
173176});
174177
175178// Override per-request:
176- await client .apps . deploy ({ entrypointRelPath: ' app.py ' , file: fs . createReadStream ( ' path/to/file ' ), version : ' REPLACE_ME' }, {
179+ await client .browsers . create ({ invocation_id : ' REPLACE_ME' }, {
177180 timeout: 5 * 1000 ,
178181});
179182```
@@ -196,17 +199,15 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
196199``` ts
197200const client = new Kernel ();
198201
199- const response = await client .apps
200- .deploy ({ entrypointRelPath: ' app.py' , file: fs .createReadStream (' path/to/file' ), version: ' REPLACE_ME' })
201- .asResponse ();
202+ const response = await client .browsers .create ({ invocation_id: ' REPLACE_ME' }).asResponse ();
202203console .log (response .headers .get (' X-My-Header' ));
203204console .log (response .statusText ); // access the underlying Response object
204205
205- const { data : response , response : raw } = await client .apps
206- .deploy ({ entrypointRelPath: ' app.py ' , file: fs . createReadStream ( ' path/to/file ' ), version : ' REPLACE_ME' })
206+ const { data : browser , response : raw } = await client .browsers
207+ .create ({ invocation_id : ' REPLACE_ME' })
207208 .withResponse ();
208209console .log (raw .headers .get (' X-My-Header' ));
209- console .log (response . apps );
210+ console .log (browser . session_id );
210211```
211212
212213### Logging
0 commit comments