-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
executable file
·75 lines (60 loc) · 2.19 KB
/
cli.ts
File metadata and controls
executable file
·75 lines (60 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bun
import 'dotenv/config';
import { createTerminalUI } from './src/terminal-ui.js';
import { createResearchWorkflow } from './src/workflow.js';
import { writeFile, appendFile } from 'fs/promises';
import { initRateLimiter } from './src/exa-tool.js';
//TODO: Remove
const DEBUG_LOG = './debug.log';
async function logErrorToFile(error: unknown, context?: string) {
const timestamp = new Date().toISOString();
const errorLog = `[${timestamp}] ${context ? context + ': ' : ''}${error instanceof Error ? error.message : String(error)}\n${error instanceof Error ? error.stack : ''}\n\n`;
try {
await appendFile(DEBUG_LOG, errorLog);
console.error(`Error logged to ${DEBUG_LOG}`);
} catch (logError) {
console.error('Failed to write to debug log:', logError);
}
}
async function clearDebugLog() {
try {
await writeFile(DEBUG_LOG, `=== Debug log started at ${new Date().toISOString()} ===\n\n`);
} catch (error) {
console.error('Failed to clear debug log:', error);
}
}
async function main() {
await clearDebugLog();
// Initialize rate limiter with default QPS or from env
const exaQPS = parseInt(process.env.EXA_QPS || '5', 10);
initRateLimiter(exaQPS);
const apiKey = process.env.ANTHROPIC_AUTH_TOKEN || process.env.OPENAI_API_KEY;
const exaKey = process.env.EXA_API_KEY;
if (!apiKey) {
const error = 'ANTHROPIC_AUTH_TOKEN, OPENAI_API_KEY not set.';
console.error(`Error: ${error}`);
console.error('Create a .env file with: ANTHROPIC_AUTH_TOKEN=your_key_here');
await logErrorToFile(error, 'API Key Check');
process.exit(1);
}
if (!exaKey) {
console.warn('Warning: EXA_API_KEY not set. Web search will be limited.');
console.warn('Add EXA_API_KEY to your .env file for full functionality.');
}
try {
const ui = createTerminalUI({
title: 'term-research',
debug: process.env.DEBUG === 'true',
});
createResearchWorkflow(ui);
} catch (error) {
await logErrorToFile(error, 'UI Initialization');
console.error('Fatal error:', error);
process.exit(1);
}
}
main().catch(async (error) => {
await logErrorToFile(error, 'Fatal Error');
console.error('Fatal error:', error);
process.exit(1);
});