Skip to content

Commit f1e0aaf

Browse files
docs: update code samples from OpenAPI
1 parent 57d38db commit f1e0aaf

10 files changed

+285
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const response = await client.browsers.fs.downloadDirZip('id', { path: '/J!' });
10+
11+
console.log(response);
12+
13+
const content = await response.blob();
14+
console.log(content);
15+
```
16+
17+
18+
```python Python
19+
from kernel import Kernel
20+
21+
client = Kernel(
22+
api_key="My API Key",
23+
)
24+
response = client.browsers.fs.download_dir_zip(
25+
id="id",
26+
path="/J!",
27+
)
28+
print(response)
29+
content = response.read()
30+
print(content)
31+
```
32+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const logEvent = await client.browsers.logs.stream('id', { source: 'path' });
10+
11+
console.log(logEvent.event);
12+
```
13+
14+
15+
```python Python
16+
from kernel import Kernel
17+
18+
client = Kernel(
19+
api_key="My API Key",
20+
)
21+
log_event = client.browsers.logs.stream(
22+
id="id",
23+
source="path",
24+
)
25+
print(log_event.event)
26+
```
27+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const response = await client.browsers.process.status('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { id: 'id' });
10+
11+
console.log(response.cpu_pct);
12+
```
13+
14+
15+
```python Python
16+
from kernel import Kernel
17+
18+
client = Kernel(
19+
api_key="My API Key",
20+
)
21+
response = client.browsers.process.status(
22+
process_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
23+
id="id",
24+
)
25+
print(response.cpu_pct)
26+
```
27+
</CodeGroup>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const response = await client.browsers.process.stdoutStream('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
10+
id: 'id',
11+
});
12+
13+
console.log(response.data_b64);
14+
```
15+
16+
17+
```python Python
18+
from kernel import Kernel
19+
20+
client = Kernel(
21+
api_key="My API Key",
22+
)
23+
response = client.browsers.process.stdout_stream(
24+
process_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
25+
id="id",
26+
)
27+
print(response.data_b64)
28+
```
29+
</CodeGroup>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
await client.browsers.fs.upload('id', {
10+
files: [{ dest_path: '/J!', file: fs.createReadStream('path/to/file') }],
11+
});
12+
```
13+
14+
15+
```python Python
16+
from kernel import Kernel
17+
18+
client = Kernel(
19+
api_key="My API Key",
20+
)
21+
client.browsers.fs.upload(
22+
id="id",
23+
files=[{
24+
"dest_path": "/J!",
25+
"file": b"raw file contents",
26+
}],
27+
)
28+
```
29+
</CodeGroup>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
await client.browsers.fs.uploadZip('id', { dest_path: '/J!', zip_file: fs.createReadStream('path/to/file') });
10+
```
11+
12+
13+
```python Python
14+
from kernel import Kernel
15+
16+
client = Kernel(
17+
api_key="My API Key",
18+
)
19+
client.browsers.fs.upload_zip(
20+
id="id",
21+
dest_path="/J!",
22+
zip_file=b"raw file contents",
23+
)
24+
```
25+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const response = await client.browsers.process.exec('id', { command: 'command' });
10+
11+
console.log(response.duration_ms);
12+
```
13+
14+
15+
```python Python
16+
from kernel import Kernel
17+
18+
client = Kernel(
19+
api_key="My API Key",
20+
)
21+
response = client.browsers.process.exec(
22+
id="id",
23+
command="command",
24+
)
25+
print(response.duration_ms)
26+
```
27+
</CodeGroup>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const response = await client.browsers.process.kill('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
10+
id: 'id',
11+
signal: 'TERM',
12+
});
13+
14+
console.log(response.ok);
15+
```
16+
17+
18+
```python Python
19+
from kernel import Kernel
20+
21+
client = Kernel(
22+
api_key="My API Key",
23+
)
24+
response = client.browsers.process.kill(
25+
process_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
26+
id="id",
27+
signal="TERM",
28+
)
29+
print(response.ok)
30+
```
31+
</CodeGroup>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const response = await client.browsers.process.stdin('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
10+
id: 'id',
11+
data_b64: 'data_b64',
12+
});
13+
14+
console.log(response.written_bytes);
15+
```
16+
17+
18+
```python Python
19+
from kernel import Kernel
20+
21+
client = Kernel(
22+
api_key="My API Key",
23+
)
24+
response = client.browsers.process.stdin(
25+
process_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
26+
id="id",
27+
data_b64="data_b64",
28+
)
29+
print(response.written_bytes)
30+
```
31+
</CodeGroup>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<CodeGroup>
2+
```typescript Typescript/Javascript
3+
import Kernel from '@onkernel/sdk';
4+
5+
const client = new Kernel({
6+
apiKey: 'My API Key',
7+
});
8+
9+
const response = await client.browsers.process.spawn('id', { command: 'command' });
10+
11+
console.log(response.pid);
12+
```
13+
14+
15+
```python Python
16+
from kernel import Kernel
17+
18+
client = Kernel(
19+
api_key="My API Key",
20+
)
21+
response = client.browsers.process.spawn(
22+
id="id",
23+
command="command",
24+
)
25+
print(response.pid)
26+
```
27+
</CodeGroup>

0 commit comments

Comments
 (0)