Merge branch 'dev' into hugo
This commit is contained in:
commit
6d40d504c5
8 files changed
+1088
-83
No files matched your search
@@ -43,6 +43,16 @@ export interface ChatUploadResult {
|
||||
type?: 'image' | 'document' | 'audio' | 'video' | 'custom';
|
||||
}
|
||||
|
||||
export interface ChatQueryPreviewPage {
|
||||
columns: string[];
|
||||
rows: any[][];
|
||||
page: number;
|
||||
page_size: number;
|
||||
total: number;
|
||||
has_more: boolean;
|
||||
query?: string;
|
||||
}
|
||||
|
||||
export const listChatSessions = (agentId: number) =>
|
||||
requestJson<ChatSessionItem[]>(`/api/chat/sessions?agent_id=${agentId}`, auth());
|
||||
|
||||
@@ -98,3 +108,16 @@ export const uploadChatFile = (agentId: number, file: File) => {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
};
|
||||
|
||||
export const getChatQueryPreviewPage = (
|
||||
agentId: number,
|
||||
chatLogId: number,
|
||||
query: { page?: number; page_size?: number } = {},
|
||||
) => {
|
||||
const qs = new URLSearchParams({
|
||||
agent_id: String(agentId),
|
||||
page: String(query.page ?? 1),
|
||||
page_size: String(query.page_size ?? 100),
|
||||
});
|
||||
return requestJson<ChatQueryPreviewPage>(`/api/chat/query-preview/${chatLogId}?${qs.toString()}`, auth());
|
||||
};
|
||||
@@ -131,6 +131,9 @@ const applyEventMetadata = (msg: ChatMessage, data: any) => {
|
||||
addAttributionParts(msg, metadata?.annotation_reply);
|
||||
addAttributionParts(msg, data?.citation);
|
||||
addAttributionParts(msg, metadata?.citation);
|
||||
if (data?.payload && typeof data.payload === 'object') {
|
||||
msg.payload = data.payload;
|
||||
}
|
||||
};
|
||||
|
||||
export function useChat() {
|
||||
|
||||
+197
-12
@@ -35,6 +35,7 @@ import {
|
||||
deleteChatSession,
|
||||
listChatMessages,
|
||||
saveLocalChatMessage,
|
||||
getChatQueryPreviewPage,
|
||||
resolveChatSourceFile,
|
||||
listOaEmployees,
|
||||
uploadChatFile,
|
||||
@@ -92,6 +93,103 @@ const DEFAULT_KB = '企业知识库';
|
||||
const ERP_KB = 'ERP知识库';
|
||||
const ERP_KB_ENABLED_AGENT_NAMES = new Set(['固资管理']);
|
||||
|
||||
type QueryPreviewPayload = {
|
||||
kind: 'text2sql_result_preview';
|
||||
previewable?: boolean;
|
||||
total_count?: number;
|
||||
preview_row_count?: number;
|
||||
query?: string;
|
||||
};
|
||||
|
||||
const showQueryPreviewDialog = ref(false);
|
||||
const queryPreviewLoading = ref(false);
|
||||
const queryPreviewError = ref('');
|
||||
const queryPreviewState = ref({
|
||||
chatLogId: 0,
|
||||
title: '',
|
||||
query: '',
|
||||
columns: [] as string[],
|
||||
rows: [] as any[][],
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
const getQueryPreviewPayload = (msg: any): QueryPreviewPayload | null => {
|
||||
const payload = msg?.payload;
|
||||
if (!payload || typeof payload !== 'object') return null;
|
||||
if ((payload as any).kind !== 'text2sql_result_preview') return null;
|
||||
return payload as QueryPreviewPayload;
|
||||
};
|
||||
|
||||
const canOpenQueryPreview = (msg: any) => {
|
||||
const payload = getQueryPreviewPayload(msg);
|
||||
return !!(payload?.previewable && Number(msg?.chat_log_id) > 0);
|
||||
};
|
||||
|
||||
const getQueryPreviewSummary = (msg: any) => {
|
||||
const payload = getQueryPreviewPayload(msg);
|
||||
const total = Number(payload?.total_count || 0);
|
||||
if (total > 0) return `查看全部预览(共 ${total} 条)`;
|
||||
return '查看全部预览';
|
||||
};
|
||||
|
||||
const closeQueryPreviewDialog = () => {
|
||||
showQueryPreviewDialog.value = false;
|
||||
queryPreviewError.value = '';
|
||||
};
|
||||
|
||||
const loadQueryPreviewPage = async (chatLogId: number, page = 1) => {
|
||||
if (!currentAgentId.value) {
|
||||
queryPreviewError.value = '当前 Agent 未就绪,请稍后重试';
|
||||
return;
|
||||
}
|
||||
queryPreviewLoading.value = true;
|
||||
queryPreviewError.value = '';
|
||||
try {
|
||||
const result = await getChatQueryPreviewPage(currentAgentId.value, chatLogId, { page, page_size: queryPreviewState.value.pageSize });
|
||||
queryPreviewState.value = {
|
||||
...queryPreviewState.value,
|
||||
chatLogId,
|
||||
title: String(result.query || queryPreviewState.value.title || '查询结果全量预览').trim() || '查询结果全量预览',
|
||||
query: String(result.query || '').trim(),
|
||||
columns: Array.isArray(result.columns) ? result.columns : [],
|
||||
rows: Array.isArray(result.rows) ? result.rows : [],
|
||||
page: Number(result.page || page || 1),
|
||||
pageSize: Number(result.page_size || queryPreviewState.value.pageSize || 100),
|
||||
total: Number(result.total || 0),
|
||||
};
|
||||
} catch (error: any) {
|
||||
queryPreviewError.value = error?.message || '加载全量预览失败';
|
||||
} finally {
|
||||
queryPreviewLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const openQueryPreviewDialog = async (msgObj: any) => {
|
||||
const chatLogId = Number(msgObj?.chat_log_id || 0);
|
||||
if (!chatLogId) return;
|
||||
const payload = getQueryPreviewPayload(msgObj);
|
||||
queryPreviewState.value = {
|
||||
...queryPreviewState.value,
|
||||
chatLogId,
|
||||
title: String(payload?.query || msgObj?.content || '查询结果全量预览').trim() || '查询结果全量预览',
|
||||
query: String(payload?.query || '').trim(),
|
||||
page: 1,
|
||||
total: Number(payload?.total_count || 0),
|
||||
};
|
||||
showQueryPreviewDialog.value = true;
|
||||
await loadQueryPreviewPage(chatLogId, 1);
|
||||
};
|
||||
|
||||
const changeQueryPreviewPage = async (delta: number) => {
|
||||
const nextPage = queryPreviewState.value.page + delta;
|
||||
if (nextPage < 1) return;
|
||||
const totalPages = Math.max(1, Math.ceil((queryPreviewState.value.total || 0) / (queryPreviewState.value.pageSize || 100)));
|
||||
if (nextPage > totalPages) return;
|
||||
await loadQueryPreviewPage(queryPreviewState.value.chatLogId, nextPage);
|
||||
};
|
||||
|
||||
const selectedKb = ref(DEFAULT_KB);
|
||||
const showKbDropdown = ref(false);
|
||||
const kbMenuRef = ref<HTMLElement | null>(null);
|
||||
@@ -891,7 +989,11 @@ const selectKb = (option: string) => {
|
||||
};
|
||||
|
||||
watch(canSelectErpKnowledgeBase, (allowed) => {
|
||||
if (!allowed && selectedKb.value === ERP_KB) {
|
||||
if (allowed) {
|
||||
selectedKb.value = ERP_KB;
|
||||
return;
|
||||
}
|
||||
if (selectedKb.value === ERP_KB) {
|
||||
selectedKb.value = DEFAULT_KB;
|
||||
}
|
||||
if (!allowed) {
|
||||
@@ -2223,10 +2325,6 @@ const normalizeBrowserInput = (value: string) => {
|
||||
return '';
|
||||
};
|
||||
|
||||
const toggleBrowserPanel = () => {
|
||||
browserPanelOpen.value = !browserPanelOpen.value;
|
||||
};
|
||||
|
||||
const loadBrowserPage = () => {
|
||||
const normalized = normalizeBrowserInput(browserDraftUrl.value);
|
||||
if (!normalized) {
|
||||
@@ -4021,6 +4119,8 @@ const resetChatStateForAgentChange = () => {
|
||||
currentAgent.value = null;
|
||||
copiedIndex.value = null;
|
||||
showAttachmentMenu.value = false;
|
||||
browserPanelOpen.value = false;
|
||||
closeQueryPreviewDialog();
|
||||
filePreviewVisible.value = false;
|
||||
previewFile.value = null;
|
||||
};
|
||||
@@ -4818,6 +4918,19 @@ const showChatRating = ref(false);
|
||||
@click="handleChatMarkdownClick"
|
||||
v-html="renderMarkdown(msg.content)"
|
||||
></div>
|
||||
<div
|
||||
v-if="msg.role === 'assistant' && canOpenQueryPreview(msg)"
|
||||
class="mt-4"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-brand-200 bg-brand-50 px-3 py-2 text-xs font-medium text-brand-700 transition hover:bg-brand-100"
|
||||
@click="openQueryPreviewDialog(msg)"
|
||||
>
|
||||
<LayoutGrid class="h-3.5 w-3.5" />
|
||||
{{ getQueryPreviewSummary(msg) }}
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="isShippingNoticeAgent && msg.shipping_actions?.length"
|
||||
class="mt-4 space-y-2 border-t border-default pt-4"
|
||||
@@ -5132,13 +5245,6 @@ const showChatRating = ref(false);
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
@click="toggleBrowserPanel"
|
||||
class="flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
>
|
||||
<Globe class="h-3.5 w-3.5 text-brand-500" />
|
||||
{{ browserPanelOpen ? $t('chat.collapseBrowser') : $t('chat.openBrowser') }}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
@click="handleSend"
|
||||
@@ -5268,6 +5374,85 @@ const showChatRating = ref(false);
|
||||
showGeneralFeedbackDialog = false;
|
||||
}"
|
||||
/>
|
||||
<div
|
||||
v-if="showQueryPreviewDialog"
|
||||
class="dialog-overlay z-[120] items-center"
|
||||
@click.self="closeQueryPreviewDialog"
|
||||
>
|
||||
<div class="dialog-panel flex max-h-[88vh] w-[min(96vw,1280px)] max-w-[1280px] flex-col">
|
||||
<div class="dialog-header">
|
||||
<div>
|
||||
<h3 class="section-title">查询结果全量预览</h3>
|
||||
<p class="section-desc mt-1">{{ queryPreviewState.query || queryPreviewState.title }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds" aria-label="关闭" @click="closeQueryPreviewDialog">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="dialog-body flex min-h-0 flex-1 flex-col gap-4 border-t-0 pt-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 rounded-xl border border-default bg-surface-soft px-4 py-3 text-sm text-secondary">
|
||||
<div>共 {{ queryPreviewState.total || 0 }} 条,当前第 {{ queryPreviewState.page }} / {{ Math.max(1, Math.ceil((queryPreviewState.total || 0) / (queryPreviewState.pageSize || 100))) }} 页</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-default px-3 py-1.5 text-xs transition-colors hover:bg-surface disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:disabled="queryPreviewLoading || queryPreviewState.page <= 1"
|
||||
@click="changeQueryPreviewPage(-1)"
|
||||
>
|
||||
上一页
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-default px-3 py-1.5 text-xs transition-colors hover:bg-surface disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:disabled="queryPreviewLoading || queryPreviewState.page >= Math.max(1, Math.ceil((queryPreviewState.total || 0) / (queryPreviewState.pageSize || 100)))"
|
||||
@click="changeQueryPreviewPage(1)"
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="queryPreviewError" class="rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
|
||||
{{ queryPreviewError }}
|
||||
</div>
|
||||
<div class="min-h-0 flex-1 overflow-auto rounded-2xl border border-default bg-surface">
|
||||
<div v-if="queryPreviewLoading" class="flex h-56 items-center justify-center">
|
||||
<Loader2 class="h-6 w-6 animate-spin text-brand-500" />
|
||||
</div>
|
||||
<div v-else-if="!queryPreviewState.columns.length" class="flex h-56 items-center justify-center text-sm text-muted">
|
||||
暂无可预览数据
|
||||
</div>
|
||||
<table v-else class="min-w-full border-collapse text-sm">
|
||||
<thead class="sticky top-0 z-10 bg-slate-50">
|
||||
<tr>
|
||||
<th
|
||||
v-for="column in queryPreviewState.columns"
|
||||
:key="`query-preview-col-${column}`"
|
||||
class="border border-slate-200 px-3 py-2 text-left font-semibold text-primary"
|
||||
>
|
||||
{{ column }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="(row, rowIndex) in queryPreviewState.rows"
|
||||
:key="`query-preview-row-${rowIndex}`"
|
||||
class="odd:bg-white even:bg-slate-50/50"
|
||||
>
|
||||
<td
|
||||
v-for="(cell, cellIndex) in row"
|
||||
:key="`query-preview-cell-${rowIndex}-${cellIndex}`"
|
||||
class="max-w-[320px] border border-slate-200 px-3 py-2 align-top text-secondary"
|
||||
>
|
||||
<div class="whitespace-pre-wrap break-all">{{ cell ?? '-' }}</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="showLeaveAgentDialog"
|
||||
class="dialog-overlay z-[100] items-center"
|
||||
|
||||
Reference in new issue
Block a user