From f25dbde2fe9685bbc44bff359d10f6be3d032414 Mon Sep 17 00:00:00 2001 From: kim Date: Sat, 17 Oct 2026 18:04:36 +0900 Subject: [PATCH] =?UTF-8?q?ab-replay:=20SSE=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20data.type=EC=9C=BC=EB=A1=9C=20=ED=8C=8C=EC=8B=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- scripts/ab-replay.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/scripts/ab-replay.py b/scripts/ab-replay.py index b86c527..5545691 100644 --- a/scripts/ab-replay.py +++ b/scripts/ab-replay.py @@ -58,24 +58,23 @@ def chat_once(token, model, sid, message, timeout=240): tools, reply, tokens, err = [], "", "", None try: with urllib.request.urlopen(req, timeout=timeout) as r: - ev = None for raw in r: line = raw.decode("utf-8", "replace").rstrip("\n") - if line.startswith("event:"): - ev = line[6:].strip() - elif line.startswith("data:"): - try: - d = json.loads(line[5:].strip()) - except Exception: - continue - if ev == "tool_result" and d.get("action") and not d.get("synthetic"): - tools.append(d["action"]) - elif ev == "token": - tokens += d.get("text", "") - elif ev == "done": - reply = d.get("reply") or "" - elif ev == "error": - err = str(d.get("message") or d)[:150] + if not line.startswith("data:"): + continue + try: + d = json.loads(line[5:].strip()) + except Exception: + continue + ev = d.get("type") + if ev == "tool_result" and d.get("action") and not d.get("synthetic"): + tools.append(d["action"]) + elif ev == "token": + tokens += d.get("text", "") + elif ev == "done": + reply = d.get("reply") or "" + elif ev == "error": + err = str(d.get("message") or d)[:150] except Exception as e: err = f"{type(e).__name__}: {str(e)[:100]}" return {"tools": tools, "reply": reply or tokens, "sec": round(time.time() - t0, 1), "error": err} @@ -100,7 +99,7 @@ def main(): a = ap.parse_args() models = [m for m in a.models.split(",") if m] - today = datetime.datetime.utcnow().strftime("%Y-%m-%d") + today = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d") daily = os.path.join(USER_DIR, "workspace", "memory", today + ".md") before = open(daily, "rb").read() if os.path.exists(daily) else None