Skip to content

Commit af95a9e

Browse files
committed
fix(usage): allow disabling auto-stop regardless of quota and fix Auto-Stop column display
- Remove client-side check that blocked 'freetier --off' when quota remains; align with web behavior (switch is always operable) - Prioritize stopMap ON/OFF over quotaStatus UNKNOWN in rendering - Query auto-stop status only for filtered models to avoid server-side batch limit error (TRAIN_INTERNAL_ERROR_EXP with 494 models)
1 parent ad5c44d commit af95a9e

3 files changed

Lines changed: 26 additions & 37 deletions

File tree

packages/commands/src/commands/usage/free.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,7 @@ export default defineCommand({
104104
}
105105
}
106106

107-
const [quotaResult, stopResult] = await Promise.all([
108-
ctx.client.console(FREE_TIER_API, requestData),
109-
ctx.client.console(FREE_TIER_ONLY_STATUS_API, {
110-
queryFreeTierOnlyStatusRequest: { models },
111-
}),
112-
]);
107+
const quotaResult = await ctx.client.console(FREE_TIER_API, requestData);
113108

114109
const allQuotas = extractQuotas(quotaResult);
115110
let quotas = modelFlag
@@ -137,7 +132,16 @@ export default defineCommand({
137132
);
138133
}
139134

140-
const stopStatuses = extractFreeTierOnlyStatuses(stopResult);
135+
// Query auto-stop status only for the filtered models (the full catalog can
136+
// exceed the status API's batch limit and trigger a server-side error).
137+
const filteredModels = quotas.map((quota) => quota.model);
138+
const stopResult = filteredModels.length
139+
? await ctx.client.console(FREE_TIER_ONLY_STATUS_API, {
140+
queryFreeTierOnlyStatusRequest: { models: filteredModels },
141+
})
142+
: null;
143+
144+
const stopStatuses = stopResult ? extractFreeTierOnlyStatuses(stopResult) : [];
141145
const stopMap = new Map(stopStatuses.map((status) => [status.model, status.freeTierOnly]));
142146

143147
if (format === "json") {
@@ -146,12 +150,12 @@ export default defineCommand({
146150
const used = hasQuota ? quota.quotaInitTotal - quota.quotaTotal : 0;
147151
const stopStatus = stopMap.get(quota.model);
148152
const autoStop =
149-
quota.quotaStatus === "UNKNOWN"
150-
? "unsupported"
151-
: stopStatus === true
152-
? true
153-
: stopStatus === false
154-
? false
153+
stopStatus === true
154+
? true
155+
: stopStatus === false
156+
? false
157+
: quota.quotaStatus === "UNKNOWN"
158+
? "unsupported"
155159
: null;
156160
return {
157161
model: quota.model,

packages/commands/src/commands/usage/freetier.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { defineCommand, detectOutputFormat, unwrapResponse } from "bailian-cli-core";
22
import { emitResult } from "bailian-cli-runtime";
33
import {
4-
FREE_TIER_API,
54
FREE_TIER_ONLY_STATUS_API,
65
extractFreeTierOnlyStatuses,
7-
extractQuotas,
86
fetchAllModels,
97
pollFreeTierBatch,
108
} from "./shared.ts";
@@ -92,15 +90,9 @@ export default defineCommand({
9290
}
9391

9492
if (off) {
95-
const [quotaResult, stopResult] = await Promise.all([
96-
ctx.client.console(FREE_TIER_API, { queryFreeTierQuotaRequest: { models } }),
97-
ctx.client.console(FREE_TIER_ONLY_STATUS_API, {
98-
queryFreeTierOnlyStatusRequest: { models },
99-
}),
100-
]);
101-
102-
const quotas = extractQuotas(quotaResult);
103-
const quotaMap = new Map(quotas.map((quota) => [quota.model, quota]));
93+
const stopResult = await ctx.client.console(FREE_TIER_ONLY_STATUS_API, {
94+
queryFreeTierOnlyStatusRequest: { models },
95+
});
10496

10597
const stopStatuses = extractFreeTierOnlyStatuses(stopResult);
10698
const stopMap = new Map(stopStatuses.map((status) => [status.model, status.freeTierOnly]));
@@ -110,13 +102,6 @@ export default defineCommand({
110102
process.stderr.write(`Auto-stop is already disabled for "${name}".\n`);
111103
continue;
112104
}
113-
const quota = quotaMap.get(name);
114-
if (quota && quota.quotaTotal > 0 && stopMap.get(name) === true) {
115-
process.stderr.write(
116-
`Cannot disable auto-stop for "${name}": free-tier quota has not been fully consumed. Please disable auto-stop after the quota is exhausted.\n`,
117-
);
118-
continue;
119-
}
120105
await pollFreeTierBatch(ctx.client, api, requestKey, [name]);
121106
process.stdout.write(`Disabled auto-stop for "${name}".\n`);
122107
}

packages/commands/src/commands/usage/shared.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ export function printFreeTierTable(options: FreeTierTableOptions): void {
187187

188188
const stopStatus = stopMap.get(quota.model);
189189
const autoStop =
190-
quota.quotaStatus === "UNKNOWN"
191-
? "Unsupported"
192-
: stopStatus === true
193-
? "ON"
194-
: stopStatus === false
195-
? "OFF"
190+
stopStatus === true
191+
? "ON"
192+
: stopStatus === false
193+
? "OFF"
194+
: quota.quotaStatus === "UNKNOWN"
195+
? "Unsupported"
196196
: "-";
197197

198198
return [quota.model, typeMap.get(quota.model) || "-", remaining, total, "", autoStop];

0 commit comments

Comments
 (0)