source-guide.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, getNotebooklmSourceGuideViaRpc, listNotebooklmSourcesFromPage, listNotebooklmSourcesViaRpc, requireNotebooklmSession, } from './utils.js'; 5 cli({ 6 site: NOTEBOOKLM_SITE, 7 name: 'source-guide', 8 description: 'Get the guide summary and keywords for one source in the currently opened NotebookLM notebook', 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: ['source_id', 'notebook_id', 'title', 'type', 'summary', 'keywords', '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-guide', '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-guide', '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 throw new EmptyResultError('opencli notebooklm source-guide', `Source "${query}" was not found in the current notebook.`); 37 } 38 const guide = await getNotebooklmSourceGuideViaRpc(page, matched).catch(() => null); 39 if (guide) 40 return [guide]; 41 throw new EmptyResultError('opencli notebooklm source-guide', `NotebookLM guide was not available for source "${matched.title}".`); 42 }, 43 });