( cell: NotebookCell, index: number, codeLanguage: string, includeLargeOutputs: boolean, )
| 81 | } |
| 82 | |
| 83 | function processCell( |
| 84 | cell: NotebookCell, |
| 85 | index: number, |
| 86 | codeLanguage: string, |
| 87 | includeLargeOutputs: boolean, |
| 88 | ): NotebookCellSource { |
| 89 | const cellId = cell.id ?? `cell-${index}` |
| 90 | const cellData: NotebookCellSource = { |
| 91 | cellType: cell.cell_type, |
| 92 | source: Array.isArray(cell.source) ? cell.source.join('') : cell.source, |
| 93 | execution_count: |
| 94 | cell.cell_type === 'code' ? cell.execution_count || undefined : undefined, |
| 95 | cell_id: cellId, |
| 96 | } |
| 97 | // Avoid giving text cells the code language. |
| 98 | if (cell.cell_type === 'code') { |
| 99 | cellData.language = codeLanguage |
| 100 | } |
| 101 | |
| 102 | if (cell.cell_type === 'code' && cell.outputs?.length) { |
| 103 | const outputs = cell.outputs.map(processOutput) |
| 104 | if (!includeLargeOutputs && isLargeOutputs(outputs)) { |
| 105 | cellData.outputs = [ |
| 106 | { |
| 107 | output_type: 'stream', |
| 108 | text: `Outputs are too large to include. Use ${BASH_TOOL_NAME} with: cat <notebook_path> | jq '.cells[${index}].outputs'`, |
| 109 | }, |
| 110 | ] |
| 111 | } else { |
| 112 | cellData.outputs = outputs |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return cellData |
| 117 | } |
| 118 | |
| 119 | function cellContentToToolResult(cell: NotebookCellSource): TextBlockParam { |
| 120 | const metadata = [] |
no test coverage detected