@webiny/ai-powerups 6.4.5 → 6.6.0-alpha.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.
Files changed (82) hide show
  1. package/admin/Extension.js +2 -1
  2. package/admin/Extension.js.map +1 -1
  3. package/admin/features/generateEntryContent/GenerateEntryContentGateway.d.ts +12 -0
  4. package/admin/features/generateEntryContent/GenerateEntryContentGateway.js +43 -0
  5. package/admin/features/generateEntryContent/GenerateEntryContentGateway.js.map +1 -0
  6. package/admin/features/generateEntryContent/GenerateEntryContentUseCase.d.ts +11 -0
  7. package/admin/features/generateEntryContent/GenerateEntryContentUseCase.js +18 -0
  8. package/admin/features/generateEntryContent/GenerateEntryContentUseCase.js.map +1 -0
  9. package/admin/features/generateEntryContent/abstractions.d.ts +23 -0
  10. package/admin/features/generateEntryContent/abstractions.js +6 -0
  11. package/admin/features/generateEntryContent/abstractions.js.map +1 -0
  12. package/admin/features/generateEntryContent/feature.d.ts +1 -0
  13. package/admin/features/generateEntryContent/feature.js +13 -0
  14. package/admin/features/generateEntryContent/feature.js.map +1 -0
  15. package/admin/features/generateEntryContent/index.d.ts +3 -0
  16. package/admin/features/generateEntryContent/index.js +2 -0
  17. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPage.js +3 -4
  18. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPage.js.map +1 -1
  19. package/admin/presentation/CmsContentGeneration/CmsGenerateContentButton.d.ts +4 -0
  20. package/admin/presentation/CmsContentGeneration/CmsGenerateContentButton.js +27 -0
  21. package/admin/presentation/CmsContentGeneration/CmsGenerateContentButton.js.map +1 -0
  22. package/admin/presentation/CmsContentGeneration/CmsGenerateContentDialog.d.ts +5 -0
  23. package/admin/presentation/CmsContentGeneration/CmsGenerateContentDialog.js +106 -0
  24. package/admin/presentation/CmsContentGeneration/CmsGenerateContentDialog.js.map +1 -0
  25. package/admin/presentation/CmsContentGeneration/CmsGenerateContentPresenter.d.ts +37 -0
  26. package/admin/presentation/CmsContentGeneration/CmsGenerateContentPresenter.js +202 -0
  27. package/admin/presentation/CmsContentGeneration/CmsGenerateContentPresenter.js.map +1 -0
  28. package/admin/presentation/CmsContentGeneration/Extension.d.ts +2 -0
  29. package/admin/presentation/CmsContentGeneration/Extension.js +23 -0
  30. package/admin/presentation/CmsContentGeneration/Extension.js.map +1 -0
  31. package/admin/presentation/CmsContentGeneration/abstractions.d.ts +20 -0
  32. package/admin/presentation/CmsContentGeneration/abstractions.js +5 -0
  33. package/admin/presentation/CmsContentGeneration/abstractions.js.map +1 -0
  34. package/admin/presentation/CmsContentGeneration/feature.d.ts +3 -0
  35. package/admin/presentation/CmsContentGeneration/feature.js +17 -0
  36. package/admin/presentation/CmsContentGeneration/feature.js.map +1 -0
  37. package/admin/presentation/ProjectsSettings.js +4 -4
  38. package/admin/presentation/ProjectsSettings.js.map +1 -1
  39. package/admin/presentation/WbContentGeneration/GenerateContentPresenter.js +2 -2
  40. package/admin/presentation/WbContentGeneration/GenerateContentPresenter.js.map +1 -1
  41. package/api/Extension.js +5 -3
  42. package/api/Extension.js.map +1 -1
  43. package/api/features/AiImageEnrichment/AiImageEnrichmentAfterCreateHandler.d.ts +3 -1
  44. package/api/features/AiImageEnrichment/AiImageEnrichmentAfterCreateHandler.js +6 -2
  45. package/api/features/AiImageEnrichment/AiImageEnrichmentAfterCreateHandler.js.map +1 -1
  46. package/api/features/AiImageEnrichment/AiImageEnrichmentTask.d.ts +7 -5
  47. package/api/features/AiImageEnrichment/AiImageEnrichmentTask.js +32 -30
  48. package/api/features/AiImageEnrichment/AiImageEnrichmentTask.js.map +1 -1
  49. package/api/features/CmsGenerateEntryContent/CmsGenerateEntryContentTask.d.ts +32 -0
  50. package/api/features/CmsGenerateEntryContent/CmsGenerateEntryContentTask.js +74 -0
  51. package/api/features/CmsGenerateEntryContent/CmsGenerateEntryContentTask.js.map +1 -0
  52. package/api/features/CmsGenerateEntryContent/CmsGenerateEntryContentUseCase.d.ts +29 -0
  53. package/api/features/CmsGenerateEntryContent/CmsGenerateEntryContentUseCase.js +141 -0
  54. package/api/features/CmsGenerateEntryContent/CmsGenerateEntryContentUseCase.js.map +1 -0
  55. package/api/features/CmsGenerateEntryContent/abstractions.d.ts +29 -0
  56. package/api/features/CmsGenerateEntryContent/abstractions.js +5 -0
  57. package/api/features/CmsGenerateEntryContent/abstractions.js.map +1 -0
  58. package/api/features/CmsGenerateEntryContent/buildPrompt.d.ts +2 -0
  59. package/api/features/CmsGenerateEntryContent/buildPrompt.js +61 -0
  60. package/api/features/CmsGenerateEntryContent/buildPrompt.js.map +1 -0
  61. package/api/features/CmsGenerateEntryContent/feature.d.ts +4 -0
  62. package/api/features/CmsGenerateEntryContent/feature.js +13 -0
  63. package/api/features/CmsGenerateEntryContent/feature.js.map +1 -0
  64. package/api/features/CmsGenerateEntryContent/index.d.ts +1 -0
  65. package/api/features/CmsGenerateEntryContent/index.js +1 -0
  66. package/api/features/CmsGenerateEntryContent/injectDynamicZoneTypenames.d.ts +2 -0
  67. package/api/features/CmsGenerateEntryContent/injectDynamicZoneTypenames.js +30 -0
  68. package/api/features/CmsGenerateEntryContent/injectDynamicZoneTypenames.js.map +1 -0
  69. package/api/features/CmsResolveImageTool/CmsResolveImageTool.d.ts +14 -0
  70. package/api/features/CmsResolveImageTool/CmsResolveImageTool.js +27 -0
  71. package/api/features/CmsResolveImageTool/CmsResolveImageTool.js.map +1 -0
  72. package/api/features/CmsResolveImageTool/feature.d.ts +4 -0
  73. package/api/features/CmsResolveImageTool/feature.js +11 -0
  74. package/api/features/CmsResolveImageTool/feature.js.map +1 -0
  75. package/api/features/GetSettings/GetSettingsUseCase.d.ts +1 -1
  76. package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.d.ts +3 -3
  77. package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.js +6 -6
  78. package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.js.map +1 -1
  79. package/api/graphql/BaseGraphQLSchema.d.ts +2 -2
  80. package/api/graphql/BaseGraphQLSchema.js +34 -2
  81. package/api/graphql/BaseGraphQLSchema.js.map +1 -1
  82. package/package.json +23 -22
