Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(media): 修复旧插件选型和视频提交边界
nana5d40f17fcd3f
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/customImageChannel.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/customImageChannel.test.tsindex ed7f1effc7..9c4755460e 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/customImageChannel.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/customImageChannel.test.ts@@ -6,6 +6,7 @@ import { buildUserProvider, type Provider } from '@cindy/model-providers';import { createCustomImageChannel, registerCustomImageChannels } from '../customImageChannel.js';import { pruneDynamicImageChannels } from '../byokImageChannel.js';import { ImageChannelRegistry } from '../imageChannelRegistry.js';+import { filterLegacyCindyMediaConfig } from '../cindyMediaCatalog.js';const MODEL = 'team/gpt-image-2.5-sunburst';const PNG = Buffer.from('89504e470d0a1a0a', 'hex');@@ -83,6 +84,21 @@ function harness(initial = provider()) {}describe('standalone custom OpenAI Images', () => {+ it('keeps URL-capable custom sources in Core but out of legacy image preferences', () => {+ const h = harness();+ const registry = new ImageChannelRegistry();+ registry.register('relay', h.channel);+ registry.register('existing', { ready: () => true, generateImage: vi.fn(), editImage: vi.fn() });+ const custom = { id: 'media:relay:image', modelId: MODEL, providerId: 'relay', label: 'Custom', supportsEdit: true };+ const existing = { ...custom, id: 'media:existing:image', providerId: 'existing', label: 'Existing' };+ const config = { models: [custom, existing], defaults: { standard: custom.id, draft: custom.id, best: custom.id } };+ const legacy = filterLegacyCindyMediaConfig(config, model => registry.isProviderLegacyReady(model.providerId, model.modelId));+ expect(legacy).toEqual({ models: [existing], defaults: { standard: existing.id, draft: existing.id, best: existing.id } });+ expect(registry.isProviderReady('relay', MODEL)).toBe(true);+ expect(config.models).toEqual([custom, existing]);+ expect(h.fetchImplementation).not.toHaveBeenCalled();+ });+it.each(['claude-code', 'codex'] as const)('binds duplicate model IDs to the explicitly enabled Images connection, not %s', async (agent) => {const source = buildUserProvider({id: 'relay', name: 'Relay', auth: { method: 'apiKey' },diff --git a/apps/desktop/src/main/cindy-brain/customImageChannel.ts b/apps/desktop/src/main/cindy-brain/customImageChannel.tsindex 470997fe1c..2cfd767d7f 100644--- a/apps/desktop/src/main/cindy-brain/customImageChannel.ts+++ b/apps/desktop/src/main/cindy-brain/customImageChannel.ts@@ -86,6 +86,7 @@ export function createCustomImageChannel(opts: CustomImageChannelOptions): Imagereturn {imageProtocol: 'openai',+ legacyCompatible: false,ready,isModelReady: (model) => connection(model) !== null,generateImage: (params) => invoke('generate', { ...params, imagePaths: [] }),diff --git a/apps/desktop/src/main/cindy-brain/imageChannelRegistry.ts b/apps/desktop/src/main/cindy-brain/imageChannelRegistry.tsindex c94627c765..90a804729c 100644--- a/apps/desktop/src/main/cindy-brain/imageChannelRegistry.ts+++ b/apps/desktop/src/main/cindy-brain/imageChannelRegistry.ts@@ -65,6 +65,8 @@ export function decodeImageResponse(res: ImageChannelResult): { buffer: Buffer;*/export interface ImageChannel {imageProtocol?: ImageProtocol;+ /** False for Core-only channels whose URL results the legacy decoder cannot consume. */+ legacyCompatible?: boolean;/** 执行凭证是否就绪。false ⇒ 该来源整段不进 cindy 白名单。 */ready(): boolean;/** A multi-runtime connection can be executable for only some of its image models. */@@ -119,6 +121,12 @@ export class ImageChannelRegistry {(modelId === undefined || channel.isModelReady?.(modelId) !== false);}+ /** The frozen synchronous plugin API only accepts channels with legacy results. */+ isProviderLegacyReady(providerId: string, modelId?: string): boolean {+ return this.channels.get(providerId)?.legacyCompatible !== false &&+ this.isProviderReady(providerId, modelId);+ }+/** 编辑操作清单派生用:就绪且 supportsEdit !== false。 */isProviderEditReady(providerId: string, modelId?: string): boolean {const ch = this.channels.get(providerId);diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex 362fc9be0a..ecc693f72d 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -3621,8 +3621,7 @@ function getCatalogMediaConfig(// managed URL/base64 handling; keep new sources out of the frozen legacy API.kind === 'image'? (providerId) =>- !registeredCustomImageAccounts.has(providerId) &&- (imageRegistry?.isProviderReady(providerId) ?? false)+ imageRegistry?.isProviderLegacyReady(providerId) ?? false: kind === 'video'? isVideoCatalogProviderReady: isXdGatewayProviderReady,@@ -4672,12 +4671,12 @@ export function getGhostCindySlot(): GhostCindySlot {const videoRegistry = capability.startsWith('video.') ? getVideoProviderRegistry() : null;// Core 专用选型不能交给旧执行器。复用存量配置迁移,确保回退后// 用户保存的 provider + modelId 与实际执行一致,不影响 Core 清单。- const executableConfig = capability.startsWith('video.')- ? filterLegacyCindyMediaConfig(- config,- (model) => videoRegistry?.hasAlias(model.modelId, model.providerId) ?? false,- )- : config;+ const executableConfig = filterLegacyCindyMediaConfig(+ config,+ (model) => capability.startsWith('video.')+ ? videoRegistry?.hasAlias(model.modelId, model.providerId) ?? false+ : getImageChannelRegistry().isProviderLegacyReady(model.providerId, model.modelId),+ );const selected = resolveAndMigrateGhostMediaPreference(ghostId,mediaCapability,diff --git a/apps/desktop/src/main/cindy-media/__tests__/customVideoProtocol.test.ts b/apps/desktop/src/main/cindy-media/__tests__/customVideoProtocol.test.tsindex 81b0e0fa19..0d5186ae1b 100644--- a/apps/desktop/src/main/cindy-media/__tests__/customVideoProtocol.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/customVideoProtocol.test.ts@@ -51,7 +51,7 @@ describe('custom xAI Videos protocol', () => {]) expect(videoConnectionRevision('relay', model.id, changed)).not.toBe(revision);});- it.each([{ fps: 30 }, { audio: false }, { duration: 16 }, { duration: 1.5 }, { resolution: '4k' }, { image: { url: 'https://example.com/p.png' } }])('rejects unsupported generation parameters before payment: %j', extra => {+ it.each([{ fps: 30 }, { audio: false }, { duration: 16 }, { duration: 1.5 }, { resolution: '4k' }, { resolution: ['480p'] }, { aspect_ratio: ['16:9'] }, { image: { url: 'https://example.com/p.png' } }])('rejects unsupported generation parameters before payment: %j', extra => {expect(() => validateCustomVideoBody({ prompt: 'cat', ...extra }, false)).toThrow();});it('requires exactly one image and leaves implicit aspect ratio to the upstream', () => {diff --git a/apps/desktop/src/main/cindy-media/__tests__/invocationService.test.ts b/apps/desktop/src/main/cindy-media/__tests__/invocationService.test.tsindex 0d5ae01e11..f566cc7ae4 100644--- a/apps/desktop/src/main/cindy-media/__tests__/invocationService.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/invocationService.test.ts@@ -45,6 +45,7 @@ const mocks = vi.hoisted(() => ({dbOwnerId: 'media-user-0',transitionDbs: [] as unknown[],failTransitionTo: null as string | null,+ onClaim: vi.fn(),recover: vi.fn<(owner: string, db: unknown) => Promise<number>>(async () => 0),prune: vi.fn(async () => undefined),rows: new Map<string, Record<string, unknown>>(),@@ -184,6 +185,7 @@ vi.mock('../mediaInvocationStore.js', () => ({const row = mocks.rows.get(id);if (!row || row.owner !== owner || row.state !== from) return false;row.state = to;+ if (to === 'submitting') mocks.onClaim();row.updatedAt = Date.now();if (taskId) row.taskId = taskId;if (responseJson) row.responseJson = responseJson;@@ -280,6 +282,7 @@ describe('Cindy Core media invocation state and security boundary', () => {mocks.providerModel.mockReset();mocks.providerInvoke.mockReset();mocks.videoConnection.mockReset();+ mocks.onClaim.mockReset();mocks.guide.mockReset();mocks.outboundFetch.mockReset();mocks.release.mockClear();@@ -324,6 +327,49 @@ describe('Cindy Core media invocation state and security boundary', () => {return connection;}+ it.each(['reference-read', 'claim'] as const)('rechecks custom video availability after %s before paying, and preserves prepared', async boundary => {+ setupCustomVideo();+ const p = await callCindyMedia({ action: 'prepare', providerId: 'relay', modelId: 'private-video', capability: 'video.image_to_video' });+ const invocationId = p.invocation_id as string;+ const stopSource = () => { mocks.providerModel.mockReturnValue(null); };+ mocks.readBlob.mockImplementation(async () => {+ if (boundary === 'reference-read') stopSource();+ return { buffer: PNG, mimeType: 'image/png' };+ });+ if (boundary === 'claim') mocks.onClaim.mockImplementationOnce(stopSource);+ expect(await callCindyMedia({ action: 'request', invocationId, body: {+ prompt: 'cat waves', image: { url: `cindy-media://blobs/${'a'.repeat(64)}.png` },+ } })).toMatchObject({ errorCode: 'MODEL_NOT_AVAILABLE', outcomeKnown: true });+ expect(mocks.outboundFetch).not.toHaveBeenCalled();+ expect(mocks.rows.get(invocationId)?.state).toBe('prepared');+ });++ it('can retrieve an already paid custom video after its model is disabled', async () => {+ setupCustomVideo();+ const p = await callCindyMedia({ action: 'prepare', providerId: 'relay', modelId: 'private-video', capability: 'video.generate' });+ const invocationId = p.invocation_id as string;+ mocks.outboundFetch.mockResolvedValueOnce(Response.json({ request_id: 'paid-task' }))+ .mockResolvedValueOnce(Response.json({ status: 'done', video: { url: '/videos/paid-task/content' } }))+ .mockResolvedValueOnce(new Response(MP4, { headers: { 'content-type': 'video/mp4' } }));+ mocks.ingestMedia.mockResolvedValue({ url: `cindy-media://blobs/${'a'.repeat(64)}.mp4` });+ await callCindyMedia({ action: 'request', invocationId, body: { prompt: 'cat' } });+ mocks.providerModel.mockReturnValue(null);+ expect(await callCindyMedia({ action: 'poll', invocationId })).toMatchObject({ status: 'complete' });+ expect(mocks.outboundFetch.mock.calls.filter(([, init]) => init.method === 'POST')).toHaveLength(1);+ });++ it.each(['video/mp4', 'audio/mpeg', 'image/gif'])('rejects %s as an image-to-video reference before claiming or paying', async mimeType => {+ setupCustomVideo();+ mocks.readBlob.mockResolvedValue({ buffer: PNG, mimeType });+ const p = await callCindyMedia({ action: 'prepare', providerId: 'relay', modelId: 'private-video', capability: 'video.image_to_video' });+ const invocationId = p.invocation_id as string;+ expect(await callCindyMedia({ action: 'request', invocationId, body: {+ prompt: 'cat waves', image: { url: `cindy-media://blobs/${'a'.repeat(64)}.png` },+ } })).toMatchObject({ errorCode: mimeType === 'image/gif' ? 'MEDIA_INPUT_INVALID' : 'REQUEST_INVALID' });+ expect(mocks.outboundFetch).not.toHaveBeenCalled();+ expect(mocks.rows.get(invocationId)?.state).toBe('prepared');+ });+it.each([['video.generate', false], ['video.image_to_video', false], ['video.generate', true], ['video.image_to_video', true]] as const)('custom %s persists one paid task and ingests video (private content=%s)', async (capability, privateContent) => {setupCustomVideo();mocks.readBlob.mockResolvedValue({ buffer: PNG, mimeType: 'image/png' });diff --git a/apps/desktop/src/main/cindy-media/customVideoProtocol.ts b/apps/desktop/src/main/cindy-media/customVideoProtocol.tsindex e35c66e0bb..93087f829d 100644--- a/apps/desktop/src/main/cindy-media/customVideoProtocol.ts+++ b/apps/desktop/src/main/cindy-media/customVideoProtocol.ts@@ -65,8 +65,8 @@ export function validateCustomVideoBody(body: Record<string, unknown>, image: boif (Object.keys(body).some(key => !allowed.has(key))) throw new Error('视频请求包含当前协议不支持的字段');if (typeof body.prompt !== 'string' || !body.prompt.trim()) throw new Error('视频请求必须提供 prompt');if (body.duration !== undefined && (!Number.isInteger(body.duration) || Number(body.duration) < 1 || Number(body.duration) > 15)) throw new Error('视频时长必须为 1–15 秒的整数');- if (body.resolution !== undefined && !['480p', '720p', '1080p'].includes(String(body.resolution))) throw new Error('视频分辨率不受支持');- if (body.aspect_ratio !== undefined && !['16:9', '9:16', '1:1', '4:3', '3:4', '3:2', '2:3'].includes(String(body.aspect_ratio))) throw new Error('视频画幅不受支持');+ if (body.resolution !== undefined && (typeof body.resolution !== 'string' || !['480p', '720p', '1080p'].includes(body.resolution))) throw new Error('视频分辨率不受支持');+ if (body.aspect_ratio !== undefined && (typeof body.aspect_ratio !== 'string' || !['16:9', '9:16', '1:1', '4:3', '3:4', '3:2', '2:3'].includes(body.aspect_ratio))) throw new Error('视频画幅不受支持');if (image) {const ref = body.image as Record<string, unknown> | undefined;if (!ref || Array.isArray(ref) || Object.keys(ref).length !== 1 || typeof ref.url !== 'string' || !ref.url) throw new Error('图生视频必须提供一张图片: image: {url}');diff --git a/apps/desktop/src/main/cindy-media/invocationService.ts b/apps/desktop/src/main/cindy-media/invocationService.tsindex 8d14699780..27eb43565f 100644--- a/apps/desktop/src/main/cindy-media/invocationService.ts+++ b/apps/desktop/src/main/cindy-media/invocationService.ts@@ -76,6 +76,7 @@ interface MediaConnection {pathPrefix?: string;headers?: Record<string, string>;assertCurrent?(): void;+ beforeSubmit?(): void;}class MediaInvocationError extends Error {@@ -275,7 +276,16 @@ function resolveInvocationConnection(invocation: StoredMediaInvocation): MediaCocatch { throw new MediaInvocationError('CONNECTION_CHANGED', '视频连接或账号已改变,本次操作已停止'); }};assertCurrent();- return { ...connection, apiKey: '', pathPrefix: new URL(connection.baseUrl).pathname.replace(/\/+$/, ''), assertCurrent };+ return {+ ...connection, apiKey: '', pathPrefix: new URL(connection.baseUrl).pathname.replace(/\/+$/, ''), assertCurrent,+ beforeSubmit: () => {+ // Re-read executable membership after reference reads and the database claim.+ // Paid task polling/recovery remains independent of the model's enable switch.+ if (!resolveProviderMediaModel(invocation.guide.connection.providerId, invocation.modelId, invocation.capability)) {+ throw new MediaInvocationError('MODEL_NOT_AVAILABLE', '该模型或来源已停用或不再支持本次能力,本次生成未发出');+ }+ },+ };}function resolveConnection(providerId: string): MediaConnection {@@ -491,6 +501,7 @@ async function dispatchRequest(input: {params: mediaRequestParamsForLog(input.body ?? {}),});input.connection.assertCurrent?.();+ if (input.operation === 'submit') input.connection.beforeSubmit?.();dispatched = true;const response = await outboundFetch(url, {method: input.method,@@ -1436,6 +1447,12 @@ async function submitInvocation(}const requestBody = await prepareRequestBody(validatedBody, invocation.guide);assertAuthScope(scope, invocation.owner);+ if (isClientVideoInvocation(invocation)) {+ // Managed refs have now become data URLs with their actual stored media MIME.+ const { model: _injectedModel, ...videoBody } = requestBody;+ try { validateCustomVideoBody(videoBody, invocation.capability === 'video.image_to_video'); }+ catch (error) { throw new MediaInvocationError('REQUEST_INVALID', (error as Error).message); }+ }let connection: MediaConnection;try {connection = resolveInvocationConnection(invocation);@@ -1588,9 +1605,9 @@ async function submitInvocation(};} catch (error) {const expected = error instanceof MediaInvocationError ? error : null;- // 本地组装失败(#5081):请求从未出站、无费用,把 invocation 放回 prepared,+ // 本地组装失败或提交前模型已停用:请求从未出站、无费用,把 invocation 放回 prepared,// 让同一 invocation_id 可以直接再次 request;其余失败仍进入 failed / unknown。- const buildFailed = expected?.code === 'REQUEST_BUILD_FAILED';+ const buildFailed = expected?.code === 'REQUEST_BUILD_FAILED' || expected?.code === 'MODEL_NOT_AVAILABLE';const restored = await transitionMediaInvocation({id: invocation.id,diff --git a/docs/custom-image-api.md b/docs/custom-image-api.mdindex bd2b5391a3..dc768b2577 100644--- a/docs/custom-image-api.md+++ b/docs/custom-image-api.md@@ -52,6 +52,7 @@ CPA/CLIProxyAPI、Sub2API 等自建中转只要提供上述契约即可复用此下载失败后使用原 invocation 再次执行 request,只恢复同一结果,不重新付费生成。- 上游提交结果不确定时不自动重提,不自动换模型或换来源;拒绝与诊断文本脱敏后返回。- 新来源使用 Core 媒体能力;冻结的旧 `cindy-request` 同步接口不扩展自定义来源。+ 旧入口的模型清单和偏好均按通道的旧协议兼容性过滤,不能把仅支持 Core 的来源交给 base64 解码器。旧插件已有能力保持原状。要使用新来源,插件需要采用 Core 媒体能力。## 后续边界diff --git a/docs/custom-video-api.md b/docs/custom-video-api.mdindex d71613d69c..4b5f32f9da 100644--- a/docs/custom-video-api.md+++ b/docs/custom-video-api.md@@ -52,6 +52,9 @@ OpenAI 官方 Sora Videos API 已于 2026-09-24 停止服务,本次不新增地址、Key、来源引擎或业务请求头变化时停止旧任务请求,恢复原连接后可查询原任务。- 一次付费提交保存任务 ID,之后只查询它。完成响应先持久化,下载或入库恢复不重新生成;签名地址过期时只刷新原任务。提交结果未知时禁止自动重提。+- 新付费请求在参考图读取和调用占用完成后,实际发出 POST 前再次检查模型、来源及能力。+ 若已停用则不提交,保留原 prepared 调用;已付费任务的查询与结果恢复不受展示/停用开关影响。+ 视频参数严格检查类型;受管参考图展开后再次校验图片 MIME,视频或音频不能作为图片提交。- 新来源使用 Core 媒体能力;冻结的旧 `cindy-request` 视频入口不扩展。- 出现在目录或通过接口探测不等于真实出片。验收需分别从 Art 执行两种操作,保存受管视频、检查实际时长/画面、确认任务退出运行状态,并区分准备与生成耗时。