dsh-duet 0.1.2 → 0.1.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 +7 -6
- package/package.json +2 -2
- package/src/client/audio.mjs +37 -2
- package/src/client/browser.mjs +70 -57
- package/src/client/connection-hint.mjs +25 -4
- package/src/client/controls-layout.mjs +18 -0
- package/src/client/entry.js +1 -1
- package/src/client/feedback.mjs +11 -6
- package/src/client/notice.mjs +47 -0
- package/src/client/settings.html +3 -3
- package/src/client/tutorial-adapter.mjs +4 -3
- package/src/client/tutorial.mjs +15 -1
- package/src/host/assets.mjs +2 -0
- package/src/shared/state.mjs +5 -1
package/README.md
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
# duet
|
|
1
|
+
# duet.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**DSH 语音操控和语音播报**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/YuMS/dsh-duet/raw/refs/heads/main/docs/media/duet-demo.mp4)
|
|
4
6
|
|
|
5
7
|
duet,意为「二重奏」。这里的 duet 使用全双工语音模型,可以边听边说,
|
|
6
8
|
让你与 DSH 的交流不必一人一句地等待。
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
任务完成后,duet 会简短播报结果,让你不用一直盯着屏幕。
|
|
10
|
+
说出需求、修改输入、发送任务、切换会话——把键盘上的操作交给声音。你可以随时插话、补充或纠正。处理任务之外,也可以聊聊天。
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
当然,你也可以用 duet 帮你只播报结果,让你不用一直盯着屏幕。
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
最重要的是,duet 语音服务目前可以免费使用。
|
|
14
15
|
|
|
15
16
|
## 安装
|
|
16
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-duet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "duet(二重奏):只用语音就能操作 DSH,边听边说、随时插话的全双工语音助手。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh-plugin",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "node scripts/test.mjs",
|
|
24
24
|
"check": "node scripts/check-package.mjs",
|
|
25
|
-
"test:browser": "node tests/browser/settings.mjs && node tests/browser/tutorial.mjs && node tests/browser/feedback.mjs && node tests/browser/connection-hint.mjs",
|
|
25
|
+
"test:browser": "node tests/browser/settings.mjs && node tests/browser/tutorial.mjs && node tests/browser/feedback.mjs && node tests/browser/connection-hint.mjs && node tests/browser/resilience.mjs",
|
|
26
26
|
"test:host": "node tests/host/isolated-host.mjs",
|
|
27
27
|
"prepack": "npm run check"
|
|
28
28
|
},
|
package/src/client/audio.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { microphoneConstraints } from './microphone.mjs?v=0.1.
|
|
1
|
+
import { microphoneConstraints } from './microphone.mjs?v=0.1.3'
|
|
2
2
|
|
|
3
3
|
/** Browser-owned microphone and PCM playback. No microphone is requested in tts_only. */
|
|
4
4
|
export class DuetAudio {
|
|
@@ -12,6 +12,7 @@ export class DuetAudio {
|
|
|
12
12
|
this.epoch = 0
|
|
13
13
|
this.nextTime = 0
|
|
14
14
|
this.tones = new Set()
|
|
15
|
+
this.captureCleanup = null
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
prepare() {
|
|
@@ -36,12 +37,43 @@ export class DuetAudio {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
async startMic(send) {
|
|
40
|
+
async startMic(send, onFailure = () => {}) {
|
|
40
41
|
const epoch = this.epoch
|
|
41
42
|
// Exact selection: an unplugged device must not silently use a different mic.
|
|
42
43
|
const stream = await navigator.mediaDevices.getUserMedia(microphoneConstraints())
|
|
43
44
|
if (epoch !== this.epoch) { stream.getTracks().forEach(t => t.stop()); return }
|
|
44
45
|
this.stream = stream
|
|
46
|
+
let failed = false
|
|
47
|
+
const cleanups = [], muteTimers = new Map()
|
|
48
|
+
const fail = code => {
|
|
49
|
+
if (failed || epoch !== this.epoch) return
|
|
50
|
+
failed = true
|
|
51
|
+
this.stop()
|
|
52
|
+
onFailure(code)
|
|
53
|
+
}
|
|
54
|
+
const watch = (target, event, fn) => {
|
|
55
|
+
target.addEventListener(event, fn)
|
|
56
|
+
cleanups.push(() => target.removeEventListener(event, fn))
|
|
57
|
+
}
|
|
58
|
+
this.captureCleanup = () => {
|
|
59
|
+
for (const cleanup of cleanups) cleanup()
|
|
60
|
+
for (const timer of muteTimers.values()) clearTimeout(timer)
|
|
61
|
+
muteTimers.clear()
|
|
62
|
+
}
|
|
63
|
+
for (const track of stream.getAudioTracks()) {
|
|
64
|
+
const muted = () => {
|
|
65
|
+
clearTimeout(muteTimers.get(track))
|
|
66
|
+
// Brief device transitions can recover. This is a media-track failure
|
|
67
|
+
// signal, not an energy/VAD test: ordinary user silence never trips it.
|
|
68
|
+
muteTimers.set(track, setTimeout(() => { if (track.muted) fail('audio_capture_failed') }, 10000))
|
|
69
|
+
}
|
|
70
|
+
watch(track, 'ended', () => fail('microphone_disconnected'))
|
|
71
|
+
watch(track, 'mute', muted)
|
|
72
|
+
watch(track, 'unmute', () => { clearTimeout(muteTimers.get(track)); muteTimers.delete(track) })
|
|
73
|
+
if (track.readyState === 'ended') fail('microphone_disconnected')
|
|
74
|
+
else if (track.muted) muted()
|
|
75
|
+
}
|
|
76
|
+
if (epoch !== this.epoch) return
|
|
45
77
|
const code = `class Capture extends AudioWorkletProcessor {
|
|
46
78
|
constructor(){super();this.phase=0;this.sum=0;this.count=0;this.pcm=new Int16Array(1280);this.offset=0;}
|
|
47
79
|
process(inputs){const a=inputs[0]?.[0];if(!a)return true;
|
|
@@ -56,6 +88,7 @@ export class DuetAudio {
|
|
|
56
88
|
if (epoch !== this.epoch) { stream.getTracks().forEach(t => t.stop()); return }
|
|
57
89
|
this.source = this.context.createMediaStreamSource(stream)
|
|
58
90
|
this.capture = new AudioWorkletNode(this.context, 'duet-audio-capture')
|
|
91
|
+
watch(this.capture, 'processorerror', () => fail('audio_capture_failed'))
|
|
59
92
|
this.capture.port.onmessage = e => { if (epoch === this.epoch) send(e.data) }
|
|
60
93
|
this.mute = this.context.createGain()
|
|
61
94
|
this.mute.gain.value = 0
|
|
@@ -122,6 +155,8 @@ export class DuetAudio {
|
|
|
122
155
|
|
|
123
156
|
stop() {
|
|
124
157
|
this.epoch++
|
|
158
|
+
this.captureCleanup?.()
|
|
159
|
+
this.captureCleanup = null
|
|
125
160
|
for (const tone of this.tones) { try { tone.stop() } catch {} }
|
|
126
161
|
this.tones.clear()
|
|
127
162
|
this.stream?.getTracks().forEach(t => t.stop())
|
package/src/client/browser.mjs
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.
|
|
2
|
-
import { DuetAudio } from './audio.mjs?v=0.1.
|
|
3
|
-
import { HarnessRPCExecutor } from './rpc.mjs?v=0.1.
|
|
4
|
-
import { composerAccess, observeComposer, focusedSession } from './composer.mjs?v=0.1.
|
|
5
|
-
import { mountTutorial } from './tutorial.mjs?v=0.1.
|
|
6
|
-
import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.1.
|
|
7
|
-
import { mountRating } from './feedback.mjs?v=0.1.
|
|
8
|
-
import { createAudioUploadConsent } from './consent.mjs?v=0.1.
|
|
9
|
-
import { bindDuetShortcuts } from './shortcuts.mjs?v=0.1.
|
|
10
|
-
import { nativeInteractions } from './interactions.mjs?v=0.1.
|
|
11
|
-
import { mountConnectionHint } from './connection-hint.mjs?v=0.1.
|
|
12
|
-
import {
|
|
1
|
+
import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.3'
|
|
2
|
+
import { DuetAudio } from './audio.mjs?v=0.1.3'
|
|
3
|
+
import { HarnessRPCExecutor } from './rpc.mjs?v=0.1.3'
|
|
4
|
+
import { composerAccess, observeComposer, focusedSession } from './composer.mjs?v=0.1.3'
|
|
5
|
+
import { mountTutorial } from './tutorial.mjs?v=0.1.3'
|
|
6
|
+
import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.1.3'
|
|
7
|
+
import { mountRating } from './feedback.mjs?v=0.1.3'
|
|
8
|
+
import { createAudioUploadConsent } from './consent.mjs?v=0.1.3'
|
|
9
|
+
import { bindDuetShortcuts } from './shortcuts.mjs?v=0.1.3'
|
|
10
|
+
import { nativeInteractions } from './interactions.mjs?v=0.1.3'
|
|
11
|
+
import { mountConnectionHint } from './connection-hint.mjs?v=0.1.3'
|
|
12
|
+
import { mountControlsLayout } from './controls-layout.mjs?v=0.1.3'
|
|
13
|
+
import { mountNotice } from './notice.mjs?v=0.1.3'
|
|
14
|
+
import { workspaceIssue, requireWorkspace, browserSessionCatalog } from './workspaces.mjs?v=0.1.3'
|
|
13
15
|
|
|
14
16
|
export function mountDuet(ctx) {
|
|
15
17
|
const audio = new DuetAudio()
|
|
16
18
|
const audioConsent = createAudioUploadConsent()
|
|
17
|
-
let disposed = false, controls,
|
|
19
|
+
let disposed = false, controls, pollRunning = false, cursor = null, resultEpoch = null
|
|
20
|
+
let nextPollAt = 0, pollController, pollWakePending = false, pollFailureSince = null, pollFailures = 0, pollGeneration = -1
|
|
21
|
+
const notices = mountNotice(() => controls)
|
|
18
22
|
const labels = new Map()
|
|
19
23
|
let clientTraceId = null, diagnosticCount = 0
|
|
20
|
-
let tutorial, teaching, ratingPanel, connectionHint
|
|
24
|
+
let tutorial, teaching, ratingPanel, connectionHint, stopControlsLayout
|
|
21
25
|
const diagnostic = data => {
|
|
22
26
|
if (++diagnosticCount > 100) return
|
|
23
27
|
const bounded = Object.fromEntries(Object.entries(data).map(([k, v]) => [k, typeof v === 'string' ? v.slice(0, 4000) : v]))
|
|
@@ -33,31 +37,12 @@ export function mountDuet(ctx) {
|
|
|
33
37
|
const notice = (text, { upgrade = false } = {}) => {
|
|
34
38
|
connectionHint?.dismiss()
|
|
35
39
|
if (upgrade) { ratingPanel?.dispose(); ratingPanel = null }
|
|
36
|
-
|
|
37
|
-
if (!toast) return
|
|
38
|
-
toast.textContent = text
|
|
39
|
-
toast.hidden = false
|
|
40
|
-
clearTimeout(toastTimer)
|
|
41
|
-
if (upgrade) {
|
|
42
|
-
const help = document.createElement('details')
|
|
43
|
-
const title = document.createElement('summary')
|
|
44
|
-
title.textContent = '如何升级'
|
|
45
|
-
help.append(title)
|
|
46
|
-
const instruction = document.createElement('p')
|
|
47
|
-
instruction.textContent = '通过 npm 安装的用户,可在终端运行:'
|
|
48
|
-
const command = document.createElement('code')
|
|
49
|
-
command.textContent = 'dsh plugin --profile web add dsh-duet@latest'
|
|
50
|
-
command.style.cssText = 'display:block;white-space:normal;overflow-wrap:anywhere;margin:8px 0'
|
|
51
|
-
const after = document.createElement('p')
|
|
52
|
-
after.textContent = '其他安装方式请从原来源更新。完成后重启 DSH 并刷新页面,再手动开启语音。'
|
|
53
|
-
help.append(instruction, command, after)
|
|
54
|
-
const dismiss = document.createElement('button')
|
|
55
|
-
dismiss.textContent = '知道了'
|
|
56
|
-
dismiss.onclick = () => { toast.hidden = true }
|
|
57
|
-
toast.append(help, dismiss)
|
|
58
|
-
} else toastTimer = setTimeout(() => { toast.hidden = true }, 8000)
|
|
40
|
+
notices.show(text, { upgrade })
|
|
59
41
|
}
|
|
60
42
|
const draw = state => {
|
|
43
|
+
if (pollGeneration !== state.generation) {
|
|
44
|
+
pollGeneration = state.generation; nextPollAt = 0; pollFailureSince = null; pollFailures = 0
|
|
45
|
+
}
|
|
61
46
|
if (!controls) return
|
|
62
47
|
for (const [kind, active] of [['mic', state.mode === 'online'], ['speaker', state.mode === 'tts_only']]) {
|
|
63
48
|
const button = controls.querySelector(`[data-voice=${kind}]`)
|
|
@@ -86,6 +71,10 @@ export function mountDuet(ctx) {
|
|
|
86
71
|
const connectionTraceId = clientTraceId
|
|
87
72
|
const report = data => diagnostic({ ...data, client_trace_id: connectionTraceId, mode })
|
|
88
73
|
let ws, closed = false, release, ready = false, stopComposer
|
|
74
|
+
const opening = new AbortController()
|
|
75
|
+
const startupTimer = setTimeout(() => {
|
|
76
|
+
if (!closed) receive({ type: 'error', code: 'voice_start_timeout' })
|
|
77
|
+
}, 45000)
|
|
89
78
|
const send = message => {
|
|
90
79
|
if (ws?.readyState !== WebSocket.OPEN || closed) return
|
|
91
80
|
if (ws.bufferedAmount > 1_000_000) { receive({ type: 'error', code: 'voice_backpressure' }); return }
|
|
@@ -103,6 +92,8 @@ export function mountDuet(ctx) {
|
|
|
103
92
|
async close() {
|
|
104
93
|
report({ event: 'browser.connection_close', buffered_bytes: ws?.bufferedAmount })
|
|
105
94
|
closed = true
|
|
95
|
+
clearTimeout(startupTimer)
|
|
96
|
+
opening.abort()
|
|
106
97
|
stopComposer?.()
|
|
107
98
|
rpc.close()
|
|
108
99
|
audio.stop()
|
|
@@ -119,7 +110,10 @@ export function mountDuet(ctx) {
|
|
|
119
110
|
const open = async () => {
|
|
120
111
|
if (closed) return
|
|
121
112
|
// Establish/renew the host-signed anonymous cookie before the WS handshake.
|
|
122
|
-
const
|
|
113
|
+
const configTimer = setTimeout(() => opening.abort(Error('voice_start_timeout')), 10000)
|
|
114
|
+
let identity
|
|
115
|
+
try { identity = await fetch('/duplex-control/api/voice/config', {credentials:'same-origin',cache:'no-store',signal:opening.signal}) }
|
|
116
|
+
finally { clearTimeout(configTimer) }
|
|
123
117
|
if(!identity.ok)throw Error('voice_config_unavailable')
|
|
124
118
|
requireWorkspace(ctx)
|
|
125
119
|
if(closed)return
|
|
@@ -152,7 +146,9 @@ export function mountDuet(ctx) {
|
|
|
152
146
|
await audio.prepare()
|
|
153
147
|
if (closed) return
|
|
154
148
|
if (mode === 'online') {
|
|
155
|
-
try { await audio.startMic(send
|
|
149
|
+
try { await audio.startMic(send, code => {
|
|
150
|
+
if (!closed) { report({event:'browser.capture_failed',code}); receive({type:'error',code}) }
|
|
151
|
+
}) }
|
|
156
152
|
catch (error) {
|
|
157
153
|
report({ event: 'browser.microphone_failed', name: error?.name })
|
|
158
154
|
if (!closed) receive({ type: 'error', code: 'microphone_unavailable' })
|
|
@@ -163,6 +159,7 @@ export function mountDuet(ctx) {
|
|
|
163
159
|
context_state: audio.context?.state, base_latency: audio.context?.baseLatency,
|
|
164
160
|
user_agent: navigator.userAgent })
|
|
165
161
|
if (!closed) {
|
|
162
|
+
clearTimeout(startupTimer)
|
|
166
163
|
receive({ type: 'ready' })
|
|
167
164
|
try { audio.connectedChime() } catch { /* A notification must not break voice. */ }
|
|
168
165
|
}
|
|
@@ -190,7 +187,9 @@ export function mountDuet(ctx) {
|
|
|
190
187
|
if (closed) return
|
|
191
188
|
if (!lock) { receive({ type: 'error', code: 'voice_tab_in_use' }); return }
|
|
192
189
|
const held = new Promise(resolve => { release = resolve })
|
|
193
|
-
|
|
190
|
+
// Opening may hang; ownership ends when close() releases it, not when
|
|
191
|
+
// a fetch or browser permission request eventually resolves.
|
|
192
|
+
void open().catch(error => { if (!closed) receive({type:'error',code:opening.signal.aborted?'voice_start_timeout':error.message||'voice_connection_failed'}) })
|
|
194
193
|
await held
|
|
195
194
|
}).catch(() => { if (!closed) receive({ type: 'error', code: 'voice_connection_failed' }) })
|
|
196
195
|
} else queueMicrotask(() => receive({ type: 'error', code: 'voice_lock_unavailable' }))
|
|
@@ -266,12 +265,8 @@ export function mountDuet(ctx) {
|
|
|
266
265
|
settings.style.cssText = 'display:flex;color:inherit;padding:5px;border-radius:6px'
|
|
267
266
|
settings.innerHTML = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z"/><path d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"/></svg>'
|
|
268
267
|
controls.append(settings)
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
toast.setAttribute('aria-live', 'polite')
|
|
272
|
-
toast.hidden = true
|
|
273
|
-
toast.style.cssText = 'position:absolute;bottom:100%;left:0;z-index:9999;min-width:180px;max-width:280px;background:#252c38;color:white;padding:10px;border-radius:8px;font-size:12px;box-shadow:0 3px 18px #0005'
|
|
274
|
-
controls.append(toast)
|
|
268
|
+
stopControlsLayout?.()
|
|
269
|
+
stopControlsLayout = mountControlsLayout(controls)
|
|
275
270
|
connectionHint?.dispose()
|
|
276
271
|
connectionHint = mountConnectionHint(controls)
|
|
277
272
|
draw(state)
|
|
@@ -281,25 +276,27 @@ export function mountDuet(ctx) {
|
|
|
281
276
|
const observer = new MutationObserver(mount)
|
|
282
277
|
observer.observe(document.body, { subtree: true, childList: true })
|
|
283
278
|
|
|
284
|
-
const api = async path => {
|
|
279
|
+
const api = async (path, signal) => {
|
|
285
280
|
const response = await fetch(`/duplex-control/api/${path}`, { cache: 'no-store',
|
|
286
|
-
headers: { 'X-Duet-Native-Interactions': '1' } })
|
|
287
|
-
if (!response.ok) throw new Error('harness_unavailable')
|
|
281
|
+
signal, headers: { 'X-Duet-Native-Interactions': '1' } })
|
|
282
|
+
if (!response.ok) throw Object.assign(new Error('harness_unavailable'), {status:response.status})
|
|
288
283
|
return response.json()
|
|
289
284
|
}
|
|
290
285
|
const poll = async () => {
|
|
291
286
|
if (disposed || pollRunning) return
|
|
292
287
|
pollRunning = true
|
|
288
|
+
pollWakePending = false
|
|
289
|
+
const generation = state.generation, controller = new AbortController(), startedAt = Date.now()
|
|
290
|
+
pollController = controller
|
|
291
|
+
const timeout = setTimeout(() => controller.abort(), 5000)
|
|
293
292
|
try {
|
|
294
|
-
const [catalog, completed, health] = await Promise.all([api('sessions'), api(`results?after=${cursor ?? 0}&limit=100
|
|
293
|
+
const [catalog, completed, health] = await Promise.all([api('sessions',controller.signal), api(`results?after=${cursor ?? 0}&limit=100`,controller.signal), api('health',controller.signal)])
|
|
295
294
|
if (disposed) return
|
|
296
295
|
catalog.sessions = browserSessionCatalog(ctx, catalog.sessions)
|
|
297
296
|
const issue = workspaceIssue(ctx)
|
|
298
297
|
if (issue === 'workspace_required' && state.mode !== 'off') state.fail(issue)
|
|
299
298
|
for (const s of catalog.sessions) labels.set(s.session_id, s.label)
|
|
300
299
|
const bootstrap = cursor === null || resultEpoch !== health.focus_epoch
|
|
301
|
-
resultEpoch = health.focus_epoch
|
|
302
|
-
cursor = bootstrap ? completed.current_cursor : completed.next_cursor
|
|
303
300
|
let composer
|
|
304
301
|
const id = focusedSession(ctx)
|
|
305
302
|
const scope = id ? ctx.sessions.scope(id) : undefined
|
|
@@ -317,15 +314,27 @@ export function mountDuet(ctx) {
|
|
|
317
314
|
text: (job.status === 'succeeded' ? job.result : (job.error || job.result)) || '未返回结果。',
|
|
318
315
|
})),
|
|
319
316
|
})
|
|
317
|
+
resultEpoch = health.focus_epoch
|
|
318
|
+
cursor = bootstrap ? completed.current_cursor : completed.next_cursor
|
|
319
|
+
if (pollFailures >= 3 && state.mode !== 'off') notice('会话同步已恢复。')
|
|
320
|
+
pollFailureSince = null; pollFailures = 0
|
|
320
321
|
} catch (error) {
|
|
321
|
-
if (state.mode !== 'off') {
|
|
322
|
+
if (!disposed && generation === state.generation && state.mode !== 'off') {
|
|
322
323
|
diagnostic({ event: 'browser.poll_failed', message: String(error?.message || error), stack: error?.stack })
|
|
323
|
-
|
|
324
|
+
pollFailureSince ??= Date.now(); pollFailures++
|
|
325
|
+
if ([401,403].includes(error.status) || (pollFailures >= 3 && Date.now()-pollFailureSince >= 15000)) state.fail('harness_sync_failed')
|
|
326
|
+
else if (pollFailures === 3) notice('会话同步暂时中断,正在重试。')
|
|
324
327
|
}
|
|
325
328
|
}
|
|
326
|
-
finally {
|
|
329
|
+
finally {
|
|
330
|
+
clearTimeout(timeout); controller.abort(); pollController = null; pollRunning = false
|
|
331
|
+
nextPollAt = pollWakePending ? 0 : startedAt + (state.mode !== 'off' || tutorial?.active ? 1000 : document.hidden ? 15000 : 5000)
|
|
332
|
+
}
|
|
327
333
|
}
|
|
328
|
-
const timer = setInterval(() => { void poll(); state.tick() }, 1000)
|
|
334
|
+
const timer = setInterval(() => { if (Date.now() >= nextPollAt) void poll(); state.tick() }, 1000)
|
|
335
|
+
const wakePoll = () => { pollWakePending = true; nextPollAt = 0 }
|
|
336
|
+
const unwatchSessions = ctx.sessions.list.subscribe?.(wakePoll)
|
|
337
|
+
const unwatchWorkspaces = ctx.workspaces?.list?.subscribe?.(wakePoll)
|
|
329
338
|
const progress = setInterval(() => { if (state.connection) audio.progress(state.connection.send) }, 200)
|
|
330
339
|
const visibility = () => { state.hidden = document.visibilityState !== 'visible'; state.tick(); void poll() }
|
|
331
340
|
document.addEventListener('visibilitychange', visibility)
|
|
@@ -347,6 +356,9 @@ export function mountDuet(ctx) {
|
|
|
347
356
|
teachingObserver.observe(document.body, { subtree: true, childList: true })
|
|
348
357
|
return () => {
|
|
349
358
|
disposed = true
|
|
359
|
+
pollController?.abort()
|
|
360
|
+
unwatchSessions?.(); unwatchWorkspaces?.()
|
|
361
|
+
notices.dispose()
|
|
350
362
|
stopShortcuts()
|
|
351
363
|
observer.disconnect()
|
|
352
364
|
teachingObserver.disconnect()
|
|
@@ -354,7 +366,8 @@ export function mountDuet(ctx) {
|
|
|
354
366
|
audioConsent.cancel()
|
|
355
367
|
ratingPanel?.dispose()
|
|
356
368
|
connectionHint?.dispose()
|
|
357
|
-
clearInterval(timer); clearInterval(progress)
|
|
369
|
+
clearInterval(timer); clearInterval(progress)
|
|
370
|
+
stopControlsLayout?.()
|
|
358
371
|
document.removeEventListener('visibilitychange', visibility)
|
|
359
372
|
window.removeEventListener('error', pageError)
|
|
360
373
|
window.removeEventListener('unhandledrejection', pageError)
|
|
@@ -5,18 +5,37 @@ export function mountConnectionHint(controls, { duration = 8000 } = {}) {
|
|
|
5
5
|
hint.setAttribute('role', 'status')
|
|
6
6
|
hint.setAttribute('aria-live', 'polite')
|
|
7
7
|
hint.hidden = true
|
|
8
|
-
hint.style.cssText = 'position:
|
|
8
|
+
hint.style.cssText = 'position:fixed;z-index:100020;box-sizing:border-box;width:268px;max-width:calc(100vw - 32px);padding:12px 15px;border:1px solid #a5d8f4;border-radius:12px;background:#eff9ff;color:#163c56;font:13px/1.65 system-ui,sans-serif;box-shadow:0 8px 28px #153e6524;pointer-events:none'
|
|
9
9
|
hint.textContent = '连接成功,可以试试对我说“你好”。'
|
|
10
10
|
const arrow = document.createElement('span')
|
|
11
11
|
arrow.setAttribute('aria-hidden', 'true')
|
|
12
12
|
arrow.style.cssText = 'position:absolute;bottom:-6px;width:10px;height:10px;transform:rotate(45deg);background:#eff9ff;border-right:1px solid #a5d8f4;border-bottom:1px solid #a5d8f4'
|
|
13
13
|
hint.append(arrow)
|
|
14
|
-
|
|
14
|
+
// A body-level overlay escapes the sidebar's overflow and stacking context.
|
|
15
|
+
document.body.append(hint)
|
|
15
16
|
let wasReady = false, timer, disposed = false
|
|
17
|
+
const position = () => {
|
|
18
|
+
if (hint.hidden || disposed) return
|
|
19
|
+
if (!controls.isConnected) { hide(); return }
|
|
20
|
+
const button = controls.querySelector('[data-voice=mic]') || controls
|
|
21
|
+
const rect = button.getBoundingClientRect(), width = hint.offsetWidth, height = hint.offsetHeight
|
|
22
|
+
const left = Math.max(16, Math.min(rect.left, innerWidth - width - 16))
|
|
23
|
+
const above = rect.top >= height + 26
|
|
24
|
+
hint.style.left = `${left}px`
|
|
25
|
+
hint.style.top = `${Math.max(16, Math.min(above ? rect.top - height - 10 : rect.bottom + 10, innerHeight - height - 16))}px`
|
|
26
|
+
arrow.style.left = `${Math.max(16, Math.min(width - 26, rect.left + rect.width / 2 - left - 5))}px`
|
|
27
|
+
arrow.style.bottom = above ? '-6px' : 'auto'
|
|
28
|
+
arrow.style.top = above ? 'auto' : '-6px'
|
|
29
|
+
arrow.style.transform = above ? 'rotate(45deg)' : 'rotate(225deg)'
|
|
30
|
+
}
|
|
16
31
|
const hide = () => { hint.hidden = true; clearTimeout(timer) }
|
|
17
32
|
const dismiss = event => { if (event.type !== 'keydown' || event.key === 'Escape') hide() }
|
|
18
33
|
controls.addEventListener('pointerdown', dismiss)
|
|
19
34
|
document.addEventListener('keydown', dismiss)
|
|
35
|
+
window.addEventListener('resize', position)
|
|
36
|
+
window.addEventListener('scroll', position, true)
|
|
37
|
+
const observer = new ResizeObserver(position)
|
|
38
|
+
observer.observe(controls)
|
|
20
39
|
return {
|
|
21
40
|
dismiss: hide,
|
|
22
41
|
update({ mode, ready, teaching = false }) {
|
|
@@ -24,9 +43,8 @@ export function mountConnectionHint(controls, { duration = 8000 } = {}) {
|
|
|
24
43
|
const active = mode === 'online' && ready
|
|
25
44
|
if (!active || teaching) hide()
|
|
26
45
|
if (active && !wasReady && !teaching) {
|
|
27
|
-
const button = controls.querySelector('[data-voice=mic]')
|
|
28
|
-
arrow.style.left = `${Math.max(16, Math.min(244, (button?.offsetLeft || 32) + (button?.offsetWidth || 30) / 2 - 5))}px`
|
|
29
46
|
hint.hidden = false
|
|
47
|
+
position()
|
|
30
48
|
clearTimeout(timer)
|
|
31
49
|
timer = setTimeout(hide, duration)
|
|
32
50
|
}
|
|
@@ -37,6 +55,9 @@ export function mountConnectionHint(controls, { duration = 8000 } = {}) {
|
|
|
37
55
|
hide()
|
|
38
56
|
controls.removeEventListener('pointerdown', dismiss)
|
|
39
57
|
document.removeEventListener('keydown', dismiss)
|
|
58
|
+
window.removeEventListener('resize', position)
|
|
59
|
+
window.removeEventListener('scroll', position, true)
|
|
60
|
+
observer.disconnect()
|
|
40
61
|
hint.remove()
|
|
41
62
|
},
|
|
42
63
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Follow the host's available sidebar width, without depending on DSH classes. */
|
|
2
|
+
export function mountControlsLayout(controls) {
|
|
3
|
+
const parent = controls.parentElement
|
|
4
|
+
const update = () => {
|
|
5
|
+
const compact = parent.getBoundingClientRect().width < 160
|
|
6
|
+
if (controls.dataset.compact === String(compact)) return
|
|
7
|
+
controls.dataset.compact = String(compact)
|
|
8
|
+
controls.style.flexDirection = compact ? 'column' : 'row'
|
|
9
|
+
controls.style.margin = compact ? '4px 0' : '4px 8px'
|
|
10
|
+
controls.style.padding = compact ? '6px 0' : '6px 8px'
|
|
11
|
+
const entry = controls.querySelector('#dsh-duet-entry')
|
|
12
|
+
if (entry) entry.style.display = compact ? 'none' : ''
|
|
13
|
+
}
|
|
14
|
+
const observer = new ResizeObserver(update)
|
|
15
|
+
observer.observe(parent)
|
|
16
|
+
update()
|
|
17
|
+
return () => observer.disconnect()
|
|
18
|
+
}
|
package/src/client/entry.js
CHANGED
|
@@ -31,7 +31,7 @@ window.__ModuleLoader__.load({
|
|
|
31
31
|
ctx.effect(() => {
|
|
32
32
|
let active = true
|
|
33
33
|
let dispose
|
|
34
|
-
import('/duet/assets/client/browser.mjs?v=0.1.
|
|
34
|
+
import('/duet/assets/client/browser.mjs?v=0.1.3').then(module => {
|
|
35
35
|
if (active) dispose = module.mountDuet(ctx)
|
|
36
36
|
}).catch(error => console.warn('duet controls could not load:', error))
|
|
37
37
|
return () => { active = false; dispose?.() }
|
package/src/client/feedback.mjs
CHANGED
|
@@ -6,7 +6,7 @@ export function mountRating(anchor, sessionTicket) {
|
|
|
6
6
|
panel.style.cssText='position:fixed;z-index:100020;width:min(300px,calc(100vw - 24px));box-sizing:border-box;background:#17212f;color:#edf3ff;border:1px solid #52647d;border-radius:16px;padding:16px;box-shadow:0 12px 40px #0006;font:14px/1.6 system-ui'
|
|
7
7
|
const title=document.createElement('h3');title.textContent='这次语音体验怎么样?';title.style.margin='0 0 10px';panel.append(title)
|
|
8
8
|
const stars=document.createElement('div');stars.setAttribute('role','group');stars.setAttribute('aria-label','1 到 5 星');panel.append(stars)
|
|
9
|
-
let rating=0,busy=false,requestId=crypto.randomUUID()
|
|
9
|
+
let rating=0,busy=false,disposed=false,requestId=crypto.randomUUID(),requestController,requestTimeout
|
|
10
10
|
const buttons=[]
|
|
11
11
|
for(let value=1;value<=5;value++){
|
|
12
12
|
const b=document.createElement('button');b.type='button';b.textContent='☆';b.setAttribute('aria-label',`${value} 星`);b.setAttribute('aria-pressed','false')
|
|
@@ -23,21 +23,26 @@ export function mountRating(anchor, sessionTicket) {
|
|
|
23
23
|
panel.style.top=(rect.top>=box.height+20?rect.top-box.height-12:rect.bottom+12)+'px'
|
|
24
24
|
}
|
|
25
25
|
let countdown,timeout
|
|
26
|
-
const dispose=()=>{clearInterval(countdown);clearTimeout(timeout);panel.remove();document.removeEventListener('keydown',onKey);window.removeEventListener('resize',position);window.removeEventListener('scroll',position,true)}
|
|
26
|
+
const dispose=()=>{disposed=true;clearInterval(countdown);clearTimeout(timeout);clearTimeout(requestTimeout);requestController?.abort();panel.remove();document.removeEventListener('keydown',onKey);window.removeEventListener('resize',position);window.removeEventListener('scroll',position,true)}
|
|
27
27
|
const onKey=e=>{if(e.key==='Escape')dispose()}
|
|
28
28
|
skip.onclick=dispose
|
|
29
29
|
submit.onclick=async()=>{
|
|
30
|
-
if(busy||!rating)return
|
|
30
|
+
if(disposed||busy||!rating)return
|
|
31
31
|
busy=true;submit.disabled=true;buttons.forEach(b=>b.disabled=true)
|
|
32
|
+
clearInterval(countdown);clearTimeout(timeout)
|
|
33
|
+
submit.textContent='正在提交…';skip.textContent='关闭'
|
|
34
|
+
requestController=new AbortController()
|
|
35
|
+
requestTimeout=setTimeout(()=>requestController.abort(),15000)
|
|
32
36
|
try {
|
|
33
37
|
const r=await fetch('/duplex-control/api/feedback',{method:'POST',credentials:'same-origin',
|
|
34
|
-
headers:{'Content-Type':'application/json','X-Duplex-Settings':'1'},signal:
|
|
38
|
+
headers:{'Content-Type':'application/json','X-Duplex-Settings':'1'},signal:requestController.signal,
|
|
35
39
|
body:JSON.stringify({kind:'rating',request_id:requestId,session_ticket:sessionTicket,rating})})
|
|
36
40
|
const result=await r.json()
|
|
41
|
+
if(disposed)return
|
|
37
42
|
if(!r.ok||result.persisted!==true)throw Error('not_saved')
|
|
38
43
|
dispose()
|
|
39
|
-
}catch{title.textContent='提交失败,请重试';submit.disabled=false;buttons.forEach(b=>b.disabled=false)}
|
|
40
|
-
finally{busy=false}
|
|
44
|
+
}catch{if(!disposed){title.textContent='提交失败,请重试';submit.disabled=false;buttons.forEach(b=>b.disabled=false)}}
|
|
45
|
+
finally{clearTimeout(requestTimeout);busy=false;if(!disposed)submit.textContent='提交评分'}
|
|
41
46
|
}
|
|
42
47
|
panel.append(submit,skip);document.body.append(panel);document.addEventListener('keydown',onKey)
|
|
43
48
|
position();window.addEventListener('resize',position);window.addEventListener('scroll',position,true)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Page-level notices must not inherit a sidebar's clipping or stacking context. */
|
|
2
|
+
export function mountNotice(anchor) {
|
|
3
|
+
const panel = document.createElement('div')
|
|
4
|
+
panel.dataset.duetNotice = ''
|
|
5
|
+
panel.setAttribute('role', 'status')
|
|
6
|
+
panel.setAttribute('aria-live', 'polite')
|
|
7
|
+
panel.hidden = true
|
|
8
|
+
panel.style.cssText = 'position:fixed;z-index:100021;box-sizing:border-box;width:280px;max-width:calc(100vw - 24px);max-height:calc(100vh - 24px);overflow:auto;background:#252c38;color:white;padding:14px;border:1px solid #52647d;border-radius:12px;font:13px/1.6 system-ui;box-shadow:0 8px 28px #0005;overflow-wrap:anywhere'
|
|
9
|
+
document.body.append(panel)
|
|
10
|
+
let timer, disposed = false
|
|
11
|
+
const hide = () => { panel.hidden = true; clearTimeout(timer) }
|
|
12
|
+
const position = () => {
|
|
13
|
+
if (panel.hidden || disposed) return
|
|
14
|
+
const control = anchor()
|
|
15
|
+
if (!control?.isConnected) { hide(); return }
|
|
16
|
+
const rect = control.getBoundingClientRect(), box = panel.getBoundingClientRect()
|
|
17
|
+
panel.style.left = Math.max(12, Math.min(rect.left, innerWidth - box.width - 12)) + 'px'
|
|
18
|
+
const top = rect.top >= box.height + 24 ? rect.top - box.height - 12 : rect.bottom + 12
|
|
19
|
+
panel.style.top = Math.max(12, Math.min(top, innerHeight - box.height - 12)) + 'px'
|
|
20
|
+
}
|
|
21
|
+
const key = event => { if (event.key === 'Escape') hide() }
|
|
22
|
+
window.addEventListener('resize', position)
|
|
23
|
+
window.addEventListener('scroll', position, true)
|
|
24
|
+
document.addEventListener('keydown', key)
|
|
25
|
+
const observer = new ResizeObserver(position)
|
|
26
|
+
observer.observe(panel)
|
|
27
|
+
return {
|
|
28
|
+
show(text, {upgrade = false} = {}) {
|
|
29
|
+
if (disposed) return
|
|
30
|
+
clearTimeout(timer); panel.textContent = text; panel.hidden = false
|
|
31
|
+
if (upgrade) {
|
|
32
|
+
const help = document.createElement('details'), title = document.createElement('summary')
|
|
33
|
+
title.textContent = '如何升级'; help.append(title)
|
|
34
|
+
const before = document.createElement('p'), command = document.createElement('code'), after = document.createElement('p')
|
|
35
|
+
before.textContent = '通过 npm 安装的用户,可在终端运行:'
|
|
36
|
+
command.textContent = 'dsh plugin --profile web add dsh-duet@latest'
|
|
37
|
+
command.style.cssText = 'display:block;white-space:normal;margin:8px 0'
|
|
38
|
+
after.textContent = '其他安装方式请从原来源更新。完成后重启 DSH 并刷新页面,再手动开启语音。'
|
|
39
|
+
help.append(before, command, after); panel.append(help)
|
|
40
|
+
help.addEventListener('toggle', position)
|
|
41
|
+
const close = document.createElement('button'); close.type = 'button'; close.textContent = '知道了'; close.onclick = hide; panel.append(close)
|
|
42
|
+
} else timer = setTimeout(hide, 8000)
|
|
43
|
+
position()
|
|
44
|
+
},
|
|
45
|
+
dispose() { disposed = true; hide(); observer.disconnect(); panel.remove(); window.removeEventListener('resize', position); window.removeEventListener('scroll', position, true); document.removeEventListener('keydown', key) },
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/client/settings.html
CHANGED
|
@@ -366,7 +366,7 @@
|
|
|
366
366
|
}
|
|
367
367
|
$('openTutorial').onclick = async () => {
|
|
368
368
|
try {
|
|
369
|
-
const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.
|
|
369
|
+
const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.3');
|
|
370
370
|
requestTutorial(localStorage);
|
|
371
371
|
$('tutorialStatus').textContent = '请回到 DSH 页面继续教学。';
|
|
372
372
|
} catch { $('tutorialStatus').textContent = '暂时无法打开教学,请允许浏览器存储后重试。'; }
|
|
@@ -375,11 +375,11 @@
|
|
|
375
375
|
setInterval(() => { loadDuetConfig().catch(() => { $('duetConnection').textContent = '语音连接信息不可用'; }); }, 2000);
|
|
376
376
|
void loadNotices();
|
|
377
377
|
setInterval(loadNotices, 60000);
|
|
378
|
-
import('/duet/assets/client/shortcuts.mjs?v=0.1.
|
|
378
|
+
import('/duet/assets/client/shortcuts.mjs?v=0.1.3').then(({mountShortcutSettings}) => {
|
|
379
379
|
const dispose = mountShortcutSettings({speaker:$('speakerShortcut'),mic:$('micShortcut'),clearSpeaker:$('clearSpeakerShortcut'),clearMic:$('clearMicShortcut'),status:$('shortcutStatus')});
|
|
380
380
|
window.addEventListener('pagehide', e => {if(!e.persisted)dispose()}, {once:true});
|
|
381
381
|
}).catch(() => { $('shortcutStatus').textContent = '暂时无法加载快捷键设置,请刷新重试。'; });
|
|
382
|
-
import('/duet/assets/client/microphone.mjs?v=0.1.
|
|
382
|
+
import('/duet/assets/client/microphone.mjs?v=0.1.3').then(({mountMicrophoneSettings}) => {
|
|
383
383
|
const dispose = mountMicrophoneSettings({select:$('microphoneDevice'),refresh:$('refreshMicrophones'),status:$('microphoneStatus')});
|
|
384
384
|
window.addEventListener('pagehide', dispose, {once:true});
|
|
385
385
|
}).catch(() => { $('microphoneStatus').textContent = '暂时无法加载麦克风设置,请刷新重试。'; });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** DSH browser services plus existing voice connection; never opens a microphone. */
|
|
2
|
-
import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.
|
|
3
|
-
import { focusedSession } from './composer.mjs?v=0.1.
|
|
4
|
-
import { requireWorkspace } from './workspaces.mjs?v=0.1.
|
|
2
|
+
import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.3'
|
|
3
|
+
import { focusedSession } from './composer.mjs?v=0.1.3'
|
|
4
|
+
import { requireWorkspace, workspaceIssue } from './workspaces.mjs?v=0.1.3'
|
|
5
5
|
export function tutorialAdapter(ctx, state, audio, pollReady) {
|
|
6
6
|
let narration
|
|
7
7
|
const completed = new Map()
|
|
@@ -38,6 +38,7 @@ export function tutorialAdapter(ctx, state, audio, pollReady) {
|
|
|
38
38
|
return s
|
|
39
39
|
}
|
|
40
40
|
return {
|
|
41
|
+
workspaceIssue:()=>workspaceIssue(ctx),
|
|
41
42
|
mode:()=>state.mode,current,
|
|
42
43
|
observe(event){if(event.type==='external_message.done'){completed.set(event.message_id,event.status);if(completed.size>128)completed.delete(completed.keys().next().value)}},
|
|
43
44
|
unlock:()=>audio.prepare(),
|
package/src/client/tutorial.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Opt-in walkthrough. All writes are limited to sessions created by this run. */
|
|
2
|
-
import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.1.
|
|
2
|
+
import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.1.3'
|
|
3
3
|
export const TUTORIAL_KEY = 'dsh-duplex-tutorial-v1'
|
|
4
4
|
export const QUESTION = '什么是语音交互?请用一句话简单解释,不使用工具。'
|
|
5
5
|
export const INPUT = '用一句话介绍语音助手。'
|
|
@@ -177,8 +177,19 @@ export function mountTutorial({ controls, adapter }) {
|
|
|
177
177
|
const owner=run
|
|
178
178
|
await owner?.stop();if(run!==owner)return
|
|
179
179
|
active=false;lockRelease?.();lockRelease=null
|
|
180
|
+
if (showWorkspaceIssue(error.message)) return
|
|
180
181
|
show('教学已暂停', `${error.message}\n不会继续发送或修改。已经提交的任务仍会保留。`, [['重新开始',welcome]])
|
|
181
182
|
}
|
|
183
|
+
const showWorkspaceIssue = issue => {
|
|
184
|
+
const messages = {
|
|
185
|
+
workspace_required: ['请先创建 workspace', '请先在 DSH 中创建一个 workspace,再回来开始教学。'],
|
|
186
|
+
workspace_loading: ['正在加载 workspace', '请稍等片刻,再试一次。'],
|
|
187
|
+
workspace_unavailable: ['暂时无法读取 workspace', '请检查 DSH 的 workspace 是否正常加载,再试一次。'],
|
|
188
|
+
}
|
|
189
|
+
if (!messages[issue]) return false
|
|
190
|
+
show(...messages[issue], [['重新检查', welcome]])
|
|
191
|
+
return true
|
|
192
|
+
}
|
|
182
193
|
const act = async (title,text,fn,next,selector,pause=0) => {
|
|
183
194
|
if(run?.busy)return
|
|
184
195
|
const owner=run
|
|
@@ -216,6 +227,7 @@ export function mountTutorial({ controls, adapter }) {
|
|
|
216
227
|
if(active)return
|
|
217
228
|
if(!consent?.sound||!consent?.chat){welcome();return}
|
|
218
229
|
closed=false
|
|
230
|
+
if(showWorkspaceIssue(adapter.workspaceIssue?.()))return
|
|
219
231
|
if(adapter.mode()!=='off'){show('先结束当前语音','请先关闭语音模式,再开始教学。',[['重新检查',welcome]]);return}
|
|
220
232
|
if(!navigator.locks){show('当前浏览器暂不支持教学','请使用新版 Chrome 或 Edge 打开 DSH。');return}
|
|
221
233
|
try {
|
|
@@ -233,11 +245,13 @@ export function mountTutorial({ controls, adapter }) {
|
|
|
233
245
|
}
|
|
234
246
|
const welcome = () => {
|
|
235
247
|
closed=false
|
|
248
|
+
if(showWorkspaceIssue(adapter.workspaceIssue?.()))return
|
|
236
249
|
const view=show('来试试用声音操作吧','我会带您体验播报模式和交互模式。\n开始前,请完成以下准备:')
|
|
237
250
|
if(!view)return
|
|
238
251
|
const check=text=>{const label=element('label'),input=element('input',null,label);input.type='checkbox';element('span',text,label);view.panel.insertBefore(label,view.footer);return input}
|
|
239
252
|
const sound=check('声音已打开'),chat=check('同意本教程通过dsh发送消息(会产生模型用量)')
|
|
240
253
|
const b=button(view.footer,'开始教学',()=>{
|
|
254
|
+
if(showWorkspaceIssue(adapter.workspaceIssue?.()))return
|
|
241
255
|
b.disabled=true
|
|
242
256
|
const consent={sound:sound.checked,chat:chat.checked}
|
|
243
257
|
// User gesture unlocks audio before either mode is demonstrated.
|
package/src/host/assets.mjs
CHANGED
|
@@ -7,6 +7,8 @@ const modules = {
|
|
|
7
7
|
tutorial_adapter: 'client/tutorial-adapter', tutorial_request: 'client/tutorial-request',
|
|
8
8
|
feedback: 'client/feedback', consent: 'client/consent',
|
|
9
9
|
connection_hint: 'client/connection-hint',
|
|
10
|
+
controls_layout: 'client/controls-layout',
|
|
11
|
+
notice: 'client/notice',
|
|
10
12
|
workspaces: 'client/workspaces',
|
|
11
13
|
}
|
|
12
14
|
const aliases = {
|
package/src/shared/state.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Desired voice mode is independent of a temporarily suspended connection. */
|
|
2
|
-
export const PLUGIN_VERSION = '0.1.
|
|
2
|
+
export const PLUGIN_VERSION = '0.1.3'
|
|
3
3
|
export const IDLE_RELEASE_MS = 60_000
|
|
4
4
|
|
|
5
5
|
const safeVersion = value => typeof value === 'string' && value.length <= 32 && /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(value) ? value : ''
|
|
@@ -109,6 +109,10 @@ export class DuetState {
|
|
|
109
109
|
workspace_loading: '正在加载 workspace,请稍后再试。',
|
|
110
110
|
workspace_unavailable: '无法读取 workspace,请刷新 DSH 后重试。',
|
|
111
111
|
microphone_unavailable: '无法使用所选麦克风,请在设置中检查设备与浏览器权限',
|
|
112
|
+
microphone_disconnected: '麦克风已断开或权限已撤销,交互模式已关闭。请检查设备后重新开启。',
|
|
113
|
+
audio_capture_failed: '麦克风采集异常,交互模式已关闭。请检查设备后重新开启。',
|
|
114
|
+
voice_start_timeout: '连接超时,请检查网络或麦克风授权后重新开启。',
|
|
115
|
+
harness_sync_failed: '无法继续同步 DSH 会话,语音已关闭。请检查 DSH 后重新开启。',
|
|
112
116
|
interaction_mode_unavailable: '交互模式暂时不可用,请稍后再试',
|
|
113
117
|
broadcast_mode_unavailable: '播报模式暂时不可用,请稍后再试',
|
|
114
118
|
client_protocol_unsupported: '插件与服务器协议不兼容,请更新插件或联系服务管理员',
|