代码修改

This commit is contained in:
董宏凯 committed 2026-07-23 15:08:00 +08:00
1 parent b60d9ed09e
commit 1d07025f74
9 files changed
+337 -53

No files matched your search

@@ -28,6 +28,10 @@ _MAX_INLINE_ARTIFACT_CHARS = 1_800
_BUILTIN_MATERIAL_BUDGET = 24_000
SUMMARY_AGENT_ID = "roundtable-summary"
ACTION_PLAN_AGENT_ID = "position-action-planner"
_BUILTIN_MARKDOWN_OUTPUTS = {
"summary": "mnt/user-data/outputs/岗位会商方案总结报告.md",
"action_plan": "mnt/user-data/outputs/岗位会商行动规划.md",
}
_TEXT_ARTIFACT_SUFFIXES = {
".csv",
".json",
@@ -113,8 +117,11 @@ class CompleteTurnRequest(BaseModel):
class RejectNodeRequest(BaseModel):
title: str = Field(min_length=1, max_length=120)
reason: str = Field(min_length=1, max_length=5_000)
# The UI only asks for an optional rejection reason. Keep ``title`` for
# compatible clients and for the audit record, but provide a stable
# default so neither field turns a valid rejection into a 422/400.
title: str = Field(default="产物驳回", max_length=120)
reason: str = Field(default="", max_length=5_000)
class PrepareBuiltinRunRequest(BaseModel):
@@ -731,6 +738,45 @@ def _artifact_manifest_refs(artifacts: list[dict[str, Any]]) -> list[dict[str, A
return refs
async def _write_builtin_markdown_fallback(
*, thread_id: str, kind: str, content: str
) -> dict[str, Any]:
"""Materialize a built-in agent's visible answer when it skipped ``write_file``.
Position roundtable runs are direct chat streams. A model can therefore
finish with a complete visible report but still omit its required artifact
tool call. Keep the chat answer as the source of truth and mirror it into
the owning thread's outputs directory so the report remains previewable and
downloadable after the stream has ended.
"""
virtual_path = _BUILTIN_MARKDOWN_OUTPUTS.get(kind)
report = content.strip()
if virtual_path is None:
raise HTTPException(status_code=400, detail=f"Unknown built-in delivery kind: {kind}")
if not report:
raise HTTPException(status_code=422, detail="内置智能体未返回可保存为报告的正文")
try:
output_path = await aresolve_thread_virtual_path(thread_id, virtual_path)
await asyncio.to_thread(output_path.parent.mkdir, parents=True, exist_ok=True)
await asyncio.to_thread(
output_path.write_text,
report if report.endswith("\n") else f"{report}\n",
encoding="utf-8",
)
stat = await asyncio.to_thread(output_path.stat)
except OSError as error:
raise HTTPException(status_code=500, detail="无法保存内置智能体 Markdown 报告") from error
return {
"name": output_path.name,
"path": virtual_path,
"mime_type": "text/markdown",
"modified_at": datetime.fromtimestamp(stat.st_mtime, tz=UTC).isoformat(),
"size_bytes": stat.st_size,
}
async def _effective_delivery_material(
session: dict[str, Any], nodes: list[dict[str, Any]]
) -> str:
@@ -1109,10 +1155,8 @@ async def complete_node_turn(
async def reject_node(
request: Request, session_id: str, node_key: str, body: RejectNodeRequest
) -> SessionDetailResponse:
title = body.title.strip()
title = body.title.strip() or "产物驳回"
reason = body.reason.strip()
if not title or not reason:
raise HTTPException(status_code=400, detail="驳回标题和理由不能为空")
store, user_id, _ = await _require_writable_session(request, session_id)
current = await store.get_node(session_id, node_key, user_id)
if current is None:
@@ -1199,7 +1243,17 @@ async def _complete_builtin_run(
artifacts = _artifact_manifest_refs(body.artifact_manifest)
markdown = [artifact for artifact in artifacts if _is_markdown_artifact(artifact)]
if not markdown:
raise HTTPException(status_code=422, detail="内置智能体必须交付 outputs 目录下的一份 Markdown 报告文档")
# The report text is already visible in the chat stream. Do not lose
# that successful result just because the model skipped its final
# write_file call: mirror the exact response into the thread outputs
# directory and persist it as the normal report artifact.
fallback_markdown = await _write_builtin_markdown_fallback(
thread_id=body.thread_id,
kind=kind,
content=body.content,
)
artifacts.append(fallback_markdown)
markdown = [fallback_markdown]
if kind == "action_plan" and not any(_is_json_artifact(artifact) for artifact in artifacts):
raise HTTPException(status_code=422, detail="行动规划智能体还需交付 action-plan-subtasks.json 子任务清单")