Repository: emcie-co/parlant
File: server/src/emcie/server/core/context_variables.py (Python)

Code before:
                "data": data,
                "key": key,
            },
            upsert=True,
        )
        return ContextVariableValue(
            id=ContextVariableValueId(value_document_id),
            variable_id=variable_id,
            last_modified=last_modified,
            data=data,
        )

    async def delete_variable(
        self,
        variable_set: str,
        id: ContextVariableId,
    ) -> None:
        try:
            await self._variable_collection.delete_one(
                {
                    "id": {"$eq": id},
                    "variable_set": {"$eq": variable_set},
                }
            )
        except NoMatchingDocumentsError:
            raise common.ItemNotFoundError(
                item_id=common.UniqueId(id), message=f"variable_set={variable_set}"
            )
        try:
            await self._value_collection.delete_one(
                {
                    "variable_id": {"$eq": id},
                    "variable_set": {"$eq": variable_set},
                }
            )
        except NoMatchingDocumentsError:
            raise common.ItemNotFoundError(
                item_id=common.UniqueId(id),
                message=f"variable_set={variable_set} in values collection",
            )

    async def list_variables(
        self,
        variable_set: str,
    ) -> Sequence[ContextVariable]:
        return [
            ContextVariable(
                id=ContextVariableId(d["id"]),
                name=d["name"],
                description=d["description"],
                tool_id=d["tool_id"],

Review comment (suggestion):
You're using multiple things from `common`, so why not just import them directly? (Consistently with what we're doing everywhere else in this file—and our codebase in general)

Code after:
                "data": data,
                "key": key,
            },
            upsert=True,
        )
        return ContextVariableValue(
            id=ContextVariableValueId(value_document_id),
            variable_id=variable_id,
            last_modified=last_modified,
            data=data,
        )

    async def delete_variable(
        self,
        variable_set: str,
        id: ContextVariableId,
    ) -> None:
        try:
            await self._variable_collection.delete_one(
                {
                    "id": {"$eq": id},
                    "variable_set": {"$eq": variable_set},
                }
            )
        except NoMatchingDocumentsError:
            raise ItemNotFoundError(item_id=UniqueId(id), message=f"variable_set={variable_set}")
        try:
            await self._value_collection.delete_one(
                {
                    "variable_id": {"$eq": id},
                    "variable_set": {"$eq": variable_set},
                }
            )
        except NoMatchingDocumentsError:
            raise ItemNotFoundError(
                item_id=UniqueId(id),
                message=f"variable_set={variable_set} in values collection",
            )

    async def list_variables(
        self,
        variable_set: str,
    ) -> Sequence[ContextVariable]:
        return [
            ContextVariable(
                id=ContextVariableId(d["id"]),
                name=d["name"],
                description=d["description"],
                tool_id=d["tool_id"],
                freshness_rules=d["freshness_rules"],
            )