MCPcopy
hub / github.com/StructuredLabs/preswald / generate_stable_atom_name_from_component_id

Function generate_stable_atom_name_from_component_id

preswald/utils.py:236–260  ·  view source on GitHub ↗

Convert a stable component ID into a corresponding atom name. Normalizes the suffix and replaces hyphens with underscores. Example: component_id='text-abc123ef' → '_auto_atom_abc123ef' Args: component_id (str): A previously generated component ID. prefix (s

(
    component_id: str, prefix: str = "_auto_atom"
)

Source from the content-addressed store, hash-verified

234
235
236def generate_stable_atom_name_from_component_id(
237 component_id: str, prefix: str = "_auto_atom"
238) -> str:
239 """
240 Convert a stable component ID into a corresponding atom name.
241 Normalizes the suffix and replaces hyphens with underscores.
242
243 Example:
244 component_id='text-abc123ef''_auto_atom_abc123ef'
245
246 Args:
247 component_id (str): A previously generated component ID.
248 prefix (str): Optional prefix for the atom name.
249
250 Returns:
251 str: A deterministic, underscore-safe atom name.
252 """
253 if component_id and "-" in component_id:
254 hash_part = component_id.rsplit("-", 1)[-1]
255 return f"{prefix}_{hash_part}"
256
257 logger.warning(
258 f"[generate_stable_atom_name_from_component_id] Unexpected component_id format {component_id=}"
259 )
260 return generate_stable_id(prefix)
261
262
263def export_app_to_pdf(all_components: list[dict], output_path: str):

Callers 4

wrapperFunction · 0.90

Calls 1

generate_stable_idFunction · 0.85

Tested by

no test coverage detected