2025-08-25 18:01:04 +08:00
|
|
|
|
<script lang="tsx">
|
|
|
|
|
|
import { message as antdMessage, Tooltip } from 'ant-design-vue';
|
|
|
|
|
|
import { BubbleList } from '@/components/xt-chat/xt-bubble';
|
|
|
|
|
|
import SenderInput from './components/sender-input/index.vue';
|
|
|
|
|
|
import RightView from './components/right-view/index.vue';
|
|
|
|
|
|
|
|
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
|
|
import { useChatStore } from '@/stores/modules/chat';
|
2025-08-27 18:07:36 +08:00
|
|
|
|
import { getConversationList } from '@/api/all/chat';
|
2025-08-25 18:01:04 +08:00
|
|
|
|
import querySSE from '@/utils/querySSE';
|
|
|
|
|
|
import useChatHandler from './useChatHandler';
|
2025-08-27 18:07:36 +08:00
|
|
|
|
import { QUESTION_ROLE, LOADING_ROLE, REMOTE_ROLE } from './constants';
|
2025-08-25 18:01:04 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
props: {
|
|
|
|
|
|
inputInfo: {
|
|
|
|
|
|
type: Object as () => CHAT.TInputInfo,
|
|
|
|
|
|
default: null,
|
|
|
|
|
|
},
|
2025-08-28 12:03:52 +08:00
|
|
|
|
conversationId: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
default: '',
|
|
|
|
|
|
},
|
2025-08-25 18:01:04 +08:00
|
|
|
|
},
|
|
|
|
|
|
setup(props, { emit, expose }) {
|
|
|
|
|
|
const chatStore = useChatStore();
|
|
|
|
|
|
|
2025-08-28 12:03:52 +08:00
|
|
|
|
// const route = useRoute();
|
2025-08-25 18:01:04 +08:00
|
|
|
|
|
|
|
|
|
|
const rightViewRef = ref(null);
|
|
|
|
|
|
const bubbleListRef = ref<any>(null);
|
2025-08-26 17:59:42 +08:00
|
|
|
|
const sseController = ref<any>(null);
|
2025-08-28 15:45:09 +08:00
|
|
|
|
const searchValue = ref<string>('');
|
2025-08-25 18:01:04 +08:00
|
|
|
|
|
|
|
|
|
|
const handleSubmit = (message: string) => {
|
|
|
|
|
|
if (generateLoading.value) {
|
|
|
|
|
|
antdMessage.warning('停止生成后可发送');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-08-27 12:04:23 +08:00
|
|
|
|
|
2025-08-28 15:45:09 +08:00
|
|
|
|
searchValue.value = '';
|
|
|
|
|
|
|
2025-08-26 17:59:42 +08:00
|
|
|
|
conversationList.value.push({
|
|
|
|
|
|
role: QUESTION_ROLE,
|
|
|
|
|
|
content: message,
|
|
|
|
|
|
});
|
2025-08-25 18:01:04 +08:00
|
|
|
|
|
|
|
|
|
|
initSse({ message });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-28 14:13:59 +08:00
|
|
|
|
const clearSseController = () => {
|
|
|
|
|
|
if (sseController.value) {
|
|
|
|
|
|
sseController.value.abort?.();
|
|
|
|
|
|
sseController.value = null;
|
|
|
|
|
|
}
|
2025-08-28 15:45:09 +08:00
|
|
|
|
};
|
2025-08-28 14:13:59 +08:00
|
|
|
|
|
2025-08-25 18:01:04 +08:00
|
|
|
|
const handleCancel = () => {
|
2025-08-26 17:59:42 +08:00
|
|
|
|
if (generateLoading.value) {
|
2025-08-28 14:13:59 +08:00
|
|
|
|
bubbleListRef.value?.abortTypingByKey(generateTeamRunTaskId.value);
|
2025-08-26 17:59:42 +08:00
|
|
|
|
sseController.value?.abort?.();
|
2025-08-25 18:01:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (showRightView.value) {
|
|
|
|
|
|
rightViewRef.value?.abortTyping?.();
|
|
|
|
|
|
}
|
2025-08-26 17:59:42 +08:00
|
|
|
|
|
|
|
|
|
|
generateLoading.value = false;
|
2025-08-25 18:01:04 +08:00
|
|
|
|
antdMessage.info('取消生成');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-28 14:13:59 +08:00
|
|
|
|
const initSse = async (inputInfo: CHAT.TInputInfo): Promise<void> => {
|
|
|
|
|
|
clearSseController();
|
2025-08-26 17:59:42 +08:00
|
|
|
|
|
2025-08-25 18:01:04 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const { message } = inputInfo;
|
|
|
|
|
|
|
|
|
|
|
|
generateLoading.value = true;
|
|
|
|
|
|
|
2025-08-28 14:13:59 +08:00
|
|
|
|
sseController.value = await querySSE({
|
2025-08-26 17:59:42 +08:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
handleMessage,
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
content: message,
|
2025-08-28 12:03:52 +08:00
|
|
|
|
session_id: props.conversationId,
|
2025-08-26 17:59:42 +08:00
|
|
|
|
agent_id: chatStore.agentInfo.agent_id,
|
|
|
|
|
|
}),
|
|
|
|
|
|
});
|
2025-08-25 18:01:04 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to initialize SSE:', error);
|
|
|
|
|
|
antdMessage.error('初始化连接失败');
|
|
|
|
|
|
generateLoading.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-28 12:03:52 +08:00
|
|
|
|
const getConversationInfo = async () => {
|
|
|
|
|
|
const { data, code } = await getConversationList({
|
|
|
|
|
|
session_id: props.conversationId,
|
|
|
|
|
|
agent_id: chatStore.agentInfo.agent_id,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (code === 200) {
|
2025-08-28 14:13:59 +08:00
|
|
|
|
const remoteData = (data.list?.flat(1) ?? []).map((v: any) => ({
|
|
|
|
|
|
...v,
|
|
|
|
|
|
teamRunTaskId: v.step_run_id,
|
|
|
|
|
|
}));
|
|
|
|
|
|
conversationList.value = [...conversationList.value, ...remoteData];
|
2025-08-28 12:03:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-26 17:59:42 +08:00
|
|
|
|
const {
|
|
|
|
|
|
roles,
|
|
|
|
|
|
showRightView,
|
2025-08-28 12:03:52 +08:00
|
|
|
|
rightViewData,
|
2025-08-28 14:13:59 +08:00
|
|
|
|
generateTeamRunTaskId,
|
2025-08-26 17:59:42 +08:00
|
|
|
|
handleMessage,
|
|
|
|
|
|
conversationList,
|
|
|
|
|
|
generateLoading,
|
|
|
|
|
|
senderRef,
|
|
|
|
|
|
} = useChatHandler({
|
|
|
|
|
|
initSse,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-25 18:01:04 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.inputInfo,
|
2025-08-28 12:03:52 +08:00
|
|
|
|
async (newVal) => {
|
2025-08-26 17:59:42 +08:00
|
|
|
|
if (newVal) {
|
2025-08-27 12:04:23 +08:00
|
|
|
|
const { message } = newVal;
|
2025-08-26 17:59:42 +08:00
|
|
|
|
conversationList.value.push({
|
|
|
|
|
|
role: QUESTION_ROLE,
|
2025-08-27 12:04:23 +08:00
|
|
|
|
content: message,
|
2025-08-26 17:59:42 +08:00
|
|
|
|
});
|
|
|
|
|
|
initSse(newVal);
|
|
|
|
|
|
}
|
2025-08-25 18:01:04 +08:00
|
|
|
|
},
|
|
|
|
|
|
{ deep: true },
|
|
|
|
|
|
);
|
2025-08-28 12:03:52 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.conversationId,
|
|
|
|
|
|
(newVal) => {
|
|
|
|
|
|
if (newVal) {
|
|
|
|
|
|
getConversationInfo();
|
2025-08-27 18:07:36 +08:00
|
|
|
|
}
|
2025-08-28 12:03:52 +08:00
|
|
|
|
},
|
|
|
|
|
|
{ immediate: true },
|
|
|
|
|
|
);
|
2025-08-27 18:07:36 +08:00
|
|
|
|
|
2025-08-28 14:13:59 +08:00
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
clearSseController();
|
2025-08-28 15:45:09 +08:00
|
|
|
|
});
|
2025-08-28 14:13:59 +08:00
|
|
|
|
|
2025-08-25 18:01:04 +08:00
|
|
|
|
return () => (
|
|
|
|
|
|
<div class="chat-view-wrap w-full h-full flex">
|
|
|
|
|
|
<section class="flex-1 flex flex-col pt-20px justify-center relative px-16px">
|
|
|
|
|
|
<div class="flex-1 overflow-hidden pb-20px">
|
|
|
|
|
|
<BubbleList
|
|
|
|
|
|
ref={bubbleListRef}
|
|
|
|
|
|
roles={roles}
|
|
|
|
|
|
items={[
|
|
|
|
|
|
...conversationList.value,
|
2025-08-26 17:59:42 +08:00
|
|
|
|
generateLoading.value ? { loading: true, role: LOADING_ROLE } : null,
|
2025-08-25 18:01:04 +08:00
|
|
|
|
].filter(Boolean)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="w-full flex flex-col justify-center items-center">
|
|
|
|
|
|
<SenderInput
|
2025-08-28 15:45:09 +08:00
|
|
|
|
v-model={searchValue.value}
|
2025-08-25 18:01:04 +08:00
|
|
|
|
ref={senderRef}
|
2025-08-26 17:59:42 +08:00
|
|
|
|
class="w-600px"
|
2025-08-25 18:01:04 +08:00
|
|
|
|
placeholder="继续追问..."
|
|
|
|
|
|
loading={generateLoading.value}
|
|
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
|
|
onCancel={handleCancel}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<p class="cts !color-#939499 text-12px !lh-20px my-4px">内容由AI生成,仅供参考</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
{/* 右侧展示区域 */}
|
|
|
|
|
|
{showRightView.value && (
|
|
|
|
|
|
<RightView
|
|
|
|
|
|
ref={rightViewRef}
|
2025-08-28 12:03:52 +08:00
|
|
|
|
rightViewData={rightViewData.value}
|
2025-08-25 18:01:04 +08:00
|
|
|
|
showRightView={showRightView.value}
|
|
|
|
|
|
onClose={() => (showRightView.value = false)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
@import './style.scss';
|
|
|
|
|
|
</style>
|