Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions apps/chat/serializers/chat_user_api_key_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,48 @@
class ChatUserApiKeyModelSerializer(serializers.ModelSerializer):
class Meta:
model = ChatUserApiKey
fields = ['id', 'secret_key', 'is_active', 'create_time', 'user_id']
fields = ["id", "secret_key", "is_active", "create_time", "user_id"]


class ChatUserApiKeySerializer(serializers.Serializer):
user_id = serializers.UUIDField(required=True, label=_('user id'))
order_by = serializers.CharField(required=False, label=_('order by'), allow_null=True, allow_blank=True)
user_id = serializers.UUIDField(required=True, label=_("user id"))
order_by = serializers.CharField(required=False, label=_("order by"), allow_null=True, allow_blank=True)

def generate(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
user_id = self.data.get("user_id")
# 一个用户只保留一个 key;每次生成都作废旧 key 并重新生成一个新的
QuerySet(ChatUserApiKey).filter(user_id=user_id).delete()
api_key = ChatUserApiKey(
id=uuid.uuid7(),
secret_key=hashlib.md5(uuid.uuid7().bytes).hexdigest(),
user_id=self.data.get('user_id')
user_id=user_id,
)
api_key.save()
return ChatUserApiKeyModelSerializer(api_key).data

def page(self, current_page: int, page_size: int, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
user_id = self.data.get('user_id')
user_id = self.data.get("user_id")
query_set = QuerySet(ChatUserApiKey).filter(user_id=user_id)
order_by = '-create_time' if self.data.get('order_by') is None or self.data.get('order_by') == '' else self.data.get('order_by')
order_by = (
"-create_time"
if self.data.get("order_by") is None or self.data.get("order_by") == ""
else self.data.get("order_by")
)
query_set = query_set.order_by(order_by)
return page_search(current_page, page_size,
query_set,
post_records_handler=lambda u: ChatUserApiKeyModelSerializer(u).data)
return page_search(
current_page, page_size, query_set, post_records_handler=lambda u: ChatUserApiKeyModelSerializer(u).data
)

class Operate(serializers.Serializer):
id = serializers.UUIDField(required=True, label=_('api key id'))
user_id = serializers.UUIDField(required=True, label=_('user id'))
id = serializers.UUIDField(required=True, label=_("api key id"))
user_id = serializers.UUIDField(required=True, label=_("user id"))

def destroy(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
QuerySet(ChatUserApiKey).filter(
id=self.data.get('id'), user_id=self.data.get('user_id')
).delete()
return True
QuerySet(ChatUserApiKey).filter(id=self.data.get("id"), user_id=self.data.get("user_id")).delete()
return True
17 changes: 15 additions & 2 deletions ui/src/conversation-panel/view/log/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { provide, watch } from 'vue'
import ChatLogApi from '@/api/admin/workspace/application/chat-log'
import type { ChatLogRecord } from '@/api/types'
import ConversationLayout from '../../core/layout/index.vue'
import LogMessageList from '../../components/log-message-list/index.vue'
import ExecutionDetail from '../../right-sidebar/execution-detail/index.vue'
Expand All @@ -9,14 +10,26 @@ import { EXECUTION_DETAIL_KEY, createExecutionDetailStore } from '../../right-si

defineOptions({ name: 'LogConversation' })

const props = defineProps<{ chatId: string; applicationId?: string }>()
/** 对话日志分页接口入参,与各资源范围 chat-log API 的 getChatRecordLog 保持结构一致。 */
type ChatRecordApi = {
getChatRecordLog: (
applicationId: string,
chatId: string,
page: { currentPage: number; pageSize: number },
orderAsc?: boolean,
) => Promise<{ records: ChatLogRecord[] }>
}

const props = withDefaults(defineProps<{ chatId: string; applicationId?: string; chatLogApi?: ChatRecordApi }>(), {
chatLogApi: () => ChatLogApi,
})

// 只读日志:只读消息列表 + 执行详情,无会话列表、无输入框。
// 不注入 MESSAGE_LIST_KEY,表单等内容项拿不到发送能力即自动只读。
const msgs = createLogMessageListStore({
// 降序取(最新在前),store 页内 reverse 成正序、上滑加载更旧
pageRecords: (cid, p, s) =>
ChatLogApi.getChatRecordLog(props.applicationId || '', cid, { currentPage: p, pageSize: s }, false),
props.chatLogApi.getChatRecordLog(props.applicationId || '', cid, { currentPage: p, pageSize: s }, false),
getChatId: () => props.chatId,
})
const detail = createExecutionDetailStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const props = defineProps<{
nextDisabled: boolean
}>()

const { applicationId } = useApplicationDetailContext()
const { applicationId, resourceApi } = useApplicationDetailContext()
const emit = defineEmits<{ previous: []; next: []; closed: [] }>()

// 对话详情抽屉的打开与关闭
Expand Down Expand Up @@ -45,7 +45,7 @@ defineExpose({ open, close })
</template>
<div v-loading="props.loading" class="h-full">
<!-- 只读会话面板:展示该日志的历史对话与执行详情,无输入框 -->
<LogConversation :chat-id="props.chatLog.id" :application-id="applicationId" />
<LogConversation :chat-id="props.chatLog.id" :application-id="applicationId" :chat-log-api="resourceApi.chatLog" />
</div>
<template #footer>
<!-- 浏览上一个对话日志 -->
Expand Down
Loading