@rebasepro/cms 0.28.2 → 0.29.0-canary.g0e3a0e7
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/README.md +3 -3
- package/dist/collection_editor/_cms_internals.d.ts +0 -1
- package/dist/collection_editor/ui/EditorCollectionAction.d.ts +2 -2
- package/dist/collection_editor/ui/EditorCollectionAction.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js +2 -2
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js.map +1 -1
- package/dist/components/AdditionalFieldValue.d.ts +9 -3
- package/dist/components/AdditionalFieldValue.js +7 -4
- package/dist/components/AdditionalFieldValue.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +117 -18
- package/dist/components/CollectionPanel.js +115 -37
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +5 -5
- package/dist/components/CollectionTableBinding/CollectionRowActions.js +16 -12
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js +33 -8
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +8 -3
- package/dist/components/CollectionTableBinding/PropertyTableCell.js +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +9 -1
- package/dist/components/CollectionTableBinding/column_utils.js +6 -3
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +3 -2
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +9 -7
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +26 -2
- package/dist/components/CollectionTableBinding/internal/common.js +88 -4
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +4 -3
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js +19 -14
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionAddButton.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js +50 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +11 -3
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -4
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +29 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js +112 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +58 -16
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.d.ts +57 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +146 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +22 -26
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +58 -22
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js +81 -1089
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +152 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js +38 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.d.ts +13 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js +32 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.d.ts +14 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js +22 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +39 -67
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js +54 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.d.ts +24 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js +69 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.js +34 -23
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.d.ts +17 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +107 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -0
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +15 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js +49 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +35 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js +45 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -0
- package/dist/components/CollectionViewBinding/RowActions.d.ts +40 -0
- package/dist/components/CollectionViewBinding/RowActions.js +60 -0
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +7 -4
- package/dist/components/CollectionViewBinding/SplitListView.js +20 -21
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/builtin_action_props.d.ts +13 -0
- package/dist/components/CollectionViewBinding/fields.d.ts +22 -0
- package/dist/components/CollectionViewBinding/fields.js +47 -0
- package/dist/components/CollectionViewBinding/fields.js.map +1 -0
- package/dist/components/CollectionViewBinding/useBoardDataController.js +6 -7
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.d.ts +19 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js +28 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js.map +1 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +125 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +844 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +20 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.js +23 -2
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +21 -3
- package/dist/components/CollectionViewBinding/useSelectionController.js +37 -6
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +3 -3
- package/dist/components/CollectionsProvider.js +4 -4
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/CollectionsScopeContext.d.ts +1 -1
- package/dist/components/CollectionsScopeContext.js +1 -1
- package/dist/components/CollectionsScopeContext.js.map +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +2 -2
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +32 -68
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js +5 -4
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -2
- package/dist/components/EditViewBinding.js +25 -15
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.js +8 -5
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +8 -1
- package/dist/components/EntityViewBinding.js +43 -14
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +40 -0
- package/dist/components/EntityViewBody.js +90 -0
- package/dist/components/EntityViewBody.js.map +1 -0
- package/dist/components/FieldValue.d.ts +50 -0
- package/dist/components/FieldValue.js +81 -0
- package/dist/components/FieldValue.js.map +1 -0
- package/dist/components/InlineEntityPreview.js +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PanelNotFound.d.ts +5 -0
- package/dist/components/PanelNotFound.js +21 -0
- package/dist/components/PanelNotFound.js.map +1 -0
- package/dist/components/RebaseCMS.d.ts +1 -1
- package/dist/components/RebaseCMS.js +11 -3
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +9 -3
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RebaseShell.js +10 -5
- package/dist/components/RebaseShell.js.map +1 -1
- package/dist/components/RecordDetail.d.ts +61 -0
- package/dist/components/RecordDetail.js +123 -0
- package/dist/components/RecordDetail.js.map +1 -0
- package/dist/components/RecordForm.d.ts +126 -0
- package/dist/components/{EntityFormPanel.js → RecordForm.js} +64 -36
- package/dist/components/RecordForm.js.map +1 -0
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +47 -17
- package/dist/components/ReferenceTable/SelectionTableBinding.js +89 -53
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +5 -3
- package/dist/components/ReferenceWidget.js +10 -7
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.js +4 -4
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.js +2 -3
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/SelectionStore.d.ts +1 -1
- package/dist/components/SelectableTable/SelectionStore.js +1 -1
- package/dist/components/SelectableTable/SelectionStore.js.map +1 -1
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
- package/dist/components/SidePanelBinding.js +13 -12
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/collection_prop.d.ts +18 -0
- package/dist/components/collection_prop.js +23 -0
- package/dist/components/collection_prop.js.map +1 -0
- package/dist/components/common/default_entity_actions.js +54 -54
- package/dist/components/common/default_entity_actions.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +4 -1
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/components/history/LastEditedByFormAction.d.ts +1 -1
- package/dist/components/index.d.ts +4 -2
- package/dist/data_export/export/ExportCollectionAction.d.ts +3 -2
- package/dist/data_export/export/ExportCollectionAction.js +4 -3
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +6 -3
- package/dist/data_export/export/additional_fields.js +8 -4
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.js +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/form/EntityForm.d.ts +1 -1
- package/dist/form/EntityForm.js +252 -150
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js +3 -2
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.d.ts +1 -1
- package/dist/form/EntityFormBinding.js +22 -11
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormField.d.ts +36 -0
- package/dist/form/FormField.js +41 -0
- package/dist/form/FormField.js.map +1 -0
- package/dist/form/FormFieldsContext.d.ts +69 -0
- package/dist/form/FormFieldsContext.js +143 -0
- package/dist/form/FormFieldsContext.js.map +1 -0
- package/dist/form/PropertyFieldBinding.js +4 -4
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/collection_showing.d.ts +8 -0
- package/dist/form/collection_showing.js +29 -0
- package/dist/form/collection_showing.js.map +1 -0
- package/dist/form/components/ErrorFocus.js +2 -1
- package/dist/form/components/ErrorFocus.js.map +1 -1
- package/dist/form/components/FieldBlock.js +3 -1
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +5 -1
- package/dist/form/components/FormRail.js +5 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/FormSections.d.ts +5 -1
- package/dist/form/components/FormSections.js +11 -4
- package/dist/form/components/FormSections.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
- package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/form_dom_ids.d.ts +25 -0
- package/dist/form/form_dom_ids.js +42 -0
- package/dist/form/form_dom_ids.js.map +1 -0
- package/dist/form/index.d.ts +3 -1
- package/dist/form/resolve_cell_property.d.ts +5 -0
- package/dist/form/resolve_cell_property.js +22 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +2 -2
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.d.ts +3 -3
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/useResolvedCollections.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.js +9 -9
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useEntityDisplay.js +6 -4
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useRecordActions.js +2 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useSelectionDialog.d.ts +20 -7
- package/dist/hooks/useSelectionDialog.js +29 -8
- package/dist/hooks/useSelectionDialog.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +15 -9
- package/dist/mcp-view.d.ts +9 -0
- package/dist/mcp-view.js +2 -0
- package/dist/mcp_view/app_modules.d.ts +29 -0
- package/dist/mcp_view/app_modules.js +163 -0
- package/dist/mcp_view/app_modules.js.map +1 -0
- package/dist/mcp_view/bridge.d.ts +90 -0
- package/dist/mcp_view/bridge.js +205 -0
- package/dist/mcp_view/bridge.js.map +1 -0
- package/dist/mcp_view/code_app.d.ts +65 -0
- package/dist/mcp_view/code_app.js +139 -0
- package/dist/mcp_view/code_app.js.map +1 -0
- package/dist/mcp_view/index.d.ts +48 -0
- package/dist/mcp_view/index.js +235 -0
- package/dist/mcp_view/index.js.map +1 -0
- package/dist/mcp_view/payload.d.ts +78 -0
- package/dist/mcp_view/payload.js +155 -0
- package/dist/mcp_view/payload.js.map +1 -0
- package/dist/mcp_view/screen.d.ts +28 -0
- package/dist/mcp_view/screen.js +223 -0
- package/dist/mcp_view/screen.js.map +1 -0
- package/dist/mcp_view/storage_source.d.ts +14 -0
- package/dist/mcp_view/storage_source.js +29 -0
- package/dist/mcp_view/storage_source.js.map +1 -0
- package/dist/mcp_view/store.d.ts +9 -0
- package/dist/mcp_view/store.js +27 -0
- package/dist/mcp_view/store.js.map +1 -0
- package/dist/mcp_view/tool_driver.d.ts +135 -0
- package/dist/mcp_view/tool_driver.js +527 -0
- package/dist/mcp_view/tool_driver.js.map +1 -0
- package/dist/preview/components/DatePreview.d.ts +34 -1
- package/dist/preview/components/DatePreview.js +72 -37
- package/dist/preview/components/DatePreview.js.map +1 -1
- package/dist/routes/RebaseRoute.js +1 -1
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +5 -3
- package/dist/selection/SelectionMenu.js +16 -9
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/index.d.ts +2 -1
- package/dist/selection/resolve_selection.d.ts +61 -7
- package/dist/selection/resolve_selection.js +93 -11
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/types/components/EntityFormProps.d.ts +60 -10
- package/dist/types/fields.d.ts +2 -65
- package/dist/util/dataControllerAdapter.d.ts +8 -0
- package/dist/util/dataControllerAdapter.js +11 -0
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/navigation_utils.d.ts +5 -4
- package/dist/util/navigation_utils.js +6 -6
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +8 -0
- package/dist/util/propertyConfigMapper.js +16 -2
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/package.json +15 -9
- package/recipes/README.md +79 -26
- package/recipes/approval-queue.tsx +79 -0
- package/recipes/bulk-set-status.tsx +23 -17
- package/recipes/calendar-view.tsx +28 -23
- package/recipes/master-detail.tsx +75 -0
- package/recipes/my-preferences.tsx +3 -3
- package/recipes/orders-dashboard.tsx +58 -84
- package/recipes/site-settings.tsx +4 -4
- package/dist/components/EntityFormPanel.d.ts +0 -63
- package/dist/components/EntityFormPanel.js.map +0 -1
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { McpAppBridge, isRecord } from "./bridge.js";
|
|
2
|
+
import { createToolDriver, describeChanges } from "./tool_driver.js";
|
|
3
|
+
import { findCollection, parseResult } from "./payload.js";
|
|
4
|
+
import { describeAppError } from "./code_app.js";
|
|
5
|
+
import { createViewStore } from "./store.js";
|
|
6
|
+
import { McpScreen } from "./screen.js";
|
|
7
|
+
import { VIEW_STORAGE_SOURCE } from "./storage_source.js";
|
|
8
|
+
import "react";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
import { Alert } from "@rebasepro/ui";
|
|
11
|
+
import { setRebaseEmbedHost } from "@rebasepro/app";
|
|
12
|
+
import { createRoot } from "react-dom/client";
|
|
13
|
+
//#region src/mcp_view/index.tsx
|
|
14
|
+
/**
|
|
15
|
+
* Connect to the host, wait for the tool's result, set the embed host from
|
|
16
|
+
* it, and mount the app.
|
|
17
|
+
*/
|
|
18
|
+
function startMcpView(options) {
|
|
19
|
+
installSubmitFix();
|
|
20
|
+
const bridge = options.bridge ?? new McpAppBridge();
|
|
21
|
+
let started = false;
|
|
22
|
+
bridge.ontoolresult = (result) => {
|
|
23
|
+
if (started) return;
|
|
24
|
+
started = true;
|
|
25
|
+
const parsed = parseResult(result);
|
|
26
|
+
if (parsed.kind === "table") {
|
|
27
|
+
const container = document.getElementById("root");
|
|
28
|
+
if (container && options.mountTable) options.mountTable(bridge, container);
|
|
29
|
+
else showError("This view cannot draw this result.");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (parsed.kind === "error") {
|
|
33
|
+
showError(parsed.message);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
setRebaseEmbedHost(embedHost(bridge, parsed.screen));
|
|
37
|
+
Promise.resolve(options.mountApp(parsed.screen)).catch((error) => showError(`The view could not start: ${error instanceof Error ? error.message : String(error)}`));
|
|
38
|
+
};
|
|
39
|
+
bridge.watchHostContext((context) => {
|
|
40
|
+
if (context.theme) document.documentElement.classList.toggle("dark", context.theme === "dark");
|
|
41
|
+
});
|
|
42
|
+
bridge.connect(options.appInfo ?? {
|
|
43
|
+
name: "rebase",
|
|
44
|
+
version: "0.3.0"
|
|
45
|
+
});
|
|
46
|
+
return bridge;
|
|
47
|
+
}
|
|
48
|
+
/** What the app runs on, here: the tools, the person, the frame's storage and theme, and the screen to draw. */
|
|
49
|
+
function embedHost(bridge, screen) {
|
|
50
|
+
const pending = createViewStore(void 0);
|
|
51
|
+
const context = createViewStore(bridge.hostContext);
|
|
52
|
+
bridge.watchHostContext((next) => context.set(next));
|
|
53
|
+
const told = modelContext(bridge);
|
|
54
|
+
const tools = createToolDriver({
|
|
55
|
+
callTool: (name, args) => bridge.callTool(name, args),
|
|
56
|
+
actions: screen.actions,
|
|
57
|
+
...screen.firstPage && { seed: screen.firstPage },
|
|
58
|
+
...screen.seeds && { seeds: screen.seeds },
|
|
59
|
+
collection: (name) => findCollection(screen.collections, name),
|
|
60
|
+
confirm: (plan) => new Promise((resolve) => pending.set({
|
|
61
|
+
plan,
|
|
62
|
+
answer: (confirmed) => {
|
|
63
|
+
pending.set(void 0);
|
|
64
|
+
resolve(confirmed);
|
|
65
|
+
}
|
|
66
|
+
})),
|
|
67
|
+
onChange: told.changes
|
|
68
|
+
});
|
|
69
|
+
const host = {
|
|
70
|
+
dataDriver: tools.driver,
|
|
71
|
+
rowHooksDriver: tools.confirmingDriver,
|
|
72
|
+
authController: viewerAuth(screen.viewer),
|
|
73
|
+
storageSource: VIEW_STORAGE_SOURCE,
|
|
74
|
+
mode: bridge.hostContext.theme === "dark" ? "dark" : "light",
|
|
75
|
+
narrowCollections: (collections) => narrowCollections(collections, screen.collections),
|
|
76
|
+
renderCms: () => /* @__PURE__ */ jsx(McpScreen, {
|
|
77
|
+
bridge,
|
|
78
|
+
screen,
|
|
79
|
+
hostContext: context,
|
|
80
|
+
pendingPlan: pending,
|
|
81
|
+
onAppError: told.appError
|
|
82
|
+
})
|
|
83
|
+
};
|
|
84
|
+
bridge.watchHostContext((next) => {
|
|
85
|
+
const mode = next.theme === "dark" ? "dark" : "light";
|
|
86
|
+
if (mode !== host.mode) {
|
|
87
|
+
host.mode = mode;
|
|
88
|
+
setRebaseEmbedHost({ ...host });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return host;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The app's collections as this person may see them here: the project's own
|
|
95
|
+
* configs — with their components — narrowed as the server narrowed the ones
|
|
96
|
+
* it sent (`McpViewPayload` in the server's `mcp/mcp-view.ts`). A field the
|
|
97
|
+
* server left out is left out; one it made read-only is read-only; its
|
|
98
|
+
* security rules (the project's, and the one closing what the connection was
|
|
99
|
+
* not granted) are the ones checked. A collection the server sent nothing
|
|
100
|
+
* for is shown with every change closed: this screen did not ask for it.
|
|
101
|
+
*
|
|
102
|
+
* Where the app has no collections of its own (the view without a project),
|
|
103
|
+
* the server's configs are the collections.
|
|
104
|
+
*/
|
|
105
|
+
function narrowCollections(own, sent) {
|
|
106
|
+
if (own.length === 0) return [...sent];
|
|
107
|
+
const bySlug = new Map(sent.map((collection) => [collection.slug, collection]));
|
|
108
|
+
return own.map((collection) => {
|
|
109
|
+
const narrowed = bySlug.get(collection.slug);
|
|
110
|
+
if (!narrowed) return {
|
|
111
|
+
...collection,
|
|
112
|
+
securityRules: [...collection.securityRules ?? [], CLOSED]
|
|
113
|
+
};
|
|
114
|
+
const copy = { ...collection };
|
|
115
|
+
return Object.assign(copy, {
|
|
116
|
+
properties: narrowProperties(collection.properties, narrowed.properties),
|
|
117
|
+
securityRules: narrowed.securityRules ?? collection.securityRules
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/** The fields the server sent, with its read-only marks; the project's own config for each. */
|
|
122
|
+
function narrowProperties(own, sent) {
|
|
123
|
+
const narrowed = { ...own };
|
|
124
|
+
for (const key of Object.keys(narrowed)) {
|
|
125
|
+
const sentProperty = sent[key];
|
|
126
|
+
if (!sentProperty) {
|
|
127
|
+
delete narrowed[key];
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const property = narrowed[key];
|
|
131
|
+
if (isRecord(sentProperty) && isRecord(sentProperty.admin) && sentProperty.admin.readOnly === true && isRecord(property)) Object.assign(narrowed, { [key]: {
|
|
132
|
+
...property,
|
|
133
|
+
admin: {
|
|
134
|
+
...isRecord(property.admin) ? property.admin : {},
|
|
135
|
+
readOnly: true
|
|
136
|
+
}
|
|
137
|
+
} });
|
|
138
|
+
}
|
|
139
|
+
return narrowed;
|
|
140
|
+
}
|
|
141
|
+
/** A restrictive rule no account passes, closing every change. */
|
|
142
|
+
var CLOSED = {
|
|
143
|
+
name: "mcp_view_not_opened",
|
|
144
|
+
mode: "restrictive",
|
|
145
|
+
operations: [
|
|
146
|
+
"insert",
|
|
147
|
+
"update",
|
|
148
|
+
"delete"
|
|
149
|
+
],
|
|
150
|
+
roles: ["__mcp_view_not_opened__"]
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* The person the server drew the screen for, as the admin panel asks about
|
|
154
|
+
* them: the security rules it evaluates before offering an action read
|
|
155
|
+
* `uid` and `roles`. Signing out means nothing here — the host holds the
|
|
156
|
+
* connection.
|
|
157
|
+
*/
|
|
158
|
+
function viewerAuth(viewer) {
|
|
159
|
+
return {
|
|
160
|
+
user: {
|
|
161
|
+
uid: viewer.uid,
|
|
162
|
+
displayName: null,
|
|
163
|
+
email: null,
|
|
164
|
+
photoURL: null,
|
|
165
|
+
providerId: "mcp",
|
|
166
|
+
isAnonymous: false,
|
|
167
|
+
roles: viewer.roles
|
|
168
|
+
},
|
|
169
|
+
initialLoading: false,
|
|
170
|
+
authLoading: false,
|
|
171
|
+
loginSkipped: true,
|
|
172
|
+
storageEnabled: false,
|
|
173
|
+
signOut: async () => void 0,
|
|
174
|
+
getAuthToken: async () => "",
|
|
175
|
+
extra: void 0,
|
|
176
|
+
setExtra: () => void 0
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* What the model is told, sent with the person's next message: the changes
|
|
181
|
+
* they made here, and an app's failure. Each update replaces the last, so
|
|
182
|
+
* both go every time.
|
|
183
|
+
*/
|
|
184
|
+
function modelContext(bridge) {
|
|
185
|
+
const state = {};
|
|
186
|
+
const send = () => {
|
|
187
|
+
const text = [state.changes, state.error].filter(Boolean).join("\n");
|
|
188
|
+
if (text) bridge.updateModelContext(text).catch(() => void 0);
|
|
189
|
+
};
|
|
190
|
+
return {
|
|
191
|
+
changes: (changes) => {
|
|
192
|
+
state.changes = describeChanges(changes);
|
|
193
|
+
send();
|
|
194
|
+
},
|
|
195
|
+
appError: (error) => {
|
|
196
|
+
state.error = describeAppError(error);
|
|
197
|
+
send();
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** An error where the app would be, before it could start. */
|
|
202
|
+
function showError(message) {
|
|
203
|
+
createRoot(document.getElementById("root") ?? document.body.appendChild(document.createElement("div"))).render(/* @__PURE__ */ jsx("div", {
|
|
204
|
+
className: "p-4",
|
|
205
|
+
children: /* @__PURE__ */ jsx(Alert, {
|
|
206
|
+
color: "error",
|
|
207
|
+
size: "small",
|
|
208
|
+
children: message
|
|
209
|
+
})
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* A host may sandbox the view without `allow-forms`, and then a form's submit
|
|
214
|
+
* button submits nothing: the browser drops the submission before the form's
|
|
215
|
+
* `submit` event — the admin panel's record form saves on that event. The
|
|
216
|
+
* click still happens, so it is turned into the event itself, after the click
|
|
217
|
+
* has finished (a button's own handler may say which save it was).
|
|
218
|
+
*/
|
|
219
|
+
function installSubmitFix() {
|
|
220
|
+
document.addEventListener("click", (event) => {
|
|
221
|
+
const button = event.target instanceof Element ? event.target.closest("button[type=submit]") : null;
|
|
222
|
+
if (!(button instanceof HTMLButtonElement) || !button.form || button.disabled) return;
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
const form = button.form;
|
|
225
|
+
setTimeout(() => form.dispatchEvent(new SubmitEvent("submit", {
|
|
226
|
+
bubbles: true,
|
|
227
|
+
cancelable: true,
|
|
228
|
+
submitter: button
|
|
229
|
+
})));
|
|
230
|
+
}, true);
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
export { narrowCollections, startMcpView };
|
|
234
|
+
|
|
235
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/mcp_view/index.tsx"],"sourcesContent":["/**\n * `@rebasepro/cms/mcp-view`: a project's admin app, inside an MCP App view.\n *\n * A client like Claude shows what the show_* tools open (a collection, a\n * record, an app the model wrote) in a sandboxed frame next to the\n * conversation. This is what runs in that frame: it speaks the host's\n * protocol, reads and writes through the server's tools as the person, and\n * draws with the admin panel's own components — inside the project's own\n * admin app, so its custom views, entity views, fields, previews, actions,\n * plugins and slots are the ones drawn.\n *\n * ```ts\n * // the project's view entry (the Vite plugin generates it)\n * import { startMcpView } from \"@rebasepro/cms/mcp-view\";\n * startMcpView({ mountApp: () => import(\"./main\") });\n * ```\n *\n * The app mounts as it does on its own page; `<Rebase>`, `<RebaseCMS>`,\n * `<RebaseStudio>` and `<RebaseShell>` find the embed host this sets\n * (`setRebaseEmbedHost` in `@rebasepro/app`) and stand in what the frame\n * cannot give them: data through the tools, the person already signed in,\n * no routes, no network.\n *\n * @module\n */\nimport React from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { setRebaseEmbedHost, type RebaseEmbedHost } from \"@rebasepro/app\";\nimport type { AdminCollection, AuthController } from \"@rebasepro/cms-types\";\nimport type { SecurityRule, User } from \"@rebasepro/types\";\nimport { Alert } from \"@rebasepro/ui\";\nimport { McpAppBridge, type HostContext, type ToolResult } from \"./bridge\";\nimport { createToolDriver, describeChanges, type ToolDriver, type ViewChange } from \"./tool_driver\";\nimport { findCollection, parseResult, type Screen } from \"./payload\";\nimport { describeAppError, type AppError } from \"./code_app\";\nimport { McpScreen, type PendingPlan } from \"./screen\";\nimport { VIEW_STORAGE_SOURCE } from \"./storage_source\";\nimport { createViewStore } from \"./store\";\n\nexport { APPS_PROTOCOL_VERSION, McpAppBridge, isRecord } from \"./bridge\";\nimport { isRecord } from \"./bridge\";\nexport type { HostContext, ToolResult, DisplayMode } from \"./bridge\";\nexport { createToolDriver, DEFAULT_ACTIONS, SaveCancelledError, describeChanges } from \"./tool_driver\";\nexport type { CallTool, SeedPage, ToolDriver, ViewActions, WritePlan, ViewChange } from \"./tool_driver\";\nexport { parseResult, actionsOf, filterOf } from \"./payload\";\nexport type { Screen, Block } from \"./payload\";\n\nexport interface McpViewOptions {\n /**\n * Mount the app, once the host is set: import the project's entry (which\n * renders its app as it would on its page), or render a default one into\n * `#root`. Given the screen the tool opened, for an app with no\n * collections of its own.\n */\n mountApp: (screen: Screen) => void | Promise<unknown>;\n /**\n * Draw a result from a server that predates the admin panel's views\n * (show_collection's columns only): the old table, where the view has it.\n */\n mountTable?: (bridge: McpAppBridge, container: HTMLElement) => void;\n /** Name and version the view gives the host. */\n appInfo?: { name: string; version: string };\n /** The channel to the host; a new one on this window's parent by default. */\n bridge?: McpAppBridge;\n}\n\n/**\n * Connect to the host, wait for the tool's result, set the embed host from\n * it, and mount the app.\n */\nexport function startMcpView(options: McpViewOptions): McpAppBridge {\n installSubmitFix();\n const bridge = options.bridge ?? new McpAppBridge();\n let started = false;\n\n bridge.ontoolresult = (result: ToolResult) => {\n if (started) return;\n started = true;\n const parsed = parseResult(result);\n if (parsed.kind === \"table\") {\n const container = document.getElementById(\"root\");\n if (container && options.mountTable) options.mountTable(bridge, container);\n else showError(\"This view cannot draw this result.\");\n return;\n }\n if (parsed.kind === \"error\") {\n showError(parsed.message);\n return;\n }\n setRebaseEmbedHost(embedHost(bridge, parsed.screen));\n Promise.resolve(options.mountApp(parsed.screen))\n .catch(error => showError(`The view could not start: ${error instanceof Error ? error.message : String(error)}`));\n };\n\n // The host's light or dark, on the class the UI kit's `dark:` variant reads.\n bridge.watchHostContext(context => {\n if (context.theme) document.documentElement.classList.toggle(\"dark\", context.theme === \"dark\");\n });\n\n void bridge.connect(options.appInfo ?? { name: \"rebase\", version: \"0.3.0\" });\n return bridge;\n}\n\n/** What the app runs on, here: the tools, the person, the frame's storage and theme, and the screen to draw. */\nfunction embedHost(bridge: McpAppBridge, screen: Screen): RebaseEmbedHost {\n const pending = createViewStore<PendingPlan | undefined>(undefined);\n const context = createViewStore<HostContext>(bridge.hostContext);\n bridge.watchHostContext(next => context.set(next));\n\n const told = modelContext(bridge);\n const tools: ToolDriver = createToolDriver({\n callTool: (name, args) => bridge.callTool(name, args),\n actions: screen.actions,\n ...(screen.firstPage && { seed: screen.firstPage }),\n ...(screen.seeds && { seeds: screen.seeds }),\n // A collection by whichever name it was read or written under: its\n // data path (the tools' name, the model's) or its slug (the admin's).\n collection: name => findCollection(screen.collections, name),\n confirm: plan => new Promise<boolean>(resolve => pending.set({\n plan,\n answer: confirmed => {\n pending.set(undefined);\n resolve(confirmed);\n }\n })),\n onChange: told.changes\n });\n\n const host: RebaseEmbedHost = {\n dataDriver: tools.driver,\n // Code can write without a click, so the row hooks ask the person\n // before each write; a save made with the admin's own controls goes\n // as on any screen. A courtesy, not the boundary: every call is the\n // server's tool as the person, under their RLS and granted scopes.\n rowHooksDriver: tools.confirmingDriver,\n authController: viewerAuth(screen.viewer),\n storageSource: VIEW_STORAGE_SOURCE,\n mode: bridge.hostContext.theme === \"dark\" ? \"dark\" : \"light\",\n narrowCollections: collections => narrowCollections(collections, screen.collections),\n renderCms: () => (\n <McpScreen\n bridge={bridge}\n screen={screen}\n hostContext={context}\n pendingPlan={pending}\n onAppError={told.appError}\n />\n )\n };\n // The theme follows the host's.\n bridge.watchHostContext(next => {\n const mode = next.theme === \"dark\" ? \"dark\" : \"light\";\n if (mode !== host.mode) {\n host.mode = mode;\n setRebaseEmbedHost({ ...host });\n }\n });\n return host;\n}\n\n/**\n * The app's collections as this person may see them here: the project's own\n * configs — with their components — narrowed as the server narrowed the ones\n * it sent (`McpViewPayload` in the server's `mcp/mcp-view.ts`). A field the\n * server left out is left out; one it made read-only is read-only; its\n * security rules (the project's, and the one closing what the connection was\n * not granted) are the ones checked. A collection the server sent nothing\n * for is shown with every change closed: this screen did not ask for it.\n *\n * Where the app has no collections of its own (the view without a project),\n * the server's configs are the collections.\n */\nexport function narrowCollections(own: AdminCollection[], sent: readonly AdminCollection[]): AdminCollection[] {\n if (own.length === 0) return [...sent];\n const bySlug = new Map(sent.map(collection => [collection.slug, collection]));\n return own.map((collection): AdminCollection => {\n const narrowed = bySlug.get(collection.slug);\n if (!narrowed) {\n return { ...collection, securityRules: [...(collection.securityRules ?? []), CLOSED] };\n }\n const copy = { ...collection };\n return Object.assign(copy, {\n properties: narrowProperties(collection.properties, narrowed.properties),\n securityRules: narrowed.securityRules ?? collection.securityRules\n });\n });\n}\n\n/** The fields the server sent, with its read-only marks; the project's own config for each. */\nfunction narrowProperties<P extends Record<string, unknown>>(own: P, sent: Record<string, unknown>): P {\n const narrowed = { ...own };\n for (const key of Object.keys(narrowed)) {\n const sentProperty = sent[key];\n if (!sentProperty) {\n delete narrowed[key];\n continue;\n }\n const property = narrowed[key];\n if (isRecord(sentProperty) && isRecord(sentProperty.admin) && sentProperty.admin.readOnly === true && isRecord(property)) {\n Object.assign(narrowed, { [key]: { ...property, admin: { ...(isRecord(property.admin) ? property.admin : {}), readOnly: true } } });\n }\n }\n return narrowed;\n}\n\n/** A restrictive rule no account passes, closing every change. */\nconst CLOSED: SecurityRule = {\n name: \"mcp_view_not_opened\",\n mode: \"restrictive\",\n operations: [\"insert\", \"update\", \"delete\"],\n roles: [\"__mcp_view_not_opened__\"]\n};\n\n/**\n * The person the server drew the screen for, as the admin panel asks about\n * them: the security rules it evaluates before offering an action read\n * `uid` and `roles`. Signing out means nothing here — the host holds the\n * connection.\n */\nfunction viewerAuth(viewer: Screen[\"viewer\"]): AuthController {\n const user: User = {\n uid: viewer.uid,\n displayName: null,\n email: null,\n photoURL: null,\n providerId: \"mcp\",\n isAnonymous: false,\n roles: viewer.roles\n };\n return {\n user,\n initialLoading: false,\n authLoading: false,\n loginSkipped: true,\n storageEnabled: false,\n signOut: async () => undefined,\n getAuthToken: async () => \"\",\n extra: undefined,\n setExtra: () => undefined\n };\n}\n\n/**\n * What the model is told, sent with the person's next message: the changes\n * they made here, and an app's failure. Each update replaces the last, so\n * both go every time.\n */\nfunction modelContext(bridge: McpAppBridge) {\n const state: { changes?: string; error?: string } = {};\n const send = () => {\n const text = [state.changes, state.error].filter(Boolean).join(\"\\n\");\n if (text) void bridge.updateModelContext(text).catch(() => undefined);\n };\n return {\n changes: (changes: readonly ViewChange[]) => {\n state.changes = describeChanges(changes);\n send();\n },\n appError: (error: AppError) => {\n state.error = describeAppError(error);\n send();\n }\n };\n}\n\n/** An error where the app would be, before it could start. */\nfunction showError(message: string): void {\n const container = document.getElementById(\"root\") ?? document.body.appendChild(document.createElement(\"div\"));\n createRoot(container).render(<div className=\"p-4\"><Alert color=\"error\" size=\"small\">{message}</Alert></div>);\n}\n\n/**\n * A host may sandbox the view without `allow-forms`, and then a form's submit\n * button submits nothing: the browser drops the submission before the form's\n * `submit` event — the admin panel's record form saves on that event. The\n * click still happens, so it is turned into the event itself, after the click\n * has finished (a button's own handler may say which save it was).\n */\nfunction installSubmitFix(): void {\n document.addEventListener(\"click\", (event) => {\n const button = event.target instanceof Element ? event.target.closest(\"button[type=submit]\") : null;\n if (!(button instanceof HTMLButtonElement) || !button.form || button.disabled) return;\n event.preventDefault();\n const form = button.form;\n setTimeout(() => form.dispatchEvent(new SubmitEvent(\"submit\", { bubbles: true, cancelable: true, submitter: button })));\n }, true);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsEA,SAAgB,aAAa,SAAuC;CAChE,iBAAiB;CACjB,MAAM,SAAS,QAAQ,UAAU,IAAI,aAAa;CAClD,IAAI,UAAU;CAEd,OAAO,gBAAgB,WAAuB;EAC1C,IAAI,SAAS;EACb,UAAU;EACV,MAAM,SAAS,YAAY,MAAM;EACjC,IAAI,OAAO,SAAS,SAAS;GACzB,MAAM,YAAY,SAAS,eA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aAAS;EAAe,CAAA;CAAM,CAAA,CAAC;AAC/G;;;;;;;;AASA,SAAS,mBAAyB;CAC9B,SAAS,iBAAiB,UAAU,UAAU;EAC1C,MAAM,SAAS,MAAM,kBAAkB,UAAU,MAAM,OAAO,QAAQ,qBAAqB,IAAI;EAC/F,IAAI,EAAE,kBAAkB,sBAAsB,CAAC,OAAO,QAAQ,OAAO,UAAU;EAC/E,MAAM,eAAe;EACrB,MAAM,OAAO,OAAO;EACpB,iBAAiB,KAAK,cAAc,IAAI,YAAY,UAAU;GAAE,SAAS;GAAM,YAAY;GAAM,WAAW;EAAO,CAAC,CAAC,CAAC;CAC1H,GAAG,IAAI;AACX"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The screen a show_* tool asked for, read from its result
|
|
3
|
+
* (`McpViewPayload` in the server's `mcp/mcp-view.ts`).
|
|
4
|
+
*
|
|
5
|
+
* A result with no payload is one from a server that only knew the table
|
|
6
|
+
* (show_collection before 0.29): the view draws that table.
|
|
7
|
+
*/
|
|
8
|
+
import { type FilterValues } from "@rebasepro/types";
|
|
9
|
+
import type { AdminCollection } from "@rebasepro/cms-types";
|
|
10
|
+
import { type ToolResult } from "./bridge.js";
|
|
11
|
+
import { type SeedPage, type ViewActions } from "./tool_driver.js";
|
|
12
|
+
export type ViewMode = "table" | "list" | "cards" | "kanban";
|
|
13
|
+
export interface CollectionBlock {
|
|
14
|
+
key: string;
|
|
15
|
+
type: "collection";
|
|
16
|
+
collection: string;
|
|
17
|
+
view?: ViewMode;
|
|
18
|
+
where?: Record<string, unknown>;
|
|
19
|
+
orderBy?: unknown;
|
|
20
|
+
searchString?: string;
|
|
21
|
+
limit?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface RecordBlock {
|
|
24
|
+
key: string;
|
|
25
|
+
type: "record";
|
|
26
|
+
collection: string;
|
|
27
|
+
id?: string;
|
|
28
|
+
values?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/** An app the model wrote: compiled CommonJS, and the collections it reads. */
|
|
31
|
+
export interface AppBlock {
|
|
32
|
+
key: string;
|
|
33
|
+
type: "app";
|
|
34
|
+
code: string;
|
|
35
|
+
collections: string[];
|
|
36
|
+
}
|
|
37
|
+
export type Block = CollectionBlock | RecordBlock | AppBlock;
|
|
38
|
+
export interface Screen {
|
|
39
|
+
title?: string;
|
|
40
|
+
blocks: Block[];
|
|
41
|
+
collections: AdminCollection[];
|
|
42
|
+
viewer: {
|
|
43
|
+
uid: string;
|
|
44
|
+
roles: string[];
|
|
45
|
+
};
|
|
46
|
+
actions: ViewActions;
|
|
47
|
+
/** The page show_collection read for the model: what the collection block reads first. */
|
|
48
|
+
firstPage?: SeedPage;
|
|
49
|
+
/** The pages show_app read ahead of the app's first render, one per collection it names. */
|
|
50
|
+
seeds?: SeedPage[];
|
|
51
|
+
}
|
|
52
|
+
export type Parsed = {
|
|
53
|
+
kind: "screen";
|
|
54
|
+
screen: Screen;
|
|
55
|
+
}
|
|
56
|
+
/** A result from before the admin panel's views: the table's own columns. */
|
|
57
|
+
| {
|
|
58
|
+
kind: "table";
|
|
59
|
+
} | {
|
|
60
|
+
kind: "error";
|
|
61
|
+
message: string;
|
|
62
|
+
};
|
|
63
|
+
export declare function parseResult(result: ToolResult): Parsed;
|
|
64
|
+
/**
|
|
65
|
+
* The tools a result says to read and write with, over the defaults. The
|
|
66
|
+
* hosted connector's table named `edit` for what is `update` here.
|
|
67
|
+
*/
|
|
68
|
+
export declare function actionsOf(raw: unknown): ViewActions;
|
|
69
|
+
/** The collection a block names: by the name the tools take, which is its data path, or by slug. */
|
|
70
|
+
export declare function findCollection(collections: readonly AdminCollection[], name: string): AdminCollection | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* A block's `where` as the admin panel's filter: each field's condition, or
|
|
73
|
+
* list of conditions, kept where it is one the read tools take. The server
|
|
74
|
+
* checked it before it opened the screen.
|
|
75
|
+
*/
|
|
76
|
+
export declare function filterOf(where: Record<string, unknown> | undefined): FilterValues<string> | undefined;
|
|
77
|
+
/** A sort as the collection view takes it: its first key. */
|
|
78
|
+
export declare function orderOf(raw: unknown): [string, "asc" | "desc"] | undefined;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { isRecord } from "./bridge.js";
|
|
2
|
+
import { DEFAULT_ACTIONS, textOf } from "./tool_driver.js";
|
|
3
|
+
import { ALL_WHERE_FILTER_OPS, deserializeCollections, getCollectionDataPath } from "@rebasepro/types";
|
|
4
|
+
//#region src/mcp_view/payload.ts
|
|
5
|
+
/**
|
|
6
|
+
* The screen a show_* tool asked for, read from its result
|
|
7
|
+
* (`McpViewPayload` in the server's `mcp/mcp-view.ts`).
|
|
8
|
+
*
|
|
9
|
+
* A result with no payload is one from a server that only knew the table
|
|
10
|
+
* (show_collection before 0.29): the view draws that table.
|
|
11
|
+
*/
|
|
12
|
+
var PAYLOAD_VERSION = 1;
|
|
13
|
+
function parseResult(result) {
|
|
14
|
+
if (result.isError) return {
|
|
15
|
+
kind: "error",
|
|
16
|
+
message: textOf(result) ?? "The view could not be opened."
|
|
17
|
+
};
|
|
18
|
+
const content = result.structuredContent;
|
|
19
|
+
if (!isRecord(content)) return {
|
|
20
|
+
kind: "error",
|
|
21
|
+
message: "This view needs the tool's structured result, and the host did not pass it."
|
|
22
|
+
};
|
|
23
|
+
const view = content.view;
|
|
24
|
+
if (!isRecord(view)) return Array.isArray(content.columns) ? { kind: "table" } : {
|
|
25
|
+
kind: "error",
|
|
26
|
+
message: "The result carries nothing this view can draw."
|
|
27
|
+
};
|
|
28
|
+
if (view.version !== PAYLOAD_VERSION) return {
|
|
29
|
+
kind: "error",
|
|
30
|
+
message: "This view is older than the server that answered; it cannot draw this screen."
|
|
31
|
+
};
|
|
32
|
+
const collections = Array.isArray(view.collections) ? deserializeCollections(view.collections) : [];
|
|
33
|
+
const blocks = Array.isArray(view.blocks) ? view.blocks.filter(isBlock) : [];
|
|
34
|
+
if (blocks.length === 0) return {
|
|
35
|
+
kind: "error",
|
|
36
|
+
message: "The screen has no blocks."
|
|
37
|
+
};
|
|
38
|
+
const viewer = isRecord(view.viewer) ? view.viewer : {};
|
|
39
|
+
const firstPage = firstPageOf(blocks[0], content);
|
|
40
|
+
const seeds = Array.isArray(view.seeds) ? view.seeds.flatMap(seedOf) : [];
|
|
41
|
+
return {
|
|
42
|
+
kind: "screen",
|
|
43
|
+
screen: {
|
|
44
|
+
...typeof view.title === "string" && { title: view.title },
|
|
45
|
+
blocks,
|
|
46
|
+
collections,
|
|
47
|
+
viewer: {
|
|
48
|
+
uid: typeof viewer.uid === "string" ? viewer.uid : "",
|
|
49
|
+
roles: Array.isArray(viewer.roles) ? viewer.roles.filter((role) => typeof role === "string") : []
|
|
50
|
+
},
|
|
51
|
+
actions: actionsOf(content.actions),
|
|
52
|
+
...firstPage && { firstPage },
|
|
53
|
+
...seeds.length > 0 && { seeds }
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The rows a show_collection result carries beside its screen — the page the
|
|
59
|
+
* server read for the model — and the arguments that read them: the block's,
|
|
60
|
+
* with the window the server says it read.
|
|
61
|
+
*/
|
|
62
|
+
function firstPageOf(block, content) {
|
|
63
|
+
if (block.type !== "collection" || !Array.isArray(content.data)) return void 0;
|
|
64
|
+
const meta = isRecord(content.meta) ? content.meta : {};
|
|
65
|
+
const limit = typeof meta.limit === "number" ? meta.limit : block.limit;
|
|
66
|
+
return {
|
|
67
|
+
collection: block.collection,
|
|
68
|
+
args: {
|
|
69
|
+
...block.where && { where: block.where },
|
|
70
|
+
...block.orderBy !== void 0 && { orderBy: block.orderBy },
|
|
71
|
+
...block.searchString && { searchString: block.searchString },
|
|
72
|
+
...limit !== void 0 && { limit },
|
|
73
|
+
...typeof meta.offset === "number" && { offset: meta.offset }
|
|
74
|
+
},
|
|
75
|
+
rows: content.data.filter(isRecord)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** One page show_app read ahead, as the server sent it; nothing for one malformed. */
|
|
79
|
+
function seedOf(value) {
|
|
80
|
+
if (!isRecord(value) || typeof value.collection !== "string" || !isRecord(value.args) || !Array.isArray(value.rows)) return [];
|
|
81
|
+
return [{
|
|
82
|
+
collection: value.collection,
|
|
83
|
+
args: value.args,
|
|
84
|
+
rows: value.rows.filter(isRecord),
|
|
85
|
+
...typeof value.total === "number" && { total: value.total }
|
|
86
|
+
}];
|
|
87
|
+
}
|
|
88
|
+
function isBlock(value) {
|
|
89
|
+
if (!isRecord(value) || typeof value.key !== "string") return false;
|
|
90
|
+
if (value.type === "app") return typeof value.code === "string" && Array.isArray(value.collections);
|
|
91
|
+
return typeof value.collection === "string" && (value.type === "collection" || value.type === "record");
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The tools a result says to read and write with, over the defaults. The
|
|
95
|
+
* hosted connector's table named `edit` for what is `update` here.
|
|
96
|
+
*/
|
|
97
|
+
function actionsOf(raw) {
|
|
98
|
+
if (!isRecord(raw)) return DEFAULT_ACTIONS;
|
|
99
|
+
const action = (value, fallback) => isRecord(value) && typeof value.tool === "string" ? {
|
|
100
|
+
tool: value.tool,
|
|
101
|
+
arguments: isRecord(value.arguments) ? value.arguments : {},
|
|
102
|
+
...value.plans === true && { plans: true }
|
|
103
|
+
} : fallback;
|
|
104
|
+
return {
|
|
105
|
+
page: action(raw.page, DEFAULT_ACTIONS.page),
|
|
106
|
+
get: action(raw.get, DEFAULT_ACTIONS.get),
|
|
107
|
+
count: action(raw.count, DEFAULT_ACTIONS.count),
|
|
108
|
+
create: action(raw.create, DEFAULT_ACTIONS.create),
|
|
109
|
+
update: action(raw.update ?? raw.edit, DEFAULT_ACTIONS.update),
|
|
110
|
+
delete: action(raw.delete, DEFAULT_ACTIONS.delete),
|
|
111
|
+
aggregate: action(raw.aggregate, DEFAULT_ACTIONS.aggregate)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** The collection a block names: by the name the tools take, which is its data path, or by slug. */
|
|
115
|
+
function findCollection(collections, name) {
|
|
116
|
+
return collections.find((collection) => getCollectionDataPath(collection) === name) ?? collections.find((collection) => collection.slug === name);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A block's `where` as the admin panel's filter: each field's condition, or
|
|
120
|
+
* list of conditions, kept where it is one the read tools take. The server
|
|
121
|
+
* checked it before it opened the screen.
|
|
122
|
+
*/
|
|
123
|
+
function filterOf(where) {
|
|
124
|
+
if (!where) return void 0;
|
|
125
|
+
const filter = {};
|
|
126
|
+
for (const [key, raw] of Object.entries(where)) {
|
|
127
|
+
const single = conditionOf(raw);
|
|
128
|
+
if (single) filter[key] = single;
|
|
129
|
+
else if (Array.isArray(raw)) {
|
|
130
|
+
const conditions = raw.map(conditionOf).filter((entry) => entry !== void 0);
|
|
131
|
+
if (conditions.length > 0 && conditions.length === raw.length) filter[key] = conditions;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return filter;
|
|
135
|
+
}
|
|
136
|
+
function conditionOf(raw) {
|
|
137
|
+
if (!Array.isArray(raw) || raw.length !== 2) return void 0;
|
|
138
|
+
const op = ALL_WHERE_FILTER_OPS.find((candidate) => candidate === raw[0]);
|
|
139
|
+
return op ? [op, raw[1]] : void 0;
|
|
140
|
+
}
|
|
141
|
+
/** A sort as the collection view takes it: its first key. */
|
|
142
|
+
function orderOf(raw) {
|
|
143
|
+
if (typeof raw === "string" && raw !== "") {
|
|
144
|
+
const [field, direction] = raw.split(":");
|
|
145
|
+
return [field, direction === "desc" ? "desc" : "asc"];
|
|
146
|
+
}
|
|
147
|
+
if (Array.isArray(raw) && raw.length > 0) {
|
|
148
|
+
const first = Array.isArray(raw[0]) ? raw[0] : raw;
|
|
149
|
+
if (typeof first[0] === "string") return [first[0], first[1] === "desc" ? "desc" : "asc"];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
export { actionsOf, filterOf, findCollection, orderOf, parseResult };
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.js","names":[],"sources":["../../src/mcp_view/payload.ts"],"sourcesContent":["/**\n * The screen a show_* tool asked for, read from its result\n * (`McpViewPayload` in the server's `mcp/mcp-view.ts`).\n *\n * A result with no payload is one from a server that only knew the table\n * (show_collection before 0.29): the view draws that table.\n */\nimport {\n ALL_WHERE_FILTER_OPS,\n deserializeCollections,\n getCollectionDataPath,\n type CollectionConfig,\n type FilterValues,\n type WhereFilterOp\n} from \"@rebasepro/types\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\nimport { isRecord, type ToolResult } from \"./bridge\";\nimport { DEFAULT_ACTIONS, textOf, type SeedPage, type ToolAction, type ViewActions } from \"./tool_driver\";\n\nexport type ViewMode = \"table\" | \"list\" | \"cards\" | \"kanban\";\n\nexport interface CollectionBlock {\n key: string;\n type: \"collection\";\n collection: string;\n view?: ViewMode;\n where?: Record<string, unknown>;\n orderBy?: unknown;\n searchString?: string;\n limit?: number;\n}\n\nexport interface RecordBlock {\n key: string;\n type: \"record\";\n collection: string;\n id?: string;\n values?: Record<string, unknown>;\n}\n\n/** An app the model wrote: compiled CommonJS, and the collections it reads. */\nexport interface AppBlock {\n key: string;\n type: \"app\";\n code: string;\n collections: string[];\n}\n\nexport type Block = CollectionBlock | RecordBlock | AppBlock;\n\nexport interface Screen {\n title?: string;\n blocks: Block[];\n collections: AdminCollection[];\n viewer: { uid: string; roles: string[] };\n actions: ViewActions;\n /** The page show_collection read for the model: what the collection block reads first. */\n firstPage?: SeedPage;\n /** The pages show_app read ahead of the app's first render, one per collection it names. */\n seeds?: SeedPage[];\n}\n\nexport type Parsed =\n | { kind: \"screen\"; screen: Screen }\n /** A result from before the admin panel's views: the table's own columns. */\n | { kind: \"table\" }\n | { kind: \"error\"; message: string };\n\nconst PAYLOAD_VERSION = 1;\n\nexport function parseResult(result: ToolResult): Parsed {\n if (result.isError) return { kind: \"error\", message: textOf(result) ?? \"The view could not be opened.\" };\n const content = result.structuredContent;\n if (!isRecord(content)) {\n return { kind: \"error\", message: \"This view needs the tool's structured result, and the host did not pass it.\" };\n }\n const view = content.view;\n if (!isRecord(view)) {\n return Array.isArray(content.columns)\n ? { kind: \"table\" }\n : { kind: \"error\", message: \"The result carries nothing this view can draw.\" };\n }\n if (view.version !== PAYLOAD_VERSION) {\n return { kind: \"error\", message: \"This view is older than the server that answered; it cannot draw this screen.\" };\n }\n const collections = Array.isArray(view.collections)\n ? deserializeCollections(view.collections) as AdminCollection[]\n : [];\n const blocks = Array.isArray(view.blocks) ? view.blocks.filter(isBlock) : [];\n if (blocks.length === 0) return { kind: \"error\", message: \"The screen has no blocks.\" };\n const viewer = isRecord(view.viewer) ? view.viewer : {};\n const firstPage = firstPageOf(blocks[0], content);\n const seeds = Array.isArray(view.seeds) ? view.seeds.flatMap(seedOf) : [];\n return {\n kind: \"screen\",\n screen: {\n ...(typeof view.title === \"string\" && { title: view.title }),\n blocks,\n collections,\n viewer: {\n uid: typeof viewer.uid === \"string\" ? viewer.uid : \"\",\n roles: Array.isArray(viewer.roles) ? viewer.roles.filter((role): role is string => typeof role === \"string\") : []\n },\n actions: actionsOf(content.actions),\n ...(firstPage && { firstPage }),\n ...(seeds.length > 0 && { seeds })\n }\n };\n}\n\n/**\n * The rows a show_collection result carries beside its screen — the page the\n * server read for the model — and the arguments that read them: the block's,\n * with the window the server says it read.\n */\nfunction firstPageOf(block: Block, content: Record<string, unknown>): SeedPage | undefined {\n if (block.type !== \"collection\" || !Array.isArray(content.data)) return undefined;\n const meta = isRecord(content.meta) ? content.meta : {};\n const limit = typeof meta.limit === \"number\" ? meta.limit : block.limit;\n return {\n collection: block.collection,\n args: {\n ...(block.where && { where: block.where }),\n ...(block.orderBy !== undefined && { orderBy: block.orderBy }),\n ...(block.searchString && { searchString: block.searchString }),\n ...(limit !== undefined && { limit }),\n ...(typeof meta.offset === \"number\" && { offset: meta.offset })\n },\n rows: content.data.filter(isRecord)\n };\n}\n\n/** One page show_app read ahead, as the server sent it; nothing for one malformed. */\nfunction seedOf(value: unknown): SeedPage[] {\n if (!isRecord(value) || typeof value.collection !== \"string\" || !isRecord(value.args) || !Array.isArray(value.rows)) return [];\n return [{\n collection: value.collection,\n args: value.args,\n rows: value.rows.filter(isRecord),\n ...(typeof value.total === \"number\" && { total: value.total })\n }];\n}\n\nfunction isBlock(value: unknown): value is Block {\n if (!isRecord(value) || typeof value.key !== \"string\") return false;\n if (value.type === \"app\") return typeof value.code === \"string\" && Array.isArray(value.collections);\n return typeof value.collection === \"string\" && (value.type === \"collection\" || value.type === \"record\");\n}\n\n/**\n * The tools a result says to read and write with, over the defaults. The\n * hosted connector's table named `edit` for what is `update` here.\n */\nexport function actionsOf(raw: unknown): ViewActions {\n if (!isRecord(raw)) return DEFAULT_ACTIONS;\n const action = (value: unknown, fallback: ToolAction): ToolAction => isRecord(value) && typeof value.tool === \"string\"\n ? { tool: value.tool, arguments: isRecord(value.arguments) ? value.arguments : {}, ...(value.plans === true && { plans: true }) }\n : fallback;\n return {\n page: action(raw.page, DEFAULT_ACTIONS.page),\n get: action(raw.get, DEFAULT_ACTIONS.get),\n count: action(raw.count, DEFAULT_ACTIONS.count),\n create: action(raw.create, DEFAULT_ACTIONS.create),\n update: action(raw.update ?? raw.edit, DEFAULT_ACTIONS.update),\n delete: action(raw.delete, DEFAULT_ACTIONS.delete),\n aggregate: action(raw.aggregate, DEFAULT_ACTIONS.aggregate)\n };\n}\n\n/** The collection a block names: by the name the tools take, which is its data path, or by slug. */\nexport function findCollection(collections: readonly AdminCollection[], name: string): AdminCollection | undefined {\n return collections.find(collection => getCollectionDataPath(collection as CollectionConfig) === name)\n ?? collections.find(collection => collection.slug === name);\n}\n\n/**\n * A block's `where` as the admin panel's filter: each field's condition, or\n * list of conditions, kept where it is one the read tools take. The server\n * checked it before it opened the screen.\n */\nexport function filterOf(where: Record<string, unknown> | undefined): FilterValues<string> | undefined {\n if (!where) return undefined;\n const filter: FilterValues<string> = {};\n for (const [key, raw] of Object.entries(where)) {\n const single = conditionOf(raw);\n if (single) {\n filter[key] = single;\n } else if (Array.isArray(raw)) {\n const conditions = raw.map(conditionOf).filter((entry): entry is [WhereFilterOp, unknown] => entry !== undefined);\n if (conditions.length > 0 && conditions.length === raw.length) filter[key] = conditions;\n }\n }\n return filter;\n}\n\nfunction conditionOf(raw: unknown): [WhereFilterOp, unknown] | undefined {\n if (!Array.isArray(raw) || raw.length !== 2) return undefined;\n const op = ALL_WHERE_FILTER_OPS.find(candidate => candidate === raw[0]);\n return op ? [op, raw[1]] : undefined;\n}\n\n/** A sort as the collection view takes it: its first key. */\nexport function orderOf(raw: unknown): [string, \"asc\" | \"desc\"] | undefined {\n if (typeof raw === \"string\" && raw !== \"\") {\n const [field, direction] = raw.split(\":\");\n return [field, direction === \"desc\" ? \"desc\" : \"asc\"];\n }\n if (Array.isArray(raw) && raw.length > 0) {\n const first: unknown[] = Array.isArray(raw[0]) ? raw[0] : raw;\n if (typeof first[0] === \"string\") return [first[0], first[1] === \"desc\" ? \"desc\" : \"asc\"];\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;AAoEA,IAAM,kBAAkB;AAExB,SAAgB,YAAY,QAA4B;CACpD,IAAI,OAAO,SAAS,OAAO;EAAE,MAAM;EAAS,SAAS,OAAO,MAAM,KAAK;CAAgC;CACvG,MAAM,UAAU,OAAO;CACvB,IAAI,CAAC,SAAS,OAAO,GACjB,OAAO;EAAE,MAAM;EAAS,SAAS;CAA8E;CAEnH,MAAM,OAAO,QAAQ;CACrB,IAAI,CAAC,SAAS,IAAI,GACd,OAAO,MAAM,QAAQ,QAAQ,OAAO,IAC9B,EAAE,MAAM,QAAQ,IAChB;EAAE,MAAM;EAAS,SAAS;CAAiD;CAErF,IAAI,KAAK,YAAY,iBACjB,OAAO;EAAE,MAAM;EAAS,SAAS;CAAgF;CAErH,MAAM,cAAc,MAAM,QAAQ,KAAK,WAAW,IAC5C,uBAAu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AAI,OAAO,MAAM,OAAO,UAAU,OAAO,CAAC,MAAM,IAAI,MAAM,OAAO,SAAS,SAAS,KAAK;CAC5F;AAEJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { HostContext, McpAppBridge } from "./bridge.js";
|
|
3
|
+
import type { WritePlan } from "./tool_driver.js";
|
|
4
|
+
import { type Screen } from "./payload.js";
|
|
5
|
+
import { type AppError } from "./code_app.js";
|
|
6
|
+
import { type ViewStore } from "./store.js";
|
|
7
|
+
/** A write's plan waiting for the person's answer. */
|
|
8
|
+
export interface PendingPlan {
|
|
9
|
+
plan: WritePlan;
|
|
10
|
+
answer: (confirmed: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface McpScreenProps {
|
|
13
|
+
bridge: McpAppBridge;
|
|
14
|
+
screen: Screen;
|
|
15
|
+
/** The host's context, as it changes. */
|
|
16
|
+
hostContext: ViewStore<HostContext>;
|
|
17
|
+
/** The write plan to confirm, as it changes. */
|
|
18
|
+
pendingPlan: ViewStore<PendingPlan | undefined>;
|
|
19
|
+
onAppError: (error: AppError) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* What the embedded app's shell draws (`renderCms` of the embed host): the
|
|
23
|
+
* one block the tool opened — a collection, a record, or an app the model
|
|
24
|
+
* wrote — inside the providers the app's own `<RebaseShell>` set up, so its
|
|
25
|
+
* collections, custom views, entity views, fields and actions are the ones
|
|
26
|
+
* drawn.
|
|
27
|
+
*/
|
|
28
|
+
export declare function McpScreen({ bridge, screen, hostContext, pendingPlan, onAppError }: McpScreenProps): React.JSX.Element;
|