diff --git a/apps/chat/api/chat_api.py b/apps/chat/api/chat_api.py index 993d2b183..f63374c82 100644 --- a/apps/chat/api/chat_api.py +++ b/apps/chat/api/chat_api.py @@ -9,8 +9,9 @@ from drf_spectacular.types import OpenApiTypes from drf_spectacular.utils import OpenApiParameter +from application.serializers.application_chat_record import ChatRecordSerializerModel from chat.serializers.chat import ChatMessageSerializers -from chat.serializers.chat_record import HistoryChatRecordModel +from chat.serializers.chat_record import HistoryChatModel from common.mixins.api_mixin import APIMixin from common.result import ResultSerializer, ResultPageSerializer @@ -33,12 +34,22 @@ class ChatAPI(APIMixin): class ApplicationCreateResponse(ResultSerializer): def get_data(self): - return HistoryChatRecordModel(many=True) + return HistoryChatModel(many=True) class PageApplicationCreateResponse(ResultPageSerializer): def get_data(self): - return HistoryChatRecordModel(many=True) + return HistoryChatModel(many=True) + + +class ApplicationRecordResponse(ResultSerializer): + def get_data(self): + return ChatRecordSerializerModel(many=True) + + +class PageApplicationRecordResponse(ResultPageSerializer): + def get_data(self): + return ChatRecordSerializerModel(many=True) class HistoricalConversationAPI(APIMixin): @@ -59,3 +70,35 @@ class PageHistoricalConversationAPI(APIMixin): @staticmethod def get_response(): return PageApplicationCreateResponse + + +class HistoricalConversationRecordAPI(APIMixin): + @staticmethod + def get_parameters(): + return [OpenApiParameter( + name="chat_id", + description="对话id", + type=OpenApiTypes.STR, + location='path', + required=True, + )] + + @staticmethod + def get_response(): + return ApplicationRecordResponse + + +class PageHistoricalConversationRecordAPI(APIMixin): + @staticmethod + def get_parameters(): + return [OpenApiParameter( + name="chat_id", + description="对话id", + type=OpenApiTypes.STR, + location='path', + required=True, + )] + + @staticmethod + def get_response(): + return PageApplicationRecordResponse diff --git a/apps/chat/serializers/chat_record.py b/apps/chat/serializers/chat_record.py index 8436de4c5..846938ea0 100644 --- a/apps/chat/serializers/chat_record.py +++ b/apps/chat/serializers/chat_record.py @@ -14,6 +14,7 @@ from django.utils.translation import gettext_lazy as _, gettext from rest_framework import serializers from application.models import VoteChoices, ChatRecord, Chat +from application.serializers.application_chat_record import ChatRecordSerializerModel from common.db.search import page_search from common.exception.app_exception import AppApiException from common.utils.lock import try_lock, un_lock @@ -24,7 +25,7 @@ class VoteRequest(serializers.Serializer): label=_("Bidding Status")) -class HistoryChatRecordModel(serializers.ModelSerializer): +class HistoryChatModel(serializers.ModelSerializer): class Meta: model = Chat fields = ['id', @@ -76,7 +77,7 @@ class VoteSerializer(serializers.Serializer): return True -class ChatRecordSerializer(serializers.Serializer): +class HistoricalConversationSerializer(serializers.Serializer): application_id = serializers.UUIDField(required=True, label=_('Application ID')) chat_user_id = serializers.UUIDField(required=True, label=_('Chat User ID')) @@ -88,8 +89,37 @@ class ChatRecordSerializer(serializers.Serializer): def list(self): self.is_valid(raise_exception=True) queryset = self.get_queryset() - return [HistoryChatRecordModel(r).data for r in queryset] + return [HistoryChatModel(r).data for r in queryset] def page(self, current_page, page_size): self.is_valid(raise_exception=True) - return page_search(current_page, page_size, self.get_queryset(), lambda r: HistoryChatRecordModel(r).data) + return page_search(current_page, page_size, self.get_queryset(), lambda r: HistoryChatModel(r).data) + + +class HistoricalConversationRecordSerializer(serializers.Serializer): + application_id = serializers.UUIDField(required=True, label=_('Application ID')) + chat_id = serializers.UUIDField(required=True, label=_('Chat ID')) + chat_user_id = serializers.UUIDField(required=True, label=_('Chat User ID')) + + def is_valid(self, *, raise_exception=False): + super().is_valid(raise_exception=True) + chat_user_id = self.data.get('chat_user_id') + application_id = self.data.get("application_id") + chat_id = self.data.get('chat_id') + chat_exist = QuerySet(Chat).filter(application_id=application_id, chat_user_id=chat_user_id, + id=chat_id).exists() + if not chat_exist: + raise AppApiException(500, _('Non-existent chatID')) + + def get_queryset(self): + chat_id = self.data.get('chat_id') + return QuerySet(ChatRecord).filter(chat_id=chat_id).order_by('-create_time') + + def list(self): + self.is_valid(raise_exception=True) + queryset = self.get_queryset() + return [ChatRecordSerializerModel(r).data for r in queryset] + + def page(self, current_page, page_size): + self.is_valid(raise_exception=True) + return page_search(current_page, page_size, self.get_queryset(), lambda r: ChatRecordSerializerModel(r).data) diff --git a/apps/chat/urls.py b/apps/chat/urls.py index 04d372ccf..101624142 100644 --- a/apps/chat/urls.py +++ b/apps/chat/urls.py @@ -16,5 +16,10 @@ urlpatterns = [ path('historical_conversation', views.HistoricalConversationView.as_view(), name='historical_conversation'), path('historical_conversation//', views.HistoricalConversationView.PageView.as_view(), - name='historical_conversation') + name='historical_conversation'), + path('historical_conversation_record/', views.HistoricalConversationRecordView.as_view(), + name='historical_conversation_record'), + path('historical_conversation_record///', + views.HistoricalConversationRecordView.PageView.as_view(), + name='historical_conversation_record') ] diff --git a/apps/chat/views/chat_record.py b/apps/chat/views/chat_record.py index 43e74320f..f480d55cf 100644 --- a/apps/chat/views/chat_record.py +++ b/apps/chat/views/chat_record.py @@ -11,9 +11,11 @@ from drf_spectacular.utils import extend_schema from rest_framework.request import Request from rest_framework.views import APIView -from chat.api.chat_api import HistoricalConversationAPI, PageHistoricalConversationAPI +from chat.api.chat_api import HistoricalConversationAPI, PageHistoricalConversationAPI, \ + PageHistoricalConversationRecordAPI, HistoricalConversationRecordAPI from chat.api.vote_api import VoteAPI -from chat.serializers.chat_record import VoteSerializer, ChatRecordSerializer +from chat.serializers.chat_record import VoteSerializer, HistoricalConversationSerializer, \ + HistoricalConversationRecordSerializer from common import result from common.auth import TokenAuth @@ -51,7 +53,7 @@ class HistoricalConversationView(APIView): tags=[_('Chat')] # type: ignore ) def get(self, request: Request): - return result.success(ChatRecordSerializer( + return result.success(HistoricalConversationSerializer( data={ 'application_id': request.auth.application_id, 'chat_user_id': request.auth.chat_user_id, @@ -70,8 +72,49 @@ class HistoricalConversationView(APIView): tags=[_('Chat')] # type: ignore ) def get(self, request: Request, current_page: int, page_size: int): - return result.success(ChatRecordSerializer( + return result.success(HistoricalConversationSerializer( data={ 'application_id': request.auth.application_id, 'chat_user_id': request.auth.chat_user_id, }).page(current_page, page_size)) + + +class HistoricalConversationRecordView(APIView): + authentication_classes = [TokenAuth] + + @extend_schema( + methods=['GET'], + description=_("Get historical conversation records"), + summary=_("Get historical conversation records"), + operation_id=_("Get historical conversation records"), # type: ignore + parameters=HistoricalConversationRecordAPI.get_parameters(), + responses=HistoricalConversationRecordAPI.get_response(), + tags=[_('Chat')] # type: ignore + ) + def get(self, request: Request, chat_id: str): + return result.success(HistoricalConversationRecordSerializer( + data={ + 'chat_id': chat_id, + 'application_id': request.auth.application_id, + 'chat_user_id': request.auth.chat_user_id, + }).list()) + + class PageView(APIView): + authentication_classes = [TokenAuth] + + @extend_schema( + methods=['GET'], + description=_("Get historical conversation records by page "), + summary=_("Get historical conversation records by page"), + operation_id=_("Get historical conversation records by page"), # type: ignore + parameters=PageHistoricalConversationRecordAPI.get_parameters(), + responses=PageHistoricalConversationRecordAPI.get_response(), + tags=[_('Chat')] # type: ignore + ) + def get(self, request: Request, chat_id: str, current_page: int, page_size: int): + return result.success(HistoricalConversationRecordSerializer( + data={ + 'chat_id': chat_id, + 'application_id': request.auth.application_id, + 'chat_user_id': request.auth.chat_user_id, + }).page(current_page, page_size)) diff --git a/apps/common/auth/handle/impl/user_token.py b/apps/common/auth/handle/impl/user_token.py index bda847086..992c68aa7 100644 --- a/apps/common/auth/handle/impl/user_token.py +++ b/apps/common/auth/handle/impl/user_token.py @@ -216,7 +216,7 @@ def get_permission_list(user, def reset_workspace_role(role, workspace_id): - if role == RoleConstants.ADMIN.value.__str__(): + if role == RoleConstants.ADMIN.value.__str__() or workspace_id is None: return role return f"{role}:/WORKSPACE/{workspace_id}" diff --git a/ui/src/api/chat/chat.ts b/ui/src/api/chat/chat.ts index 9373be679..72467f9cb 100644 --- a/ui/src/api/chat/chat.ts +++ b/ui/src/api/chat/chat.ts @@ -189,6 +189,18 @@ const pageChat: ( ) => Promise> = (current_page, page_size, loading) => { return get(`/historical_conversation/${current_page}/${page_size}`, undefined, loading) } +const pageChatRecord: ( + chat_id: string, + current_page: number, + page_size: number, + loading?: Ref, +) => Promise> = (chat_id, current_page, page_size, loading) => { + return get( + `/historical_conversation_record/${chat_id}/${current_page}/${page_size}`, + undefined, + loading, + ) +} export default { open, chat, @@ -208,4 +220,5 @@ export default { passwordAuthentication, vote, pageChat, + pageChatRecord, } diff --git a/ui/src/components/app-icon/icons/application.ts b/ui/src/components/app-icon/icons/application.ts index aad4b79de..1171d4615 100644 --- a/ui/src/components/app-icon/icons/application.ts +++ b/ui/src/components/app-icon/icons/application.ts @@ -371,7 +371,7 @@ export default { ]) }, }, - 'app-fitview': { + 'app-fitview': { iconReader: () => { return h('i', [ h( @@ -380,23 +380,23 @@ export default { style: { height: '100%', width: '100%' }, viewBox: '0 0 1024 1024', version: '1.1', - xmlns: 'http://www.w3.org/2000/svg' + xmlns: 'http://www.w3.org/2000/svg', }, [ h('path', { d: 'M128 85.333333h192a21.333333 21.333333 0 0 1 21.333333 21.333334v42.666666a21.333333 21.333333 0 0 1-21.333333 21.333334H170.666667v149.333333a21.333333 21.333333 0 0 1-21.333334 21.333333h-42.666666a21.333333 21.333333 0 0 1-21.333334-21.333333V128a42.666667 42.666667 0 0 1 42.666667-42.666667z m768 853.333334h-192a21.333333 21.333333 0 0 1-21.333333-21.333334v-42.666666a21.333333 21.333333 0 0 1 21.333333-21.333334H853.333333v-149.333333a21.333333 21.333333 0 0 1 21.333334-21.333333h42.666666a21.333333 21.333333 0 0 1 21.333334 21.333333V896a42.666667 42.666667 0 0 1-42.666667 42.666667zM85.333333 896v-192a21.333333 21.333333 0 0 1 21.333334-21.333333h42.666666a21.333333 21.333333 0 0 1 21.333334 21.333333V853.333333h149.333333a21.333333 21.333333 0 0 1 21.333333 21.333334v42.666666a21.333333 21.333333 0 0 1-21.333333 21.333334H128a42.666667 42.666667 0 0 1-42.666667-42.666667zM938.666667 128v192a21.333333 21.333333 0 0 1-21.333334 21.333333h-42.666666a21.333333 21.333333 0 0 1-21.333334-21.333333V170.666667h-149.333333a21.333333 21.333333 0 0 1-21.333333-21.333334v-42.666666a21.333333 21.333333 0 0 1 21.333333-21.333334H896a42.666667 42.666667 0 0 1 42.666667 42.666667z', - fill: 'currentColor' + fill: 'currentColor', }), h('path', { d: 'M512 512m-170.666667 0a170.666667 170.666667 0 1 0 341.333334 0 170.666667 170.666667 0 1 0-341.333334 0Z', - fill: 'currentColor' - }) - ] - ) + fill: 'currentColor', + }), + ], + ), ]) - } + }, }, - 'app-retract': { + 'app-retract': { iconReader: () => { return h('i', [ h( @@ -405,27 +405,27 @@ export default { style: { height: '100%', width: '100%' }, viewBox: '0 0 16 16', version: '1.1', - xmlns: 'http://www.w3.org/2000/svg' + xmlns: 'http://www.w3.org/2000/svg', }, [ h('path', { d: 'M5.44661 0.747985C5.55509 0.639506 5.73097 0.639506 5.83945 0.747985L8.00004 2.90858L10.1606 0.748004C10.2691 0.639525 10.445 0.639525 10.5534 0.748004L11.1034 1.29798C11.2119 1.40645 11.2119 1.58233 11.1034 1.69081L8.7488 4.04544L8.74644 4.04782L8.19647 4.59779C8.16892 4.62534 8.13703 4.64589 8.10299 4.65945C8.003 4.6993 7.88453 4.67875 7.80359 4.59781L7.25362 4.04784L7.25003 4.04419L4.89664 1.69079C4.78816 1.58232 4.78816 1.40644 4.89664 1.29796L5.44661 0.747985Z', - fill: 'currentColor' + fill: 'currentColor', }), h('path', { d: 'M1.99999 5.82774C1.63181 5.82774 1.33333 6.12622 1.33333 6.49441V9.16107C1.33333 9.52926 1.63181 9.82774 2 9.82774H14C14.3682 9.82774 14.6667 9.52926 14.6667 9.16107V6.49441C14.6667 6.12622 14.3682 5.82774 14 5.82774H1.99999ZM13.3333 7.16108V8.49441H2.66666V7.16108H13.3333Z', - fill: 'currentColor' + fill: 'currentColor', }), h('path', { d: 'M10.1605 14.9075C10.269 15.016 10.4449 15.016 10.5534 14.9075L11.1033 14.3575C11.2118 14.249 11.2118 14.0732 11.1033 13.9647L8.75 11.6113L8.74637 11.6076L8.1964 11.0577C8.11546 10.9767 7.99699 10.9562 7.897 10.996C7.86296 11.0096 7.83107 11.0301 7.80352 11.0577L7.25354 11.6077L7.25117 11.6101L4.89657 13.9647C4.78809 14.0731 4.78809 14.249 4.89657 14.3575L5.44654 14.9075C5.55502 15.016 5.7309 15.016 5.83938 14.9075L7.99995 12.7469L10.1605 14.9075Z', - fill: 'currentColor' - }) - ] - ) + fill: 'currentColor', + }), + ], + ), ]) - } + }, }, - 'app-extend': { + 'app-extend': { iconReader: () => { return h('i', [ h( @@ -434,27 +434,27 @@ export default { style: { height: '100%', width: '100%' }, viewBox: '0 0 16 16', version: '1.1', - xmlns: 'http://www.w3.org/2000/svg' + xmlns: 'http://www.w3.org/2000/svg', }, [ h('path', { d: 'M10.5534 5.07974C10.4449 5.18822 10.269 5.18822 10.1605 5.07974L7.99992 2.91915L5.83935 5.07972C5.73087 5.1882 5.555 5.1882 5.44652 5.07972L4.89654 4.52975C4.78807 4.42127 4.78807 4.24539 4.89654 4.13691L7.25117 1.78229L7.25352 1.77991L7.80349 1.22994C7.83019 1.20324 7.86098 1.18311 7.89384 1.16955C7.99448 1.12801 8.11459 1.14813 8.19638 1.22992L8.74635 1.77989L8.74998 1.78359L11.1033 4.13693C11.2118 4.24541 11.2118 4.42129 11.1033 4.52977L10.5534 5.07974Z', - fill: 'currentColor' + fill: 'currentColor', }), h('path', { d: 'M5.83943 10.9202C5.73095 10.8118 5.55507 10.8118 5.44659 10.9202L4.89662 11.4702C4.78814 11.5787 4.78814 11.7546 4.89662 11.863L7.24997 14.2164L7.25359 14.2201L7.80357 14.7701C7.8862 14.8527 8.00795 14.8724 8.10922 14.8291C8.14091 14.8156 8.17059 14.7959 8.19645 14.77L8.74642 14.2201L8.74873 14.2177L11.1034 11.8631C11.2119 11.7546 11.2119 11.5787 11.1034 11.4702L10.5534 10.9202C10.4449 10.8118 10.2691 10.8118 10.1606 10.9202L8.00002 13.0808L5.83943 10.9202Z', - fill: 'currentColor' + fill: 'currentColor', }), h('path', { d: 'M2.00004 6C1.63185 6 1.33337 6.29848 1.33337 6.66667V9.33333C1.33337 9.70152 1.63185 10 2.00004 10H14C14.3682 10 14.6667 9.70152 14.6667 9.33333V6.66667C14.6667 6.29848 14.3682 6 14 6H2.00004ZM13.3334 7.33333V8.66667H2.66671V7.33333H13.3334Z', - fill: 'currentColor' - }) - ] - ) + fill: 'currentColor', + }), + ], + ), ]) - } + }, }, - 'app-beautify': { + 'app-beautify': { iconReader: () => { return h('i', [ h( @@ -463,16 +463,41 @@ export default { style: { height: '100%', width: '100%' }, viewBox: '0 0 1024 1024', version: '1.1', - xmlns: 'http://www.w3.org/2000/svg' + xmlns: 'http://www.w3.org/2000/svg', }, [ h('path', { d: 'M739.6864 689.92l4.2496 3.584 136.4992 135.936a34.1504 34.1504 0 0 1-43.9296 51.968l-4.1984-3.584-136.5504-135.936a34.1504 34.1504 0 0 1 43.9296-51.968zM663.4496 151.552a34.1504 34.1504 0 0 1 51.2512 30.464l-5.9392 216.6272 156.4672 146.1248a34.1504 34.1504 0 0 1-8.6528 55.808l-4.8128 1.792-202.8032 61.0816-87.4496 197.12a34.1504 34.1504 0 0 1-56.32 9.216l-3.2768-4.096-119.5008-178.432-209.9712-24.064a34.1504 34.1504 0 0 1-26.1632-50.176l2.7648-4.3008 129.28-171.7248-42.5472-212.3776a34.1504 34.1504 0 0 1 40.448-40.1408l4.6592 1.3312 198.912 72.3456z m-18.6368 89.7536l-144.5376 83.968a34.1504 34.1504 0 0 1-28.8256 2.56L314.5728 270.592l33.792 167.8848c1.4848 7.68 0.3584 15.5136-3.1744 22.3232l-3.072 4.9152-102.656 136.2944 166.4 19.1488c8.2944 0.9216 15.872 4.864 21.4016 10.9568l3.072 3.9424 93.8496 140.032 68.7104-154.7776a34.1504 34.1504 0 0 1 16.7936-17.0496l4.608-1.792 160.9216-48.4864-124.2624-116.0192a34.1504 34.1504 0 0 1-10.4448-20.0704l-0.3584-5.7856 4.6592-170.9056z', - fill: 'currentColor' - }) - ] - ) + fill: 'currentColor', + }), + ], + ), ]) - } + }, + }, + 'app-chat-record': { + iconReader: () => { + return h('i', [ + h( + 'svg', + { + style: { height: '100%', width: '100%' }, + viewBox: '0 0 16 16', + version: '1.1', + xmlns: 'http://www.w3.org/2000/svg', + }, + [ + h('path', { + d: 'M11.3333 7.33334C11.3333 6.96515 11.6318 6.66667 12 6.66667H14.6667C15.0349 6.66667 15.3333 6.96515 15.3333 7.33334V12.6667C15.3333 13.0349 15.0349 13.3333 14.6667 13.3333H13.2761L12.4714 14.1381C12.2111 14.3984 11.7889 14.3984 11.5286 14.1381L10.7239 13.3333H7.33334C6.96515 13.3333 6.66667 13.0349 6.66667 12.6667V10C6.66667 9.63182 6.96515 9.33334 7.33334 9.33334H11.3333V7.33334ZM12.6667 8.00001V10C12.6667 10.3682 12.3682 10.6667 12 10.6667H8.00001V12H11C11.1768 12 11.3464 12.0702 11.4714 12.1953L12 12.7239L12.5286 12.1953C12.6536 12.0702 12.8232 12 13 12H14V8.00001H12.6667Z', + fill: 'currentColor', + }), + h('path', { + d: 'M1.33334 1.33333C0.965149 1.33333 0.666672 1.63181 0.666672 1.99999V10C0.666672 10.3682 0.965149 10.6667 1.33334 10.6667H2.72386L3.86193 11.8047C4.12228 12.0651 4.54439 12.0651 4.80474 11.8047L5.94281 10.6667H12C12.3682 10.6667 12.6667 10.3682 12.6667 10V1.99999C12.6667 1.63181 12.3682 1.33333 12 1.33333H1.33334ZM4.66667 5.99999C4.66667 6.36818 4.36819 6.66666 4.00001 6.66666C3.63182 6.66666 3.33334 6.36818 3.33334 5.99999C3.33334 5.6318 3.63182 5.33333 4.00001 5.33333C4.36819 5.33333 4.66667 5.6318 4.66667 5.99999ZM7.33334 5.99999C7.33334 6.36818 7.03486 6.66666 6.66667 6.66666C6.29848 6.66666 6 6.36818 6 5.99999C6 5.6318 6.29848 5.33333 6.66667 5.33333C7.03486 5.33333 7.33334 5.6318 7.33334 5.99999ZM10 5.99999C10 6.36818 9.70153 6.66666 9.33334 6.66666C8.96515 6.66666 8.66667 6.36818 8.66667 5.99999C8.66667 5.6318 8.96515 5.33333 9.33334 5.33333C9.70153 5.33333 10 5.6318 10 5.99999Z', + fill: 'currentColor', + }), + ], + ), + ]) + }, }, } diff --git a/ui/src/components/app-icon/index.ts b/ui/src/components/app-icon/index.ts index eaf5b0eb9..37f3127ec 100644 --- a/ui/src/components/app-icon/index.ts +++ b/ui/src/components/app-icon/index.ts @@ -7,6 +7,7 @@ const dynamicIcons = Object.values(iconsImport).reduce( }), {} as Record, ) +console.log(dynamicIcons) export const iconMap: any = { 'app-warning': { iconReader: () => { diff --git a/ui/src/views/chat/pc/index.vue b/ui/src/views/chat/pc/index.vue index 22d615cfc..1fec481c9 100644 --- a/ui/src/views/chat/pc/index.vue +++ b/ui/src/views/chat/pc/index.vue @@ -297,13 +297,12 @@ function getChatLog(id: string, refresh?: boolean) { } function getChatRecord() { - return chatLog - .asyncChatRecordLog( - applicationDetail.value.id, + return chatAPI + .pageChatRecord( currentChatId.value, - paginationConfig.value, + paginationConfig.value.current_page, + paginationConfig.value.page_size, loading, - false, ) .then((res: any) => { paginationConfig.value.total = res.data.total