Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
import type { BlueprintListParams } from './resources/blueprints';
import type { ObjectCreateParams, ObjectListParams } from './resources/objects';
import type { AgentCreateParams, AgentListParams } from './resources/agents';
import type { AxonCreateParams } from './resources/axons';
import type { AxonCreateParams, AxonListParams } from './resources/axons/axons';
import type { ScorerCreateParams, ScorerListParams } from './resources/scenarios/scorers';
import type { NetworkPolicyCreateParams, NetworkPolicyListParams } from './resources/network-policies';
import type { GatewayConfigCreateParams, GatewayConfigListParams } from './resources/gateway-configs';
Expand Down Expand Up @@ -1565,12 +1565,24 @@ export class AxonOps {
/**
* [Beta] List all active axons.
*
* @example
* ```typescript
* const runloop = new RunloopSDK();
* const axons = await runloop.axon.list({ limit: 10 });
* console.log(axons.map((a) => a.id));
* ```
*
* @param {AxonListParams} [params] - Optional filter/pagination parameters.
* @param {Core.RequestOptions} [options] - Request options.
* @returns {Promise<Axon[]>} An array of {@link Axon} instances.
*/
async list(options?: Core.RequestOptions): Promise<Axon[]> {
const result = await this.client.axons.list(options);
return result.axons.map((axon) => Axon.fromId(this.client, axon.id));
async list(params?: AxonListParams, options?: Core.RequestOptions): Promise<Axon[]> {
const result = await this.client.axons.list(params, options);
const axons: Axon[] = [];
for await (const axon of result) {
axons.push(Axon.fromId(this.client, axon.id));
}
return axons;
}
}

Expand Down
42 changes: 28 additions & 14 deletions tests/sdk/axon-ops.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxonOps } from '../../src/sdk';
import { Axon } from '../../src/sdk/axon';
import type { AxonView, AxonListView } from '../../src/resources/axons';
import type { AxonView } from '../../src/resources/axons';

jest.mock('../../src/sdk/axon');

Expand Down Expand Up @@ -77,19 +77,25 @@ describe('AxonOps', () => {
});

describe('list', () => {
it('should list axons and wrap as Axon instances', async () => {
const mockListView: AxonListView = {
axons: [
{ id: 'axn_1', created_at_ms: Date.now(), name: 'axon-1' },
{ id: 'axn_2', created_at_ms: Date.now(), name: 'axon-2' },
{ id: 'axn_3', created_at_ms: Date.now() },
],
function mockPageResult(items: AxonView[]) {
return {
[Symbol.asyncIterator]: async function* () {
yield* items;
},
};
mockClient.axons.list.mockResolvedValue(mockListView);
}

it('should list axons and wrap as Axon instances', async () => {
const mockAxons: AxonView[] = [
{ id: 'axn_1', created_at_ms: Date.now(), name: 'axon-1' },
{ id: 'axn_2', created_at_ms: Date.now(), name: 'axon-2' },
{ id: 'axn_3', created_at_ms: Date.now() },
];
mockClient.axons.list.mockResolvedValue(mockPageResult(mockAxons));

const axons = await axonOps.list();

expect(mockClient.axons.list).toHaveBeenCalledWith(undefined);
expect(mockClient.axons.list).toHaveBeenCalledWith(undefined, undefined);
expect(Axon.fromId).toHaveBeenCalledTimes(3);
expect(Axon.fromId).toHaveBeenCalledWith(mockClient, 'axn_1');
expect(Axon.fromId).toHaveBeenCalledWith(mockClient, 'axn_2');
Expand All @@ -98,19 +104,27 @@ describe('AxonOps', () => {
});

it('should return empty array when no axons exist', async () => {
mockClient.axons.list.mockResolvedValue({ axons: [] });
mockClient.axons.list.mockResolvedValue(mockPageResult([]));

const axons = await axonOps.list();

expect(axons).toHaveLength(0);
});

it('should pass filter params', async () => {
mockClient.axons.list.mockResolvedValue(mockPageResult([]));

await axonOps.list({ name: 'my-axon', limit: 10 });

expect(mockClient.axons.list).toHaveBeenCalledWith({ name: 'my-axon', limit: 10 }, undefined);
});

it('should pass request options', async () => {
mockClient.axons.list.mockResolvedValue({ axons: [] });
mockClient.axons.list.mockResolvedValue(mockPageResult([]));

await axonOps.list({ timeout: 3000 });
await axonOps.list(undefined, { timeout: 3000 });

expect(mockClient.axons.list).toHaveBeenCalledWith({ timeout: 3000 });
expect(mockClient.axons.list).toHaveBeenCalledWith(undefined, { timeout: 3000 });
});
});
});
Loading