INNER CODE UNIT · Python
_print_event
tomascupr/sandstorm · src/sandstorm/cli.py:51
def _print_event(line: str) -> None:
"""Parse a JSON event line and print it to the appropriate stream."""
try:
event = json.loads(line)
except json.JSONDecodeError:
click.echo(line, nl=False)
return
event_type = event.get("type")
if event_type == "assistant":
message = event.get("message", {})
for block in message.get("content", []):
if block.get("type") == "text":
click.echo(block["text"], nl=False)
elif block.get("type") == "tool_use":
click.echo(f"[tool: {block.get('name', 'unknown')}]", nl=False, err=True)