agent-loft 0.2.53 → 0.2.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.53",
3
+ "version": "0.2.55",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -547,54 +547,50 @@ a.att-file:hover {
547
547
  color: var(--fg);
548
548
  }
549
549
 
550
- .ai-actions {
550
+ .ai-actions,
551
+ .user-actions {
551
552
  display: flex;
552
553
  gap: 4px;
553
554
  align-items: center;
554
- /* 只有最后一条回复默认显示,前面的 hover 时才出来;用 opacity 占着位置,免得 hover 时内容跳动 */
555
+ /* 两类消息预留相同高度,隐藏时也占位,展开操作栏不会改变消息间距。 */
556
+ min-height: 28px;
555
557
  opacity: 0;
558
+ pointer-events: none;
556
559
  transition: opacity 0.15s;
557
560
  }
558
561
 
559
- .msg-ai.latest .ai-actions,
560
- .msg-ai:hover .ai-actions,
561
- .ai-actions:focus-within {
562
+ .msg-ai.latest .ai-actions {
562
563
  opacity: 1;
564
+ pointer-events: auto;
563
565
  }
564
566
 
565
- /* 触屏没有 hover:都显示,否则前面的回复就没法复制 / 分叉了 */
566
- @media (hover: none) {
567
- .ai-actions {
567
+ @media (hover: hover) {
568
+ .msg-ai:hover .ai-actions,
569
+ .msg-user-group:hover .user-actions,
570
+ .ai-actions:focus-within,
571
+ .user-actions:focus-within {
568
572
  opacity: 1;
573
+ pointer-events: auto;
569
574
  }
570
575
  }
571
576
 
572
- /* 用户消息下面的复制:hover 时才出来,和回复的操作栏一样用 opacity 占着位置 */
573
- .user-actions {
574
- display: flex;
575
- margin-top: -4px;
576
- opacity: 0;
577
- transition: opacity 0.15s;
577
+ @media (hover: none) {
578
+ .msg-ai.actions-open .ai-actions,
579
+ .msg-user-group.actions-open .user-actions,
580
+ .ai-actions:has(:focus-visible),
581
+ .user-actions:has(:focus-visible) {
582
+ opacity: 1;
583
+ pointer-events: auto;
584
+ }
578
585
  }
579
586
 
580
587
  .user-actions[hidden] {
581
588
  display: none;
582
589
  }
583
590
 
584
- .msg-user-group:hover .user-actions,
585
- .user-actions:focus-within {
586
- opacity: 1;
587
- }
588
-
589
- @media (hover: none) {
590
- .user-actions {
591
- opacity: 1;
592
- }
593
- }
594
-
595
591
  .user-actions .icon-btn {
596
- width: 26px;
597
- height: 26px;
592
+ width: 28px;
593
+ height: 28px;
598
594
  }
599
595
 
600
596
  .user-actions .icon-btn svg {
@@ -306,17 +306,15 @@ const AVATAR_PX = 128;
306
306
  /**
307
307
  * 头像:点一下选图片,居中裁成正方形、缩到 128px 再上传。没传时显示加号。
308
308
  * src.avatar 是已有头像的地址;isNew(复制一份)时把它读成 data URL 一起带上。
309
- * payload():没动过就不带 avatar(服务端沿用),去掉了带空字符串
309
+ * payload():没动过就不带 avatar(服务端沿用),换了图片就带上新的 data URL
310
310
  */
311
311
  function avatarPicker(src, isNew) {
312
- let value; // undefined = 没动过;"" = 去掉;data URL = 新的
312
+ let value; // undefined = 没动过;data URL = 新的
313
313
  let shown = src.avatar || "";
314
314
  const preview = h("button", { type: "button", class: "avatar-preview", title: "上传头像", "aria-label": "上传头像" });
315
315
  const file = h("input", { type: "file", accept: "image/*", hidden: true });
316
- const remove = h("button", { type: "button", class: "btn small" }, "去掉");
317
316
  const refresh = () => {
318
317
  fill(preview, shown ? h("img", { src: shown, alt: "", draggable: "false" }) : icon("plus"));
319
- remove.hidden = !shown;
320
318
  };
321
319
  preview.onclick = () => file.click();
322
320
  file.onchange = async () => {
@@ -330,11 +328,6 @@ function avatarPicker(src, isNew) {
330
328
  toast(err.message);
331
329
  }
332
330
  };
333
- remove.onclick = () => {
334
- value = "";
335
- shown = "";
336
- refresh();
337
- };
338
331
  // 复制一份:头像也带过去(新专家还没有自己的头像地址)
339
332
  if (src.avatar && isNew) {
340
333
  void fetch(src.avatar)
@@ -348,7 +341,7 @@ function avatarPicker(src, isNew) {
348
341
  }
349
342
  refresh();
350
343
  return {
351
- el: h("div", { class: "avatar-field" }, preview, remove, file),
344
+ el: h("div", { class: "avatar-field" }, preview, file),
352
345
  payload: () => (value === undefined ? {} : { avatar: value }),
353
346
  };
354
347
  }
@@ -301,7 +301,7 @@ export async function sendMessage() {
301
301
  let key;
302
302
  let res;
303
303
  setSending(true);
304
- // 发出去之后恢复自动滚动;回显的那条用户消息到了就顶到最上面(见 applyEvent)
304
+ // 记录本页发送:普通消息回显后定位到顶部,排队消息等开始回复时再定位(见 applyEvent)。
305
305
  S.pinNext = true;
306
306
  try {
307
307
  key = await ensureConversation();
@@ -224,6 +224,7 @@ function historyQuestion(key, m) {
224
224
  // 留白靠消息列表后面的 ui.spacer 撑出来:高度 = 刚好够那条消息滚到顶,回复越长它越矮,到 0 为止。
225
225
  // - 回复过程中只要用户自己滚了(滚轮、触摸、拖滚动条、键盘翻页),就不再自动滚,直到下一次发消息。
226
226
  // ui.follow 记着现在要不要自动滚。
227
+ // - 排队消息不改变当前定位,也不计入自动跟随的底部;轮到它时再切换定位。
227
228
 
228
229
  function nearBottom(gap = 120) {
229
230
  const m = ui.messages;
@@ -233,11 +234,20 @@ function nearBottom(gap = 120) {
233
234
  /** 内容变了之后:重算留白,要跟随的话贴到底(有留白时「底」正好就是被顶上去的那条消息) */
234
235
  function afterLayout() {
235
236
  if (!ui.messages) return;
236
- fitSpacer();
237
- if (ui.follow && performance.now() > (ui.smoothUntil ?? 0)) ui.messages.scrollTop = ui.messages.scrollHeight;
237
+ const pinTop = fitSpacer();
238
+ if (ui.follow && performance.now() > (ui.smoothUntil ?? 0)) ui.messages.scrollTop = followScrollTop(pinTop);
238
239
  updateToBottomBtn();
239
240
  }
240
241
 
242
+ /** 排队消息在当前回复后面:自动滚动只跟随回复,队列再长也不把当前这一轮挤出视口。 */
243
+ function followScrollTop(pinTop) {
244
+ if (pinTop === undefined || !S.items.at(-1)?.queued) return ui.messages.scrollHeight;
245
+ const last = S.items.findLast((it) => !it.queued);
246
+ if (!last?.el?.isConnected) return ui.messages.scrollHeight;
247
+ const bottom = last.el.offsetTop + last.el.offsetHeight + parseFloat(getComputedStyle(ui.msgInner).paddingBottom);
248
+ return Math.max(pinTop, bottom - ui.messages.clientHeight);
249
+ }
250
+
241
251
  function fitSpacer() {
242
252
  const pin = ui.pinEl;
243
253
  if (!pin?.isConnected) {
@@ -250,6 +260,7 @@ function fitSpacer() {
250
260
  const top = Math.max(0, pin.offsetTop - covered - 12);
251
261
  const need = top + ui.messages.clientHeight - ui.msgInner.offsetHeight;
252
262
  ui.spacer.style.height = `${Math.max(0, Math.ceil(need))}px`;
263
+ return top;
253
264
  }
254
265
 
255
266
  /** 回到跟随模式并贴到底:打开会话、点「回到底部」时用 */
@@ -262,9 +273,9 @@ export function scrollToBottom() {
262
273
  function pinToTop(el) {
263
274
  ui.pinEl = el;
264
275
  ui.follow = true;
265
- fitSpacer();
276
+ const pinTop = fitSpacer();
266
277
  ui.smoothUntil = performance.now() + 450;
267
- ui.messages.scrollTo({ top: ui.messages.scrollHeight, behavior: "smooth" });
278
+ ui.messages.scrollTo({ top: followScrollTop(pinTop), behavior: "smooth" });
268
279
  // 平滑滚动期间留白可能又变了(比如输入框清空变矮),滚完再对齐一次
269
280
  setTimeout(afterLayout, 460);
270
281
  updateToBottomBtn();
@@ -290,13 +301,24 @@ export function bindScrollWatch() {
290
301
  if (["PageUp", "PageDown", "ArrowUp", "ArrowDown", "Home", "End", " "].includes(e.key)) userScrolled();
291
302
  });
292
303
  m.addEventListener("scroll", updateToBottomBtn, { passive: true });
304
+ // 触屏点消息才展开操作栏;点其它消息或空白处收起,链接、按钮和选中文字保持原来的行为。
305
+ document.addEventListener("click", (e) => {
306
+ if (!matchMedia("(hover: none)").matches) return;
307
+ const message = m.contains(e.target) ? e.target.closest(".msg-user-group, .msg-ai") : null;
308
+ if (message && (e.target.closest("button, a, input, textarea, select, summary, [role='button'], [contenteditable], .ai-actions, .user-actions") || window.getSelection()?.isCollapsed === false)) return;
309
+ const wasOpen = message?.classList.contains("actions-open");
310
+ for (const el of m.querySelectorAll(".actions-open")) el.classList.remove("actions-open");
311
+ if (!wasOpen && message && !message.classList.contains("latest") && message.querySelector(".ai-actions, .user-actions:not([hidden])")) {
312
+ message.classList.add("actions-open");
313
+ }
314
+ });
293
315
  // 消息区变高(发送后输入框清空变矮)、内容变高都要重算留白;窗口 resize 管不到元素自己变尺寸
294
316
  const ro = new ResizeObserver(() => afterLayout());
295
317
  ro.observe(m);
296
318
  ro.observe(ui.msgInner);
297
319
  }
298
320
 
299
- /** 只有最后一条回复默认显示底部的操作栏(复制 / 分叉 / 用时…),前面的 hover 才出来 */
321
+ /** 只有最后一条回复默认显示底部操作栏,前面的在桌面 hover、触屏点击时显示 */
300
322
  function markLatestAi() {
301
323
  let latest = null;
302
324
  for (let i = S.items.length - 1; i >= 0; i--) {
@@ -724,10 +746,11 @@ export function applyEvent(env) {
724
746
  }
725
747
  if (!queued && (!S.turnAi || S.turnAi.done)) turnStartAt = env.ts;
726
748
  const it = addItem({ type: "user", text: ev.text, files: ev.files ?? ev.attachments, origin: ev.origin, id: ev.id, queued });
727
- // 这个页面刚发的:顶到最上面
749
+ // 这个页面刚发的:普通消息顶到最上面,排队消息等轮到它时再定位。
728
750
  if (S.pinNext && ev.origin?.channel === "web") {
729
751
  S.pinNext = false;
730
- pinToTop(it.el);
752
+ if (queued) it.pinOnStart = true;
753
+ else pinToTop(it.el);
731
754
  }
732
755
  if (!queued) currentAi(env.ts);
733
756
  return;
@@ -749,6 +772,10 @@ export function applyEvent(env) {
749
772
  return;
750
773
  }
751
774
  if (it) setQueueState(it, ev.state === "dropped" ? "dropped" : null);
775
+ if (it?.pinOnStart && ev.state === "started") {
776
+ it.pinOnStart = false;
777
+ if (ui.follow) pinToTop(it.el);
778
+ }
752
779
  // 轮到它了(上一轮刚出结果):挂上「思考中」占位,用时从现在算。被当成提问的回答时那一轮还在跑,不用挂
753
780
  if (ev.state === "started" && (!S.turnAi || S.turnAi.done)) {
754
781
  turnStartAt = env.ts;