mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 17:09:20 +08:00
feat: aichat 改用 tdesign chat
This commit is contained in:
@@ -59,20 +59,28 @@ class OpenAICompatibleStreamer(ChatStreamer):
|
|||||||
yield text
|
yield text
|
||||||
return
|
return
|
||||||
|
|
||||||
# 工具轮:先非流式执行 tool_calls,最后一轮流式输出正文
|
# 工具轮:每轮用 astream 边生成边推 token;出现 tool_call 再执行工具后继续
|
||||||
bound = model.bind_tools(tools)
|
bound = model.bind_tools(tools)
|
||||||
tool_map = {t.name: t for t in tools if getattr(t, "name", None)}
|
tool_map = {t.name: t for t in tools if getattr(t, "name", None)}
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
ai = await bound.ainvoke(messages)
|
gathered = None
|
||||||
messages.append(ai)
|
saw_tool = False
|
||||||
tool_calls = getattr(ai, "tool_calls", None) or []
|
async for chunk in bound.astream(messages):
|
||||||
|
gathered = chunk if gathered is None else gathered + chunk
|
||||||
|
if getattr(chunk, "tool_call_chunks", None) or getattr(chunk, "tool_calls", None):
|
||||||
|
saw_tool = True
|
||||||
|
continue
|
||||||
|
if saw_tool:
|
||||||
|
continue
|
||||||
|
text = _chunk_text(getattr(chunk, "content", None))
|
||||||
|
if text:
|
||||||
|
yield text
|
||||||
|
if gathered is None:
|
||||||
|
yield "(模型未返回内容)"
|
||||||
|
return
|
||||||
|
messages.append(gathered)
|
||||||
|
tool_calls = getattr(gathered, "tool_calls", None) or []
|
||||||
if not tool_calls:
|
if not tool_calls:
|
||||||
content = ai.content if isinstance(ai.content, str) else _chunk_text(ai.content)
|
|
||||||
if content:
|
|
||||||
# 按小段 yield,便于前端渐进展示
|
|
||||||
step = 24
|
|
||||||
for i in range(0, len(content), step):
|
|
||||||
yield content[i : i + step]
|
|
||||||
return
|
return
|
||||||
|
|
||||||
yield f"\n[调用工具: {', '.join(tc.get('name', '?') for tc in tool_calls)}]\n"
|
yield f"\n[调用工具: {', '.join(tc.get('name', '?') for tc in tool_calls)}]\n"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"#/*": "./src/*"
|
"#/*": "./src/*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@tdesign-vue-next/chat": "^0.7.0",
|
||||||
"@vben/access": "workspace:*",
|
"@vben/access": "workspace:*",
|
||||||
"@vben/common-ui": "workspace:*",
|
"@vben/common-ui": "workspace:*",
|
||||||
"@vben/constants": "workspace:*",
|
"@vben/constants": "workspace:*",
|
||||||
@@ -42,20 +43,16 @@
|
|||||||
"@vben/utils": "workspace:*",
|
"@vben/utils": "workspace:*",
|
||||||
"@vueuse/core": "catalog:",
|
"@vueuse/core": "catalog:",
|
||||||
"ant-design-vue": "catalog:",
|
"ant-design-vue": "catalog:",
|
||||||
"ant-design-x-vue": "^1.6.0",
|
|
||||||
"dayjs": "catalog:",
|
"dayjs": "catalog:",
|
||||||
"dompurify": "^3.4.15",
|
|
||||||
"marked": "^18.0.13",
|
|
||||||
"papaparse": "^5.4.1",
|
"papaparse": "^5.4.1",
|
||||||
"pinia": "catalog:",
|
"pinia": "catalog:",
|
||||||
"spark-md5": "^3.0.2",
|
"spark-md5": "^3.0.2",
|
||||||
|
"tdesign-vue-next": "^1.20.8",
|
||||||
"vue": "catalog:",
|
"vue": "catalog:",
|
||||||
"vue-router": "catalog:",
|
"vue-router": "catalog:",
|
||||||
"vue-waterfall-plugin-next": "^3.0.0"
|
"vue-waterfall-plugin-next": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/dompurify": "^3.2.0",
|
|
||||||
"@types/marked": "^6.0.0",
|
|
||||||
"@types/papaparse": "^5.3.14",
|
"@types/papaparse": "^5.3.14",
|
||||||
"@types/spark-md5": "^3.0.5"
|
"@types/spark-md5": "^3.0.5"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,8 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type {
|
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||||
BubbleListProps,
|
|
||||||
BubbleProps,
|
|
||||||
Conversation,
|
|
||||||
} from 'ant-design-x-vue';
|
|
||||||
|
|
||||||
import { computed, h, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import {
|
import { PlusOutlined, SettingOutlined } from '@ant-design/icons-vue';
|
||||||
PlusOutlined,
|
|
||||||
RobotOutlined,
|
|
||||||
SettingOutlined,
|
|
||||||
UserOutlined,
|
|
||||||
} from '@ant-design/icons-vue';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -26,7 +15,9 @@ import {
|
|||||||
Spin,
|
Spin,
|
||||||
message,
|
message,
|
||||||
} from 'ant-design-vue';
|
} from 'ant-design-vue';
|
||||||
import { BubbleList, Conversations, Sender } from 'ant-design-x-vue';
|
import { ChatItem, ChatSender } from '@tdesign-vue-next/chat';
|
||||||
|
import 'tdesign-vue-next/es/style/index.css';
|
||||||
|
import '@tdesign-vue-next/chat/es/style/index.css';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createAgentSessionApi,
|
createAgentSessionApi,
|
||||||
@@ -40,10 +31,17 @@ import {
|
|||||||
updateAgentLlmSettingsApi,
|
updateAgentLlmSettingsApi,
|
||||||
} from '#/api/agent';
|
} from '#/api/agent';
|
||||||
|
|
||||||
import { renderAgentMarkdown } from './markdown';
|
|
||||||
|
|
||||||
defineOptions({ name: 'AgentChat' });
|
defineOptions({ name: 'AgentChat' });
|
||||||
|
|
||||||
|
/** 消息气泡视图模型(走 Vue ChatItem,避免 ChatList→WebComponent 丢正文) */
|
||||||
|
type BubbleView = {
|
||||||
|
id: string;
|
||||||
|
role: 'user' | 'assistant';
|
||||||
|
name: string;
|
||||||
|
content: string;
|
||||||
|
textLoading: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
const loadingSessions = ref(false);
|
const loadingSessions = ref(false);
|
||||||
const loadingMessages = ref(false);
|
const loadingMessages = ref(false);
|
||||||
const sending = ref(false);
|
const sending = ref(false);
|
||||||
@@ -63,12 +61,7 @@ const llmForm = ref({
|
|||||||
apiKeyMasked: '' as string | null,
|
apiKeyMasked: '' as string | null,
|
||||||
configured: false,
|
configured: false,
|
||||||
});
|
});
|
||||||
const bubbleListRef = ref<{
|
const messagePaneRef = ref<HTMLElement | null>(null);
|
||||||
scrollTo?: (info: {
|
|
||||||
key?: string | number;
|
|
||||||
block?: ScrollLogicalPosition;
|
|
||||||
}) => void;
|
|
||||||
} | null>(null);
|
|
||||||
let abort: AbortController | null = null;
|
let abort: AbortController | null = null;
|
||||||
let messagesLoadSeq = 0;
|
let messagesLoadSeq = 0;
|
||||||
|
|
||||||
@@ -80,79 +73,38 @@ const showMessageLoading = computed(
|
|||||||
() => loadingMessages.value && !sending.value && messages.value.length === 0,
|
() => loadingMessages.value && !sending.value && messages.value.length === 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderAssistantMarkdown: BubbleProps['messageRender'] = (content) => {
|
const bubbleViews = computed<BubbleView[]>(() =>
|
||||||
const html = renderAgentMarkdown(String(content ?? ''));
|
|
||||||
return h('div', { class: 'agent-md', innerHTML: html || '…' });
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Bubble.List 角色预设:SSE 已流式输出,关闭组件自带 typing 动画 */
|
|
||||||
const bubbleRoles: BubbleListProps['roles'] = {
|
|
||||||
assistant: {
|
|
||||||
placement: 'start',
|
|
||||||
variant: 'filled',
|
|
||||||
avatar: {
|
|
||||||
icon: h(RobotOutlined),
|
|
||||||
style: { background: '#1677ff', color: '#fff' },
|
|
||||||
},
|
|
||||||
messageRender: renderAssistantMarkdown,
|
|
||||||
styles: { content: { maxWidth: 'min(720px, 85%)' } },
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
placement: 'end',
|
|
||||||
variant: 'filled',
|
|
||||||
avatar: {
|
|
||||||
icon: h(UserOutlined),
|
|
||||||
style: { background: '#87d068', color: '#fff' },
|
|
||||||
},
|
|
||||||
styles: { content: { maxWidth: 'min(720px, 85%)' } },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const bubbleItems = computed<BubbleListProps['items']>(() =>
|
|
||||||
messages.value.map((m, idx) => {
|
messages.value.map((m, idx) => {
|
||||||
const isStreamingAssistant =
|
const isStreamingAssistant =
|
||||||
sending.value &&
|
sending.value &&
|
||||||
idx === messages.value.length - 1 &&
|
idx === messages.value.length - 1 &&
|
||||||
m.role === 'assistant';
|
m.role === 'assistant';
|
||||||
const content = isStreamingAssistant
|
const text = isStreamingAssistant
|
||||||
? streamingText.value || m.content || ''
|
? streamingText.value || m.content || ''
|
||||||
: m.content || '';
|
: m.content || '';
|
||||||
const role = m.role === 'user' ? 'user' : 'assistant';
|
const role = m.role === 'user' ? 'user' : 'assistant';
|
||||||
return {
|
return {
|
||||||
key: m.id || `${m.seq}-${idx}`,
|
id: m.id || `${m.seq}-${idx}`,
|
||||||
role,
|
role,
|
||||||
content,
|
name: role === 'user' ? '我' : '智能助手',
|
||||||
loading: isStreamingAssistant && !content,
|
content: text,
|
||||||
|
textLoading: isStreamingAssistant && !text,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
/** 侧栏会话列表:映射为 Conversations items(label 用字符串,避免 Typography ellipsis+children 告警) */
|
function scrollChatToBottom() {
|
||||||
const conversationItems = computed<Conversation[]>(() =>
|
const el = messagePaneRef.value;
|
||||||
sessions.value.map((s) => {
|
if (!el) return;
|
||||||
const ts = s.updatedAt || s.lastMessageAt || s.createdAt;
|
el.scrollTop = el.scrollHeight;
|
||||||
const timeMs = ts ? Date.parse(ts) : undefined;
|
}
|
||||||
return {
|
|
||||||
key: s.threadId,
|
|
||||||
label: s.title || '新对话',
|
|
||||||
timestamp: Number.isFinite(timeMs) ? timeMs : undefined,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
function onConversationActiveChange(key: string) {
|
function onSessionClick(threadId: string) {
|
||||||
if (sending.value) {
|
if (sending.value) {
|
||||||
message.warning('回复生成中,请稍候再切换会话');
|
message.warning('回复生成中,请稍候再切换会话');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
activeThreadId.value = key;
|
activeThreadId.value = threadId;
|
||||||
}
|
|
||||||
|
|
||||||
function scrollBubblesToBottom() {
|
|
||||||
const items = bubbleItems.value || [];
|
|
||||||
const last = items[items.length - 1];
|
|
||||||
if (last?.key == null) return;
|
|
||||||
bubbleListRef.value?.scrollTo?.({ key: last.key, block: 'end' });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshSessions() {
|
async function refreshSessions() {
|
||||||
@@ -185,7 +137,7 @@ async function loadMessages(threadId: string) {
|
|||||||
messages.value = res.items || [];
|
messages.value = res.items || [];
|
||||||
streamingText.value = '';
|
streamingText.value = '';
|
||||||
await nextTick();
|
await nextTick();
|
||||||
scrollBubblesToBottom();
|
scrollChatToBottom();
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (seq === messagesLoadSeq && !sending.value) {
|
if (seq === messagesLoadSeq && !sending.value) {
|
||||||
message.error(e?.message || '加载消息失败');
|
message.error(e?.message || '加载消息失败');
|
||||||
@@ -281,7 +233,7 @@ function appendStreamToken(t: string) {
|
|||||||
if (last?.role === 'assistant') {
|
if (last?.role === 'assistant') {
|
||||||
messages.value[idx] = { ...last, content: streamingText.value };
|
messages.value[idx] = { ...last, content: streamingText.value };
|
||||||
}
|
}
|
||||||
void nextTick().then(scrollBubblesToBottom);
|
void nextTick().then(scrollChatToBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function send(textOverride?: string) {
|
async function send(textOverride?: string) {
|
||||||
@@ -309,7 +261,7 @@ async function send(textOverride?: string) {
|
|||||||
content: '',
|
content: '',
|
||||||
});
|
});
|
||||||
await nextTick();
|
await nextTick();
|
||||||
scrollBubblesToBottom();
|
scrollChatToBottom();
|
||||||
|
|
||||||
abort?.abort();
|
abort?.abort();
|
||||||
abort = streamAgentChat({
|
abort = streamAgentChat({
|
||||||
@@ -340,11 +292,11 @@ async function send(textOverride?: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSenderSubmit(msg: string) {
|
function onSenderSend(value: string) {
|
||||||
void send(msg);
|
void send(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSenderCancel() {
|
function onSenderStop() {
|
||||||
abort?.abort();
|
abort?.abort();
|
||||||
sending.value = false;
|
sending.value = false;
|
||||||
}
|
}
|
||||||
@@ -374,17 +326,32 @@ void refreshSessions();
|
|||||||
<Spin size="small" />
|
<Spin size="small" />
|
||||||
</div>
|
</div>
|
||||||
<Empty
|
<Empty
|
||||||
v-if="!loadingSessions && conversationItems.length === 0"
|
v-if="!loadingSessions && sessions.length === 0"
|
||||||
class="mt-10 px-2"
|
class="mt-10 px-2"
|
||||||
description="暂无会话"
|
description="暂无会话"
|
||||||
/>
|
/>
|
||||||
<Conversations
|
<div v-else class="h-full space-y-1 overflow-y-auto px-3 py-2">
|
||||||
v-else
|
<button
|
||||||
class="agent-conversations h-full overflow-y-auto px-3 py-2"
|
v-for="s in sessions"
|
||||||
:items="conversationItems"
|
:key="s.threadId"
|
||||||
:active-key="activeThreadId ?? undefined"
|
type="button"
|
||||||
@active-change="onConversationActiveChange"
|
class="w-full rounded-lg px-3 py-2 text-left text-sm transition-colors"
|
||||||
/>
|
:class="
|
||||||
|
s.threadId === activeThreadId
|
||||||
|
? 'bg-primary/10 text-primary'
|
||||||
|
: 'hover:bg-muted text-foreground'
|
||||||
|
"
|
||||||
|
@click="onSessionClick(s.threadId)"
|
||||||
|
>
|
||||||
|
<div class="truncate font-medium">{{ s.title || '新对话' }}</div>
|
||||||
|
<div
|
||||||
|
v-if="s.updatedAt || s.lastMessageAt"
|
||||||
|
class="text-muted-foreground mt-0.5 truncate text-xs"
|
||||||
|
>
|
||||||
|
{{ s.updatedAt || s.lastMessageAt }}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="border-t border-border p-3">
|
<div class="border-t border-border p-3">
|
||||||
<Button block @click="openSettings">
|
<Button block @click="openSettings">
|
||||||
@@ -394,7 +361,7 @@ void refreshSessions();
|
|||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<section class="flex min-h-0 min-w-0 flex-1 flex-col">
|
<section class="agent-chat-main flex min-h-0 min-w-0 flex-1 flex-col">
|
||||||
<header
|
<header
|
||||||
class="flex h-12 shrink-0 items-center border-b border-border px-4"
|
class="flex h-12 shrink-0 items-center border-b border-border px-4"
|
||||||
>
|
>
|
||||||
@@ -403,7 +370,7 @@ void refreshSessions();
|
|||||||
</span>
|
</span>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="relative min-h-0 flex-1">
|
<div class="relative flex min-h-0 flex-1 flex-col">
|
||||||
<div
|
<div
|
||||||
v-if="showMessageLoading"
|
v-if="showMessageLoading"
|
||||||
class="text-muted-foreground absolute inset-0 z-10 flex items-center justify-center bg-background/60 text-sm"
|
class="text-muted-foreground absolute inset-0 z-10 flex items-center justify-center bg-background/60 text-sm"
|
||||||
@@ -415,27 +382,34 @@ void refreshSessions();
|
|||||||
class="absolute inset-0 flex items-center justify-center"
|
class="absolute inset-0 flex items-center justify-center"
|
||||||
description="开始提问吧(需先配置公司模型 API)"
|
description="开始提问吧(需先配置公司模型 API)"
|
||||||
/>
|
/>
|
||||||
<BubbleList
|
<div
|
||||||
v-show="messages.length > 0"
|
ref="messagePaneRef"
|
||||||
ref="bubbleListRef"
|
class="agent-td-chat t-chat t-chat--normal min-h-0 flex-1 overflow-y-auto py-4"
|
||||||
class="h-full px-4 py-4"
|
>
|
||||||
:roles="bubbleRoles"
|
<ChatItem
|
||||||
:items="bubbleItems"
|
v-for="item in bubbleViews"
|
||||||
:auto-scroll="true"
|
:key="item.id"
|
||||||
|
class="agent-td-item"
|
||||||
|
:role="item.role"
|
||||||
|
:name="item.name"
|
||||||
|
:content="item.content"
|
||||||
|
:text-loading="item.textLoading"
|
||||||
|
variant="base"
|
||||||
|
animation="gradient"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="shrink-0 border-t border-border p-3">
|
||||||
<footer class="shrink-0 border-t border-border p-3">
|
<ChatSender
|
||||||
<Sender
|
v-model="draft"
|
||||||
v-model:value="draft"
|
class="agent-td-sender"
|
||||||
:loading="sending"
|
:loading="sending"
|
||||||
placeholder="输入问题,Enter 发送(Shift+Enter 换行)"
|
placeholder="输入问题,Enter 发送"
|
||||||
:auto-size="{ minRows: 2, maxRows: 6 }"
|
:textarea-props="{ autosize: { minRows: 2, maxRows: 6 } }"
|
||||||
submit-type="enter"
|
@send="onSenderSend"
|
||||||
@submit="onSenderSubmit"
|
@stop="onSenderStop"
|
||||||
@cancel="onSenderCancel"
|
|
||||||
/>
|
/>
|
||||||
</footer>
|
</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -499,57 +473,26 @@ void refreshSessions();
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.agent-conversations :deep(.ant-conversations-list) {
|
.agent-td-chat {
|
||||||
padding-inline: 0;
|
--td-bg-color-container: transparent;
|
||||||
|
padding-inline: 28px;
|
||||||
}
|
}
|
||||||
.agent-md :deep(p) {
|
.agent-td-item {
|
||||||
margin: 0.35em 0;
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
.agent-md :deep(p:first-child) {
|
/* 气泡按内容收缩,左右再留一截,避免贴边铺满 */
|
||||||
margin-top: 0;
|
.agent-td-item :deep(.t-chat__inner) {
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding-inline: 4px;
|
||||||
}
|
}
|
||||||
.agent-md :deep(p:last-child) {
|
.agent-td-item :deep(.t-chat__content) {
|
||||||
margin-bottom: 0;
|
width: auto;
|
||||||
|
max-width: min(720px, calc(100% - 32px));
|
||||||
}
|
}
|
||||||
.agent-md :deep(ul),
|
.agent-td-item :deep(.t-chat__inner.user) {
|
||||||
.agent-md :deep(ol) {
|
justify-content: flex-end;
|
||||||
margin: 0.35em 0;
|
|
||||||
padding-left: 1.25em;
|
|
||||||
}
|
}
|
||||||
.agent-md :deep(pre) {
|
.agent-td-sender {
|
||||||
margin: 0.5em 0;
|
width: 100%;
|
||||||
overflow-x: auto;
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
background: rgba(0, 0, 0, 0.06);
|
|
||||||
padding: 0.6em 0.75em;
|
|
||||||
font-size: 0.85em;
|
|
||||||
}
|
|
||||||
.agent-md :deep(code) {
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
||||||
font-size: 0.9em;
|
|
||||||
}
|
|
||||||
.agent-md :deep(:not(pre) > code) {
|
|
||||||
border-radius: 0.25rem;
|
|
||||||
background: rgba(0, 0, 0, 0.06);
|
|
||||||
padding: 0.1em 0.35em;
|
|
||||||
}
|
|
||||||
.agent-md :deep(a) {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
.agent-md :deep(blockquote) {
|
|
||||||
margin: 0.4em 0;
|
|
||||||
border-left: 3px solid rgba(0, 0, 0, 0.2);
|
|
||||||
padding-left: 0.75em;
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.agent-md :deep(table) {
|
|
||||||
margin: 0.5em 0;
|
|
||||||
border-collapse: collapse;
|
|
||||||
font-size: 0.9em;
|
|
||||||
}
|
|
||||||
.agent-md :deep(th),
|
|
||||||
.agent-md :deep(td) {
|
|
||||||
border: 1px solid rgba(0, 0, 0, 0.12);
|
|
||||||
padding: 0.25em 0.5em;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
/** 轻量 Markdown → 安全 HTML(流式场景下未闭合围栏也能尽量渲染)。 */
|
|
||||||
import DOMPurify from 'dompurify';
|
|
||||||
import { marked } from 'marked';
|
|
||||||
|
|
||||||
marked.setOptions({
|
|
||||||
gfm: true,
|
|
||||||
breaks: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
export function renderAgentMarkdown(source: string): string {
|
|
||||||
const raw = source || '';
|
|
||||||
if (!raw.trim()) return '';
|
|
||||||
try {
|
|
||||||
const html = marked.parse(raw, { async: false }) as string;
|
|
||||||
return DOMPurify.sanitize(html, {
|
|
||||||
USE_PROFILES: { html: true },
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
return DOMPurify.sanitize(raw.replace(/</g, '<').replace(/>/g, '>'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
diff --git a/es/conversations/ConversationsItem.mjs b/es/conversations/ConversationsItem.mjs
|
|
||||||
index 7245467416f4bff50d882a1cc4b0e6085150d507..45ccd67847af10d4706e476e6d2682aac1b13a16 100644
|
|
||||||
--- a/es/conversations/ConversationsItem.mjs
|
|
||||||
+++ b/es/conversations/ConversationsItem.mjs
|
|
||||||
@@ -84,14 +84,18 @@ const j = /* @__PURE__ */ h({
|
|
||||||
onClick: x
|
|
||||||
}), [e.info.icon && n("div", {
|
|
||||||
class: `${e.prefixCls}-icon`
|
|
||||||
- }, [e.info.icon]), n(M.Text, {
|
|
||||||
- class: `${e.prefixCls}-label`,
|
|
||||||
- ellipsis: {
|
|
||||||
- onEllipsis: v
|
|
||||||
- }
|
|
||||||
- }, {
|
|
||||||
- default: () => [e.info.label]
|
|
||||||
- }), !o.value && e.menu && n(N, {
|
|
||||||
+ }, [e.info.icon]), (() => {
|
|
||||||
+ const A = e.info.label, S = typeof A == "string" || typeof A == "number";
|
|
||||||
+ return n(M.Text, {
|
|
||||||
+ class: `${e.prefixCls}-label`,
|
|
||||||
+ content: S ? A : void 0,
|
|
||||||
+ ellipsis: {
|
|
||||||
+ onEllipsis: v
|
|
||||||
+ }
|
|
||||||
+ }, S ? void 0 : {
|
|
||||||
+ default: () => [A]
|
|
||||||
+ });
|
|
||||||
+ })(), !o.value && e.menu && n(N, {
|
|
||||||
placement: e.direction === "rtl" ? "bottomLeft" : "bottomRight",
|
|
||||||
trigger: ["click"],
|
|
||||||
disabled: o.value,
|
|
||||||
diff --git a/lib/conversations/ConversationsItem.js b/lib/conversations/ConversationsItem.js
|
|
||||||
index ded16c252b0d9b4c5fe8bdb98bad0366f77ebe2c..582665631e71ac65215803f616b74d0d88bfd869 100644
|
|
||||||
--- a/lib/conversations/ConversationsItem.js
|
|
||||||
+++ b/lib/conversations/ConversationsItem.js
|
|
||||||
@@ -1 +1 @@
|
|
||||||
-"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),d=require("../chunks/helper-chunk.js"),s=require("../chunks/module-chunk.js"),P=require("../_util/pick-attrs.js"),a=require("ant-design-vue"),c=require("../_util/hooks/use-state.js"),N=t.defineComponent({name:"AXConversationsItem",__name:"ConversationsItem",props:{info:{type:Object,required:!0},prefixCls:{type:String,required:!1},direction:{required:!1},menu:{type:Object,required:!1},active:{type:Boolean,required:!1},onClick:{type:Function,required:!1}},setup(e,{expose:f}){f();const g=d.createPropsRestProxy(e,["prefixCls","info","class","direction","onClick","active","menu"]);t.toRef(e,"class");const m=t.computed(()=>P.default(g,{aria:!0,data:!0,attr:!0})),v=n=>{n.stopPropagation()},i=t.computed(()=>e.info.disabled),[C,p]=c.default(!1),[b,r]=c.default(!1),x=t.computed(()=>s.classnames(e.class,`${e.prefixCls}-item`,{[`${e.prefixCls}-item-active`]:e.active&&!i.value},{[`${e.prefixCls}-item-disabled`]:i.value})),h=()=>{!i.value&&e.onClick&&e.onClick(e.info)},k=n=>{n&&r(!n)},o=t.computed(()=>{var n;return(n=e.menu)==null?void 0:n.trigger}),u=t.computed(()=>{const{trigger:n,...l}=e.menu||{};return l}),q=t.computed(()=>{var n;return(n=u.value)==null?void 0:n.getPopupContainer}),y=n=>{const l=t.createVNode(s.EllipsisOutlined,{onClick:v,class:`${e.prefixCls}-menu-icon`},null);return o.value?typeof o.value=="function"?o.value(n,{originNode:l}):o.value:l};return()=>t.createVNode(a.Tooltip,{title:e.info.label,open:C.value&&b.value,onOpenChange:r,placement:e.direction==="rtl"?"left":"right"},{default:()=>[t.createVNode("li",t.mergeProps(m.value,{class:x.value,onClick:h}),[e.info.icon&&t.createVNode("div",{class:`${e.prefixCls}-icon`},[e.info.icon]),t.createVNode(a.Typography.Text,{class:`${e.prefixCls}-label`,ellipsis:{onEllipsis:p}},{default:()=>[e.info.label]}),!i.value&&e.menu&&t.createVNode(a.Dropdown,{placement:e.direction==="rtl"?"bottomLeft":"bottomRight",trigger:["click"],disabled:i.value,onOpenChange:k,getPopupContainer:q.value},{default:()=>y(e.info),overlay:()=>t.createVNode(a.Menu,u.value,null)})])]})}}),O=d._export_sfc(N,[["__file","/Users/wangzhichao/办公/code/github/ant-design-x-vue-pure/ant-design-x-vue/src/conversations/ConversationsItem.vue"]]);exports.default=O;
|
|
||||||
+"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),d=require("../chunks/helper-chunk.js"),s=require("../chunks/module-chunk.js"),P=require("../_util/pick-attrs.js"),a=require("ant-design-vue"),c=require("../_util/hooks/use-state.js"),N=t.defineComponent({name:"AXConversationsItem",__name:"ConversationsItem",props:{info:{type:Object,required:!0},prefixCls:{type:String,required:!1},direction:{required:!1},menu:{type:Object,required:!1},active:{type:Boolean,required:!1},onClick:{type:Function,required:!1}},setup(e,{expose:f}){f();const g=d.createPropsRestProxy(e,["prefixCls","info","class","direction","onClick","active","menu"]);t.toRef(e,"class");const m=t.computed(()=>P.default(g,{aria:!0,data:!0,attr:!0})),v=n=>{n.stopPropagation()},i=t.computed(()=>e.info.disabled),[C,p]=c.default(!1),[b,r]=c.default(!1),x=t.computed(()=>s.classnames(e.class,`${e.prefixCls}-item`,{[`${e.prefixCls}-item-active`]:e.active&&!i.value},{[`${e.prefixCls}-item-disabled`]:i.value})),h=()=>{!i.value&&e.onClick&&e.onClick(e.info)},k=n=>{n&&r(!n)},o=t.computed(()=>{var n;return(n=e.menu)==null?void 0:n.trigger}),u=t.computed(()=>{const{trigger:n,...l}=e.menu||{};return l}),q=t.computed(()=>{var n;return(n=u.value)==null?void 0:n.getPopupContainer}),y=n=>{const l=t.createVNode(s.EllipsisOutlined,{onClick:v,class:`${e.prefixCls}-menu-icon`},null);return o.value?typeof o.value=="function"?o.value(n,{originNode:l}):o.value:l};return()=>t.createVNode(a.Tooltip,{title:e.info.label,open:C.value&&b.value,onOpenChange:r,placement:e.direction==="rtl"?"left":"right"},{default:()=>[t.createVNode("li",t.mergeProps(m.value,{class:x.value,onClick:h}),[e.info.icon&&t.createVNode("div",{class:`${e.prefixCls}-icon`},[e.info.icon]),((A)=>{const S=typeof A=="string"||typeof A=="number";return t.createVNode(a.Typography.Text,{class:`${e.prefixCls}-label`,content:S?A:void 0,ellipsis:{onEllipsis:p}},S?void 0:{default:()=>[A]})})(e.info.label),!i.value&&e.menu&&t.createVNode(a.Dropdown,{placement:e.direction==="rtl"?"bottomLeft":"bottomRight",trigger:["click"],disabled:i.value,onOpenChange:k,getPopupContainer:q.value},{default:()=>y(e.info),overlay:()=>t.createVNode(a.Menu,u.value,null)})])]})}}),O=d._export_sfc(N,[["__file","/Users/wangzhichao/办公/code/github/ant-design-x-vue-pure/ant-design-x-vue/src/conversations/ConversationsItem.vue"]]);exports.default=O;
|
|
||||||
Generated
+1660
-74
File diff suppressed because it is too large
Load Diff
@@ -13,10 +13,6 @@ packages:
|
|||||||
- docs
|
- docs
|
||||||
- playground
|
- playground
|
||||||
|
|
||||||
# ConversationsItem:Typography ellipsis 改用 content,消除 ant-design-vue 控制台告警
|
|
||||||
patchedDependencies:
|
|
||||||
ant-design-x-vue@1.6.0: patches/ant-design-x-vue@1.6.0.patch
|
|
||||||
|
|
||||||
catalog:
|
catalog:
|
||||||
'@ast-grep/napi': ^0.37.0
|
'@ast-grep/napi': ^0.37.0
|
||||||
'@changesets/changelog-github': ^0.5.1
|
'@changesets/changelog-github': ^0.5.1
|
||||||
|
|||||||
Reference in New Issue
Block a user