auto-sync: 2026-05-26 10:46:55
This commit is contained in:
+10
-3
@@ -834,19 +834,26 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_
|
||||
|
||||
@staticmethod
|
||||
def _parse_stdout_json(stdout_text: str) -> dict:
|
||||
"""解析 openclaw agent --json 的 stdout 输出"""
|
||||
"""解析 openclaw agent --json 的 stdout 输出
|
||||
|
||||
openclaw agent --json 输出格式:
|
||||
{ "kind": "agent-response", "response": { "meta": { "transport": ..., ... } } }
|
||||
"""
|
||||
text = stdout_text.strip()
|
||||
if not text:
|
||||
return {}
|
||||
try:
|
||||
data = json.loads(text)
|
||||
return data.get("meta", {})
|
||||
# 正确路径: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)
|
||||
return data.get("meta", {})
|
||||
response = data.get("response", data)
|
||||
return response.get("meta", {})
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
return {}
|
||||
|
||||
Reference in New Issue
Block a user