@dxtmisha/scripts 0.11.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/ai-resources/componentMaterials.md +19 -0
- package/ai-resources/componentPrompt.md +381 -0
- package/ai-resources/componentWiki.md +13 -0
- package/bin/arguments.ts +168 -0
- package/bin/build-packages.ts +34 -3
- package/bin/build-publish-packages.ts +12 -2
- package/bin/design-component.ts +7 -1
- package/bin/design-constructor.ts +22 -3
- package/bin/design-figma.ts +26 -4
- package/bin/design-flags.ts +14 -2
- package/bin/design-library.ts +7 -1
- package/bin/design-package.ts +29 -5
- package/bin/design-prompt.ts +27 -3
- package/bin/design-screenshot.ts +12 -2
- package/bin/design-types-save.ts +32 -5
- package/bin/design-types.ts +32 -6
- package/bin/design-ui.ts +21 -3
- package/bin/design-wiki-storm.ts +11 -3
- package/dist/AiZAi-BiLAcdFy.js +232 -0
- package/dist/PropertiesConfig-BKZz_FWW.js +262 -0
- package/{src/config.ts → dist/config.d.ts} +185 -158
- package/dist/config.js +20 -0
- package/dist/figmaApiTypes-CArSsNW8.js +6 -0
- package/dist/library-ai.d.ts +482 -0
- package/dist/library-ai.js +2 -0
- package/dist/library-figma.d.ts +462 -0
- package/dist/library-figma.js +75 -0
- package/dist/library-ui.d.ts +586 -0
- package/dist/library-ui.js +3760 -0
- package/dist/library.d.ts +4910 -0
- package/dist/library.js +1568 -0
- package/dist/propertyTypes-C64u6rT3.js +236 -0
- package/package.json +76 -27
- package/bin/ai-doc.ts +0 -7
- package/bin/build-functional.ts +0 -5
- package/bin/design-component-wiki.ts +0 -11
- package/src/classes/Ai/AiAbstract.ts +0 -242
- package/src/classes/Ai/AiClaude.ts +0 -26
- package/src/classes/Ai/AiClaudeAgent.ts +0 -16
- package/src/classes/Ai/AiClaudeAgentLite.ts +0 -86
- package/src/classes/Ai/AiClaudeCli.ts +0 -24
- package/src/classes/Ai/AiClaudeCliLite.ts +0 -108
- package/src/classes/Ai/AiClaudeLite.ts +0 -112
- package/src/classes/Ai/AiDoc.ts +0 -81
- package/src/classes/Ai/AiDocItem.ts +0 -27
- package/src/classes/Ai/AiDocItemAbstract.ts +0 -209
- package/src/classes/Ai/AiDocItemClasses.ts +0 -27
- package/src/classes/Ai/AiDocItemComposables.ts +0 -20
- package/src/classes/Ai/AiDocType.ts +0 -45
- package/src/classes/Ai/AiGoogle.ts +0 -26
- package/src/classes/Ai/AiGoogleCli.ts +0 -24
- package/src/classes/Ai/AiGoogleCliLite.ts +0 -108
- package/src/classes/Ai/AiGoogleLite.ts +0 -78
- package/src/classes/Ai/AiOpenAi.ts +0 -26
- package/src/classes/Ai/AiOpenAiLite.ts +0 -107
- package/src/classes/Ai/AiZAi.ts +0 -17
- package/src/classes/Ai/AiZAiLite.ts +0 -77
- package/src/classes/Ai/ApiTmp.ts +0 -43
- package/src/classes/BrowserItem.ts +0 -408
- package/src/classes/Build/BuildFunctional.ts +0 -54
- package/src/classes/Build/BuildPackages.ts +0 -137
- package/src/classes/Build/BuildPublishPackages.ts +0 -105
- package/src/classes/BuildItem.ts +0 -187
- package/src/classes/Component/ComponentCreator.ts +0 -45
- package/src/classes/Component/ComponentItem.ts +0 -161
- package/src/classes/Component/ComponentWiki.ts +0 -258
- package/src/classes/Component/ComponentWikiFile.ts +0 -138
- package/src/classes/Design/DesignCommand.ts +0 -243
- package/src/classes/Design/DesignComponent.ts +0 -824
- package/src/classes/Design/DesignConstructor.ts +0 -222
- package/src/classes/Design/DesignConstructors.ts +0 -101
- package/src/classes/Design/DesignFigma.ts +0 -61
- package/src/classes/Design/DesignFlags.ts +0 -215
- package/src/classes/Design/DesignReplace.ts +0 -672
- package/src/classes/Design/DesignScreenshot.ts +0 -140
- package/src/classes/Design/DesignStructure.ts +0 -201
- package/src/classes/Design/DesignStructureClasses.ts +0 -105
- package/src/classes/Design/DesignStructureItemAbstract.ts +0 -52
- package/src/classes/Design/DesignStructureRead.ts +0 -349
- package/src/classes/Design/DesignStructureStyles.ts +0 -45
- package/src/classes/Design/DesignTypes.ts +0 -94
- package/src/classes/Design/DesignTypesAi.ts +0 -135
- package/src/classes/Design/DesignTypesDescription.ts +0 -121
- package/src/classes/Design/DesignTypesMake.ts +0 -460
- package/src/classes/Design/DesignTypesMcp.ts +0 -90
- package/src/classes/Design/DesignTypesPrompts.ts +0 -332
- package/src/classes/Design/DesignTypescript.ts +0 -244
- package/src/classes/Design/DesignUi.ts +0 -143
- package/src/classes/Design/DesignWiki.ts +0 -52
- package/src/classes/Design/DesignWikiStorm.ts +0 -95
- package/src/classes/Design/DesignWikiStormItem.ts +0 -316
- package/src/classes/FigmaApi.ts +0 -190
- package/src/classes/Git/GitRead.ts +0 -261
- package/src/classes/Library/LibraryAiMcpItem.ts +0 -67
- package/src/classes/Library/LibraryAiPrompt.ts +0 -268
- package/src/classes/Library/LibraryAiPromptItem.ts +0 -331
- package/src/classes/Library/LibraryAiWiki.ts +0 -127
- package/src/classes/Library/LibraryAiWikiItem.ts +0 -79
- package/src/classes/Library/LibraryExport.ts +0 -167
- package/src/classes/Library/LibraryFlags.ts +0 -62
- package/src/classes/Library/LibraryItems.ts +0 -138
- package/src/classes/Library/LibraryList.ts +0 -189
- package/src/classes/Library/LibraryMedia.ts +0 -139
- package/src/classes/Library/LibraryPlugin.ts +0 -73
- package/src/classes/Library/LibraryTypes.ts +0 -130
- package/src/classes/Package/PackageFile.ts +0 -154
- package/src/classes/Package/PackageInit.ts +0 -54
- package/src/classes/Package/PackageItem.ts +0 -329
- package/src/classes/Properties/Properties.ts +0 -175
- package/src/classes/Properties/PropertiesCache.ts +0 -248
- package/src/classes/Properties/PropertiesConfig.ts +0 -213
- package/src/classes/Properties/PropertiesConvector.ts +0 -52
- package/src/classes/Properties/PropertiesFile.ts +0 -522
- package/src/classes/Properties/PropertiesImport.ts +0 -182
- package/src/classes/Properties/PropertiesItems.ts +0 -605
- package/src/classes/Properties/PropertiesKeys.ts +0 -121
- package/src/classes/Properties/PropertiesMain.ts +0 -138
- package/src/classes/Properties/PropertiesPalette.ts +0 -149
- package/src/classes/Properties/PropertiesPath.ts +0 -193
- package/src/classes/Properties/PropertiesScss.ts +0 -261
- package/src/classes/Properties/PropertiesSeparator.ts +0 -118
- package/src/classes/Properties/PropertiesSettings.ts +0 -104
- package/src/classes/Properties/PropertiesStandard.ts +0 -180
- package/src/classes/Properties/PropertiesTool.ts +0 -80
- package/src/classes/Properties/PropertiesTypes.ts +0 -147
- package/src/classes/Properties/PropertiesValues.ts +0 -75
- package/src/classes/Properties/PropertiesWrap.ts +0 -187
- package/src/classes/Properties/convector/convectorColor.ts +0 -27
- package/src/classes/Properties/convector/convectorFontFamilies.ts +0 -18
- package/src/classes/Properties/convector/convectorShadow.ts +0 -61
- package/src/classes/Properties/convector/convectorTypography.ts +0 -19
- package/src/classes/Properties/to/PropertiesToAbstract.ts +0 -51
- package/src/classes/Properties/to/PropertiesToAnimate.ts +0 -59
- package/src/classes/Properties/to/PropertiesToClass.ts +0 -49
- package/src/classes/Properties/to/PropertiesToClone.ts +0 -114
- package/src/classes/Properties/to/PropertiesToComponent.ts +0 -52
- package/src/classes/Properties/to/PropertiesToDrag.ts +0 -231
- package/src/classes/Properties/to/PropertiesToDuplicate.ts +0 -165
- package/src/classes/Properties/to/PropertiesToFull.ts +0 -36
- package/src/classes/Properties/to/PropertiesToLink.ts +0 -259
- package/src/classes/Properties/to/PropertiesToMedia.ts +0 -187
- package/src/classes/Properties/to/PropertiesToMulti.ts +0 -101
- package/src/classes/Properties/to/PropertiesToNone.ts +0 -46
- package/src/classes/Properties/to/PropertiesToPalette.ts +0 -241
- package/src/classes/Properties/to/PropertiesToProperty.ts +0 -31
- package/src/classes/Properties/to/PropertiesToRemove.ts +0 -33
- package/src/classes/Properties/to/PropertiesToReplace.ts +0 -77
- package/src/classes/Properties/to/PropertiesToRoot.ts +0 -40
- package/src/classes/Properties/to/PropertiesToSimilar.ts +0 -128
- package/src/classes/Properties/to/PropertiesToSort.ts +0 -146
- package/src/classes/Properties/to/PropertiesToState.ts +0 -65
- package/src/classes/Properties/to/PropertiesToStyle.ts +0 -52
- package/src/classes/Properties/to/PropertiesToSub.ts +0 -95
- package/src/classes/Properties/to/PropertiesToSubclass.ts +0 -76
- package/src/classes/Properties/to/PropertiesToVar.ts +0 -194
- package/src/classes/Properties/to/PropertiesToVariable.ts +0 -176
- package/src/classes/Styles/Styles.ts +0 -247
- package/src/classes/Styles/StylesClasses.ts +0 -86
- package/src/classes/Styles/StylesProperties.ts +0 -197
- package/src/classes/Styles/StylesRoot.ts +0 -103
- package/src/classes/Styles/StylesTool.ts +0 -112
- package/src/classes/Styles/to/StylesToAbstract.ts +0 -93
- package/src/classes/Styles/to/StylesToAnimate.ts +0 -19
- package/src/classes/Styles/to/StylesToClass.ts +0 -25
- package/src/classes/Styles/to/StylesToClassFull.ts +0 -19
- package/src/classes/Styles/to/StylesToContainer.ts +0 -24
- package/src/classes/Styles/to/StylesToMedia.ts +0 -19
- package/src/classes/Styles/to/StylesToProperty.ts +0 -123
- package/src/classes/Styles/to/StylesToRoot.ts +0 -14
- package/src/classes/Styles/to/StylesToSelector.ts +0 -71
- package/src/classes/Styles/to/StylesToVar.ts +0 -105
- package/src/classes/Styles/to/StylesToVirtual.ts +0 -33
- package/src/composables/useAi.ts +0 -38
- package/src/demo/ai.ts +0 -10
- package/src/functions/getComponentPaths.ts +0 -13
- package/src/functions/getConfigAi.ts +0 -14
- package/src/functions/getConstructorProperties.ts +0 -54
- package/src/functions/getDirname.ts +0 -17
- package/src/functions/getNameDirByPaths.ts +0 -16
- package/src/functions/getPackageJson.ts +0 -19
- package/src/functions/hasNativeDirname.ts +0 -8
- package/src/functions/run.ts +0 -47
- package/src/functions/toPathStandardSep.ts +0 -14
- package/src/library-ai.ts +0 -10
- package/src/library.ts +0 -73
- package/src/media/ai/ai-doc-types.ts +0 -21
- package/src/media/properties/css.ts +0 -634
- package/src/media/properties/cssSelector.ts +0 -74
- package/src/media/properties/cssVirtual.ts +0 -12
- package/src/media/properties/listSort.ts +0 -113
- package/src/media/properties/style.ts +0 -81
- package/src/media/templates/component/DesignComponent.mdx +0 -30
- package/src/media/templates/component/DesignComponent.stories.ts +0 -34
- package/src/media/templates/component/DesignComponent.vue +0 -54
- package/src/media/templates/component/DesignComponentAiWiki.vue +0 -25
- package/src/media/templates/component/index.ts +0 -13
- package/src/media/templates/component/props.ts +0 -27
- package/src/media/templates/component/styleToken.scss +0 -17
- package/src/media/templates/component/wiki.ts +0 -13
- package/src/media/templates/component/wikiData.ts +0 -28
- package/src/media/templates/componentDoc/ComponentDoc.vue +0 -26
- package/src/media/templates/componentDoc/index.ts +0 -12
- package/src/media/templates/componentDoc/materials/README.md +0 -8
- package/src/media/templates/componentDoc/materials/prompt.md +0 -38
- package/src/media/templates/componentDoc/subcomponents/_.gitignore.txt +0 -0
- package/src/media/templates/componentDoc/types.ts +0 -15
- package/src/media/templates/componentDoc/wiki/ComponentDoc.mdx +0 -13
- package/src/media/templates/componentDoc/wiki/ComponentDoc.stories.ts +0 -24
- package/src/media/templates/componentDoc/wiki/prompt.md +0 -41
- package/src/media/templates/constructors/Constructors.ts +0 -33
- package/src/media/templates/constructors/ConstructorsDesign.tsx +0 -129
- package/src/media/templates/constructors/basicTypes.ts +0 -0
- package/src/media/templates/constructors/index.ts +0 -5
- package/src/media/templates/constructors/props.ts +0 -28
- package/src/media/templates/constructors/style.scss +0 -5
- package/src/media/templates/constructors/types.ts +0 -47
- package/src/media/templates/packages/figma/README.md +0 -1
- package/src/media/templates/packages/figma/_.gitignore.txt +0 -29
- package/src/media/templates/packages/figma/ai.sample.config.ts +0 -2
- package/src/media/templates/packages/figma/design.config.json +0 -3
- package/src/media/templates/packages/figma/index.html +0 -12
- package/src/media/templates/packages/figma/manifest.json +0 -25
- package/src/media/templates/packages/figma/package.json +0 -37
- package/src/media/templates/packages/figma/src/App.vue +0 -9
- package/src/media/templates/packages/figma/src/classes/_.gitignore.txt +0 -1
- package/src/media/templates/packages/figma/src/code.ts +0 -16
- package/src/media/templates/packages/figma/src/components/_.gitignore.txt +0 -1
- package/src/media/templates/packages/figma/src/composables/_.gitignore.txt +0 -1
- package/src/media/templates/packages/figma/src/config.ts +0 -0
- package/src/media/templates/packages/figma/src/functions/_.gitignore.txt +0 -1
- package/src/media/templates/packages/figma/src/library.ts +0 -0
- package/src/media/templates/packages/figma/src/main.ts +0 -4
- package/src/media/templates/packages/figma/src/media/_.gitignore.txt +0 -1
- package/src/media/templates/packages/figma/src/storybook/_.gitignore.txt +0 -1
- package/src/media/templates/packages/figma/src/types/_.gitignore.txt +0 -1
- package/src/media/templates/packages/figma/src/vite-env.d.ts +0 -1
- package/src/media/templates/packages/figma/tsconfig.app.json +0 -12
- package/src/media/templates/packages/figma/tsconfig.json +0 -7
- package/src/media/templates/packages/figma/tsconfig.node.json +0 -8
- package/src/media/templates/packages/figma/vite.config.ts +0 -7
- package/src/media/templates/packages/library/README.md +0 -1
- package/src/media/templates/packages/library/_.gitignore.txt +0 -27
- package/src/media/templates/packages/library/ai-description.md +0 -15
- package/src/media/templates/packages/library/design.config.json +0 -3
- package/src/media/templates/packages/library/index.html +0 -12
- package/src/media/templates/packages/library/materials/README.md +0 -8
- package/src/media/templates/packages/library/materials/prompt.md +0 -45
- package/src/media/templates/packages/library/package.json +0 -46
- package/src/media/templates/packages/library/src/App.vue +0 -8
- package/src/media/templates/packages/library/src/classes/_.gitignore.txt +0 -1
- package/src/media/templates/packages/library/src/components/_.gitignore.txt +0 -1
- package/src/media/templates/packages/library/src/composables/_.gitignore.txt +0 -1
- package/src/media/templates/packages/library/src/functions/_.gitignore.txt +0 -1
- package/src/media/templates/packages/library/src/library.ts +0 -0
- package/src/media/templates/packages/library/src/main.ts +0 -6
- package/src/media/templates/packages/library/src/style.scss +0 -0
- package/src/media/templates/packages/library/src/types/_.gitignore.txt +0 -1
- package/src/media/templates/packages/library/src/vite-env.d.ts +0 -1
- package/src/media/templates/packages/library/tsconfig.app.json +0 -11
- package/src/media/templates/packages/library/tsconfig.json +0 -7
- package/src/media/templates/packages/library/tsconfig.node.json +0 -7
- package/src/media/templates/packages/library/vite.config.ts +0 -14
- package/src/media/templates/packages/nitro/README.md +0 -1
- package/src/media/templates/packages/nitro/_.gitignore.txt +0 -28
- package/src/media/templates/packages/nitro/index.html +0 -2
- package/src/media/templates/packages/nitro/package.json +0 -25
- package/src/media/templates/packages/nitro/server/plugins/ui-plugin.ts +0 -7
- package/src/media/templates/packages/nitro/server/routes/api/hello.ts +0 -13
- package/src/media/templates/packages/nitro/src/App.vue +0 -10
- package/src/media/templates/packages/nitro/src/assets/_.gitignore.txt +0 -0
- package/src/media/templates/packages/nitro/src/components/_.gitignore.txt +0 -0
- package/src/media/templates/packages/nitro/src/composables/_.gitignore.txt +0 -0
- package/src/media/templates/packages/nitro/src/entry-client.ts +0 -13
- package/src/media/templates/packages/nitro/src/entry-server.ts +0 -29
- package/src/media/templates/packages/nitro/src/main.ts +0 -14
- package/src/media/templates/packages/nitro/src/pages/HomePage.vue +0 -8
- package/src/media/templates/packages/nitro/src/router.ts +0 -11
- package/src/media/templates/packages/nitro/src/style.scss +0 -0
- package/src/media/templates/packages/nitro/src/templates/main.html +0 -21
- package/src/media/templates/packages/nitro/src/vite-env.d.ts +0 -11
- package/src/media/templates/packages/nitro/tsconfig.app.json +0 -14
- package/src/media/templates/packages/nitro/tsconfig.json +0 -7
- package/src/media/templates/packages/nitro/tsconfig.node.json +0 -12
- package/src/media/templates/packages/nitro/vite.config.ts +0 -17
- package/src/media/templates/packages/project/README.md +0 -1
- package/src/media/templates/packages/project/_.gitignore.txt +0 -28
- package/src/media/templates/packages/project/design.config.json +0 -3
- package/src/media/templates/packages/project/index.html +0 -12
- package/src/media/templates/packages/project/materials/README.md +0 -8
- package/src/media/templates/packages/project/materials/prompt.md +0 -41
- package/src/media/templates/packages/project/package.json +0 -13
- package/src/media/templates/packages/project/public/_.gitignore.txt +0 -0
- package/src/media/templates/packages/project/src/App.vue +0 -12
- package/src/media/templates/packages/project/src/assets/_.gitignore.txt +0 -0
- package/src/media/templates/packages/project/src/components/_.gitignore.txt +0 -0
- package/src/media/templates/packages/project/src/composables/_.gitignore.txt +0 -0
- package/src/media/templates/packages/project/src/main.ts +0 -6
- package/src/media/templates/packages/project/src/style.scss +0 -0
- package/src/media/templates/packages/project/src/vite-env.d.ts +0 -1
- package/src/media/templates/packages/project/tsconfig.app.json +0 -11
- package/src/media/templates/packages/project/tsconfig.json +0 -7
- package/src/media/templates/packages/project/tsconfig.node.json +0 -7
- package/src/media/templates/packages/project/vite.config.ts +0 -7
- package/src/media/templates/prompts/aiCodeGlobalPrompt.en.md +0 -22
- package/src/media/templates/prompts/aiCodeGlobalPrompt.ru.md +0 -21
- package/src/media/templates/prompts/aiCodeVuePrompt.en.md +0 -17
- package/src/media/templates/prompts/aiCodeVuePrompt.ru.md +0 -17
- package/src/media/templates/prompts/aiDocClassPrompt.en.txt +0 -63
- package/src/media/templates/prompts/aiDocClassPrompt.ru.txt +0 -63
- package/src/media/templates/prompts/aiDocComposablePrompt.en.txt +0 -67
- package/src/media/templates/prompts/aiDocComposablePrompt.ru.txt +0 -67
- package/src/media/templates/prompts/aiDocFunctionPrompt.en.txt +0 -57
- package/src/media/templates/prompts/aiDocFunctionPrompt.ru.txt +0 -57
- package/src/media/templates/prompts/componentPrompt.en.txt +0 -182
- package/src/media/templates/prompts/componentPrompt.ru.txt +0 -182
- package/src/media/templates/prompts/demoClassEn.mdx +0 -111
- package/src/media/templates/prompts/demoClassRu.mdx +0 -111
- package/src/media/templates/prompts/demoComponentEn.mdx +0 -282
- package/src/media/templates/prompts/demoComponentRu.mdx +0 -282
- package/src/media/templates/prompts/demoComposableEn.mdx +0 -103
- package/src/media/templates/prompts/demoComposableRu.mdx +0 -103
- package/src/media/templates/prompts/demoDocEn.mdx +0 -30
- package/src/media/templates/prompts/demoDocRu.mdx +0 -30
- package/src/media/templates/viteComponentTemplateConfig.ts +0 -14
- package/src/types/aiTypes.ts +0 -19
- package/src/types/configTypes.ts +0 -69
- package/src/types/designTypes.ts +0 -167
- package/src/types/figmaApiTypes.ts +0 -337
- package/src/types/gitTypes.ts +0 -59
- package/src/types/libraryTypes.ts +0 -49
- package/src/types/propertyTypes.ts +0 -586
- package/src/types/screenshotTypes.ts +0 -55
- package/src/types/webTypes.ts +0 -134
- package/src/vite-env.d.ts +0 -1
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { OpenAI } from 'openai'
|
|
2
|
-
import { forEach } from '@dxtmisha/functional-basic'
|
|
3
|
-
|
|
4
|
-
import { AiAbstract } from './AiAbstract'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* OpenAI implementation of AiAbstract.
|
|
8
|
-
* Initializes OpenAI client and performs text generation requests.
|
|
9
|
-
*
|
|
10
|
-
* Реализация OpenAI поверх AiAbstract.
|
|
11
|
-
* Инициализирует клиент OpenAI и выполняет запросы генерации текста.
|
|
12
|
-
*
|
|
13
|
-
* Responsibilities / Ответственности:
|
|
14
|
-
* - Provide API key / Предоставить API ключ
|
|
15
|
-
* - Initialize OpenAI client / Инициализировать клиент OpenAI
|
|
16
|
-
* - Call chat.completions.create and extract text content / Вызвать chat.completions.create и извлечь текст
|
|
17
|
-
*
|
|
18
|
-
* Notes / Примечания:
|
|
19
|
-
* - Model must be set via setModel() before generate() / Модель нужно задать через setModel()
|
|
20
|
-
* - Returns empty string if response is missing / Возвращает пустую строку при отсутствии результата
|
|
21
|
-
*/
|
|
22
|
-
export class AiOpenAiLite extends AiAbstract<OpenAI> {
|
|
23
|
-
/**
|
|
24
|
-
* Initializes OpenAI client instance.
|
|
25
|
-
*
|
|
26
|
-
* Инициализирует экземпляр клиента OpenAI.
|
|
27
|
-
*/
|
|
28
|
-
protected init(): void {
|
|
29
|
-
this.ai = new OpenAI({
|
|
30
|
-
apiKey: this.key
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Implementation hook: convert accumulated images to model-specific format.
|
|
36
|
-
* OpenAI expects images as content blocks with type 'image_url'.
|
|
37
|
-
*
|
|
38
|
-
* Хук реализации: преобразовать накопленные изображения в формат, специфичный для модели.
|
|
39
|
-
* OpenAI ожидает изображения как блоки контента с типом 'image_url'.
|
|
40
|
-
*/
|
|
41
|
-
protected toImages(): any {
|
|
42
|
-
return forEach(this.images, image => ({
|
|
43
|
-
type: 'image_url',
|
|
44
|
-
image_url: {
|
|
45
|
-
url: `data:${image.mime};base64,${image.base64}`
|
|
46
|
-
}
|
|
47
|
-
}))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Implementation hook: convert accumulated contents to model-specific format.
|
|
52
|
-
* OpenAI expects text as content blocks with type 'text'.
|
|
53
|
-
*
|
|
54
|
-
* Хук реализации: преобразовать накопленное содержимое в формат, специфичный для модели.
|
|
55
|
-
* OpenAI ожидает текст как блоки контента с типом 'text'.
|
|
56
|
-
*/
|
|
57
|
-
protected toContents(): any {
|
|
58
|
-
return forEach(this.contents, content => ({
|
|
59
|
-
type: 'text',
|
|
60
|
-
text: content
|
|
61
|
-
}))
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Performs content generation request and returns textual result.
|
|
66
|
-
*
|
|
67
|
-
* Выполняет запрос генерации контента и возвращает текстовый результат.
|
|
68
|
-
* @param model Model identifier (e.g., 'gpt-4o') / Идентификатор модели
|
|
69
|
-
* @param contents Composed contents for generation / Собранный контент для генерации
|
|
70
|
-
*/
|
|
71
|
-
protected async response(
|
|
72
|
-
model: string,
|
|
73
|
-
contents: string
|
|
74
|
-
): Promise<string> {
|
|
75
|
-
console.log('asd', this.ai?.baseURL, JSON.stringify({
|
|
76
|
-
model,
|
|
77
|
-
messages: [
|
|
78
|
-
{
|
|
79
|
-
role: 'user',
|
|
80
|
-
content: [
|
|
81
|
-
...this.toImages(),
|
|
82
|
-
...this.toContents(),
|
|
83
|
-
{ type: 'text', text: contents }
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
],
|
|
87
|
-
...this.config
|
|
88
|
-
}))
|
|
89
|
-
|
|
90
|
-
const response = await this.ai?.chat.completions.create({
|
|
91
|
-
model,
|
|
92
|
-
messages: [
|
|
93
|
-
{
|
|
94
|
-
role: 'user',
|
|
95
|
-
content: [
|
|
96
|
-
...this.toImages(),
|
|
97
|
-
...this.toContents(),
|
|
98
|
-
{ type: 'text', text: contents }
|
|
99
|
-
]
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
|
-
...this.config
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
return response?.choices?.[0]?.message?.content ?? ''
|
|
106
|
-
}
|
|
107
|
-
}
|
package/src/classes/Ai/AiZAi.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getConfigAi } from '../../functions/getConfigAi'
|
|
2
|
-
import { AiZAiLite } from './AiZAiLite'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Z.ai (Zhipu AI) implementation extending AiZAiLite.
|
|
6
|
-
* Automatically configured using project environment settings.
|
|
7
|
-
*
|
|
8
|
-
* Реализация Z.ai (Zhipu AI) расширяющая AiZAiLite.
|
|
9
|
-
* Автоматически настраивается с использованием настроек окружения проекта.
|
|
10
|
-
*/
|
|
11
|
-
export class AiZAi extends AiZAiLite {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(
|
|
14
|
-
...getConfigAi()
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { createXai, type XaiProvider } from '@ai-sdk/xai'
|
|
2
|
-
import { generateText } from 'ai'
|
|
3
|
-
import { forEach } from '@dxtmisha/functional-basic'
|
|
4
|
-
|
|
5
|
-
import { AiAbstract } from './AiAbstract'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* xAI (Grok) implementation of AiAbstract using @ai-sdk/xai and ai SDK.
|
|
9
|
-
* Performs text generation requests via Grok models (e.g. grok-4.5).
|
|
10
|
-
*
|
|
11
|
-
* Реализация xAI (Grok) поверх AiAbstract с использованием @ai-sdk/xai и ai SDK.
|
|
12
|
-
* Выполняет запросы генерации текста через модели Grok (например, grok-4.5).
|
|
13
|
-
*
|
|
14
|
-
* Responsibilities / Ответственности:
|
|
15
|
-
* - Initialize xAI client provider / Инициализировать провайдер клиента xAI
|
|
16
|
-
* - Execute generateText via Grok responses model / Выполнять generateText через модель ответов Grok
|
|
17
|
-
*/
|
|
18
|
-
export class AiZAiLite extends AiAbstract<XaiProvider> {
|
|
19
|
-
/**
|
|
20
|
-
* Initializes xAI client provider instance.
|
|
21
|
-
*
|
|
22
|
-
* Инициализирует экземпляр провайдера клиента xAI.
|
|
23
|
-
*/
|
|
24
|
-
protected init(): void {
|
|
25
|
-
this.ai = createXai({
|
|
26
|
-
apiKey: this.key
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Implementation hook: convert accumulated images to model-specific format.
|
|
32
|
-
*
|
|
33
|
-
* Хук реализации: преобразовать накопленные изображения в формат, специфичный для модели.
|
|
34
|
-
*/
|
|
35
|
-
protected toImages(): any[] {
|
|
36
|
-
return forEach(this.images, image => ({
|
|
37
|
-
type: 'image',
|
|
38
|
-
image: `data:${image.mime};base64,${image.base64}`
|
|
39
|
-
}))
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Implementation hook: convert accumulated contents to model-specific format.
|
|
44
|
-
*
|
|
45
|
-
* Хук реализации: преобразовать накопленное содержимое в формат, специфичный для модели.
|
|
46
|
-
*/
|
|
47
|
-
protected toContents(): any[] {
|
|
48
|
-
return forEach(this.contents, content => ({
|
|
49
|
-
type: 'text',
|
|
50
|
-
text: content
|
|
51
|
-
}))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Performs content generation request using xAI responses model and returns textual result.
|
|
56
|
-
*
|
|
57
|
-
* Выполняет запрос генерации контента с использованием модели ответов xAI и возвращает текстовый результат.
|
|
58
|
-
* @param model - Model identifier (e.g., 'grok-4.5') / Идентификатор модели
|
|
59
|
-
* @param contents - Composed contents for generation / Собранный контент для генерации
|
|
60
|
-
* @returns Generated text response / Сгенерированный текстовый ответ
|
|
61
|
-
*/
|
|
62
|
-
protected async response(
|
|
63
|
-
model: string,
|
|
64
|
-
contents: string
|
|
65
|
-
): Promise<string> {
|
|
66
|
-
const client = this.ai ?? createXai({ apiKey: this.key })
|
|
67
|
-
const activeModel = model || 'grok-4.5'
|
|
68
|
-
|
|
69
|
-
const { text } = await generateText({
|
|
70
|
-
model: client.responses(activeModel as any),
|
|
71
|
-
prompt: contents,
|
|
72
|
-
...this.config
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
return text ?? ''
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/classes/Ai/ApiTmp.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { PropertiesFile } from '../Properties/PropertiesFile'
|
|
2
|
-
|
|
3
|
-
const TEMPORARY_DIR = './ai-tmp'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* ApiTmp
|
|
7
|
-
*/
|
|
8
|
-
export class ApiTmp {
|
|
9
|
-
protected idFile = 1
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Generates a unique file path for the temporary prompt.
|
|
13
|
-
*
|
|
14
|
-
* Генерирует уникальный путь к файлу для временного промпта.
|
|
15
|
-
*/
|
|
16
|
-
protected getFileName(): string {
|
|
17
|
-
return `${TEMPORARY_DIR}/Prompt-${this.idFile++}.txt`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Creates a temporary file with the prompt content and returns the path formatted for the CLI.
|
|
22
|
-
*
|
|
23
|
-
* Создает временный файл с содержимым промпта и возвращает путь, отформатированный для CLI.
|
|
24
|
-
* @param content Prompt content / Содержимое промпта
|
|
25
|
-
* @returns Formatted file path (e.g., @./ai-tmp/Prompt-1.txt) / Отформатированный путь к файлу
|
|
26
|
-
*/
|
|
27
|
-
createFile(content: string): string {
|
|
28
|
-
const name = this.getFileName()
|
|
29
|
-
|
|
30
|
-
PropertiesFile.writeByPath(name, content.trim())
|
|
31
|
-
|
|
32
|
-
return `Please read the following file as it contains the prompt instructions: @${name}`
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Cleans up temporary files and directories.
|
|
37
|
-
*
|
|
38
|
-
* Очищает временные файлы и директории.
|
|
39
|
-
*/
|
|
40
|
-
removeFile(): void {
|
|
41
|
-
PropertiesFile.removeDir(TEMPORARY_DIR)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Browser,
|
|
3
|
-
type EvaluateFunc,
|
|
4
|
-
type HTTPResponse,
|
|
5
|
-
launch,
|
|
6
|
-
type Page,
|
|
7
|
-
type PuppeteerLifeCycleEvent
|
|
8
|
-
} from 'puppeteer'
|
|
9
|
-
import { sleep } from '@dxtmisha/functional-basic'
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
type ScreenshotMetrics,
|
|
13
|
-
type ScreenshotOptions,
|
|
14
|
-
SCREENSHOT_ARGS,
|
|
15
|
-
SCREENSHOT_FORMAT,
|
|
16
|
-
SCREENSHOT_HEIGHTS,
|
|
17
|
-
SCREENSHOT_TIMEOUT,
|
|
18
|
-
SCREENSHOT_QUALITY,
|
|
19
|
-
SCREENSHOT_WAIT_UNTIL,
|
|
20
|
-
SCREENSHOT_WIDTHS
|
|
21
|
-
} from '../types/screenshotTypes'
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Class for managing browser instances and taking screenshots using Puppeteer.
|
|
25
|
-
*
|
|
26
|
-
* Класс для управления экземплярами браузера и создания скриншотов с помощью Puppeteer.
|
|
27
|
-
*/
|
|
28
|
-
export class BrowserItem {
|
|
29
|
-
/** Browser instance / Экземпляр браузера */
|
|
30
|
-
protected browser?: Browser
|
|
31
|
-
|
|
32
|
-
/** Page instance / Экземпляр страницы */
|
|
33
|
-
protected page?: Page
|
|
34
|
-
|
|
35
|
-
/** HTTP Response from page loading / HTTP-ответ при загрузке страницы */
|
|
36
|
-
protected response?: HTTPResponse
|
|
37
|
-
|
|
38
|
-
/** Total scrollable width of the loaded page / Полная прокручиваемая ширина загруженной страницы */
|
|
39
|
-
protected pageWidth: number = -1
|
|
40
|
-
|
|
41
|
-
/** Total scrollable height of the loaded page / Полная прокручиваемая высота загруженной страницы */
|
|
42
|
-
protected pageHeight: number = -1
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Constructor
|
|
46
|
-
* @param url component path / путь к компоненту
|
|
47
|
-
* @param options additional options for capture / дополнительные опции захвата
|
|
48
|
-
*/
|
|
49
|
-
constructor(
|
|
50
|
-
protected url: string,
|
|
51
|
-
protected readonly options: ScreenshotOptions = {}
|
|
52
|
-
) {
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Additional arguments for browser launch / Дополнительные аргументы для запуска браузера */
|
|
56
|
-
get args(): string[] {
|
|
57
|
-
return this.options.args ?? SCREENSHOT_ARGS
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Condition to wait for when navigating to the page / Условие, которое нужно дождаться при переходе на страницу */
|
|
61
|
-
get waitUntil(): PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[] {
|
|
62
|
-
return this.options.waitUntil ?? SCREENSHOT_WAIT_UNTIL
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Timeout for navigating to the page / Таймаут для перехода на страницу */
|
|
66
|
-
get timeout(): number {
|
|
67
|
-
return this.options.timeout ?? SCREENSHOT_TIMEOUT
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** Image format for screenshots / Формат изображения для скриншотов */
|
|
71
|
-
get format(): ScreenshotOptions['format'] {
|
|
72
|
-
return this.options.format ?? SCREENSHOT_FORMAT
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Viewport width for the initial capture / Ширина порта просмотра для начального захвата */
|
|
76
|
-
get width(): number {
|
|
77
|
-
return this.options.width ?? SCREENSHOT_WIDTHS
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Viewport height for the initial capture and page-by-page slicing / Высота порта просмотра для начального захвата и постраничной нарезки */
|
|
81
|
-
get height(): number {
|
|
82
|
-
return this.options.height ?? SCREENSHOT_HEIGHTS
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Quality for JPEG/WebP formats (0-100) / Качество для форматов JPEG/WebP (0-100) */
|
|
86
|
-
get quality(): number {
|
|
87
|
-
return this.options.quality ?? SCREENSHOT_QUALITY
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** Whether to capture the whole scrollable page at once or in slices / Захватывать ли всю прокручиваемую страницу сразу или по частям */
|
|
91
|
-
get fullPage(): boolean {
|
|
92
|
-
return this.options.fullPage ?? false
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** File extension based on the selected format / Расширение файла на основе выбранного формата */
|
|
96
|
-
get extension(): string {
|
|
97
|
-
const format = this.format
|
|
98
|
-
|
|
99
|
-
if (format === 'jpeg') {
|
|
100
|
-
return '.jpg'
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return `.${format}`
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* launches or returns the browser instance.
|
|
108
|
-
*
|
|
109
|
-
* Запускает или возвращает экземпляр браузера.
|
|
110
|
-
* @returns browser instance / экземпляр браузера
|
|
111
|
-
*/
|
|
112
|
-
async getBrowser(): Promise<Browser> {
|
|
113
|
-
if (!this.browser) {
|
|
114
|
-
this.browser = await launch({
|
|
115
|
-
headless: true,
|
|
116
|
-
args: this.args
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return this.browser
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Creates or returns the page instance.
|
|
125
|
-
*
|
|
126
|
-
* Создает или возвращает экземпляр страницы.
|
|
127
|
-
* @returns page instance / экземпляр страницы
|
|
128
|
-
*/
|
|
129
|
-
async getPage(): Promise<Page> {
|
|
130
|
-
if (!this.page) {
|
|
131
|
-
this.page = await (await this.getBrowser()).newPage()
|
|
132
|
-
|
|
133
|
-
await this.page.setViewport({
|
|
134
|
-
width: this.width,
|
|
135
|
-
height: this.height
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
this.page.on(
|
|
139
|
-
'console',
|
|
140
|
-
msg => this.toConsole(`Log: ${msg.text()}`)
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
this.page.on(
|
|
144
|
-
'pageerror',
|
|
145
|
-
err => this.toConsole(`Error: ${(err as any)?.message}`)
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return this.page
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Navigates to the URL and returns the HTTP response.
|
|
154
|
-
*
|
|
155
|
-
* Переходит по URL и возвращает HTTP-ответ.
|
|
156
|
-
* @returns HTTP response or undefined / HTTP-ответ или undefined
|
|
157
|
-
*/
|
|
158
|
-
async getResponse(): Promise<HTTPResponse | undefined> {
|
|
159
|
-
if (!this.response) {
|
|
160
|
-
const response = await (await this.getPage()).goto(this.url, {
|
|
161
|
-
waitUntil: this.waitUntil,
|
|
162
|
-
timeout: this.timeout
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
response
|
|
167
|
-
&& response.ok()
|
|
168
|
-
) {
|
|
169
|
-
this.response = response
|
|
170
|
-
} else {
|
|
171
|
-
this.toConsole(
|
|
172
|
-
`Failed to load page: ${this.url}. Status: ${response?.status()}`
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return this.response
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Retrieves the HTML content of the page.
|
|
182
|
-
*
|
|
183
|
-
* Извлекает HTML-содержимое страницы.
|
|
184
|
-
* @returns html content string / HTML-содержимое
|
|
185
|
-
*/
|
|
186
|
-
async getDom(): Promise<string> {
|
|
187
|
-
return await (await this.getPage()).content()
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Retrieves the HTML content of the body.
|
|
192
|
-
*
|
|
193
|
-
* Извлекает HTML-содержимое тела (body) страницы.
|
|
194
|
-
* @returns body html content string / HTML-содержимое body
|
|
195
|
-
*/
|
|
196
|
-
async getBody(): Promise<string> {
|
|
197
|
-
return await this.evaluate(() => document.body.innerHTML) ?? ''
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Retrieves all CSS styles from the page.
|
|
202
|
-
*
|
|
203
|
-
* Извлекает все CSS-стили со страницы.
|
|
204
|
-
* @returns CSS content string / CSS-содержимое
|
|
205
|
-
*/
|
|
206
|
-
async getStyles(): Promise<string> {
|
|
207
|
-
return await this.evaluate(() => {
|
|
208
|
-
return Array.from(document.styleSheets)
|
|
209
|
-
.map((sheet) => {
|
|
210
|
-
try {
|
|
211
|
-
return Array.from(sheet.cssRules)
|
|
212
|
-
.map(rule => rule.cssText)
|
|
213
|
-
.join('\n')
|
|
214
|
-
} catch (e) {
|
|
215
|
-
console.error('Error getting CSS rules:', e)
|
|
216
|
-
return ''
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
.join('\n')
|
|
220
|
-
}) ?? ''
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Extracts scrollable dimensions of the page.
|
|
225
|
-
*
|
|
226
|
-
* Извлекает прокручиваемые размеры страницы.
|
|
227
|
-
* @returns object with width and height / объект с шириной и высотой
|
|
228
|
-
*/
|
|
229
|
-
async getMetrics(): Promise<ScreenshotMetrics> {
|
|
230
|
-
if (
|
|
231
|
-
await this.getResponse()
|
|
232
|
-
&& (
|
|
233
|
-
this.pageWidth === -1
|
|
234
|
-
|| this.pageHeight === -1
|
|
235
|
-
)
|
|
236
|
-
) {
|
|
237
|
-
const metrics = await this.evaluate(() => {
|
|
238
|
-
return {
|
|
239
|
-
height: document.documentElement.scrollHeight,
|
|
240
|
-
width: document.documentElement.scrollWidth
|
|
241
|
-
}
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
if (metrics) {
|
|
245
|
-
this.pageWidth = metrics.width
|
|
246
|
-
this.pageHeight = metrics.height
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
height: this.pageHeight,
|
|
252
|
-
width: this.pageWidth
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Evaluates a function in the browser context.
|
|
258
|
-
*
|
|
259
|
-
* Выполняет функцию в контексте браузера.
|
|
260
|
-
* @param pageFunction function to evaluate / функция для выполнения
|
|
261
|
-
* @param args arguments for the function / аргументы для функции
|
|
262
|
-
* @returns result of evaluation / результат выполнения
|
|
263
|
-
*/
|
|
264
|
-
async evaluate<
|
|
265
|
-
Params extends unknown[],
|
|
266
|
-
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>
|
|
267
|
-
>(
|
|
268
|
-
pageFunction: Func | string,
|
|
269
|
-
...args: Params
|
|
270
|
-
): Promise<Awaited<ReturnType<Func>> | undefined> {
|
|
271
|
-
return await (await this.getPage()).evaluate<Params, Func>(
|
|
272
|
-
pageFunction,
|
|
273
|
-
...args
|
|
274
|
-
)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Captures screenshots based on the fullPage option.
|
|
279
|
-
*
|
|
280
|
-
* Создает скриншоты в зависимости от опции fullPage.
|
|
281
|
-
* @param outputPath base path for saving / базовый путь для сохранения
|
|
282
|
-
* @returns this instance / этот экземпляр
|
|
283
|
-
*/
|
|
284
|
-
async screenshot(outputPath: string): Promise<this> {
|
|
285
|
-
if (this.fullPage) {
|
|
286
|
-
await this.screenshotFull(outputPath)
|
|
287
|
-
} else {
|
|
288
|
-
await this.screenshotPages(outputPath)
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return this
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Resets internal page and response states.
|
|
296
|
-
*
|
|
297
|
-
* Сбрасывает состояние страницы и ответа.
|
|
298
|
-
* @returns this instance / этот экземпляр
|
|
299
|
-
*/
|
|
300
|
-
async reset(): Promise<this> {
|
|
301
|
-
this.page = undefined
|
|
302
|
-
this.pageWidth = -1
|
|
303
|
-
this.pageHeight = -1
|
|
304
|
-
|
|
305
|
-
this.response = undefined
|
|
306
|
-
|
|
307
|
-
return this
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Formats the final file path based on current state and index.
|
|
312
|
-
*
|
|
313
|
-
* Форматирует итоговый путь к файлу на основе состояния и индекса.
|
|
314
|
-
* @param outputPath original output path / исходный путь сохранения
|
|
315
|
-
* @param index current page index / текущий индекс страницы
|
|
316
|
-
* @param max total pages count / общее количество страниц
|
|
317
|
-
* @returns formatted path string / отформатированная строка пути
|
|
318
|
-
*/
|
|
319
|
-
protected getOutputPath(
|
|
320
|
-
outputPath: string,
|
|
321
|
-
index: number = 1,
|
|
322
|
-
max: number = 1
|
|
323
|
-
): string {
|
|
324
|
-
if (this.fullPage) {
|
|
325
|
-
return outputPath + this.extension
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return outputPath + `-${max}_${index}` + this.extension
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Internal wrapper for Puppeteer's screenshot method.
|
|
333
|
-
*
|
|
334
|
-
* Внутренняя обертка для метода скриншота Puppeteer.
|
|
335
|
-
* @param path specific file path / путь к конкретному файлу
|
|
336
|
-
* @returns this instance / этот экземпляр
|
|
337
|
-
*/
|
|
338
|
-
protected async saveScreenshot(path: string): Promise<this> {
|
|
339
|
-
const type = this.format
|
|
340
|
-
const quality = type === 'png' ? undefined : this.quality
|
|
341
|
-
|
|
342
|
-
await (await this.getPage()).screenshot({
|
|
343
|
-
path,
|
|
344
|
-
type,
|
|
345
|
-
quality,
|
|
346
|
-
fullPage: this.fullPage
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
return this
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Iterates through page slices and saves multiple screenshots.
|
|
354
|
-
*
|
|
355
|
-
* Проходит по частям страницы и сохраняет несколько скриншотов.
|
|
356
|
-
* @param outputPath base output path / базовый путь сохранения
|
|
357
|
-
* @returns this instance / этот экземпляр
|
|
358
|
-
*/
|
|
359
|
-
protected async screenshotPages(outputPath: string): Promise<this> {
|
|
360
|
-
const {
|
|
361
|
-
height: pageHeight
|
|
362
|
-
} = await this.getMetrics()
|
|
363
|
-
|
|
364
|
-
const viewportHeight = this.height
|
|
365
|
-
const pages = Math.ceil(pageHeight / viewportHeight)
|
|
366
|
-
|
|
367
|
-
this.toConsole(`Page height: ${pageHeight}px, viewport height: ${viewportHeight}px, total pages: ${pages}`)
|
|
368
|
-
|
|
369
|
-
for (let i = 0; i < pages; i++) {
|
|
370
|
-
const currentY = i * viewportHeight
|
|
371
|
-
const fileOutputPath = this.getOutputPath(outputPath, i + 1, pages)
|
|
372
|
-
|
|
373
|
-
await this.evaluate(y => window.scrollTo(0, y), currentY)
|
|
374
|
-
await sleep(320)
|
|
375
|
-
await this.saveScreenshot(fileOutputPath)
|
|
376
|
-
|
|
377
|
-
this.toConsole(`Saved screenshot page ${i + 1}/${pages} to ${fileOutputPath}`)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return this
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Captures a single full page screenshot.
|
|
385
|
-
*
|
|
386
|
-
* Создает один скриншот всей страницы.
|
|
387
|
-
* @param outputPath output path / путь сохранения
|
|
388
|
-
* @returns this instance / этот экземпляр
|
|
389
|
-
*/
|
|
390
|
-
protected async screenshotFull(outputPath: string): Promise<this> {
|
|
391
|
-
const outputPathFull = this.getOutputPath(outputPath)
|
|
392
|
-
await this.saveScreenshot(outputPathFull)
|
|
393
|
-
|
|
394
|
-
this.toConsole(`Saved full page screenshot to ${outputPathFull}`)
|
|
395
|
-
|
|
396
|
-
return this
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Logs text with a "Browser" prefix.
|
|
401
|
-
*
|
|
402
|
-
* Выводит текст в консоль с префиксом "Browser".
|
|
403
|
-
* @param text text to log / текст для вывода
|
|
404
|
-
*/
|
|
405
|
-
protected toConsole(text: string): void {
|
|
406
|
-
console.log('Browser', text)
|
|
407
|
-
}
|
|
408
|
-
}
|