def _add_value_at_path(
        self, data: Dict[str, Any], path_parts: List[Union[str, int]], value: Any
    ) -> None:
        """Add value at the specified path."""
        if not path_parts:
            raise ValueError("Cannot add to root")

        current = data
        for part in path_parts[:-1]:
            if isinstance(current, dict):
                if part not in current:
                    raise KeyError(f"Key '{part}' not found")
                current = current[part]
            elif isinstance(current, list):
                if not isinstance(part, int):
                    raise ValueError(f"Array index must be integer, got {part}")
                if part >= len(current) or part < -len(current):
                    raise IndexError(f"Array index {part} out of range")
                current = current[part]
            else:
                raise ValueError(
                    f"Cannot index into {type(current).__name__} with {part}"
                )

        last_part = path_parts[-1]
        if isinstance(current, dict):
            current[last_part] = value
        elif isinstance(current, list):
            if isinstance(last_part, int):
                if last_part > len(current) or last_part < -len(current) - 1:
                    raise IndexError(
                        f"Array index {last_part} out of range for insertion"
                    )
                current.insert(last_part, value)
            elif last_part == "-":  # Special case for appending to array
                current.append(value)
            else:
                raise ValueError(f"Invalid array index for add operation: {last_part}")
        else:
            raise ValueError(f"Cannot add value to {type(current).__name__}")
Add value at the specified path.
llama-index-integrations/tools/llama-index-tools-artifact-editor/llama_index/tools/artifact_editor/base.py