( notebookPath: string, cellId?: string, )
| 164 | * Reads and parses a Jupyter notebook file into processed cell data |
| 165 | */ |
| 166 | export async function readNotebook( |
| 167 | notebookPath: string, |
| 168 | cellId?: string, |
| 169 | ): Promise<NotebookCellSource[]> { |
| 170 | const fullPath = expandPath(notebookPath) |
| 171 | const buffer = await getFsImplementation().readFileBytes(fullPath) |
| 172 | const content = buffer.toString('utf-8') |
| 173 | const notebook = jsonParse(content) as NotebookContent |
| 174 | const language = notebook.metadata.language_info?.name ?? 'python' |
| 175 | if (cellId) { |
| 176 | const cell = notebook.cells.find(c => c.id === cellId) |
| 177 | if (!cell) { |
| 178 | throw new Error(`Cell with ID "${cellId}" not found in notebook`) |
| 179 | } |
| 180 | return [processCell(cell, notebook.cells.indexOf(cell), language, true)] |
| 181 | } |
| 182 | return notebook.cells.map((cell, index) => |
| 183 | processCell(cell, index, language, false), |
| 184 | ) |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Maps notebook cell data to tool result block parameters with sophisticated text block merging |
no test coverage detected