@mcampa/ai-context-cli 0.0.1-beta.05e8984
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/LICENSE +21 -0
- package/README.md +257 -0
- package/bin/ai-context-index.js +46 -0
- package/dist/config-loader.d.ts +13 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +196 -0
- package/dist/config-loader.js.map +1 -0
- package/dist/config-loader.test.d.ts +2 -0
- package/dist/config-loader.test.d.ts.map +1 -0
- package/dist/config-loader.test.js +236 -0
- package/dist/config-loader.test.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer.d.ts +9 -0
- package/dist/indexer.d.ts.map +1 -0
- package/dist/indexer.js +97 -0
- package/dist/indexer.js.map +1 -0
- package/dist/indexer.test.d.ts +2 -0
- package/dist/indexer.test.d.ts.map +1 -0
- package/dist/indexer.test.js +160 -0
- package/dist/indexer.test.js.map +1 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/types.test.d.ts +2 -0
- package/dist/types.test.d.ts.map +1 -0
- package/dist/types.test.js +137 -0
- package/dist/types.test.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Zilliz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# @mcampa/ai-context-cli
|
|
2
|
+
|
|
3
|
+
A command-line tool for indexing codebases with AI-powered semantic search. This CLI tool reads your configuration and indexes your codebase into a vector database for semantic search capabilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can run this tool directly without installation using `npx`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @mcampa/ai-context-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install it globally:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @mcampa/ai-context-cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or as a dev dependency in your project:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -D @mcampa/ai-context-cli
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
1. Create a configuration file `ai-context.config.ts` in your project root:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import type { ContextConfig } from "@mcampa/ai-context-cli";
|
|
31
|
+
|
|
32
|
+
const config: ContextConfig = {
|
|
33
|
+
name: "my-project",
|
|
34
|
+
embeddingConfig: {
|
|
35
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
36
|
+
model: "text-embedding-3-small",
|
|
37
|
+
},
|
|
38
|
+
vectorDatabaseConfig: {
|
|
39
|
+
address: "localhost:19530",
|
|
40
|
+
// Or for Zilliz Cloud:
|
|
41
|
+
// token: process.env.ZILLIZ_TOKEN,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default config;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. Run the indexer:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx @mcampa/ai-context-cli
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Configuration
|
|
55
|
+
|
|
56
|
+
### TypeScript Configuration (`ai-context.config.ts`)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import type { ContextConfig } from "@mcampa/ai-context-cli";
|
|
60
|
+
|
|
61
|
+
const config: ContextConfig = {
|
|
62
|
+
// Optional: Name identifier for this context (used in collection naming)
|
|
63
|
+
name: "my-project",
|
|
64
|
+
|
|
65
|
+
// Required: OpenAI embedding configuration
|
|
66
|
+
embeddingConfig: {
|
|
67
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
68
|
+
model: "text-embedding-3-small",
|
|
69
|
+
// Optional: Custom base URL for OpenAI-compatible APIs
|
|
70
|
+
baseURL: "https://api.openai.com/v1",
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// Required: Milvus vector database configuration
|
|
74
|
+
vectorDatabaseConfig: {
|
|
75
|
+
// Option 1: Direct address (for self-hosted Milvus)
|
|
76
|
+
address: "localhost:19530",
|
|
77
|
+
|
|
78
|
+
// Option 2: Token-based auth (for Zilliz Cloud)
|
|
79
|
+
// token: process.env.ZILLIZ_TOKEN,
|
|
80
|
+
|
|
81
|
+
// Optional: Username/password authentication
|
|
82
|
+
// username: "user",
|
|
83
|
+
// password: "password",
|
|
84
|
+
|
|
85
|
+
// Optional: Enable SSL
|
|
86
|
+
// ssl: true,
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
// Optional: Override default supported file extensions
|
|
90
|
+
// supportedExtensions: [".ts", ".tsx", ".js", ".jsx", ".py"],
|
|
91
|
+
|
|
92
|
+
// Optional: Override default ignore patterns
|
|
93
|
+
// ignorePatterns: ["node_modules/**", "dist/**"],
|
|
94
|
+
|
|
95
|
+
// Optional: Add additional extensions beyond defaults
|
|
96
|
+
customExtensions: [".vue", ".svelte"],
|
|
97
|
+
|
|
98
|
+
// Optional: Add additional ignore patterns beyond defaults
|
|
99
|
+
customIgnorePatterns: ["*.test.ts", "*.spec.ts"],
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export default config;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### JavaScript Configuration (`ai-context.config.js`)
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
/** @type {import('@mcampa/ai-context-cli').ContextConfig} */
|
|
109
|
+
const config = {
|
|
110
|
+
name: "my-project",
|
|
111
|
+
embeddingConfig: {
|
|
112
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
113
|
+
model: "text-embedding-3-small",
|
|
114
|
+
},
|
|
115
|
+
vectorDatabaseConfig: {
|
|
116
|
+
address: "localhost:19530",
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default config;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## CLI Options
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
Usage: ai-context-index [options]
|
|
127
|
+
|
|
128
|
+
Options:
|
|
129
|
+
-V, --version output the version number
|
|
130
|
+
-c, --config <path> path to config file (default: ai-context.config.ts/js)
|
|
131
|
+
-f, --force force reindex even if collection already exists
|
|
132
|
+
-h, --help display help for command
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Examples
|
|
136
|
+
|
|
137
|
+
Index with default config location:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx @mcampa/ai-context-cli
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Specify a custom config file:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npx @mcampa/ai-context-cli --config ./configs/production.config.ts
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Force reindex (drop and recreate collection):
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npx @mcampa/ai-context-cli --force
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## CI/CD Integration
|
|
156
|
+
|
|
157
|
+
### GitHub Actions
|
|
158
|
+
|
|
159
|
+
```yaml
|
|
160
|
+
name: Index Codebase
|
|
161
|
+
|
|
162
|
+
on:
|
|
163
|
+
push:
|
|
164
|
+
branches: [main]
|
|
165
|
+
|
|
166
|
+
jobs:
|
|
167
|
+
index:
|
|
168
|
+
runs-on: ubuntu-latest
|
|
169
|
+
steps:
|
|
170
|
+
- uses: actions/checkout@v4
|
|
171
|
+
|
|
172
|
+
- uses: actions/setup-node@v4
|
|
173
|
+
with:
|
|
174
|
+
node-version: "20"
|
|
175
|
+
|
|
176
|
+
- name: Index codebase
|
|
177
|
+
env:
|
|
178
|
+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
|
179
|
+
ZILLIZ_TOKEN: ${{ secrets.ZILLIZ_TOKEN }}
|
|
180
|
+
run: npx @mcampa/ai-context-cli --force
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### GitLab CI
|
|
184
|
+
|
|
185
|
+
```yaml
|
|
186
|
+
index-codebase:
|
|
187
|
+
image: node:20
|
|
188
|
+
script:
|
|
189
|
+
- npx @mcampa/ai-context-cli --force
|
|
190
|
+
variables:
|
|
191
|
+
OPENAI_API_KEY: $OPENAI_API_KEY
|
|
192
|
+
ZILLIZ_TOKEN: $ZILLIZ_TOKEN
|
|
193
|
+
only:
|
|
194
|
+
- main
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Environment Variables
|
|
198
|
+
|
|
199
|
+
You can use environment variables in your configuration file:
|
|
200
|
+
|
|
201
|
+
| Variable | Description |
|
|
202
|
+
| ----------------- | -------------------------------------- |
|
|
203
|
+
| `OPENAI_API_KEY` | Your OpenAI API key |
|
|
204
|
+
| `OPENAI_BASE_URL` | Custom OpenAI-compatible API base URL |
|
|
205
|
+
| `ZILLIZ_TOKEN` | Zilliz Cloud API token |
|
|
206
|
+
| `MILVUS_ADDRESS` | Milvus server address |
|
|
207
|
+
| `DEBUG` | Enable debug output (set to any value) |
|
|
208
|
+
|
|
209
|
+
## Supported File Types
|
|
210
|
+
|
|
211
|
+
By default, the following file extensions are indexed:
|
|
212
|
+
|
|
213
|
+
- **TypeScript/JavaScript**: `.ts`, `.tsx`, `.js`, `.jsx`
|
|
214
|
+
- **Python**: `.py`
|
|
215
|
+
- **Java**: `.java`
|
|
216
|
+
- **C/C++**: `.c`, `.cpp`, `.h`, `.hpp`
|
|
217
|
+
- **C#**: `.cs`
|
|
218
|
+
- **Go**: `.go`
|
|
219
|
+
- **Rust**: `.rs`
|
|
220
|
+
- **PHP**: `.php`
|
|
221
|
+
- **Ruby**: `.rb`
|
|
222
|
+
- **Swift**: `.swift`
|
|
223
|
+
- **Kotlin**: `.kt`
|
|
224
|
+
- **Scala**: `.scala`
|
|
225
|
+
- **Objective-C**: `.m`, `.mm`
|
|
226
|
+
- **Markdown**: `.md`, `.markdown`
|
|
227
|
+
- **Jupyter**: `.ipynb`
|
|
228
|
+
|
|
229
|
+
Use `customExtensions` to add more file types or `supportedExtensions` to override the defaults.
|
|
230
|
+
|
|
231
|
+
## Troubleshooting
|
|
232
|
+
|
|
233
|
+
### "Config file not found"
|
|
234
|
+
|
|
235
|
+
Make sure you have a config file named `ai-context.config.ts` or `ai-context.config.js` in the directory where you're running the command, or specify a custom path with `--config`.
|
|
236
|
+
|
|
237
|
+
### "Missing required field: embeddingConfig.apiKey"
|
|
238
|
+
|
|
239
|
+
Your OpenAI API key is not set. Make sure the environment variable is available:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
export OPENAI_API_KEY="your-api-key"
|
|
243
|
+
npx @mcampa/ai-context-cli
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### "Address is required and could not be resolved from token"
|
|
247
|
+
|
|
248
|
+
Either provide a Milvus `address` or a Zilliz Cloud `token` in your config.
|
|
249
|
+
|
|
250
|
+
### Connection errors
|
|
251
|
+
|
|
252
|
+
- For self-hosted Milvus: Ensure Milvus is running and accessible at the configured address
|
|
253
|
+
- For Zilliz Cloud: Verify your token is correct and not expired
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AI Context CLI - Entry point
|
|
5
|
+
*
|
|
6
|
+
* Runs the CLI directly with Node.js.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = dirname(__filename);
|
|
15
|
+
const cliRoot = join(__dirname, "..");
|
|
16
|
+
|
|
17
|
+
const mainScript = join(cliRoot, "dist", "index.js");
|
|
18
|
+
|
|
19
|
+
// Set NODE_PATH to include the cli package's node_modules
|
|
20
|
+
const nodePath = join(cliRoot, "node_modules");
|
|
21
|
+
const existingNodePath = process.env.NODE_PATH || "";
|
|
22
|
+
const newNodePath = existingNodePath
|
|
23
|
+
? `${nodePath}:${existingNodePath}`
|
|
24
|
+
: nodePath;
|
|
25
|
+
|
|
26
|
+
const env = {
|
|
27
|
+
...process.env,
|
|
28
|
+
NODE_PATH: newNodePath,
|
|
29
|
+
// Pass the cli package root for tsx resolution in config-loader
|
|
30
|
+
AI_CONTEXT_CLI_ROOT: cliRoot,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const child = spawn(process.execPath, [mainScript, ...process.argv.slice(2)], {
|
|
34
|
+
stdio: "inherit",
|
|
35
|
+
env,
|
|
36
|
+
cwd: process.cwd(),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
child.on("close", (code) => {
|
|
40
|
+
process.exit(code ?? 0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
child.on("error", (err) => {
|
|
44
|
+
console.error("Failed to start CLI:", err.message);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ContextConfig } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Find the config file in the given directory
|
|
4
|
+
* Searches for ai-context.config.ts first, then ai-context.config.js
|
|
5
|
+
*/
|
|
6
|
+
export declare function findConfigFile(cwd: string): string | null;
|
|
7
|
+
/**
|
|
8
|
+
* Load and validate the configuration file
|
|
9
|
+
* @param configPath Path to the config file, or directory to search for config
|
|
10
|
+
* @returns Validated configuration object
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadConfig(configPath?: string): Promise<ContextConfig>;
|
|
13
|
+
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../src/config-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQzD;AAsED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAsD5E"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { resolve, join } from "path";
|
|
3
|
+
import { pathToFileURL } from "url";
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
5
|
+
const CONFIG_FILE_NAMES = ["ai-context.config.ts", "ai-context.config.js"];
|
|
6
|
+
/**
|
|
7
|
+
* Find the config file in the given directory
|
|
8
|
+
* Searches for ai-context.config.ts first, then ai-context.config.js
|
|
9
|
+
*/
|
|
10
|
+
export function findConfigFile(cwd) {
|
|
11
|
+
for (const fileName of CONFIG_FILE_NAMES) {
|
|
12
|
+
const filePath = join(cwd, fileName);
|
|
13
|
+
if (existsSync(filePath)) {
|
|
14
|
+
return filePath;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Load a TypeScript config file by spawning tsx
|
|
21
|
+
*/
|
|
22
|
+
function loadTypeScriptConfig(filePath) {
|
|
23
|
+
// Get the CLI root from environment or fallback
|
|
24
|
+
const cliRoot = process.env.AI_CONTEXT_CLI_ROOT;
|
|
25
|
+
// Find tsx binary
|
|
26
|
+
let tsxPath = null;
|
|
27
|
+
if (cliRoot) {
|
|
28
|
+
const possiblePath = join(cliRoot, "node_modules", ".bin", "tsx");
|
|
29
|
+
if (existsSync(possiblePath)) {
|
|
30
|
+
tsxPath = possiblePath;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!tsxPath) {
|
|
34
|
+
throw new Error("TypeScript config files require tsx to be installed.\n" +
|
|
35
|
+
"Please use a JavaScript config file (ai-context.config.js) instead,\n" +
|
|
36
|
+
"or install tsx: npm install -g tsx");
|
|
37
|
+
}
|
|
38
|
+
// Create a wrapper script to load and export the config
|
|
39
|
+
const wrapperScript = `
|
|
40
|
+
import config from ${JSON.stringify(pathToFileURL(filePath).href)};
|
|
41
|
+
console.log(JSON.stringify(config.default || config));
|
|
42
|
+
`;
|
|
43
|
+
const result = spawnSync(tsxPath, ["--eval", wrapperScript], {
|
|
44
|
+
encoding: "utf-8",
|
|
45
|
+
cwd: process.cwd(),
|
|
46
|
+
env: {
|
|
47
|
+
...process.env,
|
|
48
|
+
// Don't inherit NODE_PATH to avoid resolution issues
|
|
49
|
+
NODE_PATH: undefined,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
if (result.error) {
|
|
53
|
+
throw new Error(`Failed to run tsx: ${result.error.message}`);
|
|
54
|
+
}
|
|
55
|
+
if (result.status !== 0) {
|
|
56
|
+
const errorOutput = result.stderr || result.stdout || "Unknown error";
|
|
57
|
+
throw new Error(`Failed to load TypeScript config:\n${errorOutput}`);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(result.stdout.trim());
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new Error(`Failed to parse config output. Make sure your config exports a valid object.\n` +
|
|
64
|
+
`Output was: ${result.stdout}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Load a JavaScript config file
|
|
69
|
+
*/
|
|
70
|
+
async function loadJavaScriptConfig(filePath) {
|
|
71
|
+
const fileUrl = pathToFileURL(filePath).href;
|
|
72
|
+
const module = await import(fileUrl);
|
|
73
|
+
return module.default || module;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Load and validate the configuration file
|
|
77
|
+
* @param configPath Path to the config file, or directory to search for config
|
|
78
|
+
* @returns Validated configuration object
|
|
79
|
+
*/
|
|
80
|
+
export async function loadConfig(configPath) {
|
|
81
|
+
const cwd = process.cwd();
|
|
82
|
+
let resolvedPath;
|
|
83
|
+
if (configPath) {
|
|
84
|
+
// User provided a specific config path
|
|
85
|
+
resolvedPath = resolve(cwd, configPath);
|
|
86
|
+
if (!existsSync(resolvedPath)) {
|
|
87
|
+
throw new Error(`Config file not found: ${resolvedPath}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Search for config file in cwd
|
|
92
|
+
const foundPath = findConfigFile(cwd);
|
|
93
|
+
if (!foundPath) {
|
|
94
|
+
throw new Error(`No config file found. Please create one of:\n` +
|
|
95
|
+
CONFIG_FILE_NAMES.map((f) => ` - ${f}`).join("\n") +
|
|
96
|
+
`\n\nExample config:\n\n` +
|
|
97
|
+
`export default {\n` +
|
|
98
|
+
` name: "my-project",\n` +
|
|
99
|
+
` embeddingConfig: {\n` +
|
|
100
|
+
` apiKey: process.env.OPENAI_API_KEY,\n` +
|
|
101
|
+
` model: "text-embedding-3-small",\n` +
|
|
102
|
+
` },\n` +
|
|
103
|
+
` vectorDatabaseConfig: {\n` +
|
|
104
|
+
` address: "localhost:19530",\n` +
|
|
105
|
+
` },\n` +
|
|
106
|
+
`};`);
|
|
107
|
+
}
|
|
108
|
+
resolvedPath = foundPath;
|
|
109
|
+
}
|
|
110
|
+
console.log(`📄 Loading config from: ${resolvedPath}`);
|
|
111
|
+
try {
|
|
112
|
+
let config;
|
|
113
|
+
if (resolvedPath.endsWith(".ts") || resolvedPath.endsWith(".tsx")) {
|
|
114
|
+
config = loadTypeScriptConfig(resolvedPath);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
config = await loadJavaScriptConfig(resolvedPath);
|
|
118
|
+
}
|
|
119
|
+
// Validate the config
|
|
120
|
+
validateConfig(config);
|
|
121
|
+
return config;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error instanceof Error) {
|
|
125
|
+
throw new Error(`Failed to load config: ${error.message}`);
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validate the configuration object
|
|
132
|
+
* @param config Configuration to validate
|
|
133
|
+
* @throws Error if validation fails
|
|
134
|
+
*/
|
|
135
|
+
function validateConfig(config) {
|
|
136
|
+
const errors = [];
|
|
137
|
+
// Check required embedding config
|
|
138
|
+
if (!config.embeddingConfig) {
|
|
139
|
+
errors.push("Missing required field: embeddingConfig");
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
if (!config.embeddingConfig.apiKey) {
|
|
143
|
+
errors.push("Missing required field: embeddingConfig.apiKey");
|
|
144
|
+
}
|
|
145
|
+
if (!config.embeddingConfig.model) {
|
|
146
|
+
errors.push("Missing required field: embeddingConfig.model");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Check required vector database config
|
|
150
|
+
if (!config.vectorDatabaseConfig) {
|
|
151
|
+
errors.push("Missing required field: vectorDatabaseConfig");
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
// At least address or token is required
|
|
155
|
+
if (!config.vectorDatabaseConfig.address &&
|
|
156
|
+
!config.vectorDatabaseConfig.token) {
|
|
157
|
+
errors.push("vectorDatabaseConfig requires either 'address' or 'token' to be set");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Validate supportedExtensions format if provided
|
|
161
|
+
if (config.supportedExtensions) {
|
|
162
|
+
if (!Array.isArray(config.supportedExtensions)) {
|
|
163
|
+
errors.push("supportedExtensions must be an array of strings");
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
for (const ext of config.supportedExtensions) {
|
|
167
|
+
if (typeof ext !== "string") {
|
|
168
|
+
errors.push(`supportedExtensions contains non-string value: ${ext}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Validate ignorePatterns format if provided
|
|
174
|
+
if (config.ignorePatterns) {
|
|
175
|
+
if (!Array.isArray(config.ignorePatterns)) {
|
|
176
|
+
errors.push("ignorePatterns must be an array of strings");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Validate customExtensions format if provided
|
|
180
|
+
if (config.customExtensions) {
|
|
181
|
+
if (!Array.isArray(config.customExtensions)) {
|
|
182
|
+
errors.push("customExtensions must be an array of strings");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Validate customIgnorePatterns format if provided
|
|
186
|
+
if (config.customIgnorePatterns) {
|
|
187
|
+
if (!Array.isArray(config.customIgnorePatterns)) {
|
|
188
|
+
errors.push("customIgnorePatterns must be an array of strings");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (errors.length > 0) {
|
|
192
|
+
throw new Error(`Invalid configuration:\n${errors.map((e) => ` - ${e}`).join("\n")}`);
|
|
193
|
+
}
|
|
194
|
+
console.log("✅ Config validated successfully");
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=config-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../src/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,MAAM,iBAAiB,GAAG,CAAC,sBAAsB,EAAE,sBAAsB,CAAC,CAAC;AAE3E;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACrC,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzB,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,QAAgB;IAC5C,gDAAgD;IAChD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;IAEhD,kBAAkB;IAClB,IAAI,OAAO,GAAkB,IAAI,CAAC;IAClC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,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