MCPcopy Create free account
hub / github.com/deepnote/deepnote / findBlockIndex

Function findBlockIndex

packages/mcp/src/tools/writing.ts:28–36  ·  view source on GitHub ↗

* Find a block index by ID or ID prefix. Returns -1 if not found.

(blocks: DeepnoteBlock[], idOrPrefix: string)

Source from the content-addressed store, hash-verified

26 * Find a block index by ID or ID prefix. Returns -1 if not found.
27 */
28function findBlockIndex(blocks: DeepnoteBlock[], idOrPrefix: string): number {
29 const matches = blocks
30 .map((block, index) => ({ block, index }))
31 .filter(({ block }) => block.id === idOrPrefix || block.id.startsWith(idOrPrefix))
32 if (matches.length > 1) {
33 throw new Error(`Ambiguous block ID prefix "${idOrPrefix}" matches multiple blocks`)
34 }
35 return matches.length === 1 ? matches[0].index : -1
36}
37
38/**
39 * Resolve a block ID or prefix to the full block ID. Returns undefined if not found.

Callers 2

handleAddBlockFunction · 0.85
handleRemoveBlockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected