opencontext 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli/index.js +60 -57
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -49,24 +49,24 @@ const boxen_1 = __importDefault(require("boxen"));
49
49
  const fs = __importStar(require("fs"));
50
50
  const path = __importStar(require("path"));
51
51
  const os = __importStar(require("os"));
52
- const VERSION = '1.0.0';
52
+ const VERSION = '1.0.2';
53
53
  const CONFIG_DIR = path.join(os.homedir(), '.opencontext');
54
54
  const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
55
55
  // ASCII Logo
56
56
  const LOGO = `
57
57
  ${chalk_1.default.cyan.bold(`
58
- ╔══════════════════════════════════════════════════════════════════════════╗
59
-
60
- ██████╗ ██████╗ ███████╗███╗ ██╗ ██████╗ ██████╗ ███╗ ██╗████████╗║
61
- ██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝██╔═══██╗████╗ ██║╚══██╔══╝║
62
- ██║ ██║██████╔╝█████╗ ██╔██╗ ██║██║ ██║ ██║██╔██╗ ██║ ██║
63
- ██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║██║ ██║ ██║██║╚██╗██║ ██║
64
- ╚██████╔╝██║ ███████╗██║ ╚████║╚██████╗╚██████╔╝██║ ╚████║ ██║
65
- ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝
66
-
67
- ${chalk_1.default.white('✨ AI-Powered Company Analysis ✨')}
68
-
69
- ╚══════════════════════════════════════════════════════════════════════════╝
58
+ ╔═══════════════════════════════════════════════════════════════════════╗
59
+
60
+ ██████╗ ██████╗ ███████╗███╗ ██╗ ██████╗ ██████╗ ███╗ ██╗████████╗
61
+ ██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝██╔═══██╗████╗ ██║╚══██╔══╝
62
+ ██║ ██║██████╔╝█████╗ ██╔██╗ ██║██║ ██║ ██║██╔██╗ ██║ ██║
63
+ ██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║██║ ██║ ██║██║╚██╗██║ ██║
64
+ ╚██████╔╝██║ ███████╗██║ ╚████║╚██████╗╚██████╔╝██║ ╚████║ ██║
65
+ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝
66
+
67
+ ║`)}${chalk_1.default.white(' ✨ AI-Powered Company Analysis ✨')}${chalk_1.default.cyan.bold(`
68
+
69
+ ╚═══════════════════════════════════════════════════════════════════════╝
70
70
  `)}
71
71
  `;
72
72
  // Config management
