dsh-duet 0.1.1 → 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 +4 -4
- package/src/client/audio.mjs +37 -2
- package/src/client/browser.mjs +90 -56
- package/src/client/connection-hint.mjs +64 -0
- package/src/client/controls-layout.mjs +18 -0
- package/src/client/entry.js +2 -2
- package/src/client/feedback.mjs +11 -6
- package/src/client/interactions.mjs +3 -1
- package/src/client/notice.mjs +47 -0
- package/src/client/rpc.mjs +3 -2
- package/src/client/settings.html +4 -8
- package/src/client/tutorial-adapter.mjs +5 -2
- package/src/client/tutorial.mjs +15 -1
- package/src/client/workspaces.mjs +25 -0
- package/src/host/assets.mjs +4 -0
- package/src/host/plugin.mjs +1 -1
- package/src/host/proxy.mjs +10 -7
- package/src/host/service-defaults.mjs +12 -0
- package/src/host/settings.mjs +8 -13
- package/src/shared/catalog.mjs +15 -4
- package/src/shared/state.mjs +8 -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",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"author": {
|
|
13
|
-
"name": "YuMS"
|
|
14
|
-
"email": "yumaoshu@gmail.com"
|
|
13
|
+
"name": "YuMS"
|
|
15
14
|
},
|
|
16
15
|
"repository": {
|
|
17
16
|
"type": "git",
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
"scripts": {
|
|
24
23
|
"test": "node scripts/test.mjs",
|
|
25
24
|
"check": "node scripts/check-package.mjs",
|
|
26
|
-
"test:browser": "node tests/browser/settings.mjs && node tests/browser/tutorial.mjs && node tests/browser/feedback.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",
|
|
27
26
|
"test:host": "node tests/host/isolated-host.mjs",
|
|
28
27
|
"prepack": "npm run check"
|
|
29
28
|
},
|
|
@@ -59,6 +58,7 @@
|
|
|
59
58
|
"client": {
|
|
60
59
|
"inject": [
|
|
61
60
|
"@deepseek-ai/dsh-api-session-controller",
|
|
61
|
+
"@deepseek-ai/dsh-api-workspace-controller",
|
|
62
62
|
"@deepseek-ai/dsh-client-ui-session",
|
|
63
63
|
"@deepseek-ai/dsh-client-ui-conversation"
|
|
64
64
|
],
|
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,21 +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.
|
|
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'
|
|
11
15
|
|
|
12
16
|
export function mountDuet(ctx) {
|
|
13
17
|
const audio = new DuetAudio()
|
|
14
18
|
const audioConsent = createAudioUploadConsent()
|
|
15
|
-
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)
|
|
16
22
|
const labels = new Map()
|
|
17
23
|
let clientTraceId = null, diagnosticCount = 0
|
|
18
|
-
let tutorial, teaching, ratingPanel
|
|
24
|
+
let tutorial, teaching, ratingPanel, connectionHint, stopControlsLayout
|
|
19
25
|
const diagnostic = data => {
|
|
20
26
|
if (++diagnosticCount > 100) return
|
|
21
27
|
const bounded = Object.fromEntries(Object.entries(data).map(([k, v]) => [k, typeof v === 'string' ? v.slice(0, 4000) : v]))
|
|
@@ -29,32 +35,14 @@ export function mountDuet(ctx) {
|
|
|
29
35
|
window.addEventListener('error', pageError)
|
|
30
36
|
window.addEventListener('unhandledrejection', pageError)
|
|
31
37
|
const notice = (text, { upgrade = false } = {}) => {
|
|
38
|
+
connectionHint?.dismiss()
|
|
32
39
|
if (upgrade) { ratingPanel?.dispose(); ratingPanel = null }
|
|
33
|
-
|
|
34
|
-
if (!toast) return
|
|
35
|
-
toast.textContent = text
|
|
36
|
-
toast.hidden = false
|
|
37
|
-
clearTimeout(toastTimer)
|
|
38
|
-
if (upgrade) {
|
|
39
|
-
const help = document.createElement('details')
|
|
40
|
-
const title = document.createElement('summary')
|
|
41
|
-
title.textContent = '如何升级'
|
|
42
|
-
help.append(title)
|
|
43
|
-
const instruction = document.createElement('p')
|
|
44
|
-
instruction.textContent = '通过 npm 安装的用户,可在终端运行:'
|
|
45
|
-
const command = document.createElement('code')
|
|
46
|
-
command.textContent = 'dsh plugin --profile web add dsh-duet@latest'
|
|
47
|
-
command.style.cssText = 'display:block;white-space:normal;overflow-wrap:anywhere;margin:8px 0'
|
|
48
|
-
const after = document.createElement('p')
|
|
49
|
-
after.textContent = '其他安装方式请从原来源更新。完成后重启 DSH 并刷新页面,再手动开启语音。'
|
|
50
|
-
help.append(instruction, command, after)
|
|
51
|
-
const dismiss = document.createElement('button')
|
|
52
|
-
dismiss.textContent = '知道了'
|
|
53
|
-
dismiss.onclick = () => { toast.hidden = true }
|
|
54
|
-
toast.append(help, dismiss)
|
|
55
|
-
} else toastTimer = setTimeout(() => { toast.hidden = true }, 8000)
|
|
40
|
+
notices.show(text, { upgrade })
|
|
56
41
|
}
|
|
57
42
|
const draw = state => {
|
|
43
|
+
if (pollGeneration !== state.generation) {
|
|
44
|
+
pollGeneration = state.generation; nextPollAt = 0; pollFailureSince = null; pollFailures = 0
|
|
45
|
+
}
|
|
58
46
|
if (!controls) return
|
|
59
47
|
for (const [kind, active] of [['mic', state.mode === 'online'], ['speaker', state.mode === 'tts_only']]) {
|
|
60
48
|
const button = controls.querySelector(`[data-voice=${kind}]`)
|
|
@@ -74,13 +62,19 @@ export function mountDuet(ctx) {
|
|
|
74
62
|
const mark = controls.querySelector('[data-duet-mark]')
|
|
75
63
|
mark.style.color = state.ready ? '#7fd6a6' : '#ed9b35'
|
|
76
64
|
mark.title = state.ready ? '语音已连接' : '语音未连接'
|
|
65
|
+
connectionHint?.update({ mode: state.mode, ready: state.ready, teaching: Boolean(tutorial?.active) })
|
|
77
66
|
}
|
|
78
67
|
const connect = (mode, receive) => {
|
|
68
|
+
requireWorkspace(ctx)
|
|
79
69
|
if (!audioConsent.granted()) throw Error('data_upload_consent_required')
|
|
80
70
|
clientTraceId = crypto.randomUUID(); diagnosticCount = 0
|
|
81
71
|
const connectionTraceId = clientTraceId
|
|
82
72
|
const report = data => diagnostic({ ...data, client_trace_id: connectionTraceId, mode })
|
|
83
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)
|
|
84
78
|
const send = message => {
|
|
85
79
|
if (ws?.readyState !== WebSocket.OPEN || closed) return
|
|
86
80
|
if (ws.bufferedAmount > 1_000_000) { receive({ type: 'error', code: 'voice_backpressure' }); return }
|
|
@@ -89,7 +83,7 @@ export function mountDuet(ctx) {
|
|
|
89
83
|
const composer = composerAccess(ctx, id => labels.get(id) || id)
|
|
90
84
|
const interactions = nativeInteractions(ctx)
|
|
91
85
|
const rpc = new HarnessRPCExecutor(send, fetch, report, async (request, signal) =>
|
|
92
|
-
(await interactions(request, signal)) ?? composer.execute(request, signal))
|
|
86
|
+
(await interactions(request, signal)) ?? composer.execute(request, signal), rows => browserSessionCatalog(ctx, rows))
|
|
93
87
|
const connection = {
|
|
94
88
|
feedbackTicket: null,
|
|
95
89
|
send,
|
|
@@ -98,6 +92,8 @@ export function mountDuet(ctx) {
|
|
|
98
92
|
async close() {
|
|
99
93
|
report({ event: 'browser.connection_close', buffered_bytes: ws?.bufferedAmount })
|
|
100
94
|
closed = true
|
|
95
|
+
clearTimeout(startupTimer)
|
|
96
|
+
opening.abort()
|
|
101
97
|
stopComposer?.()
|
|
102
98
|
rpc.close()
|
|
103
99
|
audio.stop()
|
|
@@ -114,8 +110,12 @@ export function mountDuet(ctx) {
|
|
|
114
110
|
const open = async () => {
|
|
115
111
|
if (closed) return
|
|
116
112
|
// Establish/renew the host-signed anonymous cookie before the WS handshake.
|
|
117
|
-
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) }
|
|
118
117
|
if(!identity.ok)throw Error('voice_config_unavailable')
|
|
118
|
+
requireWorkspace(ctx)
|
|
119
119
|
if(closed)return
|
|
120
120
|
const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
121
121
|
ws = new WebSocket(`${protocol}//${location.host}/duplex-control/voice/ws?mode=${mode}&plugin_version=${PLUGIN_VERSION}&client_trace_id=${connectionTraceId}`)
|
|
@@ -146,7 +146,9 @@ export function mountDuet(ctx) {
|
|
|
146
146
|
await audio.prepare()
|
|
147
147
|
if (closed) return
|
|
148
148
|
if (mode === 'online') {
|
|
149
|
-
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
|
+
}) }
|
|
150
152
|
catch (error) {
|
|
151
153
|
report({ event: 'browser.microphone_failed', name: error?.name })
|
|
152
154
|
if (!closed) receive({ type: 'error', code: 'microphone_unavailable' })
|
|
@@ -157,6 +159,7 @@ export function mountDuet(ctx) {
|
|
|
157
159
|
context_state: audio.context?.state, base_latency: audio.context?.baseLatency,
|
|
158
160
|
user_agent: navigator.userAgent })
|
|
159
161
|
if (!closed) {
|
|
162
|
+
clearTimeout(startupTimer)
|
|
160
163
|
receive({ type: 'ready' })
|
|
161
164
|
try { audio.connectedChime() } catch { /* A notification must not break voice. */ }
|
|
162
165
|
}
|
|
@@ -184,7 +187,9 @@ export function mountDuet(ctx) {
|
|
|
184
187
|
if (closed) return
|
|
185
188
|
if (!lock) { receive({ type: 'error', code: 'voice_tab_in_use' }); return }
|
|
186
189
|
const held = new Promise(resolve => { release = resolve })
|
|
187
|
-
|
|
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'}) })
|
|
188
193
|
await held
|
|
189
194
|
}).catch(() => { if (!closed) receive({ type: 'error', code: 'voice_connection_failed' }) })
|
|
190
195
|
} else queueMicrotask(() => receive({ type: 'error', code: 'voice_lock_unavailable' }))
|
|
@@ -223,8 +228,17 @@ export function mountDuet(ctx) {
|
|
|
223
228
|
button.append(ring)
|
|
224
229
|
button.onclick = () => {
|
|
225
230
|
if (tutorial?.active) { notice('请先结束教学,再切换模式。'); return }
|
|
231
|
+
const requestedMode = kind === 'mic' ? 'online' : 'tts_only'
|
|
232
|
+
const checkWorkspace = () => {
|
|
233
|
+
if (state.mode === requestedMode) return true // Closing is always allowed.
|
|
234
|
+
const issue = workspaceIssue(ctx)
|
|
235
|
+
if (issue) { state.fail(issue); return false }
|
|
236
|
+
return true
|
|
237
|
+
}
|
|
238
|
+
if (!checkWorkspace()) return
|
|
226
239
|
const activate = () => {
|
|
227
240
|
if (disposed || tutorial?.active) return
|
|
241
|
+
if (!checkWorkspace()) return
|
|
228
242
|
// Unlock playback inside user activation, before any network await.
|
|
229
243
|
const enabling = kind === 'mic' ? state.mode !== 'online' : state.mode !== 'tts_only'
|
|
230
244
|
if (enabling) void audio.prepare().catch(() => state.fail('audio_permission_denied'))
|
|
@@ -251,12 +265,10 @@ export function mountDuet(ctx) {
|
|
|
251
265
|
settings.style.cssText = 'display:flex;color:inherit;padding:5px;border-radius:6px'
|
|
252
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>'
|
|
253
267
|
controls.append(settings)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
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'
|
|
259
|
-
controls.append(toast)
|
|
268
|
+
stopControlsLayout?.()
|
|
269
|
+
stopControlsLayout = mountControlsLayout(controls)
|
|
270
|
+
connectionHint?.dispose()
|
|
271
|
+
connectionHint = mountConnectionHint(controls)
|
|
260
272
|
draw(state)
|
|
261
273
|
}
|
|
262
274
|
mount()
|
|
@@ -264,22 +276,27 @@ export function mountDuet(ctx) {
|
|
|
264
276
|
const observer = new MutationObserver(mount)
|
|
265
277
|
observer.observe(document.body, { subtree: true, childList: true })
|
|
266
278
|
|
|
267
|
-
const api = async path => {
|
|
279
|
+
const api = async (path, signal) => {
|
|
268
280
|
const response = await fetch(`/duplex-control/api/${path}`, { cache: 'no-store',
|
|
269
|
-
headers: { 'X-Duet-Native-Interactions': '1' } })
|
|
270
|
-
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})
|
|
271
283
|
return response.json()
|
|
272
284
|
}
|
|
273
285
|
const poll = async () => {
|
|
274
286
|
if (disposed || pollRunning) return
|
|
275
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)
|
|
276
292
|
try {
|
|
277
|
-
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)])
|
|
278
294
|
if (disposed) return
|
|
295
|
+
catalog.sessions = browserSessionCatalog(ctx, catalog.sessions)
|
|
296
|
+
const issue = workspaceIssue(ctx)
|
|
297
|
+
if (issue === 'workspace_required' && state.mode !== 'off') state.fail(issue)
|
|
279
298
|
for (const s of catalog.sessions) labels.set(s.session_id, s.label)
|
|
280
299
|
const bootstrap = cursor === null || resultEpoch !== health.focus_epoch
|
|
281
|
-
resultEpoch = health.focus_epoch
|
|
282
|
-
cursor = bootstrap ? completed.current_cursor : completed.next_cursor
|
|
283
300
|
let composer
|
|
284
301
|
const id = focusedSession(ctx)
|
|
285
302
|
const scope = id ? ctx.sessions.scope(id) : undefined
|
|
@@ -297,15 +314,27 @@ export function mountDuet(ctx) {
|
|
|
297
314
|
text: (job.status === 'succeeded' ? job.result : (job.error || job.result)) || '未返回结果。',
|
|
298
315
|
})),
|
|
299
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
|
|
300
321
|
} catch (error) {
|
|
301
|
-
if (state.mode !== 'off') {
|
|
322
|
+
if (!disposed && generation === state.generation && state.mode !== 'off') {
|
|
302
323
|
diagnostic({ event: 'browser.poll_failed', message: String(error?.message || error), stack: error?.stack })
|
|
303
|
-
|
|
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('会话同步暂时中断,正在重试。')
|
|
304
327
|
}
|
|
305
328
|
}
|
|
306
|
-
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
|
+
}
|
|
307
333
|
}
|
|
308
|
-
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)
|
|
309
338
|
const progress = setInterval(() => { if (state.connection) audio.progress(state.connection.send) }, 200)
|
|
310
339
|
const visibility = () => { state.hidden = document.visibilityState !== 'visible'; state.tick(); void poll() }
|
|
311
340
|
document.addEventListener('visibilitychange', visibility)
|
|
@@ -327,13 +356,18 @@ export function mountDuet(ctx) {
|
|
|
327
356
|
teachingObserver.observe(document.body, { subtree: true, childList: true })
|
|
328
357
|
return () => {
|
|
329
358
|
disposed = true
|
|
359
|
+
pollController?.abort()
|
|
360
|
+
unwatchSessions?.(); unwatchWorkspaces?.()
|
|
361
|
+
notices.dispose()
|
|
330
362
|
stopShortcuts()
|
|
331
363
|
observer.disconnect()
|
|
332
364
|
teachingObserver.disconnect()
|
|
333
365
|
tutorial?.dispose()
|
|
334
366
|
audioConsent.cancel()
|
|
335
367
|
ratingPanel?.dispose()
|
|
336
|
-
|
|
368
|
+
connectionHint?.dispose()
|
|
369
|
+
clearInterval(timer); clearInterval(progress)
|
|
370
|
+
stopControlsLayout?.()
|
|
337
371
|
document.removeEventListener('visibilitychange', visibility)
|
|
338
372
|
window.removeEventListener('error', pageError)
|
|
339
373
|
window.removeEventListener('unhandledrejection', pageError)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** A brief, non-modal invitation after the microphone is actually ready. */
|
|
2
|
+
export function mountConnectionHint(controls, { duration = 8000 } = {}) {
|
|
3
|
+
const hint = document.createElement('div')
|
|
4
|
+
hint.dataset.duetConnectionHint = ''
|
|
5
|
+
hint.setAttribute('role', 'status')
|
|
6
|
+
hint.setAttribute('aria-live', 'polite')
|
|
7
|
+
hint.hidden = true
|
|
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
|
+
hint.textContent = '连接成功,可以试试对我说“你好”。'
|
|
10
|
+
const arrow = document.createElement('span')
|
|
11
|
+
arrow.setAttribute('aria-hidden', 'true')
|
|
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
|
+
hint.append(arrow)
|
|
14
|
+
// A body-level overlay escapes the sidebar's overflow and stacking context.
|
|
15
|
+
document.body.append(hint)
|
|
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
|
+
}
|
|
31
|
+
const hide = () => { hint.hidden = true; clearTimeout(timer) }
|
|
32
|
+
const dismiss = event => { if (event.type !== 'keydown' || event.key === 'Escape') hide() }
|
|
33
|
+
controls.addEventListener('pointerdown', dismiss)
|
|
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)
|
|
39
|
+
return {
|
|
40
|
+
dismiss: hide,
|
|
41
|
+
update({ mode, ready, teaching = false }) {
|
|
42
|
+
if (disposed) return
|
|
43
|
+
const active = mode === 'online' && ready
|
|
44
|
+
if (!active || teaching) hide()
|
|
45
|
+
if (active && !wasReady && !teaching) {
|
|
46
|
+
hint.hidden = false
|
|
47
|
+
position()
|
|
48
|
+
clearTimeout(timer)
|
|
49
|
+
timer = setTimeout(hide, duration)
|
|
50
|
+
}
|
|
51
|
+
wasReady = active
|
|
52
|
+
},
|
|
53
|
+
dispose() {
|
|
54
|
+
disposed = true
|
|
55
|
+
hide()
|
|
56
|
+
controls.removeEventListener('pointerdown', dismiss)
|
|
57
|
+
document.removeEventListener('keydown', dismiss)
|
|
58
|
+
window.removeEventListener('resize', position)
|
|
59
|
+
window.removeEventListener('scroll', position, true)
|
|
60
|
+
observer.disconnect()
|
|
61
|
+
hint.remove()
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -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
|
@@ -5,7 +5,7 @@ window.__ModuleLoader__.load({
|
|
|
5
5
|
const exports = module.exports
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" })
|
|
7
7
|
|
|
8
|
-
const inject = ["sessions", "conversation", "uiSession"]
|
|
8
|
+
const inject = ["sessions", "conversation", "uiSession", "workspaces"]
|
|
9
9
|
|
|
10
10
|
function apply(ctx) {
|
|
11
11
|
const focusedSession = () => {
|
|
@@ -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)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** Use the same pending objects as DSH's clickable question/approval cards. */
|
|
2
2
|
export function nativeInteractions(ctx) {
|
|
3
3
|
const firstSeen = new WeakMap()
|
|
4
|
-
const pending = () =>
|
|
4
|
+
const pending = () => ctx.uiSession.sessionStatus
|
|
5
|
+
? [...ctx.uiSession.sessionStatus.getSnapshot().values()].map(row => row.pendingInteraction).filter(Boolean)
|
|
6
|
+
: [...ctx.uiSession.pendingInteractions.getSnapshot().values()]
|
|
5
7
|
const publicValue = value => {
|
|
6
8
|
if (!firstSeen.has(value)) firstSeen.set(value, Date.now() / 1000)
|
|
7
9
|
return { id: value.key, session_id: value.sessionId, created_at: firstSeen.get(value),
|
|
@@ -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/rpc.mjs
CHANGED
|
@@ -20,12 +20,13 @@ export function validateRPC(request) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class HarnessRPCExecutor {
|
|
23
|
-
constructor(send, fetchImpl = fetch, diagnostic = () => {}, localComposer = null) {
|
|
23
|
+
constructor(send, fetchImpl = fetch, diagnostic = () => {}, localComposer = null, catalogOrder = rows => orderSessionCatalog(rows, readWorkspaceView())) {
|
|
24
24
|
// Native Window.fetch rejects an RPCExecutor receiver (Illegal invocation).
|
|
25
25
|
// Call the captured function plainly, not as an instance method.
|
|
26
26
|
this.send = send; this.fetch = (...args) => fetchImpl(...args); this.closed = false
|
|
27
27
|
this.diagnostic = diagnostic
|
|
28
28
|
this.localComposer = localComposer
|
|
29
|
+
this.catalogOrder = catalogOrder
|
|
29
30
|
this.connectionId = null; this.seen = new Map(); this.retired = new Set(); this.controllers = new Set()
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -84,7 +85,7 @@ export class HarnessRPCExecutor {
|
|
|
84
85
|
if (response.status === 200 && request.path === '/api/sessions' && Array.isArray(body.sessions)) {
|
|
85
86
|
// Both startup prompt and nth_N resolution read this same browser-local
|
|
86
87
|
// order, including manual drag order; archived rows cannot consume ranks.
|
|
87
|
-
body.sessions =
|
|
88
|
+
body.sessions = this.catalogOrder(body.sessions)
|
|
88
89
|
}
|
|
89
90
|
return { ...envelope, status: response.status, body }
|
|
90
91
|
} catch (error) {
|
package/src/client/settings.html
CHANGED
|
@@ -85,8 +85,6 @@
|
|
|
85
85
|
<details id="advancedConnection"><summary>连接配置</summary>
|
|
86
86
|
<label for="backendUrl">服务地址</label>
|
|
87
87
|
<input id="backendUrl" type="url" placeholder="wss://服务地址/ws?protocol=realtime_v2" autocomplete="off">
|
|
88
|
-
<label for="authToken">访问密钥</label>
|
|
89
|
-
<input id="authToken" type="password" placeholder="请输入访问密钥" autocomplete="new-password" spellcheck="false">
|
|
90
88
|
<div class="row"><button id="saveDuet" disabled>保存连接配置</button></div>
|
|
91
89
|
<div id="settingsMessage" role="status" style="margin-top:10px"></div>
|
|
92
90
|
</details>
|
|
@@ -304,8 +302,6 @@
|
|
|
304
302
|
if (fill) {
|
|
305
303
|
settingsRevision = config.revision;
|
|
306
304
|
$('backendUrl').value = config.backend_url || '';
|
|
307
|
-
$('authToken').value = '';
|
|
308
|
-
$('authToken').placeholder = config.token_placeholder;
|
|
309
305
|
}
|
|
310
306
|
const c = config.connection || {};
|
|
311
307
|
$('duetMark').style.color = c.online || c.tts_only ? '#7fd6a6' : '#ed9b35';
|
|
@@ -337,7 +333,7 @@
|
|
|
337
333
|
$('saveDuet').onclick = async () => {
|
|
338
334
|
$('saveDuet').disabled = true;
|
|
339
335
|
try {
|
|
340
|
-
await api('/voice/config', {method:'PUT', headers:{'Content-Type':'application/json','X-Duplex-Settings':'1'}, body:JSON.stringify({backend_url:$('backendUrl').value.trim(),
|
|
336
|
+
await api('/voice/config', {method:'PUT', headers:{'Content-Type':'application/json','X-Duplex-Settings':'1'}, body:JSON.stringify({backend_url:$('backendUrl').value.trim(), revision:settingsRevision})});
|
|
341
337
|
$('settingsMessage').textContent = '配置已保存;如需语音,请在 DSH 主页面重新打开。';
|
|
342
338
|
await loadDuetConfig(true);
|
|
343
339
|
} catch (error) { $('settingsMessage').textContent = debugEnabled ? `保存失败:${error.message}` : '保存失败,请稍后重试。'; }
|
|
@@ -370,7 +366,7 @@
|
|
|
370
366
|
}
|
|
371
367
|
$('openTutorial').onclick = async () => {
|
|
372
368
|
try {
|
|
373
|
-
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');
|
|
374
370
|
requestTutorial(localStorage);
|
|
375
371
|
$('tutorialStatus').textContent = '请回到 DSH 页面继续教学。';
|
|
376
372
|
} catch { $('tutorialStatus').textContent = '暂时无法打开教学,请允许浏览器存储后重试。'; }
|
|
@@ -379,11 +375,11 @@
|
|
|
379
375
|
setInterval(() => { loadDuetConfig().catch(() => { $('duetConnection').textContent = '语音连接信息不可用'; }); }, 2000);
|
|
380
376
|
void loadNotices();
|
|
381
377
|
setInterval(loadNotices, 60000);
|
|
382
|
-
import('/duet/assets/client/shortcuts.mjs?v=0.1.
|
|
378
|
+
import('/duet/assets/client/shortcuts.mjs?v=0.1.3').then(({mountShortcutSettings}) => {
|
|
383
379
|
const dispose = mountShortcutSettings({speaker:$('speakerShortcut'),mic:$('micShortcut'),clearSpeaker:$('clearSpeakerShortcut'),clearMic:$('clearMicShortcut'),status:$('shortcutStatus')});
|
|
384
380
|
window.addEventListener('pagehide', e => {if(!e.persisted)dispose()}, {once:true});
|
|
385
381
|
}).catch(() => { $('shortcutStatus').textContent = '暂时无法加载快捷键设置,请刷新重试。'; });
|
|
386
|
-
import('/duet/assets/client/microphone.mjs?v=0.1.
|
|
382
|
+
import('/duet/assets/client/microphone.mjs?v=0.1.3').then(({mountMicrophoneSettings}) => {
|
|
387
383
|
const dispose = mountMicrophoneSettings({select:$('microphoneDevice'),refresh:$('refreshMicrophones'),status:$('microphoneStatus')});
|
|
388
384
|
window.addEventListener('pagehide', dispose, {once:true});
|
|
389
385
|
}).catch(() => { $('microphoneStatus').textContent = '暂时无法加载麦克风设置,请刷新重试。'; });
|
|
@@ -1,6 +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.
|
|
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'
|
|
4
5
|
export function tutorialAdapter(ctx, state, audio, pollReady) {
|
|
5
6
|
let narration
|
|
6
7
|
const completed = new Map()
|
|
@@ -37,10 +38,12 @@ export function tutorialAdapter(ctx, state, audio, pollReady) {
|
|
|
37
38
|
return s
|
|
38
39
|
}
|
|
39
40
|
return {
|
|
41
|
+
workspaceIssue:()=>workspaceIssue(ctx),
|
|
40
42
|
mode:()=>state.mode,current,
|
|
41
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)}},
|
|
42
44
|
unlock:()=>audio.prepare(),
|
|
43
45
|
async create(name,signal){
|
|
46
|
+
requireWorkspace(ctx)
|
|
44
47
|
const catalog=await api('sessions',signal), cwd=catalog.sessions.find(s=>s.session_id===current())?.cwd
|
|
45
48
|
const d=await api('sessions',signal,'POST',{name,...(cwd?{cwd}:{})});return d.session.session_id
|
|
46
49
|
},
|
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.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Workspace readiness and browser-local session ordering shared by all voice paths. */
|
|
2
|
+
import { orderSessionCatalog, readWorkspaceView } from '../shared/catalog.mjs'
|
|
3
|
+
import { focusedSession } from './composer.mjs'
|
|
4
|
+
|
|
5
|
+
export function workspaceIssue(ctx) {
|
|
6
|
+
const snapshot = ctx.workspaces?.list?.getSnapshot()
|
|
7
|
+
if (!snapshot || snapshot.phase !== 'ready' || snapshot.state === 'loading') return 'workspace_loading'
|
|
8
|
+
if (snapshot.state === 'error') return 'workspace_unavailable'
|
|
9
|
+
return snapshot.items.length ? null : 'workspace_required'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function requireWorkspace(ctx) {
|
|
13
|
+
const issue = workspaceIssue(ctx)
|
|
14
|
+
if (issue) throw Error(issue)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function browserSessionCatalog(ctx, rows) {
|
|
18
|
+
const snapshot = ctx.sessions.list.getSnapshot()
|
|
19
|
+
const active = focusedSession(ctx)
|
|
20
|
+
const archived = new Set(ctx.workspaces?.list?.getSnapshot().archivedSessionIds || [])
|
|
21
|
+
return orderSessionCatalog(rows.filter(row => !archived.has(row.session_id)).map(row => ({
|
|
22
|
+
...row, active: row.session_id === active,
|
|
23
|
+
updated_at: snapshot.byId?.[row.session_id]?.updatedAt ?? row.updated_at,
|
|
24
|
+
})), readWorkspaceView())
|
|
25
|
+
}
|
package/src/host/assets.mjs
CHANGED
|
@@ -6,6 +6,10 @@ const modules = {
|
|
|
6
6
|
interactions: 'client/interactions', tutorial: 'client/tutorial',
|
|
7
7
|
tutorial_adapter: 'client/tutorial-adapter', tutorial_request: 'client/tutorial-request',
|
|
8
8
|
feedback: 'client/feedback', consent: 'client/consent',
|
|
9
|
+
connection_hint: 'client/connection-hint',
|
|
10
|
+
controls_layout: 'client/controls-layout',
|
|
11
|
+
notice: 'client/notice',
|
|
12
|
+
workspaces: 'client/workspaces',
|
|
9
13
|
}
|
|
10
14
|
const aliases = {
|
|
11
15
|
state: 'DuetState as VoiceState', audio: 'DuetAudio as VoiceAudio',
|
package/src/host/plugin.mjs
CHANGED
|
@@ -173,7 +173,7 @@ export function apply(ctx, options = {}) {
|
|
|
173
173
|
const feedbackStore = options.feedbackStore ?? (options.feedbackDisabled ? null : new RemoteFeedback(()=>settings.effective(),{keyPath:options.feedbackIdentityPath}))
|
|
174
174
|
const feedback = new FeedbackService(feedbackStore)
|
|
175
175
|
let duetProxy
|
|
176
|
-
ctx.effect(() => { duetProxy = registerDuetProxy(ctx, voice, feedback); return duetProxy })
|
|
176
|
+
ctx.effect(() => { duetProxy = registerDuetProxy(ctx, voice, feedback, () => (ctx.workspaceRegistry.list?.() || []).length > 0); return duetProxy })
|
|
177
177
|
|
|
178
178
|
ctx.effect(() => () => { hostAbort.abort() })
|
|
179
179
|
|
package/src/host/proxy.mjs
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import { createRequire } from 'node:module'
|
|
3
3
|
import { DuetTrace } from './trace.mjs'
|
|
4
4
|
import { duetEnv } from './environment.mjs'
|
|
5
|
+
import { DEFAULT_DUET_URL, publicServiceAuthorization } from './service-defaults.mjs'
|
|
6
|
+
export { DEFAULT_DUET_URL } from './service-defaults.mjs'
|
|
5
7
|
const require = createRequire(import.meta.url)
|
|
6
|
-
export const DEFAULT_DUET_URL = 'ws://duet-router.1781574661016173.ap-southeast-1.pai-eas.aliyuncs.com/ws?protocol=realtime_v2'
|
|
7
8
|
|
|
8
9
|
export function compatibleVersion(version, min = '0.1.0', maxExclusive = '0.2.0') {
|
|
9
10
|
const parse = v => /^\d+\.\d+\.\d+$/.test(v || '') ? v.split('.').map(Number) : null
|
|
@@ -13,15 +14,16 @@ export function compatibleVersion(version, min = '0.1.0', maxExclusive = '0.2.0'
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export function duetConfig(env = process.env) {
|
|
17
|
+
const endpoints = {
|
|
18
|
+
online: duetEnv('ONLINE_URL', env) || duetEnv('URL', env) || DEFAULT_DUET_URL,
|
|
19
|
+
tts_only: duetEnv('TTS_ONLY_URL', env) || duetEnv('URL', env) || DEFAULT_DUET_URL,
|
|
20
|
+
}
|
|
16
21
|
return {
|
|
17
22
|
min_version: duetEnv('MIN_VERSION', env) || '0.1.0',
|
|
18
23
|
max_version_exclusive: duetEnv('MAX_VERSION_EXCLUSIVE', env) || '0.2.0',
|
|
19
24
|
control_transport: duetEnv('CONTROL_TRANSPORT', env) || 'client_rpc_v1',
|
|
20
|
-
authorization:
|
|
21
|
-
endpoints
|
|
22
|
-
online: duetEnv('ONLINE_URL', env) || duetEnv('URL', env) || DEFAULT_DUET_URL,
|
|
23
|
-
tts_only: duetEnv('TTS_ONLY_URL', env) || duetEnv('URL', env) || DEFAULT_DUET_URL,
|
|
24
|
-
},
|
|
25
|
+
authorization: publicServiceAuthorization(endpoints),
|
|
26
|
+
endpoints,
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -42,7 +44,7 @@ export function externalWithState(message, _state) {
|
|
|
42
44
|
...(source === undefined ? {} : { source: { ...source } }) }
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
export function registerDuetProxy(ctx, config = duetConfig(), feedback = null) {
|
|
47
|
+
export function registerDuetProxy(ctx, config = duetConfig(), feedback = null, canUseVoice = () => true) {
|
|
46
48
|
if (!['http', 'client_rpc_v1'].includes(config.control_transport || 'http')) throw new Error('invalid_harness_transport')
|
|
47
49
|
if (!compatibleVersion(config.min_version, config.min_version, config.max_version_exclusive)) throw new Error('invalid_plugin_version_policy')
|
|
48
50
|
for (const target of Object.values(config.endpoints)) {
|
|
@@ -92,6 +94,7 @@ export function registerDuetProxy(ctx, config = duetConfig(), feedback = null) {
|
|
|
92
94
|
const mode = params.get('mode')
|
|
93
95
|
if (!compatibleVersion(params.get('plugin_version'), config.min_version, config.max_version_exclusive)) { fail('plugin_upgrade_required'); return }
|
|
94
96
|
if (!['online', 'tts_only'].includes(mode)) { fail('invalid_voice_mode'); return }
|
|
97
|
+
if (!canUseVoice()) { fail('workspace_required'); return }
|
|
95
98
|
connections.set(front, { mode, ready: false, trace })
|
|
96
99
|
front.on('close', () => connections.delete(front))
|
|
97
100
|
const target = config.endpoints[mode]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Public trial connection details distributed with the plugin. */
|
|
2
|
+
export const DEFAULT_DUET_URL = 'ws://duet-router.1781574661016173.ap-southeast-1.pai-eas.aliyuncs.com/ws?protocol=realtime_v2'
|
|
3
|
+
export const PUBLIC_TRIAL_AUTHORIZATION = "ZTZhZWI4YzA3ODcyZWI2NzZhZjU4MDk3NGE3NGUxODQ2MjgxYWVjYQ=="
|
|
4
|
+
|
|
5
|
+
/** Never forward the trial credential to a user-selected third-party service. */
|
|
6
|
+
export function publicServiceAuthorization(endpoints) {
|
|
7
|
+
const urls = Object.values(endpoints)
|
|
8
|
+
return urls.length && urls.every(value => {
|
|
9
|
+
const url = new URL(value), expected = new URL(DEFAULT_DUET_URL)
|
|
10
|
+
return url.origin === expected.origin && url.pathname === expected.pathname && !url.username && !url.password
|
|
11
|
+
}) ? PUBLIC_TRIAL_AUTHORIZATION : ''
|
|
12
|
+
}
|
package/src/host/settings.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
/** Host-only settings
|
|
1
|
+
/** Host-only endpoint settings; trial authentication comes from the package. */
|
|
2
2
|
import { readFileSync } from 'node:fs'
|
|
3
3
|
import { mkdir, writeFile, rename, unlink } from 'node:fs/promises'
|
|
4
4
|
import { dirname, join } from 'node:path'
|
|
5
5
|
import { homedir } from 'node:os'
|
|
6
6
|
import { randomUUID } from 'node:crypto'
|
|
7
7
|
import { duetEnv } from './environment.mjs'
|
|
8
|
+
import { publicServiceAuthorization } from './service-defaults.mjs'
|
|
8
9
|
|
|
9
10
|
export function validateBackendURL(value, insecureOrigin = null) {
|
|
10
11
|
if (typeof value !== 'string' || value.length > 2048) throw new Error('invalid_backend_url')
|
|
11
12
|
const url = new URL(value)
|
|
12
13
|
if (!['ws:', 'wss:'].includes(url.protocol) || url.username || url.password || url.hash) throw new Error('invalid_backend_url')
|
|
13
|
-
// Credentials belong in
|
|
14
|
+
// Credentials never belong in URLs or logs.
|
|
14
15
|
if ([...url.searchParams.keys()].some(k => k !== 'protocol')) throw new Error('backend_url_query_not_allowed')
|
|
15
16
|
if (url.protocol === 'ws:' && !['localhost', '127.0.0.1', '[::1]'].includes(url.hostname) && url.origin !== insecureOrigin) throw new Error('backend_requires_wss')
|
|
16
17
|
return url.toString()
|
|
@@ -33,15 +34,14 @@ export class DuetSettings {
|
|
|
33
34
|
validate(data) {
|
|
34
35
|
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('invalid_voice_settings')
|
|
35
36
|
const backend_url = validateBackendURL(data.backend_url, data.insecure_origin)
|
|
36
|
-
const auth_token = data.auth_token
|
|
37
|
-
if (typeof auth_token !== 'string' || auth_token.length > 8192 || /[\r\n\0]/.test(auth_token)) throw new Error('invalid_auth_token')
|
|
38
37
|
const url = new URL(backend_url)
|
|
39
38
|
const insecure_origin = url.protocol === 'ws:' && url.origin === data.insecure_origin ? url.origin : null
|
|
40
|
-
return { backend_url,
|
|
39
|
+
return { backend_url, ...(insecure_origin ? { insecure_origin } : {}) }
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
effective() {
|
|
44
|
-
|
|
43
|
+
const endpoints = this.saved ? { online: this.saved.backend_url, tts_only: this.saved.backend_url } : this.base.endpoints
|
|
44
|
+
return { ...this.base, endpoints, authorization: publicServiceAuthorization(endpoints) }
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
public() {
|
|
@@ -56,7 +56,7 @@ export class DuetSettings {
|
|
|
56
56
|
min_version: config.min_version, max_version_exclusive: config.max_version_exclusive,
|
|
57
57
|
modes: Object.keys(config.endpoints), endpoints,
|
|
58
58
|
backend_url: endpoints.online, config_source: this.saved ? 'plugin_settings' : 'environment_or_default',
|
|
59
|
-
auth_configured: Boolean(config.authorization),
|
|
59
|
+
auth_configured: Boolean(config.authorization),
|
|
60
60
|
debug: this.debug, revision: this.revision,
|
|
61
61
|
insecure_transport: new URL(config.endpoints.online).protocol !== 'wss:',
|
|
62
62
|
}
|
|
@@ -65,15 +65,10 @@ export class DuetSettings {
|
|
|
65
65
|
async save(input) {
|
|
66
66
|
if (this.writing) throw new Error('settings_write_in_progress')
|
|
67
67
|
if (!input || input.revision !== this.revision) throw new Error('settings_revision_conflict')
|
|
68
|
-
const current = this.effective()
|
|
69
68
|
// A deliberate, authenticated per-origin opt-in, never a global TLS bypass.
|
|
70
69
|
const insecureOrigin = input.allow_insecure_http === true ? new URL(input.backend_url).origin : this.saved?.insecure_origin
|
|
71
70
|
const url = validateBackendURL(input.backend_url, insecureOrigin)
|
|
72
|
-
|
|
73
|
-
const token = input.auth_token === '' || input.auth_token === undefined
|
|
74
|
-
? url === current.endpoints.online ? current.authorization || 'test' : 'test'
|
|
75
|
-
: input.auth_token
|
|
76
|
-
const next = this.validate({ backend_url: url, auth_token: token, insecure_origin: insecureOrigin })
|
|
71
|
+
const next = this.validate({ backend_url: url, insecure_origin: insecureOrigin })
|
|
77
72
|
this.writing = true
|
|
78
73
|
const temp = `${this.path}.${randomUUID()}.tmp`
|
|
79
74
|
try {
|
package/src/shared/catalog.mjs
CHANGED
|
@@ -19,10 +19,21 @@ function reconcile(rows, ids) {
|
|
|
19
19
|
export function orderSessionCatalog(rows, view = {}) {
|
|
20
20
|
const visible = rows.filter(row => !row.archived && row.origin !== 'subagent' && (!row.blank || row.active))
|
|
21
21
|
const accounts = view?.sessionOrderByAccount || {}
|
|
22
|
+
// 0.1.5 persists the effective activity-promoted order; 0.1.6 derives recency
|
|
23
|
+
// live and keeps stored orders only for manual mode (same v5 storage key).
|
|
24
|
+
const legacy = Object.hasOwn(view, 'sessionUpdatedAtByAccount')
|
|
25
|
+
const recent = members => [...members].sort((a,b) => (b.updated_at || 0) - (a.updated_at || 0)
|
|
26
|
+
|| (String(a.session_id) < String(b.session_id) ? -1 : 1))
|
|
27
|
+
const ordered = (members, key) => {
|
|
28
|
+
const stored = accounts[key]
|
|
29
|
+
const updated = (view.orderBy || 'updated') === 'updated'
|
|
30
|
+
const result = updated && (!legacy || !Array.isArray(stored))
|
|
31
|
+
? recent(members) : reconcile(members, stored)
|
|
32
|
+
if (legacy) return result
|
|
33
|
+
return [...result.filter(row => row.blank && row.active), ...result.filter(row => !row.blank || !row.active)]
|
|
34
|
+
}
|
|
22
35
|
if (view?.groupBy === 'flat') {
|
|
23
|
-
|
|
24
|
-
|| String(a.session_id).localeCompare(String(b.session_id)))
|
|
25
|
-
return reconcile(recent, accounts.__flat_session_order__)
|
|
36
|
+
return ordered(visible, '__flat_session_order__')
|
|
26
37
|
}
|
|
27
38
|
const groups = new Map()
|
|
28
39
|
for (const row of visible) {
|
|
@@ -30,7 +41,7 @@ export function orderSessionCatalog(rows, view = {}) {
|
|
|
30
41
|
if (!groups.has(key)) groups.set(key, [])
|
|
31
42
|
groups.get(key).push(row)
|
|
32
43
|
}
|
|
33
|
-
return [...groups].flatMap(([key, members]) =>
|
|
44
|
+
return [...groups].flatMap(([key, members]) => ordered(members, key))
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
export function buildSessionCatalog(items, {workspaces = [], archivedIds = [], activeId, includeBlank = false} = {}) {
|
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 : ''
|
|
@@ -105,7 +105,14 @@ export class DuetState {
|
|
|
105
105
|
return
|
|
106
106
|
}
|
|
107
107
|
const policyNotices = {
|
|
108
|
+
workspace_required: '请先在 DSH 中创建 workspace,再开启 duet。',
|
|
109
|
+
workspace_loading: '正在加载 workspace,请稍后再试。',
|
|
110
|
+
workspace_unavailable: '无法读取 workspace,请刷新 DSH 后重试。',
|
|
108
111
|
microphone_unavailable: '无法使用所选麦克风,请在设置中检查设备与浏览器权限',
|
|
112
|
+
microphone_disconnected: '麦克风已断开或权限已撤销,交互模式已关闭。请检查设备后重新开启。',
|
|
113
|
+
audio_capture_failed: '麦克风采集异常,交互模式已关闭。请检查设备后重新开启。',
|
|
114
|
+
voice_start_timeout: '连接超时,请检查网络或麦克风授权后重新开启。',
|
|
115
|
+
harness_sync_failed: '无法继续同步 DSH 会话,语音已关闭。请检查 DSH 后重新开启。',
|
|
109
116
|
interaction_mode_unavailable: '交互模式暂时不可用,请稍后再试',
|
|
110
117
|
broadcast_mode_unavailable: '播报模式暂时不可用,请稍后再试',
|
|
111
118
|
client_protocol_unsupported: '插件与服务器协议不兼容,请更新插件或联系服务管理员',
|