(args: Record<string, unknown>)
| 208 | ] |
| 209 | |
| 210 | async function handleSnapshotList(args: Record<string, unknown>) { |
| 211 | if (args.path === undefined) { |
| 212 | return snapshotError('path is required') |
| 213 | } |
| 214 | const parsedArgs = snapshotListArgsSchema.safeParse(args) |
| 215 | if (!parsedArgs.success) { |
| 216 | return snapshotError(`Invalid arguments for deepnote_snapshot_list: ${formatFirstIssue(parsedArgs.error)}`) |
| 217 | } |
| 218 | const { path: filePath, snapshotDir } = parsedArgs.data |
| 219 | |
| 220 | try { |
| 221 | const absolutePath = path.resolve(filePath) |
| 222 | const projectDir = path.dirname(absolutePath) |
| 223 | |
| 224 | // Read file to get the project ID |
| 225 | const content = await fs.readFile(absolutePath, 'utf-8') |
| 226 | const file = deserializeDeepnoteFile(content) |
| 227 | const projectId = file.project.id |
| 228 | |
| 229 | const notebookId = resolveSnapshotNotebookId(file) |
| 230 | const snapshotOptions = { ...(snapshotDir ? { snapshotDir } : {}), ...(notebookId ? { notebookId } : {}) } |
| 231 | const snapshots = await findSnapshotsForProject(projectDir, projectId, snapshotOptions) |
| 232 | const resolvedSnapshotDir = snapshotDir ? snapshotDir : path.join(projectDir, 'snapshots') |
| 233 | |
| 234 | return { |
| 235 | content: [ |
| 236 | { |
| 237 | type: 'text', |
| 238 | text: JSON.stringify( |
| 239 | { |
| 240 | sourcePath: absolutePath, |
| 241 | snapshotDir: resolvedSnapshotDir, |
| 242 | snapshotsFound: snapshots.length, |
| 243 | snapshots: snapshots.map(s => ({ |
| 244 | path: s.path, |
| 245 | slug: s.slug, |
| 246 | projectId: s.projectId, |
| 247 | timestamp: s.timestamp, |
| 248 | isLatest: s.timestamp === 'latest', |
| 249 | })), |
| 250 | }, |
| 251 | null, |
| 252 | 2 |
| 253 | ), |
| 254 | }, |
| 255 | ], |
| 256 | } |
| 257 | } catch (error) { |
| 258 | const message = error instanceof Error ? error.message : String(error) |
| 259 | return { |
| 260 | content: [{ type: 'text', text: JSON.stringify({ error: message }) }], |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | async function handleSnapshotLoad(args: Record<string, unknown>) { |
| 266 | if (args.path === undefined) { |
no test coverage detected