dsh-duet 0.1.0 → 0.1.2

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.
Files changed (42) hide show
  1. package/README.md +15 -16
  2. package/package.json +31 -20
  3. package/{deepseek_harness_voice_audio.mjs → src/client/audio.mjs} +4 -4
  4. package/{deepseek_harness_voice_browser.mjs → src/client/browser.mjs} +41 -20
  5. package/src/client/connection-hint.mjs +43 -0
  6. package/{deepseek_harness_duplex_focus_client/lib/client.js → src/client/entry.js} +15 -15
  7. package/{deepseek_harness_voice_interactions.mjs → src/client/interactions.mjs} +3 -1
  8. package/{deepseek_harness_voice_rpc.mjs → src/client/rpc.mjs} +4 -3
  9. package/{deepseek_harness_duplex_control_plugin.html → src/client/settings.html} +18 -22
  10. package/{deepseek_harness_voice_shortcuts.mjs → src/client/shortcuts.mjs} +1 -1
  11. package/{deepseek_harness_voice_tutorial_adapter.mjs → src/client/tutorial-adapter.mjs} +4 -2
  12. package/{deepseek_harness_voice_tutorial.mjs → src/client/tutorial.mjs} +15 -15
  13. package/src/client/workspaces.mjs +25 -0
  14. package/src/host/assets.mjs +28 -0
  15. package/src/host/environment.mjs +10 -0
  16. package/{deepseek_harness_duplex_control_plugin.mjs → src/host/plugin.mjs} +34 -32
  17. package/{deepseek_harness_voice_proxy.mjs → src/host/proxy.mjs} +17 -13
  18. package/src/host/service-defaults.mjs +12 -0
  19. package/{deepseek_harness_voice_settings.mjs → src/host/settings.mjs} +11 -15
  20. package/{deepseek_harness_voice_trace.mjs → src/host/trace.mjs} +4 -3
  21. package/{deepseek_harness_voice_catalog.mjs → src/shared/catalog.mjs} +15 -4
  22. package/{deepseek_harness_voice_state.mjs → src/shared/state.mjs} +5 -2
  23. /package/{tutorial-audio → assets/tutorial-audio}/broadcast.wav +0 -0
  24. /package/{tutorial-audio → assets/tutorial-audio}/clear.wav +0 -0
  25. /package/{tutorial-audio → assets/tutorial-audio}/edit.wav +0 -0
  26. /package/{tutorial-audio → assets/tutorial-audio}/input.wav +0 -0
  27. /package/{tutorial-audio → assets/tutorial-audio}/manifest.json +0 -0
  28. /package/{tutorial-audio → assets/tutorial-audio}/modes_broadcast.wav +0 -0
  29. /package/{tutorial-audio → assets/tutorial-audio}/modes_interaction.wav +0 -0
  30. /package/{tutorial-audio → assets/tutorial-audio}/reinput.wav +0 -0
  31. /package/{tutorial-audio → assets/tutorial-audio}/send.wav +0 -0
  32. /package/{tutorial-audio → assets/tutorial-audio}/switch.wav +0 -0
  33. /package/{deepseek_harness_duplex_control.patch.yml → config/duet.patch.yml} +0 -0
  34. /package/{deepseek_harness_voice_composer.mjs → src/client/composer.mjs} +0 -0
  35. /package/{deepseek_harness_voice_consent.mjs → src/client/consent.mjs} +0 -0
  36. /package/{deepseek_harness_voice_feedback.mjs → src/client/feedback.mjs} +0 -0
  37. /package/{deepseek_harness_voice_microphone.mjs → src/client/microphone.mjs} +0 -0
  38. /package/{deepseek_harness_voice_tutorial_request.mjs → src/client/tutorial-request.mjs} +0 -0
  39. /package/{deepseek_harness_voice_feedback_files.mjs → src/host/feedback-files.mjs} +0 -0
  40. /package/{deepseek_harness_voice_feedback_store.mjs → src/host/feedback-store.mjs} +0 -0
  41. /package/{deepseek_harness_voice_notices.mjs → src/host/notices.mjs} +0 -0
  42. /package/{deepseek_harness_voice_service_info.mjs → src/host/service-info.mjs} +0 -0
