From 88051388d4d4563fa90dc3121fdd8dbe1f2b0b43 Mon Sep 17 00:00:00 2001 From: OG T Date: Wed, 1 Apr 2026 22:37:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(ai):=20=E4=BF=AE=E5=BE=A9=20=5Fcall=5Fopenc?= =?UTF-8?q?law=5Fanalyze=20datetime=20=E5=BA=8F=E5=88=97=E5=8C=96=E5=A4=B1?= =?UTF-8?q?=E6=95=97=20=E2=86=92=20fallback=20Gemini?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit signals dict 內含 datetime 物件,httpx json= 無法序列化 加入 _to_serializable 遞迴轉換,datetime → str Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/services/openclaw.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/api/src/services/openclaw.py b/apps/api/src/services/openclaw.py index ba619d434..c89c4a11e 100644 --- a/apps/api/src/services/openclaw.py +++ b/apps/api/src/services/openclaw.py @@ -276,12 +276,24 @@ class OpenClawService: """ try: client = await self._get_client() + import json as _json + def _to_serializable(obj): + if isinstance(obj, dict): + return {k: _to_serializable(v) for k, v in obj.items()} + if isinstance(obj, list): + return [_to_serializable(i) for i in obj] + try: + _json.dumps(obj) + return obj + except (TypeError, ValueError): + return str(obj) + payload = { "incident_id": incident_id, "severity": severity, - "signals": signals[:5], + "signals": _to_serializable(signals[:5]), "affected_services": affected_services, - "expert_context": expert_context, + "expert_context": _to_serializable(expert_context) if expert_context else None, } resp = await client.post( f"{settings.OPENCLAW_URL}/api/v1/analyze/incident",