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): probe model-level routes

Chrisa31823b66a01
diff --git a/apps/desktop/src/main/maker-host/__tests__/providerDiagnostics.test.ts b/apps/desktop/src/main/maker-host/__tests__/providerDiagnostics.test.ts
index 03500add1a..4441b27996 100644
--- a/apps/desktop/src/main/maker-host/__tests__/providerDiagnostics.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/providerDiagnostics.test.ts
@@ -425,6 +425,81 @@ describe('resolveSavedProbeSpec / testProviderConnection(saved)', () => {
expect(seenUrl).toBe('https://api.deepseek.com/chat/completions');
});
+ it('仅选择 glm-5.3 时 saved 探测使用模型级 Responses 路由', async () => {
+ setCustomProviders([
+ buildUserProvider({
+ id: 'glm-responses-only',
+ name: 'GLM Responses Only',
+ runtimes: {
+ codex: {
+ baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4',
+ wireProtocol: 'openai-chat',
+ models: [
+ {
+ id: 'glm-5.3',
+ name: 'GLM-5.3',
+ route: {
+ baseUrl: 'https://open.bigmodel.cn/api/v1',
+ wireProtocol: 'openai-responses',
+ requestPath: '/responses',
+ },
+ },
+ ],
+ },
+ },
+ }),
+ ]);
+ setDiagnosticsKeyReader(() => 'glm-key');
+
+ expect(resolveSavedProbeSpec('glm-responses-only', 'codex')).toMatchObject({
+ baseUrl: 'https://open.bigmodel.cn/api/v1',
+ modelId: 'glm-5.3',
+ wireProtocol: 'openai-responses',
+ requestPath: '/responses',
+ });
+ let seenUrl = '';
+ await testProviderConnection(
+ { kind: 'saved', providerId: 'glm-responses-only', agent: 'codex' },
+ async (url) => {
+ seenUrl = String(url);
+ return fakeResponse(200, '{}');
+ },
+ );
+ expect(seenUrl).toBe('https://open.bigmodel.cn/api/v1/responses');
+ });
+
+ it('无模型级 route 的 glm-5.2 saved 探测继续使用 runtime V4 Chat 路由', async () => {
+ setCustomProviders([
+ buildUserProvider({
+ id: 'glm-chat-only',
+ name: 'GLM Chat Only',
+ runtimes: {
+ codex: {
+ baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4',
+ wireProtocol: 'openai-chat',
+ models: [{ id: 'glm-5.2', name: 'GLM-5.2' }],
+ },
+ },
+ }),
+ ]);
+ setDiagnosticsKeyReader(() => 'glm-key');
+
+ expect(resolveSavedProbeSpec('glm-chat-only', 'codex')).toMatchObject({
+ baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4',
+ modelId: 'glm-5.2',
+ wireProtocol: 'openai-chat',
+ });
+ let seenUrl = '';
+ await testProviderConnection(
+ { kind: 'saved', providerId: 'glm-chat-only', agent: 'codex' },
+ async (url) => {
+ seenUrl = String(url);
+ return fakeResponse(200, 'data: [DONE]\n\n');
+ },
+ );
+ expect(seenUrl).toBe('https://open.bigmodel.cn/api/coding/paas/v4/chat/completions');
+ });
+
it('saved 探测沿用自定义供应商的精确请求路径', async () => {
setCustomProviders([
buildUserProvider({
diff --git a/apps/desktop/src/main/maker-host/provider-diagnostics.ts b/apps/desktop/src/main/maker-host/provider-diagnostics.ts
index f4a5aecada..d697f1ded5 100644
--- a/apps/desktop/src/main/maker-host/provider-diagnostics.ts
+++ b/apps/desktop/src/main/maker-host/provider-diagnostics.ts
@@ -333,8 +333,12 @@ export function resolveSavedProbeSpec(providerId: string, agent: AgentKind): Pro
isAgentSelectableModel(m, { userProvider: provider.source === 'user' }),
);
if (!model) throw new Error(`provider '${providerId}' has no chat models for '${agent}'`);
+ const baseUrl = model.route?.baseUrl ?? routing.upstream;
+ const wireProtocol = model.route?.wireProtocol ?? routing.wireProtocol;
// Pi derives its inference path from wireProtocol and does not consume requestPath.
- const requestPath = agent === 'pi' ? undefined : routing.requestPath;
+ const requestPath = agent === 'pi'
+ ? undefined
+ : (model.route?.requestPath ?? routing.requestPath);
// OAuth 形态:探测凭证用 Runner 持有的 access_token(与 oauth-token 路由同源),未登录时
// 无 token → 探测会得到 AUTH_INVALID,这本身就是「先去登录」的正确结论。
// token 走 authorization 头而**不走 apiKey 字段**——apiKey 会让 cc 探测同时发
@@ -344,9 +348,9 @@ export function resolveSavedProbeSpec(providerId: string, agent: AgentKind): Pro
const oauthToken = oauthProbeTokenReader(providerId);
return {
agent,
- baseUrl: routing.upstream,
+ baseUrl,
modelId: model.id,
- wireProtocol: routing.wireProtocol,
+ wireProtocol,
requestPath,
apiKey: null,
headers: {
@@ -358,9 +362,9 @@ export function resolveSavedProbeSpec(providerId: string, agent: AgentKind): Pro
if (routing.authStrategy === 'none') {
return {
agent,
- baseUrl: routing.upstream,
+ baseUrl,
modelId: model.id,
- wireProtocol: routing.wireProtocol,
+ wireProtocol,
requestPath,
apiKey: null,
headers: withoutCredentialHeaders(routing.headerOverride),
@@ -369,12 +373,12 @@ export function resolveSavedProbeSpec(providerId: string, agent: AgentKind): Pro
const apiKey = keyReader(providerId, agent);
return {
agent,
- baseUrl: routing.upstream,
+ baseUrl,
modelId: model.id,
// 与 oauth-token 分支对齐:Chat 桥接供应商(api-key-header + openai-chat)的 saved 探测
// 必须带上 wireProtocol,否则 buildProbeRequest 回落到原生 /responses,对 Chat-only 上游
// 误报连接失败(真实会话走 resolveSessionRoute 不受影响,探测结论会与真实会话相反)。
- wireProtocol: routing.wireProtocol,
+ wireProtocol,
requestPath,
apiKey,
// 与真实会话路由保持 legacy 兼容:safeStorage 已有 key 时清掉旧凭证头,由 apiKey