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(pi): avoid duplicate Anthropic /v1 path

Battleplus8f547019a745
diff --git a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
index d06173e012..b51c2e2304 100644
--- a/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/piNativeProviders.test.ts
@@ -553,6 +553,58 @@ describe('buildPiNativeProvidersFromConfigs', () => {
expect(providers[0].models[0].baseUrl ?? providers[0].baseUrl).toBe(baseUrl);
});
+ it('strips an inherited /v1 suffix for a model-level Anthropic route (#7258)', () => {
+ // Test value: the production launch mapper materializes models.json. Existing coverage only
+ // protects Google's endpoint rewrite; this same-provider cross-API route was missing.
+ // The minimum failure input is one Anthropic API override on an OpenAI provider /v1 URL;
+ // without a model baseUrl Pi appends /v1/messages to /v1 and gets /v1/v1/messages. Unit tier.
+ const baseUrl = 'http://127.0.0.1:8000/v1';
+ const { providers } = buildPiNativeProvidersFromConfigs([{
+ id: 'mixed-api',
+ name: 'Mixed API',
+ runtimes: {
+ pi: piRuntime({
+ baseUrl,
+ wireProtocol: 'openai-chat',
+ models: [
+ {
+ id: 'anthropic-api-override',
+ api: 'anthropic-messages',
+ },
+ {
+ id: 'anthropic-route-override',
+ route: { baseUrl, wireProtocol: 'anthropic-messages' },
+ },
+ {
+ id: 'anthropic-custom-route',
+ route: { baseUrl: 'https://gateway.example/proxy/v1', wireProtocol: 'anthropic-messages' },
+ },
+ {
+ id: 'anthropic-request-path',
+ api: 'anthropic-messages',
+ route: { baseUrl, wireProtocol: 'anthropic-messages', requestPath: '/custom/messages' },
+ },
+ { id: 'openai-model', name: 'OpenAI model' },
+ ],
+ }),
+ },
+ }], () => 'fixture-key');
+
+ expect(providers[0]).toMatchObject({
+ baseUrl,
+ api: 'openai-completions',
+ models: [
+ { id: 'anthropic-api-override', api: 'anthropic-messages', baseUrl: 'http://127.0.0.1:8000' },
+ { id: 'anthropic-route-override', api: 'anthropic-messages', baseUrl: 'http://127.0.0.1:8000' },
+ { id: 'anthropic-custom-route', api: 'anthropic-messages', baseUrl: 'https://gateway.example/proxy/v1' },
+ { id: 'anthropic-request-path', api: 'anthropic-messages' },
+ { id: 'openai-model' },
+ ],
+ });
+ expect(providers[0]?.models?.[3]).not.toHaveProperty('baseUrl');
+ expect(providers[0]?.models?.[4]).not.toHaveProperty('baseUrl');
+ });
+
it('carries catalog-generated suppliers through the real Pi launch mapping', () => {
const generatedIds = ['ant-ling', 'baseten', 'cerebras', 'fireworks', 'groq',
'huggingface', 'nvidia', 'together', 'mistral', 'opencode', 'qwen-token-plan',
diff --git a/apps/desktop/src/main/maker-host/pi-host.ts b/apps/desktop/src/main/maker-host/pi-host.ts
index 2dbc006a4e..6c65fe1cf9 100644
--- a/apps/desktop/src/main/maker-host/pi-host.ts
+++ b/apps/desktop/src/main/maker-host/pi-host.ts
@@ -1440,17 +1440,27 @@ export function buildPiNativeProvidersFromConfigs(
const explicitRouteApi = explicitRoute
? wireProtocolToPiApi(explicitRoute.wireProtocol)
: undefined;
- // bundled/official rows may lend protocol-compatible capabilities, but never routing.
+ // Bundled/official rows may lend protocol-compatible capabilities, but never routing.
// A same-origin URL is not the same endpoint: replacing /proxy/v1 with /v1 can bypass
- // the user's proxy. Only the model's own explicit route may create a model-level baseUrl.
- // Exception: Google's official preset keeps /v1beta/openai for discovery, but its native
- // SDK must call /v1beta. providerBaseUrlForApi only rewrites Google's public endpoints.
+ // the user's proxy. Keep explicit model routes, except for protocol-specific SDK roots:
+ // Google uses /v1beta instead of its discovery /v1beta/openai path, while Anthropic
+ // appends /v1/messages and needs an inherited trailing /v1 removed.
const nativeGoogleBaseUrl =
modelApi === 'google-generative-ai' && !m.route?.requestPath && !rt.requestPath
? providerBaseUrlForApi(rt.baseUrl, modelApi) : undefined;
+ const inheritedAnthropicBaseUrl = explicitRoute?.baseUrl ?? rt.baseUrl;
+ const nativeAnthropicBaseUrl =
+ authMethod !== 'oauth' &&
+ modelApi === 'anthropic-messages' &&
+ !m.route?.requestPath && !rt.requestPath &&
+ (!m.route || m.route.baseUrl === rt.baseUrl) &&
+ /\/v1\/?$/.test(inheritedAnthropicBaseUrl)
+ ? inheritedAnthropicBaseUrl.replace(/\/v1\/?$/, '')
+ : undefined;
const modelBaseUrl =
- m.api && m.route ? m.route.baseUrl :
- m.route && explicitRouteApi === modelApi ? explicitRoute?.baseUrl : nativeGoogleBaseUrl;
+ nativeAnthropicBaseUrl ??
+ (m.api && m.route ? m.route.baseUrl :
+ m.route && explicitRouteApi === modelApi ? explicitRoute?.baseUrl : nativeGoogleBaseUrl);
const spec = {
id: m.id,
...(m.selectedInterface ? { wireId: m.selectedInterface.wireModelId } : {}),