@dxtmisha/scripts 0.4.7 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ai-doc.ts +9 -0
- package/package.json +9 -7
- package/src/classes/Ai/AiAbstract.ts +94 -13
- package/src/classes/Ai/AiDoc.ts +62 -0
- package/src/classes/Ai/AiDocItem.ts +20 -0
- package/src/classes/Ai/AiDocItemAbstract.ts +198 -0
- package/src/classes/Ai/AiDocItemClasses.ts +20 -0
- package/src/classes/Ai/AiDocItemComposables.ts +13 -0
- package/src/classes/Ai/AiDocType.ts +45 -0
- package/src/classes/Ai/AiGoogle.ts +7 -29
- package/src/classes/Ai/AiGoogleCli.ts +24 -0
- package/src/classes/Ai/AiGoogleCliLite.ts +144 -0
- package/src/classes/Ai/AiGoogleLite.ts +77 -0
- package/src/classes/BuildItem.ts +176 -0
- package/src/classes/Component/ComponentCreator.ts +2 -0
- package/src/classes/Component/ComponentItem.ts +3 -1
- package/src/classes/Component/ComponentWiki.ts +107 -190
- package/src/classes/Component/ComponentWikiFile.ts +102 -15
- package/src/classes/Design/DesignCommand.ts +3 -1
- package/src/classes/Design/DesignComponent.ts +3 -1
- package/src/classes/Design/DesignConstructor.ts +3 -1
- package/src/classes/Design/DesignConstructors.ts +3 -1
- package/src/classes/Design/DesignReplace.ts +3 -1
- package/src/classes/Design/DesignStructure.ts +3 -1
- package/src/classes/Design/DesignStructureClasses.ts +3 -1
- package/src/classes/Design/DesignStructureItemAbstract.ts +2 -0
- package/src/classes/Design/DesignStructureRead.ts +3 -1
- package/src/classes/Design/DesignStructureStyles.ts +2 -0
- package/src/classes/Design/DesignTypescript.ts +1 -1
- package/src/classes/Design/DesignUi.ts +3 -1
- package/src/classes/Design/DesignWiki.ts +3 -1
- package/src/classes/Git/GitRead.ts +258 -0
- package/src/classes/Library/LibraryExport.ts +2 -0
- package/src/classes/Library/LibraryFlags.ts +3 -1
- package/src/classes/Library/LibraryItems.ts +3 -1
- package/src/classes/Library/LibraryMedia.ts +3 -1
- package/src/classes/Package/PackageInit.ts +2 -0
- package/src/classes/Package/PackageItem.ts +2 -0
- package/src/classes/Properties/Properties.ts +3 -1
- package/src/classes/Properties/PropertiesCache.ts +3 -1
- package/src/classes/Properties/PropertiesConfig.ts +21 -0
- package/src/classes/Properties/PropertiesConvector.ts +3 -1
- package/src/classes/Properties/PropertiesFile.ts +11 -1
- package/src/classes/Properties/PropertiesImport.ts +3 -1
- package/src/classes/Properties/PropertiesItems.ts +3 -1
- package/src/classes/Properties/PropertiesKeys.ts +3 -1
- package/src/classes/Properties/PropertiesMain.ts +3 -1
- package/src/classes/Properties/PropertiesPalette.ts +3 -1
- package/src/classes/Properties/PropertiesPath.ts +3 -1
- package/src/classes/Properties/PropertiesScss.ts +3 -1
- package/src/classes/Properties/PropertiesSeparator.ts +3 -1
- package/src/classes/Properties/PropertiesSettings.ts +3 -1
- package/src/classes/Properties/PropertiesStandard.ts +3 -1
- package/src/classes/Properties/PropertiesTool.ts +3 -1
- package/src/classes/Properties/PropertiesTypes.ts +3 -1
- package/src/classes/Properties/PropertiesValues.ts +2 -0
- package/src/classes/Properties/PropertiesWrap.ts +3 -1
- package/src/classes/Properties/convector/convectorColor.ts +2 -0
- package/src/classes/Properties/convector/convectorFontFamilies.ts +2 -0
- package/src/classes/Properties/convector/convectorShadow.ts +3 -1
- package/src/classes/Properties/convector/convectorTypography.ts +3 -1
- package/src/classes/Properties/to/PropertiesToAbstract.ts +2 -0
- package/src/classes/Properties/to/PropertiesToAnimate.ts +3 -1
- package/src/classes/Properties/to/PropertiesToClass.ts +2 -0
- package/src/classes/Properties/to/PropertiesToClone.ts +3 -1
- package/src/classes/Properties/to/PropertiesToComponent.ts +2 -0
- package/src/classes/Properties/to/PropertiesToDrag.ts +3 -1
- package/src/classes/Properties/to/PropertiesToDuplicate.ts +3 -1
- package/src/classes/Properties/to/PropertiesToFull.ts +2 -0
- package/src/classes/Properties/to/PropertiesToLink.ts +3 -1
- package/src/classes/Properties/to/PropertiesToMedia.ts +3 -1
- package/src/classes/Properties/to/PropertiesToMulti.ts +3 -1
- package/src/classes/Properties/to/PropertiesToNone.ts +3 -1
- package/src/classes/Properties/to/PropertiesToPalette.ts +3 -1
- package/src/classes/Properties/to/PropertiesToProperty.ts +3 -1
- package/src/classes/Properties/to/PropertiesToRemove.ts +3 -1
- package/src/classes/Properties/to/PropertiesToReplace.ts +2 -0
- package/src/classes/Properties/to/PropertiesToRoot.ts +2 -0
- package/src/classes/Properties/to/PropertiesToSimilar.ts +3 -1
- package/src/classes/Properties/to/PropertiesToSort.ts +3 -1
- package/src/classes/Properties/to/PropertiesToState.ts +3 -1
- package/src/classes/Properties/to/PropertiesToStyle.ts +3 -1
- package/src/classes/Properties/to/PropertiesToSub.ts +2 -0
- package/src/classes/Properties/to/PropertiesToSubclass.ts +2 -0
- package/src/classes/Properties/to/PropertiesToVar.ts +3 -1
- package/src/classes/Properties/to/PropertiesToVariable.ts +3 -1
- package/src/classes/Styles/Styles.ts +3 -1
- package/src/classes/Styles/StylesClasses.ts +3 -1
- package/src/classes/Styles/StylesProperties.ts +2 -0
- package/src/classes/Styles/StylesRoot.ts +2 -0
- package/src/classes/Styles/StylesTool.ts +3 -1
- package/src/classes/Styles/to/StylesToAbstract.ts +3 -1
- package/src/classes/Styles/to/StylesToAnimate.ts +2 -0
- package/src/classes/Styles/to/StylesToClass.ts +2 -0
- package/src/classes/Styles/to/StylesToClassFull.ts +2 -0
- package/src/classes/Styles/to/StylesToContainer.ts +2 -0
- package/src/classes/Styles/to/StylesToMedia.ts +2 -0
- package/src/classes/Styles/to/StylesToProperty.ts +3 -1
- package/src/classes/Styles/to/StylesToRoot.ts +2 -0
- package/src/classes/Styles/to/StylesToSelector.ts +3 -1
- package/src/classes/Styles/to/StylesToVar.ts +3 -1
- package/src/classes/Styles/to/StylesToVirtual.ts +2 -0
- package/src/composables/useAi.ts +3 -0
- package/src/config.ts +11 -0
- package/src/functions/getComponentPaths.ts +2 -0
- package/src/functions/getConfigAi.ts +13 -0
- package/src/functions/getConstructorProperties.ts +3 -1
- package/src/functions/getNameDirByPaths.ts +2 -0
- package/src/functions/toPathStandardSep.ts +2 -0
- package/src/library-ai.ts +4 -0
- package/src/library.ts +30 -105
- package/src/media/ai/ai-doc-types.ts +21 -0
- package/src/media/properties/css.ts +4 -1
- package/src/media/properties/listSort.ts +1 -1
- package/src/media/properties/style.ts +2 -0
- package/src/media/templates/component/DesignComponent.vue +1 -1
- package/src/media/templates/constructors/ConstructorsDesign.tsx +4 -2
- package/src/media/templates/packages/library/package.json +2 -1
- package/src/media/templates/prompts/aiDocClassPrompt.en.txt +66 -0
- package/src/media/templates/prompts/aiDocClassPrompt.ru.txt +64 -0
- package/src/media/templates/prompts/aiDocComposablePrompt.en.txt +67 -0
- package/src/media/templates/prompts/aiDocComposablePrompt.ru.txt +67 -0
- package/src/media/templates/prompts/aiDocFunctionPrompt.en.txt +57 -0
- package/src/media/templates/prompts/aiDocFunctionPrompt.ru.txt +57 -0
- package/src/media/templates/prompts/componentPrompt.en.txt +105 -0
- package/src/media/templates/prompts/componentPrompt.ru.txt +105 -0
- package/src/media/templates/prompts/demoClassEn.mdx +111 -0
- package/src/media/templates/prompts/demoClassRu.mdx +111 -0
- package/src/media/templates/prompts/demoComponentEn.mdx +282 -0
- package/src/media/templates/prompts/demoComponentRu.mdx +282 -0
- package/src/media/templates/prompts/demoComposableEn.mdx +103 -0
- package/src/media/templates/prompts/demoComposableRu.mdx +103 -0
- package/src/media/templates/prompts/demoDocEn.mdx +30 -0
- package/src/media/templates/prompts/demoDocRu.mdx +30 -0
- package/src/media/templates/viteComponentTemplateConfig.ts +1 -1
- package/src/types/aiTypes.ts +19 -0
- package/src/types/configTypes.ts +8 -2
- package/src/types/gitTypes.ts +59 -0
- package/src/media/templates/componentPrompt.en.txt +0 -541
- package/src/media/templates/componentPrompt.ru.txt +0 -539
package/bin/ai-doc.ts
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxtmisha/scripts",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Development scripts and CLI tools for DXT UI projects - automated component generation, library building and project management tools",
|
|
7
7
|
"keywords": [
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"main": "./src/library.ts",
|
|
41
41
|
"module": "./src/library.ts",
|
|
42
42
|
"bin": {
|
|
43
|
+
"dxt-ai-doc": "bin/ai-doc.ts",
|
|
43
44
|
"dxt-component": "bin/design-component.ts",
|
|
44
45
|
"dxt-component-wiki": "bin/design-component-wiki.ts",
|
|
45
46
|
"dxt-constructor": "bin/design-constructor.ts",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
},
|
|
50
51
|
"exports": {
|
|
51
52
|
".": "./src/library.ts",
|
|
53
|
+
"./ai": "./src/library-ai.ts",
|
|
52
54
|
"./config": "./src/config.ts",
|
|
53
55
|
"./properties.json": "./src/media/properties.json"
|
|
54
56
|
},
|
|
@@ -56,12 +58,12 @@
|
|
|
56
58
|
"node": ">=18.0.0"
|
|
57
59
|
},
|
|
58
60
|
"peerDependencies": {
|
|
59
|
-
"@dxtmisha/configuration": "
|
|
60
|
-
"@dxtmisha/functional": "
|
|
61
|
-
"@dxtmisha/styles": "
|
|
62
|
-
"@dxtmisha/wiki": "
|
|
63
|
-
"typescript": "
|
|
64
|
-
"vue": "
|
|
61
|
+
"@dxtmisha/configuration": "*",
|
|
62
|
+
"@dxtmisha/functional": "*",
|
|
63
|
+
"@dxtmisha/styles": "*",
|
|
64
|
+
"@dxtmisha/wiki": "*",
|
|
65
|
+
"typescript": "*",
|
|
66
|
+
"vue": "*"
|
|
65
67
|
},
|
|
66
68
|
"dependencies": {}
|
|
67
69
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AiImageItem, AiImageList } from '../../types/aiTypes'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Abstract AI base class providing common mechanics for AI integrations.
|
|
@@ -21,26 +21,69 @@ import { PropertiesConfig } from '../Properties/PropertiesConfig'
|
|
|
21
21
|
* - response(): конкретный вызов модели
|
|
22
22
|
*/
|
|
23
23
|
export abstract class AiAbstract<AI = any> {
|
|
24
|
-
/** API key / API ключ */
|
|
25
|
-
protected key: string
|
|
26
|
-
|
|
27
24
|
/** AI client instance / Экземпляр AI-клиента */
|
|
28
25
|
protected ai?: AI
|
|
29
26
|
|
|
30
|
-
/** Active model id / Идентификатор активной модели */
|
|
31
|
-
protected model: string
|
|
32
|
-
|
|
33
27
|
/** Prompt prefix / Префикс prompt */
|
|
34
28
|
protected prompt: string = ''
|
|
35
29
|
|
|
30
|
+
/** Accumulated image list / Накопленный список изображений */
|
|
31
|
+
protected images: AiImageList = []
|
|
32
|
+
|
|
33
|
+
/** Accumulated contents / Накопленные содержимое */
|
|
34
|
+
protected contents: string[] = []
|
|
35
|
+
|
|
36
36
|
/**
|
|
37
37
|
* Constructor initializes implementation specific resources.
|
|
38
38
|
*
|
|
39
39
|
* Конструктор инициализирует ресурсы конкретной реализации.
|
|
40
|
+
* @param key - API key / API ключ
|
|
41
|
+
* @param model - initial model id / начальный идентификатор модели
|
|
42
|
+
*/
|
|
43
|
+
constructor(
|
|
44
|
+
protected key: string,
|
|
45
|
+
protected model: string
|
|
46
|
+
) {
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns accumulated image list.
|
|
51
|
+
*
|
|
52
|
+
* Возвращает накопленный список изображений.
|
|
53
|
+
*/
|
|
54
|
+
getImages(): AiImageList {
|
|
55
|
+
return this.images
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns accumulated contents.
|
|
60
|
+
*
|
|
61
|
+
* Возвращает накопленное содержимое.
|
|
62
|
+
*/
|
|
63
|
+
getContents(): string[] {
|
|
64
|
+
return this.contents
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Appends an image to the accumulated image list.
|
|
69
|
+
*
|
|
70
|
+
* Добавляет изображение к накопленному списку изображений.
|
|
71
|
+
* @param image - image item / элемент изображения
|
|
72
|
+
*/
|
|
73
|
+
addImage(image: AiImageItem): this {
|
|
74
|
+
this.images.push(image)
|
|
75
|
+
return this
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Appends content to the accumulated contents.
|
|
80
|
+
*
|
|
81
|
+
* Добавляет содержимое к накопленному содержимому.
|
|
82
|
+
* @param content - content string / строка содержимого
|
|
40
83
|
*/
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
this
|
|
84
|
+
addContent(content: string): this {
|
|
85
|
+
this.contents.push(content)
|
|
86
|
+
return this
|
|
44
87
|
}
|
|
45
88
|
|
|
46
89
|
/**
|
|
@@ -52,6 +95,26 @@ export abstract class AiAbstract<AI = any> {
|
|
|
52
95
|
this.prompt += `\n${prompt}`
|
|
53
96
|
}
|
|
54
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Clears entire accumulated image list.
|
|
100
|
+
*
|
|
101
|
+
* Очищает весь накопленный список изображений.
|
|
102
|
+
*/
|
|
103
|
+
resetImages(): this {
|
|
104
|
+
this.images = []
|
|
105
|
+
return this
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Clears entire accumulated contents.
|
|
110
|
+
*
|
|
111
|
+
* Очищает все накопленное содержимое.
|
|
112
|
+
*/
|
|
113
|
+
resetContents(): this {
|
|
114
|
+
this.contents = []
|
|
115
|
+
return this
|
|
116
|
+
}
|
|
117
|
+
|
|
55
118
|
/**
|
|
56
119
|
* Clears entire accumulated prompt.
|
|
57
120
|
*
|
|
@@ -104,10 +167,14 @@ export abstract class AiAbstract<AI = any> {
|
|
|
104
167
|
if (this.ai) {
|
|
105
168
|
console.log('[Ai] Generating')
|
|
106
169
|
|
|
107
|
-
|
|
170
|
+
const generate = await this.response(
|
|
108
171
|
this.model,
|
|
109
|
-
this.
|
|
172
|
+
this.getMainContents(contents)
|
|
110
173
|
)
|
|
174
|
+
|
|
175
|
+
console.log(`[Ai] End (length: ${generate.length})`)
|
|
176
|
+
|
|
177
|
+
return generate
|
|
111
178
|
}
|
|
112
179
|
|
|
113
180
|
return ''
|
|
@@ -118,7 +185,7 @@ export abstract class AiAbstract<AI = any> {
|
|
|
118
185
|
*
|
|
119
186
|
* Объединяет постоянный префикс prompt с переданным содержимым.
|
|
120
187
|
*/
|
|
121
|
-
protected
|
|
188
|
+
protected getMainContents(contents: string): string {
|
|
122
189
|
return `${this.prompt}\n${contents}`
|
|
123
190
|
}
|
|
124
191
|
|
|
@@ -129,6 +196,20 @@ export abstract class AiAbstract<AI = any> {
|
|
|
129
196
|
*/
|
|
130
197
|
protected abstract init(): void
|
|
131
198
|
|
|
199
|
+
/**
|
|
200
|
+
* Implementation hook: convert accumulated images to model-specific format.
|
|
201
|
+
*
|
|
202
|
+
* Хук реализации: преобразовать накопленные изображения в формат, специфичный для модели.
|
|
203
|
+
*/
|
|
204
|
+
protected abstract toImages(): void
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Implementation hook: convert accumulated contents to model-specific format.
|
|
208
|
+
*
|
|
209
|
+
* Хук реализации: преобразовать накопленное содержимое в формат, специфичный для модели.
|
|
210
|
+
*/
|
|
211
|
+
protected abstract toContents(): void
|
|
212
|
+
|
|
132
213
|
/**
|
|
133
214
|
* Implementation hook: perform model call and return textual result.
|
|
134
215
|
*
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PropertiesConfig } from '../Properties/PropertiesConfig'
|
|
2
|
+
import { GitRead } from '../Git/GitRead'
|
|
3
|
+
import { AiDocType } from './AiDocType'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class for generating AI documentation.
|
|
7
|
+
*
|
|
8
|
+
* Класс для генерации AI документации.
|
|
9
|
+
*/
|
|
10
|
+
export class AiDoc {
|
|
11
|
+
/**
|
|
12
|
+
* Main method to generate documentation.
|
|
13
|
+
*
|
|
14
|
+
* Основной метод для генерации документации.
|
|
15
|
+
*/
|
|
16
|
+
async make() {
|
|
17
|
+
const dirs = PropertiesConfig.getAiDocDirectory()
|
|
18
|
+
const path = PropertiesConfig.getAiDocStorybookPath()
|
|
19
|
+
|
|
20
|
+
console.log(`AI documentation: ${path}`)
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
dirs
|
|
24
|
+
&& dirs.length
|
|
25
|
+
) {
|
|
26
|
+
for (const dir of dirs) {
|
|
27
|
+
await this.makeDirectory(dir)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Process a specific directory.
|
|
34
|
+
*
|
|
35
|
+
* Обрабатывает конкретную директорию.
|
|
36
|
+
* @param dir - directory path / путь к директории
|
|
37
|
+
*/
|
|
38
|
+
async makeDirectory(dir: string) {
|
|
39
|
+
console.log('')
|
|
40
|
+
console.log(`Dir: ${dir}...`)
|
|
41
|
+
|
|
42
|
+
for (const item of this.getListByDirectory(dir)) {
|
|
43
|
+
try {
|
|
44
|
+
await AiDocType.make(item)
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error(`Error processing file ${item}:`, e)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get list of files in a directory.
|
|
53
|
+
*
|
|
54
|
+
* Получает список файлов в директории.
|
|
55
|
+
* @param dir - directory path / путь к директории
|
|
56
|
+
*/
|
|
57
|
+
protected getListByDirectory(dir: string) {
|
|
58
|
+
return GitRead.filterByDirectory(
|
|
59
|
+
GitRead.getListByDirectory(dir)
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AiDocItemAbstract } from './AiDocItemAbstract'
|
|
2
|
+
|
|
3
|
+
/** Sample prompt template path / Путь к шаблону промпта */
|
|
4
|
+
const FILE_PROMPT_SAMPLE = [__dirname, '..', '..', 'media', 'templates', 'prompts']
|
|
5
|
+
|
|
6
|
+
/** Sample prompt template path for functions / Путь к шаблону промпта для функций */
|
|
7
|
+
const FILE_PROMPT_SAMPLE_ITEM = [...FILE_PROMPT_SAMPLE, 'aiDocFunctionPrompt.en.txt']
|
|
8
|
+
|
|
9
|
+
/** Sample demo file path for functions / Путь к демо файлу для функций */
|
|
10
|
+
const FILE_DEMO_SAMPLE_ITEM = [...FILE_PROMPT_SAMPLE, 'demoDocEn.mdx']
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Class for generating documentation for Functions.
|
|
14
|
+
*
|
|
15
|
+
* Класс для генерации документации для Функций.
|
|
16
|
+
*/
|
|
17
|
+
export class AiDocItem extends AiDocItemAbstract {
|
|
18
|
+
protected pathDemo: string[] = FILE_DEMO_SAMPLE_ITEM
|
|
19
|
+
protected pathPrompt: string[] = FILE_PROMPT_SAMPLE_ITEM
|
|
20
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Datetime, removeCommonPrefix } from '@dxtmisha/functional-basic'
|
|
2
|
+
import { useAi } from '../../composables/useAi'
|
|
3
|
+
|
|
4
|
+
import { PropertiesFile } from '../Properties/PropertiesFile'
|
|
5
|
+
import { PropertiesConfig } from '../Properties/PropertiesConfig'
|
|
6
|
+
import { GitRead } from '../Git/GitRead'
|
|
7
|
+
import { BuildItem } from '../BuildItem'
|
|
8
|
+
import { ComponentWikiFile } from '../Component/ComponentWikiFile'
|
|
9
|
+
|
|
10
|
+
import type { AiAbstract } from './AiAbstract'
|
|
11
|
+
import type { GitFileItem } from '../../types/gitTypes'
|
|
12
|
+
|
|
13
|
+
import { UI_DIR_IN, UI_FILE_PACKAGE } from '../../config'
|
|
14
|
+
|
|
15
|
+
export abstract class AiDocItemAbstract {
|
|
16
|
+
/** Demo file path / Путь к файлу демо */
|
|
17
|
+
protected abstract pathDemo: string[]
|
|
18
|
+
/** Prompt template path / Путь к шаблону промпта */
|
|
19
|
+
protected abstract pathPrompt: string[]
|
|
20
|
+
|
|
21
|
+
/** Build item / Элемент сборки */
|
|
22
|
+
protected readonly build: BuildItem
|
|
23
|
+
|
|
24
|
+
/** Markdown file / Файл в формате Markdown */
|
|
25
|
+
protected readonly mdFile: ComponentWikiFile
|
|
26
|
+
|
|
27
|
+
/** Code file / Файл с кодом */
|
|
28
|
+
protected readonly code: ComponentWikiFile
|
|
29
|
+
|
|
30
|
+
/** Property file data / Данные из файла свойств */
|
|
31
|
+
protected readonly projectName: string
|
|
32
|
+
|
|
33
|
+
/** AI instance / Экземпляр ИИ */
|
|
34
|
+
protected readonly ai?: AiAbstract
|
|
35
|
+
|
|
36
|
+
/** Description from AI / Описание от ИИ */
|
|
37
|
+
protected description?: string
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Constructor
|
|
41
|
+
* @param path source file path / путь к исходному файлу
|
|
42
|
+
* @param item git file item / элемент файла git
|
|
43
|
+
*/
|
|
44
|
+
constructor(
|
|
45
|
+
protected readonly path: string,
|
|
46
|
+
protected readonly item: GitFileItem
|
|
47
|
+
) {
|
|
48
|
+
this.build = new BuildItem(this.item.path)
|
|
49
|
+
this.mdFile = new ComponentWikiFile(this.getPathWiki(), true, false)
|
|
50
|
+
this.code = new ComponentWikiFile(this.item.pathByOS, false, false)
|
|
51
|
+
this.projectName = PropertiesFile.readFile<Record<string, any>>(UI_FILE_PACKAGE)?.name ?? 'Library'
|
|
52
|
+
this.ai = useAi()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Generates documentation using AI.
|
|
57
|
+
*
|
|
58
|
+
* Генерирует документацию с использованием ИИ.
|
|
59
|
+
*/
|
|
60
|
+
async make() {
|
|
61
|
+
const date = this.mdFile.getDate()
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
this.ai
|
|
65
|
+
&& this.getItemDate() > date.getDate()
|
|
66
|
+
) {
|
|
67
|
+
console.log(
|
|
68
|
+
`${this.projectName}/File:`,
|
|
69
|
+
this.item.path,
|
|
70
|
+
PropertiesConfig.getWikiLanguage()
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const status = await this.build.make()
|
|
74
|
+
|
|
75
|
+
if (status) {
|
|
76
|
+
this.makeAi()
|
|
77
|
+
|
|
78
|
+
const generate = await this.ai.generate(
|
|
79
|
+
this.readPrompt()
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if (generate) {
|
|
83
|
+
const read = generate.split('#########')
|
|
84
|
+
|
|
85
|
+
if (read?.[0]) {
|
|
86
|
+
this.description = read[0].trim()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (
|
|
90
|
+
read?.[1]
|
|
91
|
+
&& !read[1].match('--FULL--')
|
|
92
|
+
) {
|
|
93
|
+
this.code.write(read[1])
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (read?.[2]) {
|
|
97
|
+
this.mdFile.write(this.initName(read[2]))
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.build.removeDir()
|
|
103
|
+
} else if (!this.ai) {
|
|
104
|
+
console.error('AI is not configured.')
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Returns the path to the Wiki file.
|
|
110
|
+
*
|
|
111
|
+
* Возвращает путь к Wiki файлу.
|
|
112
|
+
*/
|
|
113
|
+
protected getPathWiki(): string[] {
|
|
114
|
+
const fileName = removeCommonPrefix(this.item.path, this.path)
|
|
115
|
+
.replace(/\.ts$/, '')
|
|
116
|
+
|
|
117
|
+
return [
|
|
118
|
+
...GitRead.splitPath(this.path),
|
|
119
|
+
...GitRead.splitPath(`${fileName}.mdx`)
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Returns the file modification date.
|
|
125
|
+
*
|
|
126
|
+
* Возвращает дату изменения файла.
|
|
127
|
+
*/
|
|
128
|
+
protected getItemDate(): Date {
|
|
129
|
+
return new Datetime(this.item.date).getDate()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns the title for the documentation.
|
|
134
|
+
*
|
|
135
|
+
* Возвращает заголовок для документации.
|
|
136
|
+
*/
|
|
137
|
+
protected getTitle() {
|
|
138
|
+
let title = this.projectName
|
|
139
|
+
+ '/'
|
|
140
|
+
+ this.item.path
|
|
141
|
+
.replace(UI_DIR_IN + '/', '')
|
|
142
|
+
.replace(/\.ts$/, '')
|
|
143
|
+
|
|
144
|
+
if (this.description) {
|
|
145
|
+
title += ` - ${this.description}`
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return title
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Reads the demo file content.
|
|
153
|
+
*
|
|
154
|
+
* Читает содержимое демо-файла.
|
|
155
|
+
*/
|
|
156
|
+
protected readDemo(): string {
|
|
157
|
+
return new ComponentWikiFile(this.pathDemo).read()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Reads the prompt template.
|
|
162
|
+
*
|
|
163
|
+
* Читает шаблон промпта.
|
|
164
|
+
*/
|
|
165
|
+
protected readPrompt(): string {
|
|
166
|
+
return new ComponentWikiFile(this.pathPrompt)
|
|
167
|
+
.read()
|
|
168
|
+
.replace(/\[wikiLanguage]/g, PropertiesConfig.getWikiLanguage())
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Prepares context for AI.
|
|
173
|
+
*
|
|
174
|
+
* Подготавливает контекст для ИИ.
|
|
175
|
+
*/
|
|
176
|
+
protected makeAi(): void {
|
|
177
|
+
if (this.ai) {
|
|
178
|
+
this.ai.addContent(`Code: ${this.build.getCode()}`)
|
|
179
|
+
this.ai.addContent(`Original code: ${this.code.read()}`)
|
|
180
|
+
this.ai.addContent(`Demo (only for template analysis, all data is fake): ${this.readDemo()}`)
|
|
181
|
+
this.ai.addContent(`Original MDX: ${this.mdFile.read()}`)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Initializes the title in the content.
|
|
187
|
+
*
|
|
188
|
+
* Инициализирует заголовок в контенте.
|
|
189
|
+
* @param content content / контент
|
|
190
|
+
*/
|
|
191
|
+
protected initName(content: string): string {
|
|
192
|
+
if (content.match('[title]')) {
|
|
193
|
+
return content.replace('[title]', this.getTitle())
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return content
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AiDocItemAbstract } from './AiDocItemAbstract'
|
|
2
|
+
|
|
3
|
+
/** Sample prompt template path / Путь к шаблону промпта */
|
|
4
|
+
const FILE_PROMPT_SAMPLE = [__dirname, '..', '..', 'media', 'templates', 'prompts']
|
|
5
|
+
|
|
6
|
+
/** Sample prompt template for classes / Шаблон промпта для классов */
|
|
7
|
+
const FILE_PROMPT_SAMPLE_CLASS = [...FILE_PROMPT_SAMPLE, 'aiDocClassPrompt.en.txt']
|
|
8
|
+
|
|
9
|
+
/** Sample demo file for classes / Пример демонстрационного файла для классов */
|
|
10
|
+
const FILE_DEMO_SAMPLE_CLASS = [...FILE_PROMPT_SAMPLE, 'demoClassEn.mdx']
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* AI Documentation Item for Classes.
|
|
14
|
+
*
|
|
15
|
+
* Элемент документации AI для классов.
|
|
16
|
+
*/
|
|
17
|
+
export class AiDocItemClasses extends AiDocItemAbstract {
|
|
18
|
+
protected pathDemo: string[] = FILE_DEMO_SAMPLE_CLASS
|
|
19
|
+
protected pathPrompt: string[] = FILE_PROMPT_SAMPLE_CLASS
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AiDocItemAbstract } from './AiDocItemAbstract'
|
|
2
|
+
|
|
3
|
+
/** Sample prompt template path / Путь к шаблону промпта */
|
|
4
|
+
const FILE_PROMPT_SAMPLE = [__dirname, '..', '..', 'media', 'templates', 'prompts']
|
|
5
|
+
|
|
6
|
+
const FILE_PROMPT_SAMPLE_COMPOSABLE = [...FILE_PROMPT_SAMPLE, 'aiDocComposablePrompt.en.txt']
|
|
7
|
+
|
|
8
|
+
const FILE_DEMO_SAMPLE_COMPOSABLE = [...FILE_PROMPT_SAMPLE, 'demoComposableEn.mdx']
|
|
9
|
+
|
|
10
|
+
export class AiDocItemComposables extends AiDocItemAbstract {
|
|
11
|
+
protected pathDemo: string[] = FILE_DEMO_SAMPLE_COMPOSABLE
|
|
12
|
+
protected pathPrompt: string[] = FILE_PROMPT_SAMPLE_COMPOSABLE
|
|
13
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PropertiesConfig } from '../Properties/PropertiesConfig'
|
|
2
|
+
|
|
3
|
+
import type { AiDocTypeItem } from '../../types/aiTypes'
|
|
4
|
+
import type { GitFileItem } from '../../types/gitTypes'
|
|
5
|
+
|
|
6
|
+
import { aiDocTypes } from '../../media/ai/ai-doc-types'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Class for managing AI documentation types.
|
|
10
|
+
*
|
|
11
|
+
* Класс для управления типами документации ИИ.
|
|
12
|
+
*/
|
|
13
|
+
export class AiDocType {
|
|
14
|
+
/** List of available documentation types / Список доступных типов документации */
|
|
15
|
+
protected static types = [...aiDocTypes]
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Adds a new documentation type to the list.
|
|
19
|
+
*
|
|
20
|
+
* Добавляет новый тип документации в список.
|
|
21
|
+
* @param type documentation type item / элемент типа документации
|
|
22
|
+
*/
|
|
23
|
+
static add(type: AiDocTypeItem) {
|
|
24
|
+
this.types.unshift(type)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Generates documentation for a file item.
|
|
29
|
+
*
|
|
30
|
+
* Генерирует документацию для элемента файла.
|
|
31
|
+
* @param item git file item / элемент файла git
|
|
32
|
+
*/
|
|
33
|
+
static async make(item: GitFileItem) {
|
|
34
|
+
const path = PropertiesConfig.getAiDocStorybookPath()
|
|
35
|
+
|
|
36
|
+
for (const docType of aiDocTypes) {
|
|
37
|
+
if (docType.check(item)) {
|
|
38
|
+
const docItem = new docType.item(path, item)
|
|
39
|
+
await docItem.make()
|
|
40
|
+
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getConfigAi } from '../../functions/getConfigAi'
|
|
2
|
+
import { AiGoogleLite } from './AiGoogleLite'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Google AI (Gemini) implementation of AiAbstract.
|
|
@@ -17,32 +17,10 @@ import { GoogleGenAI } from '@google/genai'
|
|
|
17
17
|
* - Model must be set via setModel() before generate() / Модель нужно задать через setModel()
|
|
18
18
|
* - Returns empty string if response is missing / Возвращает пустую строку при отсутствии результата
|
|
19
19
|
*/
|
|
20
|
-
export class AiGoogle extends
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
protected init(): void {
|
|
27
|
-
this.ai = new GoogleGenAI({ apiKey: this.key })
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Performs content generation request and returns textual result.
|
|
32
|
-
*
|
|
33
|
-
* Выполняет запрос генерации контента и возвращает текстовый результат.
|
|
34
|
-
* @param model Model identifier / Идентификатор модели
|
|
35
|
-
* @param contents Composed contents for generation / Собранный контент для генерации
|
|
36
|
-
*/
|
|
37
|
-
protected async response(
|
|
38
|
-
model: string,
|
|
39
|
-
contents: string
|
|
40
|
-
): Promise<string> {
|
|
41
|
-
const response = await this.ai?.models.generateContent({
|
|
42
|
-
model,
|
|
43
|
-
contents
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
return response?.text ?? ''
|
|
20
|
+
export class AiGoogle extends AiGoogleLite {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(
|
|
23
|
+
...getConfigAi()
|
|
24
|
+
)
|
|
47
25
|
}
|
|
48
26
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getConfigAi } from '../../functions/getConfigAi'
|
|
2
|
+
import { AiGoogleCliLite } from './AiGoogleCliLite'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Google AI (Gemini) implementation via CLI.
|
|
6
|
+
* Extends AiGoogleCliLite and provides configuration from the project environment.
|
|
7
|
+
*
|
|
8
|
+
* Реализация Google AI (Gemini) через CLI.
|
|
9
|
+
* Расширяет AiGoogleCliLite и предоставляет конфигурацию из окружения проекта.
|
|
10
|
+
*
|
|
11
|
+
* Responsibilities / Ответственности:
|
|
12
|
+
* - Provide API key and model from config / Предоставить API ключ и модель из конфигурации
|
|
13
|
+
* - Initialize CLI wrapper / Инициализировать обертку CLI
|
|
14
|
+
*
|
|
15
|
+
* Notes / Примечания:
|
|
16
|
+
* - Uses getConfigAi() to retrieve credentials / Использует getConfigAi() для получения учетных данных
|
|
17
|
+
*/
|
|
18
|
+
export class AiGoogleCli extends AiGoogleCliLite {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(
|
|
21
|
+
...getConfigAi()
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
}
|