Skip to content

Commit cd578f2

Browse files
Miriadresearch
andcommitted
fix(notebooklm): add getSourceIds(), auto-fetch source IDs for artifacts, fix nesting
- Add getSourceIds() method that fetches source IDs from notebook via GET_NOTEBOOK RPC - generateInfographic() and generateReport() now auto-fetch source IDs if not provided - Fix sourceIdsTriple nesting: was [[[sid]]] (4 levels), now [[sid]] (matching Python's [[[sid]] for sid in source_ids]) Co-authored-by: research <research@miriad.systems>
1 parent 9ba76c6 commit cd578f2

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

lib/services/notebooklm/client.ts

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,47 @@ export class NotebookLMClient {
532532
// Artifact generation
533533
// -------------------------------------------------------------------------
534534

535+
/**
536+
* Get all source IDs from a notebook.
537+
* Required for artifact generation (infographics, reports, etc.)
538+
*/
539+
async getSourceIds(notebookId: string): Promise<string[]> {
540+
try {
541+
const result = await this.rpcCall(
542+
RPCMethod.GET_NOTEBOOK,
543+
[notebookId, null, [2], null, 0],
544+
`/notebook/${notebookId}`
545+
);
546+
547+
const resultArr = result as unknown[];
548+
if (!Array.isArray(resultArr) || !Array.isArray(resultArr[0])) {
549+
return [];
550+
}
551+
552+
const notebookInfo = resultArr[0] as unknown[];
553+
if (!Array.isArray(notebookInfo[1])) {
554+
return [];
555+
}
556+
557+
const sources = notebookInfo[1] as unknown[][];
558+
const sourceIds: string[] = [];
559+
for (const source of sources) {
560+
if (!Array.isArray(source) || source.length === 0) continue;
561+
const first = source[0];
562+
if (Array.isArray(first) && first.length > 0 && typeof first[0] === 'string') {
563+
sourceIds.push(first[0]);
564+
}
565+
}
566+
return sourceIds;
567+
} catch (error: unknown) {
568+
console.warn(
569+
'[NotebookLM] Failed to get source IDs:',
570+
error instanceof Error ? error.message : String(error)
571+
);
572+
return [];
573+
}
574+
}
575+
535576
/**
536577
* Generate an infographic for a notebook.
537578
*/
@@ -549,9 +590,14 @@ export class NotebookLMClient {
549590
`[NotebookLM] Generating infographic for notebook ${notebookId}`
550591
);
551592

552-
const sourceIdsTriple = (options?.sourceIds ?? []).map((sid) => [
553-
[[sid]],
554-
]);
593+
// Auto-fetch source IDs if not provided
594+
const sourceIds = options?.sourceIds ?? await this.getSourceIds(notebookId);
595+
if (sourceIds.length === 0) {
596+
console.warn('[NotebookLM] No source IDs found — infographic generation may fail');
597+
}
598+
599+
// Python format: [[[sid]] for sid in source_ids] → [[[sid1]], [[sid2]], ...]
600+
const sourceIdsTriple = sourceIds.map((sid) => [[sid]]);
555601
const instructions = options?.instructions ?? null;
556602
const language = options?.language ?? null;
557603
const orientation = options?.orientation ?? null;
@@ -608,9 +654,14 @@ export class NotebookLMClient {
608654
): Promise<GenerationStatus> {
609655
console.log(`[NotebookLM] Generating report for notebook ${notebookId}`);
610656

611-
const sourceIdsTriple = (options?.sourceIds ?? []).map((sid) => [
612-
[[sid]],
613-
]);
657+
// Auto-fetch source IDs if not provided
658+
const sourceIds = options?.sourceIds ?? await this.getSourceIds(notebookId);
659+
if (sourceIds.length === 0) {
660+
console.warn('[NotebookLM] No source IDs found — report generation may fail');
661+
}
662+
663+
// Python format: [[[sid]] for sid in source_ids] → [[[sid1]], [[sid2]], ...]
664+
const sourceIdsTriple = sourceIds.map((sid) => [[sid]]);
614665
const instructions = options?.instructions ?? null;
615666
const language = options?.language ?? null;
616667

0 commit comments

Comments
 (0)