@webiny/ai-powerups 6.3.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.
Files changed (214) hide show
  1. package/AiPowerups.d.ts +2 -0
  2. package/AiPowerups.js +12 -0
  3. package/AiPowerups.js.map +1 -0
  4. package/LICENSE +36 -0
  5. package/README.md +11 -0
  6. package/admin/Extension.d.ts +2 -0
  7. package/admin/Extension.js +31 -0
  8. package/admin/Extension.js.map +1 -0
  9. package/admin/features/feature.d.ts +1 -0
  10. package/admin/features/feature.js +21 -0
  11. package/admin/features/feature.js.map +1 -0
  12. package/admin/features/generatePageContent/GeneratePageContentGateway.d.ts +12 -0
  13. package/admin/features/generatePageContent/GeneratePageContentGateway.js +26 -0
  14. package/admin/features/generatePageContent/GeneratePageContentGateway.js.map +1 -0
  15. package/admin/features/generatePageContent/GeneratePageContentUseCase.d.ts +11 -0
  16. package/admin/features/generatePageContent/GeneratePageContentUseCase.js +15 -0
  17. package/admin/features/generatePageContent/GeneratePageContentUseCase.js.map +1 -0
  18. package/admin/features/generatePageContent/abstractions.d.ts +20 -0
  19. package/admin/features/generatePageContent/abstractions.js +5 -0
  20. package/admin/features/generatePageContent/abstractions.js.map +1 -0
  21. package/admin/features/generatePageContent/feature.d.ts +1 -0
  22. package/admin/features/generatePageContent/feature.js +12 -0
  23. package/admin/features/generatePageContent/feature.js.map +1 -0
  24. package/admin/features/generatePageContent/index.d.ts +3 -0
  25. package/admin/features/generatePageContent/index.js +4 -0
  26. package/admin/features/generatePageContent/index.js.map +1 -0
  27. package/admin/features/listModels/ListModelsGateway.d.ts +12 -0
  28. package/admin/features/listModels/ListModelsGateway.js +31 -0
  29. package/admin/features/listModels/ListModelsGateway.js.map +1 -0
  30. package/admin/features/listModels/ListModelsRepository.d.ts +13 -0
  31. package/admin/features/listModels/ListModelsRepository.js +24 -0
  32. package/admin/features/listModels/ListModelsRepository.js.map +1 -0
  33. package/admin/features/listModels/ListModelsUseCase.d.ts +10 -0
  34. package/admin/features/listModels/ListModelsUseCase.js +15 -0
  35. package/admin/features/listModels/ListModelsUseCase.js.map +1 -0
  36. package/admin/features/listModels/abstractions.d.ts +28 -0
  37. package/admin/features/listModels/abstractions.js +6 -0
  38. package/admin/features/listModels/abstractions.js.map +1 -0
  39. package/admin/features/listModels/feature.d.ts +3 -0
  40. package/admin/features/listModels/feature.js +20 -0
  41. package/admin/features/listModels/feature.js.map +1 -0
  42. package/admin/features/listModels/index.d.ts +2 -0
  43. package/admin/features/listModels/index.js +4 -0
  44. package/admin/features/listModels/index.js.map +1 -0
  45. package/admin/features/settings/getSettings/GetSettingsGateway.d.ts +11 -0
  46. package/admin/features/settings/getSettings/GetSettingsGateway.js +26 -0
  47. package/admin/features/settings/getSettings/GetSettingsGateway.js.map +1 -0
  48. package/admin/features/settings/getSettings/GetSettingsRepository.d.ts +12 -0
  49. package/admin/features/settings/getSettings/GetSettingsRepository.js +23 -0
  50. package/admin/features/settings/getSettings/GetSettingsRepository.js.map +1 -0
  51. package/admin/features/settings/getSettings/GetSettingsUseCase.d.ts +10 -0
  52. package/admin/features/settings/getSettings/GetSettingsUseCase.js +15 -0
  53. package/admin/features/settings/getSettings/GetSettingsUseCase.js.map +1 -0
  54. package/admin/features/settings/getSettings/abstractions.d.ts +22 -0
  55. package/admin/features/settings/getSettings/abstractions.js +6 -0
  56. package/admin/features/settings/getSettings/abstractions.js.map +1 -0
  57. package/admin/features/settings/getSettings/feature.d.ts +3 -0
  58. package/admin/features/settings/getSettings/feature.js +20 -0
  59. package/admin/features/settings/getSettings/feature.js.map +1 -0
  60. package/admin/features/settings/getSettings/index.d.ts +2 -0
  61. package/admin/features/settings/getSettings/index.js +4 -0
  62. package/admin/features/settings/getSettings/index.js.map +1 -0
  63. package/admin/features/settings/shared/SettingsCache.d.ts +9 -0
  64. package/admin/features/settings/shared/SettingsCache.js +18 -0
  65. package/admin/features/settings/shared/SettingsCache.js.map +1 -0
  66. package/admin/features/settings/shared/abstractions.d.ts +9 -0
  67. package/admin/features/settings/shared/abstractions.js +21 -0
  68. package/admin/features/settings/shared/abstractions.js.map +1 -0
  69. package/admin/features/settings/shared/feature.d.ts +1 -0
  70. package/admin/features/settings/shared/feature.js +14 -0
  71. package/admin/features/settings/shared/feature.js.map +1 -0
  72. package/admin/features/settings/shared/index.d.ts +2 -0
  73. package/admin/features/settings/shared/index.js +4 -0
  74. package/admin/features/settings/shared/index.js.map +1 -0
  75. package/admin/features/settings/updateSettings/UpdateSettingsGateway.d.ts +12 -0
  76. package/admin/features/settings/updateSettings/UpdateSettingsGateway.js +29 -0
  77. package/admin/features/settings/updateSettings/UpdateSettingsGateway.js.map +1 -0
  78. package/admin/features/settings/updateSettings/UpdateSettingsRepository.d.ts +13 -0
  79. package/admin/features/settings/updateSettings/UpdateSettingsRepository.js +19 -0
  80. package/admin/features/settings/updateSettings/UpdateSettingsRepository.js.map +1 -0
  81. package/admin/features/settings/updateSettings/UpdateSettingsUseCase.d.ts +11 -0
  82. package/admin/features/settings/updateSettings/UpdateSettingsUseCase.js +15 -0
  83. package/admin/features/settings/updateSettings/UpdateSettingsUseCase.js.map +1 -0
  84. package/admin/features/settings/updateSettings/abstractions.d.ts +22 -0
  85. package/admin/features/settings/updateSettings/abstractions.js +6 -0
  86. package/admin/features/settings/updateSettings/abstractions.js.map +1 -0
  87. package/admin/features/settings/updateSettings/feature.d.ts +3 -0
  88. package/admin/features/settings/updateSettings/feature.js +20 -0
  89. package/admin/features/settings/updateSettings/feature.js.map +1 -0
  90. package/admin/features/settings/updateSettings/index.d.ts +2 -0
  91. package/admin/features/settings/updateSettings/index.js +4 -0
  92. package/admin/features/settings/updateSettings/index.js.map +1 -0
  93. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsConfig.d.ts +2 -0
  94. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsConfig.js +11 -0
  95. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsConfig.js.map +1 -0
  96. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.d.ts +5 -0
  97. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.js +58 -0
  98. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.js.map +1 -0
  99. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.d.ts +25 -0
  100. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.js +140 -0
  101. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.js.map +1 -0
  102. package/admin/presentation/AiPowerUpsSettings/abstractions.d.ts +17 -0
  103. package/admin/presentation/AiPowerUpsSettings/abstractions.js +4 -0
  104. package/admin/presentation/AiPowerUpsSettings/abstractions.js.map +1 -0
  105. package/admin/presentation/AiPowerUpsSettings/feature.d.ts +3 -0
  106. package/admin/presentation/AiPowerUpsSettings/feature.js +21 -0
  107. package/admin/presentation/AiPowerUpsSettings/feature.js.map +1 -0
  108. package/admin/presentation/AiPowerUpsSettings/index.d.ts +5 -0
  109. package/admin/presentation/AiPowerUpsSettings/index.js +7 -0
  110. package/admin/presentation/AiPowerUpsSettings/index.js.map +1 -0
  111. package/admin/presentation/AiPowerUpsSettings/settingsGroup.d.ts +18 -0
  112. package/admin/presentation/AiPowerUpsSettings/settingsGroup.js +4 -0
  113. package/admin/presentation/AiPowerUpsSettings/settingsGroup.js.map +1 -0
  114. package/admin/presentation/AiPowerUpsSettings/useAiPowerUpsSettingsDialog.d.ts +1 -0
  115. package/admin/presentation/AiPowerUpsSettings/useAiPowerUpsSettingsDialog.js +12 -0
  116. package/admin/presentation/AiPowerUpsSettings/useAiPowerUpsSettingsDialog.js.map +1 -0
  117. package/admin/presentation/PersonasSettings.d.ts +11 -0
  118. package/admin/presentation/PersonasSettings.js +28 -0
  119. package/admin/presentation/PersonasSettings.js.map +1 -0
  120. package/admin/presentation/ProvidersSettings.d.ts +16 -0
  121. package/admin/presentation/ProvidersSettings.js +37 -0
  122. package/admin/presentation/ProvidersSettings.js.map +1 -0
  123. package/admin/presentation/WbContentGeneration/Extension.d.ts +2 -0
  124. package/admin/presentation/WbContentGeneration/Extension.js +23 -0
  125. package/admin/presentation/WbContentGeneration/Extension.js.map +1 -0
  126. package/admin/presentation/WbContentGeneration/GenerateContentButton.d.ts +2 -0
  127. package/admin/presentation/WbContentGeneration/GenerateContentButton.js +17 -0
  128. package/admin/presentation/WbContentGeneration/GenerateContentButton.js.map +1 -0
  129. package/admin/presentation/WbContentGeneration/GenerateContentDialog.d.ts +21 -0
  130. package/admin/presentation/WbContentGeneration/GenerateContentDialog.js +102 -0
  131. package/admin/presentation/WbContentGeneration/GenerateContentDialog.js.map +1 -0
  132. package/admin/presentation/WbContentGeneration/GenerateContentPresenter.d.ts +24 -0
  133. package/admin/presentation/WbContentGeneration/GenerateContentPresenter.js +91 -0
  134. package/admin/presentation/WbContentGeneration/GenerateContentPresenter.js.map +1 -0
  135. package/admin/presentation/WbContentGeneration/PROCESS_IDEA.md +190 -0
  136. package/admin/presentation/WbContentGeneration/abstractions.d.ts +28 -0
  137. package/admin/presentation/WbContentGeneration/abstractions.js +4 -0
  138. package/admin/presentation/WbContentGeneration/abstractions.js.map +1 -0
  139. package/admin/presentation/WbContentGeneration/decompressGzipBase64.d.ts +1 -0
  140. package/admin/presentation/WbContentGeneration/decompressGzipBase64.js +14 -0
  141. package/admin/presentation/WbContentGeneration/decompressGzipBase64.js.map +1 -0
  142. package/admin/presentation/WbContentGeneration/feature.d.ts +3 -0
  143. package/admin/presentation/WbContentGeneration/feature.js +16 -0
  144. package/admin/presentation/WbContentGeneration/feature.js.map +1 -0
  145. package/api/Extension.d.ts +4 -0
  146. package/api/Extension.js +16 -0
  147. package/api/Extension.js.map +1 -0
  148. package/api/constants.d.ts +1 -0
  149. package/api/constants.js +3 -0
  150. package/api/constants.js.map +1 -0
  151. package/api/features/GetSettings/GetSettingsRepository.d.ts +15 -0
  152. package/api/features/GetSettings/GetSettingsRepository.js +45 -0
  153. package/api/features/GetSettings/GetSettingsRepository.js.map +1 -0
  154. package/api/features/GetSettings/GetSettingsUseCase.d.ts +10 -0
  155. package/api/features/GetSettings/GetSettingsUseCase.js +15 -0
  156. package/api/features/GetSettings/GetSettingsUseCase.js.map +1 -0
  157. package/api/features/GetSettings/abstractions.d.ts +16 -0
  158. package/api/features/GetSettings/abstractions.js +5 -0
  159. package/api/features/GetSettings/abstractions.js.map +1 -0
  160. package/api/features/GetSettings/feature.d.ts +4 -0
  161. package/api/features/GetSettings/feature.js +12 -0
  162. package/api/features/GetSettings/feature.js.map +1 -0
  163. package/api/features/GetSettings/index.d.ts +1 -0
  164. package/api/features/GetSettings/index.js +3 -0
  165. package/api/features/GetSettings/index.js.map +1 -0
  166. package/api/features/UpdateSettings/UpdateSettingsRepository.d.ts +15 -0
  167. package/api/features/UpdateSettings/UpdateSettingsRepository.js +42 -0
  168. package/api/features/UpdateSettings/UpdateSettingsRepository.js.map +1 -0
  169. package/api/features/UpdateSettings/UpdateSettingsUseCase.d.ts +14 -0
  170. package/api/features/UpdateSettings/UpdateSettingsUseCase.js +40 -0
  171. package/api/features/UpdateSettings/UpdateSettingsUseCase.js.map +1 -0
  172. package/api/features/UpdateSettings/abstractions.d.ts +46 -0
  173. package/api/features/UpdateSettings/abstractions.js +10 -0
  174. package/api/features/UpdateSettings/abstractions.js.map +1 -0
  175. package/api/features/UpdateSettings/events.d.ts +10 -0
  176. package/api/features/UpdateSettings/events.js +16 -0
  177. package/api/features/UpdateSettings/events.js.map +1 -0
  178. package/api/features/UpdateSettings/feature.d.ts +4 -0
  179. package/api/features/UpdateSettings/feature.js +12 -0
  180. package/api/features/UpdateSettings/feature.js.map +1 -0
  181. package/api/features/UpdateSettings/index.d.ts +1 -0
  182. package/api/features/UpdateSettings/index.js +3 -0
  183. package/api/features/UpdateSettings/index.js.map +1 -0
  184. package/api/features/UpdateSettings/validation.d.ts +17 -0
  185. package/api/features/UpdateSettings/validation.js +21 -0
  186. package/api/features/UpdateSettings/validation.js.map +1 -0
  187. package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.d.ts +29 -0
  188. package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.js +72 -0
  189. package/api/features/WbGeneratePageContent/WbGeneratePageContentTask.js.map +1 -0
  190. package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.d.ts +17 -0
  191. package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.js +62 -0
  192. package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.js.map +1 -0
  193. package/api/features/WbGeneratePageContent/abstractions.d.ts +14 -0
  194. package/api/features/WbGeneratePageContent/abstractions.js +4 -0
  195. package/api/features/WbGeneratePageContent/abstractions.js.map +1 -0
  196. package/api/features/WbGeneratePageContent/buildPrompt.d.ts +1 -0
  197. package/api/features/WbGeneratePageContent/buildPrompt.js +142 -0
  198. package/api/features/WbGeneratePageContent/buildPrompt.js.map +1 -0
  199. package/api/features/WbGeneratePageContent/feature.d.ts +4 -0
  200. package/api/features/WbGeneratePageContent/feature.js +12 -0
  201. package/api/features/WbGeneratePageContent/feature.js.map +1 -0
  202. package/api/features/WbGeneratePageContent/index.d.ts +1 -0
  203. package/api/features/WbGeneratePageContent/index.js +3 -0
  204. package/api/features/WbGeneratePageContent/index.js.map +1 -0
  205. package/api/graphql/BaseGraphQLSchema.d.ts +8 -0
  206. package/api/graphql/BaseGraphQLSchema.js +110 -0
  207. package/api/graphql/BaseGraphQLSchema.js.map +1 -0
  208. package/api/types.d.ts +19 -0
  209. package/api/types.js +3 -0
  210. package/api/types.js.map +1 -0
  211. package/index.d.ts +1 -0
  212. package/index.js +3 -0
  213. package/index.js.map +1 -0
  214. package/package.json +54 -0
