优化h5页面显示风格

This commit is contained in:
2026-10-20 13:16:00 +08:00
parent 9c82c84bab
commit 95efef8bac
9 changed files with 395 additions and 178 deletions
+142 -41
View File
@@ -55,6 +55,7 @@ input, textarea { font: inherit; color: inherit; border: 0; outline: none; backg
gap: 8px;
padding: 10px 12px;
min-height: 56px;
background: var(--drawer-bg);
}
.header .icon-btn {
width: 36px; height: 36px; border-radius: 50%;
@@ -734,7 +735,7 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0
border-radius: 12px;
}
/* 定时任务会话标记:左缘紫色短竖条,绝对定位压在 conv-item 左 padding 区,不吃标题宽度;
颜色与 schedule-bar 紫色体系呼应,区别于状态色(蓝/绿/黄) */
紫色体系与「定时任务」动作项同语义,区别于状态色(蓝/绿/黄) */
.conv-wrap.scheduled::before {
content: ""; position: absolute; left: 2px; top: 24%; bottom: 24%;
width: 3px; border-radius: 2px; background: #7048e8;
@@ -806,50 +807,13 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0
.scroll-bottom-btn .sb-spinner path { stroke: #3964FE; stroke-width: 2.5; stroke-linecap: round; fill: none; }
@keyframes sb-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
/* ================= 会话状态栏(phase-bar,搬自 style.css) ================= */
.phase-bar {
flex: none; display: flex; align-items: center; gap: 2px;
padding: 6px 12px; background: var(--page); border-bottom: 1px solid var(--border);
}
/* 状态栏随会话状态染色:排队=淡蓝、执行中=绿底、保持中=黄底;
完成=中性浅灰、终止=淡红底,均与顶部白底标题栏区分 */
.phase-bar.queued { background: #f1f4ff; border-bottom-color: #dfe4fb; }
.phase-bar.active { background: #f0f9f2; border-bottom-color: #cde8d3; }
.phase-bar.held { background: #fffbe8; border-bottom-color: #f5e3b3; }
.phase-bar.completed { background: #f4f5f8; border-bottom-color: #e3e6ed; }
.phase-bar.cancelled { background: #fdf3f2; border-bottom-color: #f5d7d3; }
.status-pill {
display: inline-flex; align-items: center; gap: 6px;
font-size: 12px; padding: 3px 10px; border-radius: 10px;
background: #eceff5; color: #5c6674;
min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.status-pill::before {
content: ''; width: 7px; height: 7px; border-radius: 50%;
background: currentColor; flex-shrink: 0;
}
.status-pill.active { background: #e3f2e6; color: #1c7a2e; }
.status-pill.active::before { animation: pill-pulse 1.2s ease-in-out infinite; }
.status-pill.held { background: #fff4dc; color: #8a6400; }
.status-pill.queued { background: #e9edff; color: var(--active); }
.status-pill.cancelled { background: #fdecea; color: #b3382c; }
/* 状态胶囊里的模型名 = 「更换模型」入口(held/cancelled 下可点,与独立「选择模型」同一弹窗,见 sessions.js updatePhaseBar) */
.status-pill .pill-model { cursor: pointer; border-bottom: 1px dashed currentColor; }
.status-pill .pill-model:hover { opacity: .7; }
@keyframes pill-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
/* 微信绑定内联卡(账户页):登录码用服务端 SVG 内联渲染(非 <img>,无坏图帧);未就绪时占位不跳高 */
.wx-qr { display: flex; justify-content: center; align-items: center; margin: 10px 0 4px; min-height: 236px; }
.wx-qr svg { width: 220px; height: 220px; background: #fff; padding: 8px; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.wx-qr-wait { color: var(--gray-light); font-size: 13px; }
.wx-id { float: right; font-weight: 400; font-size: 11px; color: var(--gray-light); margin-top: 5px; }
.stop-link {
background: none; border: none; cursor: pointer; flex: none;
color: #c33; font-size: 12px; padding: 4px 6px;
}
.stop-link.muted { color: #8a6400; }
.stop-link:active { opacity: 0.6; }
/* 「清空」钮推到状态栏最右 */
#clear-msg-btn { margin-left: auto; color: #b3382c; }
/* ================= 工具调用卡片(样式/交互同步 index 的 .tool-card) ================= */
.tool-card {
@@ -1198,7 +1162,7 @@ label.icon-btn { cursor: pointer; }
.modal .del-dir { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink); margin-bottom: 14px; cursor: pointer; }
.modal .del-dir input { width: 16px; height: 16px; padding: 0; margin: 0; flex: none; accent-color: var(--active); }
/* 模型选择弹窗(会话页 phase-bar「选择模型」入口) */
/* 模型选择弹窗(顶部动作区「切换模型」/欢迎页头像入口) */
.msw-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.msw-titles h3 { margin: 0 0 4px 0; font-size: 16px; }
.msw-sub { font-size: 13px; color: var(--gray-light); margin: 0; }
@@ -1326,3 +1290,140 @@ body.pv-resizing #pv-pane iframe { pointer-events: none; }
.ui-card .name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-card .sub { display: block; font-size: 12px; color: var(--gray); }
.ui-card .go { font-size: 13px; color: var(--active); white-space: nowrap; }
/* ================= 顶部动作区(切换模型 / 定时任务 / 压缩上下文 / 新建会话) =================
桌面端平铺 4 个圆形图标(与 header 左侧历史钮同款 .header .icon-btn);
移动端收进右上角「更多」下拉菜单,菜单项与图标共用 data-act,事件统一由 sessions.js 分发。 */
.header-actions { flex: none; position: relative; display: flex; align-items: center; gap: 2px; }
.ha-icons { display: flex; align-items: center; gap: 2px; }
.header-actions .icon-btn:disabled { opacity: .35; cursor: default; }
/* 「更多」钮:窄屏才出现(.header .icon-btn 已给尺寸/圆形,这里只控制显隐) */
.header .ha-more { display: none; }
/* 下拉菜单:锚在动作区右下,轻边框 + 浮层阴影,风格与 .pv-suggest 一致 */
.ha-menu {
position: absolute; top: calc(100% + 8px); right: 0; z-index: 70;
min-width: 202px; max-width: min(78vw, 280px);
display: flex; flex-direction: column; gap: 2px;
padding: 6px; background: var(--page); border: 1px solid var(--border);
border-radius: 14px; box-shadow: 0 12px 32px rgba(15, 17, 21, .16);
animation: ha-menu-in .14s ease-out;
}
@keyframes ha-menu-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.ha-item {
display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px;
padding: 0 10px; border-radius: 10px; font-size: 14px; color: var(--ink); text-align: left;
}
.ha-item .ic { width: 18px; height: 18px; color: var(--gray); }
.ha-item:active { background: var(--surface); }
.ha-item:disabled { opacity: .38; cursor: default; }
.ha-item-main { flex: 1 1 auto; min-width: 0; white-space: nowrap; }
/* 副标题(当前模型名 / 定时任务频次):过长省略号截断,不把菜单撑宽 */
.ha-item-sub {
flex: 0 1 auto; min-width: 0; max-width: 54%;
font-size: 12px; color: var(--gray);
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
.ha-item:hover { background: var(--surface); }
.header-actions .ha-btn:hover { background: var(--surface); }
}
@media (max-width: 639px) {
.ha-icons { display: none; }
/* 「更多」钮:移动端扩到 44px 触控热区(图标尺寸不变) */
.header .ha-more { display: flex; width: 44px; height: 44px; }
}
/* 宽屏下下拉菜单不参与布局(窗口从窄拖宽时残留的展开态也不会挡住内容) */
@media (min-width: 640px) {
.header .ha-menu { display: none; }
}
/* ---------- 桌面端(≥640px):标题左对齐,属性区紧随标题,右侧只留「新建会话」 ----------
作用域限定在 #chat-header:设置页也用 .header/.header-center,不能跟着左对齐。 */
@media (min-width: 640px) {
/* margin-left:标题与左侧「历史/侧边栏」钮拉开距离,避免文字贴上按钮 */
#chat-header .header-center { flex: 0 1 auto; justify-content: flex-start; text-align: left; margin-left: 10px; }
#chat-header .header-title { justify-content: flex-start; }
#chat-header .header-meta { display: flex; }
#chat-header .header-actions { margin-left: auto; }
}
/* 会话属性区(默认隐藏;桌面端才展开):模型名 / 定时任务 / 压缩 */
.header-meta { display: none; flex: none; align-items: center; gap: 4px; min-width: 0; }
.hdr-chip {
position: relative; display: inline-flex; align-items: center; gap: 5px;
height: 26px; padding: 0 9px; border-radius: 10px;
font-size: 12.5px; color: var(--gray); white-space: nowrap;
}
.hdr-chip .ic { width: 14px; height: 14px; }
.hdr-chip .hdr-label { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-chip:active { opacity: .75; }
.hdr-chip:disabled { opacity: .38; cursor: default; }
/* hover/按下态的 opacity<1 会给胶囊自己创建层叠上下文(把气泡内部的 z-index 关在里面);
而 main 里带 opacity 的 .msg-archived 也是层叠上下文且 DOM 在 header 之后,
会盖住气泡。这里给交互态整体抬一层,保证气泡始终在消息内容之上。 */
.hdr-chip:hover, .hdr-chip:focus-visible, .hdr-chip:active { z-index: 10; }
/* 模型位兼做会话状态指示:浅底 + 同色文字 + 圆点(做法同旧 schedule-bar 的「浅底同色字」,
色值取自旧状态胶囊;active 的圆点做呼吸动画,代替已移除的 phase-bar 转圈) */
.hdr-model {
max-width: 200px;
padding: 0 13px; /* 带状态底色的胶囊,左右留白比纯文字位稍大,文字不贴边 */
background: #eceff5; color: #5c6674;
}
.hdr-model::before {
content: ''; flex: none; width: 6px; height: 6px; border-radius: 50%;
background: currentColor;
}
.hdr-model .hdr-label { border-bottom: 1px dashed currentColor; }
.hdr-model[data-status="active"] { background: #e3f2e6; color: #1c7a2e; }
.hdr-model[data-status="active"]::before { animation: hdr-pulse 1.2s ease-in-out infinite; }
.hdr-model[data-status="held"] { background: #fff4dc; color: #8a6400; }
.hdr-model[data-status="cancelled"] { background: #fdecea; color: #b3382c; }
.hdr-model[data-status="completed"] { background: #f4f5f8; color: #5c6674; }
@keyframes hdr-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
/* 定时任务:无任务=只留灰色时钟图标(点击新建);有任务=紫色频次文字(点击编辑,配色同原 schedule-bar) */
.hdr-sched { max-width: 190px; }
.hdr-sched:not(.on) { padding: 0 7px; } /* 纯图标时收紧内边距,不显得空 */
/* 图标尺寸/描边对齐压缩键的圆柱图标(.hdr-compact 也是 19px / 1.6 描边) */
#header-meta .hdr-sched .ic { width: 19px; height: 19px; stroke-width: 1.7; }
.hdr-sched.on { background: #f8f5ff; color: #5f3dc4; }
/* 压缩:沿用原状态栏的蓝色圆柱图标 */
#header-meta .hdr-compact { color: var(--active); }
#header-meta .hdr-compact .ic { width: 19px; height: 19px; }
#header-meta .icon-btn:disabled { opacity: .35; cursor: default; }
/* 桌面图标/文字位的悬停提示:原生 title 有 ~1s 延迟,改用 CSS 气泡(hover / 键盘焦点立即出现) */
.ha-btn, .hdr-chip { position: relative; }
@media (hover: hover) and (pointer: fine) {
.ha-btn::after, .hdr-chip::after {
content: attr(data-tip);
position: absolute; top: calc(100% + 6px); left: 50%;
transform: translateX(-50%) translateY(-2px);
max-width: 240px; overflow: hidden; text-overflow: ellipsis;
padding: 5px 9px; border-radius: 8px;
background: rgba(15, 17, 21, .9); color: #fff;
font-size: 12px; line-height: 1.2; white-space: nowrap;
opacity: 0; pointer-events: none; z-index: 80;
transition: opacity .12s ease, transform .12s ease;
}
.ha-btn:hover::after, .ha-btn:focus-visible::after,
.hdr-chip:hover::after, .hdr-chip:focus-visible::after {
opacity: 1; transform: translateX(-50%) translateY(0);
}
/* 最右侧「新建会话」气泡改右对齐,避免被 #app 的 overflow:hidden 裁掉 */
.ha-icons .ha-btn:last-child::after { left: auto; right: 0; transform: translateY(-2px); }
.ha-icons .ha-btn:last-child:hover::after,
.ha-icons .ha-btn:last-child:focus-visible::after { transform: translateY(0); }
/* 属性文字位的悬停反馈:模型位已有状态底色,只降透明度不改色 */
.hdr-model:hover { opacity: .82; }
.hdr-sched:hover { background: var(--surface); }
.hdr-sched.on:hover { background: #f1ecff; color: #4c2fa8; }
#header-meta .hdr-compact:hover { background: var(--surface); }
.header-actions .ha-btn:hover { background: var(--surface); }
/* 模型位的提示带「状态 + 模型 id」,比另外两个稍长,宽度上限放宽一档 */
#header-meta .hdr-model::after { max-width: 300px; }
}
/* 发送键 = 发送⇄停止:生成中只换图标(白色方块),底色保持 --active 不变,输入区不跳动 */
.send-btn .stop-sq { display: none; width: 11px; height: 11px; border-radius: 2px; background: #fff; }
.send-btn[data-state="stop"] > svg { display: none; }
.send-btn[data-state="stop"] .stop-sq { display: block; }
+54 -42
View File
@@ -48,27 +48,7 @@
margin: 10px 0 12px; font-size: 11px; color: var(--gray);
}
.archived-note::before, .archived-note::after { content: ''; flex: 1; height: 1px; background: var(--border); }
/* 状态栏图标按钮(压缩):仅显示 SVG、去掉文字 padding;保持与文字按钮同高。 */
.stop-link.icon-only { padding: 0 8px; line-height: 0; }
.stop-link.icon-only .ic { width: 18px; height: 18px; vertical-align: middle; }
/* 状态栏「压缩」图标按钮:主操作色(蓝色),与其他 stop-link 区分(终止/选择模型是灰) */
.stop-link.icon-only.icon-primary { color: var(--active); }
.stop-link.icon-only.icon-primary:hover { color: #2854d6; }
/* 推到 phase-bar 最右侧(独立动作,与左侧状态区分;「选择模型」与压缩同列右靠) */
.phase-bar .phase-bar-right { margin-left: auto; }
/* 定时任务状态条:整条可点,弹详情窗(改频次/提示词、删除;创建走 AI 的 schedule 工具),紫色调区别于状态栏;
左侧 3px 竖条与侧边栏定时任务会话的紫色标记同一语义。
高度与 phase-bar 对齐:同 6px 上下内边距,sched-text 用与 stop-link 同构的 12px 字 + 4px 上下 padding(天然同 line-box),eye 同 icon-only 钮 */
.schedule-bar {
flex: none; display: flex; align-items: center; gap: 8px;
padding: 6px 12px; font-size: 12px; color: #5f3dc4; cursor: pointer;
background: #f8f5ff; border-bottom: 1px solid #e7def9; border-left: 3px solid #7048e8;
}
.schedule-bar:active { opacity: 0.75; }
.schedule-bar .sched-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 4px 0; }
/* eye 图标与 phase-bar 右侧 icon-only 钮垂直对齐:同 6px 上下内边距、同 0 8px 水平、同 18px 图标 */
.schedule-bar .sched-eye { margin-left: auto; flex: none; padding: 0 8px; line-height: 0; }
.schedule-bar .sched-eye .ic { width: 18px; height: 18px; vertical-align: middle; }
/* schedule 弹窗控件(.modal select/input 的 100% 宽会撑满整行,这里收窄成本行内样式) */
#schedule-modal .sched-row { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; font-size: 14px; color: var(--ink); flex-wrap: wrap; }
#schedule-modal .sched-row select,
@@ -106,28 +86,58 @@
<div id="app">
<!-- ================= 顶部导航栏 ================= -->
<header class="header">
<header class="header" id="chat-header">
<button class="icon-btn" id="menu-btn" title="历史记录" aria-label="打开历史记录">
<svg viewBox="0 0 24 24" class="ic sm"><path stroke-width="2" stroke-linecap="round" d="M4 5h16M4 15h10"/></svg>
</button>
<div class="header-center" id="header-center"><!-- 未对话状态为空白,JS 注入对话信息 --></div>
<button class="icon-btn hidden" id="new-chat-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>
</button>
</header>
<!-- ================= 会话状态栏(搬自 index 的 phase-bar;仅在对话中显示) ================= -->
<div id="phase-bar" class="phase-bar hidden">
<span class="status-pill" id="status-pill">--</span>
<button class="stop-link hidden" id="stop-btn" onclick="stopSession()">终止</button>
<button class="stop-link hidden phase-bar-right" id="model-switch-btn" onclick="openModelSwitch()">选择模型</button>
<button class="stop-link icon-only icon-primary phase-bar-right hidden" id="compress-btn" title="压缩上下文" aria-label="压缩上下文" onclick="summarizeChat()">
<svg class="ic" viewBox="0 0 24 24"><ellipse cx="12" cy="5" rx="8" ry="2.5" fill="none" stroke="currentColor" stroke-width="1.6"></ellipse><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M4 5v6c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5V5"></path><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M4 11v6c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5v-6"></path></svg>
</button>
</div>
<!-- 标题右侧的会话属性区(仅桌面端):模型名(文字)/ 定时任务(无任务=灰色入口·有任务=紫色频次)/ 压缩。
无会话时只留模型占位(选模型),定时与压缩隐藏。 -->
<div class="header-meta" id="header-meta">
<button class="hdr-chip hdr-model" id="hdr-model" data-act="model" data-tip="切换模型" aria-label="切换模型">
<span class="hdr-label" id="hdr-model-text">选择模型</span>
</button>
<button class="hdr-chip hdr-sched hidden" id="hdr-sched" data-act="schedule" data-tip="定时任务" aria-label="定时任务">
<svg class="ic" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8.5"></circle><polyline points="12 7.5 12 12 15.5 14"></polyline></svg>
<span class="hdr-label" id="hdr-sched-text">定时任务</span>
</button>
<button class="icon-btn ha-btn hdr-compact hidden" id="hdr-compact" data-act="compact" data-tip="压缩上下文" aria-label="压缩上下文">
<svg class="ic" viewBox="0 0 24 24"><ellipse cx="12" cy="5" rx="8" ry="2.5" fill="none" stroke="currentColor" stroke-width="1.6"></ellipse><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M4 5v6c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5V5"></path><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M4 11v6c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5v-6"></path></svg>
</button>
</div>
<!-- ================= 定时任务状态栏(有任务才显示;数据随会话详情下发,见 routes/sessions.js GET /:id) ================= -->
<div id="schedule-bar" class="schedule-bar hidden" onclick="openScheduleModal()"></div>
<!-- 右侧动作区:桌面端只留「新建会话」;移动端整组收进「更多」下拉菜单。
桌面属性区与菜单项共用 data-act,事件统一在 sessions.js 分发。 -->
<div class="header-actions" id="header-actions">
<div class="ha-icons">
<button class="icon-btn ha-btn" data-act="new" data-tip="新建会话" aria-label="新建会话">
<svg class="ic sm" 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>
</div>
<button class="icon-btn ha-more" id="ha-more" title="更多" aria-label="更多操作" aria-haspopup="menu" aria-expanded="false" aria-controls="ha-menu">
<svg class="ic sm" viewBox="0 0 24 24"><circle cx="5" cy="12" r="1.4" fill="currentColor" stroke="none"></circle><circle cx="12" cy="12" r="1.4" fill="currentColor" stroke="none"></circle><circle cx="19" cy="12" r="1.4" fill="currentColor" stroke="none"></circle></svg>
</button>
<div class="ha-menu hidden" id="ha-menu" role="menu">
<button class="ha-item" role="menuitem" data-act="model">
<svg class="ic sm" viewBox="0 0 24 24"><line x1="3" y1="7" x2="21" y2="7"></line><circle cx="9" cy="7" r="2.6"></circle><line x1="3" y1="17" x2="21" y2="17"></line><circle cx="15" cy="17" r="2.6"></circle></svg>
<span class="ha-item-main">切换模型</span><span class="ha-item-sub hidden" id="ha-model-sub"></span>
</button>
<button class="ha-item" role="menuitem" data-act="schedule">
<svg class="ic sm" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8.5"></circle><polyline points="12 7.5 12 12 15.5 14"></polyline></svg>
<span class="ha-item-main">定时任务</span><span class="ha-item-sub hidden" id="ha-sched-sub"></span>
</button>
<button class="ha-item" role="menuitem" data-act="compact">
<svg class="ic sm" viewBox="0 0 24 24"><ellipse cx="12" cy="5" rx="8" ry="2.5" fill="none" stroke="currentColor" stroke-width="1.6"></ellipse><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M4 5v6c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5V5"></path><path fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" d="M4 11v6c0 1.4 3.6 2.5 8 2.5s8-1.1 8-2.5v-6"></path></svg>
<span class="ha-item-main">压缩上下文</span>
</button>
<button class="ha-item" role="menuitem" data-act="new">
<svg class="ic sm" 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>
<span class="ha-item-main">新建会话</span>
</button>
</div>
</div>
</header>
<main>
<!-- ================= 未对话状态:欢迎页 ================= -->
@@ -164,8 +174,10 @@
<button class="plus-btn" id="attach-btn" title="上传文件" aria-label="上传文件">
<svg viewBox="0 0 24 24" class="ic sm"><path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"></path></svg>
</button>
<button class="send-btn" id="send-btn" title="发送" aria-label="发送">
<!-- 同一按钮两态:发送(↑)/ 停止(白色方块)。data-state 由 JS 切换,尺寸不变避免输入区跳动 -->
<button class="send-btn" id="send-btn" data-state="send" title="发送" aria-label="发送">
<svg viewBox="0 0 24 24" class="ic sm"><line x1="12" y1="19" x2="12" y2="5"></line><polyline points="5 12 12 5 19 12"></polyline></svg>
<span class="stop-sq" aria-hidden="true"></span>
</button>
</div>
</div>
@@ -340,7 +352,7 @@
<button class="modal-close-btn" onclick="closeScheduleModal()">
<svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
</button>
<h3>定时任务</h3>
<h3 id="schedule-modal-title">定时任务</h3>
<div class="sched-row">
<select id="sched-freq" onchange="schedFreqUi()">
<option value="daily">每天</option>
@@ -361,8 +373,8 @@
<div class="sched-meta" id="sched-modal-meta"></div>
<textarea id="sched-modal-prompt" rows="6" placeholder="每次触发时投递给本会话的提示词"></textarea>
<div class="btn-row">
<button class="ghost-btn danger" onclick="deleteSchedule()">删除</button>
<button class="primary-btn" onclick="saveSchedule()">更新</button>
<button class="ghost-btn danger" id="sched-del-btn" onclick="deleteSchedule()">删除</button>
<button class="primary-btn" id="sched-save-btn" onclick="saveSchedule()">更新</button>
</div>
</div>
</div>
@@ -398,7 +410,7 @@
</div>
</div>
<!-- 已完成/已终止会话:选择模型继续(搬自 index;phase-bar「选择模型」入口) -->
<!-- 已完成/已终止会话:选择模型继续(搬自 index;顶部动作区「切换模型」入口) -->
<div id="bind-model-modal" class="modal-overlay hidden" onclick="if(event.target===this)closeModelSwitch()">
<div class="modal">
<div class="msw-header">
+3 -2
View File
@@ -356,14 +356,15 @@
state.sessionTitle = (s && s.title) || '';
state.sessionType = (s && s.assistant_type) || 'secretary'; // 顶部 icon 跟随会话类型
state.status = (s && s.status) || '';
state.schedule = detail.schedule || null; // 定时任务状态条数据(随 updatePhaseBar 一并渲染)
state.modelId = (s && s.model_id) || ''; // 顶部动作区展示当前模型
state.schedule = detail.schedule || null; // 定时任务数据(顶部动作区副标题)
state.toolCards = {};
state.toolCallStreaming = {}; // 流式参数早卡映射随会话/回合重置
state.toolCallMsgIds = {}; // tool_call.id → tool 消息行 id(展开时懒加载用)
userPaused = false;
removeTyping();
renderHeader();
updatePhaseBar({ model_id: s && s.model_id });
updateHeaderActions();
const box = $('chat-view');
box.innerHTML = '';
appendMessagesDom(detail.messages || [], box).closeArc();
+2 -2
View File
@@ -164,6 +164,7 @@
pendingModel: '', // welcome 预选模型(ensureSession 建档时透传 model_id)
sessionId: null, // 当前会话
sessionTitle: '', // 当前会话标题
modelId: '', // 当前会话绑定的模型 id(顶部动作区展示/切换)
status: '', // 当前会话状态(SSE 更新)
schedule: null, // 当前会话定时任务(详情 schedule 字段,null=无)
sessions: [], // 抽屉列表缓存
@@ -194,9 +195,8 @@
state.view = view;
$('welcome-view').classList.toggle('hidden', view !== 'welcome');
$('chat-view').classList.toggle('hidden', view !== 'chat');
$('new-chat-btn').classList.toggle('hidden', view !== 'chat'); // 新建按钮仅对话状态显示
renderHeader();
updatePhaseBar(); // 状态栏仅对话视图显示
updateHeaderActions(); // 顶部动作区可用态随视图切换(定时任务/压缩需要会话)
updateScrollBottomBtn();
}
+12 -1
View File
@@ -29,7 +29,18 @@
send();
}
});
$('send-btn').addEventListener('click', () => send()); // 发送按钮与 Enter 行为一致
// 发送键双职:生成中变「停止」(白色方块),点击终止当前回合;否则正常发送。
// 400ms 内重复点击忽略:防双击重复 abort(服务端 status 事件回来前按钮仍是停止态)。
let stopClickAt = 0;
$('send-btn').addEventListener('click', () => {
if (state.status === 'active') {
if (Date.now() - stopClickAt < 400) return;
stopClickAt = Date.now();
stopSession();
return;
}
send();
});
// 深度思考开关:每次发消息随 body 传给后端,后端会合并该模型的 thinking_params
$('deep-think-btn').addEventListener('click', () => {
+151 -82
View File
@@ -157,7 +157,8 @@
if (typeof pvCloseDoc === 'function') pvCloseDoc(); // 同上:收起文档预览右栏,防旧会话内容残留
state.sessionId = id;
state.status = '';
state.schedule = null; // 防详情返回前残留上一会话的任务状态条
state.modelId = '';
state.schedule = null; // 防详情返回前残留上一会话的任务状态
// 先从抽屉列表缓存取会话类型,让顶部 icon 立即正确;详情回来后由 renderDetail 纠正
const cached = (state.sessions || []).find(x => x.id === id);
state.sessionType = (cached && cached.assistant_type) || 'secretary';
@@ -199,7 +200,7 @@
state.pendingModel = '';
setView('chat');
renderHeader();
updatePhaseBar();
updateHeaderActions();
connectStream();
return s.id;
}
@@ -212,6 +213,7 @@
state.sessionTitle = '';
state.sessionType = 'secretary';
state.status = '';
state.modelId = '';
state.schedule = null;
state.pendingModel = '';
state.attachments = [];
@@ -247,54 +249,109 @@
} catch (e) { toast('重命名失败:' + e.message); }
}
// ---------- 会话状态栏(搬自 index 的 phase-bar 功能) ----------
function updatePhaseBar(d) {
const bar = $('phase-bar');
if (!bar) return;
// 定时任务状态条与会话状态栏同刷新入口(其内部自判视图/有无任务,早退路径也要走到)
updateScheduleBar();
if (!(state.view === 'chat' && state.sessionId)) { bar.classList.add('hidden'); return; }
bar.classList.remove('hidden');
const pill = $('status-pill');
const stMap = { active: '活跃中', held: '保持中', completed: '已完成', cancelled: '已终止' };
const statusText = stMap[state.status] || state.status || '--';
// 持有绑定的态都附带当前模型:key 非独占、无租约,绑定跨结版持续可见;
// held/cancelled 下模型名即「更换模型」入口(复用选择弹窗),输出中(active)只展示不给点;
// completed 收走展示(手动断开/超时长自动收口),再发言仍沿用原绑定
const showModel = !!(d && d.model_id && state.status !== 'completed');
const switchable = showModel && state.status !== 'active';
if (switchable) {
pill.innerHTML = esc(statusText) + ' · <span class="pill-model" title="点击更换模型" onclick="openModelSwitch()">' + esc(d.model_id) + '</span>';
} else if (showModel) {
pill.innerHTML = esc(statusText) + ' · ' + esc(d.model_id);
} else {
pill.textContent = statusText;
}
// 状态胶囊配色:活跃中绿(执行中)、保持中黄(已答完、保持模型中)等;状态栏整体同步染色
pill.className = 'status-pill ' + (state.status || '');
bar.className = 'phase-bar ' + (state.status || '');
// 活跃中提供「终止」;保持中改为「断开」(纯状态动作:收起保持态徽标,绑定仍在、再发言继续用原模型)
const btn = $('stop-btn');
const actionable = state.status === 'active' || state.status === 'held';
btn.classList.toggle('hidden', !actionable);
btn.textContent = state.status === 'held' ? '断开' : '终止';
btn.classList.toggle('muted', state.status === 'held');
// 「选择模型」独立按钮:胶囊里的模型名可点时(held/cancelled)不再重复给入口;
// completed(无模型名)或事件未带 model_id 时仍靠它继续/换模;active 维持原逻辑隐藏
const msBtn = $('model-switch-btn');
if (msBtn) msBtn.classList.toggle('hidden', !(state.sessionId && state.status && !switchable && state.status !== 'active'));
// 状态栏「压缩」按钮:active 时不允许(避免与正在跑的回合抢上下文);
// 其余状态可点。未发起总结时可点;发起后按钮 disabled 防双击。
const cpBtn = $('compress-btn');
if (cpBtn) {
const allowShow = !!(state.sessionId && state.status && state.status !== 'active');
cpBtn.classList.toggle('hidden', !allowShow);
// 只有不在请求中时才允许 active 决定 disabled;避免总结流程中被打断时再次被 allowed
if (!state.pendingSummary) cpBtn.disabled = state.status === 'active';
}
}
// ---------- 顶部动作区(切换模型 / 定时任务 / 压缩上下文 / 新建会话) ----------
// 原 phase-bar 状态栏已移除:运行状态由发送按钮(发送⇄停止)表达,模型名与定时任务信息收进动作区;
// 桌面端平铺 4 个图标,移动端(<640px)收进「更多」下拉菜单,两者共用 data-act。
function currentModelLabel() {
return state.sessionId ? (state.modelId || '') : (state.pendingModel || '');
}
// ---------- 定时任务状态条(整条可点→详情弹窗;创建只走 AI 工具,频次/提示词可在弹窗内改) ----------
function updateHeaderActions() {
const inChat = state.view === 'chat' && !!state.sessionId;
const running = state.status === 'active';
// 定时任务需要会话;压缩额外要求不在生成中(回合进行中后端会 409)
const compactOk = inChat && !running && !state.pendingSummary;
document.querySelectorAll('#header-meta [data-act], #header-actions [data-act]').forEach(el => {
const act = el.dataset.act;
if (act === 'schedule') el.disabled = !inChat;
else if (act === 'compact') el.disabled = !compactOk;
});
// 当前模型:桌面文字位(仅会话内显示)+ 移动菜单副标题(过长由 CSS 省略号截断)
const name = currentModelLabel();
const mtext = $('hdr-model-text');
if (mtext) mtext.textContent = name || '选择模型';
const mchip = $('hdr-model');
if (mchip) {
// 新建会话页(welcome)不展示模型位,由欢迎页头像入口接管
mchip.classList.toggle('hidden', !inChat);
// 底色/文字色随会话状态变化(active/held/completed/cancelled),与旧状态胶囊一致
mchip.dataset.status = inChat ? (state.status || '') : '';
// 状态文字只在 tooltip 里保留——颜色是主信号,悬停给明确语义;顺带展示(可能被截断的)完整模型名
const stText = { active: '活跃中', held: '保持中', completed: '已完成', cancelled: '已终止' }[state.status] || '';
mchip.dataset.tip = stText ? stText + ' · ' + (name || '切换模型') : (name ? '切换模型 · ' + name : '切换模型');
}
const msub = $('ha-model-sub');
if (msub) { msub.textContent = name; msub.classList.toggle('hidden', !name); }
// 定时任务:无任务=灰色「定时任务」(点击新建),有任务=紫色频次(点击编辑);无会话整块隐藏
const hasSched = !!state.schedule;
const schip = $('hdr-sched');
if (schip) {
schip.classList.toggle('hidden', !inChat);
schip.classList.toggle('on', hasSched);
// 无任务时只留时钟图标(文字整块收起);有任务才展开频次文字
const stext = $('hdr-sched-text');
if (stext) {
stext.textContent = hasSched ? cronText(state.schedule.cron_expr) : '';
stext.classList.toggle('hidden', !hasSched);
}
schip.dataset.tip = hasSched ? '定时任务 · 点击编辑' : '定时任务 · 点击新建';
}
// 压缩图标仅会话内有意义
const cchip = $('hdr-compact');
if (cchip) cchip.classList.toggle('hidden', !inChat);
// 移动菜单里的定时任务副标题
const ssub = $('ha-sched-sub');
if (ssub) {
const t = inChat ? (hasSched ? cronText(state.schedule.cron_expr) : '未设置') : '';
ssub.textContent = t;
ssub.classList.toggle('hidden', !t);
}
// 发送键在生成中切「停止」:同一按钮换图标,尺寸不变,输入区不跳动
const sb = $('send-btn');
if (sb) {
sb.dataset.state = running ? 'stop' : 'send';
sb.title = running ? '停止生成' : '发送';
sb.setAttribute('aria-label', running ? '停止生成' : '发送');
}
}
function openHeaderMenu() {
updateHeaderActions();
$('ha-menu').classList.remove('hidden');
$('ha-more').setAttribute('aria-expanded', 'true');
}
function closeHeaderMenu() {
const m = $('ha-menu');
if (!m || m.classList.contains('hidden')) return;
m.classList.add('hidden');
const t = $('ha-more');
if (t) t.setAttribute('aria-expanded', 'false');
}
function toggleHeaderMenu() {
if ($('ha-menu').classList.contains('hidden')) openHeaderMenu(); else closeHeaderMenu();
}
function runHeaderAction(act) {
closeHeaderMenu();
if (act === 'model') openModelSwitch();
else if (act === 'schedule') openScheduleModal();
else if (act === 'compact') summarizeChat();
else if (act === 'new') newChat();
}
// 桌面属性区(模型/定时任务/压缩)与移动菜单项共用同一批 data-act,事件只在这里绑一次。
(function bindHeaderActions() {
document.querySelectorAll('#header-meta [data-act], #header-actions [data-act]').forEach(el => {
el.addEventListener('click', () => { if (!el.disabled) runHeaderAction(el.dataset.act); });
});
$('ha-more').addEventListener('click', toggleHeaderMenu);
// 点动作区以外关闭菜单(Esc 同)
document.addEventListener('click', e => {
if ($('ha-menu').classList.contains('hidden')) return;
if (!e.target.closest('#header-actions')) closeHeaderMenu();
});
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeHeaderMenu(); });
})();
// ---------- 定时任务(弹窗改频次/提示词;无任务时同一弹窗即新建) ----------
const CRON_DOW = ['日', '一', '二', '三', '四', '五', '六'];
// cron 人类可读化:只覆盖常见形态(每天/每周几几点、每 N 小时),其余原样显示表达式
function cronText(expr) {
@@ -311,22 +368,6 @@
}
return String(expr);
}
function updateScheduleBar() {
const bar = $('schedule-bar');
if (!bar) return;
const sc = state.schedule;
if (!(state.view === 'chat' && state.sessionId && sc)) { bar.classList.add('hidden'); bar.innerHTML = ''; return; }
let last;
// running 不精确(AI 跑完到下次 tick 间仍显示),对 UI 够用;无专用轮询,重进会话时刷新
if (sc.last_status === 'running') last = '执行中…';
else if (sc.last_status === 'ok') last = '上次 ok';
else if (sc.last_status === 'error') last = '上次 error' + (sc.last_note ? ': ' + sc.last_note : '');
else if (sc.last_status === 'skipped') last = '上次 跳过' + (sc.last_note ? ':' + sc.last_note : '');
else last = '下次 ' + fmtTime(sc.next_run_at);
bar.innerHTML = '<span class="sched-text">' + esc(cronText(sc.cron_expr)) + ' · ' + esc(last) + '</span>'
+ '<span class="sched-eye"><svg class="ic" viewBox="0 0 24 24"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path><circle cx="12" cy="12" r="3"></circle></svg></span>';
bar.classList.remove('hidden');
}
// 频次控件显隐:每天=[时分] 每周=[天][时分] 每隔=[N][小时] 自定义=[cron 文本框]
function schedFreqUi() {
const f = $('sched-freq').value;
@@ -374,32 +415,60 @@
if (!(mm >= 0 && mm <= 59)) throw new Error('分钟需为 0-59');
return mm + ' ' + hh + ' * * ' + (f === 'weekly' ? $('sched-dow').value : '*');
}
// 定时任务弹窗两种形态:edit = 已有任务(改频次/提示词/删除);create = 本会话还没任务(直接新建)
let schedMode = 'edit';
function openScheduleModal() {
if (!(state.view === 'chat' && state.sessionId)) { toast('先打开一个会话,再设置定时任务'); return; }
const sc = state.schedule;
if (!sc || state.view !== 'chat') return;
schedFillFromCron(sc.cron_expr);
let meta = sc.next_run_at ? '下次执行 ' + fmtTime(sc.next_run_at) : '';
if (sc.last_run_at) meta += (meta ? '\n' : '') + '上次执行 ' + fmtTime(sc.last_run_at) + (sc.last_status ? ' · ' + sc.last_status : '');
$('sched-modal-meta').textContent = meta;
$('sched-modal-prompt').value = sc.prompt || '';
schedMode = sc ? 'edit' : 'create';
const title = $('schedule-modal-title');
const delBtn = $('sched-del-btn');
const saveBtn = $('sched-save-btn');
if (sc) {
schedFillFromCron(sc.cron_expr);
let meta = sc.next_run_at ? '下次执行 ' + fmtTime(sc.next_run_at) : '';
if (sc.last_run_at) meta += (meta ? '\n' : '') + '上次执行 ' + fmtTime(sc.last_run_at) + (sc.last_status ? ' · ' + sc.last_status : '');
$('sched-modal-meta').textContent = meta;
$('sched-modal-prompt').value = sc.prompt || '';
if (title) title.textContent = '定时任务';
if (delBtn) delBtn.classList.remove('hidden');
if (saveBtn) saveBtn.textContent = '更新';
} else {
// 新建:默认每天 09:00,提示词留空
$('sched-freq').value = 'daily';
$('sched-dow').value = '1';
$('sched-hh').value = 9;
$('sched-mm').value = 0;
schedFreqUi();
$('sched-modal-meta').textContent = '本会话还没有定时任务,填好频次与提示词后点「创建」。';
$('sched-modal-prompt').value = '';
if (title) title.textContent = '新建定时任务';
if (delBtn) delBtn.classList.add('hidden');
if (saveBtn) saveBtn.textContent = '创建';
}
$('schedule-modal').classList.remove('hidden');
}
function closeScheduleModal() { $('schedule-modal').classList.add('hidden'); }
async function saveSchedule() {
const id = state.sessionId;
if (!id || !state.schedule) return;
if (!id) return;
const prompt = $('sched-modal-prompt').value.trim();
if (!prompt) { toast('提示词不能为空'); return; }
let cron;
try { cron = schedComposeCron(); } catch (e) { toast(e.message); return; }
const isCreate = schedMode === 'create' || !state.schedule;
try {
await req('PATCH', '/api/sessions/' + id + '/schedule', { prompt: prompt, cron_expr: cron });
toast('定时任务已更新');
if (isCreate) {
await req('POST', '/api/sessions/' + id + '/schedule', { prompt: prompt, cron_expr: cron });
} else {
await req('PATCH', '/api/sessions/' + id + '/schedule', { prompt: prompt, cron_expr: cron });
}
toast(isCreate ? '定时任务已创建' : '定时任务已更新');
closeScheduleModal();
// 频次变了 next_run_at 由后端重算,重拉详情同步状态条(与删除后同一套刷新路径)
// 频次变了 next_run_at 由后端重算,重拉详情同步动作区(与删除后同一套刷新路径)
const detail = await req('GET', '/api/sessions/' + id + '?limit=' + Math.max(CHAT_PAGE_SIZE, state.chatLoadedCount));
if (state.sessionId === id) { renderDetail(detail); connectStream(); }
} catch (e) { toast('更新失败:' + e.message); }
} catch (e) { toast((isCreate ? '创建失败:' : '更新失败:') + e.message); }
}
async function deleteSchedule() {
if (!state.sessionId) return;
@@ -428,6 +497,8 @@
} catch (e) { toast((held ? '断开失败:' : '终止失败:') + e.message); }
}
async function openModelSwitch() {
// 生成中后端会拒绝换绑(回合进行中):直接提示,不弹一个选了也绑不上的窗
if (state.status === 'active') { toast('AI 正在输出,请稍后再切换模型'); return; }
// welcome(无会话)也可开:模型选择记为预选项,ensureSession 建档时兑现。有会话则即点即绑,行为与原逻辑一致。
const list = $('bind-model-list');
const sub = $('bind-model-sub');
@@ -519,7 +590,7 @@
} catch (_) {}
}
// ---------- 「压缩」上下文总结 ----------
// 用户点 phase-bar「压缩」按钮 → 弹窗选动作(右上角 X 关闭 = 不做任何事):
// 用户点顶部动作区「压缩上下文」→ 弹窗选动作(右上角 X 关闭 = 不做任何事):
// 摘要(generate_only):AI 总结落库后,后端把摘要标 type='summary'、之前的消息标 type='archived'
// (UI 保留全部展示,但旧消息不再发给模型);前端把摘要前旧消息就地淡出存档。
// 清空:直接走 clearChat()(DELETE 全部聊天记录,从零开始,不可恢复)。
@@ -544,8 +615,7 @@
async function startSummary() {
if (!state.sessionId || state.pendingSummary) return;
state.pendingSummary = true;
const btn = $('compress-btn');
if (btn) btn.disabled = true;
updateHeaderActions(); // 「压缩」项置灰,防重复点击
try {
const r = await req('POST', '/api/sessions/' + state.sessionId + '/summarize');
// 开始压缩后直接把「压缩指令」当成普通用户消息发出来(后端回显 prompt);
@@ -555,7 +625,7 @@
toast('已生成摘要中…');
} catch (e) {
state.pendingSummary = false;
if (btn) btn.disabled = false;
updateHeaderActions();
toast('压缩失败:' + e.message);
}
}
@@ -659,7 +729,6 @@
if (state.sessionId === id) { renderDetail(detail); connectStream(); }
loadSessionList();
} catch (e) { toast('清空失败:' + e.message); }
const cpBtn = $('compress-btn');
if (cpBtn) cpBtn.disabled = state.status === 'active';
updateHeaderActions();
}
+1 -1
View File
@@ -1,6 +1,6 @@
// 设置区(页面栈/账户/服务/config/技能/模型池/MCP)+ 全局初始化(必须最后加载,初始化段在文件尾)
'use strict';
$('new-chat-btn').addEventListener('click', newChat);
// 「新建会话」入口已并入顶部动作区(见 sessions.js 的 data-act="new"),此处不再单独绑 #new-chat-btn
// ============================================================================
// 设置区(侧边栏用户区点击进入;页面搬自 index.html,接口全部复用既有 /api)
+7 -7
View File
@@ -11,6 +11,8 @@
async function send() {
const ta = $('msg-input');
// 生成中发送键已变「停止」:不接受新消息(不做排队发送,停止后再发)
if (state.status === 'active') { toast('正在生成中,请先停止'); return; }
const content = ta.value.trim();
// 没有文字就不发(避免产生空消息);上传文件告知行在发送时拼在正文前(见下)。
if (!content) {
@@ -136,8 +138,9 @@
es.addEventListener('status', ev => {
const d = JSON.parse(ev.data);
state.status = d.status;
if (d.model_id) state.modelId = d.model_id;
renderHeader();
updatePhaseBar(d);
updateHeaderActions();
updateScrollBottomBtn(); // 状态切换同步右下角转圈(开始/结束干活)
});
es.addEventListener('assistant_delta', ev => {
@@ -238,13 +241,11 @@
// 历史保留展示,但摘要之前的旧消息已存档:同步淡出 + 尾部说明,和重进入后的样式一致。
archiveDomBeforeSummary();
toast('已生成摘要:旧历史已存档,后续对话从摘要开始');
const cpBtn = $('compress-btn');
if (cpBtn) cpBtn.disabled = state.status === 'active';
updateHeaderActions();
} else if (d.is_summary && state.pendingSummary && !hasText) {
// AI 总结为空/出错,复位状态。用于按钮状态还原。
state.pendingSummary = false;
const cpBtn = $('compress-btn');
if (cpBtn) cpBtn.disabled = state.status === 'active';
updateHeaderActions();
}
});
// 参数流式生成早卡:id+name 就绪即建卡展开,长参数(write_file 大文件)期间不再是死寂 typing
@@ -313,8 +314,7 @@
if (state.pendingSummary) {
state.pendingSummary = false;
toast('压缩回合已结束,未收到摘要,历史未变动');
const cpBtn = $('compress-btn');
if (cpBtn) cpBtn.disabled = state.status === 'active';
updateHeaderActions();
}
state.streaming = false;
state.streamEl = null; // 防御性清理:回合异常结束(如终止)时不留悬空气泡到下一轮
+23
View File
@@ -237,6 +237,29 @@ router.delete('/:id', wrap((req, res) => {
res.json(engine.deleteSession(req.params.id, delDir));
}));
// 手动创建定时任务(顶部动作区「定时任务」→ 本会话还没有任务时的新建弹窗入口)。
// 与 AI schedule 工具同源(scheduler.createTask):cron 校验、最小间隔 1h、提示词上限完全一致;
// brief 取提示词首行(与工具路径「人话描述」同义),作为下班日记碎片的底子。
router.post('/:id/schedule', wrap((req, res) => {
const db = engine.getDb();
const body = req.body || {};
const s = db.prepare('SELECT id FROM sessions WHERE id = ?').get(req.params.id);
if (!s) throw Object.assign(new Error('会话不存在'), { status_code: 404 });
const prompt = String(body.prompt || '').trim();
if (!prompt) throw Object.assign(new Error('提示词不能为空'), { status_code: 400 });
const cron = String(body.cron_expr || '').trim();
if (!cron) throw Object.assign(new Error('请选择执行频次'), { status_code: 400 });
let r;
try {
r = scheduler.createTask(db, req.params.id, cron, prompt, prompt.split('\n')[0].slice(0, 40), '', '');
} catch (e) {
// cron 不合法/间隔不足/已有任务:都是调用方输入问题,回 400 让前端 toast
throw Object.assign(e, { status_code: 400 });
}
log.info('scheduler', (req.user || '-') + ' 手动创建定时任务 ' + cron + ' ' + req.params.id);
res.json(r);
}));
// 手动修改定时任务(会话详情 schedule 弹窗入口):提示词 + 频次(前端预设控件组合出的 cron,兼容自定义表达式)。
// cron 变化才重算 next_run_at(同样以 now 为基准);不插通知消息——每次触发前历史会被存档,
// AI 只看到投递的 prompt 本身,改完下次触发自然生效。