diff --git a/docs/en/dev/openapi-scopes.md b/docs/en/dev/openapi-scopes.md index c995ccc8110..e713d33dcc2 100644 --- a/docs/en/dev/openapi-scopes.md +++ b/docs/en/dev/openapi-scopes.md @@ -256,14 +256,14 @@ Manage plugins, plugin configuration, plugin sources, and marketplace data. | `GET` | `/api/v1/plugins/page-bridge-sdk.js` | — | | `GET` | `/api/v1/plugins/page/assets` | — | | `GET` | `/api/v1/plugins/pages` | — | -| `GET` | `/api/v1/plugins/views` | — | -| `GET` | `/api/v1/plugins/view` | — | -| `GET` | `/api/v1/plugins/view/assets` | — | | `GET` | `/api/v1/plugins/readme` | — | | `POST` | `/api/v1/plugins/reload` | — | | `POST` | `/api/v1/plugins/update` | — | | `POST` | `/api/v1/plugins/validate/repo` | — | | `POST` | `/api/v1/plugins/version-support/check` | — | +| `GET` | `/api/v1/plugins/view` | — | +| `GET` | `/api/v1/plugins/view/assets` | — | +| `GET` | `/api/v1/plugins/views` | — | | `GET` | `/api/v1/plugins/{plugin_id}` | — | | `DELETE` | `/api/v1/plugins/{plugin_id}` | — | | `GET` | `/api/v1/plugins/{plugin_id}/changelog` | — | @@ -278,13 +278,13 @@ Manage plugins, plugin configuration, plugin sources, and marketplace data. | `GET` | `/api/v1/plugins/{plugin_id}/pages` | — | | `GET` | `/api/v1/plugins/{plugin_id}/pages/{page_name}` | — | | `GET` | `/api/v1/plugins/{plugin_id}/pages/{page_name}/assets/{asset_path}` | — | -| `GET` | `/api/v1/plugins/{plugin_id}/views` | — | -| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}` | — | -| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}` | — | | `GET` | `/api/v1/plugins/{plugin_id}/readme` | — | | `POST` | `/api/v1/plugins/{plugin_id}/reload` | — | | `POST` | `/api/v1/plugins/{plugin_id}/source` | — | | `POST` | `/api/v1/plugins/{plugin_id}/update` | — | +| `GET` | `/api/v1/plugins/{plugin_id}/views` | — | +| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}` | — | +| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}` | — | ## `mcp` diff --git a/docs/public/openapi.json b/docs/public/openapi.json index 646690e6655..11e8cef7fbd 100644 --- a/docs/public/openapi.json +++ b/docs/public/openapi.json @@ -4398,6 +4398,196 @@ "description": "**Required scope:** `plugin`" } }, + "/api/v1/plugins/views": { + "get": { + "tags": [ + "Plugin Pages" + ], + "summary": "List plugin views by query ID (alias of /plugins/pages)", + "operationId": "listPluginViewsById", + "x-astrbot-scope": "plugin", + "parameters": [ + { + "name": "plugin_id", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/Ok" + } + }, + "description": "**Required scope:** `plugin`" + } + }, + "/api/v1/plugins/view": { + "get": { + "tags": [ + "Plugin Pages" + ], + "summary": "Get plugin view entry HTML by query ID (alias of /plugins/page)", + "operationId": "getPluginViewById", + "x-astrbot-scope": "plugin", + "parameters": [ + { + "name": "plugin_id", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "page_name", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/Html" + } + }, + "description": "**Required scope:** `plugin`" + } + }, + "/api/v1/plugins/view/assets": { + "get": { + "tags": [ + "Plugin Pages" + ], + "summary": "Get a plugin view asset by query ID (alias of /plugins/page/assets)", + "operationId": "getPluginViewAssetById", + "x-astrbot-scope": "plugin", + "parameters": [ + { + "name": "plugin_id", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "page_name", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "asset_path", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Plugin asset content" + } + }, + "description": "**Required scope:** `plugin`" + } + }, + "/api/v1/plugins/{plugin_id}/views": { + "get": { + "tags": [ + "Plugin Pages" + ], + "summary": "List plugin views (alias of /plugins/{plugin_id}/pages)", + "operationId": "listPluginViews", + "x-astrbot-scope": "plugin", + "parameters": [ + { + "$ref": "#/components/parameters/PluginId" + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/Ok" + } + }, + "description": "**Required scope:** `plugin`" + } + }, + "/api/v1/plugins/{plugin_id}/views/{page_name}": { + "get": { + "tags": [ + "Plugin Pages" + ], + "summary": "Get plugin view entry HTML (alias of /plugins/{plugin_id}/pages/{page_name})", + "operationId": "getPluginView", + "x-astrbot-scope": "plugin", + "parameters": [ + { + "$ref": "#/components/parameters/PluginId" + }, + { + "name": "page_name", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "$ref": "#/components/responses/Html" + } + }, + "description": "**Required scope:** `plugin`" + } + }, + "/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}": { + "get": { + "tags": [ + "Plugin Pages" + ], + "summary": "Get a plugin view asset (alias of /plugins/{plugin_id}/pages/{page_name}/assets/{asset_path})", + "operationId": "getPluginViewAsset", + "x-astrbot-scope": "plugin", + "parameters": [ + { + "$ref": "#/components/parameters/PluginId" + }, + { + "name": "page_name", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "asset_path", + "in": "path", + "required": true, + "description": "URL-encoded relative asset path.", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Plugin asset content" + } + }, + "description": "**Required scope:** `plugin`" + } + }, "/api/v1/plugins/page-bridge-sdk.js": { "get": { "tags": [ diff --git a/docs/zh/dev/openapi-scopes.md b/docs/zh/dev/openapi-scopes.md index 53b06ea9949..f89d766e3b5 100644 --- a/docs/zh/dev/openapi-scopes.md +++ b/docs/zh/dev/openapi-scopes.md @@ -256,14 +256,14 @@ outline: deep | `GET` | `/api/v1/plugins/page-bridge-sdk.js` | — | | `GET` | `/api/v1/plugins/page/assets` | — | | `GET` | `/api/v1/plugins/pages` | — | -| `GET` | `/api/v1/plugins/views` | — | -| `GET` | `/api/v1/plugins/view` | — | -| `GET` | `/api/v1/plugins/view/assets` | — | | `GET` | `/api/v1/plugins/readme` | — | | `POST` | `/api/v1/plugins/reload` | — | | `POST` | `/api/v1/plugins/update` | — | | `POST` | `/api/v1/plugins/validate/repo` | — | | `POST` | `/api/v1/plugins/version-support/check` | — | +| `GET` | `/api/v1/plugins/view` | — | +| `GET` | `/api/v1/plugins/view/assets` | — | +| `GET` | `/api/v1/plugins/views` | — | | `GET` | `/api/v1/plugins/{plugin_id}` | — | | `DELETE` | `/api/v1/plugins/{plugin_id}` | — | | `GET` | `/api/v1/plugins/{plugin_id}/changelog` | — | @@ -278,13 +278,13 @@ outline: deep | `GET` | `/api/v1/plugins/{plugin_id}/pages` | — | | `GET` | `/api/v1/plugins/{plugin_id}/pages/{page_name}` | — | | `GET` | `/api/v1/plugins/{plugin_id}/pages/{page_name}/assets/{asset_path}` | — | -| `GET` | `/api/v1/plugins/{plugin_id}/views` | — | -| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}` | — | -| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}` | — | | `GET` | `/api/v1/plugins/{plugin_id}/readme` | — | | `POST` | `/api/v1/plugins/{plugin_id}/reload` | — | | `POST` | `/api/v1/plugins/{plugin_id}/source` | — | | `POST` | `/api/v1/plugins/{plugin_id}/update` | — | +| `GET` | `/api/v1/plugins/{plugin_id}/views` | — | +| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}` | — | +| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}` | — | ## `mcp` diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 583023d0407..948bd581197 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -2058,7 +2058,7 @@ async def test_plugin_page_content_issues_scoped_asset_token( bridge_response = await anonymous_client.get(bridge_sdk_url.group(1)) assert bridge_response.status_code == 200 bridge_js = (await bridge_response.get_data()).decode("utf-8") - assert "window.AstrBotPluginPage?.__setInitialContext" in bridge_js + assert "window.AstrBotPluginView?.__setInitialContext" in bridge_js assert '"locale": "zh-CN"' in bridge_js assert '"displayName": "插件页面演示"' in bridge_js assert '"pageTitle": "Bridge 演示页"' in bridge_js diff --git a/tests/test_plugin_manager.py b/tests/test_plugin_manager.py index 2bf27a2aac6..230dc0f52cc 100644 --- a/tests/test_plugin_manager.py +++ b/tests/test_plugin_manager.py @@ -141,11 +141,26 @@ def test_load_plugin_metadata_includes_i18n(tmp_path: Path): assert metadata is not None assert metadata.short_desc == "Local test short description" - assert metadata.pages == [] + assert metadata.views == [] assert metadata.i18n == {"zh-CN": {"metadata": {"display_name": "你好世界"}}} -def test_load_plugin_metadata_includes_pages(tmp_path: Path): +def test_load_plugin_metadata_includes_views(tmp_path: Path): + plugin_path = tmp_path / "helloworld" + _write_local_test_plugin(plugin_path, TEST_PLUGIN_REPO) + metadata_path = plugin_path / "metadata.yaml" + metadata = yaml.safe_load(metadata_path.read_text(encoding="utf-8")) + metadata["views"] = [{"name": "dashboard", "title": "Dashboard"}] + metadata_path.write_text(yaml.dump(metadata), encoding="utf-8") + + loaded_metadata = PluginManager._load_plugin_metadata(str(plugin_path)) + + assert loaded_metadata is not None + assert loaded_metadata.views == [{"name": "dashboard", "title": "Dashboard"}] + + +def test_load_plugin_metadata_pages_alias_maps_to_views(tmp_path: Path): + # "pages" stays a compatible alias for "views" in metadata.yaml. plugin_path = tmp_path / "helloworld" _write_local_test_plugin(plugin_path, TEST_PLUGIN_REPO) metadata_path = plugin_path / "metadata.yaml" @@ -156,7 +171,7 @@ def test_load_plugin_metadata_includes_pages(tmp_path: Path): loaded_metadata = PluginManager._load_plugin_metadata(str(plugin_path)) assert loaded_metadata is not None - assert loaded_metadata.pages == [{"name": "dashboard", "title": "Dashboard"}] + assert loaded_metadata.views == [{"name": "dashboard", "title": "Dashboard"}] def test_load_plugin_metadata_accepts_yml_suffix(tmp_path: Path):