Skip to content

Commit 40153de

Browse files
committed
style: fix code review issues in VoyageAI integration
Remove non-TSDoc separator comments, fix relative import in barrel export, fix any types, and apply biome formatting fixes.
1 parent 363df7b commit 40153de

File tree

8 files changed

+33
-29
lines changed

8 files changed

+33
-29
lines changed

apps/sim/app/api/tools/voyageai/multimodal-embeddings/route.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ export async function POST(request: NextRequest) {
4141

4242
const content: Array<Record<string, string>> = []
4343

44-
// Add text content
4544
if (params.input?.trim()) {
4645
content.push({ type: 'text', text: params.input })
4746
}
4847

49-
// Process image files → base64
5048
if (params.imageFiles) {
5149
const files = Array.isArray(params.imageFiles) ? params.imageFiles : [params.imageFiles]
5250
for (const rawFile of files) {
@@ -66,14 +64,16 @@ export async function POST(request: NextRequest) {
6664
} catch (error) {
6765
logger.error(`[${requestId}] Failed to process image file:`, error)
6866
return NextResponse.json(
69-
{ success: false, error: `Failed to process image file: ${error instanceof Error ? error.message : 'Unknown error'}` },
67+
{
68+
success: false,
69+
error: `Failed to process image file: ${error instanceof Error ? error.message : 'Unknown error'}`,
70+
},
7071
{ status: 400 }
7172
)
7273
}
7374
}
7475
}
7576

76-
// Process image URLs
7777
if (params.imageUrls?.trim()) {
7878
let urls: string[]
7979
try {
@@ -97,7 +97,6 @@ export async function POST(request: NextRequest) {
9797
}
9898
}
9999

100-
// Process video file → base64
101100
if (params.videoFile) {
102101
try {
103102
const userFile = processSingleFileToUserFile(params.videoFile, requestId, logger)
@@ -115,13 +114,15 @@ export async function POST(request: NextRequest) {
115114
} catch (error) {
116115
logger.error(`[${requestId}] Failed to process video file:`, error)
117116
return NextResponse.json(
118-
{ success: false, error: `Failed to process video file: ${error instanceof Error ? error.message : 'Unknown error'}` },
117+
{
118+
success: false,
119+
error: `Failed to process video file: ${error instanceof Error ? error.message : 'Unknown error'}`,
120+
},
119121
{ status: 400 }
120122
)
121123
}
122124
}
123125

124-
// Process video URL
125126
if (params.videoUrl?.trim()) {
126127
const validation = await validateUrlWithDNS(params.videoUrl, 'videoUrl')
127128
if (!validation.isValid) {
@@ -145,7 +146,6 @@ export async function POST(request: NextRequest) {
145146
model: params.model,
146147
})
147148

148-
// Build VoyageAI request
149149
const voyageBody: Record<string, unknown> = {
150150
inputs: [{ content }],
151151
model: params.model,

apps/sim/blocks/blocks/voyageai.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const VoyageAIBlock: BlockConfig = {
2727
],
2828
value: () => 'embeddings',
2929
},
30-
// === Text Embeddings fields ===
3130
{
3231
id: 'input',
3332
title: 'Input Text',
@@ -66,7 +65,6 @@ export const VoyageAIBlock: BlockConfig = {
6665
value: () => 'document',
6766
mode: 'advanced',
6867
},
69-
// === Multimodal Embeddings fields ===
7068
{
7169
id: 'multimodalInput',
7270
title: 'Text Input',
@@ -153,7 +151,6 @@ export const VoyageAIBlock: BlockConfig = {
153151
value: () => 'document',
154152
mode: 'advanced',
155153
},
156-
// === Rerank fields ===
157154
{
158155
id: 'query',
159156
title: 'Query',
@@ -191,7 +188,6 @@ export const VoyageAIBlock: BlockConfig = {
191188
condition: { field: 'operation', value: 'rerank' },
192189
mode: 'advanced',
193190
},
194-
// === Common fields ===
195191
{
196192
id: 'apiKey',
197193
title: 'API Key',

apps/sim/tools/voyageai/embeddings.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { VoyageAIEmbeddingsParams, VoyageAIEmbeddingsResponse } from '@/tools/voyageai/types'
21
import type { ToolConfig } from '@/tools/types'
2+
import type { VoyageAIEmbeddingsParams, VoyageAIEmbeddingsResponse } from '@/tools/voyageai/types'
33

44
export const embeddingsTool: ToolConfig<VoyageAIEmbeddingsParams, VoyageAIEmbeddingsResponse> = {
55
id: 'voyageai_embeddings',
@@ -25,7 +25,8 @@ export const embeddingsTool: ToolConfig<VoyageAIEmbeddingsParams, VoyageAIEmbedd
2525
type: 'string',
2626
required: false,
2727
visibility: 'user-only',
28-
description: 'Type of input: "query" for search queries, "document" for documents to be indexed',
28+
description:
29+
'Type of input: "query" for search queries, "document" for documents to be indexed',
2930
},
3031
apiKey: {
3132
type: 'string',

apps/sim/tools/voyageai/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export const voyageaiEmbeddingsTool = embeddingsTool
66
export const voyageaiMultimodalEmbeddingsTool = multimodalEmbeddingsTool
77
export const voyageaiRerankTool = rerankTool
88

9-
export * from './types'
9+
export * from '@/tools/voyageai/types'

apps/sim/tools/voyageai/multimodal-embeddings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import type { ToolConfig } from '@/tools/types'
12
import type {
23
VoyageAIMultimodalEmbeddingsParams,
34
VoyageAIMultimodalEmbeddingsResponse,
45
} from '@/tools/voyageai/types'
5-
import type { ToolConfig } from '@/tools/types'
66

77
export const multimodalEmbeddingsTool: ToolConfig<
88
VoyageAIMultimodalEmbeddingsParams,

apps/sim/tools/voyageai/rerank.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { VoyageAIRerankParams, VoyageAIRerankResponse } from '@/tools/voyageai/types'
21
import type { ToolConfig } from '@/tools/types'
2+
import type { VoyageAIRerankParams, VoyageAIRerankResponse } from '@/tools/voyageai/types'
33

44
export const rerankTool: ToolConfig<VoyageAIRerankParams, VoyageAIRerankResponse> = {
55
id: 'voyageai_rerank',

apps/sim/tools/voyageai/voyageai.integration.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ const describeIntegration = API_KEY ? describe : describe.skip
1616
* Use undici's fetch directly to bypass the global fetch mock set up in vitest.setup.ts.
1717
*/
1818
async function liveFetch(url: string, init: RequestInit): Promise<Response> {
19-
// vi.mocked(fetch) is the mock — call the real underlying impl
2019
const { request } = await import('undici')
2120
const resp = await request(url, {
22-
method: init.method as any,
21+
method: init.method as 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',
2322
headers: init.headers as Record<string, string>,
2423
body: init.body as string,
2524
})
@@ -359,7 +358,11 @@ describeIntegration('VoyageAI Integration Tests (live API)', () => {
359358
}, 15000)
360359

361360
it('should reject invalid API key', async () => {
362-
const headers = rerankTool.request.headers({ apiKey: 'invalid-key', query: '', documents: [] })
361+
const headers = rerankTool.request.headers({
362+
apiKey: 'invalid-key',
363+
query: '',
364+
documents: [],
365+
})
363366
const body = rerankTool.request.body!({
364367
apiKey: 'invalid-key',
365368
query: 'test',
@@ -416,7 +419,11 @@ describeIntegration('VoyageAI Integration Tests (live API)', () => {
416419
query: 'What are neural networks used for?',
417420
documents,
418421
})
419-
const rerankHeaders = rerankTool.request.headers({ apiKey: API_KEY!, query: '', documents: [] })
422+
const rerankHeaders = rerankTool.request.headers({
423+
apiKey: API_KEY!,
424+
query: '',
425+
documents: [],
426+
})
420427
const rerankUrl =
421428
typeof rerankTool.request.url === 'function'
422429
? rerankTool.request.url({ apiKey: API_KEY!, query: '', documents: [] })
@@ -451,7 +458,9 @@ describeIntegration('VoyageAI Integration Tests (live API)', () => {
451458

452459
// The AI-related docs should score higher than the unrelated ones
453460
const aiDocIndices = [0, 2] // "Neural networks..." and "Deep learning..."
454-
const topTwoIndices = rerankResult.output.results.slice(0, 2).map((r: any) => r.index)
461+
const topTwoIndices = rerankResult.output.results
462+
.slice(0, 2)
463+
.map((r: { index: number }) => r.index)
455464
const aiDocsInTop2 = topTwoIndices.filter((i: number) => aiDocIndices.includes(i))
456465
expect(aiDocsInTop2.length).toBeGreaterThanOrEqual(1)
457466
}, 30000)

apps/sim/tools/voyageai/voyageai.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ describe('Voyage AI Rerank Tool', () => {
314314

315315
describe('URL Construction', () => {
316316
it('should return the VoyageAI rerank endpoint', () => {
317-
expect(
318-
tester.getRequestUrl({ apiKey: 'key', query: 'test', documents: ['doc1'] })
319-
).toBe('https://api.voyageai.com/v1/rerank')
317+
expect(tester.getRequestUrl({ apiKey: 'key', query: 'test', documents: ['doc1'] })).toBe(
318+
'https://api.voyageai.com/v1/rerank'
319+
)
320320
})
321321
})
322322

@@ -490,7 +490,7 @@ describe('Voyage AI Rerank Tool', () => {
490490
data: [
491491
{ index: 2, relevance_score: 0.99 },
492492
{ index: 0, relevance_score: 0.75 },
493-
{ index: 1, relevance_score: 0.30 },
493+
{ index: 1, relevance_score: 0.3 },
494494
],
495495
model: 'rerank-2',
496496
usage: { total_tokens: 40 },
@@ -595,9 +595,7 @@ describe('Voyage AI Multimodal Embeddings Tool', () => {
595595
})
596596

597597
it('should use internal proxy URL', () => {
598-
expect(multimodalEmbeddingsTool.request.url).toBe(
599-
'/api/tools/voyageai/multimodal-embeddings'
600-
)
598+
expect(multimodalEmbeddingsTool.request.url).toBe('/api/tools/voyageai/multimodal-embeddings')
601599
})
602600

603601
it('should use POST method', () => {

0 commit comments

Comments
 (0)