Skip to content

Graph Transitions Routes

This section documents the graph transitions API endpoints.

backend.routes.transitions

Classes

Functions

load_transition_registry(user_id: str)

Load transition registry, converting from old format if needed.

Source code in backend/routes/transitions.py
def load_transition_registry(user_id: str):
    """Load transition registry, converting from old format if needed."""
    path = transition_registry_path(user_id)
    if not path.exists():
        return {}

    registry = load_registry(path)

    # If registry is a list (old format), convert to new format
    if isinstance(registry, list):
        new_registry = {}
        for transition in registry:
            transition_id = transition.get('id', 'unknown')
            new_registry[transition_id] = {
                **transition,
                'graphs': transition.get('graphs', [])
            }
        # Save the converted registry
        save_registry(path, new_registry)
        return new_registry

    return registry

save_transition_registry(user_id: str, registry: dict)

Save transition registry.

Source code in backend/routes/transitions.py
def save_transition_registry(user_id: str, registry: dict):
    """Save transition registry."""
    path = transition_registry_path(user_id)
    save_registry(path, registry)

update_transition_registry_entry(registry: dict, entry: dict, graph_id: str | None = None)

Update registry entry with proper graph tracking.

Source code in backend/routes/transitions.py
def update_transition_registry_entry(registry: dict, entry: dict, graph_id: str | None = None):
    """Update registry entry with proper graph tracking."""
    entry_id = entry.get("id")
    if not entry_id:
        raise ValueError("Entry must have an 'id' field")

    # Add graph tracking
    if graph_id:
        if 'graphs' not in entry:
            entry['graphs'] = []
        if graph_id not in entry['graphs']:
            entry['graphs'].append(graph_id)

    # Add timestamps
    now = datetime.utcnow().isoformat()
    if 'created_at' not in entry:
        entry['created_at'] = now
    entry['updated_at'] = now

    registry[entry_id] = entry
    return registry

remove_transition_registry_entry(registry: dict, entry_id: str)

Remove entry from registry.

Source code in backend/routes/transitions.py
def remove_transition_registry_entry(registry: dict, entry_id: str):
    """Remove entry from registry."""
    if entry_id in registry:
        del registry[entry_id]
    return registry