@webiny/ai-powerups 6.3.0-beta.2 → 6.3.0-beta.4

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 (68) hide show
  1. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.js +2 -2
  2. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.js.map +1 -1
  3. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.js +17 -13
  4. package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.js.map +1 -1
  5. package/admin/presentation/AiPowerUpsSettings/settingsGroup.d.ts +3 -4
  6. package/admin/presentation/AiPowerUpsSettings/settingsGroup.js.map +1 -1
  7. package/admin/presentation/PersonasSettings.js +2 -1
  8. package/admin/presentation/PersonasSettings.js.map +1 -1
  9. package/admin/presentation/ProvidersSettings.js +6 -3
  10. package/admin/presentation/ProvidersSettings.js.map +1 -1
  11. package/admin/presentation/WbContentGeneration/GenerateContentDialog.js +36 -0
  12. package/admin/presentation/WbContentGeneration/GenerateContentDialog.js.map +1 -1
  13. package/api/Extension.js +4 -0
  14. package/api/Extension.js.map +1 -1
  15. package/api/features/GetSettings/GetSettingsRepository.d.ts +5 -5
  16. package/api/features/GetSettings/GetSettingsRepository.js +20 -22
  17. package/api/features/GetSettings/GetSettingsRepository.js.map +1 -1
  18. package/api/features/GetSettings/GetSettingsUseCase.d.ts +1 -1
  19. package/api/features/GetSettings/abstractions.d.ts +3 -3
  20. package/api/features/GetSettings/abstractions.js.map +1 -1
  21. package/api/features/Providers/ProvidersGraphQLMapper.d.ts +21 -0
  22. package/api/features/Providers/ProvidersGraphQLMapper.js +36 -0
  23. package/api/features/Providers/ProvidersGraphQLMapper.js.map +1 -0
  24. package/api/features/Providers/ProvidersHandler.d.ts +26 -0
  25. package/api/features/Providers/ProvidersHandler.js +76 -0
  26. package/api/features/Providers/ProvidersHandler.js.map +1 -0
  27. package/api/features/Providers/feature.d.ts +4 -0
  28. package/api/features/Providers/feature.js +12 -0
  29. package/api/features/Providers/feature.js.map +1 -0
  30. package/api/features/Providers/index.d.ts +1 -0
  31. package/api/features/Providers/index.js +3 -0
  32. package/api/features/Providers/index.js.map +1 -0
  33. package/api/features/Providers/types.d.ts +29 -0
  34. package/api/features/Providers/types.js +3 -0
  35. package/api/features/Providers/types.js.map +1 -0
  36. package/api/features/UpdateSettings/UpdateSettingsRepository.d.ts +6 -6
  37. package/api/features/UpdateSettings/UpdateSettingsRepository.js +56 -18
  38. package/api/features/UpdateSettings/UpdateSettingsRepository.js.map +1 -1
  39. package/api/features/UpdateSettings/UpdateSettingsUseCase.d.ts +4 -5
  40. package/api/features/UpdateSettings/UpdateSettingsUseCase.js +2 -14
  41. package/api/features/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
  42. package/api/features/UpdateSettings/abstractions.d.ts +8 -15
  43. package/api/features/UpdateSettings/abstractions.js.map +1 -1
  44. package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.d.ts +3 -1
  45. package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.js +8 -3
  46. package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.js.map +1 -1
  47. package/api/features/shared/abstractions.d.ts +20 -0
  48. package/api/features/shared/abstractions.js +5 -0
  49. package/api/features/shared/abstractions.js.map +1 -0
  50. package/api/features/shared/index.d.ts +1 -0
  51. package/api/features/shared/index.js +3 -0
  52. package/api/features/shared/index.js.map +1 -0
  53. package/api/graphql/AiPowerUpsSettingsGraphQLMapper.d.ts +13 -0
  54. package/api/graphql/AiPowerUpsSettingsGraphQLMapper.js +35 -0
  55. package/api/graphql/AiPowerUpsSettingsGraphQLMapper.js.map +1 -0
  56. package/api/graphql/BaseGraphQLSchema.d.ts +1 -1
  57. package/api/graphql/BaseGraphQLSchema.js +15 -9
  58. package/api/graphql/BaseGraphQLSchema.js.map +1 -1
  59. package/api/graphql/abstractions.d.ts +9 -0
  60. package/api/graphql/abstractions.js +4 -0
  61. package/api/graphql/abstractions.js.map +1 -0
  62. package/api/types.d.ts +2 -10
  63. package/api/types.js +3 -0
  64. package/api/types.js.map +1 -1
  65. package/package.json +26 -23
  66. package/api/features/UpdateSettings/validation.d.ts +0 -11
  67. package/api/features/UpdateSettings/validation.js +0 -16
  68. package/api/features/UpdateSettings/validation.js.map +0 -1
