source-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 { findNotebooklmSourceRow, getNotebooklmPageState, listNotebooklmSourcesFromPage, listNotebooklmSourcesViaRpc, requireNotebooklmSession, } from './utils.js'; 5 cli({ 6 site: NOTEBOOKLM_SITE, 7 name: 'source-get', 8 description: 'Get one source from the currently opened NotebookLM notebook by id or title', 9 domain: NOTEBOOKLM_DOMAIN, 10 strategy: Strategy.COOKIE, 11 browser: true, 12 navigateBefore: false, 13 args: [ 14 { 15 name: 'source', 16 positional: true, 17 required: true, 18 help: 'Source id or title from the current notebook', 19 }, 20 ], 21 columns: ['title', 'id', 'type', 'size', 'created_at', 'updated_at', 'url', 'source'], 22 func: async (page, kwargs) => { 23 await requireNotebooklmSession(page); 24 const state = await getNotebooklmPageState(page); 25 if (state.kind !== 'notebook') { 26 throw new EmptyResultError('opencli notebooklm source-get', 'No NotebookLM notebook is open in the automation workspace. Run `opencli notebooklm open <notebook>` first.'); 27 } 28 const rpcRows = await listNotebooklmSourcesViaRpc(page).catch(() => []); 29 const rows = rpcRows.length > 0 ? rpcRows : await listNotebooklmSourcesFromPage(page); 30 if (rows.length === 0) { 31 throw new EmptyResultError('opencli notebooklm source-get', 'No NotebookLM sources were found on the current page.'); 32 } 33 const query = typeof kwargs.source === 'string' ? kwargs.source : String(kwargs.source ?? ''); 34 const matched = findNotebooklmSourceRow(rows, query); 35 if (matched) 36 return [matched]; 37 throw new EmptyResultError('opencli notebooklm source-get', `Source "${query}" was not found in the current notebook.`); 38 }, 39 });