Skip to content

Commit e47b27f

Browse files
committed
refactor(copilot): dedup getDocumentFormatInfo across copilot file tools
The same extension -> { formatName, sourceMime, taskId } mapping was duplicated in workspace-file.ts and edit-content.ts. Any future format or task-id change had to happen in two places. Exports getDocumentFormatInfo + DocumentFormatInfo from workspace-file.ts (which already owned the PPTX/DOCX/PDF source MIME constants) and imports it in edit-content.ts. Same source-of-truth pattern the file already uses for inferContentType. Made-with: Cursor
1 parent a1c099c commit e47b27f

File tree

2 files changed

+5
-38
lines changed

2 files changed

+5
-38
lines changed

apps/sim/lib/copilot/tools/server/files/edit-content.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import {
77
import { toError } from '@/lib/core/utils/helpers'
88
import { runSandboxTask } from '@/lib/execution/sandbox/run-task'
99
import { updateWorkspaceFileContent } from '@/lib/uploads/contexts/workspace/workspace-file-manager'
10-
import type { SandboxTaskId } from '@/sandbox-tasks/registry'
1110
import { consumeLatestFileIntent } from './file-intent-store'
12-
import { inferContentType } from './workspace-file'
11+
import { getDocumentFormatInfo, inferContentType } from './workspace-file'
1312

1413
const logger = createLogger('EditContentServerTool')
1514

@@ -23,40 +22,6 @@ type EditContentResult = {
2322
data?: Record<string, unknown>
2423
}
2524

26-
function getDocumentFormatInfo(fileName: string): {
27-
isDoc: boolean
28-
formatName?: string
29-
sourceMime?: string
30-
taskId?: SandboxTaskId
31-
} {
32-
const lowerName = fileName.toLowerCase()
33-
if (lowerName.endsWith('.pptx')) {
34-
return {
35-
isDoc: true,
36-
formatName: 'PPTX',
37-
sourceMime: 'text/x-pptxgenjs',
38-
taskId: 'pptx-generate',
39-
}
40-
}
41-
if (lowerName.endsWith('.docx')) {
42-
return {
43-
isDoc: true,
44-
formatName: 'DOCX',
45-
sourceMime: 'text/x-docxjs',
46-
taskId: 'docx-generate',
47-
}
48-
}
49-
if (lowerName.endsWith('.pdf')) {
50-
return {
51-
isDoc: true,
52-
formatName: 'PDF',
53-
sourceMime: 'text/x-pdflibjs',
54-
taskId: 'pdf-generate',
55-
}
56-
}
57-
return { isDoc: false }
58-
}
59-
6025
export const editContentServerTool: BaseServerTool<EditContentArgs, EditContentResult> = {
6126
name: 'edit_content',
6227
async execute(params: EditContentArgs, context?: ServerToolContext): Promise<EditContentResult> {

apps/sim/lib/copilot/tools/server/files/workspace-file.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ export function validateFlatWorkspaceFileName(fileName: string): string | null {
102102
return null
103103
}
104104

105-
function getDocumentFormatInfo(fileName: string): {
105+
export interface DocumentFormatInfo {
106106
isDoc: boolean
107107
formatName?: 'PPTX' | 'DOCX' | 'PDF'
108108
sourceMime?: string
109109
taskId?: SandboxTaskId
110-
} {
110+
}
111+
112+
export function getDocumentFormatInfo(fileName: string): DocumentFormatInfo {
111113
const lowerName = fileName.toLowerCase()
112114
if (lowerName.endsWith('.pptx')) {
113115
return {

0 commit comments

Comments
 (0)