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): 修复 XD 网关向量模型能力投影 (#3806)

Dash5d19150d52fb
diff --git a/apps/desktop/src/main/maker-host/__tests__/activeCatalogXdAvailability.test.ts b/apps/desktop/src/main/maker-host/__tests__/activeCatalogXdAvailability.test.ts
index 15b194b49f..1a9a9e7db3 100644
--- a/apps/desktop/src/main/maker-host/__tests__/activeCatalogXdAvailability.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/activeCatalogXdAvailability.test.ts
@@ -44,6 +44,9 @@ describe('XD 网关权威模型清单重建', () => {
const xd = getActiveCatalog().providers.find((provider) => provider.id === 'xd');
expect(xd?.imageModels).toEqual([]);
expect(xd?.videoModels).toEqual([]);
+ expect(xd?.embeddingModels).toEqual(
+ BUNDLED_CATALOG.providers.find((provider) => provider.id === 'xd')?.embeddingModels,
+ );
});
it('显式空列表保持 XD 模型不可用', () => {
@@ -118,6 +121,20 @@ describe('XD 网关权威模型清单重建', () => {
agents: [],
modalities: { input: ['text', 'image'], output: ['video'] },
},
+ {
+ id: 'voyage/voyage-4',
+ name: 'Voyage 4',
+ mode: 'embedding',
+ availability: 'available',
+ agents: [],
+ },
+ {
+ id: 'voyage/voyage-4-large',
+ name: 'Voyage 4 Large',
+ mode: 'embedding',
+ availability: 'requires_payment',
+ agents: [],
+ },
]);
const activeXd = getActiveCatalog().providers.find((provider) => provider.id === 'xd');
@@ -130,7 +147,8 @@ describe('XD 网关权威模型清单重建', () => {
},
]);
expect(activeXd?.imageDefaults).toEqual({ standard: 'openai/gpt-image-2' });
- expect(activeXd?.embeddingModels).toEqual([]);
+ expect(activeXd?.embeddingModels).toEqual([{ id: 'voyage/voyage-4', name: 'Voyage 4' }]);
+ expect(activeXd?.embeddingDefaults).toEqual({ standard: 'voyage/voyage-4' });
expect(activeXd?.videoModels).toEqual([
{
id: 'bytedance/seedance-2.5',
@@ -142,6 +160,90 @@ describe('XD 网关权威模型清单重建', () => {
expect(xdModels('claude-code')).toEqual([]);
});
+ it('网关明确返回仅付费 embedding 时不保留静态 embedding', () => {
+ const catalog = JSON.parse(JSON.stringify(BUNDLED_CATALOG)) as typeof BUNDLED_CATALOG;
+ const catalogXd = catalog.providers.find((provider) => provider.id === 'xd');
+ if (!catalogXd) throw new Error('missing XD provider fixture');
+ catalogXd.embeddingModels = [{ id: 'voyage/voyage-4', name: 'Voyage 4' }];
+ catalogXd.embeddingDefaults = { standard: 'voyage/voyage-4' };
+
+ setActiveCatalog(catalog);
+ setXdGatewayModels([
+ {
+ id: 'voyage/voyage-4',
+ name: 'Voyage 4',
+ mode: 'embedding',
+ availability: 'requires_payment',
+ agents: [],
+ },
+ ], { authoritative: true });
+
+ const activeXd = getActiveCatalog().providers.find((provider) => provider.id === 'xd');
+ expect(activeXd?.embeddingModels).toBeUndefined();
+ expect(activeXd?.embeddingDefaults).toBeUndefined();
+
+ setXdGatewayModels([], {
+ authoritative: false,
+ preservePaymentRequiredRoutes: true,
+ });
+
+ const afterRefreshFailure = getActiveCatalog().providers.find((provider) => provider.id === 'xd');
+ expect(afterRefreshFailure?.embeddingModels).toBeUndefined();
+ expect(afterRefreshFailure?.embeddingDefaults).toBeUndefined();
+ });
+
+ it('网关 embedding 缺少 availability 时不解锁静态 embedding', () => {
+ const catalog = JSON.parse(JSON.stringify(BUNDLED_CATALOG)) as typeof BUNDLED_CATALOG;
+ const catalogXd = catalog.providers.find((provider) => provider.id === 'xd');
+ if (!catalogXd) throw new Error('missing XD provider fixture');
+ catalogXd.embeddingModels = [{ id: 'voyage/voyage-4', name: 'Voyage 4' }];
+ catalogXd.embeddingDefaults = { standard: 'voyage/voyage-4' };
+
+ setActiveCatalog(catalog);
+ setXdGatewayModels([
+ {
+ id: 'voyage/voyage-4',
+ name: 'Voyage 4',
+ mode: 'embedding',
+ agents: [],
+ },
+ ]);
+
+ const activeXd = getActiveCatalog().providers.find((provider) => provider.id === 'xd');
+ expect(activeXd?.embeddingModels).toBeUndefined();
+ expect(activeXd?.embeddingDefaults).toBeUndefined();
+ });
+
+ it('网关权威空快照清除静态 embedding', () => {
+ const catalog = JSON.parse(JSON.stringify(BUNDLED_CATALOG)) as typeof BUNDLED_CATALOG;
+ const catalogXd = catalog.providers.find((provider) => provider.id === 'xd');
+ if (!catalogXd) throw new Error('missing XD provider fixture');
+ catalogXd.embeddingModels = [{ id: 'voyage/voyage-4', name: 'Voyage 4' }];
+ catalogXd.embeddingDefaults = { standard: 'voyage/voyage-4' };
+
+ setActiveCatalog(catalog);
+ setXdGatewayModels([], { authoritative: true });
+
+ const activeXd = getActiveCatalog().providers.find((provider) => provider.id === 'xd');
+ expect(activeXd?.embeddingModels).toBeUndefined();
+ expect(activeXd?.embeddingDefaults).toBeUndefined();
+ });
+
+ it('账号边界等待新快照时不回退到静态 embedding', () => {
+ const catalog = JSON.parse(JSON.stringify(BUNDLED_CATALOG)) as typeof BUNDLED_CATALOG;
+ const catalogXd = catalog.providers.find((provider) => provider.id === 'xd');
+ if (!catalogXd) throw new Error('missing XD provider fixture');
+ catalogXd.embeddingModels = [{ id: 'voyage/voyage-4', name: 'Voyage 4' }];
+ catalogXd.embeddingDefaults = { standard: 'voyage/voyage-4' };
+
+ setActiveCatalog(catalog);
+ setXdGatewayModels([], { suppressEmbeddingFallback: true });
+
+ const activeXd = getActiveCatalog().providers.find((provider) => provider.id === 'xd');
+ expect(activeXd?.embeddingModels).toBeUndefined();
+ expect(activeXd?.embeddingDefaults).toBeUndefined();
+ });
+
it('v3 未声明 agents 的模型不进入任何 runtime', () => {
setActiveCatalog(BUNDLED_CATALOG);
setXdGatewayModels([{ id: 'brand-new-model' }]);
diff --git a/apps/desktop/src/main/maker-host/active-catalog.ts b/apps/desktop/src/main/maker-host/active-catalog.ts
index 9ea94a9b2a..366c616c44 100644
--- a/apps/desktop/src/main/maker-host/active-catalog.ts
+++ b/apps/desktop/src/main/maker-host/active-catalog.ts
@@ -198,6 +198,14 @@ export interface XdGatewayModelInfo {
let xdGatewayModels: XdGatewayModelInfo[] = [];
/** 当前账号最近一次 `/models` 成功响应;false 时清单缺席不能作为模型不存在的 deny 证据。 */
let xdGatewayModelsAuthoritative = false;
+/**
+ * 最近一次网关快照是否已把 embedding 能力交给网关判定。
+ *
+ * 刷新失败时会把过期的 requires_payment 行从活动目录移除;即使因此暂时没有
+ * embedding 条目,也不能再回退到 bundled embedding。账号边界显式置为 true,
+ * 直到新账号收到首个权威快照;测试清理和非账号的空快照才会重置它。
+ */
+let xdGatewayEmbeddingFallbackSuppressed = false;
/**
* 最近一次成功 v5 响应明确拒绝的 XD 对话路由。
*
@@ -865,6 +873,7 @@ function withEmptyModels(p: Provider): Provider {
function projectXdGatewayMediaModels(
provider: Provider,
gatewayModels: readonly XdGatewayModelInfo[],
+ options: { authoritative: boolean },
): Provider {
const imageModels = gatewayModels
.filter((model) => model.mode === 'image_generation')
@@ -882,17 +891,39 @@ function projectXdGatewayMediaModels(
...(model.availability ? { availability: model.availability } : {}),
...(model.modalities ? { modalities: model.modalities } : {}),
}));
+ // Embedding is a provider-level capability, so it must be projected separately from
+ // agent-bound `models`. A gateway snapshot that explicitly includes embedding models is
+ // authoritative for the current account; payment-only entries must not unlock chat indexing.
+ const embeddingModels = gatewayModels
+ .filter((model) => model.mode === 'embedding' && model.availability === 'available')
+ .map((model) => ({
+ id: model.id,
+ name: model.name ?? model.id,
+ }));
+ const hasEmbeddingEntries = gatewayModels.some((model) => model.mode === 'embedding');
const identity = { ...provider };
delete identity.imageModels;
delete identity.imageDefaults;
delete identity.videoModels;
delete identity.videoDefaults;
+ if (
+ options.authoritative ||
+ hasEmbeddingEntries ||
+ xdGatewayEmbeddingFallbackSuppressed
+ ) {
+ delete identity.embeddingModels;
+ delete identity.embeddingDefaults;
+ }
return {
...identity,
imageModels,
videoModels,
+ ...(embeddingModels.length > 0 ? { embeddingModels } : {}),
...(imageModels[0] ? { imageDefaults: { standard: imageModels[0].id } } : {}),
...(videoModels[0] ? { videoDefaults: { standard: videoModels[0].id } } : {}),
+ ...(embeddingModels[0]
+ ? { embeddingDefaults: { standard: embeddingModels[0].id } }
+ : {}),
};
}
@@ -1268,7 +1299,12 @@ function computeMerged(): Catalog {
)
.map(({ model }) => model);
}
- return { ...projectXdGatewayMediaModels(p, gwModels), models };
+ return {
+ ...projectXdGatewayMediaModels(p, gwModels, {
+ authoritative: xdGatewayModelsAuthoritative,
+ }),
+ models,
+ };
});
if (providers === b.providers) return b; // 无 augment、无 custom → 原样返回
@@ -1529,12 +1565,21 @@ export function setDiscoveredProviderMediaModels(
*/
export function setXdGatewayModels(
models: XdGatewayModelInfo[],
- options?: { authoritative?: boolean; preservePaymentRequiredRoutes?: boolean },
+ options?: {
+ authoritative?: boolean;
+ preservePaymentRequiredRoutes?: boolean;
+ suppressEmbeddingFallback?: boolean;
+ },
): void {
xdGatewayModels = [...models];
if (options?.authoritative !== undefined) {
xdGatewayModelsAuthoritative = options.authoritative;
}
+ if (options?.authoritative === true || options?.suppressEmbeddingFallback === true) {
+ xdGatewayEmbeddingFallbackSuppressed = true;
+ } else if (models.length === 0 && options?.preservePaymentRequiredRoutes !== true) {
+ xdGatewayEmbeddingFallbackSuppressed = false;
+ }
if (options?.preservePaymentRequiredRoutes !== true) {
xdGatewayPaymentRequiredRoutes = new Set(
models.flatMap((model) =>
diff --git a/apps/desktop/src/main/model-access/index.ts b/apps/desktop/src/main/model-access/index.ts
index 917816f34b..47f1557cc5 100644
--- a/apps/desktop/src/main/model-access/index.ts
+++ b/apps/desktop/src/main/model-access/index.ts
@@ -181,6 +181,7 @@ function applyGatewayModels(
authenticatedUserId?: string;
authoritative?: boolean;
preservePaymentRequiredRoutes?: boolean;
+ suppressEmbeddingFallback?: boolean;
} = {},
): void {
// 同一次 /models 响应建立 XD 模型与价格投影。空成功响应会同时清空模型和价格;请求失败不会调用本函数,
@@ -221,6 +222,7 @@ function applyGatewayModels(
setXdGatewayModels(models, {
authoritative: options.authoritative ?? false,
preservePaymentRequiredRoutes: options.preservePaymentRequiredRoutes,
+ suppressEmbeddingFallback: options.suppressEmbeddingFallback,
});
}
@@ -364,7 +366,7 @@ function getSync(): CredentialsSync {
preservePaymentRequiredRoutes: shouldPreservePaymentRequiredRoutes(status),
});
} else if (['disabled', 'unsupported', 'idle'].includes(status.state)) {
- applyGatewayModels([]);
+ applyGatewayModels([], { suppressEmbeddingFallback: true });
}
},
log: {
@@ -472,7 +474,7 @@ export function initModelAccess(): void {
authGeneration++;
accountTier = null;
// 旧身份模型清单不能跨账号/区域继续显示;新身份拉取成功后再注入。
- applyGatewayModels([]);
+ applyGatewayModels([], { suppressEmbeddingFallback: true });
}
lastAuthUserId = isAuthenticated ? (userId ?? lastAuthUserId) : null;
lastAuthRealm = isAuthenticated ? (realm ?? lastAuthRealm) : null;
diff --git a/packages/model-providers/src/__tests__/modelAccessValidator.test.ts b/packages/model-providers/src/__tests__/modelAccessValidator.test.ts
index d4127dc11f..5cb6cfd71a 100644
--- a/packages/model-providers/src/__tests__/modelAccessValidator.test.ts
+++ b/packages/model-providers/src/__tests__/modelAccessValidator.test.ts
@@ -332,6 +332,43 @@ describe('model access catalog contract', () => {
}
});
+ it('v4/v5 允许 provider-level embedding 模型使用空 agents 且省略 contextWindow', () => {
+ const embeddingModel = {
+ id: 'voyage/voyage-4',
+ name: 'Voyage 4',
+ mode: 'embedding',
+ currency: 'CNY',
+ agents: [],
+ } as const;
+
+ expect(
+ parseListModelsResponse({
+ schemaVersion: MODEL_ACCESS_CATALOG_SCHEMA_VERSION,
+ models: [embeddingModel],
+ }).ok,
+ ).toBe(true);
+ expect(
+ parseListModelsResponse({
+ schemaVersion: MODEL_ACCESS_CATALOG_V5_SCHEMA_VERSION,
+ accountTier: 'paid',
+ models: [{ ...embeddingModel, availability: 'available' }],
+ }).ok,
+ ).toBe(true);
+ expect(
+ parseListModelsResponse({
+ schemaVersion: MODEL_ACCESS_CATALOG_V3_SCHEMA_VERSION,
+ models: [embeddingModel],
+ }).ok,
+ ).toBe(false);
+ expectReject(
+ {
+ schemaVersion: MODEL_ACCESS_CATALOG_SCHEMA_VERSION,
+ models: [{ ...embeddingModel, agents: ['codex'] }],
+ },
+ 'response.models[0].agents must be empty',
+ );
+ });
+
it.each(['CNY', 'USD'] as const)('accepts the supported %s currency', (currency) => {
const result = parseListModelsResponse({
...VALID_RESPONSE,
diff --git a/packages/model-providers/src/modelAccessValidator.ts b/packages/model-providers/src/modelAccessValidator.ts
index c0bf5cdd58..b88e982bc0 100644
--- a/packages/model-providers/src/modelAccessValidator.ts
+++ b/packages/model-providers/src/modelAccessValidator.ts
@@ -467,19 +467,21 @@ function modelEntryError(
);
if (defaultError) return defaultError;
}
- const isV4MediaModel =
+ const isV4StandaloneModel =
schemaVersion === MODEL_ACCESS_CATALOG_SCHEMA_VERSION &&
- (value.mode === 'image_generation' || value.mode === 'video_generation');
- if (isV4MediaModel && supportedAgents.length > 0) {
- return `${path}.agents must be empty for a v4 Gateway media mode`;
+ (value.mode === 'image_generation' ||
+ value.mode === 'video_generation' ||
+ value.mode === 'embedding');
+ if (isV4StandaloneModel && supportedAgents.length > 0) {
+ return `${path}.agents must be empty for a v4 Gateway standalone capability mode`;
}
if (
(schemaVersion === MODEL_ACCESS_CATALOG_V3_SCHEMA_VERSION ||
schemaVersion === MODEL_ACCESS_CATALOG_SCHEMA_VERSION) &&
supportedAgents.length === 0 &&
- !isV4MediaModel
+ !isV4StandaloneModel
) {
- return `${path}.agents may be empty only for a v4 Gateway media mode`;
+ return `${path}.agents may be empty only for a v4 Gateway standalone capability mode`;
}
for (const [key, max] of [
@@ -509,7 +511,7 @@ function modelEntryError(
}
if (
(schemaVersion === MODEL_ACCESS_CATALOG_V3_SCHEMA_VERSION ||
- (schemaVersion === MODEL_ACCESS_CATALOG_SCHEMA_VERSION && !isV4MediaModel)) &&
+ (schemaVersion === MODEL_ACCESS_CATALOG_SCHEMA_VERSION && !isV4StandaloneModel)) &&
value.contextWindow === undefined
) {
return `${path}.contextWindow is required for schema version 3 and v4 chat models`;