@gitsense/gsc-utils 0.2.24 → 0.2.27
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 -62
- package/dist/gsc-utils.cjs.js +14270 -523
- package/dist/gsc-utils.esm.js +14270 -523
- package/package.json +1 -1
- package/src/AnalyzerUtils/cloner.js +149 -0
- package/src/AnalyzerUtils/constants.js +1 -1
- package/src/AnalyzerUtils/defaultPromptLoader.js +10 -10
- package/src/AnalyzerUtils/discovery.js +48 -39
- package/src/AnalyzerUtils/index.js +13 -7
- package/src/AnalyzerUtils/instructionLoader.js +6 -6
- package/src/AnalyzerUtils/jsonParser.js +35 -0
- package/src/AnalyzerUtils/management.js +6 -6
- package/src/AnalyzerUtils/saver.js +5 -5
- package/src/AnalyzerUtils/schemaLoader.js +194 -26
- package/src/AnalyzerUtils/updater.js +187 -0
- package/src/CodeBlockUtils/blockProcessor.js +14 -32
- package/src/CodeBlockUtils/constants.js +8 -4
- package/src/CodeBlockUtils/headerUtils.js +19 -3
- package/src/CodeBlockUtils/index.js +7 -6
- package/src/CodeBlockUtils/lineageTracer.js +95 -0
- package/src/CompactChatUtils/CompactedMessageUtils.js +224 -0
- package/src/CompactChatUtils/README.md +321 -0
- package/src/CompactChatUtils/ReferenceMessageUtils.js +143 -0
- package/src/CompactChatUtils/index.js +40 -0
- package/src/ContextUtils.js +41 -5
- package/src/DomUtils.js +559 -0
- package/src/GSToolBlockUtils.js +66 -1
- package/src/GitSenseChatUtils.js +108 -16
- package/src/LanguageNameUtils.js +171 -0
- package/src/MarkdownUtils.js +127 -0
- package/src/MessageUtils.js +1 -1
- package/src/MetaRawResultUtils.js +244 -0
- package/src/ObjectUtils.js +54 -0
- package/src/PatchUtils/constants.js +9 -3
- package/src/PatchUtils/patchParser.js +60 -37
- package/src/PatchUtils/patchProcessor.js +8 -5
- package/src/PatchUtils/patchVerifier/detectAndFixOverlappingHunks.js +1 -1
- package/src/SVGUtils.js +1467 -0
- package/src/SharedUtils/stringUtils.js +303 -0
- package/src/CodeBlockUtils/blockProcessor.js.rej +0 -8
package/src/GitSenseChatUtils.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Component: GitSenseChatUtils
|
|
3
|
-
* Block-UUID:
|
|
4
|
-
* Parent-UUID:
|
|
5
|
-
* Version: 2.
|
|
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
|
|
3
|
+
* Block-UUID: c1b6c4d3-7959-4eb6-8022-6cd7aa59240d
|
|
4
|
+
* Parent-UUID: 1793b3a8-4881-4306-bfdf-673eef503679
|
|
5
|
+
* Version: 2.7.0
|
|
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, EnvUtils, ObjectUtils, MetaRawResultUtils, and CompactChatUtils.
|
|
7
7
|
* Language: JavaScript
|
|
8
|
-
* Created-at: 2025-
|
|
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), Gemini 2.5 Flash (v2.1.4), Qwen 3 Coder 480B - Cerebras (v2.1.5)
|
|
8
|
+
* Created-at: 2025-10-17T17:13:04.663Z
|
|
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), Gemini 2.5 Flash (v2.1.4), Qwen 3 Coder 480B - Cerebras (v2.1.5), Qwen 3 Coder 480B - Cerebras (v2.2.0), Qwen 3 Coder 480B - Cerebras (v2.2.1), Claude Haiku 4.5 (v2.3.0), Qwen 3 Coder 480B - Cerebras (v2.4.0), Qwen 3 Coder 480B - Cerebras (v2.5.0), GLM-4.6 (v2.6.0), GLM-4.6 (v2.7.0)
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
|
|
@@ -22,8 +22,21 @@ const LLMUtils = require('./LLMUtils');
|
|
|
22
22
|
const JsonUtils = require('./JsonUtils');
|
|
23
23
|
const DateUtils = require('./DateUtils');
|
|
24
24
|
const FormatterUtils = require('./FormatterUtils');
|
|
25
|
+
const MarkdownUtils = require('./MarkdownUtils');
|
|
25
26
|
const ConfigUtils = require('./ConfigUtils');
|
|
26
27
|
const EnvUtils = require('./EnvUtils');
|
|
28
|
+
const DomUtils = require('./DomUtils');
|
|
29
|
+
const ObjectUtils = require('./ObjectUtils');
|
|
30
|
+
const SVGUtils = require('./SVGUtils');
|
|
31
|
+
const StringUtils = require('./SharedUtils/stringUtils');
|
|
32
|
+
const LanguageNameUtils = require('./LanguageNameUtils');
|
|
33
|
+
const MetaRawResultUtils = require('./MetaRawResultUtils');
|
|
34
|
+
const CompactChatUtils = require('./CompactChatUtils');
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
normalizeLanguageName,
|
|
38
|
+
isKnownLanguage,
|
|
39
|
+
} = LanguageNameUtils;
|
|
27
40
|
|
|
28
41
|
const {
|
|
29
42
|
formatAge,
|
|
@@ -31,15 +44,15 @@ const {
|
|
|
31
44
|
compareDates,
|
|
32
45
|
normalizeDateTime,
|
|
33
46
|
getTimeDifference,
|
|
34
|
-
formatTimeDifference
|
|
47
|
+
formatTimeDifference,
|
|
35
48
|
} = DateUtils;
|
|
36
49
|
|
|
37
50
|
const {
|
|
38
|
-
estimateTokens
|
|
51
|
+
estimateTokens,
|
|
39
52
|
} = LLMUtils;
|
|
40
53
|
|
|
41
54
|
const {
|
|
42
|
-
detectJsonComments
|
|
55
|
+
detectJsonComments,
|
|
43
56
|
} = JsonUtils;
|
|
44
57
|
|
|
45
58
|
const {
|
|
@@ -104,6 +117,7 @@ const {
|
|
|
104
117
|
removeCodeBlockMarkers,
|
|
105
118
|
updateCodeBlockByIndex,
|
|
106
119
|
deleteCodeBlockByIndex,
|
|
120
|
+
getLineage,
|
|
107
121
|
} = CodeBlockUtils;
|
|
108
122
|
|
|
109
123
|
const {
|
|
@@ -140,13 +154,45 @@ const {
|
|
|
140
154
|
formatTokens,
|
|
141
155
|
} = FormatterUtils;
|
|
142
156
|
|
|
157
|
+
const {
|
|
158
|
+
createMarkdownRenderer,
|
|
159
|
+
removeSignature,
|
|
160
|
+
} = MarkdownUtils;
|
|
161
|
+
|
|
143
162
|
const {
|
|
144
163
|
parseContextSection,
|
|
145
164
|
extractContextSections,
|
|
146
165
|
extractContextItemsOverviewTableRows,
|
|
166
|
+
getContextFiles,
|
|
147
167
|
formatContextContent,
|
|
148
168
|
} = ContextUtils;
|
|
149
169
|
|
|
170
|
+
const {
|
|
171
|
+
trimObjectStrings
|
|
172
|
+
} = ObjectUtils;
|
|
173
|
+
|
|
174
|
+
const {
|
|
175
|
+
splitWithLimit,
|
|
176
|
+
capitalize,
|
|
177
|
+
titleCase,
|
|
178
|
+
camelCase,
|
|
179
|
+
kebabCase,
|
|
180
|
+
snakeCase,
|
|
181
|
+
constantCase,
|
|
182
|
+
pascalCase,
|
|
183
|
+
trimWhitespace,
|
|
184
|
+
truncate,
|
|
185
|
+
} = StringUtils;
|
|
186
|
+
|
|
187
|
+
const {
|
|
188
|
+
extractMetaRawResultMappings,
|
|
189
|
+
isMetaRawResultMessage,
|
|
190
|
+
parseMetaRawResultContent,
|
|
191
|
+
parseTableRow,
|
|
192
|
+
parseSize,
|
|
193
|
+
parseTokens
|
|
194
|
+
} = MetaRawResultUtils;
|
|
195
|
+
|
|
150
196
|
|
|
151
197
|
/**
|
|
152
198
|
* GitSenseChatUtils class provides a unified interface to code block and patch utilities.
|
|
@@ -349,17 +395,22 @@ class GitSenseChatUtils {
|
|
|
349
395
|
// Uses function from CodeBlockUtils
|
|
350
396
|
return CodeBlockUtils.isValidISOTimestamp(timestamp);
|
|
351
397
|
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Creates a configured markdown-it renderer instance.
|
|
401
|
+
* @param {Object} hljs - An instance of highlight.js.
|
|
402
|
+
* @param {Object} [hstyle={}] - Optional styles for highlighted code blocks.
|
|
403
|
+
* @param {Object} [nhstyle={}] - Optional styles for non-highlighted code blocks.
|
|
404
|
+
* @returns {Object} A configured markdown-it instance.
|
|
405
|
+
*/
|
|
406
|
+
createMarkdownRenderer(hljs, hstyle, nhstyle) {
|
|
407
|
+
return MarkdownUtils.createMarkdownRenderer(hljs, hstyle, nhstyle);
|
|
408
|
+
}
|
|
352
409
|
}
|
|
353
410
|
|
|
354
411
|
// Export the main class, the aggregated CodeBlockUtils, PatchUtils,
|
|
355
412
|
// and individual functions for backward compatibility or direct use.
|
|
356
413
|
module.exports = {
|
|
357
|
-
// New Utility Modules
|
|
358
|
-
DateUtils,
|
|
359
|
-
FormatterUtils,
|
|
360
|
-
|
|
361
|
-
// Date Utility Functions
|
|
362
|
-
|
|
363
414
|
// Main class
|
|
364
415
|
GitSenseChatUtils,
|
|
365
416
|
|
|
@@ -376,9 +427,18 @@ module.exports = {
|
|
|
376
427
|
JsonUtils,
|
|
377
428
|
ConfigUtils,
|
|
378
429
|
DateUtils,
|
|
430
|
+
LanguageNameUtils,
|
|
379
431
|
FormatterUtils,
|
|
380
|
-
|
|
432
|
+
MarkdownUtils,
|
|
381
433
|
EnvUtils,
|
|
434
|
+
DomUtils,
|
|
435
|
+
ObjectUtils,
|
|
436
|
+
StringUtils,
|
|
437
|
+
SVGUtils,
|
|
438
|
+
MetaRawResultUtils,
|
|
439
|
+
CompactChatUtils,
|
|
440
|
+
ReferenceMessageUtils: CompactChatUtils.ReferenceMessageUtils,
|
|
441
|
+
CompactedMessageUtils: CompactChatUtils.CompactedMessageUtils,
|
|
382
442
|
|
|
383
443
|
// --- Individual Function Exports (sourced correctly) ---
|
|
384
444
|
|
|
@@ -396,6 +456,10 @@ module.exports = {
|
|
|
396
456
|
// Timestamp (from CodeBlockUtils)
|
|
397
457
|
isValidISOTimestamp,
|
|
398
458
|
|
|
459
|
+
// Language Name Utilities (from LanguageNameUtils)
|
|
460
|
+
normalizeLanguageName,
|
|
461
|
+
isKnownLanguage,
|
|
462
|
+
|
|
399
463
|
// Patch Detection/Integration (from CodeBlockUtils)
|
|
400
464
|
containsPatch,
|
|
401
465
|
|
|
@@ -463,6 +527,25 @@ module.exports = {
|
|
|
463
527
|
// Formatter Utils
|
|
464
528
|
formatBytes,
|
|
465
529
|
formatTokens,
|
|
530
|
+
|
|
531
|
+
// Object Utils
|
|
532
|
+
trimObjectStrings,
|
|
533
|
+
|
|
534
|
+
// String Utils
|
|
535
|
+
splitWithLimit,
|
|
536
|
+
capitalize,
|
|
537
|
+
titleCase,
|
|
538
|
+
camelCase,
|
|
539
|
+
kebabCase,
|
|
540
|
+
snakeCase,
|
|
541
|
+
constantCase,
|
|
542
|
+
pascalCase,
|
|
543
|
+
trimWhitespace,
|
|
544
|
+
truncate,
|
|
545
|
+
|
|
546
|
+
// Markdown Utils
|
|
547
|
+
createMarkdownRenderer,
|
|
548
|
+
removeSignature,
|
|
466
549
|
|
|
467
550
|
// GS Tool Block
|
|
468
551
|
isToolBlock,
|
|
@@ -479,8 +562,17 @@ module.exports = {
|
|
|
479
562
|
getApiKey,
|
|
480
563
|
|
|
481
564
|
// Context Utils
|
|
565
|
+
getContextFiles,
|
|
482
566
|
parseContextSection,
|
|
483
567
|
extractContextSections,
|
|
484
568
|
extractContextItemsOverviewTableRows,
|
|
485
569
|
formatContextContent,
|
|
570
|
+
|
|
571
|
+
// MetaRawResult Utils
|
|
572
|
+
extractMetaRawResultMappings,
|
|
573
|
+
isMetaRawResultMessage,
|
|
574
|
+
parseMetaRawResultContent,
|
|
575
|
+
parseTableRow,
|
|
576
|
+
parseSize,
|
|
577
|
+
parseTokens,
|
|
486
578
|
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Component: Language Name Utils
|
|
3
|
+
* Block-UUID: 313abeab-2bb3-49d1-8693-e9e88aa97113
|
|
4
|
+
* Parent-UUID: N/A
|
|
5
|
+
* Version: 1.0.0
|
|
6
|
+
* Description: Utility for converting common lowercase language names and aliases to their proper capitalization
|
|
7
|
+
* Language: JavaScript
|
|
8
|
+
* Created-at: 2025-10-19T23:25:09.231Z
|
|
9
|
+
* Authors: Qwen 3 Coder 480B - Cerebras (v1.0.0)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A mapping of language aliases to their properly capitalized names
|
|
15
|
+
*/
|
|
16
|
+
const LANGUAGE_NAME_MAP = {
|
|
17
|
+
// Core Programming Languages
|
|
18
|
+
'javascript': 'JavaScript',
|
|
19
|
+
'js': 'JavaScript',
|
|
20
|
+
'typescript': 'TypeScript',
|
|
21
|
+
'ts': 'TypeScript',
|
|
22
|
+
'python': 'Python',
|
|
23
|
+
'py': 'Python',
|
|
24
|
+
'java': 'Java',
|
|
25
|
+
'c': 'C',
|
|
26
|
+
'c++': 'C++',
|
|
27
|
+
'cpp': 'C++',
|
|
28
|
+
'c#': 'C#',
|
|
29
|
+
'csharp': 'C#',
|
|
30
|
+
'go': 'Go',
|
|
31
|
+
'rust': 'Rust',
|
|
32
|
+
'rs': 'Rust',
|
|
33
|
+
'swift': 'Swift',
|
|
34
|
+
'kotlin': 'Kotlin',
|
|
35
|
+
'ruby': 'Ruby',
|
|
36
|
+
'rb': 'Ruby',
|
|
37
|
+
'php': 'PHP',
|
|
38
|
+
'perl': 'Perl',
|
|
39
|
+
'scala': 'Scala',
|
|
40
|
+
'r': 'R',
|
|
41
|
+
'matlab': 'MATLAB',
|
|
42
|
+
|
|
43
|
+
// Web Development & Templating
|
|
44
|
+
'html': 'HTML',
|
|
45
|
+
'css': 'CSS',
|
|
46
|
+
'xml': 'XML',
|
|
47
|
+
'json': 'JSON',
|
|
48
|
+
'yaml': 'YAML',
|
|
49
|
+
'yml': 'YAML',
|
|
50
|
+
'markdown': 'Markdown',
|
|
51
|
+
'md': 'Markdown',
|
|
52
|
+
'jsx': 'JSX',
|
|
53
|
+
'tsx': 'TSX',
|
|
54
|
+
'sass': 'Sass',
|
|
55
|
+
'scss': 'SCSS',
|
|
56
|
+
'less': 'Less',
|
|
57
|
+
'vue': 'Vue',
|
|
58
|
+
'svelte': 'Svelte',
|
|
59
|
+
|
|
60
|
+
// Infrastructure & DevOps
|
|
61
|
+
'dockerfile': 'Dockerfile',
|
|
62
|
+
'terraform': 'Terraform',
|
|
63
|
+
'hcl': 'HCL',
|
|
64
|
+
'groovy': 'Groovy',
|
|
65
|
+
'gradle': 'Gradle',
|
|
66
|
+
'cmake': 'CMake',
|
|
67
|
+
'make': 'Make',
|
|
68
|
+
|
|
69
|
+
// Shell/Scripting Languages
|
|
70
|
+
'bash': 'Bash',
|
|
71
|
+
'shell': 'Shell',
|
|
72
|
+
'powershell': 'PowerShell',
|
|
73
|
+
'ps': 'PowerShell',
|
|
74
|
+
|
|
75
|
+
// Database/Query Languages
|
|
76
|
+
'sql': 'SQL',
|
|
77
|
+
'mysql': 'MySQL',
|
|
78
|
+
'postgresql': 'PostgreSQL',
|
|
79
|
+
'postgres': 'PostgreSQL',
|
|
80
|
+
'mongodb': 'MongoDB',
|
|
81
|
+
'redis': 'Redis',
|
|
82
|
+
|
|
83
|
+
// Data & Configuration Formats
|
|
84
|
+
'toml': 'TOML',
|
|
85
|
+
'ini': 'INI',
|
|
86
|
+
'protobuf': 'Protocol Buffers',
|
|
87
|
+
'proto': 'Protocol Buffers',
|
|
88
|
+
'avro': 'Avro',
|
|
89
|
+
|
|
90
|
+
// Documentation & Markup
|
|
91
|
+
'rst': 'reStructuredText',
|
|
92
|
+
'asciidoc': 'AsciiDoc',
|
|
93
|
+
'tex': 'TeX',
|
|
94
|
+
'latex': 'LaTeX',
|
|
95
|
+
|
|
96
|
+
// Specialized & Niche Languages
|
|
97
|
+
'dart': 'Dart',
|
|
98
|
+
'lua': 'Lua',
|
|
99
|
+
'haskell': 'Haskell',
|
|
100
|
+
'elixir': 'Elixir',
|
|
101
|
+
'erlang': 'Erlang',
|
|
102
|
+
'clojure': 'Clojure',
|
|
103
|
+
'f#': 'F#',
|
|
104
|
+
'fortran': 'Fortran',
|
|
105
|
+
'cobol': 'COBOL',
|
|
106
|
+
'pascal': 'Pascal',
|
|
107
|
+
'delphi': 'Delphi',
|
|
108
|
+
'objective-c': 'Objective-C',
|
|
109
|
+
'objc': 'Objective-C',
|
|
110
|
+
'assembly': 'Assembly',
|
|
111
|
+
'asm': 'Assembly',
|
|
112
|
+
'solidity': 'Solidity',
|
|
113
|
+
'julia': 'Julia',
|
|
114
|
+
'zig': 'Zig',
|
|
115
|
+
'ocaml': 'OCaml',
|
|
116
|
+
'gdscript': 'GDScript',
|
|
117
|
+
'lisp': 'Lisp',
|
|
118
|
+
'move': 'Move',
|
|
119
|
+
'cairo': 'Cairo',
|
|
120
|
+
'vyper': 'Vyper',
|
|
121
|
+
|
|
122
|
+
// Legacy & Foundational
|
|
123
|
+
'vb.net': 'VB.NET',
|
|
124
|
+
'vbnet': 'VB.NET'
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Normalizes a language name or alias to its proper capitalization
|
|
129
|
+
* @param {string} language - The language name or alias to normalize
|
|
130
|
+
* @returns {string} The properly capitalized language name, or the original input if not found
|
|
131
|
+
*/
|
|
132
|
+
function normalizeLanguageName(language) {
|
|
133
|
+
if (!language) return language;
|
|
134
|
+
|
|
135
|
+
const lowerLanguage = language.toLowerCase();
|
|
136
|
+
return LANGUAGE_NAME_MAP[lowerLanguage] || language;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Checks if a language name or alias is known to the normalizer
|
|
141
|
+
* @param {string} language - The language name or alias to check
|
|
142
|
+
* @returns {boolean} True if the language is known, false otherwise
|
|
143
|
+
*/
|
|
144
|
+
function isKnownLanguage(language) {
|
|
145
|
+
if (!language) return false;
|
|
146
|
+
|
|
147
|
+
return LANGUAGE_NAME_MAP.hasOwnProperty(language.toLowerCase());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Gets all known language aliases
|
|
152
|
+
* @returns {string[]} Array of all known language aliases
|
|
153
|
+
*/
|
|
154
|
+
function getKnownLanguageAliases() {
|
|
155
|
+
return Object.keys(LANGUAGE_NAME_MAP);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Gets the mapping of language aliases to their normalized names
|
|
160
|
+
* @returns {Object} The language name mapping object
|
|
161
|
+
*/
|
|
162
|
+
function getLanguageNameMap() {
|
|
163
|
+
return { ...LANGUAGE_NAME_MAP };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = {
|
|
167
|
+
normalizeLanguageName,
|
|
168
|
+
isKnownLanguage,
|
|
169
|
+
getKnownLanguageAliases,
|
|
170
|
+
getLanguageNameMap
|
|
171
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Component: Markdown Utilities
|
|
3
|
+
* Block-UUID: 1e1b9db3-c1c6-45a7-80d8-7f7bc093e433
|
|
4
|
+
* Parent-UUID: N/A
|
|
5
|
+
* Version: 1.0.0
|
|
6
|
+
* Description: Provides utilities for configuring and using markdown-it with highlight.js for rendering Markdown content with syntax highlighting. Designed for use within GitSense Chat UI components.
|
|
7
|
+
* Language: JavaScript
|
|
8
|
+
* Created-at: 2025-10-15T23:48:15.318Z
|
|
9
|
+
* Authors: Qwen 3 Coder 480B - Cerebras (v1.0.0)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const { h } = require('./DomUtils');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a configured markdown renderer instance.
|
|
17
|
+
* This renderer integrates markdown-it for Markdown processing and highlight.js for syntax highlighting
|
|
18
|
+
* within code blocks, replicating the style used in the main GitSense Chat conversation view.
|
|
19
|
+
*
|
|
20
|
+
* @param {Object} hljs - An instance of highlight.js.
|
|
21
|
+
* @param {Object} [hstyle={}] - Optional custom styles for highlighted code blocks. Merged with defaults.
|
|
22
|
+
* @param {Object} [nhstyle={}] - Optional custom styles for non-highlighted code blocks. Merged with defaults.
|
|
23
|
+
* @returns {Object} A configured markdown-it instance.
|
|
24
|
+
*/
|
|
25
|
+
function createMarkdownRenderer(hljs, hstyle = {}, nhstyle = {}) {
|
|
26
|
+
const MarkDownIt = require("markdown-it");
|
|
27
|
+
|
|
28
|
+
const defaultHighlightStyle = {
|
|
29
|
+
backgroundColor: '#fafafa',
|
|
30
|
+
border: '1px solid #ddd',
|
|
31
|
+
marginTop: '5px',
|
|
32
|
+
overflow: 'auto',
|
|
33
|
+
maxHeight: '500px'
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const defaultNoHighlightStyle = {
|
|
37
|
+
marginTop: '5px',
|
|
38
|
+
overflow: 'auto',
|
|
39
|
+
maxHeight: '800px'
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Merge default and custom styles
|
|
43
|
+
const highlightStyle = { ...defaultHighlightStyle, ...hstyle };
|
|
44
|
+
const noHighlightStyle = { ...defaultNoHighlightStyle, ...nhstyle };
|
|
45
|
+
|
|
46
|
+
// Configure markdown-it with a custom highlight function
|
|
47
|
+
const md = new MarkDownIt({
|
|
48
|
+
html: false, // Can be overridden if needed
|
|
49
|
+
highlight: function (str, lang) {
|
|
50
|
+
// Attempt to highlight if the language is supported
|
|
51
|
+
if (lang && hljs.getLanguage(lang)) {
|
|
52
|
+
try {
|
|
53
|
+
// Use highlight.js to generate the highlighted code HTML
|
|
54
|
+
const highlightedCode = hljs.highlight(str, { language: lang, ignoreIllegals: true }).value;
|
|
55
|
+
|
|
56
|
+
// Create the inner code element with the highlighted content
|
|
57
|
+
// and the language label prepended.
|
|
58
|
+
const codeElement = h.createCode({
|
|
59
|
+
html: `<span class='gs-chat-lang'>${lang}</span>\n\n${highlightedCode}`,
|
|
60
|
+
style: {
|
|
61
|
+
fontSize: '13px'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Wrap the code element in a pre tag with styling
|
|
66
|
+
const preElement = h.createPre({
|
|
67
|
+
cls: 'hljs', // Standard class for highlight.js containers
|
|
68
|
+
style: highlightStyle,
|
|
69
|
+
append: [codeElement]
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Return the outer HTML of the pre element to be injected into the Markdown output
|
|
73
|
+
return preElement.outerHTML;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
// Gracefully handle highlight.js errors
|
|
76
|
+
console.warn("Syntax highlighting failed for language:", lang, error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Fallback for unsupported languages or highlighting errors
|
|
81
|
+
const escapedCode = md.utils.escapeHtml(str);
|
|
82
|
+
const codeElement = h.createCode({
|
|
83
|
+
html: escapedCode
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const preElement = h.createPre({
|
|
87
|
+
cls: 'hljs',
|
|
88
|
+
style: noHighlightStyle,
|
|
89
|
+
append: [codeElement]
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return preElement.outerHTML;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// --- Register Common markdown-it Plugins ---
|
|
97
|
+
// These are commonly used in GitSense Chat and should be included by default.
|
|
98
|
+
// The integrator can choose to disable them or add more via md.disable() or md.use() after creation.
|
|
99
|
+
md.use(require('markdown-it-anchor'), { level: 1 }); // Add anchors to headings
|
|
100
|
+
md.use(require('markdown-it-attrs'), { allowedAttributes: ['id'] }); // Allow custom attributes like {#custom-id}
|
|
101
|
+
|
|
102
|
+
return md;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* This function removes any existing LLM author signature. After streaming, the backend will
|
|
107
|
+
* add the LLM author signature as a regular Markdown line, which is why we are matching for
|
|
108
|
+
* a paragraph. The signature is important for processing, but we don't want the user to see
|
|
109
|
+
* it.
|
|
110
|
+
*
|
|
111
|
+
* @param {HTMLElement} body - The DOM element containing the rendered markdown HTML.
|
|
112
|
+
* @param {string} model - The name of the model to include in the signature.
|
|
113
|
+
*/
|
|
114
|
+
function removeSignature(body) {
|
|
115
|
+
if (!body) {
|
|
116
|
+
console.warn('MarkdownUtils.removeSignature: Invalid body.');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const llmSignatureRegex = new RegExp(`<p>Authored by [^<]+</p>$`, 'i');
|
|
121
|
+
body.innerHTML = body.innerHTML.replace(llmSignatureRegex, '');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = {
|
|
125
|
+
createMarkdownRenderer,
|
|
126
|
+
removeSignature,
|
|
127
|
+
};
|
package/src/MessageUtils.js
CHANGED
|
@@ -363,7 +363,7 @@ function getMessageContentType(messageContent) {
|
|
|
363
363
|
return 'regular'; // Handle non-string input gracefully
|
|
364
364
|
}
|
|
365
365
|
const trimmedContent = messageContent.trimStart(); // Check from the beginning, ignoring leading whitespace
|
|
366
|
-
if (trimmedContent.startsWith('## FILE CONTENT')) {
|
|
366
|
+
if (trimmedContent.startsWith('## FILE CONTENT') || trimmedContent.startsWith('## REFERENCE FILE CONTENT')) {
|
|
367
367
|
return 'file-content-context';
|
|
368
368
|
} else if (trimmedContent.startsWith('## OVERVIEW')) {
|
|
369
369
|
return 'overview-context';
|