agent-loft 0.2.51 → 0.2.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,13 +51,13 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
51
51
  - 输入框里的小圆环显示上下文窗口占用;模型按钮显示实际的模型和思考程度(如「Opus 5.5 high」)。
52
52
  - 滚动和 ChatGPT 一样:发出的问题顶到最上面、下面留白,回复长到屏幕底部才跟着往下滚;回复过程中自己滚动了就不再自动滚,下次发消息再恢复。
53
53
  - 定时发送:右上角「更多」→「定时发送」,默认排在 5 小时额度重置后 5 分钟(弹窗里提示 5 小时 / 7 天额度的重置时间),由服务端到点发出,关掉页面也会发。适合额度用完、要等刷新才能接着干活的时候。
54
- - 侧栏直接显示各个文件夹,Web 会话按工作目录归类(目录可以拖动排序,右键可置顶;排好的顺序跟着账号走、各设备一致,新消息不会打乱),飞书机器人各占一行(右键看历史会话);项目名、有分叉的会话后面有个小三角,点一下折叠 / 展开(折叠后显示「N 个嵌套会话」);分叉出来的会话缩进挂在原会话下面,用一条细线连着;标题放不下时尾巴淡出;会话标题由 agent 自动生成,双击重命名;鼠标移到会话上,标题后显示对应的专家图标。
55
- - **搜索**:侧栏「搜索」弹窗,搜全部会话的标题、目录名和聊天内容(不开记忆也能搜),可以按专家筛;电脑和手机上弹窗都固定高度,结果在内部滚动;↑↓ 选、回车打开。
54
+ - 侧栏直接显示各个文件夹,Web 会话按工作目录归类(目录可以拖动排序,右键可置顶;排好的顺序跟着账号走、各设备一致,新消息不会打乱),飞书机器人各占一行(右键看历史会话);项目名、有分叉的会话后面有个小三角,点一下折叠 / 展开(折叠后显示「N 个嵌套会话」);分叉出来的会话缩进挂在原会话下面,用一条细线连着;标题放不下时尾巴淡出;会话标题由 agent 自动生成,双击重命名;鼠标移到会话上,行尾显示对应的专家图标;定时任务的时钟图标始终放在最右侧。
55
+ - **搜索**:侧栏「搜索」弹窗,搜全部会话的标题、目录名和聊天内容(不开记忆也能搜),可以按专家筛;电脑和手机上弹窗都固定高度,结果在内部滚动,手机上从底部展开;↑↓ 选、回车打开。
56
56
  - 会话页顶部标题前是专家的头像,鼠标停上去或点一下,看专家的说明、模型、能力和当前工作目录。
57
57
  - 附件可以直接拖到聊天区任意位置上传。
58
- - 回复过程中接着发的消息排队,标着「排队中」,上一条回复完自动接着处理;点「撤销并编辑」图标把排队消息放回输入框;点「打断并发送」停掉正在进行的回复、马上处理这条;点停止则连排着的一起取消(标「没有发出」)。
58
+ - 回复过程中接着发的消息排队,标着「排队中」,隐藏底部的复制和回退按钮,上一条回复完自动接着处理;点「撤销并编辑」图标把排队消息放回输入框;点「打断并发送」停掉正在进行的回复、马上处理这条;点停止则连排着的一起取消(标「没有发出」)。
59
59
  - 用户消息的复制按钮后有「回退到此处」图标:把这条消息及附件放回输入框,并删除它及之后的聊天内容,重新发送时从之前的上下文继续。
60
- - 太长的消息先收起,点「展开显示」看全文;对话里有至少 3 条用户消息时,右侧显示快速定位尺,电脑上鼠标移入查看消息开头、点击跳转;手机上滚动时显示,停下约 1.2 秒后隐藏,点刻度跳转。
60
+ - 太长的消息先收起,点「展开显示」看全文;对话里有至少 3 条用户消息时,右侧显示快速定位尺,电脑上鼠标移入查看消息开头、点击跳转;手机上手动滚动时显示短轨道,按住拖动可预览问题和位置,松手跳转,停止操作约 1.6 秒后隐藏。
61
61
  - 回复底部的 token 数自动按大小显示为 K、M 等单位。
62
62
  - 侧栏按页加载:每个项目目录先显示 5 条,点「展开显示」每次再拉 10 条。
63
63
  - 侧栏底部显示 Claude / Codex 的订阅额度(5 小时 / 7 天窗口,以及多久后重置);关了额度查询就整块不显示。
@@ -71,7 +71,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
71
71
  - **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude 的「总是允许」名单;「/」命令);**连接**(飞书机器人、配对批准、指令面板同步;远程控制;服务器);**管理**(用户、所有人的登录设备;服务端版本和升级、重启、局域网访问和端口)。改了没保存就切页或关掉设置会先提醒。
72
72
  - **多用户**(信任型):管理员在 设置 → 用户 里给别人建账号。每个人只看得到自己的对话、授权和通知,设置只有管理员能改,见下面「安全」。
73
73
  - **专家**:设置 → 专家。专家是一份配置,新建对话、定时任务时选一个,对话从头到尾都是它(中途不能换;飞书里 `/expert 名字`、`/claude`、`/codex` 换专家会开新会话)。**内置专家**:Claude Code、Codex,就是 agent 原装的样子(原装提示词、机器上的技能和 MCP、所有工具)。**自定义专家**每人管自己的,可以配:
