dsh-duet 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -16
- package/package.json +31 -20
- package/{deepseek_harness_voice_audio.mjs → src/client/audio.mjs} +4 -4
- package/{deepseek_harness_voice_browser.mjs → src/client/browser.mjs} +18 -18
- package/{deepseek_harness_duplex_focus_client/lib/client.js → src/client/entry.js} +14 -14
- package/{deepseek_harness_voice_rpc.mjs → src/client/rpc.mjs} +1 -1
- package/{deepseek_harness_duplex_control_plugin.html → src/client/settings.html} +17 -17
- package/{deepseek_harness_voice_shortcuts.mjs → src/client/shortcuts.mjs} +1 -1
- package/{deepseek_harness_voice_tutorial_adapter.mjs → src/client/tutorial-adapter.mjs} +2 -2
- package/{deepseek_harness_voice_tutorial.mjs → src/client/tutorial.mjs} +15 -15
- package/src/host/assets.mjs +26 -0
- package/src/host/environment.mjs +10 -0
- package/{deepseek_harness_duplex_control_plugin.mjs → src/host/plugin.mjs} +34 -32
- package/{deepseek_harness_voice_proxy.mjs → src/host/proxy.mjs} +12 -11
- package/{deepseek_harness_voice_settings.mjs → src/host/settings.mjs} +3 -2
- package/{deepseek_harness_voice_trace.mjs → src/host/trace.mjs} +4 -3
- package/{deepseek_harness_voice_state.mjs → src/shared/state.mjs} +2 -2
- /package/{tutorial-audio → assets/tutorial-audio}/broadcast.wav +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/clear.wav +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/edit.wav +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/input.wav +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/manifest.json +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/modes_broadcast.wav +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/modes_interaction.wav +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/reinput.wav +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/send.wav +0 -0
- /package/{tutorial-audio → assets/tutorial-audio}/switch.wav +0 -0
- /package/{deepseek_harness_duplex_control.patch.yml → config/duet.patch.yml} +0 -0
- /package/{deepseek_harness_voice_composer.mjs → src/client/composer.mjs} +0 -0
- /package/{deepseek_harness_voice_consent.mjs → src/client/consent.mjs} +0 -0
- /package/{deepseek_harness_voice_feedback.mjs → src/client/feedback.mjs} +0 -0
- /package/{deepseek_harness_voice_interactions.mjs → src/client/interactions.mjs} +0 -0
- /package/{deepseek_harness_voice_microphone.mjs → src/client/microphone.mjs} +0 -0
- /package/{deepseek_harness_voice_tutorial_request.mjs → src/client/tutorial-request.mjs} +0 -0
- /package/{deepseek_harness_voice_feedback_files.mjs → src/host/feedback-files.mjs} +0 -0
- /package/{deepseek_harness_voice_feedback_store.mjs → src/host/feedback-store.mjs} +0 -0
- /package/{deepseek_harness_voice_notices.mjs → src/host/notices.mjs} +0 -0
- /package/{deepseek_harness_voice_service_info.mjs → src/host/service-info.mjs} +0 -0
- /package/{deepseek_harness_voice_catalog.mjs → src/shared/catalog.mjs} +0 -0
package/README.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# duet
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
它可以边听边说,你不必等它说完再开口:随时插话、补充需求、修改内容,让对话自然接续。
|
|
5
|
-
你可以用语音输入和提交任务、切换会话;任务完成后,dsh-duet 会简要播报结果。除此之外,你还可以跟 dsh-duet 聊聊天。
|
|
3
|
+
**只用语音,就能操作 DeepSeek Harness(DSH)。**
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
duet,意为「二重奏」。这里的 duet 使用全双工语音模型,可以边听边说,
|
|
6
|
+
让你与 DSH 的交流不必一人一句地等待。
|
|
7
|
+
|
|
8
|
+
说出需求、修改输入、发送任务、切换会话——把键盘上的操作交给声音。
|
|
9
|
+
任务完成后,duet 会简短播报结果,让你不用一直盯着屏幕。
|
|
10
|
+
|
|
11
|
+
你可以随时插话、补充或纠正。处理任务之外,也可以聊聊天。
|
|
12
|
+
|
|
13
|
+
目前处于**试用阶段**,duet 语音服务可以免费使用。
|
|
9
14
|
|
|
10
15
|
## 安装
|
|
11
16
|
|
|
@@ -30,17 +35,14 @@ dsh web
|
|
|
30
35
|
|
|
31
36
|
## 使用
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
默认两个模式都关闭。
|
|
38
|
+
duet 支持两种模式。
|
|
35
39
|
|
|
36
40
|
| 按钮 | 模式 | 用途 |
|
|
37
41
|
| --- | --- | --- |
|
|
38
42
|
| 喇叭 | 播报模式 | 任务完成后,进行简短的播报 |
|
|
39
43
|
| 双向箭头 | 交互模式 | 开口操作 DSH、自由聊天,也可以在回复过程中插话 |
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### 支持的语音操作
|
|
45
|
+
### 目前支持的语音操作
|
|
44
46
|
|
|
45
47
|
| 操作 | 你可以这样说 |
|
|
46
48
|
| --- | --- |
|
|
@@ -53,20 +55,17 @@ dsh web
|
|
|
53
55
|
| 重命名会话 | “把当前会话改名为周末安排” |
|
|
54
56
|
| 分叉会话 | “从当前会话分叉一个新会话” |
|
|
55
57
|
| 归档会话 | “归档这个会话” |
|
|
58
|
+
| 回答 DSH 的问题 | “选第二个”“用中文就好” |
|
|
56
59
|
| 自由聊天 | “什么是全双工语音交互?” |
|
|
57
60
|
|
|
58
|
-
输入和修改不会自动发送,检查内容后再说“发送”。任务结果会在完成后播报。
|
|
59
|
-
设置页还提供服务通知、教学和文字反馈,关闭语音时也可以为本次体验打分。
|
|
60
|
-
|
|
61
61
|
## 麦克风与隐私
|
|
62
62
|
|
|
63
63
|
duet 通过服务器提供语音服务。根据所使用的功能,以下信息会上传至服务器,用于理解语音、执行会话操作、生成回复和语音播报:
|
|
64
64
|
|
|
65
65
|
- 交互模式开启期间,麦克风采集的交互音频。
|
|
66
|
-
-
|
|
67
|
-
-
|
|
66
|
+
- 交互所需的会话信息,例如会话标识、名称、运行状态和当前会话名称。
|
|
67
|
+
- 交互所需的输入框内容、任务结果。
|
|
68
68
|
|
|
69
|
-
关闭交互模式后,会停止采集和上传麦克风音频。
|
|
70
69
|
请勿在交互中提供密码、密钥等敏感内容。
|
|
71
70
|
|
|
72
71
|
**目前仅支持中文。**
|
package/package.json
CHANGED
|
@@ -1,27 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-duet",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "duet
|
|
5
|
-
"keywords": [
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "duet(二重奏):只用语音就能操作 DSH,边听边说、随时插话的全双工语音助手。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh-plugin",
|
|
7
|
+
"deepseek-harness",
|
|
8
|
+
"full-duplex",
|
|
9
|
+
"voice"
|
|
10
|
+
],
|
|
6
11
|
"license": "Apache-2.0",
|
|
7
|
-
"author": {
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "YuMS",
|
|
14
|
+
"email": "yumaoshu@gmail.com"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/YuMS/dsh-duet.git"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
22
|
+
},
|
|
10
23
|
"scripts": {
|
|
11
24
|
"test": "node scripts/test.mjs",
|
|
12
25
|
"check": "node scripts/check-package.mjs",
|
|
13
|
-
"test:browser": "node
|
|
14
|
-
"test:host": "node
|
|
26
|
+
"test:browser": "node tests/browser/settings.mjs && node tests/browser/tutorial.mjs && node tests/browser/feedback.mjs",
|
|
27
|
+
"test:host": "node tests/host/isolated-host.mjs",
|
|
15
28
|
"prepack": "npm run check"
|
|
16
29
|
},
|
|
17
30
|
"type": "module",
|
|
18
|
-
"main": "./
|
|
31
|
+
"main": "./src/host/plugin.mjs",
|
|
19
32
|
"exports": {
|
|
20
33
|
".": {
|
|
21
|
-
"default": "./
|
|
34
|
+
"default": "./src/host/plugin.mjs"
|
|
22
35
|
},
|
|
23
36
|
"./client": {
|
|
24
|
-
"default": "./
|
|
37
|
+
"default": "./src/client/entry.js"
|
|
25
38
|
},
|
|
26
39
|
"./package.json": "./package.json"
|
|
27
40
|
},
|
|
@@ -29,21 +42,19 @@
|
|
|
29
42
|
"LICENSE",
|
|
30
43
|
"NOTICE",
|
|
31
44
|
"HEROICONS-LICENSE.txt",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"tutorial-audio/
|
|
35
|
-
"deepseek_harness_duplex_control.patch.yml",
|
|
36
|
-
"deepseek_harness_duplex_control_plugin.mjs",
|
|
37
|
-
"deepseek_harness_duplex_control_plugin.html",
|
|
38
|
-
"deepseek_harness_duplex_focus_client/lib/client.js"
|
|
45
|
+
"src/",
|
|
46
|
+
"config/",
|
|
47
|
+
"assets/tutorial-audio/"
|
|
39
48
|
],
|
|
40
49
|
"dependencies": {
|
|
41
50
|
"ws": "^8.18.3"
|
|
42
51
|
},
|
|
43
|
-
"devDependencies": {
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"playwright": "1.58.2"
|
|
54
|
+
},
|
|
44
55
|
"dsh": {
|
|
45
56
|
"bundle": {
|
|
46
|
-
"patch": "./
|
|
57
|
+
"patch": "./config/duet.patch.yml"
|
|
47
58
|
},
|
|
48
59
|
"client": {
|
|
49
60
|
"inject": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { microphoneConstraints } from './
|
|
1
|
+
import { microphoneConstraints } from './microphone.mjs?v=0.1.1'
|
|
2
2
|
|
|
3
3
|
/** Browser-owned microphone and PCM playback. No microphone is requested in tts_only. */
|
|
4
|
-
export class
|
|
4
|
+
export class DuetAudio {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.context = null
|
|
7
7
|
this.stream = null
|
|
@@ -48,14 +48,14 @@ export class VoiceAudio {
|
|
|
48
48
|
for(const x of a){this.sum+=x;this.count++;this.phase+=16000;
|
|
49
49
|
if(this.phase>=sampleRate){this.phase-=sampleRate;const v=Math.max(-1,Math.min(1,this.sum/this.count));this.pcm[this.offset++]=v<0?v*32768:v*32767;this.sum=0;this.count=0;
|
|
50
50
|
if(this.offset===1280){this.port.postMessage(this.pcm.buffer,[this.pcm.buffer]);this.pcm=new Int16Array(1280);this.offset=0;}}}return true;}}
|
|
51
|
-
registerProcessor('
|
|
51
|
+
registerProcessor('duet-audio-capture',Capture)`
|
|
52
52
|
if (!this.captureLoaded) {
|
|
53
53
|
const url = URL.createObjectURL(new Blob([code], { type: 'text/javascript' }))
|
|
54
54
|
try { await this.context.audioWorklet.addModule(url); this.captureLoaded = true } finally { URL.revokeObjectURL(url) }
|
|
55
55
|
}
|
|
56
56
|
if (epoch !== this.epoch) { stream.getTracks().forEach(t => t.stop()); return }
|
|
57
57
|
this.source = this.context.createMediaStreamSource(stream)
|
|
58
|
-
this.capture = new AudioWorkletNode(this.context, '
|
|
58
|
+
this.capture = new AudioWorkletNode(this.context, 'duet-audio-capture')
|
|
59
59
|
this.capture.port.onmessage = e => { if (epoch === this.epoch) send(e.data) }
|
|
60
60
|
this.mute = this.context.createGain()
|
|
61
61
|
this.mute.gain.value = 0
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { HarnessRPCExecutor } from './
|
|
4
|
-
import { composerAccess, observeComposer, focusedSession } from './
|
|
5
|
-
import { mountTutorial } from './
|
|
6
|
-
import { tutorialAdapter } from './
|
|
7
|
-
import { mountRating } from './
|
|
8
|
-
import { createAudioUploadConsent } from './
|
|
9
|
-
import {
|
|
10
|
-
import { nativeInteractions } from './
|
|
1
|
+
import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.1'
|
|
2
|
+
import { DuetAudio } from './audio.mjs?v=0.1.1'
|
|
3
|
+
import { HarnessRPCExecutor } from './rpc.mjs?v=0.1.1'
|
|
4
|
+
import { composerAccess, observeComposer, focusedSession } from './composer.mjs?v=0.1.1'
|
|
5
|
+
import { mountTutorial } from './tutorial.mjs?v=0.1.1'
|
|
6
|
+
import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.1.1'
|
|
7
|
+
import { mountRating } from './feedback.mjs?v=0.1.1'
|
|
8
|
+
import { createAudioUploadConsent } from './consent.mjs?v=0.1.1'
|
|
9
|
+
import { bindDuetShortcuts } from './shortcuts.mjs?v=0.1.1'
|
|
10
|
+
import { nativeInteractions } from './interactions.mjs?v=0.1.1'
|
|
11
11
|
|
|
12
|
-
export function
|
|
13
|
-
const audio = new
|
|
12
|
+
export function mountDuet(ctx) {
|
|
13
|
+
const audio = new DuetAudio()
|
|
14
14
|
const audioConsent = createAudioUploadConsent()
|
|
15
15
|
let disposed = false, controls, toastTimer, pollRunning = false, cursor = null, resultEpoch = null
|
|
16
16
|
const labels = new Map()
|
|
@@ -190,15 +190,15 @@ export function mountVoice(ctx) {
|
|
|
190
190
|
} else queueMicrotask(() => receive({ type: 'error', code: 'voice_lock_unavailable' }))
|
|
191
191
|
return connection
|
|
192
192
|
}
|
|
193
|
-
const state = new
|
|
193
|
+
const state = new DuetState({ connect, changed: draw, notice })
|
|
194
194
|
const mount = () => {
|
|
195
|
-
const entry = document.getElementById('dsh-
|
|
196
|
-
if (!entry || document.getElementById('dsh-
|
|
195
|
+
const entry = document.getElementById('dsh-duet-entry')
|
|
196
|
+
if (!entry || document.getElementById('dsh-duet-controls')) return
|
|
197
197
|
controls = document.createElement('div')
|
|
198
|
-
controls.id = 'dsh-
|
|
198
|
+
controls.id = 'dsh-duet-controls'
|
|
199
199
|
controls.style.cssText = 'display:flex;gap:4px;position:relative;padding:6px 8px;align-items:center;margin:4px 8px;max-width:100%'
|
|
200
200
|
const style = document.createElement('style')
|
|
201
|
-
style.textContent = '@keyframes duet-connecting-snake{from{stroke-dashoffset:0}to{stroke-dashoffset:-100}} #dsh-
|
|
201
|
+
style.textContent = '@keyframes duet-connecting-snake{from{stroke-dashoffset:0}to{stroke-dashoffset:-100}} #dsh-duet-controls [data-connecting-ring]{position:absolute;inset:0;pointer-events:none} #dsh-duet-controls [data-connecting-ring] svg{display:block;width:100%;height:100%;overflow:visible} #dsh-duet-controls [data-connecting-ring] rect{fill:none;stroke:#ed9b35;stroke-width:2;stroke-linecap:round;stroke-dasharray:28 72;animation:duet-connecting-snake 1.6s linear infinite!important} #dsh-duet-controls [data-connecting-ring][hidden]{display:none}'
|
|
202
202
|
controls.append(style)
|
|
203
203
|
const parent = entry.parentElement
|
|
204
204
|
parent.insertBefore(controls, entry)
|
|
@@ -260,7 +260,7 @@ export function mountVoice(ctx) {
|
|
|
260
260
|
draw(state)
|
|
261
261
|
}
|
|
262
262
|
mount()
|
|
263
|
-
const stopShortcuts =
|
|
263
|
+
const stopShortcuts = bindDuetShortcuts(kind => controls?.querySelector(`[data-voice=${kind}]`)?.click())
|
|
264
264
|
const observer = new MutationObserver(mount)
|
|
265
265
|
observer.observe(document.body, { subtree: true, childList: true })
|
|
266
266
|
|
|
@@ -31,13 +31,13 @@ window.__ModuleLoader__.load({
|
|
|
31
31
|
ctx.effect(() => {
|
|
32
32
|
let active = true
|
|
33
33
|
let dispose
|
|
34
|
-
import('/
|
|
35
|
-
if (active) dispose = module.
|
|
36
|
-
}).catch(error => console.warn('
|
|
34
|
+
import('/duet/assets/client/browser.mjs?v=0.1.1').then(module => {
|
|
35
|
+
if (active) dispose = module.mountDuet(ctx)
|
|
36
|
+
}).catch(error => console.warn('duet controls could not load:', error))
|
|
37
37
|
return () => { active = false; dispose?.() }
|
|
38
|
-
}, '
|
|
38
|
+
}, 'duet-client: three-state microphone and playback controls')
|
|
39
39
|
ctx.effect(() => {
|
|
40
|
-
const entryId = "dsh-
|
|
40
|
+
const entryId = "dsh-duet-entry"
|
|
41
41
|
|
|
42
42
|
const mountEntry = () => {
|
|
43
43
|
if (document.getElementById(entryId) !== null) return
|
|
@@ -49,7 +49,7 @@ window.__ModuleLoader__.load({
|
|
|
49
49
|
const entry = document.createElement("span")
|
|
50
50
|
entry.id = entryId
|
|
51
51
|
entry.setAttribute("aria-label", "duet")
|
|
52
|
-
entry.setAttribute("data-
|
|
52
|
+
entry.setAttribute("data-duet-surface", "control-entry")
|
|
53
53
|
entry.style.textDecoration = "none"
|
|
54
54
|
entry.style.marginBottom = "4px"
|
|
55
55
|
|
|
@@ -68,7 +68,7 @@ window.__ModuleLoader__.load({
|
|
|
68
68
|
observer.disconnect()
|
|
69
69
|
document.getElementById(entryId)?.remove()
|
|
70
70
|
}
|
|
71
|
-
}, "
|
|
71
|
+
}, "duet-client: mount main page entry")
|
|
72
72
|
|
|
73
73
|
ctx.effect(() => {
|
|
74
74
|
if (typeof BroadcastChannel === "undefined") return () => {}
|
|
@@ -136,7 +136,7 @@ window.__ModuleLoader__.load({
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
return () => channel.close()
|
|
139
|
-
}, "
|
|
139
|
+
}, "duet-client: bridge current composer")
|
|
140
140
|
|
|
141
141
|
ctx.effect(() => {
|
|
142
142
|
const controller = new AbortController()
|
|
@@ -298,7 +298,7 @@ window.__ModuleLoader__.load({
|
|
|
298
298
|
// rather than spinning if a browser/host upgrade is staggered.
|
|
299
299
|
succeeded = payload.long_poll_supported === true
|
|
300
300
|
} catch (error) {
|
|
301
|
-
if (!controller.signal.aborted) console.warn("
|
|
301
|
+
if (!controller.signal.aborted) console.warn("duet composer RPC failed:", error)
|
|
302
302
|
} finally {
|
|
303
303
|
pollRunning = false
|
|
304
304
|
if (!controller.signal.aborted) {
|
|
@@ -321,7 +321,7 @@ window.__ModuleLoader__.load({
|
|
|
321
321
|
window.removeEventListener?.('pageshow', resume)
|
|
322
322
|
if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', resume)
|
|
323
323
|
}
|
|
324
|
-
}, "
|
|
324
|
+
}, "duet-client: bridge server composer RPC")
|
|
325
325
|
|
|
326
326
|
ctx.effect(() => {
|
|
327
327
|
const controller = new AbortController()
|
|
@@ -361,7 +361,7 @@ window.__ModuleLoader__.load({
|
|
|
361
361
|
})
|
|
362
362
|
if (response.ok) observeEpoch((await response.json()).focus_epoch)
|
|
363
363
|
} catch (error) {
|
|
364
|
-
if (!controller.signal.aborted) console.warn("
|
|
364
|
+
if (!controller.signal.aborted) console.warn("duet heartbeat failed:", error)
|
|
365
365
|
} finally {
|
|
366
366
|
heartbeatRunning = false
|
|
367
367
|
}
|
|
@@ -393,7 +393,7 @@ window.__ModuleLoader__.load({
|
|
|
393
393
|
lastPublishedSession = sessionId
|
|
394
394
|
} while (publishPending)
|
|
395
395
|
} catch (error) {
|
|
396
|
-
if (!controller.signal.aborted) console.warn("
|
|
396
|
+
if (!controller.signal.aborted) console.warn("duet selection publish failed:", error)
|
|
397
397
|
} finally {
|
|
398
398
|
publishRunning = false
|
|
399
399
|
}
|
|
@@ -426,7 +426,7 @@ window.__ModuleLoader__.load({
|
|
|
426
426
|
else ctx.sessions.open(focus.session_id)
|
|
427
427
|
lastRevision = focus.revision
|
|
428
428
|
} catch (error) {
|
|
429
|
-
if (!controller.signal.aborted) console.warn("
|
|
429
|
+
if (!controller.signal.aborted) console.warn("duet focus sync failed:", error)
|
|
430
430
|
} finally {
|
|
431
431
|
pollRunning = false
|
|
432
432
|
}
|
|
@@ -456,7 +456,7 @@ window.__ModuleLoader__.load({
|
|
|
456
456
|
window.removeEventListener?.('pageshow', onVisibilityChange)
|
|
457
457
|
unsubscribe()
|
|
458
458
|
}
|
|
459
|
-
}, "
|
|
459
|
+
}, "duet-client: synchronize host and browser focus")
|
|
460
460
|
}
|
|
461
461
|
|
|
462
462
|
exports.apply = apply
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Reverse RPC executes on this authenticated DSH origin, never a supplied URL. */
|
|
2
|
-
import { orderSessionCatalog, readWorkspaceView } from '
|
|
2
|
+
import { orderSessionCatalog, readWorkspaceView } from '../shared/catalog.mjs'
|
|
3
3
|
const MAX_BYTES = 256_000
|
|
4
4
|
const READ = /^\/api\/(?:health|sessions|jobs|results|interactions|composer\/focused|sessions\/[A-Za-z0-9_-]+\/composer)$/
|
|
5
5
|
const WRITE = /^\/api\/(?:sessions\/[A-Za-z0-9_-]+\/(?:composer\/submit|activate|rename|fork)|interactions\/(?:(?:question|approval)(?::|%3[Aa]))?[A-Za-z0-9_-]+\/respond)$/
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
button.secondary { background:#2c3b33;color:#dcebe3 }
|
|
59
59
|
details { border-top:1px solid #303d36;margin-top:24px;padding-top:20px }
|
|
60
60
|
summary { cursor:pointer;color:#c2d6c9;font-size:13px;user-select:none }
|
|
61
|
-
#
|
|
61
|
+
#saveDuet { width:auto;min-width:150px;margin-top:12px }
|
|
62
62
|
.section-note { color:#92a69b;font-size:13px;line-height:1.8;margin:0 0 18px }
|
|
63
63
|
footer { font-size:12px;color:#71867a;display:flex;justify-content:space-between;margin-top:28px }
|
|
64
64
|
@media(max-width:600px) { main{padding:32px 18px}.cards{grid-template-columns:1fr}.panel{padding:20px}h1{font-size:42px} }
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
<h2>连接概览</h2>
|
|
77
77
|
<p class="section-note">选择一种语音模式,点击当前模式即可关闭。</p>
|
|
78
78
|
<div class="cards">
|
|
79
|
-
<div class="metric"><small>当前模式</small><strong id="
|
|
79
|
+
<div class="metric"><small>当前模式</small><strong id="duetConnection">全部关闭</strong></div>
|
|
80
80
|
<div class="metric"><small>服务配置</small><strong id="authState">检查中</strong></div>
|
|
81
81
|
<div class="metric"><small>插件版本</small><strong id="pluginVersion">检查中</strong></div>
|
|
82
82
|
<div class="metric"><small>双工模型</small><strong id="duplexModel" style="font-size:16px;overflow-wrap:anywhere">检查中</strong></div>
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
<input id="backendUrl" type="url" placeholder="wss://服务地址/ws?protocol=realtime_v2" autocomplete="off">
|
|
88
88
|
<label for="authToken">访问密钥</label>
|
|
89
89
|
<input id="authToken" type="password" placeholder="请输入访问密钥" autocomplete="new-password" spellcheck="false">
|
|
90
|
-
<div class="row"><button id="
|
|
90
|
+
<div class="row"><button id="saveDuet" disabled>保存连接配置</button></div>
|
|
91
91
|
<div id="settingsMessage" role="status" style="margin-top:10px"></div>
|
|
92
92
|
</details>
|
|
93
93
|
</section>
|
|
@@ -215,11 +215,11 @@
|
|
|
215
215
|
if (!health.browser_client_connected) {
|
|
216
216
|
card.classList.add("disconnected");
|
|
217
217
|
$("connectionTitle").textContent = "DSH 主页面未连接";
|
|
218
|
-
$("connectionDetail").textContent = debugEnabled ? `请打开或刷新 DSH 主页面;
|
|
218
|
+
$("connectionDetail").textContent = debugEnabled ? `请打开或刷新 DSH 主页面;duet 当前选择:${sessionLabel(health.active_session_id)}` : '请回到 DSH 页面开启语音模式。';
|
|
219
219
|
} else if (!health.browser_focus_matches) {
|
|
220
220
|
card.classList.add("mismatch");
|
|
221
221
|
$("connectionTitle").textContent = "正在连接 DSH 会话";
|
|
222
|
-
$("connectionDetail").textContent = debugEnabled ? `
|
|
222
|
+
$("connectionDetail").textContent = debugEnabled ? `duet:${sessionLabel(health.active_session_id)} · DSH:${sessionLabel(health.browser_focus_session_id)} · 最近心跳 ${age?.toFixed(1)} 秒前` : '';
|
|
223
223
|
} else {
|
|
224
224
|
card.classList.add("connected");
|
|
225
225
|
$("connectionTitle").textContent = "DSH 主页面已连接";
|
|
@@ -294,7 +294,7 @@
|
|
|
294
294
|
};
|
|
295
295
|
$("refresh").onclick = async () => Promise.all([loadSessions(), loadJobs()]);
|
|
296
296
|
async function refresh() { try { await Promise.all([loadSessions(), loadJobs(), loadConnectionStatus()]); } catch (error) { showMessage(error.message, true); } }
|
|
297
|
-
async function
|
|
297
|
+
async function loadDuetConfig(fill = false) {
|
|
298
298
|
const config = await api('/voice/config');
|
|
299
299
|
const info = await api('/voice/service-info').catch(() => ({status:'unavailable'}));
|
|
300
300
|
$('duplexModel').textContent = info.status === 'ok' ? info.models.duplex : '暂不可用';
|
|
@@ -309,10 +309,10 @@
|
|
|
309
309
|
}
|
|
310
310
|
const c = config.connection || {};
|
|
311
311
|
$('duetMark').style.color = c.online || c.tts_only ? '#7fd6a6' : '#ed9b35';
|
|
312
|
-
$('
|
|
312
|
+
$('duetConnection').textContent = c.online ? '交互模式' : c.tts_only ? '播报模式' : c.connecting ? '正在连接' : '未开启';
|
|
313
313
|
$('authState').textContent = config.backend_url ? '已配置' : '待配置';
|
|
314
314
|
$('pluginVersion').textContent = config.plugin_version || '—';
|
|
315
|
-
$('
|
|
315
|
+
$('saveDuet').disabled = false;
|
|
316
316
|
$('submitFeedback').disabled = feedbackSubmitting || config.feedback_enabled !== true;
|
|
317
317
|
if(config.feedback_enabled !== true)$('feedbackStatus').textContent = '反馈暂时不可用,请稍后再试。';
|
|
318
318
|
else if($('feedbackStatus').textContent.startsWith('正在检查') || $('feedbackStatus').textContent.startsWith('反馈暂时'))$('feedbackStatus').textContent = '';
|
|
@@ -334,14 +334,14 @@
|
|
|
334
334
|
} catch(error){$('feedbackStatus').textContent='提交失败,内容已保留,请稍后重试。'}
|
|
335
335
|
finally{feedbackSubmitting=false;$('submitFeedback').disabled=false;$('feedbackText').disabled=false}
|
|
336
336
|
};
|
|
337
|
-
$('
|
|
338
|
-
$('
|
|
337
|
+
$('saveDuet').onclick = async () => {
|
|
338
|
+
$('saveDuet').disabled = true;
|
|
339
339
|
try {
|
|
340
340
|
await api('/voice/config', {method:'PUT', headers:{'Content-Type':'application/json','X-Duplex-Settings':'1'}, body:JSON.stringify({backend_url:$('backendUrl').value.trim(), auth_token:$('authToken').value, revision:settingsRevision})});
|
|
341
341
|
$('settingsMessage').textContent = '配置已保存;如需语音,请在 DSH 主页面重新打开。';
|
|
342
|
-
await
|
|
342
|
+
await loadDuetConfig(true);
|
|
343
343
|
} catch (error) { $('settingsMessage').textContent = debugEnabled ? `保存失败:${error.message}` : '保存失败,请稍后重试。'; }
|
|
344
|
-
finally { $('
|
|
344
|
+
finally { $('saveDuet').disabled = false; }
|
|
345
345
|
};
|
|
346
346
|
async function loadNotices() {
|
|
347
347
|
const target = $('announcements');
|
|
@@ -360,7 +360,7 @@
|
|
|
360
360
|
} catch { target.textContent = '服务通知暂时不可用。'; }
|
|
361
361
|
}
|
|
362
362
|
async function initialize() {
|
|
363
|
-
await
|
|
363
|
+
await loadDuetConfig(true);
|
|
364
364
|
if (debugEnabled) {
|
|
365
365
|
await refresh();
|
|
366
366
|
composerRequest('composer/get').then(composer => showComposer(composer)).catch(() => {});
|
|
@@ -370,20 +370,20 @@
|
|
|
370
370
|
}
|
|
371
371
|
$('openTutorial').onclick = async () => {
|
|
372
372
|
try {
|
|
373
|
-
const {requestTutorial} = await import('/
|
|
373
|
+
const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.1');
|
|
374
374
|
requestTutorial(localStorage);
|
|
375
375
|
$('tutorialStatus').textContent = '请回到 DSH 页面继续教学。';
|
|
376
376
|
} catch { $('tutorialStatus').textContent = '暂时无法打开教学,请允许浏览器存储后重试。'; }
|
|
377
377
|
};
|
|
378
378
|
initialize().catch(error => { $('settingsMessage').textContent = debugEnabled ? `配置读取失败:${error.message}` : '暂时无法加载设置,请刷新重试。'; });
|
|
379
|
-
setInterval(() => {
|
|
379
|
+
setInterval(() => { loadDuetConfig().catch(() => { $('duetConnection').textContent = '语音连接信息不可用'; }); }, 2000);
|
|
380
380
|
void loadNotices();
|
|
381
381
|
setInterval(loadNotices, 60000);
|
|
382
|
-
import('/
|
|
382
|
+
import('/duet/assets/client/shortcuts.mjs?v=0.1.1').then(({mountShortcutSettings}) => {
|
|
383
383
|
const dispose = mountShortcutSettings({speaker:$('speakerShortcut'),mic:$('micShortcut'),clearSpeaker:$('clearSpeakerShortcut'),clearMic:$('clearMicShortcut'),status:$('shortcutStatus')});
|
|
384
384
|
window.addEventListener('pagehide', e => {if(!e.persisted)dispose()}, {once:true});
|
|
385
385
|
}).catch(() => { $('shortcutStatus').textContent = '暂时无法加载快捷键设置,请刷新重试。'; });
|
|
386
|
-
import('/
|
|
386
|
+
import('/duet/assets/client/microphone.mjs?v=0.1.1').then(({mountMicrophoneSettings}) => {
|
|
387
387
|
const dispose = mountMicrophoneSettings({select:$('microphoneDevice'),refresh:$('refreshMicrophones'),status:$('microphoneStatus')});
|
|
388
388
|
window.addEventListener('pagehide', dispose, {once:true});
|
|
389
389
|
}).catch(() => { $('microphoneStatus').textContent = '暂时无法加载麦克风设置,请刷新重试。'; });
|
|
@@ -32,7 +32,7 @@ export function saveShortcut(kind,value,store=storage()) {
|
|
|
32
32
|
store.setItem(SHORTCUTS_KEY,JSON.stringify(settings))
|
|
33
33
|
return settings
|
|
34
34
|
}
|
|
35
|
-
export function
|
|
35
|
+
export function bindDuetShortcuts(activate,target=window,store=storage()) {
|
|
36
36
|
const handler=event=>{
|
|
37
37
|
if(event.defaultPrevented||document.querySelector('dialog[open]'))return
|
|
38
38
|
const value=shortcutFromEvent(event)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** DSH browser services plus existing voice connection; never opens a microphone. */
|
|
2
|
-
import { PLUGIN_VERSION } from '
|
|
3
|
-
import { focusedSession } from './
|
|
2
|
+
import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.1'
|
|
3
|
+
import { focusedSession } from './composer.mjs?v=0.1.1'
|
|
4
4
|
export function tutorialAdapter(ctx, state, audio, pollReady) {
|
|
5
5
|
let narration
|
|
6
6
|
const completed = new Map()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Opt-in walkthrough. All writes are limited to sessions created by this run. */
|
|
2
|
-
import {consumeTutorialRequest} from './
|
|
2
|
+
import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.1.1'
|
|
3
3
|
export const TUTORIAL_KEY = 'dsh-duplex-tutorial-v1'
|
|
4
4
|
export const QUESTION = '什么是语音交互?请用一句话简单解释,不使用工具。'
|
|
5
5
|
export const INPUT = '用一句话介绍语音助手。'
|
|
@@ -20,7 +20,7 @@ const aborted = () => new DOMException('教学已停止', 'AbortError')
|
|
|
20
20
|
export class TutorialRun {
|
|
21
21
|
constructor(adapter) {
|
|
22
22
|
this.a = adapter; this.controller = new AbortController(); this.owned = new Set()
|
|
23
|
-
this.first = null; this.second = null; this.expected = ''; this.
|
|
23
|
+
this.first = null; this.second = null; this.expected = ''; this.duetOwned = false
|
|
24
24
|
this.step = 'new'; this.busy = false; this.submitted = false
|
|
25
25
|
}
|
|
26
26
|
check() { if (this.controller.signal.aborted) throw aborted() }
|
|
@@ -54,7 +54,7 @@ export class TutorialRun {
|
|
|
54
54
|
async broadcast(consent) { return this.operation(async () => {
|
|
55
55
|
this.require('consent')
|
|
56
56
|
if (!consent?.sound || !consent?.chat) { await this.stop(); throw Error('未确认声音和真实聊天,教学已停止') }
|
|
57
|
-
this.assertFocus(this.first); this.
|
|
57
|
+
this.assertFocus(this.first); this.duetOwned = true
|
|
58
58
|
await this.a.narrate('broadcast', this.controller.signal); this.assertFocus(this.first)
|
|
59
59
|
await this.a.enableBroadcast(this.controller.signal); this.check()
|
|
60
60
|
await this.write(this.first, QUESTION, '')
|
|
@@ -63,7 +63,7 @@ export class TutorialRun {
|
|
|
63
63
|
const job = await this.a.submit(this.first, QUESTION, this.controller.signal)
|
|
64
64
|
this.submitted = true; this.check()
|
|
65
65
|
await this.a.waitBroadcast(job, this.controller.signal); this.check()
|
|
66
|
-
await this.a.off(); this.
|
|
66
|
+
await this.a.off(); this.duetOwned = false; this.step = 'input'
|
|
67
67
|
}) }
|
|
68
68
|
async explainMode(mode) { return this.operation(async () => {
|
|
69
69
|
this.require('consent'); this.assertFocus(this.first)
|
|
@@ -109,7 +109,7 @@ export class TutorialRun {
|
|
|
109
109
|
}) }
|
|
110
110
|
async stop() {
|
|
111
111
|
this.controller.abort(); this.a.stopNarration()
|
|
112
|
-
if (this.
|
|
112
|
+
if (this.duetOwned) { this.duetOwned = false; await this.a.off() }
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -120,12 +120,12 @@ export function mountTutorial({ controls, adapter }) {
|
|
|
120
120
|
const put = (store, key, value) => { try { store.setItem(key, value) } catch { /* private browsing */ } }
|
|
121
121
|
const style = element('style', null, document.head)
|
|
122
122
|
style.textContent = `
|
|
123
|
-
.
|
|
124
|
-
.
|
|
125
|
-
.
|
|
126
|
-
.
|
|
123
|
+
.duet-tutorial-pointer{position:fixed;z-index:100011;pointer-events:none;color:#80c2ff;filter:drop-shadow(0 2px 5px #0008)}
|
|
124
|
+
.duet-tutorial-mode{display:flex;align-items:center;gap:12px;margin:14px 0}.duet-tutorial-mode svg{width:24px;height:24px;color:#80c2ff;flex-shrink:0}
|
|
125
|
+
.duet-tutorial{position:fixed;z-index:100010;width:min(380px,calc(100vw - 28px));max-height:calc(100vh - 28px);overflow:auto;box-sizing:border-box;padding:22px;color:#edf3ff;background:#17212f;border:1px solid #52647d;border-radius:18px;box-shadow:0 14px 50px #0007;font:14px/1.65 system-ui,sans-serif}
|
|
126
|
+
.duet-tutorial h3{font-size:19px;margin:4px 0 12px}.duet-tutorial p{white-space:pre-wrap;margin:10px 0}.duet-tutorial small{color:#b1c5dc}.duet-tutorial footer{display:flex;gap:8px;flex-wrap:wrap;margin-top:18px}.duet-tutorial button{font:inherit;padding:7px 13px;border:1px solid #66809c;border-radius:9px;background:transparent;color:inherit;cursor:pointer}.duet-tutorial button.primary{background:#80c2ff;color:#112035;border-color:transparent;font-weight:650}.duet-tutorial button:disabled{opacity:.45;cursor:wait}.duet-tutorial label{display:flex;align-items:flex-start;gap:10px;margin:12px 0;cursor:pointer}.duet-tutorial input{margin-top:6px}.duet-tutorial-highlight{position:fixed;z-index:100009;pointer-events:none;border:2px solid #80c2ff;border-radius:12px;box-shadow:0 0 0 5px #80c2ff25;transition:all .15s}.duet-tutorial-help{border:0;background:transparent;color:inherit;cursor:pointer;font:600 12px system-ui;padding:5px}
|
|
127
127
|
`
|
|
128
|
-
let target = controls, targetSelector = '#dsh-
|
|
128
|
+
let target = controls, targetSelector = '#dsh-duet-controls'
|
|
129
129
|
const position = () => {
|
|
130
130
|
if (!panel) return
|
|
131
131
|
target = document.querySelector(targetSelector) || controls
|
|
@@ -153,17 +153,17 @@ export function mountTutorial({ controls, adapter }) {
|
|
|
153
153
|
const show = (title, text, actions=[], selector, finished=false) => {
|
|
154
154
|
if(closed)return
|
|
155
155
|
panel?.remove(); highlight?.remove();pointer?.remove();pointer=null
|
|
156
|
-
targetSelector = selector || '#dsh-
|
|
156
|
+
targetSelector = selector || '#dsh-duet-controls'
|
|
157
157
|
target = document.querySelector(targetSelector) || controls
|
|
158
|
-
highlight = element('div',null,document.body); highlight.className='
|
|
158
|
+
highlight = element('div',null,document.body); highlight.className='duet-tutorial-highlight'; highlight.setAttribute('aria-hidden','true')
|
|
159
159
|
highlight.dataset.target=targetSelector
|
|
160
160
|
if(selector==='[data-voice="speaker"]'||selector==='[data-voice="mic"]'){
|
|
161
|
-
pointer=document.createElementNS('http://www.w3.org/2000/svg','svg');pointer.classList.add('
|
|
161
|
+
pointer=document.createElementNS('http://www.w3.org/2000/svg','svg');pointer.classList.add('duet-tutorial-pointer')
|
|
162
162
|
pointer.setAttribute('viewBox','0 0 28 36');pointer.setAttribute('width','28');pointer.setAttribute('height','36');pointer.setAttribute('aria-hidden','true')
|
|
163
163
|
pointer.innerHTML='<path d="M14 2v28m-8-8 8 8 8-8" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>'
|
|
164
164
|
document.body.append(pointer)
|
|
165
165
|
}
|
|
166
|
-
panel=element('section',null,document.body); panel.className='
|
|
166
|
+
panel=element('section',null,document.body); panel.className='duet-tutorial'; panel.setAttribute('role','region'); panel.setAttribute('aria-label','duet 使用教学')
|
|
167
167
|
element('small', finished?'duet':active ? 'duet / GUIDED TOUR · 可随时退出' : 'WELCOME TO duet',panel)
|
|
168
168
|
element('h3',title,panel); element('p',text,panel)
|
|
169
169
|
const footer=element('footer',null,panel)
|
|
@@ -195,7 +195,7 @@ export function mountTutorial({ controls, adapter }) {
|
|
|
195
195
|
const view=show('现在您可以自己试试了', '', [['完成',()=>{void dismiss()}]],undefined,true)
|
|
196
196
|
if(!view)return
|
|
197
197
|
for(const [kind,text] of [['mic','交互模式'],['speaker','播报模式']]){
|
|
198
|
-
const row=element('div');row.className='
|
|
198
|
+
const row=element('div');row.className='duet-tutorial-mode'
|
|
199
199
|
const icon=controls.querySelector(`[data-voice="${kind}"] svg`)?.cloneNode(true)
|
|
200
200
|
if(icon)row.append(icon)
|
|
201
201
|
element('span',text,row);view.panel.insertBefore(row,view.footer)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Explicit public asset inventory. Host code and configuration are never served. */
|
|
2
|
+
const modules = {
|
|
3
|
+
state: 'shared/state', catalog: 'shared/catalog',
|
|
4
|
+
audio: 'client/audio', microphone: 'client/microphone', shortcuts: 'client/shortcuts',
|
|
5
|
+
browser: 'client/browser', rpc: 'client/rpc', composer: 'client/composer',
|
|
6
|
+
interactions: 'client/interactions', tutorial: 'client/tutorial',
|
|
7
|
+
tutorial_adapter: 'client/tutorial-adapter', tutorial_request: 'client/tutorial-request',
|
|
8
|
+
feedback: 'client/feedback', consent: 'client/consent',
|
|
9
|
+
}
|
|
10
|
+
const aliases = {
|
|
11
|
+
state: 'DuetState as VoiceState', audio: 'DuetAudio as VoiceAudio',
|
|
12
|
+
browser: 'mountDuet as mountVoice', shortcuts: 'bindDuetShortcuts as bindVoiceShortcuts',
|
|
13
|
+
}
|
|
14
|
+
const publicModules = new Set(Object.values(modules))
|
|
15
|
+
|
|
16
|
+
export function publicAsset(pathname) {
|
|
17
|
+
const modern = pathname.match(/^\/duet\/assets\/(client|shared)\/([a-z-]+)\.mjs$/)
|
|
18
|
+
if (modern && publicModules.has(`${modern[1]}/${modern[2]}`)) {
|
|
19
|
+
return { url: new URL(`../${modern[1]}/${modern[2]}.mjs`, import.meta.url) }
|
|
20
|
+
}
|
|
21
|
+
// Old open pages may request their previous module URLs after an upgrade.
|
|
22
|
+
const legacy = pathname.match(/^\/duplex-control\/deepseek_harness_voice_([a-z_]+)\.mjs$/)
|
|
23
|
+
if (!legacy || !Object.hasOwn(modules, legacy[1])) return null
|
|
24
|
+
const target = `/duet/assets/${modules[legacy[1]]}.mjs`
|
|
25
|
+
return { body: `export * from '${target}';\n${aliases[legacy[1]] ? `export { ${aliases[legacy[1]]} } from '${target}';\n` : ''}` }
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Prefer duet names while accepting existing installations' environment keys. */
|
|
2
|
+
const legacyNames = {
|
|
3
|
+
MIN_VERSION: 'DUPLEX_PLUGIN_MIN_VERSION',
|
|
4
|
+
MAX_VERSION_EXCLUSIVE: 'DUPLEX_PLUGIN_MAX_VERSION_EXCLUSIVE',
|
|
5
|
+
DEBUG: 'DUPLEX_CONTROL_DEBUG',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function duetEnv(name, env = process.env) {
|
|
9
|
+
return env[`DUET_${name}`] ?? env[legacyNames[name] ?? `DUPLEX_VOICE_${name}`]
|
|
10
|
+
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** duet Host entry: session operations, authenticated settings, and client assets. */
|
|
2
2
|
|
|
3
3
|
import { readFile } from 'node:fs/promises'
|
|
4
4
|
import { randomUUID } from 'node:crypto'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { ServiceNotices } from './
|
|
8
|
-
import { ServiceInfo } from './
|
|
9
|
-
import {
|
|
10
|
-
import { FeedbackService } from './
|
|
11
|
-
import { RemoteFeedback } from './
|
|
12
|
-
import { PLUGIN_VERSION } from '
|
|
13
|
-
import { buildSessionCatalog } from '
|
|
5
|
+
import { registerDuetProxy, duetConfig } from './proxy.mjs'
|
|
6
|
+
import { DuetSettings, settingsWriteAllowed } from './settings.mjs'
|
|
7
|
+
import { ServiceNotices } from './notices.mjs'
|
|
8
|
+
import { ServiceInfo } from './service-info.mjs'
|
|
9
|
+
import { DuetTrace } from './trace.mjs'
|
|
10
|
+
import { FeedbackService } from './feedback-store.mjs'
|
|
11
|
+
import { RemoteFeedback } from './feedback-files.mjs'
|
|
12
|
+
import { PLUGIN_VERSION } from '../shared/state.mjs'
|
|
13
|
+
import { buildSessionCatalog } from '../shared/catalog.mjs'
|
|
14
|
+
import { publicAsset } from './assets.mjs'
|
|
15
|
+
import { duetEnv } from './environment.mjs'
|
|
14
16
|
|
|
15
17
|
const ROUTE = '/duplex-control'
|
|
16
18
|
const PAGE_ROUTE = '/duet'
|
|
@@ -21,8 +23,8 @@ const COMPOSER_RPC_TIMEOUT_MS = 5_000
|
|
|
21
23
|
// Long polling refreshes liveness every <=20s even when background timers slow.
|
|
22
24
|
// This remains a finite lease, not a claim that a frozen/closed tab is usable.
|
|
23
25
|
const BROWSER_CLIENT_STALE_SECONDS = 45
|
|
24
|
-
const
|
|
25
|
-
const HTML_URL = new URL('
|
|
26
|
+
const DUET_RUNTIME_STALE_SECONDS = 3
|
|
27
|
+
const HTML_URL = new URL('../client/settings.html', import.meta.url)
|
|
26
28
|
|
|
27
29
|
export const name = 'dsh-duet'
|
|
28
30
|
export const inject = [
|
|
@@ -156,27 +158,27 @@ export function apply(ctx, options = {}) {
|
|
|
156
158
|
let focusRevision = Date.now()
|
|
157
159
|
let completionSequence = 0
|
|
158
160
|
let composerRequestSequence = 0
|
|
159
|
-
let
|
|
161
|
+
let lastDuetRuntimeSeenAt = 0
|
|
160
162
|
let lastNativeInteractionsSeenAt = -Infinity
|
|
161
163
|
const hostAbort = new AbortController()
|
|
162
164
|
|
|
163
|
-
const voice =
|
|
164
|
-
const settings = new
|
|
165
|
+
const voice = duetConfig()
|
|
166
|
+
const settings = new DuetSettings(voice, { path: options.settingsPath, debug: options.debug === true || duetEnv('DEBUG') === '1' })
|
|
165
167
|
Object.assign(voice, settings.effective())
|
|
166
|
-
const audit = new
|
|
168
|
+
const audit = new DuetTrace({ kind: 'host', plugin_version: PLUGIN_VERSION, pid: process.pid },
|
|
167
169
|
{ ...options.traceOptions, secrets: [voice.authorization] })
|
|
168
170
|
ctx.effect(() => () => { void audit.close({ reason: 'plugin_dispose' }) })
|
|
169
171
|
const notices = new ServiceNotices(() => settings.effective())
|
|
170
172
|
const serviceInfo = new ServiceInfo(() => settings.effective())
|
|
171
173
|
const feedbackStore = options.feedbackStore ?? (options.feedbackDisabled ? null : new RemoteFeedback(()=>settings.effective(),{keyPath:options.feedbackIdentityPath}))
|
|
172
174
|
const feedback = new FeedbackService(feedbackStore)
|
|
173
|
-
let
|
|
174
|
-
ctx.effect(() => {
|
|
175
|
+
let duetProxy
|
|
176
|
+
ctx.effect(() => { duetProxy = registerDuetProxy(ctx, voice, feedback); return duetProxy })
|
|
175
177
|
|
|
176
178
|
ctx.effect(() => () => { hostAbort.abort() })
|
|
177
179
|
|
|
178
|
-
const
|
|
179
|
-
nowSeconds() -
|
|
180
|
+
const duetRuntimeActive = () => (
|
|
181
|
+
nowSeconds() - lastDuetRuntimeSeenAt <= DUET_RUNTIME_STALE_SECONDS
|
|
180
182
|
)
|
|
181
183
|
// A background tab may throttle its heartbeat. Once the native UI capability
|
|
182
184
|
// is known, never steal its requests again during this Host lifetime.
|
|
@@ -210,7 +212,7 @@ export function apply(ctx, options = {}) {
|
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
ctx.on('approval/request', function (request, next) {
|
|
213
|
-
if (!
|
|
215
|
+
if (!duetRuntimeActive() || nativeInteractionsActive()) return next()
|
|
214
216
|
// IDs are opaque and URL-safe.
|
|
215
217
|
const id = `approval_${randomUUID().replaceAll('-', '')}`
|
|
216
218
|
return pendingInteraction({
|
|
@@ -226,7 +228,7 @@ export function apply(ctx, options = {}) {
|
|
|
226
228
|
}, { prepend: true })
|
|
227
229
|
|
|
228
230
|
ctx.on('user-questions/request', function (request, next) {
|
|
229
|
-
if (!
|
|
231
|
+
if (!duetRuntimeActive() || nativeInteractionsActive()) return next()
|
|
230
232
|
const questions = Array.isArray(request.questions) ? request.questions : []
|
|
231
233
|
const planReview = questions.some(question => question?.intent?.kind === 'plan-review')
|
|
232
234
|
const id = `question_${randomUUID().replaceAll('-', '')}`
|
|
@@ -242,7 +244,7 @@ export function apply(ctx, options = {}) {
|
|
|
242
244
|
ctx.effect(() => () => {
|
|
243
245
|
for (const interaction of pendingInteractions.values()) {
|
|
244
246
|
finishInteraction(interaction, () => {
|
|
245
|
-
interaction.reject(codedError('plugin_stopped', '
|
|
247
|
+
interaction.reject(codedError('plugin_stopped', 'duet plugin stopped'))
|
|
246
248
|
})
|
|
247
249
|
}
|
|
248
250
|
})
|
|
@@ -494,7 +496,7 @@ export function apply(ctx, options = {}) {
|
|
|
494
496
|
}
|
|
495
497
|
if (req.method === 'GET' && pathname === `${ROUTE}/api/voice/config`) {
|
|
496
498
|
try{feedbackStore?.ensureIdentity?.(req,res)}catch{sendJson(res,503,{error_code:'feedback_identity_unavailable'});return}
|
|
497
|
-
sendJson(res, 200, { ...settings.public(), plugin_version: PLUGIN_VERSION, feedback_enabled: feedback.enabled, connection:
|
|
499
|
+
sendJson(res, 200, { ...settings.public(), plugin_version: PLUGIN_VERSION, feedback_enabled: feedback.enabled, connection: duetProxy?.snapshot?.() || { online: 0, tts_only: 0 } })
|
|
498
500
|
return
|
|
499
501
|
}
|
|
500
502
|
if (req.method === 'PUT' && pathname === `${ROUTE}/api/voice/config`) {
|
|
@@ -506,7 +508,7 @@ export function apply(ctx, options = {}) {
|
|
|
506
508
|
audit.secrets.push(voice.authorization)
|
|
507
509
|
notices.invalidate()
|
|
508
510
|
serviceInfo.invalidate()
|
|
509
|
-
|
|
511
|
+
duetProxy?.closeConnections?.('voice_settings_changed')
|
|
510
512
|
sendJson(res, 200, result)
|
|
511
513
|
} catch (error) { sendError(res, 400, error.message) }
|
|
512
514
|
return
|
|
@@ -532,9 +534,9 @@ export function apply(ctx, options = {}) {
|
|
|
532
534
|
pending_composer_request_count: composerRequests.size,
|
|
533
535
|
interaction_rpc_version: 'harness_pending_interaction_rpc_v1',
|
|
534
536
|
pending_interaction_count: pendingInteractions.size,
|
|
535
|
-
duplex_runtime_connected:
|
|
536
|
-
duplex_runtime_last_seen_at:
|
|
537
|
-
duplex_runtime_stale_after_seconds:
|
|
537
|
+
duplex_runtime_connected: duetRuntimeActive(),
|
|
538
|
+
duplex_runtime_last_seen_at: lastDuetRuntimeSeenAt || null,
|
|
539
|
+
duplex_runtime_stale_after_seconds: DUET_RUNTIME_STALE_SECONDS,
|
|
538
540
|
browser_client_status_version: 'harness_browser_client_status_v1',
|
|
539
541
|
...browserClientStatus(),
|
|
540
542
|
})
|
|
@@ -1058,20 +1060,20 @@ export function apply(ctx, options = {}) {
|
|
|
1058
1060
|
if (req.method === 'GET' && tutorialAudio) {
|
|
1059
1061
|
const rejection = ctx.connection.requestRejection(req)
|
|
1060
1062
|
if (rejection) { sendError(res, rejection, '请先打开并登录 DSH 主页面'); return }
|
|
1061
|
-
const body = await readFile(new URL(
|
|
1063
|
+
const body = await readFile(new URL(`../../assets/tutorial-audio/${tutorialAudio[1]}.wav`, import.meta.url))
|
|
1062
1064
|
res.writeHead(200, { 'content-type': 'audio/wav', 'cache-control': 'private, max-age=3600', 'content-length': body.length })
|
|
1063
1065
|
res.end(body)
|
|
1064
1066
|
return
|
|
1065
1067
|
}
|
|
1066
|
-
const asset = pathname
|
|
1068
|
+
const asset = publicAsset(pathname)
|
|
1067
1069
|
if (req.method === 'GET' && asset) {
|
|
1068
|
-
const body = await readFile(
|
|
1070
|
+
const body = asset.body ?? await readFile(asset.url)
|
|
1069
1071
|
res.writeHead(200, { 'content-type': 'text/javascript; charset=utf-8', 'cache-control': 'no-store' })
|
|
1070
1072
|
res.end(body)
|
|
1071
1073
|
return
|
|
1072
1074
|
}
|
|
1073
1075
|
if (String(req.headers?.['x-duplex-control-client'] || '').trim()) {
|
|
1074
|
-
|
|
1076
|
+
lastDuetRuntimeSeenAt = nowSeconds()
|
|
1075
1077
|
}
|
|
1076
1078
|
if (req.headers?.['x-duet-native-interactions'] === '1') lastNativeInteractionsSeenAt = nowSeconds()
|
|
1077
1079
|
if ((pathname === ROUTE || pathname === `${ROUTE}/`) && req.method === 'GET') {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/** Same-origin voice relay; endpoint and compatibility policy belong to the DSH host. */
|
|
2
2
|
import { createRequire } from 'node:module'
|
|
3
|
-
import {
|
|
3
|
+
import { DuetTrace } from './trace.mjs'
|
|
4
|
+
import { duetEnv } from './environment.mjs'
|
|
4
5
|
const require = createRequire(import.meta.url)
|
|
5
|
-
export const
|
|
6
|
+
export const DEFAULT_DUET_URL = 'ws://duet-router.1781574661016173.ap-southeast-1.pai-eas.aliyuncs.com/ws?protocol=realtime_v2'
|
|
6
7
|
|
|
7
8
|
export function compatibleVersion(version, min = '0.1.0', maxExclusive = '0.2.0') {
|
|
8
9
|
const parse = v => /^\d+\.\d+\.\d+$/.test(v || '') ? v.split('.').map(Number) : null
|
|
@@ -11,15 +12,15 @@ export function compatibleVersion(version, min = '0.1.0', maxExclusive = '0.2.0'
|
|
|
11
12
|
return Boolean(v && low && high && compare(v, low) >= 0 && compare(v, high) < 0)
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export function
|
|
15
|
+
export function duetConfig(env = process.env) {
|
|
15
16
|
return {
|
|
16
|
-
min_version: env
|
|
17
|
-
max_version_exclusive: env
|
|
18
|
-
control_transport: env
|
|
19
|
-
authorization: env
|
|
17
|
+
min_version: duetEnv('MIN_VERSION', env) || '0.1.0',
|
|
18
|
+
max_version_exclusive: duetEnv('MAX_VERSION_EXCLUSIVE', env) || '0.2.0',
|
|
19
|
+
control_transport: duetEnv('CONTROL_TRANSPORT', env) || 'client_rpc_v1',
|
|
20
|
+
authorization: duetEnv('AUTHORIZATION', env) || '',
|
|
20
21
|
endpoints: {
|
|
21
|
-
online: env
|
|
22
|
-
tts_only: env
|
|
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,
|
|
23
24
|
},
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -41,7 +42,7 @@ export function externalWithState(message, _state) {
|
|
|
41
42
|
...(source === undefined ? {} : { source: { ...source } }) }
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
export function
|
|
45
|
+
export function registerDuetProxy(ctx, config = duetConfig(), feedback = null) {
|
|
45
46
|
if (!['http', 'client_rpc_v1'].includes(config.control_transport || 'http')) throw new Error('invalid_harness_transport')
|
|
46
47
|
if (!compatibleVersion(config.min_version, config.min_version, config.max_version_exclusive)) throw new Error('invalid_plugin_version_policy')
|
|
47
48
|
for (const target of Object.values(config.endpoints)) {
|
|
@@ -67,7 +68,7 @@ export function registerVoiceProxy(ctx, config = voiceConfig(), feedback = null)
|
|
|
67
68
|
server.handleUpgrade(req, socket, head, front => {
|
|
68
69
|
front.on('error', () => {})
|
|
69
70
|
const params = new URL(req.url, 'http://localhost').searchParams
|
|
70
|
-
const trace = new
|
|
71
|
+
const trace = new DuetTrace({ mode: params.get('mode'), plugin_version: params.get('plugin_version'),
|
|
71
72
|
client_trace_id: (params.get('client_trace_id') || '').slice(0, 64),
|
|
72
73
|
backend_origin: new URL(config.endpoints[params.get('mode')] || config.endpoints.online).origin,
|
|
73
74
|
control_transport: config.control_transport }, { ...config.traceOptions, secrets: [config.authorization] })
|
|
@@ -4,6 +4,7 @@ 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
|
+
import { duetEnv } from './environment.mjs'
|
|
7
8
|
|
|
8
9
|
export function validateBackendURL(value, insecureOrigin = null) {
|
|
9
10
|
if (typeof value !== 'string' || value.length > 2048) throw new Error('invalid_backend_url')
|
|
@@ -15,10 +16,10 @@ export function validateBackendURL(value, insecureOrigin = null) {
|
|
|
15
16
|
return url.toString()
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export class
|
|
19
|
+
export class DuetSettings {
|
|
19
20
|
constructor(base, { path, debug = false } = {}) {
|
|
20
21
|
this.base = base
|
|
21
|
-
this.path = path ||
|
|
22
|
+
this.path = path || duetEnv('SETTINGS_FILE') || join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'duplex-control', 'voice.json')
|
|
22
23
|
this.debug = debug
|
|
23
24
|
this.saved = null
|
|
24
25
|
this.revision = 0
|
|
@@ -3,6 +3,7 @@ import { createWriteStream, mkdirSync, readdirSync, statSync } from 'node:fs'
|
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
import { randomUUID } from 'node:crypto'
|
|
6
|
+
import { duetEnv } from './environment.mjs'
|
|
6
7
|
|
|
7
8
|
export function redact(value, secrets = []) {
|
|
8
9
|
if (typeof value === 'string') {
|
|
@@ -17,8 +18,8 @@ export function redact(value, secrets = []) {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const budgets = new Map()
|
|
20
|
-
export class
|
|
21
|
-
constructor(metadata, { root =
|
|
21
|
+
export class DuetTrace {
|
|
22
|
+
constructor(metadata, { root = duetEnv('TRACE_DIR') || join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'duplex-control', 'traces'),
|
|
22
23
|
secrets = [], maxBytes = 512 * 1024 ** 2, totalBytes = 20 * 1024 ** 3, queueBytes = 8 * 1024 ** 2 } = {}) {
|
|
23
24
|
this.id = randomUUID(); this.start = performance.now(); this.seq = 0; this.bytes = 0
|
|
24
25
|
this.offset = 0; this.closed = false; this.error = null; this.secrets = secrets
|
|
@@ -62,7 +63,7 @@ export class VoiceTrace {
|
|
|
62
63
|
if (this.error) return
|
|
63
64
|
this.error = reason
|
|
64
65
|
// No payloads or credentials in stderr, and never crash audio for a logging error.
|
|
65
|
-
console.error(`[
|
|
66
|
+
console.error(`[duet-trace] capture incomplete trace=${this.id} reason=${reason}`)
|
|
66
67
|
if (this.events && !this.events.destroyed) {
|
|
67
68
|
this.events.end(JSON.stringify({ type: 'trace.incomplete', reason, utc: new Date().toISOString() }) + '\n')
|
|
68
69
|
}
|
|
@@ -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.1'
|
|
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 : ''
|
|
@@ -20,7 +20,7 @@ export function compatibilityNotice(code, details = {}, mode = 'online') {
|
|
|
20
20
|
return null
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export class
|
|
23
|
+
export class DuetState {
|
|
24
24
|
constructor({ connect, changed = () => {}, notice = () => {}, now = Date.now }) {
|
|
25
25
|
Object.assign(this, { connect, changed, notice, now })
|
|
26
26
|
this.mode = 'off'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|