@equinor/fusion-framework-cli-plugin-ai-index 1.0.5 → 2.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/CHANGELOG.md +91 -2
- package/README.md +105 -69
- package/dist/esm/bin/embed.js +28 -13
- package/dist/esm/bin/embed.js.map +1 -1
- package/dist/esm/delete-command.js +100 -0
- package/dist/esm/delete-command.js.map +1 -0
- package/dist/esm/delete-command.options.js +43 -0
- package/dist/esm/delete-command.options.js.map +1 -0
- package/dist/esm/{command.js → embeddings-command.js} +42 -28
- package/dist/esm/embeddings-command.js.map +1 -0
- package/dist/esm/{command.options.js → embeddings-command.options.js} +14 -7
- package/dist/esm/embeddings-command.options.js.map +1 -0
- package/dist/esm/index.js +37 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/search-command.js +198 -0
- package/dist/esm/search-command.js.map +1 -0
- package/dist/esm/utils/generate-chunk-id.js +17 -5
- package/dist/esm/utils/generate-chunk-id.js.map +1 -1
- package/dist/esm/utils/git/file-changes.js +26 -11
- package/dist/esm/utils/git/file-changes.js.map +1 -1
- package/dist/esm/utils/git/git-client.js +16 -7
- package/dist/esm/utils/git/git-client.js.map +1 -1
- package/dist/esm/utils/git/metadata.js +7 -3
- package/dist/esm/utils/git/metadata.js.map +1 -1
- package/dist/esm/utils/git/status.js +9 -3
- package/dist/esm/utils/git/status.js.map +1 -1
- package/dist/esm/utils/markdown/parser.js +53 -13
- package/dist/esm/utils/markdown/parser.js.map +1 -1
- package/dist/esm/utils/package-resolver.js +10 -6
- package/dist/esm/utils/package-resolver.js.map +1 -1
- package/dist/esm/utils/ts-doc/constants.js +4 -1
- package/dist/esm/utils/ts-doc/constants.js.map +1 -1
- package/dist/esm/utils/ts-doc/extractors.js +27 -13
- package/dist/esm/utils/ts-doc/extractors.js.map +1 -1
- package/dist/esm/utils/ts-doc/parser.js +19 -10
- package/dist/esm/utils/ts-doc/parser.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +51 -10
- package/dist/types/delete-command.d.ts +9 -0
- package/dist/types/delete-command.options.d.ts +32 -0
- package/dist/types/embeddings-command.d.ts +11 -0
- package/dist/types/embeddings-command.options.d.ts +40 -0
- package/dist/types/index.d.ts +19 -2
- package/dist/types/search-command.d.ts +8 -0
- package/dist/types/utils/generate-chunk-id.d.ts +17 -5
- package/dist/types/utils/git/file-changes.d.ts +26 -11
- package/dist/types/utils/git/git-client.d.ts +16 -7
- package/dist/types/utils/git/metadata.d.ts +7 -3
- package/dist/types/utils/git/status.d.ts +9 -3
- package/dist/types/utils/git/types.d.ts +15 -9
- package/dist/types/utils/markdown/parser.d.ts +23 -10
- package/dist/types/utils/markdown/types.d.ts +13 -2
- package/dist/types/utils/package-resolver.d.ts +8 -5
- package/dist/types/utils/ts-doc/constants.d.ts +4 -1
- package/dist/types/utils/ts-doc/extractors.d.ts +27 -13
- package/dist/types/utils/ts-doc/parser.d.ts +19 -10
- package/dist/types/utils/ts-doc/types.d.ts +12 -4
- package/dist/types/utils/types.d.ts +10 -6
- package/dist/types/version.d.ts +1 -1
- package/package.json +13 -11
- package/src/bin/delete-removed-files.ts +1 -1
- package/src/bin/embed.ts +47 -18
- package/src/bin/file-stream.ts +1 -1
- package/src/bin/get-diff.ts +1 -1
- package/src/bin/types.ts +1 -1
- package/src/config.ts +52 -10
- package/src/delete-command.options.ts +51 -0
- package/src/delete-command.ts +117 -0
- package/src/{command.options.ts → embeddings-command.options.ts} +16 -9
- package/src/{command.ts → embeddings-command.ts} +46 -28
- package/src/index.ts +38 -4
- package/src/search-command.ts +259 -0
- package/src/utils/generate-chunk-id.ts +17 -5
- package/src/utils/git/file-changes.ts +26 -11
- package/src/utils/git/git-client.ts +16 -7
- package/src/utils/git/metadata.ts +7 -3
- package/src/utils/git/status.ts +9 -3
- package/src/utils/git/types.ts +15 -9
- package/src/utils/markdown/parser.ts +54 -13
- package/src/utils/markdown/types.ts +13 -2
- package/src/utils/package-resolver.ts +10 -6
- package/src/utils/ts-doc/constants.ts +4 -1
- package/src/utils/ts-doc/extractors.ts +27 -13
- package/src/utils/ts-doc/parser.ts +19 -10
- package/src/utils/ts-doc/types.ts +12 -4
- package/src/utils/types.ts +10 -6
- package/src/version.ts +1 -1
- package/dist/esm/command.js.map +0 -1
- package/dist/esm/command.options.js.map +0 -1
- package/dist/types/command.d.ts +0 -2
- package/dist/types/command.options.d.ts +0 -33
package/dist/types/config.d.ts
CHANGED
|
@@ -1,33 +1,74 @@
|
|
|
1
1
|
import type { VectorStoreDocument } from '@equinor/fusion-framework-module-ai/lib';
|
|
2
2
|
import type { FusionAIConfig } from '@equinor/fusion-framework-cli-plugin-ai-base';
|
|
3
3
|
/**
|
|
4
|
-
* Index-specific configuration for Fusion AI operations
|
|
4
|
+
* Index-specific configuration for Fusion AI document indexing operations.
|
|
5
|
+
*
|
|
6
|
+
* Controls which files are collected, how they are chunked, and what metadata
|
|
7
|
+
* is attached before being sent to the Azure AI Search vector store.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const indexConfig: IndexConfig = {
|
|
12
|
+
* patterns: ['src/\**\/*.ts', 'docs/\**\/*.md'],
|
|
13
|
+
* ignore: ['dist/\**', 'node_modules/\**'],
|
|
14
|
+
* metadata: { resolvePackage: true, resolveGit: true },
|
|
15
|
+
* embedding: { chunkSize: 2000, chunkOverlap: 300 },
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
5
18
|
*/
|
|
6
19
|
export interface IndexConfig {
|
|
20
|
+
/** Azure Cognitive Search index name. Overridden by the `--azure-search-index-name` CLI flag. */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** Azure OpenAI embedding deployment name. Overridden by the `--openai-embedding-deployment` CLI flag. */
|
|
23
|
+
model?: string;
|
|
7
24
|
patterns?: string[];
|
|
8
|
-
/**
|
|
25
|
+
/** Glob patterns for files that should be indexed as-is, without chunking or transformation. */
|
|
9
26
|
rawPatterns?: string[];
|
|
10
|
-
/**
|
|
27
|
+
/** Glob patterns to ignore — only applied when file paths are provided to the command. */
|
|
11
28
|
ignore?: string[];
|
|
12
|
-
/**
|
|
29
|
+
/** Respect `.gitignore` rules when globbing files. Defaults to `true`. Set to `false` for build-output directories that are gitignored. */
|
|
30
|
+
gitignore?: boolean;
|
|
31
|
+
/** Metadata processing configuration. */
|
|
13
32
|
metadata?: {
|
|
14
|
-
/** Automatically resolve package
|
|
33
|
+
/** Automatically resolve the nearest `package.json` and attach package name/version/keywords. */
|
|
15
34
|
resolvePackage?: boolean;
|
|
35
|
+
/** Resolve git metadata (commit hash, date, permalink) for each source file. Defaults to `true`. */
|
|
16
36
|
resolveGit?: boolean;
|
|
17
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Custom callback to transform document attributes before embedding.
|
|
39
|
+
*
|
|
40
|
+
* @param metadata - The current attribute map for the document.
|
|
41
|
+
* @param document - The full vector-store document being processed.
|
|
42
|
+
* @returns The transformed attribute map.
|
|
43
|
+
*/
|
|
18
44
|
attributeProcessor?: (metadata: Record<string, unknown>, document: VectorStoreDocument) => Record<string, unknown>;
|
|
19
45
|
};
|
|
20
|
-
/** Embedding generation configuration */
|
|
46
|
+
/** Embedding generation configuration. */
|
|
21
47
|
embedding?: {
|
|
22
|
-
/**
|
|
48
|
+
/** Maximum token size of each text chunk sent for embedding generation. */
|
|
23
49
|
chunkSize?: number;
|
|
24
|
-
/**
|
|
50
|
+
/** Number of overlapping tokens between consecutive chunks. */
|
|
25
51
|
chunkOverlap?: number;
|
|
26
52
|
};
|
|
27
53
|
}
|
|
28
54
|
/**
|
|
29
|
-
*
|
|
55
|
+
* Fusion AI configuration extended with {@link IndexConfig | index-specific settings}.
|
|
56
|
+
*
|
|
57
|
+
* Used as the return type of `configureFusionAI()` when the `ai index add` or
|
|
58
|
+
* `ai index remove` commands are configured.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { configureFusionAI, type FusionAIConfigWithIndex } from '@equinor/fusion-framework-cli-plugin-ai-index';
|
|
63
|
+
*
|
|
64
|
+
* export default configureFusionAI((): FusionAIConfigWithIndex => ({
|
|
65
|
+
* index: {
|
|
66
|
+
* patterns: ['packages/\**\/*.ts', 'packages/\**\/*.md'],
|
|
67
|
+
* },
|
|
68
|
+
* }));
|
|
69
|
+
* ```
|
|
30
70
|
*/
|
|
31
71
|
export interface FusionAIConfigWithIndex extends FusionAIConfig {
|
|
72
|
+
/** Index-specific configuration for document collection, chunking, and metadata. */
|
|
32
73
|
index?: IndexConfig;
|
|
33
74
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configured Commander command for the `ai index remove` subcommand.
|
|
3
|
+
*
|
|
4
|
+
* This constant is the fully-configured {@link Command} instance with all
|
|
5
|
+
* AI-specific options (embedding deployment, Azure Search credentials) applied
|
|
6
|
+
* via `withAiOptions`. It is registered with the CLI automatically by
|
|
7
|
+
* {@link registerAiPlugin}.
|
|
8
|
+
*/
|
|
9
|
+
export declare const deleteCommand: import("commander").Command;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating options of the `ai index remove` command.
|
|
4
|
+
*
|
|
5
|
+
* Extends the base AI options schema ({@link AiOptionsSchema}) to require
|
|
6
|
+
* Azure Search credentials and the embedding deployment (needed to initialise
|
|
7
|
+
* the vector store service for document removal).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const validated = await DeleteOptionsSchema.parseAsync(rawOptions);
|
|
12
|
+
* // validated.dryRun, validated.filter, validated.azureSearchEndpoint, etc.
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const DeleteOptionsSchema: z.ZodObject<{
|
|
16
|
+
openaiApiKey: z.ZodString;
|
|
17
|
+
openaiApiVersion: z.ZodString;
|
|
18
|
+
openaiInstance: z.ZodString;
|
|
19
|
+
openaiChatDeployment: z.ZodOptional<z.ZodString>;
|
|
20
|
+
openaiEmbeddingDeployment: z.ZodString;
|
|
21
|
+
azureSearchEndpoint: z.ZodString;
|
|
22
|
+
azureSearchApiKey: z.ZodString;
|
|
23
|
+
azureSearchIndexName: z.ZodString;
|
|
24
|
+
dryRun: z.ZodBoolean;
|
|
25
|
+
filter: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
/**
|
|
28
|
+
* Validated options for the `ai index remove` command.
|
|
29
|
+
*
|
|
30
|
+
* Inferred from {@link DeleteOptionsSchema}.
|
|
31
|
+
*/
|
|
32
|
+
export type DeleteOptions = z.infer<typeof DeleteOptionsSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Configured Commander command for the `ai index add` subcommand.
|
|
4
|
+
*
|
|
5
|
+
* This constant is the fully-configured {@link Command} instance with all
|
|
6
|
+
* AI-specific options (embedding deployment, Azure Search credentials) applied
|
|
7
|
+
* via `withAiOptions`. It is registered with the CLI automatically by
|
|
8
|
+
* {@link registerAiPlugin}.
|
|
9
|
+
*/
|
|
10
|
+
export declare const command: Command;
|
|
11
|
+
export default command;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for validating command options for the `ai index add` command.
|
|
4
|
+
*
|
|
5
|
+
* Extends the base AI options schema ({@link AiOptionsSchema}) with
|
|
6
|
+
* add-specific options such as `--dry-run`, `--diff`, `--config`,
|
|
7
|
+
* `--base-ref`, and `--clean`.
|
|
8
|
+
*
|
|
9
|
+
* Azure Search and embedding options that are optional in the base schema
|
|
10
|
+
* become **required** because the add command always writes to a
|
|
11
|
+
* vector store.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const validated = await CommandOptionsSchema.parseAsync(rawOptions);
|
|
16
|
+
* // validated.dryRun, validated.azureSearchEndpoint, etc.
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const CommandOptionsSchema: z.ZodObject<{
|
|
20
|
+
openaiApiKey: z.ZodString;
|
|
21
|
+
openaiApiVersion: z.ZodString;
|
|
22
|
+
openaiInstance: z.ZodString;
|
|
23
|
+
openaiChatDeployment: z.ZodOptional<z.ZodString>;
|
|
24
|
+
openaiEmbeddingDeployment: z.ZodString;
|
|
25
|
+
azureSearchEndpoint: z.ZodString;
|
|
26
|
+
azureSearchApiKey: z.ZodString;
|
|
27
|
+
azureSearchIndexName: z.ZodString;
|
|
28
|
+
dryRun: z.ZodBoolean;
|
|
29
|
+
config: z.ZodString;
|
|
30
|
+
diff: z.ZodBoolean;
|
|
31
|
+
baseRef: z.ZodOptional<z.ZodString>;
|
|
32
|
+
clean: z.ZodBoolean;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
/**
|
|
35
|
+
* Validated options for the `ai index add` command.
|
|
36
|
+
*
|
|
37
|
+
* Inferred from {@link CommandOptionsSchema} and used as the single
|
|
38
|
+
* source of truth for option types throughout the add/embeddings pipeline.
|
|
39
|
+
*/
|
|
40
|
+
export type CommandOptions = z.infer<typeof CommandOptionsSchema>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
2
|
export { FusionAIConfigWithIndex, IndexConfig } from './config.js';
|
|
3
3
|
/**
|
|
4
|
-
* Registers the
|
|
5
|
-
*
|
|
4
|
+
* Registers the `ai index` command with the Fusion Framework CLI.
|
|
5
|
+
*
|
|
6
|
+
* Adds a single `index` command under `ai` with subcommands for indexing,
|
|
7
|
+
* searching, and removing documents in the Azure AI Search vector store.
|
|
8
|
+
*
|
|
9
|
+
* @param program - The root Commander {@link Command} instance to attach to.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { Command } from 'commander';
|
|
14
|
+
* import { registerAiPlugin } from '@equinor/fusion-framework-cli-plugin-ai-index';
|
|
15
|
+
*
|
|
16
|
+
* const program = new Command();
|
|
17
|
+
* registerAiPlugin(program);
|
|
18
|
+
* program.parse();
|
|
19
|
+
* // ffc ai index add [glob-patterns...]
|
|
20
|
+
* // ffc ai index search <query>
|
|
21
|
+
* // ffc ai index remove [source-paths...]
|
|
22
|
+
* ```
|
|
6
23
|
*/
|
|
7
24
|
export declare function registerAiPlugin(program: Command): void;
|
|
8
25
|
export default registerAiPlugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configured Commander command for the `ai index search` subcommand.
|
|
3
|
+
*
|
|
4
|
+
* Fully-configured {@link Command} instance with all AI-specific options
|
|
5
|
+
* (embedding deployment, Azure Search credentials) applied via `withAiOptions`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const searchCommand: import("commander").Command;
|
|
8
|
+
export default searchCommand;
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generates a
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Generates a deterministic, URL-safe identifier for a document chunk.
|
|
3
|
+
*
|
|
4
|
+
* The identifier is a Base64-encoded hash of the file path with all
|
|
5
|
+
* non-alphanumeric characters stripped, making it safe for use as an
|
|
6
|
+
* Azure AI Search document key.
|
|
7
|
+
*
|
|
8
|
+
* @param filePath - The relative file path to hash.
|
|
9
|
+
* @param chunkIndex - Optional zero-based chunk index appended to distinguish
|
|
10
|
+
* multiple chunks originating from the same file.
|
|
11
|
+
* @returns A stable, alphanumeric document ID string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* generateChunkId('packages/cli/src/index.ts'); // 'cGFja2FnZXMvY2xpL3NyYy9pbmRleC50cw'
|
|
16
|
+
* generateChunkId('packages/cli/src/index.ts', 0); // 'cGFja2FnZXMvY2xpL3NyYy9pbmRleC50cw-0'
|
|
17
|
+
* generateChunkId('packages/cli/src/index.ts', 3); // 'cGFja2FnZXMvY2xpL3NyYy9pbmRleC50cw-3'
|
|
18
|
+
* ```
|
|
7
19
|
*/
|
|
8
20
|
export declare const generateChunkId: (filePath: string, chunkIndex?: number) => string;
|
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
import type { ChangedFile, GitDiffOptions } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Returns a list of files changed between `baseRef` and HEAD.
|
|
4
|
+
*
|
|
5
|
+
* Parses the output of `git diff --name-status` to classify each file as
|
|
6
|
+
* `'new'`, `'modified'`, or `'removed'`. Renames are expanded into a
|
|
7
|
+
* `'removed'` entry for the old path and a `'new'` entry for the new path.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Configuration controlling the diff reference and working directory.
|
|
10
|
+
* @returns Array of changed files with their status.
|
|
11
|
+
* @throws {Error} If the working directory is not inside a git repository.
|
|
6
12
|
*/
|
|
7
13
|
export declare const getChangedFiles: (options: GitDiffOptions) => Promise<ChangedFile[]>;
|
|
8
14
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
15
|
+
* Determines the git change status of a single file.
|
|
16
|
+
*
|
|
17
|
+
* Checks tracked status, porcelain output, and rename/copy detection to
|
|
18
|
+
* produce one or two {@link ChangedFile} entries (two when a rename is
|
|
19
|
+
* detected — one `'removed'` for the old path and one `'new'` for the
|
|
20
|
+
* current path).
|
|
21
|
+
*
|
|
22
|
+
* @param filePath - Absolute path to the file to inspect.
|
|
23
|
+
* @returns Array with one or two changed-file entries.
|
|
13
24
|
*/
|
|
14
25
|
export declare const getFileStatus: (filePath: string) => Promise<ChangedFile[]>;
|
|
15
26
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
27
|
+
* Checks whether a file path appears in a list of changed files.
|
|
28
|
+
*
|
|
29
|
+
* When the changed-files list is empty (no diff filtering active), every
|
|
30
|
+
* file is considered changed so that all files are processed.
|
|
31
|
+
*
|
|
32
|
+
* @param filePath - Absolute file path to look up.
|
|
33
|
+
* @param changedFiles - Array of {@link ChangedFile} entries to search.
|
|
34
|
+
* @returns `true` if the file has changed or if diff filtering is disabled.
|
|
20
35
|
*/
|
|
21
36
|
export declare const isFileChanged: (filePath: string, changedFiles: ChangedFile[]) => boolean;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { type SimpleGit } from 'simple-git';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Resolves the git repository root for a given file path.
|
|
4
|
+
*
|
|
5
|
+
* Walks up the directory tree looking for a `.git` directory or file
|
|
6
|
+
* (to support worktrees) and returns the enclosing directory.
|
|
7
|
+
*
|
|
8
|
+
* @param filePath - Absolute file or directory path to resolve from.
|
|
9
|
+
* @returns Absolute path to the repository root, or `undefined` if not inside a git repo.
|
|
6
10
|
*/
|
|
7
11
|
export declare const resolveProjectRoot: (filePath: string) => string | undefined;
|
|
8
12
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* Returns a cached `SimpleGit` instance scoped to the repository that
|
|
14
|
+
* contains `filePath`.
|
|
15
|
+
*
|
|
16
|
+
* Instances are cached by repository root to avoid repeatedly spawning
|
|
17
|
+
* new git processes for the same repo.
|
|
18
|
+
*
|
|
19
|
+
* @param filePath - Absolute file path to locate the repository for.
|
|
20
|
+
* @returns An object containing the git client and the repository root path,
|
|
21
|
+
* or `undefined` when `filePath` is not inside a git repository.
|
|
13
22
|
*/
|
|
14
23
|
export declare const getGit: (filePath: string) => {
|
|
15
24
|
git: SimpleGit | undefined;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { GitMetadata } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Extracts git metadata for a single source file.
|
|
4
|
+
*
|
|
5
|
+
* Resolves the latest commit hash, commit date, and a GitHub permalink
|
|
6
|
+
* (when the remote is a GitHub URL) by inspecting `git log` output.
|
|
7
|
+
*
|
|
8
|
+
* @param filePath - Absolute path to the file.
|
|
9
|
+
* @returns Git metadata, or `undefined` if the file is not inside a git repository.
|
|
6
10
|
*/
|
|
7
11
|
export declare const extractGitMetadata: (filePath: string) => Promise<GitMetadata | undefined>;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Retrieves a summary of the current git working-tree status.
|
|
3
|
+
*
|
|
4
|
+
* Returns the current branch name, abbreviated HEAD commit, and counts of
|
|
5
|
+
* staged / unstaged changes. Useful for informational output in CLI commands.
|
|
6
|
+
*
|
|
7
|
+
* @param cwd - Working directory for git operations. Defaults to `process.cwd()`.
|
|
8
|
+
* @returns An object with branch, commit, and file-change counts.
|
|
9
|
+
* @throws {Error} If the working directory is not inside a git repository or
|
|
10
|
+
* the git client cannot be initialised.
|
|
5
11
|
*/
|
|
6
12
|
export declare const getGitStatus: (cwd?: string) => Promise<{
|
|
7
13
|
branch: string;
|
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Git metadata extracted from repository
|
|
2
|
+
* Git metadata extracted from the repository for a single source file.
|
|
3
|
+
*
|
|
4
|
+
* Attached to vector-store documents as part of `metadata.attributes`.
|
|
3
5
|
*/
|
|
4
6
|
export type GitMetadata = Partial<{
|
|
7
|
+
/** Remote origin URL of the git repository. */
|
|
5
8
|
git_remote_url: string;
|
|
9
|
+
/** Short SHA of the most recent commit that touched the file. */
|
|
6
10
|
git_commit_hash: string;
|
|
11
|
+
/** ISO-8601 date string of the most recent commit that touched the file. */
|
|
7
12
|
git_commit_date: string;
|
|
13
|
+
/** GitHub permalink to the file on the default branch. */
|
|
8
14
|
git_link: string;
|
|
9
15
|
}>;
|
|
10
16
|
/**
|
|
11
|
-
*
|
|
17
|
+
* Configuration for retrieving changed files via `git diff`.
|
|
12
18
|
*/
|
|
13
19
|
export interface GitDiffOptions {
|
|
14
|
-
/**
|
|
20
|
+
/** When `true`, enable diff-based file filtering. */
|
|
15
21
|
diff: boolean;
|
|
16
|
-
/** Git reference to compare against (
|
|
22
|
+
/** Git reference to compare against (e.g. `'HEAD~1'`, `'origin/main'`). Defaults to `'HEAD~1'`. */
|
|
17
23
|
baseRef?: string;
|
|
18
|
-
/** Working directory for git operations */
|
|
24
|
+
/** Working directory for git operations. Defaults to `process.cwd()`. */
|
|
19
25
|
cwd?: string;
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
|
-
*
|
|
28
|
+
* Possible change statuses reported by git.
|
|
23
29
|
*/
|
|
24
30
|
export type FileChangeStatus = 'new' | 'modified' | 'removed';
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
32
|
+
* Describes a single file that has changed according to git.
|
|
27
33
|
*/
|
|
28
34
|
export interface ChangedFile {
|
|
29
|
-
/** Absolute file path */
|
|
35
|
+
/** Absolute file-system path to the changed file. */
|
|
30
36
|
filepath: string;
|
|
31
|
-
/**
|
|
37
|
+
/** How the file was changed: added, modified, or deleted. */
|
|
32
38
|
status: FileChangeStatus;
|
|
33
39
|
}
|
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
import type { SourceFile } from '../types.js';
|
|
2
2
|
import type { MarkdownDocument } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
4
|
+
* Checks whether a file path has a Markdown (`.md`) or MDX (`.mdx`) extension.
|
|
5
|
+
*
|
|
6
|
+
* @param filePath - Absolute or relative file path.
|
|
7
|
+
* @returns `true` when the extension is `.md` or `.mdx`.
|
|
7
8
|
*/
|
|
8
9
|
export declare const isMarkdownFile: (filePath: string) => boolean;
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
11
|
+
* Parses Markdown or MDX content into chunked vector-store documents.
|
|
12
|
+
*
|
|
13
|
+
* Extracts YAML frontmatter via `gray-matter`, splits the body using
|
|
14
|
+
* {@link RecursiveCharacterTextSplitter}, and returns one
|
|
15
|
+
* {@link MarkdownDocument} per valid chunk.
|
|
16
|
+
*
|
|
17
|
+
* @template T - Additional frontmatter attributes.
|
|
18
|
+
* @param content - Raw Markdown / MDX string.
|
|
19
|
+
* @param source - Relative source file path used as the document key.
|
|
20
|
+
* @returns Array of chunked Markdown documents.
|
|
14
21
|
*/
|
|
15
22
|
export declare const parseMarkdown: <T extends Record<string, unknown> = Record<string, unknown>>(content: string, source: string) => Promise<MarkdownDocument<T>[]>;
|
|
16
23
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
24
|
+
* Reads a Markdown or MDX file from disk and parses it into chunked documents.
|
|
25
|
+
*
|
|
26
|
+
* Delegates to {@link parseMarkdown} after reading the file content, then
|
|
27
|
+
* enriches each resulting document with the `rootPath` from the source file.
|
|
28
|
+
*
|
|
29
|
+
* @template T - Additional frontmatter attributes.
|
|
30
|
+
* @param file - Source file descriptor with path and optional project root.
|
|
31
|
+
* @returns Array of Markdown documents with root-path metadata.
|
|
32
|
+
* @throws {AssertionError} If the file does not have a `.md` or `.mdx` extension.
|
|
20
33
|
*/
|
|
21
34
|
export declare const parseMarkdownFile: <T extends Record<string, unknown> = Record<string, unknown>>(file: SourceFile) => Promise<MarkdownDocument<T>[]>;
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import type { VectorStoreDocument, VectorStoreDocumentMetadata } from '@equinor/fusion-framework-module-ai/lib';
|
|
2
2
|
/**
|
|
3
|
-
* Markdown
|
|
3
|
+
* Metadata shape for documents generated from Markdown / MDX files.
|
|
4
|
+
*
|
|
5
|
+
* Extends the base vector-store metadata with a `'markdown'` type discriminator
|
|
6
|
+
* and any frontmatter key-value pairs (prefixed with `md_`).
|
|
7
|
+
*
|
|
8
|
+
* @template T - Additional frontmatter attributes.
|
|
4
9
|
*/
|
|
5
10
|
export type MarkdownMetadata<T extends Record<string, unknown> = Record<string, unknown>> = VectorStoreDocumentMetadata<T & {
|
|
11
|
+
/** Discriminator identifying the document as extracted from Markdown. */
|
|
6
12
|
type: 'markdown';
|
|
7
13
|
}>;
|
|
8
14
|
/**
|
|
9
|
-
* Markdown
|
|
15
|
+
* A vector-store document originating from a Markdown or MDX file.
|
|
16
|
+
*
|
|
17
|
+
* Contains a text chunk of the markdown content together with
|
|
18
|
+
* {@link MarkdownMetadata}.
|
|
19
|
+
*
|
|
20
|
+
* @template T - Additional frontmatter attributes.
|
|
10
21
|
*/
|
|
11
22
|
export type MarkdownDocument<T extends Record<string, unknown> = Record<string, unknown>> = VectorStoreDocument<MarkdownMetadata<T>>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { type PackageJson } from 'read-package-up';
|
|
2
2
|
/**
|
|
3
|
-
* Resolves
|
|
4
|
-
* First checks the cache map, then uses read-package-up if no match found.
|
|
3
|
+
* Resolves the nearest `package.json` for a given file path.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Uses an in-memory cache keyed by the package’s directory to avoid
|
|
6
|
+
* redundant file-system lookups when many files share the same package.
|
|
7
|
+
*
|
|
8
|
+
* @param filePath - Absolute path to a source file.
|
|
9
|
+
* @returns The parsed `PackageJson` if found, or `undefined`.
|
|
8
10
|
*
|
|
9
11
|
* @example
|
|
10
12
|
* ```ts
|
|
11
|
-
* const
|
|
13
|
+
* const pkg = await resolvePackage('/repo/packages/cli/src/index.ts');
|
|
14
|
+
* console.log(pkg?.name); // '@equinor/fusion-framework-cli'
|
|
12
15
|
* ```
|
|
13
16
|
*/
|
|
14
17
|
export declare function resolvePackage(filePath: string): Promise<PackageJson | undefined>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { SyntaxKind } from 'ts-morph';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Top-level TypeScript syntax kinds that the TSDoc extractor inspects.
|
|
4
|
+
*
|
|
5
|
+
* Only nodes matching one of these kinds are considered for document
|
|
6
|
+
* extraction; all other descendants are skipped.
|
|
4
7
|
*/
|
|
5
8
|
export declare const nodeKinds: SyntaxKind[];
|
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
import { type SourceFile as ProjectSourceFile, Node, type ClassDeclaration } from 'ts-morph';
|
|
2
2
|
import type { TypescriptDocument, ParseTsDocOptions } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Extracts a
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Extracts a vector-store document from a TypeScript class declaration.
|
|
5
|
+
*
|
|
6
|
+
* Collects the class-level TSDoc comment, constructor signature (if documented),
|
|
7
|
+
* and all public members with TSDoc into a single document whose `pageContent`
|
|
8
|
+
* mirrors a minimal class interface.
|
|
9
|
+
*
|
|
10
|
+
* @param classNode - The `ts-morph` {@link ClassDeclaration} node to inspect.
|
|
11
|
+
* @param sourceFile - The project source file that contains the class.
|
|
12
|
+
* @param _options - Optional parsing configuration.
|
|
13
|
+
* @returns A {@link TypescriptDocument}, or `null` when the class has no TSDoc.
|
|
9
14
|
*/
|
|
10
15
|
export declare const extractDocumentFromClassNode: (classNode: ClassDeclaration, sourceFile: ProjectSourceFile, _options?: ParseTsDocOptions) => TypescriptDocument | null;
|
|
11
16
|
/**
|
|
12
|
-
* Extracts a
|
|
13
|
-
*
|
|
14
|
-
*
|
|
17
|
+
* Extracts a vector-store document from a single TypeScript AST node.
|
|
18
|
+
*
|
|
19
|
+
* Handles function declarations, variable statements (arrow / function
|
|
20
|
+
* expressions), interfaces, type aliases, enums, and classes. Delegates
|
|
21
|
+
* to {@link extractDocumentFromClassNode} for class declarations.
|
|
22
|
+
*
|
|
23
|
+
* @param node - The `ts-morph` AST node to inspect.
|
|
24
|
+
* @param sourceFile - The project source file that contains the node.
|
|
15
25
|
* @param options - Optional parsing configuration.
|
|
16
|
-
* @param nodeOptions - Optional
|
|
17
|
-
*
|
|
26
|
+
* @param nodeOptions - Optional flags (e.g. `skipKindCheck`) to override default
|
|
27
|
+
* kind filtering.
|
|
28
|
+
* @returns A {@link TypescriptDocument}, or `null` when the node has no TSDoc or
|
|
29
|
+
* is not a supported kind.
|
|
18
30
|
*/
|
|
19
31
|
export declare const extractDocumentFromNode: (node: Node, sourceFile: ProjectSourceFile, options?: ParseTsDocOptions, nodeOptions?: {
|
|
20
32
|
skipKindCheck?: boolean;
|
|
21
33
|
}) => TypescriptDocument | null;
|
|
22
34
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
35
|
+
* Walks a TypeScript source file and extracts a {@link TypescriptDocument}
|
|
36
|
+
* for every top-level declaration that carries a TSDoc comment.
|
|
37
|
+
*
|
|
38
|
+
* @param sourceFile - The `ts-morph` source file to traverse.
|
|
25
39
|
* @param options - Optional parsing configuration.
|
|
26
|
-
* @returns
|
|
40
|
+
* @returns Array of extracted documents (one per documented declaration).
|
|
27
41
|
*/
|
|
28
42
|
export declare const processSourceFile: (sourceFile: ProjectSourceFile, options?: ParseTsDocOptions) => TypescriptDocument[];
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import type { SourceFile } from '../types.js';
|
|
2
2
|
import type { TypescriptDocument, ParseTsDocOptions } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Checks
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
4
|
+
* Checks whether a file path has a TypeScript (`.ts`) or TSX (`.tsx`) extension.
|
|
5
|
+
*
|
|
6
|
+
* @param filePath - Absolute or relative file path.
|
|
7
|
+
* @returns `true` if the file extension is `.ts` or `.tsx`.
|
|
7
8
|
*/
|
|
8
9
|
export declare const isTypescriptFile: (filePath: string) => boolean;
|
|
9
10
|
/**
|
|
10
|
-
* Parses TSDoc from
|
|
11
|
-
*
|
|
11
|
+
* Parses TSDoc comments from an in-memory TypeScript code string.
|
|
12
|
+
*
|
|
13
|
+
* Creates a temporary `ts-morph` project, analyses the source, and returns
|
|
14
|
+
* one {@link TypescriptDocument} per documented top-level declaration.
|
|
15
|
+
*
|
|
16
|
+
* @param content - TypeScript source code to parse.
|
|
12
17
|
* @param options - Optional parsing configuration.
|
|
13
|
-
* @returns
|
|
18
|
+
* @returns Array of extracted TypeScript documents with TSDoc metadata.
|
|
14
19
|
*/
|
|
15
20
|
export declare const parseTsDocSync: (content: string, options?: ParseTsDocOptions) => TypescriptDocument[];
|
|
16
21
|
/**
|
|
17
|
-
* Parses TSDoc from a TypeScript file
|
|
18
|
-
*
|
|
22
|
+
* Parses TSDoc comments from a TypeScript file on disk.
|
|
23
|
+
*
|
|
24
|
+
* Reads the file synchronously, creates a `ts-morph` project, and returns
|
|
25
|
+
* one {@link TypescriptDocument} per documented top-level declaration.
|
|
26
|
+
*
|
|
27
|
+
* @param file - Source file descriptor with path and optional project root.
|
|
19
28
|
* @param options - Optional parsing configuration.
|
|
20
|
-
* @returns
|
|
21
|
-
* @throws If the file
|
|
29
|
+
* @returns Array of extracted TypeScript documents.
|
|
30
|
+
* @throws {AssertionError} If the file does not have a `.ts` or `.tsx` extension.
|
|
22
31
|
*/
|
|
23
32
|
export declare const parseTsDocFromFileSync: (file: SourceFile, options?: ParseTsDocOptions) => TypescriptDocument[];
|