@@ -0,0 +1,202 @@
1
+ import { computed, makeAutoObservable, runInAction } from "mobx";
2
+ import { FormModelFactory, ToolPipelineRunner } from "@webiny/app-admin";
3
+ import { CmsGenerateContentPresenter } from "./abstractions.js";
4
+ import { GenerateEntryContentUseCase } from "../../features/generateEntryContent/index.js";
5
+ import { GetSettingsUseCase } from "../../features/settings/getSettings/abstractions.js";
6
+ const SUBMIT_TIMEOUT_MS = 300000;
7
+ class CmsGenerateContentPresenterImpl {
8
+ constructor(pipelineRunner, generateEntryContent, formModelFactory, getSettings){
9
+ this.pipelineRunner = pipelineRunner;
10
+ this.generateEntryContent = generateEntryContent;
11
+ this.formModelFactory = formModelFactory;
12
+ this.getSettings = getSettings;
13
+ this._loading = false;
14
+ this._submitting = false;
15
+ this._timedOut = false;
16
+ this._form = null;
17
+ this._settings = null;
18
+ this._timeoutId = null;
19
+ this._intervalId = null;
20
+ this._elapsedSeconds = 0;
21
+ makeAutoObservable(this, {
22
+ vm: computed
23
+ }, {
24
+ autoBind: true
25
+ });
26
+ }
27
+ get vm() {
28
+ return {
29
+ form: this._form ? this._form.vm : null,
30
+ loading: this._loading,
31
+ submitting: this._submitting,
32
+ timedOut: this._timedOut,
33
+ elapsedSeconds: this._elapsedSeconds
34
+ };
35
+ }
36
+ async init() {
37
+ this._loading = true;
38
+ try {
39
+ const settings = await this.getSettings.execute();
40
+ runInAction(()=>{
41
+ this._settings = settings;
42
+ this._form = this.buildForm();
43
+ });
44
+ } finally{
45
+ runInAction(()=>{
46
+ this._loading = false;
47
+ });
48
+ }
49
+ }
50
+ async submit(modelId) {
51
+ if (!this._form) return;
52
+ const data = await this._form.submit();
53
+ if (!data) return;
54
+ runInAction(()=>{
55
+ this._submitting = true;
56
+ this._timedOut = false;
57
+ });
58
+ this.startTimeout();
59
+ try {
60
+ const excludedFileIds = this.computeExcludedFileIds(data.project, data.includedFiles);
61
+ await this.generateEntryContent.execute({
62
+ prompt: data.prompt,
63
+ modelId,
64
+ projectId: data.project || null,
65
+ excludedFileIds,
66
+ readerPersonaId: data.readerPersona || null,
67
+ writerPersonaId: data.writerPersona || null
68
+ });
69
+ } catch {
70
+ this.clearTimeout();
71
+ runInAction(()=>{
72
+ this._submitting = false;
73
+ });
74
+ }
75
+ }
76
+ async processAiResponse(responseText) {
77
+ this.clearTimeout();
78
+ runInAction(()=>{
79
+ this._submitting = false;
80
+ });
81
+ const aiResponseJson = JSON.parse(responseText);
82
+ const resolved = await this.pipelineRunner.resolve(aiResponseJson);
83
+ return resolved;
84
+ }
85
+ cancelPrompt() {
86
+ this.clearTimeout();
87
+ this._submitting = false;
88
+ }
89
+ startTimeout() {
90
+ this.clearTimeout();
91
+ this._elapsedSeconds = 0;
92
+ this._intervalId = setInterval(()=>{
93
+ runInAction(()=>{
94
+ this._elapsedSeconds++;
95
+ });
96
+ }, 1000);
97
+ this._timeoutId = setTimeout(()=>{
98
+ runInAction(()=>{
99
+ this._submitting = false;
100
+ this._timedOut = true;
101
+ });
102
+ this.clearInterval();
103
+ }, SUBMIT_TIMEOUT_MS);
104
+ }
105
+ clearTimeout() {
106
+ if (null !== this._timeoutId) {
107
+ clearTimeout(this._timeoutId);
108
+ this._timeoutId = null;
109
+ }
110
+ this.clearInterval();
111
+ }
112
+ clearInterval() {
113
+ if (null !== this._intervalId) {
114
+ clearInterval(this._intervalId);
115
+ this._intervalId = null;
116
+ }
117
+ }
118
+ buildForm() {
119
+ return this.formModelFactory.create({
120
+ fields: (fields)=>({
121
+ project: fields.text().label("Project").description("Select a predefined context to attach.").options(()=>this.getProjectOptions()).afterChange((value, { form })=>{
122
+ const projectId = value;
123
+ const project = projectId ? this._settings?.projects?.presets?.find((p)=>p.id === projectId) : void 0;
124
+ if (project?.defaultReaderPersonaId) form.field("readerPersona").setValue(project.defaultReaderPersonaId);
125
+ if (project?.defaultWriterPersonaId) form.field("writerPersona").setValue(project.defaultWriterPersonaId);
126
+ const fileIds = (project?.files ?? []).map((f)=>f.id);
127
+ form.field("includedFiles").setValue(fileIds);
128
+ }),
129
+ includedFiles: fields.text().label("Files included").description("Uncheck files to exclude them from this generation only.").options(()=>this.getProjectFileOptions()).renderer("checkboxes").list().hiddenWhen(({ form })=>{
130
+ const projectId = form.field("project").as("text").getValue();
131
+ if (!projectId) return true;
132
+ const project = this._settings?.projects?.presets?.find((p)=>p.id === projectId);
133
+ return !project?.files || 0 === project.files.length;
134
+ }),
135
+ readerPersona: fields.text().label("Reader Persona").description("Select the target audience for the generated content.").options(()=>this.getPersonaOptions("reader")),
136
+ writerPersona: fields.text().label("Writer Persona").description("Select the writing style for the generated content.").options(()=>this.getPersonaOptions("writer")),
137
+ prompt: fields.text().label("Prompt").description("Describe the content you want to generate for this entry.").required("Prompt is required").renderer("textarea", {
138
+ rows: 6
139
+ }).defaultValue("Write an evaluation guide for enterprise, self-hosted CMS platform. Use at least 3 content blocks.")
140
+ }),
141
+ layout: (layout)=>[
142
+ layout.row("project"),
143
+ layout.row("includedFiles"),
144
+ layout.row("readerPersona"),
145
+ layout.row("writerPersona"),
146
+ layout.row("prompt")
147
+ ]
148
+ });
149
+ }
150
+ getSelectedProject() {
151
+ if (!this._form || !this._settings) return;
152
+ const projectId = this._form.field("project").getValue();
153
+ if (!projectId) return;
154
+ return this._settings.projects?.presets?.find((p)=>p.id === projectId);
155
+ }
156
+ getProjectFileOptions() {
157
+ const project = this.getSelectedProject();
158
+ const files = project?.files;
159
+ if (!files || 0 === files.length) return [];
160
+ return files.map((f)=>({
161
+ label: f.name,
162
+ value: f.id
163
+ }));
164
+ }
165
+ computeExcludedFileIds(projectId, includedFiles) {
166
+ if (!projectId) return null;
167
+ const project = this._settings?.projects?.presets?.find((p)=>p.id === projectId);
168
+ const allFileIds = (project?.files ?? []).map((f)=>f.id);
169
+ if (0 === allFileIds.length) return null;
170
+ const included = new Set(includedFiles ?? []);
171
+ const excluded = allFileIds.filter((id)=>!included.has(id));
172
+ return excluded.length > 0 ? excluded : null;
173
+ }
174
+ getProjectOptions() {
175
+ const presets = this._settings?.projects?.presets;
176
+ if (!presets || 0 === presets.length) return [];
177
+ return presets.map((preset)=>({
178
+ label: preset.name,
179
+ value: preset.id
180
+ }));
181
+ }
182
+ getPersonaOptions(type) {
183
+ const presets = "reader" === type ? this._settings?.readerPersonas?.presets : this._settings?.writerPersonas?.presets;
184
+ if (!presets || 0 === presets.length) return [];
185
+ return presets.map((preset)=>({
186
+ label: preset.name,
187
+ value: preset.id
188
+ }));
189
+ }
190
+ }
191
+ const CmsGenerateContentPresenter_CmsGenerateContentPresenter = CmsGenerateContentPresenter.createImplementation({
192
+ implementation: CmsGenerateContentPresenterImpl,
193
+ dependencies: [
194
+ ToolPipelineRunner,
195
+ GenerateEntryContentUseCase,
196
+ FormModelFactory,
197
+ GetSettingsUseCase
198
+ ]
199
+ });
200
+ export { CmsGenerateContentPresenter_CmsGenerateContentPresenter as CmsGenerateContentPresenter };
201
+
202
+ //# sourceMappingURL=CmsGenerateContentPresenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/CmsContentGeneration/CmsGenerateContentPresenter.js","sources":["../../../../src/admin/presentation/CmsContentGeneration/CmsGenerateContentPresenter.ts"],"sourcesContent":["import { makeAutoObservable, computed, runInAction } from \"mobx\";\nimport { FormModelFactory, ToolPipelineRunner } from \"@webiny/app-admin\";\nimport type { FormModel } from \"@webiny/app-admin\";\nimport { CmsGenerateContentPresenter as Abstraction } from \"./abstractions.js\";\nimport { GenerateEntryContentUseCase } from \"~/admin/features/generateEntryContent/index.js\";\nimport { GetSettingsUseCase } from \"~/admin/features/settings/getSettings/abstractions.js\";\nimport type { IAiPowerUpsSettings } from \"~/admin/features/settings/shared/abstractions.js\";\n\nconst SUBMIT_TIMEOUT_MS = 300_000;\n\nclass CmsGenerateContentPresenterImpl implements Abstraction.Interface {\n private _loading = false;\n private _submitting = false;\n private _timedOut = false;\n private _form: FormModel.Interface | null = null;\n private _settings: IAiPowerUpsSettings | null = null;\n private _timeoutId: ReturnType<typeof setTimeout> | null = null;\n private _intervalId: ReturnType<typeof setInterval> | null = null;\n private _elapsedSeconds = 0;\n\n constructor(\n private pipelineRunner: ToolPipelineRunner.Interface,\n private generateEntryContent: GenerateEntryContentUseCase.Interface,\n private formModelFactory: FormModelFactory.Interface,\n private getSettings: GetSettingsUseCase.Interface\n ) {\n makeAutoObservable(this, { vm: computed }, { autoBind: true });\n }\n\n get vm(): Abstraction.ViewModel {\n return {\n form: this._form ? this._form.vm : null,\n loading: this._loading,\n submitting: this._submitting,\n timedOut: this._timedOut,\n elapsedSeconds: this._elapsedSeconds\n };\n }\n\n async init(): Promise<void> {\n this._loading = true;\n\n try {\n const settings = await this.getSettings.execute();\n runInAction(() => {\n this._settings = settings;\n this._form = this.buildForm();\n });\n } finally {\n runInAction(() => {\n this._loading = false;\n });\n }\n }\n\n async submit(modelId: string): Promise<void> {\n if (!this._form) {\n return;\n }\n\n const data = await this._form.submit<{\n prompt: string;\n project?: string;\n includedFiles?: string[];\n readerPersona?: string;\n writerPersona?: string;\n }>();\n\n if (!data) {\n return;\n }\n\n runInAction(() => {\n this._submitting = true;\n this._timedOut = false;\n });\n\n this.startTimeout();\n\n try {\n const excludedFileIds = this.computeExcludedFileIds(data.project, data.includedFiles);\n\n await this.generateEntryContent.execute({\n prompt: data.prompt,\n modelId,\n projectId: data.project || null,\n excludedFileIds,\n readerPersonaId: data.readerPersona || null,\n writerPersonaId: data.writerPersona || null\n });\n } catch {\n this.clearTimeout();\n runInAction(() => {\n this._submitting = false;\n });\n }\n }\n\n async processAiResponse(responseText: string): Promise<Record<string, unknown>> {\n this.clearTimeout();\n runInAction(() => {\n this._submitting = false;\n });\n\n const aiResponseJson = JSON.parse(responseText);\n const resolved = await this.pipelineRunner.resolve(aiResponseJson);\n return resolved as Record<string, unknown>;\n }\n\n cancelPrompt(): void {\n this.clearTimeout();\n this._submitting = false;\n }\n\n private startTimeout(): void {\n this.clearTimeout();\n this._elapsedSeconds = 0;\n this._intervalId = setInterval(() => {\n runInAction(() => {\n this._elapsedSeconds++;\n });\n }, 1000);\n this._timeoutId = setTimeout(() => {\n runInAction(() => {\n this._submitting = false;\n this._timedOut = true;\n });\n this.clearInterval();\n }, SUBMIT_TIMEOUT_MS);\n }\n\n private clearTimeout(): void {\n if (this._timeoutId !== null) {\n clearTimeout(this._timeoutId);\n this._timeoutId = null;\n }\n this.clearInterval();\n }\n\n private clearInterval(): void {\n if (this._intervalId !== null) {\n clearInterval(this._intervalId);\n this._intervalId = null;\n }\n }\n\n private buildForm() {\n return this.formModelFactory.create({\n fields: fields => ({\n project: fields\n .text()\n .label(\"Project\")\n .description(\"Select a predefined context to attach.\")\n .options(() => this.getProjectOptions())\n .afterChange((value, { form }) => {\n const projectId = value as string | undefined;\n const project = projectId\n ? this._settings?.projects?.presets?.find(p => p.id === projectId)\n : undefined;\n\n if (project?.defaultReaderPersonaId) {\n form.field(\"readerPersona\").setValue(project.defaultReaderPersonaId);\n }\n if (project?.defaultWriterPersonaId) {\n form.field(\"writerPersona\").setValue(project.defaultWriterPersonaId);\n }\n\n const fileIds = (project?.files ?? []).map((f: { id: string }) => f.id);\n form.field(\"includedFiles\").setValue(fileIds);\n }),\n includedFiles: fields\n .text()\n .label(\"Files included\")\n .description(\"Uncheck files to exclude them from this generation only.\")\n .options(() => this.getProjectFileOptions())\n .renderer(\"checkboxes\")\n .list()\n .hiddenWhen(({ form }) => {\n const projectId = form.field(\"project\").as(\"text\").getValue();\n if (!projectId) {\n return true;\n }\n const project = this._settings?.projects?.presets?.find(\n p => p.id === projectId\n );\n return !project?.files || project.files.length === 0;\n }),\n readerPersona: fields\n .text()\n .label(\"Reader Persona\")\n .description(\"Select the target audience for the generated content.\")\n .options(() => this.getPersonaOptions(\"reader\")),\n writerPersona: fields\n .text()\n .label(\"Writer Persona\")\n .description(\"Select the writing style for the generated content.\")\n .options(() => this.getPersonaOptions(\"writer\")),\n prompt: fields\n .text()\n .label(\"Prompt\")\n .description(\"Describe the content you want to generate for this entry.\")\n .required(\"Prompt is required\")\n .renderer(\"textarea\", { rows: 6 })\n .defaultValue(\n \"Write an evaluation guide for enterprise, self-hosted CMS platform. Use at least 3 content blocks.\"\n )\n }),\n layout: layout => [\n layout.row(\"project\"),\n layout.row(\"includedFiles\"),\n layout.row(\"readerPersona\"),\n layout.row(\"writerPersona\"),\n layout.row(\"prompt\")\n ]\n });\n }\n\n private getSelectedProject() {\n if (!this._form || !this._settings) {\n return undefined;\n }\n const projectId = this._form.field(\"project\").getValue<string>();\n if (!projectId) {\n return undefined;\n }\n return this._settings.projects?.presets?.find(p => p.id === projectId);\n }\n\n private getProjectFileOptions() {\n const project = this.getSelectedProject();\n const files = project?.files;\n if (!files || files.length === 0) {\n return [];\n }\n return files.map((f: { id: string; name: string }) => ({\n label: f.name,\n value: f.id\n }));\n }\n\n private computeExcludedFileIds(projectId?: string, includedFiles?: string[]): string[] | null {\n if (!projectId) {\n return null;\n }\n const project = this._settings?.projects?.presets?.find(p => p.id === projectId);\n const allFileIds = (project?.files ?? []).map((f: { id: string }) => f.id);\n if (allFileIds.length === 0) {\n return null;\n }\n const included = new Set(includedFiles ?? []);\n const excluded = allFileIds.filter((id: string) => !included.has(id));\n return excluded.length > 0 ? excluded : null;\n }\n\n private getProjectOptions() {\n const presets = this._settings?.projects?.presets;\n if (!presets || presets.length === 0) {\n return [];\n }\n return presets.map(preset => ({\n label: preset.name,\n value: preset.id\n }));\n }\n\n private getPersonaOptions(type: \"reader\" | \"writer\") {\n const presets =\n type === \"reader\"\n ? this._settings?.readerPersonas?.presets\n : this._settings?.writerPersonas?.presets;\n\n if (!presets || presets.length === 0) {\n return [];\n }\n\n return presets.map(preset => ({\n label: preset.name,\n value: preset.id\n }));\n }\n}\n\nexport const CmsGenerateContentPresenter = Abstraction.createImplementation({\n implementation: CmsGenerateContentPresenterImpl,\n dependencies: [\n ToolPipelineRunner,\n GenerateEntryContentUseCase,\n FormModelFactory,\n GetSettingsUseCase\n ]\n});\n"],"names":["SUBMIT_TIMEOUT_MS","CmsGenerateContentPresenterImpl","pipelineRunner","generateEntryContent","formModelFactory","getSettings","makeAutoObservable","computed","settings","runInAction","modelId","data","excludedFileIds","responseText","aiResponseJson","JSON","resolved","setInterval","setTimeout","clearTimeout","clearInterval","fields","value","form","projectId","project","p","undefined","fileIds","f","layout","files","includedFiles","allFileIds","included","Set","excluded","id","presets","preset","type","CmsGenerateContentPresenter","Abstraction","ToolPipelineRunner","GenerateEntryContentUseCase","FormModelFactory","GetSettingsUseCase"],"mappings":";;;;;AAQA,MAAMA,oBAAoB;AAE1B,MAAMC;IAUF,YACYC,cAA4C,EAC5CC,oBAA2D,EAC3DC,gBAA4C,EAC5CC,WAAyC,CACnD;aAJUH,cAAc,GAAdA;aACAC,oBAAoB,GAApBA;aACAC,gBAAgB,GAAhBA;aACAC,WAAW,GAAXA;aAbJ,QAAQ,GAAG;aACX,WAAW,GAAG;aACd,SAAS,GAAG;aACZ,KAAK,GAA+B;aACpC,SAAS,GAA+B;aACxC,UAAU,GAAyC;aACnD,WAAW,GAA0C;aACrD,eAAe,GAAG;QAQtBC,mBAAmB,IAAI,EAAE;YAAE,IAAIC;QAAS,GAAG;YAAE,UAAU;QAAK;IAChE;IAEA,IAAI,KAA4B;QAC5B,OAAO;YACH,MAAM,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG;YACnC,SAAS,IAAI,CAAC,QAAQ;YACtB,YAAY,IAAI,CAAC,WAAW;YAC5B,UAAU,IAAI,CAAC,SAAS;YACxB,gBAAgB,IAAI,CAAC,eAAe;QACxC;IACJ;IAEA,MAAM,OAAsB;QACxB,IAAI,CAAC,QAAQ,GAAG;QAEhB,IAAI;YACA,MAAMC,WAAW,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;YAC/CC,YAAY;gBACR,IAAI,CAAC,SAAS,GAAGD;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AE;QAGb,OAAOA,QAAQ,GAAG,CAACC,CAAAA,SAAW;gBAC1B,OAAOA,OAAO,IAAI;gBAClB,OAAOA,OAAO,EAAE;YACpB;IACJ;AACJ;AAEO,MAAME,0DAA8BC,4BAAAA,oBAAgC,CAAC;IACxE,gBAAgBzC;IAChB,cAAc;QACV0C;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare const CmsContentGeneration: () => React.JSX.Element;
@@ -0,0 +1,23 @@
1
+ import react from "react";
2
+ import { AdminConfig, RegisterFeature } from "@webiny/app-admin";
3
+ import { ContentEntryEditorConfig } from "@webiny/app-headless-cms/admin/config/contentEntries/index.js";
4
+ import { CmsGenerateContentButton } from "./CmsGenerateContentButton.js";
5
+ import { CMS_GENERATE_CONTENT_DIALOG, CmsGenerateContentDialog } from "./CmsGenerateContentDialog.js";
6
+ import { CmsGenerateContentFeature } from "./feature.js";
7
+ import { GenerateEntryContentFeature } from "../../features/generateEntryContent/index.js";
8
+ const { Actions: Actions } = ContentEntryEditorConfig;
9
+ const CmsContentGeneration = ()=>/*#__PURE__*/ react.createElement(react.Fragment, null, /*#__PURE__*/ react.createElement(RegisterFeature, {
10
+ feature: CmsGenerateContentFeature
11
+ }), /*#__PURE__*/ react.createElement(RegisterFeature, {
12
+ feature: GenerateEntryContentFeature
13
+ }), /*#__PURE__*/ react.createElement(AdminConfig, null, /*#__PURE__*/ react.createElement(AdminConfig.Dialog, {
14
+ name: CMS_GENERATE_CONTENT_DIALOG,
15
+ element: /*#__PURE__*/ react.createElement(CmsGenerateContentDialog, null)
16
+ })), /*#__PURE__*/ react.createElement(ContentEntryEditorConfig, null, /*#__PURE__*/ react.createElement(Actions.ButtonAction, {
17
+ name: "generateEntryContent",
18
+ before: "save",
19
+ element: /*#__PURE__*/ react.createElement(CmsGenerateContentButton, null)
20
+ })));
21
+ export { CmsContentGeneration };
22
+
23
+ //# sourceMappingURL=Extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/CmsContentGeneration/Extension.js","sources":["../../../../src/admin/presentation/CmsContentGeneration/Extension.tsx"],"sourcesContent":["import React from \"react\";\nimport { AdminConfig, RegisterFeature } from \"@webiny/app-admin\";\nimport { ContentEntryEditorConfig } from \"@webiny/app-headless-cms/admin/config/contentEntries/index.js\";\nimport { CmsGenerateContentButton } from \"~/admin/presentation/CmsContentGeneration/CmsGenerateContentButton.js\";\nimport {\n CmsGenerateContentDialog,\n CMS_GENERATE_CONTENT_DIALOG\n} from \"~/admin/presentation/CmsContentGeneration/CmsGenerateContentDialog.js\";\nimport { CmsGenerateContentFeature } from \"~/admin/presentation/CmsContentGeneration/feature.js\";\nimport { GenerateEntryContentFeature } from \"~/admin/features/generateEntryContent/index.js\";\n\nconst { Actions } = ContentEntryEditorConfig;\n\nexport const CmsContentGeneration = () => {\n return (\n <>\n <RegisterFeature feature={CmsGenerateContentFeature} />\n <RegisterFeature feature={GenerateEntryContentFeature} />\n <AdminConfig>\n <AdminConfig.Dialog\n name={CMS_GENERATE_CONTENT_DIALOG}\n element={<CmsGenerateContentDialog />}\n />\n </AdminConfig>\n <ContentEntryEditorConfig>\n <Actions.ButtonAction\n name={\"generateEntryContent\"}\n before={\"save\"}\n element={<CmsGenerateContentButton />}\n />\n </ContentEntryEditorConfig>\n </>\n );\n};\n"],"names":["Actions","ContentEntryEditorConfig","CmsContentGeneration","RegisterFeature","CmsGenerateContentFeature","GenerateEntryContentFeature","AdminConfig","CMS_GENERATE_CONTENT_DIALOG","CmsGenerateContentDialog","CmsGenerateContentButton"],"mappings":";;;;;;;AAWA,MAAM,EAAEA,SAAAA,OAAO,EAAE,GAAGC;AAEb,MAAMC,uBAAuB,IACzB,WAAP,GACI,wDACI,oBAACC,iBAAeA;QAAC,SAASC;sBAC1B,oBAACD,iBAAeA;QAAC,SAASE;sBAC1B,oBAACC,aAAWA,MAAAA,WAAAA,GACR,oBAACA,YAAY,MAAM;QACf,MAAMC;QACN,uBAAS,oBAACC,0BAAwBA;uBAG1C,oBAACP,0BAAwBA,MAAAA,WAAAA,GACrB,oBAACD,QAAQ,YAAY;QACjB,MAAM;QACN,QAAQ;QACR,uBAAS,oBAACS,0BAAwBA"}
@@ -0,0 +1,20 @@
1
+ import type { IFormVM } from "@webiny/app-admin/features/formModel/abstractions.js";
2
+ export interface ICmsGenerateContentVm {
3
+ form: IFormVM | null;
4
+ loading: boolean;
5
+ submitting: boolean;
6
+ timedOut: boolean;
7
+ elapsedSeconds: number;
8
+ }
9
+ export interface ICmsGenerateContentPresenter {
10
+ readonly vm: ICmsGenerateContentVm;
11
+ init(): Promise<void>;
12
+ submit(modelId: string): Promise<void>;
13
+ cancelPrompt(): void;
14
+ processAiResponse(responseText: string): Promise<Record<string, unknown>>;
15
+ }
16
+ export declare const CmsGenerateContentPresenter: import("@webiny/di").Abstraction<ICmsGenerateContentPresenter>;
17
+ export declare namespace CmsGenerateContentPresenter {
18
+ type Interface = ICmsGenerateContentPresenter;
19
+ type ViewModel = ICmsGenerateContentVm;
20
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/admin";
2
+ const CmsGenerateContentPresenter = createAbstraction("CmsContentGeneration/Presenter");
3
+ export { CmsGenerateContentPresenter };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/CmsContentGeneration/abstractions.js","sources":["../../../../src/admin/presentation/CmsContentGeneration/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { IFormVM } from \"@webiny/app-admin/features/formModel/abstractions.js\";\n\nexport interface ICmsGenerateContentVm {\n form: IFormVM | null;\n loading: boolean;\n submitting: boolean;\n timedOut: boolean;\n elapsedSeconds: number;\n}\n\nexport interface ICmsGenerateContentPresenter {\n readonly vm: ICmsGenerateContentVm;\n init(): Promise<void>;\n submit(modelId: string): Promise<void>;\n cancelPrompt(): void;\n processAiResponse(responseText: string): Promise<Record<string, unknown>>;\n}\n\nexport const CmsGenerateContentPresenter = createAbstraction<ICmsGenerateContentPresenter>(\n \"CmsContentGeneration/Presenter\"\n);\n\nexport namespace CmsGenerateContentPresenter {\n export type Interface = ICmsGenerateContentPresenter;\n export type ViewModel = ICmsGenerateContentVm;\n}\n"],"names":["CmsGenerateContentPresenter","createAbstraction"],"mappings":";AAmBO,MAAMA,8BAA8BC,kBACvC"}
@@ -0,0 +1,3 @@
1
+ export declare const CmsGenerateContentFeature: import("@webiny/feature/admin").FeatureDefinition<{
2
+ presenter: import("./abstractions.js").ICmsGenerateContentPresenter;
3
+ }, []>;
@@ -0,0 +1,17 @@
1
+ import { createFeature } from "@webiny/feature/admin";
2
+ import { CmsGenerateContentPresenter } from "./abstractions.js";
3
+ import { CmsGenerateContentPresenter as external_CmsGenerateContentPresenter_js_CmsGenerateContentPresenter } from "./CmsGenerateContentPresenter.js";
4
+ const CmsGenerateContentFeature = createFeature({
5
+ name: "CmsContentGeneration/Presenter",
6
+ register (container) {
7
+ container.register(external_CmsGenerateContentPresenter_js_CmsGenerateContentPresenter);
8
+ },
9
+ resolve (container) {
10
+ return {
11
+ presenter: container.resolve(CmsGenerateContentPresenter)
12
+ };
13
+ }
14
+ });
15
+ export { CmsGenerateContentFeature };
16
+
17
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/CmsContentGeneration/feature.js","sources":["../../../../src/admin/presentation/CmsContentGeneration/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { CmsGenerateContentPresenter as Abstraction } from \"./abstractions.js\";\nimport { CmsGenerateContentPresenter } from \"./CmsGenerateContentPresenter.js\";\n\nexport const CmsGenerateContentFeature = createFeature({\n name: \"CmsContentGeneration/Presenter\",\n register(container) {\n container.register(CmsGenerateContentPresenter);\n },\n resolve(container) {\n return {\n presenter: container.resolve(Abstraction)\n };\n }\n});\n"],"names":["CmsGenerateContentFeature","createFeature","container","CmsGenerateContentPresenter","Abstraction"],"mappings":";;;AAIO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;IACA,SAAQD,SAAS;QACb,OAAO;YACH,WAAWA,UAAU,OAAO,CAACE;QACjC;IACJ;AACJ"}
@@ -16,8 +16,8 @@ class ProjectsSettingsImpl {
16
16
  instructions: f.text().label("Instructions").description("System-prompt-style guidance that will be sent to the LLM when this project is selected.").renderer("textarea", {
17
17
  rows: 6
18
18
  }),
19
- defaultReaderPersonaId: f.text().label("Default Reader Persona").description("Auto-populates the reader persona when this project is selected.").options((formModel)=>{
20
- const data = formModel.getData();
19
+ defaultReaderPersonaId: f.text().label("Default Reader Persona").description("Auto-populates the reader persona when this project is selected.").options(({ form })=>{
20
+ const data = form.getData();
21
21
  const presets = data?.readerPersonas?.presets;
22
22
  if (!presets || 0 === presets.length) return [];
23
23
  return presets.map((preset)=>({
@@ -25,8 +25,8 @@ class ProjectsSettingsImpl {
25
25
  value: preset.id
26
26
  }));
27
27
  }),
28
- defaultWriterPersonaId: f.text().label("Default Writer Persona").description("Auto-populates the writer persona when this project is selected.").options((formModel)=>{
29
- const data = formModel.getData();
28
+ defaultWriterPersonaId: f.text().label("Default Writer Persona").description("Auto-populates the writer persona when this project is selected.").options(({ form })=>{
29
+ const data = form.getData();
30
30
  const presets = data?.writerPersonas?.presets;
31
31
  if (!presets || 0 === presets.length) return [];
32
32
  return presets.map((preset)=>({
@@ -1 +1 @@
1
- {"version":3,"file":"admin/presentation/ProjectsSettings.js","sources":["../../../src/admin/presentation/ProjectsSettings.ts"],"sourcesContent":["import { generateAlphaNumericId } from \"@webiny/utils\";\nimport type { IFormModel } from \"@webiny/app-admin\";\nimport { AiPowerUpsSettingsGroup } from \"./AiPowerUpsSettings/settingsGroup.js\";\n\nclass ProjectsSettingsImpl implements AiPowerUpsSettingsGroup.Interface {\n name = \"projects\";\n label = \"Projects\";\n description = \"Predefined prompting contexts.\";\n\n buildForm(form: AiPowerUpsSettingsGroup.FormBuilder): void {\n form.fields(fields => ({\n presets: fields\n .object()\n .label(\"Presets\")\n .renderer(\"objectAccordionMultiple\", {\n container: false,\n addItemLabel: \"Add project\",\n itemTitle: (data, index) => String(data.name || `Project #${index + 1}`)\n })\n .fields(f => ({\n id: f\n .text()\n .hidden()\n .defaultValue(() => generateAlphaNumericId(10)),\n name: f\n .text()\n .label(\"Name\")\n .required(\"Name is required\")\n .description(\"This name will be used to identify the project in the UI.\"),\n description: f\n .text()\n .label(\"Description\")\n .description(\n \"Human-facing description shown in the project picker. Not sent to the LLM.\"\n )\n .renderer(\"textarea\", { rows: 3 }),\n instructions: f\n .text()\n .label(\"Instructions\")\n .description(\n \"System-prompt-style guidance that will be sent to the LLM when this project is selected.\"\n )\n .renderer(\"textarea\", { rows: 6 }),\n defaultReaderPersonaId: f\n .text()\n .label(\"Default Reader Persona\")\n .description(\n \"Auto-populates the reader persona when this project is selected.\"\n )\n .options((formModel: IFormModel) => {\n const data = formModel.getData();\n const presets = data?.readerPersonas?.presets;\n if (!presets || presets.length === 0) {\n return [];\n }\n return presets.map((preset: { id: string; name: string }) => ({\n label: preset.name,\n value: preset.id\n }));\n }),\n defaultWriterPersonaId: f\n .text()\n .label(\"Default Writer Persona\")\n .description(\n \"Auto-populates the writer persona when this project is selected.\"\n )\n .options((formModel: IFormModel) => {\n const data = formModel.getData();\n const presets = data?.writerPersonas?.presets;\n if (!presets || presets.length === 0) {\n return [];\n }\n return presets.map((preset: { id: string; name: string }) => ({\n label: preset.name,\n value: preset.id\n }));\n }),\n files: f\n .file()\n .label(\"Files\")\n .list()\n .description(\n \"Add files from the library to include as context for the LLM.\"\n )\n .note(\n \"Only files containing text will be sent to the LLM (.mdx, .md, .html, .json, .csv, .txt, etc.)\"\n )\n }))\n .list()\n }));\n\n form.layout(layout => [layout.row(\"presets\")]);\n }\n}\n\nexport const ProjectsSettings = AiPowerUpsSettingsGroup.createImplementation({\n implementation: ProjectsSettingsImpl,\n dependencies: []\n});\n"],"names":["ProjectsSettingsImpl","form","fields","data","index","String","f","generateAlphaNumericId","formModel","presets","preset","layout","ProjectsSettings","AiPowerUpsSettingsGroup"],"mappings":";;AAIA,MAAMA;IAKF,UAAUC,IAAyC,EAAQ;QACvDA,KAAK,MAAM,CAACC,CAAAA,SAAW;gBACnB,SAASA,OACJ,MAAM,GACN,KAAK,CAAC,WACN,QAAQ,CAAC,2BAA2B;oBACjC,WAAW;oBACX,cAAc;oBACd,WAAW,CAACC,MAAMC,QAAUC,OAAOF,KAAK,IAAI,IAAI,CAAC,SAAS,EAAEC,QAAQ,GAAG;gBAC3E,GACC,MAAM,CAACE,CAAAA,IAAM;wBACV,IAAIA,EACC,IAAI,GACJ,MAAM,GACN,YAAY,CAAC,IAAMC,uBAAuB;wBAC/C,MAAMD,EACD,IAAI,GACJ,KAAK,CAAC,QACN,QAAQ,CAAC,oBACT,WAAW,CAAC;wBACjB,aAAaA,EACR,IAAI,GACJ,KAAK,CAAC,eACN,WAAW,CACR,8EAEH,QAAQ,CAAC,YAAY;4BAAE,MAAM;wBAAE;wBACpC,cAAcA,EACT,IAAI,GACJ,KAAK,CAAC,gBACN,WAAW,CACR,4FAEH,QAAQ,CAAC,YAAY;4BAAE,MAAM;wBAAE;wBACpC,wBAAwBA,EACnB,IAAI,GACJ,KAAK,CAAC,0BACN,WAAW,CACR,oEAEH,OAAO,CAAC,CAACE;4BACN,MAAML,OAAOK,UAAU,OAAO;4BAC9B,MAAMC,UAAUN,MAAM,gBAAgB;4BACtC,IAAI,CAACM,WAAWA,AAAmB,MAAnBA,QAAQ,MAAM,EAC1B,OAAO,EAAE;4BAEb,OAAOA,QAAQ,GAAG,CAAC,CAACC,SAA0C;oCAC1D,OAAOA,OAAO,IAAI;oCAClB,OAAOA,OAAO,EAAE;gCACpB;wBACJ;wBACJ,wBAAwBJ,EACnB,IAAI,GACJ,KAAK,CAAC,0BACN,WAAW,CACR,oEAEH,OAAO,CAAC,CAACE;4BACN,MAAML,OAAOK,UAAU,OAAO;4BAC9B,MAAMC,UAAUN,MAAM,gBAAgB;4BACtC,IAAI,CAACM,WAAWA,AAAmB,MAAnBA,QAAQ,MAAM,EAC1B,OAAO,EAAE;4BAEb,OAAOA,QAAQ,GAAG,CAAC,CAACC,SAA0C;oCAC1D,OAAOA,OAAO,IAAI;oCAClB,OAAOA,OAAO,EAAE;gCACpB;wBACJ;wBACJ,OAAOJ,EACF,IAAI,GACJ,KAAK,CAAC,SACN,IAAI,GACJ,WAAW,CACR,iEAEH,IAAI,CACD;oBAEZ,IACC,IAAI;YACb;QAEAL,KAAK,MAAM,CAACU,CAAAA,SAAU;gBAACA,OAAO,GAAG,CAAC;aAAW;IACjD;;aAvFA,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAAG;;AAsFlB;AAEO,MAAMC,mBAAmBC,wBAAwB,oBAAoB,CAAC;IACzE,gBAAgBb;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"admin/presentation/ProjectsSettings.js","sources":["../../../src/admin/presentation/ProjectsSettings.ts"],"sourcesContent":["import { generateAlphaNumericId } from \"@webiny/utils\";\nimport { AiPowerUpsSettingsGroup } from \"./AiPowerUpsSettings/settingsGroup.js\";\n\nclass ProjectsSettingsImpl implements AiPowerUpsSettingsGroup.Interface {\n name = \"projects\";\n label = \"Projects\";\n description = \"Predefined prompting contexts.\";\n\n buildForm(form: AiPowerUpsSettingsGroup.FormBuilder): void {\n form.fields(fields => ({\n presets: fields\n .object()\n .label(\"Presets\")\n .renderer(\"objectAccordionMultiple\", {\n container: false,\n addItemLabel: \"Add project\",\n itemTitle: (data, index) => String(data.name || `Project #${index + 1}`)\n })\n .fields(f => ({\n id: f\n .text()\n .hidden()\n .defaultValue(() => generateAlphaNumericId(10)),\n name: f\n .text()\n .label(\"Name\")\n .required(\"Name is required\")\n .description(\"This name will be used to identify the project in the UI.\"),\n description: f\n .text()\n .label(\"Description\")\n .description(\n \"Human-facing description shown in the project picker. Not sent to the LLM.\"\n )\n .renderer(\"textarea\", { rows: 3 }),\n instructions: f\n .text()\n .label(\"Instructions\")\n .description(\n \"System-prompt-style guidance that will be sent to the LLM when this project is selected.\"\n )\n .renderer(\"textarea\", { rows: 6 }),\n defaultReaderPersonaId: f\n .text()\n .label(\"Default Reader Persona\")\n .description(\n \"Auto-populates the reader persona when this project is selected.\"\n )\n .options(({ form }) => {\n const data = form.getData();\n const presets = data?.readerPersonas?.presets;\n if (!presets || presets.length === 0) {\n return [];\n }\n return presets.map((preset: { id: string; name: string }) => ({\n label: preset.name,\n value: preset.id\n }));\n }),\n defaultWriterPersonaId: f\n .text()\n .label(\"Default Writer Persona\")\n .description(\n \"Auto-populates the writer persona when this project is selected.\"\n )\n .options(({ form }) => {\n const data = form.getData();\n const presets = data?.writerPersonas?.presets;\n if (!presets || presets.length === 0) {\n return [];\n }\n return presets.map((preset: { id: string; name: string }) => ({\n label: preset.name,\n value: preset.id\n }));\n }),\n files: f\n .file()\n .label(\"Files\")\n .list()\n .description(\n \"Add files from the library to include as context for the LLM.\"\n )\n .note(\n \"Only files containing text will be sent to the LLM (.mdx, .md, .html, .json, .csv, .txt, etc.)\"\n )\n }))\n .list()\n }));\n\n form.layout(layout => [layout.row(\"presets\")]);\n }\n}\n\nexport const ProjectsSettings = AiPowerUpsSettingsGroup.createImplementation({\n implementation: ProjectsSettingsImpl,\n dependencies: []\n});\n"],"names":["ProjectsSettingsImpl","form","fields","data","index","String","f","generateAlphaNumericId","presets","preset","layout","ProjectsSettings","AiPowerUpsSettingsGroup"],"mappings":";;AAGA,MAAMA;IAKF,UAAUC,IAAyC,EAAQ;QACvDA,KAAK,MAAM,CAACC,CAAAA,SAAW;gBACnB,SAASA,OACJ,MAAM,GACN,KAAK,CAAC,WACN,QAAQ,CAAC,2BAA2B;oBACjC,WAAW;oBACX,cAAc;oBACd,WAAW,CAACC,MAAMC,QAAUC,OAAOF,KAAK,IAAI,IAAI,CAAC,SAAS,EAAEC,QAAQ,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Z,IACC,IAAI;YACb;QAEAL,KAAK,MAAM,CAACS,CAAAA,SAAU;gBAACA,OAAO,GAAG,CAAC;aAAW;IACjD;;aAvFA,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAAG;;AAsFlB;AAEO,MAAMC,mBAAmBC,wBAAwB,oBAAoB,CAAC;IACzE,gBAAgBZ;IAChB,cAAc,EAAE;AACpB"}
@@ -158,7 +158,7 @@ class GenerateContentPresenterImpl {
158
158
  buildForm() {
159
159
  return this.formModelFactory.create({
160
160
  fields: (fields)=>({
161
- project: fields.text().label("Project").description("Select a predefined context to attach.").options(()=>this.getProjectOptions()).afterChange((value, form)=>{
161
+ project: fields.text().label("Project").description("Select a predefined context to attach.").options(()=>this.getProjectOptions()).afterChange((value, { form })=>{
162
162
  const projectId = value;
163
163
  const project = projectId ? this._settings?.projects?.presets?.find((p)=>p.id === projectId) : void 0;
164
164
  if (project?.defaultReaderPersonaId) form.field("readerPersona").setValue(project.defaultReaderPersonaId);
@@ -166,7 +166,7 @@ class GenerateContentPresenterImpl {
166
166
  const fileIds = (project?.files ?? []).map((f)=>f.id);
167
167
  form.field("includedFiles").setValue(fileIds);
168
168
  }),
169
- includedFiles: fields.text().label("Files included").description("Uncheck files to exclude them from this generation only.").options(()=>this.getProjectFileOptions()).renderer("checkboxes").list().hiddenWhen((form)=>{
169
+ includedFiles: fields.text().label("Files included").description("Uncheck files to exclude them from this generation only.").options(()=>this.getProjectFileOptions()).renderer("checkboxes").list().hiddenWhen(({ form })=>{
170
170
  const projectId = form.field("project").as("text").getValue();
171
171
  if (!projectId) return true;
172
172
  const project = this._settings?.projects?.presets?.find((p)=>p.id === projectId);
@@ -1 +1 @@
1
- {"version":3,"file":"admin/presentation/WbContentGeneration/GenerateContentPresenter.js","sources":["../../../../src/admin/presentation/WbContentGeneration/GenerateContentPresenter.ts"],"sourcesContent":["import { makeAutoObservable, computed, toJS, runInAction } from \"mobx\";\nimport { z } from \"zod\";\nimport pick from \"lodash/pick.js\";\nimport { FormModelFactory, FormModel, ToolRegistry, ToolPipelineRunner } from \"@webiny/app-admin\";\nimport { GenerateContentPresenter, type CreateElementsFn } from \"./abstractions.js\";\nimport { GeneratePageContentUseCase } from \"~/admin/features/generatePageContent/index.js\";\nimport { GetSettingsUseCase } from \"~/admin/features/settings/getSettings/abstractions.js\";\nimport type { IAiPowerUpsSettings } from \"~/admin/features/settings/shared/abstractions.js\";\n\nconst SUBMIT_TIMEOUT_MS = 300_000;\n\nclass GenerateContentPresenterImpl implements GenerateContentPresenter.Interface {\n private _loading = false;\n private _submitting = false;\n private _processing = false;\n private _timedOut = false;\n private _components: Record<string, any>[] = [];\n private _createElements: CreateElementsFn = () => {};\n private _form: FormModel.Interface | null = null;\n private _settings: IAiPowerUpsSettings | null = null;\n private _timeoutId: ReturnType<typeof setTimeout> | null = null;\n private _intervalId: ReturnType<typeof setInterval> | null = null;\n private _elapsedSeconds = 0;\n\n constructor(\n private toolRegistry: ToolRegistry.Interface,\n private pipelineRunner: ToolPipelineRunner.Interface,\n private generatePageContent: GeneratePageContentUseCase.Interface,\n private formModelFactory: FormModelFactory.Interface,\n private getSettings: GetSettingsUseCase.Interface\n ) {\n makeAutoObservable(this, { vm: computed }, { autoBind: true });\n }\n\n get vm(): GenerateContentPresenter.ViewModel {\n return {\n form: this._form ? this._form.vm : null,\n loading: this._loading,\n submitting: this._submitting,\n processing: this._processing,\n timedOut: this._timedOut,\n elapsedSeconds: this._elapsedSeconds\n };\n }\n\n async init(components: Record<string, any>[], createElements: CreateElementsFn): Promise<void> {\n this._components = components;\n this._createElements = createElements;\n\n this._loading = true;\n\n try {\n const settings = await this.getSettings.execute();\n runInAction(() => {\n this._settings = settings;\n this._form = this.buildForm();\n });\n } finally {\n runInAction(() => {\n this._loading = false;\n });\n }\n }\n\n async submit(): Promise<void> {\n if (!this._form) {\n return;\n }\n\n const data = await this._form.submit<{\n prompt: string;\n project?: string;\n includedFiles?: string[];\n readerPersona?: string;\n writerPersona?: string;\n }>();\n\n if (!data) {\n return;\n }\n\n runInAction(() => {\n this._submitting = true;\n this._timedOut = false;\n });\n\n this.startTimeout();\n\n try {\n const tools = this.toolRegistry.getTools().map(tool => ({\n name: tool.name,\n description: tool.description,\n inputSchema: pick(z.toJSONSchema(tool.inputSchema), [\"properties\", \"type\"]),\n outputSchema: pick(z.toJSONSchema(tool.outputSchema), [\"properties\", \"type\"])\n }));\n\n const excludedFileIds = this.computeExcludedFileIds(data.project, data.includedFiles);\n\n await this.generatePageContent.execute({\n prompt: data.prompt,\n components: toJS(this._components),\n tools,\n projectId: data.project || null,\n excludedFileIds,\n readerPersonaId: data.readerPersona || null,\n writerPersonaId: data.writerPersona || null\n });\n } catch {\n this.clearTimeout();\n runInAction(() => {\n this._submitting = false;\n });\n }\n }\n\n async processAiResponse(responseText: string): Promise<void> {\n this.clearTimeout();\n runInAction(() => {\n this._processing = true;\n this._submitting = false;\n });\n\n try {\n const aiResponseJson = JSON.parse(responseText);\n const resolved = await this.pipelineRunner.resolve(aiResponseJson);\n const items = Array.isArray(resolved) ? resolved : [resolved];\n\n await this._createElements(\n items.map((element: { component: string; inputs: Record<string, unknown> }) => ({\n componentName: element.component,\n parentId: \"root\",\n slot: \"children\",\n bindings: { inputs: element.inputs }\n }))\n );\n } finally {\n runInAction(() => {\n this._processing = false;\n });\n }\n }\n\n cancelPrompt(): void {\n this.clearTimeout();\n this._processing = false;\n this._submitting = false;\n }\n\n private startTimeout(): void {\n this.clearTimeout();\n this._elapsedSeconds = 0;\n this._intervalId = setInterval(() => {\n runInAction(() => {\n this._elapsedSeconds++;\n });\n }, 1000);\n this._timeoutId = setTimeout(() => {\n runInAction(() => {\n this._submitting = false;\n this._timedOut = true;\n });\n this.clearInterval();\n }, SUBMIT_TIMEOUT_MS);\n }\n\n private clearTimeout(): void {\n if (this._timeoutId !== null) {\n clearTimeout(this._timeoutId);\n this._timeoutId = null;\n }\n this.clearInterval();\n }\n\n private clearInterval(): void {\n if (this._intervalId !== null) {\n clearInterval(this._intervalId);\n this._intervalId = null;\n }\n }\n\n private buildForm() {\n return this.formModelFactory.create({\n fields: fields => ({\n project: fields\n .text()\n .label(\"Project\")\n .description(\"Select a predefined context to attach.\")\n .options(() => this.getProjectOptions())\n .afterChange((value, form) => {\n const projectId = value as string | undefined;\n const project = projectId\n ? this._settings?.projects?.presets?.find(p => p.id === projectId)\n : undefined;\n\n if (project?.defaultReaderPersonaId) {\n form.field(\"readerPersona\").setValue(project.defaultReaderPersonaId);\n }\n if (project?.defaultWriterPersonaId) {\n form.field(\"writerPersona\").setValue(project.defaultWriterPersonaId);\n }\n\n const fileIds = (project?.files ?? []).map(f => f.id);\n form.field(\"includedFiles\").setValue(fileIds);\n }),\n includedFiles: fields\n .text()\n .label(\"Files included\")\n .description(\"Uncheck files to exclude them from this generation only.\")\n .options(() => this.getProjectFileOptions())\n .renderer(\"checkboxes\")\n .list()\n .hiddenWhen(form => {\n const projectId = form.field(\"project\").as(\"text\").getValue();\n if (!projectId) {\n return true;\n }\n const project = this._settings?.projects?.presets?.find(\n p => p.id === projectId\n );\n return !project?.files || project.files.length === 0;\n }),\n readerPersona: fields\n .text()\n .label(\"Reader Persona\")\n .description(\"Select the target audience for the generated content.\")\n .options(() => this.getPersonaOptions(\"reader\")),\n writerPersona: fields\n .text()\n .label(\"Writer Persona\")\n .description(\"Select the writing style for the generated content.\")\n .options(() => this.getPersonaOptions(\"writer\")),\n prompt: fields\n .text()\n .label(\"Prompt\")\n .description(\"Describe the page content you want to generate.\")\n .required(\"Prompt is required\")\n .renderer(\"textarea\", { rows: 6 })\n }),\n layout: layout => [\n layout.row(\"project\"),\n layout.row(\"includedFiles\"),\n layout.row(\"readerPersona\"),\n layout.row(\"writerPersona\"),\n layout.row(\"prompt\")\n ]\n });\n }\n\n private getSelectedProject() {\n if (!this._form || !this._settings) {\n return undefined;\n }\n const projectId = this._form.field(\"project\").getValue<string>();\n if (!projectId) {\n return undefined;\n }\n return this._settings.projects?.presets?.find(p => p.id === projectId);\n }\n\n private getProjectFileOptions() {\n const project = this.getSelectedProject();\n const files = project?.files;\n if (!files || files.length === 0) {\n return [];\n }\n return files.map(f => ({\n label: f.name,\n value: f.id\n }));\n }\n\n private computeExcludedFileIds(projectId?: string, includedFiles?: string[]): string[] | null {\n if (!projectId) {\n return null;\n }\n const project = this._settings?.projects?.presets?.find(p => p.id === projectId);\n const allFileIds = (project?.files ?? []).map(f => f.id);\n if (allFileIds.length === 0) {\n return null;\n }\n const included = new Set(includedFiles ?? []);\n const excluded = allFileIds.filter(id => !included.has(id));\n return excluded.length > 0 ? excluded : null;\n }\n\n private getProjectOptions() {\n const presets = this._settings?.projects?.presets;\n if (!presets || presets.length === 0) {\n return [];\n }\n return presets.map(preset => ({\n label: preset.name,\n value: preset.id\n }));\n }\n\n private getPersonaOptions(type: \"reader\" | \"writer\") {\n const presets =\n type === \"reader\"\n ? this._settings?.readerPersonas?.presets\n : this._settings?.writerPersonas?.presets;\n\n if (!presets || presets.length === 0) {\n return [];\n }\n\n return presets.map(preset => ({\n label: preset.name,\n value: preset.id\n }));\n }\n}\n\nexport const GenerateContentPresenterRegistration = GenerateContentPresenter.createImplementation({\n implementation: GenerateContentPresenterImpl,\n dependencies: [\n ToolRegistry,\n ToolPipelineRunner,\n GeneratePageContentUseCase,\n FormModelFactory,\n GetSettingsUseCase\n ]\n});\n"],"names":["SUBMIT_TIMEOUT_MS","GenerateContentPresenterImpl","toolRegistry","pipelineRunner","generatePageContent","formModelFactory","getSettings","makeAutoObservable","computed","components","createElements","settings","runInAction","data","tools","tool","pick","z","excludedFileIds","toJS","responseText","aiResponseJson","JSON","resolved","items","Array","element","setInterval","setTimeout","clearTimeout","clearInterval","fields","value","form","projectId","project","p","undefined","fileIds","f","layout","files","includedFiles","allFileIds","included","Set","excluded","id","presets","preset","type","GenerateContentPresenterRegistration","GenerateContentPresenter","ToolRegistry","ToolPipelineRunner","GeneratePageContentUseCase","FormModelFactory","GetSettingsUseCase"],"mappings":";;;;;;;AASA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;IAEQ,oBAAoB;QACxB,MAAME,UAAU,IAAI,CAAC,SAAS,EAAE,UAAU;QAC1C,IAAI,CAACA,WAAWA,AAAmB,MAAnBA,QAAQ,MAAM,EAC1B,OAAO,EAAE;QAEb,OAAOA,QAAQ,GAAG,CAACC,CAAAA,SAAW;gBAC1B,OAAOA,OAAO,IAAI;gBAClB,OAAOA,OAAO,EAAE;YACpB;IACJ;IAEQ,kBAAkBC,IAAyB,EAAE;QACjD,MAAMF,UACFE,AAAS,aAATA,OACM,IAAI,CAAC,SAAS,EAAE,gBAAgB,UAChC,IAAI,CAAC,SAAS,EAAE,gBAAgB;QAE1C,IAAI,CAACF,WAAWA,AAAmB,MAAnBA,QAAQ,MAAM,EAC1B,OAAO,EAAE;QAGb,OAAOA,QAAQ,GAAG,CAACC,CAAAA,SAAW;gBAC1B,OAAOA,OAAO,IAAI;gBAClB,OAAOA,OAAO,EAAE;YACpB;IACJ;AACJ;AAEO,MAAME,uCAAuCC,yBAAyB,oBAAoB,CAAC;IAC9F,gBAAgBnD;IAChB,cAAc;QACVoD;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"admin/presentation/WbContentGeneration/GenerateContentPresenter.js","sources":["../../../../src/admin/presentation/WbContentGeneration/GenerateContentPresenter.ts"],"sourcesContent":["import { makeAutoObservable, computed, toJS, runInAction } from \"mobx\";\nimport { z } from \"zod\";\nimport pick from \"lodash/pick.js\";\nimport { FormModelFactory, FormModel, ToolRegistry, ToolPipelineRunner } from \"@webiny/app-admin\";\nimport { GenerateContentPresenter, type CreateElementsFn } from \"./abstractions.js\";\nimport { GeneratePageContentUseCase } from \"~/admin/features/generatePageContent/index.js\";\nimport { GetSettingsUseCase } from \"~/admin/features/settings/getSettings/abstractions.js\";\nimport type { IAiPowerUpsSettings } from \"~/admin/features/settings/shared/abstractions.js\";\n\nconst SUBMIT_TIMEOUT_MS = 300_000;\n\nclass GenerateContentPresenterImpl implements GenerateContentPresenter.Interface {\n private _loading = false;\n private _submitting = false;\n private _processing = false;\n private _timedOut = false;\n private _components: Record<string, any>[] = [];\n private _createElements: CreateElementsFn = () => {};\n private _form: FormModel.Interface | null = null;\n private _settings: IAiPowerUpsSettings | null = null;\n private _timeoutId: ReturnType<typeof setTimeout> | null = null;\n private _intervalId: ReturnType<typeof setInterval> | null = null;\n private _elapsedSeconds = 0;\n\n constructor(\n private toolRegistry: ToolRegistry.Interface,\n private pipelineRunner: ToolPipelineRunner.Interface,\n private generatePageContent: GeneratePageContentUseCase.Interface,\n private formModelFactory: FormModelFactory.Interface,\n private getSettings: GetSettingsUseCase.Interface\n ) {\n makeAutoObservable(this, { vm: computed }, { autoBind: true });\n }\n\n get vm(): GenerateContentPresenter.ViewModel {\n return {\n form: this._form ? this._form.vm : null,\n loading: this._loading,\n submitting: this._submitting,\n processing: this._processing,\n timedOut: this._timedOut,\n elapsedSeconds: this._elapsedSeconds\n };\n }\n\n async init(components: Record<string, any>[], createElements: CreateElementsFn): Promise<void> {\n this._components = components;\n this._createElements = createElements;\n\n this._loading = true;\n\n try {\n const settings = await this.getSettings.execute();\n runInAction(() => {\n this._settings = settings;\n this._form = this.buildForm();\n });\n } finally {\n runInAction(() => {\n this._loading = false;\n });\n }\n }\n\n async submit(): Promise<void> {\n if (!this._form) {\n return;\n }\n\n const data = await this._form.submit<{\n prompt: string;\n project?: string;\n includedFiles?: string[];\n readerPersona?: string;\n writerPersona?: string;\n }>();\n\n if (!data) {\n return;\n }\n\n runInAction(() => {\n this._submitting = true;\n this._timedOut = false;\n });\n\n this.startTimeout();\n\n try {\n const tools = this.toolRegistry.getTools().map(tool => ({\n name: tool.name,\n description: tool.description,\n inputSchema: pick(z.toJSONSchema(tool.inputSchema), [\"properties\", \"type\"]),\n outputSchema: pick(z.toJSONSchema(tool.outputSchema), [\"properties\", \"type\"])\n }));\n\n const excludedFileIds = this.computeExcludedFileIds(data.project, data.includedFiles);\n\n await this.generatePageContent.execute({\n prompt: data.prompt,\n components: toJS(this._components),\n tools,\n projectId: data.project || null,\n excludedFileIds,\n readerPersonaId: data.readerPersona || null,\n writerPersonaId: data.writerPersona || null\n });\n } catch {\n this.clearTimeout();\n runInAction(() => {\n this._submitting = false;\n });\n }\n }\n\n async processAiResponse(responseText: string): Promise<void> {\n this.clearTimeout();\n runInAction(() => {\n this._processing = true;\n this._submitting = false;\n });\n\n try {\n const aiResponseJson = JSON.parse(responseText);\n const resolved = await this.pipelineRunner.resolve(aiResponseJson);\n const items = Array.isArray(resolved) ? resolved : [resolved];\n\n await this._createElements(\n items.map((element: { component: string; inputs: Record<string, unknown> }) => ({\n componentName: element.component,\n parentId: \"root\",\n slot: \"children\",\n bindings: { inputs: element.inputs }\n }))\n );\n } finally {\n runInAction(() => {\n this._processing = false;\n });\n }\n }\n\n cancelPrompt(): void {\n this.clearTimeout();\n this._processing = false;\n this._submitting = false;\n }\n\n private startTimeout(): void {\n this.clearTimeout();\n this._elapsedSeconds = 0;\n this._intervalId = setInterval(() => {\n runInAction(() => {\n this._elapsedSeconds++;\n });\n }, 1000);\n this._timeoutId = setTimeout(() => {\n runInAction(() => {\n this._submitting = false;\n this._timedOut = true;\n });\n this.clearInterval();\n }, SUBMIT_TIMEOUT_MS);\n }\n\n private clearTimeout(): void {\n if (this._timeoutId !== null) {\n clearTimeout(this._timeoutId);\n this._timeoutId = null;\n }\n this.clearInterval();\n }\n\n private clearInterval(): void {\n if (this._intervalId !== null) {\n clearInterval(this._intervalId);\n this._intervalId = null;\n }\n }\n\n private buildForm() {\n return this.formModelFactory.create({\n fields: fields => ({\n project: fields\n .text()\n .label(\"Project\")\n .description(\"Select a predefined context to attach.\")\n .options(() => this.getProjectOptions())\n .afterChange((value, { form }) => {\n const projectId = value as string | undefined;\n const project = projectId\n ? this._settings?.projects?.presets?.find(p => p.id === projectId)\n : undefined;\n\n if (project?.defaultReaderPersonaId) {\n form.field(\"readerPersona\").setValue(project.defaultReaderPersonaId);\n }\n if (project?.defaultWriterPersonaId) {\n form.field(\"writerPersona\").setValue(project.defaultWriterPersonaId);\n }\n\n const fileIds = (project?.files ?? []).map(f => f.id);\n form.field(\"includedFiles\").setValue(fileIds);\n }),\n includedFiles: fields\n .text()\n .label(\"Files included\")\n .description(\"Uncheck files to exclude them from this generation only.\")\n .options(() => this.getProjectFileOptions())\n .renderer(\"checkboxes\")\n .list()\n .hiddenWhen(({ form }) => {\n const projectId = form.field(\"project\").as(\"text\").getValue();\n if (!projectId) {\n return true;\n }\n const project = this._settings?.projects?.presets?.find(\n p => p.id === projectId\n );\n return !project?.files || project.files.length === 0;\n }),\n readerPersona: fields\n .text()\n .label(\"Reader Persona\")\n .description(\"Select the target audience for the generated content.\")\n .options(() => this.getPersonaOptions(\"reader\")),\n writerPersona: fields\n .text()\n .label(\"Writer Persona\")\n .description(\"Select the writing style for the generated content.\")\n .options(() => this.getPersonaOptions(\"writer\")),\n prompt: fields\n .text()\n .label(\"Prompt\")\n .description(\"Describe the page content you want to generate.\")\n .required(\"Prompt is required\")\n .renderer(\"textarea\", { rows: 6 })\n }),\n layout: layout => [\n layout.row(\"project\"),\n layout.row(\"includedFiles\"),\n layout.row(\"readerPersona\"),\n layout.row(\"writerPersona\"),\n layout.row(\"prompt\")\n ]\n });\n }\n\n private getSelectedProject() {\n if (!this._form || !this._settings) {\n return undefined;\n }\n const projectId = this._form.field(\"project\").getValue<string>();\n if (!projectId) {\n return undefined;\n }\n return this._settings.projects?.presets?.find(p => p.id === projectId);\n }\n\n private getProjectFileOptions() {\n const project = this.getSelectedProject();\n const files = project?.files;\n if (!files || files.length === 0) {\n return [];\n }\n return files.map(f => ({\n label: f.name,\n value: f.id\n }));\n }\n\n private computeExcludedFileIds(projectId?: string, includedFiles?: string[]): string[] | null {\n if (!projectId) {\n return null;\n }\n const project = this._settings?.projects?.presets?.find(p => p.id === projectId);\n const allFileIds = (project?.files ?? []).map(f => f.id);\n if (allFileIds.length === 0) {\n return null;\n }\n const included = new Set(includedFiles ?? []);\n const excluded = allFileIds.filter(id => !included.has(id));\n return excluded.length > 0 ? excluded : null;\n }\n\n private getProjectOptions() {\n const presets = this._settings?.projects?.presets;\n if (!presets || presets.length === 0) {\n return [];\n }\n return presets.map(preset => ({\n label: preset.name,\n value: preset.id\n }));\n }\n\n private getPersonaOptions(type: \"reader\" | \"writer\") {\n const presets =\n type === \"reader\"\n ? this._settings?.readerPersonas?.presets\n : this._settings?.writerPersonas?.presets;\n\n if (!presets || presets.length === 0) {\n return [];\n }\n\n return presets.map(preset => ({\n label: preset.name,\n value: preset.id\n }));\n }\n}\n\nexport const GenerateContentPresenterRegistration = GenerateContentPresenter.createImplementation({\n implementation: GenerateContentPresenterImpl,\n dependencies: [\n ToolRegistry,\n ToolPipelineRunner,\n GeneratePageContentUseCase,\n FormModelFactory,\n GetSettingsUseCase\n ]\n});\n"],"names":["SUBMIT_TIMEOUT_MS","GenerateContentPresenterImpl","toolRegistry","pipelineRunner","generatePageContent","formModelFactory","getSettings","makeAutoObservable","computed","components","createElements","settings","runInAction","data","tools","tool","pick","z","excludedFileIds","toJS","responseText","aiResponseJson","JSON","resolved","items","Array","element","setInterval","setTimeout","clearTimeout","clearInterval","fields","value","form","projectId","project","p","undefined","fileIds","f","layout","files","includedFiles","allFileIds","included","Set","excluded","id","presets","preset","type","GenerateContentPresenterRegistration","GenerateContentPresenter","ToolRegistry","ToolPipelineRunner","GeneratePageContentUseCase","FormModelFactory","GetSettingsUseCase"],"mappings":";;;;;;;AASA,MAAMA,oBAAoB;AAE1B,MAAMC;IAaF,YACYC,YAAoC,EACpCC,cAA4C,EAC5CC,mBAAyD,EACzDC,gBAA4C,EAC5CC,WAAyC,CACnD;aALUJ,YAAY,GAAZA;aACAC,cAAc,GAAdA;aACAC,mBAAmB,GAAnBA;aACAC,gBAAgB,GAAhBA;aACAC,WAAW,GAAXA;aAjBJ,QAAQ,GAAG;aACX,WAAW,GAAG;aACd,WAAW,GAAG;aACd,SAAS,GAAG;aACZ,WAAW,GAA0B,EAAE;aACvC,eAAe,GAAqB,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AS,aAATA,OACM,IAAI,CAAC,SAAS,EAAE,gBAAgB,UAChC,IAAI,CAAC,SAAS,EAAE,gBAAgB;QAE1C,IAAI,CAACF,WAAWA,AAAmB,MAAnBA,QAAQ,MAAM,EAC1B,OAAO,EAAE;QAGb,OAAOA,QAAQ,GAAG,CAACC,CAAAA,SAAW;gBAC1B,OAAOA,OAAO,IAAI;gBAClB,OAAOA,OAAO,EAAE;YACpB;IACJ;AACJ;AAEO,MAAME,uCAAuCC,yBAAyB,oBAAoB,CAAC;IAC9F,gBAAgBnD;IAChB,cAAc;QACVoD;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
package/api/Extension.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
- import { WcpContext } from "@webiny/api-core/features/wcp/WcpContext/index.js";
3
2
  import { BaseGraphQLSchema } from "./graphql/BaseGraphQLSchema.js";
4
3
  import AiPowerUpsSettingsGraphQLMapper from "./graphql/AiPowerUpsSettingsGraphQLMapper.js";
5
4
  import { AiPowerUpsSettingsCache } from "./features/shared/SettingsCache.js";
@@ -13,6 +12,8 @@ import { ProjectsFeature } from "./features/Projects/feature.js";
13
12
  import { AiPromptContextFeature } from "./features/AiPromptContext/feature.js";
14
13
  import { AiImageEnrichmentFeature } from "./features/AiImageEnrichment/feature.js";
15
14
  import { ExtractFrontmatterFeature } from "./features/ExtractFrontmatter/feature.js";
15
+ import { CmsGenerateEntryContentFeature } from "./features/CmsGenerateEntryContent/feature.js";
16
+ import { CmsResolveImageToolFeature } from "./features/CmsResolveImageTool/feature.js";
16
17
  const Extension = createFeature({
17
18
  name: "AiPowerUps",
18
19
  register (container) {
@@ -25,9 +26,10 @@ const Extension = createFeature({
25
26
  ProjectsFeature.register(container);
26
27
  AiPromptContextFeature.register(container);
27
28
  WbGeneratePageContentFeature.register(container);
29
+ CmsGenerateEntryContentFeature.register(container);
30
+ CmsResolveImageToolFeature.register(container);
28
31
  ExtractFrontmatterFeature.register(container);
29
- const wcp = container.resolve(WcpContext);
30
- if (wcp.canUseAiImageEnrichment()) AiImageEnrichmentFeature.register(container);
32
+ AiImageEnrichmentFeature.register(container);
31
33
  container.register(AiPowerUpsSettingsGraphQLMapper).inSingletonScope();
32
34
  container.register(BaseGraphQLSchema);
33
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api/Extension.js","sources":["../../src/api/Extension.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { WcpContext } from \"@webiny/api-core/features/wcp/WcpContext/index.js\";\nimport { BaseGraphQLSchema } from \"./graphql/BaseGraphQLSchema.js\";\nimport AiPowerUpsSettingsGraphQLMapperImpl from \"./graphql/AiPowerUpsSettingsGraphQLMapper.js\";\nimport { AiPowerUpsSettingsCache } from \"./features/shared/SettingsCache.js\";\nimport { GetSettingsFeature } from \"./features/GetSettings/feature.js\";\nimport { UpdateSettingsFeature } from \"./features/UpdateSettings/feature.js\";\nimport { WbGeneratePageContentFeature } from \"./features/WbGeneratePageContent/feature.js\";\nimport { ProvidersFeature } from \"./features/Providers/feature.js\";\nimport { ReaderPersonasFeature } from \"./features/ReaderPersonas/feature.js\";\nimport { WriterPersonasFeature } from \"./features/WriterPersonas/feature.js\";\nimport { ProjectsFeature } from \"./features/Projects/feature.js\";\nimport { AiPromptContextFeature } from \"./features/AiPromptContext/feature.js\";\nimport { AiImageEnrichmentFeature } from \"./features/AiImageEnrichment/feature.js\";\nimport { ExtractFrontmatterFeature } from \"./features/ExtractFrontmatter/feature.js\";\n\nexport const Extension = createFeature({\n name: \"AiPowerUps\",\n register(container) {\n container.register(AiPowerUpsSettingsCache).inSingletonScope();\n\n GetSettingsFeature.register(container);\n UpdateSettingsFeature.register(container);\n ProvidersFeature.register(container);\n ReaderPersonasFeature.register(container);\n WriterPersonasFeature.register(container);\n ProjectsFeature.register(container);\n AiPromptContextFeature.register(container);\n WbGeneratePageContentFeature.register(container);\n ExtractFrontmatterFeature.register(container);\n\n const wcp = container.resolve(WcpContext);\n if (wcp.canUseAiImageEnrichment()) {\n AiImageEnrichmentFeature.register(container);\n }\n\n container.register(AiPowerUpsSettingsGraphQLMapperImpl).inSingletonScope();\n container.register(BaseGraphQLSchema);\n }\n});\n"],"names":["Extension","createFeature","container","AiPowerUpsSettingsCache","GetSettingsFeature","UpdateSettingsFeature","ProvidersFeature","ReaderPersonasFeature","WriterPersonasFeature","ProjectsFeature","AiPromptContextFeature","WbGeneratePageContentFeature","ExtractFrontmatterFeature","wcp","WcpContext","AiImageEnrichmentFeature","AiPowerUpsSettingsGraphQLMapperImpl","BaseGraphQLSchema"],"mappings":";;;;;;;;;;;;;;;AAgBO,MAAMA,YAAYC,cAAc;IACnC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,yBAAyB,gBAAgB;QAE5DC,mBAAmB,QAAQ,CAACF;QAC5BG,sBAAsB,QAAQ,CAACH;QAC/BI,iBAAiB,QAAQ,CAACJ;QAC1BK,sBAAsB,QAAQ,CAACL;QAC/BM,sBAAsB,QAAQ,CAACN;QAC/BO,gBAAgB,QAAQ,CAACP;QACzBQ,uBAAuB,QAAQ,CAACR;QAChCS,6BAA6B,QAAQ,CAACT;QACtCU,0BAA0B,QAAQ,CAACV;QAEnC,MAAMW,MAAMX,UAAU,OAAO,CAACY;QAC9B,IAAID,IAAI,uBAAuB,IAC3BE,yBAAyB,QAAQ,CAACb;QAGtCA,UAAU,QAAQ,CAACc,iCAAqC,gBAAgB;QACxEd,UAAU,QAAQ,CAACe;IACvB;AACJ"}
1
+ {"version":3,"file":"api/Extension.js","sources":["../../src/api/Extension.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { BaseGraphQLSchema } from \"./graphql/BaseGraphQLSchema.js\";\nimport AiPowerUpsSettingsGraphQLMapperImpl from \"./graphql/AiPowerUpsSettingsGraphQLMapper.js\";\nimport { AiPowerUpsSettingsCache } from \"./features/shared/SettingsCache.js\";\nimport { GetSettingsFeature } from \"./features/GetSettings/feature.js\";\nimport { UpdateSettingsFeature } from \"./features/UpdateSettings/feature.js\";\nimport { WbGeneratePageContentFeature } from \"./features/WbGeneratePageContent/feature.js\";\nimport { ProvidersFeature } from \"./features/Providers/feature.js\";\nimport { ReaderPersonasFeature } from \"./features/ReaderPersonas/feature.js\";\nimport { WriterPersonasFeature } from \"./features/WriterPersonas/feature.js\";\nimport { ProjectsFeature } from \"./features/Projects/feature.js\";\nimport { AiPromptContextFeature } from \"./features/AiPromptContext/feature.js\";\nimport { AiImageEnrichmentFeature } from \"./features/AiImageEnrichment/feature.js\";\nimport { ExtractFrontmatterFeature } from \"./features/ExtractFrontmatter/feature.js\";\nimport { CmsGenerateEntryContentFeature } from \"./features/CmsGenerateEntryContent/feature.js\";\nimport { CmsResolveImageToolFeature } from \"./features/CmsResolveImageTool/feature.js\";\n\nexport const Extension = createFeature({\n name: \"AiPowerUps\",\n register(container) {\n container.register(AiPowerUpsSettingsCache).inSingletonScope();\n\n GetSettingsFeature.register(container);\n UpdateSettingsFeature.register(container);\n ProvidersFeature.register(container);\n ReaderPersonasFeature.register(container);\n WriterPersonasFeature.register(container);\n ProjectsFeature.register(container);\n AiPromptContextFeature.register(container);\n WbGeneratePageContentFeature.register(container);\n CmsGenerateEntryContentFeature.register(container);\n CmsResolveImageToolFeature.register(container);\n ExtractFrontmatterFeature.register(container);\n\n // Registered unconditionally. The WCP license gate lives inside the feature's\n // FileAfterCreate handler (trigger-time), because the license isn't loaded yet during this\n // register() phase — a register-time canUse* check reads NullLicense and is always false.\n AiImageEnrichmentFeature.register(container);\n\n container.register(AiPowerUpsSettingsGraphQLMapperImpl).inSingletonScope();\n container.register(BaseGraphQLSchema);\n }\n});\n"],"names":["Extension","createFeature","container","AiPowerUpsSettingsCache","GetSettingsFeature","UpdateSettingsFeature","ProvidersFeature","ReaderPersonasFeature","WriterPersonasFeature","ProjectsFeature","AiPromptContextFeature","WbGeneratePageContentFeature","CmsGenerateEntryContentFeature","CmsResolveImageToolFeature","ExtractFrontmatterFeature","AiImageEnrichmentFeature","AiPowerUpsSettingsGraphQLMapperImpl","BaseGraphQLSchema"],"mappings":";;;;;;;;;;;;;;;;AAiBO,MAAMA,YAAYC,cAAc;IACnC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,yBAAyB,gBAAgB;QAE5DC,mBAAmB,QAAQ,CAACF;QAC5BG,sBAAsB,QAAQ,CAACH;QAC/BI,iBAAiB,QAAQ,CAACJ;QAC1BK,sBAAsB,QAAQ,CAACL;QAC/BM,sBAAsB,QAAQ,CAACN;QAC/BO,gBAAgB,QAAQ,CAACP;QACzBQ,uBAAuB,QAAQ,CAACR;QAChCS,6BAA6B,QAAQ,CAACT;QACtCU,+BAA+B,QAAQ,CAACV;QACxCW,2BAA2B,QAAQ,CAACX;QACpCY,0BAA0B,QAAQ,CAACZ;QAKnCa,yBAAyB,QAAQ,CAACb;QAElCA,UAAU,QAAQ,CAACc,iCAAqC,gBAAgB;QACxEd,UAAU,QAAQ,CAACe;IACvB;AACJ"}
@@ -1,8 +1,10 @@
1
1
  import { FileAfterCreateEventHandler } from "@webiny/api-file-manager/features/file/CreateFile/events.js";
2
2
  import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
3
+ import { WcpContext } from "@webiny/api-core/features/wcp/WcpContext/index.js";
3
4
  declare class AiImageEnrichmentAfterCreateHandlerImpl implements FileAfterCreateEventHandler.Interface {
4
5
  private taskService;
5
- constructor(taskService: TaskService.Interface);
6
+ private wcp;
7
+ constructor(taskService: TaskService.Interface, wcp: WcpContext.Interface);
6
8
  handle(event: FileAfterCreateEventHandler.Event): Promise<void>;
7
9
  }
8
10
  export declare const AiImageEnrichmentAfterCreateHandler: typeof AiImageEnrichmentAfterCreateHandlerImpl & {
@@ -1,13 +1,16 @@
1
1
  import { FileAfterCreateEventHandler } from "@webiny/api-file-manager/features/file/CreateFile/events.js";
2
2
  import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
3
+ import { WcpContext } from "@webiny/api-core/features/wcp/WcpContext/index.js";
3
4
  import { AI_IMAGE_ENRICHMENT_TASK_ID } from "./AiImageEnrichmentTask.js";
4
5
  class AiImageEnrichmentAfterCreateHandlerImpl {
5
- constructor(taskService){
6
+ constructor(taskService, wcp){
6
7
  this.taskService = taskService;
8
+ this.wcp = wcp;
7
9
  }
8
10
  async handle(event) {
9
11
  const { file } = event.payload;
10
12
  if (!file.type.startsWith("image/")) return;
13
+ if (!this.wcp.canUseAiImageEnrichment()) return;
11
14
  await this.taskService.trigger({
12
15
  definition: AI_IMAGE_ENRICHMENT_TASK_ID,
13
16
  input: {
@@ -19,7 +22,8 @@ class AiImageEnrichmentAfterCreateHandlerImpl {
19
22
  const AiImageEnrichmentAfterCreateHandler = FileAfterCreateEventHandler.createImplementation({
20
23
  implementation: AiImageEnrichmentAfterCreateHandlerImpl,
21
24
  dependencies: [
22
- TaskService
25
+ TaskService,
26
+ WcpContext
23
27
  ]
24
28
  });
25
29
  export { AiImageEnrichmentAfterCreateHandler };