| 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | # All rights reserved. |
| 3 | # |
| 4 | # This source code is licensed under the terms described in the LICENSE file in |
| 5 | # the root directory of this source tree. |
| 6 | |
| 7 | from datetime import datetime |
| 8 | from typing import Any, List, Optional, Protocol |
| 9 | |
| 10 | from llama_models.schema_utils import json_schema_type, webmethod |
| 11 | from pydantic import BaseModel |
| 12 | |
| 13 | |
| 14 | @json_schema_type |
| 15 | class ControlPlaneValue(BaseModel): |
| 16 | key: str |
| 17 | value: Any |
| 18 | expiration: Optional[datetime] = None |
| 19 | |
| 20 | |
| 21 | @json_schema_type |
| 22 | class ControlPlane(Protocol): |
| 23 | @webmethod(route="/control_plane/set") |
| 24 | async def set( |
| 25 | self, key: str, value: Any, expiration: Optional[datetime] = None |
| 26 | ) -> None: ... |
| 27 | |
| 28 | @webmethod(route="/control_plane/get", method="GET") |
| 29 | async def get(self, key: str) -> Optional[ControlPlaneValue]: ... |
| 30 | |
| 31 | @webmethod(route="/control_plane/delete") |
| 32 | async def delete(self, key: str) -> None: ... |
| 33 | |
| 34 | @webmethod(route="/control_plane/range", method="GET") |
| 35 | async def range(self, start_key: str, end_key: str) -> List[ControlPlaneValue]: ... |