Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 把 SuperGrok 预付余额从美分换成美元

Kafeifei269ae43b71bf
diff --git a/apps/desktop/src/shared/__tests__/xaiSubscriptionUsage.test.ts b/apps/desktop/src/shared/__tests__/xaiSubscriptionUsage.test.ts
index 73fc54939b..447c7d48d0 100644
--- a/apps/desktop/src/shared/__tests__/xaiSubscriptionUsage.test.ts
+++ b/apps/desktop/src/shared/__tests__/xaiSubscriptionUsage.test.ts
@@ -62,6 +62,16 @@ describe('parseXaiBillingCreditsConfig', () => {
expect(parsed?.creditUsagePercent).toBe(40);
});
+ it('converts prepaidBalance.val from cents into dollars', () => {
+ const parsed = parseXaiBillingCreditsConfig({
+ config: {
+ creditUsagePercent: 28,
+ prepaidBalance: { val: 3741 },
+ },
+ });
+ expect(parsed?.prepaidBalance).toBe(37.41);
+ });
+
it('returns null when neither percent nor reset exists', () => {
expect(parseXaiBillingCreditsConfig({ config: { prepaidBalance: { val: 0 } } })).toBeNull();
expect(parseXaiBillingCreditsConfig(null)).toBeNull();
diff --git a/apps/desktop/src/shared/xaiSubscriptionUsage.ts b/apps/desktop/src/shared/xaiSubscriptionUsage.ts
index a50225f6a2..6c66c94676 100644
--- a/apps/desktop/src/shared/xaiSubscriptionUsage.ts
+++ b/apps/desktop/src/shared/xaiSubscriptionUsage.ts
@@ -56,6 +56,13 @@ function unwrapVal(v: unknown): unknown {
return v;
}
+/** grok.com 把 prepaidBalance.val 记成 prepaidBalanceCents,单位是美分。 */
+function prepaidBalanceUsd(raw: unknown): number | null {
+ const cents = toFiniteNumber(unwrapVal(raw));
+ if (cents === null) return null;
+ return cents / 100;
+}
+
/** settings JSON → 套餐名。没有 subscription_tier_display 则 null。 */
export function parseXaiSettingsPlanLabel(data: unknown): string | null {
if (!isPlainObject(data)) return null;
@@ -134,7 +141,7 @@ export function parseXaiBillingCreditsConfig(
weeklyResetsAt
?? toXaiUsageEpochSeconds(period?.end)
?? toXaiUsageEpochSeconds(config.billingPeriodEnd);
- const prepaidBalance = toFiniteNumber(unwrapVal(config.prepaidBalance));
+ const prepaidBalance = prepaidBalanceUsd(config.prepaidBalance);
if (creditUsagePercent === null && resetsAt === null) return null;
return {
creditUsagePercent: inferXaiWeeklyUsagePercent(
diff --git a/packages/maker-shared/src/subscriptionUsage.ts b/packages/maker-shared/src/subscriptionUsage.ts
index eb9bdd549c..85e7b7e33e 100644
--- a/packages/maker-shared/src/subscriptionUsage.ts
+++ b/packages/maker-shared/src/subscriptionUsage.ts
@@ -148,7 +148,8 @@ export interface XaiSubscriptionUsageSnapshot {
/** 分产品已用百分比。 */
productUsage?: XaiProductUsage[];
/**
- * 额外使用点数余额。单位按 grok.com 页面为美元;0 / 缺失不要当「免费额度」展示。
+ * 额外预付余额,美元。接口 prepaidBalance.val 是美分,解析时已除以 100。
+ * 0 / 缺失不要当「免费额度」展示。
*/
prepaidBalance?: number | null;
source?: 'cli-billing' | string | null;