@@ -0,0 +1,36 @@
1
+ import { AiPowerUpsSettingsGroupGraphQLMapper } from "../shared/index.js";
2
+ class ProvidersGraphQLMapperImpl {
3
+ name = "providers";
4
+ toApi(internal) {
5
+ const data = internal;
6
+ return {
7
+ presets: data.presets.map(p => ({
8
+ id: p.id,
9
+ name: p.name,
10
+ description: p.description,
11
+ model: p.model,
12
+ apiKey: p.apiKeyMasked ?? null
13
+ }))
14
+ };
15
+ }
16
+ fromApi(api) {
17
+ const data = api;
18
+ return {
19
+ presets: data.presets.map(p => ({
20
+ id: p.id,
21
+ name: p.name,
22
+ description: p.description,
23
+ model: p.model,
24
+ apiKey: p.apiKey,
25
+ apiKeyMasked: "",
26
+ apiKeyEncrypted: ""
27
+ }))
28
+ };
29
+ }
30
+ }
31
+ export default AiPowerUpsSettingsGroupGraphQLMapper.createImplementation({
32
+ implementation: ProvidersGraphQLMapperImpl,
33
+ dependencies: []
34
+ });
35
+
36
+ //# sourceMappingURL=ProvidersGraphQLMapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AiPowerUpsSettingsGroupGraphQLMapper","ProvidersGraphQLMapperImpl","name","toApi","internal","data","presets","map","p","id","description","model","apiKey","apiKeyMasked","fromApi","api","apiKeyEncrypted","createImplementation","implementation","dependencies"],"sources":["ProvidersGraphQLMapper.ts"],"sourcesContent":["import { AiPowerUpsSettingsGroupGraphQLMapper } from \"~/api/features/shared/index.js\";\nimport type { ProvidersSettings } from \"./types.js\";\n\ninterface ApiProviderPreset {\n id: string;\n name: string;\n description?: string;\n model: string;\n apiKey: string | null;\n}\n\ninterface ApiProviders {\n presets: ApiProviderPreset[];\n}\n\ninterface ApiInputProviderPreset {\n id: string;\n name: string;\n description?: string;\n model: string;\n apiKey?: string;\n}\n\ninterface ApiInputProviders {\n presets: ApiInputProviderPreset[];\n}\n\nclass ProvidersGraphQLMapperImpl implements AiPowerUpsSettingsGroupGraphQLMapper.Interface {\n readonly name = \"providers\";\n\n toApi(internal: unknown): ApiProviders {\n const data = internal as ProvidersSettings;\n return {\n presets: data.presets.map(p => ({\n id: p.id,\n name: p.name,\n description: p.description,\n model: p.model,\n apiKey: p.apiKeyMasked ?? null\n }))\n };\n }\n\n fromApi(api: unknown): ProvidersSettings {\n const data = api as ApiInputProviders;\n return {\n presets: data.presets.map(p => ({\n id: p.id,\n name: p.name,\n description: p.description,\n model: p.model,\n apiKey: p.apiKey,\n apiKeyMasked: \"\",\n apiKeyEncrypted: \"\"\n }))\n };\n }\n}\n\nexport default AiPowerUpsSettingsGroupGraphQLMapper.createImplementation({\n implementation: ProvidersGraphQLMapperImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,oCAAoC;AA2B7C,MAAMC,0BAA0B,CAA2D;EAC9EC,IAAI,GAAG,WAAW;EAE3BC,KAAKA,CAACC,QAAiB,EAAgB;IACnC,MAAMC,IAAI,GAAGD,QAA6B;IAC1C,OAAO;MACHE,OAAO,EAAED,IAAI,CAACC,OAAO,CAACC,GAAG,CAACC,CAAC,KAAK;QAC5BC,EAAE,EAAED,CAAC,CAACC,EAAE;QACRP,IAAI,EAAEM,CAAC,CAACN,IAAI;QACZQ,WAAW,EAAEF,CAAC,CAACE,WAAW;QAC1BC,KAAK,EAAEH,CAAC,CAACG,KAAK;QACdC,MAAM,EAAEJ,CAAC,CAACK,YAAY,IAAI;MAC9B,CAAC,CAAC;IACN,CAAC;EACL;EAEAC,OAAOA,CAACC,GAAY,EAAqB;IACrC,MAAMV,IAAI,GAAGU,GAAwB;IACrC,OAAO;MACHT,OAAO,EAAED,IAAI,CAACC,OAAO,CAACC,GAAG,CAACC,CAAC,KAAK;QAC5BC,EAAE,EAAED,CAAC,CAACC,EAAE;QACRP,IAAI,EAAEM,CAAC,CAACN,IAAI;QACZQ,WAAW,EAAEF,CAAC,CAACE,WAAW;QAC1BC,KAAK,EAAEH,CAAC,CAACG,KAAK;QACdC,MAAM,EAAEJ,CAAC,CAACI,MAAM;QAChBC,YAAY,EAAE,EAAE;QAChBG,eAAe,EAAE;MACrB,CAAC,CAAC;IACN,CAAC;EACL;AACJ;AAEA,eAAehB,oCAAoC,CAACiB,oBAAoB,CAAC;EACrEC,cAAc,EAAEjB,0BAA0B;EAC1CkB,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import { z } from "zod";
2
+ import { Encryption } from "@webiny/api-core/features/encryption/index.js";
3
+ import { Masker } from "@webiny/api-core/features/masker/index.js";
4
+ import { AiPowerUpsSettingsGroupHandler } from "../../../api/features/shared/index.js";
5
+ import type { PersistedProviders, ProvidersSettings } from "./types.js";
6
+ declare class ProvidersHandlerImpl implements AiPowerUpsSettingsGroupHandler.Interface {
7
+ private encryption;
8
+ private masker;
9
+ readonly name = "providers";
10
+ readonly inputSchema: z.ZodObject<{
11
+ presets: z.ZodArray<z.ZodObject<{
12
+ id: z.ZodString;
13
+ name: z.ZodString;
14
+ description: z.ZodOptional<z.ZodString>;
15
+ model: z.ZodString;
16
+ apiKey: z.ZodOptional<z.ZodString>;
17
+ }, z.core.$strip>>;
18
+ }, z.core.$strip>;
19
+ constructor(encryption: Encryption.Interface, masker: Masker.Interface);
20
+ mapFromStorage(persisted: unknown): ProvidersSettings;
21
+ mapToStorage(internal: unknown, existing: unknown | null): Promise<PersistedProviders>;
22
+ }
23
+ declare const _default: typeof ProvidersHandlerImpl & {
24
+ __abstraction: import("@webiny/di").Abstraction<import("../shared/abstractions.js").IAiPowerUpsSettingsGroupHandler>;
25
+ };
26
+ export default _default;
@@ -0,0 +1,76 @@
1
+ import { z } from "zod";
2
+ import { Encryption } from "@webiny/api-core/features/encryption/index.js";
3
+ import { Masker } from "@webiny/api-core/features/masker/index.js";
4
+ import { AiPowerUpsSettingsGroupHandler } from "../shared/index.js";
5
+ const inputSchema = z.object({
6
+ presets: z.array(z.object({
7
+ id: z.string().min(1),
8
+ name: z.string().min(1),
9
+ description: z.string().optional(),
10
+ model: z.string().min(1),
11
+ apiKey: z.string().optional()
12
+ }))
13
+ });
14
+ class ProvidersHandlerImpl {
15
+ name = "providers";
16
+ inputSchema = inputSchema;
17
+ constructor(encryption, masker) {
18
+ this.encryption = encryption;
19
+ this.masker = masker;
20
+ }
21
+ mapFromStorage(persisted) {
22
+ if (!persisted || typeof persisted !== "object") {
23
+ return {
24
+ presets: []
25
+ };
26
+ }
27
+ const data = persisted;
28
+ const presets = (data.presets ?? []).map(p => ({
29
+ id: p.id,
30
+ name: p.name,
31
+ description: p.description,
32
+ model: p.model,
33
+ apiKeyMasked: p.apiKeyMasked ?? "",
34
+ apiKeyEncrypted: p.apiKeyEncrypted ?? ""
35
+ }));
36
+ return {
37
+ presets
38
+ };
39
+ }
40
+ async mapToStorage(internal, existing) {
41
+ const input = internal;
42
+ const existingData = existing;
43
+ const existingPresets = existingData?.presets ?? [];
44
+ const presets = await Promise.all(input.presets.map(async preset => {
45
+ const existingMatch = existingPresets.find(ep => ep.id === preset.id);
46
+ let apiKeyEncrypted;
47
+ let apiKeyMasked;
48
+ if (!preset.apiKey || preset.apiKey === existingMatch?.apiKeyMasked) {
49
+ // Carry forward existing encrypted key
50
+ apiKeyEncrypted = existingMatch?.apiKeyEncrypted ?? "";
51
+ apiKeyMasked = existingMatch?.apiKeyMasked ?? "";
52
+ } else {
53
+ // New plaintext key — encrypt and mask
54
+ apiKeyEncrypted = this.encryption.encrypt(preset.apiKey);
55
+ apiKeyMasked = this.masker.mask(preset.apiKey, [8, 4]);
56
+ }
57
+ return {
58
+ id: preset.id,
59
+ name: preset.name,
60
+ description: preset.description,
61
+ model: preset.model,
62
+ apiKeyEncrypted,
63
+ apiKeyMasked
64
+ };
65
+ }));
66
+ return {
67
+ presets
68
+ };
69
+ }
70
+ }
71
+ export default AiPowerUpsSettingsGroupHandler.createImplementation({
72
+ implementation: ProvidersHandlerImpl,
73
+ dependencies: [Encryption, Masker]
74
+ });
75
+
76
+ //# sourceMappingURL=ProvidersHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["z","Encryption","Masker","AiPowerUpsSettingsGroupHandler","inputSchema","object","presets","array","id","string","min","name","description","optional","model","apiKey","ProvidersHandlerImpl","constructor","encryption","masker","mapFromStorage","persisted","data","map","p","apiKeyMasked","apiKeyEncrypted","mapToStorage","internal","existing","input","existingData","existingPresets","Promise","all","preset","existingMatch","find","ep","encrypt","mask","createImplementation","implementation","dependencies"],"sources":["ProvidersHandler.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Encryption } from \"@webiny/api-core/features/encryption/index.js\";\nimport { Masker } from \"@webiny/api-core/features/masker/index.js\";\nimport { AiPowerUpsSettingsGroupHandler } from \"~/api/features/shared/index.js\";\nimport type { PersistedProviderPreset, PersistedProviders, ProvidersSettings } from \"./types.js\";\n\nconst inputSchema = z.object({\n presets: z.array(\n z.object({\n id: z.string().min(1),\n name: z.string().min(1),\n description: z.string().optional(),\n model: z.string().min(1),\n apiKey: z.string().optional()\n })\n )\n});\n\nclass ProvidersHandlerImpl implements AiPowerUpsSettingsGroupHandler.Interface {\n readonly name = \"providers\";\n readonly inputSchema = inputSchema;\n\n constructor(\n private encryption: Encryption.Interface,\n private masker: Masker.Interface\n ) {}\n\n mapFromStorage(persisted: unknown): ProvidersSettings {\n if (!persisted || typeof persisted !== \"object\") {\n return { presets: [] };\n }\n\n const data = persisted as PersistedProviders;\n const presets = (data.presets ?? []).map(p => ({\n id: p.id,\n name: p.name,\n description: p.description,\n model: p.model,\n apiKeyMasked: p.apiKeyMasked ?? \"\",\n apiKeyEncrypted: p.apiKeyEncrypted ?? \"\"\n }));\n\n return { presets };\n }\n\n async mapToStorage(internal: unknown, existing: unknown | null): Promise<PersistedProviders> {\n const input = internal as ProvidersSettings;\n const existingData = existing as ProvidersSettings | null;\n const existingPresets = existingData?.presets ?? [];\n\n const presets: PersistedProviderPreset[] = await Promise.all(\n input.presets.map(async preset => {\n const existingMatch = existingPresets.find(ep => ep.id === preset.id);\n\n let apiKeyEncrypted: string;\n let apiKeyMasked: string;\n\n if (!preset.apiKey || preset.apiKey === existingMatch?.apiKeyMasked) {\n // Carry forward existing encrypted key\n apiKeyEncrypted = existingMatch?.apiKeyEncrypted ?? \"\";\n apiKeyMasked = existingMatch?.apiKeyMasked ?? \"\";\n } else {\n // New plaintext key — encrypt and mask\n apiKeyEncrypted = this.encryption.encrypt(preset.apiKey);\n apiKeyMasked = this.masker.mask(preset.apiKey, [8, 4]);\n }\n\n return {\n id: preset.id,\n name: preset.name,\n description: preset.description,\n model: preset.model,\n apiKeyEncrypted,\n apiKeyMasked\n };\n })\n );\n\n return { presets };\n }\n}\n\nexport default AiPowerUpsSettingsGroupHandler.createImplementation({\n implementation: ProvidersHandlerImpl,\n dependencies: [Encryption, Masker]\n});\n"],"mappings":"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","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export declare const ProvidersFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,12 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import ProvidersHandler from "./ProvidersHandler.js";
3
+ import ProvidersGraphQLMapper from "./ProvidersGraphQLMapper.js";
4
+ export const ProvidersFeature = createFeature({
5
+ name: "AiPowerUpsProviders",
6
+ register(container) {
7
+ container.register(ProvidersHandler);
8
+ container.register(ProvidersGraphQLMapper);
9
+ }
10
+ });
11
+
12
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFeature","ProvidersHandler","ProvidersGraphQLMapper","ProvidersFeature","name","register","container"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport ProvidersHandler from \"./ProvidersHandler.js\";\nimport ProvidersGraphQLMapper from \"./ProvidersGraphQLMapper.js\";\n\nexport const ProvidersFeature = createFeature({\n name: \"AiPowerUpsProviders\",\n register(container) {\n container.register(ProvidersHandler);\n container.register(ProvidersGraphQLMapper);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,OAAOC,gBAAgB;AACvB,OAAOC,sBAAsB;AAE7B,OAAO,MAAMC,gBAAgB,GAAGH,aAAa,CAAC;EAC1CI,IAAI,EAAE,qBAAqB;EAC3BC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACJ,gBAAgB,CAAC;IACpCK,SAAS,CAACD,QAAQ,CAACH,sBAAsB,CAAC;EAC9C;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export type { ProviderPreset, ProvidersSettings } from "./types.js";
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type { ProviderPreset, ProvidersSettings } from \"./types.js\";\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ import type { IAiPowerUpsSettings } from "../../../api/types.js";
2
+ export interface ProviderPreset {
3
+ id: string;
4
+ name: string;
5
+ description?: string;
6
+ model: string;
7
+ apiKey?: string;
8
+ apiKeyMasked: string;
9
+ apiKeyEncrypted: string;
10
+ }
11
+ declare module "~/api/types.js" {
12
+ interface IAiPowerUpsSettings {
13
+ providers: {
14
+ presets: ProviderPreset[];
15
+ };
16
+ }
17
+ }
18
+ export type ProvidersSettings = IAiPowerUpsSettings["providers"];
19
+ export interface PersistedProviderPreset {
20
+ id: string;
21
+ name: string;
22
+ description?: string;
23
+ model: string;
24
+ apiKeyEncrypted: string;
25
+ apiKeyMasked: string;
26
+ }
27
+ export interface PersistedProviders {
28
+ presets: PersistedProviderPreset[];
29
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IAiPowerUpsSettings } from \"~/api/types.js\";\n\nexport interface ProviderPreset {\n id: string;\n name: string;\n description?: string;\n model: string;\n apiKey?: string;\n apiKeyMasked: string;\n apiKeyEncrypted: string;\n}\n\ndeclare module \"~/api/types.js\" {\n interface IAiPowerUpsSettings {\n providers: {\n presets: ProviderPreset[];\n };\n }\n}\n\nexport type ProvidersSettings = IAiPowerUpsSettings[\"providers\"];\n\nexport interface PersistedProviderPreset {\n id: string;\n name: string;\n description?: string;\n model: string;\n apiKeyEncrypted: string;\n apiKeyMasked: string;\n}\n\nexport interface PersistedProviders {\n presets: PersistedProviderPreset[];\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,13 +1,13 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
3
- import { Encryption } from "@webiny/api-core/features/encryption/index.js";
4
- import { UpdateSettingsRepository, type UpdateSettingsInput } from "./abstractions.js";
5
- import type { AiPowerUpsSettings } from "../../../api/types.js";
3
+ import { AiPowerUpsSettingsGroupHandler } from "../../../api/features/shared/index.js";
4
+ import { UpdateSettingsRepository } from "./abstractions.js";
5
+ import type { IAiPowerUpsSettings } from "../../../api/types.js";
6
6
  declare class UpdateSettingsRepositoryImpl implements UpdateSettingsRepository.Interface {
7
7
  private keyValueStore;
8
- private encryption;
9
- constructor(keyValueStore: KeyValueStore.Interface, encryption: Encryption.Interface);
10
- execute(input: UpdateSettingsInput): Promise<Result<AiPowerUpsSettings, Error>>;
8
+ private handlers;
9
+ constructor(keyValueStore: KeyValueStore.Interface, handlers: AiPowerUpsSettingsGroupHandler.Interface[]);
10
+ execute(input: IAiPowerUpsSettings): Promise<Result<IAiPowerUpsSettings, Error>>;
11
11
  }
