Skip to content

Commit f14dc62

Browse files
committed
feat: enhance ChatLogDetailDrawer with resource API integration and update API key generation logic
1 parent afa8923 commit f14dc62

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎apps/chat/serializers/chat_user_api_key_serializers.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ class ChatUserApiKeySerializer(serializers.Serializer):
2424
def generate(self, with_valid=True):
2525
if with_valid:
2626
self.is_valid(raise_exception=True)
27+
user_id = self.data.get('user_id')
28+
# 一个用户只保留一个 key;每次生成都作废旧 key 并重新生成一个新的
29+
QuerySet(ChatUserApiKey).filter(user_id=user_id).delete()
2730
api_key = ChatUserApiKey(
2831
id=uuid.uuid7(),
2932
secret_key=hashlib.md5(uuid.uuid7().bytes).hexdigest(),
30-
user_id=self.data.get('user_id')
33+
user_id=user_id,
3134
)
3235
api_key.save()
3336
return ChatUserApiKeyModelSerializer(api_key).data

‎ui/src/conversation-panel/view/log/index.vue‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { provide, watch } from 'vue'
33
import ChatLogApi from '@/api/admin/workspace/application/chat-log'
4+
import type { ChatLogRecord } from '@/api/types'
45
import ConversationLayout from '../../core/layout/index.vue'
56
import LogMessageList from '../../components/log-message-list/index.vue'
67
import ExecutionDetail from '../../right-sidebar/execution-detail/index.vue'
@@ -9,14 +10,26 @@ import { EXECUTION_DETAIL_KEY, createExecutionDetailStore } from '../../right-si
910
1011
defineOptions({ name: 'LogConversation' })
1112
12-
const props = defineProps<{ chatId: string; applicationId?: string }>()
13+
/** 对话日志分页接口入参,与各资源范围 chat-log API 的 getChatRecordLog 保持结构一致。 */
14+
type ChatRecordApi = {
15+
getChatRecordLog: (
16+
applicationId: string,
17+
chatId: string,
18+
page: { currentPage: number; pageSize: number },
19+
orderAsc?: boolean,
20+
) => Promise<{ records: ChatLogRecord[] }>
21+
}
22+
23+
const props = withDefaults(defineProps<{ chatId: string; applicationId?: string; chatLogApi?: ChatRecordApi }>(), {
24+
chatLogApi: () => ChatLogApi,
25+
})
1326
1427
// 只读日志:只读消息列表 + 执行详情,无会话列表、无输入框。
1528
// 不注入 MESSAGE_LIST_KEY,表单等内容项拿不到发送能力即自动只读。
1629
const msgs = createLogMessageListStore({
1730
// 降序取(最新在前),store 页内 reverse 成正序、上滑加载更旧
1831
pageRecords: (cid, p, s) =>
19-
ChatLogApi.getChatRecordLog(props.applicationId || '', cid, { currentPage: p, pageSize: s }, false),
32+
props.chatLogApi.getChatRecordLog(props.applicationId || '', cid, { currentPage: p, pageSize: s }, false),
2033
getChatId: () => props.chatId,
2134
})
2235
const detail = createExecutionDetailStore()

‎ui/src/views/application-detail/chat-log/ChatLogDetailDrawer.vue‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const props = defineProps<{
1111
nextDisabled: boolean
1212
}>()
1313
14-
const { applicationId } = useApplicationDetailContext()
14+
const { applicationId, resourceApi } = useApplicationDetailContext()
1515
const emit = defineEmits<{ previous: []; next: []; closed: [] }>()
1616
1717
// 对话详情抽屉的打开与关闭
@@ -45,7 +45,7 @@ defineExpose({ open, close })
4545
</template>
4646
<div v-loading="props.loading" class="h-full">
4747
<!-- 只读会话面板:展示该日志的历史对话与执行详情,无输入框 -->
48-
<LogConversation :chat-id="props.chatLog.id" :application-id="applicationId" />
48+
<LogConversation :chat-id="props.chatLog.id" :application-id="applicationId" :chat-log-api="resourceApi.chatLog" />
4949
</div>
5050
<template #footer>
5151
<!-- 浏览上一个对话日志 -->

0 commit comments

Comments
 (0)