agent-loft 0.2.77 → 0.2.78

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.77",
3
+ "version": "0.2.78",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -8,7 +8,7 @@ import { cleanCustomCommands } from "../../core/command-catalog.js";
8
8
  import { hub } from "../../core/hub.js";
9
9
  import { interactions } from "../../core/interactions.js";
10
10
  import { approve, listApproved, listPending, revoke } from "../../core/pairing.js";
11
- import { getConversation, listConversations, updateConversation } from "../../core/store.js";
11
+ import { agentBinding, getConversation, listConversations, touchConversation, updateConversation } from "../../core/store.js";
12
12
  import { addScheduled, clearScheduled, removeScheduled } from "../../core/scheduled.js";
13
13
  import { resolveUploadFile, saveBuffer, sniff, uploadKeyOf } from "../../core/uploads.js";
14
14
  import { mentions, replyFileType, resolveReplyFile } from "../../core/reply-files.js";
@@ -896,6 +896,19 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
896
896
  // 别人的会话:当它不存在
897
897
  if (!visible(conv)) throw new HttpError(404, "会话不存在");
898
898
 
899
+ if (sub === "continue" && method === "POST") {
900
+ const body = await readJsonBody<{ agent?: unknown; sessionId?: unknown }>(req);
901
+ const binding = agentBinding(conv);
902
+ // 页面上的提示可能已经过时,不能把「继续旧上下文」用到后来切换的会话上。
903
+ if (body.agent !== conv.agent || body.sessionId !== binding.sessionId || !(binding.sessionId || binding.forkFrom)) {
904
+ throw new HttpError(409, "会话已经变化,请重新打开后重试");
905
+ }
906
+ touchConversation(key);
907
+ hub.emitEvent(key, { type: "meta" });
908
+ sendJson(res, 200, hub.info(key));
909
+ return;
910
+ }
911
+
899
912
  if ((sub === "cancel-queued" || sub === "rewind") && method === "POST") {
900
913
  const body = await readJsonBody<{ id?: unknown; anchor?: unknown; sessionId?: unknown }>(req);
901
914
  const id = typeof body.id === "string" ? body.id : undefined;
package/src/core/hub.ts CHANGED
@@ -166,6 +166,8 @@ export type ConversationInfo = {
166
166
  usage?: UsageTotals;
167
167
  busy: boolean;
168
168
  activeAt: number;
169
+ /** 当前上下文已闲置过期;直接发消息会自动换新,打开历史本身不会续期。 */
170
+ idleExpired: boolean;
169
171
  createdAt: number;
170
172
  hidden?: boolean;
171
173
  /** 从哪条对话分叉出来的 */
@@ -618,6 +620,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
618
620
  })(),
619
621
  busy: this.isBusy(key),
620
622
  activeAt: conv.activeAt,
623
+ idleExpired: !!(binding.sessionId || binding.forkFrom) && isExpired(conv),
621
624
  createdAt: conv.createdAt,
622
625
  ...(conv.hidden ? { hidden: true } : {}),
623
626
  ...(conv.forkOf ? { forkOf: conv.forkOf } : {}),
@@ -186,6 +186,22 @@
186
186
  margin: 0;
187
187
  }
188
188
 
