dsh-watch-together 0.2.2 → 0.2.4
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/CHANGELOG.md +1317 -1229
- package/README.md +21 -1
- package/docs/INTERFACES.zh.md +17 -0
- package/docs/images/reward-qr.png +0 -0
- package/dsh.plugin.json +12 -12
- package/examples/floating-chat/glass_window.py +9 -1
- package/examples/floating-chat/glass_window_gpu.py +16 -7
- package/examples/floating-chat/window.py +447 -74
- package/package.json +115 -111
- package/src/chat-store.js +17 -10
- package/src/handler.js +11 -1
- package/src/index.js +5 -5
- package/src/input-surface.js +13 -12
- package/src/interfaces.js +8 -2
- package/src/public-api.js +6 -0
- package/src/runtime-ports.js +45 -0
- package/src/watch-actions.js +177 -173
- package/src/watch-loop.js +13 -10
- package/src/watch-run.js +5 -5
- package/src/window-interface.js +21 -13
package/src/watch-actions.js
CHANGED
|
@@ -1,173 +1,177 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* watch-actions.js — `watch_together` 的**单发命令**:不进主流程,一问一答就结束。
|
|
3
|
-
*
|
|
4
|
-
* 从 index.js 拆出来的。这些东西放在工具注册函数里,会把"注册五个工具"这件事淹掉,
|
|
5
|
-
* 而且它们各自回答的是不同的运维问题:
|
|
6
|
-
*
|
|
7
|
-
* stopLoop 停钟(唯一一个"只写不读"的命令)
|
|
8
|
-
* statusOnly 钟在哪、浏览器在不在 —— **只问不建**,排查"它为什么没反应"的第一站
|
|
9
|
-
* checkCookies B 站登录态 / 字幕可用性 —— 能立刻回答"为什么还在用 ASR"
|
|
10
|
-
* testWake 5 秒内回答"loop 到底叫不叫得醒我"
|
|
11
|
-
*
|
|
12
|
-
* **没有语音相关的命令**:核心不发声,念不念由订了 `speech` 事件的那一方决定
|
|
13
|
-
* (见 voice.js 和 README 的「接声音」)。
|
|
14
|
-
*
|
|
15
|
-
* 返回 `null` 表示"这一轮不是单发命令",交给主流程。**判据在调用方之外只有这一条**。
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { configuredPort, probeBrowser } from 'dsh-video-storyboard/browser-time';
|
|
19
|
-
import { checkBiliLogin, fetchRemoteSubtitles } from 'dsh-video-storyboard/subtitles';
|
|
20
|
-
import { explainCuesFailure, loadCues, sentencesBetween } from './lines-util.js';
|
|
21
|
-
import { linesOverview } from './watch-lines.js';
|
|
22
|
-
import { markMaterial, materialNote } from './watch-material.js';
|
|
23
|
-
import { controllerOf, wakeSession } from './timer.js';
|
|
24
|
-
import { loopStatus, stopWatchLoop } from './watch-loop.js';
|
|
25
|
-
import { appendAssistantSay } from './chat.js';
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
1
|
+
/**
|
|
2
|
+
* watch-actions.js — `watch_together` 的**单发命令**:不进主流程,一问一答就结束。
|
|
3
|
+
*
|
|
4
|
+
* 从 index.js 拆出来的。这些东西放在工具注册函数里,会把"注册五个工具"这件事淹掉,
|
|
5
|
+
* 而且它们各自回答的是不同的运维问题:
|
|
6
|
+
*
|
|
7
|
+
* stopLoop 停钟(唯一一个"只写不读"的命令)
|
|
8
|
+
* statusOnly 钟在哪、浏览器在不在 —— **只问不建**,排查"它为什么没反应"的第一站
|
|
9
|
+
* checkCookies B 站登录态 / 字幕可用性 —— 能立刻回答"为什么还在用 ASR"
|
|
10
|
+
* testWake 5 秒内回答"loop 到底叫不叫得醒我"
|
|
11
|
+
*
|
|
12
|
+
* **没有语音相关的命令**:核心不发声,念不念由订了 `speech` 事件的那一方决定
|
|
13
|
+
* (见 voice.js 和 README 的「接声音」)。
|
|
14
|
+
*
|
|
15
|
+
* 返回 `null` 表示"这一轮不是单发命令",交给主流程。**判据在调用方之外只有这一条**。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { configuredPort, probeBrowser } from 'dsh-video-storyboard/browser-time';
|
|
19
|
+
import { checkBiliLogin, fetchRemoteSubtitles } from 'dsh-video-storyboard/subtitles';
|
|
20
|
+
import { explainCuesFailure, loadCues, sentencesBetween } from './lines-util.js';
|
|
21
|
+
import { linesOverview } from './watch-lines.js';
|
|
22
|
+
import { markMaterial, materialNote } from './watch-material.js';
|
|
23
|
+
import { controllerOf, wakeSession } from './timer.js';
|
|
24
|
+
import { loopStatus, stopWatchLoop } from './watch-loop.js';
|
|
25
|
+
import { appendAssistantSay } from './chat.js';
|
|
26
|
+
import { getTtsPort, getWindowPort } from './runtime-ports.js';
|
|
27
|
+
import { mmss } from './time.js';
|
|
28
|
+
|
|
29
|
+
export async function runWatchAction(args, {
|
|
30
|
+
ctx = null, sessionId = null, browserPort, tts = null, window: windowService = null,
|
|
31
|
+
} = {}) {
|
|
32
|
+
const ttsPort = tts ?? getTtsPort();
|
|
33
|
+
const winPort = windowService ?? getWindowPort();
|
|
34
|
+
// 模型插话时说的那一句:写进统一流 + 交给声音。不占图片、不等位置,所以排在所有单发命令最前面。
|
|
35
|
+
if (typeof args.say === 'string' && args.say.trim()) {
|
|
36
|
+
const entry = appendAssistantSay(args.say, { t: ttsPort.last()?.at ?? null });
|
|
37
|
+
return { text: JSON.stringify({ ok: true, said: entry?.text ?? '', inChat: true }), images: [] };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// `stop` 是别名:用户说"停止一起看"时,模型第一反应就是敲 stop
|
|
41
|
+
if (args.stopLoop === true || args.stop === true) {
|
|
42
|
+
return { text: JSON.stringify(stopWatchLoop('requested')), images: [] };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// **藏起来 / 放出来**:和关窗是两件事(关窗 = 不看了,会停表;藏起来 = 陪看继续)。
|
|
46
|
+
// 用户的原话是"如果有其他功能隐藏悬浮窗会更好"(2026-11-01)—— 他嫌它挡画面,
|
|
47
|
+
// 但并不想结束陪看。窗口进程不动,只写一个配置键,窗口自己每 200ms 读一次。
|
|
48
|
+
if (args.window === 'hide' || args.window === 'show') {
|
|
49
|
+
const want = args.window === 'hide';
|
|
50
|
+
const r = want ? winPort.hide() : winPort.show();
|
|
51
|
+
// 接口实现可以返回 {ok,reason}(自带窗口),也可以只返回 boolean(简单 transport)。
|
|
52
|
+
if (r !== true && r?.ok !== true) {
|
|
53
|
+
return {
|
|
54
|
+
images: [],
|
|
55
|
+
text: `[window] ${r?.reason === 'window-not-open'
|
|
56
|
+
? '悬浮窗没开着,没什么可藏的'
|
|
57
|
+
: r?.reason === 'disabled'
|
|
58
|
+
? '这台机器关掉了悬浮窗(DSH_WATCH_NO_WIDGET=1)'
|
|
59
|
+
: `切不过去(${r?.reason})`}。`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// 藏起来之后用户看不见窗口,所以这句话只能靠 `say` 进流 —— 让它自己说一句
|
|
63
|
+
return {
|
|
64
|
+
images: [],
|
|
65
|
+
text: `[window] 悬浮窗已${want ? '藏起来(陪看继续,位置照跟、台词照念)' : '放出来'}。`
|
|
66
|
+
+ '别调 stop,也别当成"用户不看了" —— 关窗才是那个意思。',
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// **只取字幕**:图和字幕要拆开返回时走这条(`transcript: true`)。
|
|
71
|
+
// 台词需要的是"句子 + 它的真实秒数",两样字幕里都有;图另一次给。
|
|
72
|
+
// 这里顺带记下"字幕这一半已经交到模型手里了",交付时才敢说"素材齐了,写台词"。
|
|
73
|
+
if (args.transcriptOnly === true || args.transcript === true) {
|
|
74
|
+
const input = typeof args.input === 'string' ? args.input : '';
|
|
75
|
+
if (!input) return { text: '[transcriptOnly] 需要 `input`(视频链接或路径)', images: [] };
|
|
76
|
+
const size = Number(args.size) > 0
|
|
77
|
+
? Number(args.size)
|
|
78
|
+
: (Number(args.segment) > 0 ? Number(args.segment) : 120);
|
|
79
|
+
const from = Number.isFinite(Number(args.from)) ? Number(args.from) : null;
|
|
80
|
+
if (from === null) {
|
|
81
|
+
return {
|
|
82
|
+
text: '[transcriptOnly] 需要 `from`(这一段从第几秒开始)。不知道就先用 statusOnly 看当前段。',
|
|
83
|
+
images: [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// 只取这一段窗口的 cue:没有 CC 字幕时 `loadCues` 会走 ASR,只转写这一段才有意义
|
|
87
|
+
// (不传窗口就永远只转 0–30 秒,后面的段全拿不到时间码)。
|
|
88
|
+
const cuesRes = await loadCues(input, { start: from, end: from + size })
|
|
89
|
+
.catch((e) => ({ ok: false, reason: String(e?.message ?? e) }));
|
|
90
|
+
if (!cuesRes.ok) {
|
|
91
|
+
return {
|
|
92
|
+
text: `[transcriptOnly] 拿不到台词(${cuesRes.reason})。`
|
|
93
|
+
+ explainCuesFailure(cuesRes.reason, cuesRes.detail)
|
|
94
|
+
+ '\n如果用户问"你为什么听不到声音",就照上面这句回答(**别只说"我听不到"**:'
|
|
95
|
+
+ '他们以为插件坏了,其实是缺一步配置)。'
|
|
96
|
+
+ '\n还能用的:带图交付里每格下面那行转写 —— 它和这里是同一批句子。别凭印象写 `at`。',
|
|
97
|
+
images: [],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const max = Number(args.max) > 0 ? Number(args.max) : 10;
|
|
101
|
+
const sents = sentencesBetween(cuesRes.cues, from, from + size).slice(0, max);
|
|
102
|
+
const mat = await markMaterial(input, from, 'transcript').catch(() => null);
|
|
103
|
+
const body = sents.map((s) => `${s.at.toFixed(1)}\t${s.text}`).join('\n');
|
|
104
|
+
return {
|
|
105
|
+
text: `段 ${mmss(from)}–${mmss(from + size)}|字幕 ${sents.length} 句(每行:秒数 + 句子)\n${body}`
|
|
106
|
+
+ (mat ? materialNote(mat) : '')
|
|
107
|
+
+ `\n写台词:\`watch_together({ lines: [{ from: ${from}, at: <上面那个秒数>, text: "…" }] })\``,
|
|
108
|
+
images: [],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 只看钟的状态,不读进度、不出图 —— 排查"它为什么不说话"时用。
|
|
113
|
+
// **顺带报浏览器状态**:这是唯一一个"只问不建"的入口,模型想知道
|
|
114
|
+
// "浏览器到底开着没"的时候应该走这里,而不是拿播放位置去倒推。
|
|
115
|
+
if (args.statusOnly === true) {
|
|
116
|
+
const bp = browserPort ?? configuredPort() ?? null;
|
|
117
|
+
const browser = bp
|
|
118
|
+
? await probeBrowser({ port: bp }).catch(() => ({ state: 'error', port: bp }))
|
|
119
|
+
: { state: 'unconfigured', port: null };
|
|
120
|
+
const st = loopStatus();
|
|
121
|
+
// **台词队列深度要读盘才准**(watch.json 里的 lines)。只在诊断入口付这个成本,
|
|
122
|
+
// 循环每 2 秒读一次不值得;`queued: null` 表示"没算",不是 0。
|
|
123
|
+
if (st.input) {
|
|
124
|
+
try {
|
|
125
|
+
const ov = await linesOverview(st.input);
|
|
126
|
+
if (Array.isArray(ov)) {
|
|
127
|
+
st.speech.queued = ov.reduce((n, x) => n + (Number(x.count) || 0), 0);
|
|
128
|
+
st.speech.segmentsWithLines = ov.length;
|
|
129
|
+
}
|
|
130
|
+
} catch (e) {
|
|
131
|
+
// **别静默**:这个 catch 第一次就吞掉了一个 ReferenceError(漏 import),
|
|
132
|
+
// 结果只是"queued 一直是 null",看起来像"没有台词"。错因要报出来。
|
|
133
|
+
st.speech.queued = null;
|
|
134
|
+
st.speech.queueError = String(e?.message ?? e).slice(0, 120);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { text: JSON.stringify({ ...st, browser }, null, 1), images: [] };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 检查 B 站登录态与字幕可用性:这一条能立刻回答"为什么还在用 ASR"
|
|
141
|
+
if (args.checkCookies === true) {
|
|
142
|
+
const login = await checkBiliLogin({ cookies: args.cookies });
|
|
143
|
+
const url = typeof args.input === 'string' && /^https?:/i.test(args.input) ? args.input : null;
|
|
144
|
+
const subs = url ? await fetchRemoteSubtitles({ url, cookies: args.cookies }) : null;
|
|
145
|
+
return {
|
|
146
|
+
text: JSON.stringify({
|
|
147
|
+
login,
|
|
148
|
+
subtitles: subs
|
|
149
|
+
? { ok: subs.ok, reason: subs.reason, count: subs.segments?.length ?? 0, lang: subs.lang }
|
|
150
|
+
: 'pass a video URL in input to check subtitles',
|
|
151
|
+
}),
|
|
152
|
+
images: [],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 立刻试一次唤醒,把结果原样报出来。这一条能 5 秒内回答"loop 到底叫不叫得醒我"。
|
|
157
|
+
if (args.testWake === true) {
|
|
158
|
+
const r = await wakeSession(ctx, {
|
|
159
|
+
sessionId,
|
|
160
|
+
text: '[一起看] 这是一次唤醒连通性测试,收到就不用回复内容,回一句"收到"即可。',
|
|
161
|
+
});
|
|
162
|
+
// **不能写 `ctx.sessionController`**:没 inject 的服务取它会直接抛错
|
|
163
|
+
const sc = controllerOf(ctx);
|
|
164
|
+
return {
|
|
165
|
+
text: JSON.stringify({
|
|
166
|
+
sessionId: sessionId ?? null,
|
|
167
|
+
hasSessionController: Boolean(sc),
|
|
168
|
+
hasResolveAgent: typeof sc?.resolveAgent === 'function',
|
|
169
|
+
...r,
|
|
170
|
+
}),
|
|
171
|
+
images: [],
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
package/src/watch-loop.js
CHANGED
|
@@ -20,9 +20,9 @@ import { startTicker, wakeSession } from './timer.js';
|
|
|
20
20
|
import { DEFAULT_LOOKAHEAD, DEFAULT_SEGMENT, describePlan, makePlan, windowFor } from './batches.js';
|
|
21
21
|
import { readBrowserPosition, looksLikeVideoUrl } from 'dsh-video-storyboard/browser-time';
|
|
22
22
|
import { readBridge } from './position-bridge.js';
|
|
23
|
-
import {
|
|
23
|
+
import { getTtsPort, getWindowPort } from './runtime-ports.js';
|
|
24
24
|
import { readPositionOrNull } from './watch-browser.js';
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
import { speechSeconds } from './speech.js';
|
|
27
27
|
import { consumeLine, dueLine, hasLine, loadLine, WATCH_LEAD } from './watch.js';
|
|
28
28
|
import { mmss } from './time.js';
|
|
@@ -257,7 +257,7 @@ export function loopStatus() {
|
|
|
257
257
|
},
|
|
258
258
|
// 声音:核心只发事件。listeners = 0 表示"没人接声音",到点的词会改走叫醒模型。
|
|
259
259
|
voice: {
|
|
260
|
-
listeners: loop.voiceListeners ? loop.voiceListeners() :
|
|
260
|
+
listeners: loop.voiceListeners ? loop.voiceListeners() : getTtsPort().subscribers(),
|
|
261
261
|
lastAt: loop.lastSpeechAt ?? null,
|
|
262
262
|
},
|
|
263
263
|
pos: est ? +est.pos.toFixed(1) : null,
|
|
@@ -307,8 +307,10 @@ export function startWatchLoop({
|
|
|
307
307
|
lead = WATCH_LEAD,
|
|
308
308
|
// 段缓存(可选):只用于 `statusOnly` 里报"缓存里已有几段",不参与任何决策
|
|
309
309
|
cache = null,
|
|
310
|
-
// TTS
|
|
310
|
+
// TTS / 窗口接口可注入(handler 传 api.tts / api.window);
|
|
311
|
+
// 不传时由 runtime-ports 提供默认适配器。
|
|
311
312
|
tts: ttsOption = null,
|
|
313
|
+
window: windowOption = null,
|
|
312
314
|
// 依赖可注入:进程内默认真实实现;测试/仿真用假的,于是"到点会不会说话"可以离线验证
|
|
313
315
|
deps = {},
|
|
314
316
|
// **到点是否往会话里投一条消息把人叫醒**。默认**关**。
|
|
@@ -339,12 +341,12 @@ export function startWatchLoop({
|
|
|
339
341
|
// 关掉时给一个**不会报错**的空实现:所有调用点照旧,但什么都不发
|
|
340
342
|
: async () => ({ ok: true, via: 'disabled' });
|
|
341
343
|
const now = deps.now ?? (() => Date.now());
|
|
342
|
-
// TTS
|
|
343
|
-
//
|
|
344
|
-
const tts = deps.tts ?? ttsOption ??
|
|
345
|
-
const listeners = () =>
|
|
344
|
+
// TTS 只走接口:没有注入时由 runtime-ports 提供默认适配器,
|
|
345
|
+
// 循环本身不再 import voice.js,也不再有第二条 fallback 路径。
|
|
346
|
+
const tts = deps.tts ?? ttsOption ?? getTtsPort();
|
|
347
|
+
const listeners = () => tts.subscribers();
|
|
346
348
|
loop.voiceListeners = listeners;
|
|
347
|
-
const speak = (event) =>
|
|
349
|
+
const speak = (event) => tts.due(event);
|
|
348
350
|
const ticker = deps.ticker ?? startTicker;
|
|
349
351
|
const readLatency = deps.loadLatency ?? loadLatency;
|
|
350
352
|
// 读进度的间隔可注入:真机 15 秒够了(读一次 CDP 是毫秒级,主要是别太频繁);
|
|
@@ -377,7 +379,8 @@ export function startWatchLoop({
|
|
|
377
379
|
// 扩展上报的位置(本地一个小 JSON)。可注入:测试里不该读到这台机器上真实的播放位置。
|
|
378
380
|
const readPosBridge = deps.readBridge ?? ((o) => readBridge(o));
|
|
379
381
|
// 窗口"还开着吗"也可注入:真机用 pid 判活,测试里给个假的
|
|
380
|
-
const windowAlive = deps.windowAlive
|
|
382
|
+
const windowAlive = deps.windowAlive
|
|
383
|
+
?? (() => (deps.window ?? windowOption ?? getWindowPort()).alive());
|
|
381
384
|
// 插话唤醒走**真**的 followup(不受 `wake: false` 影响);可注入便于测试
|
|
382
385
|
const chatWatcher = deps.chatWatcher ?? (() => chatWatcherShared());
|
|
383
386
|
const chatWake = deps.wakeChat ?? ((c, o) => wakeSession(c, o));
|
package/src/watch-run.js
CHANGED
|
@@ -21,9 +21,8 @@ import {
|
|
|
21
21
|
deliveryState, loadWatch, pruneSlot, readSlot, saveWatch,
|
|
22
22
|
sessionKey, WATCH_LEAD,
|
|
23
23
|
} from './watch.js';
|
|
24
|
-
import { floatingWindowAlive } from './floating-window.js';
|
|
25
24
|
import { markMaterial, materialNote, materialState } from './watch-material.js';
|
|
26
|
-
import { speechEvents } from './
|
|
25
|
+
import { speechEvents } from './speech-bus.js';
|
|
27
26
|
import { appendChat, appendSpoken } from './chat.js';
|
|
28
27
|
import { describeLatency, aheadSeconds, loadLatency, recordLatency } from './latency.js';
|
|
29
28
|
import { DEFAULT_LOOKAHEAD, DEFAULT_SEGMENT, makePlan, windowFor } from './batches.js';
|
|
@@ -303,13 +302,14 @@ export async function runWatchPass(args, deps) {
|
|
|
303
302
|
signal = null,
|
|
304
303
|
/** 进入阻塞前的准备(起聊天服务 + 开悬浮窗)。只有真要走 wait 才回调它 */
|
|
305
304
|
prepareWait = null,
|
|
306
|
-
/** 窗口"还开着吗"
|
|
307
|
-
windowAlive =
|
|
305
|
+
/** 窗口"还开着吗"(必须由调用方/接口注入;没有就不启用关窗即收工) */
|
|
306
|
+
windowAlive = null,
|
|
308
307
|
/** 这次真的开过窗吗 —— 只有开过才知道"关掉"是什么意思 */
|
|
309
308
|
expectWindow = false,
|
|
310
309
|
} = deps;
|
|
311
310
|
// 关窗即收工:等待期间用户把悬浮窗关了,就别再挂着(他没有插话入口了)
|
|
312
|
-
const windowGone = () => expectWindow === true
|
|
311
|
+
const windowGone = () => expectWindow === true
|
|
312
|
+
&& typeof windowAlive === 'function' && windowAlive() !== true;
|
|
313
313
|
// 从"开始读进度"到"结果返回"的耗时 —— 这就是本机延迟的实测值,用来做提前量标定
|
|
314
314
|
const tStart = Date.now();
|
|
315
315
|
tStartForNote = tStart;
|
package/src/window-interface.js
CHANGED
|
@@ -56,23 +56,31 @@ export function createWindowInterface({ transport = null } = {}) {
|
|
|
56
56
|
hidden() {
|
|
57
57
|
return t.hidden();
|
|
58
58
|
},
|
|
59
|
-
message(entry) {
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
message(entry, env = process.env) {
|
|
60
|
+
return typeof t.message === 'function'
|
|
61
|
+
? t.message(entry, env)
|
|
62
|
+
: appendWindowEvent({ type: 'message', ...entry }, env);
|
|
63
|
+
},
|
|
64
|
+
meta(text, extra = {}, env = process.env) {
|
|
65
|
+
return typeof t.meta === 'function'
|
|
66
|
+
? t.meta(text, extra, env)
|
|
67
|
+
: appendWindowEvent({ type: 'meta', text, ...extra }, env);
|
|
68
|
+
},
|
|
69
|
+
control(action, value = null, env = process.env) {
|
|
70
|
+
return typeof t.control === 'function'
|
|
71
|
+
? t.control(action, value, env)
|
|
72
|
+
: appendWindowEvent({ type: 'control', action, value }, env);
|
|
73
|
+
},
|
|
74
|
+
tts(event, env = process.env) {
|
|
75
|
+
return typeof t.tts === 'function'
|
|
76
|
+
? t.tts(event, env)
|
|
77
|
+
: appendWindowEvent({ type: 'tts', ...event }, env);
|
|
70
78
|
},
|
|
71
79
|
actions(env = process.env) {
|
|
72
|
-
return readWindowActions(env);
|
|
80
|
+
return typeof t.actions === 'function' ? t.actions(env) : readWindowActions(env);
|
|
73
81
|
},
|
|
74
82
|
accept(action, env = process.env) {
|
|
75
|
-
return appendWindowAction(action, env);
|
|
83
|
+
return typeof t.accept === 'function' ? t.accept(action, env) : appendWindowAction(action, env);
|
|
76
84
|
},
|
|
77
85
|
status() {
|
|
78
86
|
return { alive: Boolean(t.alive()), hidden: Boolean(t.hidden()) };
|