dep-context-mcp 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/README.md +380 -0
- package/dist/analysis/relationships.d.ts +25 -0
- package/dist/analysis/relationships.d.ts.map +1 -0
- package/dist/analysis/relationships.js +26 -0
- package/dist/analysis/relationships.js.map +1 -0
- package/dist/build-info.d.ts +15 -0
- package/dist/build-info.d.ts.map +1 -0
- package/dist/build-info.js +24 -0
- package/dist/build-info.js.map +1 -0
- package/dist/cache/manager.d.ts +19 -0
- package/dist/cache/manager.d.ts.map +1 -0
- package/dist/cache/manager.js +131 -0
- package/dist/cache/manager.js.map +1 -0
- package/dist/cache/registry.d.ts +44 -0
- package/dist/cache/registry.d.ts.map +1 -0
- package/dist/cache/registry.js +92 -0
- package/dist/cache/registry.js.map +1 -0
- package/dist/config/loader.d.ts +62 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +193 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/extraction/examples.d.ts +22 -0
- package/dist/extraction/examples.d.ts.map +1 -0
- package/dist/extraction/examples.js +109 -0
- package/dist/extraction/examples.js.map +1 -0
- package/dist/extraction/external-resolver.d.ts +26 -0
- package/dist/extraction/external-resolver.d.ts.map +1 -0
- package/dist/extraction/external-resolver.js +79 -0
- package/dist/extraction/external-resolver.js.map +1 -0
- package/dist/extraction/import-tracker.d.ts +58 -0
- package/dist/extraction/import-tracker.d.ts.map +1 -0
- package/dist/extraction/import-tracker.js +113 -0
- package/dist/extraction/import-tracker.js.map +1 -0
- package/dist/extraction/readme.d.ts +19 -0
- package/dist/extraction/readme.d.ts.map +1 -0
- package/dist/extraction/readme.js +79 -0
- package/dist/extraction/readme.js.map +1 -0
- package/dist/extraction/snapshot.d.ts +32 -0
- package/dist/extraction/snapshot.d.ts.map +1 -0
- package/dist/extraction/snapshot.js +258 -0
- package/dist/extraction/snapshot.js.map +1 -0
- package/dist/extraction/typescript.d.ts +104 -0
- package/dist/extraction/typescript.d.ts.map +1 -0
- package/dist/extraction/typescript.js +647 -0
- package/dist/extraction/typescript.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +329 -0
- package/dist/index.js.map +1 -0
- package/dist/resolver/package.d.ts +62 -0
- package/dist/resolver/package.d.ts.map +1 -0
- package/dist/resolver/package.js +334 -0
- package/dist/resolver/package.js.map +1 -0
- package/dist/tools/get-dependency.d.ts +55 -0
- package/dist/tools/get-dependency.d.ts.map +1 -0
- package/dist/tools/get-dependency.js +105 -0
- package/dist/tools/get-dependency.js.map +1 -0
- package/dist/tools/index-dependencies.d.ts +51 -0
- package/dist/tools/index-dependencies.d.ts.map +1 -0
- package/dist/tools/index-dependencies.js +90 -0
- package/dist/tools/index-dependencies.js.map +1 -0
- package/dist/tools/index-status.d.ts +36 -0
- package/dist/tools/index-status.d.ts.map +1 -0
- package/dist/tools/index-status.js +45 -0
- package/dist/tools/index-status.js.map +1 -0
- package/dist/tools/list.d.ts +48 -0
- package/dist/tools/list.d.ts.map +1 -0
- package/dist/tools/list.js +55 -0
- package/dist/tools/list.js.map +1 -0
- package/dist/tools/refresh.d.ts +59 -0
- package/dist/tools/refresh.d.ts.map +1 -0
- package/dist/tools/refresh.js +109 -0
- package/dist/tools/refresh.js.map +1 -0
- package/dist/tools/relationships.d.ts +41 -0
- package/dist/tools/relationships.d.ts.map +1 -0
- package/dist/tools/relationships.js +36 -0
- package/dist/tools/relationships.js.map +1 -0
- package/dist/tools/search-codebase.d.ts +64 -0
- package/dist/tools/search-codebase.d.ts.map +1 -0
- package/dist/tools/search-codebase.js +117 -0
- package/dist/tools/search-codebase.js.map +1 -0
- package/dist/tools/search.d.ts +37 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +77 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +71 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/vector/chroma.d.ts +38 -0
- package/dist/vector/chroma.d.ts.map +1 -0
- package/dist/vector/chroma.js +69 -0
- package/dist/vector/chroma.js.map +1 -0
- package/dist/vector/chunker.d.ts +29 -0
- package/dist/vector/chunker.d.ts.map +1 -0
- package/dist/vector/chunker.js +205 -0
- package/dist/vector/chunker.js.map +1 -0
- package/dist/vector/embeddings.d.ts +36 -0
- package/dist/vector/embeddings.d.ts.map +1 -0
- package/dist/vector/embeddings.js +106 -0
- package/dist/vector/embeddings.js.map +1 -0
- package/dist/vector/file-store.d.ts +10 -0
- package/dist/vector/file-store.d.ts.map +1 -0
- package/dist/vector/file-store.js +80 -0
- package/dist/vector/file-store.js.map +1 -0
- package/dist/vector/index-manager.d.ts +39 -0
- package/dist/vector/index-manager.d.ts.map +1 -0
- package/dist/vector/index-manager.js +105 -0
- package/dist/vector/index-manager.js.map +1 -0
- package/dist/vector/provider-factory.d.ts +23 -0
- package/dist/vector/provider-factory.d.ts.map +1 -0
- package/dist/vector/provider-factory.js +50 -0
- package/dist/vector/provider-factory.js.map +1 -0
- package/dist/vector/storage-factory.d.ts +17 -0
- package/dist/vector/storage-factory.d.ts.map +1 -0
- package/dist/vector/storage-factory.js +55 -0
- package/dist/vector/storage-factory.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache registry - manages the index of cached packages
|
|
3
|
+
*/
|
|
4
|
+
export interface CacheEntry {
|
|
5
|
+
packageName: string;
|
|
6
|
+
version: string;
|
|
7
|
+
snapshotPath: string;
|
|
8
|
+
generatedAt: string;
|
|
9
|
+
checksum: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CacheRegistry {
|
|
12
|
+
version: string;
|
|
13
|
+
entries: Record<string, CacheEntry>;
|
|
14
|
+
lastUpdated: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates an empty registry
|
|
18
|
+
*/
|
|
19
|
+
export declare function createEmptyRegistry(): CacheRegistry;
|
|
20
|
+
/**
|
|
21
|
+
* Loads the registry from disk
|
|
22
|
+
*/
|
|
23
|
+
export declare function loadRegistry(cacheDir: string): Promise<CacheRegistry>;
|
|
24
|
+
/**
|
|
25
|
+
* Saves the registry to disk
|
|
26
|
+
*/
|
|
27
|
+
export declare function saveRegistry(cacheDir: string, registry: CacheRegistry): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Adds or updates an entry in the registry
|
|
30
|
+
*/
|
|
31
|
+
export declare function addEntry(registry: CacheRegistry, packageName: string, version: string, snapshotPath: string, generatedAt: string, checksum: string): CacheRegistry;
|
|
32
|
+
/**
|
|
33
|
+
* Removes an entry from the registry
|
|
34
|
+
*/
|
|
35
|
+
export declare function removeEntry(registry: CacheRegistry, packageName: string): CacheRegistry;
|
|
36
|
+
/**
|
|
37
|
+
* Gets an entry from the registry
|
|
38
|
+
*/
|
|
39
|
+
export declare function getEntry(registry: CacheRegistry, packageName: string): CacheEntry | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an entry exists and matches the version
|
|
42
|
+
*/
|
|
43
|
+
export declare function hasValidEntry(registry: CacheRegistry, packageName: string, version: string): boolean;
|
|
44
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/cache/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACnC,WAAW,EAAE,MAAM,CAAA;CACpB;AAID;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAMnD;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAsB3E;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAS3F;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,aAAa,EACvB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,aAAa,CAcf;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa,CAMvF;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAE7F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAGpG"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache registry - manages the index of cached packages
|
|
3
|
+
*/
|
|
4
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
5
|
+
import { join, dirname } from 'node:path';
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
const REGISTRY_VERSION = '1.0.0';
|
|
8
|
+
/**
|
|
9
|
+
* Creates an empty registry
|
|
10
|
+
*/
|
|
11
|
+
export function createEmptyRegistry() {
|
|
12
|
+
return {
|
|
13
|
+
version: REGISTRY_VERSION,
|
|
14
|
+
entries: {},
|
|
15
|
+
lastUpdated: new Date().toISOString()
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Loads the registry from disk
|
|
20
|
+
*/
|
|
21
|
+
export async function loadRegistry(cacheDir) {
|
|
22
|
+
const registryPath = join(cacheDir, 'registry.json');
|
|
23
|
+
if (!existsSync(registryPath)) {
|
|
24
|
+
return createEmptyRegistry();
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const content = await readFile(registryPath, 'utf-8');
|
|
28
|
+
const registry = JSON.parse(content);
|
|
29
|
+
// Validate version
|
|
30
|
+
if (registry.version !== REGISTRY_VERSION) {
|
|
31
|
+
// Version mismatch - return empty registry (will rebuild cache)
|
|
32
|
+
return createEmptyRegistry();
|
|
33
|
+
}
|
|
34
|
+
return registry;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Corrupted registry - return empty
|
|
38
|
+
return createEmptyRegistry();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Saves the registry to disk
|
|
43
|
+
*/
|
|
44
|
+
export async function saveRegistry(cacheDir, registry) {
|
|
45
|
+
const registryPath = join(cacheDir, 'registry.json');
|
|
46
|
+
// Ensure cache directory exists
|
|
47
|
+
await mkdir(dirname(registryPath), { recursive: true });
|
|
48
|
+
registry.lastUpdated = new Date().toISOString();
|
|
49
|
+
await writeFile(registryPath, JSON.stringify(registry, null, 2), 'utf-8');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Adds or updates an entry in the registry
|
|
53
|
+
*/
|
|
54
|
+
export function addEntry(registry, packageName, version, snapshotPath, generatedAt, checksum) {
|
|
55
|
+
return {
|
|
56
|
+
...registry,
|
|
57
|
+
entries: {
|
|
58
|
+
...registry.entries,
|
|
59
|
+
[packageName]: {
|
|
60
|
+
packageName,
|
|
61
|
+
version,
|
|
62
|
+
snapshotPath,
|
|
63
|
+
generatedAt,
|
|
64
|
+
checksum
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Removes an entry from the registry
|
|
71
|
+
*/
|
|
72
|
+
export function removeEntry(registry, packageName) {
|
|
73
|
+
const { [packageName]: _, ...remainingEntries } = registry.entries;
|
|
74
|
+
return {
|
|
75
|
+
...registry,
|
|
76
|
+
entries: remainingEntries
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets an entry from the registry
|
|
81
|
+
*/
|
|
82
|
+
export function getEntry(registry, packageName) {
|
|
83
|
+
return registry.entries[packageName];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Checks if an entry exists and matches the version
|
|
87
|
+
*/
|
|
88
|
+
export function hasValidEntry(registry, packageName, version) {
|
|
89
|
+
const entry = registry.entries[packageName];
|
|
90
|
+
return entry !== undefined && entry.version === version;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/cache/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAgBpC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAEhC;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,OAAO,EAAE,gBAAgB;QACzB,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACtC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAgB;IACjD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;IAEpD,IAA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Z,WAAW;gBACX,QAAQ;aACT;SACF;KACF,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,QAAuB,EAAE,WAAmB;IACtE,MAAM,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,GAAG,gBAAgB,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAA;IAClE,OAAO;QACL,GAAG,QAAQ;QACX,OAAO,EAAE,gBAAgB;KAC1B,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAuB,EAAE,WAAmB;IACnE,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAuB,EAAE,WAAmB,EAAE,OAAe;IACzF,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC3C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO,CAAA;AACzD,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loader for the Dependency Context MCP Server
|
|
3
|
+
*/
|
|
4
|
+
export interface ExtractionConfig {
|
|
5
|
+
includeReadme: boolean;
|
|
6
|
+
includeJsDoc: boolean;
|
|
7
|
+
includeExamples: boolean;
|
|
8
|
+
maxReadmeLength: number;
|
|
9
|
+
maxExamples: number;
|
|
10
|
+
}
|
|
11
|
+
export interface VectorEmbeddingConfig {
|
|
12
|
+
provider: 'openai' | 'ollama';
|
|
13
|
+
ollama?: {
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
model?: string;
|
|
16
|
+
};
|
|
17
|
+
openai?: {
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
model?: 'text-embedding-3-small' | 'text-embedding-3-large';
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface VectorStorageConfig {
|
|
24
|
+
type: 'auto' | 'chroma' | 'file' | 'none';
|
|
25
|
+
chromaHost?: string;
|
|
26
|
+
localPath?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface VectorConfig {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
embedding: VectorEmbeddingConfig;
|
|
31
|
+
storage: VectorStorageConfig;
|
|
32
|
+
indexConcurrency: number;
|
|
33
|
+
}
|
|
34
|
+
export interface GitLabConfig {
|
|
35
|
+
enabled: boolean;
|
|
36
|
+
baseUrl: string;
|
|
37
|
+
token: string;
|
|
38
|
+
}
|
|
39
|
+
export interface Config {
|
|
40
|
+
projectRoot: string;
|
|
41
|
+
nodeModulesPath: string;
|
|
42
|
+
cacheDir: string;
|
|
43
|
+
extraction: ExtractionConfig;
|
|
44
|
+
vector: VectorConfig;
|
|
45
|
+
gitlab: GitLabConfig;
|
|
46
|
+
}
|
|
47
|
+
export declare class ConfigValidationError extends Error {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validates a partial config object and returns a complete config with defaults applied
|
|
52
|
+
*/
|
|
53
|
+
export declare function validateConfig(partial: Partial<Config>): Config;
|
|
54
|
+
/**
|
|
55
|
+
* Loads configuration from file or environment, applying defaults
|
|
56
|
+
*/
|
|
57
|
+
export declare function loadConfig(configPath?: string): Promise<Config>;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the default configuration
|
|
60
|
+
*/
|
|
61
|
+
export declare function getDefaultConfig(): Config;
|
|
62
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,OAAO,CAAA;IACtB,YAAY,EAAE,OAAO,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,eAAe,EAAE,MAAM,CA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AAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA0CrE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loader for the Dependency Context MCP Server
|
|
3
|
+
*/
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { existsSync } from 'node:fs';
|
|
6
|
+
const DEFAULT_CONFIG = {
|
|
7
|
+
projectRoot: process.cwd(),
|
|
8
|
+
nodeModulesPath: './node_modules',
|
|
9
|
+
cacheDir: './.cache/dep-context',
|
|
10
|
+
extraction: {
|
|
11
|
+
includeReadme: true,
|
|
12
|
+
includeJsDoc: true,
|
|
13
|
+
includeExamples: true,
|
|
14
|
+
maxReadmeLength: 5000,
|
|
15
|
+
maxExamples: 10
|
|
16
|
+
},
|
|
17
|
+
vector: {
|
|
18
|
+
enabled: false,
|
|
19
|
+
embedding: {
|
|
20
|
+
provider: 'ollama',
|
|
21
|
+
ollama: {
|
|
22
|
+
baseUrl: 'http://localhost:11434',
|
|
23
|
+
model: 'nomic-embed-text'
|
|
24
|
+
},
|
|
25
|
+
openai: {
|
|
26
|
+
model: 'text-embedding-3-small'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
storage: {
|
|
30
|
+
type: 'auto',
|
|
31
|
+
chromaHost: 'http://localhost:8000',
|
|
32
|
+
localPath: './.cache/dep-context/vectors'
|
|
33
|
+
},
|
|
34
|
+
indexConcurrency: 4
|
|
35
|
+
},
|
|
36
|
+
gitlab: {
|
|
37
|
+
enabled: false,
|
|
38
|
+
baseUrl: '',
|
|
39
|
+
token: ''
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export class ConfigValidationError extends Error {
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = 'ConfigValidationError';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validates a partial config object and returns a complete config with defaults applied
|
|
50
|
+
*/
|
|
51
|
+
export function validateConfig(partial) {
|
|
52
|
+
const config = {
|
|
53
|
+
...DEFAULT_CONFIG,
|
|
54
|
+
...partial,
|
|
55
|
+
extraction: {
|
|
56
|
+
...DEFAULT_CONFIG.extraction,
|
|
57
|
+
...partial.extraction
|
|
58
|
+
},
|
|
59
|
+
vector: {
|
|
60
|
+
...DEFAULT_CONFIG.vector,
|
|
61
|
+
...partial.vector,
|
|
62
|
+
embedding: {
|
|
63
|
+
...DEFAULT_CONFIG.vector.embedding,
|
|
64
|
+
...(partial.vector?.embedding || {}),
|
|
65
|
+
ollama: {
|
|
66
|
+
...DEFAULT_CONFIG.vector.embedding.ollama,
|
|
67
|
+
...(partial.vector?.embedding?.ollama || {})
|
|
68
|
+
},
|
|
69
|
+
openai: {
|
|
70
|
+
...DEFAULT_CONFIG.vector.embedding.openai,
|
|
71
|
+
...(partial.vector?.embedding?.openai || {})
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
storage: {
|
|
75
|
+
...DEFAULT_CONFIG.vector.storage,
|
|
76
|
+
...(partial.vector?.storage || {})
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
gitlab: {
|
|
80
|
+
...DEFAULT_CONFIG.gitlab,
|
|
81
|
+
...partial.gitlab
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// Expand environment variables in API key
|
|
85
|
+
if (config.vector.embedding.openai?.apiKey?.startsWith('${') && config.vector.embedding.openai.apiKey.endsWith('}')) {
|
|
86
|
+
const envVar = config.vector.embedding.openai.apiKey.slice(2, -1);
|
|
87
|
+
config.vector.embedding.openai.apiKey = process.env[envVar] || '';
|
|
88
|
+
}
|
|
89
|
+
// Validate projectRoot
|
|
90
|
+
if (typeof config.projectRoot !== 'string' || config.projectRoot.length === 0) {
|
|
91
|
+
throw new ConfigValidationError('projectRoot must be a non-empty string');
|
|
92
|
+
}
|
|
93
|
+
// Validate nodeModulesPath
|
|
94
|
+
if (typeof config.nodeModulesPath !== 'string' || config.nodeModulesPath.length === 0) {
|
|
95
|
+
throw new ConfigValidationError('nodeModulesPath must be a non-empty string');
|
|
96
|
+
}
|
|
97
|
+
// Validate cacheDir
|
|
98
|
+
if (typeof config.cacheDir !== 'string' || config.cacheDir.length === 0) {
|
|
99
|
+
throw new ConfigValidationError('cacheDir must be a non-empty string');
|
|
100
|
+
}
|
|
101
|
+
// Validate extraction config
|
|
102
|
+
if (typeof config.extraction.includeReadme !== 'boolean') {
|
|
103
|
+
throw new ConfigValidationError('extraction.includeReadme must be a boolean');
|
|
104
|
+
}
|
|
105
|
+
if (typeof config.extraction.includeJsDoc !== 'boolean') {
|
|
106
|
+
throw new ConfigValidationError('extraction.includeJsDoc must be a boolean');
|
|
107
|
+
}
|
|
108
|
+
if (typeof config.extraction.includeExamples !== 'boolean') {
|
|
109
|
+
throw new ConfigValidationError('extraction.includeExamples must be a boolean');
|
|
110
|
+
}
|
|
111
|
+
if (typeof config.extraction.maxReadmeLength !== 'number' || config.extraction.maxReadmeLength < 0) {
|
|
112
|
+
throw new ConfigValidationError('extraction.maxReadmeLength must be a non-negative number');
|
|
113
|
+
}
|
|
114
|
+
if (typeof config.extraction.maxExamples !== 'number' || config.extraction.maxExamples < 0) {
|
|
115
|
+
throw new ConfigValidationError('extraction.maxExamples must be a non-negative number');
|
|
116
|
+
}
|
|
117
|
+
// Validate vector config
|
|
118
|
+
if (typeof config.vector.enabled !== 'boolean') {
|
|
119
|
+
throw new ConfigValidationError('vector.enabled must be a boolean');
|
|
120
|
+
}
|
|
121
|
+
if (config.vector.embedding.provider !== 'openai' && config.vector.embedding.provider !== 'ollama') {
|
|
122
|
+
throw new ConfigValidationError('vector.embedding.provider must be "openai" or "ollama"');
|
|
123
|
+
}
|
|
124
|
+
if (typeof config.vector.indexConcurrency !== 'number' || config.vector.indexConcurrency < 1) {
|
|
125
|
+
throw new ConfigValidationError('vector.indexConcurrency must be a positive number');
|
|
126
|
+
}
|
|
127
|
+
const validStorageTypes = ['auto', 'chroma', 'file', 'none'];
|
|
128
|
+
if (!validStorageTypes.includes(config.vector.storage.type)) {
|
|
129
|
+
throw new ConfigValidationError('vector.storage.type must be one of: auto, chroma, file, none');
|
|
130
|
+
}
|
|
131
|
+
// Validate gitlab config
|
|
132
|
+
if (typeof config.gitlab.enabled !== 'boolean') {
|
|
133
|
+
throw new ConfigValidationError('gitlab.enabled must be a boolean');
|
|
134
|
+
}
|
|
135
|
+
if (config.gitlab.enabled) {
|
|
136
|
+
if (typeof config.gitlab.baseUrl !== 'string' || config.gitlab.baseUrl.length === 0) {
|
|
137
|
+
throw new ConfigValidationError('gitlab.baseUrl must be a non-empty string when gitlab is enabled');
|
|
138
|
+
}
|
|
139
|
+
if (typeof config.gitlab.token !== 'string' || config.gitlab.token.length === 0) {
|
|
140
|
+
throw new ConfigValidationError('gitlab.token must be a non-empty string when gitlab is enabled');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return config;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Loads configuration from file or environment, applying defaults
|
|
147
|
+
*/
|
|
148
|
+
export async function loadConfig(configPath) {
|
|
149
|
+
// Check for config path from environment
|
|
150
|
+
const envConfigPath = process.env['DEPCONTEXT_CONFIG'];
|
|
151
|
+
// Try multiple config file names
|
|
152
|
+
let resolvedPath = configPath ?? envConfigPath;
|
|
153
|
+
if (!resolvedPath) {
|
|
154
|
+
if (existsSync('dep-context.config.json')) {
|
|
155
|
+
resolvedPath = 'dep-context.config.json';
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
resolvedPath = 'config.json';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let fileConfig = {};
|
|
162
|
+
if (existsSync(resolvedPath)) {
|
|
163
|
+
try {
|
|
164
|
+
const content = await readFile(resolvedPath, 'utf-8');
|
|
165
|
+
fileConfig = JSON.parse(content);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (error instanceof SyntaxError) {
|
|
169
|
+
throw new ConfigValidationError(`Invalid JSON in config file: ${resolvedPath}`);
|
|
170
|
+
}
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// Apply environment variable overrides
|
|
175
|
+
if (process.env['DEPCONTEXT_CACHE_DIR']) {
|
|
176
|
+
fileConfig.cacheDir = process.env['DEPCONTEXT_CACHE_DIR'];
|
|
177
|
+
}
|
|
178
|
+
// GitLab token from environment
|
|
179
|
+
if (process.env['GITLAB_TOKEN'] && fileConfig.gitlab) {
|
|
180
|
+
fileConfig.gitlab = {
|
|
181
|
+
...fileConfig.gitlab,
|
|
182
|
+
token: process.env['GITLAB_TOKEN']
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return validateConfig(fileConfig);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns the default configuration
|
|
189
|
+
*/
|
|
190
|
+
export function getDefaultConfig() {
|
|
191
|
+
return { ...DEFAULT_CONFIG };
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAmDpC,MAAM,cAAc,GAAW;IAC7B,WAAW,EAAE,OAAO,CAAC,GAAG,EAAE;IAC1B,eAAe,EAAE,gBAAgB;IACjC,QAAQ,EAAE,sBAAsB;IAChC,UAAU,EAAE;QACV,aAAa,EAAE,IAAI;QACnB,YAAY,EAAE,IAAI;QAClB,eAAe,EAAE,IAAI;QACrB,eAAe,EAAE,IAAI;QACrB,WAAW,EAAE,EAAE;KAChB;IACD,MAAM,EAAE;QACN,OAAO,EAAE,KA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B;IAC9B,OAAO,EAAE,GAAG,cAAc,EAAE,CAAA;AAC9B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example extractor - extracts and associates code examples from README files
|
|
3
|
+
*/
|
|
4
|
+
export interface CodeExample {
|
|
5
|
+
code: string;
|
|
6
|
+
language: string;
|
|
7
|
+
context: string;
|
|
8
|
+
associatedExports: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Extracts code examples from markdown content with language and context
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractExamples(markdown: string): CodeExample[];
|
|
14
|
+
/**
|
|
15
|
+
* Associates code examples with known export names
|
|
16
|
+
*/
|
|
17
|
+
export declare function associateExamples(examples: CodeExample[], exportNames: string[]): CodeExample[];
|
|
18
|
+
/**
|
|
19
|
+
* Filters examples to only those with associations, limited by count
|
|
20
|
+
*/
|
|
21
|
+
export declare function filterRelevantExamples(examples: CodeExample[], maxExamples?: number): CodeExample[];
|
|
22
|
+
//# sourceMappingURL=examples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../../src/extraction/examples.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAC5B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,EAAE,CA2B/D;AA8BD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,WAAW,EAAE,EACvB,WAAW,EAAE,MAAM,EAAE,GACpB,WAAW,EAAE,CAqCf;AASD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,WAAW,EAAE,EACvB,WAAW,GAAE,MAAW,GACvB,WAAW,EAAE,CAOf"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example extractor - extracts and associates code examples from README files
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Extracts code examples from markdown content with language and context
|
|
6
|
+
*/
|
|
7
|
+
export function extractExamples(markdown) {
|
|
8
|
+
const examples = [];
|
|
9
|
+
// Match fenced code blocks with js/ts language tags only
|
|
10
|
+
const codeBlockRegex = /```(typescript|javascript|ts|js|tsx|jsx)\n([\s\S]*?)```/gi;
|
|
11
|
+
let match;
|
|
12
|
+
while ((match = codeBlockRegex.exec(markdown)) !== null) {
|
|
13
|
+
const language = (match[1] || 'javascript').toLowerCase();
|
|
14
|
+
const code = match[2].trim();
|
|
15
|
+
// Skip empty or very short blocks
|
|
16
|
+
if (code.length < 10)
|
|
17
|
+
continue;
|
|
18
|
+
// Get context: up to 200 chars before the code block
|
|
19
|
+
const beforeBlock = markdown.slice(Math.max(0, match.index - 300), match.index);
|
|
20
|
+
const context = extractContext(beforeBlock);
|
|
21
|
+
examples.push({
|
|
22
|
+
code,
|
|
23
|
+
language: normaliseLanguage(language),
|
|
24
|
+
context,
|
|
25
|
+
associatedExports: [] // Filled in later
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return examples;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extracts the last paragraph before a code block as context
|
|
32
|
+
*/
|
|
33
|
+
function extractContext(text) {
|
|
34
|
+
// Split by double newlines and get the last non-empty paragraph
|
|
35
|
+
const paragraphs = text.split(/\n\n+/).filter(p => p.trim());
|
|
36
|
+
if (paragraphs.length === 0)
|
|
37
|
+
return '';
|
|
38
|
+
const lastPara = paragraphs[paragraphs.length - 1].trim();
|
|
39
|
+
// Clean up markdown formatting
|
|
40
|
+
return lastPara
|
|
41
|
+
.replace(/^#+\s*/, '') // Remove heading markers
|
|
42
|
+
.replace(/\*\*/g, '') // Remove bold
|
|
43
|
+
.replace(/\*/g, '') // Remove italic
|
|
44
|
+
.slice(0, 200); // Limit length
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Normalises language tags
|
|
48
|
+
*/
|
|
49
|
+
function normaliseLanguage(lang) {
|
|
50
|
+
const normalised = lang.toLowerCase();
|
|
51
|
+
if (normalised === 'ts' || normalised === 'tsx')
|
|
52
|
+
return 'typescript';
|
|
53
|
+
if (normalised === 'js' || normalised === 'jsx')
|
|
54
|
+
return 'javascript';
|
|
55
|
+
return normalised;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Associates code examples with known export names
|
|
59
|
+
*/
|
|
60
|
+
export function associateExamples(examples, exportNames) {
|
|
61
|
+
// Create a set for fast lookup
|
|
62
|
+
const exports = new Set(exportNames);
|
|
63
|
+
// Build regex patterns for common usage patterns
|
|
64
|
+
// e.g., functionName(, ClassName., import { name }
|
|
65
|
+
return examples.map(example => {
|
|
66
|
+
const associated = [];
|
|
67
|
+
for (const name of exports) {
|
|
68
|
+
// Skip very short names to avoid false positives
|
|
69
|
+
if (name.length < 2)
|
|
70
|
+
continue;
|
|
71
|
+
// Check for common usage patterns
|
|
72
|
+
const patterns = [
|
|
73
|
+
new RegExp(`\\b${escapeRegex(name)}\\s*\\(`, 'g'), // function call: name(
|
|
74
|
+
new RegExp(`\\b${escapeRegex(name)}\\.`, 'g'), // method access: name.
|
|
75
|
+
new RegExp(`new\\s+${escapeRegex(name)}`, 'g'), // constructor: new Name
|
|
76
|
+
new RegExp(`:\\s*${escapeRegex(name)}\\b`, 'g'), // type annotation: : Name
|
|
77
|
+
new RegExp(`<${escapeRegex(name)}[\\s>]`, 'g'), // generic: <Name>
|
|
78
|
+
new RegExp(`import.*\\b${escapeRegex(name)}\\b`, 'g'), // import: import { name }
|
|
79
|
+
];
|
|
80
|
+
for (const pattern of patterns) {
|
|
81
|
+
if (pattern.test(example.code)) {
|
|
82
|
+
associated.push(name);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
...example,
|
|
89
|
+
associatedExports: [...new Set(associated)] // Dedupe
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Escapes special regex characters
|
|
95
|
+
*/
|
|
96
|
+
function escapeRegex(str) {
|
|
97
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Filters examples to only those with associations, limited by count
|
|
101
|
+
*/
|
|
102
|
+
export function filterRelevantExamples(examples, maxExamples = 10) {
|
|
103
|
+
// Prioritise examples with more associations
|
|
104
|
+
const withAssociations = examples
|
|
105
|
+
.filter(e => e.associatedExports.length > 0)
|
|
106
|
+
.sort((a, b) => b.associatedExports.length - a.associatedExports.length);
|
|
107
|
+
return withAssociations.slice(0, maxExamples);
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=examples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples.js","sourceRoot":"","sources":["../../src/extraction/examples.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,QAAQ,GAAkB,EAAE,CAAA;IAElC,yDAAyD;IACzD,MAAM,cAAc,GAAG,2DAA2D,CAAA;IAElF,IAAI,KAAK,CAAA;IACT,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACxD,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,WAAW,EAAE,CAAA;QACzD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAE5B,kCAAkC;QAClC,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE;YAAE,SAAQ;QAE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AAC,IAAI,CAAC,EAAE,CAAC;oBAC/B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oBACrB,MAAK;gBACP,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO;YACL,GAAG,OAAO;YACV,iBAAiB,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAE,SAAS;SACvD,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAAuB,EACvB,cAAsB,EAAE;IAExB,6CAA6C;IAC7C,MAAM,gBAAgB,GAAG,QAAQ;SAC9B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;IAE1E,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAA;AAC/C,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External Package Resolver - Resolves type definitions from external packages
|
|
3
|
+
*
|
|
4
|
+
* When a package re-exports from external dependencies (e.g., vitest re-exports from @vitest/runner),
|
|
5
|
+
* this resolver finds the type definitions in those external packages.
|
|
6
|
+
*/
|
|
7
|
+
import { type PackageMetadata } from '../resolver/package.js';
|
|
8
|
+
export interface ExternalResolverResult {
|
|
9
|
+
success: boolean;
|
|
10
|
+
typesPath: string | undefined;
|
|
11
|
+
metadata: PackageMetadata | undefined;
|
|
12
|
+
error: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface ExternalPackageResolver {
|
|
15
|
+
resolve(packageName: string): Promise<ExternalResolverResult>;
|
|
16
|
+
clearCache(): void;
|
|
17
|
+
getCacheStats(): {
|
|
18
|
+
resolved: number;
|
|
19
|
+
failed: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates an ExternalPackageResolver with caching
|
|
24
|
+
*/
|
|
25
|
+
export declare function createExternalPackageResolver(projectRoot: string): ExternalPackageResolver;
|
|
26
|
+
//# sourceMappingURL=external-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-resolver.d.ts","sourceRoot":"","sources":["../../src/extraction/external-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAEpF,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,EAAE,eAAe,GAAG,SAAS,CAAA;IACrC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAA;IAC7D,UAAU,IAAI,IAAI,CAAA;IAClB,aAAa,IAAI;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CACtD;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,WAAW,EAAE,MAAM,GAAG,uBAAuB,CA6E1F"}
|