diff --git a/CHANGELOG.md b/CHANGELOG.md index 7497262..6321201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,26 @@ ## 2026-04-05 +### 套餐档位真正变成服务端额度预设 + +- `/v2/tenant/quota` 现在会把 `trial / growth / scale / custom` 视为真正的服务端套餐档位,而不只是前端标签。 +- 当项目选择 `试用 / 增长 / 规模` 套餐时,后端会自动应用对应的预算、动作池和存储上限,并把规范化后的 `package_title / package_focus / package_defaults / warn_threshold` 一起回写给前端。 +- `自定义套餐` 仍然保留手工数值,适合已经明确成本模型或需要特殊策略的项目。 +- `额度` 页也跟着升级成更像正式产品的展示:会直接显示套餐标题和套餐定位,不再只看到生硬的 `growth/custom` 标签。 + +### 失败任务人工处理流改成站内分场景建议 + +- `生产中心` 里不再用“当前链路没有可自动恢复的模板,建议交给管理员处理”这种笼统提示。 +- 前端现在会按失败原因分流成更具体的站内处理建议: + - 额度拦截 + - 上传素材缺失 + - 实拍剪辑缺少源任务 + - AI 视频缺少源任务 + - 内容源同步缺主页 + - 文本 / 链接缺输入 + - 通用站内处理 +- 每种场景都会直接给出更贴切的 CTA,比如 `去额度 / 重新上传 / 去导入主页 / 看源任务 / 交给主 Agent`,让失败任务不再断在泛泛提示层。 + ### AI 视频链兼容 Seedance 2.0 - `创建 AI 视频任务` 现在新增了 `视频引擎`、`引擎模型`、`镜头语言`、`运动节奏`、`风格约束` 和 `画幅`,可以直接用当前默认引擎或切到 `Seedance 2.0`。 diff --git a/collector-service/app/oneliner_features.py b/collector-service/app/oneliner_features.py index 7aec827..23a57ed 100644 --- a/collector-service/app/oneliner_features.py +++ b/collector-service/app/oneliner_features.py @@ -137,6 +137,7 @@ class PlatformSkillRollbackRequest(BaseModel): class TenantQuotaRequest(BaseModel): + package_label: str = "" monthly_budget_cents: int = Field(default=0, ge=0) storage_limit_bytes: int = Field(default=0, ge=0) analysis_quota: int = Field(default=0, ge=0) @@ -356,6 +357,48 @@ USAGE_COST_DEFAULTS: dict[str, dict[str, Any]] = { "live_recorder": {"cost_cents": 2, "quota_field": "recorder_quota"}, } +TENANT_QUOTA_PACKAGE_PRESETS: dict[str, dict[str, Any]] = { + "trial": { + "title": "试用套餐", + "description": "适合先跑通主流程的小规模项目,预算和动作池会优先保护试错成本。", + "focus": "先验证项目是否跑得通,再决定是否扩容。", + "warn_threshold": 0.7, + "monthly_budget_cents": 9900, + "storage_limit_bytes": 5 * 1024 * 1024 * 1024, + "analysis_quota": 30, + "copy_quota": 60, + "ai_video_quota": 2, + "real_cut_quota": 1, + "recorder_quota": 4, + }, + "growth": { + "title": "增长套餐", + "description": "适合已经形成固定内容节奏的项目,兼顾分析、文案和视频动作的持续投放。", + "focus": "先把稳定增长跑顺,再看哪里需要单独加码。", + "warn_threshold": 0.8, + "monthly_budget_cents": 49900, + "storage_limit_bytes": 20 * 1024 * 1024 * 1024, + "analysis_quota": 160, + "copy_quota": 320, + "ai_video_quota": 12, + "real_cut_quota": 8, + "recorder_quota": 20, + }, + "scale": { + "title": "规模套餐", + "description": "适合多账号、多批次的量产项目,预算、存储和视频动作都会按高负载配置。", + "focus": "优先保证量产吞吐,再按平台专项做局部优化。", + "warn_threshold": 0.85, + "monthly_budget_cents": 199000, + "storage_limit_bytes": 80 * 1024 * 1024 * 1024, + "analysis_quota": 800, + "copy_quota": 1600, + "ai_video_quota": 40, + "real_cut_quota": 24, + "recorder_quota": 80, + }, +} + ACTION_USAGE_KEYS: dict[str, str] = { "generate-copy": "copy", "review-draft": "review", @@ -386,6 +429,101 @@ def register_oneliner_routes(app: Any, legacy: Any) -> None: def _dump(value: Any) -> str: return json.dumps(value or {}, ensure_ascii=False) + def _normalize_package_label(value: Any) -> str: + label = str(value or "").strip().lower() + if not label: + return "custom" + return label if label in TENANT_QUOTA_PACKAGE_PRESETS else "custom" + + def _clamp_warn_threshold(value: Any, fallback: float = 0.8) -> float: + try: + parsed = float(value) + except (TypeError, ValueError): + parsed = float(fallback) + if parsed <= 0: + parsed = float(fallback) + return max(0.1, min(parsed, 0.95)) + + def _tenant_quota_package_label(data: dict[str, Any]) -> str: + config = _parse_json(data.get("config_json"), {}) + label = _normalize_package_label(config.get("package_label")) + if label != "custom": + return label + for preset_label, preset_values in TENANT_QUOTA_PACKAGE_PRESETS.items(): + numeric_fields = ( + "monthly_budget_cents", + "storage_limit_bytes", + "analysis_quota", + "copy_quota", + "ai_video_quota", + "real_cut_quota", + "recorder_quota", + ) + if all(int(data.get(field) or 0) == int(preset_values.get(field) or 0) for field in numeric_fields): + return preset_label + return "custom" + + def _tenant_quota_config(data: dict[str, Any]) -> dict[str, Any]: + config = _parse_json(data.get("config_json"), {}) + package_label = _tenant_quota_package_label(data) + config["package_label"] = package_label + preset = TENANT_QUOTA_PACKAGE_PRESETS.get(package_label) + config["warn_threshold"] = _clamp_warn_threshold( + config.get("warn_threshold", preset.get("warn_threshold", 0.8) if preset else 0.8), + preset.get("warn_threshold", 0.8) if preset else 0.8, + ) + if preset: + config.update( + { + "package_title": preset["title"], + "package_description": preset["description"], + "package_focus": preset["focus"], + "package_is_preset": True, + "package_defaults": { + "monthly_budget_cents": int(preset["monthly_budget_cents"]), + "storage_limit_bytes": int(preset["storage_limit_bytes"]), + "analysis_quota": int(preset["analysis_quota"]), + "copy_quota": int(preset["copy_quota"]), + "ai_video_quota": int(preset["ai_video_quota"]), + "real_cut_quota": int(preset["real_cut_quota"]), + "recorder_quota": int(preset["recorder_quota"]), + }, + } + ) + else: + config.update( + { + "package_title": "自定义套餐", + "package_description": "按当前项目的预算、动作池和阶段手动配置套餐。", + "package_focus": "适合已经明确成本模型或需要特殊额度策略的项目。", + "package_is_preset": False, + "package_defaults": {}, + } + ) + return config + + def _tenant_quota_values(request: TenantQuotaRequest, package_label: str) -> dict[str, int]: + preset = TENANT_QUOTA_PACKAGE_PRESETS.get(package_label) + if preset: + return { + "monthly_budget_cents": int(preset["monthly_budget_cents"]), + "storage_limit_bytes": int(preset["storage_limit_bytes"]), + "analysis_quota": int(preset["analysis_quota"]), + "copy_quota": int(preset["copy_quota"]), + "ai_video_quota": int(preset["ai_video_quota"]), + "real_cut_quota": int(preset["real_cut_quota"]), + "recorder_quota": int(preset["recorder_quota"]), + } + return { + "monthly_budget_cents": int(request.monthly_budget_cents or 0), + "storage_limit_bytes": int(request.storage_limit_bytes or 0), + "analysis_quota": int(request.analysis_quota or 0), + "copy_quota": int(request.copy_quota or 0), + "ai_video_quota": int(request.ai_video_quota or 0), + "real_cut_quota": int(request.real_cut_quota or 0), + "recorder_quota": int(request.recorder_quota or 0), + } + def _bool_flag(value: Any) -> bool: if isinstance(value, bool): return value @@ -2743,10 +2881,12 @@ def register_oneliner_routes(app: Any, legacy: Any) -> None: def _tenant_quota_payload(row: dict[str, Any] | None, *, usage: dict[str, Any] | None = None) -> dict[str, Any]: data = row or {} + config = _tenant_quota_config(data) return { "id": data.get("id", ""), "user_id": data.get("user_id", ""), "project_id": data.get("project_id", ""), + "package_label": config["package_label"], "monthly_budget_cents": int(data.get("monthly_budget_cents") or 0), "storage_limit_bytes": int(data.get("storage_limit_bytes") or 0), "analysis_quota": int(data.get("analysis_quota") or 0), @@ -2755,7 +2895,7 @@ def register_oneliner_routes(app: Any, legacy: Any) -> None: "real_cut_quota": int(data.get("real_cut_quota") or 0), "recorder_quota": int(data.get("recorder_quota") or 0), "enabled": True if row is None else _bool_flag(data.get("enabled", 1)), - "config": _parse_json(data.get("config_json"), {}), + "config": config, "usage": usage or {}, "created_at": data.get("created_at", ""), "updated_at": data.get("updated_at", ""), @@ -7244,6 +7384,17 @@ def register_oneliner_routes(app: Any, legacy: Any) -> None: project = _resolve_project(account, project_id or None) existing = _get_tenant_quota_row(account, project_id=project["id"]) timestamp = now() + request_config = dict(request.config or {}) + requested_package_label = _normalize_package_label(request.package_label or request_config.get("package_label")) + package_label = requested_package_label if requested_package_label in TENANT_QUOTA_PACKAGE_PRESETS else "custom" + warn_threshold_value = _clamp_warn_threshold( + request_config.get("warn_threshold", 0.8), + TENANT_QUOTA_PACKAGE_PRESETS.get(package_label, {}).get("warn_threshold", 0.8), + ) + normalized_config = dict(request_config) + normalized_config["package_label"] = package_label + normalized_config["warn_threshold"] = warn_threshold_value + quota_values = _tenant_quota_values(request, package_label) if existing: legacy.db.execute( """ @@ -7253,15 +7404,15 @@ def register_oneliner_routes(app: Any, legacy: Any) -> None: WHERE id = ? """, ( - request.monthly_budget_cents, - request.storage_limit_bytes, - request.analysis_quota, - request.copy_quota, - request.ai_video_quota, - request.real_cut_quota, - request.recorder_quota, + quota_values["monthly_budget_cents"], + quota_values["storage_limit_bytes"], + quota_values["analysis_quota"], + quota_values["copy_quota"], + quota_values["ai_video_quota"], + quota_values["real_cut_quota"], + quota_values["recorder_quota"], 1 if request.enabled else 0, - _dump(request.config), + _dump(normalized_config), timestamp, existing["id"], ), @@ -7279,15 +7430,15 @@ def register_oneliner_routes(app: Any, legacy: Any) -> None: quota_id, account["id"], project["id"], - request.monthly_budget_cents, - request.storage_limit_bytes, - request.analysis_quota, - request.copy_quota, - request.ai_video_quota, - request.real_cut_quota, - request.recorder_quota, + quota_values["monthly_budget_cents"], + quota_values["storage_limit_bytes"], + quota_values["analysis_quota"], + quota_values["copy_quota"], + quota_values["ai_video_quota"], + quota_values["real_cut_quota"], + quota_values["recorder_quota"], 1 if request.enabled else 0, - _dump(request.config), + _dump(normalized_config), timestamp, timestamp, ), diff --git a/tests/test_main_agent_governance.py b/tests/test_main_agent_governance.py index d3af014..7a1000f 100644 --- a/tests/test_main_agent_governance.py +++ b/tests/test_main_agent_governance.py @@ -787,27 +787,92 @@ class MainAgentGovernanceTests(unittest.TestCase): self.assertEqual(saved_registry["config"]["tone"], "sales") self.assertEqual(saved_registry["source"], "override") + growth_preset = { + "monthly_budget_cents": 49900, + "storage_limit_bytes": 21474836480, + "analysis_quota": 160, + "copy_quota": 320, + "ai_video_quota": 12, + "real_cut_quota": 8, + "recorder_quota": 20, + } quota_response = self.client.put( "/v2/tenant/quota", headers=self.ctx["member_headers"], params={"project_id": self.ctx["project_id"]}, json={ "enabled": True, - "monthly_budget_cents": 12800, - "storage_limit_bytes": 987654321, - "analysis_quota": 21, - "copy_quota": 13, + "monthly_budget_cents": 1, + "storage_limit_bytes": 2, + "analysis_quota": 3, + "copy_quota": 4, "ai_video_quota": 5, - "real_cut_quota": 4, - "recorder_quota": 9, - "config": {"warn_threshold": 0.8}, + "real_cut_quota": 6, + "recorder_quota": 7, + "config": {"package_label": "growth", "warn_threshold": 0.8, "custom_note": "keep"}, }, ) self.assertEqual(quota_response.status_code, 200, quota_response.text) quota_payload = quota_response.json() - self.assertEqual(quota_payload["monthly_budget_cents"], 12800) - self.assertEqual(quota_payload["analysis_quota"], 21) + self.assertEqual(quota_payload["package_label"], "growth") + self.assertEqual(quota_payload["monthly_budget_cents"], growth_preset["monthly_budget_cents"]) + self.assertEqual(quota_payload["storage_limit_bytes"], growth_preset["storage_limit_bytes"]) + self.assertEqual(quota_payload["analysis_quota"], growth_preset["analysis_quota"]) + self.assertEqual(quota_payload["copy_quota"], growth_preset["copy_quota"]) + self.assertEqual(quota_payload["ai_video_quota"], growth_preset["ai_video_quota"]) + self.assertEqual(quota_payload["real_cut_quota"], growth_preset["real_cut_quota"]) + self.assertEqual(quota_payload["recorder_quota"], growth_preset["recorder_quota"]) + self.assertEqual(quota_payload["config"]["package_label"], "growth") self.assertEqual(quota_payload["config"]["warn_threshold"], 0.8) + self.assertEqual(quota_payload["config"]["package_title"], "增长套餐") + self.assertTrue(quota_payload["config"]["package_is_preset"]) + self.assertEqual(quota_payload["config"]["custom_note"], "keep") + + quota_get_response = self.client.get( + "/v2/tenant/quota", + headers=self.ctx["member_headers"], + params={"project_id": self.ctx["project_id"]}, + ) + self.assertEqual(quota_get_response.status_code, 200, quota_get_response.text) + quota_get_payload = quota_get_response.json() + self.assertEqual(quota_get_payload["package_label"], "growth") + self.assertEqual(quota_get_payload["monthly_budget_cents"], growth_preset["monthly_budget_cents"]) + self.assertEqual(quota_get_payload["config"]["package_label"], "growth") + self.assertEqual(quota_get_payload["config"]["warn_threshold"], 0.8) + self.assertEqual(quota_get_payload["config"]["package_title"], "增长套餐") + + custom_response = self.client.put( + "/v2/tenant/quota", + headers=self.ctx["member_headers"], + params={"project_id": self.ctx["project_id"]}, + json={ + "enabled": False, + "monthly_budget_cents": 9100, + "storage_limit_bytes": 111, + "analysis_quota": 22, + "copy_quota": 33, + "ai_video_quota": 44, + "real_cut_quota": 55, + "recorder_quota": 66, + "config": {"package_label": "custom", "warn_threshold": 0.55, "custom_note": "manual"}, + }, + ) + self.assertEqual(custom_response.status_code, 200, custom_response.text) + custom_payload = custom_response.json() + self.assertEqual(custom_payload["package_label"], "custom") + self.assertEqual(custom_payload["monthly_budget_cents"], 9100) + self.assertEqual(custom_payload["storage_limit_bytes"], 111) + self.assertEqual(custom_payload["analysis_quota"], 22) + self.assertEqual(custom_payload["copy_quota"], 33) + self.assertEqual(custom_payload["ai_video_quota"], 44) + self.assertEqual(custom_payload["real_cut_quota"], 55) + self.assertEqual(custom_payload["recorder_quota"], 66) + self.assertFalse(custom_payload["enabled"]) + self.assertEqual(custom_payload["config"]["package_label"], "custom") + self.assertEqual(custom_payload["config"]["warn_threshold"], 0.55) + self.assertEqual(custom_payload["config"]["package_title"], "自定义套餐") + self.assertFalse(custom_payload["config"]["package_is_preset"]) + self.assertEqual(custom_payload["config"]["custom_note"], "manual") usage_response = self.client.get( "/v2/tenant/usage", diff --git a/web/storyforge-web-v4/assets/app.js b/web/storyforge-web-v4/assets/app.js index 9610a10..900df2b 100644 --- a/web/storyforge-web-v4/assets/app.js +++ b/web/storyforge-web-v4/assets/app.js @@ -4155,7 +4155,8 @@ function renderTenantQuotaPanel() { (quota?.recorder_quota || 0) > 0 ); const usageCount = recentItems.length; - const packageLabel = String(quotaConfig.package_label || "").trim() || (hasHardLimit ? "自定义套餐" : "未设套餐"); + const packageLabel = String(quotaConfig.package_title || quotaConfig.package_label || "").trim() || (hasHardLimit ? "自定义套餐" : "未设套餐"); + const packageFocus = String(quotaConfig.package_focus || "").trim(); const warnThreshold = Number(quotaConfig.warn_threshold ?? 0.8); const quotaTaskTitle = quota?.storage_over_limit ? "先处理存储超限" @@ -4184,7 +4185,7 @@ function renderTenantQuotaPanel() { topCategory ? `${escapeHtml(`主要消耗 ${topCategory.category || "usage"}`)}` : `本周期未产生消耗` ]; const cards = [ - { label: "套餐档位", value: packageLabel, sub: `预警阈值 ${formatNumber((warnThreshold || 0.8) * 100)}%` }, + { label: "套餐档位", value: packageLabel, sub: packageFocus || `预警阈值 ${formatNumber((warnThreshold || 0.8) * 100)}%` }, { label: "预算", value: `${formatNumber((quota?.monthly_budget_cents || 0) / 100)} 元`, sub: `已用 ${formatNumber((usage?.total_cost_cents || 0) / 100)} 元` }, { label: "分析配额", value: formatNumber(quota?.analysis_quota || 0), sub: `已用 ${formatNumber(categories.analysis?.quantity || 0)}` }, { label: "文案配额", value: formatNumber(quota?.copy_quota || 0), sub: `已用 ${formatNumber(categories.copy?.quantity || 0)}` }, @@ -4197,7 +4198,7 @@ function renderTenantQuotaPanel() {