Skip to content

Commit e782319

Browse files
chore(axon): add axon auto-pagination to stainless sdks (#8420)
1 parent 674d8f2 commit e782319

7 files changed

Lines changed: 102 additions & 17 deletions

File tree

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 124
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/runloop-ai%2Frunloop-f32de1991bef7651f9b0970b503e2986c7a88708c4a408d54abe6d089795e9f9.yml
33
openapi_spec_hash: d2005d48f75fba4a5368209cf49641dc
4-
config_hash: a759c23a5a04ad26f8740acc7e094c01
4+
config_hash: 5ffcc19219880e7d9ce43c1e6860568c

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Methods:
9292

9393
- <code title="post /v1/axons">client.axons.<a href="./src/resources/axons/axons.ts">create</a>({ ...params }) -> AxonView</code>
9494
- <code title="get /v1/axons/{id}">client.axons.<a href="./src/resources/axons/axons.ts">retrieve</a>(id) -> AxonView</code>
95-
- <code title="get /v1/axons">client.axons.<a href="./src/resources/axons/axons.ts">list</a>({ ...params }) -> AxonListView</code>
95+
- <code title="get /v1/axons">client.axons.<a href="./src/resources/axons/axons.ts">list</a>({ ...params }) -> AxonViewsAxonsCursorIDPage</code>
9696
- <code title="post /v1/axons/{id}/publish">client.axons.<a href="./src/resources/axons/axons.ts">publish</a>(id, { ...params }) -> PublishResultView</code>
9797
- <code title="get /v1/axons/{id}/subscribe/sse">client.axons.<a href="./src/resources/axons/axons.ts">subscribeSse</a>(id) -> AxonEventView</code>
9898

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import * as Pagination from './pagination';
77
import {
88
type AgentsCursorIDPageParams,
99
AgentsCursorIDPageResponse,
10+
type AxonsCursorIDPageParams,
11+
AxonsCursorIDPageResponse,
1012
type BenchmarkRunsCursorIDPageParams,
1113
BenchmarkRunsCursorIDPageResponse,
1214
type BenchmarksCursorIDPageParams,
@@ -180,6 +182,7 @@ import {
180182
AxonListView,
181183
AxonPublishParams,
182184
AxonView,
185+
AxonViewsAxonsCursorIDPage,
183186
Axons,
184187
PublishParams,
185188
PublishResultView,
@@ -436,6 +439,7 @@ Runloop.BenchmarkJobs = BenchmarkJobs;
436439
Runloop.Agents = Agents;
437440
Runloop.AgentViewsAgentsCursorIDPage = AgentViewsAgentsCursorIDPage;
438441
Runloop.Axons = Axons;
442+
Runloop.AxonViewsAxonsCursorIDPage = AxonViewsAxonsCursorIDPage;
439443
Runloop.Blueprints = Blueprints;
440444
Runloop.BlueprintViewsBlueprintsCursorIDPage = BlueprintViewsBlueprintsCursorIDPage;
441445
Runloop.Devboxes = Devboxes;
@@ -494,6 +498,12 @@ export declare namespace Runloop {
494498
type AgentsCursorIDPageResponse as AgentsCursorIDPageResponse,
495499
};
496500

501+
export import AxonsCursorIDPage = Pagination.AxonsCursorIDPage;
502+
export {
503+
type AxonsCursorIDPageParams as AxonsCursorIDPageParams,
504+
type AxonsCursorIDPageResponse as AxonsCursorIDPageResponse,
505+
};
506+
497507
export import BenchmarkRunsCursorIDPage = Pagination.BenchmarkRunsCursorIDPage;
498508
export {
499509
type BenchmarkRunsCursorIDPageParams as BenchmarkRunsCursorIDPageParams,
@@ -596,6 +606,7 @@ export declare namespace Runloop {
596606
type AxonView as AxonView,
597607
type PublishParams as PublishParams,
598608
type PublishResultView as PublishResultView,
609+
AxonViewsAxonsCursorIDPage as AxonViewsAxonsCursorIDPage,
599610
type AxonListParams as AxonListParams,
600611
type AxonPublishParams as AxonPublishParams,
601612
};

src/pagination.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,80 @@ export class AgentsCursorIDPage<Item extends { id: string }>
446446
}
447447
}
448448

449+
export interface AxonsCursorIDPageResponse<Item> {
450+
axons: Array<Item>;
451+
452+
has_more: boolean;
453+
454+
total_count: number;
455+
}
456+
457+
export interface AxonsCursorIDPageParams {
458+
starting_after?: string;
459+
460+
limit?: number;
461+
}
462+
463+
export class AxonsCursorIDPage<Item extends { id: string }>
464+
extends AbstractPage<Item>
465+
implements AxonsCursorIDPageResponse<Item>
466+
{
467+
axons: Array<Item>;
468+
469+
has_more: boolean;
470+
471+
total_count: number;
472+
473+
constructor(
474+
client: APIClient,
475+
response: Response,
476+
body: AxonsCursorIDPageResponse<Item>,
477+
options: FinalRequestOptions,
478+
) {
479+
super(client, response, body, options);
480+
481+
this.axons = body.axons || [];
482+
this.has_more = body.has_more || false;
483+
this.total_count = body.total_count || 0;
484+
}
485+
486+
getPaginatedItems(): Item[] {
487+
return this.axons ?? [];
488+
}
489+
490+
override hasNextPage(): boolean {
491+
if (this.has_more === false) {
492+
return false;
493+
}
494+
495+
return super.hasNextPage();
496+
}
497+
498+
// @deprecated Please use `nextPageInfo()` instead
499+
nextPageParams(): Partial<AxonsCursorIDPageParams> | null {
500+
const info = this.nextPageInfo();
501+
if (!info) return null;
502+
if ('params' in info) return info.params;
503+
const params = Object.fromEntries(info.url.searchParams);
504+
if (!Object.keys(params).length) return null;
505+
return params;
506+
}
507+
508+
nextPageInfo(): PageInfo | null {
509+
const axons = this.getPaginatedItems();
510+
if (!axons.length) {
511+
return null;
512+
}
513+
514+
const id = axons[axons.length - 1]?.id;
515+
if (!id) {
516+
return null;
517+
}
518+
519+
return { params: { starting_after: id } };
520+
}
521+
}
522+
449523
export interface BenchmarkRunsCursorIDPageResponse<Item> {
450524
runs: Array<Item>;
451525

src/resources/axons/axons.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
SqlStepErrorView,
1818
SqlStepResultView,
1919
} from './sql';
20+
import { AxonsCursorIDPage, type AxonsCursorIDPageParams } from '../../pagination';
2021
import { Stream } from '../../streaming';
2122

2223
export class Axons extends APIResource {
@@ -47,16 +48,19 @@ export class Axons extends APIResource {
4748
/**
4849
* [Beta] List all active axons.
4950
*/
50-
list(query?: AxonListParams, options?: Core.RequestOptions): Core.APIPromise<AxonListView>;
51-
list(options?: Core.RequestOptions): Core.APIPromise<AxonListView>;
51+
list(
52+
query?: AxonListParams,
53+
options?: Core.RequestOptions,
54+
): Core.PagePromise<AxonViewsAxonsCursorIDPage, AxonView>;
55+
list(options?: Core.RequestOptions): Core.PagePromise<AxonViewsAxonsCursorIDPage, AxonView>;
5256
list(
5357
query: AxonListParams | Core.RequestOptions = {},
5458
options?: Core.RequestOptions,
55-
): Core.APIPromise<AxonListView> {
59+
): Core.PagePromise<AxonViewsAxonsCursorIDPage, AxonView> {
5660
if (isRequestOptions(query)) {
5761
return this.list({}, query);
5862
}
59-
return this._client.get('/v1/axons', { query, ...options });
63+
return this._client.getAPIList('/v1/axons', AxonViewsAxonsCursorIDPage, { query, ...options });
6064
}
6165

6266
/**
@@ -88,6 +92,8 @@ export class Axons extends APIResource {
8892
}
8993
}
9094

95+
export class AxonViewsAxonsCursorIDPage extends AxonsCursorIDPage<AxonView> {}
96+
9197
export interface AxonCreateParams {
9298
/**
9399
* (Optional) Name for the axon.
@@ -201,7 +207,7 @@ export interface AxonCreateParams {
201207
name?: string | null;
202208
}
203209

204-
export interface AxonListParams {
210+
export interface AxonListParams extends AxonsCursorIDPageParams {
205211
/**
206212
* Filter by axon ID.
207213
*/
@@ -213,20 +219,10 @@ export interface AxonListParams {
213219
*/
214220
include_total_count?: boolean;
215221

216-
/**
217-
* The limit of items to return. Default is 20. Max is 5000.
218-
*/
219-
limit?: number;
220-
221222
/**
222223
* Filter by axon name (prefix match supported).
223224
*/
224225
name?: string;
225-
226-
/**
227-
* Load the next page of data starting after the item with the given ID.
228-
*/
229-
starting_after?: string;
230226
}
231227

232228
export interface AxonPublishParams {
@@ -251,6 +247,7 @@ export interface AxonPublishParams {
251247
source: string;
252248
}
253249

250+
Axons.AxonViewsAxonsCursorIDPage = AxonViewsAxonsCursorIDPage;
254251
Axons.Sql = Sql;
255252

256253
export declare namespace Axons {
@@ -261,6 +258,7 @@ export declare namespace Axons {
261258
type AxonView as AxonView,
262259
type PublishParams as PublishParams,
263260
type PublishResultView as PublishResultView,
261+
AxonViewsAxonsCursorIDPage as AxonViewsAxonsCursorIDPage,
264262
type AxonListParams as AxonListParams,
265263
type AxonPublishParams as AxonPublishParams,
266264
};

src/resources/axons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
export {
4+
AxonViewsAxonsCursorIDPage,
45
Axons,
56
type AxonCreateParams,
67
type AxonEventView,

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
type AgentListParams,
1212
} from './agents';
1313
export {
14+
AxonViewsAxonsCursorIDPage,
1415
Axons,
1516
type AxonCreateParams,
1617
type AxonEventView,

0 commit comments

Comments
 (0)