2023-11-06 11:36:16 +00:00
|
|
|
import enum
|
2025-07-31 10:43:04 +00:00
|
|
|
from datetime import datetime
|
2025-11-20 01:44:39 +00:00
|
|
|
from uuid import uuid4
|
2023-11-06 11:36:16 +00:00
|
|
|
|
2025-08-02 15:54:23 +00:00
|
|
|
import sqlalchemy as sa
|
2025-11-20 01:44:39 +00:00
|
|
|
from sqlalchemy import DateTime, String, func
|
2025-07-31 10:43:04 +00:00
|
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
2024-12-21 15:13:58 +00:00
|
|
|
|
2025-11-21 05:23:32 +00:00
|
|
|
from .base import TypeBase
|
2025-11-20 01:44:39 +00:00
|
|
|
from .types import LongText, StringUUID
|
2024-02-06 05:21:13 +00:00
|
|
|
|
2023-11-06 11:36:16 +00:00
|
|
|
|
2025-10-11 01:08:29 +00:00
|
|
|
class APIBasedExtensionPoint(enum.StrEnum):
|
2024-09-10 09:08:06 +00:00
|
|
|
APP_EXTERNAL_DATA_TOOL_QUERY = "app.external_data_tool.query"
|
|
|
|
|
PING = "ping"
|
|
|
|
|
APP_MODERATION_INPUT = "app.moderation.input"
|
|
|
|
|
APP_MODERATION_OUTPUT = "app.moderation.output"
|
2023-11-06 11:36:16 +00:00
|
|
|
|
|
|
|
|
|
2025-11-21 05:23:32 +00:00
|
|
|
class APIBasedExtension(TypeBase):
|
2024-09-10 09:08:06 +00:00
|
|
|
__tablename__ = "api_based_extensions"
|
2023-11-06 11:36:16 +00:00
|
|
|
__table_args__ = (
|
2025-08-02 15:54:23 +00:00
|
|
|
sa.PrimaryKeyConstraint("id", name="api_based_extension_pkey"),
|
|
|
|
|
sa.Index("api_based_extension_tenant_idx", "tenant_id"),
|
2023-11-06 11:36:16 +00:00
|
|
|
)
|
|
|
|
|
|
2025-11-21 05:23:32 +00:00
|
|
|
id: Mapped[str] = mapped_column(StringUUID, default=lambda: str(uuid4()), init=False)
|
|
|
|
|
tenant_id: Mapped[str] = mapped_column(StringUUID, nullable=False)
|
2025-07-31 10:43:04 +00:00
|
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
|
|
|
api_endpoint: Mapped[str] = mapped_column(String(255), nullable=False)
|
2025-11-21 05:23:32 +00:00
|
|
|
api_key: Mapped[str] = mapped_column(LongText, nullable=False)
|
|
|
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
|
|
|
DateTime, nullable=False, server_default=func.current_timestamp(), init=False
|
|
|
|
|
)
|