@webiny/ai-powerups 6.3.0 → 6.4.0-beta.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/AiPowerups.js +8 -9
- package/AiPowerups.js.map +1 -1
- package/admin/Extension.js +28 -26
- package/admin/Extension.js.map +1 -1
- package/admin/domain/errors.d.ts +12 -0
- package/admin/domain/errors.js +21 -0
- package/admin/domain/errors.js.map +1 -0
- package/admin/features/feature.js +13 -12
- package/admin/features/feature.js.map +1 -1
- package/admin/features/generatePageContent/GeneratePageContentGateway.js +35 -16
- package/admin/features/generatePageContent/GeneratePageContentGateway.js.map +1 -1
- package/admin/features/generatePageContent/GeneratePageContentUseCase.js +13 -10
- package/admin/features/generatePageContent/GeneratePageContentUseCase.js.map +1 -1
- package/admin/features/generatePageContent/abstractions.d.ts +4 -0
- package/admin/features/generatePageContent/abstractions.js +3 -2
- package/admin/features/generatePageContent/abstractions.js.map +1 -1
- package/admin/features/generatePageContent/feature.js +7 -6
- package/admin/features/generatePageContent/feature.js.map +1 -1
- package/admin/features/generatePageContent/index.js +1 -3
- package/admin/features/listModels/ListModelsGateway.js +17 -14
- package/admin/features/listModels/ListModelsGateway.js.map +1 -1
- package/admin/features/listModels/ListModelsRepository.js +21 -18
- package/admin/features/listModels/ListModelsRepository.js.map +1 -1
- package/admin/features/listModels/ListModelsUseCase.js +13 -10
- package/admin/features/listModels/ListModelsUseCase.js.map +1 -1
- package/admin/features/listModels/abstractions.js +4 -3
- package/admin/features/listModels/abstractions.js.map +1 -1
- package/admin/features/listModels/feature.js +15 -14
- package/admin/features/listModels/feature.js.map +1 -1
- package/admin/features/listModels/index.js +1 -3
- package/admin/features/settings/getSettings/GetSettingsGateway.js +17 -14
- package/admin/features/settings/getSettings/GetSettingsGateway.js.map +1 -1
- package/admin/features/settings/getSettings/GetSettingsRepository.js +23 -23
- package/admin/features/settings/getSettings/GetSettingsRepository.js.map +1 -1
- package/admin/features/settings/getSettings/GetSettingsUseCase.js +13 -10
- package/admin/features/settings/getSettings/GetSettingsUseCase.js.map +1 -1
- package/admin/features/settings/getSettings/abstractions.js +4 -3
- package/admin/features/settings/getSettings/abstractions.js.map +1 -1
- package/admin/features/settings/getSettings/feature.js +15 -14
- package/admin/features/settings/getSettings/feature.js.map +1 -1
- package/admin/features/settings/getSettings/index.js +1 -3
- package/admin/features/settings/shared/SettingsCache.js +14 -13
- package/admin/features/settings/shared/SettingsCache.js.map +1 -1
- package/admin/features/settings/shared/abstractions.d.ts +32 -0
- package/admin/features/settings/shared/abstractions.js +2 -18
- package/admin/features/settings/shared/abstractions.js.map +1 -1
- package/admin/features/settings/shared/feature.js +11 -10
- package/admin/features/settings/shared/feature.js.map +1 -1
- package/admin/features/settings/shared/index.js +0 -2
- package/admin/features/settings/updateSettings/UpdateSettingsGateway.js +34 -18
- package/admin/features/settings/updateSettings/UpdateSettingsGateway.js.map +1 -1
- package/admin/features/settings/updateSettings/UpdateSettingsRepository.js +17 -13
- package/admin/features/settings/updateSettings/UpdateSettingsRepository.js.map +1 -1
- package/admin/features/settings/updateSettings/UpdateSettingsUseCase.js +13 -10
- package/admin/features/settings/updateSettings/UpdateSettingsUseCase.js.map +1 -1
- package/admin/features/settings/updateSettings/abstractions.js +4 -3
- package/admin/features/settings/updateSettings/abstractions.js.map +1 -1
- package/admin/features/settings/updateSettings/feature.js +15 -14
- package/admin/features/settings/updateSettings/feature.js.map +1 -1
- package/admin/features/settings/updateSettings/index.js +1 -3
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPage.d.ts +4 -0
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPage.js +50 -0
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPage.js.map +1 -0
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.d.ts +2 -1
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.js +133 -129
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.js.map +1 -1
- package/admin/presentation/AiPowerUpsSettings/abstractions.d.ts +2 -1
- package/admin/presentation/AiPowerUpsSettings/abstractions.js +2 -1
- package/admin/presentation/AiPowerUpsSettings/abstractions.js.map +1 -1
- package/admin/presentation/AiPowerUpsSettings/feature.js +20 -16
- package/admin/presentation/AiPowerUpsSettings/feature.js.map +1 -1
- package/admin/presentation/AiPowerUpsSettings/index.d.ts +0 -3
- package/admin/presentation/AiPowerUpsSettings/index.js +0 -5
- package/admin/presentation/AiPowerUpsSettings/settingsGroup.js +2 -1
- package/admin/presentation/AiPowerUpsSettings/settingsGroup.js.map +1 -1
- package/admin/presentation/AiPowerUpsSettings/useAiPowerUpsSettings.js +19 -20
- package/admin/presentation/AiPowerUpsSettings/useAiPowerUpsSettings.js.map +1 -1
- package/admin/presentation/{PersonasSettings.d.ts → ProjectsSettings.d.ts} +2 -2
- package/admin/presentation/ProjectsSettings.js +56 -0
- package/admin/presentation/ProjectsSettings.js.map +1 -0
- package/admin/presentation/ProvidersSettings.js +39 -33
- package/admin/presentation/ProvidersSettings.js.map +1 -1
- package/admin/presentation/ReaderPersonasSettings.d.ts +11 -0
- package/admin/presentation/ReaderPersonasSettings.js +37 -0
- package/admin/presentation/ReaderPersonasSettings.js.map +1 -0
- package/admin/presentation/WbContentGeneration/Extension.js +15 -16
- package/admin/presentation/WbContentGeneration/Extension.js.map +1 -1
- package/admin/presentation/WbContentGeneration/GenerateContentButton.js +12 -17
- package/admin/presentation/WbContentGeneration/GenerateContentButton.js.map +1 -1
- package/admin/presentation/WbContentGeneration/GenerateContentDialog.js +94 -127
- package/admin/presentation/WbContentGeneration/GenerateContentDialog.js.map +1 -1
- package/admin/presentation/WbContentGeneration/GenerateContentPresenter.d.ts +19 -5
- package/admin/presentation/WbContentGeneration/GenerateContentPresenter.js +214 -77
- package/admin/presentation/WbContentGeneration/GenerateContentPresenter.js.map +1 -1
- package/admin/presentation/WbContentGeneration/abstractions.d.ts +4 -2
- package/admin/presentation/WbContentGeneration/abstractions.js +2 -1
- package/admin/presentation/WbContentGeneration/abstractions.js.map +1 -1
- package/admin/presentation/WbContentGeneration/decompressGzipBase64.js +10 -11
- package/admin/presentation/WbContentGeneration/decompressGzipBase64.js.map +1 -1
- package/admin/presentation/WbContentGeneration/feature.js +11 -10
- package/admin/presentation/WbContentGeneration/feature.js.map +1 -1
- package/admin/presentation/WriterPersonasSettings.d.ts +11 -0
- package/admin/presentation/WriterPersonasSettings.js +37 -0
- package/admin/presentation/WriterPersonasSettings.js.map +1 -0
- package/admin/routes.d.ts +4 -0
- package/admin/routes.js +10 -0
- package/admin/routes.js.map +1 -0
- package/api/Extension.js +28 -11
- package/api/Extension.js.map +1 -1
- package/api/constants.js +2 -1
- package/api/constants.js.map +1 -1
- package/api/features/AiImageEnrichment/AiImageEnrichmentAfterCreateHandler.d.ts +11 -0
- package/api/features/AiImageEnrichment/AiImageEnrichmentAfterCreateHandler.js +27 -0
- package/api/features/AiImageEnrichment/AiImageEnrichmentAfterCreateHandler.js.map +1 -0
- package/api/features/AiImageEnrichment/AiImageEnrichmentTask.d.ts +34 -0
- package/api/features/AiImageEnrichment/AiImageEnrichmentTask.js +140 -0
- package/api/features/AiImageEnrichment/AiImageEnrichmentTask.js.map +1 -0
- package/api/features/AiImageEnrichment/feature.d.ts +4 -0
- package/api/features/AiImageEnrichment/feature.js +13 -0
- package/api/features/AiImageEnrichment/feature.js.map +1 -0
- package/api/features/AiPromptContext/AiPromptContextBuilder.d.ts +12 -0
- package/api/features/AiPromptContext/AiPromptContextBuilder.js +103 -0
- package/api/features/AiPromptContext/AiPromptContextBuilder.js.map +1 -0
- package/api/features/AiPromptContext/ProjectFileAssembler.d.ts +22 -0
- package/api/features/AiPromptContext/ProjectFileAssembler.js +76 -0
- package/api/features/AiPromptContext/ProjectFileAssembler.js.map +1 -0
- package/api/features/AiPromptContext/ProjectFileCache.d.ts +16 -0
- package/api/features/AiPromptContext/ProjectFileCache.js +61 -0
- package/api/features/AiPromptContext/ProjectFileCache.js.map +1 -0
- package/api/features/AiPromptContext/ProjectSection.d.ts +4 -0
- package/api/features/AiPromptContext/ProjectSection.js +35 -0
- package/api/features/AiPromptContext/ProjectSection.js.map +1 -0
- package/api/features/AiPromptContext/ReadProjectFileTool.d.ts +3 -0
- package/api/features/AiPromptContext/ReadProjectFileTool.js +36 -0
- package/api/features/AiPromptContext/ReadProjectFileTool.js.map +1 -0
- package/api/features/AiPromptContext/ReaderPersonaSection.d.ts +4 -0
- package/api/features/AiPromptContext/ReaderPersonaSection.js +10 -0
- package/api/features/AiPromptContext/ReaderPersonaSection.js.map +1 -0
- package/api/features/AiPromptContext/WriterPersonaSection.d.ts +4 -0
- package/api/features/AiPromptContext/WriterPersonaSection.js +10 -0
- package/api/features/AiPromptContext/WriterPersonaSection.js.map +1 -0
- package/api/features/AiPromptContext/abstractions.d.ts +68 -0
- package/api/features/AiPromptContext/abstractions.js +7 -0
- package/api/features/AiPromptContext/abstractions.js.map +1 -0
- package/api/features/AiPromptContext/feature.d.ts +4 -0
- package/api/features/AiPromptContext/feature.js +15 -0
- package/api/features/AiPromptContext/feature.js.map +1 -0
- package/api/features/AiPromptContext/index.d.ts +1 -0
- package/api/features/AiPromptContext/index.js +1 -0
- package/api/features/ExtractFrontmatter/ExtractFrontmatterBeforeCreateHandler.d.ts +11 -0
- package/api/features/ExtractFrontmatter/ExtractFrontmatterBeforeCreateHandler.js +34 -0
- package/api/features/ExtractFrontmatter/ExtractFrontmatterBeforeCreateHandler.js.map +1 -0
- package/api/features/ExtractFrontmatter/feature.d.ts +4 -0
- package/api/features/ExtractFrontmatter/feature.js +11 -0
- package/api/features/ExtractFrontmatter/feature.js.map +1 -0
- package/api/features/GetSettings/GetSettingsRepository.d.ts +3 -2
- package/api/features/GetSettings/GetSettingsRepository.js +29 -26
- package/api/features/GetSettings/GetSettingsRepository.js.map +1 -1
- package/api/features/GetSettings/GetSettingsUseCase.js +13 -10
- package/api/features/GetSettings/GetSettingsUseCase.js.map +1 -1
- package/api/features/GetSettings/abstractions.js +3 -2
- package/api/features/GetSettings/abstractions.js.map +1 -1
- package/api/features/GetSettings/feature.js +7 -6
- package/api/features/GetSettings/feature.js.map +1 -1
- package/api/features/GetSettings/index.js +0 -2
- package/api/features/Projects/ProjectsHandler.d.ts +31 -0
- package/api/features/Projects/ProjectsHandler.js +103 -0
- package/api/features/Projects/ProjectsHandler.js.map +1 -0
- package/api/features/Projects/feature.d.ts +4 -0
- package/api/features/Projects/feature.js +11 -0
- package/api/features/Projects/feature.js.map +1 -0
- package/api/features/Projects/types.d.ts +50 -0
- package/api/features/Projects/types.js +0 -0
- package/api/features/Providers/ProvidersGraphQLMapper.js +33 -30
- package/api/features/Providers/ProvidersGraphQLMapper.js.map +1 -1
- package/api/features/Providers/ProvidersHandler.js +67 -64
- package/api/features/Providers/ProvidersHandler.js.map +1 -1
- package/api/features/Providers/feature.js +7 -6
- package/api/features/Providers/feature.js.map +1 -1
- package/api/features/Providers/index.js +0 -3
- package/api/features/Providers/types.js +0 -3
- package/api/features/ReaderPersonas/ReaderPersonasHandler.d.ts +20 -0
- package/api/features/ReaderPersonas/ReaderPersonasHandler.js +43 -0
- package/api/features/ReaderPersonas/ReaderPersonasHandler.js.map +1 -0
- package/api/features/ReaderPersonas/feature.d.ts +4 -0
- package/api/features/ReaderPersonas/feature.js +11 -0
- package/api/features/ReaderPersonas/feature.js.map +1 -0
- package/api/features/ReaderPersonas/index.d.ts +2 -0
- package/api/features/ReaderPersonas/index.js +1 -0
- package/api/features/ReaderPersonas/types.d.ts +24 -0
- package/api/features/ReaderPersonas/types.js +0 -0
- package/api/features/UpdateSettings/UpdateSettingsRepository.d.ts +3 -2
- package/api/features/UpdateSettings/UpdateSettingsRepository.js +59 -62
- package/api/features/UpdateSettings/UpdateSettingsRepository.js.map +1 -1
- package/api/features/UpdateSettings/UpdateSettingsUseCase.js +23 -21
- package/api/features/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
- package/api/features/UpdateSettings/abstractions.js +5 -7
- package/api/features/UpdateSettings/abstractions.js.map +1 -1
- package/api/features/UpdateSettings/errors.d.ts +10 -0
- package/api/features/UpdateSettings/errors.js +14 -0
- package/api/features/UpdateSettings/errors.js.map +1 -0
- package/api/features/UpdateSettings/events.js +16 -11
- package/api/features/UpdateSettings/events.js.map +1 -1
- package/api/features/UpdateSettings/feature.js +7 -6
- package/api/features/UpdateSettings/feature.js.map +1 -1
- package/api/features/UpdateSettings/index.js +1 -3
- package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.d.ts +4 -0
- package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.js +63 -60
- package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.js.map +1 -1
- package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.d.ts +5 -3
- package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.js +92 -53
- package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.js.map +1 -1
- package/api/features/WbGeneratePageContent/abstractions.d.ts +15 -1
- package/api/features/WbGeneratePageContent/abstractions.js +2 -1
- package/api/features/WbGeneratePageContent/abstractions.js.map +1 -1
- package/api/features/WbGeneratePageContent/buildPrompt.d.ts +1 -1
- package/api/features/WbGeneratePageContent/buildPrompt.js +11 -10
- package/api/features/WbGeneratePageContent/buildPrompt.js.map +1 -1
- package/api/features/WbGeneratePageContent/feature.js +7 -6
- package/api/features/WbGeneratePageContent/feature.js.map +1 -1
- package/api/features/WbGeneratePageContent/index.js +0 -2
- package/api/features/WriterPersonas/WriterPersonasHandler.d.ts +20 -0
- package/api/features/WriterPersonas/WriterPersonasHandler.js +43 -0
- package/api/features/WriterPersonas/WriterPersonasHandler.js.map +1 -0
- package/api/features/WriterPersonas/feature.d.ts +4 -0
- package/api/features/WriterPersonas/feature.js +11 -0
- package/api/features/WriterPersonas/feature.js.map +1 -0
- package/api/features/WriterPersonas/index.d.ts +2 -0
- package/api/features/WriterPersonas/index.js +1 -0
- package/api/features/WriterPersonas/types.d.ts +24 -0
- package/api/features/WriterPersonas/types.js +0 -0
- package/api/features/shared/SettingsCache.d.ts +12 -0
- package/api/features/shared/SettingsCache.js +22 -0
- package/api/features/shared/SettingsCache.js.map +1 -0
- package/api/features/shared/abstractions.d.ts +13 -0
- package/api/features/shared/abstractions.js +4 -2
- package/api/features/shared/abstractions.js.map +1 -1
- package/api/features/shared/index.d.ts +3 -1
- package/api/features/shared/index.js +1 -3
- package/api/graphql/AiPowerUpsSettingsGraphQLMapper.js +35 -26
- package/api/graphql/AiPowerUpsSettingsGraphQLMapper.js.map +1 -1
- package/api/graphql/BaseGraphQLSchema.js +98 -81
- package/api/graphql/BaseGraphQLSchema.js.map +1 -1
- package/api/graphql/abstractions.js +2 -1
- package/api/graphql/abstractions.js.map +1 -1
- package/api/types.d.ts +1 -0
- package/api/types.js +1 -4
- package/index.js +0 -2
- package/package.json +26 -24
- package/admin/features/generatePageContent/index.js.map +0 -1
- package/admin/features/listModels/index.js.map +0 -1
- package/admin/features/settings/getSettings/index.js.map +0 -1
- package/admin/features/settings/shared/index.js.map +0 -1
- package/admin/features/settings/updateSettings/index.js.map +0 -1
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsConfig.d.ts +0 -2
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsConfig.js +0 -11
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsConfig.js.map +0 -1
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.d.ts +0 -5
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.js +0 -58
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.js.map +0 -1
- package/admin/presentation/AiPowerUpsSettings/index.js.map +0 -1
- package/admin/presentation/AiPowerUpsSettings/useAiPowerUpsSettingsDialog.d.ts +0 -1
- package/admin/presentation/AiPowerUpsSettings/useAiPowerUpsSettingsDialog.js +0 -12
- package/admin/presentation/AiPowerUpsSettings/useAiPowerUpsSettingsDialog.js.map +0 -1
- package/admin/presentation/PersonasSettings.js +0 -29
- package/admin/presentation/PersonasSettings.js.map +0 -1
- package/api/features/GetSettings/index.js.map +0 -1
- package/api/features/Providers/index.js.map +0 -1
- package/api/features/Providers/types.js.map +0 -1
- package/api/features/UpdateSettings/index.js.map +0 -1
- package/api/features/WbGeneratePageContent/index.js.map +0 -1
- package/api/features/shared/index.js.map +0 -1
- package/api/types.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { AiImageEnrichmentAfterCreateHandler } from "./AiImageEnrichmentAfterCreateHandler.js";
|
|
3
|
+
import { AiImageEnrichmentTask } from "./AiImageEnrichmentTask.js";
|
|
4
|
+
const AiImageEnrichmentFeature = createFeature({
|
|
5
|
+
name: "AiPowerUps/AiImageEnrichment",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(AiImageEnrichmentAfterCreateHandler);
|
|
8
|
+
container.register(AiImageEnrichmentTask);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { AiImageEnrichmentFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiImageEnrichment/feature.js","sources":["../../../../src/api/features/AiImageEnrichment/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AiImageEnrichmentAfterCreateHandler } from \"./AiImageEnrichmentAfterCreateHandler.js\";\nimport { AiImageEnrichmentTask } from \"./AiImageEnrichmentTask.js\";\n\nexport const AiImageEnrichmentFeature = createFeature({\n name: \"AiPowerUps/AiImageEnrichment\",\n register(container) {\n container.register(AiImageEnrichmentAfterCreateHandler);\n container.register(AiImageEnrichmentTask);\n }\n});\n"],"names":["AiImageEnrichmentFeature","createFeature","container","AiImageEnrichmentAfterCreateHandler","AiImageEnrichmentTask"],"mappings":";;;AAIO,MAAMA,2BAA2BC,cAAc;IAClD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GetSettingsUseCase } from "../../../api/features/GetSettings/index.js";
|
|
2
|
+
import { AiPromptContextBuilder as Abstraction, ProjectFileAssembler, type AiPromptContext, type AiPromptContextParams } from "./abstractions.js";
|
|
3
|
+
declare class AiPromptContextBuilderImpl implements Abstraction.Interface {
|
|
4
|
+
private getSettings;
|
|
5
|
+
private fileAssembler;
|
|
6
|
+
constructor(getSettings: GetSettingsUseCase.Interface, fileAssembler: ProjectFileAssembler.Interface);
|
|
7
|
+
execute(params: AiPromptContextParams): Promise<AiPromptContext>;
|
|
8
|
+
}
|
|
9
|
+
export declare const AiPromptContextBuilder: typeof AiPromptContextBuilderImpl & {
|
|
10
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IAiPromptContextBuilder>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { GetSettingsUseCase } from "../GetSettings/index.js";
|
|
2
|
+
import { AiPromptContextBuilder, ProjectFileAssembler } from "./abstractions.js";
|
|
3
|
+
import { WriterPersonaSection } from "./WriterPersonaSection.js";
|
|
4
|
+
import { ReaderPersonaSection } from "./ReaderPersonaSection.js";
|
|
5
|
+
import { ProjectSection } from "./ProjectSection.js";
|
|
6
|
+
function resolvePersonas(settings, project, params) {
|
|
7
|
+
const readerPersonaId = params.readerPersonaId ?? project?.defaultReaderPersonaId ?? void 0;
|
|
8
|
+
const writerPersonaId = params.writerPersonaId ?? project?.defaultWriterPersonaId ?? void 0;
|
|
9
|
+
const readerPreset = readerPersonaId ? settings.readerPersonas?.presets?.find((p)=>p.id === readerPersonaId) : void 0;
|
|
10
|
+
const writerPreset = writerPersonaId ? settings.writerPersonas?.presets?.find((p)=>p.id === writerPersonaId) : void 0;
|
|
11
|
+
return {
|
|
12
|
+
reader: readerPreset ? {
|
|
13
|
+
name: readerPreset.name,
|
|
14
|
+
description: readerPreset.description,
|
|
15
|
+
style: readerPreset.style
|
|
16
|
+
} : void 0,
|
|
17
|
+
writer: writerPreset ? {
|
|
18
|
+
name: writerPreset.name,
|
|
19
|
+
description: writerPreset.description,
|
|
20
|
+
style: writerPreset.style
|
|
21
|
+
} : void 0
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function formatContext(ctx) {
|
|
25
|
+
const sections = [];
|
|
26
|
+
if (ctx.writerPersona) sections.push(WriterPersonaSection.format(ctx.writerPersona));
|
|
27
|
+
if (ctx.readerPersona) sections.push(ReaderPersonaSection.format(ctx.readerPersona));
|
|
28
|
+
if (ctx.project) {
|
|
29
|
+
const projectText = ProjectSection.format(ctx.project);
|
|
30
|
+
if (projectText) sections.push(projectText);
|
|
31
|
+
}
|
|
32
|
+
return sections.length > 0 ? "\n\n" + sections.join("\n\n") : "";
|
|
33
|
+
}
|
|
34
|
+
function emptyContext(warnings) {
|
|
35
|
+
return {
|
|
36
|
+
project: void 0,
|
|
37
|
+
readerPersona: void 0,
|
|
38
|
+
writerPersona: void 0,
|
|
39
|
+
allProjectFiles: [],
|
|
40
|
+
excludedFileIds: new Set(),
|
|
41
|
+
cacheHit: false,
|
|
42
|
+
warnings,
|
|
43
|
+
toString () {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
class AiPromptContextBuilderImpl {
|
|
49
|
+
constructor(getSettings, fileAssembler){
|
|
50
|
+
this.getSettings = getSettings;
|
|
51
|
+
this.fileAssembler = fileAssembler;
|
|
52
|
+
}
|
|
53
|
+
async execute(params) {
|
|
54
|
+
const warnings = [];
|
|
55
|
+
const settingsResult = await this.getSettings.execute();
|
|
56
|
+
if (settingsResult.isFail()) {
|
|
57
|
+
warnings.push("Failed to load AI PowerUps settings.");
|
|
58
|
+
return emptyContext(warnings);
|
|
59
|
+
}
|
|
60
|
+
const settings = settingsResult.value;
|
|
61
|
+
const projectPreset = params.projectId ? settings.projects?.presets?.find((p)=>p.id === params.projectId) : void 0;
|
|
62
|
+
const { reader, writer } = resolvePersonas(settings, projectPreset, params);
|
|
63
|
+
const excludedFileIds = new Set(params.excludedFileIds ?? []);
|
|
64
|
+
let project;
|
|
65
|
+
let allProjectFiles = [];
|
|
66
|
+
let cacheHit = false;
|
|
67
|
+
if (projectPreset) {
|
|
68
|
+
const assembled = await this.fileAssembler.execute(projectPreset.id, projectPreset.version ?? 0, projectPreset.files ?? [], warnings);
|
|
69
|
+
allProjectFiles = assembled.files;
|
|
70
|
+
cacheHit = assembled.cacheHit;
|
|
71
|
+
const visibleFiles = excludedFileIds.size > 0 ? allProjectFiles.filter((f)=>!excludedFileIds.has(f.id)) : allProjectFiles;
|
|
72
|
+
project = {
|
|
73
|
+
name: projectPreset.name,
|
|
74
|
+
instructions: projectPreset.instructions,
|
|
75
|
+
files: visibleFiles,
|
|
76
|
+
totalTokens: visibleFiles.reduce((sum, f)=>sum + f.tokenCount, 0)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const ctx = {
|
|
80
|
+
project,
|
|
81
|
+
readerPersona: reader,
|
|
82
|
+
writerPersona: writer,
|
|
83
|
+
allProjectFiles,
|
|
84
|
+
excludedFileIds,
|
|
85
|
+
cacheHit,
|
|
86
|
+
warnings,
|
|
87
|
+
toString () {
|
|
88
|
+
return formatContext(this);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return ctx;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const AiPromptContextBuilder_AiPromptContextBuilder = AiPromptContextBuilder.createImplementation({
|
|
95
|
+
implementation: AiPromptContextBuilderImpl,
|
|
96
|
+
dependencies: [
|
|
97
|
+
GetSettingsUseCase,
|
|
98
|
+
ProjectFileAssembler
|
|
99
|
+
]
|
|
100
|
+
});
|
|
101
|
+
export { AiPromptContextBuilder_AiPromptContextBuilder as AiPromptContextBuilder };
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=AiPromptContextBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/AiPromptContextBuilder.js","sources":["../../../../src/api/features/AiPromptContext/AiPromptContextBuilder.ts"],"sourcesContent":["import { GetSettingsUseCase } from \"~/api/features/GetSettings/index.js\";\nimport {\n AiPromptContextBuilder as Abstraction,\n ProjectFileAssembler,\n type AiPromptContext,\n type AiPromptContextParams,\n type ProjectFileContent,\n type ResolvedPersona,\n type ResolvedProject\n} from \"./abstractions.js\";\nimport type { IAiPowerUpsSettings } from \"~/api/types.js\";\nimport type { ProjectPreset } from \"~/api/features/Projects/types.js\";\nimport { WriterPersonaSection } from \"./WriterPersonaSection.js\";\nimport { ReaderPersonaSection } from \"./ReaderPersonaSection.js\";\nimport { ProjectSection } from \"./ProjectSection.js\";\n\nfunction resolvePersonas(\n settings: IAiPowerUpsSettings,\n project: ProjectPreset | undefined,\n params: AiPromptContextParams\n): { reader?: ResolvedPersona; writer?: ResolvedPersona } {\n const readerPersonaId = params.readerPersonaId ?? project?.defaultReaderPersonaId ?? undefined;\n const writerPersonaId = params.writerPersonaId ?? project?.defaultWriterPersonaId ?? undefined;\n\n const readerPreset = readerPersonaId\n ? settings.readerPersonas?.presets?.find(p => p.id === readerPersonaId)\n : undefined;\n\n const writerPreset = writerPersonaId\n ? settings.writerPersonas?.presets?.find(p => p.id === writerPersonaId)\n : undefined;\n\n return {\n reader: readerPreset\n ? {\n name: readerPreset.name,\n description: readerPreset.description,\n style: readerPreset.style\n }\n : undefined,\n writer: writerPreset\n ? {\n name: writerPreset.name,\n description: writerPreset.description,\n style: writerPreset.style\n }\n : undefined\n };\n}\n\nfunction formatContext(ctx: AiPromptContext): string {\n const sections: string[] = [];\n\n if (ctx.writerPersona) {\n sections.push(WriterPersonaSection.format(ctx.writerPersona));\n }\n if (ctx.readerPersona) {\n sections.push(ReaderPersonaSection.format(ctx.readerPersona));\n }\n if (ctx.project) {\n const projectText = ProjectSection.format(ctx.project);\n if (projectText) {\n sections.push(projectText);\n }\n }\n\n return sections.length > 0 ? \"\\n\\n\" + sections.join(\"\\n\\n\") : \"\";\n}\n\nfunction emptyContext(warnings: string[]): AiPromptContext {\n return {\n project: undefined,\n readerPersona: undefined,\n writerPersona: undefined,\n allProjectFiles: [],\n excludedFileIds: new Set(),\n cacheHit: false,\n warnings,\n toString() {\n return \"\";\n }\n };\n}\n\nclass AiPromptContextBuilderImpl implements Abstraction.Interface {\n constructor(\n private getSettings: GetSettingsUseCase.Interface,\n private fileAssembler: ProjectFileAssembler.Interface\n ) {}\n\n async execute(params: AiPromptContextParams): Promise<AiPromptContext> {\n const warnings: string[] = [];\n\n const settingsResult = await this.getSettings.execute();\n if (settingsResult.isFail()) {\n warnings.push(\"Failed to load AI PowerUps settings.\");\n return emptyContext(warnings);\n }\n\n const settings = settingsResult.value;\n const projectPreset = params.projectId\n ? settings.projects?.presets?.find(p => p.id === params.projectId)\n : undefined;\n\n const { reader, writer } = resolvePersonas(settings, projectPreset, params);\n const excludedFileIds = new Set(params.excludedFileIds ?? []);\n\n let project: ResolvedProject | undefined;\n let allProjectFiles: ProjectFileContent[] = [];\n let cacheHit = false;\n\n if (projectPreset) {\n const assembled = await this.fileAssembler.execute(\n projectPreset.id,\n projectPreset.version ?? 0,\n projectPreset.files ?? [],\n warnings\n );\n allProjectFiles = assembled.files;\n cacheHit = assembled.cacheHit;\n\n const visibleFiles =\n excludedFileIds.size > 0\n ? allProjectFiles.filter(f => !excludedFileIds.has(f.id))\n : allProjectFiles;\n\n project = {\n name: projectPreset.name,\n instructions: projectPreset.instructions,\n files: visibleFiles,\n totalTokens: visibleFiles.reduce((sum, f) => sum + f.tokenCount, 0)\n };\n }\n\n const ctx: AiPromptContext = {\n project,\n readerPersona: reader,\n writerPersona: writer,\n allProjectFiles,\n excludedFileIds,\n cacheHit,\n warnings,\n toString() {\n return formatContext(this);\n }\n };\n\n return ctx;\n }\n}\n\nexport const AiPromptContextBuilder = Abstraction.createImplementation({\n implementation: AiPromptContextBuilderImpl,\n dependencies: [GetSettingsUseCase, ProjectFileAssembler]\n});\n"],"names":["resolvePersonas","settings","project","params","readerPersonaId","undefined","writerPersonaId","readerPreset","p","writerPreset","formatContext","ctx","sections","WriterPersonaSection","ReaderPersonaSection","projectText","ProjectSection","emptyContext","warnings","Set","AiPromptContextBuilderImpl","getSettings","fileAssembler","settingsResult","projectPreset","reader","writer","excludedFileIds","allProjectFiles","cacheHit","assembled","visibleFiles","f","sum","AiPromptContextBuilder","Abstraction","GetSettingsUseCase","ProjectFileAssembler"],"mappings":";;;;;AAgBA,SAASA,gBACLC,QAA6B,EAC7BC,OAAkC,EAClCC,MAA6B;IAE7B,MAAMC,kBAAkBD,OAAO,eAAe,IAAID,SAAS,0BAA0BG;IACrF,MAAMC,kBAAkBH,OAAO,eAAe,IAAID,SAAS,0BAA0BG;IAErF,MAAME,eAAeH,kBACfH,SAAS,cAAc,EAAE,SAAS,KAAKO,CAAAA,IAAKA,EAAE,EAAE,KAAKJ,mBACrDC;IAEN,MAAMI,eAAeH,kBACfL,SAAS,cAAc,EAAE,SAAS,KAAKO,CAAAA,IAAKA,EAAE,EAAE,KAAKF,mBACrDD;IAEN,OAAO;QACH,QAAQE,eACF;YACI,MAAMA,aAAa,IAAI;YACvB,aAAaA,aAAa,WAAW;YACrC,OAAOA,aAAa,KAAK;QAC7B,IACAF;QACN,QAAQI,eACF;YACI,MAAMA,aAAa,IAAI;YACvB,aAAaA,aAAa,WAAW;YACrC,OAAOA,aAAa,KAAK;QAC7B,IACAJ;IACV;AACJ;AAEA,SAASK,cAAcC,GAAoB;IACvC,MAAMC,WAAqB,EAAE;IAE7B,IAAID,IAAI,aAAa,EACjBC,SAAS,IAAI,CAACC,qBAAqB,MAAM,CAACF,IAAI,aAAa;IAE/D,IAAIA,IAAI,aAAa,EACjBC,SAAS,IAAI,CAACE,qBAAqB,MAAM,CAACH,IAAI,aAAa;IAE/D,IAAIA,IAAI,OAAO,EAAE;QACb,MAAMI,cAAcC,eAAe,MAAM,CAACL,IAAI,OAAO;QACrD,IAAII,aACAH,SAAS,IAAI,CAACG;IAEtB;IAEA,OAAOH,SAAS,MAAM,GAAG,IAAI,SAASA,SAAS,IAAI,CAAC,UAAU;AAClE;AAEA,SAASK,aAAaC,QAAkB;IACpC,OAAO;QACH,SAASb;QACT,eAAeA;QACf,eAAeA;QACf,iBAAiB,EAAE;QACnB,iBAAiB,IAAIc;QACrB,UAAU;QACVD;QACA;YACI,OAAO;QACX;IACJ;AACJ;AAEA,MAAME;IACF,YACYC,WAAyC,EACzCC,aAA6C,CACvD;aAFUD,WAAW,GAAXA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQnB,MAA6B,EAA4B;QACnE,MAAMe,WAAqB,EAAE;QAE7B,MAAMK,iBAAiB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;QACrD,IAAIA,eAAe,MAAM,IAAI;YACzBL,SAAS,IAAI,CAAC;YACd,OAAOD,aAAaC;QACxB;QAEA,MAAMjB,WAAWsB,eAAe,KAAK;QACrC,MAAMC,gBAAgBrB,OAAO,SAAS,GAChCF,SAAS,QAAQ,EAAE,SAAS,KAAKO,CAAAA,IAAKA,EAAE,EAAE,KAAKL,OAAO,SAAS,IAC/DE;QAEN,MAAM,EAAEoB,MAAM,EAAEC,MAAM,EAAE,GAAG1B,gBAAgBC,UAAUuB,eAAerB;QACpE,MAAMwB,kBAAkB,IAAIR,IAAIhB,OAAO,eAAe,IAAI,EAAE;QAE5D,IAAID;QACJ,IAAI0B,kBAAwC,EAAE;QAC9C,IAAIC,WAAW;QAEf,IAAIL,eAAe;YACf,MAAMM,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAC9CN,cAAc,EAAE,EAChBA,cAAc,OAAO,IAAI,GACzBA,cAAc,KAAK,IAAI,EAAE,EACzBN;YAEJU,kBAAkBE,UAAU,KAAK;YACjCD,WAAWC,UAAU,QAAQ;YAE7B,MAAMC,eACFJ,gBAAgB,IAAI,GAAG,IACjBC,gBAAgB,MAAM,CAACI,CAAAA,IAAK,CAACL,gBAAgB,GAAG,CAACK,EAAE,EAAE,KACrDJ;YAEV1B,UAAU;gBACN,MAAMsB,cAAc,IAAI;gBACxB,cAAcA,cAAc,YAAY;gBACxC,OAAOO;gBACP,aAAaA,aAAa,MAAM,CAAC,CAACE,KAAKD,IAAMC,MAAMD,EAAE,UAAU,EAAE;YACrE;QACJ;QAEA,MAAMrB,MAAuB;YACzBT;YACA,eAAeuB;YACf,eAAeC;YACfE;YACAD;YACAE;YACAX;YACA;gBACI,OAAOR,cAAc,IAAI;YAC7B;QACJ;QAEA,OAAOC;IACX;AACJ;AAEO,MAAMuB,gDAAyBC,uBAAAA,oBAAgC,CAAC;IACnE,gBAAgBf;IAChB,cAAc;QAACgB;QAAoBC;KAAqB;AAC5D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
2
|
+
import { GetFileUseCase } from "@webiny/api-file-manager/features/file/GetFile/index.js";
|
|
3
|
+
import { ProjectFileAssembler as Abstraction, ProjectFileCache, type ProjectFileContent } from "./abstractions.js";
|
|
4
|
+
declare class ProjectFileAssemblerImpl implements Abstraction.Interface {
|
|
5
|
+
private getFileContents;
|
|
6
|
+
private getFile;
|
|
7
|
+
private cache;
|
|
8
|
+
constructor(getFileContents: GetFileContentsByIdUseCase.Interface, getFile: GetFileUseCase.Interface, cache: ProjectFileCache.Interface);
|
|
9
|
+
execute(projectId: string, version: number, files: Array<{
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
mimeType: string;
|
|
13
|
+
}>, warnings: string[]): Promise<{
|
|
14
|
+
files: ProjectFileContent[];
|
|
15
|
+
cacheHit: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
private assembleFiles;
|
|
18
|
+
}
|
|
19
|
+
export declare const ProjectFileAssembler: typeof ProjectFileAssemblerImpl & {
|
|
20
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IProjectFileAssembler>;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
2
|
+
import { GetFileUseCase } from "@webiny/api-file-manager/features/file/GetFile/index.js";
|
|
3
|
+
import { ProjectFileAssembler, ProjectFileCache } from "./abstractions.js";
|
|
4
|
+
const SUPPORTED_MIME_PREFIXES = [
|
|
5
|
+
"text/"
|
|
6
|
+
];
|
|
7
|
+
const SUPPORTED_MIME_TYPES = new Set([
|
|
8
|
+
"application/json",
|
|
9
|
+
"application/csv"
|
|
10
|
+
]);
|
|
11
|
+
function isSupportedType(mimeType) {
|
|
12
|
+
if (SUPPORTED_MIME_PREFIXES.some((prefix)=>mimeType.startsWith(prefix))) return true;
|
|
13
|
+
return SUPPORTED_MIME_TYPES.has(mimeType);
|
|
14
|
+
}
|
|
15
|
+
function estimateTokenCount(text) {
|
|
16
|
+
return Math.ceil(text.length / 4);
|
|
17
|
+
}
|
|
18
|
+
class ProjectFileAssemblerImpl {
|
|
19
|
+
constructor(getFileContents, getFile, cache){
|
|
20
|
+
this.getFileContents = getFileContents;
|
|
21
|
+
this.getFile = getFile;
|
|
22
|
+
this.cache = cache;
|
|
23
|
+
}
|
|
24
|
+
async execute(projectId, version, files, warnings) {
|
|
25
|
+
const cached = await this.cache.get(projectId, version);
|
|
26
|
+
if (cached.hit) return {
|
|
27
|
+
files: cached.files,
|
|
28
|
+
cacheHit: true
|
|
29
|
+
};
|
|
30
|
+
const assembled = await this.assembleFiles(files, warnings);
|
|
31
|
+
await this.cache.set(projectId, version, assembled);
|
|
32
|
+
return {
|
|
33
|
+
files: assembled,
|
|
34
|
+
cacheHit: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async assembleFiles(files, warnings) {
|
|
38
|
+
const supportedFiles = files.filter((f)=>isSupportedType(f.mimeType));
|
|
39
|
+
if (0 === supportedFiles.length) return [];
|
|
40
|
+
const results = await Promise.all(supportedFiles.map(async (file)=>{
|
|
41
|
+
const [contentsResult, damResult] = await Promise.all([
|
|
42
|
+
this.getFileContents.execute(file.id),
|
|
43
|
+
this.getFile.execute(file.id)
|
|
44
|
+
]);
|
|
45
|
+
if (contentsResult.isFail()) {
|
|
46
|
+
const msg = `Failed to load file "${file.name}" (${file.id}): ${contentsResult.error.message}`;
|
|
47
|
+
console.warn("ProjectFileAssembler:", msg);
|
|
48
|
+
warnings.push(msg);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const content = contentsResult.value.buffer.toString("utf-8");
|
|
52
|
+
let description;
|
|
53
|
+
if (damResult.isFail()) console.warn(`ProjectFileAssembler: failed to load DAM record for "${file.name}" (${file.id})`);
|
|
54
|
+
else if (damResult.value.description) description = damResult.value.description;
|
|
55
|
+
return {
|
|
56
|
+
id: file.id,
|
|
57
|
+
name: file.name,
|
|
58
|
+
content,
|
|
59
|
+
description,
|
|
60
|
+
tokenCount: estimateTokenCount(content)
|
|
61
|
+
};
|
|
62
|
+
}));
|
|
63
|
+
return results.filter((r)=>null !== r);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const ProjectFileAssembler_ProjectFileAssembler = ProjectFileAssembler.createImplementation({
|
|
67
|
+
implementation: ProjectFileAssemblerImpl,
|
|
68
|
+
dependencies: [
|
|
69
|
+
GetFileContentsByIdUseCase,
|
|
70
|
+
GetFileUseCase,
|
|
71
|
+
ProjectFileCache
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
export { ProjectFileAssembler_ProjectFileAssembler as ProjectFileAssembler };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=ProjectFileAssembler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/ProjectFileAssembler.js","sources":["../../../../src/api/features/AiPromptContext/ProjectFileAssembler.ts"],"sourcesContent":["import { GetFileContentsByIdUseCase } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport { GetFileUseCase } from \"@webiny/api-file-manager/features/file/GetFile/index.js\";\nimport {\n ProjectFileAssembler as Abstraction,\n ProjectFileCache,\n type ProjectFileContent\n} from \"./abstractions.js\";\n\nconst SUPPORTED_MIME_PREFIXES = [\"text/\"];\nconst SUPPORTED_MIME_TYPES = new Set([\"application/json\", \"application/csv\"]);\n\nfunction isSupportedType(mimeType: string): boolean {\n if (SUPPORTED_MIME_PREFIXES.some(prefix => mimeType.startsWith(prefix))) {\n return true;\n }\n return SUPPORTED_MIME_TYPES.has(mimeType);\n}\n\nfunction estimateTokenCount(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\nclass ProjectFileAssemblerImpl implements Abstraction.Interface {\n constructor(\n private getFileContents: GetFileContentsByIdUseCase.Interface,\n private getFile: GetFileUseCase.Interface,\n private cache: ProjectFileCache.Interface\n ) {}\n\n async execute(\n projectId: string,\n version: number,\n files: Array<{ id: string; name: string; mimeType: string }>,\n warnings: string[]\n ): Promise<{ files: ProjectFileContent[]; cacheHit: boolean }> {\n const cached = await this.cache.get(projectId, version);\n if (cached.hit) {\n return { files: cached.files, cacheHit: true };\n }\n\n const assembled = await this.assembleFiles(files, warnings);\n await this.cache.set(projectId, version, assembled);\n return { files: assembled, cacheHit: false };\n }\n\n private async assembleFiles(\n files: Array<{ id: string; name: string; mimeType: string }>,\n warnings: string[]\n ): Promise<ProjectFileContent[]> {\n const supportedFiles = files.filter(f => isSupportedType(f.mimeType));\n\n if (supportedFiles.length === 0) {\n return [];\n }\n\n const results = await Promise.all(\n supportedFiles.map(async (file): Promise<ProjectFileContent | null> => {\n const [contentsResult, damResult] = await Promise.all([\n this.getFileContents.execute(file.id),\n this.getFile.execute(file.id)\n ]);\n\n if (contentsResult.isFail()) {\n const msg = `Failed to load file \"${file.name}\" (${file.id}): ${contentsResult.error.message}`;\n console.warn(\"ProjectFileAssembler:\", msg);\n warnings.push(msg);\n return null;\n }\n\n const content = contentsResult.value.buffer.toString(\"utf-8\");\n\n let description: string | undefined;\n if (damResult.isFail()) {\n console.warn(\n `ProjectFileAssembler: failed to load DAM record for \"${file.name}\" (${file.id})`\n );\n } else if (damResult.value.description) {\n description = damResult.value.description;\n }\n\n return {\n id: file.id,\n name: file.name,\n content,\n description,\n tokenCount: estimateTokenCount(content)\n };\n })\n );\n\n return results.filter((r): r is ProjectFileContent => r !== null);\n }\n}\n\nexport const ProjectFileAssembler = Abstraction.createImplementation({\n implementation: ProjectFileAssemblerImpl,\n dependencies: [GetFileContentsByIdUseCase, GetFileUseCase, ProjectFileCache]\n});\n"],"names":["SUPPORTED_MIME_PREFIXES","SUPPORTED_MIME_TYPES","Set","isSupportedType","mimeType","prefix","estimateTokenCount","text","Math","ProjectFileAssemblerImpl","getFileContents","getFile","cache","projectId","version","files","warnings","cached","assembled","supportedFiles","f","results","Promise","file","contentsResult","damResult","msg","console","content","description","r","ProjectFileAssembler","Abstraction","GetFileContentsByIdUseCase","GetFileUseCase","ProjectFileCache"],"mappings":";;;AAQA,MAAMA,0BAA0B;IAAC;CAAQ;AACzC,MAAMC,uBAAuB,IAAIC,IAAI;IAAC;IAAoB;CAAkB;AAE5E,SAASC,gBAAgBC,QAAgB;IACrC,IAAIJ,wBAAwB,IAAI,CAACK,CAAAA,SAAUD,SAAS,UAAU,CAACC,UAC3D,OAAO;IAEX,OAAOJ,qBAAqB,GAAG,CAACG;AACpC;AAEA,SAASE,mBAAmBC,IAAY;IACpC,OAAOC,KAAK,IAAI,CAACD,KAAK,MAAM,GAAG;AACnC;AAEA,MAAME;IACF,YACYC,eAAqD,EACrDC,OAAiC,EACjCC,KAAiC,CAC3C;aAHUF,eAAe,GAAfA;aACAC,OAAO,GAAPA;aACAC,KAAK,GAALA;IACT;IAEH,MAAM,QACFC,SAAiB,EACjBC,OAAe,EACfC,KAA4D,EAC5DC,QAAkB,EACyC;QAC3D,MAAMC,SAAS,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAACJ,WAAWC;QAC/C,IAAIG,OAAO,GAAG,EACV,OAAO;YAAE,OAAOA,OAAO,KAAK;YAAE,UAAU;QAAK;QAGjD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAACH,OAAOC;QAClD,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAACH,WAAWC,SAASI;QACzC,OAAO;YAAE,OAAOA;YAAW,UAAU;QAAM;IAC/C;IAEA,MAAc,cACVH,KAA4D,EAC5DC,QAAkB,EACW;QAC7B,MAAMG,iBAAiBJ,MAAM,MAAM,CAACK,CAAAA,IAAKjB,gBAAgBiB,EAAE,QAAQ;QAEnE,IAAID,AAA0B,MAA1BA,eAAe,MAAM,EACrB,OAAO,EAAE;QAGb,MAAME,UAAU,MAAMC,QAAQ,GAAG,CAC7BH,eAAe,GAAG,CAAC,OAAOI;YACtB,MAAM,CAACC,gBAAgBC,UAAU,GAAG,MAAMH,QAAQ,GAAG,CAAC;gBAClD,IAAI,CAAC,eAAe,CAAC,OAAO,CAACC,KAAK,EAAE;gBACpC,IAAI,CAAC,OAAO,CAAC,OAAO,CAACA,KAAK,EAAE;aAC/B;YAED,IAAIC,eAAe,MAAM,IAAI;gBACzB,MAAME,MAAM,CAAC,qBAAqB,EAAEH,KAAK,IAAI,CAAC,GAAG,EAAEA,KAAK,EAAE,CAAC,GAAG,EAAEC,eAAe,KAAK,CAAC,OAAO,EAAE;gBAC9FG,QAAQ,IAAI,CAAC,yBAAyBD;gBACtCV,SAAS,IAAI,CAACU;gBACd,OAAO;YACX;YAEA,MAAME,UAAUJ,eAAe,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;YAErD,IAAIK;YACJ,IAAIJ,UAAU,MAAM,IAChBE,QAAQ,IAAI,CACR,CAAC,qDAAqD,EAAEJ,KAAK,IAAI,CAAC,GAAG,EAAEA,KAAK,EAAE,CAAC,CAAC,CAAC;iBAElF,IAAIE,UAAU,KAAK,CAAC,WAAW,EAClCI,cAAcJ,UAAU,KAAK,CAAC,WAAW;YAG7C,OAAO;gBACH,IAAIF,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;gBACfK;gBACAC;gBACA,YAAYvB,mBAAmBsB;YACnC;QACJ;QAGJ,OAAOP,QAAQ,MAAM,CAAC,CAACS,IAA+BA,AAAM,SAANA;IAC1D;AACJ;AAEO,MAAMC,4CAAuBC,qBAAAA,oBAAgC,CAAC;IACjE,gBAAgBvB;IAChB,cAAc;QAACwB;QAA4BC;QAAgBC;KAAiB;AAChF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
2
|
+
import { ProjectFileCache as Abstraction, ProjectFileContent } from "./abstractions.js";
|
|
3
|
+
declare class ProjectFileCacheImpl implements Abstraction.Interface {
|
|
4
|
+
private keyValueStore;
|
|
5
|
+
constructor(keyValueStore: GlobalKeyValueStore.Interface);
|
|
6
|
+
get(projectId: string, version: number): Promise<{
|
|
7
|
+
files: ProjectFileContent[];
|
|
8
|
+
hit: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
set(projectId: string, version: number, files: ProjectFileContent[]): Promise<void>;
|
|
11
|
+
private cacheKey;
|
|
12
|
+
}
|
|
13
|
+
export declare const ProjectFileCache: typeof ProjectFileCacheImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IProjectFileCache>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { compress, decompress } from "@webiny/utils/features/compression/legacy/gzip.js";
|
|
2
|
+
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
3
|
+
import { ProjectFileCache } from "./abstractions.js";
|
|
4
|
+
const CACHE_TTL_DAYS = 30;
|
|
5
|
+
class ProjectFileCacheImpl {
|
|
6
|
+
constructor(keyValueStore){
|
|
7
|
+
this.keyValueStore = keyValueStore;
|
|
8
|
+
}
|
|
9
|
+
async get(projectId, version) {
|
|
10
|
+
const key = this.cacheKey(projectId, version);
|
|
11
|
+
const cached = await this.keyValueStore.get(key);
|
|
12
|
+
if (!cached.isFail() && cached.value) try {
|
|
13
|
+
const decompressed = await decompress(Buffer.from(cached.value, "base64"));
|
|
14
|
+
const parsed = JSON.parse(decompressed.toString("utf-8"));
|
|
15
|
+
return {
|
|
16
|
+
files: parsed.files,
|
|
17
|
+
hit: true
|
|
18
|
+
};
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.warn("ProjectFileCache: cache entry corrupted, rebuilding", {
|
|
21
|
+
key,
|
|
22
|
+
error
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
files: [],
|
|
27
|
+
hit: false
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async set(projectId, version, files) {
|
|
31
|
+
const key = this.cacheKey(projectId, version);
|
|
32
|
+
try {
|
|
33
|
+
const payload = {
|
|
34
|
+
files
|
|
35
|
+
};
|
|
36
|
+
const compressed = await compress(JSON.stringify(payload));
|
|
37
|
+
const expiresAt = new Date();
|
|
38
|
+
expiresAt.setDate(expiresAt.getDate() + CACHE_TTL_DAYS);
|
|
39
|
+
await this.keyValueStore.set(key, compressed.toString("base64"), {
|
|
40
|
+
expiresAt
|
|
41
|
+
});
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.warn("ProjectFileCache: cache write failed", {
|
|
44
|
+
key,
|
|
45
|
+
error
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
cacheKey(projectId, version) {
|
|
50
|
+
return `AiProjectContext/${projectId}/v${version}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const ProjectFileCache_ProjectFileCache = ProjectFileCache.createImplementation({
|
|
54
|
+
implementation: ProjectFileCacheImpl,
|
|
55
|
+
dependencies: [
|
|
56
|
+
GlobalKeyValueStore
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
export { ProjectFileCache_ProjectFileCache as ProjectFileCache };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=ProjectFileCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/ProjectFileCache.js","sources":["../../../../src/api/features/AiPromptContext/ProjectFileCache.ts"],"sourcesContent":["import { compress, decompress } from \"@webiny/utils/features/compression/legacy/gzip.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { ProjectFileCache as Abstraction, ProjectFileContent } from \"./abstractions.js\";\n\nconst CACHE_TTL_DAYS = 30;\n\ninterface CachedProjectContext {\n files: ProjectFileContent[];\n}\n\nclass ProjectFileCacheImpl implements Abstraction.Interface {\n constructor(private keyValueStore: GlobalKeyValueStore.Interface) {}\n\n async get(\n projectId: string,\n version: number\n ): Promise<{ files: ProjectFileContent[]; hit: boolean }> {\n const key = this.cacheKey(projectId, version);\n const cached = await this.keyValueStore.get<string>(key);\n\n if (!cached.isFail() && cached.value) {\n try {\n const decompressed = await decompress(Buffer.from(cached.value, \"base64\"));\n const parsed = JSON.parse(decompressed.toString(\"utf-8\")) as CachedProjectContext;\n return { files: parsed.files, hit: true };\n } catch (error) {\n console.warn(\"ProjectFileCache: cache entry corrupted, rebuilding\", {\n key,\n error\n });\n }\n }\n\n return { files: [], hit: false };\n }\n\n async set(projectId: string, version: number, files: ProjectFileContent[]): Promise<void> {\n const key = this.cacheKey(projectId, version);\n\n try {\n const payload: CachedProjectContext = { files };\n const compressed = await compress(JSON.stringify(payload));\n const expiresAt = new Date();\n expiresAt.setDate(expiresAt.getDate() + CACHE_TTL_DAYS);\n await this.keyValueStore.set(key, compressed.toString(\"base64\"), { expiresAt });\n } catch (error) {\n console.warn(\"ProjectFileCache: cache write failed\", { key, error });\n }\n }\n\n private cacheKey(projectId: string, version: number): string {\n return `AiProjectContext/${projectId}/v${version}`;\n }\n}\n\nexport const ProjectFileCache = Abstraction.createImplementation({\n implementation: ProjectFileCacheImpl,\n dependencies: [GlobalKeyValueStore]\n});\n"],"names":["CACHE_TTL_DAYS","ProjectFileCacheImpl","keyValueStore","projectId","version","key","cached","decompressed","decompress","Buffer","parsed","JSON","error","console","files","payload","compressed","compress","expiresAt","Date","ProjectFileCache","Abstraction","GlobalKeyValueStore"],"mappings":";;;AAIA,MAAMA,iBAAiB;AAMvB,MAAMC;IACF,YAAoBC,aAA4C,CAAE;aAA9CA,aAAa,GAAbA;IAA+C;IAEnE,MAAM,IACFC,SAAiB,EACjBC,OAAe,EACuC;QACtD,MAAMC,MAAM,IAAI,CAAC,QAAQ,CAACF,WAAWC;QACrC,MAAME,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAASD;QAEpD,IAAI,CAACC,OAAO,MAAM,MAAMA,OAAO,KAAK,EAChC,IAAI;YACA,MAAMC,eAAe,MAAMC,WAAWC,OAAO,IAAI,CAACH,OAAO,KAAK,EAAE;YAChE,MAAMI,SAASC,KAAK,KAAK,CAACJ,aAAa,QAAQ,CAAC;YAChD,OAAO;gBAAE,OAAOG,OAAO,KAAK;gBAAE,KAAK;YAAK;QAC5C,EAAE,OAAOE,OAAO;YACZC,QAAQ,IAAI,CAAC,uDAAuD;gBAChER;gBACAO;YACJ;QACJ;QAGJ,OAAO;YAAE,OAAO,EAAE;YAAE,KAAK;QAAM;IACnC;IAEA,MAAM,IAAIT,SAAiB,EAAEC,OAAe,EAAEU,KAA2B,EAAiB;QACtF,MAAMT,MAAM,IAAI,CAAC,QAAQ,CAACF,WAAWC;QAErC,IAAI;YACA,MAAMW,UAAgC;gBAAED;YAAM;YAC9C,MAAME,aAAa,MAAMC,SAASN,KAAK,SAAS,CAACI;YACjD,MAAMG,YAAY,IAAIC;YACtBD,UAAU,OAAO,CAACA,UAAU,OAAO,KAAKlB;YACxC,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAACK,KAAKW,WAAW,QAAQ,CAAC,WAAW;gBAAEE;YAAU;QACjF,EAAE,OAAON,OAAO;YACZC,QAAQ,IAAI,CAAC,wCAAwC;gBAAER;gBAAKO;YAAM;QACtE;IACJ;IAEQ,SAAST,SAAiB,EAAEC,OAAe,EAAU;QACzD,OAAO,CAAC,iBAAiB,EAAED,UAAU,EAAE,EAAEC,SAAS;IACtD;AACJ;AAEO,MAAMgB,oCAAmBC,iBAAAA,oBAAgC,CAAC;IAC7D,gBAAgBpB;IAChB,cAAc;QAACqB;KAAoB;AACvC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class ProjectSection {
|
|
2
|
+
static format(project) {
|
|
3
|
+
const hasInstructions = !!project.instructions;
|
|
4
|
+
const hasFiles = project.files.length > 0;
|
|
5
|
+
if (!hasInstructions && !hasFiles) return "";
|
|
6
|
+
const parts = [
|
|
7
|
+
`## Project: ${project.name}`
|
|
8
|
+
];
|
|
9
|
+
if (hasInstructions) parts.push(project.instructions);
|
|
10
|
+
if (hasFiles) parts.push([
|
|
11
|
+
"### Available reference files",
|
|
12
|
+
"",
|
|
13
|
+
`You have access to ${project.files.length} reference files for this project. Use the`,
|
|
14
|
+
"`read_project_file` tool to read any file when its contents are relevant",
|
|
15
|
+
"to the user's request. Read files only when needed — do not read all files",
|
|
16
|
+
"preemptively.",
|
|
17
|
+
"",
|
|
18
|
+
"Files:",
|
|
19
|
+
"",
|
|
20
|
+
...project.files.map((file)=>{
|
|
21
|
+
const lines = [
|
|
22
|
+
`- id: "${file.id}"`,
|
|
23
|
+
` name: "${file.name}"`,
|
|
24
|
+
` description: "${file.description || "(no description)"}"`,
|
|
25
|
+
` tokens: ~${file.tokenCount}`
|
|
26
|
+
];
|
|
27
|
+
return lines.join("\n");
|
|
28
|
+
})
|
|
29
|
+
].join("\n"));
|
|
30
|
+
return parts.join("\n\n");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export { ProjectSection };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=ProjectSection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/ProjectSection.js","sources":["../../../../src/api/features/AiPromptContext/ProjectSection.ts"],"sourcesContent":["import type { ResolvedProject } from \"./abstractions.js\";\n\nexport class ProjectSection {\n static format(project: ResolvedProject): string {\n const hasInstructions = !!project.instructions;\n const hasFiles = project.files.length > 0;\n\n if (!hasInstructions && !hasFiles) {\n return \"\";\n }\n\n const parts: string[] = [`## Project: ${project.name}`];\n\n if (hasInstructions) {\n parts.push(project.instructions!);\n }\n\n if (hasFiles) {\n parts.push(\n [\n \"### Available reference files\",\n \"\",\n `You have access to ${project.files.length} reference files for this project. Use the`,\n \"`read_project_file` tool to read any file when its contents are relevant\",\n \"to the user's request. Read files only when needed — do not read all files\",\n \"preemptively.\",\n \"\",\n \"Files:\",\n \"\",\n ...project.files.map(file => {\n const lines = [\n `- id: \"${file.id}\"`,\n ` name: \"${file.name}\"`,\n ` description: \"${file.description || \"(no description)\"}\"`,\n ` tokens: ~${file.tokenCount}`\n ];\n return lines.join(\"\\n\");\n })\n ].join(\"\\n\")\n );\n }\n\n return parts.join(\"\\n\\n\");\n }\n}\n"],"names":["ProjectSection","project","hasInstructions","hasFiles","parts","file","lines"],"mappings":"AAEO,MAAMA;IACT,OAAO,OAAOC,OAAwB,EAAU;QAC5C,MAAMC,kBAAkB,CAAC,CAACD,QAAQ,YAAY;QAC9C,MAAME,WAAWF,QAAQ,KAAK,CAAC,MAAM,GAAG;QAExC,IAAI,CAACC,mBAAmB,CAACC,UACrB,OAAO;QAGX,MAAMC,QAAkB;YAAC,CAAC,YAAY,EAAEH,QAAQ,IAAI,EAAE;SAAC;QAEvD,IAAIC,iBACAE,MAAM,IAAI,CAACH,QAAQ,YAAY;QAGnC,IAAIE,UACAC,MAAM,IAAI,CACN;YACI;YACA;YACA,CAAC,mBAAmB,EAAEH,QAAQ,KAAK,CAAC,MAAM,CAAC,0CAA0C,CAAC;YACtF;YACA;YACA;YACA;YACA;YACA;eACGA,QAAQ,KAAK,CAAC,GAAG,CAACI,CAAAA;gBACjB,MAAMC,QAAQ;oBACV,CAAC,OAAO,EAAED,KAAK,EAAE,CAAC,CAAC,CAAC;oBACpB,CAAC,SAAS,EAAEA,KAAK,IAAI,CAAC,CAAC,CAAC;oBACxB,CAAC,gBAAgB,EAAEA,KAAK,WAAW,IAAI,mBAAmB,CAAC,CAAC;oBAC5D,CAAC,WAAW,EAAEA,KAAK,UAAU,EAAE;iBAClC;gBACD,OAAOC,MAAM,IAAI,CAAC;YACtB;SACH,CAAC,IAAI,CAAC;QAIf,OAAOF,MAAM,IAAI,CAAC;IACtB;AACJ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const inputSchema = z.object({
|
|
3
|
+
fileId: z.string().describe("The id of the file from the project manifest.")
|
|
4
|
+
});
|
|
5
|
+
function createReadProjectFileTool(files, excludedFileIds) {
|
|
6
|
+
const fileMap = new Map(files.map((f)=>[
|
|
7
|
+
f.id,
|
|
8
|
+
f
|
|
9
|
+
]));
|
|
10
|
+
return {
|
|
11
|
+
read_project_file: {
|
|
12
|
+
description: "Read the full contents of a project reference file by its id. Use this when a file from the manifest contains information relevant to the user's request.",
|
|
13
|
+
inputSchema: inputSchema,
|
|
14
|
+
execute: async (input)=>{
|
|
15
|
+
const { fileId } = input;
|
|
16
|
+
if (excludedFileIds.has(fileId)) return {
|
|
17
|
+
error: "File excluded for this generation."
|
|
18
|
+
};
|
|
19
|
+
const file = fileMap.get(fileId);
|
|
20
|
+
if (!file) {
|
|
21
|
+
const availableIds = files.map((f)=>f.id).join(", ");
|
|
22
|
+
return {
|
|
23
|
+
error: `File not found. Available ids: ${availableIds}`
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
content: file.content,
|
|
28
|
+
name: file.name
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export { createReadProjectFileTool };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=ReadProjectFileTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/ReadProjectFileTool.js","sources":["../../../../src/api/features/AiPromptContext/ReadProjectFileTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { ToolSet } from \"ai\";\nimport type { ProjectFileContent } from \"./abstractions.js\";\n\nconst inputSchema = z.object({\n fileId: z.string().describe(\"The id of the file from the project manifest.\")\n});\n\nexport function createReadProjectFileTool(\n files: ProjectFileContent[],\n excludedFileIds: Set<string>\n): ToolSet {\n const fileMap = new Map(files.map(f => [f.id, f]));\n\n return {\n read_project_file: {\n description:\n \"Read the full contents of a project reference file by its id. \" +\n \"Use this when a file from the manifest contains information relevant to the user's request.\",\n inputSchema,\n execute: async (input: unknown) => {\n const { fileId } = input as z.infer<typeof inputSchema>;\n\n if (excludedFileIds.has(fileId)) {\n return { error: \"File excluded for this generation.\" };\n }\n\n const file = fileMap.get(fileId);\n if (!file) {\n const availableIds = files.map(f => f.id).join(\", \");\n return {\n error: `File not found. Available ids: ${availableIds}`\n };\n }\n\n return {\n content: file.content,\n name: file.name\n };\n }\n }\n };\n}\n"],"names":["inputSchema","z","createReadProjectFileTool","files","excludedFileIds","fileMap","Map","f","input","fileId","file","availableIds"],"mappings":";AAIA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,QAAQA,EAAE,MAAM,GAAG,QAAQ,CAAC;AAChC;AAEO,SAASC,0BACZC,KAA2B,EAC3BC,eAA4B;IAE5B,MAAMC,UAAU,IAAIC,IAAIH,MAAM,GAAG,CAACI,CAAAA,IAAK;YAACA,EAAE,EAAE;YAAEA;SAAE;IAEhD,OAAO;QACH,mBAAmB;YACf,aACI;YAEJP,aAAAA;YACA,SAAS,OAAOQ;gBACZ,MAAM,EAAEC,MAAM,EAAE,GAAGD;gBAEnB,IAAIJ,gBAAgB,GAAG,CAACK,SACpB,OAAO;oBAAE,OAAO;gBAAqC;gBAGzD,MAAMC,OAAOL,QAAQ,GAAG,CAACI;gBACzB,IAAI,CAACC,MAAM;oBACP,MAAMC,eAAeR,MAAM,GAAG,CAACI,CAAAA,IAAKA,EAAE,EAAE,EAAE,IAAI,CAAC;oBAC/C,OAAO;wBACH,OAAO,CAAC,+BAA+B,EAAEI,cAAc;oBAC3D;gBACJ;gBAEA,OAAO;oBACH,SAASD,KAAK,OAAO;oBACrB,MAAMA,KAAK,IAAI;gBACnB;YACJ;QACJ;IACJ;AACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class ReaderPersonaSection {
|
|
2
|
+
static format(persona) {
|
|
3
|
+
let section = `### Reader Persona (Target Audience)\n\nYou are writing for "${persona.name}": ${persona.description}`;
|
|
4
|
+
if (persona.style) section += `\nExpected tone/style: ${persona.style}`;
|
|
5
|
+
return section;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { ReaderPersonaSection };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=ReaderPersonaSection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/ReaderPersonaSection.js","sources":["../../../../src/api/features/AiPromptContext/ReaderPersonaSection.ts"],"sourcesContent":["import type { ResolvedPersona } from \"./abstractions.js\";\n\nexport class ReaderPersonaSection {\n static format(persona: ResolvedPersona): string {\n let section = `### Reader Persona (Target Audience)\\n\\nYou are writing for \"${persona.name}\": ${persona.description}`;\n\n if (persona.style) {\n section += `\\nExpected tone/style: ${persona.style}`;\n }\n\n return section;\n }\n}\n"],"names":["ReaderPersonaSection","persona","section"],"mappings":"AAEO,MAAMA;IACT,OAAO,OAAOC,OAAwB,EAAU;QAC5C,IAAIC,UAAU,CAAC,6DAA6D,EAAED,QAAQ,IAAI,CAAC,GAAG,EAAEA,QAAQ,WAAW,EAAE;QAErH,IAAIA,QAAQ,KAAK,EACbC,WAAW,CAAC,uBAAuB,EAAED,QAAQ,KAAK,EAAE;QAGxD,OAAOC;IACX;AACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class WriterPersonaSection {
|
|
2
|
+
static format(persona) {
|
|
3
|
+
let section = `### Writer Persona\n\nYou are writing as "${persona.name}": ${persona.description}`;
|
|
4
|
+
if (persona.style) section += `\nStyle: ${persona.style}`;
|
|
5
|
+
return section;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export { WriterPersonaSection };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=WriterPersonaSection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/WriterPersonaSection.js","sources":["../../../../src/api/features/AiPromptContext/WriterPersonaSection.ts"],"sourcesContent":["import type { ResolvedPersona } from \"./abstractions.js\";\n\nexport class WriterPersonaSection {\n static format(persona: ResolvedPersona): string {\n let section = `### Writer Persona\\n\\nYou are writing as \"${persona.name}\": ${persona.description}`;\n\n if (persona.style) {\n section += `\\nStyle: ${persona.style}`;\n }\n\n return section;\n }\n}\n"],"names":["WriterPersonaSection","persona","section"],"mappings":"AAEO,MAAMA;IACT,OAAO,OAAOC,OAAwB,EAAU;QAC5C,IAAIC,UAAU,CAAC,0CAA0C,EAAED,QAAQ,IAAI,CAAC,GAAG,EAAEA,QAAQ,WAAW,EAAE;QAElG,IAAIA,QAAQ,KAAK,EACbC,WAAW,CAAC,SAAS,EAAED,QAAQ,KAAK,EAAE;QAG1C,OAAOC;IACX;AACJ"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface IProjectFileCache {
|
|
2
|
+
get(projectId: string, version: number): Promise<{
|
|
3
|
+
files: ProjectFileContent[];
|
|
4
|
+
hit: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
set(projectId: string, version: number, files: ProjectFileContent[]): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare const ProjectFileCache: import("@webiny/di").Abstraction<IProjectFileCache>;
|
|
9
|
+
export declare namespace ProjectFileCache {
|
|
10
|
+
type Interface = IProjectFileCache;
|
|
11
|
+
}
|
|
12
|
+
export interface IProjectFileAssembler {
|
|
13
|
+
execute(projectId: string, version: number, files: Array<{
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
mimeType: string;
|
|
17
|
+
}>, warnings: string[]): Promise<{
|
|
18
|
+
files: ProjectFileContent[];
|
|
19
|
+
cacheHit: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
export declare const ProjectFileAssembler: import("@webiny/di").Abstraction<IProjectFileAssembler>;
|
|
23
|
+
export declare namespace ProjectFileAssembler {
|
|
24
|
+
type Interface = IProjectFileAssembler;
|
|
25
|
+
}
|
|
26
|
+
export interface AiPromptContextParams {
|
|
27
|
+
projectId?: string | null;
|
|
28
|
+
readerPersonaId?: string | null;
|
|
29
|
+
writerPersonaId?: string | null;
|
|
30
|
+
excludedFileIds?: string[] | null;
|
|
31
|
+
}
|
|
32
|
+
export interface ProjectFileContent {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
content: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
tokenCount: number;
|
|
38
|
+
}
|
|
39
|
+
export interface ResolvedProject {
|
|
40
|
+
name: string;
|
|
41
|
+
instructions?: string;
|
|
42
|
+
files: ProjectFileContent[];
|
|
43
|
+
totalTokens: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ResolvedPersona {
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
style?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface AiPromptContext {
|
|
51
|
+
project?: ResolvedProject;
|
|
52
|
+
readerPersona?: ResolvedPersona;
|
|
53
|
+
writerPersona?: ResolvedPersona;
|
|
54
|
+
allProjectFiles: ProjectFileContent[];
|
|
55
|
+
excludedFileIds: Set<string>;
|
|
56
|
+
cacheHit: boolean;
|
|
57
|
+
warnings: string[];
|
|
58
|
+
toString(): string;
|
|
59
|
+
}
|
|
60
|
+
export interface IAiPromptContextBuilder {
|
|
61
|
+
execute(params: AiPromptContextParams): Promise<AiPromptContext>;
|
|
62
|
+
}
|
|
63
|
+
export declare const AiPromptContextBuilder: import("@webiny/di").Abstraction<IAiPromptContextBuilder>;
|
|
64
|
+
export declare namespace AiPromptContextBuilder {
|
|
65
|
+
type Interface = IAiPromptContextBuilder;
|
|
66
|
+
type Params = AiPromptContextParams;
|
|
67
|
+
type Context = AiPromptContext;
|
|
68
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const ProjectFileCache = createAbstraction("ProjectFileCache");
|
|
3
|
+
const ProjectFileAssembler = createAbstraction("ProjectFileAssembler");
|
|
4
|
+
const AiPromptContextBuilder = createAbstraction("AiPowerUpsPromptContextBuilder");
|
|
5
|
+
export { AiPromptContextBuilder, ProjectFileAssembler, ProjectFileCache };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/abstractions.js","sources":["../../../../src/api/features/AiPromptContext/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\n// ============================================================================\n// ProjectFileCache\n// ============================================================================\n\nexport interface IProjectFileCache {\n get(projectId: string, version: number): Promise<{ files: ProjectFileContent[]; hit: boolean }>;\n set(projectId: string, version: number, files: ProjectFileContent[]): Promise<void>;\n}\n\nexport const ProjectFileCache = createAbstraction<IProjectFileCache>(\"ProjectFileCache\");\n\nexport namespace ProjectFileCache {\n export type Interface = IProjectFileCache;\n}\n\n// ============================================================================\n// ProjectFileAssembler\n// ============================================================================\n\nexport interface IProjectFileAssembler {\n execute(\n projectId: string,\n version: number,\n files: Array<{ id: string; name: string; mimeType: string }>,\n warnings: string[]\n ): Promise<{ files: ProjectFileContent[]; cacheHit: boolean }>;\n}\n\nexport const ProjectFileAssembler =\n createAbstraction<IProjectFileAssembler>(\"ProjectFileAssembler\");\n\nexport namespace ProjectFileAssembler {\n export type Interface = IProjectFileAssembler;\n}\n\n// ============================================================================\n// AiPromptContext\n// ============================================================================\n\nexport interface AiPromptContextParams {\n projectId?: string | null;\n readerPersonaId?: string | null;\n writerPersonaId?: string | null;\n excludedFileIds?: string[] | null;\n}\n\nexport interface ProjectFileContent {\n id: string;\n name: string;\n content: string;\n description?: string;\n tokenCount: number;\n}\n\nexport interface ResolvedProject {\n name: string;\n instructions?: string;\n files: ProjectFileContent[];\n totalTokens: number;\n}\n\nexport interface ResolvedPersona {\n name: string;\n description: string;\n style?: string;\n}\n\nexport interface AiPromptContext {\n project?: ResolvedProject;\n readerPersona?: ResolvedPersona;\n writerPersona?: ResolvedPersona;\n allProjectFiles: ProjectFileContent[];\n excludedFileIds: Set<string>;\n cacheHit: boolean;\n warnings: string[];\n toString(): string;\n}\n\nexport interface IAiPromptContextBuilder {\n execute(params: AiPromptContextParams): Promise<AiPromptContext>;\n}\n\nexport const AiPromptContextBuilder = createAbstraction<IAiPromptContextBuilder>(\n \"AiPowerUpsPromptContextBuilder\"\n);\n\nexport namespace AiPromptContextBuilder {\n export type Interface = IAiPromptContextBuilder;\n export type Params = AiPromptContextParams;\n export type Context = AiPromptContext;\n}\n"],"names":["ProjectFileCache","createAbstraction","ProjectFileAssembler","AiPromptContextBuilder"],"mappings":";AAWO,MAAMA,mBAAmBC,kBAAqC;AAmB9D,MAAMC,uBACTD,kBAAyC;AAqDtC,MAAME,yBAAyBF,kBAClC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ProjectFileCache } from "./ProjectFileCache.js";
|
|
3
|
+
import { ProjectFileAssembler } from "./ProjectFileAssembler.js";
|
|
4
|
+
import { AiPromptContextBuilder } from "./AiPromptContextBuilder.js";
|
|
5
|
+
const AiPromptContextFeature = createFeature({
|
|
6
|
+
name: "AiPowerUps/AiPromptContext",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(ProjectFileCache);
|
|
9
|
+
container.register(ProjectFileAssembler);
|
|
10
|
+
container.register(AiPromptContextBuilder);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export { AiPromptContextFeature };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/AiPromptContext/feature.js","sources":["../../../../src/api/features/AiPromptContext/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ProjectFileCache } from \"./ProjectFileCache.js\";\nimport { ProjectFileAssembler } from \"./ProjectFileAssembler.js\";\nimport { AiPromptContextBuilder } from \"./AiPromptContextBuilder.js\";\n\nexport const AiPromptContextFeature = createFeature({\n name: \"AiPowerUps/AiPromptContext\",\n register(container) {\n container.register(ProjectFileCache);\n container.register(ProjectFileAssembler);\n container.register(AiPromptContextBuilder);\n }\n});\n"],"names":["AiPromptContextFeature","createFeature","container","ProjectFileCache","ProjectFileAssembler","AiPromptContextBuilder"],"mappings":";;;;AAKO,MAAMA,yBAAyBC,cAAc;IAChD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AiPromptContextBuilder, type ResolvedProject, type ResolvedPersona, type ProjectFileContent } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AiPromptContextBuilder } from "./abstractions.js";
|