MCPcopy Index your code
hub / github.com/deepnote/deepnote / computeDagInfo

Function computeDagInfo

packages/mcp/src/tools/reading.ts:83–133  ·  view source on GitHub ↗
(file: DeepnoteFile, notebookFilter?: string)

Source from the content-addressed store, hash-verified

81}
82
83async function computeDagInfo(file: DeepnoteFile, notebookFilter?: string) {
84 const dagInfo: Array<{
85 notebook: string
86 blocks: Array<{
87 id: string
88 shortId: string
89 defines: string[]
90 uses: string[]
91 dependsOn: string[]
92 }>
93 }> = []
94
95 for (const notebook of file.project.notebooks) {
96 if (notebookFilter && notebook.name !== notebookFilter && notebook.id !== notebookFilter) {
97 continue
98 }
99
100 try {
101 const blockDeps = await getBlockDependencies(notebook.blocks)
102 const varToBlock = new Map<string, string>()
103
104 for (const block of blockDeps) {
105 for (const v of block.definedVariables) varToBlock.set(v, block.id)
106 for (const m of block.importedModules || []) varToBlock.set(m, block.id)
107 }
108
109 const blocks = blockDeps.map(block => {
110 const deps = new Set<string>()
111 for (const usedVar of block.usedVariables) {
112 const definingBlock = varToBlock.get(usedVar)
113 if (definingBlock && definingBlock !== block.id) {
114 deps.add(definingBlock)
115 }
116 }
117 return {
118 id: block.id,
119 shortId: block.id.slice(0, 8),
120 defines: block.definedVariables,
121 uses: block.usedVariables,
122 dependsOn: Array.from(deps),
123 }
124 })
125
126 dagInfo.push({ notebook: notebook.name, blocks })
127 } catch {
128 dagInfo.push({ notebook: notebook.name, blocks: [] })
129 }
130 }
131
132 return dagInfo
133}
134
135// --- End internal helpers ---
136

Callers 1

handleReadFunction · 0.85

Calls 1

getBlockDependenciesFunction · 0.90

Tested by

no test coverage detected