feat(chat): refactor agent stream display and tool result rendering
Add RagPipelineProgress timeline, simplify AgentStreamDisplay structure, group grep hits per document, and add KnowledgeChunksList tool result UI.
This commit is contained in:
@@ -164,3 +164,30 @@
|
||||
filter: saturate(1.06);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.streaming-mermaid-loading) {
|
||||
display: block;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-width: 480px;
|
||||
min-height: 180px;
|
||||
margin: 0.75em 0;
|
||||
border-radius: 0;
|
||||
border: 0;
|
||||
background: var(--td-bg-color-container);
|
||||
overflow: hidden;
|
||||
animation: streamingImageBreath 2.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
:deep(.streaming-mermaid-loading__skeleton) {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(
|
||||
110deg,
|
||||
rgba(234, 239, 246, 0.95) 8%,
|
||||
rgba(248, 250, 252, 0.98) 18%,
|
||||
rgba(234, 239, 246, 0.95) 33%
|
||||
);
|
||||
background-size: 220% 100%;
|
||||
animation: streamingImageShimmer 1.4s linear infinite;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
@keyframes chatTimelineTypingBounce {
|
||||
|
||||
0%,
|
||||
60%,
|
||||
100% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
30% {
|
||||
transform: translateY(-8px);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes chatTimelineLoadingFadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.streaming-loading-node {
|
||||
.tree-child-content {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.loading-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 24px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
position: relative;
|
||||
animation: chatTimelineLoadingFadeIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
.loading-typing {
|
||||
position: absolute;
|
||||
left: -42px;
|
||||
top: 9px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
span {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
border-radius: 50%;
|
||||
background: var(--td-text-color-placeholder);
|
||||
animation: chatTimelineTypingBounce 1.4s ease-in-out infinite;
|
||||
|
||||
&:nth-child(1) {
|
||||
animation-delay: 0s;
|
||||
}
|
||||
|
||||
&:nth-child(2) {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
|
||||
&:nth-child(3) {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const css = readFileSync(join(here, 'chat-timeline-loading.less'), 'utf8')
|
||||
|
||||
test('timeline loading uses shared gray bounce dots on the axis', () => {
|
||||
assert.match(css, /\.streaming-loading-node\s*\{[\s\S]*left:\s*-42px/)
|
||||
assert.match(css, /width:\s*4px/)
|
||||
assert.match(css, /background:\s*var\(--td-text-color-placeholder\)/)
|
||||
assert.match(css, /animation:\s*chatTimelineTypingBounce/)
|
||||
assert.match(css, /animation-delay:\s*0\.2s/)
|
||||
})
|
||||
@@ -1,5 +1,6 @@
|
||||
import { markRaw, nextTick, type Ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ensureRagPipelineHistoryStream } from '@/utils/rag-pipeline-history'
|
||||
|
||||
export type ChatMessage = Record<string, unknown>
|
||||
|
||||
@@ -66,8 +67,74 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const extractKnowledgeReferences = (data: ChatMessage) => {
|
||||
const dataPayload = data.data as ChatMessage | undefined
|
||||
const refs =
|
||||
data.knowledge_references ||
|
||||
dataPayload?.references ||
|
||||
dataPayload?.knowledge_references ||
|
||||
[]
|
||||
return Array.isArray(refs) ? refs : []
|
||||
}
|
||||
|
||||
/** Match the in-flight assistant row by request id or assistant message id. */
|
||||
const resolveActiveAssistantMessage = (data: ChatMessage) => {
|
||||
const dataId = data.id as string | undefined
|
||||
const assistantId =
|
||||
(data.assistant_message_id as string | undefined) ||
|
||||
currentAssistantMessageId.value ||
|
||||
undefined
|
||||
|
||||
const matched = findLastMessage((item) => {
|
||||
if (item.role !== 'assistant') return false
|
||||
if (dataId && (item.request_id === dataId || item.id === dataId)) return true
|
||||
if (assistantId && (item.id === assistantId || item.request_id === assistantId)) return true
|
||||
return false
|
||||
})
|
||||
if (matched) return matched
|
||||
|
||||
return findLastMessage((item) => item.role === 'assistant' && !item.is_completed)
|
||||
}
|
||||
|
||||
const applyKnowledgeReferences = (data: ChatMessage) => {
|
||||
const refs = extractKnowledgeReferences(data)
|
||||
if (!refs.length) return undefined
|
||||
|
||||
let message = resolveActiveAssistantMessage(data)
|
||||
const created = !message
|
||||
if (!message) {
|
||||
const rowId = (data.id as string | undefined) || currentAssistantMessageId.value
|
||||
message = {
|
||||
id: rowId,
|
||||
request_id: rowId,
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
showThink: false,
|
||||
thinkContent: '',
|
||||
thinking: false,
|
||||
is_completed: false,
|
||||
knowledge_references: [],
|
||||
}
|
||||
ensureAgentMessageShell(message, data.id as string | undefined)
|
||||
messagesList.push(message)
|
||||
onMessageCreated?.(message)
|
||||
loading.value = false
|
||||
} else {
|
||||
ensureAgentMessageShell(message, data.id as string | undefined)
|
||||
}
|
||||
|
||||
message.knowledge_references = refs.slice()
|
||||
if (created) onAgentChunkBound?.(message, true)
|
||||
onMessageUpdated?.(message, data)
|
||||
log('[References] Saved to message, count:', refs.length)
|
||||
return message
|
||||
}
|
||||
|
||||
const ensureAgentMessageShell = (message: ChatMessage, requestId?: string) => {
|
||||
message.isAgentMode = true
|
||||
if (!isAgentStreamSession()) {
|
||||
message.isRagMode = true
|
||||
}
|
||||
if (!message.agentEventStream) message.agentEventStream = []
|
||||
if (!message._eventMap) message._eventMap = new Map()
|
||||
if (!message._pendingToolCalls) message._pendingToolCalls = new Map()
|
||||
@@ -79,8 +146,44 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
|
||||
const shouldRenderAssistantMessage = (session: ChatMessage) => {
|
||||
if (!session?.isAgentMode) return true
|
||||
if (!session.is_completed) return true
|
||||
const stream = session.agentEventStream
|
||||
return Array.isArray(stream) && stream.length > 0
|
||||
if (Array.isArray(stream) && stream.length > 0) return true
|
||||
if (Array.isArray(session.knowledge_references) && session.knowledge_references.length > 0) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const shouldShowGlobalTypingIndicator = (
|
||||
messages: ChatMessage[],
|
||||
isLoading: boolean,
|
||||
isRecovering = false,
|
||||
) => {
|
||||
if (!isLoading && !isRecovering) return false
|
||||
const last = messages[messages.length - 1]
|
||||
if (last?.role === 'assistant' && last?.isAgentMode && !last?.is_completed) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/** Quick-answer sessions: restore flags lost after history reload. */
|
||||
const restoreQuickAnswerFlags = (item: ChatMessage) => {
|
||||
if (isAgentStreamSession() || item.role !== 'assistant') return
|
||||
item.isRagMode = true
|
||||
if (
|
||||
item.agent_steps &&
|
||||
Array.isArray(item.agent_steps) &&
|
||||
item.agent_steps.length > 0
|
||||
) {
|
||||
item.isAgentMode = true
|
||||
item.hideContent = true
|
||||
}
|
||||
ensureRagPipelineHistoryStream(item as Parameters<typeof ensureRagPipelineHistoryStream>[0])
|
||||
if (item.isRagMode && item.agentEventStream) {
|
||||
item.agentEventStream = markRaw(item.agentEventStream as object)
|
||||
}
|
||||
}
|
||||
|
||||
const recomposeAgentAnswer = (message: ChatMessage) => {
|
||||
@@ -233,6 +336,8 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
item.hideContent = true
|
||||
}
|
||||
|
||||
restoreQuickAnswerFlags(item)
|
||||
|
||||
if (item.content) {
|
||||
const content = String(item.content)
|
||||
const thinkCloseTag = '</think>'
|
||||
@@ -329,6 +434,7 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
isAgentMode: true,
|
||||
isRagMode: !isAgentStreamSession(),
|
||||
agentEventStream: [],
|
||||
_eventMap: new Map(),
|
||||
knowledge_references: [],
|
||||
@@ -575,14 +681,6 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'references': {
|
||||
if (dataPayload?.references) {
|
||||
message.knowledge_references = dataPayload.references
|
||||
} else if (data.knowledge_references) {
|
||||
message.knowledge_references = data.knowledge_references
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'answer': {
|
||||
message.thinking = false
|
||||
const eventId = dataPayload?.event_id as string | undefined
|
||||
@@ -696,6 +794,7 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
isAgentMode: true,
|
||||
isRagMode: !isAgentStreamSession(),
|
||||
is_completed: false,
|
||||
agentEventStream: [],
|
||||
_eventMap: new Map(),
|
||||
@@ -704,6 +803,7 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
}
|
||||
messagesList.push(existingMessage)
|
||||
onMessageCreated?.(existingMessage)
|
||||
loading.value = false
|
||||
scrollToBottom(true)
|
||||
log('[Agent Query] Created agent placeholder message')
|
||||
} else {
|
||||
@@ -740,36 +840,8 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
isAgentCompleteChunk
|
||||
|
||||
if (data.response_type === 'references') {
|
||||
if (isCurrentlyAgentMode) {
|
||||
handleAgentChunk(data)
|
||||
return
|
||||
}
|
||||
let existingMessage = findLastMessage(
|
||||
(item) => item.request_id === data.id || item.id === data.id,
|
||||
)
|
||||
if (!existingMessage) {
|
||||
existingMessage = {
|
||||
id: data.id,
|
||||
request_id: data.id,
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
showThink: false,
|
||||
thinkContent: '',
|
||||
thinking: false,
|
||||
is_completed: false,
|
||||
knowledge_references: [],
|
||||
}
|
||||
messagesList.push(existingMessage)
|
||||
onMessageCreated?.(existingMessage)
|
||||
loading.value = false
|
||||
scrollToBottom(true)
|
||||
}
|
||||
const refs =
|
||||
data.knowledge_references ||
|
||||
(data.data as ChatMessage | undefined)?.references ||
|
||||
[]
|
||||
existingMessage.knowledge_references = refs
|
||||
log('[References] Saved to message, count:', Array.isArray(refs) ? refs.length : 0)
|
||||
applyKnowledgeReferences(data)
|
||||
scrollToBottom()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -849,6 +921,7 @@ export function useChatStreamHandler(options: UseChatStreamHandlerOptions) {
|
||||
return {
|
||||
findLastMessage,
|
||||
shouldRenderAssistantMessage,
|
||||
shouldShowGlobalTypingIndicator,
|
||||
handleMsgList,
|
||||
processStreamChunk,
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ export type DisplayType =
|
||||
| 'web_search_results'
|
||||
| 'web_fetch_results'
|
||||
| 'grep_results'
|
||||
| 'knowledge_chunks_list'
|
||||
| 'wiki_write_page'
|
||||
| 'wiki_replace_text'
|
||||
| 'wiki_rename_page'
|
||||
@@ -248,12 +249,27 @@ export interface GrepResultsData {
|
||||
chunk_results?: GrepChunkResult[];
|
||||
knowledge_results: GrepKnowledgeResult[];
|
||||
result_count: number;
|
||||
document_count?: number;
|
||||
total_matches: number;
|
||||
knowledge_base_ids?: string[];
|
||||
limit?: number;
|
||||
max_results: number;
|
||||
}
|
||||
|
||||
// Knowledge chunks list data (list_knowledge_chunks tool)
|
||||
export interface KnowledgeChunksListData {
|
||||
display_type: 'knowledge_chunks_list';
|
||||
knowledge_id?: string;
|
||||
knowledge_title?: string;
|
||||
total_chunks?: number;
|
||||
fetched_chunks?: number;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
faq_question?: string;
|
||||
faq_id?: string;
|
||||
single_chunk?: boolean;
|
||||
}
|
||||
|
||||
// Wiki write page data
|
||||
export interface WikiWritePageData {
|
||||
display_type: 'wiki_write_page';
|
||||
@@ -309,6 +325,7 @@ export type ToolResultData =
|
||||
| WebSearchResultsData
|
||||
| WebFetchResultsData
|
||||
| GrepResultsData
|
||||
| KnowledgeChunksListData
|
||||
| WikiWritePageData
|
||||
| WikiReplaceTextData
|
||||
| WikiRenamePageData
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { getAgentToolIconName } from './agent-tool-icons.ts'
|
||||
import {
|
||||
getKnowledgeSearchSummaryHtml,
|
||||
getQueryText,
|
||||
getRagPipelineStepTitle,
|
||||
} from './agent-tool-display.ts'
|
||||
|
||||
const t = (key, params) => {
|
||||
if (key === 'agentStream.search.foundResultsFromFiles') {
|
||||
return `found ${params?.count} from ${params?.files} files`
|
||||
}
|
||||
if (key === 'agentStream.ragPipeline.searchingWithQuery') {
|
||||
return `searching ${params?.query}`
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
test('getAgentToolIconName maps rag pipeline tools', () => {
|
||||
assert.equal(getAgentToolIconName('query_understand'), 'ai-search')
|
||||
assert.equal(getAgentToolIconName('knowledge_search'), 'data-search')
|
||||
})
|
||||
|
||||
test('getQueryText joins unique query strings', () => {
|
||||
assert.equal(getQueryText({ query: 'foo', queries: ['foo', 'bar'] }), 'foo,bar')
|
||||
})
|
||||
|
||||
test('getQueryText parses JSON-encoded queries string', () => {
|
||||
assert.equal(
|
||||
getQueryText({
|
||||
queries: '["合力天胜游泳俱乐部介绍", "合力天胜游泳训练机构", "合力天胜游泳队"]',
|
||||
}),
|
||||
'合力天胜游泳俱乐部介绍,合力天胜游泳训练机构,合力天胜游泳队',
|
||||
)
|
||||
})
|
||||
|
||||
test('getKnowledgeSearchSummaryHtml includes file count when present', () => {
|
||||
const html = getKnowledgeSearchSummaryHtml(t, {
|
||||
results: [{}, {}],
|
||||
kb_counts: { a: 1, b: 2 },
|
||||
})
|
||||
assert.match(html, /found <strong>2<\/strong> from <strong>2<\/strong> files/)
|
||||
})
|
||||
|
||||
test('getRagPipelineStepTitle uses query-aware search labels', () => {
|
||||
const title = getRagPipelineStepTitle(t, {
|
||||
tool_name: 'knowledge_search',
|
||||
pending: true,
|
||||
arguments: { query: '讯飞开放平台' },
|
||||
})
|
||||
assert.equal(title, 'searching 讯飞开放平台')
|
||||
})
|
||||
@@ -0,0 +1,109 @@
|
||||
import type { ComposerTranslation } from 'vue-i18n'
|
||||
|
||||
function collectQueryStrings(value: unknown): string[] {
|
||||
if (value == null) return []
|
||||
|
||||
if (typeof value === 'string') {
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) return []
|
||||
if (trimmed.startsWith('[')) {
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed)
|
||||
if (Array.isArray(parsed)) {
|
||||
return parsed.filter((q): q is string => typeof q === 'string' && Boolean(q.trim()))
|
||||
}
|
||||
} catch {
|
||||
// fall through to treat as a single query string
|
||||
}
|
||||
}
|
||||
return [trimmed]
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value.filter((q): q is string => typeof q === 'string' && Boolean(q.trim()))
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
export function getQueryText(args: unknown): string {
|
||||
if (!args) return ''
|
||||
|
||||
let parsedArgs = args
|
||||
if (typeof parsedArgs === 'string') {
|
||||
try {
|
||||
parsedArgs = JSON.parse(parsedArgs)
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
if (!parsedArgs || typeof parsedArgs !== 'object') return ''
|
||||
|
||||
const queries: string[] = []
|
||||
const record = parsedArgs as Record<string, unknown>
|
||||
|
||||
queries.push(...collectQueryStrings(record.query))
|
||||
queries.push(...collectQueryStrings(record.queries))
|
||||
|
||||
return Array.from(new Set(queries)).join(',')
|
||||
}
|
||||
|
||||
export function getKnowledgeSearchSummaryHtml(
|
||||
t: ComposerTranslation,
|
||||
toolData: Record<string, unknown> | null | undefined,
|
||||
): string {
|
||||
if (!toolData) return ''
|
||||
|
||||
const results = toolData.results
|
||||
const count = (Array.isArray(results) ? results.length : 0) || Number(toolData.count) || 0
|
||||
if (count === 0) return t('agentStream.search.noResults')
|
||||
|
||||
const kbCounts = toolData.kb_counts
|
||||
const kbCount = kbCounts && typeof kbCounts === 'object' ? Object.keys(kbCounts).length : 0
|
||||
if (kbCount > 0) {
|
||||
return t('agentStream.search.foundResultsFromFiles', {
|
||||
count: `<strong>${count}</strong>`,
|
||||
files: `<strong>${kbCount}</strong>`,
|
||||
})
|
||||
}
|
||||
|
||||
return t('agentStream.search.foundResults', { count: `<strong>${count}</strong>` })
|
||||
}
|
||||
|
||||
type RagPipelineEvent = {
|
||||
tool_name?: string
|
||||
pending?: boolean
|
||||
success?: boolean
|
||||
arguments?: unknown
|
||||
tool_data?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export function getRagPipelineStepTitle(t: ComposerTranslation, event: RagPipelineEvent): string {
|
||||
const toolName = String(event.tool_name || '')
|
||||
const pending = event.pending === true
|
||||
const query =
|
||||
getQueryText(event.arguments) ||
|
||||
getQueryText(event.tool_data)
|
||||
|
||||
if (toolName === 'query_understand') {
|
||||
return pending
|
||||
? t('agentStream.toolStatus.queryUnderstanding')
|
||||
: t('agentStream.toolStatus.queryUnderstandDone')
|
||||
}
|
||||
|
||||
if (toolName === 'knowledge_search' || toolName === 'search_knowledge') {
|
||||
if (pending) {
|
||||
return query
|
||||
? t('agentStream.ragPipeline.searchingWithQuery', { query })
|
||||
: t('agentStream.ragPipeline.searching')
|
||||
}
|
||||
|
||||
const baseTitle = event.success === false
|
||||
? t('agentStream.toolStatus.searchKbFailed')
|
||||
: t('agentStream.toolStatus.searchKb')
|
||||
return query ? `${baseTitle}:「${query}」` : baseTitle
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/** TDesign icon names for agent / RAG pipeline tool steps. */
|
||||
export function getAgentToolIconName(toolName: string): string {
|
||||
if (toolName === 'thinking') {
|
||||
return 'ai-search'
|
||||
}
|
||||
if (toolName === 'search_knowledge' || toolName === 'knowledge_search') {
|
||||
return 'data-search'
|
||||
}
|
||||
if (toolName === 'grep_chunks') {
|
||||
return 'search'
|
||||
}
|
||||
if (toolName === 'web_search') {
|
||||
return 'internet'
|
||||
}
|
||||
if (toolName === 'get_document_info' || toolName === 'list_knowledge_chunks') {
|
||||
return 'file-search'
|
||||
}
|
||||
if (toolName === 'get_document_content' || toolName === 'wiki_read_source_doc') {
|
||||
return 'file-search'
|
||||
}
|
||||
if (toolName === 'todo_write') {
|
||||
return 'task'
|
||||
}
|
||||
if (toolName === 'image_analysis' || toolName === 'query_understand') {
|
||||
return 'ai-search'
|
||||
}
|
||||
if (toolName.startsWith('mcp_')) {
|
||||
return 'terminal'
|
||||
}
|
||||
return 'file-paste'
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { countGrepDocuments, groupGrepChunkResults } from './grepResultsGroup.ts'
|
||||
|
||||
test('groupGrepChunkResults merges chunks from the same document', () => {
|
||||
const grouped = groupGrepChunkResults([
|
||||
{
|
||||
chunk_id: 'chunk-a',
|
||||
knowledge_id: 'doc-1',
|
||||
knowledge_base_id: 'kb-1',
|
||||
knowledge_title: 'sample-report.pdf',
|
||||
match_snippet: 'hit one',
|
||||
},
|
||||
{
|
||||
chunk_id: 'chunk-b',
|
||||
knowledge_id: 'doc-1',
|
||||
knowledge_base_id: 'kb-1',
|
||||
knowledge_title: 'sample-report.pdf',
|
||||
match_snippet: 'hit two',
|
||||
},
|
||||
{
|
||||
chunk_id: 'chunk-c',
|
||||
knowledge_id: 'doc-2',
|
||||
knowledge_base_id: 'kb-1',
|
||||
knowledge_title: 'other-report.pdf',
|
||||
match_snippet: 'other hit',
|
||||
},
|
||||
])
|
||||
|
||||
assert.equal(grouped.length, 2)
|
||||
assert.equal(grouped[0].chunk_hit_count, 2)
|
||||
assert.equal(grouped[0].chunks.length, 2)
|
||||
assert.equal(grouped[1].chunk_hit_count, 1)
|
||||
})
|
||||
|
||||
test('groupGrepChunkResults keeps FAQ entries separate', () => {
|
||||
const grouped = groupGrepChunkResults([
|
||||
{
|
||||
chunk_id: 'faq-1',
|
||||
faq_id: 'faq-1',
|
||||
knowledge_id: 'doc-faq',
|
||||
knowledge_base_id: 'kb-1',
|
||||
knowledge_title: 'FAQ doc',
|
||||
chunk_type: 'faq',
|
||||
faq_question: 'Question A',
|
||||
match_snippet: 'answer a',
|
||||
},
|
||||
{
|
||||
chunk_id: 'faq-2',
|
||||
faq_id: 'faq-2',
|
||||
knowledge_id: 'doc-faq',
|
||||
knowledge_base_id: 'kb-1',
|
||||
knowledge_title: 'FAQ doc',
|
||||
chunk_type: 'faq',
|
||||
faq_question: 'Question B',
|
||||
match_snippet: 'answer b',
|
||||
},
|
||||
])
|
||||
|
||||
assert.equal(grouped.length, 2)
|
||||
assert.equal(grouped[0].title, 'Question A')
|
||||
assert.equal(grouped[1].title, 'Question B')
|
||||
})
|
||||
|
||||
test('countGrepDocuments prefers document_count from backend', () => {
|
||||
assert.equal(
|
||||
countGrepDocuments({
|
||||
document_count: 1,
|
||||
knowledge_results: [{ knowledge_id: 'doc-1' }, { knowledge_id: 'doc-2' }],
|
||||
chunk_results: [{ chunk_id: 'c1', knowledge_id: 'doc-1', knowledge_base_id: 'kb', knowledge_title: 'a' }],
|
||||
}),
|
||||
1,
|
||||
)
|
||||
})
|
||||
|
||||
test('countGrepDocuments prefers knowledge_results length when document_count absent', () => {
|
||||
assert.equal(
|
||||
countGrepDocuments({
|
||||
knowledge_results: [{ knowledge_id: 'doc-1' }, { knowledge_id: 'doc-2' }],
|
||||
chunk_results: [{ chunk_id: 'c1', knowledge_id: 'doc-1', knowledge_base_id: 'kb', knowledge_title: 'a' }],
|
||||
}),
|
||||
2,
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,71 @@
|
||||
import type { GrepChunkResult, GrepKnowledgeResult } from '@/types/tool-results'
|
||||
|
||||
export type GrepGroupedRow = {
|
||||
key: string
|
||||
knowledge_id: string
|
||||
title: string
|
||||
is_faq: boolean
|
||||
chunk_hit_count: number
|
||||
title_match: boolean
|
||||
match_snippet: string
|
||||
chunks: { content: string; chunk_id: string; knowledge_id: string }[]
|
||||
}
|
||||
|
||||
/** Collapse per-chunk grep hits into one row per document; FAQ entries stay separate. */
|
||||
export function groupGrepChunkResults(chunkRows: GrepChunkResult[]): GrepGroupedRow[] {
|
||||
const map = new Map<string, GrepGroupedRow>()
|
||||
const order: string[] = []
|
||||
|
||||
for (const result of chunkRows) {
|
||||
const isFAQ = !!result.faq_id || result.chunk_type === 'faq'
|
||||
const key = isFAQ ? (result.faq_id || result.chunk_id) : result.knowledge_id
|
||||
if (!key) continue
|
||||
|
||||
const snippet = String(result.match_snippet ?? '').trim()
|
||||
if (!map.has(key)) {
|
||||
map.set(key, {
|
||||
key,
|
||||
knowledge_id: result.knowledge_id,
|
||||
title: result.faq_question || result.knowledge_title || '',
|
||||
is_faq: isFAQ,
|
||||
chunk_hit_count: 0,
|
||||
title_match: false,
|
||||
match_snippet: snippet,
|
||||
chunks: [],
|
||||
})
|
||||
order.push(key)
|
||||
}
|
||||
|
||||
const group = map.get(key)!
|
||||
group.chunk_hit_count += 1
|
||||
if (result.title_match) group.title_match = true
|
||||
if (!group.match_snippet && snippet) group.match_snippet = snippet
|
||||
if (snippet) {
|
||||
group.chunks.push({
|
||||
content: snippet,
|
||||
chunk_id: result.faq_id || result.chunk_id,
|
||||
knowledge_id: result.knowledge_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return order.map((key) => map.get(key)!)
|
||||
}
|
||||
|
||||
export function countGrepDocuments(toolData: {
|
||||
document_count?: number
|
||||
knowledge_results?: GrepKnowledgeResult[]
|
||||
chunk_results?: GrepChunkResult[]
|
||||
} | null | undefined): number {
|
||||
if (!toolData) return 0
|
||||
if (typeof toolData.document_count === 'number' && toolData.document_count >= 0) {
|
||||
return toolData.document_count
|
||||
}
|
||||
if (toolData.knowledge_results?.length) {
|
||||
return toolData.knowledge_results.length
|
||||
}
|
||||
if (toolData.chunk_results?.length) {
|
||||
return groupGrepChunkResults(toolData.chunk_results).length
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { getKnowledgeChunksSummaryHtml } from './knowledgeChunksDisplay.ts'
|
||||
|
||||
const t = (key, params) => {
|
||||
if (key === 'agentStream.knowledgeChunksList.chunkRange') {
|
||||
return `loaded ${params?.fetched}/${params?.total}`
|
||||
}
|
||||
if (key === 'agentStream.knowledgeChunksList.page') {
|
||||
return `page ${params?.page}/${params?.pageSize}`
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
test('getKnowledgeChunksSummaryHtml joins chunk range and page', () => {
|
||||
const html = getKnowledgeChunksSummaryHtml(t, {
|
||||
display_type: 'knowledge_chunks_list',
|
||||
fetched_chunks: 20,
|
||||
total_chunks: 282,
|
||||
page: 3,
|
||||
page_size: 20,
|
||||
})
|
||||
assert.match(html, /loaded <strong>20<\/strong>\/<strong>282<\/strong>/)
|
||||
assert.match(html, /page 3\/20/)
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { ComposerTranslation } from 'vue-i18n'
|
||||
|
||||
import type { KnowledgeChunksListData } from '@/types/tool-results'
|
||||
|
||||
export function getKnowledgeChunksSummaryHtml(
|
||||
t: ComposerTranslation,
|
||||
toolData: KnowledgeChunksListData | null | undefined,
|
||||
): string {
|
||||
if (!toolData || toolData.fetched_chunks === undefined) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const parts: string[] = [
|
||||
t('agentStream.knowledgeChunksList.chunkRange', {
|
||||
fetched: `<strong>${toolData.fetched_chunks ?? 0}</strong>`,
|
||||
total: `<strong>${toolData.total_chunks ?? '?'}</strong>`,
|
||||
}),
|
||||
]
|
||||
|
||||
const total = Number(toolData.total_chunks ?? 0)
|
||||
const pageSize = Number(toolData.page_size ?? 0)
|
||||
if (total > pageSize && pageSize > 0) {
|
||||
parts.push(
|
||||
t('agentStream.knowledgeChunksList.page', {
|
||||
page: toolData.page ?? 1,
|
||||
pageSize,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
return parts.join(' · ')
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
ensureRagPipelineHistoryStream,
|
||||
hasRagPipelineToolEvents,
|
||||
synthesizeRagPipelineToolEvents,
|
||||
} from './rag-pipeline-history.ts'
|
||||
|
||||
test('synthesizeRagPipelineToolEvents builds completed retrieval steps', () => {
|
||||
const events = synthesizeRagPipelineToolEvents({
|
||||
knowledge_references: [
|
||||
{ knowledge_id: 'a' },
|
||||
{ knowledge_id: 'a' },
|
||||
{ knowledge_id: 'b' },
|
||||
],
|
||||
})
|
||||
|
||||
assert.equal(events.length, 2)
|
||||
assert.equal(events[0].tool_name, 'query_understand')
|
||||
assert.equal(events[1].tool_name, 'knowledge_search')
|
||||
assert.equal(events[1].tool_data.count, 3)
|
||||
})
|
||||
|
||||
test('ensureRagPipelineHistoryStream restores quick-answer history after reload', () => {
|
||||
const item = {
|
||||
is_completed: true,
|
||||
content: 'final answer',
|
||||
knowledge_references: [{ knowledge_id: 'doc-1' }],
|
||||
agentEventStream: [],
|
||||
}
|
||||
|
||||
ensureRagPipelineHistoryStream(item)
|
||||
|
||||
assert.equal(item.isAgentMode, true)
|
||||
assert.equal(item.hideContent, true)
|
||||
assert.equal(hasRagPipelineToolEvents(item.agentEventStream), true)
|
||||
assert.equal(
|
||||
item.agentEventStream.some((event) => event.type === 'answer'),
|
||||
true,
|
||||
)
|
||||
})
|
||||
|
||||
test('ensureRagPipelineHistoryStream keeps existing pipeline events', () => {
|
||||
const existing = {
|
||||
type: 'tool_call',
|
||||
tool_name: 'knowledge_search',
|
||||
tool_call_id: 'live-1',
|
||||
pending: false,
|
||||
}
|
||||
const item = {
|
||||
is_completed: true,
|
||||
content: 'answer',
|
||||
agentEventStream: [existing],
|
||||
}
|
||||
|
||||
ensureRagPipelineHistoryStream(item)
|
||||
|
||||
assert.equal(item.agentEventStream.length, 1)
|
||||
assert.equal(item.agentEventStream[0].tool_call_id, 'live-1')
|
||||
})
|
||||
@@ -0,0 +1,106 @@
|
||||
export const RAG_PIPELINE_TOOL_NAMES = new Set(['query_understand', 'knowledge_search'])
|
||||
|
||||
type RagHistoryMessage = {
|
||||
knowledge_references?: Array<{
|
||||
chunk_type?: string
|
||||
knowledge_id?: string
|
||||
knowledge_title?: string
|
||||
}>
|
||||
agentEventStream?: Array<Record<string, unknown>>
|
||||
}
|
||||
|
||||
export function hasRagPipelineToolEvents(stream: Array<Record<string, unknown>> | undefined): boolean {
|
||||
if (!stream?.length) return false
|
||||
return stream.some((event) => {
|
||||
return (
|
||||
event.type === 'tool_call' &&
|
||||
typeof event.tool_name === 'string' &&
|
||||
RAG_PIPELINE_TOOL_NAMES.has(event.tool_name)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export function synthesizeRagPipelineToolEvents(
|
||||
item: RagHistoryMessage,
|
||||
): Array<Record<string, unknown>> {
|
||||
const refs = item.knowledge_references ?? []
|
||||
const kbCounts: Record<string, number> = {}
|
||||
|
||||
for (const ref of refs) {
|
||||
if (ref.chunk_type === 'web_search') continue
|
||||
const key = ref.knowledge_id || ref.knowledge_title || 'document'
|
||||
kbCounts[key] = (kbCounts[key] || 0) + 1
|
||||
}
|
||||
|
||||
const events: Array<Record<string, unknown>> = [
|
||||
{
|
||||
type: 'tool_call',
|
||||
tool_call_id: 'rag-history-query-understand',
|
||||
tool_name: 'query_understand',
|
||||
pending: false,
|
||||
success: true,
|
||||
},
|
||||
{
|
||||
type: 'tool_call',
|
||||
tool_call_id: 'rag-history-knowledge-search',
|
||||
tool_name: 'knowledge_search',
|
||||
pending: false,
|
||||
success: true,
|
||||
tool_data: {
|
||||
count: refs.length,
|
||||
kb_counts: kbCounts,
|
||||
results: refs,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
return events
|
||||
}
|
||||
|
||||
export function ensureRagPipelineHistoryStream(item: RagHistoryMessage & {
|
||||
content?: string
|
||||
is_completed?: boolean
|
||||
isAgentMode?: boolean
|
||||
hideContent?: boolean
|
||||
}): void {
|
||||
if (!item.is_completed) return
|
||||
|
||||
const stream = Array.isArray(item.agentEventStream)
|
||||
? [...item.agentEventStream]
|
||||
: []
|
||||
|
||||
if (hasRagPipelineToolEvents(stream)) return
|
||||
|
||||
const hasRestorablePayload =
|
||||
Boolean(item.content?.trim()) ||
|
||||
Boolean(item.knowledge_references?.length)
|
||||
if (!hasRestorablePayload) return
|
||||
|
||||
const synthesized = synthesizeRagPipelineToolEvents(item)
|
||||
const preserved = stream.filter((event) => {
|
||||
return !(
|
||||
event.type === 'tool_call' &&
|
||||
typeof event.tool_name === 'string' &&
|
||||
RAG_PIPELINE_TOOL_NAMES.has(event.tool_name)
|
||||
)
|
||||
})
|
||||
|
||||
item.agentEventStream = [...synthesized, ...preserved]
|
||||
|
||||
const hasAnswer = preserved.some((event) => {
|
||||
if (event.type !== 'answer' || event.superseded) return false
|
||||
const content = event.content
|
||||
return typeof content === 'string' && content.trim().length > 0
|
||||
})
|
||||
|
||||
if (!hasAnswer && item.content?.trim()) {
|
||||
item.agentEventStream.push({
|
||||
type: 'answer',
|
||||
content: item.content,
|
||||
done: true,
|
||||
})
|
||||
}
|
||||
|
||||
item.isAgentMode = true
|
||||
item.hideContent = true
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const source = readFileSync(join(here, 'AgentStreamDisplay.vue'), 'utf8')
|
||||
|
||||
test('agent steps use compact muted timeline styling', () => {
|
||||
assert.match(source, /--agent-step-text-size:\s*14px/)
|
||||
assert.match(source, /--agent-step-summary-size:\s*13px/)
|
||||
assert.match(source, /--agent-step-icon-color:\s*var\(--td-text-color-placeholder\)/)
|
||||
assert.match(source, /max-height:\s*none/)
|
||||
assert.match(source, /overflow-y:\s*visible/)
|
||||
assert.match(source, /\.tree-root \.action-name\s*\{[\s\S]*font-size:\s*14px/)
|
||||
assert.match(source, /\.tree-child \.action-title-icon\s*\{[\s\S]*position:\s*absolute/)
|
||||
assert.match(source, /function maskIconStyle\(src: string, size = 18\)/)
|
||||
assert.match(source, /\.icon-mask\s*\{[\s\S]*background-color:\s*var\(--agent-step-icon-color\)/)
|
||||
assert.doesNotMatch(source, /\.action-title \.action-title-icon,\s*\n\s*\.icon-mask\s*\{/)
|
||||
})
|
||||
|
||||
test('expanded agent step log hides raw thinking narration', () => {
|
||||
assert.match(source, /visibleIntermediateEvents\s*=\s*computed/)
|
||||
assert.match(source, /e\.type === 'thinking'\)\s*return false/)
|
||||
assert.match(source, /e\.type === 'tool_call' && e\.tool_name === 'thinking'\)\s*return false/)
|
||||
assert.match(source, /v-for="\(event, index\) in visibleIntermediateEvents"/)
|
||||
})
|
||||
|
||||
test('streaming log also hides raw thinking narration', () => {
|
||||
assert.match(source, /if \(!isConversationDone\.value\)\s*\{\s*return result\.filter/)
|
||||
assert.match(source, /e\.type === 'thinking'\) return false/)
|
||||
assert.match(source, /e\.type === 'tool_call' && e\.tool_name === 'thinking'\) return false/)
|
||||
assert.doesNotMatch(source, /if \(!isConversationDone\.value\)\s*\{\s*return result;\s*\}/)
|
||||
})
|
||||
|
||||
test('streaming tool log uses the same timeline structure', () => {
|
||||
assert.match(source, /'is-streaming-timeline': showStreamingTimeline/)
|
||||
assert.match(source, /'tree-child': isStreamingTimelineEvent\(event\)/)
|
||||
assert.match(source, /class="tree-child tree-child-last streaming-loading-node"/)
|
||||
assert.match(source, /chat-timeline-loading\.less/)
|
||||
assert.match(source, /lastStreamingTimelineEventIndex\s*=\s*computed/)
|
||||
})
|
||||
|
||||
test('final done row uses an existing common translation key', () => {
|
||||
assert.match(source, /t\('common\.finish'\)/)
|
||||
assert.doesNotMatch(source, /\$t\('common\.done'\)/)
|
||||
assert.match(source, /'tree-child-last': !isConversationDone && index === visibleIntermediateEvents\.length - 1/)
|
||||
})
|
||||
|
||||
test('tool rows use line icon names instead of legacy asset masks', () => {
|
||||
assert.match(source, /getAgentToolIconName/)
|
||||
assert.match(source, /:name="getToolIconName\(event\.tool_name\)"/)
|
||||
assert.match(source, /wiki_read_source_doc: 'agentStream\.tools\.wikiReadSourceDoc'/)
|
||||
assert.match(source, /toolName === 'get_document_content' \|\| toolName === 'wiki_read_source_doc'/)
|
||||
assert.doesNotMatch(source, /getToolIcon\(event\.tool_name\)/)
|
||||
})
|
||||
|
||||
test('rag mode delegates pre-answer loading to pipeline and keeps dots while answer streams', () => {
|
||||
assert.match(source, /if \(props\.ragMode\) return hasAnswerStarted\.value/)
|
||||
assert.match(source, /v-if="!ragMode \|\| displayEvents\.length > 0 \|\| showAgentActivityIndicator"/)
|
||||
})
|
||||
|
||||
test('only the collapsed root summary shows an expand chevron', () => {
|
||||
assert.match(source, /tree-root-summary[\s\S]*class="action-show-icon"/)
|
||||
assert.match(source, /showIntermediateSteps \? 'chevron-down' : 'chevron-right'/)
|
||||
assert.doesNotMatch(source, /isEventExpanded\(event\.tool_call_id\) \? 'chevron/)
|
||||
assert.doesNotMatch(source, /isEventExpanded\(event\.event_id\) \? 'chevron/)
|
||||
})
|
||||
|
||||
test('pending tool rows do not render an extra axis dot', () => {
|
||||
assert.doesNotMatch(source, /&\.action-pending\s*\{[\s\S]*&::after/)
|
||||
})
|
||||
|
||||
test('agent mode keeps gray timeline dots for the full turn', () => {
|
||||
assert.match(source, /if \(isConversationDone\.value\) return false/)
|
||||
assert.match(source, /if \(props\.ragMode\) return false/)
|
||||
assert.match(source, /return true;\s*\}\);/)
|
||||
assert.match(source, /chat-timeline-loading\.less/)
|
||||
})
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,67 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const source = readFileSync(join(here, 'RagPipelineProgress.vue'), 'utf8')
|
||||
|
||||
test('rag pipeline uses agent-style timeline structure', () => {
|
||||
assert.match(source, /class="tree-children"/)
|
||||
assert.match(source, /class="tree-child/)
|
||||
assert.match(source, /getAgentToolIconName/)
|
||||
assert.match(source, /name="check-circle"/)
|
||||
assert.match(source, /streaming-loading-node/)
|
||||
assert.match(source, /@import ['"]@\/components\/css\/chat-timeline-loading\.less['"]/)
|
||||
assert.match(source, /search-results-summary-fixed/)
|
||||
})
|
||||
|
||||
test('rag pipeline persists and collapses after the answer arrives', () => {
|
||||
assert.match(source, /showCollapsedRoot/)
|
||||
assert.match(source, /tree-root-summary/)
|
||||
assert.match(source, /collapsedSummaryHtml/)
|
||||
assert.match(source, /visible = computed\(\(\) => steps\.value\.length > 0 \|\| showPrePipelineWait\.value\)/)
|
||||
})
|
||||
|
||||
test('rag pipeline toggles expand and collapse from the root header', () => {
|
||||
assert.match(source, /class="action-card tree-root" @click="toggleExpanded"/)
|
||||
assert.match(source, /showExpandedTimeline \? 'chevron-down' : 'chevron-right'/)
|
||||
assert.doesNotMatch(source, /refsExpanded \? 'chevron/)
|
||||
assert.doesNotMatch(source, /tree-collapse-bar/)
|
||||
})
|
||||
|
||||
test('only the collapsed root summary shows an expand chevron', () => {
|
||||
assert.match(source, /tree-root-summary[\s\S]*class="action-show-icon"/)
|
||||
assert.equal((source.match(/class="action-show-icon"/g) || []).length, 1)
|
||||
})
|
||||
|
||||
test('rag pipeline embeds references in the timeline instead of a separate card', () => {
|
||||
assert.match(source, /timeline-mode/)
|
||||
assert.match(source, /content-only/)
|
||||
assert.match(source, /rag-ref-step[\s\S]*name="file-search"/)
|
||||
})
|
||||
|
||||
test('rag pipeline keeps loading inside the timeline without duplicate dots', () => {
|
||||
assert.match(source, /showPrePipelineWait/)
|
||||
assert.match(source, /showActivityIndicator = computed\(\s*\(\) => steps\.value\.length > 0 && !hasAnswer\.value/)
|
||||
assert.match(source, /showPrePipelineWait = computed/)
|
||||
})
|
||||
|
||||
test('rag pipeline places references before the done row', () => {
|
||||
const refsIndex = source.indexOf('class="tree-child rag-ref-step"')
|
||||
const doneIndex = source.indexOf('agent-step-done')
|
||||
assert.ok(refsIndex > -1 && doneIndex > -1)
|
||||
assert.ok(refsIndex < doneIndex)
|
||||
})
|
||||
|
||||
test('clickable timeline headers use pointer cursor', () => {
|
||||
assert.match(source, /\.tool-event \{[\s\S]*\.action-header \{[\s\S]*cursor: pointer/)
|
||||
assert.match(source, /\.action-header \{[\s\S]*&\.no-results \{[\s\S]*cursor: default/)
|
||||
assert.match(source, /\.tree-root \{[\s\S]*cursor: pointer/)
|
||||
})
|
||||
|
||||
test('collapsed summary uses the same title-to-answer spacing as agent', () => {
|
||||
assert.match(source, /\.tree-container \{\s*margin: 0 0 16px;/)
|
||||
assert.match(source, /\.rag-pipeline-progress \{[\s\S]*margin: 0;/)
|
||||
})
|
||||
@@ -0,0 +1,534 @@
|
||||
<template>
|
||||
<div v-if="visible" class="rag-pipeline-progress">
|
||||
<div v-if="showPrePipelineWait" class="tree-children">
|
||||
<div class="tree-child tree-child-last streaming-loading-node">
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="loading-indicator">
|
||||
<div class="loading-typing">
|
||||
<span />
|
||||
<span />
|
||||
<span />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="!showCollapsedRoot" class="tree-children">
|
||||
<div v-for="(step, index) in steps" :key="step.id" class="tree-child" :class="{
|
||||
'tree-child-last':
|
||||
!showActivityIndicator
|
||||
&& !showDoneRow
|
||||
&& !hasReferences
|
||||
&& index === steps.length - 1,
|
||||
}">
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="tool-event">
|
||||
<div class="action-card">
|
||||
<div class="action-header no-results">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" :name="step.iconName" />
|
||||
<span class="action-name">{{ step.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="step.summaryHtml" class="search-results-summary-fixed">
|
||||
<div class="results-summary-text" v-html="step.summaryHtml" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="hasReferences" class="tree-child rag-ref-step"
|
||||
:class="{ 'tree-child-last': !showDoneRow && !showActivityIndicator }">
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="tool-event">
|
||||
<div class="action-card">
|
||||
<div class="action-header" @click="toggleReferences">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" name="file-search" />
|
||||
<span class="action-name">{{ referencesHeaderText }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<DocInfo v-show="refsExpanded" :session="session" :embedded-mode="embeddedMode" timeline-mode
|
||||
content-only />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showDoneRow" class="tree-child agent-step-done" :class="{ 'tree-child-last': !showActivityIndicator }">
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="tool-event">
|
||||
<div class="action-card">
|
||||
<div class="action-header no-results">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" name="check-circle" />
|
||||
<span class="action-name">{{ t('common.finish') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showActivityIndicator" class="tree-child tree-child-last streaming-loading-node">
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="loading-indicator">
|
||||
<div class="loading-typing">
|
||||
<span />
|
||||
<span />
|
||||
<span />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="tree-container">
|
||||
<div class="tool-event">
|
||||
<div class="action-card tree-root" @click="toggleExpanded">
|
||||
<div class="action-header">
|
||||
<div class="action-title">
|
||||
<span class="action-name tree-root-summary" v-html="collapsedSummaryHtml" />
|
||||
<div class="action-show-icon">
|
||||
<t-icon :name="showExpandedTimeline ? 'chevron-down' : 'chevron-right'" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showExpandedTimeline" class="tree-children tree-children-expanded">
|
||||
<div v-for="(step, index) in steps" :key="step.id" class="tree-child"
|
||||
:class="{ 'tree-child-last': index === steps.length - 1 && !hasReferences && !showDoneRow }">
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="tool-event">
|
||||
<div class="action-card">
|
||||
<div class="action-header no-results">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" :name="step.iconName" />
|
||||
<span class="action-name">{{ step.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="step.summaryHtml" class="search-results-summary-fixed">
|
||||
<div class="results-summary-text" v-html="step.summaryHtml" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="hasReferences" class="tree-child rag-ref-step" :class="{ 'tree-child-last': !showDoneRow }">
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="tool-event">
|
||||
<div class="action-card">
|
||||
<div class="action-header" @click="toggleReferences">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" name="file-search" />
|
||||
<span class="action-name">{{ referencesHeaderText }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<DocInfo v-show="refsExpanded" :session="session" :embedded-mode="embeddedMode" timeline-mode
|
||||
content-only />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showDoneRow" class="tree-child agent-step-done tree-child-last">
|
||||
<div class="tree-branch" />
|
||||
<div class="tree-child-content">
|
||||
<div class="tool-event">
|
||||
<div class="action-card">
|
||||
<div class="action-header no-results">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" name="check-circle" />
|
||||
<span class="action-name">{{ t('common.finish') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import DocInfo from './docInfo.vue'
|
||||
import { getAgentToolIconName } from '@/utils/agent-tool-icons'
|
||||
import {
|
||||
getKnowledgeSearchSummaryHtml,
|
||||
getRagPipelineStepTitle,
|
||||
} from '@/utils/agent-tool-display'
|
||||
import { RAG_PIPELINE_TOOL_NAMES } from '@/utils/rag-pipeline-history'
|
||||
|
||||
const props = defineProps<{
|
||||
session?: {
|
||||
agentEventStream?: Array<Record<string, unknown>>
|
||||
content?: string
|
||||
knowledge_references?: Array<{ chunk_type?: string; knowledge_id?: string; knowledge_title?: string }>
|
||||
is_completed?: boolean
|
||||
}
|
||||
embeddedMode?: boolean
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const userExpanded = ref(false)
|
||||
const refsExpanded = ref(false)
|
||||
|
||||
const hasAnswer = computed(() => {
|
||||
const sessionContent = props.session?.content
|
||||
if (typeof sessionContent === 'string' && sessionContent.trim().length > 0) return true
|
||||
|
||||
const stream = props.session?.agentEventStream
|
||||
if (!stream?.length) return false
|
||||
return stream.some((event) => {
|
||||
if (event.type !== 'answer' || event.superseded) return false
|
||||
const content = event.content
|
||||
return typeof content === 'string' && content.trim().length > 0
|
||||
})
|
||||
})
|
||||
|
||||
const hasReferences = computed(
|
||||
() => (props.session?.knowledge_references?.length ?? 0) > 0,
|
||||
)
|
||||
|
||||
const steps = computed(() => {
|
||||
const stream = props.session?.agentEventStream
|
||||
if (!stream?.length) return []
|
||||
|
||||
return stream
|
||||
.filter((event) => {
|
||||
return (
|
||||
event.type === 'tool_call' &&
|
||||
typeof event.tool_name === 'string' &&
|
||||
RAG_PIPELINE_TOOL_NAMES.has(event.tool_name)
|
||||
)
|
||||
})
|
||||
.map((event) => {
|
||||
const toolName = String(event.tool_name)
|
||||
const pending = event.pending === true
|
||||
const toolData =
|
||||
event.tool_data && typeof event.tool_data === 'object'
|
||||
? (event.tool_data as Record<string, unknown>)
|
||||
: null
|
||||
|
||||
const isSearchTool = toolName === 'knowledge_search' || toolName === 'search_knowledge'
|
||||
const summaryHtml =
|
||||
!pending && isSearchTool && toolData
|
||||
? getKnowledgeSearchSummaryHtml(t, toolData)
|
||||
: ''
|
||||
|
||||
return {
|
||||
id: String(event.tool_call_id || `${toolName}-${event.timestamp || 0}`),
|
||||
pending,
|
||||
iconName: getAgentToolIconName(toolName),
|
||||
title: getRagPipelineStepTitle(t, {
|
||||
tool_name: toolName,
|
||||
pending,
|
||||
success: event.success as boolean | undefined,
|
||||
arguments: event.arguments,
|
||||
tool_data: toolData,
|
||||
}),
|
||||
summaryHtml,
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const allStepsDone = computed(
|
||||
() => steps.value.length > 0 && steps.value.every((step) => !step.pending),
|
||||
)
|
||||
|
||||
const showCollapsedRoot = computed(
|
||||
() => (hasAnswer.value || Boolean(props.session?.is_completed)) && steps.value.length > 0,
|
||||
)
|
||||
|
||||
const showExpandedTimeline = computed(() => {
|
||||
if (!showCollapsedRoot.value) return true
|
||||
return userExpanded.value
|
||||
})
|
||||
|
||||
const showDoneRow = computed(() => allStepsDone.value)
|
||||
|
||||
const showPrePipelineWait = computed(
|
||||
() => !hasAnswer.value && !props.session?.is_completed && steps.value.length === 0,
|
||||
)
|
||||
|
||||
// Trailing dots on the timeline axis while pipeline steps are running or waiting for the answer.
|
||||
const showActivityIndicator = computed(
|
||||
() => steps.value.length > 0 && !hasAnswer.value && !props.session?.is_completed,
|
||||
)
|
||||
|
||||
const visible = computed(() => steps.value.length > 0 || showPrePipelineWait.value)
|
||||
|
||||
const referenceDocCount = computed(() => {
|
||||
const refs = props.session?.knowledge_references ?? []
|
||||
const keys = new Set<string>()
|
||||
for (const item of refs) {
|
||||
if (item.chunk_type === 'web_search') continue
|
||||
keys.add(item.knowledge_id || item.knowledge_title || 'doc')
|
||||
}
|
||||
return keys.size
|
||||
})
|
||||
|
||||
const referenceWebCount = computed(() => {
|
||||
const refs = props.session?.knowledge_references ?? []
|
||||
return refs.filter((item) => item.chunk_type === 'web_search').length
|
||||
})
|
||||
|
||||
const referencesHeaderText = computed(() => {
|
||||
const docCount = referenceDocCount.value
|
||||
const webCount = referenceWebCount.value
|
||||
const total = props.session?.knowledge_references?.length ?? 0
|
||||
|
||||
if (docCount > 0 && webCount > 0) {
|
||||
return t('chat.referencesDocAndWebCount', { docCount, webCount })
|
||||
}
|
||||
if (docCount > 0) {
|
||||
return t('chat.referencesDocCount', { count: docCount })
|
||||
}
|
||||
return t('chat.referencesTitle', { count: total })
|
||||
})
|
||||
|
||||
const collapsedSummaryHtml = computed(() => {
|
||||
const parts: string[] = [t('agentStream.ragPipeline.searchDone')]
|
||||
const docCount = referenceDocCount.value
|
||||
const webCount = referenceWebCount.value
|
||||
|
||||
if (docCount > 0 && webCount > 0) {
|
||||
parts.push(
|
||||
t('agentStream.ragPipeline.referencedDocAndWeb', {
|
||||
docCount: `<strong>${docCount}</strong>`,
|
||||
webCount: `<strong>${webCount}</strong>`,
|
||||
}),
|
||||
)
|
||||
} else if (docCount > 0) {
|
||||
parts.push(
|
||||
t('agentStream.ragPipeline.referencedDocs', {
|
||||
count: `<strong>${docCount}</strong>`,
|
||||
}),
|
||||
)
|
||||
} else if (webCount > 0) {
|
||||
parts.push(
|
||||
t('agentStream.ragPipeline.referencedWebs', {
|
||||
count: `<strong>${webCount}</strong>`,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
return parts.join(t('agent.stepSummarySeparator'))
|
||||
})
|
||||
|
||||
function toggleExpanded() {
|
||||
userExpanded.value = !userExpanded.value
|
||||
}
|
||||
|
||||
function toggleReferences() {
|
||||
refsExpanded.value = !refsExpanded.value
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@import '@/components/css/chat-timeline-loading.less';
|
||||
|
||||
.rag-pipeline-progress {
|
||||
--agent-step-text-size: 14px;
|
||||
--agent-step-summary-size: 13px;
|
||||
--agent-step-line-color: color-mix(in srgb, var(--td-text-color-primary) 16%, transparent);
|
||||
--agent-step-icon-color: var(--td-text-color-placeholder);
|
||||
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tree-container {
|
||||
margin: 0 0 16px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tree-root {
|
||||
cursor: pointer;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin-bottom: 0;
|
||||
|
||||
.action-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 24px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.action-title {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.tree-root-summary {
|
||||
font-size: 14px;
|
||||
line-height: 1.55;
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
:deep(strong) {
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.action-show-icon {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.tree-children {
|
||||
position: relative;
|
||||
padding-left: 0;
|
||||
margin-top: 0;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.tree-children-expanded {
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.tree-child {
|
||||
position: relative;
|
||||
padding-left: 42px;
|
||||
padding-bottom: 0;
|
||||
margin-bottom: 18px;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 9px;
|
||||
top: 22px;
|
||||
bottom: -18px;
|
||||
width: 0;
|
||||
border-left: 1px solid var(--agent-step-line-color);
|
||||
}
|
||||
|
||||
.tree-branch {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&.tree-child-last {
|
||||
margin-bottom: 0;
|
||||
|
||||
&::before {
|
||||
content: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.rag-ref-step {
|
||||
.action-header {
|
||||
width: 100%;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.action-title {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.action-show-icon {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:deep(.refer-timeline.refer) {
|
||||
margin-top: 4px;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
:deep(.refer-timeline .doc-group-chunks) {
|
||||
padding-left: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.tool-event {
|
||||
.action-card {
|
||||
position: relative;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.action-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 24px;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
|
||||
&.no-results {
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
|
||||
.action-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
position: relative;
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
|
||||
.action-show-icon {
|
||||
flex-shrink: 0;
|
||||
margin-left: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.action-title-icon {
|
||||
position: absolute;
|
||||
left: -42px;
|
||||
top: 3px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
flex-shrink: 0;
|
||||
color: var(--agent-step-icon-color);
|
||||
}
|
||||
|
||||
.action-name {
|
||||
font-size: var(--agent-step-text-size);
|
||||
line-height: 1.55;
|
||||
font-weight: 400;
|
||||
color: var(--td-text-color-secondary);
|
||||
word-break: break-word;
|
||||
max-width: min(680px, 100%);
|
||||
}
|
||||
}
|
||||
|
||||
.search-results-summary-fixed {
|
||||
padding: 2px 0 0 0;
|
||||
|
||||
.results-summary-text {
|
||||
font-size: var(--agent-step-summary-size);
|
||||
font-weight: 400;
|
||||
color: var(--td-text-color-secondary);
|
||||
line-height: 1.5;
|
||||
|
||||
:deep(strong) {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,84 +1,51 @@
|
||||
<template>
|
||||
<div class="tool-result-renderer">
|
||||
<!-- Search Results -->
|
||||
<SearchResults
|
||||
v-if="displayType === 'search_results'"
|
||||
:data="toolData as SearchResultsData"
|
||||
:arguments="toolArguments"
|
||||
/>
|
||||
|
||||
<SearchResults v-if="displayType === 'search_results'" :data="toolData as SearchResultsData"
|
||||
:arguments="toolArguments" />
|
||||
|
||||
<!-- Chunk Detail -->
|
||||
<ChunkDetail
|
||||
v-else-if="displayType === 'chunk_detail'"
|
||||
:data="toolData as ChunkDetailData"
|
||||
/>
|
||||
|
||||
<ChunkDetail v-else-if="displayType === 'chunk_detail'" :data="toolData as ChunkDetailData" />
|
||||
|
||||
<!-- Related Chunks -->
|
||||
<RelatedChunks
|
||||
v-else-if="displayType === 'related_chunks'"
|
||||
:data="toolData as RelatedChunksData"
|
||||
/>
|
||||
|
||||
<RelatedChunks v-else-if="displayType === 'related_chunks'" :data="toolData as RelatedChunksData" />
|
||||
|
||||
<!-- Knowledge Base List -->
|
||||
<KnowledgeBaseList
|
||||
v-else-if="displayType === 'knowledge_base_list'"
|
||||
:data="toolData as KnowledgeBaseListData"
|
||||
/>
|
||||
|
||||
<KnowledgeBaseList v-else-if="displayType === 'knowledge_base_list'" :data="toolData as KnowledgeBaseListData" />
|
||||
|
||||
<!-- Document Info -->
|
||||
<DocumentInfo
|
||||
v-else-if="displayType === 'document_info'"
|
||||
:data="toolData as DocumentInfoData"
|
||||
/>
|
||||
|
||||
<DocumentInfo v-else-if="displayType === 'document_info'" :data="toolData as DocumentInfoData" />
|
||||
|
||||
<!-- Graph Query Results -->
|
||||
<GraphQueryResults
|
||||
v-else-if="displayType === 'graph_query_results'"
|
||||
:data="toolData as GraphQueryResultsData"
|
||||
/>
|
||||
|
||||
<GraphQueryResults v-else-if="displayType === 'graph_query_results'" :data="toolData as GraphQueryResultsData" />
|
||||
|
||||
<!-- Thinking Display -->
|
||||
<ThinkingDisplay
|
||||
v-else-if="displayType === 'thinking'"
|
||||
:data="toolData as ThinkingData"
|
||||
/>
|
||||
|
||||
<ThinkingDisplay v-else-if="displayType === 'thinking'" :data="toolData as ThinkingData" />
|
||||
|
||||
<!-- Plan Display -->
|
||||
<PlanDisplay
|
||||
v-else-if="displayType === 'plan'"
|
||||
:data="toolData as PlanData"
|
||||
/>
|
||||
|
||||
<PlanDisplay v-else-if="displayType === 'plan'" :data="toolData as PlanData" />
|
||||
|
||||
<!-- Database Query Display -->
|
||||
<DatabaseQuery
|
||||
v-else-if="displayType === 'database_query'"
|
||||
:data="toolData as DatabaseQueryData"
|
||||
/>
|
||||
|
||||
<DatabaseQuery v-else-if="displayType === 'database_query'" :data="toolData as DatabaseQueryData" />
|
||||
|
||||
<!-- Web Search Results Display -->
|
||||
<WebSearchResults
|
||||
v-else-if="displayType === 'web_search_results'"
|
||||
:data="toolData as WebSearchResultsData"
|
||||
/>
|
||||
|
||||
<WebSearchResults v-else-if="displayType === 'web_search_results'" :data="toolData as WebSearchResultsData" />
|
||||
|
||||
<!-- Web Fetch Results Display -->
|
||||
<WebFetchResults
|
||||
v-else-if="displayType === 'web_fetch_results'"
|
||||
:data="toolData as WebFetchResultsData"
|
||||
/>
|
||||
|
||||
<WebFetchResults v-else-if="displayType === 'web_fetch_results'" :data="toolData as WebFetchResultsData" />
|
||||
|
||||
<!-- Grep Results Display -->
|
||||
<GrepResults
|
||||
v-else-if="displayType === 'grep_results'"
|
||||
:data="toolData as GrepResultsData"
|
||||
/>
|
||||
|
||||
<GrepResults v-else-if="displayType === 'grep_results'" :data="toolData as GrepResultsData" />
|
||||
|
||||
<!-- Knowledge Chunks List -->
|
||||
<KnowledgeChunksList v-else-if="displayType === 'knowledge_chunks_list'"
|
||||
:data="toolData as KnowledgeChunksListData" />
|
||||
|
||||
<!-- Wiki Edit Results Display -->
|
||||
<WikiEditResult
|
||||
v-else-if="displayType === 'wiki_write_page' || displayType === 'wiki_replace_text' || displayType === 'wiki_rename_page' || displayType === 'wiki_delete_page'"
|
||||
:data="toolData as WikiEditData"
|
||||
/>
|
||||
|
||||
:data="toolData as WikiEditData" />
|
||||
|
||||
<!-- Fallback: Display raw output -->
|
||||
<div v-else class="fallback-output">
|
||||
<div class="fallback-header">
|
||||
@@ -93,7 +60,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineProps, computed } from 'vue';
|
||||
import type {
|
||||
import type {
|
||||
DisplayType,
|
||||
SearchResultsData,
|
||||
ChunkDetailData,
|
||||
@@ -107,6 +74,7 @@ import type {
|
||||
WebSearchResultsData,
|
||||
WebFetchResultsData,
|
||||
GrepResultsData,
|
||||
KnowledgeChunksListData,
|
||||
WikiEditData
|
||||
} from '@/types/tool-results';
|
||||
|
||||
@@ -122,6 +90,7 @@ import DatabaseQuery from './tool-results/DatabaseQuery.vue';
|
||||
import WebSearchResults from './tool-results/WebSearchResults.vue';
|
||||
import WebFetchResults from './tool-results/WebFetchResults.vue';
|
||||
import GrepResults from './tool-results/GrepResults.vue';
|
||||
import KnowledgeChunksList from './tool-results/KnowledgeChunksList.vue';
|
||||
import WikiEditResult from './tool-results/WikiEditResult.vue';
|
||||
|
||||
interface Props {
|
||||
@@ -147,13 +116,13 @@ const toolArguments = computed(() => props.arguments || {});
|
||||
.fallback-output {
|
||||
margin: 12px 0;
|
||||
padding: 0;
|
||||
|
||||
|
||||
.fallback-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
padding: 0 4px;
|
||||
|
||||
|
||||
.fallback-label {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary);
|
||||
@@ -161,7 +130,7 @@ const toolArguments = computed(() => props.arguments || {});
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.detail-output-wrapper {
|
||||
position: relative;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
@@ -170,7 +139,7 @@ const toolArguments = computed(() => props.arguments || {});
|
||||
overflow: hidden;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
|
||||
.detail-output {
|
||||
font-family: var(--app-font-family-mono);
|
||||
font-size: 12px;
|
||||
@@ -185,22 +154,22 @@ const toolArguments = computed(() => props.arguments || {});
|
||||
overflow-x: auto;
|
||||
background: var(--td-bg-color-container);
|
||||
display: block;
|
||||
|
||||
|
||||
// 滚动条样式
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--td-component-border);
|
||||
border-radius: 4px;
|
||||
|
||||
|
||||
&:hover {
|
||||
background: var(--td-text-color-placeholder);
|
||||
}
|
||||
@@ -209,4 +178,3 @@ const toolArguments = computed(() => props.arguments || {});
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import test from 'node:test'
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
const source = readFileSync(join(here, 'docInfo.vue'), 'utf8')
|
||||
|
||||
test('timeline references neutralize brand colors via local css variables', () => {
|
||||
assert.match(source, /&\.refer-timeline \{[\s\S]*--td-brand-color:\s*var\(--td-text-color-placeholder\)/)
|
||||
assert.match(source, /\.doc-chunk-item \.doc-chunk-text:hover/)
|
||||
})
|
||||
|
||||
test('doc header uses right/down chevron on the outer title only', () => {
|
||||
assert.match(source, /showReferBox \? 'chevron-down' : 'chevron-right'/)
|
||||
assert.doesNotMatch(source, /class="doc-group-arrow"/)
|
||||
})
|
||||
@@ -1,36 +1,32 @@
|
||||
<template>
|
||||
<div class="refer" v-if="session.knowledge_references && session.knowledge_references.length">
|
||||
<div class="refer_header" @click="referBoxSwitch">
|
||||
<div class="refer" :class="{ 'refer-timeline': timelineMode }"
|
||||
v-if="session.knowledge_references && session.knowledge_references.length">
|
||||
<div class="refer_header" v-if="!contentOnly" @click="referBoxSwitch">
|
||||
<div class="refer_title">
|
||||
<span class="refer-title-icon icon-mask" aria-hidden="true" />
|
||||
<t-icon v-if="!timelineMode" name="file" class="refer-title-icon" />
|
||||
<span>{{ headerText }}</span>
|
||||
</div>
|
||||
<div class="refer_show_icon">
|
||||
<t-icon :name="showReferBox ? 'chevron-up' : 'chevron-down'" />
|
||||
<div class="refer_show_icon">
|
||||
<t-icon :name="showReferBox ? 'chevron-down' : 'chevron-right'" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="refer_box" v-show="showReferBox">
|
||||
<div class="refer_box" v-show="contentOnly || showReferBox">
|
||||
<!-- Web search references (ungrouped) -->
|
||||
<div v-for="(item, index) in webSearchRefs" :key="'web-' + index">
|
||||
<a
|
||||
:href="getWebSearchUrl(item)"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="doc doc-web"
|
||||
@click.stop
|
||||
>
|
||||
{{ webSearchRefs.length < 2 ? getWebSearchDisplayText(item) : `${index + 1}. ${getWebSearchDisplayText(item)}` }}
|
||||
</a>
|
||||
<a :href="getWebSearchUrl(item)" target="_blank" rel="noopener noreferrer" class="doc doc-web"
|
||||
@click.stop>
|
||||
{{ webSearchRefs.length < 2 ? getWebSearchDisplayText(item) : `${index + 1}.
|
||||
${getWebSearchDisplayText(item)}` }} </a>
|
||||
</div>
|
||||
|
||||
<!-- Knowledge references grouped by document -->
|
||||
<div v-for="(group, gIdx) in groupedKnowledgeRefs" :key="'grp-' + gIdx" class="doc-group">
|
||||
<div class="doc-group-header" @click="toggleGroup(group.key)">
|
||||
<div class="doc-group-left">
|
||||
<t-icon :name="expandedGroups[group.key] ? 'chevron-down' : 'chevron-right'" size="14px" class="doc-group-arrow" />
|
||||
<t-icon name="file" size="14px" class="doc-group-icon" />
|
||||
<span class="doc-group-title" :title="group.title">{{ group.title }}</span>
|
||||
<span class="doc-group-count">{{ $t('chat.referenceChunkCount', { count: group.chunks.length }) }}</span>
|
||||
<span class="doc-group-count">{{ $t('chat.referenceChunkCount', { count: group.chunks.length })
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="doc-group-actions" v-if="!embeddedMode && group.knowledgeBaseId" @click.stop>
|
||||
<t-tooltip :content="$t('chat.navigateToDocument')">
|
||||
@@ -42,7 +38,8 @@
|
||||
</div>
|
||||
<div class="doc-group-chunks" v-show="expandedGroups[group.key]">
|
||||
<div v-for="(chunk, cIdx) in group.chunks" :key="'chunk-' + cIdx" class="doc-chunk-item">
|
||||
<t-popup overlayClassName="refer-to-layer" placement="bottom-left" width="400" :showArrow="false" trigger="click">
|
||||
<t-popup overlayClassName="refer-to-layer" placement="bottom-left" width="400"
|
||||
:showArrow="false" trigger="click">
|
||||
<template #content>
|
||||
<ContentPopup :content="safeProcessContent(chunk.content)" :is-html="true" />
|
||||
</template>
|
||||
@@ -79,6 +76,14 @@ const props = defineProps({
|
||||
embeddedMode: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
timelineMode: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
contentOnly: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
});
|
||||
|
||||
@@ -211,17 +216,97 @@ const getWebSearchDisplayText = (item) => {
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
margin-bottom: 8px;
|
||||
|
||||
&.refer-timeline {
|
||||
--td-brand-color: var(--td-text-color-placeholder);
|
||||
--embed-primary: var(--td-text-color-placeholder);
|
||||
--refer-brand-4: color-mix(in srgb, var(--td-text-color-primary) 4%, transparent);
|
||||
--refer-brand-8: color-mix(in srgb, var(--td-text-color-primary) 6%, transparent);
|
||||
--refer-brand-12: color-mix(in srgb, var(--td-text-color-primary) 8%, transparent);
|
||||
|
||||
width: 100%;
|
||||
border-radius: 0;
|
||||
background-color: transparent;
|
||||
border: 0;
|
||||
box-shadow: none;
|
||||
margin-bottom: 0;
|
||||
font-size: 13px;
|
||||
|
||||
.refer_header {
|
||||
padding: 0;
|
||||
font-weight: 400;
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
.refer_title span {
|
||||
font-size: 14px;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.refer_header:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.refer_show_icon {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.refer_box {
|
||||
padding: 2px 0 0 0;
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
.doc-group {
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.doc-group-header {
|
||||
padding: 2px 0;
|
||||
}
|
||||
|
||||
.doc-group-title {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-weight: 400;
|
||||
font-size: 13px;
|
||||
max-width: min(520px, 100%);
|
||||
}
|
||||
|
||||
.doc-group-count,
|
||||
.doc-chunk-text,
|
||||
.doc-chunk-index {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.doc-group-icon {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.doc-group-navigate {
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.doc {
|
||||
color: var(--td-text-color-secondary);
|
||||
border-bottom-color: color-mix(in srgb, var(--td-text-color-secondary) 30%, transparent);
|
||||
}
|
||||
|
||||
.doc-chunk-item .doc-chunk-text:hover {
|
||||
background-color: var(--refer-brand-4);
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.refer_header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 6px 14px;
|
||||
color: var(--td-text-color-primary);
|
||||
font-weight: 500;
|
||||
|
||||
.refer_title {
|
||||
display: flex;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
|
||||
span {
|
||||
white-space: nowrap;
|
||||
@@ -233,6 +318,7 @@ const getWebSearchDisplayText = (item) => {
|
||||
font-size: 14px;
|
||||
padding: 0 2px 1px 2px;
|
||||
color: var(--td-brand-color);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,24 +334,12 @@ const getWebSearchDisplayText = (item) => {
|
||||
}
|
||||
}
|
||||
|
||||
.icon-mask {
|
||||
display: inline-block;
|
||||
flex-shrink: 0;
|
||||
background-color: var(--embed-primary, var(--td-brand-color));
|
||||
mask-size: contain;
|
||||
mask-repeat: no-repeat;
|
||||
mask-position: center;
|
||||
-webkit-mask-size: contain;
|
||||
-webkit-mask-repeat: no-repeat;
|
||||
-webkit-mask-position: center;
|
||||
}
|
||||
|
||||
.refer-title-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-right: 8px;
|
||||
mask-image: url('@/assets/img/ziliao.svg');
|
||||
-webkit-mask-image: url('@/assets/img/ziliao.svg');
|
||||
flex-shrink: 0;
|
||||
color: var(--embed-primary, var(--td-brand-color));
|
||||
}
|
||||
|
||||
.doc {
|
||||
@@ -320,7 +394,7 @@ const getWebSearchDisplayText = (item) => {
|
||||
.doc-group-arrow {
|
||||
color: var(--td-text-color-placeholder);
|
||||
flex-shrink: 0;
|
||||
margin-right: 2px;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.doc-group-icon {
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
<template>
|
||||
<div class="grep-results">
|
||||
<div v-if="rows.length" class="results-list">
|
||||
<ResultRow
|
||||
v-for="(result, index) in rows"
|
||||
:key="result.key"
|
||||
:index="index + 1"
|
||||
:title="result.title"
|
||||
:meta="result.meta"
|
||||
:popup-key="result.key"
|
||||
:show-popup="!!result.snippet"
|
||||
:content="result.snippet"
|
||||
:chunk-id="result.chunkId"
|
||||
:knowledge-id="result.knowledgeId"
|
||||
:highlight="searchPattern"
|
||||
:regex="true"
|
||||
/>
|
||||
<ResultRow v-for="(result, index) in rows" :key="result.key" :index="index + 1" :title="result.title"
|
||||
:meta="result.meta" :popup-key="result.key" :show-popup="result.chunks.length > 0 || !!result.snippet"
|
||||
:content="result.chunks.length === 1 ? result.snippet : undefined"
|
||||
:chunks="result.chunks.length > 1 ? result.chunks : undefined" :chunk-id="result.chunkId"
|
||||
:knowledge-id="result.knowledgeId" :highlight="searchPattern" :regex="true" />
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
@@ -28,7 +19,8 @@ import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { cleanSnippet } from './contentClean';
|
||||
import ResultRow from './ResultRow.vue';
|
||||
import type { GrepChunkResult, GrepKnowledgeResult, GrepResultsData } from '@/types/tool-results';
|
||||
import { groupGrepChunkResults } from '@/utils/grepResultsGroup';
|
||||
import type { GrepKnowledgeResult, GrepResultsData } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: GrepResultsData;
|
||||
@@ -43,6 +35,7 @@ type GrepRow = {
|
||||
title: string;
|
||||
meta: string;
|
||||
snippet: string;
|
||||
chunks: { content: string; chunk_id: string; knowledge_id: string }[];
|
||||
chunkId?: string;
|
||||
knowledgeId?: string;
|
||||
};
|
||||
@@ -63,28 +56,32 @@ const formatKnowledgeMeta = (result: GrepKnowledgeResult): string => {
|
||||
return parts.join(' · ');
|
||||
};
|
||||
|
||||
const rowFromChunk = (result: GrepChunkResult): GrepRow => {
|
||||
const isFAQ = !!result.faq_id || result.chunk_type === 'faq';
|
||||
const title = result.faq_question || result.knowledge_title || t('knowledge.untitledDocument');
|
||||
const meta = isFAQ
|
||||
const rowFromGroupedChunk = (group: ReturnType<typeof groupGrepChunkResults>[number]): GrepRow => {
|
||||
const title = group.title || t('knowledge.untitledDocument');
|
||||
const meta = group.is_faq
|
||||
? t('agentStream.grepResults.faqEntry')
|
||||
: formatKnowledgeMeta({
|
||||
knowledge_id: result.knowledge_id,
|
||||
knowledge_base_id: result.knowledge_base_id,
|
||||
knowledge_title: result.knowledge_title,
|
||||
chunk_hit_count: 1,
|
||||
total_pattern_hits: 1,
|
||||
distinct_patterns: 1,
|
||||
pattern_counts: {},
|
||||
title_match: !!result.title_match,
|
||||
});
|
||||
knowledge_id: group.knowledge_id,
|
||||
knowledge_base_id: '',
|
||||
knowledge_title: title,
|
||||
chunk_hit_count: group.chunk_hit_count,
|
||||
total_pattern_hits: group.chunk_hit_count,
|
||||
distinct_patterns: 1,
|
||||
pattern_counts: {},
|
||||
title_match: group.title_match,
|
||||
});
|
||||
return {
|
||||
key: result.faq_id || result.chunk_id || String(result.index ?? '') || result.knowledge_id,
|
||||
key: group.key,
|
||||
title,
|
||||
meta,
|
||||
snippet: cleanSnippet(result.match_snippet ?? ''),
|
||||
chunkId: result.faq_id || result.chunk_id,
|
||||
knowledgeId: result.knowledge_id,
|
||||
snippet: cleanSnippet(group.match_snippet),
|
||||
chunks: group.chunks.map((chunk) => ({
|
||||
content: cleanSnippet(chunk.content),
|
||||
chunk_id: chunk.chunk_id,
|
||||
knowledge_id: chunk.knowledge_id,
|
||||
})),
|
||||
chunkId: group.chunks.length === 1 ? group.chunks[0].chunk_id : undefined,
|
||||
knowledgeId: group.knowledge_id,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -93,13 +90,20 @@ const rowFromKnowledge = (result: GrepKnowledgeResult): GrepRow => ({
|
||||
title: result.faq_question || result.knowledge_title || t('knowledge.untitledDocument'),
|
||||
meta: formatKnowledgeMeta(result),
|
||||
snippet: cleanSnippet(result.match_snippet ?? ''),
|
||||
chunks: result.match_snippet
|
||||
? [{
|
||||
content: cleanSnippet(result.match_snippet ?? ''),
|
||||
chunk_id: '',
|
||||
knowledge_id: result.knowledge_id,
|
||||
}]
|
||||
: [],
|
||||
knowledgeId: result.knowledge_id,
|
||||
});
|
||||
|
||||
const rows = computed((): GrepRow[] => {
|
||||
const chunkRows = props.data.chunk_results;
|
||||
if (chunkRows?.length) {
|
||||
return chunkRows.map(rowFromChunk);
|
||||
return groupGrepChunkResults(chunkRows).map(rowFromGroupedChunk);
|
||||
}
|
||||
return (props.data.knowledge_results ?? []).map(rowFromKnowledge);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<!-- Fallback for ToolResultRenderer when used outside AgentStreamDisplay. -->
|
||||
<div class="knowledge-chunks-list">
|
||||
<div v-if="summaryHtml" class="results-summary-text" v-html="summaryHtml" />
|
||||
<div v-else class="empty-state">{{ $t('chat.noMatchFound') }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { getKnowledgeChunksSummaryHtml } from '@/utils/knowledgeChunksDisplay';
|
||||
import type { KnowledgeChunksListData } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: KnowledgeChunksListData;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const summaryHtml = computed(() => getKnowledgeChunksSummaryHtml(t, props.data));
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.knowledge-chunks-list {
|
||||
.results-summary-text {
|
||||
font-size: var(--agent-step-summary-size, 12px);
|
||||
font-weight: 400;
|
||||
color: var(--td-text-color-secondary);
|
||||
line-height: 1.5;
|
||||
|
||||
:deep(strong) {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
font-size: 13px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,14 +2,9 @@
|
||||
<div class="user_msg_container" ref="containerRef" :class="{ 'is-embedded': embeddedMode }">
|
||||
<!-- 显示@的知识库和文件 -->
|
||||
<div v-if="mentioned_items && mentioned_items.length > 0" class="mentioned_items">
|
||||
<span
|
||||
v-for="item in mentioned_items"
|
||||
:key="item.id"
|
||||
class="mentioned_tag"
|
||||
:class="[
|
||||
item.type === 'kb' ? (item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag') : 'file-tag'
|
||||
]"
|
||||
>
|
||||
<span v-for="item in mentioned_items" :key="item.id" class="mentioned_tag" :class="[
|
||||
item.type === 'kb' ? (item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag') : 'file-tag'
|
||||
]">
|
||||
<span class="tag_icon">
|
||||
<t-icon v-if="item.type === 'kb'" :name="item.kb_type === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||
<t-icon v-else name="file" />
|
||||
@@ -19,30 +14,26 @@
|
||||
</div>
|
||||
<!-- 显示上传的图片 -->
|
||||
<div v-if="hasImages" class="user_images">
|
||||
<img
|
||||
v-for="(img, idx) in props.images"
|
||||
:key="idx"
|
||||
:src="img.url"
|
||||
class="user_image_thumb"
|
||||
@click="previewImage($event)"
|
||||
/>
|
||||
<img v-for="(img, idx) in props.images" :key="idx" :src="img.url" class="user_image_thumb"
|
||||
@click="previewImage($event)" />
|
||||
</div>
|
||||
<!-- 显示上传的附件 -->
|
||||
<div v-if="hasAttachments" class="user_attachments">
|
||||
<div v-for="(att, idx) in props.attachments" :key="idx" class="user_attachment_card">
|
||||
<div class="attachment_card_icon">
|
||||
<svg viewBox="0 0 40 48" fill="none" xmlns="http://www.w3.org/2000/svg" width="36" height="44">
|
||||
<rect width="40" height="48" rx="4" fill="#4A90D9"/>
|
||||
<path d="M8 6h16l8 8v28a2 2 0 01-2 2H8a2 2 0 01-2-2V8a2 2 0 012-2z" fill="#5BA3E8"/>
|
||||
<path d="M24 6l8 8h-6a2 2 0 01-2-2V6z" fill="#3A7BC8"/>
|
||||
<rect x="10" y="20" width="20" height="2" rx="1" fill="white" fill-opacity="0.9"/>
|
||||
<rect x="10" y="26" width="20" height="2" rx="1" fill="white" fill-opacity="0.9"/>
|
||||
<rect x="10" y="32" width="14" height="2" rx="1" fill="white" fill-opacity="0.9"/>
|
||||
<rect width="40" height="48" rx="4" fill="#4A90D9" />
|
||||
<path d="M8 6h16l8 8v28a2 2 0 01-2 2H8a2 2 0 01-2-2V8a2 2 0 012-2z" fill="#5BA3E8" />
|
||||
<path d="M24 6l8 8h-6a2 2 0 01-2-2V6z" fill="#3A7BC8" />
|
||||
<rect x="10" y="20" width="20" height="2" rx="1" fill="white" fill-opacity="0.9" />
|
||||
<rect x="10" y="26" width="20" height="2" rx="1" fill="white" fill-opacity="0.9" />
|
||||
<rect x="10" y="32" width="14" height="2" rx="1" fill="white" fill-opacity="0.9" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="attachment_card_info">
|
||||
<div class="attachment_card_name">{{ att.file_name }}</div>
|
||||
<div class="attachment_card_meta">{{ getFileExt(att.file_name) }}<span v-if="att.file_size"> · {{ formatFileSize(att.file_size) }}</span></div>
|
||||
<div class="attachment_card_meta">{{ getFileExt(att.file_name) }}<span
|
||||
v-if="att.file_size"> · {{ formatFileSize(att.file_size) }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -242,7 +233,7 @@ const closePreImg = () => {
|
||||
background: #8CE97F;
|
||||
margin-left: auto;
|
||||
color: #000000e6;
|
||||
font-size: 15px;
|
||||
font-size: 16px;
|
||||
text-align: justify;
|
||||
word-break: break-all;
|
||||
box-sizing: border-box;
|
||||
|
||||
@@ -8,36 +8,46 @@
|
||||
<t-skeleton animation="gradient" :row-col="[{ width: '45%', height: '36px', type: 'rect' }]" />
|
||||
</div>
|
||||
<div class="msg-skeleton msg-skeleton-bot">
|
||||
<t-skeleton animation="gradient" :row-col="[{ width: '80%', height: '16px' }, { width: '100%', height: '16px' }, { width: '60%', height: '16px' }]" />
|
||||
<t-skeleton animation="gradient"
|
||||
:row-col="[{ width: '80%', height: '16px' }, { width: '100%', height: '16px' }, { width: '60%', height: '16px' }]" />
|
||||
</div>
|
||||
<div class="msg-skeleton msg-skeleton-user">
|
||||
<t-skeleton animation="gradient" :row-col="[{ width: '35%', height: '36px', type: 'rect' }]" />
|
||||
</div>
|
||||
<div class="msg-skeleton msg-skeleton-bot">
|
||||
<t-skeleton animation="gradient" :row-col="[{ width: '70%', height: '16px' }, { width: '90%', height: '16px' }]" />
|
||||
<t-skeleton animation="gradient"
|
||||
:row-col="[{ width: '70%', height: '16px' }, { width: '90%', height: '16px' }]" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- 推荐问题卡片 - 仅在新会话(无消息)时展示 -->
|
||||
<div v-if="!embeddedMode && messagesList.length === 0 && !loading" class="suggested-questions-container" :class="{ 'has-questions': suggestedQuestions.length > 0 || suggestedQuestionsLoading }">
|
||||
<div v-if="!embeddedMode && messagesList.length === 0 && !loading" class="suggested-questions-container"
|
||||
:class="{ 'has-questions': suggestedQuestions.length > 0 || suggestedQuestionsLoading }">
|
||||
<!-- 骨架屏占位 -->
|
||||
<div v-if="suggestedQuestionsLoading && suggestedQuestions.length === 0" class="suggested-questions-inner">
|
||||
<div class="suggested-questions-title"><t-skeleton animation="gradient" :row-col="[{ width: '120px', height: '18px' }]" /></div>
|
||||
<div v-if="suggestedQuestionsLoading && suggestedQuestions.length === 0"
|
||||
class="suggested-questions-inner">
|
||||
<div class="suggested-questions-title"><t-skeleton animation="gradient"
|
||||
:row-col="[{ width: '120px', height: '18px' }]" /></div>
|
||||
<div class="suggested-questions-grid">
|
||||
<div v-for="n in 6" :key="'sq-skel-'+n" class="suggested-question-card sq-card-skeleton">
|
||||
<t-skeleton animation="gradient" :row-col="[{ width: '100%', height: '14px', type: 'rect' }]" />
|
||||
<div v-for="n in 6" :key="'sq-skel-' + n" class="suggested-question-card sq-card-skeleton">
|
||||
<t-skeleton animation="gradient"
|
||||
:row-col="[{ width: '100%', height: '14px', type: 'rect' }]" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<transition v-else appear name="sq-fade">
|
||||
<div v-if="suggestedQuestions.length > 0" class="suggested-questions-inner">
|
||||
<div class="suggested-questions-title">{{ t('chat.suggestedQuestions') }}</div>
|
||||
<div class="suggested-questions-title-row">
|
||||
<div class="suggested-questions-title">{{ t('chat.suggestedQuestions') }}</div>
|
||||
<t-button variant="text" shape="square" size="small" class="suggested-questions-refresh"
|
||||
:loading="suggestedQuestionsLoading" :title="t('chat.refreshSuggestedQuestions')"
|
||||
@click="fetchSuggestedQuestions">
|
||||
<template #icon><t-icon name="refresh" /></template>
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="suggested-questions-grid">
|
||||
<div
|
||||
v-for="(item, index) in suggestedQuestions"
|
||||
:key="item.question"
|
||||
<div v-for="(item, index) in suggestedQuestions" :key="item.question"
|
||||
class="suggested-question-card"
|
||||
@click="handleSuggestedQuestionClick(item.question)"
|
||||
>
|
||||
@click="handleSuggestedQuestionClick(item.question)">
|
||||
<span class="suggested-question-text">{{ item.question }}</span>
|
||||
<span v-if="item.source === 'faq'" class="suggested-question-badge faq">FAQ</span>
|
||||
</div>
|
||||
@@ -53,14 +63,13 @@
|
||||
这是历史加载时白屏 + layout shift 蔓延到 session 列表的根因。
|
||||
仅对极少数尚未拿到 id 的本地占位消息 fallback 到 role+created_at+index。
|
||||
-->
|
||||
<div
|
||||
v-for="(session, index) in messagesList"
|
||||
:key="session.id || `${session.role}-${session.created_at}-${index}`"
|
||||
class="msg-item-wrapper"
|
||||
>
|
||||
<div v-for="(session, index) in messagesList"
|
||||
:key="session.id || `${session.role}-${session.created_at}-${index}`" class="msg-item-wrapper">
|
||||
|
||||
<div v-if="session.role == 'user'">
|
||||
<usermsg :content="session.content" :mentioned_items="session.mentioned_items" :images="session.images" :attachments="session.attachments" :embeddedMode="embeddedMode"></usermsg>
|
||||
<usermsg :content="session.content" :mentioned_items="session.mentioned_items"
|
||||
:images="session.images" :attachments="session.attachments" :embeddedMode="embeddedMode">
|
||||
</usermsg>
|
||||
</div>
|
||||
<div v-if="session.role == 'assistant' && shouldRenderAssistantMessage(session)">
|
||||
<botmsg :content="session.content" :session="session" :session-id="session_id"
|
||||
@@ -68,7 +77,7 @@
|
||||
:isFirstEnter="isFirstEnter" :embeddedMode="embeddedMode"></botmsg>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="loading || isImRecovering"
|
||||
<div v-if="showGlobalTypingIndicator"
|
||||
style="height: 41px;display: flex;align-items: center;padding-left: 4px;">
|
||||
<div class="loading-typing">
|
||||
<span></span>
|
||||
@@ -84,29 +93,19 @@
|
||||
</div>
|
||||
</transition>
|
||||
<div class="input-container" :class="{ 'is-embedded': embeddedMode }">
|
||||
<InputField
|
||||
ref="inputFieldRef"
|
||||
<InputField ref="inputFieldRef"
|
||||
@send-msg="(query, modelId, mentionedItems, imageFiles, attachmentFiles) => sendMsg(query, modelId, mentionedItems, imageFiles, attachmentFiles)"
|
||||
@stop-generation="handleStopGeneration"
|
||||
:isReplying="isReplying"
|
||||
:sessionId="session_id"
|
||||
:assistantMessageId="currentAssistantMessageId"
|
||||
:embeddedMode="embeddedMode"
|
||||
></InputField>
|
||||
@stop-generation="handleStopGeneration" :isReplying="isReplying" :sessionId="session_id"
|
||||
:assistantMessageId="currentAssistantMessageId" :embeddedMode="embeddedMode"></InputField>
|
||||
</div>
|
||||
</div>
|
||||
<KnowledgeBaseEditorModal
|
||||
:visible="uiStore.showKBEditorModal"
|
||||
:mode="uiStore.kbEditorMode"
|
||||
:kb-id="uiStore.currentKBId || undefined"
|
||||
:initial-type="uiStore.kbEditorType"
|
||||
@update:visible="(val) => val ? null : uiStore.closeKBEditor()"
|
||||
@success="handleKBEditorSuccess"
|
||||
/>
|
||||
<KnowledgeBaseEditorModal :visible="uiStore.showKBEditorModal" :mode="uiStore.kbEditorMode"
|
||||
:kb-id="uiStore.currentKBId || undefined" :initial-type="uiStore.kbEditorType"
|
||||
@update:visible="(val) => val ? null : uiStore.closeKBEditor()" @success="handleKBEditorSuccess" />
|
||||
</template>
|
||||
<script setup>
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ref, onMounted, onBeforeMount, onUnmounted, nextTick, watch, reactive, defineProps } from 'vue';
|
||||
import { ref, onMounted, onBeforeMount, onUnmounted, nextTick, watch, reactive, defineProps, computed } from 'vue';
|
||||
import { useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from 'vue-router';
|
||||
import InputField from '../../components/Input-field.vue';
|
||||
import botmsg from './components/botmsg.vue';
|
||||
@@ -122,12 +121,13 @@ import { useUIStore } from '@/stores/ui';
|
||||
import KnowledgeBaseEditorModal from '@/views/knowledge/KnowledgeBaseEditorModal.vue';
|
||||
import { useKnowledgeBaseCreationNavigation } from '@/hooks/useKnowledgeBaseCreationNavigation';
|
||||
import { useChatStreamHandler } from '@/composables/useChatStreamHandler';
|
||||
import { clearCitationChunkCache } from '@/utils/citationChunkCache';
|
||||
|
||||
const props = defineProps({
|
||||
session_id: { type: String, default: '' },
|
||||
agentId: { type: String, default: '' },
|
||||
kbIds: { type: Array, default: () => [] },
|
||||
embeddedMode: { type: Boolean, default: false },
|
||||
session_id: { type: String, default: '' },
|
||||
agentId: { type: String, default: '' },
|
||||
kbIds: { type: Array, default: () => [] },
|
||||
embeddedMode: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const usemenuStore = useMenuStore();
|
||||
@@ -350,7 +350,8 @@ watch([() => route.params], async (newvalue) => {
|
||||
}
|
||||
messagesList.splice(0);
|
||||
session_id.value = newvalue[0].chatid;
|
||||
|
||||
clearCitationChunkCache();
|
||||
|
||||
// 切换会话时,重置状态
|
||||
historyLoading.value = true;
|
||||
historyLoadingMore.value = false;
|
||||
@@ -418,6 +419,7 @@ const fetchMessageList = (data) => getMessageList(data);
|
||||
const {
|
||||
findLastMessage,
|
||||
shouldRenderAssistantMessage,
|
||||
shouldShowGlobalTypingIndicator,
|
||||
handleMsgList,
|
||||
processStreamChunk,
|
||||
} = useChatStreamHandler({
|
||||
@@ -481,6 +483,10 @@ const {
|
||||
},
|
||||
});
|
||||
|
||||
const showGlobalTypingIndicator = computed(() =>
|
||||
shouldShowGlobalTypingIndicator(messagesList, loading.value, isImRecovering.value),
|
||||
);
|
||||
|
||||
const getmsgList = (data, isScrollType = false, scrollHeight) => {
|
||||
if (isScrollType) {
|
||||
if (historyLoadingMore.value || !hasMoreHistory.value) return;
|
||||
@@ -585,23 +591,23 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
}
|
||||
|
||||
// 将@提及的知识库和文件信息存入用户消息
|
||||
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems, images: userImages, attachments: attachmentFiles.map(a => ({ file_name: a.name, file_size: a.size, file_type: '.' + a.name.split('.').pop()?.toLowerCase() })), channel: 'web' });
|
||||
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems, images: userImages, attachments: attachmentFiles.map(a => ({ file_name: a.name, file_size: a.size, file_type: '.' + a.name.split('.').pop()?.toLowerCase() })), channel: 'web' });
|
||||
userHasScrolledUp.value = false;
|
||||
scrollToBottom(true);
|
||||
|
||||
|
||||
// Get agent mode status from settings store
|
||||
const agentEnabled = props.embeddedMode ? (props.agentId && props.agentId !== 'builtin-quick-answer') : useSettingsStoreInstance.isAgentEnabled;
|
||||
|
||||
|
||||
// Get web search status from settings store
|
||||
const webSearchEnabled = props.embeddedMode ? false : useSettingsStoreInstance.isWebSearchEnabled;
|
||||
|
||||
|
||||
// Memory toggle is now a server-side per-user preference (see PUT
|
||||
// /auth/me/preferences). For the normal logged-in chat we leave the
|
||||
// field unset so the backend reads `user.preferences.enable_memory`;
|
||||
// for embedded widgets we still send an explicit `false` so a user's
|
||||
// personal "memory on" setting doesn't leak into a KB-embed context.
|
||||
const enableMemoryOverride = props.embeddedMode ? false : undefined;
|
||||
|
||||
|
||||
// Get knowledge_base_ids from settings store (selected by user via KnowledgeBaseSelector)
|
||||
// Merge @mentioned KB/file IDs so retrieval uses the same targets user @mentioned (including shared KBs)
|
||||
const sidebarKbIds = props.embeddedMode ? props.kbIds : (useSettingsStoreInstance.settings.selectedKnowledgeBases || []);
|
||||
@@ -609,12 +615,12 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
const kbIdSet = new Set(sidebarKbIds);
|
||||
const fileIdSet = new Set(sidebarFileIds);
|
||||
for (const item of mentionedItems || []) {
|
||||
if (!item?.id) continue;
|
||||
if (item.type === 'kb' && !kbIdSet.has(item.id)) {
|
||||
kbIdSet.add(item.id);
|
||||
} else if (item.type === 'file' && !fileIdSet.has(item.id)) {
|
||||
fileIdSet.add(item.id);
|
||||
}
|
||||
if (!item?.id) continue;
|
||||
if (item.type === 'kb' && !kbIdSet.has(item.id)) {
|
||||
kbIdSet.add(item.id);
|
||||
} else if (item.type === 'file' && !fileIdSet.has(item.id)) {
|
||||
fileIdSet.add(item.id);
|
||||
}
|
||||
}
|
||||
const kbIds = [...kbIdSet];
|
||||
const knowledgeIds = [...fileIdSet];
|
||||
@@ -626,9 +632,9 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
|
||||
// Get selected MCP services from settings store (if available)
|
||||
const mcpServiceIds = props.embeddedMode ? [] : (useSettingsStoreInstance.settings.selectedMCPServices || []);
|
||||
|
||||
await startStream({
|
||||
session_id: session_id.value,
|
||||
|
||||
await startStream({
|
||||
session_id: session_id.value,
|
||||
knowledge_base_ids: kbIds,
|
||||
knowledge_ids: knowledgeIds,
|
||||
agent_enabled: agentEnabled,
|
||||
@@ -640,8 +646,8 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
|
||||
mentioned_items: mentionedItems,
|
||||
images: imageAttachments.length > 0 ? imageAttachments : undefined,
|
||||
attachment_uploads: attachmentUploads.length > 0 ? attachmentUploads : undefined,
|
||||
query: value,
|
||||
method: 'POST',
|
||||
query: value,
|
||||
method: 'POST',
|
||||
url: endpoint,
|
||||
});
|
||||
}
|
||||
@@ -940,6 +946,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
.scroll-btn-fade-leave-active {
|
||||
transition: opacity 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
.scroll-btn-fade-enter-from,
|
||||
.scroll-btn-fade-leave-to {
|
||||
opacity: 0;
|
||||
@@ -947,8 +954,15 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
}
|
||||
|
||||
@keyframes contentFadeIn {
|
||||
from { opacity: 0; transform: translateY(6px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(6px);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.msg-skeleton-list {
|
||||
@@ -959,10 +973,12 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
padding: 16px 0;
|
||||
animation: contentFadeIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
.msg-skeleton-user {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.msg-skeleton-bot {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -975,11 +991,10 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
// Keep the input visible when messages overflow: without flex-shrink: 0
|
||||
// a tall .chat_scroll_box can squeeze this container down to 0 height.
|
||||
flex-shrink: 0;
|
||||
margin: 16px auto 4px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
box-sizing: border-box;
|
||||
padding-right: 20px;
|
||||
|
||||
&.is-embedded {
|
||||
max-width: 100%;
|
||||
@@ -1022,27 +1037,27 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
height: 18px;
|
||||
margin-left: 16px;
|
||||
}
|
||||
|
||||
|
||||
.loading-typing {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
|
||||
span {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--td-brand-color);
|
||||
background: var(--td-text-color-placeholder);
|
||||
animation: typingBounce 1.4s ease-in-out infinite;
|
||||
|
||||
|
||||
&:nth-child(1) {
|
||||
animation-delay: 0s;
|
||||
}
|
||||
|
||||
|
||||
&:nth-child(2) {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
|
||||
|
||||
&:nth-child(3) {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
@@ -1051,9 +1066,13 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
}
|
||||
|
||||
@keyframes typingBounce {
|
||||
0%, 60%, 100% {
|
||||
|
||||
0%,
|
||||
60%,
|
||||
100% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
30% {
|
||||
transform: translateY(-8px);
|
||||
}
|
||||
@@ -1087,18 +1106,35 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
.sq-fade-leave-active {
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
.sq-fade-enter-from,
|
||||
.sq-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.suggested-questions-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.suggested-questions-title {
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-secondary);
|
||||
margin-bottom: 16px;
|
||||
margin-bottom: 0;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.suggested-questions-refresh {
|
||||
flex-shrink: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
&:hover:not(.t-is-disabled) {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.suggested-questions-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@@ -1128,19 +1164,38 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
:deep(.t-skeleton) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.t-skeleton__row) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.t-skeleton__col) {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
&:nth-child(1) { width: 132px; }
|
||||
&:nth-child(2) { width: 168px; }
|
||||
&:nth-child(3) { width: 116px; }
|
||||
&:nth-child(4) { width: 152px; }
|
||||
&:nth-child(5) { width: 124px; }
|
||||
&:nth-child(6) { width: 144px; }
|
||||
&:nth-child(1) {
|
||||
width: 132px;
|
||||
}
|
||||
|
||||
&:nth-child(2) {
|
||||
width: 168px;
|
||||
}
|
||||
|
||||
&:nth-child(3) {
|
||||
width: 116px;
|
||||
}
|
||||
|
||||
&:nth-child(4) {
|
||||
width: 152px;
|
||||
}
|
||||
|
||||
&:nth-child(5) {
|
||||
width: 124px;
|
||||
}
|
||||
|
||||
&:nth-child(6) {
|
||||
width: 144px;
|
||||
}
|
||||
}
|
||||
|
||||
&:not(.sq-card-skeleton):hover {
|
||||
|
||||
Reference in New Issue
Block a user