feat(chat): add citation popover and chunk caching
Introduce ChatCitationFloat hover UI, session-scoped citation chunk cache, and unified citation markdown handling for main chat and embed views.
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<div v-if="float.visible" class="chat-citation-float" :style="{ top: `${float.top}px`, left: `${float.left}px` }"
|
||||||
|
@mouseenter="onEnter?.()" @mouseleave="onLeave?.()">
|
||||||
|
<template v-if="float.type === 'web'">
|
||||||
|
<div class="chat-citation-float__title">{{ float.title || float.url }}</div>
|
||||||
|
<a v-if="float.url" class="chat-citation-float__link" :href="float.url" target="_blank"
|
||||||
|
rel="noopener noreferrer">{{ float.url }}</a>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="chat-citation-float__title">{{ float.title }}</div>
|
||||||
|
<div v-if="float.loading" class="chat-citation-float__muted">{{ loadingText }}</div>
|
||||||
|
<div v-else-if="float.error" class="chat-citation-float__error">{{ float.error }}</div>
|
||||||
|
<div v-else class="chat-citation-float__body">{{ float.content }}</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import type { CitationFloatState } from '@/composables/useChatCitationPopover'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
float: CitationFloatState
|
||||||
|
onEnter?: () => void
|
||||||
|
onLeave?: () => void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const loadingText = t('common.loading')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less">
|
||||||
|
@import './css/chat-citations.less';
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
.chat-citation-pills() {
|
||||||
|
:deep(.citation) {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 2px;
|
||||||
|
vertical-align: baseline;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 0 5px;
|
||||||
|
font-size: 0.72em;
|
||||||
|
line-height: 1.45;
|
||||||
|
margin: 0 0.06em;
|
||||||
|
background-clip: padding-box;
|
||||||
|
transform: translateY(-0.04em);
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-icon) {
|
||||||
|
display: inline-block;
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
flex-shrink: 0;
|
||||||
|
background-color: currentColor;
|
||||||
|
opacity: 0.68;
|
||||||
|
mask-size: contain;
|
||||||
|
mask-repeat: no-repeat;
|
||||||
|
mask-position: center;
|
||||||
|
-webkit-mask-size: contain;
|
||||||
|
-webkit-mask-repeat: no-repeat;
|
||||||
|
-webkit-mask-position: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-icon--book) {
|
||||||
|
mask-image: url('@/assets/img/ziliao.svg');
|
||||||
|
-webkit-mask-image: url('@/assets/img/ziliao.svg');
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-icon--web) {
|
||||||
|
mask-image: url('@/assets/img/websearch-globe.svg');
|
||||||
|
-webkit-mask-image: url('@/assets/img/websearch-globe.svg');
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-text),
|
||||||
|
:deep(.citation-domain) {
|
||||||
|
line-height: 1.45;
|
||||||
|
max-width: 180px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-kb) {
|
||||||
|
background: color-mix(in srgb, var(--td-text-color-primary) 4%, transparent);
|
||||||
|
color: color-mix(in srgb, var(--td-text-color-secondary) 86%, var(--td-text-color-primary));
|
||||||
|
border: 0;
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--td-text-color-primary) 10%, transparent);
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
position: relative;
|
||||||
|
transition: background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-kb:hover) {
|
||||||
|
background: color-mix(in srgb, var(--td-text-color-primary) 7%, transparent);
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--td-text-color-primary) 18%, transparent);
|
||||||
|
color: var(--td-text-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-web) {
|
||||||
|
background: color-mix(in srgb, var(--td-brand-color) 6%, transparent);
|
||||||
|
color: color-mix(in srgb, var(--td-brand-color) 72%, var(--td-text-color-secondary));
|
||||||
|
border: 0;
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--td-brand-color) 17%, transparent);
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
position: relative;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-web:hover) {
|
||||||
|
background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--td-brand-color) 28%, transparent);
|
||||||
|
color: color-mix(in srgb, var(--td-brand-color) 82%, var(--td-text-color-primary));
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-web:focus-visible),
|
||||||
|
:deep(.citation-kb:focus-visible) {
|
||||||
|
outline: 2px solid var(--td-component-border);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.citation-tip) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(a.wiki-content-link) {
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
border-bottom: 1px dashed var(--td-brand-color);
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 500;
|
||||||
|
transition: border-bottom-style 0.15s ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-bottom-style: solid;
|
||||||
|
text-decoration: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 2px solid var(--td-brand-color);
|
||||||
|
outline-offset: 2px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-citation-float {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 10000;
|
||||||
|
max-width: 320px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: var(--td-bg-color-container);
|
||||||
|
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: var(--td-text-color-primary);
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__link {
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__body {
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__muted,
|
||||||
|
&__error {
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__error {
|
||||||
|
color: var(--td-error-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import { dirname, join } from 'node:path'
|
||||||
|
import test from 'node:test'
|
||||||
|
|
||||||
|
const here = dirname(fileURLToPath(import.meta.url))
|
||||||
|
const css = readFileSync(join(here, 'chat-citations.less'), 'utf8')
|
||||||
|
|
||||||
|
test('citation pills use compact baseline-aligned source styling', () => {
|
||||||
|
assert.match(css, /border-radius:\s*999px/)
|
||||||
|
assert.match(css, /font-size:\s*0\.72em/)
|
||||||
|
assert.match(css, /box-shadow:\s*inset 0 0 0 1px/)
|
||||||
|
})
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
import { onBeforeUnmount, onMounted, ref, watch, type Ref } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import { getChunkByIdOnly } from '@/api/knowledge-base'
|
||||||
|
import { getEmbedChunkById } from '@/api/embed'
|
||||||
|
import { resolveCitationChunkId, type CitationKnowledgeRef } from '@/utils/citationMarkdown'
|
||||||
|
import {
|
||||||
|
getCitationChunkCache,
|
||||||
|
setCitationChunkCache,
|
||||||
|
} from '@/utils/citationChunkCache'
|
||||||
|
|
||||||
|
export { clearCitationChunkCache } from '@/utils/citationChunkCache'
|
||||||
|
|
||||||
|
type FloatState = {
|
||||||
|
visible: boolean
|
||||||
|
type: 'kb' | 'web'
|
||||||
|
top: number
|
||||||
|
left: number
|
||||||
|
title: string
|
||||||
|
content: string
|
||||||
|
url: string
|
||||||
|
loading: boolean
|
||||||
|
error: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CitationFloatState = FloatState
|
||||||
|
|
||||||
|
export type ChatCitationPopoverOptions = {
|
||||||
|
getKnowledgeReferences?: () => CitationKnowledgeRef[] | null | undefined
|
||||||
|
embedChannelId?: () => string | undefined
|
||||||
|
embedToken?: () => string | undefined
|
||||||
|
sessionId?: () => string | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useChatCitationPopover(
|
||||||
|
rootRef: Ref<HTMLElement | null>,
|
||||||
|
options?: ChatCitationPopoverOptions,
|
||||||
|
) {
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const getCacheScope = () => {
|
||||||
|
const channelId = options?.embedChannelId?.()
|
||||||
|
const token = options?.embedToken?.()
|
||||||
|
if (channelId && token) return `embed:${channelId}:${token}`
|
||||||
|
return options?.sessionId?.() || 'default'
|
||||||
|
}
|
||||||
|
|
||||||
|
const float = ref<FloatState>({
|
||||||
|
visible: false,
|
||||||
|
type: 'kb',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
url: '',
|
||||||
|
loading: false,
|
||||||
|
error: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
let hoverTimer: number | null = null
|
||||||
|
let closeTimer: number | null = null
|
||||||
|
|
||||||
|
const positionFor = (el: HTMLElement, offsetY = 0) => {
|
||||||
|
const rect = el.getBoundingClientRect()
|
||||||
|
float.value.top = rect.bottom + window.scrollY + 6 + offsetY
|
||||||
|
float.value.left = Math.min(rect.left + window.scrollX, window.innerWidth - 320)
|
||||||
|
}
|
||||||
|
|
||||||
|
const openWeb = (el: HTMLElement) => {
|
||||||
|
const url = el.getAttribute('data-url') || ''
|
||||||
|
float.value.type = 'web'
|
||||||
|
float.value.url = url
|
||||||
|
float.value.title = el.querySelector('.tip-title')?.textContent || ''
|
||||||
|
float.value.content = ''
|
||||||
|
float.value.loading = false
|
||||||
|
float.value.error = ''
|
||||||
|
float.value.visible = true
|
||||||
|
positionFor(el)
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchChunkContent = async (chunkId: string) => {
|
||||||
|
const channelId = options?.embedChannelId?.()
|
||||||
|
const token = options?.embedToken?.()
|
||||||
|
if (channelId && token) {
|
||||||
|
return getEmbedChunkById(channelId, token, chunkId)
|
||||||
|
}
|
||||||
|
return getChunkByIdOnly(chunkId)
|
||||||
|
}
|
||||||
|
|
||||||
|
const openKb = async (el: HTMLElement) => {
|
||||||
|
const rawChunkId = el.getAttribute('data-chunk-id') || ''
|
||||||
|
const title = el.getAttribute('data-doc') || ''
|
||||||
|
const kbId = el.getAttribute('data-kb-id') || ''
|
||||||
|
const chunkId = resolveCitationChunkId(
|
||||||
|
rawChunkId,
|
||||||
|
{ doc: title, kbId },
|
||||||
|
options?.getKnowledgeReferences?.(),
|
||||||
|
) || rawChunkId
|
||||||
|
if (!chunkId) return
|
||||||
|
float.value.type = 'kb'
|
||||||
|
float.value.title = title
|
||||||
|
float.value.url = ''
|
||||||
|
float.value.visible = true
|
||||||
|
positionFor(el, 4)
|
||||||
|
|
||||||
|
const scope = getCacheScope()
|
||||||
|
const cached = getCitationChunkCache(scope, chunkId)
|
||||||
|
if (cached) {
|
||||||
|
float.value.content = cached.content
|
||||||
|
float.value.error = cached.error || ''
|
||||||
|
float.value.loading = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
float.value.loading = true
|
||||||
|
float.value.error = ''
|
||||||
|
float.value.content = ''
|
||||||
|
try {
|
||||||
|
const res = await fetchChunkContent(chunkId)
|
||||||
|
const content = String(res?.data?.content || '').trim()
|
||||||
|
if (!content) {
|
||||||
|
const msg = t('agentStream.citation.notFound')
|
||||||
|
setCitationChunkCache(scope, chunkId, { content: '', error: msg })
|
||||||
|
float.value.error = msg
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setCitationChunkCache(scope, chunkId, { content })
|
||||||
|
float.value.content = content
|
||||||
|
} catch {
|
||||||
|
const msg = t('agentStream.citation.loadFailed')
|
||||||
|
setCitationChunkCache(scope, chunkId, { content: '', error: msg })
|
||||||
|
float.value.error = msg
|
||||||
|
} finally {
|
||||||
|
float.value.loading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const scheduleClose = () => {
|
||||||
|
if (closeTimer) window.clearTimeout(closeTimer)
|
||||||
|
closeTimer = window.setTimeout(() => {
|
||||||
|
const hoveredCitation = document.querySelector('.citation-kb:hover, .citation-web:hover')
|
||||||
|
const hoveredPopup = document.querySelector('.chat-citation-float:hover')
|
||||||
|
if (!hoveredCitation && !hoveredPopup) {
|
||||||
|
float.value.visible = false
|
||||||
|
}
|
||||||
|
}, 120)
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancelClose = () => {
|
||||||
|
if (closeTimer) {
|
||||||
|
window.clearTimeout(closeTimer)
|
||||||
|
closeTimer = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onMouseOver = (e: Event) => {
|
||||||
|
const target = e.target as HTMLElement
|
||||||
|
const kbEl = target.closest?.('.citation-kb') as HTMLElement | null
|
||||||
|
const webEl = target.closest?.('.citation-web') as HTMLElement | null
|
||||||
|
if (!kbEl && !webEl) return
|
||||||
|
cancelClose()
|
||||||
|
if (hoverTimer) window.clearTimeout(hoverTimer)
|
||||||
|
hoverTimer = window.setTimeout(() => {
|
||||||
|
if (kbEl) void openKb(kbEl)
|
||||||
|
else if (webEl) openWeb(webEl)
|
||||||
|
}, kbEl ? 80 : 40)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onMouseOut = (e: Event) => {
|
||||||
|
const rt = (e as MouseEvent).relatedTarget as HTMLElement | null
|
||||||
|
if (rt?.closest?.('.citation-kb, .citation-web, .chat-citation-float')) return
|
||||||
|
if (hoverTimer) {
|
||||||
|
window.clearTimeout(hoverTimer)
|
||||||
|
hoverTimer = null
|
||||||
|
}
|
||||||
|
scheduleClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
const onClick = (e: Event) => {
|
||||||
|
const target = e.target as HTMLElement
|
||||||
|
const kbEl = target.closest?.('.citation-kb') as HTMLElement | null
|
||||||
|
if (kbEl) {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
void openKb(kbEl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onViewportChange = () => {
|
||||||
|
if (float.value.visible) scheduleClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
const bind = () => {
|
||||||
|
const root = rootRef.value
|
||||||
|
if (!root) return
|
||||||
|
root.addEventListener('mouseover', onMouseOver, true)
|
||||||
|
root.addEventListener('mouseout', onMouseOut, true)
|
||||||
|
root.addEventListener('click', onClick, true)
|
||||||
|
window.addEventListener('scroll', onViewportChange, true)
|
||||||
|
window.addEventListener('resize', onViewportChange, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const unbind = () => {
|
||||||
|
const root = rootRef.value
|
||||||
|
if (root) {
|
||||||
|
root.removeEventListener('mouseover', onMouseOver, true)
|
||||||
|
root.removeEventListener('mouseout', onMouseOut, true)
|
||||||
|
root.removeEventListener('click', onClick, true)
|
||||||
|
}
|
||||||
|
window.removeEventListener('scroll', onViewportChange, true)
|
||||||
|
window.removeEventListener('resize', onViewportChange, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(rootRef, () => {
|
||||||
|
unbind()
|
||||||
|
bind()
|
||||||
|
}, { flush: 'post' })
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
bind()
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
unbind()
|
||||||
|
if (hoverTimer) window.clearTimeout(hoverTimer)
|
||||||
|
if (closeTimer) window.clearTimeout(closeTimer)
|
||||||
|
})
|
||||||
|
|
||||||
|
return { float, rebind: () => { unbind(); bind() }, cancelClose, scheduleClose }
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
import { onBeforeUnmount, ref, unref, watch, type MaybeRef, type Ref } from 'vue'
|
import { onBeforeUnmount, ref, unref, watch, type MaybeRef, type Ref } from 'vue'
|
||||||
import { getEmbedChunkById } from '@/api/embed'
|
import { getEmbedChunkById } from '@/api/embed'
|
||||||
|
import {
|
||||||
|
getCitationChunkCache,
|
||||||
|
setCitationChunkCache,
|
||||||
|
} from '@/utils/citationChunkCache'
|
||||||
|
|
||||||
type FloatState = {
|
type FloatState = {
|
||||||
visible: boolean
|
visible: boolean
|
||||||
@@ -13,8 +17,6 @@ type FloatState = {
|
|||||||
error: string
|
error: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const chunkCache = new Map<string, { content: string; error?: string }>()
|
|
||||||
|
|
||||||
export function useEmbedCitationPopover(
|
export function useEmbedCitationPopover(
|
||||||
rootRef: Ref<HTMLElement | null>,
|
rootRef: Ref<HTMLElement | null>,
|
||||||
channelId: MaybeRef<string>,
|
channelId: MaybeRef<string>,
|
||||||
@@ -35,6 +37,8 @@ export function useEmbedCitationPopover(
|
|||||||
let hoverTimer: number | null = null
|
let hoverTimer: number | null = null
|
||||||
let closeTimer: number | null = null
|
let closeTimer: number | null = null
|
||||||
|
|
||||||
|
const getCacheScope = () => `embed:${unref(channelId)}:${unref(token)}`
|
||||||
|
|
||||||
const positionFor = (el: HTMLElement, offsetY = 0) => {
|
const positionFor = (el: HTMLElement, offsetY = 0) => {
|
||||||
const rect = el.getBoundingClientRect()
|
const rect = el.getBoundingClientRect()
|
||||||
float.value.top = rect.bottom + window.scrollY + 6 + offsetY
|
float.value.top = rect.bottom + window.scrollY + 6 + offsetY
|
||||||
@@ -63,7 +67,8 @@ export function useEmbedCitationPopover(
|
|||||||
float.value.visible = true
|
float.value.visible = true
|
||||||
positionFor(el, 4)
|
positionFor(el, 4)
|
||||||
|
|
||||||
const cached = chunkCache.get(chunkId)
|
const scope = getCacheScope()
|
||||||
|
const cached = getCitationChunkCache(scope, chunkId)
|
||||||
if (cached) {
|
if (cached) {
|
||||||
float.value.content = cached.content
|
float.value.content = cached.content
|
||||||
float.value.error = cached.error || ''
|
float.value.error = cached.error || ''
|
||||||
@@ -77,11 +82,11 @@ export function useEmbedCitationPopover(
|
|||||||
try {
|
try {
|
||||||
const res = await getEmbedChunkById(unref(channelId), unref(token), chunkId)
|
const res = await getEmbedChunkById(unref(channelId), unref(token), chunkId)
|
||||||
const content = String(res?.data?.content || '').trim()
|
const content = String(res?.data?.content || '').trim()
|
||||||
chunkCache.set(chunkId, { content })
|
setCitationChunkCache(scope, chunkId, { content })
|
||||||
float.value.content = content
|
float.value.content = content
|
||||||
} catch {
|
} catch {
|
||||||
const msg = 'Failed to load'
|
const msg = 'Failed to load'
|
||||||
chunkCache.set(chunkId, { content: '', error: msg })
|
setCitationChunkCache(scope, chunkId, { content: '', error: msg })
|
||||||
float.value.error = msg
|
float.value.error = msg
|
||||||
} finally {
|
} finally {
|
||||||
float.value.loading = false
|
float.value.loading = false
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import i18n from '@/i18n';
|
import i18n from '@/i18n';
|
||||||
|
import { buildMermaidBlockHtml, buildMermaidLoadingHtml } from '@/utils/markdownEnhancements';
|
||||||
|
|
||||||
const STREAMING_IMAGE_PLACEHOLDER = '<span class="streaming-image-loading"><span class="streaming-image-loading__skeleton"></span></span>';
|
const STREAMING_IMAGE_PLACEHOLDER = '<span class="streaming-image-loading"><span class="streaming-image-loading__skeleton"></span></span>';
|
||||||
|
const STREAMING_MERMAID_PLACEHOLDER = buildMermaidLoadingHtml();
|
||||||
|
const MERMAID_FENCE_START = '```mermaid';
|
||||||
|
|
||||||
export const replaceIncompleteImageWithPlaceholder = (content: string): string => {
|
export const replaceIncompleteImageWithPlaceholder = (content: string): string => {
|
||||||
if (!content) return '';
|
if (!content) return '';
|
||||||
@@ -23,6 +26,65 @@ export const replaceIncompleteImageWithPlaceholder = (content: string): string =
|
|||||||
return content;
|
return content;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Hide an unclosed trailing ```mermaid fence while streaming to avoid layout jitter. */
|
||||||
|
export const replaceIncompleteMermaidWithPlaceholder = (content: string): string => {
|
||||||
|
if (!content) return '';
|
||||||
|
|
||||||
|
const start = content.lastIndexOf(MERMAID_FENCE_START);
|
||||||
|
if (start < 0) return content;
|
||||||
|
|
||||||
|
const tail = content.slice(start + MERMAID_FENCE_START.length);
|
||||||
|
if (tail.includes('```')) return content;
|
||||||
|
|
||||||
|
return content.slice(0, start) + STREAMING_MERMAID_PLACEHOLDER;
|
||||||
|
};
|
||||||
|
|
||||||
|
const MERMAID_BLOCK_RE = /```mermaid[\s\S]*?```/;
|
||||||
|
|
||||||
|
/** Keep mermaid as a stable placeholder for the whole stream; render once at the end. */
|
||||||
|
export const maskMermaidBlocksForStreaming = (content: string): string => {
|
||||||
|
if (!content) return '';
|
||||||
|
const masked = content.replace(MERMAID_BLOCK_RE, STREAMING_MERMAID_PLACEHOLDER);
|
||||||
|
return replaceIncompleteMermaidWithPlaceholder(masked);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const hasCompleteMermaidBlock = (content: string): boolean => {
|
||||||
|
return MERMAID_BLOCK_RE.test(content);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** While streaming: loading placeholder for mermaid; swap to cached SVG after sanitize. */
|
||||||
|
export const prepareStreamingMermaidMarkdown = (
|
||||||
|
content: string,
|
||||||
|
_cachedSvgHtml?: string | null,
|
||||||
|
): string => {
|
||||||
|
if (!content) return '';
|
||||||
|
|
||||||
|
if (hasCompleteMermaidBlock(content)) {
|
||||||
|
return maskMermaidBlocksForStreaming(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
return replaceIncompleteMermaidWithPlaceholder(content);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const extractFirstMermaidCode = (content: string): string | null => {
|
||||||
|
const match = content.match(/```mermaid([\s\S]*?)```/);
|
||||||
|
return match?.[1]?.trim() || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const STREAMING_MERMAID_LOADING_RE = /<div class="chat-mermaid-block[^"]*"[^>]*>[\s\S]*?<div class="streaming-mermaid-loading"[^>]*>[\s\S]*?<\/div>[\s\S]*?<\/div>/g;
|
||||||
|
|
||||||
|
/** Inject trusted Mermaid SVG after DOMPurify, replacing the streaming loading shell. */
|
||||||
|
export const injectCachedMermaidSvg = (
|
||||||
|
html: string,
|
||||||
|
cachedSvgHtml: string | null | undefined,
|
||||||
|
): string => {
|
||||||
|
if (!html || !cachedSvgHtml) return html;
|
||||||
|
return html.replace(
|
||||||
|
STREAMING_MERMAID_LOADING_RE,
|
||||||
|
buildMermaidBlockHtml(cachedSvgHtml, 'data-mermaid="cached"'),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const formatManualTitle = (question?: string): string => {
|
export const formatManualTitle = (question?: string): string => {
|
||||||
if (!question) {
|
if (!question) {
|
||||||
return i18n.global.t('chat.sessionExcerpt');
|
return i18n.global.t('chat.sessionExcerpt');
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import test from 'node:test'
|
||||||
|
import {
|
||||||
|
clearCitationChunkCache,
|
||||||
|
getCitationChunkCache,
|
||||||
|
makeCitationCacheKey,
|
||||||
|
setCitationChunkCache,
|
||||||
|
} from './citationChunkCache.ts'
|
||||||
|
|
||||||
|
test('makeCitationCacheKey combines scope and chunkId', () => {
|
||||||
|
assert.equal(makeCitationCacheKey('session-1', 'chunk-a'), 'session-1::chunk-a')
|
||||||
|
assert.equal(
|
||||||
|
makeCitationCacheKey('embed:ch:tok', 'chunk-b'),
|
||||||
|
'embed:ch:tok::chunk-b',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('get/set are isolated per scope', () => {
|
||||||
|
clearCitationChunkCache()
|
||||||
|
setCitationChunkCache('session-1', 'chunk-a', { content: 'one' })
|
||||||
|
setCitationChunkCache('session-2', 'chunk-a', { content: 'two' })
|
||||||
|
|
||||||
|
assert.equal(getCitationChunkCache('session-1', 'chunk-a')?.content, 'one')
|
||||||
|
assert.equal(getCitationChunkCache('session-2', 'chunk-a')?.content, 'two')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('clearCitationChunkCache clears one scope or all', () => {
|
||||||
|
clearCitationChunkCache()
|
||||||
|
setCitationChunkCache('session-1', 'chunk-a', { content: 'one' })
|
||||||
|
setCitationChunkCache('session-2', 'chunk-a', { content: 'two' })
|
||||||
|
|
||||||
|
clearCitationChunkCache('session-1')
|
||||||
|
assert.equal(getCitationChunkCache('session-1', 'chunk-a'), undefined)
|
||||||
|
assert.equal(getCitationChunkCache('session-2', 'chunk-a')?.content, 'two')
|
||||||
|
|
||||||
|
clearCitationChunkCache()
|
||||||
|
assert.equal(getCitationChunkCache('session-2', 'chunk-a'), undefined)
|
||||||
|
})
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
export type CitationChunkCacheValue = { content: string; error?: string }
|
||||||
|
|
||||||
|
const chunkCache = new Map<string, CitationChunkCacheValue>()
|
||||||
|
|
||||||
|
export function makeCitationCacheKey(scope: string, chunkId: string): string {
|
||||||
|
return `${scope}::${chunkId}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCitationChunkCache(
|
||||||
|
scope: string,
|
||||||
|
chunkId: string,
|
||||||
|
): CitationChunkCacheValue | undefined {
|
||||||
|
return chunkCache.get(makeCitationCacheKey(scope, chunkId))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setCitationChunkCache(
|
||||||
|
scope: string,
|
||||||
|
chunkId: string,
|
||||||
|
value: CitationChunkCacheValue,
|
||||||
|
): void {
|
||||||
|
chunkCache.set(makeCitationCacheKey(scope, chunkId), value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearCitationChunkCache(scope?: string): void {
|
||||||
|
if (scope === undefined) {
|
||||||
|
chunkCache.clear()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const prefix = `${scope}::`
|
||||||
|
for (const key of chunkCache.keys()) {
|
||||||
|
if (key.startsWith(prefix)) {
|
||||||
|
chunkCache.delete(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
/** Shared citation tag preprocessing for chat markdown (QA + agent). */
|
/** Shared citation tag preprocessing for chat markdown (QA + agent). */
|
||||||
|
|
||||||
|
/** Self-closing or unclosed `<kb/>` / `<web/>` tags from model output. */
|
||||||
|
export const KB_WEB_TAG_RE = /<(?:kb|web)\b[^>]*?\s*\/?>/g
|
||||||
|
const KB_TAG_ATTR_RE = /<kb\b([^>]*?)\s*\/?>/g
|
||||||
|
const WEB_TAG_ATTR_RE = /<web\b([^>]*?)\s*\/?>/g
|
||||||
|
|
||||||
const ATTRIBUTE_REGEX = /([\w-]+)\s*=\s*"([^"]*)"/g
|
const ATTRIBUTE_REGEX = /([\w-]+)\s*=\s*"([^"]*)"/g
|
||||||
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
||||||
|
|
||||||
|
export type CitationKnowledgeRef = {
|
||||||
|
id?: string
|
||||||
|
knowledge_id?: string
|
||||||
|
knowledge_title?: string
|
||||||
|
knowledge_filename?: string
|
||||||
|
chunk_index?: number
|
||||||
|
chunk_type?: string
|
||||||
|
knowledge_base_id?: string
|
||||||
|
}
|
||||||
|
|
||||||
function parseTagAttributes(attrString: string): Record<string, string> {
|
function parseTagAttributes(attrString: string): Record<string, string> {
|
||||||
const attributes: Record<string, string> = {}
|
const attributes: Record<string, string> = {}
|
||||||
@@ -30,12 +46,88 @@ function truncateMiddle(text: string, maxLength = 13): string {
|
|||||||
return `${start}...${end}`
|
return `${start}...${end}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeDocTitle(title: string): string {
|
||||||
|
return title.trim().toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
function docTitlesMatch(a: string, b: string): boolean {
|
||||||
|
if (!a || !b) return false
|
||||||
|
const na = normalizeDocTitle(a)
|
||||||
|
const nb = normalizeDocTitle(b)
|
||||||
|
return na === nb || na.includes(nb) || nb.includes(na)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Map model context index (1, FAQ-1, DOC-2) to the real chunk UUID from retrieval results. */
|
||||||
|
export function resolveCitationChunkId(
|
||||||
|
rawChunkId: string,
|
||||||
|
attrs: { doc?: string; kbId?: string },
|
||||||
|
refs?: CitationKnowledgeRef[] | null,
|
||||||
|
): string {
|
||||||
|
const raw = String(rawChunkId || '').trim()
|
||||||
|
if (!raw || UUID_RE.test(raw)) return raw
|
||||||
|
|
||||||
|
const list = (refs || []).filter((r) => r && r.chunk_type !== 'web_search')
|
||||||
|
if (!list.length) return raw
|
||||||
|
|
||||||
|
const doc = (attrs.doc || '').trim()
|
||||||
|
const kbId = (attrs.kbId || '').trim()
|
||||||
|
|
||||||
|
if (doc) {
|
||||||
|
const byDoc = list.find(
|
||||||
|
(r) =>
|
||||||
|
docTitlesMatch(doc, r.knowledge_title || '') ||
|
||||||
|
docTitlesMatch(doc, r.knowledge_filename || ''),
|
||||||
|
)
|
||||||
|
if (byDoc?.id) return byDoc.id
|
||||||
|
}
|
||||||
|
|
||||||
|
const faqMatch = raw.match(/^FAQ-(\d+)$/i)
|
||||||
|
if (faqMatch) {
|
||||||
|
const faqRefs = list.filter((r) => r.chunk_type === 'faq')
|
||||||
|
const hit = faqRefs[parseInt(faqMatch[1], 10) - 1]
|
||||||
|
if (hit?.id) return hit.id
|
||||||
|
}
|
||||||
|
|
||||||
|
const docMatch = raw.match(/^DOC-(\d+)$/i)
|
||||||
|
if (docMatch) {
|
||||||
|
const docRefs = list.filter((r) => r.chunk_type !== 'faq')
|
||||||
|
const hit = docRefs[parseInt(docMatch[1], 10) - 1]
|
||||||
|
if (hit?.id) return hit.id
|
||||||
|
}
|
||||||
|
|
||||||
|
const num = parseInt(raw, 10)
|
||||||
|
if (!Number.isNaN(num) && String(num) === raw) {
|
||||||
|
const byPos = list[num - 1]
|
||||||
|
if (byPos?.id) return byPos.id
|
||||||
|
const byChunkIndex = list.find((r) => r.chunk_index === num || r.chunk_index === num - 1)
|
||||||
|
if (byChunkIndex?.id) return byChunkIndex.id
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kbId) {
|
||||||
|
const scoped = list.filter((r) => r.knowledge_base_id === kbId)
|
||||||
|
if (doc) {
|
||||||
|
const byDoc = scoped.find(
|
||||||
|
(r) =>
|
||||||
|
docTitlesMatch(doc, r.knowledge_title || '') ||
|
||||||
|
docTitlesMatch(doc, r.knowledge_filename || ''),
|
||||||
|
)
|
||||||
|
if (byDoc?.id) return byDoc.id
|
||||||
|
}
|
||||||
|
if (scoped.length === 1 && scoped[0].id) return scoped[0].id
|
||||||
|
}
|
||||||
|
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
|
||||||
/** Convert <web/> / <kb/> / [[wiki]] tags into inline citation HTML. */
|
/** Convert <web/> / <kb/> / [[wiki]] tags into inline citation HTML. */
|
||||||
export function preprocessCitationTags(contentStr: string): string {
|
export function preprocessCitationTags(
|
||||||
|
contentStr: string,
|
||||||
|
refs?: CitationKnowledgeRef[] | null,
|
||||||
|
): string {
|
||||||
if (!contentStr.trim()) return ''
|
if (!contentStr.trim()) return ''
|
||||||
|
|
||||||
return contentStr
|
return contentStr
|
||||||
.replace(/<web\b([^>]*)\/>/g, (_m, attrString: string) => {
|
.replace(WEB_TAG_ATTR_RE, (_m, attrString: string) => {
|
||||||
const attrs = parseTagAttributes(attrString)
|
const attrs = parseTagAttributes(attrString)
|
||||||
const url = attrs.url || ''
|
const url = attrs.url || ''
|
||||||
const title = attrs.title || ''
|
const title = attrs.title || ''
|
||||||
@@ -52,20 +144,21 @@ export function preprocessCitationTags(contentStr: string): string {
|
|||||||
}
|
}
|
||||||
const safeTitle = escapeHtml(title)
|
const safeTitle = escapeHtml(title)
|
||||||
const safeUrl = escapeHtml(url)
|
const safeUrl = escapeHtml(url)
|
||||||
return `<a class="citation citation-web" data-url="${safeUrl}" href="${safeUrl}" target="_blank" rel="noopener noreferrer"><span class="citation-icon web"></span><span class="citation-domain">${domain}</span><span class="citation-tip"><span class="tip-title">${safeTitle}</span><span class="tip-url">${safeUrl}</span></span></a>`
|
return `<a class="citation citation-web" data-url="${safeUrl}" href="${safeUrl}" target="_blank" rel="noopener noreferrer"><span class="citation-icon citation-icon--web" aria-hidden="true"></span><span class="citation-domain">${domain}</span><span class="citation-tip"><span class="tip-title">${safeTitle}</span><span class="tip-url">${safeUrl}</span></span></a>`
|
||||||
})
|
})
|
||||||
.replace(/<kb\b([^>]*)\/>/g, (_m, attrString: string) => {
|
.replace(KB_TAG_ATTR_RE, (_m, attrString: string) => {
|
||||||
const attrs = parseTagAttributes(attrString)
|
const attrs = parseTagAttributes(attrString)
|
||||||
const doc = attrs.doc || ''
|
const doc = attrs.doc || ''
|
||||||
const chunkId = attrs.chunk_id || attrs.chunkId || ''
|
const rawChunkId = attrs.chunk_id || attrs.chunkId || ''
|
||||||
const kbId = attrs.kb_id || attrs.kbId || ''
|
const kbId = attrs.kb_id || attrs.kbId || ''
|
||||||
|
const chunkId = resolveCitationChunkId(rawChunkId, { doc, kbId }, refs)
|
||||||
if (!doc || !chunkId) return ''
|
if (!doc || !chunkId) return ''
|
||||||
|
|
||||||
const safeDoc = escapeHtml(doc)
|
const safeDoc = escapeHtml(doc)
|
||||||
const safeKbId = escapeHtml(kbId)
|
const safeKbId = escapeHtml(kbId)
|
||||||
const safeChunkId = escapeHtml(chunkId)
|
const safeChunkId = escapeHtml(chunkId)
|
||||||
const displayDoc = escapeHtml(truncateMiddle(doc))
|
const displayDoc = escapeHtml(truncateMiddle(doc))
|
||||||
return `<span class="citation citation-kb" data-kb-id="${safeKbId}" data-chunk-id="${safeChunkId}" data-doc="${safeDoc}" role="button" tabindex="0"><span class="citation-icon kb"></span><span class="citation-text">${displayDoc}</span><span class="citation-tip"><span class="tip-loading">…</span></span></span>`
|
return `<span class="citation citation-kb" data-kb-id="${safeKbId}" data-chunk-id="${safeChunkId}" data-doc="${safeDoc}" role="button" tabindex="0"><span class="citation-icon citation-icon--book" aria-hidden="true"></span><span class="citation-text">${displayDoc}</span><span class="citation-tip"><span class="tip-loading">…</span></span></span>`
|
||||||
})
|
})
|
||||||
.replace(/\[\[([^\]]+)\]\]/g, (match, inner: string) => {
|
.replace(/\[\[([^\]]+)\]\]/g, (match, inner: string) => {
|
||||||
const pipeIdx = inner.indexOf('|')
|
const pipeIdx = inner.indexOf('|')
|
||||||
@@ -85,7 +178,10 @@ export function preprocessCitationTags(contentStr: string): string {
|
|||||||
const HTML_PLACEHOLDER_RE = /@@WEKNORA_HTML_PLACEHOLDER_(\d+)@@/g
|
const HTML_PLACEHOLDER_RE = /@@WEKNORA_HTML_PLACEHOLDER_(\d+)@@/g
|
||||||
|
|
||||||
/** Protect citation HTML from markdown parser; restore after marked.parse. */
|
/** Protect citation HTML from markdown parser; restore after marked.parse. */
|
||||||
export function extractCitationHtmlPlaceholders(contentStr: string): { content: string; htmlSnippets: string[] } {
|
export function extractCitationHtmlPlaceholders(
|
||||||
|
contentStr: string,
|
||||||
|
refs?: CitationKnowledgeRef[] | null,
|
||||||
|
): { content: string; htmlSnippets: string[] } {
|
||||||
const htmlSnippets: string[] = []
|
const htmlSnippets: string[] = []
|
||||||
const storeHtml = (html: string): string => {
|
const storeHtml = (html: string): string => {
|
||||||
const idx = htmlSnippets.length
|
const idx = htmlSnippets.length
|
||||||
@@ -94,8 +190,8 @@ export function extractCitationHtmlPlaceholders(contentStr: string): { content:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const content = contentStr
|
const content = contentStr
|
||||||
.replace(/<(?:kb|web)\b[^>]*\/>/g, (match) => storeHtml(preprocessCitationTags(match)))
|
.replace(KB_WEB_TAG_RE, (match) => storeHtml(preprocessCitationTags(match, refs)))
|
||||||
.replace(/\[\[([^\]]+)\]\]/g, (match) => storeHtml(preprocessCitationTags(match)))
|
.replace(/\[\[([^\]]+)\]\]/g, (match) => storeHtml(preprocessCitationTags(match, refs)))
|
||||||
|
|
||||||
return { content, htmlSnippets }
|
return { content, htmlSnippets }
|
||||||
}
|
}
|
||||||
@@ -105,10 +201,67 @@ export function restoreCitationHtmlPlaceholders(html: string, htmlSnippets: stri
|
|||||||
return html.replace(HTML_PLACEHOLDER_RE, (_match, idx) => htmlSnippets[Number(idx)] || '')
|
return html.replace(HTML_PLACEHOLDER_RE, (_match, idx) => htmlSnippets[Number(idx)] || '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Collapse newlines around <kb/> / <web/> so marked keeps citations inline. */
|
||||||
|
export function joinCitationTagsToPreviousLine(content: string): string {
|
||||||
|
if (!content) return content
|
||||||
|
|
||||||
|
let result = content
|
||||||
|
|
||||||
|
// Newlines between consecutive citation tags
|
||||||
|
let prev = ''
|
||||||
|
while (result !== prev) {
|
||||||
|
prev = result
|
||||||
|
result = result.replace(
|
||||||
|
/(<(?:kb|web)\b[^>]*?\s*\/?>)\s*\n+\s*(<(?:kb|web)\b)/gi,
|
||||||
|
'$1 $2',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Blank lines before citations: join to previous prose, but keep a break after lists
|
||||||
|
result = result.replace(/\n[ \t]*\n+([ \t]*<(?:kb|web)\b)/gi, (match, kbStart, offset, full) => {
|
||||||
|
const before = full.slice(0, offset)
|
||||||
|
const lastLine = before.split('\n').filter((line) => line.trim()).pop() || ''
|
||||||
|
const isListItem = /^\s*(\d+\.|[-*+])\s+\S/.test(lastLine)
|
||||||
|
return isListItem ? `\n\n${kbStart}` : ` ${kbStart}`
|
||||||
|
})
|
||||||
|
|
||||||
|
// Single newline before citation when it follows text or another citation (not after a blank line)
|
||||||
|
result = result.replace(
|
||||||
|
/(?<!\n)(<(?:kb|web)\b[^>]*?\s*\/?>|[ \t]*\S[^\n]*?)\n([ \t]*<(?:kb|web)\b)/g,
|
||||||
|
'$1 $2',
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
const CITATION_HTML_FRAGMENT =
|
||||||
|
'(?:<span class="citation\\b[^]*?</span>|<a class="citation\\b[^]*?</a>)'
|
||||||
|
|
||||||
|
/** Merge citation-only <p> blocks into the preceding paragraph (marked splits on newlines). */
|
||||||
|
export function collapseStandaloneCitationParagraphs(html: string): string {
|
||||||
|
if (!html || !html.includes('citation')) return html
|
||||||
|
|
||||||
|
const mergePattern = new RegExp(
|
||||||
|
`(<\\/(?:p|li)>)\\s*(?:<p>\\s*<\\/p>\\s*)*<p>\\s*(${CITATION_HTML_FRAGMENT})\\s*<\\/p>`,
|
||||||
|
'g',
|
||||||
|
)
|
||||||
|
|
||||||
|
let result = html
|
||||||
|
let prev = ''
|
||||||
|
while (result !== prev) {
|
||||||
|
prev = result
|
||||||
|
result = result.replace(mergePattern, (_match, closeTag: string, citation: string) => {
|
||||||
|
return ` ${citation}${closeTag}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/** Preserve raw <kb>/<web> tags before sanitizers that would strip them. */
|
/** Preserve raw <kb>/<web> tags before sanitizers that would strip them. */
|
||||||
export function preserveCitationTags(contentStr: string): { text: string; tags: string[] } {
|
export function preserveCitationTags(contentStr: string): { text: string; tags: string[] } {
|
||||||
const tags: string[] = []
|
const tags: string[] = []
|
||||||
const text = contentStr.replace(/<(?:kb|web)\b[^>]*\/>/g, (match) => {
|
const text = contentStr.replace(KB_WEB_TAG_RE, (match) => {
|
||||||
const idx = tags.length
|
const idx = tags.length
|
||||||
tags.push(match)
|
tags.push(match)
|
||||||
return `\x00TAG${idx}\x00`
|
return `\x00TAG${idx}\x00`
|
||||||
|
|||||||
@@ -3,23 +3,27 @@
|
|||||||
<div style="display: flex;flex-direction: column; gap:8px">
|
<div style="display: flex;flex-direction: column; gap:8px">
|
||||||
<!-- 显示@的知识库和文件(非 Agent 模式下显示) -->
|
<!-- 显示@的知识库和文件(非 Agent 模式下显示) -->
|
||||||
<div v-if="!session.isAgentMode && mentionedItems && mentionedItems.length > 0" class="mentioned_items">
|
<div v-if="!session.isAgentMode && mentionedItems && mentionedItems.length > 0" class="mentioned_items">
|
||||||
<span
|
<span v-for="item in mentionedItems" :key="item.id" class="mentioned_tag" :class="[
|
||||||
v-for="item in mentionedItems"
|
item.type === 'kb' ? (item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag') : 'file-tag'
|
||||||
:key="item.id"
|
]">
|
||||||
class="mentioned_tag"
|
|
||||||
:class="[
|
|
||||||
item.type === 'kb' ? (item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag') : 'file-tag'
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
<span class="tag_icon">
|
<span class="tag_icon">
|
||||||
<t-icon v-if="item.type === 'kb'" :name="item.kb_type === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
<t-icon v-if="item.type === 'kb'"
|
||||||
|
:name="item.kb_type === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||||
<t-icon v-else name="file" />
|
<t-icon v-else name="file" />
|
||||||
</span>
|
</span>
|
||||||
<span class="tag_name">{{ item.name }}</span>
|
<span class="tag_name">{{ item.name }}</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<docInfo :session="session"></docInfo>
|
<div v-if="session.isRagMode" class="rag-answer-stack">
|
||||||
<AgentStreamDisplay :session="session" :session-id="sessionId" :user-query="userQuery" v-if="session.isAgentMode"></AgentStreamDisplay>
|
<RagPipelineProgress :session="session" :embedded-mode="embeddedMode" />
|
||||||
|
<AgentStreamDisplay v-if="session.isAgentMode" :session="session" :session-id="sessionId"
|
||||||
|
:user-query="userQuery" :rag-mode="true" />
|
||||||
|
</div>
|
||||||
|
<template v-else>
|
||||||
|
<docInfo v-if="session.knowledge_references?.length" :session="session"></docInfo>
|
||||||
|
<AgentStreamDisplay :session="session" :session-id="sessionId" :user-query="userQuery"
|
||||||
|
v-if="session.isAgentMode" />
|
||||||
|
</template>
|
||||||
<deepThink :deepSession="session" v-if="session.showThink && !session.isAgentMode"></deepThink>
|
<deepThink :deepSession="session" v-if="session.showThink && !session.isAgentMode"></deepThink>
|
||||||
</div>
|
</div>
|
||||||
<!-- 非 Agent 模式下才显示传统的 markdown 渲染 -->
|
<!-- 非 Agent 模式下才显示传统的 markdown 渲染 -->
|
||||||
@@ -40,10 +44,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- 复制和添加到知识库按钮 - 非 Agent 模式下显示 -->
|
<!-- 复制和添加到知识库按钮 - 非 Agent 模式下显示 -->
|
||||||
<div v-if="session.is_completed && (content || session.content)" class="answer-toolbar">
|
<div v-if="session.is_completed && (content || session.content)" class="answer-toolbar">
|
||||||
<t-button size="small" variant="outline" shape="round" @click.stop="handleCopyAnswer" :title="$t('agent.copy')">
|
<t-button size="small" variant="outline" shape="round" @click.stop="handleCopyAnswer"
|
||||||
|
:title="$t('agent.copy')">
|
||||||
<t-icon name="copy" />
|
<t-icon name="copy" />
|
||||||
</t-button>
|
</t-button>
|
||||||
<t-button size="small" variant="outline" shape="round" @click.stop="handleAddToKnowledge" :title="$t('agent.addToKnowledgeBase')">
|
<t-button size="small" variant="outline" shape="round" @click.stop="handleAddToKnowledge"
|
||||||
|
:title="$t('agent.addToKnowledgeBase')">
|
||||||
<t-icon name="add" />
|
<t-icon name="add" />
|
||||||
</t-button>
|
</t-button>
|
||||||
<!-- Fallback 提示图标 -->
|
<!-- Fallback 提示图标 -->
|
||||||
@@ -52,28 +58,29 @@
|
|||||||
<t-icon name="info-circle" />
|
<t-icon name="info-circle" />
|
||||||
</t-button>
|
</t-button>
|
||||||
</t-tooltip>
|
</t-tooltip>
|
||||||
<ChatRequestInfoButton
|
<ChatRequestInfoButton v-if="showRequestInfo" :session="session" :session-id="sessionId" />
|
||||||
v-if="showRequestInfo"
|
|
||||||
:session="session"
|
|
||||||
:session-id="sessionId"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div v-if="isImgLoading" class="img_loading"><t-loading size="small"></t-loading><span>{{ $t('common.loading') }}</span></div>
|
<div v-if="isImgLoading" class="img_loading"><t-loading size="small"></t-loading><span>{{
|
||||||
|
$t('common.loading') }}</span></div>
|
||||||
</div>
|
</div>
|
||||||
<picturePreview :reviewImg="reviewImg" :reviewUrl="reviewUrl" @closePreImg="closePreImg"></picturePreview>
|
<picturePreview :reviewImg="reviewImg" :reviewUrl="reviewUrl" @closePreImg="closePreImg"></picturePreview>
|
||||||
|
<Teleport to="body">
|
||||||
|
<ChatCitationFloat :float="citationFloat" :on-enter="cancelCitationClose"
|
||||||
|
:on-leave="scheduleCitationClose" />
|
||||||
|
</Teleport>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, onBeforeUnmount, watch, computed, ref, reactive, defineProps, nextTick, onUpdated } from 'vue';
|
import { onMounted, onBeforeUnmount, watch, computed, ref, reactive, defineProps, nextTick, onUpdated } from 'vue';
|
||||||
import { marked } from 'marked';
|
|
||||||
import markedKatex from 'marked-katex-extension';
|
|
||||||
import 'katex/dist/katex.min.css';
|
import 'katex/dist/katex.min.css';
|
||||||
import docInfo from './docInfo.vue';
|
import docInfo from './docInfo.vue';
|
||||||
import deepThink from './deepThink.vue';
|
import deepThink from './deepThink.vue';
|
||||||
import AgentStreamDisplay from './AgentStreamDisplay.vue';
|
import AgentStreamDisplay from './AgentStreamDisplay.vue';
|
||||||
|
import RagPipelineProgress from './RagPipelineProgress.vue';
|
||||||
import ChatRequestInfoButton from '@/components/ChatRequestInfoButton.vue';
|
import ChatRequestInfoButton from '@/components/ChatRequestInfoButton.vue';
|
||||||
|
import ChatCitationFloat from '@/components/ChatCitationFloat.vue';
|
||||||
import picturePreview from '@/components/picture-preview.vue';
|
import picturePreview from '@/components/picture-preview.vue';
|
||||||
import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL, hydrateProtectedFileImages } from '@/utils/security';
|
import { sanitizeMarkdownHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL, hydrateProtectedFileImages } from '@/utils/security';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { MessagePlugin } from 'tdesign-vue-next';
|
import { MessagePlugin } from 'tdesign-vue-next';
|
||||||
import { useUIStore } from '@/stores/ui';
|
import { useUIStore } from '@/stores/ui';
|
||||||
@@ -81,36 +88,30 @@ import {
|
|||||||
buildManualMarkdown,
|
buildManualMarkdown,
|
||||||
copyTextToClipboard,
|
copyTextToClipboard,
|
||||||
formatManualTitle,
|
formatManualTitle,
|
||||||
replaceIncompleteImageWithPlaceholder
|
|
||||||
} from '@/utils/chatMessageShared';
|
} from '@/utils/chatMessageShared';
|
||||||
|
import {
|
||||||
|
createChatMarkdownRenderer,
|
||||||
|
renderChatMarkdown,
|
||||||
|
} from '@/utils/chatMarkdownRenderer';
|
||||||
import {
|
import {
|
||||||
createMermaidCodeRenderer,
|
createMermaidCodeRenderer,
|
||||||
ensureMermaidInitialized,
|
ensureMermaidInitialized,
|
||||||
renderMermaidInContainer
|
renderMermaidInContainer,
|
||||||
|
enhanceMarkdownContainer,
|
||||||
} from '@/utils/mermaidShared';
|
} from '@/utils/mermaidShared';
|
||||||
|
import { refreshMarkdownEnhancements } from '@/utils/markdownEnhancements';
|
||||||
marked.use({
|
import { useChatCitationPopover } from '@/composables/useChatCitationPopover';
|
||||||
breaks: true, // 全局启用单个换行支持
|
|
||||||
});
|
|
||||||
|
|
||||||
marked.use(markedKatex({ throwOnError: false, nonStandard: true }));
|
|
||||||
|
|
||||||
const preprocessMathDelimiters = (rawText) => {
|
|
||||||
if (!rawText || typeof rawText !== 'string') {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return rawText
|
|
||||||
.replace(/\\\[([\s\S]*?)\\\]/g, '$$$$$1$$$$')
|
|
||||||
.replace(/\\\(([\s\S]*?)\\\)/g, '$$$1$$');
|
|
||||||
};
|
|
||||||
|
|
||||||
ensureMermaidInitialized();
|
ensureMermaidInitialized();
|
||||||
|
|
||||||
const emit = defineEmits(['scroll-bottom'])
|
const emit = defineEmits(['scroll-bottom'])
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const uiStore = useUIStore();
|
const uiStore = useUIStore();
|
||||||
const renderer = new marked.Renderer();
|
|
||||||
let parentMd = ref()
|
let parentMd = ref()
|
||||||
|
const { float: citationFloat, rebind: rebindCitations, cancelClose: cancelCitationClose, scheduleClose: scheduleCitationClose } = useChatCitationPopover(parentMd, {
|
||||||
|
getKnowledgeReferences: () => props.session?.knowledge_references,
|
||||||
|
sessionId: () => props.sessionId,
|
||||||
|
});
|
||||||
let reviewUrl = ref('')
|
let reviewUrl = ref('')
|
||||||
let reviewImg = ref(false)
|
let reviewImg = ref(false)
|
||||||
let isImgLoading = ref(false);
|
let isImgLoading = ref(false);
|
||||||
@@ -157,18 +158,12 @@ const closePreImg = () => {
|
|||||||
reviewUrl.value = '';
|
reviewUrl.value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建自定义渲染器实例
|
const markdownRenderer = createChatMarkdownRenderer({
|
||||||
const customRenderer = new marked.Renderer();
|
codeRenderer: createMermaidCodeRenderer('mermaid-botmsg'),
|
||||||
// 覆盖图片渲染方法
|
imageRenderer: ({ href, title, text }) => createSafeImage(href, text || '', title || ''),
|
||||||
customRenderer.image = function({href, title, text}){
|
invalidImageHtml: () => `<p>${t('error.invalidImageLink')}</p>`,
|
||||||
if (!isValidImageURL(href)) {
|
isValidImageUrl: isValidImageURL,
|
||||||
return `<p>${t('error.invalidImageLink')}</p>`;
|
});
|
||||||
}
|
|
||||||
return createSafeImage(href, text || '', title || '');
|
|
||||||
};
|
|
||||||
|
|
||||||
// 覆盖代码块渲染方法,支持 Mermaid
|
|
||||||
customRenderer.code = createMermaidCodeRenderer('mermaid-botmsg');
|
|
||||||
|
|
||||||
// 计算属性:将 Markdown 文本转换为 tokens
|
// 计算属性:将 Markdown 文本转换为 tokens
|
||||||
const mentionedItems = computed(() => {
|
const mentionedItems = computed(() => {
|
||||||
@@ -179,11 +174,12 @@ const mentionedItems = computed(() => {
|
|||||||
const renderedHTML = computed(() => {
|
const renderedHTML = computed(() => {
|
||||||
const text = props.content || props.session?.content || '';
|
const text = props.content || props.session?.content || '';
|
||||||
if (!text || typeof text !== 'string') return '';
|
if (!text || typeof text !== 'string') return '';
|
||||||
const processed = replaceIncompleteImageWithPlaceholder(text);
|
return renderChatMarkdown(text, {
|
||||||
const safeText = preprocessMathDelimiters(processed);
|
renderer: markdownRenderer,
|
||||||
const safeMarkdown = safeMarkdownToHTML(safeText);
|
escapeMarkdown: safeMarkdownToHTML,
|
||||||
const html = marked.parse(safeMarkdown, { renderer: customRenderer, breaks: true });
|
sanitizeHtml: sanitizeMarkdownHTML,
|
||||||
return sanitizeHTML(html);
|
knowledgeReferences: props.session?.knowledge_references,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 计算属性:判断是否有实际内容(非空且不只是空白)
|
// 计算属性:判断是否有实际内容(非空且不只是空白)
|
||||||
@@ -225,7 +221,7 @@ const handleAddToKnowledge = () => {
|
|||||||
const question = (props.userQuery || '').trim();
|
const question = (props.userQuery || '').trim();
|
||||||
const manualContent = buildManualMarkdown(question, content);
|
const manualContent = buildManualMarkdown(question, content);
|
||||||
const manualTitle = formatManualTitle(question);
|
const manualTitle = formatManualTitle(question);
|
||||||
``
|
``
|
||||||
uiStore.openManualEditor({
|
uiStore.openManualEditor({
|
||||||
mode: 'create',
|
mode: 'create',
|
||||||
title: manualTitle,
|
title: manualTitle,
|
||||||
@@ -249,18 +245,19 @@ const handleMarkdownImageClick = (e) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 渲染 Mermaid 图表的函数
|
watch(renderedHTML, () => {
|
||||||
const renderMermaidDiagrams = async () => {
|
nextTick(() => {
|
||||||
await renderMermaidInContainer(parentMd.value);
|
rebindCitations();
|
||||||
};
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 监听内容变化并渲染 Mermaid - 只在会话完成后渲染
|
// 渲染 Mermaid 图表的函数
|
||||||
onUpdated(() => {
|
onUpdated(() => {
|
||||||
nextTick(async () => {
|
nextTick(async () => {
|
||||||
await hydrateProtectedFileImages(parentMd.value);
|
await hydrateProtectedFileImages(parentMd.value);
|
||||||
// 只在会话完成后渲染 mermaid
|
refreshMarkdownEnhancements(parentMd.value);
|
||||||
if (props.session?.is_completed) {
|
if (props.session?.is_completed) {
|
||||||
renderMermaidDiagrams();
|
await renderMermaidInContainer(parentMd.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -271,9 +268,9 @@ onMounted(async () => {
|
|||||||
if (parentMd.value) {
|
if (parentMd.value) {
|
||||||
parentMd.value.addEventListener('click', handleMarkdownImageClick, true);
|
parentMd.value.addEventListener('click', handleMarkdownImageClick, true);
|
||||||
}
|
}
|
||||||
|
rebindCitations();
|
||||||
await hydrateProtectedFileImages(parentMd.value);
|
await hydrateProtectedFileImages(parentMd.value);
|
||||||
// 初始渲染 Mermaid 图表
|
await enhanceMarkdownContainer(parentMd.value);
|
||||||
renderMermaidDiagrams();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -284,8 +281,9 @@ onBeforeUnmount(() => {
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
@import '../../../components/css/markdown.less';
|
@import '../../../components/css/chat-markdown.less';
|
||||||
@import '../../../components/css/chat-message-shared.less';
|
@import '../../../components/css/chat-message-shared.less';
|
||||||
|
@import '../../../components/css/chat-citations.less';
|
||||||
|
|
||||||
.bot_msg {
|
.bot_msg {
|
||||||
&.is-embedded {
|
&.is-embedded {
|
||||||
@@ -297,12 +295,22 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rag-answer-stack {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
|
||||||
// 内容包装器 - 与 Agent 模式的 answer 样式一致
|
// 内容包装器 - 与 Agent 模式的 answer 样式一致
|
||||||
.content-wrapper {
|
.content-wrapper {
|
||||||
background: var(--td-bg-color-container);
|
padding: 2px 0;
|
||||||
border-radius: 6px;
|
}
|
||||||
padding: 8px 0px;
|
|
||||||
transition: all 0.2s ease;
|
.markdown-content {
|
||||||
|
// Chat Markdown visual styles are centralized in chat-markdown.less.
|
||||||
|
// Do not add element-level Markdown rules here; update the shared mixin.
|
||||||
|
.chat-markdown-typography();
|
||||||
|
.chat-citation-pills();
|
||||||
}
|
}
|
||||||
|
|
||||||
.mentioned_items {
|
.mentioned_items {
|
||||||
@@ -376,131 +384,13 @@ onBeforeUnmount(() => {
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateY(8px);
|
transform: translateY(8px);
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: translateY(0);
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ai-markdown-template {
|
|
||||||
font-size: 15px;
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-content {
|
|
||||||
:deep(p) {
|
|
||||||
margin: 6px 0;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(code) {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
padding: 2px 5px;
|
|
||||||
border-radius: 3px;
|
|
||||||
font-family: var(--app-font-family-mono);
|
|
||||||
font-size: 11px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(pre) {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
padding: 10px;
|
|
||||||
border-radius: 4px;
|
|
||||||
overflow-x: auto;
|
|
||||||
margin: 6px 0;
|
|
||||||
|
|
||||||
code {
|
|
||||||
background: none;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(ul), :deep(ol) {
|
|
||||||
margin: 6px 0;
|
|
||||||
padding-left: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(li) {
|
|
||||||
margin: 3px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(blockquote) {
|
|
||||||
border-left: 2px solid var(--td-brand-color);
|
|
||||||
padding-left: 10px;
|
|
||||||
margin: 6px 0;
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(h1), :deep(h2), :deep(h3), :deep(h4), :deep(h5), :deep(h6) {
|
|
||||||
margin: 10px 0 6px 0;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(a) {
|
|
||||||
color: var(--td-brand-color);
|
|
||||||
text-decoration: none;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(table) {
|
|
||||||
border-collapse: collapse;
|
|
||||||
margin: 6px 0;
|
|
||||||
font-size: 11px;
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
th, td {
|
|
||||||
border: 1px solid var(--td-component-stroke);
|
|
||||||
padding: 5px 8px;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
tbody tr:nth-child(even) {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(img) {
|
|
||||||
max-width: 80%;
|
|
||||||
max-height: 300px;
|
|
||||||
width: auto;
|
|
||||||
height: auto;
|
|
||||||
border-radius: 8px;
|
|
||||||
display: block;
|
|
||||||
margin: 8px 0;
|
|
||||||
border: 0.5px solid var(--td-component-stroke);
|
|
||||||
object-fit: contain;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: transform 0.2s ease;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mermaid 图表样式
|
|
||||||
:deep(.mermaid) {
|
|
||||||
margin: 16px 0;
|
|
||||||
padding: 16px;
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
border-radius: 8px;
|
|
||||||
overflow-x: auto;
|
|
||||||
text-align: center;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
max-width: 100%;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.ai-markdown-img {
|
.ai-markdown-img {
|
||||||
max-width: 80%;
|
max-width: 80%;
|
||||||
max-height: 300px;
|
max-height: 300px;
|
||||||
@@ -571,9 +461,13 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes typingBounce {
|
@keyframes typingBounce {
|
||||||
0%, 60%, 100% {
|
|
||||||
|
0%,
|
||||||
|
60%,
|
||||||
|
100% {
|
||||||
transform: translateY(0);
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
30% {
|
30% {
|
||||||
transform: translateY(-8px);
|
transform: translateY(-8px);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,36 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="embed-bot-msg" :class="{ 'is-embedded': embeddedMode }">
|
<div class="embed-bot-msg" :class="{ 'is-embedded': embeddedMode }">
|
||||||
<DocInfo
|
<div v-if="session?.isRagMode" class="rag-answer-stack">
|
||||||
v-if="session && !session.isAgentMode"
|
<RagPipelineProgress :session="session" embedded-mode />
|
||||||
:session="session"
|
<AgentStreamDisplay v-if="session?.isAgentMode" :session="session" :session-id="sessionId" :user-query="userQuery"
|
||||||
embedded-mode
|
rag-mode :embedded-mode="embeddedMode" :embed-channel-id="embedChannelId" :embed-token="embedToken" />
|
||||||
/>
|
</div>
|
||||||
<AgentStreamDisplay
|
<template v-else>
|
||||||
v-if="session?.isAgentMode"
|
<DocInfo v-if="session?.knowledge_references?.length" :session="session" embedded-mode />
|
||||||
:session="session"
|
<AgentStreamDisplay v-if="session?.isAgentMode" :session="session" :session-id="sessionId" :user-query="userQuery"
|
||||||
:session-id="sessionId"
|
:embedded-mode="embeddedMode" :embed-channel-id="embedChannelId" :embed-token="embedToken" />
|
||||||
:user-query="userQuery"
|
</template>
|
||||||
:embedded-mode="embeddedMode"
|
<DeepThink v-if="session?.showThink && !session?.isAgentMode" :deep-session="session" />
|
||||||
:embed-channel-id="embedChannelId"
|
<div v-if="!session?.hideContent && !session?.isAgentMode" ref="parentMd">
|
||||||
:embed-token="embedToken"
|
<div v-if="hasActualContent" class="content-wrapper">
|
||||||
/>
|
<div class="ai-markdown-template markdown-content" v-html="renderedHTML" />
|
||||||
<template v-else-if="!session?.isAgentMode">
|
</div>
|
||||||
<DeepThink v-if="session?.showThink" :deep-session="session" />
|
<div v-if="hasActualContent && !session?.is_completed" class="loading-indicator">
|
||||||
<div v-if="!session?.hideContent" ref="parentMd">
|
<div class="loading-typing">
|
||||||
<div v-if="hasActualContent" class="content-wrapper">
|
<span></span>
|
||||||
<div class="ai-markdown-template markdown-content" v-html="renderedHTML" />
|
<span></span>
|
||||||
</div>
|
<span></span>
|
||||||
<div v-if="hasActualContent && !session?.is_completed" class="loading-indicator">
|
|
||||||
<div class="loading-typing">
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</div>
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
<div
|
<div v-if="citationFloat.visible" class="embed-citation-float"
|
||||||
v-if="citationFloat.visible"
|
:style="{ top: `${citationFloat.top}px`, left: `${citationFloat.left}px` }" @mouseenter="cancelCitationClose"
|
||||||
class="embed-citation-float"
|
@mouseleave="scheduleCitationClose">
|
||||||
:style="{ top: `${citationFloat.top}px`, left: `${citationFloat.left}px` }"
|
|
||||||
@mouseenter="cancelCitationClose"
|
|
||||||
@mouseleave="scheduleCitationClose"
|
|
||||||
>
|
|
||||||
<template v-if="citationFloat.type === 'web'">
|
<template v-if="citationFloat.type === 'web'">
|
||||||
<div class="embed-citation-float__title">{{ citationFloat.title || citationFloat.url }}</div>
|
<div class="embed-citation-float__title">{{ citationFloat.title || citationFloat.url }}</div>
|
||||||
<a
|
<a v-if="citationFloat.url" class="embed-citation-float__link" :href="citationFloat.url" target="_blank"
|
||||||
v-if="citationFloat.url"
|
rel="noopener noreferrer">{{ citationFloat.url }}</a>
|
||||||
class="embed-citation-float__link"
|
|
||||||
:href="citationFloat.url"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>{{ citationFloat.url }}</a>
|
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="embed-citation-float__title">{{ citationFloat.title }}</div>
|
<div class="embed-citation-float__title">{{ citationFloat.title }}</div>
|
||||||
@@ -60,30 +45,28 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, defineAsyncComponent, nextTick, onMounted, onUpdated, ref, watch } from 'vue'
|
import { computed, defineAsyncComponent, nextTick, onMounted, onUpdated, ref, watch } from 'vue'
|
||||||
import { marked } from 'marked'
|
|
||||||
import markedKatex from 'marked-katex-extension'
|
|
||||||
import 'katex/dist/katex.min.css'
|
import 'katex/dist/katex.min.css'
|
||||||
import {
|
import {
|
||||||
sanitizeHTML,
|
sanitizeMarkdownHTML,
|
||||||
safeMarkdownToHTML,
|
safeMarkdownToHTML,
|
||||||
createSafeImage,
|
createSafeImage,
|
||||||
isValidImageURL,
|
isValidImageURL,
|
||||||
hydrateProtectedFileImages,
|
hydrateProtectedFileImages,
|
||||||
} from '@/utils/security'
|
} from '@/utils/security'
|
||||||
import { replaceIncompleteImageWithPlaceholder } from '@/utils/chatMessageShared'
|
import {
|
||||||
|
createChatMarkdownRenderer,
|
||||||
|
renderChatMarkdown,
|
||||||
|
} from '@/utils/chatMarkdownRenderer'
|
||||||
import {
|
import {
|
||||||
createMermaidCodeRenderer,
|
createMermaidCodeRenderer,
|
||||||
ensureMermaidInitialized,
|
ensureMermaidInitialized,
|
||||||
renderMermaidInContainer,
|
enhanceMarkdownContainer,
|
||||||
} from '@/utils/mermaidShared'
|
} from '@/utils/mermaidShared'
|
||||||
import {
|
|
||||||
extractCitationHtmlPlaceholders,
|
|
||||||
preserveCitationTags,
|
|
||||||
restoreCitationHtmlPlaceholders,
|
|
||||||
restoreCitationTags,
|
|
||||||
} from '@/utils/citationMarkdown'
|
|
||||||
import { useEmbedCitationPopover } from '@/composables/useEmbedCitationPopover'
|
import { useEmbedCitationPopover } from '@/composables/useEmbedCitationPopover'
|
||||||
|
|
||||||
|
const RagPipelineProgress = defineAsyncComponent(
|
||||||
|
() => import('@/views/chat/components/RagPipelineProgress.vue'),
|
||||||
|
)
|
||||||
const AgentStreamDisplay = defineAsyncComponent(
|
const AgentStreamDisplay = defineAsyncComponent(
|
||||||
() => import('@/views/chat/components/AgentStreamDisplay.vue'),
|
() => import('@/views/chat/components/AgentStreamDisplay.vue'),
|
||||||
)
|
)
|
||||||
@@ -94,28 +77,29 @@ const DeepThink = defineAsyncComponent(
|
|||||||
() => import('@/views/chat/components/deepThink.vue'),
|
() => import('@/views/chat/components/deepThink.vue'),
|
||||||
)
|
)
|
||||||
|
|
||||||
marked.use({ breaks: true })
|
|
||||||
marked.use(markedKatex({ throwOnError: false, nonStandard: true }))
|
|
||||||
ensureMermaidInitialized()
|
ensureMermaidInitialized()
|
||||||
|
|
||||||
const preprocessMathDelimiters = (rawText: string): string => {
|
const markdownRenderer = createChatMarkdownRenderer({
|
||||||
if (!rawText || typeof rawText !== 'string') return ''
|
codeRenderer: createMermaidCodeRenderer('mermaid-embed-botmsg'),
|
||||||
return rawText
|
imageRenderer: ({ href, title, text }) => createSafeImage(href, text || '', title || ''),
|
||||||
.replace(/\\\[([\s\S]*?)\\\]/g, '$$$$$1$$$$')
|
isValidImageUrl: isValidImageURL,
|
||||||
.replace(/\\\(([\s\S]*?)\\\)/g, '$$$1$$')
|
})
|
||||||
}
|
|
||||||
|
|
||||||
const customRenderer = new marked.Renderer()
|
type EmbedSession = {
|
||||||
customRenderer.image = function ({ href, title, text }) {
|
content?: string
|
||||||
if (!isValidImageURL(href)) return ''
|
isRagMode?: boolean
|
||||||
return createSafeImage(href, text || '', title || '')
|
isAgentMode?: boolean
|
||||||
|
showThink?: boolean
|
||||||
|
hideContent?: boolean
|
||||||
|
is_completed?: boolean
|
||||||
|
agentEventStream?: Array<Record<string, unknown>>
|
||||||
|
knowledge_references?: Array<{ chunk_type?: string; knowledge_id?: string; knowledge_title?: string }>
|
||||||
}
|
}
|
||||||
customRenderer.code = createMermaidCodeRenderer('mermaid-embed-botmsg')
|
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
content?: string
|
content?: string
|
||||||
session?: Record<string, unknown>
|
session?: EmbedSession
|
||||||
sessionId?: string
|
sessionId?: string
|
||||||
userQuery?: string
|
userQuery?: string
|
||||||
embeddedMode?: boolean
|
embeddedMode?: boolean
|
||||||
@@ -161,15 +145,11 @@ const scheduleCitationClose = () => {
|
|||||||
const renderedHTML = computed(() => {
|
const renderedHTML = computed(() => {
|
||||||
const text = String(props.content || props.session?.content || '')
|
const text = String(props.content || props.session?.content || '')
|
||||||
if (!text.trim()) return ''
|
if (!text.trim()) return ''
|
||||||
const { text: tagSafe, tags } = preserveCitationTags(text)
|
return renderChatMarkdown(text, {
|
||||||
const processed = replaceIncompleteImageWithPlaceholder(tagSafe)
|
renderer: markdownRenderer,
|
||||||
const mathSafe = preprocessMathDelimiters(processed)
|
escapeMarkdown: safeMarkdownToHTML,
|
||||||
const restoredTags = restoreCitationTags(mathSafe, tags)
|
sanitizeHtml: sanitizeMarkdownHTML,
|
||||||
const safeMarkdown = safeMarkdownToHTML(restoredTags)
|
})
|
||||||
const { content: mdWithPlaceholders, htmlSnippets } = extractCitationHtmlPlaceholders(safeMarkdown)
|
|
||||||
const html = marked.parse(mdWithPlaceholders, { renderer: customRenderer, breaks: true }) as string
|
|
||||||
const withCitations = restoreCitationHtmlPlaceholders(html, htmlSnippets)
|
|
||||||
return sanitizeHTML(withCitations)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const hasActualContent = computed(() => {
|
const hasActualContent = computed(() => {
|
||||||
@@ -186,7 +166,7 @@ const hydrateImages = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const renderMermaidDiagrams = async () => {
|
const renderMermaidDiagrams = async () => {
|
||||||
await renderMermaidInContainer(parentMd.value)
|
await enhanceMarkdownContainer(parentMd.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(renderedHTML, () => {
|
watch(renderedHTML, () => {
|
||||||
@@ -217,7 +197,8 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
@import '../../components/css/markdown.less';
|
@import '../../components/css/chat-markdown.less';
|
||||||
|
@import '../../components/css/chat-citations.less';
|
||||||
|
|
||||||
.embed-bot-msg {
|
.embed-bot-msg {
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
@@ -236,130 +217,21 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.content-wrapper {
|
.rag-answer-stack {
|
||||||
background: var(--td-bg-color-container);
|
display: flex;
|
||||||
border-radius: 6px;
|
flex-direction: column;
|
||||||
padding: 8px 0;
|
gap: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ai-markdown-template {
|
.content-wrapper {
|
||||||
font-size: 15px;
|
padding: 2px 0;
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-content {
|
.markdown-content {
|
||||||
:deep(p) {
|
// Chat Markdown visual styles are centralized in chat-markdown.less.
|
||||||
margin: 6px 0;
|
// Do not add element-level Markdown rules here; update the shared mixin.
|
||||||
line-height: 1.6;
|
.chat-markdown-typography();
|
||||||
}
|
.chat-citation-pills();
|
||||||
|
|
||||||
:deep(code) {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
padding: 2px 5px;
|
|
||||||
border-radius: 3px;
|
|
||||||
font-family: var(--app-font-family-mono);
|
|
||||||
font-size: 11px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(pre) {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
padding: 10px;
|
|
||||||
border-radius: 4px;
|
|
||||||
overflow-x: auto;
|
|
||||||
margin: 6px 0;
|
|
||||||
|
|
||||||
code {
|
|
||||||
background: none;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(ul),
|
|
||||||
:deep(ol) {
|
|
||||||
margin: 6px 0;
|
|
||||||
padding-left: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(li) {
|
|
||||||
margin: 3px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(blockquote) {
|
|
||||||
border-left: 2px solid var(--td-brand-color);
|
|
||||||
padding-left: 10px;
|
|
||||||
margin: 6px 0;
|
|
||||||
color: var(--td-text-color-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(h1),
|
|
||||||
:deep(h2),
|
|
||||||
:deep(h3),
|
|
||||||
:deep(h4),
|
|
||||||
:deep(h5),
|
|
||||||
:deep(h6) {
|
|
||||||
margin: 10px 0 6px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--td-text-color-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(a) {
|
|
||||||
color: var(--td-brand-color);
|
|
||||||
text-decoration: none;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(table) {
|
|
||||||
border-collapse: collapse;
|
|
||||||
margin: 6px 0;
|
|
||||||
font-size: 11px;
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
th,
|
|
||||||
td {
|
|
||||||
border: 1px solid var(--td-component-stroke);
|
|
||||||
padding: 5px 8px;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
tbody tr:nth-child(even) {
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(img) {
|
|
||||||
max-width: 80%;
|
|
||||||
max-height: 300px;
|
|
||||||
width: auto;
|
|
||||||
height: auto;
|
|
||||||
border-radius: 8px;
|
|
||||||
display: block;
|
|
||||||
margin: 8px 0;
|
|
||||||
border: 0.5px solid var(--td-component-stroke);
|
|
||||||
object-fit: contain;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.mermaid) {
|
|
||||||
margin: 16px 0;
|
|
||||||
padding: 16px;
|
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
|
||||||
border-radius: 8px;
|
|
||||||
overflow-x: auto;
|
|
||||||
text-align: center;
|
|
||||||
|
|
||||||
svg {
|
|
||||||
max-width: 100%;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-indicator {
|
.loading-indicator {
|
||||||
@@ -393,6 +265,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes typingBounce {
|
@keyframes typingBounce {
|
||||||
|
|
||||||
0%,
|
0%,
|
||||||
60%,
|
60%,
|
||||||
100% {
|
100% {
|
||||||
@@ -404,69 +277,6 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown-content {
|
|
||||||
:deep(.citation) {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 4px;
|
|
||||||
border-radius: 10px;
|
|
||||||
padding: 2px 4px;
|
|
||||||
font-size: 11px;
|
|
||||||
line-height: 1.4;
|
|
||||||
margin: 0 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.citation-web),
|
|
||||||
:deep(.citation-kb) {
|
|
||||||
background: color-mix(in srgb, var(--td-brand-color) 8%, transparent);
|
|
||||||
color: var(--td-brand-color);
|
|
||||||
border: 1px solid color-mix(in srgb, var(--td-brand-color) 20%, transparent);
|
|
||||||
cursor: pointer;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.citation-web:hover),
|
|
||||||
:deep(.citation-kb:hover) {
|
|
||||||
background: color-mix(in srgb, var(--td-brand-color) 12%, transparent);
|
|
||||||
border-color: var(--td-brand-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.citation .citation-icon) {
|
|
||||||
display: inline-block;
|
|
||||||
width: 14px;
|
|
||||||
height: 14px;
|
|
||||||
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;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.citation .citation-icon.web) {
|
|
||||||
mask-image: url('@/assets/img/websearch-globe.svg');
|
|
||||||
-webkit-mask-image: url('@/assets/img/websearch-globe.svg');
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.citation .citation-icon.kb) {
|
|
||||||
mask-image: url('@/assets/img/zhishiku.svg');
|
|
||||||
-webkit-mask-image: url('@/assets/img/zhishiku.svg');
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(.citation-tip) {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
:deep(a.wiki-content-link) {
|
|
||||||
color: var(--td-brand-color);
|
|
||||||
border-bottom: 1px dashed var(--td-brand-color);
|
|
||||||
text-decoration: none;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.embed-citation-float {
|
.embed-citation-float {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 10000;
|
z-index: 10000;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="loading" class="embed-chat__typing">
|
<div v-if="showGlobalTypingIndicator" class="embed-chat__typing">
|
||||||
<div class="loading-typing">
|
<div class="loading-typing">
|
||||||
<span></span>
|
<span></span>
|
||||||
<span></span>
|
<span></span>
|
||||||
@@ -179,6 +179,7 @@ const {
|
|||||||
scrollContainer,
|
scrollContainer,
|
||||||
userHasScrolledUp,
|
userHasScrolledUp,
|
||||||
shouldRenderAssistantMessage,
|
shouldRenderAssistantMessage,
|
||||||
|
shouldShowGlobalTypingIndicator,
|
||||||
getUserQuery,
|
getUserQuery,
|
||||||
handleScroll,
|
handleScroll,
|
||||||
scrollToBottom,
|
scrollToBottom,
|
||||||
@@ -209,6 +210,10 @@ const hasWelcomeText = computed(() => welcomeText.value.length > 0)
|
|||||||
const hasUserMessage = computed(() =>
|
const hasUserMessage = computed(() =>
|
||||||
messagesList.some((m) => m.role === 'user'))
|
messagesList.some((m) => m.role === 'user'))
|
||||||
|
|
||||||
|
const showGlobalTypingIndicator = computed(() =>
|
||||||
|
shouldShowGlobalTypingIndicator(messagesList, loading.value),
|
||||||
|
)
|
||||||
|
|
||||||
/** 访客未发言前始终展示欢迎语(含历史加载中),发送后隐藏 */
|
/** 访客未发言前始终展示欢迎语(含历史加载中),发送后隐藏 */
|
||||||
const showWelcome = computed(() => hasWelcomeText.value && !hasUserMessage.value)
|
const showWelcome = computed(() => hasWelcomeText.value && !hasUserMessage.value)
|
||||||
|
|
||||||
@@ -444,7 +449,7 @@ watch(
|
|||||||
width: 6px;
|
width: 6px;
|
||||||
height: 6px;
|
height: 6px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: var(--embed-primary, #0052d9);
|
background: var(--td-text-color-placeholder);
|
||||||
animation: typingBounce 1.4s ease-in-out infinite;
|
animation: typingBounce 1.4s ease-in-out infinite;
|
||||||
|
|
||||||
&:nth-child(1) { animation-delay: 0s; }
|
&:nth-child(1) { animation-delay: 0s; }
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="containerRef" class="embed-user-msg" :class="{ 'is-embedded': embeddedMode }">
|
<div ref="containerRef" class="embed-user-msg" :class="{ 'is-embedded': embeddedMode }">
|
||||||
<div v-if="hasImages" class="user_images">
|
<div v-if="hasImages" class="user_images">
|
||||||
<img
|
<img v-for="(img, idx) in displayImages" :key="idx" :src="img.url" class="user_image_thumb" alt=""
|
||||||
v-for="(img, idx) in displayImages"
|
@click="previewImage($event)" />
|
||||||
:key="idx"
|
|
||||||
:src="img.url"
|
|
||||||
class="user_image_thumb"
|
|
||||||
alt=""
|
|
||||||
@click="previewImage($event)"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div v-if="hasAttachments" class="user_attachments">
|
<div v-if="hasAttachments" class="user_attachments">
|
||||||
<div v-for="(att, idx) in attachments" :key="idx" class="user_attachment_card">
|
<div v-for="(att, idx) in attachments" :key="idx" class="user_attachment_card">
|
||||||
@@ -118,7 +112,7 @@ const formatFileSize = (bytes: number): string => {
|
|||||||
background: #8ce97f;
|
background: #8ce97f;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
color: #000000e6;
|
color: #000000e6;
|
||||||
font-size: 15px;
|
font-size: 16px;
|
||||||
text-align: justify;
|
text-align: justify;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|||||||
Reference in New Issue
Block a user