(params: CreateFileArgs, context?: ServerToolContext)
| 34 | export const createFileServerTool: BaseServerTool<CreateFileArgs, CreateFileResult> = { |
| 35 | name: CREATE_FILE_TOOL_ID, |
| 36 | async execute(params: CreateFileArgs, context?: ServerToolContext): Promise<CreateFileResult> { |
| 37 | if (!context?.userId) { |
| 38 | throw new Error('Authentication required') |
| 39 | } |
| 40 | const workspaceId = context.workspaceId |
| 41 | if (!workspaceId) { |
| 42 | return { success: false, message: 'Workspace ID is required' } |
| 43 | } |
| 44 | await ensureWorkspaceAccess(workspaceId, context.userId, 'write') |
| 45 | |
| 46 | const nested = params.args |
| 47 | const fileName = params.fileName || (nested?.fileName as string) || '' |
| 48 | const explicitType = params.contentType || (nested?.contentType as string) || undefined |
| 49 | const outputFile = params.outputs?.files?.[0] |
| 50 | if (!outputFile?.path && !fileName) { |
| 51 | return { success: false, message: 'create_file requires outputs.files[0].path or fileName' } |
| 52 | } |
| 53 | const outputPath = |
| 54 | outputFile?.path ?? (fileName.startsWith('files/') ? fileName : `files/${fileName}`) |
| 55 | if (isPlanAliasPath(outputPath)) { |
| 56 | return { |
| 57 | success: false, |
| 58 | message: |
| 59 | 'create_file does not initialize plan aliases; changelog.md is created automatically per workflow.', |
| 60 | } |
| 61 | } |
| 62 | const contentType = outputFile?.mimeType ?? inferContentType(outputPath, explicitType) |
| 63 | const emptyBuffer = Buffer.from('', 'utf-8') |
| 64 | |
| 65 | assertServerToolNotAborted(context) |
| 66 | const result = await writeWorkspaceFileByPath({ |
| 67 | workspaceId, |
| 68 | userId: context.userId, |
| 69 | target: { |
| 70 | path: outputPath, |
| 71 | mode: outputFile?.mode ?? 'create', |
| 72 | mimeType: outputFile?.mimeType, |
| 73 | }, |
| 74 | buffer: emptyBuffer, |
| 75 | inferredMimeType: contentType, |
| 76 | }) |
| 77 | |
| 78 | logger.info('File created via create_file', { |
| 79 | fileId: result.id, |
| 80 | name: result.vfsPath, |
| 81 | contentType, |
| 82 | userId: context.userId, |
| 83 | }) |
| 84 | |
| 85 | return { |
| 86 | success: true, |
| 87 | message: `File "${result.vfsPath}" created successfully`, |
| 88 | data: { |
| 89 | id: result.id, |
| 90 | name: result.name, |
| 91 | contentType, |
| 92 | vfsPath: result.vfsPath, |
| 93 | backingVfsPath: result.backingVfsPath, |
nothing calls this directly
no test coverage detected