Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
da336f0
1
Parent(s): 28cafcc
feat: Add format_bytes utility to formatting module
Browse filesCo-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
.openclaw/agents/core/formatting.py
CHANGED
|
@@ -198,6 +198,23 @@ def truncate(text: str, max_length: int = 100, suffix: str = "...") -> str:
|
|
| 198 |
return text[:max_length - len(suffix)] + suffix
|
| 199 |
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
__all__ = [
|
| 202 |
"clean_output",
|
| 203 |
"format_response",
|
|
@@ -206,5 +223,6 @@ __all__ = [
|
|
| 206 |
"format_conversation_message",
|
| 207 |
"format_status",
|
| 208 |
"pretty_print_json",
|
| 209 |
-
"truncate"
|
|
|
|
| 210 |
]
|
|
|
|
| 198 |
return text[:max_length - len(suffix)] + suffix
|
| 199 |
|
| 200 |
|
| 201 |
+
def format_bytes(size_bytes: int) -> str:
|
| 202 |
+
"""
|
| 203 |
+
Format byte size to human-readable string.
|
| 204 |
+
|
| 205 |
+
Args:
|
| 206 |
+
size_bytes: Size in bytes
|
| 207 |
+
|
| 208 |
+
Returns:
|
| 209 |
+
Formatted string (e.g., "1.5 MB")
|
| 210 |
+
"""
|
| 211 |
+
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
|
| 212 |
+
if size_bytes < 1024.0:
|
| 213 |
+
return f"{size_bytes:.1f} {unit}"
|
| 214 |
+
size_bytes /= 1024.0
|
| 215 |
+
return f"{size_bytes:.1f} PB"
|
| 216 |
+
|
| 217 |
+
|
| 218 |
__all__ = [
|
| 219 |
"clean_output",
|
| 220 |
"format_response",
|
|
|
|
| 223 |
"format_conversation_message",
|
| 224 |
"format_status",
|
| 225 |
"pretty_print_json",
|
| 226 |
+
"truncate",
|
| 227 |
+
"format_bytes"
|
| 228 |
]
|