feat(cloud): manage LLM providers in database
Tests / Test passed: 664

This commit is contained in:
2026-07-14 00:31:47 +08:00
parent b613a315ff
commit a166ffd8a4
35 changed files with 2432 additions and 204 deletions
@@ -285,3 +285,45 @@ class TokenUsageEventRow(Base):
output_tokens: Mapped[int | None] = mapped_column(Integer, nullable=True)
total_tokens: Mapped[int] = mapped_column(Integer, nullable=False)
occurred_at: Mapped[str] = mapped_column(String, nullable=False)
class LlmProviderProfileRow(Base):
__tablename__ = "cloud_llm_provider_profiles"
__table_args__ = (
UniqueConstraint(
"name_normalized",
name="uq_cloud_llm_provider_profiles_name_normalized",
),
Index("ix_cloud_llm_provider_profiles_enabled", "enabled"),
)
id: Mapped[str] = mapped_column(String, primary_key=True)
name: Mapped[str] = mapped_column(String, nullable=False)
name_normalized: Mapped[str] = mapped_column(String, nullable=False)
provider_type: Mapped[str] = mapped_column(String, nullable=False)
model: Mapped[str] = mapped_column(String, nullable=False)
base_url: Mapped[str | None] = mapped_column(String, nullable=True)
timeout_seconds: Mapped[float] = mapped_column(nullable=False)
api_key_ciphertext: Mapped[str] = mapped_column(Text, nullable=False)
key_last_rotated_at: Mapped[str] = mapped_column(String, nullable=False)
enabled: Mapped[int] = mapped_column(
Integer, nullable=False, default=1, server_default=text("1")
)
revision: Mapped[int] = mapped_column(
Integer, nullable=False, default=1, server_default=text("1")
)
created_at: Mapped[str] = mapped_column(String, nullable=False)
updated_at: Mapped[str] = mapped_column(String, nullable=False)
class LlmProviderSettingsRow(Base):
__tablename__ = "cloud_llm_provider_settings"
id: Mapped[str] = mapped_column(String, primary_key=True)
active_profile_id: Mapped[str | None] = mapped_column(
ForeignKey("cloud_llm_provider_profiles.id"), nullable=True
)
revision: Mapped[int] = mapped_column(
Integer, nullable=False, default=1, server_default=text("1")
)
updated_at: Mapped[str] = mapped_column(String, nullable=False)