MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / mapNotebookCellsToToolResult

Function mapNotebookCellsToToolResult

source code/utils/notebook.ts:190–217  ·  view source on GitHub ↗
(
  data: NotebookCellSource[],
  toolUseID: string,
)

Source from the content-addressed store, hash-verified

188 * Maps notebook cell data to tool result block parameters with sophisticated text block merging
189 */
190export function mapNotebookCellsToToolResult(
191 data: NotebookCellSource[],
192 toolUseID: string,
193): ToolResultBlockParam {
194 const allResults = data.flatMap(getToolResultFromCell)
195
196 // Merge adjacent text blocks
197 return {
198 tool_use_id: toolUseID,
199 type: 'tool_result' as const,
200 content: allResults.reduce<(TextBlockParam | ImageBlockParam)[]>(
201 (acc, curr) => {
202 if (acc.length === 0) return [curr]
203
204 const prev = acc[acc.length - 1]
205 if (prev && prev.type === 'text' && curr.type === 'text') {
206 // Merge the text blocks
207 prev.text += '\n' + curr.text
208 return acc
209 }
210
211 acc.push(curr)
212 return acc
213 },
214 [],
215 ),
216 }
217}
218
219export function parseCellId(cellId: string): number | undefined {
220 const match = cellId.match(/^cell-(\d+)$/)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected