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(providers): 优化 MiMo 品牌展示与订阅提示 (#4881)

Dashd04e731f5106
diff --git a/apps/desktop/src/main/__tests__/makerEventHotPathOrdering.test.ts b/apps/desktop/src/main/__tests__/makerEventHotPathOrdering.test.ts
index 1d783ee476..b6ddecfe08 100644
--- a/apps/desktop/src/main/__tests__/makerEventHotPathOrdering.test.ts
+++ b/apps/desktop/src/main/__tests__/makerEventHotPathOrdering.test.ts
@@ -992,16 +992,13 @@ describe('maker:event hot path ordering', () => {
expect(claudeDoneSource).toContain('recordSessionTurnSpend(session.id, turnMoney);');
expect(claudeDoneSource).toContain('subscriptionEstimate ?? unpricedSubscriptionValueMarker()');
expect(claudeDoneSource).toContain('money: modelRowMoney,');
- // 订阅轮 (Claude Anthropic 订阅或 bridge 订阅直连) 打 #billing=subscription 标记,
+ // 订阅轮复用计费解析结果打 #billing=subscription 标记,
// 仪表盘按订阅估算价折算; 其余轮仍写归一化裸 id。
expect(claudeDoneSource).toMatch(
- /model:\s*isClaudeSubscriptionValueRow \|\| isBridgeSubscriptionRow\s*\?\s*claudeSubscriptionUsageModelKey\(m\.model\)\s*:\s*m\.model,/,
+ /model:\s*isSubscriptionValueRow\s*\?\s*claudeSubscriptionUsageModelKey\(m\.model\)\s*:\s*m\.model,/,
);
expect(claudeDoneSource).toContain(
- 'isClaudeSubscriptionSession && !m.money && isAnthropicModel(m.model)',
- );
- expect(claudeDoneSource).toContain(
- "m.source === 'subscription' && isSubscriptionDirectRoute(m.model)",
+ "const isSubscriptionValueRow = m.source === 'subscription'",
);
expect(claudeDoneSource).toContain('const subscriptionTurnEstimates: RegionalMoney[] = [];');
expect(claudeDoneSource).toMatch(
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
index 66537f42c1..5277313040 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts
@@ -1413,6 +1413,44 @@ describe('usage through the production event pipeline', () => {
await h.dispose();
});
+ it.each(['subscription', 'unpriced', 'api'] as const)(
+ 'records MiMo Claude Code usage using its billing route (%s)', async (mode) => {
+ const h = harness();
+ pricing(true);
+ effects.fn('getSessionProvider').mockReturnValue('mimo-account');
+ effects.fn('getActiveCatalog').mockReturnValue({ providers: [{
+ id: 'mimo-account', auth: { method: 'apiKey' },
+ access: { kind: mode === 'api' ? 'api' : 'subscription' },
+ }] });
+ if (mode === 'unpriced') {
+ effects.fn('getCodexProviderSubscriptionValuePrice').mockReturnValue(undefined);
+ effects.fn('getSubscriptionDirectValuePrice').mockReturnValue(undefined);
+ effects.fn('getModelPriceQuote').mockReturnValue(undefined);
+ }
+ h.emit(event('done', {
+ total_cost_usd: 2,
+ modelUsageCumulativeStartsAtZero: true,
+ modelUsage: { 'mimo-v2-pro': { inputTokens: 100, outputTokens: 20, costUSD: 2 } },
+ usageSegmentsComplete: true,
+ usageSegments: [{ ...segment, model: 'mimo-v2-pro', cacheReadTokens: 0 }],
+ }, { source: 'claude-code' }));
+ await microtasks();
+ expect(effects.fn('recordModelTurnUsage')).toHaveBeenCalledWith(expect.objectContaining({
+ model: mode === 'api' ? 'mimo-v2-pro' : 'mimo-v2-pro#billing=subscription',
+ inputTokensDelta: 100, outputTokensDelta: 20,
+ money: expect.objectContaining({ kind: mode === 'api' ? 'actual-cost' : 'value-estimate' }),
+ }));
+ expect(effects.fn('recordTurnSpend')).toHaveBeenCalledTimes(mode === 'api' ? 1 : 0);
+ expect(effects.fn('recordSessionTurnSpend')).toHaveBeenCalledTimes(mode === 'api' ? 1 : 0);
+ if (mode === 'subscription') {
+ expect(effects.fn('recordSchedulerTurnCost')).toHaveBeenCalledWith(expect.objectContaining({
+ money: expect.objectContaining({ kind: 'value-estimate', amount: expect.any(Number) }),
+ }));
+ }
+ await h.dispose();
+ },
+ );
+
it.each([[false, false], [true, false], [false, true], [true, true]])('keeps independent Claude subscription accounting out of actual spend (fallback=%s, deleted=%s)', async (fallback, deleted) => {
const h = harness();
pricing(true);
diff --git a/apps/desktop/src/main/maker-ipc/sessionClaudeTurnUsage.ts b/apps/desktop/src/main/maker-ipc/sessionClaudeTurnUsage.ts
index 814c64461f..c92fbdc861 100644
--- a/apps/desktop/src/main/maker-ipc/sessionClaudeTurnUsage.ts
+++ b/apps/desktop/src/main/maker-ipc/sessionClaudeTurnUsage.ts
@@ -7,7 +7,6 @@ import { readClaudeApiKey } from '../maker-host/auth-adapters.js';
import { recordSessionTurnSpend } from '../sessionSpendBroadcaster.js';
import { recordSchedulerTurnCost, recordTurnUsageOnMessage } from '../turnCostBroadcaster.js';
import { recordModelMismatchOnMessage } from '../modelMismatchBroadcaster.js';
-import { isClaudeSubscriptionProviderId } from '../maker-host/subscription-account-auth.js';
import { detectClaudeModelMismatch } from '../../shared/modelMismatch.js';
import { triggerClaudeAccountUsageRefresh } from '../usage/claudeAccountUsage.js';
import {
@@ -29,7 +28,6 @@ import {
billingRouteForExplicitProvider,
buildClaudeTurnUsageDetails,
computePriceQuoteTurnMoney,
- isAnthropicModel,
normalizeTurnUsageSegments,
normalizeModelIdForPricing,
resolveClaudeTurnCostSinks,
@@ -268,19 +266,15 @@ export function recordSessionClaudeTurnUsage(
}));
// 按模型记账 (首页仪表盘"按模型拆分"): 保留 provider/SKU 前缀,
// `codex/` 等预算路由必须精确命中自己的报价,不能回落到裸模型的另一折扣。
- // 订阅轮打 #billing=subscription 标记(Claude 订阅:Anthropic 模型 + cost=0),
- // 或 bridge 订阅轮(chatgpt// xai/ 前缀,source==='subscription');两类均需触发
- // rebroadcastTodaySpend 刷新首页仪表盘。
+ // 订阅分类复用计费解析结果,覆盖显式 Token Plan 与 bridge 订阅路由。
+ // 同一判据驱动估值、模型行标记与首页仪表盘刷新。
const modelUsageWrites: Promise<unknown>[] = [];
const subscriptionTurnEstimates: RegionalMoney[] = [];
let hasSubscriptionValueRow = false;
for (const m of perModel) {
- const isClaudeSubscriptionValueRow =
- isClaudeSubscriptionSession && !m.money && isAnthropicModel(m.model);
- const isBridgeSubscriptionRow =
- m.source === 'subscription' && isSubscriptionDirectRoute(m.model);
+ const isSubscriptionValueRow = m.source === 'subscription';
const subscriptionEstimate =
- isClaudeSubscriptionValueRow || isBridgeSubscriptionRow
+ isSubscriptionValueRow
? computePriceQuoteTurnMoney(
m.deltas,
(sessionProviderForBilling
@@ -293,19 +287,19 @@ export function recordSessionClaudeTurnUsage(
if (subscriptionEstimate?.amount) {
subscriptionTurnEstimates.push(subscriptionEstimate);
}
- if (isClaudeSubscriptionValueRow || isBridgeSubscriptionRow)
+ if (isSubscriptionValueRow)
hasSubscriptionValueRow = true;
const modelRowMoney =
m.money?.kind === 'actual-cost'
? m.money
- : isClaudeSubscriptionValueRow || isBridgeSubscriptionRow
+ : isSubscriptionValueRow
? (subscriptionEstimate ?? deps.unpricedSubscriptionValueMarker())
: null;
modelUsageWrites.push(
recordModelTurnUsage({
agentKind: 'claude-code',
model:
- isClaudeSubscriptionValueRow || isBridgeSubscriptionRow
+ isSubscriptionValueRow
? claudeSubscriptionUsageModelKey(m.model)
: m.model,
// The subscription suffix lets the existing schema reconstruct this amount as
diff --git a/apps/desktop/src/main/usage/__tests__/accountReferencePrice.test.ts b/apps/desktop/src/main/usage/__tests__/accountReferencePrice.test.ts
index fe2980419f..37955c9a6b 100644
--- a/apps/desktop/src/main/usage/__tests__/accountReferencePrice.test.ts
+++ b/apps/desktop/src/main/usage/__tests__/accountReferencePrice.test.ts
@@ -17,7 +17,15 @@ vi.mock('../../maker-host/active-catalog.js', () => ({
runtimes: { pi: { baseUrl: 'https://openrouter.ai/api/v1', wireProtocol: 'openai-chat', models: [
{ id: 'oauth/new', name: 'OAuth New', discoveredCost: { input: 0.1, output: 0.2 } },
] } },
- }), ...(['claude', 'xai'] as const).map(native => {
+ }), ...['mimo-account', 'mimo-second'].map(id => buildUserProvider({
+ id, name: 'MiMo', runtimes: Object.fromEntries(
+ (['claude-code', 'codex', 'pi'] as const).map(agent => [agent, {
+ baseUrl: `https://token-plan-cn.xiaomimimo.com/${agent === 'claude-code' ? 'anthropic' : 'v1'}`,
+ catalogPresetId: 'xiaomi-mimo-token-plan-cn',
+ models: [{ id: 'mimo-v2.6-pro', name: 'MiMo' }],
+ }]),
+ ),
+ })), ...(['claude', 'xai'] as const).map(native => {
const provider = buildUserProvider({
id: `${native}-account`, name: 'Account', auth: { method: 'oauth', native }, runtimes: {},
});
@@ -36,6 +44,25 @@ import { accountReferencePriceQuote } from '../accountReferencePrice.js';
import { getReferenceModelPricing, getCodexProviderSubscriptionValuePrice } from '../referenceModelPricing.js';
describe('independent subscription account reference prices', () => {
+ it.each(['claude-code', 'codex', 'pi'] as const)(
+ 'resolves MiMo %s prices through the preset while retaining account ownership', (agent) => {
+ const model = 'mimo-v2.6-pro';
+ const base = providerReferencePriceQuote('xiaomi-mimo-token-plan-cn', model,
+ BUNDLED_CATALOG.modelRegistry, { agent, officialOnly: true });
+ expect(base).toBeDefined();
+ const own = { ...base!, providerId: 'mimo-account', source: 'user-override' as const,
+ inputPerMtok: 123, outputPerMtok: 456 };
+ const pricing = { 'mimo-account': { [modelPricingKey(model, agent)]: own } };
+ expect(getCodexProviderSubscriptionValuePrice('mimo-account', model, {}, undefined, undefined, agent))
+ .toEqual({ ...base, providerId: 'mimo-account', modelId: model });
+ expect(getCodexProviderSubscriptionValuePrice('mimo-account', model, pricing, undefined, undefined, agent))
+ .toEqual(own);
+ expect(getCodexProviderSubscriptionValuePrice('mimo-second', model, pricing, undefined, undefined, agent))
+ .toEqual({ ...base, providerId: 'mimo-second', modelId: model });
+ expect(getCodexProviderSubscriptionValuePrice('mimo-account', 'unknown-model', {}, undefined, undefined, agent))
+ .toBeUndefined();
+ },
+ );
it('publishes imported and discovered BYOK prices under the actual connection and engine', () => {
const pricing = getReferenceModelPricing();
expect(getModelPriceQuote(pricing, 'router-account', 'aion-labs/aion-3.0-mini', 'pi'))
diff --git a/apps/desktop/src/main/usage/accountReferencePrice.ts b/apps/desktop/src/main/usage/accountReferencePrice.ts
index 74eca56ab6..6b2a4c0c9d 100644
--- a/apps/desktop/src/main/usage/accountReferencePrice.ts
+++ b/apps/desktop/src/main/usage/accountReferencePrice.ts
@@ -7,7 +7,18 @@ export const accountReferencePriceQuote: typeof providerReferencePriceQuote = (
providerId, modelId, registry, options,
) => {
const provider = getActiveCatalog().providers.find(provider => provider.id === providerId);
- const catalogId = provider ? providerCatalogId(provider) : providerId;
+ let catalogId = provider ? providerCatalogId(provider) : providerId;
+ // API-key subscriptions have account-local IDs. Resolve their public tariff
+ // from the selected engine/model's preset, never from another account.
+ if (provider?.access?.kind === 'subscription' && provider.auth.method === 'apiKey') {
+ const models = options?.agent
+ ? provider.models[options.agent] ?? []
+ : Object.values(provider.models).flat();
+ const presetIds = new Set(models
+ .filter(model => model.id === modelId && model.catalogPresetId)
+ .map(model => model.catalogPresetId!));
+ if (presetIds.size === 1) catalogId = [...presetIds][0];
+ }
const quote = providerReferencePriceQuote(
catalogId, modelId, registry, options,
);
diff --git a/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx b/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
index da63c2f2ee..b7fb783d6e 100644
--- a/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
@@ -15,8 +15,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { buildUserProvider, BUNDLED_CATALOG, parseModelsListResponse, modelProtocolComparison, type ProviderView } from '@cindy/model-providers';
+const testI18n = vi.hoisted(() => ({ language: 'zh-CN' }));
vi.mock('react-i18next', () => ({
- useTranslation: () => ({ t: (key: string) => key, i18n: { language: 'zh-CN' } }),
+ useTranslation: () => ({ t: (key: string) => key, i18n: testI18n }),
}));
vi.mock('@/hooks/useCodexAuth', () => ({
@@ -242,6 +243,38 @@ function renderWizard(presetId: string) {
);
}
+it.each([
+ ['zh-CN', '小米'],
+ ['zh-TW', '小米'],
+ ['en', 'Xiaomi'],
+])('finds the displayed MiMo brand in %s', async (language, query) => {
+ testI18n.language = language;
+ const presets = BUNDLED_CATALOG.presets!.filter(p =>
+ ['xiaomi-token-plan-ams', 'xiaomi-token-plan-sgp'].includes(p.id),
+ );
+ expect(presets).toHaveLength(2);
+ vi.mocked(window.electronAPI.maker.listProviderPresets).mockResolvedValue({ presets: [...presets, deepseekPreset] });
+ render(<AddProviderWizard providers={[]} onOpenCustomForm={vi.fn()} onClose={vi.fn()} onDone={vi.fn()} />);
+ await screen.findByText('DeepSeek');
+ fireEvent.change(screen.getByPlaceholderText('settings.providers.wizard.searchPlaceholder'), { target: { value: query } });
+ expect(screen.getAllByText('settings.providers.models.subscriptionProduct')).toHaveLength(2);
+ expect(screen.queryByText('DeepSeek')).toBeNull();
+});
+
+it.each(['xiaomi-mimo-token-plan-cn', 'xiaomi-token-plan-ams', 'xiaomi-token-plan-sgp'])(
+ 'presents %s as a subscription with the dedicated key hint', async id => {
+ const preset = BUNDLED_CATALOG.presets!.find(p => p.id === id)!;
+ vi.mocked(window.electronAPI.maker.listProviderPresets).mockResolvedValue({ presets: [preset, deepseekPreset] });
+ render(<AddProviderWizard providers={[]} onOpenCustomForm={vi.fn()} onClose={vi.fn()} onDone={vi.fn()} />);
+ const hint = await screen.findByText('settings.providers.models.subscriptionProduct');
+ fireEvent.click(hint.closest('button')!);
+ expect(await screen.findByPlaceholderText('tp-…')).toBeTruthy();
+ expect(screen.getByText('settings.providers.wizard.mimoTokenPlanNote')).toBeTruthy();
+ expect(screen.getByRole('link', { name: 'settings.providers.wizard.setupLink.apiKey' }).getAttribute('href')).toBe('https://platform.xiaomimimo.com/token-plan');
+ expect(screen.queryByPlaceholderText('sk-…')).toBeNull();
+ },
+);
+
it.each(['openrouter', 'minimax-cn', 'minimax-global', 'moonshot-kimi-code', 'github-copilot', 'nous'])(
'shows the same sign-in/API choice in the supplier list and connection page for %s', async id => {
const preset = BUNDLED_CATALOG.presets!.find(p => p.id === id)!;
@@ -261,6 +294,7 @@ it.each(['openrouter', 'minimax-cn', 'minimax-global', 'moonshot-kimi-code', 'gi
);
beforeEach(() => {
+ testI18n.language = 'zh-CN';
(window as unknown as { electronAPI: unknown }).electronAPI = {
maker: {
onProviderOAuthProgress: vi.fn(() => () => undefined),
diff --git a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
index eb0d96c171..382817b184 100644
--- a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
+++ b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
@@ -1,4 +1,4 @@
-import { providerSetupLink, providerPresetOAuth, providerPresetOAuthRuntimes, buildUserProvider } from '@cindy/model-providers';
+import { providerSetupLink, providerPresetOAuth, providerPresetOAuthRuntimes, buildUserProvider, isMimoTokenPlanPreset } from '@cindy/model-providers';
import { bindProviderPresetRuntime, providerEndpointBindings, bindProviderEndpoint } from '@cindy/model-providers';
/**
* AddProviderWizard —— 「添加供应商」三步向导(2026-07 模型供应商重构)。
@@ -538,6 +538,7 @@ export function AddProviderWizard({
q
? sortedPresets.filter(
(p) =>
+ presetDisplayName(p, i18n.language).toLowerCase().includes(q) ||
p.name.toLowerCase().includes(q) ||
(p.nameEn?.toLowerCase().includes(q) ?? false) ||
(p.nameZhTW?.toLowerCase().includes(q) ?? false),
@@ -1648,13 +1649,19 @@ export function AddProviderWizard({
name: presetDisplayName(p, i18n.language),
})}
name={presetDisplayName(p, i18n.language)}
- meta={t(
- providerPresetOAuth(p.id)
- ? 'settings.providers.wizard.metaLoginOrApi'
- : p.authMethod === 'none'
- ? 'settings.providers.wizard.metaNoAuth'
- : 'settings.providers.wizard.metaApiKey',
- )}
+ meta={
+ isMimoTokenPlanPreset(p)
+ ? t('settings.providers.models.subscriptionProduct', {
+ product: 'MiMo Token Plan',
+ })
+ : t(
+ providerPresetOAuth(p.id)
+ ? 'settings.providers.wizard.metaLoginOrApi'
+ : p.authMethod === 'none'
+ ? 'settings.providers.wizard.metaNoAuth'
+ : 'settings.providers.wizard.metaApiKey',
+ )
+ }
beta={isLocalRuntimeBetaProviderId(p.id)}
onClick={() => pickPreset(p)}
/>
@@ -1914,12 +1921,15 @@ export function AddProviderWizard({
<SettingsTextInput
value={apiKey}
onChange={setApiKey}
- placeholder="sk-…"
+ placeholder={isMimoTokenPlanPreset(sel.preset) ? 'tp-…' : 'sk-…'}
size="md"
mono
secret
secretTipContentClassName="z-[10001]"
/>
+ {isMimoTokenPlanPreset(sel.preset) && (
+ <InfoLine text={t('settings.providers.wizard.mimoTokenPlanNote')} />
+ )}
</div>
) : (
<InfoLine text={t('settings.providers.wizard.noAuthNote')} />
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 9e5021db87..6b2d2a64c0 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -2344,6 +2344,7 @@
"endpointLabel": "{{agent}} base URL",
"noAuthNote": "This proxy needs no client key; Cindy removes CLI subscription credentials before forwarding.",
"signIn": "Sign in",
+ "mimoTokenPlanNote": "Use the dedicated API key from your MiMo Token Plan page (tp-…). Calls use your subscription quota. Pay-as-you-go API keys cannot be used here.",
"setupLink": {
"apiKey": "Get an API key",
"account": "Sign up or sign in",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 8365c769ec..d9ed26da09 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -2343,6 +2343,7 @@
"endpointLabel": "{{agent}} ベース URL",
"noAuthNote": "このプロキシにクライアントキーは不要です。Cindy は転送前に CLI のサブスクリプション認証情報を削除します。",
"signIn": "ログイン",
+ "mimoTokenPlanNote": "MiMo Token Plan ページの専用 API キー (tp-…) を使用してください。呼び出しにはサブスクの利用枠が使われます。従量課金の API キーは使用できません。",
"setupLink": {
"apiKey": "API キーを取得",
"account": "登録・ログイン",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 0d7d79cfa0..eaf52f21c6 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -2343,6 +2343,7 @@
"endpointLabel": "{{agent}} 기본 URL",
"noAuthNote": "이 프록시는 클라이언트 키가 필요하지 않습니다. Cindy는 전달 전에 CLI 구독 자격 증명을 제거합니다.",
"signIn": "로그인",
+ "mimoTokenPlanNote": "MiMo Token Plan 페이지의 전용 API 키 (tp-…)를 사용하세요. 호출 시 구독 할당량이 사용됩니다. 종량제 API 키와 혼용할 수 없습니다.",
"setupLink": {
"apiKey": "API 키 받기",
"account": "가입 또는 로그인",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 84b380fec7..c79a7ad204 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -2343,6 +2343,7 @@
"endpointLabel": "{{agent}} 基础 URL",
"noAuthNote": "此 Proxy 无需客户端密钥;Cindy 会在转发前移除 CLI 的订阅凭证。",
"signIn": "登录",
+ "mimoTokenPlanNote": "请使用 MiMo Token Plan 页面提供的专属 API Key (tp-…)。调用消耗订阅配额,不能与按量付费 API Key 混用。",
"setupLink": {
"apiKey": "获取 API Key",
"account": "注册或登录",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 792cd6f9d6..f6eccaf745 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -2343,6 +2343,7 @@
"endpointLabel": "{{agent}} 基礎 URL",
"noAuthNote": "此 Proxy 無需客戶端金鑰;Cindy 會在轉發前移除 CLI 的訂閱憑證。",
"signIn": "登入",
+ "mimoTokenPlanNote": "請使用 MiMo Token Plan 頁面提供的專屬 API Key (tp-…)。呼叫會消耗訂閱配額,不能與按量付費 API Key 混用。",
"setupLink": {
"apiKey": "取得 API Key",
"account": "註冊或登入",
diff --git a/packages/model-providers/src/__tests__/mimoPresentation.test.ts b/packages/model-providers/src/__tests__/mimoPresentation.test.ts
new file mode 100644
index 0000000000..f2b8aff4e2
--- /dev/null
+++ b/packages/model-providers/src/__tests__/mimoPresentation.test.ts
@@ -0,0 +1,99 @@
+import { describe, expect, it } from "vitest";
+import { BUNDLED_CATALOG, presetDisplayName } from "../catalog.js";
+import { buildUserProvider } from "../user-provider.js";
+import { isMimoTokenPlanPreset } from "../mimoPresentation.js";
+import type { CustomProviderConfig } from "../types.js";
+
+const config = (baseUrl: string): CustomProviderConfig => ({
+ id: "my-account",
+ name: "Personal models",
+ runtimes: {
+ codex: {
+ baseUrl,
+ wireProtocol: "openai-chat",
+ models: [{ id: "mimo-v2.5", name: "MiMo" }],
+ },
+ },
+});
+
+describe("MiMo subscription presentation", () => {
+ it.each(["cn", "ams", "sgp"])(
+ "recognizes existing and renamed %s connections without changing auth or routing",
+ (region) => {
+ const baseUrl = `https://token-plan-${region}.xiaomimimo.com/v1`;
+ const provider = buildUserProvider(config(baseUrl));
+ expect(provider.access).toEqual({
+ kind: "subscription",
+ product: "MiMo Token Plan",
+ });
+ expect(provider.name).toBe("Personal models");
+ expect(provider.id).toBe("my-account");
+ expect(provider.auth).toEqual({ method: "apiKey" });
+ expect(provider.routing.codex?.upstream).toBe(baseUrl);
+ expect(provider.routing.codex?.authStrategy).toBe("api-key-header");
+ },
+ );
+
+ it.each([
+ "https://api.xiaomimimo.com/v1",
+ "https://proxy.example/v1",
+ "https://token-plan-cn.xiaomimimo.com.example.org/v1",
+ "https://[email protected]/v1",
+ "http://token-plan-cn.xiaomimimo.com/v1",
+ "https://token-plan-cn.xiaomimimo.com:8080/v1",
+ ])("keeps %s as an API even with a subscription-looking name", (baseUrl) => {
+ expect(
+ buildUserProvider({ ...config(baseUrl), name: "MiMo Token Plan" }).access,
+ ).toEqual({ kind: "api" });
+ });
+
+ it("does not label mixed runtime/model endpoints or unauthenticated connections as subscriptions", () => {
+ const input = config("https://token-plan-cn.xiaomimimo.com/v1");
+ expect(
+ buildUserProvider({ ...input, auth: { method: "none" } }).access,
+ ).toEqual({ kind: "api" });
+ input.runtimes.pi = {
+ baseUrl: "https://api.xiaomimimo.com/v1",
+ models: [],
+ };
+ expect(buildUserProvider(input).access).toEqual({ kind: "api" });
+ delete input.runtimes.pi;
+ input.runtimes.codex!.models[0].route = {
+ baseUrl: "https://api.xiaomimimo.com/v1",
+ wireProtocol: "openai-chat",
+ };
+ expect(buildUserProvider(input).access).toEqual({ kind: "api" });
+ });
+
+ it("recognizes shipped Token Plan presets and localizes their names even with old catalog labels", () => {
+ for (const id of [
+ "xiaomi-mimo-token-plan-cn",
+ "xiaomi-token-plan-ams",
+ "xiaomi-token-plan-sgp",
+ ]) {
+ const preset = BUNDLED_CATALOG.presets!.find((p) => p.id === id)!;
+ expect(isMimoTokenPlanPreset(preset), id).toBe(true);
+ expect(presetDisplayName(preset, "zh-CN")).toMatch(
+ /^小米 MiMo Token Plan/,
+ );
+ expect(presetDisplayName(preset, "en")).toMatch(
+ /^Xiaomi MiMo Token Plan/,
+ );
+ }
+ expect(
+ isMimoTokenPlanPreset(
+ BUNDLED_CATALOG.presets!.find((p) => p.id === "xiaomi-mimo-api-cn")!,
+ ),
+ ).toBe(false);
+ expect(isMimoTokenPlanPreset({ runtimes: {} })).toBe(false);
+ expect(
+ presetDisplayName(
+ { id: "xiaomi-token-plan-sgp", name: "MiMo Token Plan (Singapore)" },
+ "zh-CN",
+ ),
+ ).toBe("小米 MiMo Token Plan (新加坡)");
+ expect(
+ presetDisplayName({ id: "xiaomi-mimo-api-cn", name: "old" }, "en"),
+ ).toBe("Xiaomi MiMo API");
+ });
+});
diff --git a/packages/model-providers/src/catalog.ts b/packages/model-providers/src/catalog.ts
index f8fc659d17..67a40c3a44 100644
--- a/packages/model-providers/src/catalog.ts
+++ b/packages/model-providers/src/catalog.ts
@@ -11,6 +11,7 @@
*/
import { projectProviderMediaModels } from './providerMediaModels.js';
+import { mimoPresetName } from './mimoPresentation.js';
import { validModelMetadata } from './modelMetadataLayers.js';
import { parseModelRegistry } from './modelAccessValidator.js';
@@ -755,10 +756,12 @@ export function sanitizePresets(input: unknown): ProviderPreset[] {
* (缺省回落 `name`)。纯呈现选择,不影响预设 id / 创建后的供应商命名语义。
*/
export function presetDisplayName(
- preset: Pick<ProviderPreset, 'name' | 'nameEn' | 'nameZhTW'>,
+ preset: Pick<ProviderPreset, 'name' | 'nameEn' | 'nameZhTW'> & { id?: string },
locale: string,
): string {
const normalizedLocale = locale.toLowerCase().replaceAll('_', '-');
+ const mimoName = mimoPresetName(preset.id, normalizedLocale);
+ if (mimoName) return mimoName;
if (normalizedLocale === 'zh-tw' || normalizedLocale.startsWith('zh-hant')) {
return preset.nameZhTW ?? preset.name;
}
diff --git a/packages/model-providers/src/index.ts b/packages/model-providers/src/index.ts
index 0003c27988..f96bba4fd2 100644
--- a/packages/model-providers/src/index.ts
+++ b/packages/model-providers/src/index.ts
@@ -40,6 +40,7 @@ export type {
export { PI_MODEL_APIS, PI_REASONING_EFFORTS } from "./types.js";
export { isLocalOnlyProviderForAgent, isOpenAiSubscriptionProvider, providerCatalogId } from './provider-identity.js';
export { sourceProviderForPreset } from './providerPresetIdentity.js';
+export { isMimoTokenPlanPreset } from './mimoPresentation.js';
export {
effectivePiWireProtocol,
diff --git a/packages/model-providers/src/mimoPresentation.ts b/packages/model-providers/src/mimoPresentation.ts
new file mode 100644
index 0000000000..d4caa723a8
--- /dev/null
+++ b/packages/model-providers/src/mimoPresentation.ts
@@ -0,0 +1,72 @@
+import type { Provider, ProviderPreset } from "./types.js";
+
+/** Official connection choices; saved connection names remain user-owned. */
+export function mimoPresetName(
+ id: string | undefined,
+ locale: string,
+): string | undefined {
+ const regions: Record<string, readonly [string, string, string]> = {
+ "xiaomi-mimo-token-plan-cn": ["中国大陆", "中國大陸", "Mainland China"],
+ "xiaomi-token-plan-cn": ["中国大陆", "中國大陸", "Mainland China"],
+ "xiaomi-token-plan-ams": ["阿姆斯特丹", "阿姆斯特丹", "Amsterdam"],
+ "xiaomi-token-plan-sgp": ["新加坡", "新加坡", "Singapore"],
+ };
+ const region = id && Object.hasOwn(regions, id) ? regions[id] : undefined;
+ if (!region && id !== "xiaomi-mimo-api-cn" && id !== "xiaomi")
+ return undefined;
+ const zh = locale.startsWith("zh");
+ const traditional = locale === "zh-tw" || locale.startsWith("zh-hant");
+ const brand = zh ? "小米 MiMo" : "Xiaomi MiMo";
+ return region
+ ? `${brand} Token Plan (${region[zh ? (traditional ? 1 : 0) : 2]})`
+ : `${brand} API`;
+}
+
+/** Billing identity comes from the official endpoint, never a user-editable name. */
+export function isMimoTokenPlanUrl(value: string): boolean {
+ try {
+ const url = new URL(value);
+ return (
+ url.protocol === "https:" &&
+ !url.port &&
+ /^token-plan-(cn|ams|sgp)\.xiaomimimo\.com$/.test(url.hostname)
+ );
+ } catch {
+ return false;
+ }
+}
+
+export function isMimoTokenPlanProvider(
+ provider: Pick<Provider, "routing" | "models">,
+): boolean {
+ const routes = Object.values(provider.routing).filter(
+ (route) => route !== undefined,
+ );
+ return (
+ routes.length > 0 &&
+ routes.every((route) => isMimoTokenPlanUrl(route.upstream)) &&
+ Object.values(provider.models).every((models) =>
+ (models ?? []).every(
+ (model) => !model.route || isMimoTokenPlanUrl(model.route.baseUrl),
+ ),
+ )
+ );
+}
+
+export function isMimoTokenPlanPreset(
+ preset: Pick<ProviderPreset, "runtimes">,
+): boolean {
+ const runtimes = Object.values(preset.runtimes).filter(
+ (runtime) => runtime !== undefined,
+ );
+ return (
+ runtimes.length > 0 &&
+ runtimes.every(
+ (runtime) =>
+ isMimoTokenPlanUrl(runtime.baseUrl) &&
+ runtime.models.every(
+ (model) => !model.route || isMimoTokenPlanUrl(model.route.baseUrl),
+ ),
+ )
+ );
+}
diff --git a/packages/model-providers/src/providerBranding.ts b/packages/model-providers/src/providerBranding.ts
index e06d1fd0b9..56b2b9eef1 100644
--- a/packages/model-providers/src/providerBranding.ts
+++ b/packages/model-providers/src/providerBranding.ts
@@ -37,8 +37,9 @@ export const PROVIDER_LOGO_PATHS = {
vercel: 'M12 0l12 20.785H0L12 0z',
volcengine:
'M7.29 5.36L3.148 21.737a.215.215 0 00.203.261h8.29a.214.214 0 00.215-.261L7.7 5.359a.214.214 0 00-.41 0z M4.553 16.18l-1.406 5.558a.214.214 0 00.203.261h2.42-4.551a.214.214 0 01-.214-.26l2.275-8.961a.214.214 0 01.409 0l.864 3.402z M14.44.15a.214.214 0 00-.41 0L8.366 21.739A.214.214 0 008.58 22H19.9a.214.214 0 00.215-.261L14.44.151z M16.694 22h3.207a.215.215 0 00.214-.262l-1.839-6.993 1.164-4.592a.214.214 0 01.411 0l2.951 11.586a.214.214 0 01-.214.261h-5.894z M10.278 7.741L6.685 21.736A.214.214 0 006.899 22h7.17a.216.216 0 00.214-.166.216.216 0 000-.098L10.687 7.742a.214.214 0 00-.409 0z',
+ // Compact Xiaomi mark (Simple Icons 16.27.0, CC0); the two-line wordmark is illegible at 14px.
xiaomimimo:
- 'M.958 15.936a.459.459 0 01.459.44v2.729a.46.46 0 01-.918 0v-2.729a.459.459 0 01.459-.44zm4.814-2.035a.46.46 0 01.553.45v4.754a.458.458 0 11-.918 0V15.48L3.74 17.202a.462.462 0 01-.655.016.462.462 0 01-.065-.082L.628 14.67a.459.459 0 01.658-.637l2.124 2.187 2.127-2.188a.46.46 0 01.235-.13zm2.068.004a.46.46 0 01.458.445v4.755a.46.46 0 01-.458.458.459.459 0 01-.458-.458V14.35a.459.459 0 01.458-.445zm1.973 2.014a.46.46 0 01.46.457v2.729a.46.46 0 01-.784.324.46.46 0 01-.134-.324v-2.729a.46.46 0 01.458-.458zm.002-2.045a.458.458 0 01.328.157l2.127 2.19 2.125-2.19a.459.459 0 01.784.318v4.756a.46.46 0 01-.455.458.46.46 0 01-.458-.458V15.48l-1.667 1.723a.46.46 0 01-.65.008l-.005-.005-.004-.003-2.455-2.534a.46.46 0 01-.008-.667.461.461 0 01.338-.128zm6.797 1.206a.46.46 0 01.53.651A1.966 1.966 0 0019.81 18.4a.462.462 0 01.623.18.46.46 0 01-.181.624 2.863 2.863 0 01-1.38.353l-.142-.004a2.88 2.88 0 01-2.393-4.263.461.461 0 01.274-.21zm.864-.931a2.884 2.884 0 013.915 3.914.46.46 0 01-.402.24l-.057-.004a.458.458 0 01-.164-.055.46.46 0 01-.182-.622 1.967 1.967 0 00-2.669-2.67.459.459 0 11-.441-.803zM9.59 6.368c1.481 0 1.696 1.202 1.696 1.654v2.648h-.917v-.432c-.26.346-.792.535-1.36.535-.133 0-1.289-.03-1.384-1.136-.082-.932.675-1.61 2.053-1.61h.691c0-.563-.367-.886-.983-.886-.44.013-.864.174-1.2.458l-.36-.664c.484-.379 1.012-.567 1.764-.567zm4.427.1c1.263 0 2.082.97 2.083 2.15 0 1.181-.824 2.154-2.083 2.154-1.26 0-2.084-.972-2.084-2.152 0-1.18.82-2.153 2.084-2.153zm6.801.015c.68 0 1.202.465 1.197 1.548v2.642H21.1V8.29c0-.312-.002-.98-.63-.98s-.628.667-.628.838v2.524h-.89V8.148c0-.17-.001-.838-.63-.838-.628 0-.628.668-.628.98v2.383h-.917v-4.03h.917V7a1.22 1.22 0 01.947-.516c.398 0 .76.193.982.686a1.321 1.321 0 011.195-.686zm-18.093.872l1.457-1.772H5.32L3.311 8.07l2.14 2.602H4.24L2.725 8.796 1.21 10.672H0L2.138 8.07.13 5.583h1.138l1.458 1.772zm4.149 3.317h-.916V6.644h.916v4.028zm16.99 0h-.916V6.644h.916v4.028zM9.925 8.71c-1.055 0-1.359.412-1.326.742.032.329.324.537.757.537a1.013 1.013 0 001.014-.968l.002-.31h-.447zM14.018 7.3c-.663 0-1.184.487-1.184 1.32 0 .832.52 1.32 1.184 1.32.662 0 1.182-.49 1.182-1.32 0-.832-.52-1.32-1.182-1.32z',
+ 'M12 0C8.016 0 4.756.255 2.493 2.516.23 4.776 0 8.033 0 12.012c0 3.98.23 7.235 2.494 9.497C4.757 23.77 8.017 24 12 24c3.983 0 7.243-.23 9.506-2.491C23.77 19.247 24 15.99 24 12.012c0-3.984-.233-7.243-2.502-9.504C19.234.252 15.978 0 12 0zM4.906 7.405h5.624c1.47 0 3.007.068 3.764.827.746.746.827 2.233.83 3.676v4.54a.15.15 0 0 1-.152.147h-1.947a.15.15 0 0 1-.152-.148V11.83c-.002-.806-.048-1.634-.464-2.051-.358-.36-1.026-.441-1.72-.458H7.158a.15.15 0 0 0-.151.147v6.98a.15.15 0 0 1-.152.148H4.906a.15.15 0 0 1-.15-.148V7.554a.15.15 0 0 1 .15-.149zm12.131 0h1.949a.15.15 0 0 1 .15.15v8.892a.15.15 0 0 1-.15.148h-1.949a.15.15 0 0 1-.151-.148V7.554a.15.15 0 0 1 .151-.149zM8.92 10.948h2.046c.083 0 .15.066.15.147v5.352a.15.15 0 0 1-.15.148H8.92a.15.15 0 0 1-.152-.148v-5.352a.15.15 0 0 1 .152-.147Z',
xai: 'M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z',
openrouter:
'M16.778 1.844v1.919q-.569-.026-1.138-.032-.708-.008-1.415.037c-1.93.126-4.023.728-6.149 2.237-2.911 2.066-2.731 1.95-4.14 2.75-.396.223-1.342.574-2.185.798-.841.225-1.753.333-1.751.333v4.229s.768.108 1.61.333c.842.224 1.789.575 2.185.799 1.41.798 1.228.683 4.14 2.75 2.126 1.509 4.22 2.11 6.148 2.236.88.058 1.716.041 2.555.005v1.918l7.222-4.168-7.222-4.17v2.176c-.86.038-1.611.065-2.278.021-1.364-.09-2.417-.357-3.979-1.465-2.244-1.593-2.866-2.027-3.68-2.508.889-.518 1.449-.906 3.822-2.59 1.56-1.109 2.614-1.377 3.978-1.466.667-.044 1.418-.017 2.278.02v2.176L24 6.014Z',
@@ -137,6 +138,8 @@ const PROVIDER_LOGO_KIND_BY_ID: Readonly<Record<string, ProviderLogoKind>> = {
litellm: 'litellm',
'litellm-proxy': 'litellm',
longcat: 'longcat',
+ xiaomi: 'xiaomimimo',
+ 'xiaomi-token-plan-cn': 'xiaomimimo',
'xiaomi-mimo-api-cn': 'xiaomimimo',
'xiaomi-mimo-token-plan-cn': 'xiaomimimo',
'volcengine-coding-plan': 'volcengine',
diff --git a/packages/model-providers/src/user-provider.ts b/packages/model-providers/src/user-provider.ts
index 02aa64c25f..7df2cbfe3d 100644
--- a/packages/model-providers/src/user-provider.ts
+++ b/packages/model-providers/src/user-provider.ts
@@ -1,5 +1,6 @@
import { alignModelApiRoute, providerInterfaceModelRoute, hasDeclaredProviderInterface, providerWireProtocolForApi, providerBaseUrlForApi } from './providerInterfaceRoutes.js';
import { nativeModelAgents } from './modelProtocol.js';
+import { isMimoTokenPlanProvider } from './mimoPresentation.js';
import { resolveCatalogModelNativeApi, resolveModelNativeApi } from './modelRegistry.js';
import { providerEndpointBindings, bindProviderEndpoint, bindProviderPresetRuntime, canonicalProviderEndpoint } from './providerEndpointTemplate.js';
import { PI_MODEL_APIS } from "./types.js";
@@ -666,8 +667,12 @@ export function buildUserProvider(
: noAuth
? { method: "none" }
: { method: "apiKey" },
- // API key / 无鉴权代理都属于用户自备接口;通用 OAuth 可能订阅也可能按量,未声明前不猜。
- ...(isOAuth ? {} : { access: { kind: "api" as const } }),
+ // Authentication and billing are independent: MiMo Token Plan uses an API key.
+ ...(isOAuth ? {} : {
+ access: !noAuth && isMimoTokenPlanProvider({ routing, models })
+ ? { kind: 'subscription' as const, product: 'MiMo Token Plan' }
+ : { kind: 'api' as const },
+ }),
routing,
models,
};