Files
jackwener__opencli/clis/notebooklm/notes-get.js
jakevin d2974a9ff6 refactor(adapters): convert adapter layer from TypeScript to JavaScript (#928)
* refactor(adapters): convert adapter layer from TypeScript to JavaScript

Core framework stays TypeScript; adapter layer moves to JS-first.
Adapters are essentially "executable config + browser scripts" that
barely use TS features — this simplifies the build/distribution pipeline
by removing the dist/clis/ intermediate compilation step.

Changes:
- Convert all 753 adapter files in clis/ from .ts to .js
- Update tsconfig to exclude clis/ from compilation
- Simplify build-manifest to scan clis/*.js directly (no dist/clis/)
- Update discovery, main, fetch-adapters to load JS adapters from clis/
- Update generate-verified to output .js artifacts
- Update package.json files field: dist/clis/ → clis/
- Fix all test files for the .ts → .js transition

* fix(main): use findPackageRoot for BUILTIN_CLIS path

The previous relative path (../../clis from __dirname) only worked for
dist/src/main.js but broke dev mode (tsx src/main.ts) where __dirname
is <repo>/src — resolving to /clis instead of <repo>/clis.

Use findPackageRoot() which works for both dev and prod paths.
2026-04-10 14:52:18 +08:00

47 lines
2.2 KiB
JavaScript

import { cli, Strategy } from '@jackwener/opencli/registry';
import { EmptyResultError } from '@jackwener/opencli/errors';
import { NOTEBOOKLM_DOMAIN, NOTEBOOKLM_SITE } from './shared.js';
import { findNotebooklmNoteRow, getNotebooklmPageState, listNotebooklmNotesFromPage, readNotebooklmVisibleNoteFromPage, requireNotebooklmSession, } from './utils.js';
function matchesNoteTitle(title, query) {
const needle = query.trim().toLowerCase();
if (!needle)
return false;
const normalized = title.trim().toLowerCase();
return normalized === needle || normalized.includes(needle);
}
cli({
site: NOTEBOOKLM_SITE,
name: 'notes-get',
description: 'Get one note from the current NotebookLM notebook by title from the visible note editor',
domain: NOTEBOOKLM_DOMAIN,
strategy: Strategy.COOKIE,
browser: true,
navigateBefore: false,
args: [
{
name: 'note',
positional: true,
required: true,
help: 'Note title or id from the current notebook',
},
],
columns: ['title', 'content', 'source', 'url'],
func: async (page, kwargs) => {
await requireNotebooklmSession(page);
const state = await getNotebooklmPageState(page);
if (state.kind !== 'notebook') {
throw new EmptyResultError('opencli notebooklm notes-get', 'No NotebookLM notebook is open in the automation workspace. Run `opencli notebooklm open <notebook>` first.');
}
const query = typeof kwargs.note === 'string' ? kwargs.note : String(kwargs.note ?? '');
const visible = await readNotebooklmVisibleNoteFromPage(page);
if (visible && matchesNoteTitle(visible.title, query))
return [visible];
const rows = await listNotebooklmNotesFromPage(page);
const listed = findNotebooklmNoteRow(rows, query);
if (listed) {
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.`);
}
throw new EmptyResultError('opencli notebooklm notes-get', `Note "${query}" was not found in the current notebook.`);
},
});