fix: 使用稳定利润账号分页令牌

This commit is contained in:
Codex
2026-07-14 17:42:55 +02:00
parent d57d69609c
commit f29c5bf4bf
4 changed files with 17 additions and 8 deletions
@@ -97,12 +97,12 @@ function renderProfitHelp(defaultWindow: string): RenderedCliResult {
renderedText: [
"SUB2API CODEX-POOL PROFIT",
"Usage:",
" bun scripts/cli.ts platform-infra sub2api codex-pool profit [--since 24h] [--target PK01] [--accounts [--page-token <account-id>]|--missing-costs] [--json]",
" bun scripts/cli.ts platform-infra sub2api codex-pool profit [--since 24h] [--target PK01] [--accounts [--page-token <token>]|--missing-costs] [--json]",
"Options:",
` --since <duration> Native usage window; YAML default is ${defaultWindow}.`,
" --target <id>",
" --accounts Include one fixed-size account page with complete names and IDs.",
" --page-token <id> Continue after the account ID returned by the previous page.",
" --page-token <token> Continue from the opaque token returned by the previous account page.",
" --missing-costs Include the missing-cost account list and API USD bases.",
" --json Emit exact structured values.",
"Notes:",
@@ -207,13 +207,13 @@ function projectProfitReport(report: Record<string, unknown> | null, options: Pr
if (!options.accounts) return compactReport;
let startIndex = 0;
if (options.pageToken !== null) {
const tokenIndex = accounts.findIndex((row) => text(row.accountId) === options.pageToken);
const tokenIndex = accounts.findIndex((row) => encodeProfitAccountPageToken(row) === options.pageToken);
if (tokenIndex < 0) throw new Error(`profit account page token not found: ${options.pageToken}`);
startIndex = tokenIndex + 1;
}
const pageAccounts = accounts.slice(startIndex, startIndex + PROFIT_ACCOUNT_PAGE_SIZE);
const hasNext = startIndex + pageAccounts.length < accounts.length;
const nextPageToken = hasNext ? text(pageAccounts.at(-1)?.accountId) : null;
const nextPageToken = hasNext && pageAccounts.length > 0 ? encodeProfitAccountPageToken(pageAccounts.at(-1)!) : null;
return {
...compactReport,
accounts: pageAccounts,
@@ -225,6 +225,15 @@ function projectProfitReport(report: Record<string, unknown> | null, options: Pr
};
}
function encodeProfitAccountPageToken(account: Record<string, unknown>): string {
return Buffer.from(JSON.stringify([
account.class ?? null,
account.groupId ?? null,
account.accountId ?? null,
account.accountName ?? null,
]), "utf8").toString("base64url");
}
function renderProfitJson(response: Record<string, unknown>): RenderedCliResult {
return {
ok: response.ok === true,
@@ -374,7 +374,7 @@ export function codexPoolHelp(): unknown {
"bun scripts/cli.ts platform-infra sub2api codex-pool runtime get --account <name-or-id> [--target PK01] [--json|--full|--raw]",
"bun scripts/cli.ts platform-infra sub2api codex-pool runtime errors [--group <name-or-id>|--all-groups] [--platform <name>] [--page-token <group-id>] [--account <name-or-id>] [--since 24h] [--tail 50000] [--target PK01] [--json|--full|--raw]",
"bun scripts/cli.ts platform-infra sub2api codex-pool faults [--level P0|P1|P2] [--group <name-or-id>] [--account <name-or-id>] [--model <model>] [--stream sync|stream] [--endpoint <path>] [--request-id <id>] [--page-token <token>] [--target PK01] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool profit [--since 24h] [--target PK01] [--accounts [--page-token <account-id>]|--missing-costs] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool profit [--since 24h] [--target PK01] [--accounts [--page-token <token>]|--missing-costs] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool runtime apply --account <name-or-id> --template <id> [--target PK01] [--confirm]",
"bun scripts/cli.ts platform-infra sub2api codex-pool runtime apply --accounts <name-or-id,...> --template <id> [--target PK01] [--confirm] [--full|--raw]",
"bun scripts/cli.ts platform-infra sub2api codex-pool runtime delete --account <name-or-id> --kind temp-unschedulable [--target PK01] [--confirm]",
+2 -2
View File
@@ -424,7 +424,7 @@ export function platformInfraHelp(): unknown {
"bun scripts/cli.ts platform-infra sub2api codex-pool validate",
"bun scripts/cli.ts platform-infra sub2api codex-pool trace --request-id <requestId>",
"bun scripts/cli.ts platform-infra sub2api codex-pool feedback --user <email-or-id> [--window 30m] [--page-token <token>|--request-id <client-or-internal-id>] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool profit [--since 24h] [--target PK01] [--accounts [--page-token <account-id>]|--missing-costs] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool profit [--since 24h] [--target PK01] [--accounts [--page-token <token>]|--missing-costs] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool sentinel-image status",
"bun scripts/cli.ts platform-infra sub2api codex-pool sentinel-probe --account unidesk-codex-hy --confirm",
"bun scripts/cli.ts platform-infra sub2rank plan [--target NC01]",
@@ -508,7 +508,7 @@ export function platformInfraHelp(): unknown {
"bun scripts/cli.ts platform-infra sub2api codex-pool validate",
"bun scripts/cli.ts platform-infra sub2api codex-pool trace --request-id <requestId>",
"bun scripts/cli.ts platform-infra sub2api codex-pool feedback --user <email-or-id> [--window 30m] [--page-token <token>|--request-id <client-or-internal-id>] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool profit [--since 24h] [--target PK01] [--accounts [--page-token <account-id>]|--missing-costs] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool profit [--since 24h] [--target PK01] [--accounts [--page-token <token>]|--missing-costs] [--json]",
"bun scripts/cli.ts platform-infra sub2api codex-pool sentinel-image status",
],
module: "scripts/src/platform-infra-sub2api-codex.ts",