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

Function mapNotebookCellsToToolResult

src/utils/notebook.ts:188–215  ·  view source on GitHub ↗
(
  data: NotebookCellSource[],
  toolUseID: string,
)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected