Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
/** Provider branding contract shared by desktop and mobile. */
import { describe, expect, it } from 'vitest';
import { BUNDLED_CATALOG } from '../catalog.js';
import {
hasProviderLogo,
isProviderLogoKind,
PROVIDER_LOGO_PATHS,
resolveProviderLogoKind,
} from '../providerBranding.js';
describe('provider branding', () => {
it.each([
['anthropic', 'anthropic'],
['openai', 'openai'],
['xd', 'cindy'],
] as const)('maps built-in provider %s to its official mark', (providerId, logoKind) => {
expect(resolveProviderLogoKind(providerId)).toBe(logoKind);
});
it('covers every bundled provider and preset id', () => {
const entries = [...BUNDLED_CATALOG.providers, ...(BUNDLED_CATALOG.presets ?? [])];
for (const entry of entries) {
expect(hasProviderLogo(entry.id), entry.id).toBe(true);
}
});
it.each(['https://chatgpt.com/backend-api/codex', 'https://api.openai.com/v1'])(
'uses the same OpenAI mark for independent account/API connections: %s', upstream => {
expect(resolveProviderLogoKind('openai-independent', {
codex: { upstream }, 'claude-code': { upstream }, pi: { upstream },
})).toBe(resolveProviderLogoKind('openai'));
expect(resolveProviderLogoKind('renamed-work-account', { codex: { upstream } })).toBe('openai');
},
);
it('does not brand lookalike ChatGPT endpoints as OpenAI', () => {
expect(resolveProviderLogoKind('custom', {
codex: { upstream: 'https://chatgpt.com.example.org/v1' },
})).toBeNull();
});
it('uses a dedicated xAI mark', () => {
expect(resolveProviderLogoKind('xai')).toBe('xai');
expect(PROVIDER_LOGO_PATHS.xai).not.toBe(PROVIDER_LOGO_PATHS.openrouter);
});
it.each([
['ollama', 'ollama'],
['cindy-local-ollama', 'ollama'],
['lmstudio', 'lmstudio'],
['cindy-local-lmstudio', 'lmstudio'],
['llamacpp', 'llamacpp'],
['vllm', 'vllm'],
] as const)('maps local runtime %s to %s', (providerId, logoKind) => {
expect(resolveProviderLogoKind(providerId)).toBe(logoKind);
expect(hasProviderLogo(providerId)).toBe(true);
});
it('only infers Vercel branding from the exact AI Gateway host', () => {
expect(resolveProviderLogoKind('renamed', {
codex: { upstream: 'https://ai-gateway.vercel.sh/v1' },
})).toBe('vercel');
expect(resolveProviderLogoKind('renamed', {
codex: { upstream: 'https://my-openrouter-proxy.vercel.sh/v1' },
})).toBeNull();
expect(resolveProviderLogoKind('renamed', {
codex: { upstream: 'https://tenant.ai-gateway.vercel.sh/v1' },
})).toBeNull();
});
it('guards runtime logo values before indexing shared paths', () => {
expect(isProviderLogoKind('cindy')).toBe(true);
expect(isProviderLogoKind('vercel')).toBe(true);
expect(isProviderLogoKind('future-brand')).toBe(false);
expect(isProviderLogoKind(null)).toBe(false);
});
it('keeps preset branding after a user-facing provider id changes', () => {
for (const preset of BUNDLED_CATALOG.presets ?? []) {
// Self-hosted presets can be moved to any host; after the id is renamed there is
// intentionally no trustworthy hostname from which to infer the vendor mark.
if (Object.values(preset.runtimes).some((runtime) => runtime?.baseUrlEditable)) continue;
const routing: Record<string, { upstream: string }> = {};
for (const [agent, runtime] of Object.entries(preset.runtimes)) {
if (runtime) routing[agent] = { upstream: runtime.baseUrl };
}
expect(hasProviderLogo('renamed-provider', routing), preset.id).toBe(true);
}
});
it.each([
'https://aiplatform.googleapis.com',
'https://us-central1-aiplatform.googleapis.com',
'https://aiplatform.us.rep.googleapis.com',
'https://aiplatform.eu.rep.googleapis.com',
])('brands official Vertex hosts as Google: %s', upstream => {
expect(resolveProviderLogoKind('renamed-vertex', { pi: { upstream } })).toBe('google');
});
it('does not brand a lookalike Vertex host as Google', () => {
expect(resolveProviderLogoKind('lookalike', {
pi: { upstream: 'https://aiplatform.googleapis.com.evil.test' },
})).toBeNull();
});
it('brands the official Azure Cognitive Services host as Azure', () => {
expect(resolveProviderLogoKind('renamed-azure', {
pi: { upstream: 'https://my-resource.cognitiveservices.azure.com/openai/v1' },
})).toBe('azure');
expect(resolveProviderLogoKind('lookalike', {
pi: { upstream: 'https://my-resource.cognitiveservices.azure.com.evil.test/openai/v1' },
})).toBeNull();
});
it('rejects spoofed hosts, malformed URLs, and mixed-brand routing deterministically', () => {
expect(
hasProviderLogo('lookalike', {
codex: { upstream: 'https://openrouter.ai.evil.example/v1' },
}),
).toBe(false);
expect(
hasProviderLogo('malformed', { codex: { upstream: 'not a url' } }),
).toBe(false);
expect(
hasProviderLogo('mixed-brands', {
codex: { upstream: 'https://api.openai.com/v1' },
'claude-code': { upstream: 'https://api.anthropic.com/v1' },
}),
).toBe(false);
expect(
hasProviderLogo('mixed-brands-reversed', {
'claude-code': { upstream: 'https://api.anthropic.com/v1' },
codex: { upstream: 'https://api.openai.com/v1' },
}),
).toBe(false);
});
});