diff --git a/agent/application/models/tables.py b/agent/application/models/tables.py index 910ab8f..e5324de 100644 --- a/agent/application/models/tables.py +++ b/agent/application/models/tables.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -表模型 +数据表模型 """ from datetime import datetime, timedelta from random import choices @@ -9,30 +9,31 @@ from pydantic_ai._uuid import uuid7 from sqlmodel import Field, JSON, SQLModel -# 验证码表 -class Captchas(SQLModel, table=True): +class CaptchaTable(SQLModel, table=True): + """ + 验证码表 + """ + email: str = Field(..., primary_key=True, description="邮箱") captcha: str = Field( default_factory=lambda: "".join(choices("0123456789", k=6)), + primary_key=True, description="验证码", ) - is_valid: bool = Field( - default=True, index=True, description="是否有效,True 表示有效,False 表示无效" - ) - is_unused: bool = Field( - default=True, + is_verified: bool = Field( + default=False, index=True, - description="是否未使用,True 表示未使用,False 表示已使用。", + description="已核验:True 表示已核验,False 表示未核验", ) expired_at: datetime = Field( default_factory=lambda: datetime.now() + timedelta(minutes=30), primary_key=True, - description="过期时间", + description="失效时间", ) # 用户表 -class Users(SQLModel, table=True): +class UserTable(SQLModel, table=True): id: str = Field( default_factory=lambda: str(uuid7()), primary_key=True, @@ -42,7 +43,7 @@ class Users(SQLModel, table=True): # 会话表 -class Conversations(SQLModel, table=True): +class ConversationTable(SQLModel, table=True): id: str = Field( default_factory=lambda: str(uuid7()), primary_key=True, @@ -50,8 +51,8 @@ class Conversations(SQLModel, table=True): ) user_id: str = Field(..., index=True, description="用户唯一标识") description: str = Field(..., description="会话描述") - is_deleted: bool = Field(default=False, index=True, description="是否删除") created_at: datetime = Field(default_factory=datetime.now, description="创建时间") + is_deleted: bool = Field(default=False, index=True, description="已删除:True 表示已删除,False 表示未删除") # 思考节点表(仅定义) diff --git a/agent/application/pages/conversation.py b/agent/application/pages/conversation.py index 9bb49ac..1823fa3 100644 --- a/agent/application/pages/conversation.py +++ b/agent/application/pages/conversation.py @@ -6,18 +6,19 @@ import reflex as rx from application.models import Conversation, Dialog, ThoughtNode from application.states import ConversationState, AuthState +from reflex_base.vars.object import ObjectVar def render_conversation_history_item( - item: rx.Var[tuple[str, Conversation]], + item: rx.Var[tuple], ) -> rx.Component: """ 渲染会话历史条目 :param item: 会话历史条目 :return: Component """ - # 解构会话唯一标识和会话实例 - conversation_id, conversation = item[0], item[1] # type: ignore + conversation_id: rx.Var[str] = item[0] + conversation: ObjectVar[Conversation] = item[1].to(Conversation) # 会话激活状态 is_conversation_actived = conversation_id == ConversationState.conversation_id @@ -44,7 +45,10 @@ def render_conversation_history_item( rx.popover.trigger( rx.box( rx.icon( - "ellipsis", size=14, color="var(--prismui-color-2)" + "ellipsis", + width="14px", + height="14px", + color="var(--prismui-color-2)", ), cursor="pointer", ) @@ -115,6 +119,14 @@ def render_conversation_history_item( margin_bottom="8px", cursor="pointer", ), + rx.hstack( + rx.spacer(), + # 创建时间 + rx.text( + "1", + margin_bottom="8px", + ), + ), ), width="100%", padding="16px", @@ -124,7 +136,7 @@ def render_conversation_history_item( "linear-gradient(to right, #f3efff, #f3efff33, #e2f1fd33, #e2f1fd)", "var(--prismui-background-color-1)", ), - border_radius="var(--prismui-border-radius-2)", + border_radius="var(--prismui-border-radius-3)", box_shadow=rx.cond(is_conversation_actived, "2px 2px 8px #e9e9e9", "none"), style={ "&:hover": { @@ -142,10 +154,12 @@ def render_conversation_history_item( ) -def render_collapse(is_expanded: bool) -> rx.Component: +def conversation_history_collapse( + is_conversation_history_shown: bool, +) -> rx.Component: """ - 渲染折叠面板 - :param is_expanded: 折叠面板展开状态 + 会话历史折叠面板 + :param is_conversation_history_shown: 会话历史展示状态 :return: Component """ return rx.box( @@ -161,22 +175,22 @@ def render_collapse(is_expanded: bool) -> rx.Component: align_items="center", justify_content="space-between", ), - # 渲染列表 + # 渲染会话历史列表 rx.auto_scroll( rx.foreach( ConversationState.conversation_history, render_conversation_history_item, ), flex="1", - margin_top="8px", - width="100%", align_items="stretch", - overflow="auto", + width="100%", + margin_top="8px", style={ "&::-webkit-scrollbar": { "display": "none", }, }, + overflow="auto", ), display="flex", flex_direction="column", @@ -185,14 +199,13 @@ def render_collapse(is_expanded: bool) -> rx.Component: background_color="#f9f9f9cc", backdrop_filter="blur(50px)", gap="12px", - color="var(--prismui-color-text)", ), - width=rx.cond(is_expanded, "25%", "0px"), - min_width=rx.cond(is_expanded, "240px", "0px"), - max_width=rx.cond(is_expanded, "380px", "0px"), + width=rx.cond(is_conversation_history_shown, "25%", "0px"), + min_width=rx.cond(is_conversation_history_shown, "240px", "0px"), + max_width=rx.cond(is_conversation_history_shown, "380px", "0px"), height="100%", - overflow="hidden", transition="all 0.3s ease-in-out", + overflow="hidden", ) @@ -357,7 +370,7 @@ def render_dialog_history_item(dialog_id: str, dialog: Dialog) -> rx.Component: max_width="600px", padding="12px 16px", background_color="var(--prismui-background-color-3)", - border_radius="var(--prismui-border-radius-2)", + border_radius="var(--prismui-border-radius-3)", word_wrap="break-word", word_break="break-all", white_space="pre-line", @@ -712,9 +725,9 @@ def render_input() -> rx.Component: ) -def render_workplace() -> rx.Component: +def workbench() -> rx.Component: """ - 渲染会话工作区 + 工作台 :return: Component """ return rx.box( @@ -742,16 +755,16 @@ def render_workplace() -> rx.Component: def render_conversation_history_collapse_button( - is_expanded: bool, + is_conversation_history_shown: bool, ) -> rx.Component: """ - 渲染会话历史折叠面板的按钮 - :param is_expanded: 会话历史折叠面板展开状态 + 渲染会话历史折叠面板按钮 + :param is_conversation_history_shown: 会话历史展示状态 :return: Component """ return rx.button( rx.icon( - rx.cond(is_expanded, "chevron-left", "chevron-right"), + rx.cond(is_conversation_history_shown, "chevron-left", "chevron-right"), stroke_width=1, width="16px", height="16px", @@ -759,12 +772,18 @@ def render_conversation_history_collapse_button( ), position="absolute", top="calc(50% - 20px)", - left=rx.cond(is_expanded, "calc(clamp(240px, 25%, 380px) - 8px)", "0"), + left=rx.cond( + is_conversation_history_shown, "calc(clamp(240px, 25%, 380px) - 8px)", "0" + ), z_index=99, width="16px", height="40px", background_color="var(--prismui-background-color-1)", - border_radius=rx.cond(is_expanded, "6px", "0 6px 6px 0"), + border_radius=rx.cond( + is_conversation_history_shown, + "var(--prismui-border-radius-2)", + "0 var(--prismui-border-radius-2)", + ), box_shadow="var(--prismui-box-shadow-4)", transition="all 0.3s ease-in-out", cursor="pointer", @@ -782,10 +801,10 @@ def render_conversation() -> rx.Component: return rx.box( rx.hstack( - # 渲染折叠面板 - render_collapse(is_conversation_history_shown), - # 渲染会话工作区 - render_workplace(), + # 会话历史折叠面板 + conversation_history_collapse(is_conversation_history_shown), + # 工作台 + workbench(), position="relative", display="flex", flex="1", @@ -794,12 +813,12 @@ def render_conversation() -> rx.Component: overflow="hidden", transition="all 0.3s ease-in-out", ), - # 渲染对话历史折叠面板打开/关闭按钮 + # 渲染会话历史折叠面板按钮 render_conversation_history_collapse_button(is_conversation_history_shown), position="relative", width="100%", height="100%", - border_radius="var(--prismui-border-radius-3)", + border_radius="var(--prismui-border-radius-4)", overflow="hidden", # 挂载事件:同步用户唯一标识 on_mount=AuthState.sync_user_id, diff --git a/agent/application/pages/index.py b/agent/application/pages/index.py index b7b5aa2..e6c5100 100644 --- a/agent/application/pages/index.py +++ b/agent/application/pages/index.py @@ -45,7 +45,7 @@ def render_nav_button( "var(--prismui-background-color-1)", "transparent", ), - border_radius="var(--prismui-border-radius-2)", + border_radius="var(--prismui-border-radius-3)", box_shadow=rx.cond( is_nav_button_actived, "var(--prismui-box-shadow-2)", "none" ), @@ -88,7 +88,7 @@ def render_settings_button(): align_items="center", width="36px", height="36px", - border_radius="var(--prismui-border-radius-2)", + border_radius="var(--prismui-border-radius-3)", style={ "&:hover": { "background": "var(--prismui-background-color-5)", @@ -120,7 +120,7 @@ def render_settings_button(): border_radius="var(--prismui-border-radius-1)", style={ "_hover": { - "background_color": "var(--prismui-color-7, #f2f2f3)", + "background_color": "var(--prismui-background-color-6)", }, }, # 点击事件:退出登录 @@ -133,6 +133,7 @@ def render_settings_button(): position="relative", align="center", padding="4px 12px", + border_radius="var(--prismui-border-radius-1)", box_shadow="var(--prismui-box-shadow-3)", font_family="var(--prismui-font-family)", overflow="visible", @@ -235,7 +236,7 @@ def render_login_window() -> rx.Component: height="45px", margin_bottom="24px", padding="4px", - border_radius="var(--prismui-border-radius-3)", + border_radius="var(--prismui-border-radius-4)", line_height="16px", # 值变化事件:设置邮箱 on_change=AuthState.set_email, @@ -287,7 +288,7 @@ def render_login_window() -> rx.Component: height="45px", align_items="center", border="var(--prismui-border-1)", - border_radius="var(--prismui-border-radius-3)", + border_radius="var(--prismui-border-radius-4)", ), rx.text( AuthState.login_error_message, @@ -363,7 +364,7 @@ def render_login_window() -> rx.Component: "登录", width="100%", height="38px", - border_radius="var(--prismui-border-radius-3)", + border_radius="var(--prismui-border-radius-4)", background_color="var(--prismui-color-5)", color="var(--prismui-color-9)", cursor="pointer", @@ -391,7 +392,7 @@ def render_login_window() -> rx.Component: padding="20px", background_color="var(--prismui-background-color-1)", border="var(--prismui-border-2)", - border_radius="var(--prismui-border-radius-4)", + border_radius="var(--prismui-border-radius-5)", ), rx.text( "加微信好友", @@ -408,7 +409,7 @@ def render_login_window() -> rx.Component: ), background="var(--prismui-background-2)", border="1px solid #2222220f", - border_radius="var(--prismui-border-radius-4)", + border_radius="var(--prismui-border-radius-5)", box_shadow="0 4px 64px 0 #0000001a", overflow="hidden", ), diff --git a/agent/assets/styles.css b/agent/assets/styles.css index dbd7565..3679826 100644 --- a/agent/assets/styles.css +++ b/agent/assets/styles.css @@ -24,9 +24,10 @@ --prismui-color-9: #ffffff; --prismui-border-1: 1px solid #060a260f; --prismui-border-radius-1: 4px; - --prismui-border-radius-2: 8px; - --prismui-border-radius-3: 12px; - --prismui-border-radius-4: 20px; + --prismui-border-radius-2: 6px; + --prismui-border-radius-3: 8px; + --prismui-border-radius-4: 12px; + --prismui-border-radius-5: 20px; --prismui-box-shadow-1: 0 4px 64px 0 #0000001a; --prismui-box-shadow-2: 0 4px 12px #0000001a; --prismui-box-shadow-3: 0 2px 12px 0 #252b3a3d; diff --git a/agent/database.db b/agent/database.db index ea057d8..022cca3 100644 Binary files a/agent/database.db and b/agent/database.db differ