Skip to content

Commit fea86dc

Browse files
committed
Merge branch 'main' into feat/bilingual-quick-start-examples
2 parents 06210a4 + 6e3fdea commit fea86dc

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
@@ -119,12 +119,7 @@ export default defineCommand({
119119
}
120120
}
121121

122-
const [quotaResult, stopResult] = await Promise.all([
123-
ctx.client.console(FREE_TIER_API, requestData),
124-
ctx.client.console(FREE_TIER_ONLY_STATUS_API, {
125-
queryFreeTierOnlyStatusRequest: { models },
126-
}),
127-
]);
122+
const quotaResult = await ctx.client.console(FREE_TIER_API, requestData);
128123

129124
const allQuotas = extractQuotas(quotaResult);
130125
let quotas = modelFlag
@@ -152,7 +147,16 @@ export default defineCommand({
152147
);
153148
}
154149

155-
const stopStatuses = extractFreeTierOnlyStatuses(stopResult);
150+
// Query auto-stop status only for the filtered models (the full catalog can
151+
// exceed the status API's batch limit and trigger a server-side error).
152+
const filteredModels = quotas.map((quota) => quota.model);
153+
const stopResult = filteredModels.length
154+
? await ctx.client.console(FREE_TIER_ONLY_STATUS_API, {
155+
queryFreeTierOnlyStatusRequest: { models: filteredModels },
156+
})
157+
: null;
158+
159+
const stopStatuses = stopResult ? extractFreeTierOnlyStatuses(stopResult) : [];
156160
const stopMap = new Map(stopStatuses.map((status) => [status.model, status.freeTierOnly]));
157161

158162
if (format === "json") {
@@ -161,12 +165,12 @@ export default defineCommand({
161165
const used = hasQuota ? quota.quotaInitTotal - quota.quotaTotal : 0;
162166
const stopStatus = stopMap.get(quota.model);
163167
const autoStop =
164-
quota.quotaStatus === "UNKNOWN"
165-
? "unsupported"
166-
: stopStatus === true
167-
? true
168-
: stopStatus === false
169-
? false
168+
stopStatus === true
169+
? true
170+
: stopStatus === false
171+
? false
172+
: quota.quotaStatus === "UNKNOWN"
173+
? "unsupported"
170174
: null;
171175
return {
172176
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";
@@ -101,15 +99,9 @@ export default defineCommand({
10199
}
102100

103101
if (off) {
104-
const [quotaResult, stopResult] = await Promise.all([
105-
ctx.client.console(FREE_TIER_API, { queryFreeTierQuotaRequest: { models } }),
106-
ctx.client.console(FREE_TIER_ONLY_STATUS_API, {
107-
queryFreeTierOnlyStatusRequest: { models },
108-
}),
109-
]);
110-
111-
const quotas = extractQuotas(quotaResult);
112-
const quotaMap = new Map(quotas.map((quota) => [quota.model, quota]));
102+
const stopResult = await ctx.client.console(FREE_TIER_ONLY_STATUS_API, {
103+
queryFreeTierOnlyStatusRequest: { models },
104+
});
113105

114106
const stopStatuses = extractFreeTierOnlyStatuses(stopResult);
115107
const stopMap = new Map(stopStatuses.map((status) => [status.model, status.freeTierOnly]));
@@ -119,13 +111,6 @@ export default defineCommand({
119111
process.stderr.write(`Auto-stop is already disabled for "${name}".\n`);
120112
continue;
121113
}
122-
const quota = quotaMap.get(name);
123-
if (quota && quota.quotaTotal > 0 && stopMap.get(name) === true) {
124-
process.stderr.write(
125-
`Cannot disable auto-stop for "${name}": free-tier quota has not been fully consumed. Please disable auto-stop after the quota is exhausted.\n`,
126-
);
127-
continue;
128-
}
129114
await pollFreeTierBatch(ctx.client, api, requestKey, [name]);
130115
process.stdout.write(`Disabled auto-stop for "${name}".\n`);
131116
}

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)