Keep loop-claude's rendering out of the adapter and Claude Code's locations in it
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from loop_claude.claude_code import content, parse, parts, said, typed
|
||||
import json
|
||||
|
||||
from loop_claude.claude_code import assistant_parts, content, parse, part_text, tool_call, typed
|
||||
from loop_claude.outcome import Failure
|
||||
|
||||
|
||||
@@ -17,9 +19,17 @@ def human_turns(entries):
|
||||
def render(entries):
|
||||
lines = []
|
||||
for entry in entries:
|
||||
if entry.get("type") == "assistant":
|
||||
lines += [line for part in parts(entry) if (line := said(part))]
|
||||
elif typed(entry):
|
||||
lines += [line for part in assistant_parts(entry) if (line := said(part))]
|
||||
if typed(entry):
|
||||
text = content(entry)
|
||||
lines.append("[human] " + (text if isinstance(text, str) else "".join(part["text"] for part in text)))
|
||||
return "\n\n".join(lines)
|
||||
|
||||
|
||||
def said(part, limit=400):
|
||||
if (text := part_text(part)) and text.strip():
|
||||
return text
|
||||
if call := tool_call(part):
|
||||
name, arguments = call
|
||||
return f"[tool {name}] {json.dumps(arguments)[:limit]}"
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user