12
12
  export declare const UpdateSettingsRepositoryImplementation: typeof UpdateSettingsRepositoryImpl & {
13
13
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUpdateSettingsRepository>;
@@ -1,36 +1,74 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
3
- import { Encryption } from "@webiny/api-core/features/encryption/index.js";
3
+ import { AiPowerUpsSettingsGroupHandler } from "../shared/index.js";
4
4
  import { UpdateSettingsRepository } from "./abstractions.js";
5
5
  import { AI_POWER_UPS_SETTINGS } from "../../constants.js";
6
6
  class UpdateSettingsRepositoryImpl {
7
- constructor(keyValueStore, encryption) {
7
+ constructor(keyValueStore, handlers) {
8
8
  this.keyValueStore = keyValueStore;
9
- this.encryption = encryption;
9
+ this.handlers = handlers;
10
10
  }
11
11
  async execute(input) {
12
- const providerPresets = await Promise.all(input.providers.presets.map(async provider => ({
13
- ...provider,
14
- apiKey: await this.encryption.encrypt(provider.apiKey)
15
- })));
16
- const result = await this.keyValueStore.set(AI_POWER_UPS_SETTINGS, {
17
- providers: {
18
- presets: providerPresets
12
+ // Load current raw record.
13
+ const storeResult = await this.keyValueStore.get(AI_POWER_UPS_SETTINGS);
14
+ const raw = storeResult.isOk() && storeResult.value ? storeResult.value : {};
15
+
16
+ // Build current internal shape for the `existing` parameter.
17
+ const existingInternal = {};
18
+ for (const handler of this.handlers) {
19
+ existingInternal[handler.name] = handler.mapFromStorage(raw[handler.name]);
20
+ }
21
+ const newSettings = input;
22
+ const errors = [];
23
+
24
+ // Validate all sections first.
25
+ for (const handler of this.handlers) {
26
+ const parseResult = await handler.inputSchema.safeParseAsync(newSettings[handler.name]);
27
+ if (!parseResult.success) {
28
+ for (const issue of parseResult.error.issues) {
29
+ const fieldPath = [handler.name, ...issue.path.map(String)].join(".");
30
+ errors.push(`${fieldPath}: ${issue.message}`);
31
+ }
19
32
  }
20
- });
21
- if (result.isFail()) {
22
- return Result.fail(new Error(String(result.error)));
23
33
  }
24
- return Result.ok({
25
- providers: {
26
- presets: input.providers.presets
34
+ if (errors.length > 0) {
35
+ return Result.fail(new Error(errors.join("; ")));
36
+ }
37
+
38
+ // Transform all sections to storage shape.
39
+ const persisted = {
40
+ ...raw
41
+ };
42
+ for (const handler of this.handlers) {
43
+ persisted[handler.name] = await handler.mapToStorage(newSettings[handler.name], existingInternal[handler.name]);
44
+ }
45
+
46
+ // Write merged record.
47
+ const writeResult = await this.keyValueStore.set(AI_POWER_UPS_SETTINGS, persisted);
48
+ if (writeResult.isFail()) {
49
+ return Result.fail(new Error(String(writeResult.error)));
50
+ }
51
+
52
+ // Build and return the new internal shape.
53
+ const result = {};
54
+ for (const handler of this.handlers) {
55
+ result[handler.name] = handler.mapFromStorage(persisted[handler.name]);
56
+ }
57
+
58
+ // Preserve unknown sections.
59
+ for (const key of Object.keys(persisted)) {
60
+ if (!(key in result)) {
61
+ result[key] = persisted[key];
27
62
  }
28
- });
63
+ }
64
+ return Result.ok(result);
29
65
  }
30
66
  }
31
67
  export const UpdateSettingsRepositoryImplementation = UpdateSettingsRepository.createImplementation({
32
68
  implementation: UpdateSettingsRepositoryImpl,
33
- dependencies: [KeyValueStore, Encryption]
69
+ dependencies: [KeyValueStore, [AiPowerUpsSettingsGroupHandler, {
70
+ multiple: true
71
+ }]]
34
72
  });
35
73
 
36
74
  //# sourceMappingURL=UpdateSettingsRepository.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Result","KeyValueStore","Encryption","UpdateSettingsRepository","AI_POWER_UPS_SETTINGS","UpdateSettingsRepositoryImpl","constructor","keyValueStore","encryption","execute","input","providerPresets","Promise","all","providers","presets","map","provider","apiKey","encrypt","result","set","isFail","fail","Error","String","error","ok","UpdateSettingsRepositoryImplementation","createImplementation","implementation","dependencies"],"sources":["UpdateSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { Encryption } from \"@webiny/api-core/features/encryption/index.js\";\nimport { UpdateSettingsRepository, type UpdateSettingsInput } from \"./abstractions.js\";\nimport type { AiPowerUpsSettings } from \"~/api/types.js\";\nimport { AI_POWER_UPS_SETTINGS } from \"~/api/constants.js\";\n\nclass UpdateSettingsRepositoryImpl implements UpdateSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private encryption: Encryption.Interface\n ) {}\n\n async execute(input: UpdateSettingsInput): Promise<Result<AiPowerUpsSettings, Error>> {\n const providerPresets = await Promise.all(\n input.providers.presets.map(async provider => ({\n ...provider,\n apiKey: await this.encryption.encrypt(provider.apiKey)\n }))\n );\n\n const result = await this.keyValueStore.set(AI_POWER_UPS_SETTINGS, {\n providers: { presets: providerPresets }\n });\n\n if (result.isFail()) {\n return Result.fail(new Error(String(result.error)));\n }\n\n return Result.ok({\n providers: { presets: input.providers.presets }\n });\n }\n}\n\nexport const UpdateSettingsRepositoryImplementation = UpdateSettingsRepository.createImplementation(\n {\n implementation: UpdateSettingsRepositoryImpl,\n dependencies: [KeyValueStore, Encryption]\n }\n);\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,aAAa,QAAQ,kDAAkD;AAChF,SAASC,UAAU,QAAQ,+CAA+C;AAC1E,SAASC,wBAAwB;AAEjC,SAASC,qBAAqB;AAE9B,MAAMC,4BAA4B,CAA+C;EAC7EC,WAAWA,CACCC,aAAsC,EACtCC,UAAgC,EAC1C;IAAA,KAFUD,aAAsC,GAAtCA,aAAsC;IAAA,KACtCC,UAAgC,GAAhCA,UAAgC;EACzC;EAEH,MAAMC,OAAOA,CAACC,KAA0B,EAA8C;IAClF,MAAMC,eAAe,GAAG,MAAMC,OAAO,CAACC,GAAG,CACrCH,KAAK,CAACI,SAAS,CAACC,OAAO,CAACC,GAAG,CAAC,MAAMC,QAAQ,KAAK;MAC3C,GAAGA,QAAQ;MACXC,MAAM,EAAE,MAAM,IAAI,CAACV,UAAU,CAACW,OAAO,CAACF,QAAQ,CAACC,MAAM;IACzD,CAAC,CAAC,CACN,CAAC;IAED,MAAME,MAAM,GAAG,MAAM,IAAI,CAACb,aAAa,CAACc,GAAG,CAACjB,qBAAqB,EAAE;MAC/DU,SAAS,EAAE;QAAEC,OAAO,EAAEJ;MAAgB;IAC1C,CAAC,CAAC;IAEF,IAAIS,MAAM,CAACE,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOtB,MAAM,CAACuB,IAAI,CAAC,IAAIC,KAAK,CAACC,MAAM,CAACL,MAAM,CAACM,KAAK,CAAC,CAAC,CAAC;IACvD;IAEA,OAAO1B,MAAM,CAAC2B,EAAE,CAAC;MACbb,SAAS,EAAE;QAAEC,OAAO,EAAEL,KAAK,CAACI,SAAS,CAACC;MAAQ;IAClD,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMa,sCAAsC,GAAGzB,wBAAwB,CAAC0B,oBAAoB,CAC/F;EACIC,cAAc,EAAEzB,4BAA4B;EAC5C0B,YAAY,EAAE,CAAC9B,aAAa,EAAEC,UAAU;AAC5C,CACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Result","KeyValueStore","AiPowerUpsSettingsGroupHandler","UpdateSettingsRepository","AI_POWER_UPS_SETTINGS","UpdateSettingsRepositoryImpl","constructor","keyValueStore","handlers","execute","input","storeResult","get","raw","isOk","value","existingInternal","handler","name","mapFromStorage","newSettings","errors","parseResult","inputSchema","safeParseAsync","success","issue","error","issues","fieldPath","path","map","String","join","push","message","length","fail","Error","persisted","mapToStorage","writeResult","set","isFail","result","key","Object","keys","ok","UpdateSettingsRepositoryImplementation","createImplementation","implementation","dependencies","multiple"],"sources":["UpdateSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { AiPowerUpsSettingsGroupHandler } from \"~/api/features/shared/index.js\";\nimport { UpdateSettingsRepository } from \"./abstractions.js\";\nimport type { IAiPowerUpsSettings } from \"~/api/types.js\";\nimport { AI_POWER_UPS_SETTINGS } from \"~/api/constants.js\";\n\nclass UpdateSettingsRepositoryImpl implements UpdateSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private handlers: AiPowerUpsSettingsGroupHandler.Interface[]\n ) {}\n\n async execute(input: IAiPowerUpsSettings): Promise<Result<IAiPowerUpsSettings, Error>> {\n // Load current raw record.\n const storeResult =\n await this.keyValueStore.get<Record<string, unknown>>(AI_POWER_UPS_SETTINGS);\n const raw: Record<string, unknown> =\n storeResult.isOk() && storeResult.value ? storeResult.value : {};\n\n // Build current internal shape for the `existing` parameter.\n const existingInternal: Record<string, unknown> = {};\n for (const handler of this.handlers) {\n existingInternal[handler.name] = handler.mapFromStorage(raw[handler.name]);\n }\n\n const newSettings = input as unknown as Record<string, unknown>;\n const errors: string[] = [];\n\n // Validate all sections first.\n for (const handler of this.handlers) {\n const parseResult = await handler.inputSchema.safeParseAsync(newSettings[handler.name]);\n if (!parseResult.success) {\n for (const issue of parseResult.error.issues) {\n const fieldPath = [handler.name, ...issue.path.map(String)].join(\".\");\n errors.push(`${fieldPath}: ${issue.message}`);\n }\n }\n }\n\n if (errors.length > 0) {\n return Result.fail(new Error(errors.join(\"; \")));\n }\n\n // Transform all sections to storage shape.\n const persisted: Record<string, unknown> = { ...raw };\n for (const handler of this.handlers) {\n persisted[handler.name] = await handler.mapToStorage(\n newSettings[handler.name],\n existingInternal[handler.name]\n );\n }\n\n // Write merged record.\n const writeResult = await this.keyValueStore.set(AI_POWER_UPS_SETTINGS, persisted);\n if (writeResult.isFail()) {\n return Result.fail(new Error(String(writeResult.error)));\n }\n\n // Build and return the new internal shape.\n const result: Record<string, unknown> = {};\n for (const handler of this.handlers) {\n result[handler.name] = handler.mapFromStorage(persisted[handler.name]);\n }\n\n // Preserve unknown sections.\n for (const key of Object.keys(persisted)) {\n if (!(key in result)) {\n result[key] = persisted[key];\n }\n }\n\n return Result.ok(result as unknown as IAiPowerUpsSettings);\n }\n}\n\nexport const UpdateSettingsRepositoryImplementation = UpdateSettingsRepository.createImplementation(\n {\n implementation: UpdateSettingsRepositoryImpl,\n dependencies: [KeyValueStore, [AiPowerUpsSettingsGroupHandler, { multiple: true }]]\n }\n);\n"],"mappings":"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","ignoreList":[]}
@@ -1,12 +1,11 @@
1
1
  import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
2
- import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
3
- import { UpdateSettingsUseCase, UpdateSettingsRepository, type UpdateSettingsInput } from "./abstractions.js";
2
+ import { UpdateSettingsUseCase, UpdateSettingsRepository } from "./abstractions.js";
3
+ import type { IAiPowerUpsSettings } from "../../../api/types.js";
4
4
  declare class UpdateSettingsUseCaseImpl implements UpdateSettingsUseCase.Interface {
5
- private identityContext;
6
5
  private eventPublisher;
7
6
  private repository;
8
- constructor(identityContext: IdentityContext.Interface, eventPublisher: EventPublisher.Interface, repository: UpdateSettingsRepository.Interface);
9
- execute(input: UpdateSettingsInput): UpdateSettingsUseCase.Return;
7
+ constructor(eventPublisher: EventPublisher.Interface, repository: UpdateSettingsRepository.Interface);
8
+ execute(input: IAiPowerUpsSettings): UpdateSettingsUseCase.Return;
10
9
  }
11
10
  export declare const UpdateSettingsUseCaseImplementation: typeof UpdateSettingsUseCaseImpl & {
12
11
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUpdateSettingsUseCase>;
@@ -1,24 +1,12 @@
1
- import { Result } from "@webiny/feature/api";
2
1
  import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
3
- import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
4
2
  import { UpdateSettingsUseCase, UpdateSettingsRepository } from "./abstractions.js";
5
3
  import { AiPowerUpsSettingsBeforeUpdateEvent, AiPowerUpsSettingsAfterUpdateEvent } from "./events.js";
6
- import { updateValidation } from "./validation.js";
7
4
  class UpdateSettingsUseCaseImpl {
8
- constructor(identityContext, eventPublisher, repository) {
9
- this.identityContext = identityContext;
5
+ constructor(eventPublisher, repository) {
10
6
  this.eventPublisher = eventPublisher;
11
7
  this.repository = repository;
12
8
  }
13
9
  async execute(input) {
14
- const permission = await this.identityContext.getPermission("ai-PowerUps");
15
- if (!permission) {
16
- return Result.fail(new Error("Not authorized to manage AI PowerUps settings."));
17
- }
18
- const validation = updateValidation.safeParse(input);
19
- if (!validation.success) {
20
- return Result.fail(new Error(validation.error.issues[0].message));
21
- }
22
10
  await this.eventPublisher.publish(new AiPowerUpsSettingsBeforeUpdateEvent({
23
11
  input
24
12
  }));
@@ -34,7 +22,7 @@ class UpdateSettingsUseCaseImpl {
34
22
  }
35
23
  export const UpdateSettingsUseCaseImplementation = UpdateSettingsUseCase.createImplementation({
36
24
  implementation: UpdateSettingsUseCaseImpl,
37
- dependencies: [IdentityContext, EventPublisher, UpdateSettingsRepository]
25
+ dependencies: [EventPublisher, UpdateSettingsRepository]
38
26
  });
39
27
 
40
28
  //# sourceMappingURL=UpdateSettingsUseCase.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Result","EventPublisher","IdentityContext","UpdateSettingsUseCase","UpdateSettingsRepository","AiPowerUpsSettingsBeforeUpdateEvent","AiPowerUpsSettingsAfterUpdateEvent","updateValidation","UpdateSettingsUseCaseImpl","constructor","identityContext","eventPublisher","repository","execute","input","permission","getPermission","fail","Error","validation","safeParse","success","error","issues","message","publish","result","isFail","settings","value","UpdateSettingsUseCaseImplementation","createImplementation","implementation","dependencies"],"sources":["UpdateSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport {\n UpdateSettingsUseCase,\n UpdateSettingsRepository,\n type UpdateSettingsInput\n} from \"./abstractions.js\";\nimport {\n AiPowerUpsSettingsBeforeUpdateEvent,\n AiPowerUpsSettingsAfterUpdateEvent\n} from \"./events.js\";\nimport { updateValidation } from \"./validation.js\";\n\nclass UpdateSettingsUseCaseImpl implements UpdateSettingsUseCase.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateSettingsRepository.Interface\n ) {}\n\n async execute(input: UpdateSettingsInput): UpdateSettingsUseCase.Return {\n const permission = await this.identityContext.getPermission(\"ai-PowerUps\");\n if (!permission) {\n return Result.fail(new Error(\"Not authorized to manage AI PowerUps settings.\"));\n }\n\n const validation = updateValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new Error(validation.error.issues[0].message));\n }\n\n await this.eventPublisher.publish(new AiPowerUpsSettingsBeforeUpdateEvent({ input }));\n\n const result = await this.repository.execute(input);\n\n if (result.isFail()) {\n return result;\n }\n\n await this.eventPublisher.publish(\n new AiPowerUpsSettingsAfterUpdateEvent({ settings: result.value })\n );\n\n return result;\n }\n}\n\nexport const UpdateSettingsUseCaseImplementation = UpdateSettingsUseCase.createImplementation({\n implementation: UpdateSettingsUseCaseImpl,\n dependencies: [IdentityContext, EventPublisher, UpdateSettingsRepository]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,cAAc,QAAQ,mDAAmD;AAClF,SAASC,eAAe,QAAQ,6DAA6D;AAC7F,SACIC,qBAAqB,EACrBC,wBAAwB;AAG5B,SACIC,mCAAmC,EACnCC,kCAAkC;AAEtC,SAASC,gBAAgB;AAEzB,MAAMC,yBAAyB,CAA4C;EACvEC,WAAWA,CACCC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA8C,EACxD;IAAA,KAHUF,eAA0C,GAA1CA,eAA0C;IAAA,KAC1CC,cAAwC,GAAxCA,cAAwC;IAAA,KACxCC,UAA8C,GAA9CA,UAA8C;EACvD;EAEH,MAAMC,OAAOA,CAACC,KAA0B,EAAgC;IACpE,MAAMC,UAAU,GAAG,MAAM,IAAI,CAACL,eAAe,CAACM,aAAa,CAAC,aAAa,CAAC;IAC1E,IAAI,CAACD,UAAU,EAAE;MACb,OAAOf,MAAM,CAACiB,IAAI,CAAC,IAAIC,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACnF;IAEA,MAAMC,UAAU,GAAGZ,gBAAgB,CAACa,SAAS,CAACN,KAAK,CAAC;IACpD,IAAI,CAACK,UAAU,CAACE,OAAO,EAAE;MACrB,OAAOrB,MAAM,CAACiB,IAAI,CAAC,IAAIC,KAAK,CAACC,UAAU,CAACG,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC;IACrE;IAEA,MAAM,IAAI,CAACb,cAAc,CAACc,OAAO,CAAC,IAAIpB,mCAAmC,CAAC;MAAES;IAAM,CAAC,CAAC,CAAC;IAErF,MAAMY,MAAM,GAAG,MAAM,IAAI,CAACd,UAAU,CAACC,OAAO,CAACC,KAAK,CAAC;IAEnD,IAAIY,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOD,MAAM;IACjB;IAEA,MAAM,IAAI,CAACf,cAAc,CAACc,OAAO,CAC7B,IAAInB,kCAAkC,CAAC;MAAEsB,QAAQ,EAAEF,MAAM,CAACG;IAAM,CAAC,CACrE,CAAC;IAED,OAAOH,MAAM;EACjB;AACJ;AAEA,OAAO,MAAMI,mCAAmC,GAAG3B,qBAAqB,CAAC4B,oBAAoB,CAAC;EAC1FC,cAAc,EAAExB,yBAAyB;EACzCyB,YAAY,EAAE,CAAC/B,eAAe,EAAED,cAAc,EAAEG,wBAAwB;AAC5E,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["EventPublisher","UpdateSettingsUseCase","UpdateSettingsRepository","AiPowerUpsSettingsBeforeUpdateEvent","AiPowerUpsSettingsAfterUpdateEvent","UpdateSettingsUseCaseImpl","constructor","eventPublisher","repository","execute","input","publish","result","isFail","settings","value","UpdateSettingsUseCaseImplementation","createImplementation","implementation","dependencies"],"sources":["UpdateSettingsUseCase.ts"],"sourcesContent":["import { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { UpdateSettingsUseCase, UpdateSettingsRepository } from \"./abstractions.js\";\nimport type { IAiPowerUpsSettings } from \"~/api/types.js\";\nimport {\n AiPowerUpsSettingsBeforeUpdateEvent,\n AiPowerUpsSettingsAfterUpdateEvent\n} from \"./events.js\";\n\nclass UpdateSettingsUseCaseImpl implements UpdateSettingsUseCase.Interface {\n constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateSettingsRepository.Interface\n ) {}\n\n async execute(input: IAiPowerUpsSettings): UpdateSettingsUseCase.Return {\n await this.eventPublisher.publish(new AiPowerUpsSettingsBeforeUpdateEvent({ input }));\n\n const result = await this.repository.execute(input);\n\n if (result.isFail()) {\n return result;\n }\n\n await this.eventPublisher.publish(\n new AiPowerUpsSettingsAfterUpdateEvent({ settings: result.value })\n );\n\n return result;\n }\n}\n\nexport const UpdateSettingsUseCaseImplementation = UpdateSettingsUseCase.createImplementation({\n implementation: UpdateSettingsUseCaseImpl,\n dependencies: [EventPublisher, UpdateSettingsRepository]\n});\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,mDAAmD;AAClF,SAASC,qBAAqB,EAAEC,wBAAwB;AAExD,SACIC,mCAAmC,EACnCC,kCAAkC;AAGtC,MAAMC,yBAAyB,CAA4C;EACvEC,WAAWA,CACCC,cAAwC,EACxCC,UAA8C,EACxD;IAAA,KAFUD,cAAwC,GAAxCA,cAAwC;IAAA,KACxCC,UAA8C,GAA9CA,UAA8C;EACvD;EAEH,MAAMC,OAAOA,CAACC,KAA0B,EAAgC;IACpE,MAAM,IAAI,CAACH,cAAc,CAACI,OAAO,CAAC,IAAIR,mCAAmC,CAAC;MAAEO;IAAM,CAAC,CAAC,CAAC;IAErF,MAAME,MAAM,GAAG,MAAM,IAAI,CAACJ,UAAU,CAACC,OAAO,CAACC,KAAK,CAAC;IAEnD,IAAIE,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;MACjB,OAAOD,MAAM;IACjB;IAEA,MAAM,IAAI,CAACL,cAAc,CAACI,OAAO,CAC7B,IAAIP,kCAAkC,CAAC;MAAEU,QAAQ,EAAEF,MAAM,CAACG;IAAM,CAAC,CACrE,CAAC;IAED,OAAOH,MAAM;EACjB;AACJ;AAEA,OAAO,MAAMI,mCAAmC,GAAGf,qBAAqB,CAACgB,oBAAoB,CAAC;EAC1FC,cAAc,EAAEb,yBAAyB;EACzCc,YAAY,EAAE,CAACnB,cAAc,EAAEE,wBAAwB;AAC3D,CAAC,CAAC","ignoreList":[]}
@@ -1,35 +1,28 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import type { DomainEvent, IEventHandler } from "@webiny/api-core/features/eventPublisher/index.js";
3
- import type { AiProvider, AiPowerUpsSettings } from "../../../api/types.js";
4
- export interface UpdateSettingsInput {
5
- providers: {
6
- presets: Array<Pick<AiProvider, "name" | "model" | "apiKey"> & {
7
- description?: string;
8
- }>;
9
- };
10
- }
3
+ import type { IAiPowerUpsSettings } from "../../../api/types.js";
11
4
  export interface IUpdateSettingsRepository {
12
- execute(input: UpdateSettingsInput): Promise<Result<AiPowerUpsSettings, Error>>;
5
+ execute(input: IAiPowerUpsSettings): Promise<Result<IAiPowerUpsSettings, Error>>;
13
6
  }
14
7
  export declare const UpdateSettingsRepository: import("@webiny/di").Abstraction<IUpdateSettingsRepository>;
15
8
  export declare namespace UpdateSettingsRepository {
16
9
  type Interface = IUpdateSettingsRepository;
17
- type Return = Promise<Result<AiPowerUpsSettings, Error>>;
10
+ type Return = Promise<Result<IAiPowerUpsSettings, Error>>;
18
11
  }
19
12
  export interface IUpdateSettingsUseCase {
20
- execute(input: UpdateSettingsInput): Promise<Result<AiPowerUpsSettings, Error>>;
13
+ execute(input: IAiPowerUpsSettings): Promise<Result<IAiPowerUpsSettings, Error>>;
21
14
  }
22
15
  export declare const UpdateSettingsUseCase: import("@webiny/di").Abstraction<IUpdateSettingsUseCase>;
23
16
  export declare namespace UpdateSettingsUseCase {
24
17
  type Interface = IUpdateSettingsUseCase;
25
- type Return = Promise<Result<AiPowerUpsSettings, Error>>;
26
- type Params = UpdateSettingsInput;
18
+ type Return = Promise<Result<IAiPowerUpsSettings, Error>>;
19
+ type Params = IAiPowerUpsSettings;
27
20
  }
28
21
  export interface AiPowerUpsSettingsBeforeUpdatePayload {
29
- input: UpdateSettingsInput;
22
+ input: IAiPowerUpsSettings;
30
23
  }
31
24
  export interface AiPowerUpsSettingsAfterUpdatePayload {
32
- settings: AiPowerUpsSettings;
25
+ settings: IAiPowerUpsSettings;
33
26
  }
34
27
  export declare const AiPowerUpsSettingsBeforeUpdateEventHandler: import("@webiny/di").Abstraction<IEventHandler<DomainEvent<AiPowerUpsSettingsBeforeUpdatePayload>>>;
35
28
  export declare namespace AiPowerUpsSettingsBeforeUpdateEventHandler {
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","UpdateSettingsRepository","UpdateSettingsUseCase","AiPowerUpsSettingsBeforeUpdateEventHandler","AiPowerUpsSettingsAfterUpdateEventHandler"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { DomainEvent, IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { AiProvider, AiPowerUpsSettings } from \"~/api/types.js\";\n\nexport interface UpdateSettingsInput {\n providers: {\n presets: Array<Pick<AiProvider, \"name\" | \"model\" | \"apiKey\"> & { description?: string }>;\n };\n}\n\nexport interface IUpdateSettingsRepository {\n execute(input: UpdateSettingsInput): Promise<Result<AiPowerUpsSettings, Error>>;\n}\n\nexport const UpdateSettingsRepository = createAbstraction<IUpdateSettingsRepository>(\n \"AiPowerUpsUpdateSettingsRepository\"\n);\n\nexport namespace UpdateSettingsRepository {\n export type Interface = IUpdateSettingsRepository;\n export type Return = Promise<Result<AiPowerUpsSettings, Error>>;\n}\n\nexport interface IUpdateSettingsUseCase {\n execute(input: UpdateSettingsInput): Promise<Result<AiPowerUpsSettings, Error>>;\n}\n\nexport const UpdateSettingsUseCase = createAbstraction<IUpdateSettingsUseCase>(\n \"AiPowerUpsUpdateSettingsUseCase\"\n);\n\nexport namespace UpdateSettingsUseCase {\n export type Interface = IUpdateSettingsUseCase;\n export type Return = Promise<Result<AiPowerUpsSettings, Error>>;\n export type Params = UpdateSettingsInput;\n}\n\n// Domain events\nexport interface AiPowerUpsSettingsBeforeUpdatePayload {\n input: UpdateSettingsInput;\n}\n\nexport interface AiPowerUpsSettingsAfterUpdatePayload {\n settings: AiPowerUpsSettings;\n}\n\nexport const AiPowerUpsSettingsBeforeUpdateEventHandler = createAbstraction<\n IEventHandler<DomainEvent<AiPowerUpsSettingsBeforeUpdatePayload>>\n>(\"AiPowerUpsSettingsBeforeUpdateEventHandler\");\n\nexport namespace AiPowerUpsSettingsBeforeUpdateEventHandler {\n export type Interface = IEventHandler<DomainEvent<AiPowerUpsSettingsBeforeUpdatePayload>>;\n export type Event = DomainEvent<AiPowerUpsSettingsBeforeUpdatePayload>;\n}\n\nexport const AiPowerUpsSettingsAfterUpdateEventHandler = createAbstraction<\n IEventHandler<DomainEvent<AiPowerUpsSettingsAfterUpdatePayload>>\n>(\"AiPowerUpsSettingsAfterUpdateEventHandler\");\n\nexport namespace AiPowerUpsSettingsAfterUpdateEventHandler {\n export type Interface = IEventHandler<DomainEvent<AiPowerUpsSettingsAfterUpdatePayload>>;\n export type Event = DomainEvent<AiPowerUpsSettingsAfterUpdatePayload>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAgB,qBAAqB;AAc/D,OAAO,MAAMC,wBAAwB,GAAGD,iBAAiB,CACrD,oCACJ,CAAC;AAWD,OAAO,MAAME,qBAAqB,GAAGF,iBAAiB,CAClD,iCACJ,CAAC;;AAQD;;AASA,OAAO,MAAMG,0CAA0C,GAAGH,iBAAiB,CAEzE,4CAA4C,CAAC;AAO/C,OAAO,MAAMI,yCAAyC,GAAGJ,iBAAiB,CAExE,2CAA2C,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createAbstraction","UpdateSettingsRepository","UpdateSettingsUseCase","AiPowerUpsSettingsBeforeUpdateEventHandler","AiPowerUpsSettingsAfterUpdateEventHandler"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { DomainEvent, IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { IAiPowerUpsSettings } from \"~/api/types.js\";\n\nexport interface IUpdateSettingsRepository {\n execute(input: IAiPowerUpsSettings): Promise<Result<IAiPowerUpsSettings, Error>>;\n}\n\nexport const UpdateSettingsRepository = createAbstraction<IUpdateSettingsRepository>(\n \"AiPowerUpsUpdateSettingsRepository\"\n);\n\nexport namespace UpdateSettingsRepository {\n export type Interface = IUpdateSettingsRepository;\n export type Return = Promise<Result<IAiPowerUpsSettings, Error>>;\n}\n\nexport interface IUpdateSettingsUseCase {\n execute(input: IAiPowerUpsSettings): Promise<Result<IAiPowerUpsSettings, Error>>;\n}\n\nexport const UpdateSettingsUseCase = createAbstraction<IUpdateSettingsUseCase>(\n \"AiPowerUpsUpdateSettingsUseCase\"\n);\n\nexport namespace UpdateSettingsUseCase {\n export type Interface = IUpdateSettingsUseCase;\n export type Return = Promise<Result<IAiPowerUpsSettings, Error>>;\n export type Params = IAiPowerUpsSettings;\n}\n\n// Domain events\nexport interface AiPowerUpsSettingsBeforeUpdatePayload {\n input: IAiPowerUpsSettings;\n}\n\nexport interface AiPowerUpsSettingsAfterUpdatePayload {\n settings: IAiPowerUpsSettings;\n}\n\nexport const AiPowerUpsSettingsBeforeUpdateEventHandler = createAbstraction<\n IEventHandler<DomainEvent<AiPowerUpsSettingsBeforeUpdatePayload>>\n>(\"AiPowerUpsSettingsBeforeUpdateEventHandler\");\n\nexport namespace AiPowerUpsSettingsBeforeUpdateEventHandler {\n export type Interface = IEventHandler<DomainEvent<AiPowerUpsSettingsBeforeUpdatePayload>>;\n export type Event = DomainEvent<AiPowerUpsSettingsBeforeUpdatePayload>;\n}\n\nexport const AiPowerUpsSettingsAfterUpdateEventHandler = createAbstraction<\n IEventHandler<DomainEvent<AiPowerUpsSettingsAfterUpdatePayload>>\n>(\"AiPowerUpsSettingsAfterUpdateEventHandler\");\n\nexport namespace AiPowerUpsSettingsAfterUpdateEventHandler {\n export type Interface = IEventHandler<DomainEvent<AiPowerUpsSettingsAfterUpdatePayload>>;\n export type Event = DomainEvent<AiPowerUpsSettingsAfterUpdatePayload>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAgB,qBAAqB;AAQ/D,OAAO,MAAMC,wBAAwB,GAAGD,iBAAiB,CACrD,oCACJ,CAAC;AAWD,OAAO,MAAME,qBAAqB,GAAGF,iBAAiB,CAClD,iCACJ,CAAC;;AAQD;;AASA,OAAO,MAAMG,0CAA0C,GAAGH,iBAAiB,CAEzE,4CAA4C,CAAC;AAO/C,OAAO,MAAMI,yCAAyC,GAAGJ,iBAAiB,CAExE,2CAA2C,CAAC","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { Ai } from "@webiny/api-core/features/ai/index.js";
3
3
  import { AiSdkTools } from "@webiny/api-core/features/ai/index.js";
4
+ import { Encryption } from "@webiny/api-core/features/encryption/index.js";
4
5
  import { GetSettingsUseCase } from "../../../api/features/GetSettings/index.js";
5
6
  import { WbGeneratePageContentUseCase } from "./abstractions.js";
6
7
  import type { WbGeneratePageContentParams } from "./abstractions.js";
@@ -8,7 +9,8 @@ declare class WbGeneratePageContentUseCaseImpl implements WbGeneratePageContentU
8
9
  private getSettings;
9
10
  private ai;
10
11
  private aiSdkTools;
11
- constructor(getSettings: GetSettingsUseCase.Interface, ai: Ai.Interface, aiSdkTools: AiSdkTools.Interface);
12
+ private encryption;
13
+ constructor(getSettings: GetSettingsUseCase.Interface, ai: Ai.Interface, aiSdkTools: AiSdkTools.Interface, encryption: Encryption.Interface);
12
14
  execute(params: WbGeneratePageContentParams): Promise<Result<string, Error>>;
13
15
  }
14
16
  export declare const WbGeneratePageContentUseCaseImplementation: typeof WbGeneratePageContentUseCaseImpl & {
@@ -2,6 +2,7 @@ import { stepCountIs } from "ai";
2
2
  import { Result } from "@webiny/feature/api";
3
3
  import { Ai } from "@webiny/api-core/features/ai/index.js";
4
4
  import { AiSdkTools } from "@webiny/api-core/features/ai/index.js";
5
+ import { Encryption } from "@webiny/api-core/features/encryption/index.js";
5
6
  import { GetSettingsUseCase } from "../GetSettings/index.js";
6
7
  import { WbGeneratePageContentUseCase } from "./abstractions.js";
7
8
  import { buildSystemPrompt } from "./buildPrompt.js";
@@ -9,10 +10,11 @@ function stripCodeFence(text) {
9
10
  return text.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
10
11
  }
11
12
  class WbGeneratePageContentUseCaseImpl {
12
- constructor(getSettings, ai, aiSdkTools) {
13
+ constructor(getSettings, ai, aiSdkTools, encryption) {
13
14
  this.getSettings = getSettings;
14
15
  this.ai = ai;
15
16
  this.aiSdkTools = aiSdkTools;
17
+ this.encryption = encryption;
16
18
  }
17
19
  async execute(params) {
18
20
  const settingsResult = await this.getSettings.execute();
@@ -25,6 +27,9 @@ class WbGeneratePageContentUseCaseImpl {
25
27
  return Result.fail(new Error("No AI provider configured. Add a provider in AI Power Ups settings."));
26
28
  }
27
29
 
30
+ // Decrypt at point of use.
31
+ const apiKey = this.encryption.decrypt(firstProvider.apiKeyEncrypted);
32
+
28
33
  // TODO: configure this in `ai` as default behavior.
29
34
  const sdkTools = this.aiSdkTools.getToolSet();
30
35
  const system = buildSystemPrompt(params.components, params.tools);
@@ -33,7 +38,7 @@ class WbGeneratePageContentUseCaseImpl {
33
38
  model: firstProvider.model,
34
39
  connection: {
35
40
  sdkName: firstProvider.model.split("/")[0],
36
- apiKey: firstProvider.apiKey
41
+ apiKey
37
42
  },
38
43
  system,
39
44
  toolChoice: "auto",
@@ -56,7 +61,7 @@ class WbGeneratePageContentUseCaseImpl {
56
61
  }
57
62
  export const WbGeneratePageContentUseCaseImplementation = WbGeneratePageContentUseCase.createImplementation({
58
63
  implementation: WbGeneratePageContentUseCaseImpl,
59
- dependencies: [GetSettingsUseCase, Ai, AiSdkTools]
64
+ dependencies: [GetSettingsUseCase, Ai, AiSdkTools, Encryption]
60
65
  });
61
66
 
62
67
  //# sourceMappingURL=WbGeneratePageContentUseCase.js.map