dsh-duet 0.1.0
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/HEROICONS-LICENSE.txt +24 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +77 -0
- package/deepseek_harness_duplex_control.patch.yml +3 -0
- package/deepseek_harness_duplex_control_plugin.html +392 -0
- package/deepseek_harness_duplex_control_plugin.mjs +1105 -0
- package/deepseek_harness_duplex_focus_client/lib/client.js +466 -0
- package/deepseek_harness_voice_audio.mjs +135 -0
- package/deepseek_harness_voice_browser.mjs +343 -0
- package/deepseek_harness_voice_catalog.mjs +56 -0
- package/deepseek_harness_voice_composer.mjs +125 -0
- package/deepseek_harness_voice_consent.mjs +63 -0
- package/deepseek_harness_voice_feedback.mjs +48 -0
- package/deepseek_harness_voice_feedback_files.mjs +55 -0
- package/deepseek_harness_voice_feedback_store.mjs +51 -0
- package/deepseek_harness_voice_interactions.mjs +32 -0
- package/deepseek_harness_voice_microphone.mjs +59 -0
- package/deepseek_harness_voice_notices.mjs +54 -0
- package/deepseek_harness_voice_proxy.mjs +223 -0
- package/deepseek_harness_voice_rpc.mjs +104 -0
- package/deepseek_harness_voice_service_info.mjs +45 -0
- package/deepseek_harness_voice_settings.mjs +95 -0
- package/deepseek_harness_voice_shortcuts.mjs +69 -0
- package/deepseek_harness_voice_state.mjs +171 -0
- package/deepseek_harness_voice_trace.mjs +107 -0
- package/deepseek_harness_voice_tutorial.mjs +265 -0
- package/deepseek_harness_voice_tutorial_adapter.mjs +95 -0
- package/deepseek_harness_voice_tutorial_request.mjs +16 -0
- package/package.json +57 -0
- package/tutorial-audio/broadcast.wav +0 -0
- package/tutorial-audio/clear.wav +0 -0
- package/tutorial-audio/edit.wav +0 -0
- package/tutorial-audio/input.wav +0 -0
- package/tutorial-audio/manifest.json +60 -0
- package/tutorial-audio/modes_broadcast.wav +0 -0
- package/tutorial-audio/modes_interaction.wav +0 -0
- package/tutorial-audio/reinput.wav +0 -0
- package/tutorial-audio/send.wav +0 -0
- package/tutorial-audio/switch.wav +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/** Opt-in walkthrough. All writes are limited to sessions created by this run. */
|
|
2
|
+
import {consumeTutorialRequest} from './deepseek_harness_voice_tutorial_request.mjs?v=0.1.0'
|
|
3
|
+
export const TUTORIAL_KEY = 'dsh-duplex-tutorial-v1'
|
|
4
|
+
export const QUESTION = '什么是语音交互?请用一句话简单解释,不使用工具。'
|
|
5
|
+
export const INPUT = '用一句话介绍语音助手。'
|
|
6
|
+
export const EDIT = '用一句简短的话介绍语音助手。'
|
|
7
|
+
export const NARRATION = {
|
|
8
|
+
modes_broadcast: '这个喇叭按钮是播报模式。在播报模式中,我只会为您简要播报完成的任务。',
|
|
9
|
+
modes_interaction: '这个双向箭头按钮是交互模式。您可以让我输入、修改、发送消息,或者切换会话,也可以和我自由聊天。两个模式只能选一个,浅蓝色表示当前模式。点另一个按钮就能切换,再点当前按钮就会关闭。',
|
|
10
|
+
broadcast: '现在我们来演示在 DSH 问一个简单的问题,看看我的播报吧。',
|
|
11
|
+
input: '现在开始演示交互模式,但是这次不需要您来说话,我会通过语音为您讲解。比如,您可以说,输入,用一句话介绍语音助手。内容就会出现在输入框里。',
|
|
12
|
+
edit: '如果想改一改,可以接着说,把一句话改成一句简短的话。',
|
|
13
|
+
clear: '想重新写,可以说,清空输入框。',
|
|
14
|
+
reinput: '然后,您可以说,输入,用一句简短的话介绍语音助手。我们就重新写好了。',
|
|
15
|
+
send: '满意的话,您可以说,发送,或者,提交。这次点击确认后,我帮您提交。',
|
|
16
|
+
switch: '想看看另一个会话,可以说,切换到播报教学的会话。',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const aborted = () => new DOMException('教学已停止', 'AbortError')
|
|
20
|
+
export class TutorialRun {
|
|
21
|
+
constructor(adapter) {
|
|
22
|
+
this.a = adapter; this.controller = new AbortController(); this.owned = new Set()
|
|
23
|
+
this.first = null; this.second = null; this.expected = ''; this.voiceOwned = false
|
|
24
|
+
this.step = 'new'; this.busy = false; this.submitted = false
|
|
25
|
+
}
|
|
26
|
+
check() { if (this.controller.signal.aborted) throw aborted() }
|
|
27
|
+
async operation(fn) {
|
|
28
|
+
this.check(); if (this.busy) throw Error('上一步尚未完成')
|
|
29
|
+
this.busy = true
|
|
30
|
+
try { const value = await fn(); this.check(); return value } finally { this.busy = false }
|
|
31
|
+
}
|
|
32
|
+
require(step) { this.check(); if (this.step !== step) throw Error('教学步骤已变化,请重新开始') }
|
|
33
|
+
async create(name) {
|
|
34
|
+
const id = await this.a.create(name, this.controller.signal)
|
|
35
|
+
// Even if the request finished after exit, no further action may follow it.
|
|
36
|
+
this.owned.add(id); this.check()
|
|
37
|
+
await this.a.focus(id, this.controller.signal); this.check()
|
|
38
|
+
return id
|
|
39
|
+
}
|
|
40
|
+
async begin(consent) { return this.operation(async () => {
|
|
41
|
+
if (!consent?.sound || !consent?.chat) throw Error('请先确认声音和教学消息授权')
|
|
42
|
+
this.require('new'); if (this.a.mode() !== 'off') throw Error('请先关闭正在使用的语音,再开始教学')
|
|
43
|
+
this.first = await this.create('duet 教学 · 播报'); this.step = 'consent'
|
|
44
|
+
}) }
|
|
45
|
+
assertFocus(id) {
|
|
46
|
+
this.check()
|
|
47
|
+
if (!this.owned.has(id) || this.a.current() !== id) throw Error('当前会话已切换,教学停止,未修改其他会话')
|
|
48
|
+
}
|
|
49
|
+
async write(id, text, expected) {
|
|
50
|
+
this.assertFocus(id)
|
|
51
|
+
await this.a.write(id, text, expected, this.controller.signal); this.check()
|
|
52
|
+
this.expected = text
|
|
53
|
+
}
|
|
54
|
+
async broadcast(consent) { return this.operation(async () => {
|
|
55
|
+
this.require('consent')
|
|
56
|
+
if (!consent?.sound || !consent?.chat) { await this.stop(); throw Error('未确认声音和真实聊天,教学已停止') }
|
|
57
|
+
this.assertFocus(this.first); this.voiceOwned = true
|
|
58
|
+
await this.a.narrate('broadcast', this.controller.signal); this.assertFocus(this.first)
|
|
59
|
+
await this.a.enableBroadcast(this.controller.signal); this.check()
|
|
60
|
+
await this.write(this.first, QUESTION, '')
|
|
61
|
+
this.a.status('任务完成后,我会为您简要播报。')
|
|
62
|
+
this.assertFocus(this.first)
|
|
63
|
+
const job = await this.a.submit(this.first, QUESTION, this.controller.signal)
|
|
64
|
+
this.submitted = true; this.check()
|
|
65
|
+
await this.a.waitBroadcast(job, this.controller.signal); this.check()
|
|
66
|
+
await this.a.off(); this.voiceOwned = false; this.step = 'input'
|
|
67
|
+
}) }
|
|
68
|
+
async explainMode(mode) { return this.operation(async () => {
|
|
69
|
+
this.require('consent'); this.assertFocus(this.first)
|
|
70
|
+
if (!['broadcast','interaction'].includes(mode)) throw Error('未知教学模式')
|
|
71
|
+
await this.a.narrate('modes_'+mode, this.controller.signal)
|
|
72
|
+
}) }
|
|
73
|
+
async input() { return this.operation(async () => {
|
|
74
|
+
this.require('input'); this.assertFocus(this.first)
|
|
75
|
+
this.second = await this.create('duet 教学 · 交互'); this.expected = ''
|
|
76
|
+
await this.a.narrate('input', this.controller.signal); this.check()
|
|
77
|
+
await this.write(this.second, INPUT, ''); this.step = 'edit'
|
|
78
|
+
}) }
|
|
79
|
+
async edit() { return this.operation(async () => {
|
|
80
|
+
this.require('edit'); this.assertFocus(this.second)
|
|
81
|
+
await this.a.narrate('edit', this.controller.signal); this.check()
|
|
82
|
+
await this.write(this.second, EDIT, INPUT); this.step = 'clear'
|
|
83
|
+
}) }
|
|
84
|
+
async clear() { return this.operation(async () => {
|
|
85
|
+
this.require('clear'); this.assertFocus(this.second)
|
|
86
|
+
await this.a.narrate('clear', this.controller.signal); this.check()
|
|
87
|
+
await this.write(this.second, '', EDIT); this.step = 'reinput'
|
|
88
|
+
}) }
|
|
89
|
+
async reinput() { return this.operation(async () => {
|
|
90
|
+
this.require('reinput'); this.assertFocus(this.second)
|
|
91
|
+
await this.a.narrate('reinput', this.controller.signal); this.check()
|
|
92
|
+
await this.write(this.second, EDIT, ''); this.step = 'send_explain'
|
|
93
|
+
}) }
|
|
94
|
+
async explainSend() { return this.operation(async () => {
|
|
95
|
+
this.require('send_explain'); this.assertFocus(this.second)
|
|
96
|
+
await this.a.narrate('send', this.controller.signal); this.step = 'send_consent'
|
|
97
|
+
}) }
|
|
98
|
+
async send(confirmed) { return this.operation(async () => {
|
|
99
|
+
this.require('send_consent')
|
|
100
|
+
if (!confirmed) { await this.stop(); return }
|
|
101
|
+
this.assertFocus(this.second)
|
|
102
|
+
await this.a.submit(this.second, EDIT, this.controller.signal)
|
|
103
|
+
this.submitted = true; this.check(); this.step = 'switch'
|
|
104
|
+
}) }
|
|
105
|
+
async switchSession() { return this.operation(async () => {
|
|
106
|
+
this.require('switch'); this.assertFocus(this.second)
|
|
107
|
+
await this.a.narrate('switch', this.controller.signal); this.assertFocus(this.second)
|
|
108
|
+
await this.a.focus(this.first, this.controller.signal); this.check(); this.step = 'done'
|
|
109
|
+
}) }
|
|
110
|
+
async stop() {
|
|
111
|
+
this.controller.abort(); this.a.stopNarration()
|
|
112
|
+
if (this.voiceOwned) { this.voiceOwned = false; await this.a.off() }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function mountTutorial({ controls, adapter }) {
|
|
117
|
+
const element = (tag, text, parent) => { const n = document.createElement(tag); if (text) n.textContent = text; parent?.append(n); return n }
|
|
118
|
+
let run, closed = false, panel, highlight, pointer, lockRelease, active = false
|
|
119
|
+
const get = (store, key) => { try { return store.getItem(key) } catch { return null } }
|
|
120
|
+
const put = (store, key, value) => { try { store.setItem(key, value) } catch { /* private browsing */ } }
|
|
121
|
+
const style = element('style', null, document.head)
|
|
122
|
+
style.textContent = `
|
|
123
|
+
.live-tutorial-pointer{position:fixed;z-index:100011;pointer-events:none;color:#80c2ff;filter:drop-shadow(0 2px 5px #0008)}
|
|
124
|
+
.live-tutorial-mode{display:flex;align-items:center;gap:12px;margin:14px 0}.live-tutorial-mode svg{width:24px;height:24px;color:#80c2ff;flex-shrink:0}
|
|
125
|
+
.live-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
|
+
.live-tutorial h3{font-size:19px;margin:4px 0 12px}.live-tutorial p{white-space:pre-wrap;margin:10px 0}.live-tutorial small{color:#b1c5dc}.live-tutorial footer{display:flex;gap:8px;flex-wrap:wrap;margin-top:18px}.live-tutorial button{font:inherit;padding:7px 13px;border:1px solid #66809c;border-radius:9px;background:transparent;color:inherit;cursor:pointer}.live-tutorial button.primary{background:#80c2ff;color:#112035;border-color:transparent;font-weight:650}.live-tutorial button:disabled{opacity:.45;cursor:wait}.live-tutorial label{display:flex;align-items:flex-start;gap:10px;margin:12px 0;cursor:pointer}.live-tutorial input{margin-top:6px}.live-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}.live-tutorial-help{border:0;background:transparent;color:inherit;cursor:pointer;font:600 12px system-ui;padding:5px}
|
|
127
|
+
`
|
|
128
|
+
let target = controls, targetSelector = '#dsh-duplex-voice-controls'
|
|
129
|
+
const position = () => {
|
|
130
|
+
if (!panel) return
|
|
131
|
+
target = document.querySelector(targetSelector) || controls
|
|
132
|
+
const rect = (target?.isConnected ? target : controls).getBoundingClientRect()
|
|
133
|
+
const width = panel.offsetWidth, height = panel.offsetHeight
|
|
134
|
+
const beside = rect.right + 16 + width < innerWidth
|
|
135
|
+
const left = beside ? rect.right + 16 : Math.max(14, innerWidth - width - 14)
|
|
136
|
+
const top = !beside && rect.top > height + 30 ? rect.top - height - 16 : rect.top
|
|
137
|
+
panel.style.left = left + 'px'; panel.style.top = Math.max(14, Math.min(top, innerHeight - height - 14)) + 'px'
|
|
138
|
+
if (highlight) Object.assign(highlight.style, {left:rect.left-4+'px',top:rect.top-4+'px',width:rect.width+8+'px',height:rect.height+8+'px'})
|
|
139
|
+
if (pointer) {
|
|
140
|
+
const above=rect.top>=55
|
|
141
|
+
Object.assign(pointer.style,{left:rect.left+rect.width/2-14+'px',top:(above?rect.top-46:rect.bottom+10)+'px',transform:above?'':'rotate(180deg)'})
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const dismiss = async (forever=false) => {
|
|
145
|
+
closed = true; put(sessionStorage,TUTORIAL_KEY,'closed'); if (forever) put(localStorage,TUTORIAL_KEY,'dismissed')
|
|
146
|
+
panel?.remove(); panel=null; highlight?.remove(); highlight=null; pointer?.remove();pointer=null
|
|
147
|
+
await run?.stop(); active=false; lockRelease?.(); lockRelease=null
|
|
148
|
+
}
|
|
149
|
+
const button = (parent, text, callback, primary=false) => {
|
|
150
|
+
const b = element('button', text, parent); b.type='button'; if(primary)b.className='primary'
|
|
151
|
+
b.onclick=callback; return b
|
|
152
|
+
}
|
|
153
|
+
const show = (title, text, actions=[], selector, finished=false) => {
|
|
154
|
+
if(closed)return
|
|
155
|
+
panel?.remove(); highlight?.remove();pointer?.remove();pointer=null
|
|
156
|
+
targetSelector = selector || '#dsh-duplex-voice-controls'
|
|
157
|
+
target = document.querySelector(targetSelector) || controls
|
|
158
|
+
highlight = element('div',null,document.body); highlight.className='live-tutorial-highlight'; highlight.setAttribute('aria-hidden','true')
|
|
159
|
+
highlight.dataset.target=targetSelector
|
|
160
|
+
if(selector==='[data-voice="speaker"]'||selector==='[data-voice="mic"]'){
|
|
161
|
+
pointer=document.createElementNS('http://www.w3.org/2000/svg','svg');pointer.classList.add('live-tutorial-pointer')
|
|
162
|
+
pointer.setAttribute('viewBox','0 0 28 36');pointer.setAttribute('width','28');pointer.setAttribute('height','36');pointer.setAttribute('aria-hidden','true')
|
|
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
|
+
document.body.append(pointer)
|
|
165
|
+
}
|
|
166
|
+
panel=element('section',null,document.body); panel.className='live-tutorial'; panel.setAttribute('role','region'); panel.setAttribute('aria-label','duet 使用教学')
|
|
167
|
+
element('small', finished?'duet':active ? 'duet / GUIDED TOUR · 可随时退出' : 'WELCOME TO duet',panel)
|
|
168
|
+
element('h3',title,panel); element('p',text,panel)
|
|
169
|
+
const footer=element('footer',null,panel)
|
|
170
|
+
for(const [text,fn] of actions) button(footer,text,fn,true)
|
|
171
|
+
if(!finished)button(footer,active?'退出教学':'关闭',()=>{void dismiss()})
|
|
172
|
+
if(!active&&!finished)button(footer,'不再提醒',()=>{void dismiss(true)})
|
|
173
|
+
position(); return {panel,footer}
|
|
174
|
+
}
|
|
175
|
+
const fail = async error => {
|
|
176
|
+
if(closed || error.name==='AbortError')return
|
|
177
|
+
const owner=run
|
|
178
|
+
await owner?.stop();if(run!==owner)return
|
|
179
|
+
active=false;lockRelease?.();lockRelease=null
|
|
180
|
+
show('教学已暂停', `${error.message}\n不会继续发送或修改。已经提交的任务仍会保留。`, [['重新开始',welcome]])
|
|
181
|
+
}
|
|
182
|
+
const act = async (title,text,fn,next,selector,pause=0) => {
|
|
183
|
+
if(run?.busy)return
|
|
184
|
+
const owner=run
|
|
185
|
+
show(title,text,[],selector)
|
|
186
|
+
try {
|
|
187
|
+
await fn()
|
|
188
|
+
if(pause)await new Promise(resolve=>setTimeout(resolve,pause))
|
|
189
|
+
if(!closed && run===owner && !owner.controller.signal.aborted)await next()
|
|
190
|
+
} catch(e){if(run===owner)void fail(e)}
|
|
191
|
+
}
|
|
192
|
+
const composerSelector = '[data-composer-input]'
|
|
193
|
+
const done = () => {
|
|
194
|
+
put(localStorage,TUTORIAL_KEY,'completed')
|
|
195
|
+
const view=show('现在您可以自己试试了', '', [['完成',()=>{void dismiss()}]],undefined,true)
|
|
196
|
+
if(!view)return
|
|
197
|
+
for(const [kind,text] of [['mic','交互模式'],['speaker','播报模式']]){
|
|
198
|
+
const row=element('div');row.className='live-tutorial-mode'
|
|
199
|
+
const icon=controls.querySelector(`[data-voice="${kind}"] svg`)?.cloneNode(true)
|
|
200
|
+
if(icon)row.append(icon)
|
|
201
|
+
element('span',text,row);view.panel.insertBefore(row,view.footer)
|
|
202
|
+
}
|
|
203
|
+
position()
|
|
204
|
+
}
|
|
205
|
+
const switchStep = () => act('再试试切换会话','“切换到播报教学的会话。”',()=>run.switchSession(),done,'[data-slot="sidebar.sessions"]',700)
|
|
206
|
+
const sendConsent = () => show('准备好了,就发出去吧', '点击确认后,我帮您提交。', [['确认发送',()=>act('发送中','马上就好…',()=>run.send(true),switchStep,composerSelector)]],composerSelector)
|
|
207
|
+
const sendStep = () => act('满意了,就说“发送”','您也可以说“提交”。',()=>run.explainSend(),sendConsent,composerSelector)
|
|
208
|
+
const reinputStep = () => act('再输入一句','您可以说:“输入,用一句简短的话介绍语音助手。”',()=>run.reinput(),sendStep,composerSelector,1000)
|
|
209
|
+
const clearStep = () => act('想重新写,就清空','“清空输入框。”',()=>run.clear(),reinputStep,composerSelector,1000)
|
|
210
|
+
const editStep = () => act('想改哪里,直接告诉我','“把一句话改成一句简短的话。”',()=>run.edit(),clearStep,composerSelector,1000)
|
|
211
|
+
const inputStep = () => act('接下来,试试交互模式','现在开始演示交互模式,但是这次不需要您来说话,我会通过语音为您讲解。',()=>run.input(),editStep,composerSelector,1000)
|
|
212
|
+
const broadcastStep = () => act('播报模式教学','现在我们来演示在 DSH 问一个简单的问题,看看我的播报吧。',()=>run.broadcast({sound:true,chat:true}),inputStep,'[data-voice="speaker"]',700)
|
|
213
|
+
const interactionIntro = () => act('双向箭头 · 交互模式','您可以用语音输入、修改、发送消息、切换会话,也可以和我自由聊天。',()=>run.explainMode('interaction'),broadcastStep,'[data-voice="mic"]')
|
|
214
|
+
const broadcastIntro = () => act('喇叭 · 播报模式','在播报模式中,我只会为您简要播报完成的任务。',()=>run.explainMode('broadcast'),interactionIntro,'[data-voice="speaker"]')
|
|
215
|
+
async function start(consent) {
|
|
216
|
+
if(active)return
|
|
217
|
+
if(!consent?.sound||!consent?.chat){welcome();return}
|
|
218
|
+
closed=false
|
|
219
|
+
if(adapter.mode()!=='off'){show('先结束当前语音','请先关闭语音模式,再开始教学。',[['重新检查',welcome]]);return}
|
|
220
|
+
if(!navigator.locks){show('当前浏览器暂不支持教学','请使用新版 Chrome 或 Edge 打开 DSH。');return}
|
|
221
|
+
try {
|
|
222
|
+
await navigator.locks.request('dsh-duplex-tutorial-owner',{ifAvailable:true},async lock=>{
|
|
223
|
+
if(!lock){show('另一个页面正在教学','请先关闭另一个页面的教学。');return}
|
|
224
|
+
active=true;run=new TutorialRun({...adapter,status:text=>{const p=panel?.querySelector('p');if(p)p.textContent=text}})
|
|
225
|
+
const owner=run
|
|
226
|
+
const held=new Promise(resolve=>{lockRelease=resolve})
|
|
227
|
+
// Exit releases ownership immediately, even while an old async operation
|
|
228
|
+
// is winding down. act ignores callbacks belonging to an older run.
|
|
229
|
+
void act('我们开始吧','先准备一个练习用的会话…',async()=>{await adapter.unlock();owner.check();await owner.begin(consent)},broadcastIntro)
|
|
230
|
+
await held
|
|
231
|
+
})
|
|
232
|
+
}catch(e){fail(e)}
|
|
233
|
+
}
|
|
234
|
+
const welcome = () => {
|
|
235
|
+
closed=false
|
|
236
|
+
const view=show('来试试用声音操作吧','我会带您体验播报模式和交互模式。\n开始前,请完成以下准备:')
|
|
237
|
+
if(!view)return
|
|
238
|
+
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
|
+
const sound=check('声音已打开'),chat=check('同意本教程通过dsh发送消息(会产生模型用量)')
|
|
240
|
+
const b=button(view.footer,'开始教学',()=>{
|
|
241
|
+
b.disabled=true
|
|
242
|
+
const consent={sound:sound.checked,chat:chat.checked}
|
|
243
|
+
// User gesture unlocks audio before either mode is demonstrated.
|
|
244
|
+
void adapter.unlock().then(()=>{if(!closed&&view.panel.isConnected)return start(consent)}).catch(fail)
|
|
245
|
+
},true)
|
|
246
|
+
b.disabled=true;sound.onchange=chat.onchange=()=>{b.disabled=!(sound.checked&&chat.checked)}
|
|
247
|
+
position()
|
|
248
|
+
}
|
|
249
|
+
const open = () => { if(!active)welcome() }
|
|
250
|
+
const onKey=e=>{if(e.key==='Escape'&&panel)void dismiss()}
|
|
251
|
+
window.addEventListener('resize',position);window.addEventListener('scroll',position,true);window.addEventListener('keydown',onKey)
|
|
252
|
+
const layoutTimer=setInterval(position,300)
|
|
253
|
+
const url = new URL(location.href)
|
|
254
|
+
const requested = url.searchParams.get('live_tutorial') === '1'
|
|
255
|
+
if(requested){url.searchParams.delete('live_tutorial');history.replaceState(history.state,'',url)}
|
|
256
|
+
const handoff = () => {
|
|
257
|
+
try { if(consumeTutorialRequest(localStorage, document.visibilityState==='visible'))open() } catch { /* Storage may be disabled. */ }
|
|
258
|
+
}
|
|
259
|
+
window.addEventListener('storage',handoff)
|
|
260
|
+
window.addEventListener('focus',handoff)
|
|
261
|
+
document.addEventListener('visibilitychange',handoff)
|
|
262
|
+
if(requested || (!get(localStorage,TUTORIAL_KEY)&&!get(sessionStorage,TUTORIAL_KEY)))welcome()
|
|
263
|
+
handoff()
|
|
264
|
+
return {open,get active(){return active},dispose(){void dismiss();clearInterval(layoutTimer);style.remove();window.removeEventListener('resize',position);window.removeEventListener('scroll',position,true);window.removeEventListener('keydown',onKey);window.removeEventListener('storage',handoff);window.removeEventListener('focus',handoff);document.removeEventListener('visibilitychange',handoff)}}
|
|
265
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** DSH browser services plus existing voice connection; never opens a microphone. */
|
|
2
|
+
import { PLUGIN_VERSION } from './deepseek_harness_voice_state.mjs?v=0.1.0'
|
|
3
|
+
import { focusedSession } from './deepseek_harness_voice_composer.mjs?v=0.1.0'
|
|
4
|
+
export function tutorialAdapter(ctx, state, audio, pollReady) {
|
|
5
|
+
let narration
|
|
6
|
+
const completed = new Map()
|
|
7
|
+
const check = signal => signal.throwIfAborted()
|
|
8
|
+
const wait = (ms, signal) => new Promise((resolve,reject) => {
|
|
9
|
+
check(signal)
|
|
10
|
+
const abort=()=>{clearTimeout(timer);reject(signal.reason)}
|
|
11
|
+
const timer=setTimeout(()=>{signal.removeEventListener('abort',abort);resolve()},ms)
|
|
12
|
+
signal.addEventListener('abort',abort,{once:true})
|
|
13
|
+
})
|
|
14
|
+
const until = async (fn, signal, seconds=30) => {
|
|
15
|
+
const deadline=Date.now()+seconds*1000
|
|
16
|
+
while(Date.now()<deadline){check(signal);if(await fn())return;await wait(150,signal)}
|
|
17
|
+
throw Error('等待超时,教学已停止;不会自动重新发送')
|
|
18
|
+
}
|
|
19
|
+
const api = async (path, signal, method='GET', body) => {
|
|
20
|
+
check(signal)
|
|
21
|
+
const r=await fetch('/duplex-control/api/'+path,{method,signal,cache:'no-store',credentials:'same-origin',
|
|
22
|
+
headers:{'Content-Type':'application/json'},...(body?{body:JSON.stringify(body)}:{})})
|
|
23
|
+
const d=await r.json();check(signal)
|
|
24
|
+
if(!r.ok)throw Error(d.detail||d.error_code||'DSH 请求失败')
|
|
25
|
+
return d
|
|
26
|
+
}
|
|
27
|
+
const current=()=>focusedSession(ctx)
|
|
28
|
+
const input=id=>{
|
|
29
|
+
if(current()!==id)throw Error('会话焦点已改变,教学停止')
|
|
30
|
+
const scope=ctx.sessions.scope(id)
|
|
31
|
+
if(!scope)throw Error('教学会话尚未就绪')
|
|
32
|
+
return ctx.conversation.input.for(scope)
|
|
33
|
+
}
|
|
34
|
+
const safeSnapshot=(id,expected)=>{
|
|
35
|
+
const s=input(id).state.getSnapshot()
|
|
36
|
+
if(s.phase!=='plain'||s.draft!==expected||(s.attachmentIds??s.imageIds??[]).length)throw Error('教学输入框已被修改或正忙,已停止,避免覆盖你的内容')
|
|
37
|
+
return s
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
mode:()=>state.mode,current,
|
|
41
|
+
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
|
+
unlock:()=>audio.prepare(),
|
|
43
|
+
async create(name,signal){
|
|
44
|
+
const catalog=await api('sessions',signal), cwd=catalog.sessions.find(s=>s.session_id===current())?.cwd
|
|
45
|
+
const d=await api('sessions',signal,'POST',{name,...(cwd?{cwd}:{})});return d.session.session_id
|
|
46
|
+
},
|
|
47
|
+
async focus(id,signal){
|
|
48
|
+
await api(`sessions/${encodeURIComponent(id)}/activate`,signal,'POST',{})
|
|
49
|
+
await ctx.sessions.refresh();check(signal)
|
|
50
|
+
const navigation=typeof ctx.get==='function'?ctx.get('uiWorkspace'):ctx.uiWorkspace
|
|
51
|
+
if(navigation?.openSession)navigation.openSession(id);else ctx.sessions.open(id)
|
|
52
|
+
await until(()=>current()===id&&ctx.sessions.scope(id),signal)
|
|
53
|
+
},
|
|
54
|
+
async write(id,text,expected,signal){check(signal);safeSnapshot(id,expected);input(id).setDraft(text)},
|
|
55
|
+
async submit(id,expected,signal){
|
|
56
|
+
safeSnapshot(id,expected)
|
|
57
|
+
const {composer}=await api(`sessions/${encodeURIComponent(id)}/composer?require_focus=true`,signal)
|
|
58
|
+
safeSnapshot(id,expected)
|
|
59
|
+
if(composer.text!==expected)throw Error('教学草稿不一致,未发送')
|
|
60
|
+
const {job}=await api(`sessions/${encodeURIComponent(id)}/composer/submit`,signal,'POST',{
|
|
61
|
+
expected_revision:composer.revision,expected_hash:composer.hash,
|
|
62
|
+
});return job
|
|
63
|
+
},
|
|
64
|
+
async enableBroadcast(signal){
|
|
65
|
+
await pollReady(signal);check(signal)
|
|
66
|
+
await state.setMode('tts_only')
|
|
67
|
+
await until(()=>{if(state.mode==='off')throw Error('语音服务器忙或连接不可用');return state.ready},signal,45)
|
|
68
|
+
},
|
|
69
|
+
async waitBroadcast(job,signal){
|
|
70
|
+
await until(async()=>{
|
|
71
|
+
if(state.mode!=='tts_only')throw Error('播报已关闭,教学停止')
|
|
72
|
+
const d=await api(`jobs/${encodeURIComponent(job.id)}`,signal)
|
|
73
|
+
if(d.job.status==='failed')throw Error('教学任务失败:'+(d.job.error||'请查看会话'))
|
|
74
|
+
const status=completed.get(`harness_${job.id}`)
|
|
75
|
+
if(status&&status!=='completed')throw Error('播报未完成,请检查连接')
|
|
76
|
+
return status==='completed'&&!audio.playing()
|
|
77
|
+
},signal,180)
|
|
78
|
+
},
|
|
79
|
+
off:()=>state.setMode('off'),
|
|
80
|
+
stopNarration(){if(narration){try{narration.stop()}catch{};narration=null}},
|
|
81
|
+
async narrate(name,signal){
|
|
82
|
+
check(signal);await audio.prepare();check(signal)
|
|
83
|
+
const response=await fetch(`/duplex-control/tutorial-audio/${name}.wav?v=${PLUGIN_VERSION}`,{signal,credentials:'same-origin'})
|
|
84
|
+
if(!response.ok)throw Error('教学预录音频不可用,请更新插件')
|
|
85
|
+
const buffer=await audio.context.decodeAudioData(await response.arrayBuffer());check(signal)
|
|
86
|
+
await new Promise((resolve,reject)=>{
|
|
87
|
+
const node=audio.context.createBufferSource();node.buffer=buffer;node.connect(audio.context.destination);narration=node
|
|
88
|
+
const abort=()=>{try{node.stop()}catch{};node.disconnect();reject(signal.reason)}
|
|
89
|
+
signal.addEventListener('abort',abort,{once:true})
|
|
90
|
+
node.onended=()=>{signal.removeEventListener('abort',abort);node.disconnect();if(narration===node)narration=null;resolve()}
|
|
91
|
+
node.start()
|
|
92
|
+
});check(signal)
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Same-origin handoff: show the welcome only after returning to a DSH tab. */
|
|
2
|
+
export const TUTORIAL_REQUEST_KEY = 'dsh-duplex-tutorial-request-v1'
|
|
3
|
+
const MAX_AGE = 10 * 60 * 1000
|
|
4
|
+
export function requestTutorial(storage, now = Date.now()) {
|
|
5
|
+
storage.setItem(TUTORIAL_REQUEST_KEY, JSON.stringify({at: now}))
|
|
6
|
+
}
|
|
7
|
+
export function consumeTutorialRequest(storage, visible, now = Date.now()) {
|
|
8
|
+
if (!visible) return false
|
|
9
|
+
const raw = storage.getItem(TUTORIAL_REQUEST_KEY)
|
|
10
|
+
if (!raw) return false
|
|
11
|
+
storage.removeItem(TUTORIAL_REQUEST_KEY)
|
|
12
|
+
try {
|
|
13
|
+
const {at} = JSON.parse(raw)
|
|
14
|
+
return Number.isFinite(at) && now >= at && now - at < MAX_AGE
|
|
15
|
+
} catch { return false }
|
|
16
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-duet",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "duet: full-duplex voice interaction and task announcements for DeepSeek Harness",
|
|
5
|
+
"keywords": ["dsh-plugin", "deepseek-harness", "full-duplex", "voice"],
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": { "name": "YuMS", "email": "yumaoshu@gmail.com" },
|
|
8
|
+
"repository": { "type": "git", "url": "https://github.com/YuMS/dsh-duet.git" },
|
|
9
|
+
"engines": { "node": "^22.19.0 || >=24.0.0" },
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node scripts/test.mjs",
|
|
12
|
+
"check": "node scripts/check-package.mjs",
|
|
13
|
+
"test:browser": "node smoke_deepseek_harness_settings_page.mjs && node smoke_harness_tutorial.mjs && node smoke_duet_feedback.mjs",
|
|
14
|
+
"test:host": "node scripts/smoke-isolated-host.mjs",
|
|
15
|
+
"prepack": "npm run check"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./deepseek_harness_duplex_control_plugin.mjs",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"default": "./deepseek_harness_duplex_control_plugin.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./client": {
|
|
24
|
+
"default": "./deepseek_harness_duplex_focus_client/lib/client.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"NOTICE",
|
|
31
|
+
"HEROICONS-LICENSE.txt",
|
|
32
|
+
"deepseek_harness_voice_*.mjs",
|
|
33
|
+
"tutorial-audio/*.wav",
|
|
34
|
+
"tutorial-audio/manifest.json",
|
|
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"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"ws": "^8.18.3"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": { "playwright": "1.58.2" },
|
|
44
|
+
"dsh": {
|
|
45
|
+
"bundle": {
|
|
46
|
+
"patch": "./deepseek_harness_duplex_control.patch.yml"
|
|
47
|
+
},
|
|
48
|
+
"client": {
|
|
49
|
+
"inject": [
|
|
50
|
+
"@deepseek-ai/dsh-api-session-controller",
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-session",
|
|
52
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
53
|
+
],
|
|
54
|
+
"platform": "web"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "live_tutorial_v1",
|
|
3
|
+
"format": "mono_pcm16_wav",
|
|
4
|
+
"clips": {
|
|
5
|
+
"modes_broadcast": {
|
|
6
|
+
"text": "这个喇叭按钮是播报模式。在播报模式中,我只会为您简要播报完成的任务。",
|
|
7
|
+
"seconds": 6.08,
|
|
8
|
+
"sample_rate": 48000,
|
|
9
|
+
"sha256": "e57f3110aca91813b3e2b065a2fd75251ffffb4eaf87413311ef3345353b72d3"
|
|
10
|
+
},
|
|
11
|
+
"modes_interaction": {
|
|
12
|
+
"text": "这个双向箭头按钮是交互模式。您可以让我输入、修改、发送消息,或者切换会话,也可以和我自由聊天。两个模式只能选一个,浅蓝色表示当前模式。点另一个按钮就能切换,再点当前按钮就会关闭。",
|
|
13
|
+
"seconds": 15.04,
|
|
14
|
+
"sample_rate": 48000,
|
|
15
|
+
"sha256": "fde42c335c541825558a6bbfe8bb0859ab140ec9d0a588fc6b62a3c5d25a624a"
|
|
16
|
+
},
|
|
17
|
+
"broadcast": {
|
|
18
|
+
"text": "现在我们来演示在 DSH 问一个简单的问题,看看我的播报吧。",
|
|
19
|
+
"seconds": 4.8,
|
|
20
|
+
"sample_rate": 48000,
|
|
21
|
+
"sha256": "2d762074b29729ab0c1ce8d0bd111a5c88c12f28e7665e1e5972a18f99af612d"
|
|
22
|
+
},
|
|
23
|
+
"input": {
|
|
24
|
+
"text": "现在开始演示交互模式,但是这次不需要您来说话,我会通过语音为您讲解。比如,您可以说,输入,用一句话介绍语音助手。内容就会出现在输入框里。",
|
|
25
|
+
"seconds": 12.8,
|
|
26
|
+
"sample_rate": 48000,
|
|
27
|
+
"sha256": "7bbb6d2d48cea52917b89e5740f6a0e5b272440ffeeb64b922d4c8b0d1c7f10c"
|
|
28
|
+
},
|
|
29
|
+
"edit": {
|
|
30
|
+
"text": "如果想改一改,可以接着说,把一句话改成一句简短的话。",
|
|
31
|
+
"seconds": 4.32,
|
|
32
|
+
"sample_rate": 48000,
|
|
33
|
+
"sha256": "0b7e5f5af1db9347c4ab2ffcb53b498053660faa8f186aaa4355f14ddfbd1be3"
|
|
34
|
+
},
|
|
35
|
+
"clear": {
|
|
36
|
+
"text": "想重新写,可以说,清空输入框。",
|
|
37
|
+
"seconds": 3.36,
|
|
38
|
+
"sample_rate": 48000,
|
|
39
|
+
"sha256": "801c57c112d0b6785976b18ff662fae17e3a1c8613ef52ef8063f3f74a81fe79"
|
|
40
|
+
},
|
|
41
|
+
"reinput": {
|
|
42
|
+
"text": "然后,您可以说,输入,用一句简短的话介绍语音助手。我们就重新写好了。",
|
|
43
|
+
"seconds": 6.4,
|
|
44
|
+
"sample_rate": 48000,
|
|
45
|
+
"sha256": "048260a6c0b4695282c7fa9fac4775de9d653d766a6a2c784d85b6823cd97e5b"
|
|
46
|
+
},
|
|
47
|
+
"send": {
|
|
48
|
+
"text": "满意的话,您可以说,发送,或者,提交。这次点击确认后,我帮您提交。",
|
|
49
|
+
"seconds": 5.76,
|
|
50
|
+
"sample_rate": 48000,
|
|
51
|
+
"sha256": "48204b774c6069ffbb6fe975eef238f508b6c1a9754ca4cd02e41797810ab512"
|
|
52
|
+
},
|
|
53
|
+
"switch": {
|
|
54
|
+
"text": "想看看另一个会话,可以说,切换到播报教学的会话。",
|
|
55
|
+
"seconds": 4.16,
|
|
56
|
+
"sample_rate": 48000,
|
|
57
|
+
"sha256": "f8e81d74e1e9e95831f6453e5d2155665cfa5f91cc5255fb75bd8ac165103597"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|