@@ -120,11 +120,27 @@ async function analyzeUrl(url, config) {
120
120
  if (config.geminiKey) {
121
121
  body.apiKey = config.geminiKey;
122
122
  }
123
- const response = await fetch(endpoint, {
124
- method: 'POST',
125
- headers,
126
- body: JSON.stringify(body)
127
- });
123
+ let response;
124
+ try {
125
+ response = await fetch(endpoint, {
126
+ method: 'POST',
127
+ headers,
128
+ body: JSON.stringify(body)
129
+ });
130
+ }
131
+ catch (err) {
132
+ // Network error - server not reachable
133
+ if (config.apiUrl.includes('localhost')) {
134
+ throw new Error(`Cannot connect to ${config.apiUrl}\n\n` +
135
+ ` The API server is not running. To fix:\n\n` +
136
+ ` Option 1: Start the server locally\n` +
137
+ ` cd opencontext && npm run dev\n\n` +
138
+ ` Option 2: Use a deployed API\n` +
139
+ ` opencontext config\n` +
140
+ ` (then set the API URL to your deployed instance)`);
141
+ }
142
+ throw new Error(`Cannot connect to ${config.apiUrl} - check your internet connection or API URL`);
143
+ }
128
144
  if (!response.ok) {
129
145
  const error = await response.json().catch(() => ({ error: 'Unknown error' }));
130
146
  throw new Error(error.error || error.message || `HTTP ${response.status}`);
@@ -214,6 +230,17 @@ function formatAnalysisResult(result) {
214
230
  sections.push(chalk_1.default.cyan('═══════════════════════════════════════════════════════════════\n'));
215
231
  return sections.join('\n');
216
232
  }
233
+ // Get Downloads folder path
234
+ function getDownloadsPath() {
235
+ return path.join(os.homedir(), 'Downloads');
236
+ }
237
+ // Generate filename from company name
238
+ function generateFilename(companyName) {
239
+ return companyName
240
+ .toLowerCase()
241
+ .replace(/[^a-z0-9]+/g, '-')
242
+ .replace(/^-|-$/g, '') + '-context.json';
243
+ }
217
244
  // Commands
218
245
  async function analyzeCommand(url, options) {
219
246
  const config = loadConfig();
@@ -234,16 +261,18 @@ async function analyzeCommand(url, options) {
234
261
  else {
235
262
  console.log(formatAnalysisResult(result));
236
263
  }
237
- // Save to file if requested
238
- if (options.output) {
239
- const outputPath = options.output;
240
- const dir = path.dirname(outputPath);
241
- if (!fs.existsSync(dir)) {
242
- fs.mkdirSync(dir, { recursive: true });
243
- }
244
- fs.writeFileSync(outputPath, JSON.stringify(result, null, 2));
245
- printSuccess(`Saved to ${outputPath}`);
264
+ // Always save to Downloads (or custom path if specified)
265
+ const downloadsDir = getDownloadsPath();
266
+ const filename = generateFilename(result.company_name);
267
+ const outputPath = options.output || path.join(downloadsDir, filename);
268
+ const dir = path.dirname(outputPath);
269
+ if (!fs.existsSync(dir)) {
270
+ fs.mkdirSync(dir, { recursive: true });
246
271
  }
272
+ fs.writeFileSync(outputPath, JSON.stringify(result, null, 2));
273
+ console.log();
274
+ console.log((0, boxen_1.default)(chalk_1.default.green.bold('Saved!') + '\n\n' +
275
+ chalk_1.default.dim('File: ') + chalk_1.default.white(outputPath), { padding: 1, borderColor: 'green', borderStyle: 'round' }));
247
276
  }
248
277
  catch (error) {
249
278
  spinner.fail('Analysis failed');
@@ -288,7 +317,7 @@ async function batchCommand(inputFile, options) {
288
317
  console.log((0, boxen_1.default)(chalk_1.default.white.bold(`Batch Analysis\n\n`) +
289
318
  chalk_1.default.dim(`Found ${chalk_1.default.cyan(urls.length.toString())} URLs to analyze`), { padding: 1, borderColor: 'cyan', borderStyle: 'round' }));
290
319
  console.log();
291
- const outputDir = options.outputDir || config.outputDir || './context-reports';
320
+ const outputDir = options.outputDir || path.join(getDownloadsPath(), 'opencontext-reports');
292
321
  if (!fs.existsSync(outputDir)) {
293
322
  fs.mkdirSync(outputDir, { recursive: true });
294
323
  }
@@ -414,28 +443,8 @@ async function interactiveMode() {
414
443
  validate: (input) => input.trim().length > 0 || 'URL is required'
415
444
  }
416
445
  ]);
417
- const { saveToFile } = await inquirer_1.default.prompt([
418
- {
419
- type: 'confirm',
420
- name: 'saveToFile',
421
- message: 'Save result to file?',
422
- default: true
423
- }
424
- ]);
425
- let outputPath;
426
- if (saveToFile) {
427
- const { path: outPath } = await inquirer_1.default.prompt([
428
- {
429
- type: 'input',
430
- name: 'path',
431
- message: 'Output file path:',
432
- default: './context-report.json'
433
- }
434
- ]);
435
- outputPath = outPath;
436
- }
437
446
  console.log();
438
- await analyzeCommand(url.trim(), { output: outputPath });
447
+ await analyzeCommand(url.trim(), {});
439
448
  break;
440
449
  }
441
450
  case 'batch': {
@@ -446,22 +455,16 @@ async function interactiveMode() {
446
455
  console.log(chalk_1.default.dim(' Supported formats: .json, .csv, .txt (one URL per line)'));
447
456
  break;
448
457
  }
449
- const { inputFile, outputDir } = await inquirer_1.default.prompt([
458
+ const { inputFile } = await inquirer_1.default.prompt([
450
459
  {
451
460
  type: 'list',
452
461
  name: 'inputFile',
453
462
  message: 'Select input file:',
454
463
  choices: files
455
- },
456
- {
457
- type: 'input',
458
- name: 'outputDir',
459
- message: 'Output directory:',
460
- default: config.outputDir || './context-reports'
461
464
  }
462
465
  ]);
463
466
  console.log();
464
- await batchCommand(inputFile, { outputDir });
467
+ await batchCommand(inputFile, {});
465
468
  break;
466
469
  }
467
470
  case 'config':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencontext",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "AI-powered company context analysis from your terminal. Extract comprehensive company profiles with a single command.",
5
5
  "main": "dist/cli/index.js",
6
6
  "bin": {