-
Notifications
You must be signed in to change notification settings - Fork 0
feat: axon list with pagination and api-client upgrade #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0289acc
chore(deps): upgrade @runloop/api-client to 1.14.1
cursoragent 8cd9b0d
feat(axon): add list command with cursor pagination
cursoragent 5b4718d
style: format axon list and commands registration
cursoragent 6e13d50
docs: update command structure for axon list
cursoragent 03274f3
refactor: address PR feedback on axon list and tunnel host
cursoragent c9170e2
test: fix ResourcePicker flakiness from restoreMocks and slow CI
cursoragent fe26836
chore(deps): bump @runloop/api-client to 1.16.0
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * List active axons (beta) | ||
| */ | ||
|
|
||
| import chalk from "chalk"; | ||
| import { formatTimeAgo } from "../../components/ResourceListView.js"; | ||
| import { listActiveAxons, type Axon } from "../../services/axonService.js"; | ||
| import { output, outputError, parseLimit } from "../../utils/output.js"; | ||
|
|
||
| interface ListOptions { | ||
| limit?: string; | ||
| startingAfter?: string; | ||
| output?: string; | ||
| } | ||
|
|
||
| const PAGE_SIZE = 100; | ||
|
|
||
| function printTable(axons: Axon[]): void { | ||
| if (axons.length === 0) { | ||
| console.log(chalk.dim("No active axons found")); | ||
| return; | ||
| } | ||
|
|
||
| const COL_ID = 34; | ||
| const COL_NAME = 28; | ||
| const COL_CREATED = 12; | ||
|
|
||
| const header = | ||
| "ID".padEnd(COL_ID) + | ||
| " " + | ||
| "NAME".padEnd(COL_NAME) + | ||
| " " + | ||
| "CREATED".padEnd(COL_CREATED); | ||
| console.log(chalk.bold(header)); | ||
| console.log(chalk.dim("─".repeat(header.length))); | ||
|
|
||
| for (const axon of axons) { | ||
| const id = | ||
| axon.id.length > COL_ID ? axon.id.slice(0, COL_ID - 1) + "…" : axon.id; | ||
| const nameRaw = axon.name ?? ""; | ||
| const name = | ||
| nameRaw.length > COL_NAME | ||
| ? nameRaw.slice(0, COL_NAME - 1) + "…" | ||
| : nameRaw; | ||
| const created = formatTimeAgo(axon.created_at_ms); | ||
| console.log( | ||
| `${id.padEnd(COL_ID)} ${name.padEnd(COL_NAME)} ${created.padEnd(COL_CREATED)}`, | ||
| ); | ||
| } | ||
|
|
||
| console.log(); | ||
| console.log( | ||
| chalk.dim(`${axons.length} axon${axons.length !== 1 ? "s" : ""}`), | ||
| ); | ||
| } | ||
|
|
||
| export async function listAxonsCommand(options: ListOptions): Promise<void> { | ||
| try { | ||
| const maxResults = parseLimit(options.limit); | ||
| const format = options.output || "text"; | ||
|
|
||
| let axons: Axon[]; | ||
|
|
||
| if (options.startingAfter) { | ||
| const pageLimit = maxResults === Infinity ? PAGE_SIZE : maxResults; | ||
| const { axons: page, hasMore } = await listActiveAxons({ | ||
| limit: pageLimit, | ||
| startingAfter: options.startingAfter, | ||
| }); | ||
| axons = page; | ||
| if (format === "text" && hasMore && axons.length > 0) { | ||
| console.log( | ||
| chalk.dim( | ||
| "More results may be available; use --starting-after with the last ID to continue.", | ||
| ), | ||
| ); | ||
| console.log(); | ||
| } | ||
| } else { | ||
| const all: Axon[] = []; | ||
| let cursor: string | undefined; | ||
| while (all.length < maxResults) { | ||
| const remaining = maxResults - all.length; | ||
| const pageLimit = Math.min(PAGE_SIZE, remaining); | ||
| const { axons: page, hasMore } = await listActiveAxons({ | ||
| limit: pageLimit, | ||
| startingAfter: cursor, | ||
| }); | ||
| all.push(...page); | ||
| if (!hasMore || page.length === 0) { | ||
| break; | ||
| } | ||
| cursor = page[page.length - 1].id; | ||
| } | ||
| axons = all; | ||
| } | ||
|
|
||
| if (format !== "text") { | ||
| output(axons, { format, defaultFormat: "json" }); | ||
| } else { | ||
| printTable(axons); | ||
| } | ||
| } catch (error) { | ||
| outputError("Failed to list active axons", error); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * Axon service — active axons listing (beta API) | ||
| */ | ||
| import { getClient } from "../utils/client.js"; | ||
| import type { AxonView } from "@runloop/api-client/resources/axons/axons"; | ||
| import type { AxonsCursorIDPage } from "@runloop/api-client/pagination"; | ||
|
|
||
| export type Axon = AxonView; | ||
|
|
||
| export interface ListActiveAxonsOptions { | ||
| limit?: number; | ||
| startingAfter?: string; | ||
| } | ||
|
|
||
| export interface ListActiveAxonsResult { | ||
| axons: Axon[]; | ||
| hasMore: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * List active axons with optional cursor pagination (`limit`, `starting_after`). | ||
| */ | ||
| export async function listActiveAxons( | ||
| options: ListActiveAxonsOptions, | ||
| ): Promise<ListActiveAxonsResult> { | ||
| const client = getClient(); | ||
|
|
||
| const query: { | ||
| limit?: number; | ||
| starting_after?: string; | ||
| } = {}; | ||
| if (options.limit !== undefined) { | ||
| query.limit = options.limit; | ||
| } | ||
| if (options.startingAfter) { | ||
| query.starting_after = options.startingAfter; | ||
| } | ||
|
|
||
| const page = (await client.axons.list( | ||
| Object.keys(query).length > 0 ? query : undefined, | ||
| )) as AxonsCursorIDPage<AxonView>; | ||
|
|
||
| const axons = page.axons || []; | ||
| const hasMore = page.has_more || false; | ||
|
|
||
| return { axons, hasMore }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.