lexi-ai 1.0.0
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.
- package/index.js +143 -0
- package/package.json +38 -0
package/index.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lexi AI CLI Tool
|
|
5
|
+
* Usage: npx lexi-ai index --url <github-repo-url> --token <github-token>
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { Command } = require('commander');
|
|
9
|
+
const axios = require('axios');
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const ora = require('ora');
|
|
12
|
+
const http = require('http');
|
|
13
|
+
|
|
14
|
+
const program = new Command();
|
|
15
|
+
|
|
16
|
+
// Auto-detect API endpoint
|
|
17
|
+
async function detectApiEndpoint() {
|
|
18
|
+
// Check for environment variable first
|
|
19
|
+
if (process.env.LEXI_AI_API_URL) {
|
|
20
|
+
return process.env.LEXI_AI_API_URL;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Check for VERCEL_URL (if deployed on Vercel)
|
|
24
|
+
if (process.env.VERCEL_URL) {
|
|
25
|
+
return `https://${process.env.VERCEL_URL}/api/scrape`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Try localhost:3000
|
|
29
|
+
const localApi = 'http://localhost:3000/api/scrape';
|
|
30
|
+
try {
|
|
31
|
+
await new Promise((resolve, reject) => {
|
|
32
|
+
const req = http.get('http://localhost:3000', (res) => {
|
|
33
|
+
resolve();
|
|
34
|
+
});
|
|
35
|
+
req.on('error', reject);
|
|
36
|
+
req.setTimeout(1000, () => reject(new Error('Timeout')));
|
|
37
|
+
});
|
|
38
|
+
return localApi;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
// If localhost doesn't work, return it anyway (user might need to start server)
|
|
41
|
+
return localApi;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Validate GitHub URL
|
|
46
|
+
function validateGitHubUrl(url) {
|
|
47
|
+
const githubPattern = /^https?:\/\/(www\.)?github\.com\/[^\/]+\/[^\/]+/;
|
|
48
|
+
if (!githubPattern.test(url)) {
|
|
49
|
+
throw new Error('URL must be a GitHub repository URL (e.g., https://github.com/owner/repo)');
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
program
|
|
55
|
+
.name('lexi-ai')
|
|
56
|
+
.description('CLI tool to index GitHub documentation for Lexi AI')
|
|
57
|
+
.version('1.0.0');
|
|
58
|
+
|
|
59
|
+
program
|
|
60
|
+
.command('index')
|
|
61
|
+
.description('Index documentation from a GitHub repository')
|
|
62
|
+
.requiredOption('-u, --url <url>', 'GitHub repository URL (e.g., https://github.com/facebook/react)')
|
|
63
|
+
.option('-t, --token <token>', 'GitHub token for authentication (or set GITHUB_TOKEN env var)')
|
|
64
|
+
.option('-n, --namespace <namespace>', 'Namespace for the indexed content', 'default')
|
|
65
|
+
.option('-a, --api <api>', 'API endpoint URL (auto-detected if not provided)')
|
|
66
|
+
.action(async (options) => {
|
|
67
|
+
const { url, namespace, token } = options;
|
|
68
|
+
|
|
69
|
+
// Validate GitHub URL
|
|
70
|
+
try {
|
|
71
|
+
validateGitHubUrl(url);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(chalk.red(`\nā ${error.message}\n`));
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Get GitHub token
|
|
78
|
+
const githubToken = token || process.env.GITHUB_TOKEN;
|
|
79
|
+
if (!githubToken) {
|
|
80
|
+
console.error(chalk.red('\nā GitHub token is required!'));
|
|
81
|
+
console.log(chalk.yellow('\nPlease provide a GitHub token:'));
|
|
82
|
+
console.log(chalk.gray(' --token <your-github-token>'));
|
|
83
|
+
console.log(chalk.gray(' or set GITHUB_TOKEN environment variable'));
|
|
84
|
+
console.log(chalk.gray('\nGet a token from: https://github.com/settings/tokens\n'));
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Auto-detect API endpoint
|
|
89
|
+
const api = options.api || await detectApiEndpoint();
|
|
90
|
+
|
|
91
|
+
console.log(chalk.blue('\nš Lexi AI Indexer\n'));
|
|
92
|
+
console.log(chalk.gray(`GitHub URL: ${url}`));
|
|
93
|
+
console.log(chalk.gray(`Namespace: ${namespace}`));
|
|
94
|
+
console.log(chalk.gray(`GitHub Token: ${githubToken.substring(0, 8)}...`));
|
|
95
|
+
console.log(chalk.gray(`API Endpoint: ${api}\n`));
|
|
96
|
+
|
|
97
|
+
const spinner = ora('Indexing documentation...').start();
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const payload = {
|
|
101
|
+
url,
|
|
102
|
+
namespace,
|
|
103
|
+
githubToken
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const response = await axios.post(api, payload, {
|
|
107
|
+
timeout: 300000 // 5 minutes timeout
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
if (response.data.success) {
|
|
111
|
+
spinner.succeed(chalk.green('ā Documentation indexed successfully!'));
|
|
112
|
+
console.log(chalk.gray(`\nYou can now query this documentation in the dashboard.\n`));
|
|
113
|
+
} else {
|
|
114
|
+
spinner.fail(chalk.red('ā Failed to index documentation'));
|
|
115
|
+
console.log(chalk.red(`Error: ${response.data.message || 'Unknown error'}\n`));
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
spinner.fail(chalk.red('ā Failed to index documentation'));
|
|
120
|
+
|
|
121
|
+
if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND') {
|
|
122
|
+
console.log(chalk.red('\nā Could not connect to the API server.'));
|
|
123
|
+
console.log(chalk.yellow('\nPossible solutions:'));
|
|
124
|
+
console.log(chalk.gray('1. Make sure your Next.js server is running:'));
|
|
125
|
+
console.log(chalk.gray(' npm run dev'));
|
|
126
|
+
console.log(chalk.gray('\n2. Or set the API endpoint explicitly:'));
|
|
127
|
+
console.log(chalk.gray(` --api ${api}`));
|
|
128
|
+
console.log(chalk.gray('\n3. Or set LEXI_AI_API_URL environment variable:'));
|
|
129
|
+
console.log(chalk.gray(' export LEXI_AI_API_URL=https://your-deployed-url.com/api/scrape\n'));
|
|
130
|
+
} else if (error.response) {
|
|
131
|
+
console.log(chalk.red(`\nError: ${error.response.data?.message || error.message}\n`));
|
|
132
|
+
if (error.response.status === 404) {
|
|
133
|
+
console.log(chalk.yellow('The API endpoint was not found. Check if the server is running.\n'));
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
console.log(chalk.red(`\nError: ${error.message}\n`));
|
|
137
|
+
}
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
program.parse();
|
|
143
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lexi-ai",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "AI-powered GitHub documentation indexing CLI tool",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"lexi-ai": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"ai",
|
|
11
|
+
"documentation",
|
|
12
|
+
"github",
|
|
13
|
+
"indexing",
|
|
14
|
+
"cli",
|
|
15
|
+
"vector-search",
|
|
16
|
+
"pinecone",
|
|
17
|
+
"openai"
|
|
18
|
+
],
|
|
19
|
+
"author": "Yash",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/altairyash/lexiAI.git"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"axios": "^1.8.3",
|
|
27
|
+
"chalk": "^4.1.2",
|
|
28
|
+
"commander": "^12.1.0",
|
|
29
|
+
"ora": "^8.2.0"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"index.js"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
|