@rebasepro/plugin-data-enhancement 0.0.1-canary.09e5ec5
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/LICENSE +114 -0
- package/README.md +89 -0
- package/dist/common/src/collections/CollectionRegistry.d.ts +56 -0
- package/dist/common/src/collections/index.d.ts +1 -0
- package/dist/common/src/data/buildRebaseData.d.ts +14 -0
- package/dist/common/src/index.d.ts +3 -0
- package/dist/common/src/util/builders.d.ts +57 -0
- package/dist/common/src/util/callbacks.d.ts +6 -0
- package/dist/common/src/util/collections.d.ts +11 -0
- package/dist/common/src/util/common.d.ts +2 -0
- package/dist/common/src/util/conditions.d.ts +26 -0
- package/dist/common/src/util/entities.d.ts +58 -0
- package/dist/common/src/util/enums.d.ts +3 -0
- package/dist/common/src/util/index.d.ts +16 -0
- package/dist/common/src/util/navigation_from_path.d.ts +34 -0
- package/dist/common/src/util/navigation_utils.d.ts +20 -0
- package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
- package/dist/common/src/util/paths.d.ts +14 -0
- package/dist/common/src/util/permissions.d.ts +5 -0
- package/dist/common/src/util/references.d.ts +2 -0
- package/dist/common/src/util/relations.d.ts +22 -0
- package/dist/common/src/util/resolutions.d.ts +72 -0
- package/dist/common/src/util/storage.d.ts +24 -0
- package/dist/core/src/components/AIIcon.d.ts +16 -0
- package/dist/core/src/components/ConfirmationDialog.d.ts +9 -0
- package/dist/core/src/components/Debug/UIReferenceView.d.ts +1 -0
- package/dist/core/src/components/Debug/UIStyleGuide.d.ts +1 -0
- package/dist/core/src/components/ErrorTooltip.d.ts +2 -0
- package/dist/core/src/components/ErrorView.d.ts +21 -0
- package/dist/core/src/components/LanguageToggle.d.ts +1 -0
- package/dist/core/src/components/LoginView/LoginView.d.ts +68 -0
- package/dist/core/src/components/LoginView/index.d.ts +2 -0
- package/dist/core/src/components/NotFoundPage.d.ts +1 -0
- package/dist/core/src/components/RebaseAuth.d.ts +10 -0
- package/dist/core/src/components/RebaseLogo.d.ts +7 -0
- package/dist/core/src/components/UnsavedChangesDialog.d.ts +9 -0
- package/dist/core/src/components/UserDisplay.d.ts +7 -0
- package/dist/core/src/components/UserSelectPopover.d.ts +62 -0
- package/dist/core/src/components/UserSettingsView.d.ts +1 -0
- package/dist/core/src/components/common/index.d.ts +6 -0
- package/dist/core/src/components/common/table_height.d.ts +5 -0
- package/dist/core/src/components/common/types.d.ts +63 -0
- package/dist/core/src/components/common/useColumnsIds.d.ts +9 -0
- package/dist/core/src/components/common/useDataTableController.d.ts +45 -0
- package/dist/core/src/components/common/useDebouncedData.d.ts +9 -0
- package/dist/core/src/components/common/useScrollRestoration.d.ts +14 -0
- package/dist/core/src/components/index.d.ts +16 -0
- package/dist/core/src/contexts/AdminModeController.d.ts +4 -0
- package/dist/core/src/contexts/AnalyticsContext.d.ts +3 -0
- package/dist/core/src/contexts/AuthControllerContext.d.ts +3 -0
- package/dist/core/src/contexts/CustomizationControllerContext.d.ts +3 -0
- package/dist/core/src/contexts/DataDriverContext.d.ts +3 -0
- package/dist/core/src/contexts/DatabaseAdminContext.d.ts +3 -0
- package/dist/core/src/contexts/DialogsProvider.d.ts +4 -0
- package/dist/core/src/contexts/EffectiveRoleController.d.ts +4 -0
- package/dist/core/src/contexts/InternalUserManagementContext.d.ts +3 -0
- package/dist/core/src/contexts/ModeController.d.ts +4 -0
- package/dist/core/src/contexts/RebaseClientInstanceContext.d.ts +6 -0
- package/dist/core/src/contexts/RebaseDataContext.d.ts +3 -0
- package/dist/core/src/contexts/SnackbarProvider.d.ts +2 -0
- package/dist/core/src/contexts/StorageSourceContext.d.ts +3 -0
- package/dist/core/src/contexts/UserConfigurationPersistenceContext.d.ts +3 -0
- package/dist/core/src/contexts/index.d.ts +13 -0
- package/dist/core/src/core/PluginLifecycleManager.d.ts +17 -0
- package/dist/core/src/core/PluginProviderStack.d.ts +21 -0
- package/dist/core/src/core/Rebase.d.ts +14 -0
- package/dist/core/src/core/RebaseProps.d.ts +136 -0
- package/dist/core/src/core/RebaseRouter.d.ts +4 -0
- package/dist/core/src/core/RebaseRoutes.d.ts +17 -0
- package/dist/core/src/core/index.d.ts +4 -0
- package/dist/core/src/hooks/ApiConfigContext.d.ts +24 -0
- package/dist/core/src/hooks/data/delete.d.ts +31 -0
- package/dist/core/src/hooks/data/save.d.ts +34 -0
- package/dist/core/src/hooks/data/useCollectionFetch.d.ts +51 -0
- package/dist/core/src/hooks/data/useData.d.ts +13 -0
- package/dist/core/src/hooks/data/useDataOrder.d.ts +12 -0
- package/dist/core/src/hooks/data/useEntityFetch.d.ts +38 -0
- package/dist/core/src/hooks/data/useRelationSelector.d.ts +52 -0
- package/dist/core/src/hooks/data/useUserSelector.d.ts +31 -0
- package/dist/core/src/hooks/index.d.ts +37 -0
- package/dist/core/src/hooks/useAdminModeController.d.ts +19 -0
- package/dist/core/src/hooks/useAnalyticsController.d.ts +5 -0
- package/dist/core/src/hooks/useAuthController.d.ts +11 -0
- package/dist/core/src/hooks/useAuthSubscription.d.ts +2 -0
- package/dist/core/src/hooks/useBackendStorageSource.d.ts +30 -0
- package/dist/core/src/hooks/useBridgeRegistration.d.ts +18 -0
- package/dist/core/src/hooks/useBrowserTitleAndIcon.d.ts +6 -0
- package/dist/core/src/hooks/useBuildAdminModeController.d.ts +6 -0
- package/dist/core/src/hooks/useBuildEffectiveRoleController.d.ts +8 -0
- package/dist/core/src/hooks/useBuildLocalConfigurationPersistence.d.ts +2 -0
- package/dist/core/src/hooks/useBuildModeController.d.ts +6 -0
- package/dist/core/src/hooks/useClipboard.d.ts +57 -0
- package/dist/core/src/hooks/useCollapsedGroups.d.ts +12 -0
- package/dist/core/src/hooks/useCustomizationController.d.ts +11 -0
- package/dist/core/src/hooks/useDialogsController.d.ts +11 -0
- package/dist/core/src/hooks/useEffectiveRoleController.d.ts +7 -0
- package/dist/core/src/hooks/useInternalUserManagementController.d.ts +12 -0
- package/dist/core/src/hooks/useLargeLayout.d.ts +1 -0
- package/dist/core/src/hooks/useModeController.d.ts +19 -0
- package/dist/core/src/hooks/usePermissions.d.ts +12 -0
- package/dist/core/src/hooks/useRebaseClient.d.ts +5 -0
- package/dist/core/src/hooks/useRebaseContext.d.ts +11 -0
- package/dist/core/src/hooks/useRebaseRegistry.d.ts +34 -0
- package/dist/core/src/hooks/useSlot.d.ts +18 -0
- package/dist/core/src/hooks/useSnackbarController.d.ts +20 -0
- package/dist/core/src/hooks/useStorageSource.d.ts +7 -0
- package/dist/core/src/hooks/useStudioBridge.d.ts +91 -0
- package/dist/core/src/hooks/useTranslation.d.ts +17 -0
- package/dist/core/src/hooks/useUnsavedChangesDialog.d.ts +12 -0
- package/dist/core/src/hooks/useUserConfigurationPersistence.d.ts +8 -0
- package/dist/core/src/hooks/useValidateAuthenticator.d.ts +21 -0
- package/dist/core/src/i18n/RebaseI18nProvider.d.ts +33 -0
- package/dist/core/src/index.d.ts +15 -0
- package/dist/core/src/internal/common.d.ts +3 -0
- package/dist/core/src/internal/useRestoreScroll.d.ts +6 -0
- package/dist/core/src/locales/de.d.ts +2 -0
- package/dist/core/src/locales/en.d.ts +10 -0
- package/dist/core/src/locales/es.d.ts +10 -0
- package/dist/core/src/locales/fr.d.ts +2 -0
- package/dist/core/src/locales/hi.d.ts +2 -0
- package/dist/core/src/locales/it.d.ts +2 -0
- package/dist/core/src/locales/pt.d.ts +7 -0
- package/dist/core/src/util/constants.d.ts +1 -0
- package/dist/core/src/util/createFormexStub.d.ts +2 -0
- package/dist/core/src/util/entity_cache.d.ts +27 -0
- package/dist/core/src/util/enums.d.ts +5 -0
- package/dist/core/src/util/icon_list.d.ts +5 -0
- package/dist/core/src/util/icon_synonyms.d.ts +1 -0
- package/dist/core/src/util/icons.d.ts +20 -0
- package/dist/core/src/util/index.d.ts +10 -0
- package/dist/core/src/util/previews.d.ts +4 -0
- package/dist/core/src/util/useStorageUploadController.d.ts +38 -0
- package/dist/core/src/util/useTraceUpdate.d.ts +2 -0
- package/dist/formex/src/Field.d.ts +52 -0
- package/dist/formex/src/Formex.d.ts +7 -0
- package/dist/formex/src/index.d.ts +5 -0
- package/dist/formex/src/types.d.ts +40 -0
- package/dist/formex/src/useCreateFormex.d.ts +14 -0
- package/dist/formex/src/utils.d.ts +16 -0
- package/dist/index.es.js +751 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +746 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/plugin-data-enhancement/src/api.d.ts +34 -0
- package/dist/plugin-data-enhancement/src/components/DataEnhancementControllerProvider.d.ts +14 -0
- package/dist/plugin-data-enhancement/src/components/FormEnhanceAction.d.ts +10 -0
- package/dist/plugin-data-enhancement/src/editor/useEditorAIController.d.ts +4 -0
- package/dist/plugin-data-enhancement/src/index.d.ts +4 -0
- package/dist/plugin-data-enhancement/src/locales/de.d.ts +21 -0
- package/dist/plugin-data-enhancement/src/locales/en.d.ts +21 -0
- package/dist/plugin-data-enhancement/src/locales/es.d.ts +21 -0
- package/dist/plugin-data-enhancement/src/locales/fr.d.ts +21 -0
- package/dist/plugin-data-enhancement/src/locales/hi.d.ts +21 -0
- package/dist/plugin-data-enhancement/src/locales/it.d.ts +21 -0
- package/dist/plugin-data-enhancement/src/locales/pt.d.ts +21 -0
- package/dist/plugin-data-enhancement/src/types/data_enhancement_controller.d.ts +71 -0
- package/dist/plugin-data-enhancement/src/types/subscriptions_message_props.d.ts +3 -0
- package/dist/plugin-data-enhancement/src/useDataEnhancementPlugin.d.ts +29 -0
- package/dist/plugin-data-enhancement/src/utils/diffStrings.d.ts +7 -0
- package/dist/plugin-data-enhancement/src/utils/properties.d.ts +3 -0
- package/dist/plugin-data-enhancement/src/utils/strings_counter.d.ts +2 -0
- package/dist/plugin-data-enhancement/src/utils/suggestions.d.ts +1 -0
- package/dist/plugin-data-enhancement/src/utils/values.d.ts +1 -0
- package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
- package/dist/types/src/controllers/auth.d.ts +119 -0
- package/dist/types/src/controllers/client.d.ts +170 -0
- package/dist/types/src/controllers/collection_registry.d.ts +45 -0
- package/dist/types/src/controllers/customization_controller.d.ts +60 -0
- package/dist/types/src/controllers/data.d.ts +168 -0
- package/dist/types/src/controllers/data_driver.d.ts +160 -0
- package/dist/types/src/controllers/database_admin.d.ts +11 -0
- package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
- package/dist/types/src/controllers/effective_role.d.ts +4 -0
- package/dist/types/src/controllers/email.d.ts +34 -0
- package/dist/types/src/controllers/index.d.ts +18 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
- package/dist/types/src/controllers/navigation.d.ts +213 -0
- package/dist/types/src/controllers/registry.d.ts +54 -0
- package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
- package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
- package/dist/types/src/controllers/snackbar.d.ts +24 -0
- package/dist/types/src/controllers/storage.d.ts +171 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/rebase_context.d.ts +105 -0
- package/dist/types/src/types/backend.d.ts +536 -0
- package/dist/types/src/types/builders.d.ts +15 -0
- package/dist/types/src/types/chips.d.ts +5 -0
- package/dist/types/src/types/collections.d.ts +856 -0
- package/dist/types/src/types/cron.d.ts +102 -0
- package/dist/types/src/types/data_source.d.ts +64 -0
- package/dist/types/src/types/entities.d.ts +145 -0
- package/dist/types/src/types/entity_actions.d.ts +98 -0
- package/dist/types/src/types/entity_callbacks.d.ts +173 -0
- package/dist/types/src/types/entity_link_builder.d.ts +7 -0
- package/dist/types/src/types/entity_overrides.d.ts +10 -0
- package/dist/types/src/types/entity_views.d.ts +61 -0
- package/dist/types/src/types/export_import.d.ts +21 -0
- package/dist/types/src/types/index.d.ts +23 -0
- package/dist/types/src/types/locales.d.ts +4 -0
- package/dist/types/src/types/modify_collections.d.ts +5 -0
- package/dist/types/src/types/plugins.d.ts +279 -0
- package/dist/types/src/types/properties.d.ts +1176 -0
- package/dist/types/src/types/property_config.d.ts +70 -0
- package/dist/types/src/types/relations.d.ts +336 -0
- package/dist/types/src/types/slots.d.ts +252 -0
- package/dist/types/src/types/translations.d.ts +870 -0
- package/dist/types/src/types/user_management_delegate.d.ts +121 -0
- package/dist/types/src/types/websockets.d.ts +78 -0
- package/dist/types/src/users/index.d.ts +2 -0
- package/dist/types/src/users/roles.d.ts +22 -0
- package/dist/types/src/users/user.d.ts +46 -0
- package/dist/ui/src/components/Alert.d.ts +12 -0
- package/dist/ui/src/components/Autocomplete.d.ts +21 -0
- package/dist/ui/src/components/Avatar.d.ts +11 -0
- package/dist/ui/src/components/Badge.d.ts +8 -0
- package/dist/ui/src/components/BooleanSwitch.d.ts +14 -0
- package/dist/ui/src/components/BooleanSwitchWithLabel.d.ts +17 -0
- package/dist/ui/src/components/Button.d.ts +14 -0
- package/dist/ui/src/components/Card.d.ts +9 -0
- package/dist/ui/src/components/CenteredView.d.ts +9 -0
- package/dist/ui/src/components/Checkbox.d.ts +13 -0
- package/dist/ui/src/components/Chip.d.ts +26 -0
- package/dist/ui/src/components/CircularProgress.d.ts +5 -0
- package/dist/ui/src/components/CircularProgressCenter.d.ts +11 -0
- package/dist/ui/src/components/Collapse.d.ts +9 -0
- package/dist/ui/src/components/ColorPicker.d.ts +30 -0
- package/dist/ui/src/components/Container.d.ts +8 -0
- package/dist/ui/src/components/DateTimeField.d.ts +24 -0
- package/dist/ui/src/components/DebouncedTextField.d.ts +2 -0
- package/dist/ui/src/components/Dialog.d.ts +39 -0
- package/dist/ui/src/components/DialogActions.d.ts +7 -0
- package/dist/ui/src/components/DialogContent.d.ts +7 -0
- package/dist/ui/src/components/DialogTitle.d.ts +10 -0
- package/dist/ui/src/components/ErrorBoundary.d.ts +11 -0
- package/dist/ui/src/components/ExpandablePanel.d.ts +12 -0
- package/dist/ui/src/components/FileUpload.d.ts +23 -0
- package/dist/ui/src/components/IconButton.d.ts +12 -0
- package/dist/ui/src/components/InfoLabel.d.ts +5 -0
- package/dist/ui/src/components/InputLabel.d.ts +11 -0
- package/dist/ui/src/components/Label.d.ts +7 -0
- package/dist/ui/src/components/LoadingButton.d.ts +7 -0
- package/dist/ui/src/components/Markdown.d.ts +10 -0
- package/dist/ui/src/components/Menu.d.ts +23 -0
- package/dist/ui/src/components/Menubar.d.ts +80 -0
- package/dist/ui/src/components/MultiSelect.d.ts +48 -0
- package/dist/ui/src/components/Paper.d.ts +6 -0
- package/dist/ui/src/components/Popover.d.ts +24 -0
- package/dist/ui/src/components/RadioGroup.d.ts +28 -0
- package/dist/ui/src/components/ResizablePanels.d.ts +18 -0
- package/dist/ui/src/components/SearchBar.d.ts +22 -0
- package/dist/ui/src/components/Select.d.ts +43 -0
- package/dist/ui/src/components/Separator.d.ts +5 -0
- package/dist/ui/src/components/Sheet.d.ts +22 -0
- package/dist/ui/src/components/Skeleton.d.ts +6 -0
- package/dist/ui/src/components/Slider.d.ts +21 -0
- package/dist/ui/src/components/Table.d.ts +34 -0
- package/dist/ui/src/components/Tabs.d.ts +19 -0
- package/dist/ui/src/components/TextField.d.ts +58 -0
- package/dist/ui/src/components/TextareaAutosize.d.ts +43 -0
- package/dist/ui/src/components/ToggleButtonGroup.d.ts +30 -0
- package/dist/ui/src/components/Tooltip.d.ts +19 -0
- package/dist/ui/src/components/Typography.d.ts +36 -0
- package/dist/ui/src/components/VirtualTable/VirtualTable.d.ts +11 -0
- package/dist/ui/src/components/VirtualTable/VirtualTableCell.d.ts +21 -0
- package/dist/ui/src/components/VirtualTable/VirtualTableHeader.d.ts +29 -0
- package/dist/ui/src/components/VirtualTable/VirtualTableHeaderRow.d.ts +2 -0
- package/dist/ui/src/components/VirtualTable/VirtualTableProps.d.ts +243 -0
- package/dist/ui/src/components/VirtualTable/VirtualTableRow.d.ts +3 -0
- package/dist/ui/src/components/VirtualTable/index.d.ts +3 -0
- package/dist/ui/src/components/VirtualTable/types.d.ts +38 -0
- package/dist/ui/src/components/common/SelectInputLabel.d.ts +5 -0
- package/dist/ui/src/components/index.d.ts +53 -0
- package/dist/ui/src/hooks/PortalContainerContext.d.ts +31 -0
- package/dist/ui/src/hooks/index.d.ts +6 -0
- package/dist/ui/src/hooks/useDebounceCallback.d.ts +1 -0
- package/dist/ui/src/hooks/useDebounceValue.d.ts +1 -0
- package/dist/ui/src/hooks/useDebouncedCallback.d.ts +1 -0
- package/dist/ui/src/hooks/useInjectStyles.d.ts +7 -0
- package/dist/ui/src/hooks/useOutsideAlerter.d.ts +5 -0
- package/dist/ui/src/icons/GitHubIcon.d.ts +2 -0
- package/dist/ui/src/icons/HandleIcon.d.ts +1 -0
- package/dist/ui/src/icons/Icon.d.ts +20 -0
- package/dist/ui/src/icons/cool_icon_keys.d.ts +1 -0
- package/dist/ui/src/icons/icon_keys.d.ts +1 -0
- package/dist/ui/src/icons/index.d.ts +6 -0
- package/dist/ui/src/index.d.ts +5 -0
- package/dist/ui/src/styles.d.ts +12 -0
- package/dist/ui/src/util/chip_colors.d.ts +4 -0
- package/dist/ui/src/util/cls.d.ts +2 -0
- package/dist/ui/src/util/debounce.d.ts +10 -0
- package/dist/ui/src/util/hash.d.ts +1 -0
- package/dist/ui/src/util/index.d.ts +4 -0
- package/dist/ui/src/util/key_to_icon_component.d.ts +1 -0
- package/package.json +86 -0
- package/src/api.ts +198 -0
- package/src/components/DataEnhancementControllerProvider.tsx +339 -0
- package/src/components/FormEnhanceAction.tsx +273 -0
- package/src/editor/useEditorAIController.tsx +37 -0
- package/src/index.ts +10 -0
- package/src/locales/de.ts +21 -0
- package/src/locales/en.ts +21 -0
- package/src/locales/es.ts +21 -0
- package/src/locales/fr.ts +21 -0
- package/src/locales/hi.ts +21 -0
- package/src/locales/it.ts +21 -0
- package/src/locales/pt.ts +21 -0
- package/src/tests/diffStrings.test.ts +128 -0
- package/src/types/data_enhancement_controller.tsx +75 -0
- package/src/types/subscriptions_message_props.tsx +1 -0
- package/src/useDataEnhancementPlugin.tsx +66 -0
- package/src/utils/diffStrings.ts +70 -0
- package/src/utils/properties.ts +168 -0
- package/src/utils/strings_counter.ts +22 -0
- package/src/utils/suggestions.ts +6 -0
- package/src/utils/values.ts +12 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react-compiler-runtime"), require("react/jsx-runtime"), require("react"), require("@rebasepro/core"), require("@rebasepro/admin"), require("@rebasepro/common"), require("@rebasepro/utils"), require("@rebasepro/ui"), require("lucide-react")) : typeof define === "function" && define.amd ? define(["exports", "react-compiler-runtime", "react/jsx-runtime", "react", "@rebasepro/core", "@rebasepro/admin", "@rebasepro/common", "@rebasepro/utils", "@rebasepro/ui", "lucide-react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.Rebase = {}, global.reactCompilerRuntime, global.jsxRuntime, global.React, global.core, global.admin, global.common, global.utils, global.ui, global.lucideReact));
|
|
3
|
+
})(this, (function(exports2, reactCompilerRuntime, jsxRuntime, React, core, admin, common, utils, ui, lucideReact) {
|
|
4
|
+
"use strict";
|
|
5
|
+
function flatMapEntityValues(values, path = "") {
|
|
6
|
+
if (!values) return {};
|
|
7
|
+
return Object.entries(values).flatMap(([key, value]) => {
|
|
8
|
+
const currentPath = path ? `${path}.${key}` : key;
|
|
9
|
+
if (typeof value === "object") {
|
|
10
|
+
return flatMapEntityValues(value, currentPath);
|
|
11
|
+
} else {
|
|
12
|
+
return {
|
|
13
|
+
[currentPath]: value
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}).reduce((acc, curr) => ({
|
|
17
|
+
...acc,
|
|
18
|
+
...curr
|
|
19
|
+
}), {});
|
|
20
|
+
}
|
|
21
|
+
const DEFAULT_SERVER = "https://api.rebase.pro";
|
|
22
|
+
async function enhanceDataAPIStream(props) {
|
|
23
|
+
const flatValues = flatMapEntityValues(props.values);
|
|
24
|
+
const properties = props.properties;
|
|
25
|
+
const inputEntity = {
|
|
26
|
+
entityId: props.entityId,
|
|
27
|
+
values: flatValues
|
|
28
|
+
};
|
|
29
|
+
const request = {
|
|
30
|
+
inputEntity,
|
|
31
|
+
properties,
|
|
32
|
+
entityName: props.entityName,
|
|
33
|
+
entityDescription: props.entityDescription,
|
|
34
|
+
propertyKey: props.propertyKey,
|
|
35
|
+
propertyInstructions: props.propertyInstructions,
|
|
36
|
+
instructions: props.instructions
|
|
37
|
+
};
|
|
38
|
+
console.debug("enhanceDataAPIStream", request);
|
|
39
|
+
return fetch((props.host ?? DEFAULT_SERVER) + "/data/enhance_stream/", {
|
|
40
|
+
// mode: "no-cors",
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
Authorization: `Basic ${props.firebaseToken}`,
|
|
45
|
+
"x-de-api-key": `Basic ${props.apiKey}`
|
|
46
|
+
// "x-de-version": version
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify(request)
|
|
49
|
+
}).then(async (res) => {
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
console.error("enhanceDataAPIStream error", res);
|
|
52
|
+
throw await res.json();
|
|
53
|
+
}
|
|
54
|
+
const reader = res.body?.getReader();
|
|
55
|
+
if (!reader) {
|
|
56
|
+
throw new Error("No reader");
|
|
57
|
+
}
|
|
58
|
+
for await (const chunk of readChunks(reader)) {
|
|
59
|
+
const str = new TextDecoder().decode(chunk);
|
|
60
|
+
try {
|
|
61
|
+
str.split("&$# ").forEach((s) => {
|
|
62
|
+
if (s && s.length > 0) {
|
|
63
|
+
const data = JSON.parse(s.trim());
|
|
64
|
+
if (data.type === "suggestion_delta") props.onUpdateDelta(data.data.propertyKey, data.data.partialValue);
|
|
65
|
+
else if (data.type === "suggestion") props.onUpdate(data.data);
|
|
66
|
+
else if (data.type === "result") props.onEnd(data.data);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} catch (e) {
|
|
70
|
+
console.error("str", str);
|
|
71
|
+
console.error("Error parsing stream", e);
|
|
72
|
+
props.onError(e);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function readChunks(reader) {
|
|
78
|
+
return {
|
|
79
|
+
async *[Symbol.asyncIterator]() {
|
|
80
|
+
let readResult = await reader.read();
|
|
81
|
+
while (!readResult.done) {
|
|
82
|
+
yield readResult.value;
|
|
83
|
+
readResult = await reader.read();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function fetchEntityPromptSuggestion(props) {
|
|
89
|
+
return fetch((props.host ?? DEFAULT_SERVER) + "/data/prompt_autocomplete/", {
|
|
90
|
+
// mode: "no-cors",
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: {
|
|
93
|
+
"Content-Type": "application/json",
|
|
94
|
+
Authorization: `Basic ${props.firebaseToken}`,
|
|
95
|
+
"x-de-api-key": `Basic ${props.apiKey}`
|
|
96
|
+
},
|
|
97
|
+
body: JSON.stringify({
|
|
98
|
+
entityName: props.entityName,
|
|
99
|
+
input: props.input ?? null
|
|
100
|
+
})
|
|
101
|
+
}).then(async (res) => {
|
|
102
|
+
const data = await res.json();
|
|
103
|
+
if (!res.ok) {
|
|
104
|
+
console.error("fetchEntityPromptSuggestion", data);
|
|
105
|
+
throw Error(data.message);
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
prompts: data.data.prompts.map((e) => ({
|
|
109
|
+
prompt: e,
|
|
110
|
+
type: "sample"
|
|
111
|
+
}))
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
async function autocompleteStream(props) {
|
|
116
|
+
let result = "";
|
|
117
|
+
return fetch((props.host ?? DEFAULT_SERVER) + "/data/autocomplete/", {
|
|
118
|
+
// mode: "no-cors",
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
Authorization: `Basic ${props.firebaseToken}`
|
|
123
|
+
// "x-de-version": version
|
|
124
|
+
},
|
|
125
|
+
body: JSON.stringify({
|
|
126
|
+
textBefore: props.textBefore,
|
|
127
|
+
textAfter: props.textAfter
|
|
128
|
+
})
|
|
129
|
+
}).then(async (res) => {
|
|
130
|
+
if (!res.ok) {
|
|
131
|
+
console.error("enhanceDataAPIStream error", res);
|
|
132
|
+
throw await res.json();
|
|
133
|
+
}
|
|
134
|
+
const reader = res.body?.getReader();
|
|
135
|
+
if (!reader) {
|
|
136
|
+
throw new Error("No reader");
|
|
137
|
+
}
|
|
138
|
+
for await (const chunk of readChunks(reader)) {
|
|
139
|
+
const str = new TextDecoder().decode(chunk);
|
|
140
|
+
result += str;
|
|
141
|
+
console.debug("Autocomplete update:", str);
|
|
142
|
+
props.onUpdate(str);
|
|
143
|
+
}
|
|
144
|
+
}).then(() => {
|
|
145
|
+
console.debug("Autocomplete result:", result);
|
|
146
|
+
return result;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function getAppendableSuggestion(suggestion, value) {
|
|
150
|
+
const suggestionIncludesValue = typeof suggestion === "string" && typeof value === "string" && suggestion.toLowerCase().trim().startsWith(value.toLowerCase().trim());
|
|
151
|
+
return typeof value === "string" && suggestionIncludesValue ? suggestion.substring(suggestion.toLowerCase().trim().indexOf(value.toLowerCase().trim()) + value.trim().length) : void 0;
|
|
152
|
+
}
|
|
153
|
+
function getSimplifiedProperties(properties, values, path = "") {
|
|
154
|
+
if (!properties) return {};
|
|
155
|
+
return Object.entries(properties).map(([key, property]) => {
|
|
156
|
+
if (common.isPropertyBuilder(property)) return {};
|
|
157
|
+
const fullKey = path ? `${path}.${key}` : key;
|
|
158
|
+
const valueInPath = utils.getValueInPath(values, fullKey);
|
|
159
|
+
return getSimplifiedProperty(property, fullKey, valueInPath);
|
|
160
|
+
}).reduce((a, b) => ({
|
|
161
|
+
...a,
|
|
162
|
+
...b
|
|
163
|
+
}), {});
|
|
164
|
+
}
|
|
165
|
+
function getSimpleProperty(property) {
|
|
166
|
+
const fieldId = admin.getFieldId(property);
|
|
167
|
+
if (!fieldId) {
|
|
168
|
+
console.error("No fieldId found for property", property);
|
|
169
|
+
throw new Error("Field id not found");
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
name: property.name,
|
|
173
|
+
description: property.description,
|
|
174
|
+
type: property.type,
|
|
175
|
+
fieldConfigId: fieldId,
|
|
176
|
+
enum: "enum" in property && property.enum ? getSimpleEnumValues(property.enum) : void 0,
|
|
177
|
+
disabled: Boolean(property.disabled || property.readOnly)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function getSimplifiedProperty(property, path, value) {
|
|
181
|
+
if (common.isPropertyBuilder(property)) return {};
|
|
182
|
+
if (property.type === "array") {
|
|
183
|
+
if (property.of && !Array.isArray(property.of) && !common.isPropertyBuilder(property.of)) {
|
|
184
|
+
const arrayParentProperty = {
|
|
185
|
+
name: property.name,
|
|
186
|
+
description: property.description,
|
|
187
|
+
type: property.type,
|
|
188
|
+
fieldConfigId: "repeat",
|
|
189
|
+
disabled: Boolean(property.disabled || property.readOnly),
|
|
190
|
+
of: getSimpleProperty(property.of)
|
|
191
|
+
};
|
|
192
|
+
const result = {
|
|
193
|
+
[path]: arrayParentProperty
|
|
194
|
+
};
|
|
195
|
+
return result;
|
|
196
|
+
} else if (property.oneOf) {
|
|
197
|
+
const arrayParentProperty = {
|
|
198
|
+
name: property.name,
|
|
199
|
+
description: property.description,
|
|
200
|
+
type: property.type,
|
|
201
|
+
fieldConfigId: "block",
|
|
202
|
+
disabled: Boolean(property.disabled || property.readOnly),
|
|
203
|
+
oneOf: {
|
|
204
|
+
typeField: property.oneOf.typeField,
|
|
205
|
+
valueField: property.oneOf.valueField,
|
|
206
|
+
properties: Object.entries(property.oneOf.properties).map(([key, prop]) => ({
|
|
207
|
+
[key]: getSimpleProperty(prop)
|
|
208
|
+
})).reduce((a, b) => ({
|
|
209
|
+
...a,
|
|
210
|
+
...b
|
|
211
|
+
}), {})
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
if (!Array.isArray(value)) {
|
|
215
|
+
return {
|
|
216
|
+
[path]: arrayParentProperty
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return value.map((v, i) => {
|
|
220
|
+
if (v == null) return {};
|
|
221
|
+
const typeKey = property.oneOf.typeField ?? "type";
|
|
222
|
+
const oneOfType = v[typeKey];
|
|
223
|
+
const valueKey = property.oneOf.valueField ?? "value";
|
|
224
|
+
const oneOfValue = v[valueKey];
|
|
225
|
+
const childProperty = property.oneOf.properties[oneOfType];
|
|
226
|
+
if (childProperty === void 0) {
|
|
227
|
+
console.error(`No property found for type ${oneOfType}`, property.oneOf.properties);
|
|
228
|
+
return {};
|
|
229
|
+
}
|
|
230
|
+
const simplifiedProperty = getSimplifiedProperty(childProperty, `${path}.${i}.${valueKey}`, oneOfValue);
|
|
231
|
+
return {
|
|
232
|
+
[`${path}.${i}.${typeKey}`]: oneOfType,
|
|
233
|
+
...simplifiedProperty
|
|
234
|
+
};
|
|
235
|
+
}).reduce((a, b) => ({
|
|
236
|
+
...a,
|
|
237
|
+
...b
|
|
238
|
+
}), {
|
|
239
|
+
[path]: arrayParentProperty
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
} else if (property.type === "map") {
|
|
243
|
+
if (property.properties) {
|
|
244
|
+
const mapProperties = Object.entries(property.properties).map(([key, childProperty]) => {
|
|
245
|
+
const childValue = value?.[key];
|
|
246
|
+
return getSimplifiedProperty(childProperty, key, childValue);
|
|
247
|
+
}).map((o) => attachPathToKeys(o, path)).reduce((a, b) => ({
|
|
248
|
+
...a,
|
|
249
|
+
...b
|
|
250
|
+
}), {});
|
|
251
|
+
if (Object.keys(mapProperties).length === 0) return {};
|
|
252
|
+
const mapParentProperty = {
|
|
253
|
+
name: property.name,
|
|
254
|
+
description: property.description,
|
|
255
|
+
type: property.type,
|
|
256
|
+
fieldConfigId: "group",
|
|
257
|
+
disabled: Boolean(property.disabled || property.readOnly)
|
|
258
|
+
};
|
|
259
|
+
return {
|
|
260
|
+
[path]: mapParentProperty,
|
|
261
|
+
...mapProperties
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
const fieldId = admin.getFieldId(property);
|
|
266
|
+
if (!fieldId) {
|
|
267
|
+
console.warn(`No fieldId found for property ${path} with type ${property.type}`);
|
|
268
|
+
return {};
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
[path]: getSimpleProperty(property)
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
return {};
|
|
275
|
+
}
|
|
276
|
+
function attachPathToKeys(obj, path = "") {
|
|
277
|
+
return Object.entries(obj).map(([key, value]) => {
|
|
278
|
+
const fullKey = path ? `${path}.${key}` : key;
|
|
279
|
+
return {
|
|
280
|
+
[fullKey]: value
|
|
281
|
+
};
|
|
282
|
+
}).reduce((a, b) => ({
|
|
283
|
+
...a,
|
|
284
|
+
...b
|
|
285
|
+
}), {});
|
|
286
|
+
}
|
|
287
|
+
function getSimpleEnumValues(enumValues) {
|
|
288
|
+
if (Array.isArray(enumValues)) return enumValues.map((v) => String(v.id));
|
|
289
|
+
if (typeof enumValues === "object") return Object.keys(enumValues);
|
|
290
|
+
throw Error("getSimpleEnumValues: Invalid enumValues");
|
|
291
|
+
}
|
|
292
|
+
function useEditorAIController({
|
|
293
|
+
getAuthToken
|
|
294
|
+
}) {
|
|
295
|
+
const autocomplete = async (textBefore, textAfter, onUpdate) => {
|
|
296
|
+
if (!getAuthToken) {
|
|
297
|
+
throw new Error("Firebase token is required");
|
|
298
|
+
}
|
|
299
|
+
const firebaseToken = await getAuthToken();
|
|
300
|
+
return autocompleteStream({
|
|
301
|
+
firebaseToken,
|
|
302
|
+
textBefore,
|
|
303
|
+
textAfter,
|
|
304
|
+
onUpdate
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
return {
|
|
308
|
+
autocomplete
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
const DataEnhancementControllerContext = React.createContext(null);
|
|
312
|
+
const useDataEnhancementController = () => {
|
|
313
|
+
return React.useContext(DataEnhancementControllerContext);
|
|
314
|
+
};
|
|
315
|
+
function getPropertyFromKey(properties, propertyKey) {
|
|
316
|
+
if (propertyKey in properties) {
|
|
317
|
+
return properties[propertyKey];
|
|
318
|
+
} else {
|
|
319
|
+
const split = propertyKey.split(".");
|
|
320
|
+
if (split.length === 1) {
|
|
321
|
+
return void 0;
|
|
322
|
+
}
|
|
323
|
+
const parentKey = split.slice(0, split.length - 1).join(".");
|
|
324
|
+
return getPropertyFromKey(properties, parentKey);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function DataEnhancementControllerProvider({
|
|
328
|
+
apiKey,
|
|
329
|
+
getConfigForPath,
|
|
330
|
+
children,
|
|
331
|
+
host,
|
|
332
|
+
path,
|
|
333
|
+
collection,
|
|
334
|
+
formContext
|
|
335
|
+
}) {
|
|
336
|
+
const [enabled, setEnabled] = React.useState(false);
|
|
337
|
+
const [suggestions, setSuggestions] = React.useState({});
|
|
338
|
+
const [loadingSuggestions, setLoadingSuggestions] = React.useState([]);
|
|
339
|
+
const enhancingInProgress = React.useRef(false);
|
|
340
|
+
const authController = core.useAuthController();
|
|
341
|
+
const snackbarController = core.useSnackbarController();
|
|
342
|
+
const properties = React.useMemo(() => getSimplifiedProperties(collection.properties, formContext?.values ?? {}), [formContext?.values]);
|
|
343
|
+
const valuesRef = React.useRef(formContext?.values ?? {});
|
|
344
|
+
React.useEffect(() => {
|
|
345
|
+
if (!enhancingInProgress.current) valuesRef.current = formContext?.values ?? {};
|
|
346
|
+
}, [formContext?.values]);
|
|
347
|
+
const allowReferenceDataSelection = false;
|
|
348
|
+
const updateConfig = React.useCallback(async () => {
|
|
349
|
+
if (!getConfigForPath) return;
|
|
350
|
+
const config = getConfigForPath({
|
|
351
|
+
path,
|
|
352
|
+
collection
|
|
353
|
+
});
|
|
354
|
+
if (config) {
|
|
355
|
+
setEnabled(true);
|
|
356
|
+
}
|
|
357
|
+
}, [collection, getConfigForPath, path]);
|
|
358
|
+
React.useEffect(() => {
|
|
359
|
+
if (!getConfigForPath) {
|
|
360
|
+
setEnabled(true);
|
|
361
|
+
} else {
|
|
362
|
+
updateConfig();
|
|
363
|
+
}
|
|
364
|
+
}, [getConfigForPath, updateConfig]);
|
|
365
|
+
const urlController = admin.useUrlController();
|
|
366
|
+
const clearSuggestion = React.useCallback((propertyKey) => {
|
|
367
|
+
setSuggestions((prev) => {
|
|
368
|
+
const {
|
|
369
|
+
[propertyKey]: _,
|
|
370
|
+
...rest
|
|
371
|
+
} = prev;
|
|
372
|
+
return rest;
|
|
373
|
+
});
|
|
374
|
+
}, []);
|
|
375
|
+
const appendValueDelta = React.useCallback((propertyKey_0, delta) => {
|
|
376
|
+
const property = getPropertyFromKey(properties, propertyKey_0);
|
|
377
|
+
if (delta === null || property?.disabled) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const value = utils.getValueInPath(valuesRef.current, propertyKey_0);
|
|
381
|
+
const currentValue = value ? value + "" : "";
|
|
382
|
+
const updatedValue = currentValue + delta;
|
|
383
|
+
valuesRef.current = {
|
|
384
|
+
...valuesRef.current,
|
|
385
|
+
[propertyKey_0]: updatedValue
|
|
386
|
+
};
|
|
387
|
+
formContext?.setFieldValue(propertyKey_0, updatedValue, false);
|
|
388
|
+
setSuggestions((prev_0) => ({
|
|
389
|
+
...prev_0,
|
|
390
|
+
[propertyKey_0]: (prev_0[propertyKey_0] ?? "") + delta
|
|
391
|
+
}));
|
|
392
|
+
}, [properties, formContext]);
|
|
393
|
+
const updateSuggestedValues = React.useCallback((currentValues, updatedValues, replaceValues) => {
|
|
394
|
+
setLoadingSuggestions((prev_1) => {
|
|
395
|
+
return prev_1.filter((p) => !Object.keys(updatedValues).includes(p));
|
|
396
|
+
});
|
|
397
|
+
Object.entries(updatedValues).forEach(([propertyKey_1, suggestion]) => {
|
|
398
|
+
const value_0 = utils.getValueInPath(currentValues, propertyKey_1);
|
|
399
|
+
const property_0 = getPropertyFromKey(properties, propertyKey_1);
|
|
400
|
+
if (!property_0 || suggestion === null || property_0.disabled) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (typeof suggestion === "number") {
|
|
404
|
+
formContext?.setFieldValue(propertyKey_1, suggestion);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (replaceValues) {
|
|
408
|
+
formContext?.setFieldValue(propertyKey_1, suggestion);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const appendableValue = getAppendableSuggestion(suggestion, value_0);
|
|
412
|
+
const currentValue_0 = value_0 ? value_0 + "" : "";
|
|
413
|
+
if (appendableValue) {
|
|
414
|
+
formContext?.setFieldValue(propertyKey_1, suggestion);
|
|
415
|
+
} else {
|
|
416
|
+
const multiline = property_0?.fieldConfigId === "multiline" || property_0?.fieldConfigId === "markdown";
|
|
417
|
+
const trimmedValue = currentValue_0.trimEnd();
|
|
418
|
+
if (multiline && (trimmedValue.endsWith(".") || trimmedValue.endsWith("?") || trimmedValue.endsWith("!") || trimmedValue.endsWith(":"))) {
|
|
419
|
+
formContext?.setFieldValue(propertyKey_1, trimmedValue + "\n\n" + suggestion.trimStart());
|
|
420
|
+
} else {
|
|
421
|
+
formContext?.setFieldValue(propertyKey_1, trimmedValue + (trimmedValue.length > 0 ? " " : "") + suggestion);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
setSuggestions((prev_2) => ({
|
|
426
|
+
...prev_2,
|
|
427
|
+
...Object.keys(updatedValues).reduce((acc, key) => {
|
|
428
|
+
const value_1 = utils.getValueInPath(formContext?.values, key);
|
|
429
|
+
const suggestion_0 = updatedValues[key];
|
|
430
|
+
return {
|
|
431
|
+
...acc,
|
|
432
|
+
[key]: getAppendableSuggestion(suggestion_0, value_1) ?? suggestion_0
|
|
433
|
+
};
|
|
434
|
+
}, {})
|
|
435
|
+
}));
|
|
436
|
+
}, [properties, formContext]);
|
|
437
|
+
const displayNeededSubscriptionSnackbar = React.useCallback((projectId) => {
|
|
438
|
+
snackbarController.open({
|
|
439
|
+
type: "warning",
|
|
440
|
+
message: "A valid subscription is needed in order to use this function.",
|
|
441
|
+
autoHideDuration: 4e3
|
|
442
|
+
});
|
|
443
|
+
}, [snackbarController]);
|
|
444
|
+
const editorAIController = useEditorAIController({
|
|
445
|
+
getAuthToken: authController.getAuthToken
|
|
446
|
+
});
|
|
447
|
+
const clearAllSuggestions = React.useCallback(() => {
|
|
448
|
+
setSuggestions({});
|
|
449
|
+
}, []);
|
|
450
|
+
const enhance = React.useCallback(async (props) => {
|
|
451
|
+
if (!authController.user) {
|
|
452
|
+
snackbarController.open({
|
|
453
|
+
type: "warning",
|
|
454
|
+
message: "You need to be logged in to enhance data"
|
|
455
|
+
});
|
|
456
|
+
return Promise.reject(new Error("Not logged in"));
|
|
457
|
+
}
|
|
458
|
+
const resolvedPath = urlController.resolveDatabasePathsFrom(path);
|
|
459
|
+
const firebaseToken = await authController.getAuthToken();
|
|
460
|
+
if (props.propertyKey) {
|
|
461
|
+
clearSuggestion(props.propertyKey);
|
|
462
|
+
} else {
|
|
463
|
+
clearAllSuggestions();
|
|
464
|
+
}
|
|
465
|
+
setLoadingSuggestions((prev_3) => [...prev_3, ...props.propertyKey ? [props.propertyKey] : Object.keys(properties)]);
|
|
466
|
+
enhancingInProgress.current = true;
|
|
467
|
+
const currentValues_0 = valuesRef.current ?? {};
|
|
468
|
+
return new Promise((resolve, reject) => {
|
|
469
|
+
function onError(e) {
|
|
470
|
+
setLoadingSuggestions([]);
|
|
471
|
+
if (e.code === "payment-required") {
|
|
472
|
+
const projectId_0 = e.data.projectId;
|
|
473
|
+
displayNeededSubscriptionSnackbar(projectId_0);
|
|
474
|
+
} else {
|
|
475
|
+
console.error("Enhance error", e);
|
|
476
|
+
}
|
|
477
|
+
reject(e);
|
|
478
|
+
enhancingInProgress.current = false;
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
enhanceDataAPIStream({
|
|
482
|
+
...props,
|
|
483
|
+
host,
|
|
484
|
+
apiKey,
|
|
485
|
+
properties,
|
|
486
|
+
path: resolvedPath,
|
|
487
|
+
entityName: collection.singularName ?? collection.name,
|
|
488
|
+
entityDescription: collection.description,
|
|
489
|
+
firebaseToken,
|
|
490
|
+
onUpdate: (suggestions_0) => {
|
|
491
|
+
console.debug("de onUpdate", suggestions_0);
|
|
492
|
+
updateSuggestedValues(currentValues_0, suggestions_0, props.replaceValues ?? false);
|
|
493
|
+
},
|
|
494
|
+
onUpdateDelta: (propertyKey_2, partialValue) => {
|
|
495
|
+
appendValueDelta(propertyKey_2, partialValue);
|
|
496
|
+
},
|
|
497
|
+
onError,
|
|
498
|
+
onEnd: (result) => {
|
|
499
|
+
console.debug("de onEnd", result);
|
|
500
|
+
if (result.errors) {
|
|
501
|
+
result.errors.forEach((error) => {
|
|
502
|
+
snackbarController.open({
|
|
503
|
+
type: "warning",
|
|
504
|
+
message: error
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
if (Object.keys(result.suggestions).length === 0) {
|
|
509
|
+
snackbarController.open({
|
|
510
|
+
type: "info",
|
|
511
|
+
autoHideDuration: 1800,
|
|
512
|
+
message: "No fields were updated"
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
setLoadingSuggestions([]);
|
|
516
|
+
resolve(result);
|
|
517
|
+
enhancingInProgress.current = false;
|
|
518
|
+
}
|
|
519
|
+
}).catch(onError);
|
|
520
|
+
} catch (e_0) {
|
|
521
|
+
onError(e_0);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}, [authController, urlController, path, clearSuggestion, clearAllSuggestions, properties, host, apiKey, collection, updateSuggestedValues, appendValueDelta, displayNeededSubscriptionSnackbar, snackbarController]);
|
|
525
|
+
const getSamplePrompts = React.useCallback(async (entityName, input) => {
|
|
526
|
+
const firebaseToken_0 = await authController.getAuthToken();
|
|
527
|
+
return fetchEntityPromptSuggestion({
|
|
528
|
+
host,
|
|
529
|
+
entityName,
|
|
530
|
+
firebaseToken: firebaseToken_0,
|
|
531
|
+
apiKey,
|
|
532
|
+
input
|
|
533
|
+
});
|
|
534
|
+
}, [apiKey, authController.getAuthToken, host]);
|
|
535
|
+
const dataEnhancementController = React.useMemo(() => ({
|
|
536
|
+
enabled,
|
|
537
|
+
suggestions,
|
|
538
|
+
clearSuggestion,
|
|
539
|
+
enhance,
|
|
540
|
+
allowReferenceDataSelection,
|
|
541
|
+
clearAllSuggestions,
|
|
542
|
+
getSamplePrompts,
|
|
543
|
+
loadingSuggestions,
|
|
544
|
+
editorAIController
|
|
545
|
+
}), [enabled, suggestions, clearSuggestion, enhance, allowReferenceDataSelection, clearAllSuggestions, getSamplePrompts, loadingSuggestions, editorAIController]);
|
|
546
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DataEnhancementControllerContext.Provider, { value: dataEnhancementController, children });
|
|
547
|
+
}
|
|
548
|
+
function FormEnhanceAction({
|
|
549
|
+
entityId,
|
|
550
|
+
path,
|
|
551
|
+
status,
|
|
552
|
+
collection,
|
|
553
|
+
formContext,
|
|
554
|
+
openEntityMode
|
|
555
|
+
}) {
|
|
556
|
+
const largeLayout = core.useLargeLayout();
|
|
557
|
+
const storageKey = createLocalStorageKey(path, status);
|
|
558
|
+
const [loading, setLoading] = React.useState(false);
|
|
559
|
+
const dataEnhancementController = useDataEnhancementController();
|
|
560
|
+
const [samplePrompts, setSamplePrompts] = React.useState(void 0);
|
|
561
|
+
const [instructions, setInstructions] = React.useState("");
|
|
562
|
+
const {
|
|
563
|
+
suggestions,
|
|
564
|
+
getSamplePrompts
|
|
565
|
+
} = dataEnhancementController;
|
|
566
|
+
const loadingPrompts = React.useRef(false);
|
|
567
|
+
const updateSuggestedPrompts = React.useCallback(async function updateSuggestedPrompts2(instructions_0) {
|
|
568
|
+
if (loadingPrompts.current) return;
|
|
569
|
+
loadingPrompts.current = true;
|
|
570
|
+
const prompts = status === "new" ? (await getSamplePrompts(collection.singularName ?? collection.name, instructions_0)).prompts : getPromptsForExistingEntities(collection.properties);
|
|
571
|
+
const recentPromptsFromStorage = getRecentPromptsFromStorage(storageKey);
|
|
572
|
+
const recentPrompts = recentPromptsFromStorage.map((prompt) => prompt.prompt);
|
|
573
|
+
setSamplePrompts([...recentPromptsFromStorage, ...prompts.filter((p) => !recentPrompts.includes(p.prompt))].slice(0, 5));
|
|
574
|
+
loadingPrompts.current = false;
|
|
575
|
+
}, [collection.name, collection.singularName, getSamplePrompts, status]);
|
|
576
|
+
React.useDeferredValue(formContext?.values);
|
|
577
|
+
React.useEffect(() => {
|
|
578
|
+
if (!samplePrompts) {
|
|
579
|
+
setSamplePrompts(getRecentPromptsFromStorage(storageKey));
|
|
580
|
+
updateSuggestedPrompts().then();
|
|
581
|
+
}
|
|
582
|
+
}, [samplePrompts, storageKey, updateSuggestedPrompts, instructions, status]);
|
|
583
|
+
React.useEffect(() => {
|
|
584
|
+
updateSuggestedPrompts().then();
|
|
585
|
+
}, [status]);
|
|
586
|
+
const enhance = (prompt_0) => {
|
|
587
|
+
if (!formContext?.values) return;
|
|
588
|
+
setLoading(true);
|
|
589
|
+
if (prompt_0) {
|
|
590
|
+
addRecentPrompt(storageKey, prompt_0);
|
|
591
|
+
setSamplePrompts([{
|
|
592
|
+
prompt: prompt_0,
|
|
593
|
+
type: "recent"
|
|
594
|
+
}, ...(samplePrompts ?? []).slice(0, 5)]);
|
|
595
|
+
}
|
|
596
|
+
return dataEnhancementController.enhance({
|
|
597
|
+
entityId,
|
|
598
|
+
values: formContext.values,
|
|
599
|
+
instructions: prompt_0,
|
|
600
|
+
replaceValues: true
|
|
601
|
+
}).finally(() => {
|
|
602
|
+
setLoading(false);
|
|
603
|
+
});
|
|
604
|
+
};
|
|
605
|
+
if (!dataEnhancementController?.enabled) return null;
|
|
606
|
+
Object.values(suggestions).filter(Boolean).length > 0;
|
|
607
|
+
(samplePrompts ?? []).length > 0 && instructions.length === 0;
|
|
608
|
+
function submit() {
|
|
609
|
+
enhance(instructions);
|
|
610
|
+
}
|
|
611
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Menu, { align: "end", sideOffset: 8, className: "max-w-[100vw]", trigger: /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { variant: "filled", color: "neutral", fullWidth: largeLayout && openEntityMode === "full_screen", size: "small", disabled: loading, children: [
|
|
612
|
+
!loading && /* @__PURE__ */ jsxRuntime.jsx(core.AIIcon, { size: "small" }),
|
|
613
|
+
loading && /* @__PURE__ */ jsxRuntime.jsx(ui.CircularProgress, { size: "small" }),
|
|
614
|
+
"Autofill"
|
|
615
|
+
] }), children: [
|
|
616
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.MenuItem, { className: "py-4", onClick: () => {
|
|
617
|
+
enhance();
|
|
618
|
+
}, children: [
|
|
619
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.AIIcon, { size: "small" }),
|
|
620
|
+
"Autofill based on the current content"
|
|
621
|
+
] }),
|
|
622
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Separator, { orientation: "horizontal", className: "mt-2" }),
|
|
623
|
+
samplePrompts?.map((samplePrompt, index) => {
|
|
624
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.MenuItem, { onClick: () => {
|
|
625
|
+
setInstructions(samplePrompt.prompt);
|
|
626
|
+
enhance(samplePrompt.prompt);
|
|
627
|
+
}, children: [
|
|
628
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pl-9 grow text-text-secondary dark:text-text-secondary-dark", children: samplePrompt.prompt }),
|
|
629
|
+
samplePrompt.type === "recent" && /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { onClick: (e) => {
|
|
630
|
+
e.preventDefault();
|
|
631
|
+
e.stopPropagation();
|
|
632
|
+
removeRecentPrompt(storageKey, samplePrompt.prompt);
|
|
633
|
+
setSamplePrompts((samplePrompts ?? []).filter((p_0) => p_0.prompt !== samplePrompt.prompt));
|
|
634
|
+
}, size: "smallest", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, { size: ui.iconSize.smallest }) })
|
|
635
|
+
] }, index + "_" + samplePrompt.prompt);
|
|
636
|
+
}),
|
|
637
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Separator, { orientation: "horizontal" }),
|
|
638
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: ui.cls("my-2 w-[500px] max-w-full flex items-start text-surface-700 dark:text-surface-200"), children: [
|
|
639
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.TextareaAutosize, { className: ui.cls("p-4 rounded-lg resize-none bg-surface-100 dark:bg-surface-950 mx-2 w-full grow outline-hidden max-h-[300px] overflow-auto", ui.focusedDisabled), value: instructions, autoFocus: status === "new", disabled: loading, onFocus: (event) => {
|
|
640
|
+
event.stopPropagation();
|
|
641
|
+
}, placeholder: "...or provide instructions", onKeyDown: (e_0) => {
|
|
642
|
+
e_0.stopPropagation();
|
|
643
|
+
if (e_0.key === "Enter" && !e_0.shiftKey) {
|
|
644
|
+
e_0.preventDefault();
|
|
645
|
+
submit();
|
|
646
|
+
}
|
|
647
|
+
}, onChange: (e_1) => {
|
|
648
|
+
setInstructions(e_1.target.value);
|
|
649
|
+
} }),
|
|
650
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", onClick: () => {
|
|
651
|
+
setInstructions("");
|
|
652
|
+
}, color: !instructions ? "primary" : void 0, disabled: loading || !instructions, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, { size: ui.iconSize.small }) }),
|
|
653
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.IconButton, { onClick: () => enhance(instructions), size: "small", color: !instructions ? "primary" : void 0, disabled: loading || !instructions, children: [
|
|
654
|
+
loading && /* @__PURE__ */ jsxRuntime.jsx(ui.CircularProgress, { size: "smallest" }),
|
|
655
|
+
!loading && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SendIcon, { color: "primary" })
|
|
656
|
+
] })
|
|
657
|
+
] })
|
|
658
|
+
] });
|
|
659
|
+
}
|
|
660
|
+
function getPromptsForExistingEntities(properties) {
|
|
661
|
+
const multilineProperties = Object.values(properties).filter((p) => {
|
|
662
|
+
if (common.isPropertyBuilder(p)) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
return p.type === "string" && (p.markdown || p.multiline);
|
|
666
|
+
});
|
|
667
|
+
const multilinePrompt = multilineProperties.length > 0 ? multilineProperties[Math.floor(Math.random() * multilineProperties.length)] : void 0;
|
|
668
|
+
const prompts = ["Fill the missing fields", "Translate the missing content"];
|
|
669
|
+
if (multilinePrompt) {
|
|
670
|
+
prompts.push(`Add 2 paragraphs to '${multilinePrompt.name}'`);
|
|
671
|
+
}
|
|
672
|
+
return prompts.map((p) => ({
|
|
673
|
+
prompt: p,
|
|
674
|
+
type: "sample"
|
|
675
|
+
}));
|
|
676
|
+
}
|
|
677
|
+
const createLocalStorageKey = (path, status) => {
|
|
678
|
+
const statusString = status === "new" ? "new" : "existing";
|
|
679
|
+
return `data_enhancement::${statusString}::${common.stripCollectionPath(path)}`;
|
|
680
|
+
};
|
|
681
|
+
const getRecentPromptsFromStorage = (storageKey) => {
|
|
682
|
+
const item = localStorage.getItem(storageKey);
|
|
683
|
+
return item ? JSON.parse(item).map((e) => ({
|
|
684
|
+
prompt: e,
|
|
685
|
+
type: "recent"
|
|
686
|
+
})) : [];
|
|
687
|
+
};
|
|
688
|
+
const addRecentPrompt = (storageKey, prompt) => {
|
|
689
|
+
if (!prompt || prompt.trim().length === 0) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
const recentPrompts = getRecentPromptsFromStorage(storageKey);
|
|
693
|
+
localStorage.setItem(storageKey, JSON.stringify([prompt, ...recentPrompts.map((e) => e.prompt).filter((e) => e !== prompt).slice(0, 5)]));
|
|
694
|
+
};
|
|
695
|
+
const removeRecentPrompt = (storageKey, prompt) => {
|
|
696
|
+
localStorage.setItem(storageKey, JSON.stringify(getRecentPromptsFromStorage(storageKey).map((e) => e.prompt).filter((e) => e !== prompt)));
|
|
697
|
+
};
|
|
698
|
+
const DEFAULT_API_KEY = "fcms-U9jdDii0xXWSDC34asfrf54lbkFJBfKfRWcEDEwdc4V5wDWEDF";
|
|
699
|
+
function useDataEnhancementPlugin(props) {
|
|
700
|
+
const $ = reactCompilerRuntime.c(5);
|
|
701
|
+
const apiKey = props?.apiKey ?? DEFAULT_API_KEY;
|
|
702
|
+
const getConfigForPath = props?.getConfigForPath;
|
|
703
|
+
props?.host;
|
|
704
|
+
let t0;
|
|
705
|
+
let t1;
|
|
706
|
+
if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
707
|
+
t1 = [{
|
|
708
|
+
slot: "form.actions",
|
|
709
|
+
Component: FormEnhanceAction,
|
|
710
|
+
order: 40
|
|
711
|
+
}];
|
|
712
|
+
$[0] = t1;
|
|
713
|
+
} else {
|
|
714
|
+
t1 = $[0];
|
|
715
|
+
}
|
|
716
|
+
const t2 = props?.host;
|
|
717
|
+
let t3;
|
|
718
|
+
if ($[1] !== apiKey || $[2] !== getConfigForPath || $[3] !== t2) {
|
|
719
|
+
t3 = {
|
|
720
|
+
key: "data_enhancement",
|
|
721
|
+
slots: t1,
|
|
722
|
+
providers: [{
|
|
723
|
+
scope: "form",
|
|
724
|
+
Component: DataEnhancementControllerProvider,
|
|
725
|
+
props: {
|
|
726
|
+
apiKey,
|
|
727
|
+
getConfigForPath,
|
|
728
|
+
host: t2
|
|
729
|
+
}
|
|
730
|
+
}]
|
|
731
|
+
};
|
|
732
|
+
$[1] = apiKey;
|
|
733
|
+
$[2] = getConfigForPath;
|
|
734
|
+
$[3] = t2;
|
|
735
|
+
$[4] = t3;
|
|
736
|
+
} else {
|
|
737
|
+
t3 = $[4];
|
|
738
|
+
}
|
|
739
|
+
t0 = t3;
|
|
740
|
+
return t0;
|
|
741
|
+
}
|
|
742
|
+
exports2.useDataEnhancementPlugin = useDataEnhancementPlugin;
|
|
743
|
+
exports2.useEditorAIController = useEditorAIController;
|
|
744
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
745
|
+
}));
|
|
746
|
+
//# sourceMappingURL=index.umd.js.map
|