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