from typing import List, Tuple def _normalize_table(table): if table is None: return [] return [list(row) for row in table if row and any(str(c).strip() for c in row)] def _upsert_row(table: List[List[str]], row: List[str], key_index: int) -> List[List[str]]: """ Insert or update a row in a table based on a key column index. """ key = row[key_index] updated = False new_table = [] for existing in table: if len(existing) > key_index and existing[key_index] == key: new_table.append(row) updated = True else: new_table.append(existing) if not updated: new_table.append(row) return new_table def _parse_params(tokens: list) -> dict: """ Parse simple key=value tokens, where value may be quoted. Example: id=event_in label="Incoming Event" type=event """ params = {} for t in tokens: if "=" not in t: continue k, v = t.split("=", 1) params[k.strip().lower()] = v.strip() return params def apply_command( command: str, nodes_table, edges_table, ) -> Tuple[list, list, str]: """ Interpret a very small SQL-ish DSL to modify nodes and edges. Supported commands (case-insensitive): ADD NODE id= label="