Skip to content

Commit aea51a8

Browse files
chore: break long lines in snippets into multiline
1 parent f2acb64 commit aea51a8

11 files changed

Lines changed: 188 additions & 33 deletions

File tree

README.md

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ The SDK provides object-oriented interfaces for all major Runloop resources:
6868

6969
The SDK is fully typed with comprehensive TypeScript definitions:
7070

71-
```typescript
72-
import { RunloopSDK, type DevboxView } from '@runloop/api-client';
73-
74-
const runloop = new RunloopSDK();
75-
const devbox: DevboxView = await runloop.devbox.create();
76-
```
77-
7871
### Scorers
7972

8073
Scorers are custom scoring functions used to evaluate scenario outputs. Create scorers via `runloop.scorer.create()`, then update or validate them with the returned `Scorer` instance:
@@ -141,8 +134,60 @@ const snapshot = await devbox.snapshotDisk();
141134
await snapshot.createDevbox();
142135
...
143136
await devbox.shutdown();
137+
144138
```
145139

140+
## File write
141+
142+
143+
// You can also pass a `fetch` `Response`:
144+
await client.devboxes.uploadFile('id', {
145+
path: 'path',
146+
file: await fetch('https://somesite/file'),
147+
});
148+
149+
// Finally, if none of the above are convenient, you can use our `toFile` helper:
150+
await client.devboxes.uploadFile('id', {
151+
path: 'path',
152+
file: await toFile(Buffer.from('my bytes'), 'file'),
153+
});
154+
await client.devboxes.uploadFile('id', {
155+
path: 'path',
156+
file: await toFile(new Uint8Array([0, 1, 2]), 'file'),
157+
});
158+
```
159+
160+
## Handling errors
161+
162+
When the library is unable to connect to the API,
163+
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
164+
a subclass of `APIError` will be thrown:
165+
166+
<!-- prettier-ignore -->
167+
```ts
168+
const devboxView = await client.devboxes.create().catch(async (err) => {
169+
if (err instanceof Runloop.APIError) {
170+
console.log(err.status); // 400
171+
console.log(err.name); // BadRequestError
172+
console.log(err.headers); // {server: 'nginx', ...}
173+
} else {
174+
throw err;
175+
}
176+
});
177+
```typescript
178+
import { RunloopSDK, type DevboxView } from '@runloop/api-client';
179+
180+
const runloop = new RunloopSDK();
181+
const devbox: DevboxView = await runloop.devbox.create();
182+
```
183+
184+
185+
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
186+
await client.devboxes.uploadFile('id', {
187+
path: 'path',
188+
file: fs.createReadStream('/path/to/file'),
189+
});
190+
146191
## Advanced Configuration
147192

148193
Customize the SDK with your API token, endpoint, timeout, and retry settings:

tests/api-resources/agents.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@ describe('resource agents', () => {
2626
version: 'version',
2727
source: {
2828
type: 'type',
29-
git: { repository: 'repository', agent_setup: ['string'], ref: 'ref' },
30-
npm: { package_name: 'package_name', agent_setup: ['string'], registry_url: 'registry_url' },
29+
git: {
30+
repository: 'repository',
31+
agent_setup: ['string'],
32+
ref: 'ref',
33+
},
34+
npm: {
35+
package_name: 'package_name',
36+
agent_setup: ['string'],
37+
registry_url: 'registry_url',
38+
},
3139
object: { object_id: 'object_id', agent_setup: ['string'] },
32-
pip: { package_name: 'package_name', agent_setup: ['string'], registry_url: 'registry_url' },
40+
pip: {
41+
package_name: 'package_name',
42+
agent_setup: ['string'],
43+
registry_url: 'registry_url',
44+
},
3345
},
3446
});
3547
});

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ describe('resource benchmarks', () => {
109109
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
110110
await expect(
111111
client.benchmarks.list(
112-
{ limit: 0, name: 'name', starting_after: 'starting_after' },
112+
{
113+
limit: 0,
114+
name: 'name',
115+
starting_after: 'starting_after',
116+
},
113117
{ path: '/_stainless_unknown_path' },
114118
),
115119
).rejects.toThrow(Runloop.NotFoundError);
@@ -203,7 +207,13 @@ describe('resource benchmarks', () => {
203207
resource_size_request: 'X_SMALL',
204208
user_parameters: { uid: 0, username: 'username' },
205209
},
206-
mounts: [{ object_id: 'object_id', object_path: 'object_path', type: 'object_mount' }],
210+
mounts: [
211+
{
212+
object_id: 'object_id',
213+
object_path: 'object_path',
214+
type: 'object_mount',
215+
},
216+
],
207217
purpose: 'purpose',
208218
secrets: { foo: 'string' },
209219
},

tests/api-resources/benchmarks/runs.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ describe('resource runs', () => {
4949
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
5050
await expect(
5151
client.benchmarks.runs.list(
52-
{ benchmark_id: 'benchmark_id', limit: 0, name: 'name', starting_after: 'starting_after' },
52+
{
53+
benchmark_id: 'benchmark_id',
54+
limit: 0,
55+
name: 'name',
56+
starting_after: 'starting_after',
57+
},
5358
{ path: '/_stainless_unknown_path' },
5459
),
5560
).rejects.toThrow(Runloop.NotFoundError);
@@ -114,7 +119,11 @@ describe('resource runs', () => {
114119
await expect(
115120
client.benchmarks.runs.listScenarioRuns(
116121
'id',
117-
{ limit: 0, starting_after: 'starting_after', state: 'running' },
122+
{
123+
limit: 0,
124+
starting_after: 'starting_after',
125+
state: 'running',
126+
},
118127
{ path: '/_stainless_unknown_path' },
119128
),
120129
).rejects.toThrow(Runloop.NotFoundError);

tests/api-resources/blueprints.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ describe('resource blueprints', () => {
131131
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
132132
await expect(
133133
client.blueprints.list(
134-
{ limit: 0, name: 'name', starting_after: 'starting_after', status: 'status' },
134+
{
135+
limit: 0,
136+
name: 'name',
137+
starting_after: 'starting_after',
138+
status: 'status',
139+
},
135140
{ path: '/_stainless_unknown_path' },
136141
),
137142
).rejects.toThrow(Runloop.NotFoundError);
@@ -215,7 +220,12 @@ describe('resource blueprints', () => {
215220
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
216221
await expect(
217222
client.blueprints.listPublic(
218-
{ limit: 0, name: 'name', starting_after: 'starting_after', status: 'status' },
223+
{
224+
limit: 0,
225+
name: 'name',
226+
starting_after: 'starting_after',
227+
status: 'status',
228+
},
219229
{ path: '/_stainless_unknown_path' },
220230
),
221231
).rejects.toThrow(Runloop.NotFoundError);

tests/api-resources/devboxes/computers.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ describe('resource computers', () => {
3131
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
3232
await expect(
3333
client.devboxes.computers.create(
34-
{ display_dimensions: { display_height_px: 0, display_width_px: 0 }, name: 'name' },
34+
{
35+
display_dimensions: { display_height_px: 0, display_width_px: 0 },
36+
name: 'name',
37+
},
3538
{ path: '/_stainless_unknown_path' },
3639
),
3740
).rejects.toThrow(Runloop.NotFoundError);

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ describe('resource devboxes', () => {
6060
user_parameters: { uid: 0, username: 'username' },
6161
},
6262
metadata: { foo: 'string' },
63-
mounts: [{ object_id: 'object_id', object_path: 'object_path', type: 'object_mount' }],
63+
mounts: [
64+
{
65+
object_id: 'object_id',
66+
object_path: 'object_path',
67+
type: 'object_mount',
68+
},
69+
],
6470
name: 'name',
6571
repo_connection_id: 'repo_connection_id',
6672
secrets: { foo: 'string' },
@@ -112,7 +118,10 @@ describe('resource devboxes', () => {
112118
await expect(
113119
client.devboxes.update(
114120
'id',
115-
{ metadata: { foo: 'string' }, name: 'name' },
121+
{
122+
metadata: { foo: 'string' },
123+
name: 'name',
124+
},
116125
{ path: '/_stainless_unknown_path' },
117126
),
118127
).rejects.toThrow(Runloop.NotFoundError);
@@ -140,7 +149,11 @@ describe('resource devboxes', () => {
140149
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
141150
await expect(
142151
client.devboxes.list(
143-
{ limit: 0, starting_after: 'starting_after', status: 'provisioning' },
152+
{
153+
limit: 0,
154+
starting_after: 'starting_after',
155+
status: 'provisioning',
156+
},
144157
{ path: '/_stainless_unknown_path' },
145158
),
146159
).rejects.toThrow(Runloop.NotFoundError);
@@ -403,7 +416,11 @@ describe('resource devboxes', () => {
403416
await expect(
404417
client.devboxes.snapshotDisk(
405418
'id',
406-
{ commit_message: 'commit_message', metadata: { foo: 'string' }, name: 'name' },
419+
{
420+
commit_message: 'commit_message',
421+
metadata: { foo: 'string' },
422+
name: 'name',
423+
},
407424
{ path: '/_stainless_unknown_path' },
408425
),
409426
).rejects.toThrow(Runloop.NotFoundError);
@@ -432,7 +449,11 @@ describe('resource devboxes', () => {
432449
await expect(
433450
client.devboxes.snapshotDiskAsync(
434451
'id',
435-
{ commit_message: 'commit_message', metadata: { foo: 'string' }, name: 'name' },
452+
{
453+
commit_message: 'commit_message',
454+
metadata: { foo: 'string' },
455+
name: 'name',
456+
},
436457
{ path: '/_stainless_unknown_path' },
437458
),
438459
).rejects.toThrow(Runloop.NotFoundError);

tests/api-resources/devboxes/disk-snapshots.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ describe('resource diskSnapshots', () => {
3232
await expect(
3333
client.devboxes.diskSnapshots.update(
3434
'id',
35-
{ commit_message: 'commit_message', metadata: { foo: 'string' }, name: 'name' },
35+
{
36+
commit_message: 'commit_message',
37+
metadata: { foo: 'string' },
38+
name: 'name',
39+
},
3640
{ path: '/_stainless_unknown_path' },
3741
),
3842
).rejects.toThrow(Runloop.NotFoundError);

tests/api-resources/repositories.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ describe('resource repositories', () => {
6969
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
7070
await expect(
7171
client.repositories.list(
72-
{ limit: 0, name: 'name', owner: 'owner', starting_after: 'starting_after' },
72+
{
73+
limit: 0,
74+
name: 'name',
75+
owner: 'owner',
76+
starting_after: 'starting_after',
77+
},
7378
{ path: '/_stainless_unknown_path' },
7479
),
7580
).rejects.toThrow(Runloop.NotFoundError);

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ describe('resource scenarios', () => {
1717
scoring_function_parameters: [
1818
{
1919
name: 'name',
20-
scorer: { pattern: 'pattern', search_directory: 'search_directory', type: 'ast_grep_scorer' },
20+
scorer: {
21+
pattern: 'pattern',
22+
search_directory: 'search_directory',
23+
type: 'ast_grep_scorer',
24+
},
2125
weight: 0,
2226
},
2327
],
@@ -34,7 +38,10 @@ describe('resource scenarios', () => {
3438

3539
test('create: required and optional params', async () => {
3640
const response = await client.scenarios.create({
37-
input_context: { problem_statement: 'problem_statement', additional_context: {} },
41+
input_context: {
42+
problem_statement: 'problem_statement',
43+
additional_context: {},
44+
},
3845
name: 'name',
3946
scoring_contract: {
4047
scoring_function_parameters: [
@@ -136,7 +143,10 @@ describe('resource scenarios', () => {
136143
snapshot_id: 'snapshot_id',
137144
working_directory: 'working_directory',
138145
},
139-
input_context: { additional_context: {}, problem_statement: 'problem_statement' },
146+
input_context: {
147+
additional_context: {},
148+
problem_statement: 'problem_statement',
149+
},
140150
metadata: { foo: 'string' },
141151
name: 'name',
142152
reference_output: 'reference_output',
@@ -219,7 +229,11 @@ describe('resource scenarios', () => {
219229
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
220230
await expect(
221231
client.scenarios.listPublic(
222-
{ limit: 0, name: 'name', starting_after: 'starting_after' },
232+
{
233+
limit: 0,
234+
name: 'name',
235+
starting_after: 'starting_after',
236+
},
223237
{ path: '/_stainless_unknown_path' },
224238
),
225239
).rejects.toThrow(Runloop.NotFoundError);
@@ -257,7 +271,13 @@ describe('resource scenarios', () => {
257271
resource_size_request: 'X_SMALL',
258272
user_parameters: { uid: 0, username: 'username' },
259273
},
260-
mounts: [{ object_id: 'object_id', object_path: 'object_path', type: 'object_mount' }],
274+
mounts: [
275+
{
276+
object_id: 'object_id',
277+
object_path: 'object_path',
278+
type: 'object_mount',
279+
},
280+
],
261281
purpose: 'purpose',
262282
secrets: { foo: 'string' },
263283
},

0 commit comments

Comments
 (0)