mirror of
https://github.com/open-webui/computer.git
synced 2026-11-28 08:09:31 -05:00
24 lines
673 B
Python
24 lines
673 B
Python
"""Prompt helpers shared by coding agent adapters."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def message_text(message: dict[str, Any]) -> str:
|
|
content = message.get("content", "")
|
|
if isinstance(content, list):
|
|
return "\n".join(
|
|
str(block.get("text", "")) for block in content if isinstance(block, dict)
|
|
)
|
|
return str(content or "")
|
|
|
|
|
|
def latest_user_text(messages: list[dict[str, Any]]) -> str:
|
|
"""Return only the current user turn for native-session agents."""
|
|
|
|
for message in reversed(messages):
|
|
if message.get("role") == "user":
|
|
return message_text(message).strip()
|
|
return ""
|