App.vue
9.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<template>
<el-container class="app-shell">
<el-header height="64px" class="app-header">
<div class="app-header-left">
<div class="app-logo">
<div class="logo-box">IF</div>
</div>
<div class="app-title-group">
<span class="app-title">Intent Fusion</span>
<span class="app-subtitle">SaaS Dual-Channel Routing Engine</span>
</div>
</div>
<div class="app-actions">
<el-button class="action-btn upload-btn" @click="showUploadDialog = true">
<el-icon class="btn-icon"><Upload /></el-icon>
<span>上传意图类别</span>
</el-button>
<el-button class="action-btn refresh-btn" @click="catalog.refresh" :loading="catalog.loading">
<el-icon class="btn-icon" v-if="!catalog.loading"><Refresh /></el-icon>
<span>刷新意图</span>
</el-button>
<el-button class="action-btn clear-btn" @click="chat.clear" :disabled="chat.messages.length === 0">
<el-icon class="btn-icon"><Delete /></el-icon>
<span>清空对话</span>
</el-button>
</div>
</el-header>
<el-main class="app-main">
<router-view />
</el-main>
<!-- 上传自定义意图类别对话框 -->
<el-dialog
v-model="showUploadDialog"
title="上传自定义意图类别"
width="460px"
destroy-on-close
class="custom-dialog"
>
<div class="dialog-body-desc">
上传你的 <code>intents.yaml</code> 意图配置文件。系统会自动编译对应的 Embedding 向量索引并建立多级大模型推理树。
</div>
<el-form label-position="top">
<el-form-item label="意图类别标识 (唯一ID,如 glsx_json)" required>
<el-input
v-model="uploadName"
placeholder="如: glsx_json"
class="custom-input"
/>
</el-form-item>
<el-form-item label="选择 YAML 意图配置文件 (intents.yaml)" required>
<div class="file-upload-wrapper">
<input type="file" accept=".yaml,.yml" @change="onFileChange" class="hidden-file-input" id="yaml-file-input" />
<label for="yaml-file-input" class="file-upload-label">
<el-icon class="upload-icon"><Document /></el-icon>
<span class="upload-text">{{ uploadFile ? uploadFile.name : '点击选择 intents.yaml 文件' }}</span>
</label>
</div>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button class="dialog-btn cancel-btn" @click="showUploadDialog = false">取消</el-button>
<el-button
class="dialog-btn submit-btn"
type="primary"
:loading="uploading"
:disabled="!uploadName || !uploadFile"
@click="handleUpload"
>
上传并自动应用
</el-button>
</div>
</template>
</el-dialog>
</el-container>
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useCatalogStore } from "./stores/catalog";
import { useChatStore } from "./stores/chat";
import { ElMessage } from "element-plus";
import { Upload, Refresh, Delete, Document } from "@element-plus/icons-vue";
const catalog = useCatalogStore();
const chat = useChatStore();
const showUploadDialog = ref(false);
const uploadName = ref("");
const uploadFile = ref<File | null>(null);
const uploading = ref(false);
function onFileChange(event: Event) {
const target = event.target as HTMLInputElement;
if (target.files && target.files.length > 0) {
uploadFile.value = target.files[0];
} else {
uploadFile.value = null;
}
}
async function handleUpload() {
const datasetName = uploadName.value.trim();
if (!datasetName || !uploadFile.value) return;
uploading.value = true;
try {
const reader = new FileReader();
reader.onload = async (e) => {
const yamlContent = e.target?.result as string;
try {
const response = await fetch("/api/intents/upload", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: datasetName,
yaml_content: yamlContent,
}),
});
const resData = await response.json();
if (!response.ok) {
throw new Error(resData.error || `HTTP ${response.status}`);
}
ElMessage.success("上传成功!正在切换至新上传的意图类别...");
showUploadDialog.value = false;
// 刷新数据集列表
await catalog.refreshDatasets();
// 切换到新上传的类别(默认为 uploads/名称)
const datasetKey = resData.dataset || `uploads/${datasetName}`;
await catalog.switchDataset(datasetKey);
// 重置状态
uploadName.value = "";
uploadFile.value = null;
} catch (err: any) {
ElMessage.error(`上传失败: ${err.message || err}`);
} finally {
uploading.value = false;
}
};
reader.readAsText(uploadFile.value);
} catch (err: any) {
ElMessage.error(`读取文件失败: ${err.message || err}`);
uploading.value = false;
}
}
onMounted(() => {
catalog.refreshDatasets();
catalog.refresh();
});
</script>
<style scoped>
.app-shell {
height: 100%;
overflow: hidden;
font-family: 'Inter', system-ui, -apple-system, sans-serif;
background-color: #f8fafc;
}
.app-header {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid rgba(226, 232, 240, 0.8);
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(12px);
padding: 0 24px;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.02);
}
.app-header-left {
display: flex;
align-items: center;
gap: 12px;
}
.app-logo {
display: flex;
align-items: center;
justify-content: center;
}
.logo-box {
width: 32px;
height: 32px;
background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);
color: white;
font-weight: 800;
font-size: 14px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
font-family: 'Plus Jakarta Sans', sans-serif;
}
.app-title-group {
display: flex;
flex-direction: column;
}
.app-title {
font-family: 'Plus Jakarta Sans', sans-serif;
font-weight: 800;
font-size: 16px;
color: #0f172a;
letter-spacing: -0.02em;
line-height: 1.2;
}
.app-subtitle {
font-size: 11px;
color: #64748b;
font-weight: 500;
}
.app-actions {
display: flex;
gap: 10px;
align-items: center;
}
.action-btn {
border-radius: 8px;
font-weight: 600;
font-size: 13px;
height: 36px;
padding: 0 16px;
display: inline-flex;
align-items: center;
gap: 6px;
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
border: 1px solid #e2e8f0;
background: #ffffff;
color: #334155;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.action-btn:hover {
border-color: #cbd5e1;
background: #f8fafc;
color: #0f172a;
transform: translateY(-1px);
}
.action-btn:active {
transform: translateY(0);
}
.upload-btn {
background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
border: none;
color: #ffffff;
box-shadow: 0 4px 12px rgba(79, 70, 229, 0.15);
}
.upload-btn:hover {
background: linear-gradient(135deg, #4338ca 0%, #3730a3 100%);
color: #ffffff;
border: none;
box-shadow: 0 6px 16px rgba(79, 70, 229, 0.25);
}
.clear-btn:disabled {
opacity: 0.5;
pointer-events: none;
box-shadow: none;
border-color: #f1f5f9;
background: #f8fafc;
}
.btn-icon {
font-size: 15px;
}
.app-main {
padding: 0;
overflow: hidden;
}
/* Dialog Stylings */
.dialog-body-desc {
font-size: 13px;
color: #64748b;
line-height: 1.5;
margin-bottom: 20px;
}
.dialog-body-desc code {
background-color: #f1f5f9;
color: #0f172a;
padding: 2px 4px;
border-radius: 4px;
font-size: 12px;
}
.custom-input :deep(.el-input__wrapper) {
border-radius: 8px;
padding: 8px 12px;
border: 1px solid #e2e8f0;
box-shadow: none !important;
transition: all 0.2s;
}
.custom-input :deep(.el-input__wrapper):hover,
.custom-input :deep(.el-input__wrapper.is-focus) {
border-color: #818cf8;
}
.file-upload-wrapper {
width: 100%;
}
.hidden-file-input {
display: none;
}
.file-upload-label {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
width: 100%;
height: 48px;
border: 2px dashed #cbd5e1;
border-radius: 8px;
cursor: pointer;
background-color: #f8fafc;
color: #64748b;
font-size: 13px;
font-weight: 500;
transition: all 0.2s;
}
.file-upload-label:hover {
border-color: #818cf8;
background-color: #f5f3ff;
color: #4f46e5;
}
.upload-icon {
font-size: 18px;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 15px;
}
.dialog-btn {
height: 38px;
border-radius: 8px;
font-weight: 600;
font-size: 13px;
padding: 0 20px;
}
.submit-btn {
background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
border: none;
}
.submit-btn:hover {
background: linear-gradient(135deg, #4338ca 0%, #3730a3 100%);
}
.cancel-btn {
border: 1px solid #e2e8f0;
color: #475569;
}
.cancel-btn:hover {
background-color: #f8fafc;
color: #0f172a;
border-color: #cbd5e1;
}
</style>