(sessionId: string, filePath: string, content: string)
| 283 | * Write a file to the container |
| 284 | */ |
| 285 | export async function writeFile(sessionId: string, filePath: string, content: string): Promise<void> { |
| 286 | const container = containerCache.get(sessionId); |
| 287 | if (!container) { |
| 288 | throw new Error(`No container found for session: ${sessionId}`); |
| 289 | } |
| 290 | |
| 291 | try { |
| 292 | const pack = tar.pack(); |
| 293 | const fileName = filePath.split('/').pop() || 'file'; |
| 294 | const dirPath = filePath.substring(0, filePath.lastIndexOf('/')) || '/workspace'; |
| 295 | |
| 296 | pack.entry({ name: fileName }, content); |
| 297 | pack.finalize(); |
| 298 | |
| 299 | await container.putArchive(pack, { path: dirPath }); |
| 300 | logger.info('File written to container', { sessionId, filePath }); |
| 301 | } catch (error) { |
| 302 | logger.error('Failed to write file to container', { sessionId, filePath, error }); |
| 303 | throw new Error(`Failed to write file: ${error}`); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Destroy container and clean up resources |
no outgoing calls
no test coverage detected