From c04379610f82b0140862b6eebf0ec5f4374828b3 Mon Sep 17 00:00:00 2001 From: David Zhang Date: Fri, 7 Mar 2025 14:03:52 -0800 Subject: [PATCH] simplified --- src/api.ts | 25 ++----------------- src/deep-research.ts | 7 +----- src/output-manager.ts | 58 ------------------------------------------- src/run.ts | 8 +----- 4 files changed, 4 insertions(+), 94 deletions(-) delete mode 100644 src/output-manager.ts diff --git a/src/api.ts b/src/api.ts index 0fd7510..4780788 100644 --- a/src/api.ts +++ b/src/api.ts @@ -2,8 +2,6 @@ import cors from 'cors'; import express, { Request, Response } from 'express'; import { deepResearch, writeFinalAnswer } from './deep-research'; -import { generateFeedback } from './feedback'; -import { OutputManager } from './output-manager'; const app = express(); const port = process.env.PORT || 3051; @@ -12,12 +10,9 @@ const port = process.env.PORT || 3051; app.use(cors()); app.use(express.json()); -// Initialize output manager -const output = new OutputManager(); - // Helper function for consistent logging function log(...args: any[]) { - output.log(...args); + console.log(...args); } // API endpoint to run research @@ -29,46 +24,30 @@ app.post('/api/research', async (req: Request, res: Response) => { return res.status(400).json({ error: 'Query is required' }); } - log('\nResearching your topic...'); - log('\nStarting research with progress tracking...\n'); + log('\nStarting research...\n'); const { learnings, visitedUrls } = await deepResearch({ query, breadth, depth, - onProgress: progress => { - output.updateProgress(progress); - }, }); log(`\n\nLearnings:\n\n${learnings.join('\n')}`); log( `\n\nVisited URLs (${visitedUrls.length}):\n\n${visitedUrls.join('\n')}`, ); - log('Writing final answer...'); - - // Save report to file with timestamp - const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); - const reportFilename = `output-${timestamp}.md`; - // await fs.writeFile(reportFilename, report, 'utf-8'); const answer = await writeFinalAnswer({ prompt: query, learnings, }); - // Save answer to file - const answerFilename = `answer-${timestamp}.md`; - // await fs.writeFile(answerFilename, answer, 'utf-8'); - // Return the results return res.json({ success: true, answer, learnings, visitedUrls, - reportFilename, - answerFilename, }); } catch (error: unknown) { console.error('Error in research API:', error); diff --git a/src/deep-research.ts b/src/deep-research.ts index 820e1a5..f27b26b 100644 --- a/src/deep-research.ts +++ b/src/deep-research.ts @@ -5,15 +5,10 @@ import pLimit from 'p-limit'; import { z } from 'zod'; import { getModel, trimPrompt } from './ai/providers'; -import { OutputManager } from './output-manager'; import { systemPrompt } from './prompt'; -// Initialize output manager for coordinated console/progress output -const output = new OutputManager(); - -// Replace console.log with output.log function log(...args: any[]) { - output.log(...args); + console.log(...args); } export type ResearchProgress = { diff --git a/src/output-manager.ts b/src/output-manager.ts deleted file mode 100644 index ae8d899..0000000 --- a/src/output-manager.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { ResearchProgress } from './deep-research'; - -export class OutputManager { - private progressLines: number = 4; - private progressArea: string[] = []; - private initialized: boolean = false; - - constructor() { - // Initialize terminal - process.stdout.write('\n'.repeat(this.progressLines)); - this.initialized = true; - } - - log(...args: any[]) { - // Move cursor up to progress area - if (this.initialized) { - process.stdout.write(`\x1B[${this.progressLines}A`); - // Clear progress area - process.stdout.write('\x1B[0J'); - } - // Print log message - console.log(...args); - // Redraw progress area if initialized - if (this.initialized) { - this.drawProgress(); - } - } - - updateProgress(progress: ResearchProgress) { - this.progressArea = [ - `Depth: [${this.getProgressBar(progress.totalDepth - progress.currentDepth, progress.totalDepth)}] ${Math.round(((progress.totalDepth - progress.currentDepth) / progress.totalDepth) * 100)}%`, - `Breadth: [${this.getProgressBar(progress.totalBreadth - progress.currentBreadth, progress.totalBreadth)}] ${Math.round(((progress.totalBreadth - progress.currentBreadth) / progress.totalBreadth) * 100)}%`, - `Queries: [${this.getProgressBar(progress.completedQueries, progress.totalQueries)}] ${Math.round((progress.completedQueries / progress.totalQueries) * 100)}%`, - progress.currentQuery ? `Current: ${progress.currentQuery}` : '', - ]; - this.drawProgress(); - } - - private getProgressBar(value: number, total: number): string { - const width = process.stdout.columns - ? Math.min(30, process.stdout.columns - 20) - : 30; - const filled = Math.round((width * value) / total); - return '█'.repeat(filled) + ' '.repeat(width - filled); - } - - private drawProgress() { - if (!this.initialized || this.progressArea.length === 0) return; - - // Move cursor to progress area - const terminalHeight = process.stdout.rows || 24; - process.stdout.write(`\x1B[${terminalHeight - this.progressLines};1H`); - // Draw progress bars - process.stdout.write(this.progressArea.join('\n')); - // Move cursor back to content area - process.stdout.write(`\x1B[${terminalHeight - this.progressLines - 1};1H`); - } -} diff --git a/src/run.ts b/src/run.ts index c85a42b..27329d9 100644 --- a/src/run.ts +++ b/src/run.ts @@ -7,13 +7,10 @@ import { writeFinalReport, } from './deep-research'; import { generateFeedback } from './feedback'; -import { OutputManager } from './output-manager'; - -const output = new OutputManager(); // Helper function for consistent logging function log(...args: any[]) { - output.log(...args); + console.log(...args); } const rl = readline.createInterface({ @@ -84,9 +81,6 @@ ${followUpQuestions.map((q: string, i: number) => `Q: ${q}\nA: ${answers[i]}`).j query: combinedQuery, breadth, depth, - onProgress: progress => { - output.updateProgress(progress); - }, }); log(`\n\nLearnings:\n\n${learnings.join('\n')}`);