Skip to content

Commit e844d3b

Browse files
Miriadresearch
andcommitted
feat(research): generate multiple infographics per topic, infographicUrls array
- Generate 5 infographics with different angles (architecture, comparison, workflow, timeline, pros/cons) - Change infographicUrl to infographicUrls (string array) in ResearchPayload - Collect URLs for all completed infographics - Generate report in parallel with infographics Co-authored-by: research <research@miriad.systems>
1 parent cd578f2 commit e844d3b

File tree

1 file changed

+70
-29
lines changed

1 file changed

+70
-29
lines changed

lib/services/research.ts

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import { NotebookLMClient } from './notebooklm/client';
14+
import type { GenerationStatus } from './notebooklm/types';
1415
import { sleep } from './notebooklm/rpc';
1516

1617
// ---------------------------------------------------------------------------
@@ -33,7 +34,7 @@ export interface ResearchPayload {
3334
prosCons?: Record<string, string[]>;
3435
commonMistakes?: string[];
3536
sceneHints: SceneHint[];
36-
infographicUrl?: string;
37+
infographicUrls?: string[];
3738
}
3839

3940
export interface ResearchSource {
@@ -383,36 +384,65 @@ export async function conductResearch(
383384
}
384385

385386
// -----------------------------------------------------------------------
386-
// Step 6 & 7: Generate artifacts in parallel
387+
// Step 6 & 7: Generate multiple infographics + report in parallel
387388
// -----------------------------------------------------------------------
388-
console.log('[research] Step 6-7/10: Generating artifacts...');
389-
390-
const [infographicResult, reportResult] = await Promise.allSettled([
391-
safeStep('generate-infographic', () =>
392-
client.generateInfographic(notebookId)
393-
),
394-
safeStep('generate-report', () => client.generateReport(notebookId)),
395-
]);
396-
397-
const infographicTaskId =
398-
infographicResult.status === 'fulfilled' && infographicResult.value
399-
? infographicResult.value.taskId
400-
: '';
401-
const reportTaskId =
402-
reportResult.status === 'fulfilled' && reportResult.value
403-
? reportResult.value.taskId
404-
: '';
389+
const infographicInstructions = [
390+
'Create a high-level architecture overview diagram',
391+
'Create a comparison chart of key features and alternatives',
392+
'Create a step-by-step workflow diagram',
393+
'Create a timeline of key developments and milestones',
394+
'Create a pros and cons visual summary',
395+
];
396+
397+
console.log(`[research] Step 6-7/10: Generating ${infographicInstructions.length} infographics + report...`);
398+
399+
const artifactPromises: Promise<GenerationStatus | undefined>[] = infographicInstructions.map(
400+
(instruction, i) =>
401+
safeStep(`generate-infographic-${i}`, () =>
402+
client.generateInfographic(notebookId, {
403+
instructions: instruction,
404+
language: 'en',
405+
orientation: 1, // landscape
406+
detailLevel: 2, // detailed
407+
})
408+
)
409+
);
410+
artifactPromises.push(
411+
safeStep('generate-report', () => client.generateReport(notebookId))
412+
);
413+
414+
const artifactResults = await Promise.allSettled(artifactPromises);
415+
416+
// Collect task IDs for all generated artifacts
417+
const infographicTaskIds: string[] = [];
418+
let reportTaskId = '';
419+
420+
for (let i = 0; i < artifactResults.length; i++) {
421+
const result = artifactResults[i];
422+
if (result.status !== 'fulfilled' || !result.value?.taskId) continue;
423+
424+
if (i < infographicInstructions.length) {
425+
infographicTaskIds.push(result.value.taskId);
426+
} else {
427+
reportTaskId = result.value.taskId;
428+
}
429+
}
430+
431+
console.log(
432+
`[research] Artifact generation started: ${infographicTaskIds.length} infographics, ` +
433+
`report: ${reportTaskId ? 'yes' : 'no'}`
434+
);
405435

406436
// -----------------------------------------------------------------------
407437
// Step 8: Wait for artifacts to complete
408438
// -----------------------------------------------------------------------
409439
console.log('[research] Step 8/10: Waiting for artifacts...');
410440

411441
const waitPromises: Promise<unknown>[] = [];
412-
if (infographicTaskId) {
442+
for (const taskId of infographicTaskIds) {
413443
waitPromises.push(
414-
safeStep('wait-infographic', () =>
415-
client.waitForArtifact(notebookId, infographicTaskId, {
444+
safeStep(`wait-infographic-${taskId.substring(0, 8)}`, () =>
445+
client.waitForArtifact(notebookId, taskId, {
416446
timeoutMs: artifactTimeout,
417447
pollIntervalMs: pollInterval,
418448
})
@@ -444,12 +474,22 @@ export async function conductResearch(
444474
const briefing = summary ?? '';
445475

446476
// -----------------------------------------------------------------------
447-
// Step 10: Get infographic URL
477+
// Step 10: Get infographic URLs
448478
// -----------------------------------------------------------------------
449-
console.log('[research] Step 10/10: Getting infographic URL...');
450-
const infographicUrl = await safeStep('get-infographic-url', () =>
451-
client.getInfographicUrl(notebookId)
452-
);
479+
console.log('[research] Step 10/10: Getting infographic URLs...');
480+
const infographicUrls: string[] = [];
481+
482+
// Collect URLs for each completed infographic
483+
for (const taskId of infographicTaskIds) {
484+
const url = await safeStep(`get-infographic-url-${taskId.substring(0, 8)}`, () =>
485+
client.getInfographicUrl(notebookId, taskId)
486+
);
487+
if (url) {
488+
infographicUrls.push(url);
489+
}
490+
}
491+
492+
console.log(`[research] Found ${infographicUrls.length} infographic URLs`);
453493

454494
// -----------------------------------------------------------------------
455495
// Build the research payload
@@ -483,12 +523,13 @@ export async function conductResearch(
483523
talkingPoints,
484524
codeExamples,
485525
sceneHints,
486-
infographicUrl: infographicUrl ?? undefined,
526+
infographicUrls: infographicUrls.length > 0 ? infographicUrls : undefined,
487527
};
488528

489529
console.log(
490530
`[research] Pipeline complete: ${classifiedSources.length} sources, ` +
491-
`${talkingPoints.length} talking points, ${sceneHints.length} scene hints`
531+
`${talkingPoints.length} talking points, ${sceneHints.length} scene hints, ` +
532+
`${infographicUrls.length} infographics`
492533
);
493534

494535
return payload;

0 commit comments

Comments
 (0)