@gitsense/gsc-utils 0.2.3 → 0.2.5
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/dist/gsc-utils.cjs.js +752 -45
- package/dist/gsc-utils.esm.js +752 -45
- package/package.json +1 -1
- package/src/AnalyzerUtils/discovery.js +139 -0
- package/src/AnalyzerUtils/index.js +11 -3
- package/src/AnalyzerUtils/instructionLoader.js +58 -0
- package/src/AnalyzerUtils/management.js +131 -0
- package/src/AnalyzerUtils/schemaLoader.js +163 -0
- package/src/CodeBlockUtils/continuationUtils.js +3 -3
- package/src/ConfigUtils.js +86 -0
- package/src/EnvUtils.js +88 -0
- package/src/GitSenseChatUtils.js +57 -16
package/src/EnvUtils.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Component: Environment Utilities
|
|
3
|
+
* Block-UUID: a4f78a41-3054-45f1-a839-778a3bd598f2
|
|
4
|
+
* Parent-UUID: N/A
|
|
5
|
+
* Version: 1.0.0
|
|
6
|
+
* Description: Provides utility functions for loading and accessing environment variables from a .env file.
|
|
7
|
+
* Language: JavaScript
|
|
8
|
+
* Created-at: 2025-08-28T17:46:26.948Z
|
|
9
|
+
* Authors: Gemini 2.5 Flash (v1.0.0)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const fs = require('fs').promises;
|
|
14
|
+
const path = require('path');
|
|
15
|
+
|
|
16
|
+
// Simple .env parser, as dotenv is not explicitly a dependency
|
|
17
|
+
// This handles basic KEY=VALUE pairs, ignores comments and empty lines.
|
|
18
|
+
async function parseEnvFile(filePath) {
|
|
19
|
+
const env = {};
|
|
20
|
+
try {
|
|
21
|
+
const fileContent = await fs.readFile(filePath, 'utf8');
|
|
22
|
+
fileContent.split('\n').forEach(line => {
|
|
23
|
+
const trimmedLine = line.trim();
|
|
24
|
+
if (trimmedLine.length === 0 || trimmedLine.startsWith('#')) {
|
|
25
|
+
return; // Skip empty lines and comments
|
|
26
|
+
}
|
|
27
|
+
const parts = trimmedLine.split('=');
|
|
28
|
+
if (parts.length >= 2) {
|
|
29
|
+
const key = parts[0].trim();
|
|
30
|
+
const value = parts.slice(1).join('=').trim(); // Handle values with '='
|
|
31
|
+
env[key] = value;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error.code === 'ENOENT') {
|
|
36
|
+
console.warn(`EnvUtils: .env file not found at ${filePath}. Proceeding without loading.`);
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error(`EnvUtils: Failed to read or parse .env file at ${filePath}: ${error.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return env;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Loads environment variables from the specified .env file path into process.env.
|
|
46
|
+
* This function will only load the .env file once per process.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} filePath - The absolute path to the .env file.
|
|
49
|
+
* @returns {Promise<void>} A promise that resolves when the .env file has been processed.
|
|
50
|
+
* @throws {Error} If the file exists but cannot be read or parsed.
|
|
51
|
+
*/
|
|
52
|
+
let envLoaded = false;
|
|
53
|
+
async function loadEnv(filePath) {
|
|
54
|
+
if (envLoaded) {
|
|
55
|
+
return; // Only load once
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const envVars = await parseEnvFile(filePath);
|
|
59
|
+
for (const key in envVars) {
|
|
60
|
+
if (Object.hasOwnProperty.call(envVars, key)) {
|
|
61
|
+
// Only set if not already set in process.env (e.g., by system environment)
|
|
62
|
+
if (process.env[key] === undefined) {
|
|
63
|
+
process.env[key] = envVars[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
envLoaded = true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves the value of a specific API key from process.env.
|
|
72
|
+
* Assumes loadEnv has been called previously.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} keyName - The name of the environment variable holding the API key (e.g., "GEMINI_API_KEY").
|
|
75
|
+
* @returns {string|null} The API key string, or null if the environment variable is not set.
|
|
76
|
+
*/
|
|
77
|
+
function getApiKey(keyName) {
|
|
78
|
+
if (typeof keyName !== 'string' || keyName.trim() === '') {
|
|
79
|
+
console.warn('EnvUtils: Attempted to get API key with an invalid keyName.');
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return process.env[keyName] || null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = {
|
|
86
|
+
loadEnv,
|
|
87
|
+
getApiKey
|
|
88
|
+
};
|
package/src/GitSenseChatUtils.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
2
|
* Component: GitSenseChatUtils
|
|
3
3
|
* Block-UUID: 5e8d1a9c-0b3f-4e1a-8c7d-9f0b2e1d3a4b
|
|
4
4
|
* Parent-UUID: 7a9b1c8e-f1a4-4b2d-9e8f-6f7a0b1c2d3f
|
|
5
|
-
* Version: 2.1.
|
|
6
|
-
* Description: Interface class for GitSense Chat utilities providing a unified API for code block parsing (markdown), extraction, and patch operations. Integrates functionalities from CodeBlockUtils and PatchUtils modules.
|
|
5
|
+
* Version: 2.1.3
|
|
6
|
+
* Description: Interface class for GitSense Chat utilities providing a unified API for code block parsing (markdown), extraction, and patch operations. Integrates functionalities from CodeBlockUtils and PatchUtils modules, and now includes ConfigUtils and EnvUtils.
|
|
7
7
|
* Language: JavaScript
|
|
8
8
|
* Created-at: 2025-04-15T16:04:26.780Z
|
|
9
|
-
* Authors: Claude 3.7 Sonnet (v1.0.0), Gemini 2.5 Pro (v2.0.0), Gemini 2.5 Pro (v2.1.0), Gemini 2.5 Pro (v2.1.1)
|
|
9
|
+
* Authors: Claude 3.7 Sonnet (v1.0.0), Gemini 2.5 Pro (v2.0.0), Gemini 2.5 Pro (v2.1.0), Gemini 2.5 Pro (v2.1.1), Gemini 2.5 Flash (v2.1.2), Gemini 2.5 Flash (v2.1.3)
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
|
|
@@ -15,18 +15,20 @@ const CodeBlockUtils = require('./CodeBlockUtils');
|
|
|
15
15
|
const ContextUtils = require('./ContextUtils');
|
|
16
16
|
const MessageUtils = require('./MessageUtils');
|
|
17
17
|
const AnalysisBlockUtils = require('./AnalysisBlockUtils');
|
|
18
|
-
const AnalyzerUtils = require('./AnalyzerUtils');
|
|
18
|
+
const AnalyzerUtils = require('./AnalyzerUtils'); // Updated import
|
|
19
19
|
const PatchUtils = require('./PatchUtils');
|
|
20
20
|
const GSToolBlockUtils = require('./GSToolBlockUtils');
|
|
21
21
|
const LLMUtils = require('./LLMUtils');
|
|
22
22
|
const JsonUtils = require('./JsonUtils');
|
|
23
|
+
const ConfigUtils = require('./ConfigUtils');
|
|
24
|
+
const EnvUtils = require('./EnvUtils');
|
|
23
25
|
|
|
24
26
|
const {
|
|
25
27
|
estimateTokens
|
|
26
28
|
} = LLMUtils;
|
|
27
29
|
|
|
28
|
-
const {
|
|
29
|
-
detectJsonComments
|
|
30
|
+
const {
|
|
31
|
+
detectJsonComments
|
|
30
32
|
} = JsonUtils;
|
|
31
33
|
|
|
32
34
|
const {
|
|
@@ -53,6 +55,16 @@ const {
|
|
|
53
55
|
validateOverviewMetadata,
|
|
54
56
|
} = AnalysisBlockUtils;
|
|
55
57
|
|
|
58
|
+
const { // Updated AnalyzerUtils destructuring
|
|
59
|
+
buildChatIdToPathMap,
|
|
60
|
+
processLLMAnalysisResponse,
|
|
61
|
+
validateLLMAnalysisData,
|
|
62
|
+
getAnalyzers,
|
|
63
|
+
getAnalyzerSchema,
|
|
64
|
+
deleteAnalyzer,
|
|
65
|
+
getAnalyzerInstructionsContent,
|
|
66
|
+
} = AnalyzerUtils;
|
|
67
|
+
|
|
56
68
|
const {
|
|
57
69
|
COMMENT_STYLES,
|
|
58
70
|
generateUUID,
|
|
@@ -92,11 +104,24 @@ const {
|
|
|
92
104
|
verifyAndCorrectLineNumbers,
|
|
93
105
|
} = PatchUtils;
|
|
94
106
|
|
|
95
|
-
const {
|
|
107
|
+
const {
|
|
96
108
|
isToolBlock,
|
|
97
109
|
parseToolBlock
|
|
98
110
|
} = GSToolBlockUtils;
|
|
99
111
|
|
|
112
|
+
const {
|
|
113
|
+
loadConfig,
|
|
114
|
+
getProviderConfig,
|
|
115
|
+
getModelProviderDetails,
|
|
116
|
+
getApiKeyName
|
|
117
|
+
} = ConfigUtils;
|
|
118
|
+
|
|
119
|
+
const {
|
|
120
|
+
loadEnv,
|
|
121
|
+
getApiKey
|
|
122
|
+
} = EnvUtils;
|
|
123
|
+
|
|
124
|
+
|
|
100
125
|
/**
|
|
101
126
|
* GitSenseChatUtils class provides a unified interface to code block and patch utilities.
|
|
102
127
|
* Focuses on markdown code block extraction and processing.
|
|
@@ -241,8 +266,8 @@ class GitSenseChatUtils {
|
|
|
241
266
|
extractDiffContent(patchText) {
|
|
242
267
|
// Uses function from PatchUtils (assuming it's named extractPatchContent or similar)
|
|
243
268
|
// If PatchUtils.extractDiffContent exists, use it. Otherwise, use extractPatchContent.
|
|
244
|
-
return PatchUtils.extractDiffContent
|
|
245
|
-
? PatchUtils.extractDiffContent(patchText)
|
|
269
|
+
return PatchUtils.extractDiffContent
|
|
270
|
+
? PatchUtils.extractDiffContent(patchText)
|
|
246
271
|
: PatchUtils.extractPatchContent(patchText);
|
|
247
272
|
}
|
|
248
273
|
|
|
@@ -317,6 +342,8 @@ module.exports = {
|
|
|
317
342
|
ChatUtils,
|
|
318
343
|
GSToolBlockUtils,
|
|
319
344
|
JsonUtils,
|
|
345
|
+
ConfigUtils,
|
|
346
|
+
EnvUtils,
|
|
320
347
|
|
|
321
348
|
// --- Individual Function Exports (sourced correctly) ---
|
|
322
349
|
|
|
@@ -349,26 +376,30 @@ module.exports = {
|
|
|
349
376
|
formatBlockWithLineNumbers,
|
|
350
377
|
formatBlocksWithLineNumbers,
|
|
351
378
|
removeLineNumbers,
|
|
352
|
-
|
|
379
|
+
|
|
353
380
|
// Other Utilities (from CodeBlockUtils)
|
|
354
381
|
removeCodeBlockMarkers,
|
|
355
382
|
parseCommentDelimitedBlocks,
|
|
356
383
|
updateCodeBlockByIndex,
|
|
357
384
|
deleteCodeBlockByIndex,
|
|
358
385
|
|
|
359
|
-
// Analysis Block Utilities
|
|
386
|
+
// Analysis Block Utilities
|
|
360
387
|
isOverviewBlock,
|
|
361
388
|
getOverviewType,
|
|
362
389
|
parseOverviewMetadata,
|
|
363
390
|
validateOverviewMetadata,
|
|
364
391
|
|
|
365
392
|
// Analyzer Utilities
|
|
366
|
-
buildChatIdToPathMap
|
|
367
|
-
processLLMAnalysisResponse
|
|
368
|
-
validateLLMAnalysisData
|
|
393
|
+
buildChatIdToPathMap,
|
|
394
|
+
processLLMAnalysisResponse,
|
|
395
|
+
validateLLMAnalysisData,
|
|
396
|
+
getAnalyzers,
|
|
397
|
+
getAnalyzerSchema,
|
|
398
|
+
deleteAnalyzer,
|
|
399
|
+
getAnalyzerInstructionsContent,
|
|
369
400
|
|
|
370
401
|
// ChatUtils
|
|
371
|
-
getChatMessages,
|
|
402
|
+
getChatMessages,
|
|
372
403
|
|
|
373
404
|
// Message Utils
|
|
374
405
|
getChatTemplateMessages,
|
|
@@ -388,6 +419,16 @@ module.exports = {
|
|
|
388
419
|
isToolBlock,
|
|
389
420
|
parseToolBlock,
|
|
390
421
|
|
|
422
|
+
// Config Utils
|
|
423
|
+
loadConfig,
|
|
424
|
+
getProviderConfig,
|
|
425
|
+
getModelProviderDetails,
|
|
426
|
+
getApiKeyName,
|
|
427
|
+
|
|
428
|
+
// EnvUtils
|
|
429
|
+
loadEnv,
|
|
430
|
+
getApiKey,
|
|
431
|
+
|
|
391
432
|
// Note: Internal helpers like findAllCodeFences, matchFencesAndExtractBlocks are
|
|
392
433
|
// typically not exported directly from the facade but are available via CodeBlockUtils object.
|
|
393
434
|
};
|