mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-19 08:28:10 +02:00
feat: add text chat UI
This commit is contained in:
parent
e313f2d235
commit
f121147a42
14 changed files with 1465 additions and 294 deletions
|
|
@ -5,37 +5,60 @@ Revises: 4c1f1e3e8ef2
|
|||
Create Date: 2026-05-18 12:58:58.573381
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '2f638891cbb6'
|
||||
down_revision: Union[str, None] = '4c1f1e3e8ef2'
|
||||
revision: str = "2f638891cbb6"
|
||||
down_revision: Union[str, None] = "4c1f1e3e8ef2"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('workflow_run_text_sessions',
|
||||
sa.Column('workflow_run_id', sa.Integer(), nullable=False),
|
||||
sa.Column('revision', sa.Integer(), server_default=sa.text('0'), nullable=False),
|
||||
sa.Column('session_data', sa.JSON(), server_default=sa.text("'{}'::json"), nullable=False),
|
||||
sa.Column('checkpoint', sa.JSON(), server_default=sa.text("'{}'::json"), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(['workflow_run_id'], ['workflow_runs.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('workflow_run_id')
|
||||
op.create_table(
|
||||
"workflow_run_text_sessions",
|
||||
sa.Column("workflow_run_id", sa.Integer(), nullable=False),
|
||||
sa.Column(
|
||||
"revision", sa.Integer(), server_default=sa.text("0"), nullable=False
|
||||
),
|
||||
sa.Column(
|
||||
"session_data",
|
||||
sa.JSON(),
|
||||
server_default=sa.text("'{}'::json"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"checkpoint",
|
||||
sa.JSON(),
|
||||
server_default=sa.text("'{}'::json"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["workflow_run_id"], ["workflow_runs.id"], ondelete="CASCADE"
|
||||
),
|
||||
sa.PrimaryKeyConstraint("workflow_run_id"),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_workflow_run_text_sessions_updated_at",
|
||||
"workflow_run_text_sessions",
|
||||
["updated_at"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index('ix_workflow_run_text_sessions_updated_at', 'workflow_run_text_sessions', ['updated_at'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index('ix_workflow_run_text_sessions_updated_at', table_name='workflow_run_text_sessions')
|
||||
op.drop_table('workflow_run_text_sessions')
|
||||
op.drop_index(
|
||||
"ix_workflow_run_text_sessions_updated_at",
|
||||
table_name="workflow_run_text_sessions",
|
||||
)
|
||||
op.drop_table("workflow_run_text_sessions")
|
||||
# ### end Alembic commands ###
|
||||
|
|
|
|||
|
|
@ -541,9 +541,7 @@ class WorkflowRunTextSessionModel(Base):
|
|||
onupdate=lambda: datetime.now(UTC),
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_workflow_run_text_sessions_updated_at", "updated_at"),
|
||||
)
|
||||
__table_args__ = (Index("ix_workflow_run_text_sessions_updated_at", "updated_at"),)
|
||||
|
||||
|
||||
class OrganizationUsageCycleModel(Base):
|
||||
|
|
|
|||
|
|
@ -148,11 +148,15 @@ def _build_response_from_run_and_session(workflow_run, text_session):
|
|||
)
|
||||
|
||||
|
||||
def _validate_turn_cursor(session_data: Dict[str, Any], cursor_turn_id: str | None) -> None:
|
||||
def _validate_turn_cursor(
|
||||
session_data: Dict[str, Any], cursor_turn_id: str | None
|
||||
) -> None:
|
||||
if cursor_turn_id is None:
|
||||
return
|
||||
if not any(turn.get("id") == cursor_turn_id for turn in session_data["turns"]):
|
||||
raise HTTPException(status_code=404, detail="Turn not found in text chat session")
|
||||
raise HTTPException(
|
||||
status_code=404, detail="Turn not found in text chat session"
|
||||
)
|
||||
|
||||
|
||||
def _truncate_future_turns(
|
||||
|
|
@ -202,7 +206,9 @@ async def _load_text_session_or_404(
|
|||
if text_session.workflow_run.workflow_id != workflow_id:
|
||||
raise HTTPException(status_code=404, detail="Text chat session not found")
|
||||
if text_session.workflow_run.mode != WorkflowRunMode.TEXTCHAT.value:
|
||||
raise HTTPException(status_code=400, detail="Workflow run is not a text chat session")
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Workflow run is not a text chat session"
|
||||
)
|
||||
return text_session
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue