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(plugin): 网关 endpoint 未就绪时隐藏向量与视频模型 (#1818)

zhanghengxdfe874306c90c
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/cindyGatewayReadiness.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/cindyGatewayReadiness.test.ts
new file mode 100644
index 0000000000..960ac5f22f
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/__tests__/cindyGatewayReadiness.test.ts
@@ -0,0 +1,85 @@
+/**
+ * cindyGatewayReadiness.test.ts — 锁住 XD 网关 endpoint 的运行期就绪判据。
+ */
+
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const runtime = vi.hoisted(() => ({
+ canUseCindyGateway: true,
+ gatewayBaseUrl: 'https://gateway.example',
+ appCapabilityReads: 0,
+ endpointReads: 0,
+}));
+
+vi.mock('../../appCapabilities.js', () => ({
+ getAppCapabilities: () => {
+ runtime.appCapabilityReads += 1;
+ return { canUseCindyGateway: runtime.canUseCindyGateway };
+ },
+}));
+
+vi.mock('../../model-access/effectiveEndpoint.js', () => ({
+ effectiveXdGatewayBaseUrl: () => {
+ runtime.endpointReads += 1;
+ return runtime.gatewayBaseUrl;
+ },
+}));
+
+import { isXdGatewayProviderReady } from '../cindyGatewayReadiness';
+
+const XD_CASES: Array<{
+ name: string;
+ canUseCindyGateway: boolean;
+ gatewayBaseUrl: string;
+ expected: boolean;
+}> = [
+ {
+ name: '已登录且 endpoint 已下发 → 就绪',
+ canUseCindyGateway: true,
+ gatewayBaseUrl: 'https://gateway.example',
+ expected: true,
+ },
+ {
+ name: '已登录但 endpoint 尚未下发 → 未就绪',
+ canUseCindyGateway: true,
+ gatewayBaseUrl: '',
+ expected: false,
+ },
+ {
+ name: '已登录但 endpoint 仅含空白 → 未就绪',
+ canUseCindyGateway: true,
+ gatewayBaseUrl: ' \n\t ',
+ expected: false,
+ },
+ {
+ name: '未登录但 endpoint 残留 → 未就绪',
+ canUseCindyGateway: false,
+ gatewayBaseUrl: 'https://gateway.example',
+ expected: false,
+ },
+];
+
+describe('isXdGatewayProviderReady', () => {
+ beforeEach(() => {
+ runtime.canUseCindyGateway = true;
+ runtime.gatewayBaseUrl = 'https://gateway.example';
+ runtime.appCapabilityReads = 0;
+ runtime.endpointReads = 0;
+ });
+
+ it.each(XD_CASES)('$name', ({ canUseCindyGateway, gatewayBaseUrl, expected }) => {
+ runtime.canUseCindyGateway = canUseCindyGateway;
+ runtime.gatewayBaseUrl = gatewayBaseUrl;
+
+ expect(isXdGatewayProviderReady('xd')).toBe(expected);
+ });
+
+ it('非 XD 供应商不依赖 XD 网关状态', () => {
+ runtime.canUseCindyGateway = false;
+ runtime.gatewayBaseUrl = '';
+
+ expect(isXdGatewayProviderReady('other')).toBe(true);
+ expect(runtime.appCapabilityReads).toBe(0);
+ expect(runtime.endpointReads).toBe(0);
+ });
+});
diff --git a/apps/desktop/src/main/cindy-brain/cindyGatewayReadiness.ts b/apps/desktop/src/main/cindy-brain/cindyGatewayReadiness.ts
new file mode 100644
index 0000000000..ec18f82e33
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/cindyGatewayReadiness.ts
@@ -0,0 +1,13 @@
+/**
+ * cindyGatewayReadiness.ts — cindy 槽向量 / 视频供应商的运行期就绪判据。
+ *
+ * XD 是这两个类目当前唯一的网关执行来源;账号能力与随凭据成对下发的
+ * endpoint 必须同时存在,才能把 XD 型号投影进插件清单。
+ */
+import { getAppCapabilities } from '../appCapabilities.js';
+import { effectiveXdGatewayBaseUrl } from '../model-access/effectiveEndpoint.js';
+
+export function isXdGatewayProviderReady(providerId: string): boolean {
+ if (providerId !== 'xd') return true;
+ return getAppCapabilities().canUseCindyGateway && effectiveXdGatewayBaseUrl().trim() !== '';
+}
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index 2ce259c111..605afcba72 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -159,6 +159,7 @@ import {
type CindyCapabilityKind,
type CindyMediaCatalogConfig,
} from './cindyMediaCatalog.js';
+import { isXdGatewayProviderReady } from './cindyGatewayReadiness.js';
import {
GhostCindySlot,
type CindyImageCapabilities,
@@ -2397,12 +2398,12 @@ function getCatalogMediaConfig(kind: CindyCapabilityKind): CindyMediaCatalogConf
// 网关能力在场 —— 未登录本地模式(canUseCindyGateway=false)下 xd 的视频型号
// 不能进清单,否则用户在本地模式钉选/点名视频型号就是"可选但必失败"
// (2026-07 review:与图像的就绪语义对齐)。
- // 向量与视频同口径:通道只有 xd 一家、不经 registry,但要求网关能力在场
- // (本地模式没有网关 key,embedSync 必然 AUTH_FAILED —— 那种型号不该出现在
- // 清单里让用户钉选)。
+ // 向量与视频同口径:通道只有 xd 一家、不经 registry,但要求账号网关能力与
+ // model-access 随凭据成对下发的 endpoint 同时在场。登录同步完成前 / 存量
+ // 手填 key 没有配套 endpoint 时,那种型号不该出现在清单里让用户钉选。
kind === 'image'
? (providerId) => getImageChannelRegistry().isProviderReady(providerId)
- : (providerId) => providerId !== 'xd' || getAppCapabilities().canUseCindyGateway,
+ : isXdGatewayProviderReady,
// 编辑就绪过滤:仅支持生成的来源(supportsEdit: false)的模型不进编辑清单,
// 防用户把该型号钉到 image.edit 偏好后在 editImage 路径拿到确定性 400。
kind === 'image' ? (providerId) => getImageChannelRegistry().isProviderEditReady(providerId) : undefined,