(args: Record<string, unknown>)
| 885 | } |
| 886 | |
| 887 | async function handleAddNotebook(args: Record<string, unknown>) { |
| 888 | const parsedArgs = addNotebookArgsSchema.safeParse(args) |
| 889 | if (!parsedArgs.success) { |
| 890 | return writingError(`Invalid args in handleAddNotebook: ${formatFirstIssue(parsedArgs.error)}`) |
| 891 | } |
| 892 | const filePath = parsedArgs.data.path |
| 893 | const name = parsedArgs.data.name |
| 894 | const blocks = parsedArgs.data.blocks ?? [] |
| 895 | const dryRun = parsedArgs.data.dryRun === true |
| 896 | |
| 897 | const file = await loadDeepnoteFile(filePath) |
| 898 | |
| 899 | const notebookId = randomUUID() |
| 900 | const newNotebook = { |
| 901 | id: notebookId, |
| 902 | name, |
| 903 | blocks: blocks.map((block, index) => createBlock(block, index)), |
| 904 | } |
| 905 | |
| 906 | if (dryRun === true) { |
| 907 | return { |
| 908 | content: [ |
| 909 | { |
| 910 | type: 'text', |
| 911 | text: JSON.stringify( |
| 912 | { |
| 913 | wouldAdd: { |
| 914 | notebookId, |
| 915 | name, |
| 916 | blockCount: newNotebook.blocks.length, |
| 917 | }, |
| 918 | }, |
| 919 | null, |
| 920 | 2 |
| 921 | ), |
| 922 | }, |
| 923 | ], |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | file.project.notebooks.push(newNotebook) |
| 928 | await saveDeepnoteFile(filePath, file) |
| 929 | |
| 930 | return { |
| 931 | content: [ |
| 932 | { |
| 933 | type: 'text', |
| 934 | text: JSON.stringify( |
| 935 | { |
| 936 | success: true, |
| 937 | notebookId, |
| 938 | name, |
| 939 | blockCount: newNotebook.blocks.length, |
| 940 | totalNotebooks: file.project.notebooks.length, |
| 941 | }, |
| 942 | null, |
| 943 | 2 |
| 944 | ), |
no test coverage detected