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): expose connected provider media models to Art (#3461)

Chris Zhangd5e4dbf16885
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/pluginMediaCatalogFallback.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/pluginMediaCatalogFallback.test.ts
new file mode 100644
index 0000000000..07e4d9a6a3
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/__tests__/pluginMediaCatalogFallback.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it, vi } from 'vitest';
+
+import { loadPluginMediaAvailability } from '../pluginMediaCatalogFallback.js';
+
+describe('loadPluginMediaAvailability', () => {
+ it('keeps a ready local video catalog when Gateway discovery fails', async () => {
+ await expect(
+ loadPluginMediaAvailability('video', 1, async () => {
+ throw new Error('gateway unavailable');
+ }),
+ ).resolves.toEqual({ models: [], unavailable: [], candidateCount: 0 });
+ });
+
+ it('preserves the Gateway failure when no local video fallback exists', async () => {
+ const load = vi.fn(async () => {
+ throw new Error('gateway unavailable');
+ });
+
+ await expect(loadPluginMediaAvailability('video', 0, load)).rejects.toThrow(
+ 'gateway unavailable',
+ );
+ });
+
+ it('never applies the video fallback to image catalogs', async () => {
+ await expect(
+ loadPluginMediaAvailability('image', 1, async () => {
+ throw new Error('gateway unavailable');
+ }),
+ ).rejects.toThrow('gateway unavailable');
+ });
+});
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index bb3bdc05db..96de840e2f 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -406,6 +406,7 @@ import {
configureProviderMediaRuntime,
listProviderMediaModels,
} from '../cindy-media/providerMediaRuntime.js';
+import { loadPluginMediaAvailability } from './pluginMediaCatalogFallback.js';
import * as ledger from '../cindy-media/ledger.js';
import { ingestMedia, supportedMime } from '../cindy-media/ingest.js';
import { captureMediaRefCompensationScope } from '../cindy-media/refCompensationJournal.js';
@@ -3443,7 +3444,9 @@ function getMediaPreferenceConfig(
const providers = new Map(
getActiveCatalog().providers.map((provider) => [provider.id, provider] as const),
);
- const providerModels: CindyMediaPreferenceModel[] = listProviderMediaModels()
+ const providerModels: CindyMediaPreferenceModel[] = (kind === 'video'
+ ? listLocalProviderVideoModels()
+ : listProviderMediaModels())
.filter(
(model) =>
model.mode === (kind === 'image' ? 'image_generation' : 'video_generation') &&
@@ -3637,10 +3640,25 @@ async function getGhostConfigurableMediaModels(
try {
// 类型目录返回该大类所有至少有一种可执行操作的模型;具体支持动作由
// Gateway modalities 透传给插件判断,不能把插件声明的多个动作取交集。
- const availability = await listExecutableMediaModels();
+ // The generic media-access snapshot is Gateway-first and historically only
+ // carried image-provider models. Video providers are host-owned (the video
+ // registry executes them), so add their local projection explicitly and do
+ // not let an unavailable Gateway snapshot hide an otherwise ready xAI list.
const mode = type === 'image' ? 'image_generation' : 'video_generation';
const videoRegistry = type === 'video' ? getVideoProviderRegistry() : null;
- const candidates = availability.models.filter(
+ const localVideoModels = type === 'video' ? listLocalProviderVideoModels() : [];
+ const availability = await loadPluginMediaAvailability(
+ type,
+ localVideoModels.length,
+ () => listExecutableMediaModels(),
+ );
+ const allModels = [...availability.models, ...localVideoModels].filter(
+ (model, index, models) =>
+ models.findIndex(
+ (candidate) => candidate.id === model.id && candidate.providerId === model.providerId,
+ ) === index,
+ );
+ const candidates = allModels.filter(
(model) =>
model.mode === mode &&
(type !== 'video' ||
@@ -4085,23 +4103,72 @@ function listLocalProviderMediaModels() {
}
const supportsEdit = getImageChannelRegistry().isProviderEditReady(provider.id);
return (provider.imageModels ?? []).flatMap((model) => {
+ if (isModelDisabled(access, provider.id, model.id)) {
+ return [];
+ }
+ // Legacy/provider catalogs may only carry id/name. The channel registry is
+ // the executable capability source in that case: every registered image
+ // channel accepts text generation, and editable channels additionally
+ // accept an image input. Without this normalization, xAI's valid image
+ // models are visible in Settings but disappear from Art's media catalog.
+ const modalities = model.modalities ?? {
+ input: supportsEdit ? ['text', 'image'] : ['text'],
+ output: ['image'],
+ };
+ if (!modalities.output.includes('image')) return [];
+ const input = supportsEdit
+ ? [...modalities.input]
+ : modalities.input.filter((modality) => modality !== 'image');
+ return [
+ {
+ id: model.id,
+ name: model.name,
+ providerId: provider.id,
+ mode: 'image_generation' as const,
+ modalities: { input, output: [...modalities.output] },
+ ...(model.officialDocs ? { officialDocs: model.officialDocs } : {}),
+ },
+ ];
+ });
+ });
+}
+
+/**
+ * Video models are executed by the host video registry rather than the image
+ * provider runtime. Keep their catalog projection beside the image projection
+ * so Art can read the same provider-owned models that Settings displays.
+ */
+function listLocalProviderVideoModels() {
+ const access = readModelDisableOverrides();
+ const registry = getVideoProviderRegistry();
+ if (!registry) return [];
+ return getActiveCatalog().providers.flatMap((provider) => {
+ if (
+ provider.id === 'xd' ||
+ isProviderDisabled(access, provider.id) ||
+ !isVideoCatalogProviderReady(provider.id)
+ ) {
+ return [];
+ }
+ return (provider.videoModels ?? []).flatMap((model) => {
if (
- !model.modalities ||
isModelDisabled(access, provider.id, model.id) ||
- !model.modalities.output.includes('image')
+ !registry.hasAlias(model.id, provider.id)
) {
return [];
}
- const input = supportsEdit
- ? [...model.modalities.input]
- : model.modalities.input.filter((modality) => modality !== 'image');
+ const modalities = model.modalities ?? {
+ input: ['text', 'image'],
+ output: ['video'],
+ };
+ if (!modalities.output.includes('video')) return [];
return [
{
id: model.id,
name: model.name,
providerId: provider.id,
- mode: 'image_generation' as const,
- modalities: { input, output: [...model.modalities.output] },
+ mode: 'video_generation' as const,
+ modalities: { input: [...modalities.input], output: [...modalities.output] },
...(model.officialDocs ? { officialDocs: model.officialDocs } : {}),
},
];
diff --git a/apps/desktop/src/main/cindy-brain/pluginMediaCatalogFallback.ts b/apps/desktop/src/main/cindy-brain/pluginMediaCatalogFallback.ts
new file mode 100644
index 0000000000..058f522d08
--- /dev/null
+++ b/apps/desktop/src/main/cindy-brain/pluginMediaCatalogFallback.ts
@@ -0,0 +1,20 @@
+import type { ExecutableMediaModelsResult } from '../model-access/mediaModels.js';
+import type { GhostMediaModelType } from '../../shared/ghost.js';
+
+/**
+ * Provider video models are executable without the Gateway catalog. Preserve
+ * that local fallback, but never turn a genuine catalog outage into a
+ * successful empty response when no local video model can be offered.
+ */
+export async function loadPluginMediaAvailability(
+ type: GhostMediaModelType,
+ localVideoModelCount: number,
+ load: () => Promise<ExecutableMediaModelsResult>,
+): Promise<ExecutableMediaModelsResult> {
+ try {
+ return await load();
+ } catch (error) {
+ if (type !== 'video' || localVideoModelCount === 0) throw error;
+ return { models: [], unavailable: [], candidateCount: 0 };
+ }
+}
diff --git a/apps/desktop/src/main/model-access/__tests__/mediaModels.test.ts b/apps/desktop/src/main/model-access/__tests__/mediaModels.test.ts
index a134cfc662..4564634e83 100644
--- a/apps/desktop/src/main/model-access/__tests__/mediaModels.test.ts
+++ b/apps/desktop/src/main/model-access/__tests__/mediaModels.test.ts
@@ -127,6 +127,22 @@ describe('listAvailableMediaModels', () => {
]);
});
+ it('xAI provider 图片模型在媒体目录中保留来源身份', async () => {
+ listProviderMediaModelsMock.mockReturnValue([
+ {
+ id: 'xai/grok-imagine-image',
+ name: 'Grok Imagine Image',
+ providerId: 'xai',
+ mode: 'image_generation',
+ modalities: { input: ['text', 'image'], output: ['image'] },
+ },
+ ]);
+
+ await expect(listAvailableMediaModels('image.edit')).resolves.toContainEqual(
+ expect.objectContaining({ id: 'xai/grok-imagine-image', providerId: 'xai' }),
+ );
+ });
+
it('叠加客户端现有 XD provider/model 停用准入', async () => {
readModelDisableOverridesMock.mockReturnValueOnce({
disabledModels: { 'xd:image-without-guide': true },