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): 对齐供应商提示中的账号名称展示 (#4270)

Dash1706d7f6e9c1
diff --git a/apps/desktop/src/main/maker-host/__tests__/nativeProviderConnectionClaim.test.ts b/apps/desktop/src/main/maker-host/__tests__/nativeProviderConnectionClaim.test.ts
index b40631ad2c..8978edbaa5 100644
--- a/apps/desktop/src/main/maker-host/__tests__/nativeProviderConnectionClaim.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/nativeProviderConnectionClaim.test.ts
@@ -55,10 +55,15 @@ vi.mock('../../appSessionState.js', () => ({
// 本机凭证库:*Unbound 是「blob 里有凭证吗」,无绑定语义;带绑定的读取叠加 owner 校验,
// 与真实实现(readClaudeAiOAuth / hasGrokOAuthLogin)的分层一致。
vi.mock('../claude-credentials-store.js', () => ({
+ readClaudeAiOAuth: () =>
+ h.claudeCredentialPresent && isBoundToCurrentOwner('anthropic')
+ ? { accessToken: 'fake-token', identity: '[email protected]' }
+ : null,
hasClaudeAiOAuthUnbound: () => h.claudeCredentialPresent,
hasClaudeAiOAuth: () => h.claudeCredentialPresent && isBoundToCurrentOwner('anthropic'),
}));
vi.mock('../grok-oauth-login.js', () => ({
+ grokAccountIdentity: () => '[email protected]',
hasGrokOAuthLoginUnbound: () => h.grokCredentialPresent,
hasGrokOAuthLogin: () => h.grokCredentialPresent && isBoundToCurrentOwner('xai'),
getGrokAccessToken: () => null,
@@ -172,6 +177,27 @@ afterEach(() => {
});
describe('native provider connection claim on read', () => {
+ it('projects only bound native account identities without exposing credentials', async () => {
+ const before = await listProviders(false);
+ for (const id of ['anthropic', 'xai']) {
+ expect(before.find((p) => p.id === id)?.subscriptionAccount?.identity).toBeUndefined();
+ }
+ bindNativeProviderAuth('anthropic', { sharedSystem: true });
+ bindNativeProviderAuth('xai');
+ const after = await listProviders(false);
+ expect(after.find((p) => p.id === 'anthropic')?.subscriptionAccount).toEqual({
+ source: 'local', identity: '[email protected]',
+ });
+ expect(after.find((p) => p.id === 'xai')?.subscriptionAccount).toEqual({
+ source: 'oauth', identity: '[email protected]',
+ });
+ h.dataOwnerId = 'owner-b';
+ h.generation += 1;
+ const switched = await listProviders(false);
+ for (const id of ['anthropic', 'xai']) {
+ expect(switched.find((p) => p.id === id)?.subscriptionAccount?.identity).toBeUndefined();
+ }
+ });
it('认领本机 anthropic 凭证并补拉一次清单(修「已连接 + 零模型」)', async () => {
expect(isNativeProviderAuthBound('anthropic')).toBe(false);
diff --git a/apps/desktop/src/main/maker-host/createDesktopProviderService.ts b/apps/desktop/src/main/maker-host/createDesktopProviderService.ts
index 3323745466..8729b34d58 100644
--- a/apps/desktop/src/main/maker-host/createDesktopProviderService.ts
+++ b/apps/desktop/src/main/maker-host/createDesktopProviderService.ts
@@ -109,11 +109,16 @@ import {
readCustomProviderHeaders,
readCustomProviderKey,
} from '../secrets/providerSecretStore.js';
-import { hasClaudeAiOAuth, hasClaudeAiOAuthUnbound } from './claude-credentials-store.js';
+import {
+ hasClaudeAiOAuth,
+ hasClaudeAiOAuthUnbound,
+ readClaudeAiOAuth,
+} from './claude-credentials-store.js';
import { getValidClaudeAiOAuth } from './claude-oauth-refresh.js';
import {
getGrokAccessToken,
hasGrokOAuthLogin,
+ grokAccountIdentity,
recoverGrokAuthAfterRejection,
resetGrokOAuthMemoryCache,
} from './grok-oauth-login.js';
@@ -128,6 +133,7 @@ import { filterProviderCatalogForAccount } from './provider-access-policy.js';
import { getAppCapabilities } from '../appCapabilities.js';
import {
claimDetectedNativeProviderAuth,
+ getNativeProviderAuthSource,
migrateLegacyNativeProviderAuthBindings,
} from './nativeProviderAuthBinding.js';
import { hasLegacyOwnerNamespaceClaim } from '../ownerNamespaceMigration.js';
@@ -1042,7 +1048,24 @@ export function getDesktopProviderService(): ProviderService {
genericOAuthConnected: (providerId) => hasGenericOAuthLogin(storedCustomProviderId(providerId)),
codexAccountConnected: (providerId) => codexAccountState(providerId).authenticated,
subscriptionAccountConnected: (providerId) => subscriptionAccountState(providerId).authenticated,
- subscriptionAccountInfo: async (providerId) => ({ source: 'oauth', identity: subscriptionAccountState(providerId).identity }),
+ subscriptionAccountInfo: async (providerId) => {
+ if (providerId === 'anthropic') {
+ const oauth = readClaudeAiOAuth();
+ const source = getNativeProviderAuthSource('anthropic');
+ return {
+ source: source === 'native-harness-inherited' ? 'local'
+ : source === 'explicit-provider-oauth' ? 'oauth' : 'unknown',
+ identity: typeof oauth?.identity === 'string' ? oauth.identity : undefined,
+ };
+ }
+ if (providerId === 'xai') {
+ return {
+ source: 'oauth',
+ identity: hasGrokOAuthLogin() ? grokAccountIdentity('xai') : undefined,
+ };
+ }
+ return { source: 'oauth', identity: subscriptionAccountState(providerId).identity };
+ },
openAiAccountInfo: async (providerId) => {
const state = providerId === 'openai' ? await desktopCodexAuthAdapter.readAccountPresentationState() : codexAccountState(providerId);
return {
diff --git a/apps/desktop/src/main/maker-host/provider-service.ts b/apps/desktop/src/main/maker-host/provider-service.ts
index 516e7e778f..dfd3c7e1d6 100644
--- a/apps/desktop/src/main/maker-host/provider-service.ts
+++ b/apps/desktop/src/main/maker-host/provider-service.ts
@@ -202,7 +202,7 @@ export function createProviderService(deps: ProviderServiceDeps): ProviderServic
}
const subscriptionInfo = new Map<string, ProviderView['subscriptionAccount']>();
if (deps.subscriptionAccountInfo) await Promise.all(catalog.providers
- .filter(p => p.auth.native === 'claude' || p.auth.native === 'xai')
+ .filter(p => p.id === 'anthropic' || p.id === 'xai' || p.auth.native === 'claude' || p.auth.native === 'xai')
.map(async p => subscriptionInfo.set(p.id, await deps.subscriptionAccountInfo!(p.id))));
return buildRegistry(catalog, connected, discoveryFailures, deps.getModelAccess?.()).map((provider) => ({
...(subscriptionInfo.get(provider.id) ? { subscriptionAccount: subscriptionInfo.get(provider.id) } : {}),
diff --git a/apps/desktop/src/renderer/__tests__/providerRailWeeklyQuota.test.tsx b/apps/desktop/src/renderer/__tests__/providerRailWeeklyQuota.test.tsx
index 77f2a3defe..2ed0a58195 100644
--- a/apps/desktop/src/renderer/__tests__/providerRailWeeklyQuota.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/providerRailWeeklyQuota.test.tsx
@@ -98,6 +98,73 @@ describe('provider weekly quota identity and windows', () => {
});
describe('provider rail weekly remaining bars', () => {
+ it.each(['openai', 'anthropic', 'xai', 'independent'])(
+ 'shows %s account identity without quota and updates it with the directory',
+ async (id) => {
+ const account = { source: 'local' as const, identity: '[email protected]' };
+ const providers = [
+ provider(
+ id,
+ id === 'openai' ? { openAiAccount: account } : { subscriptionAccount: account },
+ ),
+ ];
+ const props = {
+ items: [{ kind: 'provider' as const, providerId: id }],
+ active: { kind: 'all' as const },
+ providers,
+ providerLabel: () => 'My provider',
+ onSelect: () => {},
+ localProviderUsage: false,
+ };
+ const { rerender } = render(<UnifiedModelRail {...props} />);
+ const button = screen.getByRole('button', { name: 'My provider · [email protected]' });
+ fireEvent.focus(button);
+ expect((await screen.findByRole('tooltip')).textContent).toBe(
+ 'My provider · [email protected]',
+ );
+ account.identity = '[email protected]';
+ rerender(<UnifiedModelRail {...props} />);
+ expect(screen.queryByRole('button', { name: /first@example/ })).toBeNull();
+ expect(
+ screen.getByRole('button', { name: 'My provider · [email protected]' }),
+ ).toBeTruthy();
+ expect(reads.codex).not.toHaveBeenCalled();
+ expect(reads.claude).not.toHaveBeenCalled();
+ expect(reads.xai).not.toHaveBeenCalled();
+ },
+ );
+ it.each([
+ ['OpenAI · [email protected] (2)', '[email protected]'],
+ ['Anthropic · [email protected]', '[email protected]'],
+ [
+ 'OpenAI · [email protected]'.slice(0, 50),
+ ],
+ [
+ 'OpenAI · [email protected]'.slice(0, 50) + ' (2)',
+ ],
+ ])(
+ 'preserves existing account connection name %s without repeating identity',
+ async (name, identity) => {
+ render(
+ <UnifiedModelRail
+ items={[{ kind: 'provider', providerId: 'independent' }]}
+ active={{ kind: 'all' }}
+ providers={[
+ provider('independent', { name, openAiAccount: { source: 'oauth', identity } }),
+ ]}
+ providerLabel={() => name}
+ onSelect={() => {}}
+ />,
+ );
+ fireEvent.focus(screen.getByRole('button', { name }));
+ expect((await screen.findByRole('tooltip')).textContent).toBe(name);
+ },
+ );
it('keeps two OpenAI accounts separate, preserves selection and updates remaining including zero', () => {
let usedB = 79;
reads.codex.mockImplementation((enabled, id) => ({
diff --git a/apps/desktop/src/renderer/components/new-chat/UnifiedModelRail.tsx b/apps/desktop/src/renderer/components/new-chat/UnifiedModelRail.tsx
index e13bdce0d8..a359d290a9 100644
--- a/apps/desktop/src/renderer/components/new-chat/UnifiedModelRail.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/UnifiedModelRail.tsx
@@ -57,6 +57,13 @@ export function UnifiedModelRail({
const separatorBefore = item.kind === 'all';
const engineOption =
item.kind === 'engine' ? agentOptionOf(engineOfAgentKind(item.agent)) : null;
+ const provider =
+ item.kind === 'provider'
+ ? providers.find((entry) => entry.id === item.providerId)
+ : undefined;
+ const accountIdentity =
+ provider?.openAiAccount?.identity?.trim() ||
+ provider?.subscriptionAccount?.identity?.trim();
const label =
item.kind === 'favorites'
? t('newChat.modelSelector.unified.railFavorites')
@@ -77,15 +84,12 @@ export function UnifiedModelRail({
)}
<RailButton
label={label}
+ accountIdentity={accountIdentity}
isActive={isActive}
itemKey={key}
onClick={() => onSelect(item)}
disabled={interactionDisabled}
- provider={
- localProviderUsage && item.kind === 'provider'
- ? providers.find((provider) => provider.id === item.providerId)
- : undefined
- }
+ provider={localProviderUsage ? provider : undefined}
>
{item.kind === 'favorites' ? (
// ☆ 未激活与其它格同灰(hover 提亮)—— 常亮金色会在没进收藏视图时也
@@ -110,6 +114,7 @@ export function UnifiedModelRail({
interface RailButtonProps {
label: string;
+ accountIdentity?: string;
isActive: boolean;
itemKey: string;
onClick: () => void;
@@ -132,8 +137,25 @@ function ProviderQuotaButton(props: RailButtonProps & { provider: ProviderView }
return <RailButtonView {...props} quota={quota} />;
}
+function accountLabel(label: string, identity?: string): string {
+ if (!identity || label === identity) return label;
+ // Independent logins already name the connection "Provider · identity".
+ // OpenAI also truncates that generated name to 50 characters and may add (2).
+ const baseLabel = label.replace(/ \(\d+\)$/, '');
+ if (baseLabel.endsWith(` · ${identity}`)) return label;
+ const separator = baseLabel.indexOf(' · ');
+ if (
+ separator >= 0 &&
+ baseLabel.length === 50 &&
+ `${baseLabel.slice(0, separator)} · ${identity}`.slice(0, 50) === baseLabel
+ )
+ return label;
+ return `${label} · ${identity}`;
+}
+
function RailButtonView({
label,
+ accountIdentity,
isActive,
itemKey,
onClick,
@@ -150,14 +172,15 @@ function RailButtonView({
? null
: `${t('quotaCard.weeklyLabel')} · ${t('quotaCard.remainingPercent', { percent: remaining })}`;
const reset = formatQuotaResetCountdown(quota?.resetsAt, Date.now(), t);
+ const displayLabel = accountLabel(label, accountIdentity);
const tooltip = quotaLabel ? (
<>
- <div>{label}</div>
- <div>{quotaLabel}</div>
+ <div>{displayLabel}</div>
+ {quotaLabel && <div>{quotaLabel}</div>}
{reset && <div>{reset}</div>}
</>
) : (
- label
+ displayLabel
);
return (
<Tip
@@ -170,7 +193,7 @@ function RailButtonView({
type="button"
disabled={disabled}
onClick={onClick}
- aria-label={label}
+ aria-label={displayLabel}
aria-description={quotaLabel ?? undefined}
aria-pressed={isActive}
data-rail-item={itemKey}