技能提交

This commit is contained in:
fengxiangdebaozi committed 2026-07-03 14:56:35 +08:00
1 parent 2215ec3c49
commit 034a379ecd
14 files changed
+287 -118

No files matched your search

@@ -2093,6 +2093,15 @@ def strategy_language(value: Any) -> int:
return as_int(value) or 3
STRATEGY_ACCOUNT_TYPE_AUDIENCE = "目标受众账号"
STRATEGY_ACCOUNT_TYPE_PATHWAY = "关键传播节点账号"
def strategy_account_type(*, audience: bool) -> str:
"""Return the fixed account type for the current strategy step."""
return STRATEGY_ACCOUNT_TYPE_AUDIENCE if audience else STRATEGY_ACCOUNT_TYPE_PATHWAY
def save_strategy_details(
ctx: FlowContext,
state: dict[str, Any],
@@ -2112,15 +2121,7 @@ def save_strategy_details(
platform = strategy_platform(
first_present(strategy.get("platform"), state.get("platform"), platform_label(item.get("account") or {}))
)
account_type = str(
first_present(
strategy.get("accountType"),
item.get("accountType"),
item.get("type"),
"目标受众账号" if audience else "关键传播节点账号",
)
or ""
).strip()
account_type = strategy_account_type(audience=audience)
persona = strategy.get("persona") or "专业议题分析者"
persona_size = chat_number(strategy.get("personaSize"), 3)
responding_count = chat_number(first_present(strategy.get("respondingCount"), strategy.get("数量")), 10)
@@ -2164,8 +2165,18 @@ def save_strategy_details(
stage + "/save-message",
)
design_ids = [item.get("designId")] if audience else item.get("designIds") or []
pathway_ids = [] if audience else [item.get("pathwayAccountId")]
# Strategy ownership must never be inferred from model text or mixed
# relations: Step5 writes only audience designId, Step6 writes only pathwayId.
if audience:
design_ids = [item.get("designId")]
pathway_ids: list[Any] = []
if not any(design_ids):
record_error(state, stage, "受众策略缺少 designId,无法写入受众策略关系", request=item)
else:
design_ids = []
pathway_ids = [first_present(item.get("pathwayAccountId"), item.get("pathwayId"))]
if not any(pathway_ids):
record_error(state, stage, "关键传播节点策略缺少 pathwayId,无法写入传播节点策略关系", request=item)
for design_id in [x for x in design_ids if x]:
save_with_id(ctx, state, "save_strategy_relation", {"designId": design_id, "strategyId": strategy_id}, stage + "/save-strategy-relation")
for pathway_id in [x for x in pathway_ids if x]:
@@ -2901,7 +2912,16 @@ def run_strategy_step(ctx: FlowContext, state: dict[str, Any], *, audience: bool
strategies = extract_strategies(data, ctx.max_strategies)
for strategy in strategies:
target = (target_names[0] if target_names else "") or (item.get("accountName") if not audience else "")
account_type = strategy.get("accountType") or ("目标受众账号" if audience else "关键传播节点账号")
account_type = strategy_account_type(audience=audience)
returned_account_type = str(first_present(strategy.get("accountType"), item.get("accountType"), item.get("type"), "") or "").strip()
if returned_account_type and returned_account_type != account_type:
record_event(
state,
stage,
f"模型返回账号类型“{returned_account_type}”与当前步骤不一致,已强制按“{account_type}”入库",
{"strategy": strategy, "item": item},
)
strategy_for_save = {**strategy, "accountType": account_type}
topic = f"利用\"{strategy.get('persona') or '专业议题分析者'}\"人设,传播\"{strategy.get('title')}\"主题"
if not strategy.get("title"):
record_error(state, stage, "策略缺少信息标题,跳过", request=strategy, response=data)
@@ -2922,9 +2942,9 @@ def run_strategy_step(ctx: FlowContext, state: dict[str, Any], *, audience: bool
if strategy_id is not None:
# Frontend strategy pages read these child tables, so a strategy
# is not complete until this helper succeeds as far as possible.
save_strategy_details(ctx, state, strategy_id, item, strategy, topic, stage, audience=audience)
save_strategy_details(ctx, state, strategy_id, item, strategy_for_save, topic, stage, audience=audience)
existing_topics.add(topic)
state[output_key].append({**strategy, "id": strategy_id, "targetAudience": target, "accountType": account_type, "topic": topic, "saveResponse": resp})
state[output_key].append({**strategy_for_save, "id": strategy_id, "targetAudience": target, "topic": topic, "saveResponse": resp})
if state[output_key]:
mark_step_status(ctx, state, ["step-analysis-strategy", "step-analysis-strategy-gantt"], stage + "/step-status")
record_event(state, stage, "完成")