dsh-planbox-dyb 0.8.2 → 0.8.3
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 +3 -3
- package/client.js +25 -9
- package/index.js +38 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ dsh plugin --profile web add dsh-planbox-dyb
|
|
|
18
18
|
|
|
19
19
|
1. 模型会在需要重启时主动登记;你也可以点每轮回答下方的「加入计划任务」。
|
|
20
20
|
2. 重启后打开侧栏底部的「计划任务」(右上角红点是数量)。
|
|
21
|
-
3.
|
|
21
|
+
3. 先点「建议」看模型打算怎么继续,再决定「中断恢复」或「忽略」。
|
|
22
22
|
|
|
23
23
|
## 面板
|
|
24
24
|
|
|
@@ -34,10 +34,10 @@ dsh plugin --profile web add dsh-planbox-dyb
|
|
|
34
34
|
- **查看**:跳到对应会话,不关闭面板,并把该任务置顶;会提示打开的是第几轮对话。
|
|
35
35
|
- **忽略**:删除这一条;扫描/异常项会隐藏到该会话下次更新。
|
|
36
36
|
- **全部忽略**:确认后清空当前列表。
|
|
37
|
-
-
|
|
37
|
+
- **中断恢复**:只处理「异常中断」,每项发一句「继续」;发送成功后记录删除,不跟踪后续进度。
|
|
38
38
|
|
|
39
39
|
## 注意
|
|
40
40
|
|
|
41
41
|
- 只支持 DSH Web;headless 没有面板。
|
|
42
42
|
- 不自动续跑、不跟踪任务是否完成,进度需要你自己看会话。
|
|
43
|
-
-
|
|
43
|
+
- 可以和自动续跑插件共存;已被自动续跑的会话会从「异常中断」消失,「中断恢复」投递前也会复核,不会重复发。
|
package/client.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* dsh-planbox-dyb — 浏览器侧。
|
|
3
3
|
*
|
|
4
4
|
* 侧栏底部一个“计划任务”入口:列出已登记的计划任务和扫描到的“等重启后继续”会话。
|
|
5
|
-
* 面板只做审核:建议 / 查看 /
|
|
5
|
+
* 面板只做审核:建议 / 查看 / 忽略;底部的「中断恢复」只对异常中断项投递一句「继续」。
|
|
6
6
|
* 面板浮在侧栏上方,点遮罩或 Esc 关闭。
|
|
7
7
|
*/
|
|
8
8
|
window.__ModuleLoader__.load({
|
|
@@ -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.3";
|
|
19
19
|
|
|
20
20
|
const FALLBACK = {
|
|
21
21
|
open: "计划任务",
|
|
@@ -38,7 +38,7 @@ window.__ModuleLoader__.load({
|
|
|
38
38
|
viewAnchor: "已打开:{label}",
|
|
39
39
|
resume: "继续",
|
|
40
40
|
view: "查看",
|
|
41
|
-
resumeAll: "
|
|
41
|
+
resumeAll: "中断恢复",
|
|
42
42
|
ignoreAll: "全部忽略",
|
|
43
43
|
ignoreAllConfirm: "确定忽略全部 {n} 项?扫描/中断项会写入忽略记录。",
|
|
44
44
|
ignoreAllOk: "确定",
|
|
@@ -485,7 +485,7 @@ window.__ModuleLoader__.load({
|
|
|
485
485
|
);
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
/**
|
|
488
|
+
/** 「中断恢复」只处理异常中断项。 */
|
|
489
489
|
function restorableItems(items) {
|
|
490
490
|
return items.filter((item) => item.source === "abnormal");
|
|
491
491
|
}
|
|
@@ -510,7 +510,7 @@ window.__ModuleLoader__.load({
|
|
|
510
510
|
function Panel(props) {
|
|
511
511
|
const { t, items, loading, busy, busyAction, error, result, pinnedId, onClose, onRefresh, onResume, onOpen, onDismiss, onSuggest, onDismissAll } = props;
|
|
512
512
|
const [confirmDismiss, setConfirmDismiss] = React.useState(false);
|
|
513
|
-
//
|
|
513
|
+
// 「中断恢复」只处理异常中断项,其余任务由用户自己审核。
|
|
514
514
|
const interrupted = restorableItems(items);
|
|
515
515
|
|
|
516
516
|
React.useEffect(() => {
|
|
@@ -680,7 +680,7 @@ window.__ModuleLoader__.load({
|
|
|
680
680
|
{
|
|
681
681
|
type: "button",
|
|
682
682
|
className: "dpb-secondary",
|
|
683
|
-
disabled: busy ||
|
|
683
|
+
disabled: busy || items.length === 0,
|
|
684
684
|
onClick: () => setConfirmDismiss(true),
|
|
685
685
|
},
|
|
686
686
|
t("ignoreAll"),
|
|
@@ -690,7 +690,7 @@ window.__ModuleLoader__.load({
|
|
|
690
690
|
{
|
|
691
691
|
type: "button",
|
|
692
692
|
className: "dpb-primary",
|
|
693
|
-
disabled: busy ||
|
|
693
|
+
disabled: busy || interrupted.length === 0,
|
|
694
694
|
title: interrupted.length === 0 ? t("noInterrupted") : undefined,
|
|
695
695
|
onClick: () => onResume(interrupted.map((item) => item.id)),
|
|
696
696
|
},
|
|
@@ -717,6 +717,8 @@ window.__ModuleLoader__.load({
|
|
|
717
717
|
// 「建议」:pendingFill 非空时弹确认框;fillNotice 是短暂的操作反馈。
|
|
718
718
|
const [pendingFill, setPendingFill] = React.useState(null);
|
|
719
719
|
const [fillNotice, setFillNotice] = React.useState(null);
|
|
720
|
+
const loadSeq = React.useRef(0);
|
|
721
|
+
const busyRef = React.useRef(false);
|
|
720
722
|
|
|
721
723
|
React.useEffect(() => {
|
|
722
724
|
panelState.open = open;
|
|
@@ -737,14 +739,19 @@ window.__ModuleLoader__.load({
|
|
|
737
739
|
|
|
738
740
|
const load = React.useCallback(
|
|
739
741
|
async (refresh) => {
|
|
740
|
-
if (muted.current) return;
|
|
742
|
+
if (muted.current || busyRef.current) return;
|
|
743
|
+
const seq = loadSeq.current + 1;
|
|
744
|
+
loadSeq.current = seq;
|
|
741
745
|
setLoading(true);
|
|
742
746
|
try {
|
|
743
747
|
const data = await request(`${API}/pending${refresh ? "?refresh=1" : ""}`);
|
|
748
|
+
if (seq !== loadSeq.current || muted.current) return;
|
|
744
749
|
setItems(Array.isArray(data.items) ? data.items : []);
|
|
745
750
|
setError(data.scanError ? t("scanFailed", { message: data.scanError }) : null);
|
|
746
751
|
} catch (cause) {
|
|
747
|
-
|
|
752
|
+
if (seq === loadSeq.current && !muted.current) {
|
|
753
|
+
setError(t("loadFailed", { message: String(cause?.message ?? cause) }));
|
|
754
|
+
}
|
|
748
755
|
} finally {
|
|
749
756
|
setLoading(false);
|
|
750
757
|
}
|
|
@@ -780,6 +787,8 @@ window.__ModuleLoader__.load({
|
|
|
780
787
|
if (busy) return;
|
|
781
788
|
const wanted = Array.isArray(ids) ? ids.filter((id) => typeof id === "string") : [];
|
|
782
789
|
if (wanted.length === 0) return;
|
|
790
|
+
busyRef.current = true;
|
|
791
|
+
loadSeq.current += 1;
|
|
783
792
|
setBusyAction("resume");
|
|
784
793
|
setResult(null);
|
|
785
794
|
try {
|
|
@@ -811,6 +820,7 @@ window.__ModuleLoader__.load({
|
|
|
811
820
|
} catch (cause) {
|
|
812
821
|
setError(t("loadFailed", { message: String(cause?.message ?? cause) }));
|
|
813
822
|
} finally {
|
|
823
|
+
busyRef.current = false;
|
|
814
824
|
setBusyAction(null);
|
|
815
825
|
}
|
|
816
826
|
},
|
|
@@ -822,6 +832,8 @@ window.__ModuleLoader__.load({
|
|
|
822
832
|
async (id) => {
|
|
823
833
|
if (busy) return;
|
|
824
834
|
const snapshot = items;
|
|
835
|
+
busyRef.current = true;
|
|
836
|
+
loadSeq.current += 1;
|
|
825
837
|
setBusyAction("dismiss");
|
|
826
838
|
setResult(null);
|
|
827
839
|
setItems((previous) => previous.filter((item) => item.id !== id));
|
|
@@ -836,6 +848,7 @@ window.__ModuleLoader__.load({
|
|
|
836
848
|
setItems(snapshot);
|
|
837
849
|
setError(t("loadFailed", { message: String(cause?.message ?? cause) }));
|
|
838
850
|
} finally {
|
|
851
|
+
busyRef.current = false;
|
|
839
852
|
setBusyAction(null);
|
|
840
853
|
}
|
|
841
854
|
},
|
|
@@ -849,6 +862,8 @@ window.__ModuleLoader__.load({
|
|
|
849
862
|
const wanted = Array.isArray(ids) ? ids : [];
|
|
850
863
|
if (wanted.length === 0) return;
|
|
851
864
|
const snapshot = items;
|
|
865
|
+
busyRef.current = true;
|
|
866
|
+
loadSeq.current += 1;
|
|
852
867
|
setBusyAction("dismiss");
|
|
853
868
|
setResult(null);
|
|
854
869
|
setItems([]);
|
|
@@ -863,6 +878,7 @@ window.__ModuleLoader__.load({
|
|
|
863
878
|
setItems(snapshot);
|
|
864
879
|
setError(t("loadFailed", { message: String(cause?.message ?? cause) }));
|
|
865
880
|
} finally {
|
|
881
|
+
busyRef.current = false;
|
|
866
882
|
setBusyAction(null);
|
|
867
883
|
}
|
|
868
884
|
},
|
package/index.js
CHANGED
|
@@ -330,6 +330,8 @@ export function createStore(options = {}) {
|
|
|
330
330
|
queueFile,
|
|
331
331
|
dismissedFile,
|
|
332
332
|
scanCache: null,
|
|
333
|
+
scanEpoch: 0,
|
|
334
|
+
scanRefresh: null,
|
|
333
335
|
|
|
334
336
|
/** 当前登记队列。 */
|
|
335
337
|
queue() {
|
|
@@ -597,10 +599,26 @@ function detectCandidate(summary, tail, turn, options) {
|
|
|
597
599
|
*/
|
|
598
600
|
export async function scanCandidates(ctx, store, options = {}) {
|
|
599
601
|
const now = typeof options.now === 'number' ? options.now : Date.now();
|
|
600
|
-
if (!options.refresh && store.scanCache
|
|
602
|
+
if (!options.refresh && store.scanCache) {
|
|
603
|
+
if (now - store.scanCache.at < SCAN_TTL_MS) {
|
|
604
|
+
return store.scanCache.value;
|
|
605
|
+
}
|
|
606
|
+
// 过期缓存先返回,后台更新;面板打开不再等整轮扫描。
|
|
607
|
+
if (store.scanRefresh === null) {
|
|
608
|
+
store.scanRefresh = scanCandidates(ctx, store, {
|
|
609
|
+
refresh: true,
|
|
610
|
+
background: true,
|
|
611
|
+
now: Date.now(),
|
|
612
|
+
})
|
|
613
|
+
.catch(() => null)
|
|
614
|
+
.finally(() => {
|
|
615
|
+
store.scanRefresh = null;
|
|
616
|
+
});
|
|
617
|
+
}
|
|
601
618
|
return store.scanCache.value;
|
|
602
619
|
}
|
|
603
620
|
|
|
621
|
+
const epoch = store.scanEpoch ?? 0;
|
|
604
622
|
const controller = withTimeout(options.signal, 20_000);
|
|
605
623
|
const items = [];
|
|
606
624
|
let scanError;
|
|
@@ -657,8 +675,19 @@ export async function scanCandidates(ctx, store, options = {}) {
|
|
|
657
675
|
scanError = String(error?.message ?? error);
|
|
658
676
|
}
|
|
659
677
|
|
|
660
|
-
const
|
|
661
|
-
|
|
678
|
+
const dismissedNow = store.dismissed();
|
|
679
|
+
const liveItems = items.filter((item) => {
|
|
680
|
+
const ignoredAt = Number(dismissedNow[item.sessionId] ?? 0);
|
|
681
|
+
return !(ignoredAt > 0 && Number(item.updatedAt ?? 0) <= ignoredAt);
|
|
682
|
+
});
|
|
683
|
+
const value = {
|
|
684
|
+
items: liveItems,
|
|
685
|
+
scannedAt: now,
|
|
686
|
+
...(scanError === undefined ? {} : { scanError }),
|
|
687
|
+
};
|
|
688
|
+
if ((store.scanEpoch ?? 0) === epoch) {
|
|
689
|
+
store.scanCache = { at: now, value };
|
|
690
|
+
}
|
|
662
691
|
return value;
|
|
663
692
|
}
|
|
664
693
|
|
|
@@ -670,9 +699,10 @@ export async function scanCandidates(ctx, store, options = {}) {
|
|
|
670
699
|
* @returns {Promise<{ items: object[], queueCount: number, scanCount: number, scannedAt: number, scanError?: string }>} 汇总。
|
|
671
700
|
*/
|
|
672
701
|
export async function collectPending(ctx, store, options = {}) {
|
|
673
|
-
const queue = await
|
|
674
|
-
|
|
675
|
-
|
|
702
|
+
const [queue, scanned] = await Promise.all([
|
|
703
|
+
queueItemsWithDetails(ctx, store, options),
|
|
704
|
+
scanCandidates(ctx, store, options),
|
|
705
|
+
]);
|
|
676
706
|
// 只有自动登记项会吞掉同会话的扫描结果;手动登记与自动结果要分开显示。
|
|
677
707
|
const known = new Set(
|
|
678
708
|
queue.filter((item) => item.origin === 'model').map((item) => item.sessionId),
|
|
@@ -757,6 +787,8 @@ async function itemsForIds(ctx, store, ids, options = {}) {
|
|
|
757
787
|
|
|
758
788
|
/** 已处理的项从扫描缓存里移除,避免下一次 GET 又看到它。 */
|
|
759
789
|
function forgetFromCache(store, doneIds, doneSessions) {
|
|
790
|
+
// 让正在进行的扫描在写入缓存前发现“已忽略/已恢复”,避免旧结果把数字又刷回来。
|
|
791
|
+
store.scanEpoch = (store.scanEpoch ?? 0) + 1;
|
|
760
792
|
const cache = store.scanCache;
|
|
761
793
|
if (!cache) return;
|
|
762
794
|
cache.value = {
|
package/package.json
CHANGED