feat: Add agent configuration and cleanup scripts for database migrations
@@ -18,6 +18,11 @@ export async function knowledgeChat(data: { session_id: string; query: string; }
|
||||
return postChat(`/api/v1/knowledge-chat/${data.session_id}`, { query: data.query });
|
||||
}
|
||||
|
||||
// Agent chat with streaming support
|
||||
export async function agentChat(data: { session_id: string; query: string; }) {
|
||||
return postChat(`/api/v1/agent-chat/${data.session_id}`, { query: data.query });
|
||||
}
|
||||
|
||||
export async function getMessageList(data: { session_id: string; limit: number, created_at: string }) {
|
||||
if (data.created_at) {
|
||||
return get(`/api/v1/messages/${data.session_id}/load?before_time=${encodeURIComponent(data.created_at)}&limit=${data.limit}`);
|
||||
|
||||
@@ -100,8 +100,16 @@ export function checkOllamaStatus(): Promise<{ available: boolean; version?: str
|
||||
});
|
||||
}
|
||||
|
||||
// 列出已安装的 Ollama 模型
|
||||
export function listOllamaModels(): Promise<string[]> {
|
||||
// Ollama 模型详细信息接口
|
||||
export interface OllamaModelInfo {
|
||||
name: string;
|
||||
size: number;
|
||||
digest: string;
|
||||
modified_at: string;
|
||||
}
|
||||
|
||||
// 列出已安装的 Ollama 模型(详细信息)
|
||||
export function listOllamaModels(): Promise<OllamaModelInfo[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
get('/api/v1/initialization/ollama/models')
|
||||
.then((response: any) => {
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import { get, post, put, del } from '../../utils/request';
|
||||
|
||||
// 模型类型定义
|
||||
export interface ModelConfig {
|
||||
id?: string;
|
||||
tenant_id?: number;
|
||||
name: string;
|
||||
type: 'KnowledgeQA' | 'Embedding' | 'Rerank' | 'VLLM';
|
||||
source: 'local' | 'remote';
|
||||
description?: string;
|
||||
parameters: {
|
||||
base_url?: string;
|
||||
api_key?: string;
|
||||
embedding_parameters?: {
|
||||
dimension?: number;
|
||||
truncate_prompt_tokens?: number;
|
||||
};
|
||||
interface_type?: 'ollama' | 'openai'; // VLLM专用
|
||||
};
|
||||
is_default?: boolean;
|
||||
status?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
deleted_at?: string | null;
|
||||
}
|
||||
|
||||
// 创建模型
|
||||
export function createModel(data: ModelConfig): Promise<ModelConfig> {
|
||||
return new Promise((resolve, reject) => {
|
||||
post('/api/v1/models', data)
|
||||
.then((response: any) => {
|
||||
if (response.success && response.data) {
|
||||
resolve(response.data);
|
||||
} else {
|
||||
reject(new Error(response.message || '创建模型失败'));
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('创建模型失败:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 获取模型列表
|
||||
export function listModels(type?: string): Promise<ModelConfig[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = type ? `/api/v1/models?type=${type}` : '/api/v1/models';
|
||||
get(url)
|
||||
.then((response: any) => {
|
||||
if (response.success && response.data) {
|
||||
resolve(response.data);
|
||||
} else {
|
||||
resolve([]);
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('获取模型列表失败:', error);
|
||||
resolve([]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 获取单个模型
|
||||
export function getModel(id: string): Promise<ModelConfig> {
|
||||
return new Promise((resolve, reject) => {
|
||||
get(`/api/v1/models/${id}`)
|
||||
.then((response: any) => {
|
||||
if (response.success && response.data) {
|
||||
resolve(response.data);
|
||||
} else {
|
||||
reject(new Error(response.message || '获取模型失败'));
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('获取模型失败:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 更新模型
|
||||
export function updateModel(id: string, data: Partial<ModelConfig>): Promise<ModelConfig> {
|
||||
return new Promise((resolve, reject) => {
|
||||
put(`/api/v1/models/${id}`, data)
|
||||
.then((response: any) => {
|
||||
if (response.success && response.data) {
|
||||
resolve(response.data);
|
||||
} else {
|
||||
reject(new Error(response.message || '更新模型失败'));
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('更新模型失败:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 删除模型
|
||||
export function deleteModel(id: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
del(`/api/v1/models/${id}`)
|
||||
.then((response: any) => {
|
||||
if (response.success) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(response.message || '删除模型失败'));
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('删除模型失败:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { get } from '@/utils/request'
|
||||
import { get, put } from '@/utils/request'
|
||||
|
||||
export interface SystemInfo {
|
||||
version: string
|
||||
@@ -7,6 +7,32 @@ export interface SystemInfo {
|
||||
go_version?: string
|
||||
}
|
||||
|
||||
export interface ToolDefinition {
|
||||
name: string
|
||||
label: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface AgentConfig {
|
||||
enabled: boolean
|
||||
max_iterations: number
|
||||
reflection_enabled: boolean
|
||||
allowed_tools: string[]
|
||||
temperature: number
|
||||
thinking_model_id: string
|
||||
rerank_model_id: string
|
||||
knowledge_bases?: string[]
|
||||
available_tools?: ToolDefinition[] // GET 响应中包含,POST/PUT 不需要
|
||||
}
|
||||
|
||||
export function getSystemInfo(): Promise<{ data: SystemInfo }> {
|
||||
return get('/api/v1/system/info')
|
||||
}
|
||||
|
||||
export function getAgentConfig(): Promise<{ data: AgentConfig }> {
|
||||
return get('/api/v1/tenants/agent-config')
|
||||
}
|
||||
|
||||
export function updateAgentConfig(config: AgentConfig): Promise<{ data: AgentConfig }> {
|
||||
return put('/api/v1/tenants/agent-config', config)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z" fill="#07C05F" stroke="#07C05F" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M15.5 4L15.8 5.2C15.85 5.45 16.05 5.65 16.3 5.7L17.5 6L16.3 6.3C16.05 6.35 15.85 6.55 15.8 6.8L15.5 8L15.2 6.8C15.15 6.55 14.95 6.35 14.7 6.3L13.5 6L14.7 5.7C14.95 5.65 15.15 5.45 15.2 5.2L15.5 4Z" fill="#07C05F" stroke="#07C05F" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M4.5 13L4.8 14.2C4.85 14.45 5.05 14.65 5.3 14.7L6.5 15L5.3 15.3C5.05 15.35 4.85 15.55 4.8 15.8L4.5 17L4.2 15.8C4.15 15.55 3.95 15.35 3.7 15.3L2.5 15L3.7 14.7C3.95 14.65 4.15 14.45 4.2 14.2L4.5 13Z" fill="#07C05F" stroke="#07C05F" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 992 B |
@@ -0,0 +1,5 @@
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M10 3L10.8 6.2C10.9 6.7 11.3 7.1 11.8 7.2L15 8L11.8 8.8C11.3 8.9 10.9 9.3 10.8 9.8L10 13L9.2 9.8C9.1 9.3 8.7 8.9 8.2 8.8L5 8L8.2 7.2C8.7 7.1 9.1 6.7 9.2 6.2L10 3Z" fill="rgba(0,0,0,0.15)" stroke="rgba(0,0,0,0.3)" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M15.5 4L15.8 5.2C15.85 5.45 16.05 5.65 16.3 5.7L17.5 6L16.3 6.3C16.05 6.35 15.85 6.55 15.8 6.8L15.5 8L15.2 6.8C15.15 6.55 14.95 6.35 14.7 6.3L13.5 6L14.7 5.7C14.95 5.65 15.15 5.45 15.2 5.2L15.5 4Z" fill="rgba(0,0,0,0.15)" stroke="rgba(0,0,0,0.3)" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M4.5 13L4.8 14.2C4.85 14.45 5.05 14.65 5.3 14.7L6.5 15L5.3 15.3C5.05 15.35 4.85 15.55 4.8 15.8L4.5 17L4.2 15.8C4.15 15.55 3.95 15.35 3.7 15.3L2.5 15L3.7 14.7C3.95 14.65 4.15 14.45 4.2 14.2L4.5 13Z" fill="rgba(0,0,0,0.15)" stroke="rgba(0,0,0,0.3)" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,4 @@
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="10" cy="10" r="3.5" stroke="#00000099" stroke-width="1.8"/>
|
||||
<path d="M13.5 10V11.5C13.5 12.163 13.7634 12.7989 14.2322 13.2678C14.7011 13.7366 15.337 14 16 14C16.663 14 17.2989 13.7366 17.7678 13.2678C18.2366 12.7989 18.5 12.163 18.5 11.5V10C18.5 7.74566 17.6045 5.58365 16.0104 3.98959C14.4163 2.39553 12.2543 1.5 10 1.5C7.74566 1.5 5.58365 2.39553 3.98959 3.98959C2.39553 5.58365 1.5 7.74566 1.5 10C1.5 12.2543 2.39553 14.4163 3.98959 16.0104C5.58365 17.6045 7.74566 18.5 10 18.5H12" stroke="#00000099" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 692 B |
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M10 12.5C11.3807 12.5 12.5 11.3807 12.5 10C12.5 8.61929 11.3807 7.5 10 7.5C8.61929 7.5 7.5 8.61929 7.5 10C7.5 11.3807 8.61929 12.5 10 12.5Z" stroke="#07C05F" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M1.66675 10.7333V9.26667C1.66675 8.4 2.37508 7.68333 3.25008 7.68333C4.75841 7.68333 5.35008 6.61667 4.59175 5.30833C4.14175 4.55833 4.38341 3.58333 5.14175 3.13333L6.58342 2.30833C7.24175 1.90833 8.09175 2.125 8.49175 2.78333L8.57508 2.92501C9.32508 4.23334 10.6751 4.23334 11.4334 2.92501L11.5167 2.78333C11.9167 2.125 12.7667 1.90833 13.4251 2.30833L14.8667 3.13333C15.6251 3.58333 15.8667 4.55833 15.4167 5.30833C14.6584 6.61667 15.2501 7.68333 16.7584 7.68333C17.6251 7.68333 18.3417 8.39167 18.3417 9.26667V10.7333C18.3417 11.6 17.6334 12.3167 16.7584 12.3167C15.2501 12.3167 14.6584 13.3833 15.4167 14.6917C15.8667 15.45 15.6251 16.4167 14.8667 16.8667L13.4251 17.6917C12.7667 18.0917 11.9167 17.875 11.5167 17.2167L11.4334 17.075C10.6834 15.7667 9.33341 15.7667 8.57508 17.075L8.49175 17.2167C8.09175 17.875 7.24175 18.0917 6.58342 17.6917L5.14175 16.8667C4.38341 16.4167 4.14175 15.4417 4.59175 14.6917C5.35008 13.3833 4.75841 12.3167 3.25008 12.3167C2.37508 12.3167 1.66675 11.6 1.66675 10.7333Z" stroke="#07C05F" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
<path d="M10 12.5C11.3807 12.5 12.5 11.3807 12.5 10C12.5 8.61929 11.3807 7.5 10 7.5C8.61929 7.5 7.5 8.61929 7.5 10C7.5 11.3807 8.61929 12.5 10 12.5Z" stroke="#07C05F" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M16.1667 12.5C16.0557 12.7513 16.0227 13.0301 16.0721 13.3006C16.1214 13.5711 16.251 13.8203 16.4417 14.0167L16.4917 14.0667C16.6447 14.2194 16.7658 14.4008 16.8482 14.6006C16.9305 14.8003 16.9725 15.0145 16.9725 15.2308C16.9725 15.4472 16.9305 15.6614 16.8482 15.8611C16.7658 16.0609 16.6447 16.2423 16.4917 16.395C16.339 16.548 16.1576 16.6691 15.9578 16.7514C15.7581 16.8338 15.5439 16.8758 15.3275 16.8758C15.1112 16.8758 14.897 16.8338 14.6972 16.7514C14.4975 16.6691 14.3161 16.548 14.1633 16.395L14.1133 16.345C13.917 16.1543 13.6678 16.0247 13.3973 15.9754C13.1268 15.926 12.848 15.959 12.5967 16.07C12.3503 16.1761 12.1423 16.3521 11.9993 16.5762C11.8563 16.8003 11.7848 17.0625 11.7942 17.3283V17.5C11.7942 17.9421 11.6184 18.3659 11.3059 18.6785C10.9933 18.991 10.5695 19.1667 10.1275 19.1667C9.6854 19.1667 9.26163 18.991 8.94907 18.6785C8.63651 18.3659 8.46083 17.9421 8.46083 17.5V17.425C8.46458 17.1515 8.38642 16.8831 8.23616 16.6542C8.0859 16.4252 7.87016 16.2461 7.61583 16.1383C7.36452 16.0273 7.08571 15.9943 6.81523 16.0437C6.54474 16.093 6.29555 16.2227 6.09917 16.4133L6.04917 16.4633C5.89641 16.6163 5.71499 16.7374 5.51525 16.8198C5.31551 16.9021 5.10132 16.9441 4.88499 16.9441C4.66866 16.9441 4.45447 16.9021 4.25473 16.8198C4.05499 16.7374 3.87357 16.6163 3.72083 16.4633C3.56783 16.3106 3.4467 16.1292 3.36438 15.9294C3.28205 15.7297 3.24005 15.5155 3.24005 15.2992C3.24005 15.0828 3.28205 14.8687 3.36438 14.6689C3.4467 14.4692 3.56783 14.2877 3.72083 14.135L3.77083 14.085C3.96147 13.8886 4.09115 13.6394 4.14049 13.3689C4.18984 13.0985 4.15685 12.8196 4.04583 12.5683C3.93975 12.322 3.76374 12.1139 3.53965 11.9709C3.31556 11.8279 3.05339 11.7564 2.7875 11.7658H2.61583C2.17379 11.7658 1.75001 11.5902 1.43745 11.2776C1.12489 10.965 0.949219 10.5412 0.949219 10.0992C0.949219 9.65712 1.12489 9.23335 1.43745 8.92079C1.75001 8.60823 2.17379 8.43255 2.61583 8.43255H2.69083C2.96438 8.4288 3.23272 8.35065 3.46167 8.20038C3.69063 8.05012 3.86979 7.83438 3.9775 7.58005C4.0885 7.32874 4.12149 7.04993 4.07215 6.77944C4.02281 6.50896 3.89313 6.25977 3.7025 6.06339L3.6525 6.01339C3.4995 5.86063 3.37837 5.67921 3.29604 5.47947C3.21372 5.27973 3.17172 5.06554 3.17172 4.84921C3.17172 4.63288 3.21372 4.41869 3.29604 4.21895C3.37837 4.01921 3.4995 3.83779 3.6525 3.68505C3.80524 3.53205 3.98666 3.41092 4.1864 3.3286C4.38614 3.24627 4.60033 3.20427 4.81666 3.20427C5.03299 3.20427 5.24719 3.24627 5.44693 3.3286C5.64666 3.41092 5.82809 3.53205 5.98083 3.68505L6.03083 3.73505C6.22721 3.92569 6.4764 4.05537 6.74688 4.10472C7.01737 4.15406 7.29618 4.12107 7.5475 4.01005H7.61583C7.86213 3.90397 8.07024 3.72796 8.21324 3.50387C8.35624 3.27978 8.42774 3.01761 8.41833 2.75172V2.58005C8.41833 2.13801 8.59401 1.71424 8.90657 1.40168C9.21913 1.08912 9.6429 0.913452 10.0849 0.913452C10.527 0.913452 10.9507 1.08912 11.2633 1.40168C11.5759 1.71424 11.7515 2.13801 11.7515 2.58005V2.65505C11.7421 2.92094 11.8136 3.18311 11.9566 3.4072C12.0996 3.63129 12.3077 3.8073 12.554 3.91339C12.8053 4.0244 13.0841 4.05739 13.3546 4.00805C13.6251 3.95871 13.8743 3.82903 14.0706 3.63839L14.1206 3.58839C14.2734 3.43539 14.4548 3.31426 14.6545 3.23193C14.8543 3.14961 15.0685 3.10761 15.2848 3.10761C15.5011 3.10761 15.7153 3.14961 15.9151 3.23193C16.1148 3.31426 16.2962 3.43539 16.449 3.58839C16.602 3.74113 16.7231 3.92255 16.8054 4.12229C16.8878 4.32203 16.9298 4.53622 16.9298 4.75255C16.9298 4.96888 16.8878 5.18307 16.8054 5.38281C16.7231 5.58255 16.602 5.76397 16.449 5.91672L16.399 5.96672C16.2084 6.1631 16.0787 6.41229 16.0293 6.68277C15.98 6.95326 16.013 7.23207 16.124 7.48339V7.58005C16.2301 7.82635 16.4061 8.03446 16.6302 8.17746C16.8543 8.32046 17.1164 8.39196 17.3823 8.38255H17.554C17.996 8.38255 18.4198 8.55823 18.7324 8.87079C19.0449 9.18335 19.2206 9.60712 19.2206 10.0492C19.2206 10.4912 19.0449 10.915 18.7324 11.2276C18.4198 11.5401 17.996 11.7158 17.554 11.7158H17.479C17.2131 11.7064 16.951 11.7779 16.7269 11.9209C16.5028 12.0639 16.3268 12.272 16.2206 12.5183V12.5Z" stroke="#07C05F" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 4.3 KiB |
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M10 12.5C11.3807 12.5 12.5 11.3807 12.5 10C12.5 8.61929 11.3807 7.5 10 7.5C8.61929 7.5 7.5 8.61929 7.5 10C7.5 11.3807 8.61929 12.5 10 12.5Z" stroke="currentColor" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M1.66675 10.7333V9.26667C1.66675 8.4 2.37508 7.68333 3.25008 7.68333C4.75841 7.68333 5.35008 6.61667 4.59175 5.30833C4.14175 4.55833 4.38341 3.58333 5.14175 3.13333L6.58342 2.30833C7.24175 1.90833 8.09175 2.125 8.49175 2.78333L8.57508 2.92501C9.32508 4.23334 10.6751 4.23334 11.4334 2.92501L11.5167 2.78333C11.9167 2.125 12.7667 1.90833 13.4251 2.30833L14.8667 3.13333C15.6251 3.58333 15.8667 4.55833 15.4167 5.30833C14.6584 6.61667 15.2501 7.68333 16.7584 7.68333C17.6251 7.68333 18.3417 8.39167 18.3417 9.26667V10.7333C18.3417 11.6 17.6334 12.3167 16.7584 12.3167C15.2501 12.3167 14.6584 13.3833 15.4167 14.6917C15.8667 15.45 15.6251 16.4167 14.8667 16.8667L13.4251 17.6917C12.7667 18.0917 11.9167 17.875 11.5167 17.2167L11.4334 17.075C10.6834 15.7667 9.33341 15.7667 8.57508 17.075L8.49175 17.2167C8.09175 17.875 7.24175 18.0917 6.58342 17.6917L5.14175 16.8667C4.38341 16.4167 4.14175 15.4417 4.59175 14.6917C5.35008 13.3833 4.75841 12.3167 3.25008 12.3167C2.37508 12.3167 1.66675 11.6 1.66675 10.7333Z" stroke="currentColor" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
<path d="M10 12.5C11.3807 12.5 12.5 11.3807 12.5 10C12.5 8.61929 11.3807 7.5 10 7.5C8.61929 7.5 7.5 8.61929 7.5 10C7.5 11.3807 8.61929 12.5 10 12.5Z" stroke="#00000099" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M16.1667 12.5C16.0557 12.7513 16.0227 13.0301 16.0721 13.3006C16.1214 13.5711 16.251 13.8203 16.4417 14.0167L16.4917 14.0667C16.6447 14.2194 16.7658 14.4008 16.8482 14.6006C16.9305 14.8003 16.9725 15.0145 16.9725 15.2308C16.9725 15.4472 16.9305 15.6614 16.8482 15.8611C16.7658 16.0609 16.6447 16.2423 16.4917 16.395C16.339 16.548 16.1576 16.6691 15.9578 16.7514C15.7581 16.8338 15.5439 16.8758 15.3275 16.8758C15.1112 16.8758 14.897 16.8338 14.6972 16.7514C14.4975 16.6691 14.3161 16.548 14.1633 16.395L14.1133 16.345C13.917 16.1543 13.6678 16.0247 13.3973 15.9754C13.1268 15.926 12.848 15.959 12.5967 16.07C12.3503 16.1761 12.1423 16.3521 11.9993 16.5762C11.8563 16.8003 11.7848 17.0625 11.7942 17.3283V17.5C11.7942 17.9421 11.6184 18.3659 11.3059 18.6785C10.9933 18.991 10.5695 19.1667 10.1275 19.1667C9.6854 19.1667 9.26163 18.991 8.94907 18.6785C8.63651 18.3659 8.46083 17.9421 8.46083 17.5V17.425C8.46458 17.1515 8.38642 16.8831 8.23616 16.6542C8.0859 16.4252 7.87016 16.2461 7.61583 16.1383C7.36452 16.0273 7.08571 15.9943 6.81523 16.0437C6.54474 16.093 6.29555 16.2227 6.09917 16.4133L6.04917 16.4633C5.89641 16.6163 5.71499 16.7374 5.51525 16.8198C5.31551 16.9021 5.10132 16.9441 4.88499 16.9441C4.66866 16.9441 4.45447 16.9021 4.25473 16.8198C4.05499 16.7374 3.87357 16.6163 3.72083 16.4633C3.56783 16.3106 3.4467 16.1292 3.36438 15.9294C3.28205 15.7297 3.24005 15.5155 3.24005 15.2992C3.24005 15.0828 3.28205 14.8687 3.36438 14.6689C3.4467 14.4692 3.56783 14.2877 3.72083 14.135L3.77083 14.085C3.96147 13.8886 4.09115 13.6394 4.14049 13.3689C4.18984 13.0985 4.15685 12.8196 4.04583 12.5683C3.93975 12.322 3.76374 12.1139 3.53965 11.9709C3.31556 11.8279 3.05339 11.7564 2.7875 11.7658H2.61583C2.17379 11.7658 1.75001 11.5902 1.43745 11.2776C1.12489 10.965 0.949219 10.5412 0.949219 10.0992C0.949219 9.65712 1.12489 9.23335 1.43745 8.92079C1.75001 8.60823 2.17379 8.43255 2.61583 8.43255H2.69083C2.96438 8.4288 3.23272 8.35065 3.46167 8.20038C3.69063 8.05012 3.86979 7.83438 3.9775 7.58005C4.0885 7.32874 4.12149 7.04993 4.07215 6.77944C4.02281 6.50896 3.89313 6.25977 3.7025 6.06339L3.6525 6.01339C3.4995 5.86063 3.37837 5.67921 3.29604 5.47947C3.21372 5.27973 3.17172 5.06554 3.17172 4.84921C3.17172 4.63288 3.21372 4.41869 3.29604 4.21895C3.37837 4.01921 3.4995 3.83779 3.6525 3.68505C3.80524 3.53205 3.98666 3.41092 4.1864 3.3286C4.38614 3.24627 4.60033 3.20427 4.81666 3.20427C5.03299 3.20427 5.24719 3.24627 5.44693 3.3286C5.64666 3.41092 5.82809 3.53205 5.98083 3.68505L6.03083 3.73505C6.22721 3.92569 6.4764 4.05537 6.74688 4.10472C7.01737 4.15406 7.29618 4.12107 7.5475 4.01005H7.61583C7.86213 3.90397 8.07024 3.72796 8.21324 3.50387C8.35624 3.27978 8.42774 3.01761 8.41833 2.75172V2.58005C8.41833 2.13801 8.59401 1.71424 8.90657 1.40168C9.21913 1.08912 9.6429 0.913452 10.0849 0.913452C10.527 0.913452 10.9507 1.08912 11.2633 1.40168C11.5759 1.71424 11.7515 2.13801 11.7515 2.58005V2.65505C11.7421 2.92094 11.8136 3.18311 11.9566 3.4072C12.0996 3.63129 12.3077 3.8073 12.554 3.91339C12.8053 4.0244 13.0841 4.05739 13.3546 4.00805C13.6251 3.95871 13.8743 3.82903 14.0706 3.63839L14.1206 3.58839C14.2734 3.43539 14.4548 3.31426 14.6545 3.23193C14.8543 3.14961 15.0685 3.10761 15.2848 3.10761C15.5011 3.10761 15.7153 3.14961 15.9151 3.23193C16.1148 3.31426 16.2962 3.43539 16.449 3.58839C16.602 3.74113 16.7231 3.92255 16.8054 4.12229C16.8878 4.32203 16.9298 4.53622 16.9298 4.75255C16.9298 4.96888 16.8878 5.18307 16.8054 5.38281C16.7231 5.58255 16.602 5.76397 16.449 5.91672L16.399 5.96672C16.2084 6.1631 16.0787 6.41229 16.0293 6.68277C15.98 6.95326 16.013 7.23207 16.124 7.48339V7.58005C16.2301 7.82635 16.4061 8.03446 16.6302 8.17746C16.8543 8.32046 17.1164 8.39196 17.3823 8.38255H17.554C17.996 8.38255 18.4198 8.55823 18.7324 8.87079C19.0449 9.18335 19.2206 9.60712 19.2206 10.0492C19.2206 10.4912 19.0449 10.915 18.7324 11.2276C18.4198 11.5401 17.996 11.7158 17.554 11.7158H17.479C17.2131 11.7064 16.951 11.7779 16.7269 11.9209C16.5028 12.0639 16.3268 12.272 16.2206 12.5183V12.5Z" stroke="#00000099" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 4.3 KiB |
@@ -1,27 +1,79 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, defineEmits, onMounted, defineProps, defineExpose } from "vue";
|
||||
import useKnowledgeBase from '@/hooks/useKnowledgeBase';
|
||||
import { ref, defineEmits, onMounted, defineProps, computed, watch, nextTick } from "vue";
|
||||
import { useRoute } from 'vue-router';
|
||||
import { onBeforeRouteUpdate } from 'vue-router';
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
let { cardList, total, getKnowled } = useKnowledgeBase()
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import { listKnowledgeBases } from '@/api/knowledge-base';
|
||||
import KnowledgeBaseSelector from './KnowledgeBaseSelector.vue';
|
||||
|
||||
const route = useRoute();
|
||||
const settingsStore = useSettingsStore();
|
||||
let query = ref("");
|
||||
const showKbSelector = ref(false);
|
||||
const atButtonRef = ref<HTMLElement>();
|
||||
|
||||
const props = defineProps({
|
||||
isReplying: {
|
||||
type: Boolean,
|
||||
required: false
|
||||
}
|
||||
});
|
||||
|
||||
const isAgentEnabled = computed(() => settingsStore.isAgentEnabled);
|
||||
const selectedKbIds = computed(() => settingsStore.settings.selectedKnowledgeBases || []);
|
||||
|
||||
// 获取已选择的知识库信息
|
||||
const knowledgeBases = ref<Array<{ id: string; name: string }>>([]);
|
||||
const selectedKbs = computed(() => {
|
||||
return knowledgeBases.value.filter(kb => selectedKbIds.value.includes(kb.id));
|
||||
});
|
||||
|
||||
// 显示的知识库标签(最多显示2个)
|
||||
const displayedKbs = computed(() => selectedKbs.value.slice(0, 2));
|
||||
const remainingCount = computed(() => Math.max(0, selectedKbs.value.length - 2));
|
||||
|
||||
// 加载知识库列表
|
||||
const loadKnowledgeBases = async () => {
|
||||
try {
|
||||
const response: any = await listKnowledgeBases();
|
||||
if (response.data && Array.isArray(response.data)) {
|
||||
knowledgeBases.value = response.data.filter((kb: any) =>
|
||||
kb.embedding_model_id && kb.embedding_model_id !== '' &&
|
||||
kb.summary_model_id && kb.summary_model_id !== ''
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load knowledge bases:', error);
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getKnowled()
|
||||
})
|
||||
loadKnowledgeBases();
|
||||
|
||||
// 如果从知识库内部进入,自动选中该知识库
|
||||
const kbId = (route.params as any)?.kbId as string;
|
||||
if (kbId && !selectedKbIds.value.includes(kbId)) {
|
||||
settingsStore.addKnowledgeBase(kbId);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听路由变化
|
||||
watch(() => route.params.kbId, (newKbId) => {
|
||||
if (newKbId && typeof newKbId === 'string' && !selectedKbIds.value.includes(newKbId)) {
|
||||
settingsStore.addKnowledgeBase(newKbId);
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['send-msg']);
|
||||
|
||||
const createSession = (val: string) => {
|
||||
if (!val.trim()) {
|
||||
MessagePlugin.info("请先输入内容!");
|
||||
return
|
||||
return;
|
||||
}
|
||||
if (!query.value && cardList.value.length == 0) {
|
||||
MessagePlugin.info("请先上传知识库!");
|
||||
if (selectedKbIds.value.length === 0) {
|
||||
MessagePlugin.warning("请先选择知识库!");
|
||||
return;
|
||||
}
|
||||
if (props.isReplying) {
|
||||
@@ -30,9 +82,11 @@ const createSession = (val: string) => {
|
||||
emit('send-msg', val);
|
||||
clearvalue();
|
||||
}
|
||||
|
||||
const clearvalue = () => {
|
||||
query.value = "";
|
||||
}
|
||||
|
||||
const onKeydown = (val: string, event: { e: { preventDefault(): unknown; keyCode: number; shiftKey: any; ctrlKey: any; }; }) => {
|
||||
if ((event.e.keyCode == 13 && event.e.shiftKey) || (event.e.keyCode == 13 && event.e.ctrlKey)) {
|
||||
return;
|
||||
@@ -42,6 +96,21 @@ const onKeydown = (val: string, event: { e: { preventDefault(): unknown; keyCode
|
||||
createSession(val)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleAgentMode = () => {
|
||||
settingsStore.toggleAgent(!isAgentEnabled.value);
|
||||
const message = isAgentEnabled.value ? 'Agent 模式已启用' : 'Agent 模式已禁用';
|
||||
MessagePlugin.success(message);
|
||||
}
|
||||
|
||||
const toggleKbSelector = () => {
|
||||
showKbSelector.value = !showKbSelector.value;
|
||||
}
|
||||
|
||||
const removeKb = (kbId: string) => {
|
||||
settingsStore.removeKnowledgeBase(kbId);
|
||||
}
|
||||
|
||||
onBeforeRouteUpdate((to, from, next) => {
|
||||
clearvalue()
|
||||
next()
|
||||
@@ -51,15 +120,90 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
<template>
|
||||
<div class="answers-input">
|
||||
<t-textarea v-model="query" placeholder="基于知识库提问" name="description" :autosize="true" @keydown="onKeydown" />
|
||||
<div class="answers-input-source">
|
||||
<span>{{ total }}个来源</span>
|
||||
</div>
|
||||
<div @click="createSession(query)" class="answers-input-send"
|
||||
:class="[query.length && total ? '' : 'grey-out']">
|
||||
<img src="../assets/img/sending-aircraft.svg" alt="">
|
||||
|
||||
<!-- 控制栏 -->
|
||||
<div class="control-bar">
|
||||
<!-- 左侧控制按钮 -->
|
||||
<div class="control-left">
|
||||
<!-- Agent 模式按钮 -->
|
||||
<t-tooltip :content="isAgentEnabled ? 'Agent 模式(已启用)' : 'Agent 模式(已禁用)'" placement="top">
|
||||
<div
|
||||
class="control-btn agent-btn"
|
||||
:class="{ 'active': isAgentEnabled }"
|
||||
@click="toggleAgentMode"
|
||||
>
|
||||
<img
|
||||
:src="isAgentEnabled ? getImgSrc('agent-active.svg') : getImgSrc('agent.svg')"
|
||||
alt="Agent"
|
||||
class="control-icon"
|
||||
/>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
|
||||
<!-- @ 知识库选择按钮 -->
|
||||
<div
|
||||
ref="atButtonRef"
|
||||
class="control-btn kb-btn"
|
||||
:class="{ 'active': selectedKbIds.length > 0 }"
|
||||
@click="toggleKbSelector"
|
||||
>
|
||||
<img :src="getImgSrc('at-icon.svg')" alt="@" class="control-icon" />
|
||||
<span class="kb-btn-text">
|
||||
{{ selectedKbIds.length > 0 ? `知识库(${selectedKbIds.length})` : '知识库' }}
|
||||
</span>
|
||||
<svg
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 12 12"
|
||||
fill="currentColor"
|
||||
class="dropdown-arrow"
|
||||
:class="{ 'rotate': showKbSelector }"
|
||||
>
|
||||
<path d="M2.5 4.5L6 8L9.5 4.5H2.5Z"/>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<!-- 已选择的知识库标签 -->
|
||||
<div v-if="displayedKbs.length > 0" class="kb-tags">
|
||||
<div
|
||||
v-for="kb in displayedKbs"
|
||||
:key="kb.id"
|
||||
class="kb-tag"
|
||||
>
|
||||
<span class="kb-tag-text">{{ kb.name }}</span>
|
||||
<span class="kb-tag-remove" @click.stop="removeKb(kb.id)">×</span>
|
||||
</div>
|
||||
<div v-if="remainingCount > 0" class="kb-tag more-tag">
|
||||
+{{ remainingCount }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧发送按钮 -->
|
||||
<div
|
||||
@click="createSession(query)"
|
||||
class="control-btn send-btn"
|
||||
:class="{ 'disabled': !query.length || selectedKbIds.length === 0 }"
|
||||
>
|
||||
<img src="../assets/img/sending-aircraft.svg" alt="发送" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 知识库选择下拉(使用 Teleport 传送到 body,避免父容器定位影响) -->
|
||||
<Teleport to="body">
|
||||
<KnowledgeBaseSelector
|
||||
v-model:visible="showKbSelector"
|
||||
:anchorEl="atButtonRef"
|
||||
@close="showKbSelector = false"
|
||||
/>
|
||||
</Teleport>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
const getImgSrc = (url: string) => {
|
||||
return new URL(`/src/assets/img/${url}`, import.meta.url).href;
|
||||
}
|
||||
</script>
|
||||
<style scoped lang="less">
|
||||
.answers-input {
|
||||
position: absolute;
|
||||
@@ -79,9 +223,8 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
line-height: 24px;
|
||||
color: #000000e6;
|
||||
font-family: "PingFang SC";
|
||||
padding: 16px 12px 12px 16px;
|
||||
padding: 16px 12px 52px 16px; /* 增加底部padding为控制栏腾出空间 */
|
||||
border-radius: 12px;
|
||||
border: 1px solid #E7E7E7;
|
||||
box-sizing: border-box;
|
||||
@@ -92,7 +235,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
border: 1px solid #07C05F;
|
||||
}
|
||||
|
||||
&:placeholder {
|
||||
&::placeholder {
|
||||
color: #00000066;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
@@ -101,35 +244,193 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
}
|
||||
}
|
||||
|
||||
.answers-input-send {
|
||||
background-color: #07C05F;
|
||||
height: 36px;
|
||||
width: 36px;
|
||||
/* 控制栏 */
|
||||
.control-bar {
|
||||
position: absolute;
|
||||
bottom: 12px;
|
||||
left: 16px;
|
||||
right: 16px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: absolute;
|
||||
bottom: 12px;
|
||||
right: 12px;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.control-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
padding: 6px 10px;
|
||||
border-radius: 6px;
|
||||
background: #f5f5f5;
|
||||
cursor: pointer;
|
||||
border-radius: 8px;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
background: #e6e6e6;
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
|
||||
&:hover {
|
||||
background: #f5f5f5;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.answers-input-source {
|
||||
position: absolute;
|
||||
bottom: 12px;
|
||||
right: 64px;
|
||||
line-height: 32px;
|
||||
color: #00000066;
|
||||
font-family: "PingFang SC";
|
||||
.agent-btn {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
|
||||
&.active {
|
||||
background: rgba(7, 192, 95, 0.1);
|
||||
|
||||
&:hover {
|
||||
background: rgba(7, 192, 95, 0.15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.control-icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.kb-btn {
|
||||
height: 28px;
|
||||
padding: 0 10px;
|
||||
min-width: auto;
|
||||
|
||||
&.active {
|
||||
background: rgba(7, 192, 95, 0.1);
|
||||
color: #07C05F;
|
||||
|
||||
&:hover {
|
||||
background: rgba(7, 192, 95, 0.15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.kb-btn-text {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.kb-btn.active .kb-btn-text {
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
.dropdown-arrow {
|
||||
transition: transform 0.2s ease;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
margin-left: 2px;
|
||||
|
||||
&.rotate {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
|
||||
.kb-tags {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex: 1;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.kb-tag {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 4px 8px;
|
||||
background: rgba(7, 192, 95, 0.1);
|
||||
border: 1px solid rgba(7, 192, 95, 0.3);
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
color: #07C05F;
|
||||
white-space: nowrap;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background: rgba(7, 192, 95, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
.grey-out {
|
||||
background-color: #b5eccf !important;
|
||||
cursor: no-drop !important;
|
||||
.kb-tag-text {
|
||||
max-width: 100px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.kb-tag-remove {
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
opacity: 0.7;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.more-tag {
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
border-color: rgba(0, 0, 0, 0.1);
|
||||
color: #666;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
}
|
||||
|
||||
.send-btn {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
background-color: #07C05F;
|
||||
|
||||
&:hover:not(.disabled) {
|
||||
background-color: #00a651;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
background-color: #b5eccf;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,371 @@
|
||||
<template>
|
||||
<div v-if="visible" class="kb-overlay" @click="close">
|
||||
<div class="kb-dropdown" @click.stop :style="dropdownStyle">
|
||||
<!-- 搜索 -->
|
||||
<div class="kb-search">
|
||||
<input
|
||||
ref="searchInput"
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
placeholder="搜索知识库..."
|
||||
class="kb-search-input"
|
||||
@keydown.down.prevent="moveSelection(1)"
|
||||
@keydown.up.prevent="moveSelection(-1)"
|
||||
@keydown.enter.prevent="toggleSelection"
|
||||
@keydown.esc="close"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 列表 -->
|
||||
<div class="kb-list" ref="kbList">
|
||||
<div
|
||||
v-for="(kb, index) in filteredKnowledgeBases"
|
||||
:key="kb.id"
|
||||
:class="['kb-item', { selected: isSelected(kb.id), highlighted: highlightedIndex === index }]"
|
||||
@click="toggleKb(kb.id)"
|
||||
@mouseenter="highlightedIndex = index"
|
||||
>
|
||||
<div class="kb-item-left">
|
||||
<div class="checkbox" :class="{ checked: isSelected(kb.id) }">
|
||||
<svg v-if="isSelected(kb.id)" width="12" height="12" viewBox="0 0 12 12" fill="none">
|
||||
<path d="M10 3L4.5 8.5L2 6" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="kb-name-wrap">
|
||||
<span class="kb-name">{{ kb.name }}</span>
|
||||
<span class="kb-docs" v-if="kb.docsCount !== undefined">{{ kb.docsCount }} docs</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="filteredKnowledgeBases.length === 0" class="kb-empty">
|
||||
{{ searchQuery ? '未找到匹配的知识库' : '暂无可用知识库' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部操作 -->
|
||||
<div class="kb-actions">
|
||||
<button @click="selectAll" class="kb-btn">全选</button>
|
||||
<button @click="clearAll" class="kb-btn">清空</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, nextTick } from 'vue'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
import { listKnowledgeBases } from '@/api/knowledge-base'
|
||||
|
||||
interface KnowledgeBase {
|
||||
id: string
|
||||
name: string
|
||||
docsCount?: number
|
||||
embedding_model_id?: string
|
||||
summary_model_id?: string
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
anchorEl?: any | null // 支持 DOM 节点、ref、组件实例
|
||||
dropdownWidth?: number
|
||||
offsetY?: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['close', 'update:visible'])
|
||||
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
// 本地状态
|
||||
const searchQuery = ref('')
|
||||
const highlightedIndex = ref(0)
|
||||
const knowledgeBases = ref<KnowledgeBase[]>([])
|
||||
const searchInput = ref<HTMLInputElement | null>(null)
|
||||
const kbList = ref<HTMLElement | null>(null)
|
||||
const dropdownStyle = ref<Record<string, string>>({})
|
||||
|
||||
// props 默认
|
||||
const dropdownWidth = props.dropdownWidth ?? 300
|
||||
const offsetY = props.offsetY ?? 8
|
||||
|
||||
// 过滤:只显示已初始化(有 embedding & summary)的
|
||||
const filteredKnowledgeBases = computed(() => {
|
||||
const valid = knowledgeBases.value.filter(
|
||||
k => k.embedding_model_id && k.summary_model_id
|
||||
)
|
||||
if (!searchQuery.value) return valid
|
||||
const q = searchQuery.value.toLowerCase()
|
||||
return valid.filter(k => k.name.toLowerCase().includes(q))
|
||||
})
|
||||
|
||||
const selectedKbIds = computed(() => settingsStore.settings.selectedKnowledgeBases || [])
|
||||
|
||||
// helper: 从 props.anchorEl 获取真实 DOM 元素(支持多种传入形式)
|
||||
const resolveAnchorEl = () => {
|
||||
const a = props.anchorEl
|
||||
if (!a) return null
|
||||
// 如果是 Vue ref:取 .value
|
||||
if (typeof a === 'object' && 'value' in a) {
|
||||
return a.value ?? null
|
||||
}
|
||||
// 如果是组件实例(可能有 $el)
|
||||
if (typeof a === 'object' && '$el' in a) {
|
||||
// @ts-ignore
|
||||
return a.$el ?? null
|
||||
}
|
||||
// 直接 DOM 节点或 DOMRect
|
||||
return a
|
||||
}
|
||||
|
||||
const isSelected = (id: string) => selectedKbIds.value.includes(id)
|
||||
|
||||
const toggleKb = (id: string) => {
|
||||
isSelected(id) ? settingsStore.removeKnowledgeBase(id) : settingsStore.addKnowledgeBase(id)
|
||||
}
|
||||
|
||||
const toggleSelection = () => {
|
||||
const kb = filteredKnowledgeBases.value[highlightedIndex.value]
|
||||
if (kb) toggleKb(kb.id)
|
||||
}
|
||||
|
||||
const moveSelection = (dir: number) => {
|
||||
const max = filteredKnowledgeBases.value.length
|
||||
if (max === 0) return
|
||||
highlightedIndex.value = Math.max(0, Math.min(max - 1, highlightedIndex.value + dir))
|
||||
nextTick(() => {
|
||||
const items = kbList.value?.querySelectorAll('.kb-item')
|
||||
items?.[highlightedIndex.value]?.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
|
||||
})
|
||||
}
|
||||
|
||||
const selectAll = () => settingsStore.selectKnowledgeBases(filteredKnowledgeBases.value.map(k => k.id))
|
||||
const clearAll = () => settingsStore.clearKnowledgeBases()
|
||||
|
||||
const close = () => {
|
||||
emit('update:visible', false)
|
||||
emit('close')
|
||||
}
|
||||
|
||||
const loadKnowledgeBases = async () => {
|
||||
try {
|
||||
const res: any = await listKnowledgeBases()
|
||||
if (res?.data && Array.isArray(res.data)) knowledgeBases.value = res.data
|
||||
} catch (e) {
|
||||
console.error('加载知识库失败', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 计算下拉位置:水平居中对齐到按钮中点,处理视口边界
|
||||
const updateDropdownPosition = () => {
|
||||
const anchor = resolveAnchorEl()
|
||||
|
||||
// fallback 函数
|
||||
const applyFallback = () => {
|
||||
const vw = window.innerWidth
|
||||
const topFallback = Math.max(80, window.innerHeight / 2 - 160)
|
||||
dropdownStyle.value = {
|
||||
width: `${dropdownWidth}px`,
|
||||
left: `${Math.round((vw - dropdownWidth) / 2)}px`,
|
||||
top: `${Math.round(topFallback)}px`
|
||||
}
|
||||
}
|
||||
|
||||
if (!anchor) {
|
||||
applyFallback()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取 anchor 的 bounding rect
|
||||
let rect: DOMRect | null = null
|
||||
try {
|
||||
if (typeof anchor.getBoundingClientRect === 'function') {
|
||||
rect = anchor.getBoundingClientRect()
|
||||
} else if (anchor.width && anchor.left) {
|
||||
// 已经是 DOMRect
|
||||
rect = anchor as DOMRect
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[KnowledgeBaseSelector] Error getting bounding rect:', e)
|
||||
}
|
||||
|
||||
if (!rect) {
|
||||
applyFallback()
|
||||
return
|
||||
}
|
||||
|
||||
const vw = window.innerWidth
|
||||
const vh = window.innerHeight
|
||||
|
||||
// 左对齐到触发元素(也可以改为居中:rect.left + rect.width / 2 - dropdownWidth / 2)
|
||||
let left = Math.round(rect.left)
|
||||
|
||||
// 边界处理:不超出视口左右(留 8px margin)
|
||||
const minLeft = 8
|
||||
const maxLeft = Math.max(8, vw - dropdownWidth - 8)
|
||||
left = Math.max(minLeft, Math.min(maxLeft, left))
|
||||
|
||||
// 垂直:优先下方,若不够则上方
|
||||
let top = Math.round(rect.bottom + offsetY)
|
||||
const estimatedHeight = 320 // 估算高度,用于判断是否溢出
|
||||
|
||||
if (top + estimatedHeight > vh) {
|
||||
// 往上弹出
|
||||
top = Math.round(rect.top - estimatedHeight - offsetY)
|
||||
if (top < 8) {
|
||||
top = 8
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 fixed 定位,不需要加 scroll offset
|
||||
dropdownStyle.value = {
|
||||
width: `${dropdownWidth}px`,
|
||||
left: `${left}px`,
|
||||
top: `${top}px`
|
||||
}
|
||||
}
|
||||
|
||||
// 当 visible 变化时处理
|
||||
watch(() => props.visible, async (v) => {
|
||||
if (v) {
|
||||
await loadKnowledgeBases()
|
||||
// 等 DOM 渲染完再计算位置,防止 rect 读取到不准值
|
||||
await nextTick()
|
||||
updateDropdownPosition()
|
||||
// 确保 focus
|
||||
nextTick(() => searchInput.value?.focus())
|
||||
// 监听 resize/scroll 做微调
|
||||
window.addEventListener('resize', updateDropdownPosition)
|
||||
window.addEventListener('scroll', updateDropdownPosition, true)
|
||||
} else {
|
||||
searchQuery.value = ''
|
||||
highlightedIndex.value = 0
|
||||
window.removeEventListener('resize', updateDropdownPosition)
|
||||
window.removeEventListener('scroll', updateDropdownPosition, true)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
// 确保所有元素使用 border-box 盒模型
|
||||
.kb-overlay,
|
||||
.kb-overlay *,
|
||||
.kb-overlay *::before,
|
||||
.kb-overlay *::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.kb-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 9999;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
/* 下拉面板使用 fixed 定位,相对于视口 */
|
||||
.kb-dropdown {
|
||||
position: fixed;
|
||||
background: #fff;
|
||||
border: 1px solid #e7e9eb;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 6px 28px rgba(15, 23, 42, 0.08);
|
||||
overflow: hidden;
|
||||
animation: fadeIn 0.12s ease-out;
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
/* 宽度由 JS 控制(dropdownWidth),这里只做内部样式 */
|
||||
.kb-search {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid #f1f3f4;
|
||||
}
|
||||
.kb-search-input {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
font-size: 13px;
|
||||
border: 1px solid #eef1f2;
|
||||
border-radius: 8px;
|
||||
background: #fbfdfc;
|
||||
outline: none;
|
||||
transition: border 0.12s;
|
||||
}
|
||||
.kb-search-input:focus {
|
||||
border-color: #10b981;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.kb-list {
|
||||
max-height: 260px;
|
||||
overflow-y: auto;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.kb-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: background 0.12s;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.kb-item:last-child { margin-bottom: 0; }
|
||||
|
||||
.kb-item:hover,
|
||||
.kb-item.highlighted { background: #f6f8f7; }
|
||||
|
||||
.kb-item.selected { background: #eefdf5; }
|
||||
|
||||
.kb-item-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.checkbox {
|
||||
width: 18px; height: 18px;
|
||||
border-radius: 4px;
|
||||
border: 1.5px solid #d7dadd;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.checkbox.checked {
|
||||
background: #10b981;
|
||||
border-color: #10b981;
|
||||
}
|
||||
.kb-name-wrap { display:flex; flex-direction: column; min-width: 0; }
|
||||
.kb-name { font-size: 13px; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.kb-docs { font-size: 11px; color: #8b9196; margin-top: 2px; }
|
||||
|
||||
.kb-empty { padding: 28px 8px; text-align: center; color: #9aa0a6; font-size: 13px; }
|
||||
|
||||
.kb-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 10px;
|
||||
border-top: 1px solid #f2f4f5;
|
||||
background: #fafcfc;
|
||||
}
|
||||
.kb-btn {
|
||||
flex: 1;
|
||||
padding: 8px 10px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e1e5e6;
|
||||
background: #fff;
|
||||
font-size: 13px;
|
||||
color: #52575a;
|
||||
cursor: pointer;
|
||||
transition: all 0.12s;
|
||||
}
|
||||
.kb-btn:hover {
|
||||
border-color: #10b981;
|
||||
color: #10b981;
|
||||
background: #f0fdf6;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; transform: translateY(-6px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,886 @@
|
||||
<template>
|
||||
<t-dialog
|
||||
v-model:visible="dialogVisible"
|
||||
:header="isEdit ? '编辑模型' : '添加模型'"
|
||||
:width="600"
|
||||
:on-confirm="handleConfirm"
|
||||
:on-cancel="handleCancel"
|
||||
:confirm-btn="{ content: '保存', loading: saving }"
|
||||
>
|
||||
<div class="model-editor-form">
|
||||
<t-form ref="formRef" :data="formData" :rules="rules" layout="vertical">
|
||||
<!-- 模型名称 -->
|
||||
<t-form-item label="模型名称" name="name">
|
||||
<t-input v-model="formData.name" placeholder="为模型取个名字,如:GPT-4" />
|
||||
</t-form-item>
|
||||
|
||||
<!-- 模型来源 -->
|
||||
<t-form-item label="模型来源" name="source">
|
||||
<t-radio-group v-model="formData.source">
|
||||
<t-radio value="local">Ollama (本地)</t-radio>
|
||||
<t-radio value="remote">Remote API (远程)</t-radio>
|
||||
</t-radio-group>
|
||||
</t-form-item>
|
||||
|
||||
<!-- VLLM 专用:接口类型(在来源选择之后) -->
|
||||
<template v-if="modelType === 'vllm' && formData.source === 'local'">
|
||||
<t-form-item label="接口类型" name="interfaceType">
|
||||
<t-radio-group v-model="formData.interfaceType">
|
||||
<t-radio value="ollama">Ollama</t-radio>
|
||||
<t-radio value="openai">OpenAI 兼容接口</t-radio>
|
||||
</t-radio-group>
|
||||
</t-form-item>
|
||||
</template>
|
||||
|
||||
<!-- Ollama 本地模型选择器 -->
|
||||
<t-form-item v-if="formData.source === 'local' && modelType !== 'vllm'" label="模型标识" name="modelName">
|
||||
<t-select
|
||||
v-model="formData.modelName"
|
||||
:loading="loadingOllamaModels"
|
||||
:class="{ 'downloading': downloading }"
|
||||
:style="downloading ? `--progress: ${downloadProgress}%` : ''"
|
||||
filterable
|
||||
:filter="handleModelFilter"
|
||||
placeholder="搜索模型..."
|
||||
@focus="loadOllamaModels"
|
||||
@visible-change="handleDropdownVisibleChange"
|
||||
>
|
||||
<!-- 已下载的模型 -->
|
||||
<t-option
|
||||
v-for="model in filteredOllamaModels"
|
||||
:key="model.name"
|
||||
:value="model.name"
|
||||
:label="model.name"
|
||||
>
|
||||
<div class="model-option">
|
||||
<t-icon name="check-circle-filled" class="downloaded-icon" />
|
||||
<span class="model-name">{{ model.name }}</span>
|
||||
<span class="model-size">{{ formatModelSize(model.size) }}</span>
|
||||
</div>
|
||||
</t-option>
|
||||
|
||||
<!-- 下载新模型选项(仅当搜索词不在列表中时显示) -->
|
||||
<t-option
|
||||
v-if="showDownloadOption"
|
||||
:value="`__download__${searchKeyword}`"
|
||||
:label="`下载: ${searchKeyword}`"
|
||||
class="download-option"
|
||||
>
|
||||
<div class="model-option download">
|
||||
<t-icon name="download" class="download-icon" />
|
||||
<span class="model-name">下载: {{ searchKeyword }}</span>
|
||||
</div>
|
||||
</t-option>
|
||||
|
||||
<!-- 下载进度后缀 -->
|
||||
<template v-if="downloading" #suffix>
|
||||
<div class="download-suffix">
|
||||
<t-icon name="loading" class="spinning" />
|
||||
<span class="progress-text">{{ downloadProgress.toFixed(1) }}%</span>
|
||||
</div>
|
||||
</template>
|
||||
</t-select>
|
||||
|
||||
<!-- 刷新按钮 -->
|
||||
<t-button
|
||||
variant="text"
|
||||
size="small"
|
||||
:loading="loadingOllamaModels"
|
||||
@click="refreshOllamaModels"
|
||||
class="refresh-btn"
|
||||
>
|
||||
<t-icon name="refresh" />
|
||||
刷新列表
|
||||
</t-button>
|
||||
</t-form-item>
|
||||
|
||||
<!-- Remote API 和 VLLM 保持原有的 input -->
|
||||
<t-form-item v-else label="模型标识" name="modelName">
|
||||
<t-input
|
||||
v-model="formData.modelName"
|
||||
:placeholder="formData.source === 'local' ? '如:llava:latest' : '如:gpt-4, claude-3-opus'"
|
||||
/>
|
||||
</t-form-item>
|
||||
|
||||
<!-- Remote API 配置或 VLLM OpenAI 兼容接口 -->
|
||||
<template v-if="formData.source === 'remote' || (modelType === 'vllm' && formData.interfaceType === 'openai')">
|
||||
<t-form-item label="Base URL" name="baseUrl">
|
||||
<t-input
|
||||
v-model="formData.baseUrl"
|
||||
:placeholder="modelType === 'vllm' ? '如:http://localhost:11434/v1' : '如:https://api.openai.com/v1'"
|
||||
/>
|
||||
</t-form-item>
|
||||
|
||||
<t-form-item label="API Key (可选)" name="apiKey">
|
||||
<t-input
|
||||
v-model="formData.apiKey"
|
||||
type="password"
|
||||
placeholder="输入 API Key"
|
||||
/>
|
||||
</t-form-item>
|
||||
|
||||
<!-- Remote API 校验 -->
|
||||
<t-form-item label="连接测试">
|
||||
<div class="api-test-section">
|
||||
<t-button
|
||||
variant="outline"
|
||||
@click="checkRemoteAPI"
|
||||
:loading="checking"
|
||||
:disabled="!formData.modelName || !formData.baseUrl"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon
|
||||
v-if="!checking && remoteChecked && remoteAvailable"
|
||||
name="check-circle-filled"
|
||||
class="status-icon available"
|
||||
/>
|
||||
<t-icon
|
||||
v-else-if="!checking && remoteChecked && !remoteAvailable"
|
||||
name="close-circle-filled"
|
||||
class="status-icon unavailable"
|
||||
/>
|
||||
</template>
|
||||
{{ checking ? '测试中...' : '测试连接' }}
|
||||
</t-button>
|
||||
<span v-if="remoteChecked" :class="['test-message', remoteAvailable ? 'success' : 'error']">
|
||||
{{ remoteMessage }}
|
||||
</span>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</template>
|
||||
|
||||
<!-- Embedding 专用:维度 -->
|
||||
<t-form-item v-if="modelType === 'embedding'" label="向量维度" name="dimension">
|
||||
<t-input-number
|
||||
v-model="formData.dimension"
|
||||
:min="128"
|
||||
:max="4096"
|
||||
placeholder="如:1536"
|
||||
/>
|
||||
</t-form-item>
|
||||
|
||||
<!-- 设为默认 -->
|
||||
<t-form-item label=" " name="isDefault">
|
||||
<t-checkbox v-model="formData.isDefault">设为默认模型</t-checkbox>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</div>
|
||||
</t-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed, onUnmounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { checkOllamaModels, checkRemoteModel, testEmbeddingModel, checkRerankModel, listOllamaModels, downloadOllamaModel, getDownloadProgress, type OllamaModelInfo } from '@/api/initialization'
|
||||
|
||||
interface ModelFormData {
|
||||
id: string
|
||||
name: string
|
||||
source: 'local' | 'remote'
|
||||
modelName: string
|
||||
baseUrl?: string
|
||||
apiKey?: string
|
||||
dimension?: number
|
||||
interfaceType?: 'ollama' | 'openai'
|
||||
isDefault: boolean
|
||||
}
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
modelType: 'chat' | 'embedding' | 'rerank' | 'vllm'
|
||||
modelData?: ModelFormData | null
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
visible: false,
|
||||
modelData: null
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:visible': [value: boolean]
|
||||
'confirm': [data: ModelFormData]
|
||||
}>()
|
||||
|
||||
const dialogVisible = computed({
|
||||
get: () => props.visible,
|
||||
set: (val) => emit('update:visible', val)
|
||||
})
|
||||
|
||||
const isEdit = computed(() => !!props.modelData)
|
||||
|
||||
const formRef = ref()
|
||||
const saving = ref(false)
|
||||
const modelChecked = ref(false)
|
||||
const modelAvailable = ref(false)
|
||||
const checking = ref(false)
|
||||
const remoteChecked = ref(false)
|
||||
const remoteAvailable = ref(false)
|
||||
const remoteMessage = ref('')
|
||||
|
||||
// Ollama 模型状态
|
||||
const ollamaModelList = ref<OllamaModelInfo[]>([])
|
||||
const loadingOllamaModels = ref(false)
|
||||
const searchKeyword = ref('')
|
||||
const downloading = ref(false)
|
||||
const downloadProgress = ref(0)
|
||||
const currentDownloadModel = ref('')
|
||||
let downloadInterval: any = null
|
||||
|
||||
const formData = ref<ModelFormData>({
|
||||
id: '',
|
||||
name: '',
|
||||
source: 'local',
|
||||
modelName: '',
|
||||
baseUrl: '',
|
||||
apiKey: '',
|
||||
dimension: 1536,
|
||||
interfaceType: 'ollama',
|
||||
isDefault: false
|
||||
})
|
||||
|
||||
const rules = {
|
||||
name: [{ required: true, message: '请输入模型名称' }],
|
||||
modelName: [{ required: true, message: '请输入模型标识' }],
|
||||
baseUrl: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入 Base URL',
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// 监听 visible 变化,初始化表单
|
||||
watch(() => props.visible, (val) => {
|
||||
if (val) {
|
||||
if (props.modelData) {
|
||||
formData.value = { ...props.modelData }
|
||||
} else {
|
||||
resetForm()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 重置表单
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: generateId(),
|
||||
name: '',
|
||||
source: 'local',
|
||||
modelName: '',
|
||||
baseUrl: '',
|
||||
apiKey: '',
|
||||
dimension: props.modelType === 'embedding' ? 1536 : undefined,
|
||||
interfaceType: props.modelType === 'vllm' ? 'ollama' : undefined,
|
||||
isDefault: false
|
||||
}
|
||||
modelChecked.value = false
|
||||
modelAvailable.value = false
|
||||
remoteChecked.value = false
|
||||
remoteAvailable.value = false
|
||||
remoteMessage.value = ''
|
||||
}
|
||||
|
||||
// 监听来源变化,重置校验状态(已合并到下面的 watch)
|
||||
|
||||
// 生成唯一ID
|
||||
const generateId = () => {
|
||||
return `model_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
|
||||
}
|
||||
|
||||
// 过滤后的模型列表
|
||||
const filteredOllamaModels = computed(() => {
|
||||
if (!searchKeyword.value) return ollamaModelList.value
|
||||
return ollamaModelList.value.filter(model =>
|
||||
model.name.toLowerCase().includes(searchKeyword.value.toLowerCase())
|
||||
)
|
||||
})
|
||||
|
||||
// 是否显示"下载模型"选项
|
||||
const showDownloadOption = computed(() => {
|
||||
if (!searchKeyword.value.trim()) return false
|
||||
// 检查搜索词是否已存在于模型列表中
|
||||
const exists = ollamaModelList.value.some(model =>
|
||||
model.name.toLowerCase() === searchKeyword.value.toLowerCase()
|
||||
)
|
||||
return !exists
|
||||
})
|
||||
|
||||
// 自定义过滤逻辑(捕获搜索关键词)
|
||||
const handleModelFilter = (filterWords: string) => {
|
||||
searchKeyword.value = filterWords
|
||||
return true // 让 TDesign 使用我们的 filteredOllamaModels
|
||||
}
|
||||
|
||||
// 加载 Ollama 模型列表
|
||||
const loadOllamaModels = async () => {
|
||||
if (formData.value.source !== 'local') return
|
||||
|
||||
loadingOllamaModels.value = true
|
||||
try {
|
||||
const models = await listOllamaModels()
|
||||
ollamaModelList.value = models
|
||||
} catch (error) {
|
||||
console.error('加载 Ollama 模型列表失败:', error)
|
||||
MessagePlugin.error('加载模型列表失败')
|
||||
} finally {
|
||||
loadingOllamaModels.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新模型列表
|
||||
const refreshOllamaModels = async () => {
|
||||
ollamaModelList.value = [] // 清空以强制重新加载
|
||||
await loadOllamaModels()
|
||||
MessagePlugin.success('列表已刷新')
|
||||
}
|
||||
|
||||
// 监听下拉框可见性变化
|
||||
const handleDropdownVisibleChange = (visible: boolean) => {
|
||||
if (!visible) {
|
||||
searchKeyword.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化模型大小
|
||||
const formatModelSize = (bytes: number): string => {
|
||||
if (!bytes || bytes === 0) return ''
|
||||
const gb = bytes / (1024 * 1024 * 1024)
|
||||
return gb >= 1 ? `${gb.toFixed(1)} GB` : `${(bytes / (1024 * 1024)).toFixed(0)} MB`
|
||||
}
|
||||
|
||||
// 检查模型状态(Ollama本地模型)
|
||||
const checkModelStatus = async () => {
|
||||
if (!formData.value.modelName || formData.value.source !== 'local') {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 调用真实 Ollama API 检查模型是否存在
|
||||
const result = await checkOllamaModels([formData.value.modelName])
|
||||
modelChecked.value = true
|
||||
modelAvailable.value = result.models[formData.value.modelName] || false
|
||||
} catch (error) {
|
||||
console.error('检查模型状态失败:', error)
|
||||
modelChecked.value = false
|
||||
modelAvailable.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 检查 Remote API 连接(根据模型类型调用不同的接口)
|
||||
const checkRemoteAPI = async () => {
|
||||
if (!formData.value.modelName || !formData.value.baseUrl) {
|
||||
MessagePlugin.warning('请先填写模型标识和 Base URL')
|
||||
return
|
||||
}
|
||||
|
||||
checking.value = true
|
||||
remoteChecked.value = false
|
||||
remoteMessage.value = ''
|
||||
|
||||
try {
|
||||
let result: any
|
||||
|
||||
// 根据模型类型调用不同的校验接口
|
||||
switch (props.modelType) {
|
||||
case 'chat':
|
||||
// 对话模型(KnowledgeQA)
|
||||
result = await checkRemoteModel({
|
||||
modelName: formData.value.modelName,
|
||||
baseUrl: formData.value.baseUrl,
|
||||
apiKey: formData.value.apiKey || ''
|
||||
})
|
||||
break
|
||||
|
||||
case 'embedding':
|
||||
// Embedding 模型
|
||||
result = await testEmbeddingModel({
|
||||
source: 'remote',
|
||||
modelName: formData.value.modelName,
|
||||
baseUrl: formData.value.baseUrl,
|
||||
apiKey: formData.value.apiKey || '',
|
||||
dimension: formData.value.dimension
|
||||
})
|
||||
// 如果测试成功且返回了维度,自动填充
|
||||
if (result.available && result.dimension) {
|
||||
formData.value.dimension = result.dimension
|
||||
MessagePlugin.info(`检测到向量维度:${result.dimension}`)
|
||||
}
|
||||
break
|
||||
|
||||
case 'rerank':
|
||||
// Rerank 模型
|
||||
result = await checkRerankModel({
|
||||
modelName: formData.value.modelName,
|
||||
baseUrl: formData.value.baseUrl,
|
||||
apiKey: formData.value.apiKey || ''
|
||||
})
|
||||
break
|
||||
|
||||
case 'vllm':
|
||||
// VLLM 模型(多模态)
|
||||
// VLLM 使用 checkRemoteModel 进行基础连接测试
|
||||
result = await checkRemoteModel({
|
||||
modelName: formData.value.modelName,
|
||||
baseUrl: formData.value.baseUrl,
|
||||
apiKey: formData.value.apiKey || ''
|
||||
})
|
||||
break
|
||||
|
||||
default:
|
||||
MessagePlugin.error('不支持的模型类型')
|
||||
return
|
||||
}
|
||||
|
||||
remoteChecked.value = true
|
||||
remoteAvailable.value = result.available || false
|
||||
remoteMessage.value = result.message || (result.available ? '连接成功' : '连接失败')
|
||||
|
||||
if (result.available) {
|
||||
MessagePlugin.success(remoteMessage.value)
|
||||
} else {
|
||||
MessagePlugin.error(remoteMessage.value)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Remote API 校验失败:', error)
|
||||
remoteChecked.value = true
|
||||
remoteAvailable.value = false
|
||||
remoteMessage.value = error.message || '连接失败,请检查配置'
|
||||
MessagePlugin.error(remoteMessage.value)
|
||||
} finally {
|
||||
checking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 确认保存
|
||||
const handleConfirm = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
saving.value = true
|
||||
|
||||
// 如果是新增且没有 id,生成一个
|
||||
if (!formData.value.id) {
|
||||
formData.value.id = generateId()
|
||||
}
|
||||
|
||||
emit('confirm', { ...formData.value })
|
||||
dialogVisible.value = false
|
||||
MessagePlugin.success(isEdit.value ? '模型已更新' : '模型已添加')
|
||||
} catch (error) {
|
||||
console.error('表单验证失败:', error)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 监听模型选择变化(处理下载逻辑)
|
||||
watch(() => formData.value.modelName, async (newValue) => {
|
||||
if (!newValue || !newValue.startsWith('__download__')) return
|
||||
|
||||
// 提取模型名称
|
||||
const modelName = newValue.replace('__download__', '')
|
||||
|
||||
// 重置选择(避免显示 __download__ 前缀)
|
||||
formData.value.modelName = ''
|
||||
|
||||
// 开始下载
|
||||
await startDownload(modelName)
|
||||
})
|
||||
|
||||
// 开始下载模型
|
||||
const startDownload = async (modelName: string) => {
|
||||
downloading.value = true
|
||||
downloadProgress.value = 0
|
||||
currentDownloadModel.value = modelName
|
||||
|
||||
try {
|
||||
// 启动下载
|
||||
const result = await downloadOllamaModel(modelName)
|
||||
const taskId = result.taskId
|
||||
|
||||
MessagePlugin.success(`开始下载 ${modelName}`)
|
||||
|
||||
// 轮询下载进度
|
||||
downloadInterval = setInterval(async () => {
|
||||
try {
|
||||
const progress = await getDownloadProgress(taskId)
|
||||
downloadProgress.value = progress.progress
|
||||
|
||||
if (progress.status === 'completed') {
|
||||
// 下载完成
|
||||
clearInterval(downloadInterval)
|
||||
downloadInterval = null
|
||||
downloading.value = false
|
||||
|
||||
MessagePlugin.success(`${modelName} 下载完成`)
|
||||
|
||||
// 刷新模型列表
|
||||
await loadOllamaModels()
|
||||
|
||||
// 自动选中新下载的模型
|
||||
formData.value.modelName = modelName
|
||||
|
||||
// 重置状态
|
||||
downloadProgress.value = 0
|
||||
currentDownloadModel.value = ''
|
||||
|
||||
} else if (progress.status === 'failed') {
|
||||
// 下载失败
|
||||
clearInterval(downloadInterval)
|
||||
downloadInterval = null
|
||||
downloading.value = false
|
||||
MessagePlugin.error(progress.message || `${modelName} 下载失败`)
|
||||
downloadProgress.value = 0
|
||||
currentDownloadModel.value = ''
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取下载进度失败:', error)
|
||||
}
|
||||
}, 1000) // 每秒查询一次
|
||||
|
||||
} catch (error: any) {
|
||||
downloading.value = false
|
||||
downloadProgress.value = 0
|
||||
currentDownloadModel.value = ''
|
||||
MessagePlugin.error(error.message || '启动下载失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 组件卸载时清理定时器
|
||||
onUnmounted(() => {
|
||||
if (downloadInterval) {
|
||||
clearInterval(downloadInterval)
|
||||
}
|
||||
})
|
||||
|
||||
// 监听来源变化,清理所有状态
|
||||
watch(() => formData.value.source, () => {
|
||||
// 重置校验状态
|
||||
modelChecked.value = false
|
||||
modelAvailable.value = false
|
||||
remoteChecked.value = false
|
||||
remoteAvailable.value = false
|
||||
remoteMessage.value = ''
|
||||
|
||||
// 清理下载状态
|
||||
searchKeyword.value = ''
|
||||
if (downloadInterval) {
|
||||
clearInterval(downloadInterval)
|
||||
downloadInterval = null
|
||||
}
|
||||
downloading.value = false
|
||||
downloadProgress.value = 0
|
||||
currentDownloadModel.value = ''
|
||||
})
|
||||
|
||||
// 取消
|
||||
const handleCancel = () => {
|
||||
dialogVisible.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.model-editor-form {
|
||||
padding: 8px 0;
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
|
||||
// 自定义滚动条
|
||||
&::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: #f5f5f5;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: #d0d0d0;
|
||||
border-radius: 3px;
|
||||
|
||||
&:hover {
|
||||
background: #b0b0b0;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-form-item) {
|
||||
margin-bottom: 18px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-form-item__label) {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
padding-bottom: 6px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
:deep(.t-input),
|
||||
:deep(.t-select),
|
||||
:deep(.t-textarea),
|
||||
:deep(.t-input-number) {
|
||||
font-size: 13px;
|
||||
background: #ffffff;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 6px;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: #07C05F;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
&:focus,
|
||||
&.t-is-focused {
|
||||
background: #ffffff;
|
||||
border-color: #07C05F;
|
||||
box-shadow: 0 0 0 2px rgba(7, 192, 95, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-input__inner) {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
:deep(.t-radio-group) {
|
||||
.t-radio {
|
||||
margin-right: 16px;
|
||||
font-size: 13px;
|
||||
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.t-radio__label {
|
||||
font-size: 13px;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-checkbox) {
|
||||
font-size: 13px;
|
||||
|
||||
.t-checkbox__label {
|
||||
font-size: 13px;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.model-input-with-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
:deep(.t-input) {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.available {
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
&.unavailable {
|
||||
color: #e34d59;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.download-hint {
|
||||
margin-top: -10px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
:deep(.t-alert) {
|
||||
padding: 8px 12px;
|
||||
font-size: 12px;
|
||||
border-radius: 6px;
|
||||
background: #fff7e6;
|
||||
border-color: #ffa940;
|
||||
}
|
||||
}
|
||||
|
||||
.api-test-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
.test-message {
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
|
||||
&.success {
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: #e34d59;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-button) {
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
|
||||
// 优化对话框样式
|
||||
:deep(.t-dialog) {
|
||||
border-radius: 12px;
|
||||
|
||||
.t-dialog__header {
|
||||
padding: 20px 24px 16px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
|
||||
.t-dialog__header-content {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
|
||||
.t-dialog__body {
|
||||
padding: 20px 24px;
|
||||
}
|
||||
|
||||
.t-dialog__footer {
|
||||
padding: 12px 24px 20px;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
|
||||
.t-button {
|
||||
font-size: 13px;
|
||||
padding: 6px 16px;
|
||||
border-radius: 6px;
|
||||
|
||||
&.t-button--theme-primary {
|
||||
background: #07C05F;
|
||||
border-color: #07C05F;
|
||||
|
||||
&:hover {
|
||||
background: #05a34e;
|
||||
border-color: #05a34e;
|
||||
}
|
||||
}
|
||||
|
||||
&.t-button--variant-outline {
|
||||
&:hover {
|
||||
border-color: #07C05F;
|
||||
color: #07C05F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ollama 模型选择器样式
|
||||
.model-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 4px 0;
|
||||
|
||||
.downloaded-icon {
|
||||
font-size: 14px;
|
||||
color: #07C05F;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.download-icon {
|
||||
font-size: 14px;
|
||||
color: #07C05F;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.model-name {
|
||||
flex: 1;
|
||||
font-size: 13px;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.model-size {
|
||||
font-size: 12px;
|
||||
color: #999999;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
&.download {
|
||||
.model-name {
|
||||
color: #07C05F;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 下载进度后缀样式
|
||||
.download-suffix {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 0 4px;
|
||||
|
||||
.spinning {
|
||||
animation: spin 1s linear infinite;
|
||||
font-size: 14px;
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: #07C05F;
|
||||
}
|
||||
}
|
||||
|
||||
// 下载中的选择框进度条效果
|
||||
:deep(.t-select.downloading) {
|
||||
.t-input {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: var(--progress, 0%);
|
||||
background: linear-gradient(90deg, rgba(7, 192, 95, 0.08), rgba(7, 192, 95, 0.15));
|
||||
transition: width 0.3s ease;
|
||||
z-index: 0;
|
||||
border-radius: 5px 0 0 5px;
|
||||
}
|
||||
|
||||
.t-input__inner,
|
||||
input {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: #666666;
|
||||
|
||||
&:hover {
|
||||
color: #07C05F;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
<template>
|
||||
<div class="user-menu" ref="menuRef">
|
||||
<!-- 用户按钮 -->
|
||||
<div class="user-button" @click="toggleMenu">
|
||||
<div class="user-avatar">
|
||||
<img v-if="userAvatar" :src="userAvatar" alt="用户头像" />
|
||||
<span v-else class="avatar-placeholder">{{ userInitial }}</span>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="user-name">{{ userName }}</div>
|
||||
<div class="user-email">{{ userEmail }}</div>
|
||||
</div>
|
||||
<t-icon :name="menuVisible ? 'chevron-up' : 'chevron-down'" class="dropdown-icon" />
|
||||
</div>
|
||||
|
||||
<!-- 下拉菜单 -->
|
||||
<Transition name="dropdown">
|
||||
<div v-if="menuVisible" class="user-dropdown" @click.stop>
|
||||
<div class="menu-item" @click="handleQuickNav('models')">
|
||||
<t-icon name="component" class="menu-icon" />
|
||||
<span>模型配置</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="handleQuickNav('ollama')">
|
||||
<span class="menu-icon emoji-icon">🦙</span>
|
||||
<span>Ollama</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="handleQuickNav('knowledge')">
|
||||
<t-icon name="layers" class="menu-icon" />
|
||||
<span>知识库</span>
|
||||
</div>
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item" @click="handleSettings">
|
||||
<t-icon name="setting" class="menu-icon" />
|
||||
<span>全部设置</span>
|
||||
</div>
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item danger" @click="handleLogout">
|
||||
<t-icon name="logout" class="menu-icon" />
|
||||
<span>注销</span>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { getCurrentUser } from '@/api/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const uiStore = useUIStore()
|
||||
|
||||
const menuRef = ref<HTMLElement>()
|
||||
const menuVisible = ref(false)
|
||||
|
||||
// 用户信息
|
||||
const userInfo = ref({
|
||||
username: '用户',
|
||||
email: 'user@example.com',
|
||||
avatar: ''
|
||||
})
|
||||
|
||||
const userName = computed(() => userInfo.value.username)
|
||||
const userEmail = computed(() => userInfo.value.email)
|
||||
const userAvatar = computed(() => userInfo.value.avatar)
|
||||
|
||||
// 用户名首字母(用于无头像时显示)
|
||||
const userInitial = computed(() => {
|
||||
return userName.value.charAt(0).toUpperCase()
|
||||
})
|
||||
|
||||
// 切换菜单显示
|
||||
const toggleMenu = () => {
|
||||
menuVisible.value = !menuVisible.value
|
||||
}
|
||||
|
||||
// 快捷导航到设置的特定部分
|
||||
const handleQuickNav = (section: string) => {
|
||||
menuVisible.value = false
|
||||
uiStore.openSettings()
|
||||
router.push('/platform/settings')
|
||||
|
||||
// 延迟一下,确保设置页面已经渲染
|
||||
setTimeout(() => {
|
||||
// 触发设置页面切换到对应section
|
||||
const event = new CustomEvent('settings-nav', { detail: { section } })
|
||||
window.dispatchEvent(event)
|
||||
}, 100)
|
||||
}
|
||||
|
||||
// 打开设置
|
||||
const handleSettings = () => {
|
||||
menuVisible.value = false
|
||||
uiStore.openSettings()
|
||||
router.push('/platform/settings')
|
||||
}
|
||||
|
||||
// 注销
|
||||
const handleLogout = () => {
|
||||
menuVisible.value = false
|
||||
|
||||
// 清理本地存储
|
||||
localStorage.removeItem('WeKnora_token')
|
||||
|
||||
MessagePlugin.success('已退出登录')
|
||||
|
||||
// 跳转到登录页
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
// 加载用户信息
|
||||
const loadUserInfo = async () => {
|
||||
try {
|
||||
const response = await getCurrentUser()
|
||||
if (response.success && response.data && response.data.user) {
|
||||
userInfo.value = {
|
||||
username: response.data.user.username || '用户',
|
||||
email: response.data.user.email || 'user@example.com',
|
||||
avatar: response.data.user.avatar || ''
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load user info:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 点击外部关闭菜单
|
||||
const handleClickOutside = (e: MouseEvent) => {
|
||||
if (menuRef.value && !menuRef.value.contains(e.target as Node)) {
|
||||
menuVisible.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('click', handleClickOutside)
|
||||
loadUserInfo()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('click', handleClickOutside)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.user-menu {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.user-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
background: transparent;
|
||||
|
||||
&:hover {
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
}
|
||||
|
||||
.user-avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, #07C05F 0%, #05A34E 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.avatar-placeholder {
|
||||
color: #ffffff;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.user-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
text-align: left;
|
||||
|
||||
.user-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.user-email {
|
||||
font-size: 12px;
|
||||
color: #666666;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown-icon {
|
||||
font-size: 16px;
|
||||
color: #666666;
|
||||
flex-shrink: 0;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.user-dropdown {
|
||||
position: absolute;
|
||||
bottom: 100%;
|
||||
left: 8px;
|
||||
right: 8px;
|
||||
margin-bottom: 8px;
|
||||
background: #ffffff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
|
||||
border: 1px solid #e5e7eb;
|
||||
overflow: hidden;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
font-size: 14px;
|
||||
color: #333333;
|
||||
|
||||
&:hover {
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
&.danger {
|
||||
color: #e34d59;
|
||||
|
||||
&:hover {
|
||||
background: #fef0f0;
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
color: #e34d59;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
font-size: 16px;
|
||||
color: #666666;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-divider {
|
||||
height: 1px;
|
||||
background: #e5e7eb;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.emoji-icon {
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
// 下拉动画
|
||||
.dropdown-enter-active,
|
||||
.dropdown-leave-active {
|
||||
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.dropdown-enter-from,
|
||||
.dropdown-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(8px);
|
||||
}
|
||||
|
||||
.dropdown-enter-to,
|
||||
.dropdown-leave-from {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -75,38 +75,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 下半部分:账户信息、系统设置、退出登录 -->
|
||||
<!-- 下半部分:用户菜单 -->
|
||||
<div class="menu_bottom">
|
||||
<div class="menu_box" v-for="(item, index) in bottomMenuItems" :key="'bottom-' + index">
|
||||
<div v-if="item.path === 'logout'">
|
||||
<t-popconfirm
|
||||
content="确定要退出登录吗?"
|
||||
@confirm="handleLogout"
|
||||
placement="top"
|
||||
:show-arrow="true"
|
||||
>
|
||||
<div @mouseenter="mouseenteMenu(item.path)" @mouseleave="mouseleaveMenu(item.path)"
|
||||
:class="['menu_item', 'logout-item']">
|
||||
<div class="menu_item-box">
|
||||
<div class="menu_icon">
|
||||
<img class="icon" :src="getImgSrc(logoutIcon)" alt="">
|
||||
</div>
|
||||
<span class="menu_title">{{ item.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-popconfirm>
|
||||
</div>
|
||||
<div v-else @click="handleMenuClick(item.path)"
|
||||
@mouseenter="mouseenteMenu(item.path)" @mouseleave="mouseleaveMenu(item.path)"
|
||||
:class="['menu_item', item.childrenPath && item.childrenPath == currentpath ? 'menu_item_c_active' : (item.path == currentpath) ? 'menu_item_active' : '']">
|
||||
<div class="menu_item-box">
|
||||
<div class="menu_icon">
|
||||
<img class="icon" :src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'tenant' ? tenantIcon : prefixIcon)" alt="">
|
||||
</div>
|
||||
<span class="menu_title">{{ item.path === 'knowledge-bases' && kbMenuItem ? kbMenuItem.title : item.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<UserMenu />
|
||||
</div>
|
||||
|
||||
<input type="file" @change="upload" style="display: none" ref="uploadInput"
|
||||
@@ -123,10 +94,13 @@ import { getKnowledgeBaseById, listKnowledgeBases, uploadKnowledgeFile } from '@
|
||||
import { kbFileTypeVerification } from '@/utils/index';
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import UserMenu from '@/components/UserMenu.vue';
|
||||
let uploadInput = ref();
|
||||
const usemenuStore = useMenuStore();
|
||||
const authStore = useAuthStore();
|
||||
const uiStore = useUIStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const currentpath = ref('');
|
||||
@@ -160,9 +134,9 @@ const isMenuItemActive = (itemPath: string): boolean => {
|
||||
currentRoute === 'knowledgeBaseDetail' ||
|
||||
currentRoute === 'knowledgeBaseSettings';
|
||||
case 'creatChat':
|
||||
return currentRoute === 'kbCreatChat';
|
||||
case 'tenant':
|
||||
return currentRoute === 'tenant';
|
||||
return currentRoute === 'kbCreatChat' || currentRoute === 'globalCreatChat';
|
||||
case 'settings':
|
||||
return currentRoute === 'settings';
|
||||
default:
|
||||
return itemPath === currentpath.value;
|
||||
}
|
||||
@@ -178,8 +152,8 @@ const getIconActiveState = (itemPath: string) => {
|
||||
currentRoute === 'knowledgeBaseDetail' ||
|
||||
currentRoute === 'knowledgeBaseSettings'
|
||||
),
|
||||
isCreatChatActive: itemPath === 'creatChat' && currentRoute === 'kbCreatChat',
|
||||
isTenantActive: itemPath === 'tenant' && currentRoute === 'tenant',
|
||||
isCreatChatActive: itemPath === 'creatChat' && (currentRoute === 'kbCreatChat' || currentRoute === 'globalCreatChat'),
|
||||
isSettingsActive: itemPath === 'settings' && currentRoute === 'settings',
|
||||
isChatActive: itemPath === 'chat' && currentRoute === 'chat'
|
||||
};
|
||||
};
|
||||
@@ -187,7 +161,7 @@ const getIconActiveState = (itemPath: string) => {
|
||||
// 分离上下两部分菜单
|
||||
const topMenuItems = computed<MenuItem[]>(() => {
|
||||
return (menuArr.value as unknown as MenuItem[]).filter((item: MenuItem) =>
|
||||
item.path === 'knowledge-bases' || (isInKnowledgeBase.value && item.path === 'creatChat')
|
||||
item.path === 'knowledge-bases' || item.path === 'creatChat'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -430,13 +404,13 @@ let fileAddIcon = ref('file-add-green.svg');
|
||||
let knowledgeIcon = ref('zhishiku-green.svg');
|
||||
let prefixIcon = ref('prefixIcon.svg');
|
||||
let logoutIcon = ref('logout.svg');
|
||||
let tenantIcon = ref('user.svg'); // 使用专门的用户图标
|
||||
let settingIcon = ref('setting.svg'); // 设置图标
|
||||
let pathPrefix = ref(route.name)
|
||||
const getIcon = (path: string) => {
|
||||
// 根据当前路由状态更新所有图标
|
||||
const kbActiveState = getIconActiveState('knowledge-bases');
|
||||
const creatChatActiveState = getIconActiveState('creatChat');
|
||||
const tenantActiveState = getIconActiveState('tenant');
|
||||
const settingsActiveState = getIconActiveState('settings');
|
||||
|
||||
// 上传图标:只在知识库相关页面显示绿色
|
||||
fileAddIcon.value = kbActiveState.isKbActive ? 'file-add-green.svg' : 'file-add.svg';
|
||||
@@ -449,8 +423,8 @@ let pathPrefix = ref(route.name)
|
||||
kbActiveState.isKbActive ? 'prefixIcon-grey.svg' :
|
||||
'prefixIcon.svg';
|
||||
|
||||
// 租户图标:只在租户页面显示绿色
|
||||
tenantIcon.value = tenantActiveState.isTenantActive ? 'user-green.svg' : 'user.svg';
|
||||
// 设置图标:只在设置页面显示绿色
|
||||
settingIcon.value = settingsActiveState.isSettingsActive ? 'setting-green.svg' : 'setting.svg';
|
||||
|
||||
// 退出图标:始终显示默认
|
||||
logoutIcon.value = 'logout.svg';
|
||||
@@ -465,6 +439,10 @@ const handleMenuClick = async (path: string) => {
|
||||
} else {
|
||||
router.push('/platform/knowledge-bases')
|
||||
}
|
||||
} else if (path === 'settings') {
|
||||
// 设置菜单项:打开设置弹窗并跳转路由
|
||||
uiStore.openSettings()
|
||||
router.push('/platform/settings')
|
||||
} else {
|
||||
gotopage(path)
|
||||
}
|
||||
@@ -493,11 +471,14 @@ const gotopage = async (path: string) => {
|
||||
return;
|
||||
} else {
|
||||
if (path === 'creatChat') {
|
||||
// 尝试获取当前知识库ID
|
||||
const kbId = await getCurrentKbId()
|
||||
if (kbId) {
|
||||
// 如果在知识库内部,进入该知识库的对话页
|
||||
router.push(`/platform/knowledge-bases/${kbId}/creatChat`)
|
||||
} else {
|
||||
router.push(`/platform/knowledge-bases`)
|
||||
// 如果不在知识库内,也进入对话创建页,让用户通过 @ 按钮选择知识库
|
||||
router.push(`/platform/creatChat`)
|
||||
}
|
||||
} else {
|
||||
router.push(`/platform/${path}`);
|
||||
|
||||
@@ -31,8 +31,12 @@ const router = createRouter({
|
||||
children: [
|
||||
{
|
||||
path: "tenant",
|
||||
name: "tenant",
|
||||
component: () => import("../views/tenant/TenantInfo.vue"),
|
||||
redirect: "/platform/settings"
|
||||
},
|
||||
{
|
||||
path: "settings",
|
||||
name: "settings",
|
||||
component: () => import("../views/settings/Settings.vue"),
|
||||
meta: { requiresInit: true, requiresAuth: true }
|
||||
},
|
||||
{
|
||||
@@ -47,6 +51,12 @@ const router = createRouter({
|
||||
component: () => import("../views/knowledge/KnowledgeBase.vue"),
|
||||
meta: { requiresInit: true, requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: "creatChat",
|
||||
name: "globalCreatChat",
|
||||
component: () => import("../views/creatChat/creatChat.vue"),
|
||||
meta: { requiresInit: true, requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: "knowledge-bases/:kbId/creatChat",
|
||||
name: "kbCreatChat",
|
||||
|
||||
@@ -13,7 +13,7 @@ export const useMenuStore = defineStore('menuStore', {
|
||||
childrenPath: 'chat',
|
||||
children: reactive<object[]>([]),
|
||||
},
|
||||
{ title: '系统信息', icon: 'tenant', path: 'tenant' },
|
||||
{ title: '设置', icon: 'setting', path: 'settings' },
|
||||
{ title: '退出登录', icon: 'logout', path: 'logout' }
|
||||
]),
|
||||
isFirstSession: false,
|
||||
|
||||
@@ -5,6 +5,47 @@ interface Settings {
|
||||
endpoint: string;
|
||||
apiKey: string;
|
||||
knowledgeBaseId: string;
|
||||
isAgentEnabled: boolean;
|
||||
agentConfig: AgentConfig;
|
||||
selectedKnowledgeBases: string[]; // 当前选中的知识库ID列表
|
||||
modelConfig: ModelConfig; // 模型配置
|
||||
ollamaConfig: OllamaConfig; // Ollama配置
|
||||
}
|
||||
|
||||
// Agent 配置接口
|
||||
interface AgentConfig {
|
||||
maxIterations: number;
|
||||
temperature: number;
|
||||
thinkingModelId: string;
|
||||
rerankModelId: string;
|
||||
allowedTools: string[];
|
||||
}
|
||||
|
||||
// 单个模型项接口
|
||||
interface ModelItem {
|
||||
id: string; // 唯一ID
|
||||
name: string; // 显示名称
|
||||
source: 'local' | 'remote'; // 模型来源
|
||||
modelName: string; // 模型标识
|
||||
baseUrl?: string; // 远程API URL
|
||||
apiKey?: string; // 远程API Key
|
||||
dimension?: number; // Embedding专用:向量维度
|
||||
interfaceType?: 'ollama' | 'openai'; // VLLM专用:接口类型
|
||||
isDefault?: boolean; // 是否为默认模型
|
||||
}
|
||||
|
||||
// 模型配置接口 - 支持多模型
|
||||
interface ModelConfig {
|
||||
chatModels: ModelItem[];
|
||||
embeddingModels: ModelItem[];
|
||||
rerankModels: ModelItem[];
|
||||
vllmModels: ModelItem[]; // VLLM视觉模型
|
||||
}
|
||||
|
||||
// Ollama 配置接口
|
||||
interface OllamaConfig {
|
||||
baseUrl: string; // Ollama 服务地址
|
||||
enabled: boolean; // 是否启用
|
||||
}
|
||||
|
||||
// 默认设置
|
||||
@@ -12,6 +53,25 @@ const defaultSettings: Settings = {
|
||||
endpoint: import.meta.env.VITE_IS_DOCKER ? "" : "http://localhost:8080",
|
||||
apiKey: "",
|
||||
knowledgeBaseId: "",
|
||||
isAgentEnabled: false,
|
||||
agentConfig: {
|
||||
maxIterations: 5,
|
||||
temperature: 0.7,
|
||||
thinkingModelId: "",
|
||||
rerankModelId: "",
|
||||
allowedTools: ["knowledge_search", "multi_kb_search", "list_knowledge_bases"]
|
||||
},
|
||||
selectedKnowledgeBases: [], // 默认为空数组
|
||||
modelConfig: {
|
||||
chatModels: [],
|
||||
embeddingModels: [],
|
||||
rerankModels: [],
|
||||
vllmModels: []
|
||||
},
|
||||
ollamaConfig: {
|
||||
baseUrl: "http://localhost:11434",
|
||||
enabled: true
|
||||
}
|
||||
};
|
||||
|
||||
export const useSettingsStore = defineStore("settings", {
|
||||
@@ -20,6 +80,17 @@ export const useSettingsStore = defineStore("settings", {
|
||||
settings: JSON.parse(localStorage.getItem("WeKnora_settings") || JSON.stringify(defaultSettings)),
|
||||
}),
|
||||
|
||||
getters: {
|
||||
// Agent 是否启用
|
||||
isAgentEnabled: (state) => state.settings.isAgentEnabled || false,
|
||||
|
||||
// 获取 Agent 配置
|
||||
agentConfig: (state) => state.settings.agentConfig || defaultSettings.agentConfig,
|
||||
|
||||
// 获取模型配置
|
||||
modelConfig: (state) => state.settings.modelConfig || defaultSettings.modelConfig,
|
||||
},
|
||||
|
||||
actions: {
|
||||
// 保存设置
|
||||
saveSettings(settings: Settings) {
|
||||
@@ -47,5 +118,117 @@ export const useSettingsStore = defineStore("settings", {
|
||||
getKnowledgeBaseId(): string {
|
||||
return this.settings.knowledgeBaseId;
|
||||
},
|
||||
|
||||
// 启用/禁用 Agent
|
||||
toggleAgent(enabled: boolean) {
|
||||
this.settings.isAgentEnabled = enabled;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 更新 Agent 配置
|
||||
updateAgentConfig(config: Partial<AgentConfig>) {
|
||||
this.settings.agentConfig = { ...this.settings.agentConfig, ...config };
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 更新模型配置
|
||||
updateModelConfig(config: Partial<ModelConfig>) {
|
||||
this.settings.modelConfig = { ...this.settings.modelConfig, ...config };
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 添加模型
|
||||
addModel(type: 'chat' | 'embedding' | 'rerank' | 'vllm', model: ModelItem) {
|
||||
const key = `${type}Models` as keyof ModelConfig;
|
||||
const models = [...this.settings.modelConfig[key]] as ModelItem[];
|
||||
// 如果设为默认,取消其他模型的默认状态
|
||||
if (model.isDefault) {
|
||||
models.forEach(m => m.isDefault = false);
|
||||
}
|
||||
// 如果是第一个模型,自动设为默认
|
||||
if (models.length === 0) {
|
||||
model.isDefault = true;
|
||||
}
|
||||
models.push(model);
|
||||
this.settings.modelConfig[key] = models as any;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 更新模型
|
||||
updateModel(type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string, updates: Partial<ModelItem>) {
|
||||
const key = `${type}Models` as keyof ModelConfig;
|
||||
const models = [...this.settings.modelConfig[key]] as ModelItem[];
|
||||
const index = models.findIndex(m => m.id === modelId);
|
||||
if (index !== -1) {
|
||||
// 如果要设为默认,取消其他模型的默认状态
|
||||
if (updates.isDefault) {
|
||||
models.forEach(m => m.isDefault = false);
|
||||
}
|
||||
models[index] = { ...models[index], ...updates };
|
||||
this.settings.modelConfig[key] = models as any;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
}
|
||||
},
|
||||
|
||||
// 删除模型
|
||||
deleteModel(type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string) {
|
||||
const key = `${type}Models` as keyof ModelConfig;
|
||||
let models = [...this.settings.modelConfig[key]] as ModelItem[];
|
||||
const deletedModel = models.find(m => m.id === modelId);
|
||||
models = models.filter(m => m.id !== modelId);
|
||||
// 如果删除的是默认模型,设置第一个为默认
|
||||
if (deletedModel?.isDefault && models.length > 0) {
|
||||
models[0].isDefault = true;
|
||||
}
|
||||
this.settings.modelConfig[key] = models as any;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 设置默认模型
|
||||
setDefaultModel(type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string) {
|
||||
const key = `${type}Models` as keyof ModelConfig;
|
||||
const models = [...this.settings.modelConfig[key]] as ModelItem[];
|
||||
models.forEach(m => m.isDefault = (m.id === modelId));
|
||||
this.settings.modelConfig[key] = models as any;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 更新 Ollama 配置
|
||||
updateOllamaConfig(config: Partial<OllamaConfig>) {
|
||||
this.settings.ollamaConfig = { ...this.settings.ollamaConfig, ...config };
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 选择知识库(替换整个列表)
|
||||
selectKnowledgeBases(kbIds: string[]) {
|
||||
this.settings.selectedKnowledgeBases = kbIds;
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 添加单个知识库
|
||||
addKnowledgeBase(kbId: string) {
|
||||
if (!this.settings.selectedKnowledgeBases.includes(kbId)) {
|
||||
this.settings.selectedKnowledgeBases.push(kbId);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
}
|
||||
},
|
||||
|
||||
// 移除单个知识库
|
||||
removeKnowledgeBase(kbId: string) {
|
||||
this.settings.selectedKnowledgeBases =
|
||||
this.settings.selectedKnowledgeBases.filter(id => id !== kbId);
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 清空知识库选择
|
||||
clearKnowledgeBases() {
|
||||
this.settings.selectedKnowledgeBases = [];
|
||||
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
|
||||
},
|
||||
|
||||
// 获取选中的知识库列表
|
||||
getSelectedKnowledgeBases(): string[] {
|
||||
return this.settings.selectedKnowledgeBases || [];
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useUIStore = defineStore('ui', {
|
||||
state: () => ({
|
||||
showSettingsModal: false
|
||||
}),
|
||||
|
||||
actions: {
|
||||
openSettings() {
|
||||
this.showSettingsModal = true
|
||||
},
|
||||
|
||||
closeSettings() {
|
||||
this.showSettingsModal = false
|
||||
},
|
||||
|
||||
toggleSettings() {
|
||||
this.showSettingsModal = !this.showSettingsModal
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Tool Results Type Definitions
|
||||
* TypeScript interfaces for all tool result types
|
||||
*/
|
||||
|
||||
// Relevance levels
|
||||
export type RelevanceLevel = '高相关' | '中相关' | '低相关' | '弱相关';
|
||||
|
||||
// Display types
|
||||
export type DisplayType =
|
||||
| 'search_results'
|
||||
| 'chunk_detail'
|
||||
| 'related_chunks'
|
||||
| 'knowledge_base_list'
|
||||
| 'document_info'
|
||||
| 'graph_query_results'
|
||||
| 'thinking'
|
||||
| 'plan'
|
||||
| 'database_query';
|
||||
|
||||
// Search result item
|
||||
export interface SearchResultItem {
|
||||
result_index: number;
|
||||
chunk_id: string;
|
||||
content: string;
|
||||
score: number;
|
||||
relevance_level: RelevanceLevel;
|
||||
knowledge_id: string;
|
||||
knowledge_title: string;
|
||||
match_type: string;
|
||||
}
|
||||
|
||||
// Chunk item
|
||||
export interface ChunkItem {
|
||||
index: number;
|
||||
chunk_id: string;
|
||||
chunk_index: number;
|
||||
content: string;
|
||||
knowledge_id: string;
|
||||
}
|
||||
|
||||
// Knowledge base item
|
||||
export interface KnowledgeBaseItem {
|
||||
index: number;
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
// Graph config
|
||||
export interface GraphConfig {
|
||||
nodes: string[];
|
||||
relations: string[];
|
||||
}
|
||||
|
||||
// Search results data
|
||||
export interface SearchResultsData {
|
||||
display_type: 'search_results';
|
||||
results?: SearchResultItem[];
|
||||
count?: number;
|
||||
kb_counts?: Record<string, number>;
|
||||
query?: string;
|
||||
knowledge_base_id?: string;
|
||||
}
|
||||
|
||||
// Chunk detail data
|
||||
export interface ChunkDetailData {
|
||||
display_type: 'chunk_detail';
|
||||
chunk_id: string;
|
||||
content: string;
|
||||
chunk_index: number;
|
||||
knowledge_id: string;
|
||||
content_length?: number;
|
||||
}
|
||||
|
||||
// Related chunks data
|
||||
export interface RelatedChunksData {
|
||||
display_type: 'related_chunks';
|
||||
chunk_id: string;
|
||||
relation_type: string;
|
||||
count: number;
|
||||
chunks: ChunkItem[];
|
||||
}
|
||||
|
||||
// Knowledge base list data
|
||||
export interface KnowledgeBaseListData {
|
||||
display_type: 'knowledge_base_list';
|
||||
knowledge_bases: KnowledgeBaseItem[];
|
||||
count: number;
|
||||
}
|
||||
|
||||
// Document info data
|
||||
export interface DocumentInfoData {
|
||||
display_type: 'document_info';
|
||||
knowledge_id: string;
|
||||
title: string;
|
||||
chunk_count_min: number;
|
||||
}
|
||||
|
||||
// Graph query results data
|
||||
export interface GraphQueryResultsData {
|
||||
display_type: 'graph_query_results';
|
||||
results: SearchResultItem[];
|
||||
count: number;
|
||||
graph_config: GraphConfig;
|
||||
}
|
||||
|
||||
// Thinking data
|
||||
export interface ThinkingData {
|
||||
display_type: 'thinking';
|
||||
thought: string;
|
||||
}
|
||||
|
||||
// Plan step
|
||||
export interface PlanStep {
|
||||
id: string;
|
||||
description: string;
|
||||
tools_to_use?: string;
|
||||
status: 'pending' | 'in_progress' | 'completed' | 'skipped';
|
||||
}
|
||||
|
||||
// Plan data
|
||||
export interface PlanData {
|
||||
display_type: 'plan';
|
||||
task: string;
|
||||
steps: PlanStep[];
|
||||
total_steps: number;
|
||||
}
|
||||
|
||||
// Database query data
|
||||
export interface DatabaseQueryData {
|
||||
display_type: 'database_query';
|
||||
columns: string[];
|
||||
rows: Array<Record<string, any>>;
|
||||
row_count: number;
|
||||
query: string;
|
||||
}
|
||||
|
||||
// Union type for all tool result data
|
||||
export type ToolResultData =
|
||||
| SearchResultsData
|
||||
| ChunkDetailData
|
||||
| RelatedChunksData
|
||||
| KnowledgeBaseListData
|
||||
| DocumentInfoData
|
||||
| GraphQueryResultsData
|
||||
| ThinkingData
|
||||
| PlanData
|
||||
| DatabaseQueryData;
|
||||
|
||||
// Action data (from index.vue)
|
||||
export interface ActionData {
|
||||
description: string;
|
||||
success: boolean;
|
||||
tool_name?: string;
|
||||
arguments?: any;
|
||||
output?: string;
|
||||
error?: string;
|
||||
details?: boolean;
|
||||
display_type?: DisplayType;
|
||||
tool_data?: Record<string, any>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Tool Icons Utility
|
||||
* Maps tool names and match types to icons for better UI display
|
||||
*/
|
||||
|
||||
// Tool name to icon mapping
|
||||
export const toolIcons: Record<string, string> = {
|
||||
multi_kb_search: '🔍',
|
||||
knowledge_search: '📚',
|
||||
get_chunk_detail: '📄',
|
||||
get_related_chunks: '🔗',
|
||||
list_knowledge_bases: '📂',
|
||||
get_document_info: 'ℹ️',
|
||||
query_knowledge_graph: '🕸️',
|
||||
think: '💭',
|
||||
todo_write: '📋',
|
||||
};
|
||||
|
||||
// Match type to icon mapping
|
||||
export const matchTypeIcons: Record<string, string> = {
|
||||
'向量匹配': '🎯',
|
||||
'关键词匹配': '🔤',
|
||||
'相邻块匹配': '📌',
|
||||
'历史匹配': '📜',
|
||||
'父块匹配': '⬆️',
|
||||
'关系块匹配': '🔗',
|
||||
'图谱匹配': '🕸️',
|
||||
};
|
||||
|
||||
// Get icon for a tool name
|
||||
export function getToolIcon(toolName: string): string {
|
||||
return toolIcons[toolName] || '🛠️';
|
||||
}
|
||||
|
||||
// Get icon for a match type
|
||||
export function getMatchTypeIcon(matchType: string): string {
|
||||
return matchTypeIcons[matchType] || '📍';
|
||||
}
|
||||
|
||||
// Get tool display name (user-friendly)
|
||||
export function getToolDisplayName(toolName: string): string {
|
||||
const displayNames: Record<string, string> = {
|
||||
multi_kb_search: '跨库搜索',
|
||||
knowledge_search: '知识库搜索',
|
||||
get_chunk_detail: '获取片段详情',
|
||||
get_related_chunks: '获取相关片段',
|
||||
list_knowledge_bases: '列出知识库',
|
||||
get_document_info: '获取文档信息',
|
||||
query_knowledge_graph: '查询知识图谱',
|
||||
think: '思考',
|
||||
todo_write: '制定计划',
|
||||
};
|
||||
return displayNames[toolName] || toolName;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,879 @@
|
||||
<template>
|
||||
<div class="agent-stream-display">
|
||||
|
||||
<!-- Collapsed intermediate steps -->
|
||||
<div v-if="shouldShowCollapsedSteps" class="intermediate-steps-collapsed" @click="toggleIntermediateSteps">
|
||||
<span class="collapse-icon">{{ showIntermediateSteps ? '▼' : '▶' }}</span>
|
||||
<span class="collapse-text">
|
||||
{{ intermediateStepsCount }} intermediate step{{ intermediateStepsCount !== 1 ? 's' : '' }} (click to {{ showIntermediateSteps ? 'collapse' : 'expand' }})
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Event Stream -->
|
||||
<template v-for="(event, index) in displayEvents" :key="getEventKey(event, index)">
|
||||
<div v-if="event && event.type" class="event-item">
|
||||
|
||||
<!-- Thinking Event -->
|
||||
<div v-if="event.type === 'thinking'" class="thinking-event">
|
||||
<div
|
||||
class="thinking-phase"
|
||||
:class="{ 'thinking-active': event.thinking }"
|
||||
>
|
||||
<div v-if="event.content"
|
||||
class="thinking-content markdown-content"
|
||||
v-html="renderMarkdown(event.content)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tool Call Event -->
|
||||
<div v-else-if="event.type === 'tool_call'" class="tool-event">
|
||||
<div
|
||||
class="action-card"
|
||||
:class="{
|
||||
'action-pending': event.pending,
|
||||
'action-error': event.success === false
|
||||
}"
|
||||
>
|
||||
<div class="action-header" @click="toggleEvent(event.tool_call_id)">
|
||||
<div class="action-title">
|
||||
<span class="action-icon" :class="{
|
||||
'success': event.success === true,
|
||||
'error': event.success === false,
|
||||
'pending': event.pending
|
||||
}">
|
||||
{{ event.pending ? '○' : (event.success ? '✓' : '✗') }}
|
||||
</span>
|
||||
<!-- Custom header for todo_write tool -->
|
||||
<span v-if="event.tool_name === 'todo_write' && event.tool_data?.steps" class="action-name">
|
||||
制定计划 {{ getPlanStatusSummary(event) }}
|
||||
</span>
|
||||
<!-- Default header for other tools -->
|
||||
<span v-else class="action-name">{{ getToolDescription(event) }}</span>
|
||||
</div>
|
||||
<span v-if="!event.pending" class="expand-icon">
|
||||
{{ isEventExpanded(event.tool_call_id) ? '▼' : '▶' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- External Tool Summary -->
|
||||
<div v-if="getToolSummary(event) && !event.pending" class="tool-summary">
|
||||
<!-- Thinking tool: render markdown -->
|
||||
<div v-if="event.tool_name === 'thinking' && event.tool_data?.thought"
|
||||
class="tool-summary-markdown"
|
||||
v-html="renderMarkdown(event.tool_data.thought)">
|
||||
</div>
|
||||
<!-- Other tools: plain text -->
|
||||
<span v-else>{{ getToolSummary(event) }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="isEventExpanded(event.tool_call_id) && !event.pending" class="action-details">
|
||||
<div v-if="event.tool_name" class="detail-row">
|
||||
<span class="detail-label">Tool:</span>
|
||||
<code class="detail-value">{{ event.tool_name }}</code>
|
||||
</div>
|
||||
<!-- Hide Arguments for todo_write tool -->
|
||||
<div v-if="event.arguments && event.tool_name !== 'todo_write'" class="detail-row">
|
||||
<span class="detail-label">Arguments:</span>
|
||||
<pre class="detail-code">{{ formatJSON(event.arguments) }}</pre>
|
||||
</div>
|
||||
|
||||
<!-- Use ToolResultRenderer if display_type is available -->
|
||||
<div v-if="event.display_type && event.tool_data" class="detail-row">
|
||||
<ToolResultRenderer
|
||||
:display-type="event.display_type"
|
||||
:tool-data="event.tool_data"
|
||||
:output="event.output"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Fallback to original output display -->
|
||||
<div v-else-if="event.output" class="detail-row">
|
||||
<span class="detail-label">{{ event.success ? 'Output:' : 'Error:' }}</span>
|
||||
<div class="detail-output">{{ event.output }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Loading Indicator -->
|
||||
<div v-if="!isConversationDone && eventStream.length > 0" class="loading-indicator">
|
||||
<img class="botanswer_loading_gif" src="@/assets/img/botanswer_loading.gif" alt="Processing...">
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue';
|
||||
import { marked } from 'marked';
|
||||
import DOMPurify from 'dompurify';
|
||||
import ToolResultRenderer from './ToolResultRenderer.vue';
|
||||
|
||||
interface SessionData {
|
||||
isAgentMode?: boolean;
|
||||
agentEventStream?: any[];
|
||||
knowledge_references?: any[];
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
session: SessionData;
|
||||
}>();
|
||||
|
||||
// Configure marked for security
|
||||
marked.use({
|
||||
mangle: false,
|
||||
headerIds: false
|
||||
});
|
||||
|
||||
// Event stream
|
||||
const eventStream = computed(() => props.session?.agentEventStream || []);
|
||||
|
||||
// Expanded events tracking (for tool calls)
|
||||
const expandedEvents = ref<Set<string>>(new Set());
|
||||
|
||||
// State for intermediate steps collapse
|
||||
const showIntermediateSteps = ref(false);
|
||||
|
||||
// Check if conversation is done (based on answer event with done=true)
|
||||
const isConversationDone = computed(() => {
|
||||
const stream = eventStream.value;
|
||||
if (!stream || stream.length === 0) {
|
||||
console.log('[Collapse] No stream or empty stream');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only check for answer event with done=true
|
||||
const answerEvents = stream.filter((e: any) => e.type === 'answer');
|
||||
const doneAnswer = answerEvents.find((e: any) => e.done === true);
|
||||
|
||||
console.log('[Collapse] Answer events:', answerEvents.length, 'Done answer:', !!doneAnswer);
|
||||
|
||||
return !!doneAnswer;
|
||||
});
|
||||
|
||||
// Find the final content to display (last thinking or answer)
|
||||
const finalContent = computed(() => {
|
||||
const stream = eventStream.value;
|
||||
if (!stream || stream.length === 0) {
|
||||
console.log('[Collapse] finalContent: no stream');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isConversationDone.value) {
|
||||
console.log('[Collapse] finalContent: not done yet');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if there's an answer with content
|
||||
const answerEvents = stream.filter((e: any) => e.type === 'answer');
|
||||
const hasAnswerContent = answerEvents.some((e: any) => e.content && e.content.trim());
|
||||
|
||||
console.log('[Collapse] Answer events:', answerEvents.length, 'Has content:', hasAnswerContent);
|
||||
|
||||
if (hasAnswerContent) {
|
||||
// Answer has content, it's the final content
|
||||
console.log('[Collapse] finalContent: showing answer');
|
||||
return { type: 'answer' };
|
||||
} else {
|
||||
// Answer is empty, find last thinking with content
|
||||
const thinkingEvents = stream.filter((e: any) => e.type === 'thinking' && e.content && e.content.trim());
|
||||
console.log('[Collapse] Thinking events with content:', thinkingEvents.length);
|
||||
|
||||
if (thinkingEvents.length > 0) {
|
||||
const lastThinking = thinkingEvents[thinkingEvents.length - 1];
|
||||
console.log('[Collapse] finalContent: showing last thinking', lastThinking.event_id);
|
||||
return { type: 'thinking', event_id: lastThinking.event_id };
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[Collapse] finalContent: no final content found');
|
||||
return null;
|
||||
});
|
||||
|
||||
// Count intermediate steps (tools + thinking that will be collapsed)
|
||||
const intermediateStepsCount = computed(() => {
|
||||
if (!finalContent.value) {
|
||||
console.log('[Collapse] intermediateStepsCount: no final content');
|
||||
return 0;
|
||||
}
|
||||
|
||||
const stream = eventStream.value;
|
||||
let count = 0;
|
||||
|
||||
for (const event of stream) {
|
||||
if (event.type === 'tool_call') {
|
||||
count++;
|
||||
} else if (event.type === 'thinking' && event.content) {
|
||||
// Count if it's not the final thinking
|
||||
if (finalContent.value.type !== 'thinking' || event.event_id !== finalContent.value.event_id) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[Collapse] intermediateStepsCount:', count);
|
||||
return count;
|
||||
});
|
||||
|
||||
// Should show the collapsed steps indicator
|
||||
const shouldShowCollapsedSteps = computed(() => {
|
||||
const result = isConversationDone.value && intermediateStepsCount.value > 0;
|
||||
console.log('[Collapse] shouldShowCollapsedSteps:', result, 'done:', isConversationDone.value, 'count:', intermediateStepsCount.value);
|
||||
return result;
|
||||
});
|
||||
|
||||
// Events to display (based on collapse state)
|
||||
const displayEvents = computed(() => {
|
||||
const stream = eventStream.value;
|
||||
if (!stream || !Array.isArray(stream)) {
|
||||
console.log('[Collapse] displayEvents: no stream or not array');
|
||||
return [];
|
||||
}
|
||||
|
||||
// Filter out invalid events
|
||||
const validStream = stream.filter((e: any) => e && typeof e === 'object' && e.type);
|
||||
|
||||
console.log('[Collapse] displayEvents: total stream length:', validStream.length);
|
||||
|
||||
// If not done, show everything
|
||||
if (!isConversationDone.value) {
|
||||
console.log('[Collapse] displayEvents: not done, showing all', validStream.length);
|
||||
return validStream;
|
||||
}
|
||||
|
||||
// If done but user wants to see intermediate steps, show all
|
||||
if (showIntermediateSteps.value) {
|
||||
console.log('[Collapse] displayEvents: user expanded, showing all', validStream.length);
|
||||
return validStream;
|
||||
}
|
||||
|
||||
// Otherwise, show only final content
|
||||
const final = finalContent.value;
|
||||
if (!final) {
|
||||
console.log('[Collapse] displayEvents: no final content, showing all', validStream.length);
|
||||
return validStream;
|
||||
}
|
||||
|
||||
if (final.type === 'answer') {
|
||||
// Filter to show only answer events
|
||||
const filtered = validStream.filter((e: any) => e.type === 'answer');
|
||||
console.log('[Collapse] displayEvents: showing answer only', filtered.length);
|
||||
return filtered;
|
||||
} else if (final.type === 'thinking') {
|
||||
// Filter to show only the last thinking
|
||||
const filtered = validStream.filter((e: any) =>
|
||||
e.type === 'thinking' && e.event_id === final.event_id
|
||||
);
|
||||
console.log('[Collapse] displayEvents: showing last thinking only', filtered.length);
|
||||
return filtered;
|
||||
}
|
||||
|
||||
console.log('[Collapse] displayEvents: fallback, showing all', validStream.length);
|
||||
return validStream;
|
||||
});
|
||||
|
||||
// Get unique key for event
|
||||
const getEventKey = (event: any, index: number): string => {
|
||||
if (!event) return `event-${index}`;
|
||||
if (event.event_id) return `event-${event.event_id}`;
|
||||
if (event.tool_call_id) return `tool-${event.tool_call_id}`;
|
||||
return `event-${index}-${event.type || 'unknown'}`;
|
||||
};
|
||||
|
||||
const toggleIntermediateSteps = () => {
|
||||
showIntermediateSteps.value = !showIntermediateSteps.value;
|
||||
};
|
||||
|
||||
const toggleEvent = (eventId: string) => {
|
||||
if (expandedEvents.value.has(eventId)) {
|
||||
expandedEvents.value.delete(eventId);
|
||||
} else {
|
||||
expandedEvents.value.add(eventId);
|
||||
}
|
||||
};
|
||||
|
||||
const isEventExpanded = (eventId: string): boolean => {
|
||||
return expandedEvents.value.has(eventId);
|
||||
};
|
||||
|
||||
// Markdown rendering function
|
||||
const renderMarkdown = (content: any): string => {
|
||||
if (!content) return '';
|
||||
|
||||
// Ensure content is a string
|
||||
const contentStr = typeof content === 'string' ? content : String(content || '');
|
||||
if (!contentStr.trim()) return '';
|
||||
|
||||
try {
|
||||
const html = marked.parse(contentStr) as string;
|
||||
if (!html) return '';
|
||||
|
||||
return DOMPurify.sanitize(html, {
|
||||
ALLOWED_TAGS: ['p', 'br', 'strong', 'em', 'u', 'code', 'pre', 'ul', 'ol', 'li', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'a', 'table', 'thead', 'tbody', 'tr', 'th', 'td'],
|
||||
ALLOWED_ATTR: ['href', 'title', 'target', 'rel']
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Markdown rendering error:', e, 'Content:', contentStr.substring(0, 100));
|
||||
// Return escaped HTML instead of raw content for safety
|
||||
return contentStr.replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
};
|
||||
|
||||
// Tool summary - extract key info to display externally
|
||||
const getToolSummary = (event: any): string => {
|
||||
if (!event || event.pending || !event.success) return '';
|
||||
|
||||
const toolName = event.tool_name;
|
||||
const toolData = event.tool_data;
|
||||
|
||||
if (toolName === 'search_knowledge' || toolName === 'knowledge_search') {
|
||||
if (toolData?.count !== undefined) {
|
||||
const kbCount = toolData.kb_counts ? Object.keys(toolData.kb_counts).length : 0;
|
||||
if (kbCount > 0) {
|
||||
return `Found ${toolData.count} result${toolData.count !== 1 ? 's' : ''} from ${kbCount} knowledge base${kbCount !== 1 ? 's' : ''}`;
|
||||
}
|
||||
return `Found ${toolData.count} result${toolData.count !== 1 ? 's' : ''}`;
|
||||
}
|
||||
} else if (toolName === 'get_document_info') {
|
||||
if (toolData?.title) {
|
||||
return `Retrieved document: ${toolData.title}`;
|
||||
}
|
||||
} else if (toolName === 'get_related_chunks') {
|
||||
if (toolData?.count !== undefined) {
|
||||
return `Found ${toolData.count} related chunk${toolData.count !== 1 ? 's' : ''}`;
|
||||
}
|
||||
} else if (toolName === 'todo_write') {
|
||||
// Extract steps from tool data
|
||||
const steps = toolData?.steps;
|
||||
if (Array.isArray(steps)) {
|
||||
const inProgress = steps.filter((s: any) => s.status === 'in_progress').length;
|
||||
const pending = steps.filter((s: any) => s.status === 'pending').length;
|
||||
const completed = steps.filter((s: any) => s.status === 'completed').length;
|
||||
|
||||
const parts = [];
|
||||
if (inProgress > 0) parts.push(`🚀 进行中 ${inProgress}`);
|
||||
if (pending > 0) parts.push(`📋 待处理 ${pending}`);
|
||||
if (completed > 0) parts.push(`✅ 已完成 ${completed}`);
|
||||
|
||||
return parts.join(' · ');
|
||||
}
|
||||
} else if (toolName === 'thinking') {
|
||||
// Return truthy value to trigger rendering, actual content rendered in template
|
||||
return toolData?.thought ? 'thinking_content' : '';
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
// Get plan status summary for todo_write tool header
|
||||
const getPlanStatusSummary = (event: any): string => {
|
||||
if (!event || !event.tool_data?.steps) return '';
|
||||
|
||||
const steps = event.tool_data.steps;
|
||||
if (!Array.isArray(steps)) return '';
|
||||
|
||||
const inProgress = steps.filter((s: any) => s.status === 'in_progress').length;
|
||||
const pending = steps.filter((s: any) => s.status === 'pending').length;
|
||||
|
||||
const parts = [];
|
||||
if (inProgress > 0) parts.push(`🚀 进行中 ${inProgress}`);
|
||||
if (pending > 0) parts.push(`📋 待处理 ${pending}`);
|
||||
|
||||
return parts.length > 0 ? parts.join(' · ') : '';
|
||||
};
|
||||
|
||||
// Tool description
|
||||
const getToolDescription = (event: any): string => {
|
||||
if (event.pending) {
|
||||
return `Calling ${event.tool_name}...`;
|
||||
}
|
||||
|
||||
const success = event.success === true;
|
||||
const toolName = event.tool_name;
|
||||
|
||||
if (toolName === 'search_knowledge' || toolName === 'knowledge_search') {
|
||||
return success ? 'Searched knowledge base' : 'Failed to search knowledge base';
|
||||
} else if (toolName === 'get_document_info') {
|
||||
return success ? 'Retrieved document information' : 'Failed to get document info';
|
||||
} else if (toolName === 'thinking') {
|
||||
return success ? 'Completed thinking' : 'Thinking failed';
|
||||
} else if (toolName === 'todo_write') {
|
||||
return success ? 'Updated task list' : 'Failed to update tasks';
|
||||
} else {
|
||||
return success ? `Called ${toolName}` : `Error calling ${toolName}`;
|
||||
}
|
||||
};
|
||||
|
||||
// Helper functions
|
||||
const formatDuration = (ms?: number): string => {
|
||||
if (!ms) return '0s';
|
||||
if (ms < 1000) return `${ms}ms`;
|
||||
const seconds = Math.floor(ms / 1000);
|
||||
if (seconds < 60) return `${seconds}s`;
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
return `${minutes}m ${remainingSeconds}s`;
|
||||
};
|
||||
|
||||
const formatJSON = (obj: any): string => {
|
||||
try {
|
||||
if (typeof obj === 'string') {
|
||||
// Try to parse if it's a JSON string
|
||||
try {
|
||||
const parsed = JSON.parse(obj);
|
||||
return JSON.stringify(parsed, null, 2);
|
||||
} catch {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return JSON.stringify(obj, null, 2);
|
||||
} catch {
|
||||
return String(obj);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import '../../../components/css/markdown.less';
|
||||
|
||||
.agent-stream-display {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.intermediate-steps-collapsed {
|
||||
cursor: pointer;
|
||||
padding: 10px 14px;
|
||||
background: #ffffff;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
user-select: none;
|
||||
margin-bottom: 8px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
||||
animation: slideInDown 0.3s ease-out;
|
||||
|
||||
&:hover {
|
||||
background: #fafafa;
|
||||
border-color: #07c05f;
|
||||
box-shadow: 0 2px 6px rgba(7, 192, 95, 0.12);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.collapse-icon {
|
||||
font-size: 12px;
|
||||
color: #07c05f;
|
||||
transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.collapse-text {
|
||||
font-size: 13px;
|
||||
color: #333333;
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
}
|
||||
|
||||
.event-item {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
// Thinking Event
|
||||
.thinking-event {
|
||||
animation: fadeInUp 0.3s ease-out;
|
||||
|
||||
.thinking-phase {
|
||||
background: #ffffff;
|
||||
border-radius: 8px;
|
||||
padding: 1px 14px;
|
||||
border-left: 3px solid #d1d5db;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
&.thinking-active {
|
||||
border-left-color: #07c05f;
|
||||
box-shadow: 0 2px 4px rgba(7, 192, 95, 0.08);
|
||||
animation: pulseBorder 2s ease-in-out infinite;
|
||||
}
|
||||
}
|
||||
|
||||
.thinking-content {
|
||||
font-size: 14px;
|
||||
color: #333333;
|
||||
line-height: 1.6;
|
||||
|
||||
&.markdown-content {
|
||||
:deep(p) {
|
||||
margin: 8px 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
:deep(code) {
|
||||
background: #f0f0f0;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
:deep(pre) {
|
||||
background: #f5f5f5;
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
margin: 8px 0;
|
||||
|
||||
code {
|
||||
background: none;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(ul), :deep(ol) {
|
||||
margin: 8px 0;
|
||||
padding-left: 24px;
|
||||
}
|
||||
|
||||
:deep(li) {
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
:deep(blockquote) {
|
||||
border-left: 3px solid #07c05f;
|
||||
padding-left: 12px;
|
||||
margin: 8px 0;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
:deep(h1), :deep(h2), :deep(h3), :deep(h4), :deep(h5), :deep(h6) {
|
||||
margin: 12px 0 8px 0;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
:deep(a) {
|
||||
color: #07c05f;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(table) {
|
||||
border-collapse: collapse;
|
||||
margin: 8px 0;
|
||||
font-size: 12px;
|
||||
|
||||
th, td {
|
||||
border: 1px solid #e5e7eb;
|
||||
padding: 6px 10px;
|
||||
}
|
||||
|
||||
th {
|
||||
background: #f5f5f5;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tool Event
|
||||
.tool-event {
|
||||
animation: fadeInUp 0.3s ease-out;
|
||||
|
||||
.action-card {
|
||||
background: #ffffff;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e5e7eb;
|
||||
overflow: hidden;
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
||||
|
||||
&:hover {
|
||||
border-color: #07c05f;
|
||||
box-shadow: 0 2px 8px rgba(7, 192, 95, 0.12);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&.action-error {
|
||||
border-left: 3px solid #e34d59;
|
||||
animation: shakeError 0.4s ease-out;
|
||||
}
|
||||
|
||||
&.action-pending {
|
||||
opacity: 0.7;
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
.tool-summary {
|
||||
padding: 8px 14px;
|
||||
font-size: 13px;
|
||||
color: #333333;
|
||||
background: #ffffff;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
line-height: 1.6;
|
||||
font-weight: 500;
|
||||
animation: slideIn 0.25s ease-out;
|
||||
|
||||
.tool-summary-markdown {
|
||||
font-weight: 400;
|
||||
line-height: 1.6;
|
||||
color: #333333;
|
||||
|
||||
:deep(p) {
|
||||
margin: 4px 0;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
:deep(ul), :deep(ol) {
|
||||
margin: 4px 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
:deep(code) {
|
||||
background: #f5f5f5;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
color: #07c05f;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
:deep(strong) {
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 6px 14px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: background-color 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
&:hover {
|
||||
background: rgba(7, 192, 95, 0.04);
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: rgba(7, 192, 95, 0.08);
|
||||
}
|
||||
}
|
||||
|
||||
.action-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
|
||||
&.success {
|
||||
color: #00a870;
|
||||
background: rgba(0, 168, 112, 0.1);
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: #e34d59;
|
||||
background: rgba(227, 77, 89, 0.1);
|
||||
}
|
||||
|
||||
&.pending {
|
||||
color: #666666;
|
||||
background: rgba(102, 102, 102, 0.1);
|
||||
animation: pulse 1.5s ease-in-out infinite;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeInUp {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(8px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes slideInDown {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-8px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulseBorder {
|
||||
0%, 100% {
|
||||
border-left-color: #07c05f;
|
||||
box-shadow: 0 2px 4px rgba(7, 192, 95, 0.08);
|
||||
}
|
||||
50% {
|
||||
border-left-color: #0ae06f;
|
||||
box-shadow: 0 2px 6px rgba(7, 192, 95, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes shakeError {
|
||||
0%, 100% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
10%, 30%, 50%, 70%, 90% {
|
||||
transform: translateX(-3px);
|
||||
}
|
||||
20%, 40%, 60%, 80% {
|
||||
transform: translateX(3px);
|
||||
}
|
||||
}
|
||||
|
||||
.action-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
font-size: 12px;
|
||||
color: #07c05f;
|
||||
transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
|
||||
font-weight: 600;
|
||||
opacity: 0.8;
|
||||
display: inline-block;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.action-header:hover .expand-icon {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.action-details {
|
||||
padding: 0 12px 12px 12px;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.detail-row {
|
||||
margin-top: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #666;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
font-size: 13px;
|
||||
color: #07c05f;
|
||||
background: rgba(7, 192, 95, 0.05);
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.detail-code {
|
||||
font-size: 12px;
|
||||
background: #f5f5f5;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
overflow-x: auto;
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.detail-output {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
background: #f5f5f5;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.loading-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
margin-top: 8px;
|
||||
animation: fadeInUp 0.3s ease-out;
|
||||
|
||||
.botanswer_loading_gif {
|
||||
width: 24px;
|
||||
height: 18px;
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,120 @@
|
||||
<template>
|
||||
<div class="tool-result-renderer">
|
||||
<!-- Search Results -->
|
||||
<SearchResults
|
||||
v-if="displayType === 'search_results'"
|
||||
:data="toolData as SearchResultsData"
|
||||
/>
|
||||
|
||||
<!-- Chunk Detail -->
|
||||
<ChunkDetail
|
||||
v-else-if="displayType === 'chunk_detail'"
|
||||
:data="toolData as ChunkDetailData"
|
||||
/>
|
||||
|
||||
<!-- Related Chunks -->
|
||||
<RelatedChunks
|
||||
v-else-if="displayType === 'related_chunks'"
|
||||
:data="toolData as RelatedChunksData"
|
||||
/>
|
||||
|
||||
<!-- Knowledge Base List -->
|
||||
<KnowledgeBaseList
|
||||
v-else-if="displayType === 'knowledge_base_list'"
|
||||
:data="toolData as KnowledgeBaseListData"
|
||||
/>
|
||||
|
||||
<!-- Document Info -->
|
||||
<DocumentInfo
|
||||
v-else-if="displayType === 'document_info'"
|
||||
:data="toolData as DocumentInfoData"
|
||||
/>
|
||||
|
||||
<!-- Graph Query Results -->
|
||||
<GraphQueryResults
|
||||
v-else-if="displayType === 'graph_query_results'"
|
||||
:data="toolData as GraphQueryResultsData"
|
||||
/>
|
||||
|
||||
<!-- Thinking Display -->
|
||||
<ThinkingDisplay
|
||||
v-else-if="displayType === 'thinking'"
|
||||
:data="toolData as ThinkingData"
|
||||
/>
|
||||
|
||||
<!-- Plan Display -->
|
||||
<PlanDisplay
|
||||
v-else-if="displayType === 'plan'"
|
||||
:data="toolData as PlanData"
|
||||
/>
|
||||
|
||||
<!-- Database Query Display -->
|
||||
<DatabaseQuery
|
||||
v-else-if="displayType === 'database_query'"
|
||||
:data="toolData as DatabaseQueryData"
|
||||
/>
|
||||
|
||||
<!-- Fallback: Display raw output -->
|
||||
<div v-else class="fallback-output">
|
||||
<div class="detail-output">{{ output }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineProps, computed } from 'vue';
|
||||
import type {
|
||||
DisplayType,
|
||||
SearchResultsData,
|
||||
ChunkDetailData,
|
||||
RelatedChunksData,
|
||||
KnowledgeBaseListData,
|
||||
DocumentInfoData,
|
||||
GraphQueryResultsData,
|
||||
ThinkingData,
|
||||
PlanData,
|
||||
DatabaseQueryData
|
||||
} from '@/types/tool-results';
|
||||
|
||||
import SearchResults from './tool-results/SearchResults.vue';
|
||||
import ChunkDetail from './tool-results/ChunkDetail.vue';
|
||||
import RelatedChunks from './tool-results/RelatedChunks.vue';
|
||||
import KnowledgeBaseList from './tool-results/KnowledgeBaseList.vue';
|
||||
import DocumentInfo from './tool-results/DocumentInfo.vue';
|
||||
import GraphQueryResults from './tool-results/GraphQueryResults.vue';
|
||||
import ThinkingDisplay from './tool-results/ThinkingDisplay.vue';
|
||||
import PlanDisplay from './tool-results/PlanDisplay.vue';
|
||||
import DatabaseQuery from './tool-results/DatabaseQuery.vue';
|
||||
|
||||
interface Props {
|
||||
displayType?: DisplayType;
|
||||
toolData?: Record<string, any>;
|
||||
output?: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const displayType = computed(() => props.displayType);
|
||||
const toolData = computed(() => props.toolData || {});
|
||||
const output = computed(() => props.output || '');
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.tool-result-renderer {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.fallback-output {
|
||||
.detail-output {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
background: #f5f5f5;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
border: 1px solid #e7e7e7;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
<div class="bot_msg">
|
||||
<div style="display: flex;flex-direction: column; gap:8px">
|
||||
<docInfo :session="session"></docInfo>
|
||||
<deepThink :deepSession="session" v-if="session.showThink"></deepThink>
|
||||
<AgentStreamDisplay :session="session" v-if="session.isAgentMode"></AgentStreamDisplay>
|
||||
<deepThink :deepSession="session" v-if="session.showThink && !session.isAgentMode"></deepThink>
|
||||
</div>
|
||||
<div ref="parentMd">
|
||||
<!-- 消息正在总结中则渲染加载gif -->
|
||||
@@ -22,6 +23,7 @@ import { onMounted, watch, computed, ref, reactive, defineProps, nextTick } from
|
||||
import { marked } from 'marked';
|
||||
import docInfo from './docInfo.vue';
|
||||
import deepThink from './deepThink.vue';
|
||||
import AgentStreamDisplay from './AgentStreamDisplay.vue';
|
||||
import picturePreview from '@/components/picture-preview.vue';
|
||||
import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL } from '@/utils/security';
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<template>
|
||||
<div class="chunk-detail">
|
||||
<div class="info-section">
|
||||
<div class="info-field">
|
||||
<span class="field-label">片段ID:</span>
|
||||
<span class="field-value"><code>{{ data.chunk_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">文档ID:</span>
|
||||
<span class="field-value"><code>{{ data.knowledge_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">位置:</span>
|
||||
<span class="field-value">第 {{ data.chunk_index }} 个片段</span>
|
||||
</div>
|
||||
<div v-if="data.content_length" class="info-field">
|
||||
<span class="field-label">内容长度:</span>
|
||||
<span class="field-value">{{ data.content_length }} 字符</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<div class="info-section-title">完整内容</div>
|
||||
<div class="full-content">{{ data.content }}</div>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<div class="action-buttons">
|
||||
<button class="action-button" @click="copyToClipboard">
|
||||
📋 复制内容
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineProps } from 'vue';
|
||||
import type { ChunkDetailData } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: ChunkDetailData;
|
||||
}>();
|
||||
|
||||
const copyToClipboard = () => {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(props.data.content);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.chunk-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 11px;
|
||||
background: #f0f0f0;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<template>
|
||||
<div class="database-query-display">
|
||||
<!-- Query Display -->
|
||||
<div v-if="data.query" class="query-section">
|
||||
<div class="section-header">执行的 SQL 查询:</div>
|
||||
<pre class="query-code">{{ data.query }}</pre>
|
||||
</div>
|
||||
|
||||
<!-- Results Summary -->
|
||||
<div class="results-summary">
|
||||
<strong>返回结果:</strong> {{ data.row_count }} 行
|
||||
<span v-if="data.columns"> × {{ data.columns.length }} 列</span>
|
||||
</div>
|
||||
|
||||
<!-- Results Table -->
|
||||
<div v-if="data.rows && data.rows.length > 0" class="results-table-container">
|
||||
<table class="results-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th v-for="column in data.columns" :key="column">{{ column }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, index) in data.rows" :key="index">
|
||||
<td v-for="column in data.columns" :key="column">
|
||||
{{ formatValue(row[column]) }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- No Results -->
|
||||
<div v-else class="no-results">
|
||||
未找到匹配的记录
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { DatabaseQueryData } from '@/types/tool-results';
|
||||
|
||||
interface Props {
|
||||
data: DatabaseQueryData;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const formatValue = (value: any): string => {
|
||||
if (value === null || value === undefined) {
|
||||
return '<NULL>';
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
return String(value);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.database-query-display {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.query-section {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin-bottom: 8px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.query-code {
|
||||
background: #1e293b;
|
||||
color: #e2e8f0;
|
||||
padding: 12px;
|
||||
border-radius: 6px;
|
||||
overflow-x: auto;
|
||||
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.results-summary {
|
||||
padding: 10px 12px;
|
||||
background: #f0f9ff;
|
||||
border-left: 3px solid #3b82f6;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 16px;
|
||||
font-size: 13px;
|
||||
|
||||
strong {
|
||||
color: #1e40af;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.results-table-container {
|
||||
overflow-x: auto;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.results-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12px;
|
||||
|
||||
thead {
|
||||
background: #f9fafb;
|
||||
border-bottom: 2px solid #e5e7eb;
|
||||
|
||||
th {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
font-weight: 600;
|
||||
color: #374151;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
tbody {
|
||||
tr {
|
||||
border-bottom: 1px solid #f3f4f6;
|
||||
|
||||
&:hover {
|
||||
background: #f9fafb;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 10px 12px;
|
||||
color: #1f2937;
|
||||
vertical-align: top;
|
||||
max-width: 400px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.no-results {
|
||||
padding: 32px;
|
||||
text-align: center;
|
||||
color: #9ca3af;
|
||||
font-style: italic;
|
||||
background: #f9fafb;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<template>
|
||||
<div class="document-info">
|
||||
<div class="info-card">
|
||||
<div class="info-section">
|
||||
<div class="info-field">
|
||||
<span class="field-label">文档ID:</span>
|
||||
<span class="field-value"><code>{{ data.knowledge_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">文档标题:</span>
|
||||
<span class="field-value">{{ data.title }}</span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">片段数量:</span>
|
||||
<span class="field-value">至少 {{ data.chunk_count_min }} 个</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-section">
|
||||
<div class="status-title">状态说明</div>
|
||||
<div class="status-list">
|
||||
<div class="status-item">✓ 文档已索引并可搜索</div>
|
||||
<div class="status-item">✓ 可使用搜索工具查找文档内容</div>
|
||||
<div class="status-item">✓ 可使用 get_chunk_detail 查看片段详情</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineProps } from 'vue';
|
||||
import type { DocumentInfoData } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: DocumentInfoData;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.document-info {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.info-card {
|
||||
background: @card-bg;
|
||||
border: 1px solid @card-border;
|
||||
border-radius: @card-radius;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.status-section {
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid @card-border;
|
||||
}
|
||||
|
||||
.status-title {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #666;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.status-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.status-item {
|
||||
font-size: 12px;
|
||||
color: #00a870;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 11px;
|
||||
background: #f0f0f0;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<template>
|
||||
<div class="graph-query-results">
|
||||
<!-- Graph Configuration Card -->
|
||||
<div v-if="data.graph_config" class="stats-card">
|
||||
<div class="stats-title">图谱配置</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">实体类型:</span>
|
||||
<span class="field-value">{{ data.graph_config.nodes.join(', ') }}</span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">关系类型:</span>
|
||||
<span class="field-value">{{ data.graph_config.relations.join(', ') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Results List -->
|
||||
<div v-if="data.results && data.results.length > 0" class="results-list">
|
||||
<div class="results-header">
|
||||
找到 {{ data.count }} 条相关结果
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="result in data.results"
|
||||
:key="result.chunk_id"
|
||||
class="result-card"
|
||||
>
|
||||
<div class="result-header" @click="toggleResult(result.chunk_id)">
|
||||
<div class="result-title">
|
||||
<span class="result-index">#{{ result.result_index }}</span>
|
||||
<span class="relevance-badge" :class="getRelevanceClass(result.relevance_level)">
|
||||
{{ result.relevance_level }}
|
||||
</span>
|
||||
<span class="knowledge-title">{{ result.knowledge_title }}</span>
|
||||
</div>
|
||||
<div class="result-meta">
|
||||
<span class="score">{{ (result.score * 100).toFixed(0) }}%</span>
|
||||
<span class="expand-icon" :class="{ expanded: expandedResults.includes(result.chunk_id) }">
|
||||
▶
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="result-content" :class="{ expanded: expandedResults.includes(result.chunk_id) }">
|
||||
<div class="full-content">{{ result.content }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
未找到相关的图谱信息
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, defineProps } from 'vue';
|
||||
import type { GraphQueryResultsData, RelevanceLevel } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: GraphQueryResultsData;
|
||||
}>();
|
||||
|
||||
const expandedResults = ref<string[]>([]);
|
||||
|
||||
const toggleResult = (chunkId: string) => {
|
||||
const index = expandedResults.value.indexOf(chunkId);
|
||||
if (index > -1) {
|
||||
expandedResults.value.splice(index, 1);
|
||||
} else {
|
||||
expandedResults.value.push(chunkId);
|
||||
}
|
||||
};
|
||||
|
||||
const getRelevanceClass = (level: RelevanceLevel): string => {
|
||||
const classMap: Record<RelevanceLevel, string> = {
|
||||
'高相关': 'high',
|
||||
'中相关': 'medium',
|
||||
'低相关': 'low',
|
||||
'弱相关': 'weak',
|
||||
};
|
||||
return classMap[level] || 'weak';
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.graph-query-results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.results-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.results-header {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.result-index {
|
||||
font-size: 13px;
|
||||
color: #8b8b8b;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.knowledge-title {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.score {
|
||||
font-size: 12px;
|
||||
color: #8b8b8b;
|
||||
font-weight: 500;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<div class="knowledge-base-list">
|
||||
<div v-if="data.knowledge_bases && data.knowledge_bases.length > 0">
|
||||
<div class="stats-card">
|
||||
<div class="stats-title">共 {{ data.count }} 个知识库</div>
|
||||
</div>
|
||||
|
||||
<div class="card-grid">
|
||||
<div
|
||||
v-for="kb in data.knowledge_bases"
|
||||
:key="kb.id"
|
||||
class="kb-card"
|
||||
>
|
||||
<div class="kb-header">
|
||||
<span class="kb-index">#{{ kb.index }}</span>
|
||||
<span class="kb-name">{{ kb.name }}</span>
|
||||
</div>
|
||||
<div class="kb-body">
|
||||
<div class="info-field">
|
||||
<span class="field-label">ID:</span>
|
||||
<span class="field-value"><code>{{ kb.id }}</code></span>
|
||||
</div>
|
||||
<div v-if="kb.description" class="kb-description">
|
||||
{{ kb.description }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
没有可用的知识库
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineProps } from 'vue';
|
||||
import type { KnowledgeBaseListData } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: KnowledgeBaseListData;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.knowledge-base-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.kb-card {
|
||||
background: @card-bg;
|
||||
border: 1px solid @card-border;
|
||||
border-radius: @card-radius;
|
||||
padding: 12px;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: @card-hover-border;
|
||||
box-shadow: @card-shadow-hover;
|
||||
}
|
||||
}
|
||||
|
||||
.kb-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.kb-index {
|
||||
font-size: 12px;
|
||||
color: #8b8b8b;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.kb-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.kb-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.kb-description {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
line-height: 1.5;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 11px;
|
||||
background: #f0f0f0;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
<template>
|
||||
<div class="plan-display">
|
||||
<div v-if="data.task" class="plan-task">
|
||||
<strong>任务:</strong> {{ data.task }}
|
||||
</div>
|
||||
|
||||
<div v-if="data.steps && data.steps.length > 0" class="plan-steps">
|
||||
<div class="steps-header">计划步骤 (共 {{ data.total_steps || data.steps.length }} 步):</div>
|
||||
<div v-for="(step, index) in data.steps" :key="step.id || index" class="step-item">
|
||||
<div class="step-header">
|
||||
<span class="step-number">{{ index + 1 }}.</span>
|
||||
<span class="step-status" :class="`status-${step.status}`">
|
||||
{{ getStatusEmoji(step.status) }}
|
||||
</span>
|
||||
<span class="step-status-text" :class="`status-${step.status}`">
|
||||
[{{ getStatusText(step.status) }}]
|
||||
</span>
|
||||
<span class="step-description">{{ step.description }}</span>
|
||||
</div>
|
||||
<div v-if="step.tools_to_use" class="step-tools">
|
||||
<span class="tools-label">工具:</span> {{ step.tools_to_use }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="no-steps">
|
||||
未提供具体步骤
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import type { PlanData } from '@/types/tool-results';
|
||||
|
||||
interface Props {
|
||||
data: PlanData;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const getStatusEmoji = (status: string): string => {
|
||||
const emojiMap: Record<string, string> = {
|
||||
pending: '⏳',
|
||||
in_progress: '🔄',
|
||||
completed: '✅',
|
||||
skipped: '⏭️'
|
||||
};
|
||||
return emojiMap[status] || '⏳';
|
||||
};
|
||||
|
||||
const getStatusText = (status: string): string => {
|
||||
const textMap: Record<string, string> = {
|
||||
pending: '待处理',
|
||||
in_progress: '进行中',
|
||||
completed: '已完成',
|
||||
skipped: '已跳过'
|
||||
};
|
||||
return textMap[status] || status;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.plan-display {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
background: #f9fafb;
|
||||
padding: 12px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.plan-task {
|
||||
margin-bottom: 16px;
|
||||
padding: 10px;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
border-left: 3px solid #3b82f6;
|
||||
|
||||
strong {
|
||||
color: #1f2937;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.plan-steps {
|
||||
.steps-header {
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin-bottom: 12px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.step-item {
|
||||
margin-bottom: 12px;
|
||||
padding: 10px;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #e5e7eb;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
border-color: #d1d5db;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.step-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.step-number {
|
||||
font-weight: 600;
|
||||
color: #6b7280;
|
||||
min-width: 20px;
|
||||
}
|
||||
|
||||
.step-status {
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.step-status-text {
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
|
||||
&.status-pending {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
&.status-in_progress {
|
||||
color: #3b82f6;
|
||||
}
|
||||
|
||||
&.status-completed {
|
||||
color: #10b981;
|
||||
}
|
||||
|
||||
&.status-skipped {
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
|
||||
.step-description {
|
||||
flex: 1;
|
||||
color: #1f2937;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.step-tools {
|
||||
margin-top: 6px;
|
||||
padding-left: 26px;
|
||||
font-size: 12px;
|
||||
color: #6b7280;
|
||||
|
||||
.tools-label {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.no-steps {
|
||||
padding: 16px;
|
||||
text-align: center;
|
||||
color: #9ca3af;
|
||||
font-style: italic;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
<template>
|
||||
<div class="related-chunks">
|
||||
<div class="info-section">
|
||||
<div class="info-field">
|
||||
<span class="field-label">参考片段:</span>
|
||||
<span class="field-value"><code>{{ data.chunk_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">关系类型:</span>
|
||||
<span class="field-value">{{ relationTypeLabel }}</span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">相关片段数:</span>
|
||||
<span class="field-value">{{ data.count }} 个</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="data.chunks && data.chunks.length > 0" class="chunks-list">
|
||||
<div
|
||||
v-for="chunk in data.chunks"
|
||||
:key="chunk.chunk_id"
|
||||
class="result-card"
|
||||
>
|
||||
<div class="result-header" @click="toggleChunk(chunk.chunk_id)">
|
||||
<div class="result-title">
|
||||
<span class="chunk-index">片段 #{{ chunk.index }}</span>
|
||||
<span class="chunk-position">(位置: {{ chunk.chunk_index }})</span>
|
||||
</div>
|
||||
<span class="expand-icon" :class="{ expanded: expandedChunks.includes(chunk.chunk_id) }">
|
||||
▶
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="result-content" :class="{ expanded: expandedChunks.includes(chunk.chunk_id) }">
|
||||
<div class="info-field">
|
||||
<span class="field-label">片段ID:</span>
|
||||
<span class="field-value"><code>{{ chunk.chunk_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-section">
|
||||
<div class="info-section-title">内容</div>
|
||||
<div class="full-content">{{ chunk.content }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
没有找到相关片段
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, defineProps, computed } from 'vue';
|
||||
import type { RelatedChunksData } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: RelatedChunksData;
|
||||
}>();
|
||||
|
||||
const expandedChunks = ref<string[]>([]);
|
||||
|
||||
const relationTypeLabel = computed(() => {
|
||||
const labels: Record<string, string> = {
|
||||
'sequential': '顺序相关',
|
||||
'semantic': '语义相关',
|
||||
};
|
||||
return labels[props.data.relation_type] || props.data.relation_type;
|
||||
});
|
||||
|
||||
const toggleChunk = (chunkId: string) => {
|
||||
const index = expandedChunks.value.indexOf(chunkId);
|
||||
if (index > -1) {
|
||||
expandedChunks.value.splice(index, 1);
|
||||
} else {
|
||||
expandedChunks.value.push(chunkId);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.related-chunks {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.chunks-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.chunk-index {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.chunk-position {
|
||||
font-size: 12px;
|
||||
color: #8b8b8b;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 11px;
|
||||
background: #f0f0f0;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
<template>
|
||||
<div class="search-results">
|
||||
<!-- Knowledge Base Statistics Card -->
|
||||
<div v-if="kbCounts && Object.keys(kbCounts).length > 0" class="stats-card">
|
||||
<div class="stats-title">知识库覆盖</div>
|
||||
<div class="stats-list">
|
||||
<div v-for="(count, kbId) in kbCounts" :key="kbId" class="stats-item">
|
||||
<span>{{ kbId }}</span>
|
||||
<span>{{ count }} 条结果</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Search Results List -->
|
||||
<div v-if="results && results.length > 0" class="results-list">
|
||||
<div
|
||||
v-for="result in results"
|
||||
:key="result.chunk_id"
|
||||
class="result-card"
|
||||
>
|
||||
<div class="result-header" @click="toggleResult(result.chunk_id)">
|
||||
<div class="result-title">
|
||||
<span class="result-index">#{{ result.result_index }}</span>
|
||||
<span class="relevance-badge" :class="getRelevanceClass(result.relevance_level)">
|
||||
{{ result.relevance_level }}
|
||||
</span>
|
||||
<span class="knowledge-title">{{ result.knowledge_title }}</span>
|
||||
</div>
|
||||
<div class="result-meta">
|
||||
<span class="match-type-badge">
|
||||
{{ getMatchTypeIcon(result.match_type) }} {{ result.match_type }}
|
||||
</span>
|
||||
<span class="score">{{ (result.score * 100).toFixed(0) }}%</span>
|
||||
<span class="expand-icon" :class="{ expanded: expandedResults.includes(result.chunk_id) }">
|
||||
▶
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="result-content" :class="{ expanded: expandedResults.includes(result.chunk_id) }">
|
||||
<div class="info-section">
|
||||
<div class="info-section-title">内容</div>
|
||||
<div class="full-content">{{ result.content }}</div>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<div class="info-field">
|
||||
<span class="field-label">片段ID:</span>
|
||||
<span class="field-value"><code>{{ result.chunk_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">文档ID:</span>
|
||||
<span class="field-value"><code>{{ result.knowledge_id }}</code></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-else class="empty-state">
|
||||
没有找到搜索结果
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, defineProps, computed } from 'vue';
|
||||
import type { SearchResultsData, SearchResultItem, RelevanceLevel } from '@/types/tool-results';
|
||||
import { getMatchTypeIcon } from '@/utils/tool-icons';
|
||||
|
||||
const props = defineProps<{
|
||||
data: SearchResultsData;
|
||||
}>();
|
||||
|
||||
const expandedResults = ref<string[]>([]);
|
||||
|
||||
const results = computed(() => props.data.results || []);
|
||||
const kbCounts = computed(() => props.data.kb_counts);
|
||||
|
||||
const toggleResult = (chunkId: string) => {
|
||||
const index = expandedResults.value.indexOf(chunkId);
|
||||
if (index > -1) {
|
||||
expandedResults.value.splice(index, 1);
|
||||
} else {
|
||||
expandedResults.value.push(chunkId);
|
||||
}
|
||||
};
|
||||
|
||||
const getRelevanceClass = (level: RelevanceLevel): string => {
|
||||
const classMap: Record<RelevanceLevel, string> = {
|
||||
'高相关': 'high',
|
||||
'中相关': 'medium',
|
||||
'低相关': 'low',
|
||||
'弱相关': 'weak',
|
||||
};
|
||||
return classMap[level] || 'weak';
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.search-results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.results-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.result-index {
|
||||
font-size: 13px;
|
||||
color: #8b8b8b;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.knowledge-title {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.score {
|
||||
font-size: 12px;
|
||||
color: #8b8b8b;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 11px;
|
||||
background: #f0f0f0;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<template>
|
||||
<div class="thinking-display">
|
||||
<div class="thinking-content">
|
||||
<div class="thinking-icon">💭</div>
|
||||
<div class="thinking-text">{{ data.thought }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineProps } from 'vue';
|
||||
import type { ThinkingData } from '@/types/tool-results';
|
||||
|
||||
const props = defineProps<{
|
||||
data: ThinkingData;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.thinking-display {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.thinking-content {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding: 10px 12px;
|
||||
background: #f3f3f3;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid #8b8b8b;
|
||||
}
|
||||
|
||||
.thinking-icon {
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.thinking-text {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
flex: 1;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
/**
|
||||
* Tool Results Shared Styles
|
||||
* Common styles for all tool result components
|
||||
*/
|
||||
|
||||
// Color scheme for relevance levels
|
||||
@relevance-high: #00a870;
|
||||
@relevance-medium: #ff9800;
|
||||
@relevance-low: #757575;
|
||||
@relevance-weak: #bdbdbd;
|
||||
|
||||
// Card colors
|
||||
@card-bg: #f8f9fa;
|
||||
@card-border: #e7e7e7;
|
||||
@card-hover-border: #07c05f;
|
||||
@card-radius: 8px;
|
||||
@card-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
@card-shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
|
||||
// Animation timing
|
||||
@transition-time: 0.3s;
|
||||
|
||||
// Tool result container
|
||||
.tool-result-container {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
// Relevance badge styles
|
||||
.relevance-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
gap: 4px;
|
||||
|
||||
&.high {
|
||||
background-color: @relevance-high;
|
||||
color: white;
|
||||
}
|
||||
|
||||
&.medium {
|
||||
background-color: @relevance-medium;
|
||||
color: white;
|
||||
}
|
||||
|
||||
&.low {
|
||||
background-color: @relevance-low;
|
||||
color: white;
|
||||
}
|
||||
|
||||
&.weak {
|
||||
background-color: @relevance-weak;
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
|
||||
// Match type badge
|
||||
.match-type-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
background-color: #e7e7e7;
|
||||
color: #666;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
// Result card
|
||||
.result-card {
|
||||
background: @card-bg;
|
||||
border: 1px solid @card-border;
|
||||
border-radius: @card-radius;
|
||||
margin-bottom: 8px;
|
||||
overflow: hidden;
|
||||
transition: all @transition-time ease;
|
||||
|
||||
&:hover {
|
||||
border-color: @card-hover-border;
|
||||
box-shadow: @card-shadow-hover;
|
||||
}
|
||||
}
|
||||
|
||||
.result-header {
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
|
||||
&:hover {
|
||||
background: rgba(7, 192, 95, 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
.result-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: 1;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.result-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: #8b8b8b;
|
||||
}
|
||||
|
||||
.result-content {
|
||||
padding: 0 12px 12px 12px;
|
||||
border-top: 1px solid @card-border;
|
||||
background: white;
|
||||
max-height: 0;
|
||||
opacity: 0;
|
||||
overflow: hidden;
|
||||
transition: max-height @transition-time ease, opacity @transition-time ease, padding @transition-time ease;
|
||||
|
||||
&.expanded {
|
||||
max-height: 2000px;
|
||||
opacity: 1;
|
||||
padding: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
font-size: 12px;
|
||||
color: #8b8b8b;
|
||||
transition: transform 0.2s ease;
|
||||
|
||||
&.expanded {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
}
|
||||
|
||||
// Info sections
|
||||
.info-section {
|
||||
margin-top: 12px;
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.info-section-title {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #666;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.info-field {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 4px;
|
||||
font-size: 13px;
|
||||
|
||||
.field-label {
|
||||
color: #8b8b8b;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
.field-value {
|
||||
color: #333;
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Statistics card (for KB counts, etc.)
|
||||
.stats-card {
|
||||
background: #f0f7ff;
|
||||
border: 1px solid #d6e4ff;
|
||||
border-radius: 6px;
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.stats-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.stats-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.stats-item {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
// Grid layout for cards
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
// List item
|
||||
.list-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
// Content preview (truncated)
|
||||
.content-preview {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
line-height: 1.5;
|
||||
max-height: 60px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
// Full content
|
||||
.full-content {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
padding: 8px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 4px;
|
||||
border: 1px solid @card-border;
|
||||
}
|
||||
|
||||
// Action buttons
|
||||
.action-button {
|
||||
padding: 4px 10px;
|
||||
font-size: 12px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid @card-border;
|
||||
background: white;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: @card-hover-border;
|
||||
color: @card-hover-border;
|
||||
}
|
||||
}
|
||||
|
||||
// Empty state
|
||||
.empty-state {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: #8b8b8b;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
// Code block
|
||||
.code-block {
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
background: #f5f5f5;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid @card-border;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,9 @@ import usermsg from './components/usermsg.vue';
|
||||
import { getMessageList, generateSessionsTitle } from "@/api/chat/index";
|
||||
import { useStream } from '../../api/chat/streame'
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
const usemenuStore = useMenuStore();
|
||||
const useSettingsStoreInstance = useSettingsStore();
|
||||
const { menuArr, isFirstSession, firstQuery } = storeToRefs(usemenuStore);
|
||||
const { output, onChunk, isStreaming, isLoading, error, startStream, stopStream } = useStream();
|
||||
const route = useRoute();
|
||||
@@ -109,7 +111,11 @@ const handleMsgList = async (data, isScrollType = false, newScrollHeight) => {
|
||||
let chatlist = data.reverse()
|
||||
for (let i = 0, len = chatlist.length; i < len; i++) {
|
||||
let item = chatlist[i];
|
||||
item.thinking = false;
|
||||
item.isAgentMode = false; // Agent 模式标记
|
||||
item.agentEventStream = item.agentEventStream || [];
|
||||
item._eventMap = new Map();
|
||||
item._pendingToolCalls = new Map();
|
||||
|
||||
if (item.content) {
|
||||
if (!item.content.includes('<think>') && !item.content.includes('<\/think>')) {
|
||||
item.thinkContent = "";
|
||||
@@ -157,18 +163,45 @@ const sendMsg = async (value) => {
|
||||
messagesList.push({ content: value, role: 'user' });
|
||||
scrollToBottom();
|
||||
|
||||
// 判断是否使用 Agent 模式
|
||||
const isAgentMode = useSettingsStoreInstance.isAgentEnabled;
|
||||
const chatUrl = isAgentMode ? '/api/v1/agent-chat' : '/api/v1/knowledge-chat';
|
||||
|
||||
await startStream({
|
||||
session_id: session_id.value,
|
||||
knowledge_base_id: knowledge_base_id.value,
|
||||
query: value,
|
||||
method: 'POST',
|
||||
url: '/api/v1/knowledge-chat'
|
||||
url: chatUrl
|
||||
});
|
||||
}
|
||||
|
||||
// 处理流式数据
|
||||
onChunk((data) => {
|
||||
loading.value = false;
|
||||
|
||||
// 日志:打印接收到的事件
|
||||
console.log('[Agent Event Received]', {
|
||||
response_type: data.response_type,
|
||||
id: data.id,
|
||||
done: data.done,
|
||||
content_length: data.content?.length || 0,
|
||||
content_preview: data.content ? data.content.substring(0, 50) : '',
|
||||
data: data.data
|
||||
});
|
||||
|
||||
// 判断是否是 Agent 模式的响应
|
||||
const isAgentResponse = data.response_type === 'thinking' ||
|
||||
data.response_type === 'tool_call' ||
|
||||
data.response_type === 'references';
|
||||
|
||||
// Agent 模式处理
|
||||
if (isAgentResponse || messagesList[messagesList.length - 1]?.isAgentMode) {
|
||||
handleAgentChunk(data);
|
||||
return;
|
||||
}
|
||||
|
||||
// 原有的知识库 QA 处理逻辑
|
||||
fullContent.value += data.content;
|
||||
let obj = { ...data, content: '', role: 'assistant', showThink: false };
|
||||
|
||||
@@ -203,6 +236,233 @@ onChunk((data) => {
|
||||
}
|
||||
updateAssistantSession(obj);
|
||||
})
|
||||
// 处理 Agent 流式数据 (Cursor-style UI)
|
||||
const handleAgentChunk = (data) => {
|
||||
const message = messagesList.findLast((item) => item.request_id === data.id || item.id === data.id);
|
||||
|
||||
if (!message) {
|
||||
// 创建新的 Assistant 消息
|
||||
const newMsg = {
|
||||
id: data.id,
|
||||
request_id: data.id,
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
isAgentMode: true,
|
||||
// Event stream: ordered list of all agent events (thinking, tool calls, etc)
|
||||
agentEventStream: [],
|
||||
// Map to track event by event_id for quick lookup
|
||||
_eventMap: new Map(),
|
||||
knowledge_references: []
|
||||
};
|
||||
messagesList.push(newMsg);
|
||||
scrollToBottom();
|
||||
return;
|
||||
}
|
||||
|
||||
message.isAgentMode = true;
|
||||
|
||||
switch(data.response_type) {
|
||||
case 'thinking':
|
||||
{
|
||||
const eventId = data.data?.event_id;
|
||||
console.log('[Thinking Event]', {
|
||||
event_id: eventId,
|
||||
done: data.done,
|
||||
content_length: data.content?.length || 0
|
||||
});
|
||||
|
||||
// Initialize structures
|
||||
if (!message.agentEventStream) message.agentEventStream = [];
|
||||
if (!message._eventMap) message._eventMap = new Map();
|
||||
|
||||
if (!data.done) {
|
||||
// Check if this thinking event already exists
|
||||
let thinkingEvent = message._eventMap.get(eventId);
|
||||
|
||||
if (!thinkingEvent) {
|
||||
// Create new thinking event
|
||||
console.log('[Thinking] Creating new thinking event, event_id:', eventId);
|
||||
thinkingEvent = {
|
||||
type: 'thinking',
|
||||
event_id: eventId,
|
||||
content: '',
|
||||
done: false,
|
||||
startTime: Date.now(),
|
||||
thinking: true
|
||||
};
|
||||
|
||||
// Add to event stream
|
||||
message.agentEventStream.push(thinkingEvent);
|
||||
message._eventMap.set(eventId, thinkingEvent);
|
||||
}
|
||||
|
||||
// Accumulate content
|
||||
if (data.content) {
|
||||
thinkingEvent.content += data.content;
|
||||
console.log('[Thinking] Event', eventId, 'accumulated:', thinkingEvent.content.length, 'chars');
|
||||
}
|
||||
|
||||
} else {
|
||||
// Thinking completed
|
||||
const thinkingEvent = message._eventMap.get(eventId);
|
||||
if (thinkingEvent) {
|
||||
console.log('[Thinking] Completing event, event_id:', eventId, 'content length:', thinkingEvent.content.length);
|
||||
|
||||
// Mark as done
|
||||
thinkingEvent.done = true;
|
||||
thinkingEvent.thinking = false;
|
||||
thinkingEvent.duration_ms = data.data?.duration_ms || (Date.now() - thinkingEvent.startTime);
|
||||
thinkingEvent.completed_at = data.data?.completed_at || Date.now();
|
||||
|
||||
console.log('[Thinking] Event completed, duration:', thinkingEvent.duration_ms, 'ms');
|
||||
} else {
|
||||
console.warn('[Thinking] Received done for unknown event_id:', eventId);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tool_call':
|
||||
// Store pending tool call to pair with result later
|
||||
if (data.data && data.data.tool_name) {
|
||||
console.log('[Tool Call]', data.data.tool_name);
|
||||
|
||||
if (!message.agentEventStream) message.agentEventStream = [];
|
||||
if (!message._pendingToolCalls) message._pendingToolCalls = new Map();
|
||||
|
||||
const toolCallId = data.data.tool_call_id || (data.data.tool_name + '_' + Date.now());
|
||||
|
||||
// Create tool call event
|
||||
const toolCallEvent = {
|
||||
type: 'tool_call',
|
||||
tool_call_id: toolCallId,
|
||||
tool_name: data.data.tool_name,
|
||||
arguments: data.data.arguments,
|
||||
timestamp: Date.now(),
|
||||
pending: true
|
||||
};
|
||||
|
||||
// Add to event stream
|
||||
message.agentEventStream.push(toolCallEvent);
|
||||
message._pendingToolCalls.set(toolCallId, toolCallEvent);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tool_result':
|
||||
case 'error':
|
||||
// Tool result - update the corresponding tool call event
|
||||
if (data.data) {
|
||||
const toolCallId = data.data.tool_call_id;
|
||||
const toolName = data.data.tool_name;
|
||||
const success = data.response_type !== 'error' && data.data.success !== false;
|
||||
|
||||
console.log('[Tool Result]', {
|
||||
tool_call_id: toolCallId,
|
||||
tool_name: toolName,
|
||||
success: success
|
||||
});
|
||||
|
||||
// Find and update the pending tool call event
|
||||
let toolCallEvent = null;
|
||||
if (message._pendingToolCalls) {
|
||||
if (toolCallId && message._pendingToolCalls.has(toolCallId)) {
|
||||
toolCallEvent = message._pendingToolCalls.get(toolCallId);
|
||||
message._pendingToolCalls.delete(toolCallId);
|
||||
} else {
|
||||
// Try to find by tool_name if no tool_call_id match
|
||||
for (const [key, value] of message._pendingToolCalls.entries()) {
|
||||
if (value.tool_name === toolName) {
|
||||
toolCallEvent = value;
|
||||
message._pendingToolCalls.delete(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toolCallEvent) {
|
||||
// Update the existing event with result
|
||||
toolCallEvent.pending = false;
|
||||
toolCallEvent.success = success;
|
||||
toolCallEvent.output = success ? (data.data.output || data.content) : (data.data.error || data.content);
|
||||
toolCallEvent.error = !success ? (data.data.error || data.content) : undefined;
|
||||
toolCallEvent.duration = data.data.duration_ms;
|
||||
toolCallEvent.display_type = data.data.display_type;
|
||||
toolCallEvent.tool_data = data.data;
|
||||
|
||||
console.log('[Tool Result] Updated event in stream');
|
||||
} else {
|
||||
console.warn('[Tool Result] No pending tool call found for', toolCallId || toolName);
|
||||
}
|
||||
|
||||
// If this is an error response without tool data, handle it
|
||||
if (data.response_type === 'error' && !toolName) {
|
||||
message.content = data.content || '处理出错';
|
||||
isReplying.value = false;
|
||||
}
|
||||
} else if (data.response_type === 'error') {
|
||||
// Generic error without tool context
|
||||
message.content = data.content || '处理出错';
|
||||
isReplying.value = false;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'references':
|
||||
// 知识引用
|
||||
if (data.knowledge_references) {
|
||||
message.knowledge_references = data.knowledge_references;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'answer':
|
||||
// 最终答案
|
||||
message.thinking = false;
|
||||
message.content = (message.content || '') + (data.content || '');
|
||||
fullContent.value += data.content || '';
|
||||
|
||||
// Add or update answer event in agentEventStream
|
||||
if (!message.agentEventStream) message.agentEventStream = [];
|
||||
|
||||
let answerEvent = message.agentEventStream.find((e) => e.type === 'answer');
|
||||
if (!answerEvent) {
|
||||
answerEvent = {
|
||||
type: 'answer',
|
||||
content: '',
|
||||
done: false
|
||||
};
|
||||
message.agentEventStream.push(answerEvent);
|
||||
}
|
||||
|
||||
answerEvent.content = message.content;
|
||||
answerEvent.done = data.done;
|
||||
|
||||
if (data.done) {
|
||||
console.log('[Agent] Answer done, content length:', message.content?.length || 0);
|
||||
|
||||
// 完成
|
||||
isReplying.value = false;
|
||||
fullContent.value = '';
|
||||
|
||||
// 生成标题
|
||||
if (isFirstSession.value || isNeedTitle.value) {
|
||||
generateSessionsTitle(session_id.value, {
|
||||
messages: [{ role: "user", content: userquery.value }]
|
||||
}).then(res => {
|
||||
if (res.data) {
|
||||
usemenuStore.changeIsFirstSession(false);
|
||||
usemenuStore.updatasessionTitle(session_id.value, res.data);
|
||||
isNeedTitle.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
scrollToBottom();
|
||||
};
|
||||
|
||||
const updateAssistantSession = (payload) => {
|
||||
const message = messagesList.findLast((item) => {
|
||||
if (item.request_id === payload.id) {
|
||||
@@ -296,6 +556,30 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
}
|
||||
|
||||
|
||||
.agent-mode-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
background: linear-gradient(135deg, #e6f7ff 0%, #bae7ff 100%);
|
||||
border: 1px solid #91d5ff;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 12px;
|
||||
max-width: 800px;
|
||||
width: 100%;
|
||||
|
||||
.agent-icon {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.agent-text {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #0050b3;
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.msg_list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -2,113 +2,77 @@
|
||||
<div class="dialogue-wrap">
|
||||
<div class="dialogue-answers">
|
||||
<div class="dialogue-title">
|
||||
<span>基于知识库内容问答</span>
|
||||
<span>基于知识库内容问答 - AI 问答</span>
|
||||
</div>
|
||||
<InputField @send-msg="sendMsg"></InputField>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<t-dialog v-model:visible="selectVisible" header="选择知识库" :confirmBtn="{ content: '开始对话', theme: 'primary' }" :onConfirm="confirmSelect" :onCancel="() => selectVisible = false">
|
||||
<t-form :data="{ kb: selectedKbId }">
|
||||
<t-form-item label="知识库">
|
||||
<t-select v-model="selectedKbId" :loading="kbLoading" placeholder="请选择知识库">
|
||||
<t-option v-for="kb in kbList" :key="kb.id" :value="kb.id" :label="kb.name" />
|
||||
</t-select>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, onUnmounted, watch } from 'vue';
|
||||
import { ref } from 'vue';
|
||||
import InputField from '@/components/Input-field.vue';
|
||||
import EmptyKnowledge from '@/components/empty-knowledge.vue';
|
||||
import { getSessionsList, createSessions, generateSessionsTitle } from "@/api/chat/index";
|
||||
import { createSessions } from "@/api/chat/index";
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import useKnowledgeBase from '@/hooks/useKnowledgeBase';
|
||||
import { listKnowledgeBases } from '@/api/knowledge-base';
|
||||
import { MessagePlugin } from 'tdesign-vue-next';
|
||||
|
||||
let { cardList } = useKnowledgeBase()
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const usemenuStore = useMenuStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
|
||||
const sendMsg = (value: string) => {
|
||||
createNewSession(value);
|
||||
}
|
||||
|
||||
const selectVisible = ref(false)
|
||||
const selectedKbId = ref<string>('')
|
||||
const kbList = ref<Array<{ id: string; name: string }>>([])
|
||||
const kbLoading = ref(false)
|
||||
|
||||
const ensureKbId = async (): Promise<string | null> => {
|
||||
// 1) 优先使用当前路由上下文(如果来自某个知识库详情页)
|
||||
const routeKb = (route.params as any)?.kbId as string
|
||||
if (routeKb) return routeKb
|
||||
|
||||
|
||||
// 3) 弹窗选择知识库(从接口拉取)
|
||||
kbLoading.value = true
|
||||
try {
|
||||
const res: any = await listKnowledgeBases()
|
||||
kbList.value = res?.data || []
|
||||
if (kbList.value.length === 0) return null
|
||||
selectedKbId.value = kbList.value[0].id
|
||||
selectVisible.value = true
|
||||
return null
|
||||
} finally {
|
||||
kbLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function createNewSession(value: string) {
|
||||
let knowledgeBaseId = await ensureKbId()
|
||||
if (!knowledgeBaseId) {
|
||||
// 等待用户在弹窗中选择
|
||||
pendingValue.value = value
|
||||
return
|
||||
}
|
||||
|
||||
createSessions({ knowledge_base_id: knowledgeBaseId }).then(async res => {
|
||||
if (res.data && res.data.id) {
|
||||
await getTitle(res.data.id, value)
|
||||
} else {
|
||||
// 错误处理
|
||||
console.error("创建会话失败");
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error("创建会话出错:", error);
|
||||
})
|
||||
}
|
||||
|
||||
const pendingValue = ref<string>('')
|
||||
const confirmSelect = async () => {
|
||||
if (!selectedKbId.value) return
|
||||
const value = pendingValue.value
|
||||
pendingValue.value = ''
|
||||
selectVisible.value = false
|
||||
createSessions({ knowledge_base_id: selectedKbId.value }).then(async res => {
|
||||
if (res.data && res.data.id) {
|
||||
await getTitle(res.data.id, value, selectedKbId.value)
|
||||
} else {
|
||||
console.error('创建会话失败')
|
||||
}
|
||||
}).catch((e:any) => console.error('创建会话出错:', e))
|
||||
}
|
||||
|
||||
const getTitle = async (session_id: string, value: string, kbId?: string) => {
|
||||
const finalKbId = kbId || await ensureKbId();
|
||||
if (!finalKbId) {
|
||||
console.error('无法获取知识库ID');
|
||||
const selectedKbs = settingsStore.settings.selectedKnowledgeBases;
|
||||
|
||||
if (!selectedKbs || selectedKbs.length === 0) {
|
||||
MessagePlugin.warning('请先选择知识库');
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建 session 数据,包含 Agent 配置
|
||||
const sessionData: any = {};
|
||||
|
||||
let obj = { title: '新会话', path: `chat/${finalKbId}/${session_id}`, id: session_id, isMore: false, isNoTitle: true }
|
||||
// 添加 Agent 配置(知识库信息在 agent_config 中)
|
||||
sessionData.agent_config = {
|
||||
enabled: true,
|
||||
max_iterations: settingsStore.agentConfig.maxIterations,
|
||||
temperature: settingsStore.agentConfig.temperature,
|
||||
thinking_model_id: settingsStore.agentConfig.thinkingModelId,
|
||||
knowledge_bases: selectedKbs, // 所有选中的知识库
|
||||
allowed_tools: settingsStore.agentConfig.allowedTools
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await createSessions(sessionData);
|
||||
if (res.data && res.data.id) {
|
||||
await navigateToSession(res.data.id, value, selectedKbs[0]);
|
||||
} else {
|
||||
console.error("创建会话失败");
|
||||
MessagePlugin.error("创建会话失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("创建会话出错:", error);
|
||||
MessagePlugin.error("创建会话失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
const navigateToSession = async (sessionId: string, value: string, kbId: string) => {
|
||||
let obj = {
|
||||
title: '新会话',
|
||||
path: `chat/${kbId}/${sessionId}`,
|
||||
id: sessionId,
|
||||
isMore: false,
|
||||
isNoTitle: true
|
||||
};
|
||||
usemenuStore.updataMenuChildren(obj);
|
||||
usemenuStore.changeIsFirstSession(true);
|
||||
usemenuStore.changeFirstQuery(value);
|
||||
router.push(`/platform/chat/${finalKbId}/${session_id}`);
|
||||
router.push(`/platform/chat/${kbId}/${sessionId}`);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -971,6 +971,88 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Agent 智能问答配置区域 -->
|
||||
<div class="config-section">
|
||||
<h3>
|
||||
<t-icon name="service" class="section-icon" />Agent 智能问答配置
|
||||
<t-tag v-if="formData.agent.enabled" theme="success" size="small" style="margin-left: 8px">已启用</t-tag>
|
||||
<t-tag v-else theme="default" size="small" style="margin-left: 8px">未启用</t-tag>
|
||||
</h3>
|
||||
|
||||
<div class="form-row">
|
||||
<t-form-item name="agent.enabled">
|
||||
<div class="checkbox-with-label">
|
||||
<t-switch v-model="formData.agent.enabled" size="large">
|
||||
<template #label="slotProps">
|
||||
{{ slotProps.value ? '已启用' : '已禁用' }}
|
||||
</template>
|
||||
</t-switch>
|
||||
<div class="help-text" style="margin-left: 16px">
|
||||
启用 Agent 模式,通过 ReAct 推理框架回答复杂问题
|
||||
<t-button variant="text" size="small" @click="showAgentHelp = true">
|
||||
了解更多
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</div>
|
||||
|
||||
<!-- Agent 详细配置(启用后显示) -->
|
||||
<div v-if="formData.agent.enabled" class="agent-detail-config">
|
||||
<div class="form-row">
|
||||
<t-form-item label="最大推理步数" name="agent.maxIterations">
|
||||
<t-input-number
|
||||
v-model="formData.agent.maxIterations"
|
||||
:min="1"
|
||||
:max="20"
|
||||
style="width: 200px;"
|
||||
/>
|
||||
<div class="field-description">Agent 最多执行多少步推理,建议 5-10 步</div>
|
||||
</t-form-item>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<t-form-item label="温度参数" name="agent.temperature">
|
||||
<t-slider
|
||||
v-model="formData.agent.temperature"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.1"
|
||||
:marks="{ 0: '精确', 0.5: '平衡', 1: '创造' }"
|
||||
style="width: 400px;"
|
||||
/>
|
||||
<div class="field-description">控制回答的随机性,0=更精确,1=更有创造性</div>
|
||||
</t-form-item>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<t-form-item label="思考模型ID" name="agent.thinkingModelId">
|
||||
<t-input
|
||||
v-model="formData.agent.thinkingModelId"
|
||||
placeholder="留空使用默认 LLM 模型"
|
||||
style="width: 400px;"
|
||||
/>
|
||||
<div class="field-description">指定用于 Agent 推理的模型 ID</div>
|
||||
</t-form-item>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<t-form-item label="允许的工具" name="agent.allowedTools">
|
||||
<t-checkbox-group v-model="formData.agent.allowedTools">
|
||||
<t-checkbox value="knowledge_search">知识库检索</t-checkbox>
|
||||
<t-checkbox value="multi_kb_search">多知识库检索</t-checkbox>
|
||||
<t-checkbox value="list_knowledge_bases">列出知识库</t-checkbox>
|
||||
<t-checkbox value="get_chunk_detail">获取文档块详情</t-checkbox>
|
||||
<t-checkbox value="get_related_chunks">获取相关文档块</t-checkbox>
|
||||
<t-checkbox value="query_knowledge_graph">查询知识图谱</t-checkbox>
|
||||
<t-checkbox value="get_document_info">获取文档信息</t-checkbox>
|
||||
</t-checkbox-group>
|
||||
<div class="field-description">选择 Agent 可以使用的工具</div>
|
||||
</t-form-item>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 提交按钮区域 -->
|
||||
<div class="submit-section">
|
||||
<t-button theme="primary" type="button" size="large"
|
||||
@@ -992,6 +1074,62 @@
|
||||
</div>
|
||||
</div>
|
||||
</t-form>
|
||||
|
||||
<!-- Agent 帮助对话框 -->
|
||||
<t-dialog
|
||||
v-model:visible="showAgentHelp"
|
||||
header="Agent 智能问答模式说明"
|
||||
width="600px"
|
||||
:footer="false"
|
||||
>
|
||||
<div class="agent-help-content">
|
||||
<h4>什么是 Agent 模式?</h4>
|
||||
<p>Agent 模式基于 ReAct (Reasoning + Acting) 框架,能够通过以下方式回答复杂问题:</p>
|
||||
<ul>
|
||||
<li><strong>多步推理</strong>:Agent 会分步思考和分析问题</li>
|
||||
<li><strong>工具调用</strong>:根据需要调用知识库检索等工具</li>
|
||||
<li><strong>自我反思</strong>:评估中间结果并调整策略</li>
|
||||
<li><strong>上下文记忆</strong>:支持多轮连续对话</li>
|
||||
</ul>
|
||||
|
||||
<h4>适用场景</h4>
|
||||
<ul>
|
||||
<li>需要对比分析多个文档</li>
|
||||
<li>需要多步推理的复杂问题</li>
|
||||
<li>需要在多个知识库中查找信息</li>
|
||||
<li>需要深度分析和总结</li>
|
||||
</ul>
|
||||
|
||||
<h4>与普通模式的区别</h4>
|
||||
<table class="comparison-table">
|
||||
<tr>
|
||||
<th>特性</th>
|
||||
<th>普通模式</th>
|
||||
<th>Agent 模式</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>推理方式</td>
|
||||
<td>单次检索+生成</td>
|
||||
<td>多步推理循环</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>工具使用</td>
|
||||
<td>固定流程</td>
|
||||
<td>动态决策</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>适用问题</td>
|
||||
<td>简单直接问题</td>
|
||||
<td>复杂推理问题</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>响应时间</td>
|
||||
<td>快</td>
|
||||
<td>相对较慢</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</t-dialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1188,9 +1326,19 @@ const formData = reactive({
|
||||
tags: [] as string[],
|
||||
nodes: [] as Node[],
|
||||
relations: [] as Relation[]
|
||||
},
|
||||
agent: {
|
||||
enabled: false,
|
||||
maxIterations: 5,
|
||||
temperature: 0.7,
|
||||
thinkingModelId: '',
|
||||
allowedTools: ['knowledge_search', 'multi_kb_search', 'list_knowledge_bases']
|
||||
}
|
||||
});
|
||||
|
||||
// Agent 帮助对话框状态
|
||||
const showAgentHelp = ref(false);
|
||||
|
||||
// 输入防抖定时器
|
||||
const inputDebounceTimers = reactive<Record<string, any>>({});
|
||||
|
||||
@@ -1637,6 +1785,18 @@ const loadCurrentConfig = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 回填 Agent 配置
|
||||
if ((config as any).agent) {
|
||||
Object.assign(formData.agent, {
|
||||
enabled: (config as any).agent.enabled || false,
|
||||
maxIterations: (config as any).agent.maxIterations || 5,
|
||||
temperature: (config as any).agent.temperature || 0.7,
|
||||
thinkingModelId: (config as any).agent.thinkingModelId || '',
|
||||
allowedTools: (config as any).agent.allowedTools || ['knowledge_search', 'multi_kb_search', 'list_knowledge_bases']
|
||||
});
|
||||
console.log('Agent config loaded:', formData.agent);
|
||||
}
|
||||
|
||||
// 在配置加载完成后,检查模型状态
|
||||
await checkModelsAfterLoading(config);
|
||||
|
||||
@@ -3564,4 +3724,81 @@ onMounted(async () => {
|
||||
.select-input-node > li:hover {
|
||||
background-color: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
/* Agent 配置样式 */
|
||||
.agent-detail-config {
|
||||
margin-top: 16px;
|
||||
padding-left: 20px;
|
||||
border-left: 3px solid #0052d9;
|
||||
}
|
||||
|
||||
.checkbox-with-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.field-description {
|
||||
font-size: 12px;
|
||||
color: #00000099;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
/* Agent 帮助对话框样式 */
|
||||
.agent-help-content {
|
||||
h4 {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #000000;
|
||||
margin: 16px 0 8px 0;
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 14px;
|
||||
color: #00000099;
|
||||
line-height: 1.6;
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin: 8px 0;
|
||||
padding-left: 20px;
|
||||
|
||||
li {
|
||||
font-size: 14px;
|
||||
color: #00000099;
|
||||
line-height: 1.8;
|
||||
|
||||
strong {
|
||||
color: #000000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.comparison-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 12px 0;
|
||||
font-size: 13px;
|
||||
|
||||
th, td {
|
||||
border: 1px solid #e7e7e7;
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
background: #f5f5f5;
|
||||
font-weight: 600;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
td {
|
||||
color: #00000099;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,652 @@
|
||||
<template>
|
||||
<div class="agent-settings">
|
||||
<div class="section-header">
|
||||
<h2>Agent 配置</h2>
|
||||
<p class="section-description">配置 AI Agent 的默认行为和参数,这些设置将应用于所有启用 Agent 模式的对话</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- 启用 Agent 模式 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>启用 Agent 模式</label>
|
||||
<p class="desc">启用后,AI 将能够使用工具进行多步推理和跨知识库搜索</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
v-model="localAgentEnabled"
|
||||
@change="handleAgentToggle"
|
||||
size="large"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 最大迭代次数 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>最大迭代次数</label>
|
||||
<p class="desc">Agent 执行任务时的最大推理步骤数</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-with-value">
|
||||
<t-slider
|
||||
v-model="localMaxIterations"
|
||||
:min="1"
|
||||
:max="30"
|
||||
:step="1"
|
||||
:marks="{ 1: '1', 5: '5', 10: '10', 15: '15', 20: '20', 25: '25', 30: '30' }"
|
||||
@change="handleMaxIterationsChange"
|
||||
:disabled="!localAgentEnabled"
|
||||
style="width: 200px;"
|
||||
/>
|
||||
<span class="value-display">{{ localMaxIterations }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 思考模型 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>思考模型</label>
|
||||
<p class="desc">用于 Agent 推理和规划的 LLM 模型</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="localThinkingModelId"
|
||||
:loading="loadingModels"
|
||||
filterable
|
||||
placeholder="搜索模型..."
|
||||
@change="handleThinkingModelChange"
|
||||
@focus="loadChatModels"
|
||||
style="width: 280px;"
|
||||
>
|
||||
<!-- 已有的对话模型 -->
|
||||
<t-option
|
||||
v-for="model in chatModels"
|
||||
:key="model.id"
|
||||
:value="model.id"
|
||||
:label="model.name"
|
||||
>
|
||||
<div class="model-option">
|
||||
<t-icon name="check-circle-filled" class="model-icon" />
|
||||
<span class="model-name">{{ model.name }}</span>
|
||||
<t-tag v-if="model.is_default" size="small" theme="success">默认</t-tag>
|
||||
</div>
|
||||
</t-option>
|
||||
|
||||
<!-- 添加模型选项 -->
|
||||
<t-option value="__add_model__" class="add-model-option">
|
||||
<div class="model-option add">
|
||||
<t-icon name="add" class="add-icon" />
|
||||
<span class="model-name">添加新的对话模型</span>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Rerank 模型 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>Rerank 模型</label>
|
||||
<p class="desc">搜索结果重排序,统一不同来源的相关度分数</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="localRerankModelId"
|
||||
:loading="loadingModels"
|
||||
filterable
|
||||
placeholder="搜索模型..."
|
||||
@change="handleRerankModelChange"
|
||||
@focus="loadRerankModels"
|
||||
style="width: 280px;"
|
||||
>
|
||||
<!-- 已有的 Rerank 模型 -->
|
||||
<t-option
|
||||
v-for="model in rerankModels"
|
||||
:key="model.id"
|
||||
:value="model.id"
|
||||
:label="model.name"
|
||||
>
|
||||
<div class="model-option">
|
||||
<t-icon name="check-circle-filled" class="model-icon" />
|
||||
<span class="model-name">{{ model.name }}</span>
|
||||
<t-tag v-if="model.is_default" size="small" theme="success">默认</t-tag>
|
||||
</div>
|
||||
</t-option>
|
||||
|
||||
<!-- 添加模型选项 -->
|
||||
<t-option value="__add_model__" class="add-model-option">
|
||||
<div class="model-option add">
|
||||
<t-icon name="add" class="add-icon" />
|
||||
<span class="model-name">添加新的 Rerank 模型</span>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 温度参数 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>温度参数</label>
|
||||
<p class="desc">控制模型输出的随机性,0 最确定,1 最随机</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-with-value">
|
||||
<t-slider
|
||||
v-model="localTemperature"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.1"
|
||||
:marks="{ 0: '0', 0.5: '0.5', 1: '1' }"
|
||||
@change="handleTemperatureChange"
|
||||
:disabled="!localAgentEnabled"
|
||||
style="width: 200px;"
|
||||
/>
|
||||
<span class="value-display">{{ localTemperature.toFixed(1) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 允许的工具 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>允许的工具</label>
|
||||
<p class="desc">选择 Agent 可以使用的工具,至少选择一个</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="localAllowedTools"
|
||||
multiple
|
||||
placeholder="请选择工具..."
|
||||
@change="handleAllowedToolsChange"
|
||||
:disabled="!localAgentEnabled"
|
||||
style="width: 400px;"
|
||||
>
|
||||
<t-option
|
||||
v-for="tool in availableTools"
|
||||
:key="tool.name"
|
||||
:value="tool.name"
|
||||
:label="tool.label"
|
||||
:title="tool.description"
|
||||
>
|
||||
{{ tool.label }}
|
||||
</t-option>
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { listModels, type ModelConfig } from '@/api/model'
|
||||
import { getAgentConfig, updateAgentConfig, type AgentConfig, type ToolDefinition } from '@/api/system'
|
||||
|
||||
const settingsStore = useSettingsStore()
|
||||
const router = useRouter()
|
||||
|
||||
// 本地状态
|
||||
const localAgentEnabled = ref(false)
|
||||
const localMaxIterations = ref(5)
|
||||
const localTemperature = ref(0.7)
|
||||
const localThinkingModelId = ref('')
|
||||
const localRerankModelId = ref('')
|
||||
const localAllowedTools = ref<string[]>([])
|
||||
|
||||
// 模型列表状态
|
||||
const chatModels = ref<ModelConfig[]>([])
|
||||
const rerankModels = ref<ModelConfig[]>([])
|
||||
const loadingModels = ref(false)
|
||||
|
||||
// 可用工具列表
|
||||
const availableTools = ref<ToolDefinition[]>([])
|
||||
|
||||
// 配置加载状态
|
||||
const loadingConfig = ref(false)
|
||||
|
||||
// 初始化加载
|
||||
onMounted(async () => {
|
||||
loadingConfig.value = true
|
||||
try {
|
||||
// 从后台加载配置
|
||||
const res = await getAgentConfig()
|
||||
const config = res.data
|
||||
|
||||
// 更新本地状态
|
||||
localAgentEnabled.value = config.enabled
|
||||
localMaxIterations.value = config.max_iterations
|
||||
localTemperature.value = config.temperature
|
||||
localThinkingModelId.value = config.thinking_model_id
|
||||
localRerankModelId.value = config.rerank_model_id
|
||||
localAllowedTools.value = config.allowed_tools || []
|
||||
availableTools.value = config.available_tools || []
|
||||
|
||||
// 如果配置了思考模型,立即加载模型列表以显示模型名称
|
||||
if (config.thinking_model_id) {
|
||||
await loadChatModels()
|
||||
}
|
||||
|
||||
// 如果配置了 rerank 模型,立即加载模型列表以显示模型名称
|
||||
if (config.rerank_model_id) {
|
||||
await loadRerankModels()
|
||||
}
|
||||
|
||||
// 同步到store
|
||||
settingsStore.toggleAgent(config.enabled)
|
||||
settingsStore.updateAgentConfig({
|
||||
maxIterations: config.max_iterations,
|
||||
temperature: config.temperature,
|
||||
thinkingModelId: config.thinking_model_id,
|
||||
rerankModelId: config.rerank_model_id
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('加载Agent配置失败:', error)
|
||||
MessagePlugin.error('加载Agent配置失败')
|
||||
|
||||
// 失败时从store加载
|
||||
localAgentEnabled.value = settingsStore.isAgentEnabled
|
||||
localMaxIterations.value = settingsStore.agentConfig.maxIterations
|
||||
localTemperature.value = settingsStore.agentConfig.temperature
|
||||
localThinkingModelId.value = settingsStore.agentConfig.thinkingModelId
|
||||
localRerankModelId.value = settingsStore.agentConfig.rerankModelId
|
||||
} finally {
|
||||
loadingConfig.value = false
|
||||
}
|
||||
})
|
||||
|
||||
// 错误码到错误消息的映射
|
||||
const getErrorMessage = (error: any): string => {
|
||||
const errorCode = error?.response?.data?.error?.code
|
||||
const errorMessage = error?.response?.data?.error?.message
|
||||
|
||||
switch (errorCode) {
|
||||
case 2100:
|
||||
return '启用Agent模式前,请先选择思考模型'
|
||||
case 2101:
|
||||
return '至少需要选择一个允许的工具'
|
||||
case 2102:
|
||||
return '最大迭代次数必须在1-20之间'
|
||||
case 2103:
|
||||
return '温度参数必须在0-2之间'
|
||||
case 1010:
|
||||
return errorMessage || '配置验证失败'
|
||||
default:
|
||||
return errorMessage || '保存失败,请重试'
|
||||
}
|
||||
}
|
||||
|
||||
// 处理 Agent 开关
|
||||
const handleAgentToggle = async (value: boolean) => {
|
||||
try {
|
||||
// 构建完整配置
|
||||
const config: AgentConfig = {
|
||||
enabled: value,
|
||||
max_iterations: localMaxIterations.value,
|
||||
reflection_enabled: false,
|
||||
allowed_tools: localAllowedTools.value,
|
||||
temperature: localTemperature.value,
|
||||
thinking_model_id: localThinkingModelId.value,
|
||||
rerank_model_id: localRerankModelId.value
|
||||
}
|
||||
|
||||
await updateAgentConfig(config)
|
||||
settingsStore.toggleAgent(value)
|
||||
MessagePlugin.success(value ? 'Agent 模式已启用' : 'Agent 模式已禁用')
|
||||
} catch (error) {
|
||||
console.error('保存Agent配置失败:', error)
|
||||
MessagePlugin.error(getErrorMessage(error))
|
||||
// 回滚
|
||||
localAgentEnabled.value = !value
|
||||
}
|
||||
}
|
||||
|
||||
// 处理最大迭代次数变化
|
||||
const handleMaxIterationsChange = async (value: number) => {
|
||||
try {
|
||||
const config: AgentConfig = {
|
||||
enabled: localAgentEnabled.value,
|
||||
max_iterations: value,
|
||||
reflection_enabled: false,
|
||||
allowed_tools: localAllowedTools.value,
|
||||
temperature: localTemperature.value,
|
||||
thinking_model_id: localThinkingModelId.value,
|
||||
rerank_model_id: localRerankModelId.value
|
||||
}
|
||||
|
||||
await updateAgentConfig(config)
|
||||
settingsStore.updateAgentConfig({ maxIterations: value })
|
||||
MessagePlugin.success('最大迭代次数已保存')
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error)
|
||||
MessagePlugin.error(getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
// 加载对话模型列表
|
||||
const loadChatModels = async () => {
|
||||
if (chatModels.value.length > 0) return // 已经加载过
|
||||
|
||||
loadingModels.value = true
|
||||
try {
|
||||
const allModels = await listModels()
|
||||
// 只获取对话模型(KnowledgeQA 类型)
|
||||
chatModels.value = allModels.filter(m => m.type === 'KnowledgeQA')
|
||||
} catch (error) {
|
||||
MessagePlugin.error('加载模型列表失败')
|
||||
} finally {
|
||||
loadingModels.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 加载 Rerank 模型列表
|
||||
const loadRerankModels = async () => {
|
||||
if (rerankModels.value.length > 0) return // 已经加载过
|
||||
|
||||
loadingModels.value = true
|
||||
try {
|
||||
const allModels = await listModels()
|
||||
rerankModels.value = allModels.filter(m => m.type === 'Rerank')
|
||||
} catch (error) {
|
||||
console.error('加载 Rerank 模型列表失败:', error)
|
||||
MessagePlugin.error('加载 Rerank 模型列表失败')
|
||||
} finally {
|
||||
loadingModels.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理思考模型变化
|
||||
const handleThinkingModelChange = async (value: string) => {
|
||||
// 如果选择添加新模型,跳转到模型配置页
|
||||
if (value === '__add_model__') {
|
||||
router.push('/settings?section=models')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const config: AgentConfig = {
|
||||
enabled: localAgentEnabled.value,
|
||||
max_iterations: localMaxIterations.value,
|
||||
reflection_enabled: false,
|
||||
allowed_tools: localAllowedTools.value,
|
||||
temperature: localTemperature.value,
|
||||
thinking_model_id: value,
|
||||
rerank_model_id: localRerankModelId.value
|
||||
}
|
||||
|
||||
await updateAgentConfig(config)
|
||||
settingsStore.updateAgentConfig({ thinkingModelId: localThinkingModelId.value })
|
||||
MessagePlugin.success('思考模型已保存')
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error)
|
||||
MessagePlugin.error(getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
// 监听模型选择,处理"添加模型"跳转
|
||||
// 处理 Rerank 模型变化
|
||||
const handleRerankModelChange = async (value: string) => {
|
||||
// 如果选择添加新模型,跳转到模型配置页
|
||||
if (value === '__add_model__') {
|
||||
router.push('/settings?section=models&subsection=rerank')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const config: AgentConfig = {
|
||||
enabled: localAgentEnabled.value,
|
||||
max_iterations: localMaxIterations.value,
|
||||
reflection_enabled: false,
|
||||
allowed_tools: localAllowedTools.value,
|
||||
temperature: localTemperature.value,
|
||||
thinking_model_id: localThinkingModelId.value,
|
||||
rerank_model_id: value
|
||||
}
|
||||
|
||||
await updateAgentConfig(config)
|
||||
settingsStore.updateAgentConfig({ rerankModelId: value })
|
||||
MessagePlugin.success('Rerank 模型已保存')
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error)
|
||||
MessagePlugin.error(getErrorMessage(error))
|
||||
// 回滚
|
||||
localRerankModelId.value = settingsStore.agentConfig.rerankModelId
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => localThinkingModelId.value, (newValue) => {
|
||||
if (newValue === '__add_model__') {
|
||||
// 重置选择
|
||||
localThinkingModelId.value = ''
|
||||
|
||||
// 跳转到模型配置页面的对话模型部分
|
||||
router.push('/platform/settings')
|
||||
|
||||
// 发送导航事件,定位到对话模型
|
||||
setTimeout(() => {
|
||||
const event = new CustomEvent('settings-nav', {
|
||||
detail: { section: 'models', subsection: 'chat' }
|
||||
})
|
||||
window.dispatchEvent(event)
|
||||
|
||||
// 滚动到对话模型区域
|
||||
setTimeout(() => {
|
||||
const element = document.querySelector('[data-model-type="chat"]')
|
||||
if (element) {
|
||||
element.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
}, 200)
|
||||
}, 100)
|
||||
}
|
||||
})
|
||||
|
||||
// 监听 Rerank 模型选择,处理"添加模型"跳转
|
||||
watch(() => localRerankModelId.value, (newValue) => {
|
||||
if (newValue === '__add_model__') {
|
||||
// 重置选择
|
||||
localRerankModelId.value = ''
|
||||
|
||||
// 跳转到模型配置页面的 Rerank 模型部分
|
||||
router.push('/platform/settings')
|
||||
|
||||
// 发送导航事件,定位到 Rerank 模型
|
||||
setTimeout(() => {
|
||||
const event = new CustomEvent('settings-nav', {
|
||||
detail: { section: 'models', subsection: 'rerank' }
|
||||
})
|
||||
window.dispatchEvent(event)
|
||||
|
||||
// 滚动到 Rerank 模型区域
|
||||
setTimeout(() => {
|
||||
const element = document.querySelector('[data-model-type="rerank"]')
|
||||
if (element) {
|
||||
element.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
}, 200)
|
||||
}, 100)
|
||||
}
|
||||
})
|
||||
|
||||
// 处理温度参数变化
|
||||
const handleTemperatureChange = async (value: number) => {
|
||||
try {
|
||||
const config: AgentConfig = {
|
||||
enabled: localAgentEnabled.value,
|
||||
max_iterations: localMaxIterations.value,
|
||||
reflection_enabled: false,
|
||||
allowed_tools: localAllowedTools.value,
|
||||
temperature: value,
|
||||
thinking_model_id: localThinkingModelId.value,
|
||||
rerank_model_id: localRerankModelId.value
|
||||
}
|
||||
|
||||
await updateAgentConfig(config)
|
||||
settingsStore.updateAgentConfig({ temperature: value })
|
||||
MessagePlugin.success('温度参数已保存')
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error)
|
||||
MessagePlugin.error(getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
// 处理允许工具变化
|
||||
const handleAllowedToolsChange = async (value: string[]) => {
|
||||
try {
|
||||
const config: AgentConfig = {
|
||||
enabled: localAgentEnabled.value,
|
||||
max_iterations: localMaxIterations.value,
|
||||
reflection_enabled: false,
|
||||
allowed_tools: value,
|
||||
temperature: localTemperature.value,
|
||||
thinking_model_id: localThinkingModelId.value,
|
||||
rerank_model_id: localRerankModelId.value
|
||||
}
|
||||
|
||||
await updateAgentConfig(config)
|
||||
settingsStore.updateAgentConfig({ allowedTools: value })
|
||||
MessagePlugin.success('工具配置已更新')
|
||||
} catch (error) {
|
||||
console.error('保存工具配置失败:', error)
|
||||
MessagePlugin.error(getErrorMessage(error))
|
||||
// 回滚
|
||||
localAllowedTools.value = settingsStore.agentConfig.allowedTools
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.agent-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&.vertical {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
|
||||
.setting-info {
|
||||
margin-bottom: 12px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.setting-control.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.slider-with-value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
width: 100%;
|
||||
justify-content: flex-end;
|
||||
|
||||
.value-display {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
min-width: 40px;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
||||
// 模型选择器样式
|
||||
.model-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
.model-icon {
|
||||
font-size: 14px;
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
.add-icon {
|
||||
font-size: 14px;
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
.model-name {
|
||||
flex: 1;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
&.add {
|
||||
.model-name {
|
||||
color: #07C05F;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<template>
|
||||
<div class="general-settings">
|
||||
<div class="section-header">
|
||||
<h2>常规设置</h2>
|
||||
<p class="section-description">配置语言、外观等基础选项</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- 语言选择 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>语言</label>
|
||||
<p class="desc">选择界面显示语言</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="localLanguage"
|
||||
placeholder="选择语言"
|
||||
@change="handleLanguageChange"
|
||||
style="width: 280px;"
|
||||
>
|
||||
<t-option value="zh-CN" label="中文">中文</t-option>
|
||||
<t-option value="en-US" label="English">English</t-option>
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 外观主题 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>外观</label>
|
||||
<p class="desc">选择界面主题样式</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-select
|
||||
v-model="localTheme"
|
||||
placeholder="选择主题"
|
||||
@change="handleThemeChange"
|
||||
style="width: 280px;"
|
||||
>
|
||||
<t-option value="light" label="明亮">明亮</t-option>
|
||||
<t-option value="dark" label="暗色">暗色</t-option>
|
||||
</t-select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
|
||||
// 本地状态
|
||||
const localLanguage = ref('zh-CN')
|
||||
const localTheme = ref('light')
|
||||
|
||||
// 初始化加载
|
||||
onMounted(() => {
|
||||
// 从 localStorage 加载常规设置
|
||||
const savedSettings = localStorage.getItem('WeKnora_general_settings')
|
||||
if (savedSettings) {
|
||||
try {
|
||||
const parsed = JSON.parse(savedSettings)
|
||||
localLanguage.value = parsed.language || 'zh-CN'
|
||||
localTheme.value = parsed.theme || 'light'
|
||||
} catch (e) {
|
||||
console.error('加载常规设置失败:', e)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 保存设置到 localStorage
|
||||
const saveSettings = () => {
|
||||
const settings = {
|
||||
language: localLanguage.value,
|
||||
theme: localTheme.value
|
||||
}
|
||||
localStorage.setItem('WeKnora_general_settings', JSON.stringify(settings))
|
||||
}
|
||||
|
||||
// 处理语言变化
|
||||
const handleLanguageChange = () => {
|
||||
saveSettings()
|
||||
MessagePlugin.success('语言设置已保存')
|
||||
// TODO: 实际的语言切换逻辑可后续添加
|
||||
}
|
||||
|
||||
// 处理主题变化
|
||||
const handleThemeChange = () => {
|
||||
saveSettings()
|
||||
MessagePlugin.success('主题设置已保存')
|
||||
// TODO: 实际的主题切换逻辑可后续添加
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.general-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
<template>
|
||||
<div class="kb-settings">
|
||||
<div class="section-header">
|
||||
<h2>知识库设置</h2>
|
||||
<p class="section-description">配置文档处理和索引的默认参数</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- Chunk 大小 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>默认 Chunk 大小</label>
|
||||
<p class="desc">文档分块的默认字符数(100-2000)</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-with-value">
|
||||
<t-slider
|
||||
v-model="localChunkSize"
|
||||
:min="100"
|
||||
:max="2000"
|
||||
:step="50"
|
||||
:marks="{ 100: '100', 1000: '1000', 2000: '2000' }"
|
||||
@change="handleChunkSizeChange"
|
||||
style="width: 200px;"
|
||||
/>
|
||||
<span class="value-display">{{ localChunkSize }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Chunk Overlap -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>Chunk Overlap</label>
|
||||
<p class="desc">相邻文档块之间的重叠字符数(0-500)</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-with-value">
|
||||
<t-slider
|
||||
v-model="localChunkOverlap"
|
||||
:min="0"
|
||||
:max="500"
|
||||
:step="20"
|
||||
:marks="{ 0: '0', 250: '250', 500: '500' }"
|
||||
@change="handleChunkOverlapChange"
|
||||
style="width: 200px;"
|
||||
/>
|
||||
<span class="value-display">{{ localChunkOverlap }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 文档语言检测 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>文档语言检测</label>
|
||||
<p class="desc">自动检测文档语言以优化分词效果</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
v-model="localLanguageDetection"
|
||||
@change="handleLanguageDetectionChange"
|
||||
size="large"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
|
||||
// 本地状态
|
||||
const localChunkSize = ref(500)
|
||||
const localChunkOverlap = ref(100)
|
||||
const localLanguageDetection = ref(true)
|
||||
|
||||
// 初始化加载
|
||||
onMounted(() => {
|
||||
// 从 localStorage 加载知识库设置
|
||||
const savedSettings = localStorage.getItem('WeKnora_kb_settings')
|
||||
if (savedSettings) {
|
||||
try {
|
||||
const parsed = JSON.parse(savedSettings)
|
||||
localChunkSize.value = parsed.chunkSize || 500
|
||||
localChunkOverlap.value = parsed.chunkOverlap || 100
|
||||
localLanguageDetection.value = parsed.languageDetection !== false
|
||||
} catch (e) {
|
||||
console.error('加载知识库设置失败:', e)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 保存设置到 localStorage
|
||||
const saveSettings = () => {
|
||||
const settings = {
|
||||
chunkSize: localChunkSize.value,
|
||||
chunkOverlap: localChunkOverlap.value,
|
||||
languageDetection: localLanguageDetection.value
|
||||
}
|
||||
localStorage.setItem('WeKnora_kb_settings', JSON.stringify(settings))
|
||||
}
|
||||
|
||||
// 处理 Chunk 大小变化
|
||||
const handleChunkSizeChange = () => {
|
||||
saveSettings()
|
||||
MessagePlugin.success('Chunk 大小已保存')
|
||||
}
|
||||
|
||||
// 处理 Chunk Overlap 变化
|
||||
const handleChunkOverlapChange = () => {
|
||||
// 确保 overlap 不超过 chunk size
|
||||
if (localChunkOverlap.value > localChunkSize.value) {
|
||||
localChunkOverlap.value = Math.floor(localChunkSize.value / 2)
|
||||
MessagePlugin.warning('Overlap 不能超过 Chunk 大小,已自动调整')
|
||||
}
|
||||
saveSettings()
|
||||
MessagePlugin.success('Chunk Overlap 已保存')
|
||||
}
|
||||
|
||||
// 处理语言检测开关
|
||||
const handleLanguageDetectionChange = () => {
|
||||
saveSettings()
|
||||
MessagePlugin.success(`文档语言检测已${localLanguageDetection.value ? '启用' : '禁用'}`)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.kb-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.slider-with-value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
width: 100%;
|
||||
justify-content: flex-end;
|
||||
|
||||
.value-display {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
min-width: 40px;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,633 @@
|
||||
<template>
|
||||
<div class="model-settings">
|
||||
<div class="section-header">
|
||||
<h2>模型配置</h2>
|
||||
<p class="section-description">管理不同类型的 AI 模型,支持 Ollama 本地模型和远程 API</p>
|
||||
</div>
|
||||
|
||||
<!-- 对话模型 -->
|
||||
<div class="model-category-section" data-model-type="chat">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<h3>对话模型</h3>
|
||||
<p>配置用于对话的大语言模型</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('chat')">
|
||||
<t-icon name="add" />添加模型
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<div v-if="chatModels.length > 0" class="model-list-container">
|
||||
<div v-for="model in chatModels" :key="model.id" class="model-card">
|
||||
<div class="model-info">
|
||||
<div class="model-name">
|
||||
{{ model.name }}
|
||||
<t-tag v-if="model.isDefault" theme="success" size="small">默认</t-tag>
|
||||
</div>
|
||||
<div class="model-meta">
|
||||
<span class="source-tag">{{ model.source === 'local' ? 'Ollama' : 'Remote' }}</span>
|
||||
<!-- <span class="model-id">{{ model.modelName }}</span> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="model-actions">
|
||||
<t-dropdown
|
||||
:options="getModelOptions('chat', model)"
|
||||
@click="(data: any) => handleMenuAction(data, 'chat', model)"
|
||||
placement="bottom-right"
|
||||
attach="body"
|
||||
>
|
||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
||||
<t-icon name="more" />
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">暂无对话模型</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('chat')">
|
||||
添加模型
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Embedding 模型 -->
|
||||
<div class="model-category-section" data-model-type="embedding">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<h3>Embedding 模型</h3>
|
||||
<p>配置用于文本向量化的嵌入模型</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('embedding')">
|
||||
<t-icon name="add" />添加模型
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<div v-if="embeddingModels.length > 0" class="model-list-container">
|
||||
<div v-for="model in embeddingModels" :key="model.id" class="model-card">
|
||||
<div class="model-info">
|
||||
<div class="model-name">
|
||||
{{ model.name }}
|
||||
<t-tag v-if="model.isDefault" theme="success" size="small">默认</t-tag>
|
||||
</div>
|
||||
<div class="model-meta">
|
||||
<span class="source-tag">{{ model.source === 'local' ? 'Ollama' : 'Remote' }}</span>
|
||||
<!-- <span class="model-id">{{ model.modelName }}</span> -->
|
||||
<span v-if="model.dimension" class="dimension">维度: {{ model.dimension }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="model-actions">
|
||||
<t-dropdown
|
||||
:options="getModelOptions('embedding', model)"
|
||||
@click="(data: any) => handleMenuAction(data, 'embedding', model)"
|
||||
placement="bottom-right"
|
||||
attach="body"
|
||||
>
|
||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
||||
<t-icon name="more" />
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">暂无 Embedding 模型</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('embedding')">
|
||||
添加模型
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ReRank 模型 -->
|
||||
<div class="model-category-section" data-model-type="rerank">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<h3>ReRank 模型</h3>
|
||||
<p>配置用于结果重排序的模型</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('rerank')">
|
||||
<t-icon name="add" />添加模型
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<div v-if="rerankModels.length > 0" class="model-list-container">
|
||||
<div v-for="model in rerankModels" :key="model.id" class="model-card">
|
||||
<div class="model-info">
|
||||
<div class="model-name">
|
||||
{{ model.name }}
|
||||
<t-tag v-if="model.isDefault" theme="success" size="small">默认</t-tag>
|
||||
</div>
|
||||
<div class="model-meta">
|
||||
<span class="source-tag">{{ model.source === 'local' ? 'Ollama' : 'Remote' }}</span>
|
||||
<!-- <span class="model-id">{{ model.modelName }}</span> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="model-actions">
|
||||
<t-dropdown
|
||||
:options="getModelOptions('rerank', model)"
|
||||
@click="(data: any) => handleMenuAction(data, 'rerank', model)"
|
||||
placement="bottom-right"
|
||||
attach="body"
|
||||
>
|
||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
||||
<t-icon name="more" />
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">暂无 ReRank 模型</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('rerank')">
|
||||
添加模型
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- VLLM 视觉模型 -->
|
||||
<div class="model-category-section" data-model-type="vllm">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<h3>VLLM 视觉模型</h3>
|
||||
<p>配置用于视觉理解和多模态的视觉语言模型</p>
|
||||
</div>
|
||||
<t-button size="small" theme="primary" @click="openAddDialog('vllm')">
|
||||
<t-icon name="add" />添加模型
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<div v-if="vllmModels.length > 0" class="model-list-container">
|
||||
<div v-for="model in vllmModels" :key="model.id" class="model-card">
|
||||
<div class="model-info">
|
||||
<div class="model-name">
|
||||
{{ model.name }}
|
||||
<t-tag v-if="model.isDefault" theme="success" size="small">默认</t-tag>
|
||||
</div>
|
||||
<div class="model-meta">
|
||||
<span class="source-tag">
|
||||
{{ model.interfaceType === 'ollama' ? 'Ollama' : 'OpenAI兼容' }}
|
||||
</span>
|
||||
<!-- <span class="model-id">{{ model.modelName }}</span> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="model-actions">
|
||||
<t-dropdown
|
||||
:options="getModelOptions('vllm', model)"
|
||||
@click="(data: any) => handleMenuAction(data, 'vllm', model)"
|
||||
placement="bottom-right"
|
||||
attach="body"
|
||||
>
|
||||
<t-button variant="text" shape="square" size="small" class="more-btn">
|
||||
<t-icon name="more" />
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">暂无 VLLM 视觉模型</p>
|
||||
<t-button theme="default" variant="outline" size="small" @click="openAddDialog('vllm')">
|
||||
添加模型
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 模型编辑器弹窗 -->
|
||||
<ModelEditorDialog
|
||||
v-model:visible="showDialog"
|
||||
:model-type="currentModelType"
|
||||
:model-data="editingModel"
|
||||
@confirm="handleModelSave"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import ModelEditorDialog from '@/components/ModelEditorDialog.vue'
|
||||
import { listModels, createModel, updateModel as updateModelAPI, deleteModel as deleteModelAPI, type ModelConfig } from '@/api/model'
|
||||
|
||||
const showDialog = ref(false)
|
||||
const currentModelType = ref<'chat' | 'embedding' | 'rerank' | 'vllm'>('chat')
|
||||
const editingModel = ref<any>(null)
|
||||
const loading = ref(true)
|
||||
|
||||
// 模型列表数据
|
||||
const allModels = ref<ModelConfig[]>([])
|
||||
|
||||
// 根据类型过滤并去重模型
|
||||
const chatModels = computed(() =>
|
||||
deduplicateModels(
|
||||
allModels.value
|
||||
.filter(m => m.type === 'KnowledgeQA')
|
||||
.map(convertToLegacyFormat)
|
||||
)
|
||||
)
|
||||
|
||||
const embeddingModels = computed(() =>
|
||||
deduplicateModels(
|
||||
allModels.value
|
||||
.filter(m => m.type === 'Embedding')
|
||||
.map(convertToLegacyFormat)
|
||||
)
|
||||
)
|
||||
|
||||
const rerankModels = computed(() =>
|
||||
deduplicateModels(
|
||||
allModels.value
|
||||
.filter(m => m.type === 'Rerank')
|
||||
.map(convertToLegacyFormat)
|
||||
)
|
||||
)
|
||||
|
||||
const vllmModels = computed(() =>
|
||||
deduplicateModels(
|
||||
allModels.value
|
||||
.filter(m => m.type === 'VLLM')
|
||||
.map(convertToLegacyFormat)
|
||||
)
|
||||
)
|
||||
|
||||
// 将后端模型格式转换为旧的前端格式
|
||||
function convertToLegacyFormat(model: ModelConfig) {
|
||||
return {
|
||||
id: model.id!,
|
||||
name: model.name,
|
||||
source: model.source,
|
||||
modelName: model.name, // 显示名称作为模型名
|
||||
baseUrl: model.parameters.base_url || '',
|
||||
apiKey: model.parameters.api_key || '',
|
||||
dimension: model.parameters.embedding_parameters?.dimension,
|
||||
interfaceType: model.parameters.interface_type,
|
||||
isDefault: model.is_default || false
|
||||
}
|
||||
}
|
||||
|
||||
// 去重函数:比较除id外的所有字段,相同的只保留第一个
|
||||
function deduplicateModels(models: any[]) {
|
||||
const seen = new Map<string, any>()
|
||||
|
||||
return models.filter(model => {
|
||||
// 创建一个不包含id的签名用于比较
|
||||
const signature = JSON.stringify({
|
||||
name: model.name,
|
||||
source: model.source,
|
||||
modelName: model.modelName,
|
||||
baseUrl: model.baseUrl,
|
||||
apiKey: model.apiKey,
|
||||
dimension: model.dimension,
|
||||
interfaceType: model.interfaceType
|
||||
})
|
||||
|
||||
if (seen.has(signature)) {
|
||||
// 如果已经存在相同的模型,优先保留默认模型
|
||||
const existing = seen.get(signature)
|
||||
if (model.isDefault && !existing.isDefault) {
|
||||
seen.set(signature, model)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
seen.set(signature, model)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// 加载模型列表
|
||||
const loadModels = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
// 直接获取所有模型,不分类型
|
||||
const models = await listModels()
|
||||
allModels.value = models
|
||||
} catch (error: any) {
|
||||
console.error('加载模型列表失败:', error)
|
||||
MessagePlugin.error(error.message || '加载模型列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 打开添加对话框
|
||||
const openAddDialog = (type: 'chat' | 'embedding' | 'rerank' | 'vllm') => {
|
||||
currentModelType.value = type
|
||||
editingModel.value = null
|
||||
showDialog.value = true
|
||||
}
|
||||
|
||||
// 编辑模型
|
||||
const editModel = (type: 'chat' | 'embedding' | 'rerank' | 'vllm', model: any) => {
|
||||
currentModelType.value = type
|
||||
editingModel.value = { ...model }
|
||||
showDialog.value = true
|
||||
}
|
||||
|
||||
// 保存模型
|
||||
const handleModelSave = async (modelData: any) => {
|
||||
try {
|
||||
// 将前端格式转换为后端格式
|
||||
const apiModelData: ModelConfig = {
|
||||
name: modelData.modelName || modelData.name,
|
||||
type: getModelType(currentModelType.value),
|
||||
source: modelData.source,
|
||||
description: '',
|
||||
parameters: {
|
||||
base_url: modelData.baseUrl,
|
||||
api_key: modelData.apiKey,
|
||||
...(currentModelType.value === 'embedding' && modelData.dimension ? {
|
||||
embedding_parameters: {
|
||||
dimension: modelData.dimension,
|
||||
truncate_prompt_tokens: 0
|
||||
}
|
||||
} : {}),
|
||||
...(currentModelType.value === 'vllm' && modelData.interfaceType ? {
|
||||
interface_type: modelData.interfaceType
|
||||
} : {})
|
||||
},
|
||||
is_default: modelData.isDefault || false
|
||||
}
|
||||
|
||||
if (editingModel.value && editingModel.value.id) {
|
||||
// 更新现有模型
|
||||
await updateModelAPI(editingModel.value.id, apiModelData)
|
||||
MessagePlugin.success('模型已更新')
|
||||
} else {
|
||||
// 添加新模型
|
||||
await createModel(apiModelData)
|
||||
MessagePlugin.success('模型已添加')
|
||||
}
|
||||
|
||||
// 重新加载模型列表
|
||||
await loadModels()
|
||||
} catch (error: any) {
|
||||
console.error('保存模型失败:', error)
|
||||
MessagePlugin.error(error.message || '保存模型失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 删除模型
|
||||
const deleteModel = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string) => {
|
||||
try {
|
||||
await deleteModelAPI(modelId)
|
||||
MessagePlugin.success('模型已删除')
|
||||
// 重新加载模型列表
|
||||
await loadModels()
|
||||
} catch (error: any) {
|
||||
console.error('删除模型失败:', error)
|
||||
MessagePlugin.error(error.message || '删除模型失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 设为默认
|
||||
const setDefault = async (type: 'chat' | 'embedding' | 'rerank' | 'vllm', modelId: string) => {
|
||||
try {
|
||||
// 更新模型的 is_default 字段
|
||||
await updateModelAPI(modelId, { is_default: true })
|
||||
MessagePlugin.success('已设为默认模型')
|
||||
// 重新加载模型列表
|
||||
await loadModels()
|
||||
} catch (error: any) {
|
||||
console.error('设置默认模型失败:', error)
|
||||
MessagePlugin.error(error.message || '设置默认模型失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 获取模型操作菜单选项
|
||||
const getModelOptions = (type: 'chat' | 'embedding' | 'rerank' | 'vllm', model: any) => {
|
||||
const options: any[] = []
|
||||
|
||||
// 如果不是默认模型,显示"设为默认"选项
|
||||
if (!model.isDefault) {
|
||||
options.push({
|
||||
content: '设为默认',
|
||||
value: `set-default-${type}-${model.id}`
|
||||
})
|
||||
}
|
||||
|
||||
// 编辑选项
|
||||
options.push({
|
||||
content: '编辑',
|
||||
value: `edit-${type}-${model.id}`
|
||||
})
|
||||
|
||||
// 删除选项
|
||||
options.push({
|
||||
content: '删除',
|
||||
value: `delete-${type}-${model.id}`,
|
||||
theme: 'error'
|
||||
})
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
// 处理菜单操作
|
||||
const handleMenuAction = (data: { value: string }, type: 'chat' | 'embedding' | 'rerank' | 'vllm', model: any) => {
|
||||
const value = data.value
|
||||
|
||||
if (value.indexOf('set-default-') === 0) {
|
||||
setDefault(type, model.id)
|
||||
} else if (value.indexOf('edit-') === 0) {
|
||||
editModel(type, model)
|
||||
} else if (value.indexOf('delete-') === 0) {
|
||||
// 使用确认对话框进行确认
|
||||
if (confirm('确定删除此模型吗?')) {
|
||||
deleteModel(type, model.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取后端模型类型
|
||||
function getModelType(type: 'chat' | 'embedding' | 'rerank' | 'vllm'): 'KnowledgeQA' | 'Embedding' | 'Rerank' | 'VLLM' {
|
||||
const typeMap = {
|
||||
chat: 'KnowledgeQA' as const,
|
||||
embedding: 'Embedding' as const,
|
||||
rerank: 'Rerank' as const,
|
||||
vllm: 'VLLM' as const
|
||||
}
|
||||
return typeMap[type]
|
||||
}
|
||||
|
||||
// 组件挂载时加载模型列表
|
||||
onMounted(() => {
|
||||
loadModels()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.model-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.model-category-section {
|
||||
margin-bottom: 24px;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
background: #ffffff;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.category-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
|
||||
.header-info {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
// 确保按钮内的图标垂直居中
|
||||
:deep(.t-button) {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
.t-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.model-list-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 12px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.model-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 6px;
|
||||
background: #fafafa;
|
||||
transition: all 0.2s;
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
|
||||
&:hover {
|
||||
border-color: #07C05F;
|
||||
background: #ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
.model-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.model-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
margin-bottom: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.model-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-size: 12px;
|
||||
color: #666666;
|
||||
|
||||
.source-tag {
|
||||
padding: 1px 6px;
|
||||
background: #e5e7eb;
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.model-id {
|
||||
font-family: monospace;
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.dimension {
|
||||
color: #999999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.model-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
flex-shrink: 0;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
position: relative;
|
||||
z-index: 1001; // 确保高于设置窗口的z-index (9999)
|
||||
|
||||
.more-btn {
|
||||
color: #666666;
|
||||
padding: 4px;
|
||||
|
||||
&:hover {
|
||||
background: #f5f7fa;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.model-card:hover .model-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 80px 0;
|
||||
text-align: center;
|
||||
|
||||
.empty-text {
|
||||
font-size: 14px;
|
||||
color: #999999;
|
||||
margin: 0 0 16px 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,641 @@
|
||||
<template>
|
||||
<div class="ollama-settings">
|
||||
<div class="section-header">
|
||||
<h2>Ollama 配置</h2>
|
||||
<p class="section-description">管理本地 Ollama 服务,查看和下载模型</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- 启用 Ollama -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>启用 Ollama</label>
|
||||
<p class="desc">启用后可以使用本地 Ollama 模型</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
v-model="localEnabled"
|
||||
@change="handleEnableToggle"
|
||||
size="large"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ollama 服务地址 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>Ollama 服务地址</label>
|
||||
<p class="desc">本地 Ollama 服务的 API 地址</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="url-control-group">
|
||||
<t-input
|
||||
v-model="localBaseUrl"
|
||||
placeholder="http://localhost:11434"
|
||||
:disabled="!localEnabled"
|
||||
style="flex: 1;"
|
||||
/>
|
||||
<div v-if="localEnabled" class="status-indicator">
|
||||
<t-icon
|
||||
v-if="testing"
|
||||
name="loading"
|
||||
class="status-icon spinning"
|
||||
/>
|
||||
<t-icon
|
||||
v-else-if="connectionStatus === true"
|
||||
name="check-circle-filled"
|
||||
class="status-icon success"
|
||||
title="连接成功"
|
||||
/>
|
||||
<t-icon
|
||||
v-else-if="connectionStatus === false"
|
||||
name="close-circle-filled"
|
||||
class="status-icon error"
|
||||
title="连接失败"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<t-alert
|
||||
v-if="connectionStatus === false && localEnabled"
|
||||
theme="error"
|
||||
message="连接失败,请检查 Ollama 是否运行"
|
||||
style="margin-top: 8px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- 已下载的模型 -->
|
||||
<div v-if="localEnabled && connectionStatus" class="model-category-section">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<h3>已下载的模型</h3>
|
||||
<p>已安装在 Ollama 中的模型列表</p>
|
||||
</div>
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
:loading="loadingModels"
|
||||
@click="refreshModels"
|
||||
>
|
||||
<t-icon name="refresh" />刷新
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<div v-if="loadingModels" class="loading-state">
|
||||
<t-loading size="small" />
|
||||
<span>加载中...</span>
|
||||
</div>
|
||||
<div v-else-if="downloadedModels.length > 0" class="model-list-container">
|
||||
<div v-for="model in downloadedModels" :key="model.name" class="model-card">
|
||||
<div class="model-info">
|
||||
<div class="model-name">{{ model.name }}</div>
|
||||
<div class="model-meta">
|
||||
<span class="model-size">{{ formatSize(model.size) }}</span>
|
||||
<span class="model-modified">{{ formatDate(model.modified_at) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-state">
|
||||
<p class="empty-text">暂无已下载的模型</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 下载新模型 -->
|
||||
<div v-if="localEnabled && connectionStatus" class="model-category-section">
|
||||
<div class="category-header">
|
||||
<div class="header-info">
|
||||
<h3>下载新模型</h3>
|
||||
<p>输入模型名称下载,或点击推荐模型快速下载</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="download-content">
|
||||
<div class="input-group">
|
||||
<t-input
|
||||
v-model="downloadModelName"
|
||||
placeholder="如:qwen2.5:0.5b"
|
||||
style="flex: 1;"
|
||||
/>
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="small"
|
||||
:loading="downloading"
|
||||
:disabled="!downloadModelName.trim()"
|
||||
@click="downloadModel"
|
||||
>
|
||||
下载
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<div v-if="downloadProgress > 0" class="download-progress">
|
||||
<div class="progress-info">
|
||||
<span>正在下载: {{ downloadModelName }}</span>
|
||||
<span>{{ downloadProgress.toFixed(2) }}%</span>
|
||||
</div>
|
||||
<t-progress :percentage="downloadProgress" size="small" />
|
||||
</div>
|
||||
|
||||
<div class="recommended-models">
|
||||
<div class="recommended-label">推荐模型:</div>
|
||||
<div class="model-tags">
|
||||
<t-tag
|
||||
v-for="model in popularModels"
|
||||
:key="model"
|
||||
theme="default"
|
||||
variant="outline"
|
||||
class="model-tag"
|
||||
@click="quickDownload(model)"
|
||||
>
|
||||
{{ model }}
|
||||
</t-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { checkOllamaStatus, listOllamaModels, downloadOllamaModel, getDownloadProgress, type OllamaModelInfo } from '@/api/initialization'
|
||||
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
const localEnabled = ref(settingsStore.settings.ollamaConfig?.enabled ?? true)
|
||||
const localBaseUrl = ref(settingsStore.settings.ollamaConfig?.baseUrl ?? '')
|
||||
|
||||
const testing = ref(false)
|
||||
const connectionStatus = ref<boolean | null>(null)
|
||||
const loadingModels = ref(false)
|
||||
const downloadedModels = ref<OllamaModelInfo[]>([])
|
||||
const downloading = ref(false)
|
||||
const downloadModelName = ref('')
|
||||
const downloadProgress = ref(0)
|
||||
|
||||
// 推荐的流行模型
|
||||
const popularModels = [
|
||||
'qwen2.5:0.5b',
|
||||
'qwen2.5:1.5b',
|
||||
'llama3.2:1b',
|
||||
'llama3.2:3b',
|
||||
'gemma2:2b',
|
||||
'phi3:mini'
|
||||
]
|
||||
|
||||
// 处理启用/禁用
|
||||
const handleEnableToggle = (value: boolean) => {
|
||||
settingsStore.updateOllamaConfig({ enabled: value })
|
||||
MessagePlugin.success(value ? 'Ollama 已启用' : 'Ollama 已禁用')
|
||||
|
||||
if (value) {
|
||||
testConnection()
|
||||
} else {
|
||||
connectionStatus.value = null
|
||||
}
|
||||
}
|
||||
|
||||
// 测试连接
|
||||
const testConnection = async () => {
|
||||
if (!localEnabled.value) return
|
||||
|
||||
testing.value = true
|
||||
connectionStatus.value = null
|
||||
|
||||
try {
|
||||
// 保存配置
|
||||
settingsStore.updateOllamaConfig({ baseUrl: localBaseUrl.value })
|
||||
|
||||
// 调用真实 Ollama API 测试连接
|
||||
const result = await checkOllamaStatus()
|
||||
|
||||
// 如果接口返回了 baseUrl 且与当前输入框的值不同,更新为接口返回的值
|
||||
if (result.baseUrl && result.baseUrl !== localBaseUrl.value) {
|
||||
localBaseUrl.value = result.baseUrl
|
||||
settingsStore.updateOllamaConfig({ baseUrl: result.baseUrl })
|
||||
}
|
||||
|
||||
connectionStatus.value = result.available
|
||||
|
||||
if (connectionStatus.value) {
|
||||
MessagePlugin.success('连接成功')
|
||||
refreshModels()
|
||||
} else {
|
||||
MessagePlugin.error(result.error || '连接失败,请检查 Ollama 是否运行')
|
||||
}
|
||||
} catch (error: any) {
|
||||
connectionStatus.value = false
|
||||
MessagePlugin.error(error.message || '连接失败')
|
||||
} finally {
|
||||
testing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新模型列表
|
||||
const refreshModels = async () => {
|
||||
loadingModels.value = true
|
||||
|
||||
try {
|
||||
// 调用真实 Ollama API 获取模型列表(现在返回完整的模型信息)
|
||||
const models = await listOllamaModels()
|
||||
downloadedModels.value = models
|
||||
} catch (error: any) {
|
||||
console.error('获取模型列表失败:', error)
|
||||
MessagePlugin.error(error.message || '获取模型列表失败')
|
||||
} finally {
|
||||
loadingModels.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化文件大小
|
||||
const formatSize = (bytes: number): string => {
|
||||
if (!bytes || bytes === 0 || isNaN(bytes)) return '0 B'
|
||||
if (bytes < 1024) return bytes + ' B'
|
||||
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB'
|
||||
if (bytes < 1024 * 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(2) + ' MB'
|
||||
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + ' GB'
|
||||
}
|
||||
|
||||
// 格式化日期
|
||||
const formatDate = (dateStr: string): string => {
|
||||
if (!dateStr) return '未知'
|
||||
|
||||
const date = new Date(dateStr)
|
||||
// 检查日期是否有效
|
||||
if (isNaN(date.getTime())) return '未知'
|
||||
|
||||
const now = new Date()
|
||||
const diff = now.getTime() - date.getTime()
|
||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24))
|
||||
|
||||
if (days === 0) return '今天'
|
||||
if (days === 1) return '昨天'
|
||||
if (days < 7) return `${days} 天前`
|
||||
if (days < 0) return date.toLocaleDateString('zh-CN')
|
||||
return date.toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
// 下载模型
|
||||
const downloadModel = async () => {
|
||||
if (!downloadModelName.value.trim()) return
|
||||
|
||||
downloading.value = true
|
||||
downloadProgress.value = 0
|
||||
|
||||
try {
|
||||
// 调用真实 Ollama API 下载模型
|
||||
const result = await downloadOllamaModel(downloadModelName.value)
|
||||
|
||||
if (result.status === 'failed') {
|
||||
MessagePlugin.error('下载失败,请稍后重试')
|
||||
downloading.value = false
|
||||
downloadProgress.value = 0
|
||||
return
|
||||
}
|
||||
|
||||
MessagePlugin.success(`已开始下载模型 ${downloadModelName.value}`)
|
||||
|
||||
// 查询下载进度
|
||||
const taskId = result.taskId
|
||||
const progressInterval = setInterval(async () => {
|
||||
try {
|
||||
const task = await getDownloadProgress(taskId)
|
||||
downloadProgress.value = task.progress
|
||||
|
||||
if (task.status === 'completed') {
|
||||
clearInterval(progressInterval)
|
||||
MessagePlugin.success(`模型 ${downloadModelName.value} 下载完成`)
|
||||
downloadModelName.value = ''
|
||||
downloadProgress.value = 0
|
||||
downloading.value = false
|
||||
refreshModels()
|
||||
} else if (task.status === 'failed') {
|
||||
clearInterval(progressInterval)
|
||||
MessagePlugin.error(task.message || '下载失败')
|
||||
downloading.value = false
|
||||
downloadProgress.value = 0
|
||||
}
|
||||
} catch (error) {
|
||||
clearInterval(progressInterval)
|
||||
MessagePlugin.error('查询下载进度失败')
|
||||
downloading.value = false
|
||||
downloadProgress.value = 0
|
||||
}
|
||||
}, 1000)
|
||||
} catch (error: any) {
|
||||
console.error('下载失败:', error)
|
||||
MessagePlugin.error(error.message || '下载失败')
|
||||
downloading.value = false
|
||||
downloadProgress.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
// 快速下载推荐模型
|
||||
const quickDownload = (modelName: string) => {
|
||||
downloadModelName.value = modelName
|
||||
downloadModel()
|
||||
}
|
||||
|
||||
// 初始化 Ollama 服务地址
|
||||
const initOllamaBaseUrl = async () => {
|
||||
try {
|
||||
const result = await checkOllamaStatus()
|
||||
// 如果接口返回了 baseUrl,优先使用接口返回的值
|
||||
if (result.baseUrl) {
|
||||
localBaseUrl.value = result.baseUrl
|
||||
// 如果 store 中没有保存过,也保存到 store 中
|
||||
if (!settingsStore.settings.ollamaConfig?.baseUrl) {
|
||||
settingsStore.updateOllamaConfig({ baseUrl: result.baseUrl })
|
||||
}
|
||||
} else if (!localBaseUrl.value) {
|
||||
// 如果接口没返回且 store 中也没有,使用默认值
|
||||
localBaseUrl.value = 'http://localhost:11434'
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('初始化 Ollama 地址失败:', error)
|
||||
// 如果获取失败,使用默认值或 store 中的值
|
||||
if (!localBaseUrl.value) {
|
||||
localBaseUrl.value = 'http://localhost:11434'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载时自动检查连接
|
||||
onMounted(async () => {
|
||||
// 先初始化服务地址
|
||||
await initOllamaBaseUrl()
|
||||
|
||||
if (localEnabled.value) {
|
||||
testConnection()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.ollama-settings {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 420px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.url-control-group {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
.status-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
.status-icon {
|
||||
font-size: 18px;
|
||||
|
||||
&.success {
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: #e34d59;
|
||||
}
|
||||
|
||||
&.spinning {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.model-category-section {
|
||||
margin-bottom: 24px;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
background: #ffffff;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.category-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
|
||||
.header-info {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding: 60px;
|
||||
color: #666666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.model-list-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 12px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.model-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 6px;
|
||||
background: #fafafa;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
border-color: #07C05F;
|
||||
background: #ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
.model-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.model-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
margin-bottom: 4px;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.model-meta {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
font-size: 12px;
|
||||
color: #666666;
|
||||
}
|
||||
}
|
||||
|
||||
.download-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.download-progress {
|
||||
padding: 12px;
|
||||
background: #f5f7fa;
|
||||
border-radius: 6px;
|
||||
|
||||
.progress-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
font-size: 13px;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
|
||||
.recommended-models {
|
||||
.recommended-label {
|
||||
font-size: 13px;
|
||||
color: #666666;
|
||||
margin: 0 0 10px 0;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.model-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
|
||||
.model-tag {
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
font-size: 12px;
|
||||
|
||||
&:hover {
|
||||
background: #07C05F;
|
||||
color: #ffffff;
|
||||
border-color: #07C05F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 80px 0;
|
||||
text-align: center;
|
||||
|
||||
.empty-text {
|
||||
font-size: 14px;
|
||||
color: #999999;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,100 +1,489 @@
|
||||
<template>
|
||||
<div class="settings-container">
|
||||
<div class="settings-header">
|
||||
<h2>系统配置</h2>
|
||||
<Teleport to="body">
|
||||
<Transition name="modal">
|
||||
<div v-if="visible" class="settings-overlay">
|
||||
<div class="settings-modal">
|
||||
<!-- 关闭按钮 -->
|
||||
<button class="close-btn" @click="handleClose" aria-label="关闭设置">
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M15 5L5 15M5 5L15 15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div class="settings-container">
|
||||
<!-- 左侧导航 -->
|
||||
<div class="settings-sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h2 class="sidebar-title">设置</h2>
|
||||
</div>
|
||||
<div class="settings-nav">
|
||||
<template v-for="(item, index) in navItems" :key="index">
|
||||
<div
|
||||
:class="['nav-item', {
|
||||
'active': currentSection === item.key,
|
||||
'has-submenu': item.children && item.children.length > 0,
|
||||
'expanded': expandedMenus.includes(item.key)
|
||||
}]"
|
||||
@click="handleNavClick(item)"
|
||||
>
|
||||
<span class="nav-icon">{{ item.icon }}</span>
|
||||
<span class="nav-label">{{ item.label }}</span>
|
||||
<t-icon
|
||||
v-if="item.children && item.children.length > 0"
|
||||
:name="expandedMenus.includes(item.key) ? 'chevron-down' : 'chevron-right'"
|
||||
class="expand-icon"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 子菜单 -->
|
||||
<Transition name="submenu">
|
||||
<div
|
||||
v-if="item.children && expandedMenus.includes(item.key)"
|
||||
class="submenu"
|
||||
>
|
||||
<div
|
||||
v-for="(child, childIndex) in item.children"
|
||||
:key="childIndex"
|
||||
:class="['submenu-item', { 'active': currentSubSection === child.key }]"
|
||||
@click.stop="handleSubMenuClick(item.key, child.key)"
|
||||
>
|
||||
<span class="submenu-label">{{ child.label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧内容区域 -->
|
||||
<div class="settings-content">
|
||||
<div class="content-wrapper">
|
||||
<!-- 常规设置 -->
|
||||
<div v-show="currentSection === 'general'" class="section">
|
||||
<GeneralSettings />
|
||||
</div>
|
||||
|
||||
<!-- 模型配置 -->
|
||||
<div v-show="currentSection === 'models'" class="section">
|
||||
<ModelSettings />
|
||||
</div>
|
||||
|
||||
<!-- Ollama 设置 -->
|
||||
<div v-show="currentSection === 'ollama'" class="section">
|
||||
<OllamaSettings />
|
||||
</div>
|
||||
|
||||
<!-- 知识库设置 -->
|
||||
<div v-show="currentSection === 'knowledge'" class="section">
|
||||
<KnowledgeBaseSettings />
|
||||
</div>
|
||||
|
||||
<!-- Agent 配置 -->
|
||||
<div v-show="currentSection === 'agent'" class="section">
|
||||
<AgentSettings />
|
||||
</div>
|
||||
|
||||
<!-- 系统信息 -->
|
||||
<div v-show="currentSection === 'system'" class="section">
|
||||
<SystemInfo />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-form">
|
||||
<t-form ref="form" :data="formData" :rules="rules" @submit="onSubmit">
|
||||
<t-form-item label="API 服务端点" name="endpoint">
|
||||
<t-input v-model="formData.endpoint" placeholder="请输入API服务端点,例如:http://localhost" />
|
||||
</t-form-item>
|
||||
<t-form-item label="API Key" name="apiKey">
|
||||
<t-input v-model="formData.apiKey" placeholder="请输入API Key" />
|
||||
</t-form-item>
|
||||
<t-form-item label="知识库ID" name="knowledgeBaseId">
|
||||
<t-input v-model="formData.knowledgeBaseId" placeholder="请输入知识库ID" />
|
||||
</t-form-item>
|
||||
<t-form-item>
|
||||
<t-space>
|
||||
<t-button theme="primary" type="submit">保存配置</t-button>
|
||||
<t-button theme="default" @click="resetForm">重置</t-button>
|
||||
</t-space>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { MessagePlugin } from 'tdesign-vue-next';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import AgentSettings from './AgentSettings.vue'
|
||||
import SystemInfo from './SystemInfo.vue'
|
||||
import GeneralSettings from './GeneralSettings.vue'
|
||||
import ModelSettings from './ModelSettings.vue'
|
||||
import KnowledgeBaseSettings from './KnowledgeBaseSettings.vue'
|
||||
import OllamaSettings from './OllamaSettings.vue'
|
||||
|
||||
const settingsStore = useSettingsStore();
|
||||
const form = ref(null);
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const uiStore = useUIStore()
|
||||
|
||||
const formData = reactive({
|
||||
endpoint: '',
|
||||
apiKey: '',
|
||||
knowledgeBaseId: ''
|
||||
});
|
||||
const currentSection = ref<string>('general')
|
||||
const currentSubSection = ref<string>('')
|
||||
const expandedMenus = ref<string[]>([])
|
||||
|
||||
const rules = {
|
||||
endpoint: [{ required: true, message: '请输入API服务端点', trigger: 'blur' }],
|
||||
apiKey: [{ required: true, message: '请输入API Key', trigger: 'blur' }],
|
||||
knowledgeBaseId: [{ required: true, message: '请输入知识库ID', trigger: 'blur' }]
|
||||
};
|
||||
const navItems = [
|
||||
{ key: 'general', icon: '⚙️', label: '常规' },
|
||||
{
|
||||
key: 'models',
|
||||
icon: '🤖',
|
||||
label: '模型配置',
|
||||
children: [
|
||||
{ key: 'chat', label: '对话模型' },
|
||||
{ key: 'embedding', label: 'Embedding' },
|
||||
{ key: 'rerank', label: 'ReRank' },
|
||||
{ key: 'vllm', label: 'VLLM' }
|
||||
]
|
||||
},
|
||||
{ key: 'ollama', icon: '🦙', label: 'Ollama' },
|
||||
{ key: 'knowledge', icon: '📚', label: '知识库' },
|
||||
{ key: 'agent', icon: '🧠', label: 'Agent 配置' },
|
||||
{ key: 'system', icon: 'ℹ️', label: '系统信息' }
|
||||
]
|
||||
|
||||
// 导航项点击处理
|
||||
const handleNavClick = (item: any) => {
|
||||
if (item.children && item.children.length > 0) {
|
||||
// 有子菜单,切换展开状态
|
||||
const index = expandedMenus.value.indexOf(item.key)
|
||||
if (index > -1) {
|
||||
expandedMenus.value.splice(index, 1)
|
||||
} else {
|
||||
expandedMenus.value.push(item.key)
|
||||
}
|
||||
}
|
||||
|
||||
// 切换到对应页面
|
||||
currentSection.value = item.key
|
||||
currentSubSection.value = ''
|
||||
}
|
||||
|
||||
// 子菜单点击处理
|
||||
const handleSubMenuClick = (parentKey: string, childKey: string) => {
|
||||
currentSection.value = parentKey
|
||||
currentSubSection.value = childKey
|
||||
|
||||
// 滚动到对应的模型类型区域
|
||||
setTimeout(() => {
|
||||
const element = document.querySelector(`[data-model-type="${childKey}"]`)
|
||||
if (element) {
|
||||
element.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
|
||||
// 控制弹窗显示
|
||||
const visible = computed(() => {
|
||||
return route.path === '/platform/settings' || uiStore.showSettingsModal
|
||||
})
|
||||
|
||||
// 关闭弹窗
|
||||
const handleClose = () => {
|
||||
uiStore.closeSettings()
|
||||
// 如果当前路由是设置页,返回上一页
|
||||
if (route.path === '/platform/settings') {
|
||||
router.back()
|
||||
}
|
||||
}
|
||||
|
||||
// ESC 键关闭
|
||||
const handleEscape = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && visible.value) {
|
||||
handleClose()
|
||||
}
|
||||
}
|
||||
|
||||
// 处理快捷导航事件
|
||||
const handleSettingsNav = (e: CustomEvent) => {
|
||||
const { section, subsection } = e.detail
|
||||
if (section) {
|
||||
currentSection.value = section
|
||||
// 如果有子菜单,自动展开
|
||||
const navItem = (navItems as any).find((item: any) => item.key === section)
|
||||
if (navItem && navItem.children && navItem.children.length > 0) {
|
||||
if (!expandedMenus.value.includes(section)) {
|
||||
expandedMenus.value.push(section)
|
||||
}
|
||||
// 如果有 subsection,选中对应的子菜单项
|
||||
if (subsection) {
|
||||
currentSubSection.value = subsection
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 初始化表单数据
|
||||
const settings = settingsStore.getSettings();
|
||||
formData.endpoint = settings.endpoint;
|
||||
formData.apiKey = settings.apiKey;
|
||||
formData.knowledgeBaseId = settings.knowledgeBaseId;
|
||||
});
|
||||
window.addEventListener('keydown', handleEscape)
|
||||
window.addEventListener('settings-nav', handleSettingsNav as EventListener)
|
||||
})
|
||||
|
||||
const onSubmit = ({ validateResult }) => {
|
||||
if (validateResult === true) {
|
||||
settingsStore.saveSettings({
|
||||
endpoint: formData.endpoint,
|
||||
apiKey: formData.apiKey,
|
||||
knowledgeBaseId: formData.knowledgeBaseId
|
||||
});
|
||||
MessagePlugin.success('配置保存成功');
|
||||
}
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
const settings = settingsStore.getSettings();
|
||||
formData.endpoint = settings.endpoint;
|
||||
formData.apiKey = settings.apiKey;
|
||||
formData.knowledgeBaseId = settings.knowledgeBaseId;
|
||||
};
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('keydown', handleEscape)
|
||||
window.removeEventListener('settings-nav', handleSettingsNav as EventListener)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.settings-container {
|
||||
padding: 20px;
|
||||
background-color: #fff;
|
||||
border-radius: 8px;
|
||||
margin: 20px;
|
||||
min-height: 80vh;
|
||||
|
||||
.settings-header {
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
padding-bottom: 16px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #000000;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-form {
|
||||
max-width: 600px;
|
||||
}
|
||||
/* 遮罩层 */
|
||||
.settings-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 999;
|
||||
background: transparent;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
/* 弹窗容器 */
|
||||
.settings-modal {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
height: 700px;
|
||||
background: #ffffff;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 6px 28px rgba(15, 23, 42, 0.08);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* 关闭按钮 */
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: #666666;
|
||||
cursor: pointer;
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s ease;
|
||||
z-index: 10;
|
||||
|
||||
&:hover {
|
||||
background: #f5f5f5;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-container {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 左侧导航栏 */
|
||||
.settings-sidebar {
|
||||
width: 220px;
|
||||
background-color: #f8f9fa;
|
||||
border-right: 1px solid #e5e7eb;
|
||||
flex-shrink: 0;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 24px 16px 16px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-nav {
|
||||
padding: 16px 8px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px 16px;
|
||||
margin-bottom: 4px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #666666;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
|
||||
&:hover {
|
||||
background-color: #e8f5ed;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: rgba(7, 192, 95, 0.1);
|
||||
color: #07C05F;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-icon {
|
||||
margin-right: 12px;
|
||||
font-size: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.nav-label {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
margin-left: 4px;
|
||||
font-size: 14px;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
/* 子菜单 */
|
||||
.submenu {
|
||||
margin-left: 32px;
|
||||
margin-bottom: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.submenu-item {
|
||||
padding: 8px 16px;
|
||||
margin-bottom: 2px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
color: #666666;
|
||||
font-size: 13px;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
|
||||
&:hover {
|
||||
background-color: #f5f7fa;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: rgba(7, 192, 95, 0.08);
|
||||
color: #07C05F;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.submenu-label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* 子菜单动画 */
|
||||
.submenu-enter-active,
|
||||
.submenu-leave-active {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.submenu-enter-from {
|
||||
opacity: 0;
|
||||
max-height: 0;
|
||||
}
|
||||
|
||||
.submenu-enter-to {
|
||||
opacity: 1;
|
||||
max-height: 300px;
|
||||
}
|
||||
|
||||
.submenu-leave-from {
|
||||
opacity: 1;
|
||||
max-height: 300px;
|
||||
}
|
||||
|
||||
.submenu-leave-to {
|
||||
opacity: 0;
|
||||
max-height: 0;
|
||||
}
|
||||
|
||||
/* 右侧内容区域 */
|
||||
.settings-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
max-width: 600px;
|
||||
padding: 40px 48px;
|
||||
}
|
||||
|
||||
.section {
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* 弹窗动画 */
|
||||
.modal-enter-active,
|
||||
.modal-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.modal-enter-active .settings-modal,
|
||||
.modal-leave-active .settings-modal {
|
||||
transition: transform 0.2s ease, opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.modal-enter-from,
|
||||
.modal-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.modal-enter-from .settings-modal,
|
||||
.modal-leave-to .settings-modal {
|
||||
transform: scale(0.95);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* 滚动条样式 */
|
||||
.settings-sidebar::-webkit-scrollbar,
|
||||
.settings-content::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.settings-sidebar::-webkit-scrollbar-track {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.settings-sidebar::-webkit-scrollbar-thumb {
|
||||
background: #d0d0d0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.settings-sidebar::-webkit-scrollbar-thumb:hover {
|
||||
background: #b0b0b0;
|
||||
}
|
||||
|
||||
.settings-content::-webkit-scrollbar-track {
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.settings-content::-webkit-scrollbar-thumb {
|
||||
background: #d0d0d0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.settings-content::-webkit-scrollbar-thumb:hover {
|
||||
background: #b0b0b0;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -0,0 +1,533 @@
|
||||
<template>
|
||||
<div class="system-info">
|
||||
<div class="section-header">
|
||||
<h2>系统信息</h2>
|
||||
<p class="section-description">查看系统版本信息和用户账户配置</p>
|
||||
</div>
|
||||
|
||||
<!-- 加载状态 -->
|
||||
<div v-if="loading" class="loading-inline">
|
||||
<t-loading size="small" />
|
||||
<span>正在加载信息...</span>
|
||||
</div>
|
||||
|
||||
<!-- 错误状态 -->
|
||||
<div v-else-if="error" class="error-inline">
|
||||
<t-alert theme="error" :message="error">
|
||||
<template #operation>
|
||||
<t-button size="small" @click="loadInfo">重试</t-button>
|
||||
</template>
|
||||
</t-alert>
|
||||
</div>
|
||||
|
||||
<!-- 信息内容 -->
|
||||
<div v-else class="settings-group">
|
||||
<!-- 系统信息分组 -->
|
||||
<div class="info-section-title">系统信息</div>
|
||||
|
||||
<!-- 系统版本 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>系统版本</label>
|
||||
<p class="desc">当前系统的版本号</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">
|
||||
{{ systemInfo?.version || '未知' }}
|
||||
<span v-if="systemInfo?.commit_id" class="commit-info">
|
||||
({{ systemInfo.commit_id }})
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 构建时间 -->
|
||||
<div v-if="systemInfo?.build_time" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>构建时间</label>
|
||||
<p class="desc">系统构建的时间</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ systemInfo.build_time }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Go版本 -->
|
||||
<div v-if="systemInfo?.go_version" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>Go 版本</label>
|
||||
<p class="desc">后端使用的 Go 语言版本</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ systemInfo.go_version }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户信息分组 -->
|
||||
<div class="info-section-title">用户信息</div>
|
||||
|
||||
<!-- 用户 ID -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>用户 ID</label>
|
||||
<p class="desc">您的唯一用户标识</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ userInfo?.id || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户名 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>用户名</label>
|
||||
<p class="desc">您的登录用户名</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ userInfo?.username || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 邮箱 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>邮箱</label>
|
||||
<p class="desc">您的注册邮箱地址</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ userInfo?.email || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户创建时间 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>注册时间</label>
|
||||
<p class="desc">账户创建的时间</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ formatDate(userInfo?.created_at) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 租户信息分组 -->
|
||||
<div class="info-section-title">租户信息</div>
|
||||
|
||||
<!-- 租户 ID -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>租户 ID</label>
|
||||
<p class="desc">您所属租户的唯一标识</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ tenantInfo?.id || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 租户名称 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>租户名称</label>
|
||||
<p class="desc">您所属的租户名称</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ tenantInfo?.name || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 租户描述 -->
|
||||
<div v-if="tenantInfo?.description" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>租户描述</label>
|
||||
<p class="desc">租户的详细描述信息</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ tenantInfo.description }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 租户业务 -->
|
||||
<div v-if="tenantInfo?.business" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>租户业务</label>
|
||||
<p class="desc">租户所属的业务类型</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ tenantInfo.business }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 租户状态 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>租户状态</label>
|
||||
<p class="desc">租户当前的运行状态</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-tag
|
||||
:theme="getStatusTheme(tenantInfo?.status)"
|
||||
variant="light"
|
||||
size="small"
|
||||
>
|
||||
{{ getStatusText(tenantInfo?.status) }}
|
||||
</t-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 租户创建时间 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>租户创建时间</label>
|
||||
<p class="desc">租户创建的时间</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ formatDate(tenantInfo?.created_at) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- API 信息分组 -->
|
||||
<div class="info-section-title">API 信息</div>
|
||||
|
||||
<!-- API Key -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>API Key</label>
|
||||
<p class="desc">用于 API 调用的密钥,请妥善保管</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="api-key-control">
|
||||
<t-input
|
||||
v-model="displayApiKey"
|
||||
readonly
|
||||
:type="showApiKey ? 'text' : 'password'"
|
||||
style="width: 100%; font-family: monospace; font-size: 12px;"
|
||||
/>
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="showApiKey = !showApiKey"
|
||||
>
|
||||
<t-icon :name="showApiKey ? 'browse-off' : 'browse'" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 存储配额 -->
|
||||
<div v-if="tenantInfo?.storage_quota !== undefined" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>存储配额</label>
|
||||
<p class="desc">租户的总存储空间配额</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ formatBytes(tenantInfo.storage_quota) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 已使用存储 -->
|
||||
<div v-if="tenantInfo?.storage_quota !== undefined" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>已使用存储</label>
|
||||
<p class="desc">已经使用的存储空间</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ formatBytes(tenantInfo.storage_used || 0) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 存储使用率 -->
|
||||
<div v-if="tenantInfo?.storage_quota !== undefined" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>存储使用率</label>
|
||||
<p class="desc">存储空间的使用百分比</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="usage-control">
|
||||
<span class="usage-text">{{ getUsagePercentage() }}%</span>
|
||||
<t-progress
|
||||
:percentage="getUsagePercentage()"
|
||||
:show-info="false"
|
||||
size="small"
|
||||
:theme="getUsagePercentage() > 80 ? 'warning' : 'success'"
|
||||
style="flex: 1;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 开发文档分组 -->
|
||||
<div class="info-section-title">开发文档</div>
|
||||
|
||||
<!-- API 文档 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>API 开发文档</label>
|
||||
<p class="desc">查看完整的 API 文档和示例代码</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="small"
|
||||
@click="openApiDoc"
|
||||
>
|
||||
<t-icon name="link" />
|
||||
查看文档
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { getCurrentUser, type TenantInfo, type UserInfo } from '@/api/auth'
|
||||
import { getSystemInfo, type SystemInfo } from '@/api/system'
|
||||
|
||||
// 响应式数据
|
||||
const tenantInfo = ref<TenantInfo | null>(null)
|
||||
const userInfo = ref<UserInfo | null>(null)
|
||||
const systemInfo = ref<SystemInfo | null>(null)
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
const showApiKey = ref(false)
|
||||
|
||||
// 计算属性
|
||||
const displayApiKey = computed(() => {
|
||||
if (!tenantInfo.value?.api_key) return ''
|
||||
return tenantInfo.value.api_key
|
||||
})
|
||||
|
||||
// 方法
|
||||
const loadInfo = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
|
||||
// 并行获取用户信息和系统信息
|
||||
const [userResponse, systemResponse] = await Promise.all([
|
||||
getCurrentUser(),
|
||||
getSystemInfo().catch(() => ({ data: null }))
|
||||
])
|
||||
|
||||
if (userResponse.success && userResponse.data) {
|
||||
userInfo.value = userResponse.data.user
|
||||
tenantInfo.value = userResponse.data.tenant
|
||||
} else {
|
||||
error.value = userResponse.message || '获取用户信息失败'
|
||||
}
|
||||
|
||||
if (systemResponse.data) {
|
||||
systemInfo.value = systemResponse.data
|
||||
}
|
||||
} catch (err: any) {
|
||||
error.value = err.message || '网络错误,请稍后重试'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openApiDoc = () => {
|
||||
window.open('https://github.com/Tencent/WeKnora/blob/main/docs/API.md', '_blank')
|
||||
}
|
||||
|
||||
const getStatusText = (status: string | undefined) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return '活跃'
|
||||
case 'inactive':
|
||||
return '未激活'
|
||||
case 'suspended':
|
||||
return '已暂停'
|
||||
default:
|
||||
return '未知'
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusTheme = (status: string | undefined) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return 'success'
|
||||
case 'inactive':
|
||||
return 'warning'
|
||||
case 'suspended':
|
||||
return 'danger'
|
||||
default:
|
||||
return 'default'
|
||||
}
|
||||
}
|
||||
|
||||
const formatDate = (dateStr: string | undefined) => {
|
||||
if (!dateStr) return '未知'
|
||||
|
||||
try {
|
||||
const date = new Date(dateStr)
|
||||
return date.toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
})
|
||||
} catch {
|
||||
return '格式错误'
|
||||
}
|
||||
}
|
||||
|
||||
const formatBytes = (bytes: number) => {
|
||||
if (bytes === 0) return '0 B'
|
||||
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
const getUsagePercentage = () => {
|
||||
if (!tenantInfo.value?.storage_quota || tenantInfo.value.storage_quota === 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const used = tenantInfo.value.storage_used || 0
|
||||
const percentage = (used / tenantInfo.value.storage_quota) * 100
|
||||
return Math.min(Math.round(percentage * 100) / 100, 100)
|
||||
}
|
||||
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
loadInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.system-info {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-inline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 40px 0;
|
||||
justify-content: center;
|
||||
color: #666666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.error-inline {
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
|
||||
.info-value {
|
||||
font-size: 14px;
|
||||
color: #333333;
|
||||
text-align: right;
|
||||
word-break: break-word;
|
||||
|
||||
.commit-info {
|
||||
color: #999999;
|
||||
font-size: 12px;
|
||||
margin-left: 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.api-key-control {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.usage-control {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
.usage-text {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
min-width: 50px;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
||||
.info-section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin-top: 24px;
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,211 +0,0 @@
|
||||
<template>
|
||||
<div class="system-settings-container">
|
||||
<!-- 页面标题区域 -->
|
||||
<div class="settings-header">
|
||||
<h2>{{ isKbSettings ? '知识库设置' : '系统设置' }}</h2>
|
||||
<p class="settings-subtitle">{{ isKbSettings ? '配置该知识库的模型与文档切分参数' : '管理和更新系统模型与服务配置' }}</p>
|
||||
</div>
|
||||
|
||||
<!-- 配置内容 -->
|
||||
<div class="settings-content">
|
||||
<!-- 系统设置:使用初始化配置 -->
|
||||
<InitializationContent v-if="!isKbSettings" />
|
||||
<!-- 知识库设置:基础信息与文档切分配置 -->
|
||||
<div v-else>
|
||||
<t-form :data="kbForm" @submit="saveKb">
|
||||
<div class="config-section">
|
||||
<h3><span class="section-icon">⚙️</span>基础信息</h3>
|
||||
<t-form-item label="名称" name="name" :rules="[{ required: true, message: '请输入名称' }]">
|
||||
<t-input v-model="kbForm.name" />
|
||||
</t-form-item>
|
||||
<t-form-item label="描述" name="description">
|
||||
<t-textarea v-model="kbForm.description" />
|
||||
</t-form-item>
|
||||
</div>
|
||||
<div class="config-section">
|
||||
<h3><span class="section-icon">📄</span>文档切分</h3>
|
||||
<t-row :gutter="16">
|
||||
<t-col :span="6">
|
||||
<t-form-item label="Chunk Size" name="chunkSize">
|
||||
<t-input-number v-model="kbForm.config.chunking_config.chunk_size" :min="1" />
|
||||
</t-form-item>
|
||||
</t-col>
|
||||
<t-col :span="6">
|
||||
<t-form-item label="Chunk Overlap" name="chunkOverlap">
|
||||
<t-input-number v-model="kbForm.config.chunking_config.chunk_overlap" :min="0" />
|
||||
</t-form-item>
|
||||
</t-col>
|
||||
</t-row>
|
||||
</div>
|
||||
<div class="submit-section">
|
||||
<t-button theme="primary" type="submit" :loading="saving">保存</t-button>
|
||||
</div>
|
||||
</t-form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { getKnowledgeBaseById, updateKnowledgeBase } from '@/api/knowledge-base'
|
||||
|
||||
// 异步加载初始化配置组件
|
||||
const InitializationContent = defineAsyncComponent(() => import('../initialization/InitializationContent.vue'))
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const isKbSettings = ref<boolean>(false)
|
||||
|
||||
interface KbForm {
|
||||
name: string
|
||||
description?: string
|
||||
config: { chunking_config: { chunk_size: number; chunk_overlap: number } }
|
||||
}
|
||||
const kbForm = reactive<KbForm>({
|
||||
name: '',
|
||||
description: '',
|
||||
config: { chunking_config: { chunk_size: 512, chunk_overlap: 64 } }
|
||||
})
|
||||
const saving = ref(false)
|
||||
|
||||
const loadKb = () => {
|
||||
const kbId = (route.params as any).kbId as string
|
||||
if (!kbId) return
|
||||
getKnowledgeBaseById(kbId).then((res: any) => {
|
||||
if (res?.data) {
|
||||
kbForm.name = res.data.name
|
||||
kbForm.description = res.data.description
|
||||
const cc = res.data.chunking_config || {}
|
||||
kbForm.config.chunking_config.chunk_size = cc.chunk_size ?? 512
|
||||
kbForm.config.chunking_config.chunk_overlap = cc.chunk_overlap ?? 64
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
isKbSettings.value = route.name === 'knowledgeBaseSettings'
|
||||
if (isKbSettings.value) loadKb()
|
||||
})
|
||||
|
||||
const saveKb = () => {
|
||||
const kbId = (route.params as any).kbId as string
|
||||
if (!kbId) return
|
||||
saving.value = true
|
||||
updateKnowledgeBase(kbId, { name: kbForm.name, description: kbForm.description, config: { chunking_config: { chunk_size: kbForm.config.chunking_config.chunk_size, chunk_overlap: kbForm.config.chunking_config.chunk_overlap, separators: [], enable_multimodal: false }, image_processing_config: { model_id: '' } } })
|
||||
.then((res: any) => {
|
||||
if (res.success) {
|
||||
MessagePlugin.success('保存成功')
|
||||
} else {
|
||||
MessagePlugin.error(res.message || '保存失败')
|
||||
}
|
||||
})
|
||||
.catch((e: any) => MessagePlugin.error(e?.message || '保存失败'))
|
||||
.finally(() => saving.value = false)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.system-settings-container {
|
||||
padding: 20px;
|
||||
background-color: #fff;
|
||||
margin: 0 20px 0 20px;
|
||||
height: calc(100vh);
|
||||
overflow-y: auto;
|
||||
box-sizing: border-box;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
padding-bottom: 16px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #000000;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.settings-subtitle {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 768px) {
|
||||
.system-settings-container {
|
||||
padding: 16px;
|
||||
margin: 10px;
|
||||
height: calc(100vh - 20px);
|
||||
}
|
||||
|
||||
.settings-header h2 {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 覆盖TDesign组件样式,与账户信息页面保持一致 */
|
||||
:deep(.t-card) {
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
border: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
/* 调整InitializationContent内部样式,使每个配置区域显示为独立卡片 */
|
||||
:deep(.config-section) {
|
||||
background: #fff;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #000000;
|
||||
margin: 0 0 16px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0;
|
||||
background: none;
|
||||
border-left: none;
|
||||
border-radius: 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
padding-bottom: 12px;
|
||||
|
||||
.section-icon {
|
||||
margin-right: 8px;
|
||||
color: #07c05f;
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.ollama-summary-card) {
|
||||
background: #fff;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
:deep(.submit-section) {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||