diff --git a/README.md b/README.md index 28a9a05..61bc060 100644 --- a/README.md +++ b/README.md @@ -1,82 +1,38 @@ # AstrBot ImageStudio -AstrBot ImageStudio is an AstrBot role asset production and image-generation workspace plugin. +ImageStudio 是一个给 AstrBot 使用的角色资产与生图工作台插件。它把角色档案、工作流、素材库、衣橱、队列、日志和模型能力探测放在同一个插件里,方便后续为角色持续生成、筛选和管理图片。 -It provides two UI surfaces: +## 现在能用什么 -- AstrBot Plugin Page UI for lightweight status, queue, recent jobs, and quick entry points. -- Standalone Web UI mounted under AstrBot's plugin extension route for the full workspace. +- 查看插件运行概览、队列状态、最近任务和最近图片。 +- 创建角色档案,维护基础设定、外观提示词、风格提示词和默认模型路由。 +- 创建角色工作流,按节点生成、重试、采纳、选择或归档图片。 +- 管理素材库、素材分类、衣橱条目,并做每日穿搭匹配。 +- 查看任务队列、失败任务、死信队列、生成日志、错误日志和审计日志。 +- 探测 OpenAI 兼容生图接口的能力,保存模型/路线能力档案。 +- 默认使用 SQLite;在配置 PostgreSQL 后可以切换到 PG 数据库。 +- 提供 AstrBot 插件卡片概览页,也提供独立工作台入口。 -Both UIs share one backend API, database, queue model, VFS media layer, material library, wardrobe system, and audit trail. +## 怎么打开 -## Development Baseline +在 AstrBot 插件页面打开 ImageStudio 时,默认看到的是轻量概览页:它用于确认插件状态、队列、最近任务、权限和快捷入口。 -Use the v3 documents as the source of truth: - -1. `imagestudio_full_plugin_dev_doc_v3_ui_adjusted.md` -2. `imagestudio_api_contract_v3_ui_adjusted.md` -3. `imagestudio_codex_hermes_dev_flow_v3.md` - -Older v0.1 planning is superseded by v3. In v3, the central fact chain is: +完整工作台在概览页的“工作台”入口里,路径由 AstrBot 挂载到: ```text -character_profiles - -> profile_workflows - -> workflow_nodes - -> generation_tasks - -> generation_images +/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web ``` -## Current Stage +## 当前 UI 状态 -The non-UI backend queue through `S120` is implemented. UI-only stages remain separate. +插件卡片页目前是概览页,这是有意保留的轻量入口,不代表后端功能只有这一页。 -Implemented backend foundation and operations: +完整工作台代码已经包含概览、角色、工作流、素材、衣橱、队列、能力探测、日志和设置等模块。后续还需要继续做 UI 体验整理、布局打磨和更顺手的操作流。 -- AstrBot runtime registration manifest and pure dispatch helpers. -- v3 response helpers, request context, permission guards, and permission matrix export. -- SQLite default database with optional PostgreSQL via `psycopg` or `psycopg2`. -- Migrations, repositories, audit logging, config snapshots, route registry, and contract export. -- Profiles, workflows, nodes, queues, images, media signing, material library, wardrobe, integrations, costs, review policy, model provider routing, and worker infrastructure. -- Real image-provider adapter path, VLM adapter interface, prompt expansion, budget guard, token rotation, safe deletion, media index, orphan scanning, PG smoke, and non-UI smoke scripts. +## 配置说明 -Useful entry points: +AstrBot 小齿轮设置用于安装后最常改的项目:默认模型、私伴插件集成、SQLite/PG 数据库配置。 -- `main.get_plugin_manifest()` -- `main.register_plugin(runtime)` -- `main.dispatch_web_request(...)` -- `scripts/imagestudio_non_ui_smoke.py` -- `scripts/imagestudio_pg_smoke.py` +更完整的配置、导出、导入、校验、差异对比和快照回滚在独立工作台的“设置”页里。 -For installation, packaging, smoke checks, and PG setup, see [INSTALL.md](INSTALL.md). - -## Repository Layout - -```text -main.py -metadata.yaml -_conf_schema.json -config.yaml -adapters/ -core/ -engines/ -backend/ -database/ -assets_builtin/ -pages/imagestudio/ -web/ -frontend/ -data/ -``` - -The root directory is the plugin repository root. Do not introduce a second backend service or a standalone web port. - -## Non-Negotiable Rules - -- Standalone Web UI must be served by AstrBot plugin extension routes. -- Plugin Page UI and Standalone Web UI must call the same backend API. -- Frontend code must not read or construct real disk paths. -- API keys and tokens must not be returned to the frontend in plain text. -- Every write operation must record `audit_logs`. -- Generated images must have `generation_images` records. -- Media access must go through signed media APIs. +安装、打包、数据库和 smoke 测试命令见 [INSTALL.md](INSTALL.md)。 diff --git a/_conf_schema.json b/_conf_schema.json index 02e2994..c3ef70d 100644 --- a/_conf_schema.json +++ b/_conf_schema.json @@ -1,12 +1,57 @@ { "default_generation_model": { - "description": "Default model used for image generation.", + "description": "默认生图模型或模型路由名。留空时由工作流或能力探测结果选择。", "type": "string", "default": "" }, "enable_private_companion_integration": { - "description": "Allow integration calls from astrbot_plugin_private_companion.", + "description": "允许 astrbot_plugin_private_companion 调用 ImageStudio 的穿搭和素材集成接口。", "type": "bool", "default": false + }, + "database_backend": { + "description": "数据库后端。auto 默认使用 SQLite;配置 PG 后自动切换;sqlite 强制本地库;postgresql 强制 PG。", + "type": "string", + "default": "auto" + }, + "sqlite_path": { + "description": "SQLite 数据库文件路径。默认放在插件目录的 data/db/imagestudio.db。", + "type": "string", + "default": "data/db/imagestudio.db" + }, + "postgresql_enabled": { + "description": "启用 PostgreSQL。填写 DSN 或主机/库名/用户后也会自动按 PG 配置运行。", + "type": "bool", + "default": false + }, + "postgresql_dsn": { + "description": "PostgreSQL DSN,优先级高于下面的主机、端口、库名、用户和密码。", + "type": "string", + "default": "" + }, + "postgresql_host": { + "description": "PostgreSQL 主机地址。不使用 DSN 时填写。", + "type": "string", + "default": "" + }, + "postgresql_port": { + "description": "PostgreSQL 端口。不使用 DSN 时填写。", + "type": "string", + "default": "5432" + }, + "postgresql_database": { + "description": "PostgreSQL 数据库名。不使用 DSN 时填写。", + "type": "string", + "default": "" + }, + "postgresql_user": { + "description": "PostgreSQL 用户名。不使用 DSN 时填写。", + "type": "string", + "default": "" + }, + "postgresql_password": { + "description": "PostgreSQL 密码。不使用 DSN 时填写。", + "type": "string", + "default": "" } } diff --git a/backend/services/settings_service.py b/backend/services/settings_service.py index 4859b0b..470f25a 100644 --- a/backend/services/settings_service.py +++ b/backend/services/settings_service.py @@ -36,58 +36,58 @@ class SettingsService: "sections": [ { "key": "plugin", - "title": "Plugin", + "title": "插件", "fields": [ - _field("name", "string", readonly=True), - _field("display_name", "string"), - _field("version", "string", readonly=True), + _field("name", "string", label="插件名", readonly=True), + _field("display_name", "string", label="显示名称"), + _field("version", "string", label="版本", readonly=True), ], }, { "key": "features", - "title": "Features", + "title": "功能", "fields": [ - _field("quick_profile", "bool"), - _field("workspace", "bool"), - _field("material_library", "bool"), - _field("wardrobe", "bool"), - _field("api_discovery", "bool"), - _field("private_companion_integration", "bool"), + _field("quick_profile", "bool", label="快速建档"), + _field("workspace", "bool", label="工作台"), + _field("material_library", "bool", label="素材库"), + _field("wardrobe", "bool", label="衣橱"), + _field("api_discovery", "bool", label="能力探测"), + _field("private_companion_integration", "bool", label="私伴插件集成"), ], }, { "key": "storage", - "title": "Storage", + "title": "存储", "fields": [ - _field("images_path", "path"), - _field("thumbnails_path", "path"), - _field("materials_path", "path"), - _field("styles_path", "path"), - _field("archives_path", "path"), - _field("temp_path", "path"), + _field("images_path", "path", label="图片目录"), + _field("thumbnails_path", "path", label="缩略图目录"), + _field("materials_path", "path", label="素材目录"), + _field("styles_path", "path", label="风格目录"), + _field("archives_path", "path", label="归档目录"), + _field("temp_path", "path", label="临时目录"), ], }, { "key": "database", - "title": "Database", + "title": "数据库", "fields": [ - _field("backend", "select", options=["auto", "sqlite", "postgresql"]), - _field("sqlite.path", "path"), - _field("postgresql.enabled", "bool"), - _field("postgresql.dsn", "string", sensitive=True), - _field("postgresql.host", "string"), - _field("postgresql.port", "number"), - _field("postgresql.database", "string"), - _field("postgresql.user", "string", sensitive=True), - _field("postgresql.password", "string", sensitive=True), + _field("backend", "select", label="后端", options=["auto", "sqlite", "postgresql"]), + _field("sqlite.path", "path", label="SQLite 路径"), + _field("postgresql.enabled", "bool", label="启用 PostgreSQL"), + _field("postgresql.dsn", "string", label="PG DSN", sensitive=True), + _field("postgresql.host", "string", label="PG 主机"), + _field("postgresql.port", "number", label="PG 端口"), + _field("postgresql.database", "string", label="PG 数据库"), + _field("postgresql.user", "string", label="PG 用户", sensitive=True), + _field("postgresql.password", "string", label="PG 密码", sensitive=True), ], }, { "key": "security", - "title": "Security", + "title": "安全", "fields": [ - _field("integration_token_set", "bool", readonly=True), - _field("allowed_integration_plugins", "string_list"), + _field("integration_token_set", "bool", label="集成令牌已设置", readonly=True), + _field("allowed_integration_plugins", "string_list", label="允许集成的插件"), ], }, ], @@ -355,12 +355,14 @@ def _field( key: str, field_type: str, *, + label: str = "", options: list[str] | None = None, sensitive: bool = False, readonly: bool = False, ) -> dict[str, Any]: return { "key": key, + "label": label or key, "type": field_type, "options": options or [], "sensitive": sensitive, diff --git a/config.yaml b/config.yaml index a0cdffb..1bc664c 100644 --- a/config.yaml +++ b/config.yaml @@ -21,9 +21,9 @@ storage: temp_path: data/temp database: - # auto: use SQLite by default, switch to PostgreSQL when postgresql.enabled is true - # sqlite: force local SQLite - # postgresql: force PostgreSQL and fail fast if the driver/config is missing + # auto: 默认使用 SQLite;配置并启用 PostgreSQL 后自动切换 + # sqlite: 强制使用本地 SQLite + # postgresql: 强制使用 PostgreSQL,驱动或连接配置缺失时会直接报错 backend: auto sqlite: path: data/db/imagestudio.db diff --git a/core/config_service.py b/core/config_service.py index 22eab61..d030c36 100644 --- a/core/config_service.py +++ b/core/config_service.py @@ -6,7 +6,7 @@ from dataclasses import dataclass from pathlib import Path from typing import Any -from database.db_helper import REPO_ROOT, _load_yaml_subset +from database.db_helper import REPO_ROOT, load_config_payload @dataclass(frozen=True) @@ -50,9 +50,9 @@ class ConfigService: self.config_path = _resolve_path(config_path) def load(self) -> ImageStudioConfig: - if not self.config_path.exists(): + payload = load_config_payload(self.config_path) + if not payload: return ImageStudioConfig() - payload = _load_yaml_subset(self.config_path.read_text(encoding="utf-8")) plugin = payload.get("plugin", {}) features = payload.get("features", {}) storage = payload.get("storage", {}) diff --git a/database/db_helper.py b/database/db_helper.py index f9f1967..9b67a1f 100644 --- a/database/db_helper.py +++ b/database/db_helper.py @@ -14,6 +14,27 @@ from typing import Any, Iterable, Mapping REPO_ROOT = Path(__file__).resolve().parents[1] +_RUNTIME_CONFIG_OVERRIDES: dict[str, Any] = {} + + +def set_runtime_config_overrides(payload: Mapping[str, Any] | None) -> None: + """Store AstrBot-provided settings as in-process overrides for default config.""" + global _RUNTIME_CONFIG_OVERRIDES + _RUNTIME_CONFIG_OVERRIDES = _copy_plain_mapping(payload or {}) + + +def get_runtime_config_overrides() -> dict[str, Any]: + return _copy_plain_mapping(_RUNTIME_CONFIG_OVERRIDES) + + +def load_config_payload(config_path: str | Path = "config.yaml") -> dict[str, Any]: + path = Path(config_path) + if not path.is_absolute(): + path = REPO_ROOT / path + payload = _load_yaml_subset(path.read_text(encoding="utf-8")) if path.exists() else {} + if _should_apply_runtime_overrides(path): + return _merge_mappings(payload, _RUNTIME_CONFIG_OVERRIDES) + return payload @dataclass(frozen=True) @@ -206,13 +227,7 @@ class Database: def load_database_settings(config_path: str | Path = "config.yaml") -> DatabaseSettings: - path = Path(config_path) - if not path.is_absolute(): - path = REPO_ROOT / path - if not path.exists(): - return DatabaseSettings() - payload = _load_yaml_subset(path.read_text(encoding="utf-8")) - return DatabaseSettings.from_mapping(payload) + return DatabaseSettings.from_mapping(load_config_payload(config_path)) class _Psycopg2ConnectionAdapter: @@ -239,6 +254,45 @@ def _as_bool(value: Any) -> bool: return bool(value) +def _should_apply_runtime_overrides(path: Path) -> bool: + try: + return path.resolve() == (REPO_ROOT / "config.yaml").resolve() + except OSError: + return path.absolute() == (REPO_ROOT / "config.yaml").absolute() + + +def _copy_plain_mapping(value: Mapping[str, Any]) -> dict[str, Any]: + copied: dict[str, Any] = {} + for key, child in value.items(): + if isinstance(child, Mapping): + copied[str(key)] = _copy_plain_mapping(child) + elif isinstance(child, list): + copied[str(key)] = [_copy_plain_item(item) for item in child] + else: + copied[str(key)] = child + return copied + + +def _copy_plain_item(value: Any) -> Any: + if isinstance(value, Mapping): + return _copy_plain_mapping(value) + if isinstance(value, list): + return [_copy_plain_item(item) for item in value] + return value + + +def _merge_mappings(base: Mapping[str, Any], override: Mapping[str, Any]) -> dict[str, Any]: + merged = _copy_plain_mapping(base) + for key, value in override.items(): + if isinstance(value, Mapping) and isinstance(merged.get(str(key)), Mapping): + merged[str(key)] = _merge_mappings(merged[str(key)], value) + elif isinstance(value, Mapping): + merged[str(key)] = _copy_plain_mapping(value) + else: + merged[str(key)] = _copy_plain_item(value) + return merged + + def _load_yaml_subset(text: str) -> dict[str, Any]: """Parse the simple YAML shape used by config.yaml without extra deps.""" root: dict[str, Any] = {} diff --git a/frontend/plugin-page/src/App.vue b/frontend/plugin-page/src/App.vue index e8a3410..e7d79aa 100644 --- a/frontend/plugin-page/src/App.vue +++ b/frontend/plugin-page/src/App.vue @@ -37,6 +37,36 @@ const text = { disabled: "\u672a\u5f00\u542f", } as const +const statusLabels: Record = { + loading: "\u52a0\u8f7d\u4e2d", + running: "\u8fd0\u884c\u4e2d", + created: "\u5df2\u521b\u5efa", + pending: "\u7b49\u5f85\u4e2d", + queued: "\u6392\u961f\u4e2d", + completed: "\u5df2\u5b8c\u6210", + succeeded: "\u5df2\u6210\u529f", + failed: "\u5931\u8d25", + cancelled: "\u5df2\u53d6\u6d88", + dead_letter: "\u6b7b\u4fe1", +} + +const permissionLabels: Record = { + can_read: "\u8bfb\u53d6", + can_write: "\u5199\u5165", + can_manage_config: "\u914d\u7f6e\u7ba1\u7406", + can_manage_materials: "\u7d20\u6750\u7ba1\u7406", + can_retry_tasks: "\u91cd\u8bd5\u4efb\u52a1", +} + +const featureLabels: Record = { + quick_profile: "\u5feb\u901f\u5efa\u6863", + workspace: "\u5de5\u4f5c\u53f0", + material_library: "\u7d20\u6750\u5e93", + wardrobe: "\u8863\u6a71", + api_discovery: "\u80fd\u529b\u63a2\u6d4b", + private_companion_integration: "\u79c1\u4f34\u63d2\u4ef6\u96c6\u6210", +} + const workbenchUrl = computed(() => `${bootstrap.value?.api_base ?? ""}/web`) const quickLinks = computed(() => { const actionLinks = uiActions.value.map(actionToLink).filter((link): link is { label: string; href: string } => Boolean(link)) @@ -112,6 +142,21 @@ function actionLabel(action: UiAction) { } return labels[action.action_id] ?? action.label } + +function statusLabel(value: unknown) { + const key = String(value || "").trim() + return statusLabels[key] ?? key +} + +function permissionLabel(value: unknown) { + const key = String(value || "").trim() + return permissionLabels[key] ?? key +} + +function featureLabel(value: unknown) { + const key = String(value || "").trim() + return featureLabels[key] ?? key +}