2023-11-06 19:36:16 +08:00
|
|
|
import enum
|
2025-07-31 19:43:04 +09:00
|
|
|
from datetime import datetime
|
2025-11-20 09:44:39 +08:00
|
|
|
from uuid import uuid4
|
2023-11-06 19:36:16 +08:00
|
|
|
|
2025-08-03 00:54:23 +09:00
|
|
|
import sqlalchemy as sa
|
2025-11-20 09:44:39 +08:00
|
|
|
from sqlalchemy import DateTime, String, func
|
2025-07-31 19:43:04 +09:00
|
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
2024-12-21 23:13:58 +08:00
|
|
|
|
2025-11-21 14:23:32 +09:00
|
|
|
from .base import TypeBase
|
2025-11-20 09:44:39 +08:00
|
|
|
from .types import LongText, StringUUID
|
2024-02-06 13:21:13 +08:00
|
|
|
|
2023-11-06 19:36:16 +08:00
|
|
|
|
2025-10-11 10:08:29 +09:00
|
|
|
class APIBasedExtensionPoint(enum.StrEnum):
|
2024-09-10 17:08:06 +08: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 19:36:16 +08:00
|
|
|
|
|
|
|
|
|
2025-11-21 14:23:32 +09:00
|
|
|
class APIBasedExtension(TypeBase):
|
2024-09-10 17:08:06 +08:00
|
|
|
__tablename__ = "api_based_extensions"
|
2023-11-06 19:36:16 +08:00
|
|
|
__table_args__ = (
|
2025-08-03 00:54:23 +09:00
|
|
|
sa.PrimaryKeyConstraint("id", name="api_based_extension_pkey"),
|
|
|
|
|
sa.Index("api_based_extension_tenant_idx", "tenant_id"),
|
2023-11-06 19:36:16 +08:00
|
|
|
)
|
|
|
|
|
|
2025-11-21 14:23:32 +09: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 19:43:04 +09:00
|
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
|
|
|
api_endpoint: Mapped[str] = mapped_column(String(255), nullable=False)
|
2025-11-21 14:23:32 +09: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
|
|
|
|
|
)
|