@@ -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 bindVoiceShortcuts(activate,target=window,store=storage()) {
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,7 @@
1
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'
2
+ import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.2'
3
+ import { focusedSession } from './composer.mjs?v=0.1.2'
4
+ import { requireWorkspace } from './workspaces.mjs?v=0.1.2'
4
5
  export function tutorialAdapter(ctx, state, audio, pollReady) {
5
6
  let narration
6
7
  const completed = new Map()
@@ -41,6 +42,7 @@ export function tutorialAdapter(ctx, state, audio, pollReady) {
41
42
  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
43
  unlock:()=>audio.prepare(),
43
44
  async create(name,signal){
45
+ requireWorkspace(ctx)
44
46
  const catalog=await api('sessions',signal), cwd=catalog.sessions.find(s=>s.session_id===current())?.cwd
45
47
  const d=await api('sessions',signal,'POST',{name,...(cwd?{cwd}:{})});return d.session.session_id
46
48
  },
@@ -1,5 +1,5 @@
1
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'
2
+ import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.1.2'
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.voiceOwned = false
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.voiceOwned = true
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.voiceOwned = false; this.step = 'input'
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.voiceOwned) { this.voiceOwned = false; await this.a.off() }
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
- .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}
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-duplex-voice-controls'
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-duplex-voice-controls'
156
+ targetSelector = selector || '#dsh-duet-controls'
157
157
  target = document.querySelector(targetSelector) || controls
158
- highlight = element('div',null,document.body); highlight.className='live-tutorial-highlight'; highlight.setAttribute('aria-hidden','true')
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('live-tutorial-pointer')
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='live-tutorial'; panel.setAttribute('role','region'); panel.setAttribute('aria-label','duet 使用教学')
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='live-tutorial-mode'
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,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
+ }
@@ -0,0 +1,28 @@
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
+ connection_hint: 'client/connection-hint',
10
+ workspaces: 'client/workspaces',
11
+ }
12
+ const aliases = {
13
+ state: 'DuetState as VoiceState', audio: 'DuetAudio as VoiceAudio',
14
+ browser: 'mountDuet as mountVoice', shortcuts: 'bindDuetShortcuts as bindVoiceShortcuts',
15
+ }
16
+ const publicModules = new Set(Object.values(modules))
17
+
18
+ export function publicAsset(pathname) {
19
+ const modern = pathname.match(/^\/duet\/assets\/(client|shared)\/([a-z-]+)\.mjs$/)
20
+ if (modern && publicModules.has(`${modern[1]}/${modern[2]}`)) {
21
+ return { url: new URL(`../${modern[1]}/${modern[2]}.mjs`, import.meta.url) }
22
+ }
23
+ // Old open pages may request their previous module URLs after an upgrade.
24
+ const legacy = pathname.match(/^\/duplex-control\/deepseek_harness_voice_([a-z_]+)\.mjs$/)
25
+ if (!legacy || !Object.hasOwn(modules, legacy[1])) return null
26
+ const target = `/duet/assets/${modules[legacy[1]]}.mjs`
27
+ return { body: `export * from '${target}';\n${aliases[legacy[1]] ? `export { ${aliases[legacy[1]]} } from '${target}';\n` : ''}` }
28
+ }
@@ -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
- /** DeepSeek Harness plugin that exposes the duplex control console on the official WebUI host. */
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 { registerVoiceProxy, voiceConfig } from './deepseek_harness_voice_proxy.mjs'
6
- import { VoiceSettings, settingsWriteAllowed } from './deepseek_harness_voice_settings.mjs'
7
- import { ServiceNotices } from './deepseek_harness_voice_notices.mjs'
8
- import { ServiceInfo } from './deepseek_harness_voice_service_info.mjs'
9
- import { VoiceTrace } from './deepseek_harness_voice_trace.mjs'
10
- import { FeedbackService } from './deepseek_harness_voice_feedback_store.mjs'
11
- import { RemoteFeedback } from './deepseek_harness_voice_feedback_files.mjs'
12
- import { PLUGIN_VERSION } from './deepseek_harness_voice_state.mjs'
13
- import { buildSessionCatalog } from './deepseek_harness_voice_catalog.mjs'
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 DUPLEX_RUNTIME_STALE_SECONDS = 3
25
- const HTML_URL = new URL('./deepseek_harness_duplex_control_plugin.html', import.meta.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 lastDuplexRuntimeSeenAt = 0
161
+ let lastDuetRuntimeSeenAt = 0
160
162
  let lastNativeInteractionsSeenAt = -Infinity
161
163
  const hostAbort = new AbortController()
162
164
 
163
- const voice = voiceConfig()
164
- const settings = new VoiceSettings(voice, { path: options.settingsPath, debug: options.debug === true || process.env.DUPLEX_CONTROL_DEBUG === '1' })
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 VoiceTrace({ kind: 'host', plugin_version: PLUGIN_VERSION, pid: process.pid },
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 voiceProxy
174
- ctx.effect(() => { voiceProxy = registerVoiceProxy(ctx, voice, feedback); return voiceProxy })
175
+ let duetProxy
176
+ ctx.effect(() => { duetProxy = registerDuetProxy(ctx, voice, feedback, () => (ctx.workspaceRegistry.list?.() || []).length > 0); return duetProxy })
175
177
 
176
178
  ctx.effect(() => () => { hostAbort.abort() })
177
179
 
178
- const duplexRuntimeActive = () => (
179
- nowSeconds() - lastDuplexRuntimeSeenAt <= DUPLEX_RUNTIME_STALE_SECONDS
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 (!duplexRuntimeActive() || nativeInteractionsActive()) return next()
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 (!duplexRuntimeActive() || nativeInteractionsActive()) return next()
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', 'Duplex control 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: voiceProxy?.snapshot?.() || { online: 0, tts_only: 0 } })
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
- voiceProxy?.closeConnections?.('voice_settings_changed')
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: duplexRuntimeActive(),
536
- duplex_runtime_last_seen_at: lastDuplexRuntimeSeenAt || null,
537
- duplex_runtime_stale_after_seconds: DUPLEX_RUNTIME_STALE_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(`./tutorial-audio/${tutorialAudio[1]}.wav`, import.meta.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.match(/^\/duplex-control\/(deepseek_harness_voice_(?:state|audio|microphone|shortcuts|catalog|browser|rpc|composer|interactions|tutorial|tutorial_adapter|tutorial_request|feedback|consent)\.mjs)$/)
1068
+ const asset = publicAsset(pathname)
1067
1069
  if (req.method === 'GET' && asset) {
1068
- const body = await readFile(new URL(`./${asset[1]}`, import.meta.url))
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
- lastDuplexRuntimeSeenAt = nowSeconds()
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,10 @@
1
1
  /** Same-origin voice relay; endpoint and compatibility policy belong to the DSH host. */
2
2
  import { createRequire } from 'node:module'
3
- import { VoiceTrace } from './deepseek_harness_voice_trace.mjs'
3
+ import { DuetTrace } from './trace.mjs'
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'
4
7
  const require = createRequire(import.meta.url)
5
- export const DEFAULT_VOICE_URL = 'ws://duet-router.1781574661016173.ap-southeast-1.pai-eas.aliyuncs.com/ws?protocol=realtime_v2'
6
8
 
7
9
  export function compatibleVersion(version, min = '0.1.0', maxExclusive = '0.2.0') {
8
10
  const parse = v => /^\d+\.\d+\.\d+$/.test(v || '') ? v.split('.').map(Number) : null
@@ -11,16 +13,17 @@ export function compatibleVersion(version, min = '0.1.0', maxExclusive = '0.2.0'
11
13
  return Boolean(v && low && high && compare(v, low) >= 0 && compare(v, high) < 0)
12
14
  }
13
15
 
14
- export function voiceConfig(env = process.env) {
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
+ }
15
21
  return {
16
- min_version: env.DUPLEX_PLUGIN_MIN_VERSION || '0.1.0',
17
- max_version_exclusive: env.DUPLEX_PLUGIN_MAX_VERSION_EXCLUSIVE || '0.2.0',
18
- control_transport: env.DUPLEX_VOICE_CONTROL_TRANSPORT || 'client_rpc_v1',
19
- authorization: env.DUPLEX_VOICE_AUTHORIZATION || '',
20
- endpoints: {
21
- online: env.DUPLEX_VOICE_ONLINE_URL || env.DUPLEX_VOICE_URL || DEFAULT_VOICE_URL,
22
- tts_only: env.DUPLEX_VOICE_TTS_ONLY_URL || env.DUPLEX_VOICE_URL || DEFAULT_VOICE_URL,
23
- },
22
+ min_version: duetEnv('MIN_VERSION', env) || '0.1.0',
23
+ max_version_exclusive: duetEnv('MAX_VERSION_EXCLUSIVE', env) || '0.2.0',
24
+ control_transport: duetEnv('CONTROL_TRANSPORT', env) || 'client_rpc_v1',
25
+ authorization: publicServiceAuthorization(endpoints),
26
+ endpoints,
24
27
  }
25
28
  }
26
29
 
@@ -41,7 +44,7 @@ export function externalWithState(message, _state) {
41
44
  ...(source === undefined ? {} : { source: { ...source } }) }
42
45
  }
43
46
 
44
- export function registerVoiceProxy(ctx, config = voiceConfig(), feedback = null) {
47
+ export function registerDuetProxy(ctx, config = duetConfig(), feedback = null, canUseVoice = () => true) {
45
48
  if (!['http', 'client_rpc_v1'].includes(config.control_transport || 'http')) throw new Error('invalid_harness_transport')
46
49
  if (!compatibleVersion(config.min_version, config.min_version, config.max_version_exclusive)) throw new Error('invalid_plugin_version_policy')
47
50
  for (const target of Object.values(config.endpoints)) {
@@ -67,7 +70,7 @@ export function registerVoiceProxy(ctx, config = voiceConfig(), feedback = null)
67
70
  server.handleUpgrade(req, socket, head, front => {
68
71
  front.on('error', () => {})
69
72
  const params = new URL(req.url, 'http://localhost').searchParams
70
- const trace = new VoiceTrace({ mode: params.get('mode'), plugin_version: params.get('plugin_version'),
73
+ const trace = new DuetTrace({ mode: params.get('mode'), plugin_version: params.get('plugin_version'),
71
74
  client_trace_id: (params.get('client_trace_id') || '').slice(0, 64),
72
75
  backend_origin: new URL(config.endpoints[params.get('mode')] || config.endpoints.online).origin,
73
76
  control_transport: config.control_transport }, { ...config.traceOptions, secrets: [config.authorization] })
@@ -91,6 +94,7 @@ export function registerVoiceProxy(ctx, config = voiceConfig(), feedback = null)
91
94
  const mode = params.get('mode')
92
95
  if (!compatibleVersion(params.get('plugin_version'), config.min_version, config.max_version_exclusive)) { fail('plugin_upgrade_required'); return }
93
96
  if (!['online', 'tts_only'].includes(mode)) { fail('invalid_voice_mode'); return }
97
+ if (!canUseVoice()) { fail('workspace_required'); return }
94
98
  connections.set(front, { mode, ready: false, trace })
95
99
  front.on('close', () => connections.delete(front))
96
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
+ }
@@ -1,24 +1,26 @@
1
- /** Host-only settings. Never return stored credentials to the browser. */
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
+ import { duetEnv } from './environment.mjs'
8
+ import { publicServiceAuthorization } from './service-defaults.mjs'
7
9
 
8
10
  export function validateBackendURL(value, insecureOrigin = null) {
9
11
  if (typeof value !== 'string' || value.length > 2048) throw new Error('invalid_backend_url')
10
12
  const url = new URL(value)
11
13
  if (!['ws:', 'wss:'].includes(url.protocol) || url.username || url.password || url.hash) throw new Error('invalid_backend_url')
12
- // Credentials belong in the host-only token field, never in URLs or logs.
14
+ // Credentials never belong in URLs or logs.
13
15
  if ([...url.searchParams.keys()].some(k => k !== 'protocol')) throw new Error('backend_url_query_not_allowed')
14
16
  if (url.protocol === 'ws:' && !['localhost', '127.0.0.1', '[::1]'].includes(url.hostname) && url.origin !== insecureOrigin) throw new Error('backend_requires_wss')
15
17
  return url.toString()
16
18
  }
17
19
 
18
- export class VoiceSettings {
20
+ export class DuetSettings {
19
21
  constructor(base, { path, debug = false } = {}) {
20
22
  this.base = base
21
- this.path = path || process.env.DUPLEX_VOICE_SETTINGS_FILE || join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'duplex-control', 'voice.json')
23
+ this.path = path || duetEnv('SETTINGS_FILE') || join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'duplex-control', 'voice.json')
22
24
  this.debug = debug
23
25
  this.saved = null
24
26
  this.revision = 0
@@ -32,15 +34,14 @@ export class VoiceSettings {
32
34
  validate(data) {
33
35
  if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('invalid_voice_settings')
34
36
  const backend_url = validateBackendURL(data.backend_url, data.insecure_origin)
35
- const auth_token = data.auth_token
36
- if (typeof auth_token !== 'string' || auth_token.length > 8192 || /[\r\n\0]/.test(auth_token)) throw new Error('invalid_auth_token')
37
37
  const url = new URL(backend_url)
38
38
  const insecure_origin = url.protocol === 'ws:' && url.origin === data.insecure_origin ? url.origin : null
39
- return { backend_url, auth_token: auth_token || 'test', ...(insecure_origin ? { insecure_origin } : {}) }
39
+ return { backend_url, ...(insecure_origin ? { insecure_origin } : {}) }
40
40
  }
41
41
 
42
42
  effective() {
43
- return this.saved ? { ...this.base, endpoints: { online: this.saved.backend_url, tts_only: this.saved.backend_url }, authorization: this.saved.auth_token === 'test' ? '' : this.saved.auth_token } : this.base
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) }
44
45
  }
45
46
 
46
47
  public() {
@@ -55,7 +56,7 @@ export class VoiceSettings {
55
56
  min_version: config.min_version, max_version_exclusive: config.max_version_exclusive,
56
57
  modes: Object.keys(config.endpoints), endpoints,
57
58
  backend_url: endpoints.online, config_source: this.saved ? 'plugin_settings' : 'environment_or_default',
58
- auth_configured: Boolean(config.authorization), token_placeholder: config.authorization ? '已保存;留空保持不变' : '请输入访问密钥',
59
+ auth_configured: Boolean(config.authorization),
59
60
  debug: this.debug, revision: this.revision,
60
61
  insecure_transport: new URL(config.endpoints.online).protocol !== 'wss:',
61
62
  }
@@ -64,15 +65,10 @@ export class VoiceSettings {
64
65
  async save(input) {
65
66
  if (this.writing) throw new Error('settings_write_in_progress')
66
67
  if (!input || input.revision !== this.revision) throw new Error('settings_revision_conflict')
67
- const current = this.effective()
68
68
  // A deliberate, authenticated per-origin opt-in, never a global TLS bypass.
69
69
  const insecureOrigin = input.allow_insecure_http === true ? new URL(input.backend_url).origin : this.saved?.insecure_origin
70
70
  const url = validateBackendURL(input.backend_url, insecureOrigin)
71
- // Never send a retained credential to a newly selected server.
72
- const token = input.auth_token === '' || input.auth_token === undefined
73
- ? url === current.endpoints.online ? current.authorization || 'test' : 'test'
74
- : input.auth_token
75
- const next = this.validate({ backend_url: url, auth_token: token, insecure_origin: insecureOrigin })
71
+ const next = this.validate({ backend_url: url, insecure_origin: insecureOrigin })
76
72
  this.writing = true
77
73
  const temp = `${this.path}.${randomUUID()}.tmp`
78
74
  try {
@@ -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 VoiceTrace {
21
- constructor(metadata, { root = process.env.DUPLEX_VOICE_TRACE_DIR || join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'duplex-control', 'traces'),
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(`[duplex-trace] capture incomplete trace=${this.id} reason=${reason}`)
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
  }
@@ -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
- const recent = [...visible].sort((a,b) => (b.updated_at || 0) - (a.updated_at || 0)
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]) => reconcile(members, accounts[key]))
44
+ return [...groups].flatMap(([key, members]) => ordered(members, key))
34
45
  }
35
46
 
36
47
  export function buildSessionCatalog(items, {workspaces = [], archivedIds = [], activeId, includeBlank = false} = {}) {
@@ -1,5 +1,5 @@
1
1
  /** Desired voice mode is independent of a temporarily suspended connection. */
2
- export const PLUGIN_VERSION = '0.1.0'
2
+ export const PLUGIN_VERSION = '0.1.2'
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 VoiceState {
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'
@@ -105,6 +105,9 @@ export class VoiceState {
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: '无法使用所选麦克风,请在设置中检查设备与浏览器权限',
109
112
  interaction_mode_unavailable: '交互模式暂时不可用,请稍后再试',
110
113
  broadcast_mode_unavailable: '播报模式暂时不可用,请稍后再试',