diff --git a/AGENTS.md b/AGENTS.md index 403e2c95..df5c74fc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -322,9 +322,8 @@ model Example { ## Infinite Scroll & Pagination -- **Frontend**: Use the `useInfiniteScroll` hook for all list UIs. - - Located in `packages/webui/hooks/use-infinite-scroll.ts`. - - Pass a `fetchData` function that accepts `page` and `limit`. +- **Frontend**: For paginated APIs (which contain `pageInfo` and `total` fields), the UI MUST use an auto infinite scroll style design using `useInfiniteQuery` from `@tanstack/react-query` and `react-intersection-observer`. Use the `total` count from the API response instead of counting the results locally. + - The default `limit` should be **20**. - **Backend**: - Most list APIs support cursor pagination using opaque tokens (via `hyrumtoken` logic) using the `paginateQuery` helper function. - Pass `PaginationParams` containing `first` (limit) and `after` (cursor). diff --git a/packages/agent/src/tools/create-file.ts b/packages/agent/src/tools/create-file.ts index 4bc2f83e..6ccd84c5 100644 --- a/packages/agent/src/tools/create-file.ts +++ b/packages/agent/src/tools/create-file.ts @@ -64,7 +64,7 @@ export function createCreateFileTool(userId: string): AgentTool { + const actual = (await importOriginal()) as Record + const actualDefault = actual.default as Record + return { + ...actual, + default: { + ...actualDefault, + readFileSync: vi.fn().mockReturnValue(Buffer.from('transcoded content')), + existsSync: vi.fn().mockReturnValue(true), + unlinkSync: vi.fn().mockReturnValue(undefined), + }, + } +}) + vi.mock('@shumai/core/src/authz/authz', () => ({ authzService: { hasPermission: vi.fn().mockResolvedValue(undefined), @@ -45,6 +60,7 @@ describe('file api', () => { vi.spyOn(metadataService, 'updateAssetMetadata').mockImplementation(vi.fn()) vi.spyOn(notificationService, 'create').mockImplementation(vi.fn()) vi.spyOn(s3Service, 'putObject').mockImplementation(vi.fn()) + vi.spyOn(transcodeService, 'transcodeImage').mockResolvedValue(undefined) vi.mocked(authzService.hasPermission).mockResolvedValue(undefined) }) @@ -294,7 +310,7 @@ describe('file api', () => { }) }) - it('POST /teams/:teamId/files', async () => { + it('POST /teams/:teamId/files - image with compression', async () => { vi.mocked(s3Service.putObject).mockResolvedValue(undefined) const formData = new FormData() @@ -309,7 +325,7 @@ describe('file api', () => { expect(res.status).toBe(200) const json = await res.json() - expect(json.key).toMatch(/^files\//) + expect(json.key).toMatch(/^files\/.*\.webp$/) expect(authzService.hasPermission).toHaveBeenCalledWith({ user: { id: 'user1', name: 'Test User' }, @@ -317,7 +333,41 @@ describe('file api', () => { type: ResourceType.Team, id: 'test-team', }) - expect(s3Service.putObject).toHaveBeenCalled() + expect(transcodeService.transcodeImage).toHaveBeenCalled() + expect(s3Service.putObject).toHaveBeenCalledWith( + expect.any(String), + expect.stringMatching(/\.webp$/), + expect.any(Buffer), + expect.any(Number), + 'image/webp', + ) + }) + + it('POST /teams/:teamId/files - non-image without compression', async () => { + vi.mocked(s3Service.putObject).mockResolvedValue(undefined) + + const formData = new FormData() + const file = new File(['test content'], 'test.txt', { type: 'text/plain' }) + formData.append('file', file) + + const app = new Hono().use('*', authMiddleware).route('/', fileRoute) + const res = await app.request('/teams/test-team/files', { + method: 'POST', + body: formData, + }) + + expect(res.status).toBe(200) + const json = await res.json() + expect(json.key).toMatch(/^files\/[A-Z0-9]+$/) + + expect(transcodeService.transcodeImage).not.toHaveBeenCalled() + expect(s3Service.putObject).toHaveBeenCalledWith( + expect.any(String), + expect.not.stringMatching(/\.webp$/), + expect.any(Buffer), + expect.any(Number), + expect.stringContaining('text/plain'), + ) }) it('PATCH /files/:fileId/metadata', async () => { diff --git a/packages/api/src/api/file.ts b/packages/api/src/api/file.ts index eef1ee59..b7c7b00c 100644 --- a/packages/api/src/api/file.ts +++ b/packages/api/src/api/file.ts @@ -1,24 +1,28 @@ -import { Hono } from 'hono' import { zValidator } from '@hono/zod-validator' -import { prisma } from '@shumai/db' -import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz' import { assetService } from '@shumai/core/src/asset/asset' +import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz' import { metadataService } from '@shumai/core/src/metadata/metadata' import { notificationService } from '@shumai/core/src/notification/notification' import { s3Service } from '@shumai/core/src/s3/s3' +import type { Prisma } from '@shumai/db' +import { prisma } from '@shumai/db' import { - updateFileRequestSchema, - updateAssetOrderRequestSchema, - deleteFilesRequestSchema, - restoreFilesRequestSchema, createCommentRequestSchema, + deleteFilesRequestSchema, + paginationParamsSchema, + restoreFilesRequestSchema, + updateAssetMetadataRequestSchema, + updateAssetOrderRequestSchema, + updateFileRequestSchema, uploadFileRequestSchema, } from '@shumai/dtos' -import { updateAssetMetadataRequestSchema } from '@shumai/dtos' -import { paginationParamsSchema } from '@shumai/dtos' +import { transcodeService } from '@shumai/transcode/src/transcode' +import fs from 'fs' +import { Hono } from 'hono' +import os from 'os' +import path from 'path' import { ulid } from 'ulid' import { z } from 'zod' -import type { Prisma } from '@shumai/db' type User = Prisma.UserGetPayload> @@ -223,14 +227,40 @@ const route = new Hono<{ Variables: { user: User } }>() id: teamId, }) - if (file.size > 10 * 1024 * 1024) { - return c.json('file too large, max 10MB', 400) + if (file.size > 30 * 1024 * 1024) { + return c.json('file too large, max 30MB', 400) } - const key = `files/${ulid()}` - const buffer = Buffer.from(await file.arrayBuffer()) + let key = `files/${ulid()}` + let buffer = Buffer.from(await file.arrayBuffer()) + let contentType = file.type - await s3Service.putObject(process.env.S3_BUCKET || 'shumai', key, buffer, file.size, file.type) + if ( + file.type.startsWith('image/') && + !file.type.includes('svg') && + !file.type.includes('gif') + ) { + const tmpOut = path.join(os.tmpdir(), `transcode-${ulid()}.webp`) + try { + await transcodeService.transcodeImage(buffer, tmpOut, -1, 80, 540) + buffer = fs.readFileSync(tmpOut) + contentType = 'image/webp' + key = `${key}.webp` + } catch (err) { + console.error('Failed to compress image:', err) + // Fallback to original image if transcoding fails + } finally { + if (fs.existsSync(tmpOut)) fs.unlinkSync(tmpOut) + } + } + + await s3Service.putObject( + process.env.S3_BUCKET || 'shumai', + key, + buffer, + buffer.length, + contentType, + ) return c.json({ key }) }) diff --git a/packages/core/src/asset/asset.test.ts b/packages/core/src/asset/asset.test.ts index 25d156a1..9bb17e54 100644 --- a/packages/core/src/asset/asset.test.ts +++ b/packages/core/src/asset/asset.test.ts @@ -1446,7 +1446,7 @@ describe('AssetService', () => { expect(remainingChildren).toBe(0) }) - it('should delete the entire directory prefix for assets with complex keys (e.g., file/ULID/raw)', async () => { + it('should delete the entire directory prefix for assets with complex keys (e.g., files/ULID/raw)', async () => { const { project } = await setupBasicAssets() const { s3Service } = await import('../s3/s3') @@ -1460,7 +1460,7 @@ describe('AssetService', () => { project: { connect: { id: project.id } }, storageKey: { create: { - key: 'file/01KSBRJVY3DPK111S2MECFKDQ4/raw', + key: 'files/01KSBRJVY3DPK111S2MECFKDQ4/raw', createdAt: new Date(Date.now() - 25 * 60 * 60 * 1000), }, }, @@ -1478,7 +1478,7 @@ describe('AssetService', () => { // Verify deletePrefix was called with the correct prefix instead of just deleteObject expect(s3Service.deletePrefix).toHaveBeenCalledWith( expect.any(String), - 'file/01KSBRJVY3DPK111S2MECFKDQ4/', + 'files/01KSBRJVY3DPK111S2MECFKDQ4/', ) // Verify record is gone diff --git a/packages/core/src/generated/providers.generated.ts b/packages/core/src/generated/providers.generated.ts index 2a4bccd5..12abeff5 100644 --- a/packages/core/src/generated/providers.generated.ts +++ b/packages/core/src/generated/providers.generated.ts @@ -2348,8 +2348,8 @@ export const builtinProviders: Record = { contextWindow: 131072, maxTokens: 16000, cost: { - input: 0.2288, - output: 0.9144, + input: 0.20020000000000002, + output: 0.8000999999999999, cacheRead: 0, cacheWrite: 0, }, @@ -2448,11 +2448,11 @@ export const builtinProviders: Record = { reasoning: true, input: ['text'], contextWindow: 131072, - maxTokens: 65536, + maxTokens: 64000, cost: { - input: 0.252, - output: 0.378, - cacheRead: 0.0252, + input: 0.2288, + output: 0.3432, + cacheRead: 0, cacheWrite: 0, }, }, @@ -2525,40 +2525,6 @@ export const builtinProviders: Record = { }, }, }, - { - modelId: 'google/gemini-2.0-flash-001', - name: 'Google: Gemini 2.0 Flash', - config: { - api: 'openai-completions', - reasoning: false, - input: ['text', 'image'], - contextWindow: 1048576, - maxTokens: 8192, - cost: { - input: 0.09999999999999999, - output: 0.39999999999999997, - cacheRead: 0.024999999999999998, - cacheWrite: 0.08333333333333334, - }, - }, - }, - { - modelId: 'google/gemini-2.0-flash-lite-001', - name: 'Google: Gemini 2.0 Flash Lite', - config: { - api: 'openai-completions', - reasoning: false, - input: ['text', 'image'], - contextWindow: 1048576, - maxTokens: 8192, - cost: { - input: 0.075, - output: 0.3, - cacheRead: 0, - cacheWrite: 0, - }, - }, - }, { modelId: 'google/gemini-2.5-flash', name: 'Google: Gemini 2.5 Flash', @@ -2943,9 +2909,9 @@ export const builtinProviders: Record = { contextWindow: 262144, maxTokens: 65536, cost: { - input: 0.3, - output: 2.5, - cacheRead: 0.06, + input: 0.075, + output: 0.625, + cacheRead: 0.015, cacheWrite: 0, }, }, @@ -3145,15 +3111,32 @@ export const builtinProviders: Record = { reasoning: true, input: ['text'], contextWindow: 204800, - maxTokens: 4096, + maxTokens: 131072, cost: { - input: 0.26, + input: 0.27899999999999997, output: 1.2, cacheRead: 0, cacheWrite: 0, }, }, }, + { + modelId: 'minimax/minimax-m3', + name: 'MiniMax: MiniMax M3', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text', 'image'], + contextWindow: 1048576, + maxTokens: 512000, + cost: { + input: 0.3, + output: 1.2, + cacheRead: 0.06, + cacheWrite: 0, + }, + }, + }, { modelId: 'mistralai/codestral-2508', name: 'Mistral: Codestral 2508', @@ -3664,6 +3647,40 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'nvidia/nemotron-3-ultra-550b-a55b', + name: 'NVIDIA: Nemotron 3 Ultra', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 1000000, + maxTokens: 16384, + cost: { + input: 0.5, + output: 2.5, + cacheRead: 0.15, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nvidia/nemotron-3-ultra-550b-a55b:free', + name: 'NVIDIA: Nemotron 3 Ultra (free)', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 1000000, + maxTokens: 65536, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, { modelId: 'nvidia/nemotron-nano-12b-v2-vl:free', name: 'NVIDIA: Nemotron Nano 12B 2 VL (free)', @@ -3783,23 +3800,6 @@ export const builtinProviders: Record = { }, }, }, - { - modelId: 'openai/gpt-4-0314', - name: 'OpenAI: GPT-4 (older v0314)', - config: { - api: 'openai-completions', - reasoning: false, - input: ['text'], - contextWindow: 8191, - maxTokens: 4096, - cost: { - input: 30, - output: 60, - cacheRead: 0, - cacheWrite: 0, - }, - }, - }, { modelId: 'openai/gpt-4-1106-preview', name: 'OpenAI: GPT-4 Turbo (older v1106)', @@ -4929,11 +4929,11 @@ export const builtinProviders: Record = { api: 'openai-completions', reasoning: false, input: ['text'], - contextWindow: 262144, - maxTokens: 262144, + contextWindow: 131072, + maxTokens: 32000, cost: { - input: 0.09, - output: 0.3, + input: 0.04815, + output: 0.19305, cacheRead: 0, cacheWrite: 0, }, @@ -5534,6 +5534,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'qwen/qwen3.7-plus', + name: 'Qwen: Qwen3.7 Plus', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text', 'image'], + contextWindow: 1000000, + maxTokens: 65536, + cost: { + input: 0.39999999999999997, + output: 1.5999999999999999, + cacheRead: 0.08, + cacheWrite: 0.5, + }, + }, + }, { modelId: 'rekaai/reka-edge', name: 'Reka Edge', @@ -5687,6 +5704,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'upstage/solar-pro-3', + name: 'Upstage: Solar Pro 3', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 128000, + maxTokens: 4096, + cost: { + input: 0.15, + output: 0.6, + cacheRead: 0.015, + cacheWrite: 0, + }, + }, + }, { modelId: 'x-ai/grok-4.20', name: 'xAI: Grok 4.20', @@ -6190,6 +6224,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'devstral-latest', + name: 'Devstral 2', + config: { + api: 'mistral-conversations', + reasoning: false, + input: ['text'], + contextWindow: 262144, + maxTokens: 262144, + cost: { + input: 0.4, + output: 2, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, { modelId: 'devstral-medium-2507', name: 'Devstral Medium', @@ -6564,6 +6615,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'open-mistral-nemo', + name: 'Open Mistral Nemo', + config: { + api: 'mistral-conversations', + reasoning: false, + input: ['text'], + contextWindow: 128000, + maxTokens: 128000, + cost: { + input: 0.15, + output: 0.15, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, { modelId: 'open-mixtral-8x22b', name: 'Mixtral 8x22B', @@ -7026,8 +7094,8 @@ export const builtinProviders: Record = { contextWindow: 1000000, maxTokens: 128000, cost: { - input: 5, - output: 25, + input: 5.5, + output: 27.5, cacheRead: 0.5, cacheWrite: 6.25, }, @@ -7043,10 +7111,10 @@ export const builtinProviders: Record = { contextWindow: 1000000, maxTokens: 128000, cost: { - input: 5, - output: 25, - cacheRead: 0.5, - cacheWrite: 6.25, + input: 5.5, + output: 27.5, + cacheRead: 0.55, + cacheWrite: 6.875, }, }, }, @@ -7060,10 +7128,10 @@ export const builtinProviders: Record = { contextWindow: 1000000, maxTokens: 128000, cost: { - input: 5, - output: 25, - cacheRead: 0.5, - cacheWrite: 6.25, + input: 5.5, + output: 27.5, + cacheRead: 0.55, + cacheWrite: 6.875, }, }, }, @@ -7077,10 +7145,10 @@ export const builtinProviders: Record = { contextWindow: 200000, maxTokens: 64000, cost: { - input: 3, - output: 15, - cacheRead: 0.3, - cacheWrite: 3.75, + input: 3.3, + output: 16.5, + cacheRead: 0.33, + cacheWrite: 4.125, }, }, }, @@ -7094,10 +7162,10 @@ export const builtinProviders: Record = { contextWindow: 1000000, maxTokens: 64000, cost: { - input: 3, - output: 15, - cacheRead: 0.3, - cacheWrite: 3.75, + input: 3.3, + output: 16.5, + cacheRead: 0.33, + cacheWrite: 4.125, }, }, }, @@ -8174,6 +8242,67 @@ export const builtinProviders: Record = { }, ], }, + 'ant-ling': { + name: 'ant-ling', + config: { + api: 'openai-completions', + baseUrl: 'https://api.ant-ling.com/v1', + apiKey: '', + }, + models: [ + { + modelId: 'Ling-2.6-1T', + name: 'Ling 2.6 1T', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text'], + contextWindow: 262144, + maxTokens: 65536, + cost: { + input: 0.06, + output: 0.25, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'Ling-2.6-flash', + name: 'Ling 2.6 Flash', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text'], + contextWindow: 262144, + maxTokens: 65536, + cost: { + input: 0.01, + output: 0.02, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'Ring-2.6-1T', + name: 'Ring 2.6 1T', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 262144, + maxTokens: 65536, + cost: { + input: 0.06, + output: 0.25, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + ], + }, 'azure-openai-responses': { name: 'azure-openai-responses', config: { @@ -9947,8 +10076,8 @@ export const builtinProviders: Record = { api: 'anthropic-messages', reasoning: true, input: ['text', 'image'], - contextWindow: 128000, - maxTokens: 8192, + contextWindow: 262144, + maxTokens: 65536, cost: { input: 0.5, output: 3, @@ -10003,7 +10132,7 @@ export const builtinProviders: Record = { models: [ { modelId: 'claude-haiku-4.5', - name: 'Claude Haiku 4.5', + name: 'Claude Haiku 4.5 (latest)', config: { api: 'anthropic-messages', reasoning: true, @@ -10011,16 +10140,16 @@ export const builtinProviders: Record = { contextWindow: 200000, maxTokens: 64000, cost: { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, + input: 1, + output: 5, + cacheRead: 0.1, + cacheWrite: 1.25, }, }, }, { modelId: 'claude-opus-4.5', - name: 'Claude Opus 4.5', + name: 'Claude Opus 4.5 (latest)', config: { api: 'anthropic-messages', reasoning: true, @@ -10028,10 +10157,10 @@ export const builtinProviders: Record = { contextWindow: 200000, maxTokens: 32000, cost: { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, + input: 5, + output: 25, + cacheRead: 0.5, + cacheWrite: 6.25, }, }, }, @@ -10045,10 +10174,10 @@ export const builtinProviders: Record = { contextWindow: 1000000, maxTokens: 32000, cost: { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, + input: 5, + output: 25, + cacheRead: 0.5, + cacheWrite: 6.25, }, }, }, @@ -10062,10 +10191,10 @@ export const builtinProviders: Record = { contextWindow: 200000, maxTokens: 32000, cost: { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, + input: 5, + output: 25, + cacheRead: 0.5, + cacheWrite: 6.25, }, }, }, @@ -10079,16 +10208,33 @@ export const builtinProviders: Record = { contextWindow: 200000, maxTokens: 64000, cost: { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, + input: 5, + output: 25, + cacheRead: 0.5, + cacheWrite: 6.25, + }, + }, + }, + { + modelId: 'claude-sonnet-4', + name: 'Claude Sonnet 4 (latest)', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text', 'image'], + contextWindow: 216000, + maxTokens: 16000, + cost: { + input: 3, + output: 15, + cacheRead: 0.3, + cacheWrite: 3.75, }, }, }, { modelId: 'claude-sonnet-4.5', - name: 'Claude Sonnet 4.5', + name: 'Claude Sonnet 4.5 (latest)', config: { api: 'anthropic-messages', reasoning: true, @@ -10096,10 +10242,10 @@ export const builtinProviders: Record = { contextWindow: 200000, maxTokens: 32000, cost: { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, + input: 3, + output: 15, + cacheRead: 0.3, + cacheWrite: 3.75, }, }, }, @@ -10113,10 +10259,10 @@ export const builtinProviders: Record = { contextWindow: 1000000, maxTokens: 32000, cost: { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, + input: 3, + output: 15, + cacheRead: 0.3, + cacheWrite: 3.75, }, }, }, @@ -10125,21 +10271,21 @@ export const builtinProviders: Record = { name: 'Gemini 2.5 Pro', config: { api: 'openai-completions', - reasoning: false, + reasoning: true, input: ['text', 'image'], contextWindow: 128000, maxTokens: 64000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 1.25, + output: 10, + cacheRead: 0.125, cacheWrite: 0, }, }, }, { modelId: 'gemini-3-flash-preview', - name: 'Gemini 3 Flash', + name: 'Gemini 3 Flash Preview', config: { api: 'openai-completions', reasoning: true, @@ -10147,9 +10293,9 @@ export const builtinProviders: Record = { contextWindow: 128000, maxTokens: 64000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 0.5, + output: 3, + cacheRead: 0.05, cacheWrite: 0, }, }, @@ -10164,9 +10310,9 @@ export const builtinProviders: Record = { contextWindow: 200000, maxTokens: 64000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 2, + output: 12, + cacheRead: 0.2, cacheWrite: 0, }, }, @@ -10181,9 +10327,9 @@ export const builtinProviders: Record = { contextWindow: 200000, maxTokens: 64000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 1.5, + output: 9, + cacheRead: 0.15, cacheWrite: 0, }, }, @@ -10198,33 +10344,16 @@ export const builtinProviders: Record = { contextWindow: 128000, maxTokens: 16384, cost: { - input: 0, - output: 0, - cacheRead: 0, - cacheWrite: 0, - }, - }, - }, - { - modelId: 'gpt-4o', - name: 'GPT-4o', - config: { - api: 'openai-completions', - reasoning: false, - input: ['text', 'image'], - contextWindow: 128000, - maxTokens: 4096, - cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 2, + output: 8, + cacheRead: 0.5, cacheWrite: 0, }, }, }, { modelId: 'gpt-5-mini', - name: 'GPT-5-mini', + name: 'GPT-5 Mini', config: { api: 'openai-responses', reasoning: true, @@ -10232,9 +10361,9 @@ export const builtinProviders: Record = { contextWindow: 264000, maxTokens: 64000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 0.25, + output: 2, + cacheRead: 0.025, cacheWrite: 0, }, }, @@ -10249,16 +10378,16 @@ export const builtinProviders: Record = { contextWindow: 400000, maxTokens: 128000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 1.75, + output: 14, + cacheRead: 0.175, cacheWrite: 0, }, }, }, { modelId: 'gpt-5.2-codex', - name: 'GPT-5.2-Codex', + name: 'GPT-5.2 Codex', config: { api: 'openai-responses', reasoning: true, @@ -10266,16 +10395,16 @@ export const builtinProviders: Record = { contextWindow: 400000, maxTokens: 128000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 1.75, + output: 14, + cacheRead: 0.175, cacheWrite: 0, }, }, }, { modelId: 'gpt-5.3-codex', - name: 'GPT-5.3-Codex', + name: 'GPT-5.3 Codex', config: { api: 'openai-responses', reasoning: true, @@ -10283,9 +10412,9 @@ export const builtinProviders: Record = { contextWindow: 400000, maxTokens: 128000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 1.75, + output: 14, + cacheRead: 0.175, cacheWrite: 0, }, }, @@ -10300,16 +10429,16 @@ export const builtinProviders: Record = { contextWindow: 400000, maxTokens: 128000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 2.5, + output: 15, + cacheRead: 0.25, cacheWrite: 0, }, }, }, { modelId: 'gpt-5.4-mini', - name: 'GPT-5.4 Mini', + name: 'GPT-5.4 mini', config: { api: 'openai-responses', reasoning: true, @@ -10317,9 +10446,26 @@ export const builtinProviders: Record = { contextWindow: 400000, maxTokens: 128000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 0.75, + output: 4.5, + cacheRead: 0.075, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'gpt-5.4-nano', + name: 'GPT-5.4 nano', + config: { + api: 'openai-responses', + reasoning: true, + input: ['text', 'image'], + contextWindow: 400000, + maxTokens: 128000, + cost: { + input: 0.2, + output: 1.25, + cacheRead: 0.02, cacheWrite: 0, }, }, @@ -10334,26 +10480,26 @@ export const builtinProviders: Record = { contextWindow: 400000, maxTokens: 128000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 5, + output: 30, + cacheRead: 0.5, cacheWrite: 0, }, }, }, { - modelId: 'grok-code-fast-1', - name: 'Grok Code Fast 1', + modelId: 'raptor-mini', + name: 'Raptor mini', config: { api: 'openai-completions', reasoning: true, - input: ['text'], - contextWindow: 128000, - maxTokens: 64000, + input: ['text', 'image'], + contextWindow: 400000, + maxTokens: 128000, cost: { - input: 0, - output: 0, - cacheRead: 0, + input: 0.25, + output: 2, + cacheRead: 0.025, cacheWrite: 0, }, }, @@ -11061,6 +11207,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'MiniMax-M3', + name: 'MiniMax-M3', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text', 'image'], + contextWindow: 512000, + maxTokens: 128000, + cost: { + input: 0.6, + output: 2.4, + cacheRead: 0.12, + cacheWrite: 0, + }, + }, + }, ], }, 'minimax-cn': { @@ -11105,6 +11268,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'MiniMax-M3', + name: 'MiniMax-M3', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text', 'image'], + contextWindow: 512000, + maxTokens: 128000, + cost: { + input: 0.6, + output: 2.4, + cacheRead: 0.12, + cacheWrite: 0, + }, + }, + }, ], }, moonshotai: { @@ -11365,6 +11545,356 @@ export const builtinProviders: Record = { }, ], }, + nvidia: { + name: 'nvidia', + config: { + api: 'openai-completions', + baseUrl: 'https://integrate.api.nvidia.com/v1', + apiKey: '', + }, + models: [ + { + modelId: 'meta/llama-3.1-70b-instruct', + name: 'Llama 3.1 70b Instruct', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text'], + contextWindow: 128000, + maxTokens: 4096, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'meta/llama-3.1-8b-instruct', + name: 'Llama 3.1 8B Instruct', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text'], + contextWindow: 16000, + maxTokens: 4096, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'meta/llama-3.2-11b-vision-instruct', + name: 'Llama 3.2 11b Vision Instruct', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text', 'image'], + contextWindow: 128000, + maxTokens: 4096, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'meta/llama-3.2-90b-vision-instruct', + name: 'Llama-3.2-90B-Vision-Instruct', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text', 'image'], + contextWindow: 128000, + maxTokens: 8192, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'meta/llama-3.3-70b-instruct', + name: 'Llama 3.3 70b Instruct', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text'], + contextWindow: 128000, + maxTokens: 4096, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'mistralai/mistral-large-3-675b-instruct-2512', + name: 'Mistral Large 3 675B Instruct 2512', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text', 'image'], + contextWindow: 262144, + maxTokens: 262144, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'mistralai/mistral-small-4-119b-2603', + name: 'mistral-small-4-119b-2603', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text'], + contextWindow: 128000, + maxTokens: 8192, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'moonshotai/kimi-k2.6', + name: 'Kimi K2.6', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text', 'image'], + contextWindow: 262144, + maxTokens: 262144, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nvidia/llama-3.3-nemotron-super-49b-v1', + name: 'Llama 3.3 Nemotron Super 49B v1', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nvidia/llama-3.3-nemotron-super-49b-v1.5', + name: 'Llama 3.3 Nemotron Super 49B v1.5', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nvidia/nemotron-3-nano-30b-a3b', + name: 'nemotron-3-nano-30b-a3b', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning', + name: 'Nemotron 3 Nano Omni', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text', 'image'], + contextWindow: 256000, + maxTokens: 65536, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nvidia/nemotron-3-super-120b-a12b', + name: 'Nemotron 3 Super', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 262144, + maxTokens: 262144, + cost: { + input: 0.2, + output: 0.8, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nvidia/nvidia-nemotron-nano-9b-v2', + name: 'nvidia-nemotron-nano-9b-v2', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'openai/gpt-oss-20b', + name: 'GPT OSS 20B', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 32768, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'qwen/qwen3-coder-480b-a35b-instruct', + name: 'Qwen3 Coder 480B A35B Instruct', + config: { + api: 'openai-completions', + reasoning: false, + input: ['text'], + contextWindow: 262144, + maxTokens: 66536, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'qwen/qwen3.5-122b-a10b', + name: 'Qwen3.5 122B-A10B', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text', 'image'], + contextWindow: 262144, + maxTokens: 65536, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'stepfun-ai/step-3.5-flash', + name: 'Step 3.5 Flash', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 256000, + maxTokens: 16384, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'stepfun-ai/step-3.7-flash', + name: 'Step 3.7 Flash', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text', 'image'], + contextWindow: 256000, + maxTokens: 16384, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'z-ai/glm-5.1', + name: 'GLM-5.1', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + ], + }, 'openai-codex': { name: 'openai-codex', config: { @@ -11373,40 +11903,6 @@ export const builtinProviders: Record = { apiKey: '', }, models: [ - { - modelId: 'gpt-5.2', - name: 'GPT-5.2', - config: { - api: 'openai-codex-responses', - reasoning: true, - input: ['text', 'image'], - contextWindow: 272000, - maxTokens: 128000, - cost: { - input: 1.75, - output: 14, - cacheRead: 0.175, - cacheWrite: 0, - }, - }, - }, - { - modelId: 'gpt-5.3-codex', - name: 'GPT-5.3 Codex', - config: { - api: 'openai-codex-responses', - reasoning: true, - input: ['text', 'image'], - contextWindow: 272000, - maxTokens: 128000, - cost: { - input: 1.75, - output: 14, - cacheRead: 0.175, - cacheWrite: 0, - }, - }, - }, { modelId: 'gpt-5.3-codex-spark', name: 'GPT-5.3 Codex Spark', @@ -12149,13 +12645,30 @@ export const builtinProviders: Record = { }, }, { - modelId: 'nemotron-3-super-free', - name: 'Nemotron 3 Super Free', + modelId: 'minimax-m3-free', + name: 'MiniMax M3 Free', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text', 'image'], + contextWindow: 200000, + maxTokens: 32000, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nemotron-3-ultra-free', + name: 'Nemotron 3 Ultra Free', config: { api: 'openai-completions', reasoning: true, input: ['text'], - contextWindow: 204800, + contextWindow: 1000000, maxTokens: 128000, cost: { input: 0, @@ -12379,6 +12892,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'minimax-m3', + name: 'MiniMax M3', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text', 'image'], + contextWindow: 512000, + maxTokens: 131072, + cost: { + input: 0.6, + output: 2.4, + cacheRead: 0.12, + cacheWrite: 0, + }, + }, + }, { modelId: 'qwen3.6-plus', name: 'Qwen3.6 Plus', @@ -12413,6 +12943,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'qwen3.7-plus', + name: 'Qwen3.7 Plus', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text', 'image'], + contextWindow: 262144, + maxTokens: 65536, + cost: { + input: 0.4, + output: 1.6, + cacheRead: 0.04, + cacheWrite: 0.5, + }, + }, + }, ], }, together: { @@ -12761,7 +13308,7 @@ export const builtinProviders: Record = { name: 'Qwen3 235B A22B', config: { api: 'anthropic-messages', - reasoning: false, + reasoning: true, input: ['text'], contextWindow: 262144, maxTokens: 16384, @@ -12813,7 +13360,7 @@ export const builtinProviders: Record = { config: { api: 'anthropic-messages', reasoning: true, - input: ['text', 'image'], + input: ['text'], contextWindow: 240000, maxTokens: 64000, cost: { @@ -12846,7 +13393,7 @@ export const builtinProviders: Record = { name: 'Qwen3 Coder 480B A35B Instruct', config: { api: 'anthropic-messages', - reasoning: false, + reasoning: true, input: ['text'], contextWindow: 262144, maxTokens: 65536, @@ -12880,7 +13427,7 @@ export const builtinProviders: Record = { name: 'Qwen3 Coder Next', config: { api: 'anthropic-messages', - reasoning: false, + reasoning: true, input: ['text'], contextWindow: 256000, maxTokens: 256000, @@ -12960,6 +13507,40 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'alibaba/qwen3-next-80b-a3b-instruct', + name: 'Qwen3 Next 80B A3B Instruct', + config: { + api: 'anthropic-messages', + reasoning: false, + input: ['text'], + contextWindow: 131072, + maxTokens: 32768, + cost: { + input: 0.15, + output: 1.2, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'alibaba/qwen3-next-80b-a3b-thinking', + name: 'Qwen3 Next 80B A3B Thinking', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 32768, + cost: { + input: 0.15, + output: 1.2, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, { modelId: 'alibaba/qwen3-vl-thinking', name: 'Qwen3 VL 235B A22B Thinking', @@ -13051,7 +13632,7 @@ export const builtinProviders: Record = { config: { api: 'anthropic-messages', reasoning: true, - input: ['text', 'image'], + input: ['text'], contextWindow: 991000, maxTokens: 64000, cost: { @@ -13062,6 +13643,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'alibaba/qwen3.7-plus', + name: 'Qwen 3.7 Plus', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text', 'image'], + contextWindow: 1000000, + maxTokens: 64000, + cost: { + input: 0.39999999999999997, + output: 1.5999999999999999, + cacheRead: 0.08, + cacheWrite: 0.5, + }, + }, + }, { modelId: 'anthropic/claude-3-haiku', name: 'Claude 3 Haiku', @@ -13407,8 +14005,8 @@ export const builtinProviders: Record = { name: 'DeepSeek V3.2', config: { api: 'anthropic-messages', - reasoning: false, - input: ['text'], + reasoning: true, + input: ['text', 'image'], contextWindow: 128000, maxTokens: 8000, cost: { @@ -13424,8 +14022,8 @@ export const builtinProviders: Record = { name: 'DeepSeek V3.2 Thinking', config: { api: 'anthropic-messages', - reasoning: false, - input: ['text'], + reasoning: true, + input: ['text', 'image'], contextWindow: 128000, maxTokens: 8000, cost: { @@ -13442,7 +14040,7 @@ export const builtinProviders: Record = { config: { api: 'anthropic-messages', reasoning: true, - input: ['text'], + input: ['text', 'image'], contextWindow: 1000000, maxTokens: 384000, cost: { @@ -13662,14 +14260,14 @@ export const builtinProviders: Record = { name: 'Gemma 4 26B A4B IT', config: { api: 'anthropic-messages', - reasoning: false, + reasoning: true, input: ['text', 'image'], contextWindow: 262144, maxTokens: 131072, cost: { - input: 0.13, - output: 0.39999999999999997, - cacheRead: 0, + input: 0.15, + output: 0.6, + cacheRead: 0.015, cacheWrite: 0, }, }, @@ -13969,7 +14567,7 @@ export const builtinProviders: Record = { config: { api: 'anthropic-messages', reasoning: true, - input: ['text', 'image'], + input: ['text'], contextWindow: 204800, maxTokens: 131000, cost: { @@ -13986,7 +14584,7 @@ export const builtinProviders: Record = { config: { api: 'anthropic-messages', reasoning: true, - input: ['text', 'image'], + input: ['text'], contextWindow: 204800, maxTokens: 131100, cost: { @@ -13997,6 +14595,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'minimax/minimax-m3', + name: 'MiniMax M3', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text', 'image'], + contextWindow: 1000000, + maxTokens: 1000000, + cost: { + input: 0.3, + output: 1.2, + cacheRead: 0.06, + cacheWrite: 0, + }, + }, + }, { modelId: 'mistral/codestral', name: 'Mistral Codestral', @@ -14133,6 +14748,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'mistral/mistral-nemo', + name: 'Mistral Nemo 12B', + config: { + api: 'anthropic-messages', + reasoning: false, + input: ['text'], + contextWindow: 131072, + maxTokens: 131072, + cost: { + input: 0.02, + output: 0.04, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, { modelId: 'mistral/mistral-small', name: 'Mistral Small', @@ -14286,6 +14918,40 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'nvidia/nemotron-3-super-120b-a12b', + name: 'NVIDIA Nemotron 3 Super 120B A12B', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text'], + contextWindow: 256000, + maxTokens: 32000, + cost: { + input: 0.15, + output: 0.65, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'nvidia/nemotron-3-ultra-550b-a55b', + name: 'Nemotron 3 Ultra', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text'], + contextWindow: 262144, + maxTokens: 65000, + cost: { + input: 0.5, + output: 2.5, + cacheRead: 0.15, + cacheWrite: 0, + }, + }, + }, { modelId: 'nvidia/nemotron-nano-12b-v2-vl', name: 'Nvidia Nemotron Nano 12B V2 VL', @@ -14462,7 +15128,7 @@ export const builtinProviders: Record = { config: { api: 'anthropic-messages', reasoning: true, - input: ['text'], + input: ['text', 'image'], contextWindow: 400000, maxTokens: 128000, cost: { @@ -14813,6 +15479,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'openai/gpt-oss-120b', + name: 'GPT OSS 120B', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 131000, + cost: { + input: 0.35, + output: 0.75, + cacheRead: 0.25, + cacheWrite: 0, + }, + }, + }, { modelId: 'openai/gpt-oss-20b', name: 'GPT OSS 20B', @@ -14983,6 +15666,23 @@ export const builtinProviders: Record = { }, }, }, + { + modelId: 'stepfun/step-3.5-flash', + name: 'StepFun 3.5 Flash', + config: { + api: 'anthropic-messages', + reasoning: true, + input: ['text'], + contextWindow: 262114, + maxTokens: 262114, + cost: { + input: 0.09, + output: 0.3, + cacheRead: 0, + cacheWrite: 0.02, + }, + }, + }, { modelId: 'stepfun/step-3.7-flash', name: 'Step 3.7 Flash', @@ -15277,7 +15977,7 @@ export const builtinProviders: Record = { name: 'GLM 4.5V', config: { api: 'anthropic-messages', - reasoning: false, + reasoning: true, input: ['text', 'image'], contextWindow: 66000, maxTokens: 16000, @@ -15431,7 +16131,7 @@ export const builtinProviders: Record = { config: { api: 'anthropic-messages', reasoning: true, - input: ['text'], + input: ['text', 'image'], contextWindow: 202800, maxTokens: 64000, cost: { @@ -16014,4 +16714,99 @@ export const builtinProviders: Record = { }, ], }, + 'zai-coding-cn': { + name: 'zai-coding-cn', + config: { + api: 'openai-completions', + baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4', + apiKey: '', + }, + models: [ + { + modelId: 'glm-4.5-air', + name: 'GLM-4.5-Air', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 131072, + maxTokens: 98304, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'glm-4.7', + name: 'GLM-4.7', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 204800, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'glm-5-turbo', + name: 'GLM-5-Turbo', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 200000, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'glm-5.1', + name: 'GLM-5.1', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text'], + contextWindow: 200000, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + { + modelId: 'glm-5v-turbo', + name: 'GLM-5V-Turbo', + config: { + api: 'openai-completions', + reasoning: true, + input: ['text', 'image'], + contextWindow: 200000, + maxTokens: 131072, + cost: { + input: 0, + output: 0, + cacheRead: 0, + cacheWrite: 0, + }, + }, + }, + ], + }, } as unknown as Record diff --git a/packages/core/src/upload/upload.ts b/packages/core/src/upload/upload.ts index a825fd35..313b37f2 100644 --- a/packages/core/src/upload/upload.ts +++ b/packages/core/src/upload/upload.ts @@ -116,7 +116,7 @@ export class UploadService { const assetType = file.type === 'folder' ? AssetType.folder : AssetType.file let key: string | null = null if (assetType === AssetType.file) { - key = `file/${ulid()}/raw` + key = `files/${ulid()}/raw` } const newAsset = await this.prismaClient.asset.create({ diff --git a/packages/transcode/src/transcode.test.ts b/packages/transcode/src/transcode.test.ts index 7daf50fb..563d0992 100644 --- a/packages/transcode/src/transcode.test.ts +++ b/packages/transcode/src/transcode.test.ts @@ -169,6 +169,18 @@ describe('TranscodeService', () => { expect(sharp).toHaveBeenCalledWith(expect.any(Buffer)) }) + it('should support Buffer as input for image transcoding', async () => { + const inputBuffer = Buffer.from('fake-buffer-image') + const outputFile = path.join(tempDir, 'output-buffer.webp') + await transcodeService.transcodeImage(inputBuffer, outputFile, 480, 80) + + expect(sharp).toHaveBeenCalledWith(inputBuffer) + const mockSharp = vi.mocked(sharp).mock.results[vi.mocked(sharp).mock.results.length - 1].value + expect(mockSharp.resize).toHaveBeenCalledWith(480, null, expect.any(Object)) + expect(mockSharp.webp).toHaveBeenCalledWith({ quality: 80 }) + expect(mockSharp.toFile).toHaveBeenCalledWith(outputFile) + }) + it('should use transcodeImage in extractVideoFrames for images', async () => { const transcodeImageSpy = vi.spyOn(transcodeService, 'transcodeImage').mockResolvedValue() const result = await transcodeService.extractVideoFrames({ diff --git a/packages/transcode/src/transcode.ts b/packages/transcode/src/transcode.ts index 942855dc..422e6a27 100644 --- a/packages/transcode/src/transcode.ts +++ b/packages/transcode/src/transcode.ts @@ -274,14 +274,14 @@ export class TranscodeService { } async transcodeImage( - inputFile: string, + inputFile: string | Buffer, outputFile: string, width: number, quality: number, height: number | null = null, ): Promise { let input: string | Buffer = inputFile - if (inputFile.startsWith('http')) { + if (typeof inputFile === 'string' && inputFile.startsWith('http')) { const resp = await fetch(inputFile) if (!resp.ok) { throw new Error(`Failed to fetch image from ${inputFile}: ${resp.statusText}`) @@ -512,7 +512,7 @@ export class TranscodeService { } // 6. Upload to S3 - const s3Key = `file/${params.assetId}/screenshots/${outName}` + const s3Key = `files/${params.assetId}/screenshots/${outName}` const fileBuffer = fs.readFileSync(localShotPath) await s3Service.putObject(bucket, s3Key, fileBuffer, fileBuffer.length, 'image/webp') @@ -556,7 +556,7 @@ export class TranscodeService { .toFile(localOutPath) // 5. Upload to S3 - const s3Key = `file/${params.assetId}/annotations/${outName}` + const s3Key = `files/${params.assetId}/annotations/${outName}` const fileBuffer = fs.readFileSync(localOutPath) await s3Service.putObject(bucket, s3Key, fileBuffer, fileBuffer.length, 'image/webp') diff --git a/packages/transcode/src/workflows/transcode.test.ts b/packages/transcode/src/workflows/transcode.test.ts index 4bdbe8ac..6a86490d 100644 --- a/packages/transcode/src/workflows/transcode.test.ts +++ b/packages/transcode/src/workflows/transcode.test.ts @@ -274,8 +274,8 @@ describe('Transcode Workflow', () => { }) mockActivities.takeScreenshotsActivity.mockResolvedValue([ - { key: 'file/asset-video/screenshots/shot1.webp', timestamp: 0.0 }, - { key: 'file/asset-video/screenshots/shot2.webp', timestamp: 5.0 }, + { key: 'files/asset-video/screenshots/shot1.webp', timestamp: 0.0 }, + { key: 'files/asset-video/screenshots/shot2.webp', timestamp: 5.0 }, ]) await transcodeMedia(task) @@ -295,8 +295,8 @@ describe('Transcode Workflow', () => { status: WorkflowTaskStatus.completed, output: { screenshots: [ - { key: 'file/asset-video/screenshots/shot1.webp', timestamp: 0.0 }, - { key: 'file/asset-video/screenshots/shot2.webp', timestamp: 5.0 }, + { key: 'files/asset-video/screenshots/shot1.webp', timestamp: 0.0 }, + { key: 'files/asset-video/screenshots/shot2.webp', timestamp: 5.0 }, ], }, }) @@ -336,7 +336,7 @@ describe('Transcode Workflow', () => { }) mockActivities.overlayAnnotationsActivity.mockResolvedValue( - 'file/asset-image/annotations/ann1.webp', + 'files/asset-image/annotations/ann1.webp', ) await transcodeMedia(task) @@ -350,7 +350,7 @@ describe('Transcode Workflow', () => { expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({ taskId: 'task-image-ann', status: WorkflowTaskStatus.completed, - output: { key: 'file/asset-image/annotations/ann1.webp' }, + output: { key: 'files/asset-image/annotations/ann1.webp' }, }) }) }) diff --git a/packages/webui/components/folder-tree.tsx b/packages/webui/components/folder-tree.tsx index 3db77c50..fa37c92e 100644 --- a/packages/webui/components/folder-tree.tsx +++ b/packages/webui/components/folder-tree.tsx @@ -1,44 +1,4 @@ -import type { AssetInfoPaginatedList, AssetInfo } from '@shumai/dtos' import { client } from '@/ui/api/client' -import { usePermissions } from '@/ui/hooks/use-permissions' -import { cn } from '@/ui/lib/utils' -import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query' -import { useMatch, useNavigate, useParams } from '@tanstack/react-router' -import { - ChevronDown, - ChevronsDownUp, - ChevronsUpDown, - ChevronRight, - Clapperboard, - Folder, - Loader2, - Trash2, - Plus, - Share2, - LayoutGrid, - Bookmark, - MoreHorizontal, -} from 'lucide-react' -import { useEffect, useMemo, useState } from 'react' -import { useInView } from 'react-intersection-observer' -import { useDraggable, useDroppable } from '@dnd-kit/react' -import type { DragState } from './dnd-types' -import { toast } from 'sonner' -import type { ShareLinkInfo } from '@shumai/dtos' -import type { CollectionInfo } from '@shumai/dtos' -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from '@/ui/components/ui/dropdown-menu' -import { - Dialog, - DialogContent, - DialogHeader, - DialogTitle, - DialogFooter, -} from '@/ui/components/ui/dialog' import { AlertDialog, AlertDialogAction, @@ -49,8 +9,46 @@ import { AlertDialogHeader, AlertDialogTitle, } from '@/ui/components/ui/alert-dialog' -import { Input } from '@/ui/components/ui/input' import { Button } from '@/ui/components/ui/button' +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/ui/components/ui/dialog' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '@/ui/components/ui/dropdown-menu' +import { Input } from '@/ui/components/ui/input' +import { usePermissions } from '@/ui/hooks/use-permissions' +import { cn } from '@/ui/lib/utils' +import { useDraggable, useDroppable } from '@dnd-kit/react' +import type { AssetInfo, AssetInfoPaginatedList, CollectionInfo, ShareLinkInfo } from '@shumai/dtos' +import { useInfiniteQuery, useMutation, useQueryClient } from '@tanstack/react-query' +import { useMatch, useNavigate, useParams } from '@tanstack/react-router' +import { + Bookmark, + ChevronDown, + ChevronRight, + ChevronsDownUp, + ChevronsUpDown, + Clapperboard, + Folder, + LayoutGrid, + Loader2, + MoreHorizontal, + Plus, + Share2, + Trash2, +} from 'lucide-react' +import { useEffect, useMemo, useState } from 'react' +import { useInView } from 'react-intersection-observer' +import { toast } from 'sonner' +import type { DragState } from './dnd-types' interface FolderTreeProps { teamId: string @@ -87,32 +85,76 @@ export function FolderTree({ const [isCollectionsExpanded, setIsCollectionsExpanded] = useState(true) const [isSharesExpanded, setIsSharesExpanded] = useState(true) - const { data: shareLinksData } = useQuery({ + const { + data: shareLinksData, + fetchNextPage: fetchNextShareLinks, + hasNextPage: hasNextShareLinks, + isFetchingNextPage: isFetchingNextShareLinks, + } = useInfiniteQuery({ queryKey: ['shares', projectId], - queryFn: async () => { + queryFn: async ({ pageParam }) => { const res = await client.api.projects[':projectId'].shares.$get({ param: { projectId }, - query: { first: '100' }, + query: { first: '20', after: pageParam as string }, }) if (!res.ok) throw new Error('Failed to fetch share links') - return (await res.json()) as unknown as { data: ShareLinkInfo[] } + return (await res.json()) as unknown as { + data: ShareLinkInfo[] + pageInfo: { cursor?: string; total?: number } + } }, + initialPageParam: '', + getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, enabled: !!projectId, }) - const { data: collectionsData } = useQuery({ + const { + data: collectionsData, + fetchNextPage: fetchNextCollections, + hasNextPage: hasNextCollections, + isFetchingNextPage: isFetchingNextCollections, + } = useInfiniteQuery({ queryKey: ['collections', projectId], - queryFn: async () => { + queryFn: async ({ pageParam }) => { const res = await client.api.projects[':projectId'].collections.$get({ param: { projectId }, - query: { first: '100' }, + query: { first: '20', after: pageParam as string }, }) if (!res.ok) throw new Error('Failed to fetch collections') - return (await res.json()) as unknown as { data: CollectionInfo[] } + return (await res.json()) as unknown as { + data: CollectionInfo[] + pageInfo: { cursor?: string; total?: number } + } }, + initialPageParam: '', + getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, enabled: !!projectId, }) + const { ref: collectionsInViewRef, inView: collectionsInView } = useInView() + const { ref: sharesInViewRef, inView: sharesInView } = useInView() + + useEffect(() => { + if (collectionsInView && hasNextCollections && !isFetchingNextCollections) { + fetchNextCollections() + } + }, [collectionsInView, hasNextCollections, isFetchingNextCollections, fetchNextCollections]) + + useEffect(() => { + if (sharesInView && hasNextShareLinks && !isFetchingNextShareLinks) { + fetchNextShareLinks() + } + }, [sharesInView, hasNextShareLinks, isFetchingNextShareLinks, fetchNextShareLinks]) + + const collections = useMemo( + () => collectionsData?.pages.flatMap((p) => p.data) || [], + [collectionsData], + ) + const shareLinks = useMemo( + () => shareLinksData?.pages.flatMap((p) => p.data) || [], + [shareLinksData], + ) + const { mutate: createCollection } = useMutation({ mutationFn: async () => { const res = await client.api.projects[':projectId'].collections.$post({ @@ -276,8 +318,6 @@ export function FolderTree({ }, }) - const shareLinks = shareLinksData?.data ?? [] - return (
- All Collections ({collectionsData?.data.length || 0}) + All Collections ({collectionsData?.pages[0]?.pageInfo?.total || 0})
- {collectionsData?.data.map((collection) => { + {collections.map((collection) => { const isColActive = params?.collectionId === collection.id return (
) })} +
+ {isFetchingNextCollections && ( +
+ +
+ )}
)} @@ -534,7 +580,7 @@ export function FolderTree({ - All Share Links ({shareLinks.length}) + All Share Links ({shareLinksData?.pages[0]?.pageInfo?.total || 0}) @@ -558,6 +604,12 @@ export function FolderTree({ }} /> ))} +
+ {isFetchingNextShareLinks && ( +
+ +
+ )}
)} diff --git a/packages/webui/components/upload-tasks.tsx b/packages/webui/components/upload-tasks.tsx index ea25e57f..427008ec 100644 --- a/packages/webui/components/upload-tasks.tsx +++ b/packages/webui/components/upload-tasks.tsx @@ -2,6 +2,7 @@ import { client } from '@/ui/api/client' import type { TaskInfo } from '@shumai/dtos' import { useTeamId } from '@/ui/hooks/use-team-id' import { useInfiniteQuery } from '@tanstack/react-query' +import { useUploadStore } from '@/ui/stores/upload' import { Loader2, CheckCircle2, Clock, UploadCloud } from 'lucide-react' import { useEffect } from 'react' import { useInView } from 'react-intersection-observer' @@ -90,6 +91,7 @@ interface TaskGroup { export function UploadTasks() { const teamId = useTeamId() + const uploading = useUploadStore((state) => state.uploading) const { data: tasksData, fetchNextPage, @@ -111,6 +113,7 @@ export function UploadTasks() { return lastPage.pageInfo?.cursor || undefined }, enabled: !!teamId, + refetchInterval: uploading > 0 ? 2000 : false, }) const { ref, inView } = useInView() diff --git a/packages/webui/routes/projects/$projectId/collections/index.tsx b/packages/webui/routes/projects/$projectId/collections/index.tsx index 07d37224..c41fea8c 100644 --- a/packages/webui/routes/projects/$projectId/collections/index.tsx +++ b/packages/webui/routes/projects/$projectId/collections/index.tsx @@ -12,10 +12,11 @@ import { import { Avatar, AvatarImage, AvatarFallback } from '@/ui/components/ui/avatar' import { useUiStore } from '@/ui/stores/ui' import { useTeamContextStore } from '@/ui/stores/team-context' -import { useQuery, useSuspenseQuery } from '@tanstack/react-query' +import { useInfiniteQuery, useSuspenseQuery } from '@tanstack/react-query' import { createFileRoute, useNavigate } from '@tanstack/react-router' -import { useEffect, useState } from 'react' -import { Bookmark, Calendar, LayoutGrid } from 'lucide-react' +import { useEffect, useMemo, useState } from 'react' +import { Bookmark, Calendar, LayoutGrid, Loader2 } from 'lucide-react' +import { useInView } from 'react-intersection-observer' import type { CollectionInfo } from '@shumai/dtos' import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons' @@ -59,25 +60,47 @@ function CollectionsPage() { setFileListLeftSidebarCollapsed: setIsLeftSidebarCollapsed, } = useUiStore() - const { data: collectionsData, isLoading: isCollectionsLoading } = useQuery({ + const { + data: collectionsData, + isLoading: isCollectionsLoading, + fetchNextPage, + hasNextPage, + isFetchingNextPage, + } = useInfiniteQuery({ queryKey: ['collections', projectId], - queryFn: async () => { + queryFn: async ({ pageParam }) => { const res = await client.api.projects[':projectId'].collections.$get({ param: { projectId }, - query: { first: '100' }, + query: { first: '20', after: pageParam as string }, }) if (!res.ok) throw new Error('Failed to fetch collections') - return (await res.json()) as unknown as { data: CollectionInfo[] } + return (await res.json()) as unknown as { + data: CollectionInfo[] + pageInfo: { cursor?: string; total?: number } + } }, + initialPageParam: '', + getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, enabled: !!projectId, }) + const { ref: inViewRef, inView } = useInView() + + useEffect(() => { + if (inView && hasNextPage && !isFetchingNextPage) { + fetchNextPage() + } + }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage]) + + const collections = useMemo( + () => collectionsData?.pages.flatMap((p) => p.data) || [], + [collectionsData], + ) + if (!teamId || !rootFolderId || !projectInfo) { return } - const collections = collectionsData?.data ?? [] - return (
@@ -187,6 +210,9 @@ function CollectionsPage() { ))} +
+ {isFetchingNextPage && } +
)}
diff --git a/packages/webui/routes/projects/$projectId/shares/index.tsx b/packages/webui/routes/projects/$projectId/shares/index.tsx index 5ebac6a6..b74b7fc3 100644 --- a/packages/webui/routes/projects/$projectId/shares/index.tsx +++ b/packages/webui/routes/projects/$projectId/shares/index.tsx @@ -14,10 +14,16 @@ import { import { Avatar, AvatarImage, AvatarFallback } from '@/ui/components/ui/avatar' import { useUiStore } from '@/ui/stores/ui' import { useTeamContextStore } from '@/ui/stores/team-context' -import { useMutation, useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query' +import { + useMutation, + useInfiniteQuery, + useQueryClient, + useSuspenseQuery, +} from '@tanstack/react-query' import { createFileRoute, useNavigate } from '@tanstack/react-router' -import { useEffect, useState } from 'react' -import { Copy, ExternalLink, Calendar, Link2, Share2 } from 'lucide-react' +import { useEffect, useMemo, useState } from 'react' +import { Copy, ExternalLink, Calendar, Link2, Share2, Loader2 } from 'lucide-react' +import { useInView } from 'react-intersection-observer' import { toast } from 'sonner' import type { ShareLinkInfo } from '@shumai/dtos' import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons' @@ -63,19 +69,40 @@ function SharesPage() { setFileListLeftSidebarCollapsed: setIsLeftSidebarCollapsed, } = useUiStore() - const { data: sharesData, isLoading: isSharesLoading } = useQuery({ + const { + data: sharesData, + isLoading: isSharesLoading, + fetchNextPage, + hasNextPage, + isFetchingNextPage, + } = useInfiniteQuery({ queryKey: ['shares', projectId], - queryFn: async () => { + queryFn: async ({ pageParam }) => { const res = await client.api.projects[':projectId'].shares.$get({ param: { projectId }, - query: { first: '100' }, + query: { first: '20', after: pageParam as string }, }) if (!res.ok) throw new Error('Failed to fetch share links') - return (await res.json()) as unknown as { data: ShareLinkInfo[] } + return (await res.json()) as unknown as { + data: ShareLinkInfo[] + pageInfo: { cursor?: string; total?: number } + } }, + initialPageParam: '', + getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, enabled: !!projectId, }) + const { ref: inViewRef, inView } = useInView() + + useEffect(() => { + if (inView && hasNextPage && !isFetchingNextPage) { + fetchNextPage() + } + }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage]) + + const shares = useMemo(() => sharesData?.pages.flatMap((p) => p.data) || [], [sharesData]) + const { mutate: toggleVisibility } = useMutation({ mutationFn: async ({ id, isDisabled }: { id: string; isDisabled: boolean }) => { const res = await client.api.shares[':shareId'].$put({ @@ -98,8 +125,6 @@ function SharesPage() { return } - const shares = sharesData?.data ?? [] - const handleCopyLink = (shareId: string) => { const url = `${window.location.origin}/share/${shareId}` navigator.clipboard.writeText(url) @@ -255,6 +280,9 @@ function SharesPage() { })} +
+ {isFetchingNextPage && } +
)}