Files
ai-video-fullstack/backend/migrations/versions/20260710_0002_add_tools.py
Xin Wang 3ed9e1b388 Add reusable tools and assistant bindings
- Introduce a new `Tool` model and `AssistantToolBinding` for managing reusable tools within the application.
- Implement CRUD operations for tools in the new `tools` route, allowing for the creation, retrieval, updating, and deletion of tools.
- Update the `Assistant` model to include a list of tool IDs, enabling assistants to utilize these tools.
- Enhance the backend routes to synchronize tool bindings with assistants, ensuring proper management of tool associations.
- Add frontend components for tool management, including a tool picker in the assistant configuration, improving user experience in tool selection.
- Create a mobile call page to facilitate video calls, integrating camera and microphone selection for enhanced communication capabilities.
- Update API definitions to include tool-related types and operations, ensuring consistency across the application.
- Add a migration script to create the necessary database tables for tools and bindings, supporting the new functionality.
2026-07-10 10:05:41 +08:00

73 lines
2.8 KiB
Python

"""add reusable tools and assistant bindings
Revision ID: 20260710_0002
Revises: 20260709_0001
Create Date: 2026-07-10 00:00:00.000000
"""
from collections.abc import Sequence
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision: str = "20260710_0002"
down_revision: str | Sequence[str] | None = "20260709_0001"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.create_table(
"tools",
sa.Column("id", sa.String(length=40), nullable=False),
sa.Column("name", sa.String(length=128), nullable=False),
sa.Column("function_name", sa.String(length=64), nullable=False),
sa.Column("type", sa.String(length=24), nullable=False),
sa.Column("description", sa.String(length=2048), server_default="", nullable=False),
sa.Column(
"definition",
postgresql.JSONB(astext_type=sa.Text()),
server_default=sa.text("'{}'::jsonb"),
nullable=False,
),
sa.Column(
"secrets",
postgresql.JSONB(astext_type=sa.Text()),
server_default=sa.text("'{}'::jsonb"),
nullable=False,
),
sa.Column("status", sa.String(length=16), server_default="active", nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index("ix_tools_function_name", "tools", ["function_name"], unique=True)
op.create_index("ix_tools_type", "tools", ["type"])
op.create_index("ix_tools_status", "tools", ["status"])
op.create_table(
"assistant_tool_bindings",
sa.Column("assistant_id", sa.String(length=40), nullable=False),
sa.Column("tool_id", sa.String(length=40), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
sa.ForeignKeyConstraint(["assistant_id"], ["assistants.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["tool_id"], ["tools.id"], ondelete="RESTRICT"),
sa.PrimaryKeyConstraint("assistant_id", "tool_id"),
)
op.create_index(
"ix_assistant_tool_bindings_tool_id",
"assistant_tool_bindings",
["tool_id"],
)
def downgrade() -> None:
op.drop_index("ix_assistant_tool_bindings_tool_id", table_name="assistant_tool_bindings")
op.drop_table("assistant_tool_bindings")
op.drop_index("ix_tools_status", table_name="tools")
op.drop_index("ix_tools_type", table_name="tools")
op.drop_index("ix_tools_function_name", table_name="tools")
op.drop_table("tools")