v2 抽出独立 CSS 并接入真实后端接口
- 将 v2.html 内联样式抽取为 public/css/v2.css - v2 前端接入 /api/sessions 列表/搜索/详情、消息发送、SSE 流式、文件上传、会话删除 - 尚未接入或后端无支撑的能力以注释列出(重命名/终止/绑定/清空/下载/模式/深度思考等)
This commit is contained in:
@@ -0,0 +1,311 @@
|
|||||||
|
/* ================= 设计变量 ================= */
|
||||||
|
:root {
|
||||||
|
--active: rgb(57, 100, 254); /* 激活状态颜色 */
|
||||||
|
--ink: rgb(15, 17, 21); /* 默认状态颜色 */
|
||||||
|
--active-soft: rgba(57, 100, 254, 0.1); /* 激活浅蓝背景 */
|
||||||
|
--gray: #8a8f99;
|
||||||
|
--gray-light: #c2c7d0;
|
||||||
|
--surface: #f2f3f7; /* 浅色面(输入框/胶囊控件/用户气泡) */
|
||||||
|
--page: #ffffff;
|
||||||
|
--border: #ececf1;
|
||||||
|
--radius-lg: 24px;
|
||||||
|
}
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||||
|
html, body { height: 100%; }
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
|
||||||
|
color: var(--ink);
|
||||||
|
background: var(--page);
|
||||||
|
overscroll-behavior: none;
|
||||||
|
}
|
||||||
|
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
|
||||||
|
input, textarea { font: inherit; color: inherit; border: 0; outline: none; background: none; }
|
||||||
|
.hidden { display: none !important; }
|
||||||
|
|
||||||
|
/* svg 图标统一描边风格(与 index.html 一致) */
|
||||||
|
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
|
||||||
|
.ic.sm { width: 17px; height: 17px; }
|
||||||
|
|
||||||
|
/* ================= 应用骨架 ================= */
|
||||||
|
#app {
|
||||||
|
height: 100%;
|
||||||
|
max-width: 760px;
|
||||||
|
margin: 0 auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: relative;
|
||||||
|
background: var(--page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================= 顶部导航栏 ================= */
|
||||||
|
.header {
|
||||||
|
flex: none;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
min-height: 56px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.header .icon-btn {
|
||||||
|
width: 40px; height: 40px; border-radius: 50%;
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
.header .icon-btn:active { background: var(--surface); }
|
||||||
|
.header-center {
|
||||||
|
flex: 1; min-width: 0;
|
||||||
|
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||||
|
gap: 1px; text-align: center;
|
||||||
|
}
|
||||||
|
.header-title {
|
||||||
|
font-size: 15px; font-weight: 600; line-height: 1.3;
|
||||||
|
max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||||
|
}
|
||||||
|
.header-sub {
|
||||||
|
font-size: 11px; color: var(--gray); line-height: 1.3;
|
||||||
|
max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||||
|
}
|
||||||
|
.header-sub .mode { color: var(--active); }
|
||||||
|
|
||||||
|
/* ================= 主内容区 ================= */
|
||||||
|
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
||||||
|
|
||||||
|
/* ---------- 未对话状态:模式选择 ---------- */
|
||||||
|
#welcome-view {
|
||||||
|
flex: 1; overflow-y: auto;
|
||||||
|
display: flex; flex-direction: column; align-items: center;
|
||||||
|
padding: max(48px, 10vh) 24px 24px;
|
||||||
|
}
|
||||||
|
.logo-badge {
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
background: none;
|
||||||
|
border-radius: 0;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: var(--active);
|
||||||
|
}
|
||||||
|
.logo-badge .ic { width: 40px; height: 40px; }
|
||||||
|
.welcome-slogan { margin-top: 0; font-size: 18px; }
|
||||||
|
.welcome-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 胶囊式分段控件 */
|
||||||
|
.mode-switch {
|
||||||
|
border: 1px solid var(--gray-light);
|
||||||
|
margin-top: 28px; width: 100%; max-width: 360px;
|
||||||
|
display: flex; gap: 4px;
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
.mode-chip {
|
||||||
|
flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
|
||||||
|
padding: 10px 0; border-radius: 999px;
|
||||||
|
font-size: 14px; color: var(--ink);
|
||||||
|
transition: background .18s, color .18s;
|
||||||
|
}
|
||||||
|
.mode-chip:hover {background: var(--surface);}
|
||||||
|
.mode-chip.on { background: var(--active-soft); color: var(--active); border: 1px solid var(--active); }
|
||||||
|
.mode-hint { margin-top: 14px; font-size: 13px; color: var(--gray); min-height: 20px; text-align: center; }
|
||||||
|
|
||||||
|
/* ---------- 对话状态:对话内容区 ---------- */
|
||||||
|
#chat-view { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 16px 8px; }
|
||||||
|
.msg { display: flex; flex-direction: column; margin-bottom: 18px; max-width: 100%; }
|
||||||
|
.msg.me { align-items: flex-end; }
|
||||||
|
.msg.other { align-items: flex-start; }
|
||||||
|
|
||||||
|
/* 用户气泡:右侧,浅色背景,圆角矩形 */
|
||||||
|
.bubble-user {
|
||||||
|
background: var(--surface); color: var(--ink);
|
||||||
|
padding: 10px 14px; border-radius: 16px 16px 4px 16px;
|
||||||
|
font-size: 15px; line-height: 1.6;
|
||||||
|
max-width: 82%; white-space: pre-wrap; word-break: break-word;
|
||||||
|
}
|
||||||
|
.attach-line { font-size: 12px; color: var(--active); margin-bottom: 4px; }
|
||||||
|
|
||||||
|
/* AI 气泡:左侧,无边框/白色背景,大段文字 */
|
||||||
|
.bubble-ai {
|
||||||
|
background: var(--page); color: var(--ink);
|
||||||
|
padding: 2px 0; font-size: 16px; line-height: 1.75;
|
||||||
|
max-width: 100%; white-space: pre-wrap; word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* AI 思考过程折叠模块 */
|
||||||
|
.think {
|
||||||
|
align-self: stretch; max-width: 100%;
|
||||||
|
margin-bottom: 8px; border-radius: 12px;
|
||||||
|
}
|
||||||
|
.think-head {
|
||||||
|
display: inline-flex; align-items: center; gap: 6px;
|
||||||
|
font-size: 13px; color: var(--gray); padding: 6px 8px; margin-left: -8px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
.think-head:active { background: var(--surface); }
|
||||||
|
.think-head .chev { transition: transform .18s; }
|
||||||
|
.think.open .think-head { color: var(--ink); }
|
||||||
|
.think.open .think-head .chev { transform: rotate(180deg); }
|
||||||
|
.think-body { display: none; padding: 4px 8px 8px 8px; }
|
||||||
|
.think.open .think-body { display: block; }
|
||||||
|
.think-body ul { list-style: none; }
|
||||||
|
.think-body li {
|
||||||
|
position: relative; padding: 5px 0 5px 16px;
|
||||||
|
font-size: 13px; line-height: 1.6; color: var(--gray);
|
||||||
|
}
|
||||||
|
.think-body li::before {
|
||||||
|
content: ""; position: absolute; left: 2px; top: 12px;
|
||||||
|
width: 5px; height: 5px; border-radius: 50%; background: var(--gray-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 输出中占位(打字点) */
|
||||||
|
.typing { display: inline-flex; gap: 4px; padding: 8px 2px; }
|
||||||
|
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--gray-light); animation: blink 1.2s infinite; }
|
||||||
|
.typing i:nth-child(2) { animation-delay: .2s; }
|
||||||
|
.typing i:nth-child(3) { animation-delay: .4s; }
|
||||||
|
@keyframes blink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; } }
|
||||||
|
|
||||||
|
/* 操作栏:时间 + 复制/删除 */
|
||||||
|
.msg-actions {
|
||||||
|
display: flex; align-items: center; gap: 10px;
|
||||||
|
margin-top: 6px; font-size: 12px; color: var(--gray-light);
|
||||||
|
}
|
||||||
|
.msg-actions .act { display: flex; color: var(--gray-light); padding: 3px; border-radius: 6px; }
|
||||||
|
.msg-actions .act:active, .msg-actions .act:hover { color: var(--ink); }
|
||||||
|
.msg-actions .act.copied { color: var(--active); }
|
||||||
|
|
||||||
|
/* ================= 底部输入区 ================= */
|
||||||
|
footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--page); }
|
||||||
|
.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
|
||||||
|
.attach-chip {
|
||||||
|
display: inline-flex; align-items: center; gap: 6px;
|
||||||
|
background: var(--surface); border-radius: 8px; padding: 5px 8px;
|
||||||
|
font-size: 12px; color: var(--ink); max-width: 100%;
|
||||||
|
}
|
||||||
|
.attach-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
|
||||||
|
.attach-chip .rm { color: var(--gray); display: flex; }
|
||||||
|
.input-shell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
gap: 6px;
|
||||||
|
background: var(--surface);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
padding: 6px 8px;
|
||||||
|
}
|
||||||
|
.input-shell textarea {
|
||||||
|
width: 100%;
|
||||||
|
flex: none;
|
||||||
|
resize: none;
|
||||||
|
background: none;
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 22px;
|
||||||
|
height: 44px; /* 初始2行 */
|
||||||
|
max-height: 120px; /* 限制最大高度 */
|
||||||
|
padding: 6px 12px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.input-shell textarea::placeholder { color: var(--gray-light); }
|
||||||
|
|
||||||
|
.input-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding-top: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 深度思考开关(左侧功能开关) */
|
||||||
|
.think-toggle {
|
||||||
|
flex: none;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
height: 36px;
|
||||||
|
padding: 0 12px;
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid var(--gray-light);
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--ink);
|
||||||
|
background: transparent;
|
||||||
|
transition: border-color .18s, background .18s, color .18s;
|
||||||
|
}
|
||||||
|
.think-toggle.on {
|
||||||
|
border-color: var(--active);
|
||||||
|
background: var(--active-soft);
|
||||||
|
color: var(--active);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.plus-btn {
|
||||||
|
flex: none; width: 36px; height: 36px; border-radius: 50%;
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
.plus-btn:active { background: #e4e6ec; }
|
||||||
|
|
||||||
|
/* ================= 历史记录抽屉 ================= */
|
||||||
|
#scrim {
|
||||||
|
position: fixed; inset: 0; background: rgba(0, 0, 0, .4);
|
||||||
|
opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 40;
|
||||||
|
}
|
||||||
|
#scrim.show { opacity: 1; pointer-events: auto; }
|
||||||
|
#drawer {
|
||||||
|
position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
|
||||||
|
width: min(78vw, 320px);
|
||||||
|
background: var(--page);
|
||||||
|
display: flex; flex-direction: column;
|
||||||
|
transform: translateX(-102%); transition: transform .25s ease;
|
||||||
|
box-shadow: 4px 0 24px rgba(0, 0, 0, .08);
|
||||||
|
}
|
||||||
|
#drawer.open { transform: translateX(0); }
|
||||||
|
|
||||||
|
.drawer-search { flex: none; padding: 14px 14px 10px; }
|
||||||
|
.search-box {
|
||||||
|
display: flex; align-items: center; gap: 8px;
|
||||||
|
background: var(--surface); border-radius: 12px; padding: 9px 12px;
|
||||||
|
color: var(--gray);
|
||||||
|
}
|
||||||
|
.search-box input { flex: 1; min-width: 0; font-size: 14px; background: none; }
|
||||||
|
.search-box input::placeholder { color: var(--gray-light); }
|
||||||
|
|
||||||
|
.drawer-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 12px; }
|
||||||
|
.group-label { padding: 14px 10px 6px; font-size: 11px; color: var(--gray); }
|
||||||
|
.conv-item {
|
||||||
|
display: block; width: 100%; text-align: left;
|
||||||
|
padding: 12px 10px; border-radius: 12px;
|
||||||
|
font-size: 14px; color: var(--ink);
|
||||||
|
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||||
|
}
|
||||||
|
.conv-item:active { background: var(--surface); }
|
||||||
|
.conv-item.active { background: var(--active-soft); color: var(--active); }
|
||||||
|
.drawer-empty { padding: 24px 10px; font-size: 13px; color: var(--gray-light); text-align: center; }
|
||||||
|
|
||||||
|
/* 底部用户区 */
|
||||||
|
.drawer-user {
|
||||||
|
flex: none; display: flex; align-items: center; gap: 10px;
|
||||||
|
padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.avatar {
|
||||||
|
width: 36px; height: 36px; border-radius: 50%; flex: none;
|
||||||
|
background: linear-gradient(135deg, var(--active), #7f9dff);
|
||||||
|
color: #fff; display: flex; align-items: center; justify-content: center;
|
||||||
|
font-size: 15px; font-weight: 600;
|
||||||
|
}
|
||||||
|
.user-name { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
.user-more { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--gray); }
|
||||||
|
.user-more:active { background: var(--surface); }
|
||||||
|
|
||||||
|
/* ================= Toast ================= */
|
||||||
|
#toast {
|
||||||
|
position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
|
||||||
|
background: rgba(15, 17, 21, .88); color: #fff;
|
||||||
|
padding: 9px 16px; border-radius: 10px; font-size: 13px;
|
||||||
|
z-index: 90; pointer-events: none; transition: opacity .2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================= 工具调用行(v2 轻量展示,替代工具卡片) ================= */
|
||||||
|
.tool-line { font-size: 12px; color: var(--gray); line-height: 1.6; padding: 2px 0; }
|
||||||
+379
-449
@@ -7,271 +7,7 @@
|
|||||||
<meta name="theme-color" content="#3964FE">
|
<meta name="theme-color" content="#3964FE">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||||
<style>
|
<link rel="stylesheet" href="/css/v2.css">
|
||||||
/* ================= 设计变量 ================= */
|
|
||||||
:root {
|
|
||||||
--active: rgb(57, 100, 254); /* 激活状态颜色 */
|
|
||||||
--ink: rgb(15, 17, 21); /* 默认状态颜色 */
|
|
||||||
--active-soft: rgba(57, 100, 254, 0.1); /* 激活浅蓝背景 */
|
|
||||||
--gray: #8a8f99;
|
|
||||||
--gray-light: #c2c7d0;
|
|
||||||
--surface: #f2f3f7; /* 浅色面(输入框/胶囊控件/用户气泡) */
|
|
||||||
--page: #ffffff;
|
|
||||||
--border: #ececf1;
|
|
||||||
--radius-lg: 24px;
|
|
||||||
}
|
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
|
||||||
html, body { height: 100%; }
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
|
|
||||||
color: var(--ink);
|
|
||||||
background: var(--page);
|
|
||||||
overscroll-behavior: none;
|
|
||||||
}
|
|
||||||
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
|
|
||||||
input, textarea { font: inherit; color: inherit; border: 0; outline: none; background: none; }
|
|
||||||
.hidden { display: none !important; }
|
|
||||||
|
|
||||||
/* svg 图标统一描边风格(与 index.html 一致) */
|
|
||||||
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
|
|
||||||
.ic.sm { width: 17px; height: 17px; }
|
|
||||||
|
|
||||||
/* ================= 应用骨架 ================= */
|
|
||||||
#app {
|
|
||||||
height: 100%;
|
|
||||||
max-width: 760px;
|
|
||||||
margin: 0 auto;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
position: relative;
|
|
||||||
background: var(--page);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================= 顶部导航栏 ================= */
|
|
||||||
.header {
|
|
||||||
flex: none;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
padding: 10px 12px;
|
|
||||||
min-height: 56px;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
.header .icon-btn {
|
|
||||||
width: 40px; height: 40px; border-radius: 50%;
|
|
||||||
display: flex; align-items: center; justify-content: center;
|
|
||||||
color: var(--ink);
|
|
||||||
}
|
|
||||||
.header .icon-btn:active { background: var(--surface); }
|
|
||||||
.header-center {
|
|
||||||
flex: 1; min-width: 0;
|
|
||||||
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
|
||||||
gap: 1px; text-align: center;
|
|
||||||
}
|
|
||||||
.header-title {
|
|
||||||
font-size: 15px; font-weight: 600; line-height: 1.3;
|
|
||||||
max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
||||||
}
|
|
||||||
.header-sub {
|
|
||||||
font-size: 11px; color: var(--gray); line-height: 1.3;
|
|
||||||
max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
||||||
}
|
|
||||||
.header-sub .mode { color: var(--active); }
|
|
||||||
|
|
||||||
/* ================= 主内容区 ================= */
|
|
||||||
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
|
||||||
|
|
||||||
/* ---------- 未对话状态:模式选择 ---------- */
|
|
||||||
#welcome-view {
|
|
||||||
flex: 1; overflow-y: auto;
|
|
||||||
display: flex; flex-direction: column; align-items: center;
|
|
||||||
padding: max(48px, 10vh) 24px 24px;
|
|
||||||
}
|
|
||||||
.logo-badge {
|
|
||||||
width: 72px; height: 72px; border-radius: 22px;
|
|
||||||
background: var(--active-soft); color: var(--active);
|
|
||||||
display: flex; align-items: center; justify-content: center;
|
|
||||||
}
|
|
||||||
.logo-badge .ic { width: 40px; height: 40px; }
|
|
||||||
.welcome-slogan { margin-top: 18px; font-size: 18px; }
|
|
||||||
|
|
||||||
/* 胶囊式分段控件 */
|
|
||||||
.mode-switch {
|
|
||||||
margin-top: 28px; width: 100%; max-width: 360px;
|
|
||||||
display: flex; gap: 4px; padding: 4px;
|
|
||||||
background: var(--surface); border-radius: 999px;
|
|
||||||
}
|
|
||||||
.mode-chip {
|
|
||||||
flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
|
|
||||||
padding: 10px 0; border-radius: 999px;
|
|
||||||
font-size: 14px; color: var(--ink);
|
|
||||||
transition: background .18s, color .18s;
|
|
||||||
}
|
|
||||||
.mode-chip.on { background: var(--active-soft); color: var(--active); font-weight: 600; }
|
|
||||||
.mode-hint { margin-top: 14px; font-size: 13px; color: var(--gray); min-height: 20px; text-align: center; }
|
|
||||||
|
|
||||||
/* ---------- 对话状态:对话内容区 ---------- */
|
|
||||||
#chat-view { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 16px 8px; }
|
|
||||||
.msg { display: flex; flex-direction: column; margin-bottom: 18px; max-width: 100%; }
|
|
||||||
.msg.me { align-items: flex-end; }
|
|
||||||
.msg.other { align-items: flex-start; }
|
|
||||||
|
|
||||||
/* 用户气泡:右侧,浅色背景,圆角矩形 */
|
|
||||||
.bubble-user {
|
|
||||||
background: var(--surface); color: var(--ink);
|
|
||||||
padding: 10px 14px; border-radius: 16px 16px 4px 16px;
|
|
||||||
font-size: 15px; line-height: 1.6;
|
|
||||||
max-width: 82%; white-space: pre-wrap; word-break: break-word;
|
|
||||||
}
|
|
||||||
.attach-line { font-size: 12px; color: var(--active); margin-bottom: 4px; }
|
|
||||||
|
|
||||||
/* AI 气泡:左侧,无边框/白色背景,大段文字 */
|
|
||||||
.bubble-ai {
|
|
||||||
background: var(--page); color: var(--ink);
|
|
||||||
padding: 2px 0; font-size: 16px; line-height: 1.75;
|
|
||||||
max-width: 100%; white-space: pre-wrap; word-break: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* AI 思考过程折叠模块 */
|
|
||||||
.think {
|
|
||||||
align-self: stretch; max-width: 100%;
|
|
||||||
margin-bottom: 8px; border-radius: 12px;
|
|
||||||
}
|
|
||||||
.think-head {
|
|
||||||
display: inline-flex; align-items: center; gap: 6px;
|
|
||||||
font-size: 13px; color: var(--gray); padding: 6px 8px; margin-left: -8px;
|
|
||||||
border-radius: 8px;
|
|
||||||
}
|
|
||||||
.think-head:active { background: var(--surface); }
|
|
||||||
.think-head .chev { transition: transform .18s; }
|
|
||||||
.think.open .think-head { color: var(--ink); }
|
|
||||||
.think.open .think-head .chev { transform: rotate(180deg); }
|
|
||||||
.think-body { display: none; padding: 4px 8px 8px 8px; }
|
|
||||||
.think.open .think-body { display: block; }
|
|
||||||
.think-body ul { list-style: none; }
|
|
||||||
.think-body li {
|
|
||||||
position: relative; padding: 5px 0 5px 16px;
|
|
||||||
font-size: 13px; line-height: 1.6; color: var(--gray);
|
|
||||||
}
|
|
||||||
.think-body li::before {
|
|
||||||
content: ""; position: absolute; left: 2px; top: 12px;
|
|
||||||
width: 5px; height: 5px; border-radius: 50%; background: var(--gray-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 输出中占位(打字点) */
|
|
||||||
.typing { display: inline-flex; gap: 4px; padding: 8px 2px; }
|
|
||||||
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--gray-light); animation: blink 1.2s infinite; }
|
|
||||||
.typing i:nth-child(2) { animation-delay: .2s; }
|
|
||||||
.typing i:nth-child(3) { animation-delay: .4s; }
|
|
||||||
@keyframes blink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; } }
|
|
||||||
|
|
||||||
/* 操作栏:时间 + 复制/删除 */
|
|
||||||
.msg-actions {
|
|
||||||
display: flex; align-items: center; gap: 10px;
|
|
||||||
margin-top: 6px; font-size: 12px; color: var(--gray-light);
|
|
||||||
}
|
|
||||||
.msg-actions .act { display: flex; color: var(--gray-light); padding: 3px; border-radius: 6px; }
|
|
||||||
.msg-actions .act:active, .msg-actions .act:hover { color: var(--ink); }
|
|
||||||
.msg-actions .act.copied { color: var(--active); }
|
|
||||||
|
|
||||||
/* ================= 底部输入区 ================= */
|
|
||||||
footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--page); }
|
|
||||||
.attach-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
|
|
||||||
.attach-chip {
|
|
||||||
display: inline-flex; align-items: center; gap: 6px;
|
|
||||||
background: var(--surface); border-radius: 8px; padding: 5px 8px;
|
|
||||||
font-size: 12px; color: var(--ink); max-width: 100%;
|
|
||||||
}
|
|
||||||
.attach-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
|
|
||||||
.attach-chip .rm { color: var(--gray); display: flex; }
|
|
||||||
.input-shell {
|
|
||||||
display: flex; align-items: flex-end; gap: 6px;
|
|
||||||
background: var(--surface); border-radius: var(--radius-lg);
|
|
||||||
padding: 6px 8px 6px 12px;
|
|
||||||
}
|
|
||||||
.input-shell textarea {
|
|
||||||
flex: 1; resize: none; background: none;
|
|
||||||
font-size: 15px; line-height: 22px; max-height: 120px;
|
|
||||||
padding: 7px 0; min-width: 0;
|
|
||||||
}
|
|
||||||
.input-shell textarea::placeholder { color: var(--gray-light); }
|
|
||||||
|
|
||||||
/* 深度思考开关(左侧功能开关) */
|
|
||||||
.think-toggle {
|
|
||||||
flex: none; display: inline-flex; align-items: center; gap: 5px;
|
|
||||||
height: 36px; padding: 0 12px; border-radius: 999px;
|
|
||||||
font-size: 13px; color: var(--ink);
|
|
||||||
transition: background .18s, color .18s;
|
|
||||||
}
|
|
||||||
.think-toggle.on { background: var(--active-soft); color: var(--active); font-weight: 600; }
|
|
||||||
.plus-btn {
|
|
||||||
flex: none; width: 36px; height: 36px; border-radius: 50%;
|
|
||||||
display: flex; align-items: center; justify-content: center;
|
|
||||||
color: var(--ink);
|
|
||||||
}
|
|
||||||
.plus-btn:active { background: #e4e6ec; }
|
|
||||||
|
|
||||||
/* ================= 历史记录抽屉 ================= */
|
|
||||||
#scrim {
|
|
||||||
position: fixed; inset: 0; background: rgba(0, 0, 0, .4);
|
|
||||||
opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 40;
|
|
||||||
}
|
|
||||||
#scrim.show { opacity: 1; pointer-events: auto; }
|
|
||||||
#drawer {
|
|
||||||
position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
|
|
||||||
width: min(78vw, 320px);
|
|
||||||
background: var(--page);
|
|
||||||
display: flex; flex-direction: column;
|
|
||||||
transform: translateX(-102%); transition: transform .25s ease;
|
|
||||||
box-shadow: 4px 0 24px rgba(0, 0, 0, .08);
|
|
||||||
}
|
|
||||||
#drawer.open { transform: translateX(0); }
|
|
||||||
|
|
||||||
.drawer-search { flex: none; padding: 14px 14px 10px; }
|
|
||||||
.search-box {
|
|
||||||
display: flex; align-items: center; gap: 8px;
|
|
||||||
background: var(--surface); border-radius: 12px; padding: 9px 12px;
|
|
||||||
color: var(--gray);
|
|
||||||
}
|
|
||||||
.search-box input { flex: 1; min-width: 0; font-size: 14px; background: none; }
|
|
||||||
.search-box input::placeholder { color: var(--gray-light); }
|
|
||||||
|
|
||||||
.drawer-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 12px; }
|
|
||||||
.group-label { padding: 14px 10px 6px; font-size: 11px; color: var(--gray); }
|
|
||||||
.conv-item {
|
|
||||||
display: block; width: 100%; text-align: left;
|
|
||||||
padding: 12px 10px; border-radius: 12px;
|
|
||||||
font-size: 16px; font-weight: 500; color: var(--ink);
|
|
||||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
||||||
}
|
|
||||||
.conv-item:active { background: var(--surface); }
|
|
||||||
.conv-item.active { background: var(--active-soft); color: var(--active); }
|
|
||||||
.drawer-empty { padding: 24px 10px; font-size: 13px; color: var(--gray-light); text-align: center; }
|
|
||||||
|
|
||||||
/* 底部用户区 */
|
|
||||||
.drawer-user {
|
|
||||||
flex: none; display: flex; align-items: center; gap: 10px;
|
|
||||||
padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
|
|
||||||
border-top: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
.avatar {
|
|
||||||
width: 36px; height: 36px; border-radius: 50%; flex: none;
|
|
||||||
background: linear-gradient(135deg, var(--active), #7f9dff);
|
|
||||||
color: #fff; display: flex; align-items: center; justify-content: center;
|
|
||||||
font-size: 15px; font-weight: 600;
|
|
||||||
}
|
|
||||||
.user-name { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
||||||
.user-more { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--gray); }
|
|
||||||
.user-more:active { background: var(--surface); }
|
|
||||||
|
|
||||||
/* ================= Toast ================= */
|
|
||||||
#toast {
|
|
||||||
position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
|
|
||||||
background: rgba(15, 17, 21, .88); color: #fff;
|
|
||||||
padding: 9px 16px; border-radius: 10px; font-size: 13px;
|
|
||||||
z-index: 90; pointer-events: none; transition: opacity .2s;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
@@ -290,10 +26,12 @@
|
|||||||
<main>
|
<main>
|
||||||
<!-- ================= 未对话状态:模式切换区 ================= -->
|
<!-- ================= 未对话状态:模式切换区 ================= -->
|
||||||
<section id="welcome-view">
|
<section id="welcome-view">
|
||||||
|
<div class="welcome-head">
|
||||||
<div class="logo-badge">
|
<div class="logo-badge">
|
||||||
<svg class="ic" viewBox="0 0 24 24"><rect x="4" y="8" width="16" height="12" rx="3"></rect><line x1="12" y1="4" x2="12" y2="8"></line><circle cx="12" cy="3" r="1.4"></circle><circle cx="9" cy="13.5" r="1" fill="currentColor" stroke="none"></circle><circle cx="15" cy="13.5" r="1" fill="currentColor" stroke="none"></circle><line x1="9.5" y1="17" x2="14.5" y2="17"></line></svg>
|
<svg class="ic" viewBox="0 0 24 24"><rect x="4" y="8" width="16" height="12" rx="3"></rect><line x1="12" y1="4" x2="12" y2="8"></line><circle cx="12" cy="3" r="1.4"></circle><circle cx="9" cy="13.5" r="1" fill="currentColor" stroke="none"></circle><circle cx="15" cy="13.5" r="1" fill="currentColor" stroke="none"></circle><line x1="9.5" y1="17" x2="14.5" y2="17"></line></svg>
|
||||||
</div>
|
</div>
|
||||||
<div class="welcome-slogan">选择模式开始对话</div>
|
<div class="welcome-slog</title>an">选择模式开始对话</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mode-switch" role="tablist" id="mode-switch">
|
<div class="mode-switch" role="tablist" id="mode-switch">
|
||||||
<button class="mode-chip on" data-mode="secretary" role="tab" aria-selected="true">
|
<button class="mode-chip on" data-mode="secretary" role="tab" aria-selected="true">
|
||||||
@@ -316,16 +54,19 @@
|
|||||||
<footer>
|
<footer>
|
||||||
<div class="attach-chips hidden" id="attach-chips"></div>
|
<div class="attach-chips hidden" id="attach-chips"></div>
|
||||||
<div class="input-shell">
|
<div class="input-shell">
|
||||||
|
<textarea id="msg-input" placeholder="传送信息" rows="2" enterkeyhint="send"></textarea>
|
||||||
|
<div class="input-actions">
|
||||||
<button class="think-toggle" id="deep-think-btn" title="深度思考">
|
<button class="think-toggle" id="deep-think-btn" title="深度思考">
|
||||||
<svg class="ic sm" viewBox="0 0 24 24"><path d="M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"></path><path d="M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"></path><path d="M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4"></path></svg>
|
<svg viewBox="0 0 24 24" class="ic sm"><path d="M12 10.2a1.8 1.8 0 1 0 0.001 3.6A1.8 1.8 0 0 0 12 10.2z"></path><path stroke-width="1.5" d="M15.76 15.76 C10.955 20.565 5.373 22.779 3.297 20.703 C1.22 18.627 3.434 13.045 8.24 8.24 C13.045 3.435 18.627 1.22 20.703 3.297 C22.779 5.374 20.565 10.955 15.76 15.76z"></path><path stroke-width="1.5" d="M16.096 7.904 C20.905 12.713 22.965 18.298 20.703 20.703 C18.44 23.108 13.003 20.755 8.24 15.76 C3.477 10.76 1.22 5.373 3.297 3.297 C5.374 1.22 10.955 3.434 16.096 7.904z"></path></svg>
|
||||||
深度思考
|
深度思考
|
||||||
</button>
|
</button>
|
||||||
<textarea id="msg-input" placeholder="传送信息" rows="1" enterkeyhint="send"></textarea>
|
|
||||||
<button class="plus-btn" id="attach-btn" title="添加附件或图片" aria-label="添加附件">
|
<button class="plus-btn" id="attach-btn" title="添加附件或图片" aria-label="添加附件">
|
||||||
<svg class="ic" viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
|
<svg class="ic" viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
|
||||||
</button>
|
</button>
|
||||||
<input type="file" id="file-input" multiple hidden>
|
<input type="file" id="file-input" multiple hidden>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<!-- ================= 历史记录抽屉 ================= -->
|
<!-- ================= 历史记录抽屉 ================= -->
|
||||||
@@ -353,25 +94,32 @@
|
|||||||
<script>
|
<script>
|
||||||
/*
|
/*
|
||||||
* ============================================================================
|
* ============================================================================
|
||||||
* Agent 任务台 v2 —— 纯 UI 原型(仅交互逻辑,未接入任何后端接口)
|
* Agent 任务台 v2 —— 接入真实后端(全部沿用 /api 现有接口,未新增任何接口)
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
* 接口参考(全部沿用 index.html / js/tasks.js 现有约定,后续接入时不要新增接口):
|
* 已接入:
|
||||||
* GET /api/sessions?status=active&limit=100 活跃会话列表
|
* GET /api/sessions?status=active&limit=100 抽屉「今天/昨天」活跃列表
|
||||||
* GET /api/sessions?status=done&limit=..&with_total=1 已完成分页(before/before_id)
|
* GET /api/sessions?status=done&limit=50&with_total=1 抽屉归档列表
|
||||||
* GET /api/sessions?q=..&limit=50&with_total=1 搜索(抽屉搜索框)
|
* GET /api/sessions?q=..&limit=50 抽屉搜索
|
||||||
* POST /api/sessions {title, model_id} 新建对话(右上角 +)
|
* POST /api/sessions {title:'', model_id:''} 首条消息自动建档
|
||||||
* GET /api/sessions/:id 会话详情(messages,抽屉点击)
|
* GET /api/sessions/:id 打开会话(消息+文件)
|
||||||
* PATCH /api/sessions/:id {title} 重命名
|
* DELETE /api/sessions/:id?delete_dir=true 删除会话(操作栏删除按钮)
|
||||||
* DELETE /api/sessions/:id?delete_dir= 删除(操作栏删除按钮)
|
* POST /api/sessions/:id/messages {content, attachments} 发送消息
|
||||||
* POST /api/sessions/:id/messages {content, attachments} 发送消息(输入框)
|
* POST /api/sessions/:id/files 附件上传(multipart)
|
||||||
* DELETE /api/sessions/:id/messages 清空
|
* GET /api/sessions/:id/stream SSE 流式输出
|
||||||
* POST /api/sessions/:id/stop | /release | /bind {model_id} 终止/释放/绑定模型
|
*
|
||||||
* GET|POST|DELETE /api/sessions/:id/files 附件(加号按钮)
|
* 后端已有但 v2 尚未接入 UI 的接口(先列出,不实现):
|
||||||
|
* PATCH /api/sessions/:id 重命名(后端已支持)
|
||||||
|
* POST /api/sessions/:id/stop | /release | /bind 终止/断开/绑定模型
|
||||||
|
* DELETE /api/sessions/:id/messages 清空会话内容
|
||||||
* GET /api/sessions/:id/files/download-token?path= 文件下载
|
* GET /api/sessions/:id/files/download-token?path= 文件下载
|
||||||
* GET /api/sessions/:id/stream SSE: status / assistant_delta /
|
|
||||||
* assistant_message / tool_call / tool_result / done
|
|
||||||
* GET /api/models | /api/system/status 模型池 / 系统状态
|
* GET /api/models | /api/system/status 模型池 / 系统状态
|
||||||
* 鉴权:任意请求 401 时跳转 /login(参考 core.js req())。
|
*
|
||||||
|
* 无后端支撑、仅前端占位的概念(先不实现):
|
||||||
|
* · 「文秘助理 / 识图专家」模式 —— 后端无 mode 字段,当前仅影响提示文案
|
||||||
|
* · 「深度思考」开关 —— 后端无 reasoning/deep-think 参数,当前仅本地视觉状态
|
||||||
|
* · 「思考过程」折叠块(已思考 N 秒) —— 后端不产出 reasoning,已移除 mock
|
||||||
|
* · 按消息粒度删除 —— 现有接口为会话级删除,故操作栏删除按钮指向删除会话
|
||||||
|
* 鉴权:任意请求 401 时跳转 /login(与 core.js 的 req 一致)。
|
||||||
* ============================================================================
|
* ============================================================================
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -383,7 +131,11 @@
|
|||||||
if (!ts) return '';
|
if (!ts) return '';
|
||||||
const d = new Date(ts);
|
const d = new Date(ts);
|
||||||
const p = n => String(n).padStart(2, '0');
|
const p = n => String(n).padStart(2, '0');
|
||||||
return p(d.getHours()) + ':' + p(d.getMinutes());
|
const now = new Date();
|
||||||
|
const hm = p(d.getHours()) + ':' + p(d.getMinutes());
|
||||||
|
if (now.toDateString() === d.toDateString()) return hm;
|
||||||
|
const md = (d.getMonth() + 1) + '/' + d.getDate();
|
||||||
|
return (d.getFullYear() === now.getFullYear() ? md : d.getFullYear() + '/' + md) + ' ' + hm;
|
||||||
}
|
}
|
||||||
function toast(msg) {
|
function toast(msg) {
|
||||||
const el = $('toast');
|
const el = $('toast');
|
||||||
@@ -410,45 +162,51 @@
|
|||||||
} catch (_) { return false; }
|
} catch (_) { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- API(与 core.js 的 req 保持一致) ----------
|
||||||
|
async function req(method, url, body, isForm) {
|
||||||
|
const opt = { method, headers: {} };
|
||||||
|
if (body && !isForm) {
|
||||||
|
opt.headers['Content-Type'] = 'application/json';
|
||||||
|
opt.body = JSON.stringify(body);
|
||||||
|
} else if (body && isForm) {
|
||||||
|
opt.body = body;
|
||||||
|
}
|
||||||
|
const res = await fetch(url, opt);
|
||||||
|
if (res.status === 401) { location.href = '/login'; throw new Error('未登录'); }
|
||||||
|
if (!res.ok) {
|
||||||
|
let msg = 'HTTP ' + res.status;
|
||||||
|
try { msg = (await res.json()).error || msg; } catch (_) {}
|
||||||
|
const err = new Error(msg);
|
||||||
|
err.status = res.status;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- 模式配置 ----------
|
// ---------- 模式配置 ----------
|
||||||
// 文案说明:文秘助理提示文案按需求暂为 "todo",后续直接在此处替换。
|
|
||||||
const MODES = {
|
const MODES = {
|
||||||
secretary: { label: '文秘助理', hint: 'todo' },
|
secretary: { label: '文秘助理', hint: '支持文字输入,可起草、润色、整理文书' },
|
||||||
vision: { label: '识图专家', hint: '支持图片识别输入' },
|
vision: { label: '识图专家', hint: '支持图片识别输入' },
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------- 全局 UI 状态(本地 mock,不请求后端) ----------
|
// ---------- 全局状态 ----------
|
||||||
const state = {
|
const state = {
|
||||||
view: 'welcome', // welcome | chat
|
view: 'welcome', // welcome | chat
|
||||||
mode: 'secretary', // 模式选择区当前选中
|
mode: 'secretary', // 模式选择区当前选中
|
||||||
deepThink: false, // 深度思考开关
|
deepThink: false, // 深度思考开关(仅本地视觉状态,无后端参数)
|
||||||
sessionId: null, // 当前会话(mock id)
|
sessionId: null, // 当前会话
|
||||||
attachments: [], // 待发送附件 {name}
|
sessionTitle: '', // 当前会话标题
|
||||||
|
status: '', // 当前会话状态(SSE 更新)
|
||||||
|
sessions: [], // 抽屉列表缓存
|
||||||
|
attachments: [], // 待发送附件 {file, name, size}
|
||||||
|
es: null, // EventSource
|
||||||
|
streamText: '', // 当前流式累积文本
|
||||||
|
streamEl: null, // 当前流式 AI 气泡
|
||||||
|
toolLines: {}, // tool_call_id -> 工具行元素
|
||||||
|
typingEl: null, // 「思考中」占位
|
||||||
|
streaming: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------- mock 数据(结构与 GET /api/sessions/:id 的 messages 对齐:role/content/created_at) ----------
|
|
||||||
const DAY = 86400000;
|
|
||||||
const now = Date.now();
|
|
||||||
const sessions = [
|
|
||||||
{
|
|
||||||
id: 'demo-greet', title: '用户打招呼', mode: 'secretary', updated_at: now - 2 * 3600e3,
|
|
||||||
messages: [
|
|
||||||
{ role: 'user', content: '你好', created_at: now - 2 * 3600e3 },
|
|
||||||
{
|
|
||||||
role: 'assistant',
|
|
||||||
content: '你好!我是文秘助理,可以帮你起草文书、整理纪要、润色段落。有什么想让我帮忙的,直接说就好。',
|
|
||||||
thinkSeconds: 2,
|
|
||||||
thinkSteps: ['理解用户意图:寒暄问候', '确认当前模式为文秘助理', '组织简短友好的自我介绍'],
|
|
||||||
created_at: now - 2 * 3600e3 + 20000,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ id: 'demo-report', title: '整理本周周报要点', mode: 'secretary', updated_at: now - 5 * 3600e3, messages: [] },
|
|
||||||
{ id: 'demo-translate', title: '翻译合同条款', mode: 'secretary', updated_at: now - DAY - 3 * 3600e3, messages: [] },
|
|
||||||
{ id: 'demo-vision', title: '识别产品截图', mode: 'vision', updated_at: now - 3 * DAY, messages: [] },
|
|
||||||
{ id: 'demo-copy', title: '起草活动宣传文案', mode: 'secretary', updated_at: now - 33 * DAY, messages: [] },
|
|
||||||
];
|
|
||||||
|
|
||||||
// ---------- 视图切换 ----------
|
// ---------- 视图切换 ----------
|
||||||
function setView(view) {
|
function setView(view) {
|
||||||
state.view = view;
|
state.view = view;
|
||||||
@@ -460,12 +218,13 @@
|
|||||||
|
|
||||||
function renderHeader() {
|
function renderHeader() {
|
||||||
const c = $('header-center');
|
const c = $('header-center');
|
||||||
if (state.view !== 'chat') { c.innerHTML = ''; return; }
|
if (state.view !== 'chat' || !state.sessionId) { c.innerHTML = ''; return; }
|
||||||
const s = sessions.find(x => x.id === state.sessionId);
|
const stMap = { queued: '排队中', active: '活跃中', held: '保持中', completed: '已完成', cancelled: '已终止' };
|
||||||
if (!s) { c.innerHTML = ''; return; }
|
const st = stMap[state.status] || '';
|
||||||
c.innerHTML =
|
c.innerHTML =
|
||||||
'<div class="header-title">' + esc(s.title) + '</div>' +
|
'<div class="header-title">' + esc(state.sessionTitle || state.sessionId) + '</div>' +
|
||||||
'<div class="header-sub"><span class="mode">' + esc(MODES[s.mode].label) + '</span> · 回答由 AI 产生,仅供参考</div>';
|
'<div class="header-sub"><span class="mode">' + esc(MODES[state.mode].label) + '</span>' +
|
||||||
|
(st ? ' · ' + esc(st) : '') + ' · 回答由 AI 产生,仅供参考</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- 模式切换区 ----------
|
// ---------- 模式切换区 ----------
|
||||||
@@ -484,146 +243,346 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ---------- 消息渲染 ----------
|
// ---------- 消息渲染 ----------
|
||||||
function thinkBlockHtml(sec, steps) {
|
// 服务端把附件说明拼在正文前(【系统通知】用户上传了文件:...),此处拆开单独展示 📎 行
|
||||||
return '<div class="think">' +
|
function parseUploadNotice(content) {
|
||||||
'<button class="think-head">' +
|
const m = /^【系统通知】用户上传了文件:([^\n]*)(?:\n([\s\S]*))?$/.exec(content || '');
|
||||||
'<span>已思考(用时 ' + sec + ' 秒)</span>' +
|
if (!m) return { text: content || '', files: null };
|
||||||
'<svg class="ic sm chev" viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9"></polyline></svg>' +
|
const files = m[1].split('、').map(s => s.replace(/(大小[^)]*)$/, '').trim()).filter(Boolean);
|
||||||
'</button>' +
|
return { text: m[2] || '', files: files };
|
||||||
'<div class="think-body"><ul>' + steps.map(s => '<li>' + esc(s) + '</li>').join('') + '</ul></div>' +
|
|
||||||
'</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function actionsHtml(ts, content) {
|
function actionsHtml(ts, content) {
|
||||||
// 复制内容用 base64 携带,避免引号破坏 HTML 属性(与 tasks.js 的 copyMap 异曲同工)
|
|
||||||
const b64 = btoa(unescape(encodeURIComponent(content)));
|
const b64 = btoa(unescape(encodeURIComponent(content)));
|
||||||
return '<div class="msg-actions">' +
|
return '<div class="msg-actions">' +
|
||||||
'<span>' + fmtTime(ts) + '</span>' +
|
'<span>' + fmtTime(ts) + '</span>' +
|
||||||
'<button class="act act-copy" title="复制" data-b64="' + b64 + '">' +
|
'<button class="act act-copy" title="复制" data-b64="' + b64 + '">' +
|
||||||
'<svg class="ic sm" viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>' +
|
'<svg class="ic sm" viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>' +
|
||||||
'</button>' +
|
'</button>' +
|
||||||
'<button class="act act-del" title="删除">' +
|
'<button class="act act-del" title="删除会话">' +
|
||||||
'<svg class="ic sm" viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>' +
|
'<svg class="ic sm" viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>' +
|
||||||
'</button>' +
|
'</button>' +
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachLine(files) {
|
|
||||||
return files && files.length
|
|
||||||
? '<div class="attach-line">📎 ' + esc(files.map(f => f.name).join('、')) + '</div>' : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function userMsgHtml(m) {
|
function userMsgHtml(m) {
|
||||||
|
const p = parseUploadNotice(m.content);
|
||||||
|
const attach = p.files && p.files.length
|
||||||
|
? '<div class="attach-line">📎 ' + esc(p.files.join('、')) + '</div>' : '';
|
||||||
return '<div class="msg me">' +
|
return '<div class="msg me">' +
|
||||||
'<div class="bubble-user">' + attachLine(m.files) + esc(m.content) + '</div>' +
|
'<div class="bubble-user">' + attach + esc(p.text) + '</div>' +
|
||||||
'<div class="msg-actions"><span>' + fmtTime(m.created_at) + '</span></div>' +
|
'<div class="msg-actions"><span>' + fmtTime(m.created_at) + '</span></div>' +
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function aiMsgHtml(m) {
|
function aiMsgHtml(m) {
|
||||||
const hasText = !!(m.content && m.content.trim());
|
const hasText = !!(m.content && m.content.trim());
|
||||||
|
let toolLines = '';
|
||||||
|
if (m.tool_calls) {
|
||||||
|
let calls = m.tool_calls;
|
||||||
|
try { if (typeof calls === 'string') calls = JSON.parse(calls); } catch (_) { calls = null; }
|
||||||
|
if (Array.isArray(calls)) {
|
||||||
|
toolLines = calls.map(c => '<div class="tool-line">🔧 ' + esc(c.function && c.function.name || '工具') + '</div>').join('');
|
||||||
|
}
|
||||||
|
}
|
||||||
return '<div class="msg other">' +
|
return '<div class="msg other">' +
|
||||||
(m.thinkSteps && m.thinkSteps.length ? thinkBlockHtml(m.thinkSeconds, m.thinkSteps) : '') +
|
toolLines +
|
||||||
(hasText ? '<div class="bubble-ai">' + esc(m.content) + '</div>' : '') +
|
(hasText ? '<div class="bubble-ai">' + esc(m.content) + '</div>' : '') +
|
||||||
(hasText ? actionsHtml(m.created_at, m.content) : '') +
|
(hasText ? actionsHtml(m.created_at, m.content) : '') +
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMessages(s) {
|
function msgNode(m) {
|
||||||
|
if (m.role === 'user') return userMsgHtml(m);
|
||||||
|
if (m.role === 'assistant') return aiMsgHtml(m);
|
||||||
|
return null; // tool 结果不单独展示
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderDetail(detail) {
|
||||||
|
const s = detail.session;
|
||||||
|
state.sessionTitle = (s && s.title) || '';
|
||||||
|
state.status = (s && s.status) || '';
|
||||||
|
renderHeader();
|
||||||
|
const box = $('chat-view');
|
||||||
|
box.innerHTML = '';
|
||||||
|
for (const m of detail.messages || []) {
|
||||||
|
const node = msgNode(m);
|
||||||
|
if (node) box.insertAdjacentHTML('beforeend', node);
|
||||||
|
}
|
||||||
|
if (!(detail.messages || []).length) {
|
||||||
|
box.innerHTML = '<div class="drawer-empty">描述你的需求,AI 会和你讨论并直接干活。</div>';
|
||||||
|
}
|
||||||
|
scrollBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendUserMsg(content, fileNames) {
|
||||||
|
const attach = fileNames && fileNames.length
|
||||||
|
? '<div class="attach-line">📎 ' + esc(fileNames.join('、')) + '</div>' : '';
|
||||||
|
const wrap = document.createElement('div');
|
||||||
|
wrap.className = 'msg me';
|
||||||
|
wrap.innerHTML = '<div class="bubble-user">' + attach + esc(content) + '</div>' +
|
||||||
|
'<div class="msg-actions"><span>' + fmtTime(Date.now()) + '</span></div>';
|
||||||
|
$('chat-view').appendChild(wrap);
|
||||||
|
scrollBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollBottom() {
|
||||||
const box = $('chat-view');
|
const box = $('chat-view');
|
||||||
box.innerHTML = s.messages.map(m => (m.role === 'user' ? userMsgHtml(m) : aiMsgHtml(m))).join('');
|
|
||||||
box.scrollTop = box.scrollHeight;
|
box.scrollTop = box.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- 会话打开 / 新建 ----------
|
function addTyping() {
|
||||||
function openSession(id) {
|
removeTyping();
|
||||||
// TODO(api): GET /api/sessions/:id 拉详情与 messages
|
const ph = document.createElement('div');
|
||||||
const s = sessions.find(x => x.id === id);
|
ph.className = 'msg other';
|
||||||
if (!s) return;
|
ph.innerHTML = '<div class="typing"><i></i><i></i><i></i></div>';
|
||||||
state.sessionId = id;
|
$('chat-view').appendChild(ph);
|
||||||
setView('chat');
|
state.typingEl = ph;
|
||||||
renderMessages(s);
|
scrollBottom();
|
||||||
|
}
|
||||||
|
function removeTyping() {
|
||||||
|
if (state.typingEl) { state.typingEl.remove(); state.typingEl = null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 会话列表(抽屉) ----------
|
||||||
|
function groupLabel(ts) {
|
||||||
|
const d = new Date(ts), n = new Date();
|
||||||
|
const sod = t => new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime();
|
||||||
|
const diff = (sod(n) - sod(d)) / 86400000;
|
||||||
|
if (diff <= 0) return '今天';
|
||||||
|
if (diff === 1) return '昨天';
|
||||||
|
return d.getFullYear() + '年' + (d.getMonth() + 1) + '月';
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderDrawerList() {
|
||||||
|
const list = state.sessions.slice().sort((a, b) => (b.updated_at || 0) - (a.updated_at || 0));
|
||||||
|
const box = $('drawer-list');
|
||||||
|
if (!list.length) { box.innerHTML = '<div class="drawer-empty">没有找到相关对话</div>'; return; }
|
||||||
|
let html = '', lastGroup = null;
|
||||||
|
for (const s of list) {
|
||||||
|
const g = groupLabel(s.updated_at);
|
||||||
|
if (g !== lastGroup) { html += '<div class="group-label">' + esc(g) + '</div>'; lastGroup = g; }
|
||||||
|
html += '<button class="conv-item' + (s.id === state.sessionId ? ' active' : '') + '" data-id="' + esc(s.id) + '">' +
|
||||||
|
esc(s.title || s.id) + '</button>';
|
||||||
|
}
|
||||||
|
box.innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadSessionList() {
|
||||||
|
const q = $('search-input').value.trim();
|
||||||
|
try {
|
||||||
|
let list;
|
||||||
|
if (q) {
|
||||||
|
const r = await req('GET', '/api/sessions?q=' + encodeURIComponent(q) + '&limit=50&with_total=1');
|
||||||
|
list = r.rows || [];
|
||||||
|
} else {
|
||||||
|
const [active, done] = await Promise.all([
|
||||||
|
req('GET', '/api/sessions?status=active&limit=100'),
|
||||||
|
req('GET', '/api/sessions?status=done&limit=50&with_total=1'),
|
||||||
|
]);
|
||||||
|
list = (active || []).concat((done && done.rows) || []);
|
||||||
|
}
|
||||||
|
state.sessions = list;
|
||||||
renderDrawerList();
|
renderDrawerList();
|
||||||
|
} catch (e) { toast('加载会话失败:' + e.message); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 会话打开 / 新建 / 删除 ----------
|
||||||
|
function closeStream() {
|
||||||
|
if (state.es) { state.es.close(); state.es = null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openSession(id) {
|
||||||
|
closeStream();
|
||||||
|
removeTyping();
|
||||||
|
state.sessionId = id;
|
||||||
|
state.streamEl = null;
|
||||||
|
state.streamText = '';
|
||||||
|
state.toolLines = {};
|
||||||
|
state.streaming = false;
|
||||||
|
state.attachments = [];
|
||||||
|
renderAttachChips();
|
||||||
|
setView('chat');
|
||||||
|
$('chat-view').innerHTML = '<div class="drawer-empty">加载中…</div>';
|
||||||
|
try {
|
||||||
|
const detail = await req('GET', '/api/sessions/' + id);
|
||||||
|
if (state.sessionId !== id) return; // 期间已切到别的会话
|
||||||
|
renderDetail(detail);
|
||||||
|
connectStream();
|
||||||
|
} catch (e) {
|
||||||
|
if (state.sessionId === id) toast('打开会话失败:' + e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保存在当前会话:首条消息自动建档(POST /api/sessions)
|
||||||
|
async function ensureSession() {
|
||||||
|
if (state.sessionId) return state.sessionId;
|
||||||
|
const s = await req('POST', '/api/sessions', { title: '', model_id: '' });
|
||||||
|
state.sessionId = s.id;
|
||||||
|
state.sessionTitle = (s && s.title) || '';
|
||||||
|
setView('chat');
|
||||||
|
renderHeader();
|
||||||
|
connectStream();
|
||||||
|
return s.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function newChat() {
|
function newChat() {
|
||||||
// TODO(api): POST /api/sessions {title:'', model_id:''} 或直接沿用现有"首条消息自动建档"流程
|
closeStream();
|
||||||
|
removeTyping();
|
||||||
state.sessionId = null;
|
state.sessionId = null;
|
||||||
|
state.sessionTitle = '';
|
||||||
|
state.status = '';
|
||||||
state.attachments = [];
|
state.attachments = [];
|
||||||
|
state.streamEl = null;
|
||||||
|
state.streamText = '';
|
||||||
|
state.toolLines = {};
|
||||||
|
state.streaming = false;
|
||||||
renderAttachChips();
|
renderAttachChips();
|
||||||
selectMode('secretary'); // 置顶逻辑:新建时自动选中【文秘助理】
|
selectMode('secretary'); // 置顶逻辑:新建时自动选中【文秘助理】
|
||||||
setView('welcome');
|
setView('welcome');
|
||||||
|
$('chat-view').innerHTML = '';
|
||||||
$('msg-input').value = '';
|
$('msg-input').value = '';
|
||||||
autosize();
|
autosize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- 发送与模拟回复(仅 UI,不请求后端) ----------
|
async function deleteSession() {
|
||||||
function send() {
|
if (!state.sessionId) return;
|
||||||
|
const id = state.sessionId;
|
||||||
|
if (!confirm('删除整个会话?其任务文件也将一并删除,且不可恢复。')) return;
|
||||||
|
try {
|
||||||
|
await req('DELETE', '/api/sessions/' + id + '?delete_dir=true');
|
||||||
|
newChat();
|
||||||
|
loadSessionList();
|
||||||
|
} catch (e) { toast('删除失败:' + e.message); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 发送 ----------
|
||||||
|
async function uploadFiles(sessionId, files) {
|
||||||
|
const fd = new FormData();
|
||||||
|
for (const f of files) fd.append('files', f.file, f.name);
|
||||||
|
const r = await req('POST', '/api/sessions/' + sessionId + '/files', fd, true);
|
||||||
|
return (r.uploaded || []).map(u => ({ name: u.filename, size: u.size }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function send() {
|
||||||
const ta = $('msg-input');
|
const ta = $('msg-input');
|
||||||
const content = ta.value.trim();
|
const content = ta.value.trim();
|
||||||
if (!content && !state.attachments.length) return;
|
if (!content && !state.attachments.length) return;
|
||||||
|
|
||||||
// 首轮发言:自动建档并进入对话态(置顶逻辑:模式选择区让位于对话内容区)
|
const pending = state.attachments.slice();
|
||||||
if (state.view !== 'chat') {
|
|
||||||
const title = content ? (content.length > 12 ? content.slice(0, 12) + '…' : content) : state.attachments[0].name;
|
|
||||||
const s = { id: 'local-' + Date.now(), title, mode: state.mode, updated_at: Date.now(), messages: [] };
|
|
||||||
sessions.unshift(s);
|
|
||||||
state.sessionId = s.id;
|
|
||||||
setView('chat');
|
|
||||||
renderDrawerList();
|
|
||||||
}
|
|
||||||
const s = sessions.find(x => x.id === state.sessionId);
|
|
||||||
|
|
||||||
const atts = state.attachments;
|
|
||||||
const msg = { role: 'user', content, files: atts.slice(), created_at: Date.now() };
|
|
||||||
s.messages.push(msg);
|
|
||||||
$('chat-view').insertAdjacentHTML('beforeend', userMsgHtml(msg));
|
|
||||||
|
|
||||||
// TODO(api): POST /api/sessions/:id/messages {content, attachments}
|
|
||||||
// 后续 AI 输出经 GET /api/sessions/:id/stream (SSE) 推送
|
|
||||||
state.attachments = [];
|
state.attachments = [];
|
||||||
renderAttachChips();
|
renderAttachChips();
|
||||||
ta.value = '';
|
ta.value = '';
|
||||||
autosize();
|
autosize();
|
||||||
mockReply(s);
|
|
||||||
|
try {
|
||||||
|
const id = await ensureSession();
|
||||||
|
let atts = [];
|
||||||
|
if (pending.length) atts = await uploadFiles(id, pending);
|
||||||
|
const body = { content };
|
||||||
|
if (atts.length) body.attachments = atts;
|
||||||
|
await req('POST', '/api/sessions/' + id + '/messages', body);
|
||||||
|
|
||||||
|
appendUserMsg(content, atts.map(a => a.name));
|
||||||
|
if (!state.sessionTitle && content) {
|
||||||
|
state.sessionTitle = content.length > 24 ? content.slice(0, 24) : content;
|
||||||
|
}
|
||||||
|
renderHeader();
|
||||||
|
addTyping();
|
||||||
|
loadSessionList();
|
||||||
|
} catch (e) {
|
||||||
|
// 发送失败:附件还原,交由用户决定重试或移除
|
||||||
|
state.attachments = pending.concat(state.attachments);
|
||||||
|
renderAttachChips();
|
||||||
|
toast('发送失败:' + e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mockReply(s) {
|
// ---------- SSE 流式 ----------
|
||||||
const box = $('chat-view');
|
function connectStream() {
|
||||||
const ph = document.createElement('div');
|
closeStream();
|
||||||
ph.className = 'msg other';
|
if (!state.sessionId) return;
|
||||||
ph.innerHTML = '<div class="typing"><i></i><i></i><i></i></div>';
|
const es = new EventSource('/api/sessions/' + state.sessionId + '/stream');
|
||||||
box.appendChild(ph);
|
state.es = es;
|
||||||
box.scrollTop = box.scrollHeight;
|
es.addEventListener('status', ev => {
|
||||||
|
const d = JSON.parse(ev.data);
|
||||||
const deep = state.deepThink;
|
state.status = d.status;
|
||||||
setTimeout(() => {
|
renderHeader();
|
||||||
const sec = deep ? 5 + (Math.random() * 4 | 0) : 1 + (Math.random() * 3 | 0);
|
});
|
||||||
const modeLabel = MODES[s.mode].label;
|
es.addEventListener('assistant_delta', ev => {
|
||||||
const msg = {
|
const d = JSON.parse(ev.data);
|
||||||
role: 'assistant',
|
removeTyping();
|
||||||
content: deep
|
state.streamText += d.text;
|
||||||
? '(模拟回复)已进入深度推理模式。我会先拆解问题、逐步推演,再给出结论。\n\n这是 UI 原型中的占位回答,接入 /api/sessions 与 SSE 流后,这里会展示模型的真实输出。'
|
if (!state.streamEl) {
|
||||||
: '(模拟回复)我是' + modeLabel + '。当前为 UI 原型阶段,还没有接入真实模型;\n发送、流式输出、思考过程等交互链路已就绪,后续对接现有 /api 接口即可。',
|
if (!state.streamText.trim()) return; // 忽略前导空白(纯工具调用回合无文本)
|
||||||
thinkSeconds: sec,
|
const wrap = document.createElement('div');
|
||||||
thinkSteps: deep
|
wrap.className = 'msg other';
|
||||||
? ['拆解用户问题,识别关键约束', '检索相关知识并交叉验证', '规划回答结构与示例', '复核结论与表述是否一致']
|
const bubble = document.createElement('div');
|
||||||
: ['理解用户意图与上下文', '结合当前模式(' + modeLabel + ')组织回答', '生成回复并检查语气'],
|
bubble.className = 'bubble-ai';
|
||||||
created_at: Date.now(),
|
wrap.appendChild(bubble);
|
||||||
};
|
$('chat-view').appendChild(wrap);
|
||||||
ph.outerHTML = aiMsgHtml(msg);
|
state.streamEl = bubble;
|
||||||
s.messages.push(msg);
|
state.streamText = d.text;
|
||||||
s.updated_at = Date.now();
|
}
|
||||||
box.scrollTop = box.scrollHeight;
|
state.streamEl.textContent = state.streamText;
|
||||||
renderDrawerList();
|
state.streaming = true;
|
||||||
}, 900);
|
scrollBottom();
|
||||||
|
});
|
||||||
|
es.addEventListener('assistant_message', ev => {
|
||||||
|
const d = JSON.parse(ev.data);
|
||||||
|
removeTyping();
|
||||||
|
const hasText = !!(d.content && d.content.trim());
|
||||||
|
if (state.streamEl) {
|
||||||
|
if (hasText) state.streamEl.textContent = d.content;
|
||||||
|
else state.streamEl.remove();
|
||||||
|
state.streamEl = null;
|
||||||
|
state.streamText = '';
|
||||||
|
} else if (hasText) {
|
||||||
|
const wrap = document.createElement('div');
|
||||||
|
wrap.className = 'msg other';
|
||||||
|
wrap.innerHTML = '<div class="bubble-ai">' + esc(d.content) + '</div>';
|
||||||
|
$('chat-view').appendChild(wrap);
|
||||||
|
}
|
||||||
|
state.streaming = false;
|
||||||
|
scrollBottom();
|
||||||
|
});
|
||||||
|
es.addEventListener('tool_call', ev => {
|
||||||
|
const d = JSON.parse(ev.data);
|
||||||
|
removeTyping();
|
||||||
|
const wrap = document.createElement('div');
|
||||||
|
wrap.className = 'msg other';
|
||||||
|
wrap.innerHTML = '<div class="tool-line">🔧 ' + esc(d.name || '工具') + '</div>';
|
||||||
|
$('chat-view').appendChild(wrap);
|
||||||
|
state.toolLines[d.id] = wrap;
|
||||||
|
scrollBottom();
|
||||||
|
});
|
||||||
|
es.addEventListener('tool_result', ev => {
|
||||||
|
const d = JSON.parse(ev.data);
|
||||||
|
const wrap = state.toolLines[d.tool_call_id];
|
||||||
|
if (wrap && d.is_error) {
|
||||||
|
const line = wrap.querySelector('.tool-line');
|
||||||
|
if (line) line.textContent += ' ⚠️ 失败';
|
||||||
|
}
|
||||||
|
scrollBottom();
|
||||||
|
});
|
||||||
|
es.addEventListener('done', ev => {
|
||||||
|
removeTyping();
|
||||||
|
state.streaming = false;
|
||||||
|
state.streamEl = null;
|
||||||
|
state.streamText = '';
|
||||||
|
state.toolLines = {};
|
||||||
|
loadSessionList();
|
||||||
|
});
|
||||||
|
es.addEventListener('error', ev => {
|
||||||
|
removeTyping();
|
||||||
|
try {
|
||||||
|
const d = JSON.parse(ev.data);
|
||||||
|
if (d && d.message) toast('错误:' + d.message);
|
||||||
|
} catch (_) { /* EventSource 连接错误,自动重连 */ }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- 消息区点击代理(折叠 / 复制 / 删除) ----------
|
// ---------- 消息区点击代理(复制 / 删除) ----------
|
||||||
$('chat-view').addEventListener('click', async e => {
|
$('chat-view').addEventListener('click', async e => {
|
||||||
const head = e.target.closest('.think-head');
|
|
||||||
if (head) { head.parentElement.classList.toggle('open'); return; }
|
|
||||||
|
|
||||||
const copyBtn = e.target.closest('.act-copy');
|
const copyBtn = e.target.closest('.act-copy');
|
||||||
if (copyBtn) {
|
if (copyBtn) {
|
||||||
let text = '';
|
let text = '';
|
||||||
@@ -636,19 +595,8 @@
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const delBtn = e.target.closest('.act-del');
|
const delBtn = e.target.closest('.act-del');
|
||||||
if (delBtn) {
|
if (delBtn) { deleteSession(); }
|
||||||
// TODO(api): DELETE /api/sessions/:id 或按消息粒度删除(现有接口为会话级删除)
|
|
||||||
const msgEl = delBtn.closest('.msg');
|
|
||||||
const s = sessions.find(x => x.id === state.sessionId);
|
|
||||||
if (s) {
|
|
||||||
const idx = Array.prototype.indexOf.call($('chat-view').children, msgEl);
|
|
||||||
if (idx >= 0) s.messages.splice(idx, 1);
|
|
||||||
}
|
|
||||||
msgEl.remove();
|
|
||||||
toast('已删除(原型内仅移除本地消息)');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---------- 输入区 ----------
|
// ---------- 输入区 ----------
|
||||||
@@ -659,20 +607,21 @@
|
|||||||
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); }
|
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); }
|
||||||
});
|
});
|
||||||
|
|
||||||
// 深度思考开关
|
// 深度思考开关(仅本地视觉状态,后端无 reasoning 参数)
|
||||||
$('deep-think-btn').addEventListener('click', () => {
|
$('deep-think-btn').addEventListener('click', () => {
|
||||||
state.deepThink = !state.deepThink;
|
state.deepThink = !state.deepThink;
|
||||||
$('deep-think-btn').classList.toggle('on', state.deepThink);
|
$('deep-think-btn').classList.toggle('on', state.deepThink);
|
||||||
toast(state.deepThink ? '深度思考已开启' : '深度思考已关闭');
|
toast(state.deepThink ? '深度思考已开启(暂不影响后端)' : '深度思考已关闭');
|
||||||
});
|
});
|
||||||
|
|
||||||
// 加号:添加附件(仅 UI,不上传)
|
// 加号:选择附件(仅入队本地展示,发送时才真正上传)
|
||||||
$('attach-btn').addEventListener('click', () => $('file-input').click());
|
$('attach-btn').addEventListener('click', () => $('file-input').click());
|
||||||
$('file-input').addEventListener('change', e => {
|
$('file-input').addEventListener('change', e => {
|
||||||
for (const f of e.target.files) state.attachments.push({ name: f.name });
|
for (const f of Array.prototype.slice.call(e.target.files || [])) {
|
||||||
|
state.attachments.push({ file: f, name: f.name, size: f.size });
|
||||||
|
}
|
||||||
e.target.value = '';
|
e.target.value = '';
|
||||||
renderAttachChips();
|
renderAttachChips();
|
||||||
// TODO(api): POST /api/sessions/:id/files (multipart FormData,参考 tasks.js startUpload)
|
|
||||||
});
|
});
|
||||||
function renderAttachChips() {
|
function renderAttachChips() {
|
||||||
const row = $('attach-chips');
|
const row = $('attach-chips');
|
||||||
@@ -693,41 +642,22 @@
|
|||||||
$('drawer').classList.toggle('open', open);
|
$('drawer').classList.toggle('open', open);
|
||||||
$('scrim').classList.toggle('show', open);
|
$('scrim').classList.toggle('show', open);
|
||||||
}
|
}
|
||||||
$('menu-btn').addEventListener('click', () => openDrawer(!$('drawer').classList.contains('open')));
|
$('menu-btn').addEventListener('click', () => {
|
||||||
|
const open = !$('drawer').classList.contains('open');
|
||||||
|
openDrawer(open);
|
||||||
|
if (open) loadSessionList();
|
||||||
|
});
|
||||||
$('scrim').addEventListener('click', () => openDrawer(false));
|
$('scrim').addEventListener('click', () => openDrawer(false));
|
||||||
|
|
||||||
function groupLabel(ts) {
|
let searchTimer = null;
|
||||||
const d = new Date(ts), n = new Date();
|
$('search-input').addEventListener('input', () => {
|
||||||
const sod = t => new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime();
|
clearTimeout(searchTimer);
|
||||||
const diff = (sod(n) - sod(d)) / DAY;
|
searchTimer = setTimeout(loadSessionList, 250);
|
||||||
if (diff <= 0) return '今天';
|
});
|
||||||
if (diff === 1) return '昨天';
|
|
||||||
return d.getFullYear() + '年' + (d.getMonth() + 1) + '月';
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderDrawerList() {
|
|
||||||
const q = $('search-input').value.trim().toLowerCase();
|
|
||||||
// TODO(api): GET /api/sessions?status=active / status=done 分页;搜索走 ?q=
|
|
||||||
const list = sessions
|
|
||||||
.filter(s => !q || s.title.toLowerCase().includes(q))
|
|
||||||
.slice()
|
|
||||||
.sort((a, b) => b.updated_at - a.updated_at);
|
|
||||||
const box = $('drawer-list');
|
|
||||||
if (!list.length) { box.innerHTML = '<div class="drawer-empty">没有找到相关对话</div>'; return; }
|
|
||||||
let html = '', lastGroup = null;
|
|
||||||
for (const s of list) {
|
|
||||||
const g = groupLabel(s.updated_at);
|
|
||||||
if (g !== lastGroup) { html += '<div class="group-label">' + esc(g) + '</div>'; lastGroup = g; }
|
|
||||||
html += '<button class="conv-item' + (s.id === state.sessionId ? ' active' : '') + '" data-id="' + esc(s.id) + '">' +
|
|
||||||
esc(s.title) + '</button>';
|
|
||||||
}
|
|
||||||
box.innerHTML = html;
|
|
||||||
}
|
|
||||||
$('search-input').addEventListener('input', renderDrawerList);
|
|
||||||
$('drawer-list').addEventListener('click', e => {
|
$('drawer-list').addEventListener('click', e => {
|
||||||
const item = e.target.closest('.conv-item');
|
const item = e.target.closest('.conv-item');
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
openSession(item.dataset.id); // TODO(api): GET /api/sessions/:id
|
openSession(item.dataset.id);
|
||||||
openDrawer(false);
|
openDrawer(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -739,7 +669,7 @@
|
|||||||
// ---------- 初始化 ----------
|
// ---------- 初始化 ----------
|
||||||
selectMode('secretary'); // 默认选中【文秘助理】
|
selectMode('secretary'); // 默认选中【文秘助理】
|
||||||
setView('welcome');
|
setView('welcome');
|
||||||
renderDrawerList();
|
loadSessionList();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user