Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): trust MiniMax Core media hosts (#3870)
betterkite086bc292e305
diff --git a/apps/desktop/src/main/cindy-media/__tests__/invocationService.test.ts b/apps/desktop/src/main/cindy-media/__tests__/invocationService.test.tsindex 356908f920..0528bf1a7d 100644--- a/apps/desktop/src/main/cindy-media/__tests__/invocationService.test.ts+++ b/apps/desktop/src/main/cindy-media/__tests__/invocationService.test.ts@@ -981,6 +981,77 @@ describe('Cindy Core media invocation state and security boundary', () => {expect(downloadInit.headers).toBeUndefined();});+ it('Core 命名空间模型保留供应商媒体域名的可信准入', async () => {+ const asyncOperation = {+ ...operation({+ mode: 'async',+ taskIdPath: ['task_id'],+ poll: {+ method: 'GET',+ path: '/video/tasks/{taskId}',+ statusPath: ['status'],+ successValues: ['succeeded'],+ failureValues: ['failed'],+ recommendedIntervalMs: 10,+ timeoutMs: 5_000,+ maxResponseBytes: 1_048_576,+ media: [{+ path: ['video', 'download_url'],+ encoding: 'url',+ kind: 'video',+ allowedUrlHosts: ['cdn.example.com'],+ }],+ },+ }, '/video/tasks'),+ capability: 'video.generate',+ };+ mocks.models.mockResolvedValue([+ {+ id: 'minimax/minimax-h3',+ name: 'MiniMax H3',+ providerId: 'xd',+ mode: 'video_generation',+ },+ ]);+ mocks.guide.mockResolvedValue({+ ...resolvedGuide(asyncOperation),+ modelId: 'minimax-h3',+ });+ mocks.outboundFetch+ .mockResolvedValueOnce(new Response(JSON.stringify({ task_id: 'task-1' }), { status: 200 }))+ .mockResolvedValueOnce(+ new Response(+ JSON.stringify({+ status: 'succeeded',+ video: { download_url: 'https://file.minimaxi.com/generated.mp4' },+ }),+ { status: 200 },+ ),+ )+ .mockResolvedValueOnce(+ new Response(MP4, { status: 200, headers: { 'content-type': 'video/mp4' } }),+ );+ mocks.ingestMedia.mockResolvedValue({+ url: `cindy-media://blobs/${'e'.repeat(64)}.mp4`,+ });++ const prepared = await callCindyMedia({+ action: 'prepare',+ modelId: 'minimax/minimax-h3',+ capability: 'video.generate',+ });+ const invocationId = prepared.invocation_id as string;+ await expect(+ callCindyMedia({ action: 'request', invocationId, body: { content: [] } }),+ ).resolves.toMatchObject({ ok: true, status: 'pending' });+ await expect(callCindyMedia({ action: 'poll', invocationId })).resolves.toMatchObject({+ ok: true,+ status: 'complete',+ xdt_video_urls: [`cindy-media://blobs/${'e'.repeat(64)}.mp4`],+ });+ expect(mocks.outboundFetch.mock.calls[2][0]).toBe('https://file.minimaxi.com/generated.mp4');+ });+it('即使持久快照异常包含反斜杠路径,也在发网前拒绝跨 Gateway origin', async () => {mocks.guide.mockResolvedValue(resolvedGuide(diff --git a/apps/desktop/src/main/cindy-media/invocationService.ts b/apps/desktop/src/main/cindy-media/invocationService.tsindex 105890e945..7e19e28773 100644--- a/apps/desktop/src/main/cindy-media/invocationService.ts+++ b/apps/desktop/src/main/cindy-media/invocationService.ts@@ -69,6 +69,11 @@ const TERMINAL_MEDIA_RESULT_ERRORS = new Set(['RESPONSE_TOO_LARGE',]);const CLIENT_PROVIDER_IMAGE_GUIDE_ID = 'cindy-provider-image-v1';+// Gateway Guides can lag behind vendor CDN rotation. Keep this map keyed by the+// vendor namespace already present in the executable Core model identity.+const MODEL_NAMESPACE_MEDIA_HOST_SUFFIXES = new Map<string, readonly string[]>([+ ['minimax', ['minimax.io', 'minimaxi.com']],+]);interface MediaConnection {baseUrl: string;@@ -924,6 +929,31 @@ function completedInvocationResult(invocation: StoredMediaInvocation): Record<st};}+function withVendorMediaUrlHosts(+ guide: PreparedMediaInvocationGuide,+): PreparedMediaInvocationGuide {+ const namespace = guide.modelId.slice(0, guide.modelId.indexOf('/')).toLowerCase();+ const vendorHosts = MODEL_NAMESPACE_MEDIA_HOST_SUFFIXES.get(namespace);+ if (!vendorHosts) return guide;++ const expand = (extractors: readonly MediaResultExtractor[]) =>+ extractors.map((extractor) => {+ if (extractor.encoding !== 'url') return extractor;+ return {+ ...extractor,+ allowedUrlHosts: [...new Set([...(extractor.allowedUrlHosts ?? []), ...vendorHosts])],+ };+ });+ const response = guide.response;+ if (response.mode === 'sync') {+ return { ...guide, response: { ...response, media: expand(response.media) } };+ }+ return {+ ...guide,+ response: { ...response, poll: { ...response.poll, media: expand(response.poll.media) } },+ };+}+async function persistCompletedInvocation(invocation: StoredMediaInvocation,media: Record<string, unknown>,@@ -1221,12 +1251,12 @@ async function prepareInvocation(}const { operations: _operations, ...guideProtocol } = resolvedGuide.guide;void _operations;- preparedGuide = {+ preparedGuide = withVendorMediaUrlHosts({// Guide 查询键不参与调用身份;配置、持久化和 Gateway 请求始终使用完整 modelId。modelId: resolvedModelId,...guideProtocol,...operation,- };+ });}await pruneInvocations(owner, db);assertAuthScope(scope);