* Unified read handler that combines multiple reading operations
(args: Record<string, unknown>)
| 285 | * Unified read handler that combines multiple reading operations |
| 286 | */ |
| 287 | async function handleRead(args: Record<string, unknown>) { |
| 288 | const parsedArgs = readArgsSchema.safeParse(args) |
| 289 | if (!parsedArgs.success) { |
| 290 | return { |
| 291 | content: [ |
| 292 | { |
| 293 | type: 'text', |
| 294 | text: 'Invalid args for deepnote_read: path is required and optional fields must match expected types', |
| 295 | }, |
| 296 | ], |
| 297 | isError: true, |
| 298 | } |
| 299 | } |
| 300 | const filePath = parsedArgs.data.path |
| 301 | const includeRaw = parsedArgs.data.include |
| 302 | const notebookFilter = parsedArgs.data.notebook |
| 303 | const compact = parsedArgs.data.compact |
| 304 | |
| 305 | // Default to structure only |
| 306 | const includeValues = includeRaw && includeRaw.length > 0 ? includeRaw : ['structure'] |
| 307 | const include = new Set(includeValues) |
| 308 | const includeAll = include.has('all') |
| 309 | |
| 310 | let file: DeepnoteFile |
| 311 | try { |
| 312 | file = await loadDeepnoteFile(filePath) |
| 313 | } catch (error) { |
| 314 | const message = error instanceof Error ? error.message : String(error) |
| 315 | return { |
| 316 | content: [{ type: 'text', text: `Failed to read file "${filePath}": ${message}` }], |
| 317 | isError: true, |
| 318 | } |
| 319 | } |
| 320 | const result: Record<string, unknown> = { path: filePath } |
| 321 | |
| 322 | if (includeAll || include.has('structure')) { |
| 323 | result.structure = computeStructure(file) |
| 324 | } |
| 325 | |
| 326 | if (includeAll || include.has('stats')) { |
| 327 | const stats = computeStats(file) |
| 328 | result.stats = { |
| 329 | totalLines: stats.totalLines, |
| 330 | uniqueImports: stats.uniqueImports, |
| 331 | importCount: stats.importCount, |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | if (includeAll || include.has('lint')) { |
| 336 | const issues = await computeLintIssues(file) |
| 337 | result.lint = { |
| 338 | issueCount: issues.length, |
| 339 | issues: compact && issues.length === 0 ? undefined : issues, |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | if (includeAll || include.has('dag')) { |
| 344 | result.dag = await computeDagInfo(file, notebookFilter) |
no test coverage detected