74
- - 头像(自己上传,没传就用引擎的图标)、引擎(Claude / Codex,建好后不能换)、默认模型和思考程度(从模型列表里选);
74
+ - 头像(点头像区域的加号上传;未上传时,会话中用引擎的图标)、引擎(Claude / Codex,建好后不能换)、默认模型和思考程度(从模型列表里选);
75
75
  - 提示词:人设、规则、输出格式。agent-loft 在后面自动补上这个专家能做什么、今天的日期、记忆。Claude 专家默认只用这段提示词(一句话约 2 千 token),也可以选「追加在 Claude Code 原装提示词后面」(干活更稳,每轮多约 1.6 万);Codex 的基础指令改不了,专家的提示词附在第一条消息后面,约束力弱一些;
76
76
  - 权限,勾选:联网搜索、读网页,以及文件权限(一级包含一级):都不勾就是**只能联网**(不碰本机文件、不弹授权,文本附件内容直接放进消息)/**能读文件**/**能改文件**/**能跑命令**(跑命令就等于能改任何文件,需要授权时弹卡)。Claude 按权限给工具;Codex 按权限开 shell、apply_patch,沙箱只读或 workspace-write;
77
77
  - 带不带个人记忆,默认工作目录,新对话页上的欢迎语和快捷提问;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.51",
3
+ "version": "0.2.52",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -950,12 +950,14 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
950
950
  const seq = hub.currentSeq();
951
951
  // 进行中的这一轮,agent 的记录里可能已经写进去了一部分,和 live 重复:
952
952
  // 记录里最后一条用户消息就是这一轮的那条时,从它起砍掉,交给 live 来画
953
- const liveUser = live.find((e) => e.ev.type === "user")?.ev as { text?: string } | undefined;
954
- if (liveUser) {
953
+ const liveUser = live.find((e) => e.ev.type === "user" && !e.ev.queued)?.ev;
954
+ if (liveUser?.type === "user") {
955
+ const anchor = live.findLast((e) => e.ev.type === "user_anchor" && e.ev.id === liveUser.id)?.ev;
955
956
  const lastUser = messages.map((m) => m.role).lastIndexOf("user");
956
957
  const norm = (t: string) => t.replace(/\s+/g, " ").trim();
957
958
  const want = norm(liveUser.text ?? "");
958
- if (lastUser >= 0 && want && norm(messages[lastUser]!.text).startsWith(want.slice(0, 200))) {
959
+ const sameAnchor = anchor?.type === "user_anchor" && messages[lastUser]?.anchor === anchor.anchor;
960
+ if (lastUser >= 0 && (sameAnchor || (want && norm(messages[lastUser]!.text).startsWith(want.slice(0, 200))))) {
959
961
  messages = messages.slice(0, lastUser);
960
962
  }
961
963
  }
package/src/core/hub.ts CHANGED
@@ -500,24 +500,21 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
500
500
  return [...parts, streaming].join("\n");
501
501
  }
502
502
 
503
- /** 正在进行的这一轮(从最后一条用户消息起),给刚打开页面的客户端补画用。 */
503
+ /** 正在进行的这一轮及尚未处理的输入,给刚打开页面的客户端补画用。 */
504
504
  liveTurn(key: string): EventEnvelope[] {
505
505
  if (!this.isBusy(key)) return [];
506
506
  const buf = this.buffers.get(key) ?? [];
507
- let start = buf.length;
508
- for (let i = buf.length - 1; i >= 0; i--) {
509
- const t = buf[i]!.ev.type;
510
- if (t === "user") {
511
- start = i;
512
- break;
513
- }
514
- if (t === "result" || t === "error") {
515
- start = i + 1;
516
- break;
517
- }
518
- if (i === 0) start = 0;
519
- }
520
- return buf.slice(start);
507
+ const start = buf.findLastIndex(({ ev }) => ev.type === "result" || ev.type === "error") + 1;
508
+ const fifo = this.turnFifo.get(key) ?? [];
509
+ const active = fifo[0]?.id;
510
+ const inputs = new Set(fifo.map((entry) => entry.id));
511
+ for (const [id, waiting] of this.pendingInputs.get(key) ?? []) if (!waiting.cancelled) inputs.add(id);
512
+ return buf.filter(({ ev }, i) => i >= start || (
513
+ (ev.type === "user" || ev.type === "queue" || ev.type === "user_anchor") && inputs.has(ev.id!)
514
+ )).map((env) => (
515
+ // 下一轮的输入可能早在上一轮结束之前就收到了,重放时它已经不再排队。
516
+ env.ev.type === "user" && env.ev.id === active ? { ...env, ev: { ...env.ev, queued: false } } : env
517
+ ));
521
518
  }
522
519
 
