@webiny/ai-powerups 6.3.0-beta.2 → 6.3.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.js +2 -2
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsDialog.js.map +1 -1
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.js +17 -13
- package/admin/presentation/AiPowerUpsSettings/AiPowerUpsSettingsPresenter.js.map +1 -1
- package/admin/presentation/AiPowerUpsSettings/settingsGroup.d.ts +3 -4
- package/admin/presentation/AiPowerUpsSettings/settingsGroup.js.map +1 -1
- package/admin/presentation/PersonasSettings.js +2 -1
- package/admin/presentation/PersonasSettings.js.map +1 -1
- package/admin/presentation/ProvidersSettings.js +6 -3
- package/admin/presentation/ProvidersSettings.js.map +1 -1
- package/admin/presentation/WbContentGeneration/GenerateContentDialog.js +36 -0
- package/admin/presentation/WbContentGeneration/GenerateContentDialog.js.map +1 -1
- package/api/Extension.js +4 -0
- package/api/Extension.js.map +1 -1
- package/api/features/GetSettings/GetSettingsRepository.d.ts +5 -5
- package/api/features/GetSettings/GetSettingsRepository.js +20 -22
- package/api/features/GetSettings/GetSettingsRepository.js.map +1 -1
- package/api/features/GetSettings/GetSettingsUseCase.d.ts +1 -1
- package/api/features/GetSettings/abstractions.d.ts +3 -3
- package/api/features/GetSettings/abstractions.js.map +1 -1
- package/api/features/Providers/ProvidersGraphQLMapper.d.ts +21 -0
- package/api/features/Providers/ProvidersGraphQLMapper.js +36 -0
- package/api/features/Providers/ProvidersGraphQLMapper.js.map +1 -0
- package/api/features/Providers/ProvidersHandler.d.ts +26 -0
- package/api/features/Providers/ProvidersHandler.js +76 -0
- package/api/features/Providers/ProvidersHandler.js.map +1 -0
- package/api/features/Providers/feature.d.ts +4 -0
- package/api/features/Providers/feature.js +12 -0
- package/api/features/Providers/feature.js.map +1 -0
- package/api/features/Providers/index.d.ts +1 -0
- package/api/features/Providers/index.js +3 -0
- package/api/features/Providers/index.js.map +1 -0
- package/api/features/Providers/types.d.ts +29 -0
- package/api/features/Providers/types.js +3 -0
- package/api/features/Providers/types.js.map +1 -0
- package/api/features/UpdateSettings/UpdateSettingsRepository.d.ts +6 -6
- package/api/features/UpdateSettings/UpdateSettingsRepository.js +56 -18
- package/api/features/UpdateSettings/UpdateSettingsRepository.js.map +1 -1
- package/api/features/UpdateSettings/UpdateSettingsUseCase.d.ts +4 -5
- package/api/features/UpdateSettings/UpdateSettingsUseCase.js +2 -14
- package/api/features/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
- package/api/features/UpdateSettings/abstractions.d.ts +8 -15
- package/api/features/UpdateSettings/abstractions.js.map +1 -1
- package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.d.ts +3 -1
- package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.js +8 -3
- package/api/features/WbGeneratePageContent/WbGeneratePageContentUseCase.js.map +1 -1
- package/api/features/shared/abstractions.d.ts +20 -0
- package/api/features/shared/abstractions.js +5 -0
- package/api/features/shared/abstractions.js.map +1 -0
- package/api/features/shared/index.d.ts +1 -0
- package/api/features/shared/index.js +3 -0
- package/api/features/shared/index.js.map +1 -0
- package/api/graphql/AiPowerUpsSettingsGraphQLMapper.d.ts +13 -0
- package/api/graphql/AiPowerUpsSettingsGraphQLMapper.js +35 -0
- package/api/graphql/AiPowerUpsSettingsGraphQLMapper.js.map +1 -0
- package/api/graphql/BaseGraphQLSchema.d.ts +1 -1
- package/api/graphql/BaseGraphQLSchema.js +15 -9
- package/api/graphql/BaseGraphQLSchema.js.map +1 -1
- package/api/graphql/abstractions.d.ts +9 -0
- package/api/graphql/abstractions.js +4 -0
- package/api/graphql/abstractions.js.map +1 -0
- package/api/types.d.ts +2 -10
- package/api/types.js +3 -0
- package/api/types.js.map +1 -1
- package/package.json +26 -23
- package/api/features/UpdateSettings/validation.d.ts +0 -11
- package/api/features/UpdateSettings/validation.js +0 -16
- package/api/features/UpdateSettings/validation.js.map +0 -1
|
@@ -31,13 +31,13 @@ export const AiPowerUpsSettingsDialog = observer(() => {
|
|
|
31
31
|
onClose: closeDialog,
|
|
32
32
|
title: "AI Power-Ups",
|
|
33
33
|
size: "xl",
|
|
34
|
-
className: "w-[1000px]",
|
|
34
|
+
className: "w-[1000px] min-h-1/2",
|
|
35
35
|
actions: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dialog.CancelAction, {
|
|
36
36
|
onClick: closeDialog,
|
|
37
37
|
text: "Cancel"
|
|
38
38
|
}), /*#__PURE__*/React.createElement(Dialog.ConfirmAction, {
|
|
39
39
|
onClick: handleSave,
|
|
40
|
-
text: "Save"
|
|
40
|
+
text: "Save Settings"
|
|
41
41
|
}))
|
|
42
42
|
}, vm.loading || vm.saving ? /*#__PURE__*/React.createElement(OverlayLoader, {
|
|
43
43
|
text: vm.saving ? "Saving..." : "Loading..."
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useEffect","observer","useDialog","FormView","Dialog","OverlayLoader","useToast","useFeature","AiPowerUpsSettingsFeature","AI_POWER_UPS_SETTINGS_DIALOG","AiPowerUpsSettingsDialog","closeDialog","toast","presenter","vm","init","handleSave","success","save","showSuccessToast","title","createElement","open","onClose","size","className","actions","Fragment","CancelAction","onClick","text","ConfirmAction","loading","saving","error","form","errors","length","map","err","i","key","label","message"],"sources":["AiPowerUpsSettingsDialog.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useDialog, FormView } from \"@webiny/app-admin\";\nimport { Dialog, OverlayLoader, useToast } from \"@webiny/admin-ui\";\nimport { useFeature } from \"@webiny/app\";\nimport { AiPowerUpsSettingsFeature } from \"./feature.js\";\n\nexport const AI_POWER_UPS_SETTINGS_DIALOG = \"ai-power-ups-settings\";\n\nexport const AiPowerUpsSettingsDialog = observer(() => {\n const { closeDialog } = useDialog();\n const toast = useToast();\n const { presenter } = useFeature(AiPowerUpsSettingsFeature);\n const vm = presenter.vm;\n\n useEffect(() => {\n presenter.init();\n }, []);\n\n const handleSave = async () => {\n const success = await presenter.save();\n if (success) {\n toast.showSuccessToast({\n title: \"AI power-ups settings saved successfully!\"\n });\n closeDialog();\n }\n };\n\n return (\n <Dialog\n open={true}\n onClose={closeDialog}\n title=\"AI Power-Ups\"\n size={\"xl\"}\n className={\"w-[1000px]\"}\n actions={\n <>\n <Dialog.CancelAction onClick={closeDialog} text=\"Cancel\" />\n <Dialog.ConfirmAction onClick={handleSave} text=\"Save\" />\n </>\n }\n >\n {vm.loading || vm.saving ? (\n <OverlayLoader text={vm.saving ? \"Saving...\" : \"Loading...\"} />\n ) : null}\n {vm.error ? (\n <div className=\"text-destructive-default text-sm mb-4\">{vm.error}</div>\n ) : null}\n {vm.form && vm.form.errors.length > 0 ? (\n <div className=\"flex flex-col gap-1 mb-4\">\n {vm.form.errors.map((err, i) => (\n <div key={i} className=\"text-destructive-default text-sm\">\n {err.label ? `${err.label}: ${err.message}` : err.message}\n </div>\n ))}\n </div>\n ) : null}\n <div className=\"flex flex-col gap-4\">\n {vm.form ? <FormView form={vm.form} /> : null}\n </div>\n </Dialog>\n );\n});\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,mBAAmB;AACvD,SAASC,MAAM,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,kBAAkB;AAClE,SAASC,UAAU,QAAQ,aAAa;AACxC,SAASC,yBAAyB;AAElC,OAAO,MAAMC,4BAA4B,GAAG,uBAAuB;AAEnE,OAAO,MAAMC,wBAAwB,GAAGT,QAAQ,CAAC,MAAM;EACnD,MAAM;IAAEU;EAAY,CAAC,GAAGT,SAAS,CAAC,CAAC;EACnC,MAAMU,KAAK,GAAGN,QAAQ,CAAC,CAAC;EACxB,MAAM;IAAEO;EAAU,CAAC,GAAGN,UAAU,CAACC,yBAAyB,CAAC;EAC3D,MAAMM,EAAE,GAAGD,SAAS,CAACC,EAAE;EAEvBd,SAAS,CAAC,MAAM;IACZa,SAAS,CAACE,IAAI,CAAC,CAAC;EACpB,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMC,UAAU,GAAG,MAAAA,CAAA,KAAY;IAC3B,MAAMC,OAAO,GAAG,MAAMJ,SAAS,CAACK,IAAI,CAAC,CAAC;IACtC,IAAID,OAAO,EAAE;MACTL,KAAK,CAACO,gBAAgB,CAAC;QACnBC,KAAK,EAAE;MACX,CAAC,CAAC;MACFT,WAAW,CAAC,CAAC;IACjB;EACJ,CAAC;EAED,oBACIZ,KAAA,CAAAsB,aAAA,CAACjB,MAAM;IACHkB,IAAI,EAAE,IAAK;IACXC,OAAO,EAAEZ,WAAY;IACrBS,KAAK,EAAC,cAAc;IACpBI,IAAI,EAAE,IAAK;IACXC,SAAS,EAAE,
|
|
1
|
+
{"version":3,"names":["React","useEffect","observer","useDialog","FormView","Dialog","OverlayLoader","useToast","useFeature","AiPowerUpsSettingsFeature","AI_POWER_UPS_SETTINGS_DIALOG","AiPowerUpsSettingsDialog","closeDialog","toast","presenter","vm","init","handleSave","success","save","showSuccessToast","title","createElement","open","onClose","size","className","actions","Fragment","CancelAction","onClick","text","ConfirmAction","loading","saving","error","form","errors","length","map","err","i","key","label","message"],"sources":["AiPowerUpsSettingsDialog.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useDialog, FormView } from \"@webiny/app-admin\";\nimport { Dialog, OverlayLoader, useToast } from \"@webiny/admin-ui\";\nimport { useFeature } from \"@webiny/app\";\nimport { AiPowerUpsSettingsFeature } from \"./feature.js\";\n\nexport const AI_POWER_UPS_SETTINGS_DIALOG = \"ai-power-ups-settings\";\n\nexport const AiPowerUpsSettingsDialog = observer(() => {\n const { closeDialog } = useDialog();\n const toast = useToast();\n const { presenter } = useFeature(AiPowerUpsSettingsFeature);\n const vm = presenter.vm;\n\n useEffect(() => {\n presenter.init();\n }, []);\n\n const handleSave = async () => {\n const success = await presenter.save();\n if (success) {\n toast.showSuccessToast({\n title: \"AI power-ups settings saved successfully!\"\n });\n closeDialog();\n }\n };\n\n return (\n <Dialog\n open={true}\n onClose={closeDialog}\n title=\"AI Power-Ups\"\n size={\"xl\"}\n className={\"w-[1000px] min-h-1/2\"}\n actions={\n <>\n <Dialog.CancelAction onClick={closeDialog} text=\"Cancel\" />\n <Dialog.ConfirmAction onClick={handleSave} text=\"Save Settings\" />\n </>\n }\n >\n {vm.loading || vm.saving ? (\n <OverlayLoader text={vm.saving ? \"Saving...\" : \"Loading...\"} />\n ) : null}\n {vm.error ? (\n <div className=\"text-destructive-default text-sm mb-4\">{vm.error}</div>\n ) : null}\n {vm.form && vm.form.errors.length > 0 ? (\n <div className=\"flex flex-col gap-1 mb-4\">\n {vm.form.errors.map((err, i) => (\n <div key={i} className=\"text-destructive-default text-sm\">\n {err.label ? `${err.label}: ${err.message}` : err.message}\n </div>\n ))}\n </div>\n ) : null}\n <div className=\"flex flex-col gap-4\">\n {vm.form ? <FormView form={vm.form} /> : null}\n </div>\n </Dialog>\n );\n});\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,mBAAmB;AACvD,SAASC,MAAM,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,kBAAkB;AAClE,SAASC,UAAU,QAAQ,aAAa;AACxC,SAASC,yBAAyB;AAElC,OAAO,MAAMC,4BAA4B,GAAG,uBAAuB;AAEnE,OAAO,MAAMC,wBAAwB,GAAGT,QAAQ,CAAC,MAAM;EACnD,MAAM;IAAEU;EAAY,CAAC,GAAGT,SAAS,CAAC,CAAC;EACnC,MAAMU,KAAK,GAAGN,QAAQ,CAAC,CAAC;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,CAAC,GACvE,IAAI,EACPpB,EAAE,CAACqB,IAAI,IAAIrB,EAAE,CAACqB,IAAI,CAACC,MAAM,CAACC,MAAM,GAAG,CAAC,gBACjCtC,KAAA,CAAAsB,aAAA;IAAKI,SAAS,EAAC;EAA0B,GACpCX,EAAE,CAACqB,IAAI,CAACC,MAAM,CAACE,GAAG,CAAC,CAACC,GAAG,EAAEC,CAAC,kBACvBzC,KAAA,CAAAsB,aAAA;IAAKoB,GAAG,EAAED,CAAE;IAACf,SAAS,EAAC;EAAkC,GACpDc,GAAG,CAACG,KAAK,GAAG,GAAGH,GAAG,CAACG,KAAK,KAAKH,GAAG,CAACI,OAAO,EAAE,GAAGJ,GAAG,CAACI,OACjD,CACR,CACA,CAAC,GACN,IAAI,eACR5C,KAAA,CAAAsB,aAAA;IAAKI,SAAS,EAAC;EAAqB,GAC/BX,EAAE,CAACqB,IAAI,gBAAGpC,KAAA,CAAAsB,aAAA,CAAClB,QAAQ;IAACgC,IAAI,EAAErB,EAAE,CAACqB;EAAK,CAAE,CAAC,GAAG,IACxC,CACD,CAAC;AAEjB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -55,6 +55,7 @@ class AiPowerUpsSettingsPresenterImpl {
|
|
|
55
55
|
if (!data) {
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
|
+
console.log("form data", data);
|
|
58
59
|
runInAction(() => {
|
|
59
60
|
this.saving = true;
|
|
60
61
|
this.error = null;
|
|
@@ -113,19 +114,22 @@ class AiPowerUpsSettingsPresenterImpl {
|
|
|
113
114
|
if (collected.length === 0) {
|
|
114
115
|
return [];
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
const tabsBuilder = layout.tabs("settings-tabs").renderer("tabsVertical");
|
|
118
|
+
for (const {
|
|
119
|
+
group
|
|
120
|
+
} of collected) {
|
|
121
|
+
tabsBuilder.tab(group.name, tab => {
|
|
122
|
+
tab.label(group.label);
|
|
123
|
+
if (group.description) {
|
|
124
|
+
tab.description(group.description);
|
|
125
|
+
}
|
|
126
|
+
if (group.icon) {
|
|
127
|
+
tab.icon(group.icon);
|
|
128
|
+
}
|
|
129
|
+
tab.layout(l => [l.row(group.name)]);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return [tabsBuilder];
|
|
129
133
|
}
|
|
130
134
|
});
|
|
131
135
|
}
|
|
@@ -1 +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 { IAiPowerUpsSettings } 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<IAiPowerUpsSettings> | 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<IAiPowerUpsSettings>();\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<IAiPowerUpsSettings>({\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":"AAAA,SAASA,kBAAkB,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,MAAM;AAChE,SAASC,gBAAgB,QAAmB,mBAAmB;AAE/D,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAC9B,SAASC,2BAA2B,IAAIC,oBAAoB;AAC5D,SAASC,uBAAuB;AAehC,MAAMC,+BAA+B,CAA2C;EACpEC,OAAO,GAAG,KAAK;EACfC,MAAM,GAAG,KAAK;EACdC,IAAI,GAAoD,IAAI;EAC5DC,KAAK,GAAkB,IAAI;EAEnCC,WAAWA,CACCC,OAAmC,EACnCC,MAA2C,EAC3CC,WAAyC,EACzCC,cAA+C,EACzD;IAAA,KAJUH,OAAmC,GAAnCA,OAAmC;IAAA,KACnCC,MAA2C,GAA3CA,MAA2C;IAAA,KAC3CC,WAAyC,GAAzCA,WAAyC;IAAA,KACzCC,cAA+C,GAA/CA,cAA+C;IAEvDlB,kBAAkB,CAAC,I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;UAAEE;QAAS,CAAC,IAAID,SAAS,EAAE;UACzC,IAAI,CAACC,QAAQ,EAAE;YACX;UACJ;UACAO,MAAM,CAACT,KAAK,CAACU,IAAI,CAAC,GAAGL,MAAM,CACtBM,MAAM,CAAC,CAAC,CACRC,KAAK,CAACZ,KAAK,CAACY,KAAK,CAAC,CAClBC,QAAQ,CAAC,aAAa,CAAC,CACvBR,MAAM,CAACH,QAAQ,CAAC;QACzB;QACA,OAAOO,MAAM;MACjB,CAAC;MACDF,MAAM,EAAEA,MAAM,IAAI;QACd,IAAIN,SAAS,CAACa,MAAM,KAAK,CAAC,EAAE;UACxB,OAAO,EAAE;QACb;QAEA,OAAO,CACHP,MAAM,CAACQ,IAAI,CAAC;UACRC,EAAE,EAAE,eAAe;UACnBH,QAAQ,EAAE,eAAe;UACzBE,IAAI,EAAEd,SAAS,CAACF,GAAG,CAAC,CAAC;YAAEC;UAAM,CAAC,MAAM;YAChCgB,EAAE,EAAEhB,KAAK,CAACU,IAAI;YACdE,KAAK,EAAEZ,KAAK,CAACY,KAAK;YAClBK,WAAW,EAAEjB,KAAK,CAACiB,WAAW;YAC9BC,IAAI,EAAElB,KAAK,CAACkB,IAAI;YAChBX,MAAM,EAAE,CAACA,MAAM,CAACY,GAAG,CAACnB,KAAK,CAACU,IAAI,CAAC;UACnC,CAAC,CAAC;QACN,CAAC,CAAC,CACL;MACL;IACJ,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMvC,2BAA2B,GAAGC,oBAAoB,CAACgD,oBAAoB,CAAC;EACjFC,cAAc,EAAE/C,+BAA+B;EAC/CgD,YAAY,EAAE,CACVtD,gBAAgB,EAChB,CAACK,uBAAuB,EAAE;IAAEkD,QAAQ,EAAE;EAAK,CAAC,CAAC,EAC7CtD,kBAAkB,EAClBC,qBAAqB;AAE7B,CAAC,CAAC","ignoreList":[]}
|
|
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","tabsBuilder","tabs","tab","description","icon","l","row","createImplementation","implementation","dependencies","multiple"],"sources":["AiPowerUpsSettingsPresenter.ts"],"sourcesContent":["import { makeAutoObservable, computed, runInAction } from \"mobx\";\nimport { FormModelFactory, FormModel } from \"@webiny/app-admin\";\nimport type { ILayoutNodeBuilder } 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 { IAiPowerUpsSettings } 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) => ILayoutNodeBuilder[];\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<IAiPowerUpsSettings> | 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<IAiPowerUpsSettings>();\n if (!data) {\n return false;\n }\n\n console.log(\"form data\", data);\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<IAiPowerUpsSettings>({\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 const tabsBuilder = layout.tabs(\"settings-tabs\").renderer(\"tabsVertical\");\n\n for (const { group } of collected) {\n tabsBuilder.tab(group.name, tab => {\n tab.label(group.label);\n if (group.description) {\n tab.description(group.description);\n }\n if (group.icon) {\n tab.icon(group.icon);\n }\n tab.layout(l => [l.row(group.name)]);\n });\n }\n\n return [tabsBuilder];\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":"AAAA,SAASA,kBAAkB,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,MAAM;AAChE,SAASC,gBAAgB,QAAmB,mBAAmB;AAE/D,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAC9B,SAASC,2BAA2B,IAAIC,oBAAoB;AAC5D,SAASC,uBAAuB;AAehC,MAAMC,+BAA+B,CAA2C;EACpEC,OAAO,GAAG,KAAK;EACfC,MAAM,GAAG,KAAK;EACdC,IAAI,GAAoD,IAAI;EAC5DC,KAAK,GAAkB,IAAI;EAEnCC,WAAWA,CACCC,OAAmC,EACnCC,MAA2C,EAC3CC,WAAyC,EACzCC,cAA+C,EACzD;IAAA,KAJUH,OAAmC,GAAnCA,OAAmC;IAAA,KACnCC,MAA2C,GAA3CA,MAA2C;IAAA,KAC3CC,WAAyC,GAAzCA,WAAyC;IAAA,KACzCC,cAA+C,GAA/CA,cAA+C;IAEvDlB,kBAAkB,CAAC,IAAI,EAAE;MAAEmB,EAAE,EAAElB;IAAS,CAAC,EAAE;MAAEmB,QAAQ,EAAE;IAAK,CAAC,CAAC;EAClE;EAEA,IAAID,EAAEA,CAAA,EAAmC;IACrC,OAAO;MACHT,OAAO,EAAE,IAAI,CAACA,OAAO;MACrBC,MAAM,EAAE,IAAI,CAACA,MAAM;MACnBC,IAAI,EAAE,IAAI,CAACA,IAAI,GAAG,IAAI,CAACA,IAAI,CAACO,EAAE,GAAG,IAAI;MACrCN,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC;EAC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,MAAM;MACjB,CAAC;MACDF,MAAM,EAAEA,MAAM,IAAI;QACd,IAAIN,SAAS,CAACa,MAAM,KAAK,CAAC,EAAE;UACxB,OAAO,EAAE;QACb;QAEA,MAAMC,WAAW,GAAGR,MAAM,CAACS,IAAI,CAAC,eAAe,CAAC,CAACH,QAAQ,CAAC,cAAc,CAAC;QAEzE,KAAK,MAAM;UAAEb;QAAM,CAAC,IAAIC,SAAS,EAAE;UAC/Bc,WAAW,CAACE,GAAG,CAACjB,KAAK,CAACU,IAAI,EAAEO,GAAG,IAAI;YAC/BA,GAAG,CAACL,KAAK,CAACZ,KAAK,CAACY,KAAK,CAAC;YACtB,IAAIZ,KAAK,CAACkB,WAAW,EAAE;cACnBD,GAAG,CAACC,WAAW,CAAClB,KAAK,CAACkB,WAAW,CAAC;YACtC;YACA,IAAIlB,KAAK,CAACmB,IAAI,EAAE;cACZF,GAAG,CAACE,IAAI,CAACnB,KAAK,CAACmB,IAAI,CAAC;YACxB;YACAF,GAAG,CAACV,MAAM,CAACa,CAAC,IAAI,CAACA,CAAC,CAACC,GAAG,CAACrB,KAAK,CAACU,IAAI,CAAC,CAAC,CAAC;UACxC,CAAC,CAAC;QACN;QAEA,OAAO,CAACK,WAAW,CAAC;MACxB;IACJ,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAM5C,2BAA2B,GAAGC,oBAAoB,CAACkD,oBAAoB,CAAC;EACjFC,cAAc,EAAEjD,+BAA+B;EAC/CkD,YAAY,EAAE,CACVxD,gBAAgB,EAChB,CAACK,uBAAuB,EAAE;IAAEoD,QAAQ,EAAE;EAAK,CAAC,CAAC,EAC7CxD,kBAAkB,EAClBC,qBAAqB;AAE7B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { FormModelFactory } from "@webiny/app-admin";
|
|
2
|
-
import type { LayoutNode } from "@webiny/app-admin/features/formModel/abstractions.js";
|
|
1
|
+
import { FormModelFactory, FormModel, Icon } from "@webiny/app-admin";
|
|
3
2
|
export interface IAiPowerUpsSettingsGroupFormBuilder {
|
|
4
3
|
fields(fn: (fields: FormModelFactory.FieldBuilderRegistry) => Record<string, FormModelFactory.FieldBuilder>): void;
|
|
5
|
-
layout(fn: (layout: FormModelFactory.LayoutBuilder) =>
|
|
4
|
+
layout(fn: (layout: FormModelFactory.LayoutBuilder) => FormModel.LayoutNodeBuilder[]): void;
|
|
6
5
|
}
|
|
7
6
|
export interface IAiPowerUpsSettingsGroup {
|
|
8
7
|
name: string;
|
|
9
8
|
label: string;
|
|
10
9
|
description?: string;
|
|
11
|
-
icon?:
|
|
10
|
+
icon?: Icon;
|
|
12
11
|
buildForm(formBuilder: IAiPowerUpsSettingsGroupFormBuilder): void;
|
|
13
12
|
}
|
|
14
13
|
export declare const AiPowerUpsSettingsGroup: import("@webiny/di").Abstraction<IAiPowerUpsSettingsGroup>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createAbstraction","AiPowerUpsSettingsGroup"],"sources":["settingsGroup.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport { FormModelFactory
|
|
1
|
+
{"version":3,"names":["createAbstraction","AiPowerUpsSettingsGroup"],"sources":["settingsGroup.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport { FormModelFactory, FormModel, Icon } from \"@webiny/app-admin\";\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) => FormModel.LayoutNodeBuilder[]): void;\n}\n\nexport interface IAiPowerUpsSettingsGroup {\n name: string;\n label: string;\n description?: string;\n icon?: Icon;\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;AAoBzD,OAAO,MAAMC,uBAAuB,GAAGD,iBAAiB,CACpD,0BACJ,CAAC","ignoreList":[]}
|
|
@@ -6,7 +6,8 @@ class PersonasSettingsImpl {
|
|
|
6
6
|
description = "Configure personas for content generation.";
|
|
7
7
|
buildForm(form) {
|
|
8
8
|
form.fields(fields => ({
|
|
9
|
-
presets: fields.object().renderer("
|
|
9
|
+
presets: fields.object().renderer("objectAccordionMultiple", {
|
|
10
|
+
container: false,
|
|
10
11
|
addItemLabel: "Add persona",
|
|
11
12
|
itemTitle: (data, index) => String(data.name || `Persona #${index + 1}`)
|
|
12
13
|
}).fields(f => ({
|
|
@@ -1 +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(\"
|
|
1
|
+
{"version":3,"names":["generateAlphaNumericId","AiPowerUpsSettingsGroup","PersonasSettingsImpl","name","label","description","buildForm","form","fields","presets","object","renderer","container","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(\"objectAccordionMultiple\", {\n container: false,\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,yBAAyB,EAAE;QACjCC,SAAS,EAAE,KAAK;QAChBC,YAAY,EAAE,aAAa;QAC3BC,SAAS,EAAEA,CAACC,IAAI,EAAEC,KAAK,KAAKC,MAAM,CAACF,IAAI,CAACZ,IAAI,IAAI,YAAYa,KAAK,GAAG,CAAC,EAAE;MAC3E,CAAC,CAAC,CACDR,MAAM,CAACU,CAAC,KAAK;QACVC,EAAE,EAAED,CAAC,CACAE,IAAI,CAAC,CAAC,CACNC,MAAM,CAAC,CAAC,CACRC,YAAY,CAAC,MAAMtB,sBAAsB,CAAC,EAAE,CAAC,CAAC;QACnDG,IAAI,EAAEe,CAAC,CACFE,IAAI,CAAC,CAAC,CACNhB,KAAK,CAAC,MAAM,CAAC,CACbmB,QAAQ,CAAC,kBAAkB,CAAC,CAC5BlB,WAAW,CAAC,2DAA2D,CAAC;QAC7EA,WAAW,EAAEa,CAAC,CACTE,IAAI,CAAC,CAAC,CACNhB,KAAK,CAAC,aAAa,CAAC,CACpBmB,QAAQ,CAAC,yBAAyB,CAAC,CACnClB,WAAW,CAAC,qDAAqD,CAAC,CAClEM,QAAQ,CAAC,UAAU,EAAE;UAAEa,IAAI,EAAE;QAAE,CAAC;MACzC,CAAC,CAAC,CAAC,CACFC,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEHlB,IAAI,CAACmB,MAAM,CAACA,MAAM,IAAI,CAACA,MAAM,CAACC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;EACnD;AACJ;AAEA,OAAO,MAAMC,gBAAgB,GAAG3B,uBAAuB,CAAC4B,oBAAoB,CAAC;EACzEC,cAAc,EAAE5B,oBAAoB;EACpC6B,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { generateAlphaNumericId } from "@webiny/utils";
|
|
1
2
|
import { AiPowerUpsSettingsGroup } from "./AiPowerUpsSettings/settingsGroup.js";
|
|
2
3
|
import { ListModelsUseCase, ListModelsRepository } from "../features/listModels/abstractions.js";
|
|
3
4
|
class ProviderSettingsImpl {
|
|
@@ -11,12 +12,14 @@ class ProviderSettingsImpl {
|
|
|
11
12
|
buildForm(form) {
|
|
12
13
|
void this.useCase.execute();
|
|
13
14
|
form.fields(fields => ({
|
|
14
|
-
presets: fields.object().renderer("
|
|
15
|
+
presets: fields.object().renderer("objectAccordionMultiple", {
|
|
16
|
+
container: false,
|
|
15
17
|
addItemLabel: "Add provider",
|
|
16
|
-
itemTitle: (data, index) => String(data.name || `
|
|
18
|
+
itemTitle: (data, index) => String(data.name || `Provider #${index + 1}`)
|
|
17
19
|
}).fields(f => ({
|
|
20
|
+
id: f.text().hidden().defaultValue(() => generateAlphaNumericId(10)),
|
|
18
21
|
name: f.text().label("Name").required("Name is required"),
|
|
19
|
-
model: f.
|
|
22
|
+
model: f.text().label("Model").required("Model is required").options(() => this.getModelOptions()),
|
|
20
23
|
apiKey: f.text().label("API Key").required("API Key is required")
|
|
21
24
|
})).list()
|
|
22
25
|
}));
|
|
@@ -1 +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","
|
|
1
|
+
{"version":3,"names":["generateAlphaNumericId","AiPowerUpsSettingsGroup","ListModelsUseCase","ListModelsRepository","ProviderSettingsImpl","name","label","description","constructor","useCase","repository","buildForm","form","execute","fields","presets","object","renderer","container","addItemLabel","itemTitle","data","index","String","f","id","text","hidden","defaultValue","required","model","options","getModelOptions","apiKey","list","layout","row","getModels","map","modelName","modelId","value","providerId","ProviderSettings","createImplementation","implementation","dependencies"],"sources":["ProvidersSettings.ts"],"sourcesContent":["import { generateAlphaNumericId } from \"@webiny/utils\";\nimport { 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(\"objectAccordionMultiple\", {\n container: false,\n addItemLabel: \"Add provider\",\n itemTitle: (data, index) => String(data.name || `Provider #${index + 1}`)\n })\n .fields(f => ({\n id: f\n .text()\n .hidden()\n .defaultValue(() => generateAlphaNumericId(10)),\n name: f.text().label(\"Name\").required(\"Name is required\"),\n model: f\n .text()\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,sBAAsB,QAAQ,eAAe;AACtD,SAASC,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,yBAAyB,EAAE;QACjCC,SAAS,EAAE,KAAK;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AAgB,GAAG1C,uBAAuB,CAAC2C,oBAAoB,CAAC;EACzEC,cAAc,EAAEzC,oBAAoB;EACpC0C,YAAY,EAAE,CAAC5C,iBAAiB,EAAEC,oBAAoB;AAC1D,CAAC,CAAC","ignoreList":[]}
|
|
@@ -62,6 +62,39 @@ export const GenerateContentDialog = observer(() => {
|
|
|
62
62
|
errorSubscription.off();
|
|
63
63
|
};
|
|
64
64
|
}, []);
|
|
65
|
+
const submitHtml = () => {
|
|
66
|
+
presenter.processAiResponse(JSON.stringify([{
|
|
67
|
+
component: "Webiny/Lexical",
|
|
68
|
+
inputs: {
|
|
69
|
+
content: {
|
|
70
|
+
tool: "textToLexical",
|
|
71
|
+
params: {
|
|
72
|
+
text: "<h1>Song of the Living Earth</h1><p>The morning opens gently, and the world begins to sing. From forest shadows to rolling tides, nature carries a melody that feels both timeless and new. This song celebrates the quiet power of the wild, where every breeze, birdcall, and wave becomes part of a larger harmony.</p><h2>Verse One: Dawn in the Forest</h2><p>The sun wakes softly through the pine,</p><p>And gold spills down the cedar line.</p><p>The brook hums low beneath the trees,</p><p>A silver thread in morning breeze.</p>"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
component: "Webiny/Lexical",
|
|
78
|
+
inputs: {
|
|
79
|
+
content: {
|
|
80
|
+
tool: "textToLexical",
|
|
81
|
+
params: {
|
|
82
|
+
text: "<h2>Verse Two: The River’s Journey</h2><p>The river travels, clear and bold,</p><p>Through stone and root and fields of gold.</p><p>It teaches hearts to move, to flow,</p><p>To leave the banks and still grow whole.</p><h3>Chorus</h3><p>Oh, nature sings in every leaf,</p><p>In winds of joy and rains of grief.</p><p>We listen close, we learn, we stay,</p><p>And find our rhythm in its sway.</p><p>Like mountains holding up the sky,</p><p>And eagles carving paths to fly,</p><p>The earth reminds us, calm and free,</p><p>That life is meant for harmony.</p>"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
component: "Webiny/Lexical",
|
|
88
|
+
inputs: {
|
|
89
|
+
content: {
|
|
90
|
+
tool: "textToLexical",
|
|
91
|
+
params: {
|
|
92
|
+
text: "<h2>Verse Three: Evening Wildflowers</h2><p>When daylight fades to amber sky,</p><p>The meadow blooms before goodbye.</p><p>The crickets tune the final part,</p><p>And dusk grows tender in the heart.</p><p>So let us walk with gentle feet,</p><p>And keep the wild, and keep it sweet.</p><p>For every branch, each shore, each stream,</p><p>Is nature’s voice inside the dream.</p><p><strong>Final refrain:</strong> Oh, nature sings in every leaf, in winds of joy and rains of grief. We listen close, we learn, we stay, and find our rhythm in its sway.</p><p><em>Let the earth be your song, and the song be your home.</em></p>"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}]));
|
|
97
|
+
};
|
|
65
98
|
useEffect(() => {
|
|
66
99
|
if (wasSubmitting.current && !vm.submitting) {
|
|
67
100
|
closeDialog();
|
|
@@ -81,6 +114,9 @@ export const GenerateContentDialog = observer(() => {
|
|
|
81
114
|
actions: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dialog.CancelAction, {
|
|
82
115
|
onClick: closeDialog,
|
|
83
116
|
text: "Cancel"
|
|
117
|
+
}), /*#__PURE__*/React.createElement(Dialog.ConfirmAction, {
|
|
118
|
+
onClick: submitHtml,
|
|
119
|
+
text: "Submit HTML"
|
|
84
120
|
}), /*#__PURE__*/React.createElement(Dialog.ConfirmAction, {
|
|
85
121
|
onClick: handleSubmit,
|
|
86
122
|
text: "Generate",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useCallback","useEffect","useRef","observer","useDialog","Dialog","OverlayLoader","Textarea","useToast","useFeature","useWebsockets","useSelectFromEditor","useCreateElement","GenerateContentFeature","decompressGzipBase64","GENERATE_CONTENT_DIALOG","WS_ACTION_CONTENT","WS_ACTION_ERROR","GenerateContentDialog","closeDialog","presenter","vm","wasSubmitting","websockets","toast","components","state","createElement","createElements","elements","forEach","el","aiComponents","Object","values","filter","c","useInAiContentGeneration","map","name","label","aiContext","inputs","input","type","description","init","contentSubscription","onMessage","message","responseText","data","value","processAiResponse","errorSubscription","showWarningToast","title","cancelPrompt","off","current","submitting","handleSubmit","submit","isProcessing","processing","isSubmitting","open","onClose","size","actions","Fragment","CancelAction","onClick","text","ConfirmAction","disabled","prompt","trim","onChange","setPrompt","String","rows"],"sources":["GenerateContentDialog.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useDialog } from \"@webiny/app-admin\";\nimport { Dialog, OverlayLoader, Textarea, useToast } from \"@webiny/admin-ui\";\nimport { useFeature } from \"@webiny/app\";\nimport type { IncomingGenericData } from \"@webiny/app-websockets\";\nimport { useWebsockets } from \"@webiny/app-websockets\";\nimport { useSelectFromEditor } from \"@webiny/app-website-builder/BaseEditor/hooks/useSelectFromEditor.js\";\nimport { useCreateElement } from \"@webiny/app-website-builder/BaseEditor/hooks/useCreateElement.js\";\nimport { GenerateContentFeature } from \"./feature.js\";\nimport { decompressGzipBase64 } from \"./decompressGzipBase64.js\";\nimport type { CreateElementParams } from \"./abstractions.js\";\n\nexport const GENERATE_CONTENT_DIALOG = \"generate-content\";\n\nexport const WS_ACTION_CONTENT = \"aiPowerUps.generatePageContent.content\";\nexport const WS_ACTION_ERROR = \"aiPowerUps.generatePageContent.error\";\n\nexport interface GeneratePageContentMessage extends IncomingGenericData {\n action: typeof WS_ACTION_CONTENT;\n data: {\n compression: \"gzip\";\n value: string;\n };\n}\n\nexport interface GeneratePageContentErrorMessage extends IncomingGenericData {\n action: typeof WS_ACTION_ERROR;\n data: {\n message: string;\n };\n}\n\nexport const GenerateContentDialog = observer(() => {\n const { closeDialog } = useDialog();\n const { presenter } = useFeature(GenerateContentFeature);\n const vm = presenter.vm;\n const wasSubmitting = useRef(false);\n const websockets = useWebsockets();\n const toast = useToast();\n\n const components = useSelectFromEditor(state => state.components);\n const { createElement } = useCreateElement();\n\n const createElements = useCallback(\n (elements: CreateElementParams[]) => {\n elements.forEach(el => createElement(el));\n },\n [createElement]\n );\n\n useEffect(() => {\n const aiComponents = Object.values(components)\n .filter(c => c.useInAiContentGeneration !== false)\n .map(c => {\n return {\n name: c.name,\n label: c.label,\n aiContext: c.aiContext,\n inputs: c.inputs.map(input => ({\n type: input.type,\n name: input.name,\n label: input.label,\n description: input.description\n }))\n };\n });\n presenter.init(aiComponents, createElements);\n }, [components, createElements]);\n\n useEffect(() => {\n const contentSubscription = websockets.onMessage<GeneratePageContentMessage>(\n WS_ACTION_CONTENT,\n async message => {\n const responseText = await decompressGzipBase64(message.data.value);\n await presenter.processAiResponse(responseText);\n }\n );\n\n const errorSubscription = websockets.onMessage<GeneratePageContentErrorMessage>(\n WS_ACTION_ERROR,\n async message => {\n toast.showWarningToast({\n title: \"Failed to generate content\",\n description: message.data.message\n });\n presenter.cancelPrompt();\n }\n );\n\n return () => {\n contentSubscription.off();\n errorSubscription.off();\n };\n }, []);\n\n useEffect(() => {\n if (wasSubmitting.current && !vm.submitting) {\n closeDialog();\n }\n wasSubmitting.current = vm.submitting;\n }, [vm.submitting]);\n\n const handleSubmit = async () => {\n await presenter.submit();\n };\n\n const isProcessing = vm.processing;\n const isSubmitting = vm.submitting;\n\n return (\n <Dialog\n open={true}\n onClose={closeDialog}\n title=\"Generate Content\"\n size={\"lg\"}\n actions={\n <>\n <Dialog.CancelAction onClick={closeDialog} text=\"Cancel\" />\n <Dialog.ConfirmAction\n onClick={handleSubmit}\n text=\"Generate\"\n disabled={!vm.prompt.trim() || vm.submitting}\n />\n </>\n }\n >\n {isSubmitting ? <OverlayLoader text={\"Generating content...\"} /> : null}\n {isProcessing ? <OverlayLoader text={\"Processing content...\"} /> : null}\n <Textarea\n label=\"Prompt\"\n description=\"Describe the page content you want to generate.\"\n value={vm.prompt}\n onChange={value => presenter.setPrompt(String(value ?? \"\"))}\n rows={6}\n />\n </Dialog>\n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E;EAAwB,CAAE,CAAC,GAAG,IAAI,EACtEV,YAAY,gBAAGhE,KAAA,CAAA4B,aAAA,CAACrB,aAAa;IAACmE,IAAI,EAAE;EAAwB,CAAE,CAAC,GAAG,IAAI,eACvE1E,KAAA,CAAA4B,aAAA,CAACpB,QAAQ;IACLiC,KAAK,EAAC,QAAQ;IACdK,WAAW,EAAC,iDAAiD;IAC7DO,KAAK,EAAE/B,EAAE,CAACuD,MAAO;IACjBE,QAAQ,EAAE1B,KAAK,IAAIhC,SAAS,CAAC2D,SAAS,CAACC,MAAM,CAAC5B,KAAK,IAAI,EAAE,CAAC,CAAE;IAC5D6B,IAAI,EAAE;EAAE,CACX,CACG,CAAC;AAEjB,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useRef","observer","useDialog","Dialog","OverlayLoader","Textarea","useToast","useFeature","useWebsockets","useSelectFromEditor","useCreateElement","GenerateContentFeature","decompressGzipBase64","GENERATE_CONTENT_DIALOG","WS_ACTION_CONTENT","WS_ACTION_ERROR","GenerateContentDialog","closeDialog","presenter","vm","wasSubmitting","websockets","toast","components","state","createElement","createElements","elements","forEach","el","aiComponents","Object","values","filter","c","useInAiContentGeneration","map","name","label","aiContext","inputs","input","type","description","init","contentSubscription","onMessage","message","responseText","data","value","processAiResponse","errorSubscription","showWarningToast","title","cancelPrompt","off","submitHtml","JSON","stringify","component","content","tool","params","text","current","submitting","handleSubmit","submit","isProcessing","processing","isSubmitting","open","onClose","size","actions","Fragment","CancelAction","onClick","ConfirmAction","disabled","prompt","trim","onChange","setPrompt","String","rows"],"sources":["GenerateContentDialog.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useDialog } from \"@webiny/app-admin\";\nimport { Dialog, OverlayLoader, Textarea, useToast } from \"@webiny/admin-ui\";\nimport { useFeature } from \"@webiny/app\";\nimport type { IncomingGenericData } from \"@webiny/app-websockets\";\nimport { useWebsockets } from \"@webiny/app-websockets\";\nimport { useSelectFromEditor } from \"@webiny/app-website-builder/BaseEditor/hooks/useSelectFromEditor.js\";\nimport { useCreateElement } from \"@webiny/app-website-builder/BaseEditor/hooks/useCreateElement.js\";\nimport { GenerateContentFeature } from \"./feature.js\";\nimport { decompressGzipBase64 } from \"./decompressGzipBase64.js\";\nimport type { CreateElementParams } from \"./abstractions.js\";\n\nexport const GENERATE_CONTENT_DIALOG = \"generate-content\";\n\nexport const WS_ACTION_CONTENT = \"aiPowerUps.generatePageContent.content\";\nexport const WS_ACTION_ERROR = \"aiPowerUps.generatePageContent.error\";\n\nexport interface GeneratePageContentMessage extends IncomingGenericData {\n action: typeof WS_ACTION_CONTENT;\n data: {\n compression: \"gzip\";\n value: string;\n };\n}\n\nexport interface GeneratePageContentErrorMessage extends IncomingGenericData {\n action: typeof WS_ACTION_ERROR;\n data: {\n message: string;\n };\n}\n\nexport const GenerateContentDialog = observer(() => {\n const { closeDialog } = useDialog();\n const { presenter } = useFeature(GenerateContentFeature);\n const vm = presenter.vm;\n const wasSubmitting = useRef(false);\n const websockets = useWebsockets();\n const toast = useToast();\n\n const components = useSelectFromEditor(state => state.components);\n const { createElement } = useCreateElement();\n\n const createElements = useCallback(\n (elements: CreateElementParams[]) => {\n elements.forEach(el => createElement(el));\n },\n [createElement]\n );\n\n useEffect(() => {\n const aiComponents = Object.values(components)\n .filter(c => c.useInAiContentGeneration !== false)\n .map(c => {\n return {\n name: c.name,\n label: c.label,\n aiContext: c.aiContext,\n inputs: c.inputs.map(input => ({\n type: input.type,\n name: input.name,\n label: input.label,\n description: input.description\n }))\n };\n });\n presenter.init(aiComponents, createElements);\n }, [components, createElements]);\n\n useEffect(() => {\n const contentSubscription = websockets.onMessage<GeneratePageContentMessage>(\n WS_ACTION_CONTENT,\n async message => {\n const responseText = await decompressGzipBase64(message.data.value);\n await presenter.processAiResponse(responseText);\n }\n );\n\n const errorSubscription = websockets.onMessage<GeneratePageContentErrorMessage>(\n WS_ACTION_ERROR,\n async message => {\n toast.showWarningToast({\n title: \"Failed to generate content\",\n description: message.data.message\n });\n presenter.cancelPrompt();\n }\n );\n\n return () => {\n contentSubscription.off();\n errorSubscription.off();\n };\n }, []);\n\n const submitHtml = () => {\n presenter.processAiResponse(\n JSON.stringify([\n {\n component: \"Webiny/Lexical\",\n inputs: {\n content: {\n tool: \"textToLexical\",\n params: {\n text: \"<h1>Song of the Living Earth</h1><p>The morning opens gently, and the world begins to sing. From forest shadows to rolling tides, nature carries a melody that feels both timeless and new. This song celebrates the quiet power of the wild, where every breeze, birdcall, and wave becomes part of a larger harmony.</p><h2>Verse One: Dawn in the Forest</h2><p>The sun wakes softly through the pine,</p><p>And gold spills down the cedar line.</p><p>The brook hums low beneath the trees,</p><p>A silver thread in morning breeze.</p>\"\n }\n }\n }\n },\n {\n component: \"Webiny/Lexical\",\n inputs: {\n content: {\n tool: \"textToLexical\",\n params: {\n text: \"<h2>Verse Two: The River’s Journey</h2><p>The river travels, clear and bold,</p><p>Through stone and root and fields of gold.</p><p>It teaches hearts to move, to flow,</p><p>To leave the banks and still grow whole.</p><h3>Chorus</h3><p>Oh, nature sings in every leaf,</p><p>In winds of joy and rains of grief.</p><p>We listen close, we learn, we stay,</p><p>And find our rhythm in its sway.</p><p>Like mountains holding up the sky,</p><p>And eagles carving paths to fly,</p><p>The earth reminds us, calm and free,</p><p>That life is meant for harmony.</p>\"\n }\n }\n }\n },\n {\n component: \"Webiny/Lexical\",\n inputs: {\n content: {\n tool: \"textToLexical\",\n params: {\n text: \"<h2>Verse Three: Evening Wildflowers</h2><p>When daylight fades to amber sky,</p><p>The meadow blooms before goodbye.</p><p>The crickets tune the final part,</p><p>And dusk grows tender in the heart.</p><p>So let us walk with gentle feet,</p><p>And keep the wild, and keep it sweet.</p><p>For every branch, each shore, each stream,</p><p>Is nature’s voice inside the dream.</p><p><strong>Final refrain:</strong> Oh, nature sings in every leaf, in winds of joy and rains of grief. We listen close, we learn, we stay, and find our rhythm in its sway.</p><p><em>Let the earth be your song, and the song be your home.</em></p>\"\n }\n }\n }\n }\n ])\n );\n };\n\n useEffect(() => {\n if (wasSubmitting.current && !vm.submitting) {\n closeDialog();\n }\n wasSubmitting.current = vm.submitting;\n }, [vm.submitting]);\n\n const handleSubmit = async () => {\n await presenter.submit();\n };\n\n const isProcessing = vm.processing;\n const isSubmitting = vm.submitting;\n\n return (\n <Dialog\n open={true}\n onClose={closeDialog}\n title=\"Generate Content\"\n size={\"lg\"}\n actions={\n <>\n <Dialog.CancelAction onClick={closeDialog} text=\"Cancel\" />\n <Dialog.ConfirmAction onClick={submitHtml} text=\"Submit HTML\" />\n <Dialog.ConfirmAction\n onClick={handleSubmit}\n text=\"Generate\"\n disabled={!vm.prompt.trim() || vm.submitting}\n />\n </>\n }\n >\n {isSubmitting ? <OverlayLoader text={\"Generating content...\"} /> : null}\n {isProcessing ? <OverlayLoader text={\"Processing content...\"} /> : null}\n <Textarea\n label=\"Prompt\"\n description=\"Describe the page content you want to generate.\"\n value={vm.prompt}\n onChange={value => presenter.setPrompt(String(value ?? \"\"))}\n rows={6}\n />\n </Dialog>\n );\n});\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAC7D,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,SAASC,SAAS,QAAQ,mBAAmB;AAC7C,SAASC,MAAM,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,QAAQ,QAAQ,kBAAkB;AAC5E,SAASC,UAAU,QAAQ,aAAa;AAExC,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,mBAAmB,QAAQ,qEAAqE;AACzG,SAASC,gBAAgB,QAAQ,kEAAkE;AACnG,SAASC,sBAAsB;AAC/B,SAASC,oBAAoB;AAG7B,OAAO,MAAMC,uBAAuB,GAAG,kBAAkB;AAEzD,OAAO,MAAMC,iBAAiB,GAAG,wCAAwC;AACzE,OAAO,MAAMC,eAAe,GAAG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a;MACtBH,IAAI,EAAC,UAAU;MACfgB,QAAQ,EAAE,CAAC7D,EAAE,CAAC8D,MAAM,CAACC,IAAI,CAAC,CAAC,IAAI/D,EAAE,CAAC+C;IAAW,CAChD,CACH;EACL,GAEAK,YAAY,gBAAG1E,KAAA,CAAA4B,aAAA,CAACrB,aAAa;IAAC4D,IAAI,EAAE;EAAwB,CAAE,CAAC,GAAG,IAAI,EACtEK,YAAY,gBAAGxE,KAAA,CAAA4B,aAAA,CAACrB,aAAa;IAAC4D,IAAI,EAAE;EAAwB,CAAE,CAAC,GAAG,IAAI,eACvEnE,KAAA,CAAA4B,aAAA,CAACpB,QAAQ;IACLiC,KAAK,EAAC,QAAQ;IACdK,WAAW,EAAC,iDAAiD;IAC7DO,KAAK,EAAE/B,EAAE,CAAC8D,MAAO;IACjBE,QAAQ,EAAEjC,KAAK,IAAIhC,SAAS,CAACkE,SAAS,CAACC,MAAM,CAACnC,KAAK,IAAI,EAAE,CAAC,CAAE;IAC5DoC,IAAI,EAAE;EAAE,CACX,CACG,CAAC;AAEjB,CAAC,CAAC","ignoreList":[]}
|
package/api/Extension.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { BaseGraphQLSchema } from "./graphql/BaseGraphQLSchema.js";
|
|
3
|
+
import AiPowerUpsSettingsGraphQLMapperImpl from "./graphql/AiPowerUpsSettingsGraphQLMapper.js";
|
|
3
4
|
import { GetSettingsFeature } from "./features/GetSettings/feature.js";
|
|
4
5
|
import { UpdateSettingsFeature } from "./features/UpdateSettings/feature.js";
|
|
5
6
|
import { WbGeneratePageContentFeature } from "./features/WbGeneratePageContent/feature.js";
|
|
7
|
+
import { ProvidersFeature } from "./features/Providers/feature.js";
|
|
6
8
|
export const Extension = createFeature({
|
|
7
9
|
name: "AiPowerUps",
|
|
8
10
|
register(container) {
|
|
9
11
|
GetSettingsFeature.register(container);
|
|
10
12
|
UpdateSettingsFeature.register(container);
|
|
11
13
|
WbGeneratePageContentFeature.register(container);
|
|
14
|
+
ProvidersFeature.register(container);
|
|
15
|
+
container.register(AiPowerUpsSettingsGraphQLMapperImpl).inSingletonScope();
|
|
12
16
|
container.register(BaseGraphQLSchema);
|
|
13
17
|
}
|
|
14
18
|
});
|
package/api/Extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","BaseGraphQLSchema","GetSettingsFeature","UpdateSettingsFeature","WbGeneratePageContentFeature","Extension","name","register","container"],"sources":["Extension.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { BaseGraphQLSchema } from \"./graphql/BaseGraphQLSchema.js\";\nimport { GetSettingsFeature } from \"./features/GetSettings/feature.js\";\nimport { UpdateSettingsFeature } from \"./features/UpdateSettings/feature.js\";\nimport { WbGeneratePageContentFeature } from \"./features/WbGeneratePageContent/feature.js\";\n\nexport const Extension = createFeature({\n name: \"AiPowerUps\",\n register(container) {\n GetSettingsFeature.register(container);\n UpdateSettingsFeature.register(container);\n WbGeneratePageContentFeature.register(container);\n\n container.register(BaseGraphQLSchema);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,iBAAiB;AAC1B,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAC9B,SAASC,4BAA4B;
|
|
1
|
+
{"version":3,"names":["createFeature","BaseGraphQLSchema","AiPowerUpsSettingsGraphQLMapperImpl","GetSettingsFeature","UpdateSettingsFeature","WbGeneratePageContentFeature","ProvidersFeature","Extension","name","register","container","inSingletonScope"],"sources":["Extension.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { BaseGraphQLSchema } from \"./graphql/BaseGraphQLSchema.js\";\nimport AiPowerUpsSettingsGraphQLMapperImpl from \"./graphql/AiPowerUpsSettingsGraphQLMapper.js\";\nimport { GetSettingsFeature } from \"./features/GetSettings/feature.js\";\nimport { UpdateSettingsFeature } from \"./features/UpdateSettings/feature.js\";\nimport { WbGeneratePageContentFeature } from \"./features/WbGeneratePageContent/feature.js\";\nimport { ProvidersFeature } from \"./features/Providers/feature.js\";\n\nexport const Extension = createFeature({\n name: \"AiPowerUps\",\n register(container) {\n GetSettingsFeature.register(container);\n UpdateSettingsFeature.register(container);\n WbGeneratePageContentFeature.register(container);\n ProvidersFeature.register(container);\n\n container.register(AiPowerUpsSettingsGraphQLMapperImpl).inSingletonScope();\n container.register(BaseGraphQLSchema);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,iBAAiB;AAC1B,OAAOC,mCAAmC;AAC1C,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAC9B,SAASC,4BAA4B;AACrC,SAASC,gBAAgB;AAEzB,OAAO,MAAMC,SAAS,GAAGP,aAAa,CAAC;EACnCQ,IAAI,EAAE,YAAY;EAClBC,QAAQA,CAACC,SAAS,EAAE;IAChBP,kBAAkB,CAACM,QAAQ,CAACC,SAAS,CAAC;IACtCN,qBAAqB,CAACK,QAAQ,CAACC,SAAS,CAAC;IACzCL,4BAA4B,CAACI,QAAQ,CAACC,SAAS,CAAC;IAChDJ,gBAAgB,CAACG,QAAQ,CAACC,SAAS,CAAC;IAEpCA,SAAS,CAACD,QAAQ,CAACP,mCAAmC,CAAC,CAACS,gBAAgB,CAAC,CAAC;IAC1ED,SAAS,CAACD,QAAQ,CAACR,iBAAiB,CAAC;EACzC;AACJ,CAAC,CAAC","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 {
|
|
3
|
+
import { AiPowerUpsSettingsGroupHandler } from "../../../api/features/shared/index.js";
|
|
4
4
|
import { GetSettingsRepository } from "./abstractions.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { IAiPowerUpsSettings } from "../../../api/types.js";
|
|
6
6
|
declare class GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {
|
|
7
7
|
private keyValueStore;
|
|
8
|
-
private
|
|
9
|
-
constructor(keyValueStore: KeyValueStore.Interface,
|
|
10
|
-
get(): Promise<Result<
|
|
8
|
+
private handlers;
|
|
9
|
+
constructor(keyValueStore: KeyValueStore.Interface, handlers: AiPowerUpsSettingsGroupHandler.Interface[]);
|
|
10
|
+
get(): Promise<Result<IAiPowerUpsSettings>>;
|
|
11
11
|
}
|
|
12
12
|
export declare const GetSettingsRepositoryImplementation: typeof GetSettingsRepositoryImpl & {
|
|
13
13
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsRepository>;
|
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { AiPowerUpsSettingsGroupHandler } from "../shared/index.js";
|
|
4
4
|
import { GetSettingsRepository } from "./abstractions.js";
|
|
5
5
|
import { AI_POWER_UPS_SETTINGS } from "../../constants.js";
|
|
6
6
|
class GetSettingsRepositoryImpl {
|
|
7
|
-
constructor(keyValueStore,
|
|
7
|
+
constructor(keyValueStore, handlers) {
|
|
8
8
|
this.keyValueStore = keyValueStore;
|
|
9
|
-
this.
|
|
9
|
+
this.handlers = handlers;
|
|
10
10
|
}
|
|
11
11
|
async get() {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const storeResult = await this.keyValueStore.get(AI_POWER_UPS_SETTINGS);
|
|
13
|
+
const raw = storeResult.isOk() && storeResult.value ? storeResult.value : {};
|
|
14
|
+
const result = {};
|
|
15
|
+
|
|
16
|
+
// Run each handler's mapFromStorage for its section.
|
|
17
|
+
for (const handler of this.handlers) {
|
|
18
|
+
result[handler.name] = handler.mapFromStorage(raw[handler.name]);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
}));
|
|
27
|
-
return Result.ok({
|
|
28
|
-
providers: {
|
|
29
|
-
presets: providerPresets
|
|
20
|
+
|
|
21
|
+
// Preserve unknown sections (sections without a handler).
|
|
22
|
+
for (const key of Object.keys(raw)) {
|
|
23
|
+
if (!(key in result)) {
|
|
24
|
+
result[key] = raw[key];
|
|
30
25
|
}
|
|
31
|
-
}
|
|
26
|
+
}
|
|
27
|
+
return Result.ok(result);
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
export const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({
|
|
35
31
|
implementation: GetSettingsRepositoryImpl,
|
|
36
|
-
dependencies: [KeyValueStore,
|
|
32
|
+
dependencies: [KeyValueStore, [AiPowerUpsSettingsGroupHandler, {
|
|
33
|
+
multiple: true
|
|
34
|
+
}]]
|
|
37
35
|
});
|
|
38
36
|
|
|
39
37
|
//# sourceMappingURL=GetSettingsRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Result","KeyValueStore","
|
|
1
|
+
{"version":3,"names":["Result","KeyValueStore","AiPowerUpsSettingsGroupHandler","GetSettingsRepository","AI_POWER_UPS_SETTINGS","GetSettingsRepositoryImpl","constructor","keyValueStore","handlers","get","storeResult","raw","isOk","value","result","handler","name","mapFromStorage","key","Object","keys","ok","GetSettingsRepositoryImplementation","createImplementation","implementation","dependencies","multiple"],"sources":["GetSettingsRepository.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 { GetSettingsRepository } from \"./abstractions.js\";\nimport type { IAiPowerUpsSettings } from \"~/api/types.js\";\nimport { AI_POWER_UPS_SETTINGS } from \"~/api/constants.js\";\n\nclass GetSettingsRepositoryImpl implements GetSettingsRepository.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private handlers: AiPowerUpsSettingsGroupHandler.Interface[]\n ) {}\n\n async get(): Promise<Result<IAiPowerUpsSettings>> {\n const storeResult =\n await this.keyValueStore.get<Record<string, unknown>>(AI_POWER_UPS_SETTINGS);\n\n const raw: Record<string, unknown> =\n storeResult.isOk() && storeResult.value ? storeResult.value : {};\n\n const result: Record<string, unknown> = {};\n\n // Run each handler's mapFromStorage for its section.\n for (const handler of this.handlers) {\n result[handler.name] = handler.mapFromStorage(raw[handler.name]);\n }\n\n // Preserve unknown sections (sections without a handler).\n for (const key of Object.keys(raw)) {\n if (!(key in result)) {\n result[key] = raw[key];\n }\n }\n\n return Result.ok(result as unknown as IAiPowerUpsSettings);\n }\n}\n\nexport const GetSettingsRepositoryImplementation = GetSettingsRepository.createImplementation({\n implementation: GetSettingsRepositoryImpl,\n dependencies: [KeyValueStore, [AiPowerUpsSettingsGroupHandler, { multiple: true }]]\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,aAAa,QAAQ,kDAAkD;AAChF,SAASC,8BAA8B;AACvC,SAASC,qBAAqB;AAE9B,SAASC,qBAAqB;AAE9B,MAAMC,yBAAyB,CAA4C;EACvEC,WAAWA,CACCC,aAAsC,EACtCC,QAAoD,EAC9D;IAAA,KAFUD,aAAsC,GAAtCA,aAAsC;IAAA,KACtCC,QAAoD,GAApDA,QAAoD;EAC7D;EAEH,MAAMC,GAAGA,CAAA,EAAyC;IAC9C,MAAMC,WAAW,GACb,MAAM,IAAI,CAACH,aAAa,CAACE,GAAG,CAA0BL,qBAAqB,CAAC;IAEhF,MAAMO,GAA4B,GAC9BD,WAAW,CAACE,IAAI,CAAC,CAAC,IAAIF,WAAW,CAACG,KAAK,GAAGH,WAAW,CAACG,KAAK,GAAG,CAAC,CAAC;IAEpE,MAAMC,MAA+B,GAAG,CAAC,CAAC;;IAE1C;IACA,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACP,QAAQ,EAAE;MACjCM,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,GAAGD,OAAO,CAACE,cAAc,CAACN,GAAG,CAACI,OAAO,CAACC,IAAI,CAAC,CAAC;IACpE;;IAEA;IACA,KAAK,MAAME,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACT,GAAG,CAAC,EAAE;MAChC,IAAI,EAAEO,GAAG,IAAIJ,MAAM,CAAC,EAAE;QAClBA,MAAM,CAACI,GAAG,CAAC,GAAGP,GAAG,CAACO,GAAG,CAAC;MAC1B;IACJ;IAEA,OAAOlB,MAAM,CAACqB,EAAE,CAACP,MAAwC,CAAC;EAC9D;AACJ;AAEA,OAAO,MAAMQ,mCAAmC,GAAGnB,qBAAqB,CAACoB,oBAAoB,CAAC;EAC1FC,cAAc,EAAEnB,yBAAyB;EACzCoB,YAAY,EAAE,CAACxB,aAAa,EAAE,CAACC,8BAA8B,EAAE;IAAEwB,QAAQ,EAAE;EAAK,CAAC,CAAC;AACtF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import { GetSettingsUseCase, GetSettingsRepository } from "./abstractions.js";
|
|
|
2
2
|
declare class GetSettingsUseCaseImpl implements GetSettingsUseCase.Interface {
|
|
3
3
|
private repository;
|
|
4
4
|
constructor(repository: GetSettingsRepository.Interface);
|
|
5
|
-
execute(): Promise<import("@webiny/feature/api").Result<import("
|
|
5
|
+
execute(): Promise<import("@webiny/feature/api").Result<import("~/api/types.js").IAiPowerUpsSettings, never>>;
|
|
6
6
|
}
|
|
7
7
|
export declare const GetSettingsUseCaseImplementation: typeof GetSettingsUseCaseImpl & {
|
|
8
8
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetSettingsUseCase>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IAiPowerUpsSettings } from "../../../api/types.js";
|
|
3
3
|
export interface IGetSettingsRepository {
|
|
4
|
-
get(): Promise<Result<
|
|
4
|
+
get(): Promise<Result<IAiPowerUpsSettings>>;
|
|
5
5
|
}
|
|
6
6
|
export declare const GetSettingsRepository: import("@webiny/di").Abstraction<IGetSettingsRepository>;
|
|
7
7
|
export declare namespace GetSettingsRepository {
|
|
8
8
|
type Interface = IGetSettingsRepository;
|
|
9
9
|
}
|
|
10
10
|
export interface IGetSettingsUseCase {
|
|
11
|
-
execute(): Promise<Result<
|
|
11
|
+
execute(): Promise<Result<IAiPowerUpsSettings>>;
|
|
12
12
|
}
|
|
13
13
|
export declare const GetSettingsUseCase: import("@webiny/di").Abstraction<IGetSettingsUseCase>;
|
|
14
14
|
export declare namespace GetSettingsUseCase {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createAbstraction","GetSettingsRepository","GetSettingsUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type {
|
|
1
|
+
{"version":3,"names":["createAbstraction","GetSettingsRepository","GetSettingsUseCase"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IAiPowerUpsSettings } from \"~/api/types.js\";\n\nexport interface IGetSettingsRepository {\n get(): Promise<Result<IAiPowerUpsSettings>>;\n}\n\nexport const GetSettingsRepository = createAbstraction<IGetSettingsRepository>(\n \"AiPowerUpsGetSettingsRepository\"\n);\n\nexport namespace GetSettingsRepository {\n export type Interface = IGetSettingsRepository;\n}\n\nexport interface IGetSettingsUseCase {\n execute(): Promise<Result<IAiPowerUpsSettings>>;\n}\n\nexport const GetSettingsUseCase = createAbstraction<IGetSettingsUseCase>(\n \"AiPowerUpsGetSettingsUseCase\"\n);\n\nexport namespace GetSettingsUseCase {\n export type Interface = IGetSettingsUseCase;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAgB,qBAAqB;AAO/D,OAAO,MAAMC,qBAAqB,GAAGD,iBAAiB,CAClD,iCACJ,CAAC;AAUD,OAAO,MAAME,kBAAkB,GAAGF,iBAAiB,CAC/C,8BACJ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AiPowerUpsSettingsGroupGraphQLMapper } from "../../../api/features/shared/index.js";
|
|
2
|
+
import type { ProvidersSettings } from "./types.js";
|
|
3
|
+
interface ApiProviderPreset {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
model: string;
|
|
8
|
+
apiKey: string | null;
|
|
9
|
+
}
|
|
10
|
+
interface ApiProviders {
|
|
11
|
+
presets: ApiProviderPreset[];
|
|
12
|
+
}
|
|
13
|
+
declare class ProvidersGraphQLMapperImpl implements AiPowerUpsSettingsGroupGraphQLMapper.Interface {
|
|
14
|
+
readonly name = "providers";
|
|
15
|
+
toApi(internal: unknown): ApiProviders;
|
|
16
|
+
fromApi(api: unknown): ProvidersSettings;
|
|
17
|
+
}
|
|
18
|
+
declare const _default: typeof ProvidersGraphQLMapperImpl & {
|
|
19
|
+
__abstraction: import("@webiny/di").Abstraction<import("../shared/abstractions.js").IAiPowerUpsSettingsGroupGraphQLMapper>;
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|