notes-get.js
1 import { cli, Strategy } from '@jackwener/opencli/registry'; 2 import { EmptyResultError } from '@jackwener/opencli/errors'; 3 import { NOTEBOOKLM_DOMAIN, NOTEBOOKLM_SITE } from './shared.js'; 4 import { findNotebooklmNoteRow, getNotebooklmPageState, listNotebooklmNotesFromPage, readNotebooklmVisibleNoteFromPage, requireNotebooklmSession, } from './utils.js'; 5 function matchesNoteTitle(title, query) { 6 const needle = query.trim().toLowerCase(); 7 if (!needle) 8 return false; 9 const normalized = title.trim().toLowerCase(); 10 return normalized === needle || normalized.includes(needle); 11 } 12 cli({ 13 site: NOTEBOOKLM_SITE, 14 name: 'notes-get', 15 description: 'Get one note from the current NotebookLM notebook by title from the visible note editor', 16 domain: NOTEBOOKLM_DOMAIN, 17 strategy: Strategy.COOKIE, 18 browser: true, 19 navigateBefore: false, 20 args: [ 21 { 22 name: 'note', 23 positional: true, 24 required: true, 25 help: 'Note title or id from the current notebook', 26 }, 27 ], 28 columns: ['title', 'content', 'source', 'url'], 29 func: async (page, kwargs) => { 30 await requireNotebooklmSession(page); 31 const state = await getNotebooklmPageState(page); 32 if (state.kind !== 'notebook') { 33 throw new EmptyResultError('opencli notebooklm notes-get', 'No NotebookLM notebook is open in the automation workspace. Run `opencli notebooklm open <notebook>` first.'); 34 } 35 const query = typeof kwargs.note === 'string' ? kwargs.note : String(kwargs.note ?? ''); 36 const visible = await readNotebooklmVisibleNoteFromPage(page); 37 if (visible && matchesNoteTitle(visible.title, query)) 38 return [visible]; 39 const rows = await listNotebooklmNotesFromPage(page); 40 const listed = findNotebooklmNoteRow(rows, query); 41 if (listed) { 42 throw new EmptyResultError('opencli notebooklm notes-get', `Note "${query}" is listed in Studio, but opencli currently reads note content only from the visible note editor. Open that note in NotebookLM, then retry.`); 43 } 44 throw new EmptyResultError('opencli notebooklm notes-get', `Note "${query}" was not found in the current notebook.`); 45 }, 46 });