dsh-video-insight 0.8.5 → 0.9.1
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 +10 -1
- package/client/client.js +315 -21
- package/lib/index.js +229 -1
- package/lib/jobs.js +206 -0
- package/lib/outline.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](LICENSE)
|
|
4
4
|
[](https://github.com/deepseek-ai)
|
|
5
5
|
[](#已知限制)
|
|
6
|
-
[](package.json)
|
|
7
7
|
|
|
8
8
|

|
|
9
9
|
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
兜底有三档:**本机 Whisper / SenseVoice 转写**(可选引擎、线程、只转前 N 秒),音频全程不出这台电脑;**纯无声/纯画面视频**(没有配音也没有字幕)还能抽帧做**画面文字识别(OCR)**,甚至直接把画面交给**视觉模型**描述场景、人物和动作(「画面理解」,会用到支持图片输入的模型),把画面内容变成带时间戳的文字稿,摘要仍用你 profile 里的模型。
|
|
13
13
|
|
|
14
|
+
粘贴链接那一刻就进**后台队列**:首页历史里每条视频会显示解析进度条,「全部解析」把还没分析完的历史一次性排进队列(默认**不限制并发**,提交几个就跑几个;`jobs.concurrency` 设成正数可限制上限)。详情页只等元信息就打开,总结、章节、导图、分镜都等后台任务跑完自动回填,切走或回首页都不影响。,一条任务从头跑完 总结 → 思维导图 → 分镜 →(可选)画面描述,不用再切页签逐个点「生成」。状态只存在内存里,分析结果照常落盘。
|
|
15
|
+
|
|
14
16
|
追问是 **RAG(检索增强)**:先把问题在转写稿里做 BM25 检索,只把最相关的几段(带时间戳)连同对话一起喂给模型,回答里标 `[mm:ss]`,气泡下面还有「依据」按钮,点一下直接跳回那段视频。
|
|
15
17
|
|
|
16
18
|
总结 / 章节 / 思维导图 / 对话都会**按视频缓存**(`~/.dsh/video-analyses/`),从「历史」里点回来直接看到上次的结果,不用重新等模型;想重来就点「重新生成」,也可以一键清空某个视频的缓存。
|
|
@@ -179,6 +181,11 @@ host 半零外部依赖(只用 Node 内置 `fetch`/`crypto`),不写锁文
|
|
|
179
181
|
| GET | `/dsh-video/api/analysis?docId=` | 取某个视频的分析缓存:`{ok,value:{docId,analysis:{summary,chapters,mindmap,chat}}}` |
|
|
180
182
|
| POST | `/dsh-video/api/analysis/clear` | `{docId}` 清掉该视频全部缓存(总结/章节/导图/对话) |
|
|
181
183
|
| POST | `/dsh-video/api/analysis/chat/clear` | `{docId}` 只清对话 |
|
|
184
|
+
| POST | `/dsh-video/api/jobs` | 开始一个后台解析任务:`{docId?/url?, describe?:true}` → `{ok,value:{job,created}}`;同一视频已在队列里时不重复排队(`created:false`) |
|
|
185
|
+
| GET | `/dsh-video/api/jobs` | 任务队列快照:`{ok,value:{concurrency,active,running,jobs:[{id,docId,url,title,status,stage,stageLabel,percent,describe,error,warnings,queuedAt,startedAt,finishedAt}]}}`(进度条就轮询这个) |
|
|
186
|
+
| POST | `/dsh-video/api/jobs/all` | 批量解析历史里还没分析完的视频:`{limit?:20, force?:false, describe?:true}` → `{ok,value:{started,skipped,jobs}}` |
|
|
187
|
+
| POST | `/dsh-video/api/jobs/cancel` | `{id}` 或 `{docId}` 取消排队/运行中的任务 → `{ok,value:{cancelled,jobs}}` |
|
|
188
|
+
| POST | `/dsh-video/api/jobs/clear` | 清掉已结束的任务记录 |
|
|
182
189
|
| GET | `/dsh-video/api/history` | `{ok,value:{items:[…]}}`,最近 100 条,新的在前(解析/分析成功后 host 自动写入);带 `hasSummary/hasChapters/hasMindmap/chatCount` 标记 |
|
|
183
190
|
| POST | `/dsh-video/api/history/remove` | `{docId}` 删一条 → `{ok,value:{items}}` |
|
|
184
191
|
| POST | `/dsh-video/api/history/clear` | 清空历史 → `{ok,value:{items:[]}}` |
|
|
@@ -225,6 +232,8 @@ host 半零外部依赖(只用 Node 内置 `fetch`/`crypto`),不写锁文
|
|
|
225
232
|
visionMaxFrames: 48 # 画面理解最多取几帧
|
|
226
233
|
visionPack: sheet # sheet=多帧拼一张分镜图(默认,省图省时)| frames=逐帧发
|
|
227
234
|
sheetCols: 3 # 分镜图列数(行数按帧数自动算)
|
|
235
|
+
jobs:
|
|
236
|
+
concurrency: 0 # 后台解析并发数:0 = 不限制(默认),>0 限制上限(最大 16)
|
|
228
237
|
```
|
|
229
238
|
|
|
230
239
|
面板「设置」里保存的 Cookie 与本地转写配置都写在 `~/.dsh/video-credentials.json`,**优先级高于**行配置,改完立即生效。
|
package/client/client.js
CHANGED
|
@@ -19,6 +19,9 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
const HISTORY_LIMIT = 100;
|
|
20
20
|
const HOME_RECENT_LIMIT = 10;
|
|
21
21
|
const SEGMENT_LIMIT = 400;
|
|
22
|
+
/** 后台解析队列轮询间隔:有任务在跑时 2s,空闲时 10s。 */
|
|
23
|
+
const JOBS_ACTIVE_MS = 2000;
|
|
24
|
+
const JOBS_IDLE_MS = 10000;
|
|
22
25
|
|
|
23
26
|
/** 同源 API 基址:应用路由是 document-relative,所以从 baseURI 解析。 */
|
|
24
27
|
const API_BASE = (() => {
|
|
@@ -790,7 +793,7 @@ window.__ModuleLoader__.load({
|
|
|
790
793
|
* 顶部紧凑工具栏:返回 + 标题/平台/状态 + 历史/设置。
|
|
791
794
|
* 视频信息压缩成两行(标题一行省略、元信息一行),不再占掉一整块纵向空间。
|
|
792
795
|
*/
|
|
793
|
-
function VideoToolbar({ doc, historyCount, canGoBack, onBack, onHistory, onSettings }) {
|
|
796
|
+
function VideoToolbar({ doc, job, historyCount, canGoBack, onBack, onHistory, onSettings, onCancelJob }) {
|
|
794
797
|
let metaBits = [];
|
|
795
798
|
if (doc) {
|
|
796
799
|
const stats = doc.stats ?? {};
|
|
@@ -820,6 +823,16 @@ window.__ModuleLoader__.load({
|
|
|
820
823
|
h('div', { key: 'meta', className: 'dvv-toolbar-meta' }, metaBits),
|
|
821
824
|
] : null),
|
|
822
825
|
h('div', { key: 'actions', className: 'dvv-toolbar-actions' }, [
|
|
826
|
+
job && jobActive(job) ? h('div', {
|
|
827
|
+
key: 'job', className: 'dvv-job-chip',
|
|
828
|
+
title: `${jobStageText(job)} · ${jobPercent(job)}%`,
|
|
829
|
+
}, [
|
|
830
|
+
h('span', { key: 't', className: 'dvv-job-chip-text' }, `后台解析 ${jobPercent(job)}% · ${jobStageText(job)}`),
|
|
831
|
+
h('button', {
|
|
832
|
+
key: 'x', type: 'button', className: 'dvv-job-chip-x', title: '取消后台解析', 'aria-label': '取消后台解析',
|
|
833
|
+
onClick: () => { if (onCancelJob) onCancelJob(job); },
|
|
834
|
+
}, '×'),
|
|
835
|
+
]) : null,
|
|
823
836
|
h('button', { key: 'history', type: 'button', className: 'dvv-btn', onClick: onHistory }, historyCount ? `历史 ${historyCount}` : '历史'),
|
|
824
837
|
h('button', { key: 'settings', type: 'button', className: 'dvv-btn', onClick: onSettings }, '设置'),
|
|
825
838
|
]),
|
|
@@ -920,7 +933,7 @@ window.__ModuleLoader__.load({
|
|
|
920
933
|
|
|
921
934
|
/* ------------------------------------------------------------------ 总结 */
|
|
922
935
|
|
|
923
|
-
function SummaryTab({ doc, summary, onRun, onStop, onCopy, onCopyMarkdown, onDownloadMarkdown, onGoSettings, onSeek }) {
|
|
936
|
+
function SummaryTab({ doc, summary, job, onRun, onStop, onCopy, onCopyMarkdown, onDownloadMarkdown, onGoSettings, onSeek }) {
|
|
924
937
|
const available = hasTranscript(doc);
|
|
925
938
|
const official = doc && doc.officialSummary && doc.officialSummary.summary ? String(doc.officialSummary.summary) : '';
|
|
926
939
|
const parts = [];
|
|
@@ -944,6 +957,14 @@ window.__ModuleLoader__.load({
|
|
|
944
957
|
parts.push(h('div', { key: 'cached', className: 'dvv-cache-note dvv-note' }, `已缓存 · ${fmtRelative(summary.cachedAt)}(点「重新生成」可覆盖)`));
|
|
945
958
|
}
|
|
946
959
|
if (summary.error) parts.push(h('div', { key: 'err', className: 'dvv-error' }, summary.error));
|
|
960
|
+
const bgActive = Boolean(job && jobActive(job));
|
|
961
|
+
if (bgActive && !summary.loading && !summary.text && !summary.error) {
|
|
962
|
+
parts.push(h('div', { key: 'bg', className: 'dvv-loading-block dvv-bg-block' }, [
|
|
963
|
+
h('span', { key: 's', className: 'dvv-spinner' }),
|
|
964
|
+
h('span', { key: 't' }, `后台解析中 ${jobPercent(job)}% · ${jobStageText(job)}`),
|
|
965
|
+
h('span', { key: 'n', className: 'dvv-note' }, '总结、章节、思维导图与分镜会在后台生成,完成后自动回填。'),
|
|
966
|
+
]));
|
|
967
|
+
}
|
|
947
968
|
if (summary.loading && !summary.text) {
|
|
948
969
|
parts.push(h('div', { key: 'loading', className: 'dvv-loading-block' }, [h('span', { key: 's', className: 'dvv-spinner' }), summary.phase || '正在生成总结…']));
|
|
949
970
|
}
|
|
@@ -974,7 +995,7 @@ window.__ModuleLoader__.load({
|
|
|
974
995
|
onClick: onDownloadMarkdown,
|
|
975
996
|
}, '下载 .md'));
|
|
976
997
|
parts.push(h('div', { key: 'actions', className: 'dvv-actions' }, actions));
|
|
977
|
-
if (!summary.loading && !summary.text && !summary.error) {
|
|
998
|
+
if (!summary.loading && !summary.text && !summary.error && !bgActive) {
|
|
978
999
|
parts.push(h('div', { key: 'idle', className: 'dvv-notice' }, [
|
|
979
1000
|
h('div', { key: 'n', className: 'dvv-note' }, '还没有生成总结。'),
|
|
980
1001
|
h('div', { key: 'a', className: 'dvv-actions' }, h('button', { type: 'button', className: 'dvv-btn', 'data-primary': 'true', onClick: onRun }, '生成总结')),
|
|
@@ -1015,7 +1036,7 @@ window.__ModuleLoader__.load({
|
|
|
1015
1036
|
]);
|
|
1016
1037
|
}
|
|
1017
1038
|
|
|
1018
|
-
function ChaptersTab({ outline, doc, currentSeconds, view, onView, onSeek, onRetry, onGenerate, onCancel }) {
|
|
1039
|
+
function ChaptersTab({ outline, doc, currentSeconds, view, onView, onSeek, onRetry, onGenerate, onCancel, hint, titlesBusy, onGenerateTitles, onGoMindmap }) {
|
|
1019
1040
|
if (!doc) return h('div', { className: 'dvv-tabpane' }, h('div', { className: 'dvv-empty-note' }, '先解析一个视频,再来看章节。'));
|
|
1020
1041
|
if (outline.loading) {
|
|
1021
1042
|
return h('div', { className: 'dvv-tabpane' }, h('div', { className: 'dvv-chlist' },
|
|
@@ -1046,6 +1067,22 @@ window.__ModuleLoader__.load({
|
|
|
1046
1067
|
outline.genLoading ? '生成中…' : visuals ? '重新生成描述' : '生成画面描述'),
|
|
1047
1068
|
].filter(Boolean));
|
|
1048
1069
|
const parts = [bar];
|
|
1070
|
+
const hintText = String(hint || '').trim();
|
|
1071
|
+
if (hintText) {
|
|
1072
|
+
parts.push(h('div', { key: 'hint', className: 'dvv-outline-hint', role: 'status' }, [
|
|
1073
|
+
h('span', { key: 't', className: 'dvv-outline-hint-text' }, hintText),
|
|
1074
|
+
h('div', { key: 'a', className: 'dvv-outline-hint-actions' }, [
|
|
1075
|
+
h('button', {
|
|
1076
|
+
key: 'gen', type: 'button', className: 'dvv-btn', 'data-primary': 'true',
|
|
1077
|
+
disabled: Boolean(titlesBusy), onClick: () => { if (typeof onGenerateTitles === 'function') onGenerateTitles(); },
|
|
1078
|
+
}, titlesBusy ? '正在生成…' : '生成章节标题'),
|
|
1079
|
+
h('button', {
|
|
1080
|
+
key: 'mm', type: 'button', className: 'dvv-btn',
|
|
1081
|
+
onClick: () => { if (typeof onGoMindmap === 'function') onGoMindmap(); },
|
|
1082
|
+
}, '去思维导图'),
|
|
1083
|
+
]),
|
|
1084
|
+
]));
|
|
1085
|
+
}
|
|
1049
1086
|
if (outline.genLoading) {
|
|
1050
1087
|
parts.push(h('div', { key: 'load', className: 'dvv-tr-progress' }, [
|
|
1051
1088
|
h('span', { key: 'p', className: 'dvv-note' }, outline.genPhase || '正在生成画面描述…'),
|
|
@@ -1739,7 +1776,7 @@ window.__ModuleLoader__.load({
|
|
|
1739
1776
|
]),
|
|
1740
1777
|
h('div', { key: 'body', className: 'dvv-kf-body' }, [
|
|
1741
1778
|
h('div', { key: 'title', className: 'dvv-kf-title', title }, title || '关键画面'),
|
|
1742
|
-
h('div', { key: 'desc', className: 'dvv-kf-desc', 'data-empty': description ? undefined : 'true' }, description || '
|
|
1779
|
+
h('div', { key: 'desc', className: 'dvv-kf-desc', 'data-empty': description ? undefined : 'true' }, description || '还没有画面描述'),
|
|
1743
1780
|
]),
|
|
1744
1781
|
]);
|
|
1745
1782
|
}
|
|
@@ -1755,7 +1792,18 @@ window.__ModuleLoader__.load({
|
|
|
1755
1792
|
}
|
|
1756
1793
|
|
|
1757
1794
|
/** 一条历史记录:封面、标题、作者/时长、平台标签、相对时间、字幕标记、星标、删除。 */
|
|
1758
|
-
|
|
1795
|
+
/* ------------------------------------------------------------ 后台解析任务 */
|
|
1796
|
+
/** 是否仍在跑(排队或执行中)。 */
|
|
1797
|
+
function jobActive(job) { const status = String((job && job.status) || ''); return status === 'queued' || status === 'running'; }
|
|
1798
|
+
/** 百分比:夹在 0–100,排队中恒为 0。 */
|
|
1799
|
+
function jobPercent(job) { if (!job || job.status === 'queued') return 0; const value = Number(job.percent); if (!Number.isFinite(value)) return 0; return Math.min(100, Math.max(0, value)); }
|
|
1800
|
+
/** 阶段文案:排队中 / host 的 stageLabel / 兜底。 */ function jobStageText(job) { if (!job) return ''; if (job.status === 'queued') return '排队中…'; return String(job.stageLabel || (job.status === 'done' ? '已完成' : '解析中…')); }
|
|
1801
|
+
/** 某个 docId 是否有在跑的后台任务(避免同时开内联 SSE 双跑)。 */
|
|
1802
|
+
function activeJobForDoc(list, docId) { if (!docId) return null; for (const job of Array.isArray(list) ? list : []) if (job && job.docId === docId && jobActive(job)) return job; return null; }
|
|
1803
|
+
/** 汇总成 docId → 最新一条任务 的 Map。 */
|
|
1804
|
+
function buildJobsByDoc(list) { const map = new Map(); for (const job of Array.isArray(list) ? list : []) { if (!job || !job.docId) continue; const before = map.get(job.docId); if (!before) { map.set(job.docId, job); continue; } if ((Number(job.updatedAt) || 0) >= (Number(before.updatedAt) || 0)) map.set(job.docId, job); } return map; }
|
|
1805
|
+
|
|
1806
|
+
function HistoryRow({ item, job, onOpen, onRemove, onFavorite, onCancelJob }) {
|
|
1759
1807
|
const platform = item.platform || guessPlatform(item.url);
|
|
1760
1808
|
const duration = Number(item.duration) > 0 ? fmtTime(item.duration) : '';
|
|
1761
1809
|
return h('div', {
|
|
@@ -1779,6 +1827,23 @@ window.__ModuleLoader__.load({
|
|
|
1779
1827
|
item.hasMindmap ? h('span', { key: 'mm', className: 'dvv-mini' }, '导图') : null,
|
|
1780
1828
|
Number(item.chatCount) > 0 ? h('span', { key: 'chat', className: 'dvv-mini' }, `${Number(item.chatCount)} 条对话`) : null,
|
|
1781
1829
|
]),
|
|
1830
|
+
job && jobActive(job) ? h('div', {
|
|
1831
|
+
key: 'job', className: 'dvv-job',
|
|
1832
|
+
onClick: (event) => { if (event && typeof event.stopPropagation === 'function') event.stopPropagation(); },
|
|
1833
|
+
}, [
|
|
1834
|
+
h('div', { key: 'bar', className: 'dvv-jobbar', 'data-queued': job.status === 'queued' ? 'true' : undefined },
|
|
1835
|
+
h('div', { key: 'fill', className: 'dvv-jobbar-fill', style: { width: `${jobPercent(job)}%` } })),
|
|
1836
|
+
h('span', { key: 'label', className: 'dvv-job-label' }, job.status === 'queued' ? '排队中…' : `${jobPercent(job)}% · ${jobStageText(job)}`),
|
|
1837
|
+
onCancelJob ? h('button', {
|
|
1838
|
+
key: 'cancel', type: 'button', className: 'dvv-del', title: '取消后台解析', 'aria-label': '取消后台解析',
|
|
1839
|
+
onClick: (event) => {
|
|
1840
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation();
|
|
1841
|
+
onCancelJob(job);
|
|
1842
|
+
},
|
|
1843
|
+
}, '×') : null,
|
|
1844
|
+
]) : (job && job.status === 'failed'
|
|
1845
|
+
? h('span', { key: 'jobfail', className: 'dvv-job-failed', title: String(job.error || '') }, '解析失败')
|
|
1846
|
+
: null),
|
|
1782
1847
|
]),
|
|
1783
1848
|
onFavorite ? h('button', {
|
|
1784
1849
|
key: 'fav', type: 'button', className: 'dvv-fav', 'data-on': item.favorite ? 'true' : 'false',
|
|
@@ -1799,7 +1864,7 @@ window.__ModuleLoader__.load({
|
|
|
1799
1864
|
}
|
|
1800
1865
|
|
|
1801
1866
|
/** 无视频空态时直接铺在主区的历史列表:只展示前 10 条,更多去抽屉。 */
|
|
1802
|
-
function HistoryList({ items, onOpen, onRemove, onFavorite, onOpenAll }) {
|
|
1867
|
+
function HistoryList({ items, jobs, activeCount, parseAllBusy, parseAllConfirm, onOpen, onRemove, onFavorite, onOpenAll, onCancelJob, onParseAll }) {
|
|
1803
1868
|
const all = Array.isArray(items) ? items : [];
|
|
1804
1869
|
if (!all.length) return null;
|
|
1805
1870
|
const shown = all.slice(0, HOME_RECENT_LIMIT);
|
|
@@ -1808,17 +1873,24 @@ window.__ModuleLoader__.load({
|
|
|
1808
1873
|
h('span', { key: 't', className: 'dvv-label' }, '最近分析'),
|
|
1809
1874
|
h('span', { key: 'c', className: 'dvv-note' }, `共 ${all.length} 条 · 最多保留 ${HISTORY_LIMIT} 条`),
|
|
1810
1875
|
h('div', { key: 's', className: 'dvv-spacer' }),
|
|
1876
|
+
onParseAll ? h('button', {
|
|
1877
|
+
key: 'parseAll', type: 'button', className: 'dvv-btn dvv-btn-mini',
|
|
1878
|
+
'data-danger': parseAllConfirm ? 'true' : undefined, disabled: Boolean(parseAllBusy),
|
|
1879
|
+
onClick: () => onParseAll(),
|
|
1880
|
+
}, parseAllConfirm ? '确认解析?' : (Number(activeCount) > 0 ? `解析中 ${Number(activeCount)}` : '全部解析')) : null,
|
|
1811
1881
|
all.length > HOME_RECENT_LIMIT && onOpenAll
|
|
1812
1882
|
? h('button', { key: 'more', type: 'button', className: 'dvv-btn dvv-btn-mini', onClick: onOpenAll }, '打开历史查看全部')
|
|
1813
1883
|
: null,
|
|
1814
1884
|
].filter(Boolean)),
|
|
1815
1885
|
h('div', { key: 'list', className: 'dvv-hist-list' }, shown.map((item, index) => h(HistoryRow, {
|
|
1816
|
-
key: `${item.docId || item.url || 'item'}-${index}`, item,
|
|
1886
|
+
key: `${item.docId || item.url || 'item'}-${index}`, item,
|
|
1887
|
+
job: jobs && typeof jobs.get === 'function' ? jobs.get(item.docId) : null,
|
|
1888
|
+
onOpen, onRemove, onFavorite, onCancelJob,
|
|
1817
1889
|
}))),
|
|
1818
1890
|
]);
|
|
1819
1891
|
}
|
|
1820
1892
|
|
|
1821
|
-
function HistoryDrawer({ items, error, query, filter, onQuery, onFilter, onOpen, onRemove, onFavorite, onClear, onClose }) {
|
|
1893
|
+
function HistoryDrawer({ items, jobs, error, query, filter, onQuery, onFilter, onOpen, onRemove, onFavorite, onCancelJob, onClear, onClose }) {
|
|
1822
1894
|
const [confirming, setConfirming] = useState(false);
|
|
1823
1895
|
const list = Array.isArray(items) ? items : [];
|
|
1824
1896
|
const needle = String(query ?? '').trim().toLowerCase();
|
|
@@ -1860,8 +1932,9 @@ window.__ModuleLoader__.load({
|
|
|
1860
1932
|
error ? h('div', { key: 'err', className: 'dvv-error' }, error) : null,
|
|
1861
1933
|
visible.length ? visible.map((item, index) => h(HistoryRow, {
|
|
1862
1934
|
key: `${item.docId || item.url || 'item'}-${index}`, item,
|
|
1935
|
+
job: jobs && typeof jobs.get === 'function' ? jobs.get(item.docId) : null,
|
|
1863
1936
|
onOpen: (picked) => { setConfirming(false); onOpen(picked); },
|
|
1864
|
-
onRemove, onFavorite,
|
|
1937
|
+
onRemove, onFavorite, onCancelJob,
|
|
1865
1938
|
})) : h('div', { key: 'empty', className: 'dvv-empty-note' },
|
|
1866
1939
|
list.length
|
|
1867
1940
|
? '没有匹配的历史记录'
|
|
@@ -2221,16 +2294,22 @@ window.__ModuleLoader__.load({
|
|
|
2221
2294
|
const [asrNote, setAsrNote] = useState('');
|
|
2222
2295
|
const [transcribe, setTranscribe] = useState(EMPTY_TRANSCRIBE);
|
|
2223
2296
|
const [mindmap, setMindmap] = useState(EMPTY_MINDMAP);
|
|
2297
|
+
const [titlesLoading, setTitlesLoading] = useState(false);
|
|
2224
2298
|
const [mmExpanded, setMmExpanded] = useState({});
|
|
2225
2299
|
const [storyboard, setStoryboard] = useState(EMPTY_STORYBOARD);
|
|
2226
2300
|
const [sbDescribe, setSbDescribe] = useState(false);
|
|
2227
2301
|
const [outline, setOutline] = useState(EMPTY_OUTLINE);
|
|
2228
2302
|
const [outlineView, setOutlineView] = useState('list');
|
|
2303
|
+
const [jobs, setJobs] = useState({ concurrency: 0, active: 0, running: 0, jobs: [] });
|
|
2304
|
+
const [jobsError, setJobsError] = useState('');
|
|
2305
|
+
const [parseAllBusy, setParseAllBusy] = useState(false);
|
|
2306
|
+
const [parseAllConfirm, setParseAllConfirm] = useState(false);
|
|
2229
2307
|
|
|
2230
2308
|
const mounted = useRef(true);
|
|
2231
2309
|
/** 同一时刻只允许一条在途请求(解析或流式),切视频 / 新请求前 abort。 */
|
|
2232
2310
|
const active = useRef(null);
|
|
2233
2311
|
const docRef = useRef(null);
|
|
2312
|
+
const titlesLoadingRef = useRef(false);
|
|
2234
2313
|
const chatRef = useRef([]);
|
|
2235
2314
|
const askBusyRef = useRef(false);
|
|
2236
2315
|
const resolveTicket = useRef(0);
|
|
@@ -2240,8 +2319,14 @@ window.__ModuleLoader__.load({
|
|
|
2240
2319
|
const pendingSeek = useRef(null);
|
|
2241
2320
|
/** 自动转写判重:docId → running | done | cancelled | failed | manual(同一视频不重复自动触发)。 */
|
|
2242
2321
|
const autoAsrRef = useRef(new Map());
|
|
2322
|
+
/** 后台自动入队判重:docId → true(同一视频每轮只自动提交一次,回首页重置)。 */
|
|
2323
|
+
const autoQueueRef = useRef(new Set());
|
|
2243
2324
|
/** 双语翻译请求的独立 AbortController(不打断总结 / 追问)。 */
|
|
2244
2325
|
const translationAbort = useRef(null);
|
|
2326
|
+
/** 后台解析队列:上一轮 jobs(用于判断 running/queued → done/failed)与最近 active 数。 */
|
|
2327
|
+
const jobsRef = useRef([]);
|
|
2328
|
+
const jobsActiveRef = useRef(0);
|
|
2329
|
+
const jobsSeen = useRef(false);
|
|
2245
2330
|
docRef.current = doc;
|
|
2246
2331
|
chatRef.current = chat;
|
|
2247
2332
|
|
|
@@ -2553,6 +2638,24 @@ window.__ModuleLoader__.load({
|
|
|
2553
2638
|
}
|
|
2554
2639
|
}, []);
|
|
2555
2640
|
|
|
2641
|
+
/** 拉取 host 分析缓存(GET /analysis)并回填面板;返回是否回填了内容。 */
|
|
2642
|
+
const loadAnalysisCache = useCallback(async (video) => {
|
|
2643
|
+
const target = video ?? docRef.current;
|
|
2644
|
+
if (!target || !target.docId || !mounted.current) return false;
|
|
2645
|
+
try {
|
|
2646
|
+
const value = await call('analysis', { docId: target.docId });
|
|
2647
|
+
if (!mounted.current) return false;
|
|
2648
|
+
const analysis = value && typeof value === 'object' ? (value.analysis || value) : null;
|
|
2649
|
+
const cache = readCachedAnalysis({ analysis });
|
|
2650
|
+
if (!cache) return false;
|
|
2651
|
+
applyAnalysisCache(cache);
|
|
2652
|
+
setDoc((current) => (current && current.docId === target.docId ? { ...current, analysis } : current));
|
|
2653
|
+
return true;
|
|
2654
|
+
} catch (caught) {
|
|
2655
|
+
return false;
|
|
2656
|
+
}
|
|
2657
|
+
}, [applyAnalysisCache]);
|
|
2658
|
+
|
|
2556
2659
|
/** 清空 host 上这个视频的分析缓存(总结 / 章节 / 导图 / 对话)。 */
|
|
2557
2660
|
const clearAnalysisCache = useCallback(async (video) => {
|
|
2558
2661
|
const target = video ?? docRef.current;
|
|
@@ -2599,6 +2702,10 @@ window.__ModuleLoader__.load({
|
|
|
2599
2702
|
const runSummary = useCallback(async (video) => {
|
|
2600
2703
|
const target = video ?? docRef.current;
|
|
2601
2704
|
if (!target || !mounted.current) return;
|
|
2705
|
+
if (activeJobForDoc(jobsRef.current, target.docId)) {
|
|
2706
|
+
showToast('后台解析中,完成后会自动回填总结');
|
|
2707
|
+
return;
|
|
2708
|
+
}
|
|
2602
2709
|
interruptActive();
|
|
2603
2710
|
const controller = new AbortController();
|
|
2604
2711
|
active.current = { controller, kind: 'summary' };
|
|
@@ -2829,16 +2936,41 @@ window.__ModuleLoader__.load({
|
|
|
2829
2936
|
cachedAt: '',
|
|
2830
2937
|
});
|
|
2831
2938
|
setMmExpanded(defaultMindmapExpanded(data));
|
|
2939
|
+
return '';
|
|
2832
2940
|
} catch (caught) {
|
|
2833
|
-
if (!mounted.current || (caught && caught.name === 'AbortError')) return;
|
|
2941
|
+
if (!mounted.current || (caught && caught.name === 'AbortError')) return '';
|
|
2942
|
+
const message = friendlyMindmapError(caught);
|
|
2834
2943
|
setMindmap({
|
|
2835
2944
|
...EMPTY_MINDMAP,
|
|
2836
|
-
error:
|
|
2945
|
+
error: message,
|
|
2837
2946
|
code: String((caught && caught.code) || ''),
|
|
2838
2947
|
});
|
|
2948
|
+
return message;
|
|
2839
2949
|
}
|
|
2840
2950
|
}, []);
|
|
2841
2951
|
|
|
2952
|
+
/* ---- 章节兜底(均匀切分)时,一键生成章节标题:先生成思维导图,再刷新大纲 ---- */
|
|
2953
|
+
const generateChapterTitles = useCallback(async (video) => {
|
|
2954
|
+
const target = video ?? docRef.current;
|
|
2955
|
+
if (!target || !target.docId || titlesLoadingRef.current) return;
|
|
2956
|
+
titlesLoadingRef.current = true;
|
|
2957
|
+
setTitlesLoading(true);
|
|
2958
|
+
try {
|
|
2959
|
+
const failure = await loadMindmap(target, false);
|
|
2960
|
+
if (!mounted.current) return;
|
|
2961
|
+
if (failure) {
|
|
2962
|
+
showToast(String(failure));
|
|
2963
|
+
return;
|
|
2964
|
+
}
|
|
2965
|
+
await loadOutline(docRef.current);
|
|
2966
|
+
} catch (caught) {
|
|
2967
|
+
if (mounted.current) showToast(friendlyMindmapError(caught));
|
|
2968
|
+
} finally {
|
|
2969
|
+
titlesLoadingRef.current = false;
|
|
2970
|
+
if (mounted.current) setTitlesLoading(false);
|
|
2971
|
+
}
|
|
2972
|
+
}, [loadMindmap, loadOutline, showToast]);
|
|
2973
|
+
|
|
2842
2974
|
const toggleMindmapNode = useCallback((path) => {
|
|
2843
2975
|
setMmExpanded((current) => ({ ...current, [path]: !current[path] }));
|
|
2844
2976
|
}, []);
|
|
@@ -2854,7 +2986,7 @@ window.__ModuleLoader__.load({
|
|
|
2854
2986
|
*/
|
|
2855
2987
|
const loadStoryboard = useCallback(async (video, options) => {
|
|
2856
2988
|
const target = video ?? docRef.current;
|
|
2857
|
-
const opts = options || {};
|
|
2989
|
+
const opts = options || {}; const silent = Boolean(opts.silent);
|
|
2858
2990
|
if (!target || !target.docId || !mounted.current || storyboard.loading) return;
|
|
2859
2991
|
interruptActive();
|
|
2860
2992
|
const controller = new AbortController();
|
|
@@ -2910,7 +3042,7 @@ window.__ModuleLoader__.load({
|
|
|
2910
3042
|
error: data ? '' : '分镜生成完了,但没有拿到可用的分镜数据。',
|
|
2911
3043
|
code: '',
|
|
2912
3044
|
});
|
|
2913
|
-
if (data) {
|
|
3045
|
+
if (data && !silent) {
|
|
2914
3046
|
const count = data.frames || data.cells.length;
|
|
2915
3047
|
showToast(`分镜已生成 · ${count} 格${data.described ? ' · 含描述' : ''}`);
|
|
2916
3048
|
}
|
|
@@ -2961,6 +3093,95 @@ window.__ModuleLoader__.load({
|
|
|
2961
3093
|
showToast('已取消生成分镜');
|
|
2962
3094
|
}, [abortActive, showToast]);
|
|
2963
3095
|
|
|
3096
|
+
/* ---- 后台解析队列:GET /jobs 轮询 + 取消 + 一键全部解析 ---- */
|
|
3097
|
+
/** 拉一次任务列表:状态迁移时刷新历史;当前视频完成时提示并刷新大纲/分镜。 */
|
|
3098
|
+
const refreshJobs = useCallback(async () => {
|
|
3099
|
+
let value = null;
|
|
3100
|
+
try {
|
|
3101
|
+
value = await call('jobs');
|
|
3102
|
+
} catch (caught) {
|
|
3103
|
+
if (mounted.current) setJobsError(`后台任务加载失败:${String(caught?.message ?? caught)}`);
|
|
3104
|
+
return;
|
|
3105
|
+
}
|
|
3106
|
+
if (!mounted.current) return;
|
|
3107
|
+
const next = value && typeof value === 'object' ? value : {};
|
|
3108
|
+
const list = Array.isArray(next.jobs) ? next.jobs.filter(Boolean) : [];
|
|
3109
|
+
const activeCount = list.reduce((sum, job) => sum + (jobActive(job) ? 1 : 0), 0);
|
|
3110
|
+
const prev = jobsRef.current;
|
|
3111
|
+
jobsRef.current = list;
|
|
3112
|
+
jobsActiveRef.current = Number(next.active) > 0 ? Number(next.active) : activeCount;
|
|
3113
|
+
setJobs({
|
|
3114
|
+
concurrency: Number(next.concurrency) || 0,
|
|
3115
|
+
active: Number(next.active) || activeCount,
|
|
3116
|
+
running: Number(next.running) || 0,
|
|
3117
|
+
jobs: list,
|
|
3118
|
+
});
|
|
3119
|
+
setJobsError('');
|
|
3120
|
+
const prevByDoc = buildJobsByDoc(prev);
|
|
3121
|
+
const nextByDoc = buildJobsByDoc(list);
|
|
3122
|
+
const finished = [];
|
|
3123
|
+
for (const [docId, job] of nextByDoc.entries()) {
|
|
3124
|
+
const before = prevByDoc.get(docId);
|
|
3125
|
+
const terminal = job.status === 'done' || job.status === 'failed';
|
|
3126
|
+
if (!terminal) continue;
|
|
3127
|
+
const wasActive = before && jobActive(before);
|
|
3128
|
+
const isNew = !before || before.status !== job.status;
|
|
3129
|
+
if (wasActive || (jobsSeen.current && isNew)) finished.push(job);
|
|
3130
|
+
}
|
|
3131
|
+
if (jobsSeen.current && finished.length) void refreshHistory();
|
|
3132
|
+
jobsSeen.current = true;
|
|
3133
|
+
const current = docRef.current;
|
|
3134
|
+
for (const job of finished) {
|
|
3135
|
+
if (!current || job.docId !== current.docId) continue;
|
|
3136
|
+
if (job.status === 'done') {
|
|
3137
|
+
showToast('后台解析完成');
|
|
3138
|
+
void loadAnalysisCache(current);
|
|
3139
|
+
void loadOutline(current);
|
|
3140
|
+
void loadStoryboard(current, { silent: true });
|
|
3141
|
+
} else if (job.status === 'failed') {
|
|
3142
|
+
showToast(`后台解析失败:${String(job.error || '未知错误')}`);
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
}, [refreshHistory, showToast, loadAnalysisCache, loadOutline, loadStoryboard]);
|
|
3146
|
+
|
|
3147
|
+
/** 取消某个 docId 的后台任务(历史行 / 详情工具条共用)。 */
|
|
3148
|
+
const cancelJob = useCallback(async (jobOrDoc) => {
|
|
3149
|
+
const docId = String((jobOrDoc && jobOrDoc.docId) || jobOrDoc || '');
|
|
3150
|
+
if (!docId) { showToast('这条任务缺少 docId,无法取消'); return; }
|
|
3151
|
+
try {
|
|
3152
|
+
await post('jobs/cancel', { docId });
|
|
3153
|
+
if (!mounted.current) return;
|
|
3154
|
+
showToast('已取消后台解析');
|
|
3155
|
+
void refreshJobs();
|
|
3156
|
+
} catch (caught) {
|
|
3157
|
+
if (mounted.current) showToast(`取消失败:${String(caught?.message ?? caught)}`);
|
|
3158
|
+
}
|
|
3159
|
+
}, [refreshJobs, showToast]);
|
|
3160
|
+
|
|
3161
|
+
/** 首页「全部解析」:第一次点击进入确认,第二次才真正提交。 */
|
|
3162
|
+
const parseAllJobs = useCallback(async () => {
|
|
3163
|
+
if (parseAllBusy) return;
|
|
3164
|
+
if (!parseAllConfirm) {
|
|
3165
|
+
if (!historyItems.length) { showToast('还没有历史记录可以解析'); return; }
|
|
3166
|
+
setParseAllConfirm(true);
|
|
3167
|
+
return;
|
|
3168
|
+
}
|
|
3169
|
+
setParseAllConfirm(false);
|
|
3170
|
+
setParseAllBusy(true);
|
|
3171
|
+
try {
|
|
3172
|
+
const value = await post('jobs/all', { limit: 20, describe: true });
|
|
3173
|
+
if (!mounted.current) return;
|
|
3174
|
+
const started = Number(value && value.started) || 0;
|
|
3175
|
+
const skipped = Number(value && value.skipped) || 0;
|
|
3176
|
+
showToast(`已开始 ${started} 个,跳过 ${skipped} 个`);
|
|
3177
|
+
void refreshJobs();
|
|
3178
|
+
} catch (caught) {
|
|
3179
|
+
if (mounted.current) showToast(`批量解析失败:${String(caught?.message ?? caught)}`);
|
|
3180
|
+
} finally {
|
|
3181
|
+
if (mounted.current) setParseAllBusy(false);
|
|
3182
|
+
}
|
|
3183
|
+
}, [parseAllBusy, parseAllConfirm, historyItems.length, showToast, refreshJobs]);
|
|
3184
|
+
|
|
2964
3185
|
/* ---- 原文双语对照:GET /translate 读缓存,没有就 POST SSE 生成(独立取消,不打断其它请求) ---- */
|
|
2965
3186
|
|
|
2966
3187
|
const loadTranslation = useCallback(async (video, lang, options) => {
|
|
@@ -3126,6 +3347,7 @@ window.__ModuleLoader__.load({
|
|
|
3126
3347
|
docRef.current = null;
|
|
3127
3348
|
setUrl(text);
|
|
3128
3349
|
let followUp = null;
|
|
3350
|
+
let queued = false;
|
|
3129
3351
|
let cachedSummary = false;
|
|
3130
3352
|
try {
|
|
3131
3353
|
const video = await call('resolve', { url: text, force: options && options.force ? 1 : undefined }, { signal: controller.signal });
|
|
@@ -3148,7 +3370,32 @@ window.__ModuleLoader__.load({
|
|
|
3148
3370
|
cachedSummary = Boolean(cache.summary);
|
|
3149
3371
|
}
|
|
3150
3372
|
void refreshHistory(); // host 在 /resolve 成功时已写入历史,客户端只重新拉取
|
|
3151
|
-
|
|
3373
|
+
// 解析成功即入队后台生成(总结 / 导图 / 分镜 / 画面描述);已在跑或分析完整时不重复提交。
|
|
3374
|
+
const runningJob = activeJobForDoc(jobsRef.current, video.docId);
|
|
3375
|
+
const complete = Boolean(cache && cache.summary && cache.chapters && cache.mindmap);
|
|
3376
|
+
const shouldQueue = !runningJob && !autoQueueRef.current.has(video.docId) && (!complete || Boolean(options && options.force));
|
|
3377
|
+
if (shouldQueue) {
|
|
3378
|
+
autoQueueRef.current.add(video.docId);
|
|
3379
|
+
try {
|
|
3380
|
+
const enqueued = await post('jobs', { docId: video.docId, describe: true }, { signal: controller.signal });
|
|
3381
|
+
if (!mounted.current) return;
|
|
3382
|
+
const job = enqueued && enqueued.job;
|
|
3383
|
+
if (job) {
|
|
3384
|
+
queued = true;
|
|
3385
|
+
jobsRef.current = [...jobsRef.current.filter((item) => item && item.docId !== job.docId), job];
|
|
3386
|
+
setJobs((current) => ({
|
|
3387
|
+
...current,
|
|
3388
|
+
jobs: jobsRef.current,
|
|
3389
|
+
}));
|
|
3390
|
+
void refreshJobs();
|
|
3391
|
+
}
|
|
3392
|
+
} catch (caught) {
|
|
3393
|
+
if (caught && caught.name === 'AbortError') return;
|
|
3394
|
+
queued = false; // 老 host / 网络错误:回退到内联总结,不能把解析弄坏
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
// 后台已接手时不跑内联总结,等 job 完成后再回填;否则保持原来的内联行为。
|
|
3398
|
+
if (!queued) followUp = video;
|
|
3152
3399
|
} catch (caught) {
|
|
3153
3400
|
if (caught && caught.name === 'AbortError') return;
|
|
3154
3401
|
if (mounted.current) setError(friendlyResolveError(caught, text));
|
|
@@ -3157,7 +3404,7 @@ window.__ModuleLoader__.load({
|
|
|
3157
3404
|
if (resolveTicket.current === ticket && mounted.current) setResolveBusy(false);
|
|
3158
3405
|
}
|
|
3159
3406
|
if (followUp && hasTranscript(followUp) && !cachedSummary) void runSummary(followUp);
|
|
3160
|
-
}, [url, interruptActive, resetPanels, refreshHistory, runSummary, applyAnalysisCache]);
|
|
3407
|
+
}, [url, interruptActive, resetPanels, refreshHistory, runSummary, applyAnalysisCache, refreshJobs]);
|
|
3161
3408
|
|
|
3162
3409
|
/* ---- 追问:带最近 6 条 history 流式回答 ---- */
|
|
3163
3410
|
|
|
@@ -3256,6 +3503,28 @@ window.__ModuleLoader__.load({
|
|
|
3256
3503
|
|
|
3257
3504
|
useEffect(() => { void refreshStatus(); void refreshHistory(); void refreshAsr(); }, [refreshStatus, refreshHistory, refreshAsr]);
|
|
3258
3505
|
|
|
3506
|
+
// 后台解析队列轮询:挂载立即拉一次;有任务 2s、空闲 10s;页面隐藏时暂停(保持 10s 心跳)。
|
|
3507
|
+
useEffect(() => {
|
|
3508
|
+
let stopped = false;
|
|
3509
|
+
let timer = 0;
|
|
3510
|
+
const schedule = (ms) => {
|
|
3511
|
+
if (stopped || typeof window.setTimeout !== 'function') return;
|
|
3512
|
+
timer = window.setTimeout(() => { void tick(); }, ms);
|
|
3513
|
+
};
|
|
3514
|
+
const tick = async () => {
|
|
3515
|
+
if (stopped) return;
|
|
3516
|
+
if (typeof document !== 'undefined' && document.hidden) { schedule(JOBS_IDLE_MS); return; }
|
|
3517
|
+
await refreshJobs();
|
|
3518
|
+
if (stopped) return;
|
|
3519
|
+
schedule(jobsActiveRef.current > 0 ? JOBS_ACTIVE_MS : JOBS_IDLE_MS);
|
|
3520
|
+
};
|
|
3521
|
+
void tick();
|
|
3522
|
+
return () => {
|
|
3523
|
+
stopped = true;
|
|
3524
|
+
try { if (timer) window.clearTimeout(timer); } catch { /* ignore */ }
|
|
3525
|
+
};
|
|
3526
|
+
}, [refreshJobs]);
|
|
3527
|
+
|
|
3259
3528
|
// 章节 / 关键画面共用同一份大纲:进入任一页签时按 docId 拉一次。
|
|
3260
3529
|
useEffect(() => {
|
|
3261
3530
|
if (tab !== 'chapters' || !doc) return;
|
|
@@ -3298,11 +3567,15 @@ window.__ModuleLoader__.load({
|
|
|
3298
3567
|
void copy(lines.join('\n'), `已复制 ${items.length} 条字幕`);
|
|
3299
3568
|
};
|
|
3300
3569
|
|
|
3570
|
+
const jobsByDoc = buildJobsByDoc(jobs.jobs);
|
|
3571
|
+
const currentJob = doc ? jobsByDoc.get(doc.docId) : null;
|
|
3572
|
+
const jobsActiveCount = Number(jobs.active) > 0 ? Number(jobs.active) : Array.from(jobsByDoc.values()).filter(jobActive).length;
|
|
3573
|
+
|
|
3301
3574
|
let tabBody = null;
|
|
3302
3575
|
if (doc) {
|
|
3303
3576
|
if (tab === 'summary') {
|
|
3304
3577
|
tabBody = h(SummaryTab, {
|
|
3305
|
-
doc, summary,
|
|
3578
|
+
doc, summary, job: currentJob,
|
|
3306
3579
|
onRun: () => { void runSummary(doc); },
|
|
3307
3580
|
onStop: stopSummary,
|
|
3308
3581
|
onCopy: () => { void copy(summary.text, '已复制总结'); },
|
|
@@ -3318,6 +3591,10 @@ window.__ModuleLoader__.load({
|
|
|
3318
3591
|
onRetry: () => { void loadOutline(doc); },
|
|
3319
3592
|
onGenerate: () => { void generateVisuals(doc, Boolean(outline.data && outline.data.visuals)); },
|
|
3320
3593
|
onCancel: cancelVisuals,
|
|
3594
|
+
hint: outline.data && outline.data.hint ? String(outline.data.hint) : '',
|
|
3595
|
+
titlesBusy: titlesLoading || mindmap.loading,
|
|
3596
|
+
onGenerateTitles: () => { void generateChapterTitles(docRef.current); },
|
|
3597
|
+
onGoMindmap: () => setTab('mindmap'),
|
|
3321
3598
|
});
|
|
3322
3599
|
} else if (tab === 'transcript') {
|
|
3323
3600
|
tabBody = h(TranscriptTab, {
|
|
@@ -3363,6 +3640,7 @@ window.__ModuleLoader__.load({
|
|
|
3363
3640
|
/** 清空当前视频状态,回到插件首页(大输入框 + 最近分析)。 */
|
|
3364
3641
|
const resetToHome = useCallback(() => {
|
|
3365
3642
|
abortActive();
|
|
3643
|
+
autoQueueRef.current.clear();
|
|
3366
3644
|
docRef.current = null;
|
|
3367
3645
|
setDoc(null);
|
|
3368
3646
|
setUrl('');
|
|
@@ -3384,6 +3662,7 @@ window.__ModuleLoader__.load({
|
|
|
3384
3662
|
setSegQuery('');
|
|
3385
3663
|
setSegAll(false);
|
|
3386
3664
|
setOverlay('');
|
|
3665
|
+
setParseAllConfirm(false);
|
|
3387
3666
|
pendingSeek.current = null;
|
|
3388
3667
|
void refreshHistory();
|
|
3389
3668
|
}, [abortActive, refreshHistory]);
|
|
@@ -3413,10 +3692,14 @@ window.__ModuleLoader__.load({
|
|
|
3413
3692
|
}),
|
|
3414
3693
|
historyItems.length
|
|
3415
3694
|
? h('div', { key: 'recent', className: 'dvv-home-recent' }, h(HistoryList, {
|
|
3416
|
-
items: historyItems,
|
|
3695
|
+
items: historyItems, jobs: jobsByDoc, activeCount: jobsActiveCount,
|
|
3696
|
+
parseAllBusy, parseAllConfirm,
|
|
3697
|
+
onOpen: openHistoryItem,
|
|
3417
3698
|
onRemove: (item) => { void removeHistory(item); },
|
|
3418
3699
|
onFavorite: (item) => { void toggleHistoryFavorite(item); },
|
|
3419
3700
|
onOpenAll: () => setOverlay('history'),
|
|
3701
|
+
onCancelJob: (job) => { void cancelJob(job); },
|
|
3702
|
+
onParseAll: () => { void parseAllJobs(); },
|
|
3420
3703
|
}))
|
|
3421
3704
|
: h('div', { key: 'none', className: 'dvv-home-none' }, '还没有分析记录,粘贴一个链接开始吧。'),
|
|
3422
3705
|
].filter(Boolean));
|
|
@@ -3452,7 +3735,8 @@ window.__ModuleLoader__.load({
|
|
|
3452
3735
|
|
|
3453
3736
|
return h('div', { className: 'dvv-root' }, [
|
|
3454
3737
|
h(VideoToolbar, {
|
|
3455
|
-
key: 'toolbar', doc, historyCount: historyItems.length, canGoBack, onBack: goBack,
|
|
3738
|
+
key: 'toolbar', doc, job: currentJob, historyCount: historyItems.length, canGoBack, onBack: goBack,
|
|
3739
|
+
onCancelJob: (job) => { void cancelJob(job); },
|
|
3456
3740
|
onHistory: () => setOverlay(overlay === 'history' ? '' : 'history'),
|
|
3457
3741
|
onSettings: () => {
|
|
3458
3742
|
if (overlay === 'settings') { setOverlay(''); return; }
|
|
@@ -3472,13 +3756,14 @@ window.__ModuleLoader__.load({
|
|
|
3472
3756
|
banners.length ? h('div', { key: 'banners', className: 'dvv-banners' }, banners) : null,
|
|
3473
3757
|
body,
|
|
3474
3758
|
overlay === 'history' ? h(HistoryDrawer, {
|
|
3475
|
-
key: 'drawer', items: historyItems, error: historyError,
|
|
3759
|
+
key: 'drawer', items: historyItems, jobs: jobsByDoc, error: historyError,
|
|
3476
3760
|
query: historyQuery, filter: historyFilter,
|
|
3477
3761
|
onQuery: (value) => setHistoryQuery(value),
|
|
3478
3762
|
onFilter: (value) => setHistoryFilter(value),
|
|
3479
3763
|
onOpen: openHistoryItem,
|
|
3480
3764
|
onRemove: (item) => { void removeHistory(item); },
|
|
3481
3765
|
onFavorite: (item) => { void toggleHistoryFavorite(item); },
|
|
3766
|
+
onCancelJob: (job) => { void cancelJob(job); },
|
|
3482
3767
|
onClear: () => { void clearHistory(); },
|
|
3483
3768
|
onClose: () => setOverlay(''),
|
|
3484
3769
|
}) : null,
|
|
@@ -3584,6 +3869,8 @@ a.dvv-toolbar-title:hover{color:var(--dsw-alias-brand-primary)}
|
|
|
3584
3869
|
.dvv-actions{display:flex;flex-wrap:wrap;align-items:center;gap:8px;padding:10px 0 2px}
|
|
3585
3870
|
.dvv-actions-spacer{flex:1}
|
|
3586
3871
|
.dvv-btn[disabled]{opacity:.55;cursor:not-allowed}
|
|
3872
|
+
.dvv-bg-block{flex-wrap:wrap}
|
|
3873
|
+
.dvv-bg-block .dvv-note{width:100%;margin:0}
|
|
3587
3874
|
.dvv-loading-block{display:flex;align-items:center;gap:8px;padding:14px 0;font-size:12px;line-height:19px;color:var(--dsw-alias-label-secondary)}
|
|
3588
3875
|
.dvv-spinner{display:inline-block;width:12px;height:12px;border-radius:50%;border:2px solid var(--dsw-alias-border-l2,rgba(127,127,127,.35));border-top-color:var(--dsw-alias-brand-primary);animation:dvv-spin .8s linear infinite}
|
|
3589
3876
|
@keyframes dvv-spin{to{transform:rotate(360deg)}}
|
|
@@ -3647,6 +3934,10 @@ a.dvv-toolbar-title:hover{color:var(--dsw-alias-brand-primary)}
|
|
|
3647
3934
|
.dvv-hist-main{flex:1;min-width:0}
|
|
3648
3935
|
.dvv-hist-title{font-size:13px;line-height:19px;font-weight:550;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
3649
3936
|
.dvv-hist-meta{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin-top:3px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary)}
|
|
3937
|
+
.dvv-job{display:flex;align-items:center;gap:6px;margin-top:4px}.dvv-jobbar{flex:1;min-width:0;height:4px;border-radius:999px;overflow:hidden;background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.16))}.dvv-jobbar-fill{height:100%;border-radius:999px;background:var(--dsw-alias-brand-primary);transition:width .25s ease}.dvv-jobbar[data-queued="true"] .dvv-jobbar-fill{width:0!important}
|
|
3938
|
+
.dvv-job-label{flex:none;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}.dvv-job-failed{font-size:11px;line-height:16px;color:var(--dsw-alias-state-error-primary)}
|
|
3939
|
+
.dvv-job-chip{display:flex;align-items:center;gap:6px;min-width:0;max-width:300px;padding:2px 4px 2px 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:999px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:20px}.dvv-job-chip-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
3940
|
+
.dvv-job-chip-x{flex:none;appearance:none;border:0;background:transparent;color:inherit;font-size:14px;line-height:18px;width:18px;height:18px;padding:0;border-radius:50%;cursor:pointer}.dvv-job-chip-x:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.16));color:var(--dsw-alias-state-error-primary)}
|
|
3650
3941
|
.dvv-status-box{display:flex;flex-direction:column;gap:6px;border:1px dashed var(--dsw-alias-border-l1,rgba(0,0,0,.14));border-radius:10px;padding:10px 12px;margin-bottom:14px}
|
|
3651
3942
|
.dvv-kv{display:flex;flex-wrap:wrap;align-items:baseline;gap:8px;font-size:12px;line-height:19px}
|
|
3652
3943
|
.dvv-label{font-size:12px;line-height:19px;font-weight:600;color:var(--dsw-alias-label-secondary)}
|
|
@@ -3761,6 +4052,9 @@ a.dvv-toolbar-title:hover{color:var(--dsw-alias-brand-primary)}
|
|
|
3761
4052
|
.dvv-sb-meta{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
|
|
3762
4053
|
.dvv-sb-check{display:flex;align-items:center;gap:4px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);cursor:pointer}
|
|
3763
4054
|
.dvv-sb-progress{display:flex;flex-direction:column;gap:8px;padding:12px 0}
|
|
4055
|
+
.dvv-outline-hint{display:flex;flex-wrap:wrap;align-items:center;gap:8px;padding:8px 12px;margin:2px 0 10px;border:1px dashed var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-2)}
|
|
4056
|
+
.dvv-outline-hint-text{flex:1 1 220px;min-width:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
|
|
4057
|
+
.dvv-outline-hint-actions{display:flex;align-items:center;gap:6px}
|
|
3764
4058
|
.dvv-sb-wrap{display:flex;flex-direction:column;gap:14px}
|
|
3765
4059
|
.dvv-sb-sheet{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
3766
4060
|
.dvv-sb-cap{font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
|
|
@@ -3863,7 +4157,7 @@ a.dvv-toolbar-title:hover{color:var(--dsw-alias-brand-primary)}
|
|
|
3863
4157
|
apply,
|
|
3864
4158
|
inject,
|
|
3865
4159
|
// 布局是纯函数,暴露给测试直接断言坐标/连线(Host 会忽略额外字段)。
|
|
3866
|
-
__test: { buildMindmapLayout, mindmapTextLines, defaultMindmapExpanded, allMindmapPaths, renderMarkdown, clockToSeconds, buildNoteMarkdown, sanitizeFileName },
|
|
4160
|
+
__test: { buildMindmapLayout, mindmapTextLines, defaultMindmapExpanded, allMindmapPaths, renderMarkdown, clockToSeconds, buildNoteMarkdown, sanitizeFileName, JOBS_ACTIVE_MS, JOBS_IDLE_MS },
|
|
3867
4161
|
};
|
|
3868
4162
|
return exports_;
|
|
3869
4163
|
},
|
package/lib/index.js
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
import { clearTranslation, normalizeLang, readTranslation, runTranslate } from './translate.js';
|
|
53
53
|
import { clearAssets, readCutsAsset, readVideoAsset } from './assets.js';
|
|
54
54
|
import { getThumb } from './thumbs.js';
|
|
55
|
+
import { createJobQueue } from './jobs.js';
|
|
55
56
|
import {
|
|
56
57
|
clearOutlineVisuals,
|
|
57
58
|
generateOutlineVisuals,
|
|
@@ -63,7 +64,7 @@ export const name = 'dsh-video-insight';
|
|
|
63
64
|
/** Route prefix the panel calls; same origin as the GUI, so no CORS preflight. */
|
|
64
65
|
export const API_PREFIX = '/dsh-video/api';
|
|
65
66
|
|
|
66
|
-
const VERSION = '0.
|
|
67
|
+
const VERSION = '0.9.1';
|
|
67
68
|
const CREDENTIALS_FILE = join(homedir(), '.dsh', 'video-credentials.json');
|
|
68
69
|
|
|
69
70
|
const DEFAULTS = {
|
|
@@ -380,6 +381,149 @@ async function analyzeOnce(aiCtx, settings, resolver, request, handlers = {}) {
|
|
|
380
381
|
return { doc, ...result };
|
|
381
382
|
}
|
|
382
383
|
|
|
384
|
+
/* ------------------------------ 后台解析队列 ------------------------------ */
|
|
385
|
+
|
|
386
|
+
/** 后台任务里跑 LLM 步骤:并发时偶发空响应/限流,自动重试几次。 */
|
|
387
|
+
async function withRetry(task, { attempts = 3, baseDelay = 1500, signal } = {}) {
|
|
388
|
+
let lastError = null;
|
|
389
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
390
|
+
if (signal?.aborted) throw new VideoError('aborted', '已取消');
|
|
391
|
+
try {
|
|
392
|
+
return await task(attempt);
|
|
393
|
+
} catch (error) {
|
|
394
|
+
lastError = error;
|
|
395
|
+
const code = String(error?.code ?? '');
|
|
396
|
+
const retriable = code === 'llm-empty' || code === 'llm-failed' || code === 'asr-failed' || code === 'vision-failed';
|
|
397
|
+
if (!retriable || attempt === attempts) throw error;
|
|
398
|
+
await new Promise((resolve) => setTimeout(resolve, baseDelay * attempt));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
throw lastError;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function progressBetween(from, to, percent) {
|
|
405
|
+
const value = Number(percent);
|
|
406
|
+
if (!Number.isFinite(value)) return null;
|
|
407
|
+
const clamped = Math.max(0, Math.min(100, value));
|
|
408
|
+
return Math.round(from + ((to - from) * clamped) / 100);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* 一次完整的后台解析:解析 → 文字稿(需要时)→ 总结 → 思维导图 → 分镜 → 画面描述。
|
|
413
|
+
* 每一步都把进度写进 job,面板轮询 /jobs 就能画进度条;任何非致命步骤失败只记 warning。
|
|
414
|
+
*/
|
|
415
|
+
async function runFullJob(job, helpers, { aiCtx, config, resolverFor }) {
|
|
416
|
+
const saved = await readSavedCredentials();
|
|
417
|
+
const settings = settingsFrom(config, saved);
|
|
418
|
+
const resolver = resolverFor(settings);
|
|
419
|
+
const signal = helpers.signal;
|
|
420
|
+
|
|
421
|
+
helpers.setStage('resolve', '正在解析视频信息…', 2);
|
|
422
|
+
let doc = job.docId ? resolver.cache.get(job.docId) : null;
|
|
423
|
+
if (!doc) {
|
|
424
|
+
// 只给了 docId(例如从历史里点「重新解析」)时,解析缓存可能已经过期,回历史里找链接。
|
|
425
|
+
let link = job.url;
|
|
426
|
+
if (!link && job.docId) {
|
|
427
|
+
const items = await readHistory().catch(() => []);
|
|
428
|
+
link = items.find((item) => item?.docId === job.docId)?.url ?? '';
|
|
429
|
+
}
|
|
430
|
+
if (!link) throw new VideoError('bad-url', '这个视频既不在解析缓存里,也没有可用的链接,请重新解析一次。');
|
|
431
|
+
job.url = link;
|
|
432
|
+
doc = await attachBestTranscript(await resolver.resolve(link));
|
|
433
|
+
}
|
|
434
|
+
job.docId = doc.docId;
|
|
435
|
+
job.url = doc.url;
|
|
436
|
+
job.title = doc.title;
|
|
437
|
+
await rememberDoc(doc);
|
|
438
|
+
helpers.setPercent(4);
|
|
439
|
+
|
|
440
|
+
if (!doc.transcript?.available && settings.asr?.enabled) {
|
|
441
|
+
helpers.setStage('transcript', '正在准备文字稿(语音 / 画面)…', 6);
|
|
442
|
+
doc.transcript = await transcribeVideo({
|
|
443
|
+
doc,
|
|
444
|
+
settings,
|
|
445
|
+
ai: aiCtx,
|
|
446
|
+
attachments: aiCtx.attachments,
|
|
447
|
+
signal,
|
|
448
|
+
onPhase: (text) => helpers.setStage('transcript', text, null),
|
|
449
|
+
onProgress: (event) => {
|
|
450
|
+
const mapped = progressBetween(6, 40, event?.percent);
|
|
451
|
+
if (mapped !== null) helpers.setPercent(mapped);
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
doc = (await attachBestTranscript(doc)) ?? doc;
|
|
455
|
+
helpers.setPercent(40);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
helpers.setStage('summary', '正在写总结…', 42);
|
|
459
|
+
const summary = await withRetry(
|
|
460
|
+
() => runSummary(aiCtx, settings, doc, { signal }),
|
|
461
|
+
{ signal },
|
|
462
|
+
);
|
|
463
|
+
await saveSummary(doc.docId, {
|
|
464
|
+
text: summary.text,
|
|
465
|
+
usage: summary.usage,
|
|
466
|
+
suggestions: summary.suggestions ?? [],
|
|
467
|
+
});
|
|
468
|
+
helpers.setPercent(58);
|
|
469
|
+
|
|
470
|
+
helpers.setStage('mindmap', '正在生成思维导图…', 60);
|
|
471
|
+
const mindmap = await withRetry(
|
|
472
|
+
() => runMindmap(aiCtx, settings, doc, { signal }),
|
|
473
|
+
{ signal },
|
|
474
|
+
);
|
|
475
|
+
if (mindmap?.mindmap) await saveMindmap(doc.docId, mindmap.mindmap);
|
|
476
|
+
helpers.setPercent(72);
|
|
477
|
+
|
|
478
|
+
helpers.setStage('storyboard', '正在抽帧、拼分镜…', 74);
|
|
479
|
+
try {
|
|
480
|
+
await generateStoryboard({
|
|
481
|
+
doc,
|
|
482
|
+
settings,
|
|
483
|
+
aiCtx,
|
|
484
|
+
frames: 0,
|
|
485
|
+
cols: 3,
|
|
486
|
+
describe: false,
|
|
487
|
+
signal,
|
|
488
|
+
onPhase: (text) => helpers.setStage('storyboard', text, null),
|
|
489
|
+
onProgress: (event) => {
|
|
490
|
+
const mapped = progressBetween(74, 90, event?.percent);
|
|
491
|
+
if (mapped !== null) helpers.setPercent(mapped);
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
} catch (error) {
|
|
495
|
+
if (error?.code === 'aborted' || signal.aborted) throw error;
|
|
496
|
+
helpers.warn(`分镜没生成:${error?.message ?? error}`);
|
|
497
|
+
}
|
|
498
|
+
helpers.setPercent(90);
|
|
499
|
+
|
|
500
|
+
if (job.describe) {
|
|
501
|
+
helpers.setStage('visuals', '正在让视觉模型描述画面…', 91);
|
|
502
|
+
try {
|
|
503
|
+
await generateOutlineVisuals({
|
|
504
|
+
doc,
|
|
505
|
+
docId: doc.docId,
|
|
506
|
+
settings,
|
|
507
|
+
aiCtx,
|
|
508
|
+
signal,
|
|
509
|
+
force: false,
|
|
510
|
+
onPhase: (text) => helpers.setStage('visuals', text, null),
|
|
511
|
+
onProgress: (event) => {
|
|
512
|
+
const mapped = progressBetween(91, 98, event?.percent);
|
|
513
|
+
if (mapped !== null) helpers.setPercent(mapped);
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
} catch (error) {
|
|
517
|
+
if (error?.code === 'aborted' || signal.aborted) throw error;
|
|
518
|
+
helpers.warn(`画面描述没生成:${error?.message ?? error}`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
await rememberDoc(doc);
|
|
523
|
+
await recordHistory(doc, 'analyze');
|
|
524
|
+
helpers.setPercent(99);
|
|
525
|
+
}
|
|
526
|
+
|
|
383
527
|
/* --------------------------------- tool ---------------------------------- */
|
|
384
528
|
|
|
385
529
|
function renderDocForTool(doc, maxChars) {
|
|
@@ -627,6 +771,12 @@ function createApiHandler(aiCtx, config) {
|
|
|
627
771
|
resolver = null;
|
|
628
772
|
};
|
|
629
773
|
|
|
774
|
+
// 后台解析队列:同一视频不重复排队,并发数可在 profile 的 jobs.concurrency 里调。
|
|
775
|
+
const jobQueue = createJobQueue({
|
|
776
|
+
concurrency: Number.isFinite(Number(config?.jobs?.concurrency)) ? Number(config?.jobs?.concurrency) : 0,
|
|
777
|
+
execute: (job, helpers) => runFullJob(job, helpers, { aiCtx, config, resolverFor }),
|
|
778
|
+
});
|
|
779
|
+
|
|
630
780
|
return async (req, res) => {
|
|
631
781
|
const url = new URL(req.url ?? '/', 'http://127.0.0.1');
|
|
632
782
|
const route = url.pathname.slice(API_PREFIX.length) || '/';
|
|
@@ -1045,6 +1195,9 @@ function createApiHandler(aiCtx, config) {
|
|
|
1045
1195
|
signature: outline.signature,
|
|
1046
1196
|
visuals: outline.visuals,
|
|
1047
1197
|
items: outline.items,
|
|
1198
|
+
hint: outline.source === 'uniform'
|
|
1199
|
+
? '这段视频还没有章节标题:生成思维导图(或 AI 章节)后会自动按内容切分。'
|
|
1200
|
+
: '',
|
|
1048
1201
|
},
|
|
1049
1202
|
});
|
|
1050
1203
|
return;
|
|
@@ -1384,6 +1537,81 @@ function createApiHandler(aiCtx, config) {
|
|
|
1384
1537
|
return;
|
|
1385
1538
|
}
|
|
1386
1539
|
|
|
1540
|
+
// 后台解析队列:开始 / 批量开始 / 进度 / 取消
|
|
1541
|
+
if (req.method === 'POST' && route === '/jobs') {
|
|
1542
|
+
const body = await readBody(req);
|
|
1543
|
+
try {
|
|
1544
|
+
const started = jobQueue.start({
|
|
1545
|
+
docId: String(body?.docId ?? '').trim(),
|
|
1546
|
+
url: String(body?.url ?? '').trim(),
|
|
1547
|
+
title: String(body?.title ?? '').trim(),
|
|
1548
|
+
describe: body?.describe !== false,
|
|
1549
|
+
});
|
|
1550
|
+
json(res, 200, { ok: true, value: started });
|
|
1551
|
+
} catch (error) {
|
|
1552
|
+
json(res, 200, { ok: false, code: error?.code ?? 'bad-param', error: String(error?.message ?? error) });
|
|
1553
|
+
}
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
if (req.method === 'GET' && route === '/jobs') {
|
|
1558
|
+
json(res, 200, { ok: true, value: jobQueue.list() });
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
if (req.method === 'POST' && route === '/jobs/all') {
|
|
1563
|
+
const body = await readBody(req).catch(() => ({}));
|
|
1564
|
+
try {
|
|
1565
|
+
const force = body?.force === true;
|
|
1566
|
+
const describe = body?.describe !== false;
|
|
1567
|
+
const limit = Math.max(1, Math.min(50, Number(body?.limit) || 20));
|
|
1568
|
+
const items = await readHistory();
|
|
1569
|
+
let started = 0;
|
|
1570
|
+
let skipped = 0;
|
|
1571
|
+
for (const item of items) {
|
|
1572
|
+
if (!item?.url) continue;
|
|
1573
|
+
if (started >= limit) break;
|
|
1574
|
+
if (!force) {
|
|
1575
|
+
const [analysis, storyboard] = await Promise.all([
|
|
1576
|
+
readAnalysis(item.docId).catch(() => null),
|
|
1577
|
+
readStoryboard(item.docId).catch(() => null),
|
|
1578
|
+
]);
|
|
1579
|
+
if (analysis?.summary && analysis?.mindmap && storyboard) {
|
|
1580
|
+
skipped += 1;
|
|
1581
|
+
continue;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
if (jobQueue.isActive(item.docId)) {
|
|
1585
|
+
skipped += 1;
|
|
1586
|
+
continue;
|
|
1587
|
+
}
|
|
1588
|
+
const result = jobQueue.start({ docId: item.docId, url: item.url, title: item.title, describe });
|
|
1589
|
+
if (result.created) started += 1;
|
|
1590
|
+
else skipped += 1;
|
|
1591
|
+
}
|
|
1592
|
+
json(res, 200, { ok: true, value: { started, skipped, jobs: jobQueue.list() } });
|
|
1593
|
+
} catch (error) {
|
|
1594
|
+
json(res, 200, { ok: false, code: error?.code ?? 'internal', error: String(error?.message ?? error) });
|
|
1595
|
+
}
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
if (req.method === 'POST' && route === '/jobs/cancel') {
|
|
1600
|
+
const body = await readBody(req);
|
|
1601
|
+
const cancelled = jobQueue.cancel({
|
|
1602
|
+
id: String(body?.id ?? '').trim(),
|
|
1603
|
+
docId: String(body?.docId ?? '').trim(),
|
|
1604
|
+
});
|
|
1605
|
+
json(res, 200, { ok: true, value: { cancelled, jobs: jobQueue.list() } });
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
if (req.method === 'POST' && route === '/jobs/clear') {
|
|
1610
|
+
jobQueue.clearFinished();
|
|
1611
|
+
json(res, 200, { ok: true, value: jobQueue.list() });
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1387
1615
|
if (req.method === 'POST' && route === '/credentials') {
|
|
1388
1616
|
const body = await readBody(req);
|
|
1389
1617
|
const next = { ...saved };
|
package/lib/jobs.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 后台解析队列。
|
|
3
|
+
*
|
|
4
|
+
* 一次「解析」不只是总结:转写(没字幕时)→ 总结 → 思维导图 → 分镜 → 画面描述
|
|
5
|
+
* 全部按顺序跑完,进度存在内存里,面板轮询 GET /jobs 拿进度条。
|
|
6
|
+
* 并发数默认 2(可在 profile 配置里调),同一视频不会重复排队。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const DEFAULT_CONCURRENCY = 0;
|
|
10
|
+
const MAX_RECORDS = 80;
|
|
11
|
+
const ACTIVE = new Set(['queued', 'running']);
|
|
12
|
+
|
|
13
|
+
function clean(value, max = 200) {
|
|
14
|
+
return String(value ?? '').replace(/\s+/g, ' ').trim().slice(0, max);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function snapshot(job) {
|
|
18
|
+
return {
|
|
19
|
+
id: job.id,
|
|
20
|
+
docId: job.docId || '',
|
|
21
|
+
url: job.url || '',
|
|
22
|
+
title: clean(job.title, 160),
|
|
23
|
+
status: job.status,
|
|
24
|
+
stage: job.stage,
|
|
25
|
+
stageLabel: job.stageLabel,
|
|
26
|
+
percent: job.percent,
|
|
27
|
+
describe: Boolean(job.describe),
|
|
28
|
+
error: job.error,
|
|
29
|
+
warnings: job.warnings.slice(0, 8),
|
|
30
|
+
queuedAt: job.queuedAt,
|
|
31
|
+
startedAt: job.startedAt,
|
|
32
|
+
finishedAt: job.finishedAt,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {object} options
|
|
38
|
+
* @param {number} [options.concurrency] 同时跑几个任务
|
|
39
|
+
* @param {(job: object, helpers: object) => Promise<void>} options.execute 真正干活
|
|
40
|
+
*/
|
|
41
|
+
export function createJobQueue({ concurrency = DEFAULT_CONCURRENCY, execute } = {}) {
|
|
42
|
+
// 0 = 不限制:提交几个就跑几个(默认就是不限,LLM 步骤自带重试,压不住的失败会记在任务里)。
|
|
43
|
+
const requested = Math.round(Number(concurrency));
|
|
44
|
+
const limit = Number.isFinite(requested) && requested >= 0 ? Math.min(16, requested) : DEFAULT_CONCURRENCY;
|
|
45
|
+
const jobs = new Map();
|
|
46
|
+
const queue = [];
|
|
47
|
+
let running = 0;
|
|
48
|
+
let seq = 0;
|
|
49
|
+
|
|
50
|
+
function trim() {
|
|
51
|
+
if (jobs.size <= MAX_RECORDS) return;
|
|
52
|
+
const finished = [...jobs.values()]
|
|
53
|
+
.filter((job) => !ACTIVE.has(job.status))
|
|
54
|
+
.sort((a, b) => a.queuedAt - b.queuedAt);
|
|
55
|
+
while (jobs.size > MAX_RECORDS && finished.length) {
|
|
56
|
+
jobs.delete(finished.shift().id);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function finish(job, status, error) {
|
|
61
|
+
job.status = status;
|
|
62
|
+
job.finishedAt = Date.now();
|
|
63
|
+
if (error) job.error = clean(error?.message ?? error, 300);
|
|
64
|
+
if (status === 'done') job.percent = 100;
|
|
65
|
+
job.stageLabel = status === 'done' ? '已完成' : status === 'failed' ? '解析失败' : job.stageLabel;
|
|
66
|
+
trim();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function pump() {
|
|
70
|
+
while ((limit <= 0 || running < limit) && queue.length) {
|
|
71
|
+
const job = queue.shift();
|
|
72
|
+
if (!job || job.status !== 'queued') continue;
|
|
73
|
+
job.status = 'running';
|
|
74
|
+
job.startedAt = Date.now();
|
|
75
|
+
job.stage = 'resolve';
|
|
76
|
+
job.stageLabel = '正在解析视频信息…';
|
|
77
|
+
job.percent = 1;
|
|
78
|
+
running += 1;
|
|
79
|
+
|
|
80
|
+
const controller = new AbortController();
|
|
81
|
+
job.controller = controller;
|
|
82
|
+
const helpers = {
|
|
83
|
+
signal: controller.signal,
|
|
84
|
+
isCancelled: () => job.status === 'cancelled' || controller.signal.aborted,
|
|
85
|
+
setStage(stage, label, percent) {
|
|
86
|
+
if (job.status === 'cancelled') return;
|
|
87
|
+
if (stage) job.stage = stage;
|
|
88
|
+
if (label) job.stageLabel = clean(label, 120);
|
|
89
|
+
if (typeof percent === 'number' && Number.isFinite(percent)) {
|
|
90
|
+
job.percent = Math.max(1, Math.min(99, Math.round(percent)));
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
setPercent(percent) {
|
|
94
|
+
if (job.status === 'cancelled') return;
|
|
95
|
+
if (typeof percent === 'number' && Number.isFinite(percent)) {
|
|
96
|
+
job.percent = Math.max(1, Math.min(99, Math.round(percent)));
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
warn(message) {
|
|
100
|
+
const text = clean(message, 160);
|
|
101
|
+
if (text && !job.warnings.includes(text)) job.warnings.push(text);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
Promise.resolve()
|
|
106
|
+
.then(() => execute(job, helpers))
|
|
107
|
+
.then(() => {
|
|
108
|
+
if (job.status === 'running') finish(job, 'done');
|
|
109
|
+
})
|
|
110
|
+
.catch((error) => {
|
|
111
|
+
if (job.status === 'cancelled' || error?.name === 'AbortError' || error?.code === 'aborted') {
|
|
112
|
+
finish(job, 'cancelled');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
finish(job, 'failed', error);
|
|
116
|
+
})
|
|
117
|
+
.finally(() => {
|
|
118
|
+
running -= 1;
|
|
119
|
+
pump();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
concurrency: limit,
|
|
126
|
+
/** 启动一个任务;同一视频已有排队/运行中的任务时直接返回那一个。 */
|
|
127
|
+
start({ docId = '', url = '', title = '', describe = true } = {}) {
|
|
128
|
+
const id = String(docId ?? '').trim();
|
|
129
|
+
const link = String(url ?? '').trim();
|
|
130
|
+
if (!id && !link) throw new Error('需要 docId 或 url');
|
|
131
|
+
for (const job of jobs.values()) {
|
|
132
|
+
if (!ACTIVE.has(job.status)) continue;
|
|
133
|
+
if ((id && job.docId === id) || (!id && link && job.url === link)) return { job: snapshot(job), created: false };
|
|
134
|
+
}
|
|
135
|
+
seq += 1;
|
|
136
|
+
const job = {
|
|
137
|
+
id: `job-${Date.now().toString(36)}-${seq}`,
|
|
138
|
+
docId: id,
|
|
139
|
+
url: link,
|
|
140
|
+
title: clean(title, 160),
|
|
141
|
+
status: 'queued',
|
|
142
|
+
stage: 'queued',
|
|
143
|
+
stageLabel: '排队中…',
|
|
144
|
+
percent: 0,
|
|
145
|
+
describe: describe !== false,
|
|
146
|
+
error: '',
|
|
147
|
+
warnings: [],
|
|
148
|
+
queuedAt: Date.now(),
|
|
149
|
+
startedAt: 0,
|
|
150
|
+
finishedAt: 0,
|
|
151
|
+
controller: null,
|
|
152
|
+
};
|
|
153
|
+
jobs.set(job.id, job);
|
|
154
|
+
queue.push(job);
|
|
155
|
+
trim();
|
|
156
|
+
pump();
|
|
157
|
+
return { job: snapshot(job), created: true };
|
|
158
|
+
},
|
|
159
|
+
/** 取消排队中或运行中的任务。 */
|
|
160
|
+
cancel({ id = '', docId = '' } = {}) {
|
|
161
|
+
const key = String(id ?? '').trim();
|
|
162
|
+
const target = String(docId ?? '').trim();
|
|
163
|
+
let cancelled = 0;
|
|
164
|
+
for (const job of jobs.values()) {
|
|
165
|
+
if (!ACTIVE.has(job.status)) continue;
|
|
166
|
+
if (key ? job.id !== key : job.docId !== target) continue;
|
|
167
|
+
job.status = 'cancelled';
|
|
168
|
+
job.stageLabel = '已取消';
|
|
169
|
+
job.finishedAt = Date.now();
|
|
170
|
+
try {
|
|
171
|
+
job.controller?.abort();
|
|
172
|
+
} catch {
|
|
173
|
+
/* ignore */
|
|
174
|
+
}
|
|
175
|
+
cancelled += 1;
|
|
176
|
+
}
|
|
177
|
+
pump();
|
|
178
|
+
return cancelled;
|
|
179
|
+
},
|
|
180
|
+
/** 清掉已结束的记录。 */
|
|
181
|
+
clearFinished() {
|
|
182
|
+
for (const [id, job] of jobs) {
|
|
183
|
+
if (!ACTIVE.has(job.status)) jobs.delete(id);
|
|
184
|
+
}
|
|
185
|
+
return this.list().jobs.length;
|
|
186
|
+
},
|
|
187
|
+
list() {
|
|
188
|
+
const all = [...jobs.values()]
|
|
189
|
+
.sort((a, b) => b.queuedAt - a.queuedAt)
|
|
190
|
+
.slice(0, MAX_RECORDS)
|
|
191
|
+
.map(snapshot);
|
|
192
|
+
return {
|
|
193
|
+
concurrency: limit,
|
|
194
|
+
active: all.filter((job) => ACTIVE.has(job.status)).length,
|
|
195
|
+
running: all.filter((job) => job.status === 'running').length,
|
|
196
|
+
jobs: all,
|
|
197
|
+
};
|
|
198
|
+
},
|
|
199
|
+
isActive(docId) {
|
|
200
|
+
for (const job of jobs.values()) {
|
|
201
|
+
if (job.docId === docId && ACTIVE.has(job.status)) return true;
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
package/lib/outline.js
CHANGED
|
@@ -99,7 +99,7 @@ function uniformItems(duration, count = 8) {
|
|
|
99
99
|
for (let index = 0; index < total; index += 1) {
|
|
100
100
|
items.push({
|
|
101
101
|
seconds: Math.round((duration * (index + 0.5)) / total * 10) / 10,
|
|
102
|
-
title:
|
|
102
|
+
title: `片段 ${index + 1}`,
|
|
103
103
|
detail: [],
|
|
104
104
|
});
|
|
105
105
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-video-insight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "在 DeepSeek Harness 里快速分析视频:左侧栏「视频解析」面板,粘贴 YouTube / 哔哩哔哩链接,自动抓字幕并生成总结、章节、要点、原文与追问;无字幕时可用本机 Whisper / SenseVoice 转写兜底(音频不出本机),纯无声视频还能用画面文字识别(OCR)或视觉模型描述画面;右栏有 AI 思维导图;追问是基于转写稿的 RAG 问答(回答带「依据」时间戳);分析结果按视频缓存,历史记录可回看。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jerry (Azerz)",
|