legacyver 2.1.8 → 3.1.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/bin/legacyver.js +6 -8
- package/legacyver-docs/OrderController.md +80 -0
- package/legacyver-docs/SUMMARY.md +3 -3
- package/legacyver-docs/bin/legacyver.md +107 -0
- package/legacyver-docs/index.md +15 -15
- package/legacyver-docs/src/api/auth.md +47 -0
- package/legacyver-docs/src/cache/hash.md +24 -0
- package/legacyver-docs/src/cache/index.md +112 -0
- package/legacyver-docs/src/cli/commands/analyze.md +58 -0
- package/legacyver-docs/src/cli/commands/cache.md +21 -0
- package/legacyver-docs/src/cli/commands/init.md +42 -0
- package/legacyver-docs/src/cli/commands/login.md +70 -0
- package/legacyver-docs/src/cli/commands/logout.md +26 -0
- package/legacyver-docs/src/cli/commands/providers.md +23 -0
- package/legacyver-docs/src/cli/commands/push.md +48 -0
- package/legacyver-docs/src/cli/commands/version.md +26 -0
- package/legacyver-docs/src/cli/ui.md +112 -0
- package/legacyver-docs/src/crawler/filters.md +54 -0
- package/legacyver-docs/src/crawler/index.md +54 -0
- package/legacyver-docs/src/crawler/manifest.md +22 -0
- package/legacyver-docs/src/crawler/walk.md +29 -0
- package/legacyver-docs/src/db/config.md +13 -0
- package/legacyver-docs/src/db/index.md +86 -0
- package/legacyver-docs/src/llm/chunker.md +28 -0
- package/legacyver-docs/src/llm/cost-estimator.md +62 -0
- package/legacyver-docs/src/llm/free-model.md +40 -0
- package/legacyver-docs/src/llm/index.md +29 -0
- package/legacyver-docs/src/llm/prompts.md +150 -0
- package/legacyver-docs/src/llm/providers/gemini.md +51 -0
- package/legacyver-docs/src/llm/providers/groq.md +76 -0
- package/legacyver-docs/src/llm/providers/kimi.md +48 -0
- package/legacyver-docs/src/llm/providers/ollama.md +50 -0
- package/legacyver-docs/src/llm/providers/openrouter.md +55 -0
- package/legacyver-docs/src/llm/queue.md +41 -0
- package/legacyver-docs/src/llm/re-prompter.md +33 -0
- package/legacyver-docs/src/llm/validator.md +34 -0
- package/legacyver-docs/src/parser/ast/generic.md +34 -0
- package/legacyver-docs/src/parser/ast/go.md +59 -0
- package/legacyver-docs/src/parser/ast/java.md +58 -0
- package/legacyver-docs/src/parser/ast/javascript.md +71 -0
- package/legacyver-docs/src/parser/ast/laravel/blade.md +45 -0
- package/legacyver-docs/src/parser/ast/laravel/classifier.md +29 -0
- package/legacyver-docs/src/parser/ast/laravel/controller.md +57 -0
- package/legacyver-docs/src/parser/ast/laravel/index.md +27 -0
- package/legacyver-docs/src/parser/ast/laravel/model.md +34 -0
- package/legacyver-docs/src/parser/ast/laravel/provider.md +31 -0
- package/legacyver-docs/src/parser/ast/laravel/routes.md +31 -0
- package/legacyver-docs/src/parser/ast/php.md +127 -0
- package/legacyver-docs/src/parser/ast/python.md +62 -0
- package/legacyver-docs/src/parser/ast/typescript.md +22 -0
- package/legacyver-docs/src/parser/body-extractor.md +34 -0
- package/legacyver-docs/src/parser/call-graph.md +45 -0
- package/legacyver-docs/src/parser/complexity-scorer.md +25 -0
- package/legacyver-docs/src/parser/index.md +59 -0
- package/legacyver-docs/src/parser/pattern-detector.md +28 -0
- package/legacyver-docs/src/parser/pkg-builder.md +34 -0
- package/legacyver-docs/src/renderer/html.md +36 -0
- package/legacyver-docs/src/renderer/index.md +26 -0
- package/legacyver-docs/src/renderer/json.md +25 -0
- package/legacyver-docs/src/renderer/markdown.md +77 -0
- package/legacyver-docs/src/utils/config.md +62 -0
- package/legacyver-docs/src/utils/errors.md +53 -0
- package/legacyver-docs/src/utils/logger.md +48 -0
- package/package.json +50 -51
- package/src/cli/commands/analyze.js +5 -5
- package/src/cli/commands/init.js +4 -4
- package/src/cli/commands/providers.js +3 -3
- package/src/llm/cost-estimator.js +2 -2
- package/src/llm/free-model.js +2 -2
- package/src/llm/index.js +2 -2
- package/src/llm/providers/openrouter.js +5 -2
- package/src/llm/validator.js +41 -2
- package/src/utils/config.js +1 -1
- package/legacyver-docs/components.md +0 -63
- package/nul +0 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
The `pushCommand` function is a CLI command that manually pushes existing generated documentation to the cloud database. It reads markdown files from the output directory and pushes them as documentation pages.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### pushCommand
|
|
6
|
+
#### Description
|
|
7
|
+
Manually push existing generated docs to the cloud database.
|
|
8
|
+
|
|
9
|
+
#### Parameters
|
|
10
|
+
| Name | Type | Description |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| target | string | The directory to read markdown files from (default: current directory) |
|
|
13
|
+
| options | object | Options object (contains `out` property) |
|
|
14
|
+
|
|
15
|
+
#### Return Value
|
|
16
|
+
No return value
|
|
17
|
+
|
|
18
|
+
#### Detected Patterns
|
|
19
|
+
* Arithmetic operations are used to calculate the number of markdown files found in the output directory.
|
|
20
|
+
|
|
21
|
+
### collectMarkdownFiles
|
|
22
|
+
#### Description
|
|
23
|
+
Recursively collect .md files from a directory. Each file becomes a fragment with { relativePath, content }.
|
|
24
|
+
|
|
25
|
+
#### Parameters
|
|
26
|
+
| Name | Type | Description |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| baseDir | string | The base directory to resolve relative paths from |
|
|
29
|
+
| dir | string | The directory to read files from |
|
|
30
|
+
| results | array | The array to store the collected fragments |
|
|
31
|
+
|
|
32
|
+
#### Return Value
|
|
33
|
+
No return value
|
|
34
|
+
|
|
35
|
+
## Dependencies
|
|
36
|
+
* `path`
|
|
37
|
+
* `fs`
|
|
38
|
+
* `picocolors`
|
|
39
|
+
* `loadSession` from `../../utils/config`
|
|
40
|
+
* `logger` from `../../utils/logger`
|
|
41
|
+
* `ora`
|
|
42
|
+
* `pushToDatabase` from `../../db/index`
|
|
43
|
+
|
|
44
|
+
## Usage Example
|
|
45
|
+
No clear pattern is visible in the code, but the function can be used as follows:
|
|
46
|
+
```bash
|
|
47
|
+
legacyver push [target]
|
|
48
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
This module exports a function `versionCommand` that prints the version of the package to the console.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### versionCommand
|
|
6
|
+
Prints the version of the package to the console.
|
|
7
|
+
|
|
8
|
+
| Param | Type | Description |
|
|
9
|
+
| --- | --- | --- |
|
|
10
|
+
| None | | |
|
|
11
|
+
|
|
12
|
+
| Return Value | Type | Description |
|
|
13
|
+
| --- | --- | --- |
|
|
14
|
+
| None | | |
|
|
15
|
+
|
|
16
|
+
## Dependencies
|
|
17
|
+
* `fs: readFileSync`
|
|
18
|
+
* `path: join`
|
|
19
|
+
|
|
20
|
+
## Usage Example
|
|
21
|
+
The function can be used as follows:
|
|
22
|
+
```javascript
|
|
23
|
+
const version = require('./version');
|
|
24
|
+
version.versionCommand();
|
|
25
|
+
```
|
|
26
|
+
This will print the version of the package to the console.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
This module exports four functions for creating a spinner, progress bar, confirming a prompt, and printing a summary of analysis results.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
|
|
6
|
+
### createSpinner(text)
|
|
7
|
+
Creates a spinner object for displaying a text message.
|
|
8
|
+
|
|
9
|
+
| Param | Type | Description |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| text | string | The text to display in the spinner |
|
|
12
|
+
|
|
13
|
+
| Return Value | Type | Description |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| object | | An object with methods for starting, succeeding, failing, warning, stopping, and getting the text |
|
|
16
|
+
|
|
17
|
+
#### Usage
|
|
18
|
+
```javascript
|
|
19
|
+
const spinner = createSpinner('Analyzing...');
|
|
20
|
+
spinner.start('Starting...');
|
|
21
|
+
spinner.succeed('Done!');
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### createProgressBar(total)
|
|
25
|
+
Creates a progress bar object for displaying a progress bar.
|
|
26
|
+
|
|
27
|
+
| Param | Type | Description |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| total | number | The total number of items to process |
|
|
30
|
+
|
|
31
|
+
| Return Value | Type | Description |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| object | | An object with methods for starting, incrementing, and stopping the progress bar |
|
|
34
|
+
|
|
35
|
+
#### Usage
|
|
36
|
+
```javascript
|
|
37
|
+
const progressBar = createProgressBar(100);
|
|
38
|
+
progressBar.start();
|
|
39
|
+
for (let i = 0; i < 100; i++) {
|
|
40
|
+
progressBar.increment();
|
|
41
|
+
}
|
|
42
|
+
progressBar.stop();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### confirmPrompt(message)
|
|
46
|
+
Asynchronously confirms a prompt with the user.
|
|
47
|
+
|
|
48
|
+
| Param | Type | Description |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| message | string | The message to display to the user |
|
|
51
|
+
|
|
52
|
+
| Return Value | Type | Description |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| Promise | | A promise that resolves to a boolean indicating whether the user confirmed |
|
|
55
|
+
|
|
56
|
+
#### Usage
|
|
57
|
+
```javascript
|
|
58
|
+
confirmPrompt('Are you sure?').then((confirmed) => {
|
|
59
|
+
if (confirmed) {
|
|
60
|
+
console.log('Confirmed!');
|
|
61
|
+
} else {
|
|
62
|
+
console.log('Not confirmed!');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### printSummary(stats)
|
|
68
|
+
Prints a summary of analysis results.
|
|
69
|
+
|
|
70
|
+
| Param | Type | Description |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| stats | object | The analysis results |
|
|
73
|
+
|
|
74
|
+
| Return Value | Type | Description |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| void | | No return value |
|
|
77
|
+
|
|
78
|
+
#### Usage
|
|
79
|
+
```javascript
|
|
80
|
+
const stats = { filesAnalyzed: 100, filesCached: 20, filesSkipped: 10 };
|
|
81
|
+
printSummary(stats);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Dependencies
|
|
85
|
+
|
|
86
|
+
* `ora`: for creating a spinner
|
|
87
|
+
* `cli-progress`: for creating a progress bar
|
|
88
|
+
* `readline`: for reading input from the user
|
|
89
|
+
* `picocolors`: for coloring console output
|
|
90
|
+
* `../utils/config`: for loading the session configuration
|
|
91
|
+
|
|
92
|
+
## Usage Example
|
|
93
|
+
```javascript
|
|
94
|
+
const { createSpinner, createProgressBar, confirmPrompt, printSummary } = require('./cli/ui');
|
|
95
|
+
|
|
96
|
+
const spinner = createSpinner('Analyzing...');
|
|
97
|
+
spinner.start('Starting...');
|
|
98
|
+
confirmPrompt('Are you sure?').then((confirmed) => {
|
|
99
|
+
if (confirmed) {
|
|
100
|
+
const progressBar = createProgressBar(100);
|
|
101
|
+
progressBar.start();
|
|
102
|
+
for (let i = 0; i < 100; i++) {
|
|
103
|
+
progressBar.increment();
|
|
104
|
+
}
|
|
105
|
+
progressBar.stop();
|
|
106
|
+
const stats = { filesAnalyzed: 100, filesCached: 20, filesSkipped: 10 };
|
|
107
|
+
printSummary(stats);
|
|
108
|
+
} else {
|
|
109
|
+
console.log('Not confirmed!');
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
This module provides functions for detecting the language of a file based on its extension and detecting the primary language of a list of files.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
|
|
6
|
+
### detectLanguage(ext)
|
|
7
|
+
Detects the language of a file based on its extension.
|
|
8
|
+
|
|
9
|
+
| Param | Type | Description |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| ext | string | The file extension to detect the language for |
|
|
12
|
+
|
|
13
|
+
| Return Value | Type | Description |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| language | string | The detected language, or null if not found |
|
|
16
|
+
|
|
17
|
+
### detectPrimaryLanguage(files)
|
|
18
|
+
Detects the primary language of a list of files.
|
|
19
|
+
|
|
20
|
+
| Param | Type | Description |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| files | array | The list of files to detect the primary language for |
|
|
23
|
+
|
|
24
|
+
| Return Value | Type | Description |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| language | string | The primary language detected |
|
|
27
|
+
|
|
28
|
+
## Dependencies
|
|
29
|
+
* `Object.entries()`
|
|
30
|
+
* `Object.values()`
|
|
31
|
+
* `flat()`
|
|
32
|
+
|
|
33
|
+
## Usage Example
|
|
34
|
+
```javascript
|
|
35
|
+
const files = [
|
|
36
|
+
{ language: 'javascript' },
|
|
37
|
+
{ language: 'typescript' },
|
|
38
|
+
{ language: 'javascript' },
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const primaryLanguage = detectPrimaryLanguage(files);
|
|
42
|
+
console.log(primaryLanguage); // Output: javascript
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Based on the provided code, here are the documentation for the missing exported symbols:
|
|
46
|
+
|
|
47
|
+
## LANGUAGE_EXTENSIONS
|
|
48
|
+
A list of language extensions supported by the module.
|
|
49
|
+
|
|
50
|
+
## ALL_EXTENSIONS
|
|
51
|
+
A list of all extensions supported by the module.
|
|
52
|
+
|
|
53
|
+
## DEFAULT_IGNORE_PATTERNS
|
|
54
|
+
A list of default patterns to ignore when processing files.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
This is a JavaScript module that exports a single function, `crawl`, which is the main entrypoint for a file crawler. The `crawl` function takes a target directory and a configuration object as input and returns an object containing a list of files, skipped files, and metadata about the crawled directory.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### crawl
|
|
6
|
+
#### Description
|
|
7
|
+
The `crawl` function is the main entrypoint for the file crawler. It takes a target directory and a configuration object as input and returns an object containing a list of files, skipped files, and metadata about the crawled directory.
|
|
8
|
+
|
|
9
|
+
#### Parameters
|
|
10
|
+
| Name | Type | Description |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| targetDir | string | The target directory to crawl. |
|
|
13
|
+
| config | Object | The configuration object for the crawler. |
|
|
14
|
+
|
|
15
|
+
#### Return Value
|
|
16
|
+
An object containing the following properties:
|
|
17
|
+
| Name | Type | Description |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| files | FileManifest[] | A list of files in the crawled directory. |
|
|
20
|
+
| skipped | Object[] | A list of files that were skipped due to size or other reasons. |
|
|
21
|
+
| meta | Object | Metadata about the crawled directory, including the primary language, framework, and total number of files. |
|
|
22
|
+
|
|
23
|
+
#### Body Logic
|
|
24
|
+
The `crawl` function performs the following steps:
|
|
25
|
+
1. Calculates the maximum file size in bytes based on the configuration object.
|
|
26
|
+
2. Walks the target directory using the `walk` function and builds a manifest of files using the `buildManifest` function.
|
|
27
|
+
3. Applies a size filter to the manifest, skipping files that exceed the maximum size.
|
|
28
|
+
4. Detects the primary language of the files using the `detectPrimaryLanguage` function.
|
|
29
|
+
5. Detects whether the directory is a Laravel project by checking for the presence of the `artisan` and `app` directories.
|
|
30
|
+
6. Returns an object containing the filtered files, skipped files, and metadata about the crawled directory.
|
|
31
|
+
|
|
32
|
+
## Dependencies
|
|
33
|
+
* `fs`: for the `existsSync` function
|
|
34
|
+
* `path`: for path manipulation
|
|
35
|
+
* `./walk`: for walking the target directory
|
|
36
|
+
* `./manifest`: for building the file manifest
|
|
37
|
+
* `./filters`: for detecting the primary language
|
|
38
|
+
* `../utils/logger`: for logging messages
|
|
39
|
+
|
|
40
|
+
## Usage Example
|
|
41
|
+
```javascript
|
|
42
|
+
const { crawl } = require('./index');
|
|
43
|
+
|
|
44
|
+
const targetDir = '/path/to/directory';
|
|
45
|
+
const config = {
|
|
46
|
+
maxFileSizeKb: 1024,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
crawl(targetDir, config).then((result) => {
|
|
50
|
+
console.log(result.files);
|
|
51
|
+
console.log(result.skipped);
|
|
52
|
+
console.log(result.meta);
|
|
53
|
+
});
|
|
54
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
The `buildManifest` function generates a list of file manifests from a list of absolute file paths.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### buildManifest
|
|
6
|
+
Build a FileManifest[] from a list of absolute paths.
|
|
7
|
+
|
|
8
|
+
| Parameter | Type | Description |
|
|
9
|
+
| --- | --- | --- |
|
|
10
|
+
| absPaths | string[] | List of absolute file paths. |
|
|
11
|
+
| targetDir | string | Target directory for relative path calculation. |
|
|
12
|
+
|
|
13
|
+
Returns: `import('./index').FileManifest[]`
|
|
14
|
+
|
|
15
|
+
## Dependencies
|
|
16
|
+
* `crypto: createHash`
|
|
17
|
+
* `fs: statSync, readFileSync`
|
|
18
|
+
* `path: path`
|
|
19
|
+
* `./filters: detectLanguage`
|
|
20
|
+
|
|
21
|
+
## Usage Example
|
|
22
|
+
The `buildManifest` function takes a list of absolute file paths and a target directory, and returns a list of file manifests. Each file manifest contains the relative path, absolute path, language, size in bytes, and SHA-256 hash of the file. If a file is unreadable, its hash is set to `null`.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
The `walk` function is used to walk a directory and return all matching source file paths. It takes a target directory and a configuration object as input.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### walk
|
|
6
|
+
* Description: Walk a directory and return all matching source file paths.
|
|
7
|
+
* Parameters:
|
|
8
|
+
+ `targetDir`: The target directory to walk.
|
|
9
|
+
+ `config`: The configuration object.
|
|
10
|
+
* Return Value: An array of absolute paths.
|
|
11
|
+
|
|
12
|
+
## Dependencies
|
|
13
|
+
* `fast-glob`: `fg`
|
|
14
|
+
* `ignore`: `ignore`
|
|
15
|
+
* `fs`: `readFileSync`, `existsSync`
|
|
16
|
+
* `path`: `path`
|
|
17
|
+
* `./filters`: `DEFAULT_IGNORE_PATTERNS`, `ALL_EXTENSIONS`
|
|
18
|
+
|
|
19
|
+
## Usage Example
|
|
20
|
+
The `walk` function can be used as follows:
|
|
21
|
+
```javascript
|
|
22
|
+
const walk = require('./walk');
|
|
23
|
+
const targetDir = '/path/to/directory';
|
|
24
|
+
const config = {};
|
|
25
|
+
|
|
26
|
+
const paths = await walk(targetDir, config);
|
|
27
|
+
console.log(paths);
|
|
28
|
+
```
|
|
29
|
+
Note: The usage example is not directly extracted from the code, but rather inferred based on the function's purpose and parameters.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
This module exports a PostgreSQL connection configuration for the Legacyver hackathon database, using SSL with a self-signed certificate.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### None
|
|
6
|
+
|
|
7
|
+
## Dependencies
|
|
8
|
+
* `module.exports`
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
None, as this module only exports a configuration object.
|
|
12
|
+
|
|
13
|
+
Note: This module does not contain any functions, only a configuration object that is exported. The usage example is not applicable in this case.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
This module provides a set of functions for interacting with a PostgreSQL database, specifically for managing repositories and documentation. It uses a lazy singleton pool to connect to the database.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
|
|
6
|
+
### getPool
|
|
7
|
+
#### Description
|
|
8
|
+
Lazy singleton pool — created on first use, ended after push.
|
|
9
|
+
#### Parameters
|
|
10
|
+
| Name | Type | Description |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| None | | |
|
|
13
|
+
#### Return Value
|
|
14
|
+
`Pool` instance
|
|
15
|
+
|
|
16
|
+
### getOrCreateRepo
|
|
17
|
+
#### Description
|
|
18
|
+
Find or create a repository for the given user + project path.
|
|
19
|
+
#### Parameters
|
|
20
|
+
| Name | Type | Description |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| pool | `Pool` | Database connection pool |
|
|
23
|
+
| userId | `string` | User ID (BIGINT as string) |
|
|
24
|
+
| projectPath | `string` | Absolute path of the analyzed directory |
|
|
25
|
+
#### Return Value
|
|
26
|
+
`Promise<string>` repository ID (UUID)
|
|
27
|
+
|
|
28
|
+
### getOrCreateDocumentation
|
|
29
|
+
#### Description
|
|
30
|
+
Find or create a documentation record for a repository.
|
|
31
|
+
#### Parameters
|
|
32
|
+
| Name | Type | Description |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| pool | `Pool` | Database connection pool |
|
|
35
|
+
| repositoryId | `string` | Repository ID (UUID) |
|
|
36
|
+
| repoName | `string` | Repository name |
|
|
37
|
+
#### Return Value
|
|
38
|
+
`Promise<string>` documentation ID (UUID)
|
|
39
|
+
|
|
40
|
+
### upsertPages
|
|
41
|
+
#### Description
|
|
42
|
+
Upsert documentation pages.
|
|
43
|
+
#### Parameters
|
|
44
|
+
| Name | Type | Description |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| pool | `Pool` | Database connection pool |
|
|
47
|
+
| documentationId | `string` | Documentation ID (UUID) |
|
|
48
|
+
| fragments | `Array<{relativePath: string, content: string}>` | Array of fragments to upsert |
|
|
49
|
+
#### Return Value
|
|
50
|
+
`Promise<number>` count of upserted pages
|
|
51
|
+
|
|
52
|
+
### pushToDatabase
|
|
53
|
+
#### Description
|
|
54
|
+
Top-level push function. Called from analyze command.
|
|
55
|
+
#### Parameters
|
|
56
|
+
| Name | Type | Description |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| fragments | `Array<{relativePath: string, content: string}>` | Array of fragments to push |
|
|
59
|
+
| projectPath | `string` | Absolute path of the analyzed directory |
|
|
60
|
+
| [opts] | `object` | Optional overrides for testing |
|
|
61
|
+
| [opts.pool] | `object` | PG Pool instance (skips singleton pool) |
|
|
62
|
+
| [opts.session] | `object` | Session object (skips loadSession) |
|
|
63
|
+
| [opts.user] | `object` | User object (skips validateToken) — { userId, username, email } |
|
|
64
|
+
#### Return Value
|
|
65
|
+
`Promise<{skipped: boolean, pushed?: number}>`
|
|
66
|
+
|
|
67
|
+
## Dependencies
|
|
68
|
+
|
|
69
|
+
* `pg: Pool`
|
|
70
|
+
* `path: path`
|
|
71
|
+
* `./config: dbConfig`
|
|
72
|
+
* `../utils/config: loadSession`
|
|
73
|
+
* `../api/auth: validateToken`
|
|
74
|
+
* `../utils/logger: logger`
|
|
75
|
+
|
|
76
|
+
## Usage Example
|
|
77
|
+
```javascript
|
|
78
|
+
const pool = getPool();
|
|
79
|
+
const repoId = await getOrCreateRepo(pool, '1234567890', '/path/to/project');
|
|
80
|
+
const docId = await getOrCreateDocumentation(pool, repoId, 'my-repo');
|
|
81
|
+
const pushed = await upsertPages(pool, docId, [
|
|
82
|
+
{ relativePath: 'file1.md', content: 'Hello world!' },
|
|
83
|
+
{ relativePath: 'file2.md', content: 'Foo bar!' },
|
|
84
|
+
]);
|
|
85
|
+
console.log(pushed); // 2
|
|
86
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
The `buildChunks` function builds LLM request chunks from a given package (`pkg`) and configuration (`config`). It processes each file in the package, truncating the source if necessary to fit within a token count limit.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### buildChunks
|
|
6
|
+
#### Description
|
|
7
|
+
Builds LLM request chunks from a given package (`pkg`) and configuration (`config`).
|
|
8
|
+
|
|
9
|
+
#### Parameters
|
|
10
|
+
| Name | Type | Description |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| `pkg` | `Object` | The package to process. |
|
|
13
|
+
| `config` | `Object` | The configuration to use. |
|
|
14
|
+
|
|
15
|
+
#### Return Value
|
|
16
|
+
`Array<{relativePath, systemPrompt, userMessage, tokenCount}>`
|
|
17
|
+
|
|
18
|
+
#### Detected Patterns
|
|
19
|
+
* Arithmetic operations are used to calculate the token count and budget characters.
|
|
20
|
+
|
|
21
|
+
## Dependencies
|
|
22
|
+
* `fs: readFileSync`
|
|
23
|
+
* `./prompts: SYSTEM_PROMPT, buildUserMessage`
|
|
24
|
+
* `./cost-estimator: countTokens`
|
|
25
|
+
* `../utils/logger: logger`
|
|
26
|
+
|
|
27
|
+
## Usage Example
|
|
28
|
+
Based on the code, it appears that the function is designed to be used in a loop, processing each file in the package. The `buildChunks` function returns an array of objects, each containing the relative path, system prompt, user message, and token count for a given file.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
This module provides functions for estimating the cost of using Large Language Models (LLMs) based on the input text and model pricing data. It uses the tiktoken library to estimate token counts and fetches model pricing data from the OpenRouter API.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
|
|
6
|
+
### countTokens(text)
|
|
7
|
+
Counts the number of tokens in the given text.
|
|
8
|
+
|
|
9
|
+
#### Parameters
|
|
10
|
+
| Name | Type | Description |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| text | string | The text to count tokens for |
|
|
13
|
+
|
|
14
|
+
#### Return Value
|
|
15
|
+
The number of tokens in the text.
|
|
16
|
+
|
|
17
|
+
#### Description
|
|
18
|
+
This function uses the tiktoken library to encode the text and return the length of the encoded string. If the tiktoken library is not available, it falls back to a rough approximation of 1 token per 4 characters.
|
|
19
|
+
|
|
20
|
+
### fetchModelPricing()
|
|
21
|
+
Fetches the model pricing data from the OpenRouter API or returns a cached version if it is still valid.
|
|
22
|
+
|
|
23
|
+
#### Return Value
|
|
24
|
+
A promise resolving to an object with model pricing data.
|
|
25
|
+
|
|
26
|
+
#### Description
|
|
27
|
+
This function checks if the model pricing cache is still valid (within the last hour). If it is, it returns the cached data. Otherwise, it fetches the data from the OpenRouter API, parses the response, and caches the result.
|
|
28
|
+
|
|
29
|
+
### estimateCost(chunks, config)
|
|
30
|
+
Estimates the cost of a list of LLM request chunks.
|
|
31
|
+
|
|
32
|
+
#### Parameters
|
|
33
|
+
| Name | Type | Description |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| chunks | Array | The list of LLM request chunks |
|
|
36
|
+
| config | Object | The configuration object with a `model` property |
|
|
37
|
+
|
|
38
|
+
#### Return Value
|
|
39
|
+
A promise resolving to an object with the estimated cost data.
|
|
40
|
+
|
|
41
|
+
#### Description
|
|
42
|
+
This function uses the `fetchModelPricing` function to get the model pricing data for the specified model. It then calculates the total input tokens by summing the tokens in each chunk's system prompt and user message. It also calculates the total output tokens based on an average of 400 tokens per chunk. The estimated cost is then calculated by multiplying the total input tokens by the input price and the total output tokens by the output price.
|
|
43
|
+
|
|
44
|
+
## Dependencies
|
|
45
|
+
* `fs`: `readFileSync`
|
|
46
|
+
* `path`: `path`
|
|
47
|
+
* `../utils/logger`: `logger`
|
|
48
|
+
* `tiktoken`: `get_encoding`
|
|
49
|
+
|
|
50
|
+
## Usage Example
|
|
51
|
+
```javascript
|
|
52
|
+
const chunks = [
|
|
53
|
+
{ systemPrompt: 'Hello, world!', userMessage: 'How are you?' },
|
|
54
|
+
{ systemPrompt: 'What is your name?', userMessage: 'John' },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const config = { model: 'meta-llama/llama-3.3-70b-instruct:free' };
|
|
58
|
+
|
|
59
|
+
estimateCost(chunks, config).then((cost) => {
|
|
60
|
+
console.log(cost);
|
|
61
|
+
});
|
|
62
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
The `applyFreeModelPolicy` function applies free model policies to a given configuration object. It checks if the model ID ends with `:free` and adjusts the configuration accordingly.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### applyFreeModelPolicy
|
|
6
|
+
#### Description
|
|
7
|
+
Applies free model policies to a given configuration object.
|
|
8
|
+
|
|
9
|
+
#### Parameters
|
|
10
|
+
| Name | Type | Description |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| config | Object | The configuration object to apply free model policies to |
|
|
13
|
+
|
|
14
|
+
#### Return Value
|
|
15
|
+
The mutated configuration object
|
|
16
|
+
|
|
17
|
+
#### Complex Logic
|
|
18
|
+
The function checks if the provider is one of Ollama, Groq, Gemini, or Kimi, and if so, sets `isFreeModel` and `skipCostEstimation` to `true`. It then checks the provider-specific rate limits and caps concurrency accordingly. If the model ID does not end with `:free`, it sets `isFreeModel` to `false`. Otherwise, it sets `isFreeModel` to `true` and caps concurrency to 2.
|
|
19
|
+
|
|
20
|
+
#### Detected Patterns
|
|
21
|
+
* Arithmetic operations (e.g. `parseInt`, `parseInt(config.concurrency) || 1`)
|
|
22
|
+
* Conditional statements (e.g. `if (provider === 'ollama' || provider === 'groq' || provider === 'gemini' || provider === 'kimi')`)
|
|
23
|
+
* String manipulation (e.g. `provider.toLowerCase()`, `model.endsWith(':free')`)
|
|
24
|
+
|
|
25
|
+
## Dependencies
|
|
26
|
+
* `../utils/logger`
|
|
27
|
+
* `picocolors`
|
|
28
|
+
|
|
29
|
+
## Usage Example
|
|
30
|
+
```javascript
|
|
31
|
+
const config = {
|
|
32
|
+
provider: 'groq',
|
|
33
|
+
model: 'meta-llama/llama-3.3-70b-instruct:free',
|
|
34
|
+
concurrency: 5
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const updatedConfig = applyFreeModelPolicy(config);
|
|
38
|
+
console.log(updatedConfig);
|
|
39
|
+
```
|
|
40
|
+
Note: This example is a simplified representation of the usage and may not cover all possible scenarios.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
This module exports a `createProvider` function that returns an instance of a provider based on the provided configuration.
|
|
3
|
+
|
|
4
|
+
## Functions
|
|
5
|
+
### createProvider
|
|
6
|
+
#### Description
|
|
7
|
+
Returns an instance of a provider based on the provided configuration.
|
|
8
|
+
|
|
9
|
+
#### Parameters
|
|
10
|
+
| Name | Type | Description |
|
|
11
|
+
| --- | --- | --- |
|
|
12
|
+
| config | Object | The configuration object |
|
|
13
|
+
|
|
14
|
+
#### Return Value
|
|
15
|
+
An instance of `OpenRouterProvider`, `OllamaProvider`, `GroqProvider`, `GeminiProvider`, or `KimiProvider`
|
|
16
|
+
|
|
17
|
+
## Dependencies
|
|
18
|
+
* `./providers/openrouter: OpenRouterProvider`
|
|
19
|
+
* `./providers/ollama: OllamaProvider`
|
|
20
|
+
* `./providers/groq: GroqProvider`
|
|
21
|
+
* `./providers/gemini: GeminiProvider`
|
|
22
|
+
* `./providers/kimi: KimiProvider`
|
|
23
|
+
|
|
24
|
+
## Usage Example
|
|
25
|
+
Based on the code, it appears that the `createProvider` function can be used as follows:
|
|
26
|
+
```javascript
|
|
27
|
+
const provider = createProvider({ provider: 'openrouter' });
|
|
28
|
+
```
|
|
29
|
+
This would return an instance of `OpenRouterProvider` with the provided configuration.
|