189
+ .idle-session-continue {
190
+ border: 0;
191
+ padding: 0;
192
+ background: none;
193
+ color: inherit;
194
+ font: inherit;
195
+ text-decoration: underline;
196
+ text-underline-offset: 3px;
197
+ cursor: pointer;
198
+ }
199
+
200
+ .idle-session-continue:disabled {
201
+ opacity: .5;
202
+ cursor: wait;
203
+ }
204
+
189
205
  .error-box {
190
206
  border: 1px solid var(--danger);
191
207
  color: var(--danger);
package/web/lib/ws.js CHANGED
@@ -5,7 +5,7 @@ import { showAuth } from "../views/auth.js";
5
5
  import { applyBootstrap, bootstrapQuery, renderSidebar, scheduleSidebar } from "../views/sidebar.js";
6
6
  import { scheduleQuota } from "../views/quota.js";
7
7
  import { renderTopbar } from "../views/topbar.js";
8
- import { applyEvent, openConversation } from "../views/messages.js";
8
+ import { applyEvent, openConversation, renderIdleNotice } from "../views/messages.js";
9
9
  import { upsertInteraction } from "../views/interaction.js";
10
10
  import { setBusy } from "../views/composer.js";
11
11
  import { SH, shownHere } from "./shell.js";
@@ -265,6 +265,7 @@ function onWsMessage(msg) {
265
265
  if (S.convs.get(msg.info.key)?.busy && !msg.info.busy) scheduleQuota();
266
266
  S.convs.set(msg.info.key, msg.info);
267
267
  if (msg.info.key === S.current) {
268
+ renderIdleNotice(msg.info);
268
269
  renderTopbar();
269
270
  setBusy(msg.info.busy);
270
271
  renderScheduled();
@@ -18,6 +18,42 @@ import { preloadCommands } from "./slash.js";
18
18
 
19
19
  // ---------- 打开会话 ----------
20
20
 
21
+ let historyLoadedKey = null;
22
+
23
+ /** 闲置提示只属于当前页面,不写进 Agent 历史;其他页面续期或发消息时同步撤下。 */
24
+ export function renderIdleNotice(info = S.convs.get(S.current)) {
25
+ if (!info || info.key !== S.current || historyLoadedKey !== S.current) return;
26
+ const existing = ui.msgInner.querySelector(".idle-session-notice");
27
+ if (!info.idleExpired) {
28
+ existing?.remove();
29
+ return;
30
+ }
31
+ if (existing) return;
32
+ const button = h("button", {
33
+ type: "button",
34
+ class: "idle-session-continue",
35
+ onclick: async () => {
36
+ button.disabled = true;
37
+ try {
38
+ const next = await api(`/api/conversations/${encodeURIComponent(info.key)}/continue`, {
39
+ method: "POST", body: { agent: info.agent, sessionId: info.sessionId },
40
+ });
41
+ S.convs.set(info.key, next);
42
+ renderIdleNotice(next);
43
+ renderSidebar();
44
+ toast("已继续当前会话");
45
+ } catch (err) {
46
+ toast(err.message);
47
+ } finally {
48
+ button.disabled = false;
49
+ }
50
+ },
51
+ }, "继续当前会话");
52
+ ui.msgInner.append(h("div", { class: "notice idle-session-notice" },
53
+ "当前会话闲置太久,直接发送消息将开启新会话,也可以", button,
54
+ ));
55
+ }
56
+
21
57
  /** 从定时任务页、远程控制回到对话:把输入框放回来 */
22
58
  function leaveTasksView() {
23
59
  if (!S.view) return;
@@ -32,6 +68,7 @@ export function latestConversation() {
32
68
  }
33
69
 
34
70
  export function newDraft({ inheritLatest = false } = {}) {
71
+ historyLoadedKey = null;
35
72
  if (inheritLatest) {
36
73
  const latest = latestConversation();
37
74
  if (latest) {
@@ -120,6 +157,7 @@ document.addEventListener("aim:experts", () => {
120
157
  });
121
158
 
122
159
  export async function openConversation(key) {
160
+ historyLoadedKey = null;
123
161
  leaveTasksView();
124
162
  const token = ++S.loadToken;
125
163
  if (S.current && S.current !== key) WS.raw({ t: "unsub", key: S.current });
@@ -208,6 +246,8 @@ export async function openConversation(key) {
208
246
  );
209
247
  }
210
248
  setBusy(data.info.busy);
249
+ historyLoadedKey = key;
250
+ renderIdleNotice(data.info);
211
251
  renderTopbar();
212
252
  WS.subscribe(key, S.seq.get(key));
213
253
  renderScheduled();
@@ -751,6 +791,7 @@ export function applyEvent(env) {
751
791
  }
752
792
  case "user": {
753
793
  // 排队的消息:正在进行的那一轮照常在上面接着输出,这条等轮到它(queue 事件)再挂占位
794
+ ui.msgInner.querySelector(".idle-session-notice")?.remove();
754
795
  const queued = !!ev.queued;
755
796
  if (!queued && S.turnAi && !S.turnAi.done && S.turnAi.steps.length === 0 && !S.turnAi.committed) {
756
797
  // 上一个占位还空着(比如消息被当成了作答),不再多留一个