feat: 对话功能开发
This commit is contained in:
@@ -22,21 +22,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- 文本内容 -->
|
<!-- 文本内容 -->
|
||||||
<MarkdownRender v-if="msg.text" :content="msg.text"></MarkdownRender>
|
<MarkdownRender v-if="msg.text" :content="msg.text"></MarkdownRender>
|
||||||
<!-- question 类型 part 展示 -->
|
|
||||||
<template v-if="msg.parts">
|
|
||||||
<div v-for="(p, idx) in msg.parts.filter((p) => p.type === 'question')" :key="'question-' + idx" class="question-part">
|
|
||||||
<div v-for="(q, qi) in p.questions" :key="qi" class="question-item">
|
|
||||||
<div class="question-header">{{ q.header }}</div>
|
|
||||||
<div class="question-text">{{ q.question }}</div>
|
|
||||||
<div class="question-options">
|
|
||||||
<div v-for="(opt, oi) in q.options" :key="oi" class="question-option" @click="sendAnswer(p.id, opt.label)">
|
|
||||||
<span class="option-label">{{ opt.label }}</span>
|
|
||||||
<span v-if="opt.description" class="option-desc">{{ opt.description }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<!-- tool 类型 part 展示 -->
|
<!-- tool 类型 part 展示 -->
|
||||||
<template v-if="msg.parts">
|
<template v-if="msg.parts">
|
||||||
<template v-for="(p, idx) in msg.parts.filter((p) => p.type === 'tool')" :key="'tool-' + idx">
|
<template v-for="(p, idx) in msg.parts.filter((p) => p.type === 'tool')" :key="'tool-' + idx">
|
||||||
@@ -145,7 +130,6 @@ const hasActiveQuestion = computed(() => {
|
|||||||
if (!msg.parts) continue;
|
if (!msg.parts) continue;
|
||||||
for (const p of msg.parts) {
|
for (const p of msg.parts) {
|
||||||
if (p.type === 'tool' && p.tool === 'question' && p.state?.status === 'running' && p._questionId) return true;
|
if (p.type === 'tool' && p.tool === 'question' && p.state?.status === 'running' && p._questionId) return true;
|
||||||
if (p.type === 'question') return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -327,13 +311,7 @@ function registerSSEListeners() {
|
|||||||
const msgId = props.tool?.messageID;
|
const msgId = props.tool?.messageID;
|
||||||
const callId = props.tool?.callID;
|
const callId = props.tool?.callID;
|
||||||
if (!msgId) return;
|
if (!msgId) return;
|
||||||
// 将 question 作为一个 part 插入对应消息
|
// 将 question id 关联到对应的 tool part(通过 callID 匹配)
|
||||||
upsertAssistantPart(msgId, {
|
|
||||||
id: props.id,
|
|
||||||
type: 'question',
|
|
||||||
questions: props.questions || [],
|
|
||||||
});
|
|
||||||
// 同时将 question id 关联到对应的 tool part(通过 callID 匹配)
|
|
||||||
if (callId) {
|
if (callId) {
|
||||||
const msg = messages.value.find((m) => m.id === msgId);
|
const msg = messages.value.find((m) => m.id === msgId);
|
||||||
if (msg && msg.parts) {
|
if (msg && msg.parts) {
|
||||||
@@ -361,9 +339,16 @@ function unregisterSSEListeners() {
|
|||||||
|
|
||||||
async function sendAnswer(questionId, label) {
|
async function sendAnswer(questionId, label) {
|
||||||
if (!currentSessionId.value) return;
|
if (!currentSessionId.value) return;
|
||||||
messages.value.push({ id: Date.now(), role: 'user', text: label });
|
|
||||||
isSending.value = true;
|
isSending.value = true;
|
||||||
scrollToBottom();
|
// 将对应 tool part 标记为已回答,使输入框在等待响应期间可见
|
||||||
|
for (const msg of messages.value) {
|
||||||
|
if (!msg.parts) continue;
|
||||||
|
for (const p of msg.parts) {
|
||||||
|
if (p.type === 'tool' && p.tool === 'question' && p._questionId === questionId) {
|
||||||
|
if (p.state) p.state.status = 'answered';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const baseUrl = window.__opencodeBaseUrl || 'http://127.0.0.1:4096';
|
const baseUrl = window.__opencodeBaseUrl || 'http://127.0.0.1:4096';
|
||||||
await axios.post(`${baseUrl}/question/${questionId}/reply`, { answers: [[label]] });
|
await axios.post(`${baseUrl}/question/${questionId}/reply`, { answers: [[label]] });
|
||||||
@@ -468,19 +453,23 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
.bubble {
|
.bubble {
|
||||||
max-width: 75%;
|
max-width: 75%;
|
||||||
|
min-width: 48px;
|
||||||
padding: 10px 14px;
|
padding: 10px 14px;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bubble-wrap.user .bubble {
|
.bubble-wrap.user .bubble {
|
||||||
|
width: fit-content;
|
||||||
background: #409eff;
|
background: #409eff;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
border-bottom-right-radius: 4px;
|
border-bottom-right-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bubble-wrap.assistant .bubble {
|
.bubble-wrap.assistant .bubble {
|
||||||
|
width: 75%;
|
||||||
background: #f0f2f5;
|
background: #f0f2f5;
|
||||||
color: #303133;
|
color: #303133;
|
||||||
border-bottom-left-radius: 4px;
|
border-bottom-left-radius: 4px;
|
||||||
|
|||||||
@@ -45,22 +45,33 @@
|
|||||||
<textarea
|
<textarea
|
||||||
v-model="inputText"
|
v-model="inputText"
|
||||||
class="input-textarea"
|
class="input-textarea"
|
||||||
placeholder="描述任务,/ 调用技能与工具,@调用知识库"
|
placeholder="输入 / 调用技能,输入 @ 调用知识库"
|
||||||
:disabled="isCreating"
|
:disabled="isCreating"
|
||||||
@keydown="handleKeydown"
|
@keydown="handleKeydown"
|
||||||
|
@input="autoResize"
|
||||||
|
ref="textareaRef"
|
||||||
></textarea>
|
></textarea>
|
||||||
<div class="input-toolbar">
|
<div class="input-toolbar">
|
||||||
<div class="toolbar-left">
|
<div class="toolbar-left">
|
||||||
<button class="toolbar-btn file-btn">
|
<button class="dir-btn">
|
||||||
<el-icon><Plus /></el-icon>
|
<LucideIcon name="folder-input" size="16"></LucideIcon>
|
||||||
<span>添加文件</span>
|
<span>选择工作目录</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="toolbar-btn symbol-btn">/</button>
|
<el-tooltip content="添加文件或者文件夹作为上下文" placement="top" :show-arrow="false">
|
||||||
<button class="toolbar-btn symbol-btn">@</button>
|
<button class="toolbar-btn icon-btn">
|
||||||
|
<LucideIcon name="paperclip" size="16"></LucideIcon>
|
||||||
|
</button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="使用 / 调用技能" placement="top" :show-arrow="false">
|
||||||
|
<button class="toolbar-btn icon-btn">/</button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="使用 @ 调用知识库" placement="top" :show-arrow="false">
|
||||||
|
<button class="toolbar-btn icon-btn">@</button>
|
||||||
|
</el-tooltip>
|
||||||
</div>
|
</div>
|
||||||
<div class="toolbar-right">
|
<div class="toolbar-right">
|
||||||
<button class="send-btn" :disabled="!inputText.trim() || isCreating" @click="handleSend">
|
<button class="send-btn" :disabled="!inputText.trim() || isCreating" @click="handleSend">
|
||||||
<el-icon><Promotion /></el-icon>
|
<LucideIcon name="arrow-up"></LucideIcon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -74,14 +85,23 @@ import { ref } from 'vue';
|
|||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useAppStore } from '@/stores/app';
|
import { useAppStore } from '@/stores/app';
|
||||||
import { useHistoryStore } from '@/stores/history';
|
import { useHistoryStore } from '@/stores/history';
|
||||||
import { Document, Plus, Promotion } from '@element-plus/icons-vue';
|
import { Document, Plus, Promotion, FolderOpened, Paperclip } from '@element-plus/icons-vue';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
|
import LucideIcon from '@/components/base/LucideIcon.vue';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const historyStore = useHistoryStore();
|
const historyStore = useHistoryStore();
|
||||||
const inputText = ref('');
|
const inputText = ref('');
|
||||||
const isCreating = ref(false);
|
const isCreating = ref(false);
|
||||||
|
const textareaRef = ref(null);
|
||||||
|
|
||||||
|
function autoResize() {
|
||||||
|
const el = textareaRef.value;
|
||||||
|
if (!el) return;
|
||||||
|
el.style.height = 'auto';
|
||||||
|
el.style.height = Math.min(el.scrollHeight, 323) + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
// 处理发送消息
|
// 处理发送消息
|
||||||
async function handleSend() {
|
async function handleSend() {
|
||||||
@@ -234,26 +254,28 @@ function handleKeydown(e) {
|
|||||||
.input-section {
|
.input-section {
|
||||||
margin-top: auto;
|
margin-top: auto;
|
||||||
padding-top: 24px;
|
padding-top: 24px;
|
||||||
|
padding-bottom: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-wrapper {
|
.input-wrapper {
|
||||||
width: 760px;
|
width: 760px;
|
||||||
height: 114px;
|
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
border: 1px solid #dcdfe6;
|
border: 1px solid #dee0e4;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
|
box-shadow: 0px 1px 20px 0px #00000008;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-textarea {
|
.input-textarea {
|
||||||
width: 758px;
|
width: 758px;
|
||||||
height: 60px;
|
min-height: 60px;
|
||||||
|
max-height: 323px;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
resize: none;
|
resize: none;
|
||||||
|
overflow-y: auto;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
color: #303133;
|
color: #303133;
|
||||||
@@ -271,7 +293,6 @@ function handleKeydown(e) {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
border-top: 1px solid #ebeef5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.toolbar-left {
|
.toolbar-left {
|
||||||
@@ -296,20 +317,33 @@ function handleKeydown(e) {
|
|||||||
color: #409eff;
|
color: #409eff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-btn {
|
.dir-btn {
|
||||||
width: 84px;
|
|
||||||
height: 28px;
|
height: 28px;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
border-radius: 6px;
|
background: #f5f6f7;
|
||||||
|
border-radius: 28px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 16px;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
color: #606266;
|
||||||
|
}
|
||||||
|
.dir-btn:hover {
|
||||||
|
background: #eeeff2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.symbol-btn {
|
.icon-btn {
|
||||||
width: 28px;
|
width: 28px;
|
||||||
height: 28px;
|
height: 28px;
|
||||||
padding: 0;
|
padding: 0 7px;
|
||||||
border-radius: 6px;
|
border-radius: 9999px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
@@ -323,8 +357,8 @@ function handleKeydown(e) {
|
|||||||
width: 32px;
|
width: 32px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
border: none;
|
border: none;
|
||||||
background: #409eff;
|
background: #1a1a1a;
|
||||||
border-radius: 8px;
|
border-radius: 32px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -334,6 +368,11 @@ function handleKeydown(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.send-btn:hover {
|
.send-btn:hover {
|
||||||
background: #66b1ff;
|
background: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.send-btn:disabled {
|
||||||
|
background: #8c8c8c;
|
||||||
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user