(args: Record<string, unknown>)
| 253 | } |
| 254 | |
| 255 | async function handleConvertFrom(args: Record<string, unknown>) { |
| 256 | const parsedArgs = convertFromArgsSchema.safeParse(args) |
| 257 | if (!parsedArgs.success) { |
| 258 | return toError(`Invalid arguments for deepnote_convert_from: ${formatFirstIssue(parsedArgs.error)}`) |
| 259 | } |
| 260 | const { inputPath, outputDir } = parsedArgs.data |
| 261 | const format = parsedArgs.data.format ?? 'jupyter' |
| 262 | |
| 263 | const absoluteInput = path.resolve(inputPath) |
| 264 | |
| 265 | let inputStat: Awaited<ReturnType<typeof fs.stat>> |
| 266 | try { |
| 267 | inputStat = await fs.stat(absoluteInput) |
| 268 | } catch (error) { |
| 269 | const message = error instanceof Error ? error.message : String(error) |
| 270 | return toError(`Invalid inputPath: ${message}`) |
| 271 | } |
| 272 | |
| 273 | if (!inputStat.isFile()) { |
| 274 | return toError('inputPath for deepnote_convert_from must point to a file') |
| 275 | } |
| 276 | |
| 277 | const finalOutputDir = outputDir ? path.resolve(outputDir) : path.dirname(absoluteInput) |
| 278 | |
| 279 | try { |
| 280 | await runFromDeepnoteConversion(format, absoluteInput, { outputDir: finalOutputDir }) |
| 281 | |
| 282 | return { |
| 283 | content: [ |
| 284 | { |
| 285 | type: 'text', |
| 286 | text: JSON.stringify( |
| 287 | { |
| 288 | success: true, |
| 289 | inputPath: absoluteInput, |
| 290 | outputFormat: format, |
| 291 | outputDir: finalOutputDir, |
| 292 | }, |
| 293 | null, |
| 294 | 2 |
| 295 | ), |
| 296 | }, |
| 297 | ], |
| 298 | } |
| 299 | } catch (error) { |
| 300 | const message = error instanceof Error ? error.message : String(error) |
| 301 | return { |
| 302 | content: [{ type: 'text', text: `Conversion failed: ${message}` }], |
| 303 | isError: true, |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | export async function handleConversionTool(name: string, args: Record<string, unknown> | undefined) { |
| 309 | const safeArgs = args || {} |
no test coverage detected