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): Chat 桥接图片输入验证清单加入火山方舟豆包 Seed 系列 (#838)

fico-hub8293bfb3c1a0
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
index c622934f27..bbe565ad33 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
@@ -282,12 +282,30 @@ describe('chatBridgeCapabilitiesForRoute', () => {
expect(chatBridgeCapabilitiesForRoute(upstream, 'kimi-k3').imageInput).toBe('image_url');
});
+ it.each([
+ ['https://ark.cn-beijing.volces.com/api/v3', 'doubao-seed-2-1-pro-260628'],
+ ['https://ark.ap-southeast-1.volces.com/api/v3/', 'doubao-seed-1-6-vision-260615'],
+ ])('enables image_url for Doubao Seed on official Volcengine Ark host: %s (#771)', async (upstream, model) => {
+ const { chatBridgeCapabilitiesForRoute } = await freshCodexProxyHost();
+ expect(chatBridgeCapabilitiesForRoute(upstream, model).imageInput).toBe('image_url');
+ });
+
it.each([
['https://api.moonshot.cn/v1', 'kimi-k2.6'],
['https://api.deepseek.com/v1', 'kimi-k3'],
['https://api.moonshot.cn.evil.example/v1', 'kimi-k3'],
['http://api.moonshot.cn/v1', 'kimi-k3'],
['not-a-url', 'kimi-k3'],
+ ['https://api.deepseek.com/v1', 'deepseek-v4-pro'],
+ ['https://ark.cn-beijing.volces.com/api/v3', 'deepseek-v4-pro'],
+ ['https://api.deepseek.com/v1', 'doubao-seed-2-1-pro-260628'],
+ ['https://ark.cn-beijing.volces.com.evil.example/api/v3', 'doubao-seed-2-1-pro-260628'],
+ ['http://ark.cn-beijing.volces.com/api/v3', 'doubao-seed-2-1-pro-260628'],
+ // Seed 1.6 之前的版本号不放行(1.6 起才是原生多模态品牌线),锁死版本契约。
+ ['https://ark.cn-beijing.volces.com/api/v3', 'doubao-seed-1-5-pro-260101'],
+ ['https://ark.cn-beijing.volces.com/api/v3', 'doubao-seed-1-0'],
+ ['https://ark.cn-beijing.volces.com/api/v3', 'doubao-seed-pro'],
+ ['https://ark.cn-beijing.volces.com/api/v3', 'doubao-1-5-vision-pro'],
])('keeps image input disabled for non-matching route %s / %s', async (upstream, model) => {
const { chatBridgeCapabilitiesForRoute } = await freshCodexProxyHost();
expect(chatBridgeCapabilitiesForRoute(upstream, model).imageInput).toBeUndefined();
diff --git a/apps/desktop/src/main/maker-host/codex-proxy-host.ts b/apps/desktop/src/main/maker-host/codex-proxy-host.ts
index 526397ebf7..aad9da04a5 100644
--- a/apps/desktop/src/main/maker-host/codex-proxy-host.ts
+++ b/apps/desktop/src/main/maker-host/codex-proxy-host.ts
@@ -215,6 +215,22 @@ function isGoogleGeminiChatUpstream(upstream: string): boolean {
}
const MOONSHOT_CHAT_HOSTS = new Set(['api.moonshot.cn', 'api.moonshot.ai']);
+/** 火山方舟(豆包)官方 DNS 边界:ark.<region>.volces.com(如 ark.cn-beijing.volces.com)。 */
+const VOLCENGINE_ARK_CHAT_HOST_RE = /^ark\.[a-z0-9-]+\.volces\.com$/;
+/**
+ * 豆包 Seed 系列 model id 的版本前缀:doubao-seed-<major>-<minor>-…。
+ * 只放行 1.6 起的版本——Seed 品牌线从 1.6 开始原生多模态(官方 Chat Completions
+ * 支持 image_url);万一上游日后出现更低版本号的 seed 变体,不被顺带放行。
+ */
+const DOUBAO_SEED_VERSION_RE = /^doubao-seed-(\d+)-(\d+)(?:-|$)/;
+
+function isDoubaoVisionModel(model: string): boolean {
+ const m = DOUBAO_SEED_VERSION_RE.exec(model);
+ if (!m) return false;
+ const major = Number(m[1]);
+ const minor = Number(m[2]);
+ return major > 1 || (major === 1 && minor >= 6);
+}
function rewriteChatBridgeModel(model: string, stripPrefix: string | undefined): string {
return stripPrefix && model.startsWith(stripPrefix)
@@ -223,30 +239,37 @@ function rewriteChatBridgeModel(model: string, stripPrefix: string | undefined):
}
/**
- * 图片桥接必须按已验证的上游能力显式开启。这里认官方 Moonshot DNS 边界 + Kimi K3
- * 上游 model,不认 provider id(预设创建后会生成用户自定义 id),也不对所有
- * openai-chat 供应商放开。未命中继续沿用 fail-closed 默认。
+ * 图片桥接必须按已验证的上游能力显式开启。这里认官方 DNS 边界 + 上游 model
+ * (Moonshot 的 Kimi K3、火山方舟的豆包 Seed 系列),不认 provider id(预设创建后
+ * 会生成用户自定义 id),也不对所有 openai-chat 供应商放开。未命中继续沿用
+ * fail-closed 默认——无图片能力的上游(如 DeepSeek)保持发送前显式报错,不静默吞图。
*/
export function chatBridgeCapabilitiesForRoute(
upstream: string,
realModel: string,
fallback: ChatBridgeCapabilities = CHAT_BRIDGE_DEFAULT_CAPABILITIES,
): ChatBridgeCapabilities {
- if (realModel !== 'kimi-k3') return fallback;
- try {
- const url = new URL(upstream);
- if (url.protocol !== 'https:' || !MOONSHOT_CHAT_HOSTS.has(url.hostname.toLowerCase())) {
- return fallback;
- }
- } catch {
- return fallback;
- }
+ if (!isVerifiedImageChatRoute(upstream, realModel)) return fallback;
return {
...fallback,
imageInput: 'image_url',
};
}
+function isVerifiedImageChatRoute(upstream: string, realModel: string): boolean {
+ let url: URL;
+ try {
+ url = new URL(upstream);
+ } catch {
+ return false;
+ }
+ if (url.protocol !== 'https:') return false;
+ const host = url.hostname.toLowerCase();
+ if (realModel === 'kimi-k3') return MOONSHOT_CHAT_HOSTS.has(host);
+ if (isDoubaoVisionModel(realModel)) return VOLCENGINE_ARK_CHAT_HOST_RE.test(host);
+ return false;
+}
+
/**
* Chat bridge 上游只收 host 明确构造的 header。绝不把 Codex/ChatGPT 请求 header
* 原样透传,防止账号 id、OpenAI OAuth bearer 或内部 session 元数据泄漏给第三方。