MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / _safe_compact_text

Function _safe_compact_text

uncommon_route/composition.py:585–600  ·  view source on GitHub ↗
(text: str)

Source from the content-addressed store, hash-verified

583
584
585def _safe_compact_text(text: str) -> str:
586 normalized = text.replace("\r\n", "\n").replace("\r", "\n")
587 try:
588 parsed = json.loads(normalized)
589 except Exception:
590 parsed = None
591 if isinstance(parsed, (dict, list)):
592 try:
593 return json.dumps(parsed, ensure_ascii=False, separators=(",", ":"))
594 except Exception:
595 pass
596
597 lines = [line.rstrip() for line in normalized.split("\n")]
598 squashed = "\n".join(lines)
599 squashed = re.sub(r"\n{3,}", "\n\n", squashed)
600 return squashed.strip()
601
602
603def _infer_tool_name(messages: list[dict[str, Any]], idx: int, tool_call_id: str) -> str:

Callers 1

_compose_deterministicFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected