auto-sync: 2026-05-26 13:39:24
This commit is contained in:
+19
-9
@@ -878,27 +878,37 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_
|
||||
def _parse_stdout_json(stdout_text: str) -> dict:
|
||||
"""解析 openclaw agent --json 的 stdout 输出
|
||||
|
||||
openclaw agent --json 输出格式:
|
||||
{ "kind": "agent-response", "response": { "meta": { "transport": ..., ... } } }
|
||||
返回可直接使用的字段:status, summary, fallback_used, fallback_reason, payloads
|
||||
不再提取 meta,直接用顶层字段。
|
||||
"""
|
||||
text = stdout_text.strip()
|
||||
if not text:
|
||||
return {}
|
||||
return {"status": None, "summary": None, "fallback_used": False, "fallback_reason": None, "payloads": []}
|
||||
try:
|
||||
data = json.loads(text)
|
||||
# 正确路径:data.response.meta
|
||||
response = data.get("response", data)
|
||||
return response.get("meta", {})
|
||||
except json.JSONDecodeError:
|
||||
# 多行输出,找最后一个 JSON
|
||||
for line in reversed(text.splitlines()):
|
||||
try:
|
||||
data = json.loads(line)
|
||||
response = data.get("response", data)
|
||||
return response.get("meta", {})
|
||||
break
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
return {}
|
||||
else:
|
||||
return {"status": None, "summary": None, "fallback_used": False, "fallback_reason": None, "payloads": []}
|
||||
|
||||
# 从 data.result.meta.executionTrace 取 fallback 信息
|
||||
result = data.get("result", {})
|
||||
meta = result.get("meta", {})
|
||||
trace = meta.get("executionTrace", {})
|
||||
|
||||
return {
|
||||
"status": data.get("status"),
|
||||
"summary": data.get("summary"),
|
||||
"fallback_used": trace.get("fallbackUsed", False),
|
||||
"fallback_reason": trace.get("fallbackReason"),
|
||||
"payloads": result.get("payloads", []),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _get_task_status(db_path: Optional[Path], task_id: Optional[str]) -> Optional[str]:
|
||||
|
||||
Reference in New Issue
Block a user