523
520
  isBusy(key: string): boolean {
@@ -183,6 +183,7 @@
183
183
  .avatar-preview {
184
184
  width: 56px;
185
185
  height: 56px;
186
+ padding: 0;
186
187
  border-radius: 50%;
187
188
  border: 1px dashed var(--border);
188
189
  background: var(--bg-soft);
@@ -198,6 +199,7 @@
198
199
  }
199
200
 
200
201
  .avatar-preview img {
202
+ display: block;
201
203
  width: 100%;
202
204
  height: 100%;
203
205
  object-fit: cover;
@@ -208,17 +210,6 @@
208
210
  height: 28px;
209
211
  }
210
212
 
211
- .avatar-emoji {
212
- font-size: 28px;
213
- line-height: 1;
214
- }
215
-
216
- .avatar-btns {
217
- display: flex;
218
- flex-direction: column;
219
- gap: 6px;
220
- }
221
-
222
- .avatar-btns .btn[hidden] {
213
+ .avatar-field .btn[hidden] {
223
214
  display: none;
224
215
  }
@@ -577,6 +577,10 @@ a.att-file:hover {
577
577
  transition: opacity 0.15s;
578
578
  }
579
579
 
580
+ .user-actions[hidden] {
581
+ display: none;
582
+ }
583
+
580
584
  .msg-user-group:hover .user-actions,
581
585
  .user-actions:focus-within {
582
586
  opacity: 1;
@@ -1042,37 +1046,157 @@ a.att-file:hover {
1042
1046
  font-weight: 500;
1043
1047
  }
1044
1048
 
1045
- /* 手机和触屏:滚动时显示,停止后淡出;点击刻度直接跳转 */
1049
+ .msg-nav-rail,
1050
+ .msg-nav-preview {
1051
+ display: none;
1052
+ }
1053
+
1054
+ /* 手机和触屏:短轨道不独立滚动,按住预览、松手定位 */
1046
1055
  @media (max-width: 768px), (hover: none) {
1047
1056
  .msg-nav {
1048
- right: max(2px, env(safe-area-inset-right));
1057
+ right: max(0px, env(safe-area-inset-right));
1049
1058
  opacity: 0;
1050
1059
  visibility: hidden;
1051
1060
  pointer-events: none;
1052
- transition: opacity 0.2s, visibility 0.2s;
1061
+ transition: opacity 0.22s, visibility 0.22s;
1053
1062
  }
1054
1063
 
1055
- .msg-nav.scrolling {
1064
+ .msg-nav.scrolling,
1065
+ .msg-nav.scrubbing {
1056
1066
  opacity: 1;
1057
1067
  visibility: visible;
1058
1068
  pointer-events: auto;
1059
1069
  }
1060
1070
 
1061
- .msg-nav-ticks {
1062
- max-height: 45dvh;
1063
- padding: 4px;
1064
- border-radius: 8px;
1065
- background: color-mix(in srgb, var(--bg) 85%, transparent);
1071
+ .msg-nav-ticks,
1072
+ .msg-nav-panel {
1073
+ display: none;
1066
1074
  }
1067
1075
 
1068
- .msg-nav-tick {
1069
- width: 28px;
1070
- height: 18px;
1071
- touch-action: manipulation;
1076
+ .msg-nav-rail {
1077
+ display: block;
1078
+ position: relative;
1079
+ width: 44px;
1080
+ height: clamp(88px, 24dvh, var(--nav-rail-height, 156px));
1081
+ touch-action: none;
1082
+ user-select: none;
1083
+ -webkit-user-select: none;
1084
+ border-radius: 16px;
1072
1085
  }
1073
1086
 
1074
- .msg-nav-panel {
1075
- display: none;
1087
+ .msg-nav-rail::before {
1088
+ content: "";
1089
+ position: absolute;
1090
+ inset: 0 4px 0 14px;
1091
+ background: color-mix(in srgb, var(--bg) 92%, transparent);
1092
+ border: 1px solid var(--border);
1093
+ border-radius: 16px;
1094
+ box-shadow: 0 2px 10px #00000008;
1095
+ opacity: 0;
1096
+ transition: opacity 0.15s;
1097
+ }
1098
+
1099
+ .msg-nav.scrubbing .msg-nav-rail::before {
1100
+ opacity: 1;
1101
+ }
1102
+
1103
+ .msg-nav-rail:focus-visible {
1104
+ outline: 2px solid var(--fg-soft);
1105
+ outline-offset: -2px;
1106
+ }
1107
+
1108
+ .msg-nav-track {
1109
+ position: absolute;
1110
+ top: 14px;
1111
+ bottom: 14px;
1112
+ right: 10px;
1113
+ width: 14px;
1114
+ pointer-events: none;
1115
+ }
1116
+
1117
+ .msg-nav-mark,
1118
+ .msg-nav-thumb {
1119
+ position: absolute;
1120
+ right: 0;
1121
+ transform: translateY(-50%);
1122
+ border-radius: 999px;
1123
+ }
1124
+
1125
+ .msg-nav-mark {
1126
+ height: 2px;
1127
+ width: 5px;
1128
+ background: var(--fg-faint);
1129
+ opacity: 0.5;
1130
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--bg) 65%, transparent);
1131
+ }
1132
+
1133
+ .msg-nav-mark.major {
1134
+ width: 9px;
1135
+ }
1136
+
1137
+ .msg-nav-thumb {
1138
+ top: calc(var(--nav-progress, 0) * 100%);
1139
+ width: 16px;
1140
+ height: 4px;
1141
+ background: var(--fg);
1142
+ box-shadow: 0 0 0 3px var(--bg);
1143
+ transition: top 0.12s ease-out;
1144
+ }
1145
+
1146
+ .msg-nav.scrubbing .msg-nav-thumb {
1147
+ transition: none;
1148
+ }
1149
+
1150
+ .msg-nav-preview {
1151
+ display: flex;
1152
+ position: absolute;
1153
+ right: 46px;
1154
+ top: calc(14px + (100% - 28px) * var(--nav-progress, 0));
1155
+ transform: translateY(-50%);
1156
+ flex-direction: column;
1157
+ gap: 4px;
1158
+ width: min(240px, calc(100vw - 72px));
1159
+ padding: 10px 12px;
1160
+ border: 1px solid var(--border);
1161
+ border-radius: 12px;
1162
+ background: var(--bg);
1163
+ box-shadow: 0 4px 20px #00000014;
1164
+ color: var(--fg);
1165
+ opacity: 0;
1166
+ visibility: hidden;
1167
+ pointer-events: none;
1168
+ transition: opacity 0.12s, visibility 0.12s;
1169
+ }
1170
+
1171
+ .msg-nav.scrubbing .msg-nav-preview {
1172
+ opacity: 1;
1173
+ visibility: visible;
1174
+ }
1175
+
1176
+ .msg-nav-count {
1177
+ font-size: 11px;
1178
+ line-height: 1.3;
1179
+ color: var(--fg-faint);
1180
+ font-variant-numeric: tabular-nums;
1181
+ }
1182
+
1183
+ .msg-nav-snippet {
1184
+ display: -webkit-box;
1185
+ -webkit-line-clamp: 2;
1186
+ -webkit-box-orient: vertical;
1187
+ overflow: hidden;
1188
+ overflow-wrap: anywhere;
1189
+ font-size: 13px;
1190
+ line-height: 1.5;
1191
+ }
1192
+ }
1193
+
1194
+ @media (prefers-reduced-motion: reduce) {
1195
+ .msg-nav,
1196
+ .msg-nav-thumb,
1197
+ .msg-nav-preview,
1198
+ .msg-nav-rail::before {
1199
+ transition: none;
1076
1200
  }
1077
1201
  }
1078
1202
 
@@ -1102,16 +1226,15 @@ a.att-file:hover {
1102
1226
  }
1103
1227
 
1104
1228
  .queue-jump {
1105
- padding: 2px 8px;
1106
- border-radius: 6px;
1229
+ padding: 2px 0;
1107
1230
  font-size: 12px;
1108
1231
  color: var(--fg-soft);
1109
- border: 1px solid var(--border);
1232
+ text-decoration: underline;
1233
+ text-underline-offset: 3px;
1110
1234
  }
1111
1235
 
1112
1236
  .queue-jump:hover {
1113
1237
  color: var(--fg);
1114
- background: var(--bg-hover);
1115
1238
  }
1116
1239
 
1117
1240
  /* ---------- 回复里提到的文件:能点开预览(views/file-preview.js) ---------- */
@@ -201,18 +201,35 @@
201
201
  color: var(--fg-faint);
202
202
  }
203
203
 
204
- /* 手机:铺满宽度,贴着顶部 */
204
+ /* 手机:和工作目录选择器一样,从底部展开的固定高度抽屉 */
205
205
  @media (max-width: 768px) {
206
206
  .overlay.search-overlay {
207
- padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
207
+ align-items: flex-end;
208
+ padding: 0;
208
209
  }
209
210
 
210
211
  .search-modal {
211
- height: min(600px, calc(100dvh - env(safe-area-inset-top) - 24px));
212
- max-height: calc(100% - 8px);
212
+ max-width: none;
213
+ height: min(600px, 86dvh);
214
+ max-height: calc(100dvh - 32px);
215
+ padding-bottom: env(safe-area-inset-bottom);
216
+ border-radius: 16px 16px 0 0;
217
+ animation: search-sheet-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
213
218
  }
214
219
 
215
220
  .hit-meta {
216
221
  display: none;
217
222
  }
218
223
  }
224
+
225
+ @keyframes search-sheet-in {
226
+ from {
227
+ transform: translateY(100%);
228
+ }
229
+ }
230
+
231
+ @media (prefers-reduced-motion: reduce) {
232
+ .search-modal {
233
+ animation: none;
234
+ }
235
+ }
@@ -364,6 +364,7 @@ button.conv-group:hover {
364
364
  display: none;
365
365
  place-items: center;
366
366
  flex-shrink: 0;
367
+ margin-left: auto;
367
368
  width: 14px;
368
369
  height: 14px;
369
370
  font-size: 13px;
@@ -371,6 +372,30 @@ button.conv-group:hover {
371
372
  color: var(--fg-soft);
372
373
  }
373
374
 
375
+ /* 有状态点时由状态点推到右侧,专家图标紧随其后 */
376
+ .conv-item > .dot + .expert-mark,
377
+ .conv-item > .conv-spin + .expert-mark {
378
+ margin-left: 0;
379
+ }
380
+
381
+ .conv-item .task-mark {
382
+ flex-shrink: 0;
383
+ width: 14px;
384
+ height: 14px;
385
+ margin-left: auto;
386
+ color: var(--fg-soft);
387
+ }
388
+
389
+ .conv-item .task-mark svg {
390
+ width: 14px;
391
+ height: 14px;
392
+ }
393
+
394
+ .conv-item > .dot ~ .task-mark,
395
+ .conv-item > .conv-spin ~ .task-mark {
396
+ margin-left: 0;
397
+ }
398
+
374
399
  .conv-item .expert-mark-icon {
375
400
  display: inline-grid;
376
401
  place-items: center;
@@ -388,6 +413,10 @@ button.conv-group:hover {
388
413
  .conv-item:hover .expert-mark {
389
414
  display: inline-grid;
390
415
  }
416
+
417
+ .conv-item:hover .expert-mark + .task-mark {
418
+ margin-left: 0;
419
+ }
391
420
  }
392
421
 
393
422
  /* ---- 侧栏底部的额度 ---- */
@@ -10,7 +10,7 @@
10
10
  display: flex;
11
11
  align-items: center;
12
12
  gap: 6px;
13
- padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
13
+ padding: calc(8px + env(safe-area-inset-top)) 12px 8px 8px;
14
14
  min-height: 52px;
15
15
  /*
16
16
  * iOS 26+ 的主屏 PWA 会在页面顶端叠一层系统的模糊渐变(Liquid Glass 边缘效果),CSS 关不掉。
@@ -152,7 +152,7 @@
152
152
  min-width: 0;
153
153
  display: flex;
154
154
  align-items: center;
155
- gap: 6px;
155
+ gap: 2px;
156
156
  }
157
157
 
158
158
  /* 标题前的专家头像:点一下 / 鼠标停上去弹出专家信息卡 */
@@ -163,7 +163,6 @@
163
163
  width: 28px;
164
164
  height: 28px;
165
165
  padding: 0;
166
- margin-left: 2px;
167
166
  border-radius: 50%;
168
167
  line-height: 1;
169
168
  color: var(--fg-soft);
@@ -300,7 +299,7 @@
300
299
  overflow: hidden;
301
300
  text-overflow: ellipsis;
302
301
  white-space: nowrap;
303
- padding: 0 4px;
302
+ padding: 0 4px 0 0;
304
303
  }
305
304
 
306
305
  .pill {
@@ -136,7 +136,7 @@ function checkList(items, picked, empty) {
136
136
  function openEditor(data, e, reload, preset) {
137
137
  const src = e ?? preset ?? {};
138
138
  const name = h("input", { value: src.name ?? "", maxlength: "40", placeholder: "比如:证券观察员" });
139
- const avatar = avatarPicker(src, () => engine.value, !e);
139
+ const avatar = avatarPicker(src, !e);
140
140
  const desc = h("input", { value: src.description ?? "", maxlength: "500", placeholder: "一句话说它是干什么的(选专家时、当子智能体时都看这句)" });
141
141
  const engine = h(
142
142
  "select",
@@ -189,7 +189,6 @@ function openEditor(data, e, reload, preset) {
189
189
  subField.hidden = eng !== "claude";
190
190
  baseField.hidden = eng !== "claude";
191
191
  perms.setEngine(eng);
192
- avatar.refresh();
193
192
  void models.load(eng);
194
193
  };
195
194
  const sync = () => (cwdField.hidden = perms.access() === "web");
@@ -305,18 +304,18 @@ function permChecks(src) {
305
304
  const AVATAR_PX = 128;
306
305
 
307
306
  /**
308
- * 头像:点一下选图片,居中裁成正方形、缩到 128px 再上传。没传就用引擎的图标(以前设过 emoji 的还显示 emoji)。
307
+ * 头像:点一下选图片,居中裁成正方形、缩到 128px 再上传。没传时显示加号。
309
308
  * src.avatar 是已有头像的地址;isNew(复制一份)时把它读成 data URL 一起带上。
310
309
  * payload():没动过就不带 avatar(服务端沿用),去掉了带空字符串
311
310
  */
312
- function avatarPicker(src, engineOf, isNew) {
311
+ function avatarPicker(src, isNew) {
313
312
  let value; // undefined = 没动过;"" = 去掉;data URL = 新的
314
313
  let shown = src.avatar || "";
315
- const preview = h("button", { type: "button", class: "avatar-preview", title: "上传头像" });
314
+ const preview = h("button", { type: "button", class: "avatar-preview", title: "上传头像", "aria-label": "上传头像" });
316
315
  const file = h("input", { type: "file", accept: "image/*", hidden: true });
317
316
  const remove = h("button", { type: "button", class: "btn small" }, "去掉");
318
317
  const refresh = () => {
319
- fill(preview, shown ? h("img", { src: shown, alt: "" }) : !value && value !== "" && src.icon ? h("span", { class: "avatar-emoji" }, src.icon) : agentIcon(engineOf()));
318
+ fill(preview, shown ? h("img", { src: shown, alt: "", draggable: "false" }) : icon("plus"));
320
319
  remove.hidden = !shown;
321
320
  };
322
321
  preview.onclick = () => file.click();
@@ -347,9 +346,9 @@ function avatarPicker(src, engineOf, isNew) {
347
346
  })
348
347
  .catch(() => {});
349
348
  }
349
+ refresh();
350
350
  return {
351
- el: h("div", { class: "avatar-field" }, preview, h("div", { class: "avatar-btns" }, h("button", { type: "button", class: "btn small", onclick: () => file.click() }, "上传"), remove), file),
352
- refresh,
351
+ el: h("div", { class: "avatar-field" }, preview, remove, file),
353
352
  payload: () => (value === undefined ? {} : { avatar: value }),
354
353
  };
355
354
  }
@@ -95,7 +95,7 @@ export function renderInteraction(item) {
95
95
  "div",
96
96
  { class: "ix-buttons" },
97
97
  spec.allowSession
98
- ? h("button", { class: "btn accent", onclick: () => ixOp(ix.id, "decide", { decision: "allow-session" }) }, "本会话全部允许")
98
+ ? h("button", { class: "btn primary", onclick: () => ixOp(ix.id, "decide", { decision: "allow-session" }) }, "本会话全部允许")
99
99
  : null,
100
100
  h("button", { class: `btn${spec.allowSession ? "" : " accent"}`, onclick: () => ixOp(ix.id, "decide", { decision: "allow-once" }) }, "允许一次"),
101
101
  // 会落盘、对所有人生效的「总是允许」只给管理员
@@ -315,8 +315,18 @@ let bulk = false;
315
315
  export function addItem(item) {
316
316
  ui.msgInner.querySelector(".empty")?.remove();
317
317
  item.el = renderItem(item);
318
- ui.msgInner.append(item.el);
319
- S.items.push(item);
318
+ // 当前回复拆成多段或恢复排队消息时,回复和交互卡仍在后续排队输入之前。
319
+ const activeUser = S.items.findLastIndex((it) => it.type === "user" && !it.queued);
320
+ const queued = item.type === "ai" || item.type === "ix"
321
+ ? S.items.findIndex((it, i) => i > activeUser && it.type === "user" && it.queued)
322
+ : -1;
323
+ if (queued >= 0) {
324
+ S.items[queued].el.before(item.el);
325
+ S.items.splice(queued, 0, item);
326
+ } else {
327
+ ui.msgInner.append(item.el);
328
+ S.items.push(item);
329
+ }
320
330
  if (bulk) return item;
321
331
  if (item.type === "user") {
322
332
  clampLongUsers([item]);
@@ -507,14 +517,16 @@ function queueNote(item, state) {
507
517
  "div",
508
518
  { class: "queue-note" },
509
519
  h("span", { class: "shimmer" }, "排队中,等上一条回复完"),
510
- editButton(item, true),
511
520
  h("button", { class: "queue-jump", title: "停掉正在进行的回复,马上处理这条", onclick: () => void doAction("jump", item.id) }, "打断并发送"),
521
+ editButton(item, true),
512
522
  );
513
523
  }
514
524
 
515
525
  /** state:queued / dropped / null(轮到它了,去掉标记) */
516
526
  function setQueueState(item, state) {
517
527
  item.queued = state === "queued";
528
+ const actions = item.el.querySelector(".user-actions");
529
+ if (actions) actions.hidden = item.queued;
518
530
  const next = state ? queueNote(item, state) : null;
519
531
  if (item.queueEl && next) item.queueEl.replaceWith(next);
520
532
  else if (item.queueEl) item.queueEl.remove();
@@ -534,7 +546,7 @@ function renderItem(item) {
534
546
  renderUserFiles(item.files),
535
547
  item.text ? (item.bubble = h("div", { class: "msg-user" }, origin ? h("span", { class: "origin" }, origin) : null, item.text)) : null,
536
548
  (item.queueEl = item.queued ? queueNote(item, "queued") : null),
537
- h("div", { class: "user-actions" },
549
+ h("div", { class: "user-actions", hidden: item.queued },
538
550
  item.text ? h("button", { class: "icon-btn", title: "复制", onclick: () => copyText(item.text) }, icon("copy")) : null,
539
551
  editButton(item),
540
552
  ),
@@ -5,15 +5,23 @@ import { userScrolled } from "./messages.js";
5
5
  // ---------- 消息区右边的快速定位(像网页版 ChatGPT) ----------
6
6
  // 每条用户消息一道短横线,竖着排在滚动条旁边,正看到的那条高亮;平时淡淡的,滚动时清楚些。
7
7
  // 鼠标移上去展开成列表,显示每条消息的开头,点一下跳过去。用户消息少于 3 条时不显示。
8
- // 手机只在滚动和操作刻度时显示,停止后自动隐藏,点刻度直接跳转。
8
+ // 手机用短轨道定位:按住拖动预览问题,松手跳转;只在手动滚动和操作时显示。
9
9
 
10
10
  const MIN_USERS = 3;
11
+ const HIDE_DELAY = 1600;
12
+ const compact = matchMedia("(max-width: 768px), (hover: none)");
11
13
  let entries = [];
12
14
  let activeIdx = -1;
13
15
  let scheduled = false;
14
16
  let scrollRaf = 0;
15
17
  let scrollingTimer = 0;
16
18
  let builtFor = null;
19
+ let scrubbing = null;
20
+
21
+ compact.addEventListener("change", () => {
22
+ resetScrolling();
23
+ updateActive();
24
+ });
17
25
 
18
26
  export function createNav() {
19
27
  resetScrolling();
@@ -21,7 +29,17 @@ export function createNav() {
21
29
  entries = [];
22
30
  ui.navTicks = h("div", { class: "msg-nav-ticks" });
23
31
  ui.navPanel = h("div", { class: "msg-nav-panel" });
24
- ui.nav = h("nav", { class: "msg-nav", hidden: true, "aria-label": "消息快速定位", onpointerenter: revealActiveRow, onpointerdown: markScrolling }, ui.navTicks, ui.navPanel);
32
+ ui.navTrack = h("div", { class: "msg-nav-track", "aria-hidden": "true" });
33
+ ui.navRail = h("div", {
34
+ class: "msg-nav-rail", role: "slider", tabindex: "0", "aria-label": "拖动定位用户消息", "aria-orientation": "vertical", "aria-valuemin": "1",
35
+ onpointerdown: startScrubbing, onpointermove: moveScrubbing, onpointerup: finishScrubbing,
36
+ onpointercancel: cancelPointer, onlostpointercapture: cancelPointer, onkeydown: onRailKey,
37
+ onfocus: markScrolling, onblur: markScrolling,
38
+ }, ui.navTrack);
39
+ ui.navCount = h("span", { class: "msg-nav-count" });
40
+ ui.navSnippet = h("span", { class: "msg-nav-snippet" });
41
+ const preview = h("div", { class: "msg-nav-preview", "aria-hidden": "true" }, ui.navCount, ui.navSnippet);
42
+ ui.nav = h("nav", { class: "msg-nav", hidden: true, "aria-label": "消息快速定位", onpointerenter: revealActiveRow, onpointerdown: markScrolling }, ui.navTicks, ui.navPanel, ui.navRail, preview);
25
43
  ui.navTicks.addEventListener("scroll", () => {
26
44
  if (ui.nav.classList.contains("scrolling")) markScrolling();
27
45
  }, { passive: true });
@@ -50,6 +68,10 @@ function build() {
50
68
  if (!ui.nav) return;
51
69
  const users = S.view ? [] : S.items.filter((it) => it.type === "user" && it.el?.isConnected);
52
70
  if (builtFor !== S.current || users.length < MIN_USERS) resetScrolling();
71
+ else if (scrubbing) {
72
+ cancelScrubbing();
73
+ markScrolling();
74
+ }
53
75
  builtFor = S.current;
54
76
  ui.nav.hidden = users.length < MIN_USERS;
55
77
  activeIdx = -1;
@@ -57,18 +79,27 @@ function build() {
57
79
  entries = [];
58
80
  ui.navTicks.replaceChildren();
59
81
  ui.navPanel.replaceChildren();
82
+ ui.navTrack.replaceChildren();
60
83
  return;
61
84
  }
62
85
  entries = users.map((item, i) => {
63
86
  const label = snippet(item);
64
87
  return {
65
88
  item,
89
+ label,
66
90
  tick: h("button", { class: "msg-nav-tick", "aria-label": `第 ${i + 1} 条:${label}`, onclick: () => jump(item) }, h("i")),
67
91
  row: h("button", { class: "msg-nav-row", onclick: () => jump(item) }, label),
68
92
  };
69
93
  });
70
94
  ui.navTicks.replaceChildren(...entries.map((e) => e.tick));
71
95
  ui.navPanel.replaceChildren(...entries.map((e) => e.row));
96
+ const marks = Math.min(entries.length, 9);
97
+ ui.navRail.style.setProperty("--nav-rail-height", `${Math.min(156, 56 + (marks - 1) * 16)}px`);
98
+ ui.navTrack.replaceChildren(
99
+ ...Array.from({ length: marks }, (_, i) => h("i", { class: `msg-nav-mark${i % 2 === 0 ? " major" : ""}`, style: { top: `${i / (marks - 1) * 100}%` } })),
100
+ h("span", { class: "msg-nav-thumb" }),
101
+ );
102
+ ui.navRail.setAttribute("aria-valuemax", String(entries.length));
72
103
  updateActive();
73
104
  }
74
105
 
@@ -78,12 +109,13 @@ function covered() {
78
109
  }
79
110
 
80
111
  function jump(item) {
81
- if (!item.el?.isConnected) return;
112
+ if (!item?.el?.isConnected) return;
82
113
  userScrolled();
83
114
  ui.messages.scrollTo({ top: Math.max(0, item.el.offsetTop - covered() - 12), behavior: "smooth" });
84
115
  }
85
116
 
86
117
  function resetScrolling() {
118
+ cancelScrubbing();
87
119
  clearTimeout(scrollingTimer);
88
120
  cancelAnimationFrame(scrollRaf);
89
121
  scrollRaf = 0;
@@ -94,12 +126,17 @@ function markScrolling() {
94
126
  if (!entries.length) return;
95
127
  ui.nav.classList.add("scrolling");
96
128
  clearTimeout(scrollingTimer);
97
- scrollingTimer = setTimeout(() => ui.nav.classList.remove("scrolling"), 1200);
129
+ if (scrubbing) return;
130
+ scrollingTimer = setTimeout(() => {
131
+ if (compact.matches && document.activeElement === ui.navRail) return;
132
+ ui.nav.classList.remove("scrolling");
133
+ }, HIDE_DELAY);
98
134
  }
99
135
 
100
136
  function onScroll() {
101
137
  if (!entries.length) return;
102
- markScrolling();
138
+ // 自动跟随模型回复时不打扰阅读;手动滚动才唤出手机上的轨道。
139
+ if (!compact.matches || ui.follow === false) markScrolling();
103
140
  if (scrollRaf) return;
104
141
  scrollRaf = requestAnimationFrame(() => {
105
142
  scrollRaf = 0;
@@ -109,7 +146,7 @@ function onScroll() {
109
146
 
110
147
  /** 正看到的:顶部往下三分之一处以上、最后一条用户消息;已经滚到底就是最后一条 */
111
148
  function updateActive() {
112
- if (!entries.length) return;
149
+ if (!entries.length || scrubbing) return;
113
150
  const m = ui.messages;
114
151
  const line = m.scrollTop + covered() + m.clientHeight * 0.3;
115
152
  let idx = 0;
@@ -120,13 +157,80 @@ function updateActive() {
120
157
  else break;
121
158
  }
122
159
  }
160
+ selectEntry(idx);
161
+ }
162
+
163
+ function selectEntry(idx) {
164
+ const entry = entries[idx];
165
+ if (!entry) return;
166
+ ui.nav.style.setProperty("--nav-progress", String(idx / (entries.length - 1)));
167
+ ui.navRail.setAttribute("aria-valuenow", String(idx + 1));
168
+ ui.navRail.setAttribute("aria-valuetext", `第 ${idx + 1} 条,共 ${entries.length} 条:${entry.label}`);
169
+ ui.navCount.textContent = `${idx + 1} / ${entries.length}`;
170
+ ui.navSnippet.textContent = entry.label;
123
171
  if (idx === activeIdx) return;
124
172
  entries[activeIdx]?.tick.classList.remove("on");
125
173
  entries[activeIdx]?.row.classList.remove("on");
126
174
  activeIdx = idx;
127
175
  entries[idx].tick.classList.add("on");
128
176
  entries[idx].row.classList.add("on");
129
- keepVisible(ui.navTicks, entries[idx].tick);
177
+ if (!compact.matches) keepVisible(ui.navTicks, entries[idx].tick);
178
+ }
179
+
180
+ function scrubTo(clientY) {
181
+ const rect = ui.navTrack.getBoundingClientRect();
182
+ if (!rect.height) return;
183
+ const fraction = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
184
+ scrubbing.index = Math.round(fraction * (entries.length - 1));
185
+ selectEntry(scrubbing.index);
186
+ }
187
+
188
+ function startScrubbing(e) {
189
+ if (!compact.matches || !entries.length || e.button !== 0 || scrubbing) return;
190
+ e.preventDefault();
191
+ scrubbing = { pointerId: e.pointerId, index: activeIdx, key: S.current };
192
+ ui.navRail.setPointerCapture(e.pointerId);
193
+ ui.nav.classList.add("scrubbing");
194
+ markScrolling();
195
+ scrubTo(e.clientY);
196
+ }
197
+
198
+ function moveScrubbing(e) {
199
+ if (scrubbing?.pointerId !== e.pointerId) return;
200
+ scrubTo(e.clientY);
201
+ }
202
+
203
+ function finishScrubbing(e) {
204
+ if (scrubbing?.pointerId !== e.pointerId) return;
205
+ scrubTo(e.clientY);
206
+ const target = scrubbing;
207
+ cancelScrubbing();
208
+ if (target.key === S.current) jump(entries[target.index]?.item);
209
+ markScrolling();
210
+ }
211
+
212
+ function cancelScrubbing() {
213
+ const pointerId = scrubbing?.pointerId;
214
+ scrubbing = null;
215
+ ui.nav?.classList.remove("scrubbing");
216
+ if (pointerId !== undefined && ui.navRail?.hasPointerCapture(pointerId)) ui.navRail.releasePointerCapture(pointerId);
217
+ updateActive();
218
+ }
219
+
220
+ function cancelPointer(e) {
221
+ if (scrubbing?.pointerId !== e.pointerId) return;
222
+ cancelScrubbing();
223
+ markScrolling();
224
+ }
225
+
226
+ function onRailKey(e) {
227
+ const delta = { ArrowUp: -1, ArrowLeft: -1, ArrowDown: 1, ArrowRight: 1, PageUp: -5, PageDown: 5 }[e.key];
228
+ if (!entries.length || (delta === undefined && e.key !== "Home" && e.key !== "End")) return;
229
+ e.preventDefault();
230
+ const idx = e.key === "Home" ? 0 : e.key === "End" ? entries.length - 1 : Math.max(0, Math.min(entries.length - 1, activeIdx + delta));
231
+ selectEntry(idx);
232
+ jump(entries[idx].item);
233
+ markScrolling();
130
234
  }
131
235
 
132
236
  /** 横线太多、竖条装不下时它自己能滚:让高亮的那道留在看得见的地方(不用 scrollIntoView,免得把外层也带着滚) */
@@ -138,6 +242,7 @@ function keepVisible(box, el) {
138
242
 
139
243
  /** 展开列表时:列表滚到正看到的那条 */
140
244
  function revealActiveRow() {
245
+ if (compact.matches) return;
141
246
  const row = entries[activeIdx]?.row;
142
247
  if (row) ui.navPanel.scrollTop = Math.max(0, row.offsetTop - ui.navPanel.clientHeight / 2);
143
248
  }
@@ -475,12 +475,11 @@ export function renderSidebar() {
475
475
  onclick: () => open(c.key),
476
476
  },
477
477
  orphan ? h("span", { class: "brand-icon lead fork-mark", html: ICON.fork }) : null,
478
- // 定时任务的专用对话
479
- c.taskId ? h("span", { class: "brand-icon lead task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
480
478
  h("span", { class: "title" }, convTitle(c)),
481
- convExpertMark(c),
482
479
  fold ? caret(fold.folded, fold.toggle) : null,
483
480
  status(fold?.folded ? fold.keys : [c.key]),
481
+ convExpertMark(c),
482
+ c.taskId ? h("span", { class: "brand-icon task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
484
483
  );
485
484
 
486
485
  const nodes = [];
@@ -502,8 +501,8 @@ export function renderSidebar() {
502
501
  },
503
502
  h("span", { class: "brand-icon lead", title: "飞书", html: ICON.feishu }),
504
503
  h("span", { class: "title" }, bot.name),
505
- convExpertMark(latest),
506
504
  status(convs.map((c) => c.key)),
505
+ convExpertMark(latest),
507
506
  ),
508
507
  });
509
508
  }