dsh-planbox-dyb 0.8.1 → 0.8.2
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 +5 -3
- package/client.js +58 -21
- package/index.js +142 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,14 +22,16 @@ dsh plugin --profile web add dsh-planbox-dyb
|
|
|
22
22
|
|
|
23
23
|
## 面板
|
|
24
24
|
|
|
25
|
-
-
|
|
25
|
+
- **已登记**:你点「加入计划任务」手动登记的任务。
|
|
26
26
|
- **异常中断**:上一回合报错或崩溃中断的会话。
|
|
27
|
-
-
|
|
27
|
+
- **扫描到**:模型登记或从会话消息里扫到的任务。
|
|
28
|
+
|
|
29
|
+
每行会标注对应的「第 N 轮」对话;同会话的手动登记和自动结果分开显示。
|
|
28
30
|
|
|
29
31
|
按钮:
|
|
30
32
|
|
|
31
33
|
- **建议**:把续跑建议填进输入框,不发送;输入框已有内容会先确认是否从下一行追加。
|
|
32
|
-
-
|
|
34
|
+
- **查看**:跳到对应会话,不关闭面板,并把该任务置顶;会提示打开的是第几轮对话。
|
|
33
35
|
- **忽略**:删除这一条;扫描/异常项会隐藏到该会话下次更新。
|
|
34
36
|
- **全部忽略**:确认后清空当前列表。
|
|
35
37
|
- **恢复中断**:只处理「异常中断」,每项发一句「继续」;发送成功后记录删除,不跟踪后续进度。
|
package/client.js
CHANGED
|
@@ -15,7 +15,7 @@ window.__ModuleLoader__.load({
|
|
|
15
15
|
const NS = "planbox";
|
|
16
16
|
const API = "/api/planbox";
|
|
17
17
|
const POLL_MS = 60_000;
|
|
18
|
-
const CLIENT_VERSION = "0.8.
|
|
18
|
+
const CLIENT_VERSION = "0.8.2";
|
|
19
19
|
|
|
20
20
|
const FALLBACK = {
|
|
21
21
|
open: "计划任务",
|
|
@@ -32,6 +32,10 @@ window.__ModuleLoader__.load({
|
|
|
32
32
|
pinnedSection: "正在查看",
|
|
33
33
|
scannedSection: "扫描到({n})",
|
|
34
34
|
running: "运行中",
|
|
35
|
+
anchorTurn: "第 {turn} 轮",
|
|
36
|
+
anchorTurnSeq: "第 {turn} 轮 · #{seq}",
|
|
37
|
+
anchorSeq: "消息 #{seq}",
|
|
38
|
+
viewAnchor: "已打开:{label}",
|
|
35
39
|
resume: "继续",
|
|
36
40
|
view: "查看",
|
|
37
41
|
resumeAll: "恢复中断",
|
|
@@ -84,6 +88,10 @@ window.__ModuleLoader__.load({
|
|
|
84
88
|
pinnedSection: "Viewing",
|
|
85
89
|
scannedSection: "Scanned ({n})",
|
|
86
90
|
running: "Running",
|
|
91
|
+
anchorTurn: "Turn {turn}",
|
|
92
|
+
anchorTurnSeq: "Turn {turn} · #{seq}",
|
|
93
|
+
anchorSeq: "Message #{seq}",
|
|
94
|
+
viewAnchor: "Opened: {label}",
|
|
87
95
|
resume: "Resume",
|
|
88
96
|
view: "View",
|
|
89
97
|
resumeAll: "Restore interrupted",
|
|
@@ -255,6 +263,7 @@ window.__ModuleLoader__.load({
|
|
|
255
263
|
".dpb-next{font-size:11px;line-height:16px;color:#9dbcff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
|
|
256
264
|
".dpb-snippet{font-size:11.5px;line-height:17px;color:var(--dsw-alias-label-secondary,#b6bac0);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere}",
|
|
257
265
|
".dpb-meta{display:flex;align-items:center;gap:5px;font-size:10.5px;line-height:15px;color:var(--dsw-alias-label-tertiary,#8b8f95);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
|
|
266
|
+
".dpb-anchor{flex:none;color:var(--dsw-alias-state-business-primary,#4c8dff)}",
|
|
258
267
|
".dpb-dot{opacity:.6}",
|
|
259
268
|
".dpb-row-actions{flex:none;display:flex;align-items:center;gap:2px}",
|
|
260
269
|
".dpb-mini{padding:0 7px;height:24px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);font:inherit;font-size:11px;cursor:pointer}",
|
|
@@ -360,14 +369,31 @@ window.__ModuleLoader__.load({
|
|
|
360
369
|
};
|
|
361
370
|
}
|
|
362
371
|
|
|
372
|
+
/** 任务对应的最近一次对话:第 N 轮 / 消息 #seq。 */
|
|
373
|
+
function anchorText(t, item) {
|
|
374
|
+
const anchor = item?.anchor;
|
|
375
|
+
if (anchor === null || anchor === undefined) return "";
|
|
376
|
+
if (anchor.turn > 0 && anchor.seq > 0) {
|
|
377
|
+
return t("anchorTurnSeq", { turn: anchor.turn, seq: anchor.seq });
|
|
378
|
+
}
|
|
379
|
+
if (anchor.turn > 0) return t("anchorTurn", { turn: anchor.turn });
|
|
380
|
+
if (anchor.seq > 0) return t("anchorSeq", { seq: anchor.seq });
|
|
381
|
+
return "";
|
|
382
|
+
}
|
|
383
|
+
|
|
363
384
|
function Row(props) {
|
|
364
385
|
const { item, t, busy, pinned, onOpen, onDismiss, onSuggest } = props;
|
|
365
386
|
const queue = item.source === "queue";
|
|
366
387
|
const tag = tagFor(item);
|
|
367
388
|
const detail = queue ? item.snippet || item.prompt : item.snippet;
|
|
368
389
|
const full = queue ? item.prompt : item.snippet;
|
|
390
|
+
const anchor = anchorText(t, item);
|
|
391
|
+
const anchorTitle =
|
|
392
|
+
anchor === "" || !item.anchor?.at
|
|
393
|
+
? anchor
|
|
394
|
+
: `${anchor} · ${new Date(item.anchor.at).toLocaleString()}`;
|
|
369
395
|
// 整行可点:和「查看」同一条路径(跳转 + 置顶),行内按钮自己 stopPropagation。
|
|
370
|
-
const open = () => onOpen(item.sessionId, item.id);
|
|
396
|
+
const open = () => onOpen(item.sessionId, item.id, item.anchor);
|
|
371
397
|
const next = nextStep(item);
|
|
372
398
|
return h(
|
|
373
399
|
"div",
|
|
@@ -400,6 +426,9 @@ window.__ModuleLoader__.load({
|
|
|
400
426
|
h(
|
|
401
427
|
"div",
|
|
402
428
|
{ className: "dpb-meta" },
|
|
429
|
+
anchor !== ""
|
|
430
|
+
? h("span", { className: "dpb-anchor", title: anchorTitle }, anchor)
|
|
431
|
+
: null,
|
|
403
432
|
h("span", null, ago(t, item.updatedAt)),
|
|
404
433
|
item.running ? h("span", { className: "dpb-dot" }, "·") : null,
|
|
405
434
|
item.running ? h("span", null, t("running")) : null,
|
|
@@ -432,7 +461,7 @@ window.__ModuleLoader__.load({
|
|
|
432
461
|
"aria-label": t("view"),
|
|
433
462
|
onClick: (event) => {
|
|
434
463
|
event.stopPropagation();
|
|
435
|
-
onOpen(item.sessionId, item.id);
|
|
464
|
+
onOpen(item.sessionId, item.id, item.anchor);
|
|
436
465
|
},
|
|
437
466
|
},
|
|
438
467
|
t("view"),
|
|
@@ -840,27 +869,34 @@ window.__ModuleLoader__.load({
|
|
|
840
869
|
[busy, items, t],
|
|
841
870
|
);
|
|
842
871
|
|
|
843
|
-
const openSession = React.useCallback(
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
if (workspace !== null && typeof workspace.openSession === "function") {
|
|
872
|
+
const openSession = React.useCallback(
|
|
873
|
+
(sessionId, itemId, anchor) => {
|
|
874
|
+
// 会话切换可能让组件重挂载,先把“面板开着 + 看的是哪条”同步写进模块状态。
|
|
875
|
+
panelState.open = true;
|
|
876
|
+
panelState.pinnedId = itemId ?? null;
|
|
877
|
+
setPinnedId(itemId ?? null);
|
|
878
|
+
const label = anchorText(t, { anchor });
|
|
879
|
+
if (label !== "") {
|
|
880
|
+
setFillNotice({ bad: false, text: t("viewAnchor", { label }) });
|
|
881
|
+
}
|
|
882
|
+
let workspace = null;
|
|
855
883
|
try {
|
|
856
|
-
workspace
|
|
857
|
-
return;
|
|
884
|
+
workspace = pluginCtx?.get?.("uiWorkspace") ?? null;
|
|
858
885
|
} catch (cause) {
|
|
859
|
-
|
|
886
|
+
workspace = null;
|
|
860
887
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
888
|
+
if (workspace !== null && typeof workspace.openSession === "function") {
|
|
889
|
+
try {
|
|
890
|
+
workspace.openSession(sessionId);
|
|
891
|
+
return;
|
|
892
|
+
} catch (cause) {
|
|
893
|
+
/* 回退到 URL 跳转 */
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
window.location.assign(`/?session=${encodeURIComponent(sessionId)}`);
|
|
897
|
+
},
|
|
898
|
+
[t],
|
|
899
|
+
);
|
|
864
900
|
|
|
865
901
|
const copySuggestion = React.useCallback(
|
|
866
902
|
async (text) => {
|
|
@@ -1187,6 +1223,7 @@ window.__ModuleLoader__.load({
|
|
|
1187
1223
|
orderPending,
|
|
1188
1224
|
tagFor,
|
|
1189
1225
|
restorableItems,
|
|
1226
|
+
anchorText,
|
|
1190
1227
|
nextStep,
|
|
1191
1228
|
},
|
|
1192
1229
|
};
|
package/index.js
CHANGED
|
@@ -193,6 +193,68 @@ export function tailTurnState(records) {
|
|
|
193
193
|
return result;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
/**
|
|
197
|
+
* 取任务对应的“最近一次对话”锚点:优先最后一条真实用户消息,退化为最近回合。
|
|
198
|
+
* 用于面板显示和「查看」时说明是哪一轮对话。
|
|
199
|
+
* @param {readonly unknown[]} records - sessionController.events() 返回的记录。
|
|
200
|
+
* @returns {{ turn: number, seq: number, at: number, messageId: string, kind: string } | null} 锚点。
|
|
201
|
+
*/
|
|
202
|
+
export function anchorOf(records) {
|
|
203
|
+
if (!Array.isArray(records)) return null;
|
|
204
|
+
let user = null;
|
|
205
|
+
let turn = null;
|
|
206
|
+
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
207
|
+
const record = records[index];
|
|
208
|
+
const event = record && typeof record === 'object' && record.type === 'event' ? record.event : null;
|
|
209
|
+
if (!event) continue;
|
|
210
|
+
const seq = Number(event.seq ?? record.seq ?? 0) || 0;
|
|
211
|
+
const at = Number(event.time ?? record.time ?? 0) || 0;
|
|
212
|
+
if (
|
|
213
|
+
user === null &&
|
|
214
|
+
event.type === 'user/message' &&
|
|
215
|
+
!isInjectedSource(event.data?.source)
|
|
216
|
+
) {
|
|
217
|
+
user = {
|
|
218
|
+
seq,
|
|
219
|
+
at,
|
|
220
|
+
messageId: typeof event.data?.id === 'string' ? event.data.id : '',
|
|
221
|
+
kind: 'user',
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (
|
|
225
|
+
turn === null &&
|
|
226
|
+
(event.type === 'turn/start' || event.type === 'turn/end')
|
|
227
|
+
) {
|
|
228
|
+
turn = {
|
|
229
|
+
turn: Number(event.data?.turn ?? 0) || 0,
|
|
230
|
+
seq,
|
|
231
|
+
at,
|
|
232
|
+
kind: 'turn',
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
if (user !== null && turn !== null) break;
|
|
236
|
+
}
|
|
237
|
+
const chosen = user ?? turn;
|
|
238
|
+
if (chosen === null) return null;
|
|
239
|
+
return {
|
|
240
|
+
turn: turn?.turn ?? 0,
|
|
241
|
+
seq: chosen.seq,
|
|
242
|
+
at: chosen.at,
|
|
243
|
+
messageId: user?.messageId ?? '',
|
|
244
|
+
kind: chosen.kind,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function normalizeAnchor(value) {
|
|
249
|
+
if (value === null || typeof value !== 'object') return null;
|
|
250
|
+
const turn = Number(value.turn ?? 0) || 0;
|
|
251
|
+
const seq = Number(value.seq ?? 0) || 0;
|
|
252
|
+
const at = Number(value.at ?? 0) || 0;
|
|
253
|
+
const messageId = typeof value.messageId === 'string' ? value.messageId : '';
|
|
254
|
+
if (turn === 0 && seq === 0 && at === 0) return null;
|
|
255
|
+
return { turn, seq, at, messageId, kind: value.kind === 'turn' ? 'turn' : 'user' };
|
|
256
|
+
}
|
|
257
|
+
|
|
196
258
|
/** 是否是异常中断(错误、崩溃补记,或未正常收尾的回合)。 */
|
|
197
259
|
function isAbnormalTurn(turn) {
|
|
198
260
|
return turn.open || turn.kind === 'error' || turn.kind === 'interrupted';
|
|
@@ -276,9 +338,12 @@ export function createStore(options = {}) {
|
|
|
276
338
|
);
|
|
277
339
|
},
|
|
278
340
|
|
|
279
|
-
/**
|
|
341
|
+
/** 新增(同一会话、同一来源类别只保留最新一条;手动与自动分开)。 */
|
|
280
342
|
add(entry) {
|
|
281
|
-
const
|
|
343
|
+
const automatic = entry.origin === 'model';
|
|
344
|
+
const items = store.queue().filter(
|
|
345
|
+
(item) => !(item.sessionId === entry.sessionId && (item.origin === 'model') === automatic),
|
|
346
|
+
);
|
|
282
347
|
items.unshift(entry);
|
|
283
348
|
writeJsonAtomic(queueFile, { version: 1, items });
|
|
284
349
|
return entry;
|
|
@@ -402,6 +467,7 @@ function queueItems(store) {
|
|
|
402
467
|
origin: entry.origin === 'model' ? 'model' : 'manual',
|
|
403
468
|
note: typeof entry.note === 'string' ? entry.note : '',
|
|
404
469
|
snapshot: entry.snapshot && typeof entry.snapshot === 'object' ? entry.snapshot : null,
|
|
470
|
+
anchor: normalizeAnchor(entry.anchor),
|
|
405
471
|
updatedAt: Number(entry.createdAt ?? Date.now()),
|
|
406
472
|
};
|
|
407
473
|
})
|
|
@@ -433,12 +499,14 @@ async function queueItemsWithDetails(ctx, store, options = {}) {
|
|
|
433
499
|
const detailed = [];
|
|
434
500
|
for (const item of base) {
|
|
435
501
|
let assistantText = '';
|
|
502
|
+
let records = null;
|
|
436
503
|
try {
|
|
437
504
|
const page = await ctx.sessionController.events(
|
|
438
505
|
{ address: { kind: 'session', sessionId: item.sessionId }, maxMessages: 30 },
|
|
439
506
|
controller,
|
|
440
507
|
);
|
|
441
|
-
|
|
508
|
+
records = page?.records;
|
|
509
|
+
assistantText = tailMessages(records).lastAssistantText;
|
|
442
510
|
} catch {
|
|
443
511
|
/* 读不到就用续跑说明兜底 */
|
|
444
512
|
}
|
|
@@ -448,6 +516,7 @@ async function queueItemsWithDetails(ctx, store, options = {}) {
|
|
|
448
516
|
title: summary ? summaryTitle(summary) : item.title,
|
|
449
517
|
snippet: tailOf(assistantText !== '' ? assistantText : item.prompt),
|
|
450
518
|
detailSource: assistantText !== '' ? 'assistant' : 'prompt',
|
|
519
|
+
anchor: item.anchor ?? normalizeAnchor(anchorOf(records)),
|
|
451
520
|
});
|
|
452
521
|
}
|
|
453
522
|
return detailed;
|
|
@@ -494,6 +563,7 @@ function detectCandidate(summary, tail, turn, options) {
|
|
|
494
563
|
title: summaryTitle(summary),
|
|
495
564
|
snippet: tailOf(detail),
|
|
496
565
|
prompt: '',
|
|
566
|
+
anchor: normalizeAnchor(options.anchor),
|
|
497
567
|
updatedAt: Number(summary.updatedAt ?? options.now),
|
|
498
568
|
running: false,
|
|
499
569
|
cwd: typeof summary.cwd === 'string' ? summary.cwd : undefined,
|
|
@@ -510,6 +580,7 @@ function detectCandidate(summary, tail, turn, options) {
|
|
|
510
580
|
title: summaryTitle(summary),
|
|
511
581
|
snippet: snippetAround(realUserText, MARKER_PATTERNS),
|
|
512
582
|
prompt: '',
|
|
583
|
+
anchor: normalizeAnchor(options.anchor),
|
|
513
584
|
updatedAt: Number(summary.updatedAt ?? options.now),
|
|
514
585
|
running: summary.running === true,
|
|
515
586
|
cwd: typeof summary.cwd === 'string' ? summary.cwd : undefined,
|
|
@@ -560,13 +631,15 @@ export async function scanCandidates(ctx, store, options = {}) {
|
|
|
560
631
|
{ address: { kind: 'session', sessionId: summary.sessionId }, maxMessages: 80 },
|
|
561
632
|
controller,
|
|
562
633
|
);
|
|
634
|
+
const records = page?.records;
|
|
563
635
|
settled[index] = detectCandidate(
|
|
564
636
|
summary,
|
|
565
|
-
tailMessages(
|
|
566
|
-
tailTurnState(
|
|
637
|
+
tailMessages(records),
|
|
638
|
+
tailTurnState(records),
|
|
567
639
|
{
|
|
568
640
|
dismissed,
|
|
569
641
|
now,
|
|
642
|
+
anchor: anchorOf(records),
|
|
570
643
|
abnormalWindowMs: options.abnormalWindowMs ?? abnormalWindowMs(),
|
|
571
644
|
},
|
|
572
645
|
);
|
|
@@ -600,7 +673,10 @@ export async function collectPending(ctx, store, options = {}) {
|
|
|
600
673
|
const queue = await queueItemsWithDetails(ctx, store, options);
|
|
601
674
|
|
|
602
675
|
const scanned = await scanCandidates(ctx, store, options);
|
|
603
|
-
|
|
676
|
+
// 只有自动登记项会吞掉同会话的扫描结果;手动登记与自动结果要分开显示。
|
|
677
|
+
const known = new Set(
|
|
678
|
+
queue.filter((item) => item.origin === 'model').map((item) => item.sessionId),
|
|
679
|
+
);
|
|
604
680
|
const extra = scanned.items
|
|
605
681
|
.filter((item) => !known.has(item.sessionId))
|
|
606
682
|
.sort((left, right) => right.updatedAt - left.updatedAt);
|
|
@@ -665,9 +741,11 @@ async function itemsForIds(ctx, store, ids, options = {}) {
|
|
|
665
741
|
{ address: { kind: 'session', sessionId: summary.sessionId }, maxMessages: 80 },
|
|
666
742
|
controller,
|
|
667
743
|
);
|
|
668
|
-
const
|
|
744
|
+
const records = page?.records;
|
|
745
|
+
const item = detectCandidate(summary, tailMessages(records), tailTurnState(records), {
|
|
669
746
|
dismissed,
|
|
670
747
|
now: Date.now(),
|
|
748
|
+
anchor: anchorOf(records),
|
|
671
749
|
});
|
|
672
750
|
if (item !== null) selected.push(item);
|
|
673
751
|
} catch {
|
|
@@ -876,7 +954,7 @@ export async function resumeSelected(ctx, store, options = {}) {
|
|
|
876
954
|
* 登记一条待续任务。
|
|
877
955
|
* @param {object} ctx - 宿主上下文。
|
|
878
956
|
* @param {ReturnType<typeof createStore>} store - 持久存储。
|
|
879
|
-
* @param {{ sessionId: string, title: string, prompt?: string, note?: string }} input - 登记内容。
|
|
957
|
+
* @param {{ sessionId: string, title: string, prompt?: string, note?: string, anchor?: object }} input - 登记内容。
|
|
880
958
|
* @returns {object} 新登记项。
|
|
881
959
|
*/
|
|
882
960
|
export function deferTask(store, input) {
|
|
@@ -892,6 +970,7 @@ export function deferTask(store, input) {
|
|
|
892
970
|
note: String(input.note ?? '').trim(),
|
|
893
971
|
origin: input.origin === 'model' ? 'model' : 'manual',
|
|
894
972
|
snapshot: normalizeSnapshot(input),
|
|
973
|
+
anchor: normalizeAnchor(input.anchor),
|
|
895
974
|
createdAt: Date.now(),
|
|
896
975
|
};
|
|
897
976
|
return store.add(entry);
|
|
@@ -913,30 +992,30 @@ export async function deferFromSession(ctx, store, sessionId, overrides = {}, op
|
|
|
913
992
|
|
|
914
993
|
let title = String(overrides.title ?? '').trim();
|
|
915
994
|
let prompt = String(overrides.prompt ?? '').trim();
|
|
995
|
+
let anchor = null;
|
|
916
996
|
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
/* 标题拿不到就用兜底 */
|
|
926
|
-
}
|
|
997
|
+
const controller = withTimeout(options.signal, 8_000);
|
|
998
|
+
if (title === '') {
|
|
999
|
+
try {
|
|
1000
|
+
const listed = await ctx.sessionController.list({}, controller);
|
|
1001
|
+
const summary = (listed?.items ?? []).find((item) => item?.sessionId === target);
|
|
1002
|
+
if (summary) title = summaryTitle(summary);
|
|
1003
|
+
} catch {
|
|
1004
|
+
/* 标题拿不到就用兜底 */
|
|
927
1005
|
}
|
|
1006
|
+
}
|
|
1007
|
+
try {
|
|
1008
|
+
const page = await ctx.sessionController.events(
|
|
1009
|
+
{ address: { kind: 'session', sessionId: target }, maxMessages: 30 },
|
|
1010
|
+
controller,
|
|
1011
|
+
);
|
|
1012
|
+
anchor = anchorOf(page?.records);
|
|
928
1013
|
if (prompt === '') {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
{ address: { kind: 'session', sessionId: target }, maxMessages: 20 },
|
|
932
|
-
controller,
|
|
933
|
-
);
|
|
934
|
-
const lastUser = tailMessages(page?.records).lastRealUserText;
|
|
935
|
-
if (lastUser !== '') prompt = lastUser.slice(0, 200);
|
|
936
|
-
} catch {
|
|
937
|
-
/* 拿不到就用兜底 */
|
|
938
|
-
}
|
|
1014
|
+
const lastUser = tailMessages(page?.records).lastRealUserText;
|
|
1015
|
+
if (lastUser !== '') prompt = lastUser.slice(0, 200);
|
|
939
1016
|
}
|
|
1017
|
+
} catch {
|
|
1018
|
+
/* 读不到就用兜底 */
|
|
940
1019
|
}
|
|
941
1020
|
|
|
942
1021
|
return deferTask(store, {
|
|
@@ -945,6 +1024,7 @@ export async function deferFromSession(ctx, store, sessionId, overrides = {}, op
|
|
|
945
1024
|
prompt: prompt === '' ? '继续完成此前未完成的任务。' : prompt,
|
|
946
1025
|
note: overrides.note,
|
|
947
1026
|
origin: overrides.origin,
|
|
1027
|
+
anchor,
|
|
948
1028
|
});
|
|
949
1029
|
}
|
|
950
1030
|
|
|
@@ -1157,8 +1237,21 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1157
1237
|
},
|
|
1158
1238
|
},
|
|
1159
1239
|
async execute(args, exec) {
|
|
1240
|
+
const sessionId = sessionIdOf(exec);
|
|
1241
|
+
let anchor = null;
|
|
1242
|
+
if (sessionId !== '') {
|
|
1243
|
+
try {
|
|
1244
|
+
const page = await ctx.sessionController.events(
|
|
1245
|
+
{ address: { kind: 'session', sessionId }, maxMessages: 30 },
|
|
1246
|
+
withTimeout(undefined, 8_000),
|
|
1247
|
+
);
|
|
1248
|
+
anchor = anchorOf(page?.records);
|
|
1249
|
+
} catch {
|
|
1250
|
+
/* 读不到就不带锚点 */
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1160
1253
|
const entry = deferTask(store, {
|
|
1161
|
-
sessionId
|
|
1254
|
+
sessionId,
|
|
1162
1255
|
title: args?.title,
|
|
1163
1256
|
prompt: args?.prompt,
|
|
1164
1257
|
nextSteps: args?.nextSteps,
|
|
@@ -1167,6 +1260,7 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1167
1260
|
lastFailedCommand: args?.lastFailedCommand,
|
|
1168
1261
|
note: args?.note,
|
|
1169
1262
|
origin: 'model',
|
|
1263
|
+
anchor,
|
|
1170
1264
|
});
|
|
1171
1265
|
return { ok: true, id: entry.id, title: entry.title, pending: store.queue().length };
|
|
1172
1266
|
},
|
|
@@ -1193,6 +1287,17 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1193
1287
|
origin: { type: 'string' },
|
|
1194
1288
|
sessionId: { type: 'string' },
|
|
1195
1289
|
title: { type: 'string' },
|
|
1290
|
+
anchor: {
|
|
1291
|
+
type: 'object',
|
|
1292
|
+
additionalProperties: false,
|
|
1293
|
+
properties: {
|
|
1294
|
+
turn: { type: 'integer' },
|
|
1295
|
+
seq: { type: 'integer' },
|
|
1296
|
+
at: { type: 'integer' },
|
|
1297
|
+
messageId: { type: 'string' },
|
|
1298
|
+
kind: { type: 'string' },
|
|
1299
|
+
},
|
|
1300
|
+
},
|
|
1196
1301
|
snapshot: {
|
|
1197
1302
|
type: 'object',
|
|
1198
1303
|
additionalProperties: false,
|
|
@@ -1224,7 +1329,13 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1224
1329
|
? '已登记'
|
|
1225
1330
|
: '扫描到';
|
|
1226
1331
|
const detail = item.snippet ? `\n ${item.snippet}` : '';
|
|
1227
|
-
|
|
1332
|
+
const anchor =
|
|
1333
|
+
item.anchor?.turn > 0
|
|
1334
|
+
? ` · 第 ${item.anchor.turn} 轮`
|
|
1335
|
+
: item.anchor?.seq > 0
|
|
1336
|
+
? ` · 消息 #${item.anchor.seq}`
|
|
1337
|
+
: '';
|
|
1338
|
+
return `- [${tag}] ${item.title}(${item.sessionId})${anchor}${detail}`;
|
|
1228
1339
|
};
|
|
1229
1340
|
const registered = value.items.filter(
|
|
1230
1341
|
(item) => item.source === 'queue' && item.origin !== 'model',
|
|
@@ -1257,6 +1368,7 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1257
1368
|
origin: item.origin ?? 'manual',
|
|
1258
1369
|
sessionId: item.sessionId,
|
|
1259
1370
|
title: item.title,
|
|
1371
|
+
...(item.anchor === null || item.anchor === undefined ? {} : { anchor: item.anchor }),
|
|
1260
1372
|
...(item.snapshot === null || item.snapshot === undefined ? {} : { snapshot: item.snapshot }),
|
|
1261
1373
|
updatedAt: Math.round(item.updatedAt),
|
|
1262
1374
|
prompt: item.prompt ?? '',
|
package/package.json
CHANGED