@@ -0,0 +1,140 @@
1
+ import { makeAutoObservable, computed, runInAction } from "mobx";
2
+ import { FormModelFactory } from "@webiny/app-admin";
3
+ import { GetSettingsUseCase } from "../../features/settings/getSettings/abstractions.js";
4
+ import { UpdateSettingsUseCase } from "../../features/settings/updateSettings/abstractions.js";
5
+ import { AiPowerUpsSettingsPresenter as PresenterAbstraction } from "./abstractions.js";
6
+ import { AiPowerUpsSettingsGroup } from "./settingsGroup.js";
7
+ class AiPowerUpsSettingsPresenterImpl {
8
+ loading = false;
9
+ saving = false;
10
+ form = null;
11
+ error = null;
12
+ constructor(factory, groups, getSettings, updateSettings) {
13
+ this.factory = factory;
14
+ this.groups = groups;
15
+ this.getSettings = getSettings;
16
+ this.updateSettings = updateSettings;
17
+ makeAutoObservable(this, {
18
+ vm: computed
19
+ }, {
20
+ autoBind: true
21
+ });
22
+ }
23
+ get vm() {
24
+ return {
25
+ loading: this.loading,
26
+ saving: this.saving,
27
+ form: this.form ? this.form.vm : null,
28
+ error: this.error
29
+ };
30
+ }
31
+ async init() {
32
+ this.loading = true;
33
+ this.error = null;
34
+ try {
35
+ const data = await this.getSettings.execute();
36
+ runInAction(() => {
37
+ this.form = this.buildForm();
38
+ this.form.setData(data);
39
+ });
40
+ } catch (err) {
41
+ runInAction(() => {
42
+ this.error = err instanceof Error ? err.message : "Failed to load settings.";
43
+ });
44
+ } finally {
45
+ runInAction(() => {
46
+ this.loading = false;
47
+ });
48
+ }
49
+ }
50
+ async save() {
51
+ if (!this.form) {
52
+ return false;
53
+ }
54
+ const data = await this.form.submit();
55
+ if (!data) {
56
+ return false;
57
+ }
58
+ runInAction(() => {
59
+ this.saving = true;
60
+ this.error = null;
61
+ });
62
+ try {
63
+ await this.updateSettings.execute(data);
64
+ return true;
65
+ } catch (err) {
66
+ console.log(err);
67
+ runInAction(() => {
68
+ this.error = err instanceof Error ? err.message : "Failed to save settings.";
69
+ });
70
+ return false;
71
+ } finally {
72
+ runInAction(() => {
73
+ this.saving = false;
74
+ });
75
+ }
76
+ }
77
+ collectGroups() {
78
+ return this.groups.map(group => {
79
+ const collected = {
80
+ group,
81
+ fieldsFn: null,
82
+ layoutFn: null
83
+ };
84
+ const builder = {
85
+ fields(fn) {
86
+ collected.fieldsFn = fn;
87
+ },
88
+ layout(fn) {
89
+ collected.layoutFn = fn;
90
+ }
91
+ };
92
+ group.buildForm(builder);
93
+ return collected;
94
+ });
95
+ }
96
+ buildForm() {
97
+ const collected = this.collectGroups();
98
+ return this.factory.create({
99
+ fields: fields => {
100
+ const result = {};
101
+ for (const {
102
+ group,
103
+ fieldsFn
104
+ } of collected) {
105
+ if (!fieldsFn) {
106
+ continue;
107
+ }
108
+ result[group.name] = fields.object().label(group.label).renderer("passthrough").fields(fieldsFn);
109
+ }
110
+ return result;
111
+ },
112
+ layout: layout => {
113
+ if (collected.length === 0) {
114
+ return [];
115
+ }
116
+ return [layout.tabs({
117
+ id: "settings-tabs",
118
+ renderer: "tabs-vertical",
119
+ tabs: collected.map(({
120
+ group
121
+ }) => ({
122
+ id: group.name,
123
+ label: group.label,
124
+ description: group.description,
125
+ icon: group.icon,
126
+ layout: [layout.row(group.name)]
127
+ }))
128
+ })];
129
+ }
130
+ });
131
+ }
132
+ }
133
+ export const AiPowerUpsSettingsPresenter = PresenterAbstraction.createImplementation({
134
+ implementation: AiPowerUpsSettingsPresenterImpl,
135
+ dependencies: [FormModelFactory, [AiPowerUpsSettingsGroup, {
136
+ multiple: true
137
+ }], GetSettingsUseCase, UpdateSettingsUseCase]
138
+ });
139
+
140
+ //# sourceMappingURL=AiPowerUpsSettingsPresenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["makeAutoObservable","computed","runInAction","FormModelFactory","GetSettingsUseCase","UpdateSettingsUseCase","AiPowerUpsSettingsPresenter","PresenterAbstraction","AiPowerUpsSettingsGroup","AiPowerUpsSettingsPresenterImpl","loading","saving","form","error","constructor","factory","groups","getSettings","updateSettings","vm","autoBind","init","data","execute","buildForm","setData","err","Error","message","save","submit","console","log","collectGroups","map","group","collected","fieldsFn","layoutFn","builder","fields","fn","layout","create","result","name","object","label","renderer","length","tabs","id","description","icon","row","createImplementation","implementation","dependencies","multiple"],"sources":["AiPowerUpsSettingsPresenter.ts"],"sourcesContent":["import { makeAutoObservable, computed, runInAction } from \"mobx\";\nimport { FormModelFactory, FormModel } from \"@webiny/app-admin\";\nimport type { LayoutNode } from \"@webiny/app-admin/features/formModel/abstractions.js\";\nimport { GetSettingsUseCase } from \"../../features/settings/getSettings/abstractions.js\";\nimport { UpdateSettingsUseCase } from \"../../features/settings/updateSettings/abstractions.js\";\nimport { AiPowerUpsSettingsPresenter as PresenterAbstraction } from \"./abstractions.js\";\nimport { AiPowerUpsSettingsGroup } from \"./settingsGroup.js\";\nimport type { ISettings } from \"~/admin/features/settings/shared/abstractions.js\";\n\ntype FieldsFactory = (\n fields: FormModelFactory.FieldBuilderRegistry\n) => Record<string, FormModelFactory.FieldBuilder>;\n\ntype LayoutFactory = (layout: FormModelFactory.LayoutBuilder) => LayoutNode[];\n\ninterface CollectedGroup {\n group: AiPowerUpsSettingsGroup.Interface;\n fieldsFn: FieldsFactory | null;\n layoutFn: LayoutFactory | null;\n}\n\nclass AiPowerUpsSettingsPresenterImpl implements PresenterAbstraction.Interface {\n private loading = false;\n private saving = false;\n private form: FormModel.Interface<ISettings> | null = null;\n private error: string | null = null;\n\n constructor(\n private factory: FormModelFactory.Interface,\n private groups: AiPowerUpsSettingsGroup.Interface[],\n private getSettings: GetSettingsUseCase.Interface,\n private updateSettings: UpdateSettingsUseCase.Interface\n ) {\n makeAutoObservable(this, { vm: computed }, { autoBind: true });\n }\n\n get vm(): PresenterAbstraction.ViewModel {\n return {\n loading: this.loading,\n saving: this.saving,\n form: this.form ? this.form.vm : null,\n error: this.error\n };\n }\n\n async init(): Promise<void> {\n this.loading = true;\n this.error = null;\n\n try {\n const data = await this.getSettings.execute();\n runInAction(() => {\n this.form = this.buildForm();\n this.form.setData(data);\n });\n } catch (err) {\n runInAction(() => {\n this.error = err instanceof Error ? err.message : \"Failed to load settings.\";\n });\n } finally {\n runInAction(() => {\n this.loading = false;\n });\n }\n }\n\n async save(): Promise<boolean> {\n if (!this.form) {\n return false;\n }\n\n const data = await this.form.submit<ISettings>();\n if (!data) {\n return false;\n }\n\n runInAction(() => {\n this.saving = true;\n this.error = null;\n });\n\n try {\n await this.updateSettings.execute(data);\n return true;\n } catch (err) {\n console.log(err);\n runInAction(() => {\n this.error = err instanceof Error ? err.message : \"Failed to save settings.\";\n });\n return false;\n } finally {\n runInAction(() => {\n this.saving = false;\n });\n }\n }\n\n private collectGroups(): CollectedGroup[] {\n return this.groups.map(group => {\n const collected: CollectedGroup = {\n group,\n fieldsFn: null,\n layoutFn: null\n };\n\n const builder: AiPowerUpsSettingsGroup.FormBuilder = {\n fields(fn: FieldsFactory) {\n collected.fieldsFn = fn;\n },\n layout(fn: LayoutFactory) {\n collected.layoutFn = fn;\n }\n };\n\n group.buildForm(builder);\n\n return collected;\n });\n }\n\n private buildForm() {\n const collected = this.collectGroups();\n\n return this.factory.create<ISettings>({\n fields: fields => {\n const result: Record<string, FormModelFactory.FieldBuilder> = {};\n for (const { group, fieldsFn } of collected) {\n if (!fieldsFn) {\n continue;\n }\n result[group.name] = fields\n .object()\n .label(group.label)\n .renderer(\"passthrough\")\n .fields(fieldsFn);\n }\n return result;\n },\n layout: layout => {\n if (collected.length === 0) {\n return [];\n }\n\n return [\n layout.tabs({\n id: \"settings-tabs\",\n renderer: \"tabs-vertical\",\n tabs: collected.map(({ group }) => ({\n id: group.name,\n label: group.label,\n description: group.description,\n icon: group.icon,\n layout: [layout.row(group.name)]\n }))\n })\n ];\n }\n });\n }\n}\n\nexport const AiPowerUpsSettingsPresenter = PresenterAbstraction.createImplementation({\n implementation: AiPowerUpsSettingsPresenterImpl,\n dependencies: [\n FormModelFactory,\n [AiPowerUpsSettingsGroup, { multiple: true }],\n GetSettingsUseCase,\n UpdateSettingsUseCase\n ]\n});\n"],"mappings":"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","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ import { FormModel } from "@webiny/app-admin";
2
+ export interface IAiPowerUpsSettingsVm {
3
+ loading: boolean;
4
+ saving: boolean;
5
+ form: FormModel.FormVM | null;
6
+ error: string | null;
7
+ }
8
+ export interface IAiPowerUpsSettingsPresenter {
9
+ readonly vm: IAiPowerUpsSettingsVm;
10
+ init(): Promise<void>;
11
+ save(): Promise<boolean>;
12
+ }
13
+ export declare const AiPowerUpsSettingsPresenter: import("@webiny/di").Abstraction<IAiPowerUpsSettingsPresenter>;
14
+ export declare namespace AiPowerUpsSettingsPresenter {
15
+ type Interface = IAiPowerUpsSettingsPresenter;
16
+ type ViewModel = IAiPowerUpsSettingsVm;
17
+ }
@@ -0,0 +1,4 @@
1
+ import { createAbstraction } from "@webiny/feature/admin";
2
+ export const AiPowerUpsSettingsPresenter = createAbstraction("AiPowerUps/SettingsPresenter");
3
+
4
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","AiPowerUpsSettingsPresenter"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport { FormModel } from \"@webiny/app-admin\";\n\nexport interface IAiPowerUpsSettingsVm {\n loading: boolean;\n saving: boolean;\n form: FormModel.FormVM | null;\n error: string | null;\n}\n\nexport interface IAiPowerUpsSettingsPresenter {\n readonly vm: IAiPowerUpsSettingsVm;\n init(): Promise<void>;\n save(): Promise<boolean>;\n}\n\nexport const AiPowerUpsSettingsPresenter = createAbstraction<IAiPowerUpsSettingsPresenter>(\n \"AiPowerUps/SettingsPresenter\"\n);\n\nexport namespace AiPowerUpsSettingsPresenter {\n export type Interface = IAiPowerUpsSettingsPresenter;\n export type ViewModel = IAiPowerUpsSettingsVm;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,uBAAuB;AAgBzD,OAAO,MAAMC,2BAA2B,GAAGD,iBAAiB,CACxD,8BACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export declare const AiPowerUpsSettingsFeature: import("@webiny/feature/admin").FeatureDefinition<{
2
+ presenter: import("./abstractions.js").IAiPowerUpsSettingsPresenter;
3
+ }, []>;
@@ -0,0 +1,21 @@
1
+ import { createFeature } from "@webiny/feature/admin";
2
+ import { AiPowerUpsSettingsPresenter as PresenterAbstraction } from "./abstractions.js";
3
+ import { AiPowerUpsSettingsPresenter } from "./AiPowerUpsSettingsPresenter.js";
4
+ import { ProviderSettings } from "../ProvidersSettings.js";
5
+ // import { PersonasSettings } from "../PersonasSettings.js";
6
+
7
+ export const AiPowerUpsSettingsFeature = createFeature({
8
+ name: "AiPowerUps/Settings/Presenter",
9
+ register(container) {
10
+ container.register(ProviderSettings);
11
+ // container.register(PersonasSettings);
12
+ container.register(AiPowerUpsSettingsPresenter);
13
+ },
14
+ resolve(container) {
15
+ return {
16
+ presenter: container.resolve(PresenterAbstraction)
17
+ };
18
+ }
19
+ });
20
+
21
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFeature","AiPowerUpsSettingsPresenter","PresenterAbstraction","ProviderSettings","AiPowerUpsSettingsFeature","name","register","container","resolve","presenter"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { AiPowerUpsSettingsPresenter as PresenterAbstraction } from \"./abstractions.js\";\nimport { AiPowerUpsSettingsPresenter } from \"./AiPowerUpsSettingsPresenter.js\";\nimport { ProviderSettings } from \"../ProvidersSettings.js\";\n// import { PersonasSettings } from \"../PersonasSettings.js\";\n\nexport const AiPowerUpsSettingsFeature = createFeature({\n name: \"AiPowerUps/Settings/Presenter\",\n register(container) {\n container.register(ProviderSettings);\n // container.register(PersonasSettings);\n container.register(AiPowerUpsSettingsPresenter);\n },\n resolve(container) {\n return {\n presenter: container.resolve(PresenterAbstraction)\n };\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,uBAAuB;AACrD,SAASC,2BAA2B,IAAIC,oBAAoB;AAC5D,SAASD,2BAA2B;AACpC,SAASE,gBAAgB;AACzB;;AAEA,OAAO,MAAMC,yBAAyB,GAAGJ,aAAa,CAAC;EACnDK,IAAI,EAAE,+BAA+B;EACrCC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,gBAAgB,CAAC;IACpC;IACAI,SAAS,CAACD,QAAQ,CAACL,2BAA2B,CAAC;EACnD,CAAC;EACDO,OAAOA,CAACD,SAAS,EAAE;IACf,OAAO;MACHE,SAAS,EAAEF,SAAS,CAACC,OAAO,CAACN,oBAAoB;IACrD,CAAC;EACL;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ export { AiPowerUpsSettingsFeature } from "./feature.js";
2
+ export { AiPowerUpsSettingsConfig } from "./AiPowerUpsSettingsConfig.js";
3
+ export { useAiPowerUpsSettingsDialog } from "./useAiPowerUpsSettingsDialog.js";
4
+ export { AI_POWER_UPS_SETTINGS_DIALOG } from "./AiPowerUpsSettingsDialog.js";
5
+ export { AiPowerUpsSettingsGroup } from "./settingsGroup.js";
@@ -0,0 +1,7 @@
1
+ export { AiPowerUpsSettingsFeature } from "./feature.js";
2
+ export { AiPowerUpsSettingsConfig } from "./AiPowerUpsSettingsConfig.js";
3
+ export { useAiPowerUpsSettingsDialog } from "./useAiPowerUpsSettingsDialog.js";
4
+ export { AI_POWER_UPS_SETTINGS_DIALOG } from "./AiPowerUpsSettingsDialog.js";
5
+ export { AiPowerUpsSettingsGroup } from "./settingsGroup.js";
6
+
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AiPowerUpsSettingsFeature","AiPowerUpsSettingsConfig","useAiPowerUpsSettingsDialog","AI_POWER_UPS_SETTINGS_DIALOG","AiPowerUpsSettingsGroup"],"sources":["index.ts"],"sourcesContent":["export { AiPowerUpsSettingsFeature } from \"./feature.js\";\nexport { AiPowerUpsSettingsConfig } from \"./AiPowerUpsSettingsConfig.js\";\nexport { useAiPowerUpsSettingsDialog } from \"./useAiPowerUpsSettingsDialog.js\";\nexport { AI_POWER_UPS_SETTINGS_DIALOG } from \"./AiPowerUpsSettingsDialog.js\";\nexport { AiPowerUpsSettingsGroup } from \"./settingsGroup.js\";\n"],"mappings":"AAAA,SAASA,yBAAyB;AAClC,SAASC,wBAAwB;AACjC,SAASC,2BAA2B;AACpC,SAASC,4BAA4B;AACrC,SAASC,uBAAuB","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ import { FormModelFactory } from "@webiny/app-admin";
2
+ import type { LayoutNode } from "@webiny/app-admin/features/formModel/abstractions.js";
3
+ export interface IAiPowerUpsSettingsGroupFormBuilder {
4
+ fields(fn: (fields: FormModelFactory.FieldBuilderRegistry) => Record<string, FormModelFactory.FieldBuilder>): void;
5
+ layout(fn: (layout: FormModelFactory.LayoutBuilder) => LayoutNode[]): void;
6
+ }
7
+ export interface IAiPowerUpsSettingsGroup {
8
+ name: string;
9
+ label: string;
10
+ description?: string;
11
+ icon?: string;
12
+ buildForm(formBuilder: IAiPowerUpsSettingsGroupFormBuilder): void;
13
+ }
14
+ export declare const AiPowerUpsSettingsGroup: import("@webiny/di").Abstraction<IAiPowerUpsSettingsGroup>;
15
+ export declare namespace AiPowerUpsSettingsGroup {
16
+ type Interface = IAiPowerUpsSettingsGroup;
17
+ type FormBuilder = IAiPowerUpsSettingsGroupFormBuilder;
18
+ }
@@ -0,0 +1,4 @@
1
+ import { createAbstraction } from "@webiny/feature/admin";
2
+ export const AiPowerUpsSettingsGroup = createAbstraction("AiPowerUps/SettingsGroup");
3
+
4
+ //# sourceMappingURL=settingsGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","AiPowerUpsSettingsGroup"],"sources":["settingsGroup.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport { FormModelFactory } from \"@webiny/app-admin\";\nimport type { LayoutNode } from \"@webiny/app-admin/features/formModel/abstractions.js\";\n\nexport interface IAiPowerUpsSettingsGroupFormBuilder {\n fields(\n fn: (\n fields: FormModelFactory.FieldBuilderRegistry\n ) => Record<string, FormModelFactory.FieldBuilder>\n ): void;\n layout(fn: (layout: FormModelFactory.LayoutBuilder) => LayoutNode[]): void;\n}\n\nexport interface IAiPowerUpsSettingsGroup {\n name: string;\n label: string;\n description?: string;\n icon?: string;\n buildForm(formBuilder: IAiPowerUpsSettingsGroupFormBuilder): void;\n}\n\nexport const AiPowerUpsSettingsGroup = createAbstraction<IAiPowerUpsSettingsGroup>(\n \"AiPowerUps/SettingsGroup\"\n);\n\nexport namespace AiPowerUpsSettingsGroup {\n export type Interface = IAiPowerUpsSettingsGroup;\n export type FormBuilder = IAiPowerUpsSettingsGroupFormBuilder;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,uBAAuB;AAqBzD,OAAO,MAAMC,uBAAuB,GAAGD,iBAAiB,CACpD,0BACJ,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const useAiPowerUpsSettingsDialog: () => () => void;
@@ -0,0 +1,12 @@
1
+ import { useOpenDialog } from "@webiny/app-admin";
2
+ import { AI_POWER_UPS_SETTINGS_DIALOG } from "./AiPowerUpsSettingsDialog.js";
3
+ export const useAiPowerUpsSettingsDialog = () => {
4
+ const {
5
+ openDialog
6
+ } = useOpenDialog();
7
+ return () => {
8
+ openDialog(AI_POWER_UPS_SETTINGS_DIALOG, {});
9
+ };
10
+ };
11
+
12
+ //# sourceMappingURL=useAiPowerUpsSettingsDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useOpenDialog","AI_POWER_UPS_SETTINGS_DIALOG","useAiPowerUpsSettingsDialog","openDialog"],"sources":["useAiPowerUpsSettingsDialog.ts"],"sourcesContent":["import { useOpenDialog } from \"@webiny/app-admin\";\nimport { AI_POWER_UPS_SETTINGS_DIALOG } from \"./AiPowerUpsSettingsDialog.js\";\n\nexport const useAiPowerUpsSettingsDialog = () => {\n const { openDialog } = useOpenDialog();\n\n return () => {\n openDialog(AI_POWER_UPS_SETTINGS_DIALOG, {});\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,mBAAmB;AACjD,SAASC,4BAA4B;AAErC,OAAO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC7C,MAAM;IAAEC;EAAW,CAAC,GAAGH,aAAa,CAAC,CAAC;EAEtC,OAAO,MAAM;IACTG,UAAU,CAACF,4BAA4B,EAAE,CAAC,CAAC,CAAC;EAChD,CAAC;AACL,CAAC","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import { AiPowerUpsSettingsGroup } from "./AiPowerUpsSettings/settingsGroup.js";
2
+ declare class PersonasSettingsImpl implements AiPowerUpsSettingsGroup.Interface {
3
+ name: string;
4
+ label: string;
5
+ description: string;
6
+ buildForm(form: AiPowerUpsSettingsGroup.FormBuilder): void;
7
+ }
8
+ export declare const PersonasSettings: typeof PersonasSettingsImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("./AiPowerUpsSettings/settingsGroup.js").IAiPowerUpsSettingsGroup>;
10
+ };
11
+ export {};
@@ -0,0 +1,28 @@
1
+ import { generateAlphaNumericId } from "@webiny/utils";
2
+ import { AiPowerUpsSettingsGroup } from "./AiPowerUpsSettings/settingsGroup.js";
3
+ class PersonasSettingsImpl {
4
+ name = "personas";
5
+ label = "Personas";
6
+ description = "Configure personas for content generation.";
7
+ buildForm(form) {
8
+ form.fields(fields => ({
9
+ presets: fields.object().renderer("objectListFlat", {
10
+ addItemLabel: "Add persona",
11
+ itemTitle: (data, index) => String(data.name || `Persona #${index + 1}`)
12
+ }).fields(f => ({
13
+ id: f.text().hidden().defaultValue(() => generateAlphaNumericId(10)),
14
+ name: f.text().label("Name").required("Name is required").description("This name will be used to identify the persona in the UI."),
15
+ description: f.text().label("Description").required("Description is required").description("Persona description will be used when prompting AI.").renderer("textarea", {
16
+ rows: 8
17
+ })
18
+ })).list()
19
+ }));
20
+ form.layout(layout => [layout.row("personas")]);
21
+ }
22
+ }
23
+ export const PersonasSettings = AiPowerUpsSettingsGroup.createImplementation({
24
+ implementation: PersonasSettingsImpl,
25
+ dependencies: []
26
+ });
27
+
28
+ //# sourceMappingURL=PersonasSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["generateAlphaNumericId","AiPowerUpsSettingsGroup","PersonasSettingsImpl","name","label","description","buildForm","form","fields","presets","object","renderer","addItemLabel","itemTitle","data","index","String","f","id","text","hidden","defaultValue","required","rows","list","layout","row","PersonasSettings","createImplementation","implementation","dependencies"],"sources":["PersonasSettings.ts"],"sourcesContent":["import { generateAlphaNumericId } from \"@webiny/utils\";\nimport { AiPowerUpsSettingsGroup } from \"./AiPowerUpsSettings/settingsGroup.js\";\n\nclass PersonasSettingsImpl implements AiPowerUpsSettingsGroup.Interface {\n name = \"personas\";\n label = \"Personas\";\n description = \"Configure personas for content generation.\";\n\n buildForm(form: AiPowerUpsSettingsGroup.FormBuilder): void {\n form.fields(fields => ({\n presets: fields\n .object()\n .renderer(\"objectListFlat\", {\n addItemLabel: \"Add persona\",\n itemTitle: (data, index) => String(data.name || `Persona #${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 persona in the UI.\"),\n description: f\n .text()\n .label(\"Description\")\n .required(\"Description is required\")\n .description(\"Persona description will be used when prompting AI.\")\n .renderer(\"textarea\", { rows: 8 })\n }))\n .list()\n }));\n\n form.layout(layout => [layout.row(\"personas\")]);\n }\n}\n\nexport const PersonasSettings = AiPowerUpsSettingsGroup.createImplementation({\n implementation: PersonasSettingsImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,eAAe;AACtD,SAASC,uBAAuB;AAEhC,MAAMC,oBAAoB,CAA8C;EACpEC,IAAI,GAAG,UAAU;EACjBC,KAAK,GAAG,UAAU;EAClBC,WAAW,GAAG,4CAA4C;EAE1DC,SAASA,CAACC,IAAyC,EAAQ;IACvDA,IAAI,CAACC,MAAM,CAACA,MAAM,KAAK;MACnBC,OAAO,EAAED,MAAM,CACVE,MAAM,CAAC,CAAC,CACRC,QAAQ,CAAC,gBAAgB,EAAE;QACxBC,YAAY,EAAE,aAAa;QAC3BC,SAAS,EAAEA,CAACC,IAAI,EAAEC,KAAK,KAAKC,MAAM,CAACF,IAAI,CAACX,IAAI,IAAI,YAAYY,KAAK,GAAG,CAAC,EAAE;MAC3E,CAAC,CAAC,CACDP,MAAM,CAACS,CAAC,KAAK;QACVC,EAAE,EAAED,CAAC,CACAE,IAAI,CAAC,CAAC,CACNC,MAAM,CAAC,CAAC,CACRC,YAAY,CAAC,MAAMrB,sBAAsB,CAAC,EAAE,CAAC,CAAC;QACnDG,IAAI,EAAEc,CAAC,CACFE,IAAI,CAAC,CAAC,CACNf,KAAK,CAAC,MAAM,CAAC,CACbkB,QAAQ,CAAC,kBAAkB,CAAC,CAC5BjB,WAAW,CAAC,2DAA2D,CAAC;QAC7EA,WAAW,EAAEY,CAAC,CACTE,IAAI,CAAC,CAAC,CACNf,KAAK,CAAC,aAAa,CAAC,CACpBkB,QAAQ,CAAC,yBAAyB,CAAC,CACnCjB,WAAW,CAAC,qDAAqD,CAAC,CAClEM,QAAQ,CAAC,UAAU,EAAE;UAAEY,IAAI,EAAE;QAAE,CAAC;MACzC,CAAC,CAAC,CAAC,CACFC,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEHjB,IAAI,CAACkB,MAAM,CAACA,MAAM,IAAI,CAACA,MAAM,CAACC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;EACnD;AACJ;AAEA,OAAO,MAAMC,gBAAgB,GAAG1B,uBAAuB,CAAC2B,oBAAoB,CAAC;EACzEC,cAAc,EAAE3B,oBAAoB;EACpC4B,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import { AiPowerUpsSettingsGroup } from "./AiPowerUpsSettings/settingsGroup.js";
2
+ import { ListModelsUseCase, ListModelsRepository } from "../../admin/features/listModels/abstractions.js";
3
+ declare class ProviderSettingsImpl implements AiPowerUpsSettingsGroup.Interface {
4
+ private useCase;
5
+ private repository;
6
+ name: string;
7
+ label: string;
8
+ description: string;
9
+ constructor(useCase: ListModelsUseCase.Interface, repository: ListModelsRepository.Interface);
10
+ buildForm(form: AiPowerUpsSettingsGroup.FormBuilder): void;
11
+ private getModelOptions;
12
+ }
13
+ export declare const ProviderSettings: typeof ProviderSettingsImpl & {
14
+ __abstraction: import("@webiny/di").Abstraction<import("./AiPowerUpsSettings/settingsGroup.js").IAiPowerUpsSettingsGroup>;
15
+ };
16
+ export {};
@@ -0,0 +1,37 @@
1
+ import { AiPowerUpsSettingsGroup } from "./AiPowerUpsSettings/settingsGroup.js";
2
+ import { ListModelsUseCase, ListModelsRepository } from "../features/listModels/abstractions.js";
3
+ class ProviderSettingsImpl {
4
+ name = "providers";
5
+ label = "Providers";
6
+ description = "Configure AI model providers.";
7
+ constructor(useCase, repository) {
8
+ this.useCase = useCase;
9
+ this.repository = repository;
10
+ }
11
+ buildForm(form) {
12
+ void this.useCase.execute();
13
+ form.fields(fields => ({
14
+ presets: fields.object().renderer("objectListFlat", {
15
+ addItemLabel: "Add provider",
16
+ itemTitle: (data, index) => String(data.name || `Preset #${index + 1}`)
17
+ }).fields(f => ({
18
+ name: f.text().label("Name").required("Name is required"),
19
+ model: f.select().label("Model").required("Model is required").options(() => this.getModelOptions()),
20
+ apiKey: f.text().label("API Key").required("API Key is required")
21
+ })).list()
22
+ }));
23
+ form.layout(layout => [layout.row("presets")]);
24
+ }
25
+ getModelOptions() {
26
+ return this.repository.getModels().map(model => ({
27
+ label: `${model.modelName} (${model.modelId})`,
28
+ value: `${model.providerId}/${model.modelId}`
29
+ }));
30
+ }
31
+ }
32
+ export const ProviderSettings = AiPowerUpsSettingsGroup.createImplementation({
33
+ implementation: ProviderSettingsImpl,
34
+ dependencies: [ListModelsUseCase, ListModelsRepository]
35
+ });
36
+
37
+ //# sourceMappingURL=ProvidersSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AiPowerUpsSettingsGroup","ListModelsUseCase","ListModelsRepository","ProviderSettingsImpl","name","label","description","constructor","useCase","repository","buildForm","form","execute","fields","presets","object","renderer","addItemLabel","itemTitle","data","index","String","f","text","required","model","select","options","getModelOptions","apiKey","list","layout","row","getModels","map","modelName","modelId","value","providerId","ProviderSettings","createImplementation","implementation","dependencies"],"sources":["ProvidersSettings.ts"],"sourcesContent":["import { AiPowerUpsSettingsGroup } from \"./AiPowerUpsSettings/settingsGroup.js\";\nimport {\n ListModelsUseCase,\n ListModelsRepository\n} from \"~/admin/features/listModels/abstractions.js\";\n\nclass ProviderSettingsImpl implements AiPowerUpsSettingsGroup.Interface {\n name = \"providers\";\n label = \"Providers\";\n description = \"Configure AI model providers.\";\n\n constructor(\n private useCase: ListModelsUseCase.Interface,\n private repository: ListModelsRepository.Interface\n ) {}\n\n buildForm(form: AiPowerUpsSettingsGroup.FormBuilder): void {\n void this.useCase.execute();\n\n form.fields(fields => ({\n presets: fields\n .object()\n .renderer(\"objectListFlat\", {\n addItemLabel: \"Add provider\",\n itemTitle: (data, index) => String(data.name || `Preset #${index + 1}`)\n })\n .fields(f => ({\n name: f.text().label(\"Name\").required(\"Name is required\"),\n model: f\n .select()\n .label(\"Model\")\n .required(\"Model is required\")\n .options(() => this.getModelOptions()),\n apiKey: f.text().label(\"API Key\").required(\"API Key is required\")\n }))\n .list()\n }));\n\n form.layout(layout => [layout.row(\"presets\")]);\n }\n\n private getModelOptions() {\n return this.repository.getModels().map(model => ({\n label: `${model.modelName} (${model.modelId})`,\n value: `${model.providerId}/${model.modelId}`\n }));\n }\n}\n\nexport const ProviderSettings = AiPowerUpsSettingsGroup.createImplementation({\n implementation: ProviderSettingsImpl,\n dependencies: [ListModelsUseCase, ListModelsRepository]\n});\n"],"mappings":"AAAA,SAASA,uBAAuB;AAChC,SACIC,iBAAiB,EACjBC,oBAAoB;AAGxB,MAAMC,oBAAoB,CAA8C;EACpEC,IAAI,GAAG,WAAW;EAClBC,KAAK,GAAG,WAAW;EACnBC,WAAW,GAAG,+BAA+B;EAE7CC,WAAWA,CACCC,OAAoC,EACpCC,UAA0C,EACpD;IAAA,KAFUD,OAAoC,GAApCA,OAAoC;IAAA,KACpCC,UAA0C,GAA1CA,UAA0C;EACnD;EAEHC,SAASA,CAACC,IAAyC,EAAQ;IACvD,KAAK,IAAI,CAACH,OAAO,CAACI,OAAO,CAAC,CAAC;IAE3BD,IAAI,CAACE,MAAM,CAACA,MAAM,KAAK;MACnBC,OAAO,EAAED,MAAM,CACVE,MAAM,CAAC,CAAC,CACRC,QAAQ,CAAC,gBAAgB,EAAE;QACxBC,YAAY,EAAE,cAAc;QAC5BC,SAAS,EAAEA,CAACC,IAAI,EAAEC,KAAK,KAAKC,MAAM,CAACF,IAAI,CAACf,IAAI,IAAI,WAAWgB,KAAK,GAAG,CAAC,EAAE;MAC1E,CAAC,CAAC,CACDP,MAAM,CAACS,CAAC,KAAK;QACVlB,IAAI,EAAEkB,CAAC,CAACC,IAAI,CAAC,CAAC,CAAClB,KAAK,CAAC,MAAM,CAAC,CAACmB,QAAQ,CAAC,kBAAkB,CAAC;QACzDC,KAAK,EAAEH,CAAC,CACHI,MAAM,CAAC,CAAC,CACRrB,KAAK,CAAC,OAAO,CAAC,CACdmB,QAAQ,CAAC,mBAAmB,CAAC,CAC7BG,OAAO,CAAC,MAAM,IAAI,CAACC,eAAe,CAAC,CAAC,CAAC;QAC1CC,MAAM,EAAEP,CAAC,CAACC,IAAI,CAAC,CAAC,CAAClB,KAAK,CAAC,SAAS,CAAC,CAACmB,QAAQ,CAAC,qBAAqB;MACpE,CAAC,CAAC,CAAC,CACFM,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEHnB,IAAI,CAACoB,MAAM,CAACA,MAAM,IAAI,CAACA,MAAM,CAACC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;EAClD;EAEQJ,eAAeA,CAAA,EAAG;IACtB,OAAO,IAAI,CAACnB,UAAU,CAACwB,SAAS,CAAC,CAAC,CAACC,GAAG,CAACT,KAAK,KAAK;MAC7CpB,KAAK,EAAE,GAAGoB,KAAK,CAACU,SAAS,KAAKV,KAAK,CAACW,OAAO,GAAG;MAC9CC,KAAK,EAAE,GAAGZ,KAAK,CAACa,UAAU,IAAIb,KAAK,CAACW,OAAO;IAC/C,CAAC,CAAC,CAAC;EACP;AACJ;AAEA,OAAO,MAAMG,gBAAgB,GAAGvC,uBAAuB,CAACwC,oBAAoB,CAAC;EACzEC,cAAc,EAAEtC,oBAAoB;EACpCuC,YAAY,EAAE,CAACzC,iBAAiB,EAAEC,oBAAoB;AAC1D,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare const WbContentGeneration: () => React.JSX.Element;
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import { AdminConfig, RegisterFeature } from "@webiny/app-admin";
3
+ import { PageEditorConfig } from "@webiny/app-website-builder";
4
+ import { GenerateContentButton } from "./GenerateContentButton.js";
5
+ import { GenerateContentDialog, GENERATE_CONTENT_DIALOG } from "./GenerateContentDialog.js";
6
+ import { GenerateContentFeature } from "./feature.js";
7
+ export const WbContentGeneration = () => {
8
+ const {
9
+ Ui
10
+ } = PageEditorConfig;
11
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(RegisterFeature, {
12
+ feature: GenerateContentFeature
13
+ }), /*#__PURE__*/React.createElement(AdminConfig, null, /*#__PURE__*/React.createElement(AdminConfig.Dialog, {
14
+ name: GENERATE_CONTENT_DIALOG,
15
+ element: /*#__PURE__*/React.createElement(GenerateContentDialog, null)
16
+ })), /*#__PURE__*/React.createElement(PageEditorConfig, null, /*#__PURE__*/React.createElement(Ui.TopBar.Action, {
17
+ name: "generateContent",
18
+ before: "revisionsMenu",
19
+ element: /*#__PURE__*/React.createElement(Ui.IsNotReadOnly, null, /*#__PURE__*/React.createElement(GenerateContentButton, null))
20
+ })));
21
+ };
22
+
23
+ //# sourceMappingURL=Extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","AdminConfig","RegisterFeature","PageEditorConfig","GenerateContentButton","GenerateContentDialog","GENERATE_CONTENT_DIALOG","GenerateContentFeature","WbContentGeneration","Ui","createElement","Fragment","feature","Dialog","name","element","TopBar","Action","before","IsNotReadOnly"],"sources":["Extension.tsx"],"sourcesContent":["import React from \"react\";\nimport { AdminConfig, RegisterFeature } from \"@webiny/app-admin\";\nimport { PageEditorConfig } from \"@webiny/app-website-builder\";\nimport { GenerateContentButton } from \"~/admin/presentation/WbContentGeneration/GenerateContentButton.js\";\nimport {\n GenerateContentDialog,\n GENERATE_CONTENT_DIALOG\n} from \"~/admin/presentation/WbContentGeneration/GenerateContentDialog.js\";\nimport { GenerateContentFeature } from \"~/admin/presentation/WbContentGeneration/feature.js\";\n\nexport const WbContentGeneration = () => {\n const { Ui } = PageEditorConfig;\n\n return (\n <>\n <RegisterFeature feature={GenerateContentFeature} />\n <AdminConfig>\n <AdminConfig.Dialog\n name={GENERATE_CONTENT_DIALOG}\n element={<GenerateContentDialog />}\n />\n </AdminConfig>\n <PageEditorConfig>\n <Ui.TopBar.Action\n name={\"generateContent\"}\n before={\"revisionsMenu\"}\n element={\n <Ui.IsNotReadOnly>\n <GenerateContentButton />\n </Ui.IsNotReadOnly>\n }\n />\n </PageEditorConfig>\n </>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW,EAAEC,eAAe,QAAQ,mBAAmB;AAChE,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,qBAAqB;AAC9B,SACIC,qBAAqB,EACrBC,uBAAuB;AAE3B,SAASC,sBAAsB;AAE/B,OAAO,MAAMC,mBAAmB,GAAGA,CAAA,KAAM;EACrC,MAAM;IAAEC;EAAG,CAAC,GAAGN,gBAAgB;EAE/B,oBACIH,KAAA,CAAAU,aAAA,CAAAV,KAAA,CAAAW,QAAA,qBACIX,KAAA,CAAAU,aAAA,CAACR,eAAe;IAACU,OAAO,EAAEL;EAAuB,CAAE,CAAC,eACpDP,KAAA,CAAAU,aAAA,CAACT,WAAW,qBACRD,KAAA,CAAAU,aAAA,CAACT,WAAW,CAACY,MAAM;IACfC,IAAI,EAAER,uBAAwB;IAC9BS,OAAO,eAAEf,KAAA,CAAAU,aAAA,CAACL,qBAAqB,MAAE;EAAE,CACtC,CACQ,CAAC,eACdL,KAAA,CAAAU,aAAA,CAACP,gBAAgB,qBACbH,KAAA,CAAAU,aAAA,CAACD,EAAE,CAACO,MAAM,CAACC,MAAM;IACbH,IAAI,EAAE,iBAAkB;IACxBI,MAAM,EAAE,eAAgB;IACxBH,OAAO,eACHf,KAAA,CAAAU,aAAA,CAACD,EAAE,CAACU,aAAa,qBACbnB,KAAA,CAAAU,aAAA,CAACN,qBAAqB,MAAE,CACV;EACrB,CACJ,CACa,CACpB,CAAC;AAEX,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare const GenerateContentButton: () => React.JSX.Element;
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { IconButton } from "@webiny/admin-ui";
3
+ import { ReactComponent as ChatIcon } from "@webiny/icons/auto_fix_high.svg";
4
+ import { useOpenDialog } from "@webiny/app-admin";
5
+ import { GENERATE_CONTENT_DIALOG } from "./GenerateContentDialog.js";
6
+ export const GenerateContentButton = () => {
7
+ const {
8
+ openDialog
9
+ } = useOpenDialog();
10
+ return /*#__PURE__*/React.createElement(IconButton, {
11
+ variant: "ghost",
12
+ icon: /*#__PURE__*/React.createElement(ChatIcon, null),
13
+ onClick: () => openDialog(GENERATE_CONTENT_DIALOG, {})
14
+ });
15
+ };
16
+
17
+ //# sourceMappingURL=GenerateContentButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","IconButton","ReactComponent","ChatIcon","useOpenDialog","GENERATE_CONTENT_DIALOG","GenerateContentButton","openDialog","createElement","variant","icon","onClick"],"sources":["GenerateContentButton.tsx"],"sourcesContent":["import React from \"react\";\nimport { IconButton } from \"@webiny/admin-ui\";\nimport { ReactComponent as ChatIcon } from \"@webiny/icons/auto_fix_high.svg\";\nimport { useOpenDialog } from \"@webiny/app-admin\";\nimport { GENERATE_CONTENT_DIALOG } from \"./GenerateContentDialog.js\";\n\nexport const GenerateContentButton = () => {\n const { openDialog } = useOpenDialog();\n\n return (\n <IconButton\n variant=\"ghost\"\n icon={<ChatIcon />}\n onClick={() => openDialog(GENERATE_CONTENT_DIALOG, {})}\n />\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,cAAc,IAAIC,QAAQ,QAAQ,iCAAiC;AAC5E,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,uBAAuB;AAEhC,OAAO,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,MAAM;IAAEC;EAAW,CAAC,GAAGH,aAAa,CAAC,CAAC;EAEtC,oBACIJ,KAAA,CAAAQ,aAAA,CAACP,UAAU;IACPQ,OAAO,EAAC,OAAO;IACfC,IAAI,eAAEV,KAAA,CAAAQ,aAAA,CAACL,QAAQ,MAAE,CAAE;IACnBQ,OAAO,EAAEA,CAAA,KAAMJ,UAAU,CAACF,uBAAuB,EAAE,CAAC,CAAC;EAAE,CAC1D,CAAC;AAEV,CAAC","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import type { IncomingGenericData } from "@webiny/app-websockets";
3
+ export declare const GENERATE_CONTENT_DIALOG = "generate-content";
4
+ export declare const WS_ACTION_CONTENT = "aiPowerUps.generatePageContent.content";
5
+ export declare const WS_ACTION_ERROR = "aiPowerUps.generatePageContent.error";
6
+ export interface GeneratePageContentMessage extends IncomingGenericData {
7
+ action: typeof WS_ACTION_CONTENT;
8
+ data: {
9
+ compression: "gzip";
10
+ value: string;
11
+ };
12
+ }
13
+ export interface GeneratePageContentErrorMessage extends IncomingGenericData {
14
+ action: typeof WS_ACTION_ERROR;
15
+ data: {
16
+ message: string;
17
+ };
18
+ }
19
+ export declare const GenerateContentDialog: (() => React.JSX.Element) & {
20
+ displayName: string;
21
+ };
@@ -0,0 +1,102 @@
1
+ import React, { useCallback, useEffect, useRef } from "react";
2
+ import { observer } from "mobx-react-lite";
3
+ import { useDialog } from "@webiny/app-admin";
4
+ import { Dialog, OverlayLoader, Textarea, useToast } from "@webiny/admin-ui";
5
+ import { useFeature } from "@webiny/app";
6
+ import { useWebsockets } from "@webiny/app-websockets";
7
+ import { useSelectFromEditor } from "@webiny/app-website-builder/BaseEditor/hooks/useSelectFromEditor.js";
8
+ import { useCreateElement } from "@webiny/app-website-builder/BaseEditor/hooks/useCreateElement.js";
9
+ import { GenerateContentFeature } from "./feature.js";
10
+ import { decompressGzipBase64 } from "./decompressGzipBase64.js";
11
+ export const GENERATE_CONTENT_DIALOG = "generate-content";
12
+ export const WS_ACTION_CONTENT = "aiPowerUps.generatePageContent.content";
13
+ export const WS_ACTION_ERROR = "aiPowerUps.generatePageContent.error";
14
+ export const GenerateContentDialog = observer(() => {
15
+ const {
16
+ closeDialog
17
+ } = useDialog();
18
+ const {
19
+ presenter
20
+ } = useFeature(GenerateContentFeature);
21
+ const vm = presenter.vm;
22
+ const wasSubmitting = useRef(false);
23
+ const websockets = useWebsockets();
24
+ const toast = useToast();
25
+ const components = useSelectFromEditor(state => state.components);
26
+ const {
27
+ createElement
28
+ } = useCreateElement();
29
+ const createElements = useCallback(elements => {
30
+ elements.forEach(el => createElement(el));
31
+ }, [createElement]);
32
+ useEffect(() => {
33
+ const aiComponents = Object.values(components).filter(c => c.useInAiContentGeneration !== false).map(c => {
34
+ return {
35
+ name: c.name,
36
+ label: c.label,
37
+ aiContext: c.aiContext,
38
+ inputs: c.inputs.map(input => ({
39
+ type: input.type,
40
+ name: input.name,
41
+ label: input.label,
42
+ description: input.description
43
+ }))
44
+ };
45
+ });
46
+ presenter.init(aiComponents, createElements);
47
+ }, [components, createElements]);
48
+ useEffect(() => {
49
+ const contentSubscription = websockets.onMessage(WS_ACTION_CONTENT, async message => {
50
+ const responseText = await decompressGzipBase64(message.data.value);
51
+ await presenter.processAiResponse(responseText);
52
+ });
53
+ const errorSubscription = websockets.onMessage(WS_ACTION_ERROR, async message => {
54
+ toast.showWarningToast({
55
+ title: "Failed to generate content",
56
+ description: message.data.message
57
+ });
58
+ presenter.cancelPrompt();
59
+ });
60
+ return () => {
61
+ contentSubscription.off();
62
+ errorSubscription.off();
63
+ };
64
+ }, []);
65
+ useEffect(() => {
66
+ if (wasSubmitting.current && !vm.submitting) {
67
+ closeDialog();
68
+ }
69
+ wasSubmitting.current = vm.submitting;
70
+ }, [vm.submitting]);
71
+ const handleSubmit = async () => {
72
+ await presenter.submit();
73
+ };
74
+ const isProcessing = vm.processing;
75
+ const isSubmitting = vm.submitting;
76
+ return /*#__PURE__*/React.createElement(Dialog, {
77
+ open: true,
78
+ onClose: closeDialog,
79
+ title: "Generate Content",
80
+ size: "lg",
81
+ actions: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dialog.CancelAction, {
82
+ onClick: closeDialog,
83
+ text: "Cancel"
84
+ }), /*#__PURE__*/React.createElement(Dialog.ConfirmAction, {
85
+ onClick: handleSubmit,
86
+ text: "Generate",
87
+ disabled: !vm.prompt.trim() || vm.submitting
88
+ }))
89
+ }, isSubmitting ? /*#__PURE__*/React.createElement(OverlayLoader, {
90
+ text: "Generating content..."
91
+ }) : null, isProcessing ? /*#__PURE__*/React.createElement(OverlayLoader, {
92
+ text: "Processing content..."
93
+ }) : null, /*#__PURE__*/React.createElement(Textarea, {
94
+ label: "Prompt",
95
+ description: "Describe the page content you want to generate.",
96
+ value: vm.prompt,
97
+ onChange: value => presenter.setPrompt(String(value ?? "")),
98
+ rows: 6
99
+ }));
100
+ });
101
+
102
+ //# sourceMappingURL=GenerateContentDialog.js.map