dsh-duet 0.1.4 → 0.1.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-duet",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "duet(二重奏):只用语音就能操作 DSH,边听边说、随时插话的全双工语音助手。",
5
5
  "keywords": [
6
6
  "dsh-plugin",
@@ -22,7 +22,7 @@
22
22
  "scripts": {
23
23
  "test": "node scripts/test.mjs",
24
24
  "check": "node scripts/check-package.mjs",
25
- "test:browser": "node tests/browser/settings.mjs && node tests/browser/tutorial.mjs && node tests/browser/feedback.mjs && node tests/browser/connection-hint.mjs && node tests/browser/resilience.mjs && node tests/browser/page-binding.mjs",
25
+ "test:browser": "node tests/browser/settings.mjs && node tests/browser/tutorial.mjs && node tests/browser/feedback.mjs && node tests/browser/connection-hint.mjs && node tests/browser/resilience.mjs && node tests/browser/page-binding.mjs && node tests/browser/desktop-settings.mjs",
26
26
  "test:host": "node tests/host/isolated-host.mjs",
27
27
  "prepack": "npm run check"
28
28
  },
@@ -1,4 +1,4 @@
1
- import { microphoneConstraints } from './microphone.mjs?v=0.1.4'
1
+ import { microphoneConstraints } from './microphone.mjs?v=0.1.5'
2
2
 
3
3
  /** Browser-owned microphone and PCM playback. No microphone is requested in tts_only. */
4
4
  export class DuetAudio {
@@ -1,18 +1,19 @@
1
- import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.4'
2
- import { DuetAudio } from './audio.mjs?v=0.1.4'
3
- import { HarnessRPCExecutor } from './rpc.mjs?v=0.1.4'
4
- import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.1.4'
5
- import { startComposerBridge } from './composer-bridge.mjs?v=0.1.4'
6
- import { mountTutorial } from './tutorial.mjs?v=0.1.4'
7
- import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.1.4'
8
- import { mountRating } from './feedback.mjs?v=0.1.4'
9
- import { createAudioUploadConsent } from './consent.mjs?v=0.1.4'
10
- import { bindDuetShortcuts } from './shortcuts.mjs?v=0.1.4'
11
- import { nativeInteractions } from './interactions.mjs?v=0.1.4'
12
- import { mountConnectionHint } from './connection-hint.mjs?v=0.1.4'
13
- import { mountControlsLayout } from './controls-layout.mjs?v=0.1.4'
14
- import { mountNotice } from './notice.mjs?v=0.1.4'
15
- import { workspaceIssue, requireWorkspace, browserSessionCatalog } from './workspaces.mjs?v=0.1.4'
1
+ import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.5'
2
+ import { DuetAudio } from './audio.mjs?v=0.1.5'
3
+ import { HarnessRPCExecutor } from './rpc.mjs?v=0.1.5'
4
+ import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.1.5'
5
+ import { startComposerBridge } from './composer-bridge.mjs?v=0.1.5'
6
+ import { mountTutorial } from './tutorial.mjs?v=0.1.5'
7
+ import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.1.5'
8
+ import { mountRating } from './feedback.mjs?v=0.1.5'
9
+ import { createAudioUploadConsent } from './consent.mjs?v=0.1.5'
10
+ import { bindDuetShortcuts } from './shortcuts.mjs?v=0.1.5'
11
+ import { nativeInteractions } from './interactions.mjs?v=0.1.5'
12
+ import { mountConnectionHint } from './connection-hint.mjs?v=0.1.5'
13
+ import { mountControlsLayout } from './controls-layout.mjs?v=0.1.5'
14
+ import { mountNotice } from './notice.mjs?v=0.1.5'
15
+ import { workspaceIssue, requireWorkspace, browserSessionCatalog } from './workspaces.mjs?v=0.1.5'
16
+ import { voiceSocketUrl, bindSettingsLink } from './transport.mjs?v=0.1.5'
16
17
 
17
18
  export function mountDuet(ctx) {
18
19
  const pageId = crypto.randomUUID()
@@ -24,7 +25,7 @@ export function mountDuet(ctx) {
24
25
  const labels = new Map()
25
26
  let clientTraceId = null, diagnosticCount = 0
26
27
  let connectionGuidance = null, reportHintShown = null
27
- let tutorial, teaching, ratingPanel, connectionHint, stopControlsLayout
28
+ let tutorial, teaching, ratingPanel, connectionHint, stopControlsLayout, stopSettings
28
29
  const diagnostic = data => {
29
30
  if (++diagnosticCount > 100) return
30
31
  const bounded = Object.fromEntries(Object.entries(data).map(([k, v]) => [k, typeof v === 'string' ? v.slice(0, 4000) : v]))
@@ -132,8 +133,7 @@ export function mountDuet(ctx) {
132
133
  if(closed)return
133
134
  if (mode === 'online') stopBridge = startComposerBridge(ctx, connectionTraceId)
134
135
  report({ event: 'browser.connection_start', page_binding: 'connection_owner_v1' })
135
- const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:'
136
- ws = new WebSocket(`${protocol}//${location.host}/duplex-control/voice/ws?mode=${mode}&plugin_version=${PLUGIN_VERSION}&client_trace_id=${connectionTraceId}&page_id=${pageId}`)
136
+ ws = new WebSocket(voiceSocketUrl({ mode, plugin_version: PLUGIN_VERSION, client_trace_id: connectionTraceId, page_id: pageId }))
137
137
  ws.onopen = () => {
138
138
  send({ type: 'session.update' })
139
139
  if (mode === 'online') stopComposer = observeComposer(ctx, composer, send)
@@ -282,6 +282,8 @@ export function mountDuet(ctx) {
282
282
  settings.href = '/duet/'
283
283
  settings.target = '_blank'
284
284
  settings.rel = 'noopener noreferrer'
285
+ stopSettings?.()
286
+ stopSettings = bindSettingsLink(settings)
285
287
  settings.title = 'duet 设置'
286
288
  settings.setAttribute('aria-label', 'duet 设置')
287
289
  settings.style.cssText = 'display:flex;color:inherit;padding:5px;border-radius:6px'
@@ -390,6 +392,7 @@ export function mountDuet(ctx) {
390
392
  connectionHint?.dispose()
391
393
  clearInterval(timer); clearInterval(progress)
392
394
  stopControlsLayout?.()
395
+ stopSettings?.()
393
396
  document.removeEventListener('visibilitychange', visibility)
394
397
  window.removeEventListener('error', pageError)
395
398
  window.removeEventListener('unhandledrejection', pageError)
@@ -1,5 +1,5 @@
1
1
  /** Composer requests belong to one explicit voice/tutorial connection, never all tabs. */
2
- import { focusedSession as currentSession } from './composer.mjs?v=0.1.4'
2
+ import { focusedSession as currentSession } from './composer.mjs?v=0.1.5'
3
3
 
4
4
  export function startComposerBridge(ctx, clientId, fetchImpl = fetch) {
5
5
  const focusedSession = () => currentSession(ctx)
@@ -1,5 +1,5 @@
1
1
  /** A brief, non-modal invitation after the microphone is actually ready. */
2
- import {normalizeGuidance} from '../shared/connection-guidance.mjs?v=0.1.4'
2
+ import {normalizeGuidance} from '../shared/connection-guidance.mjs?v=0.1.5'
3
3
  export function mountConnectionHint(controls, { duration = 8000, onShown = ()=>{} } = {}) {
4
4
  const hint = document.createElement('div')
5
5
  hint.dataset.duetConnectionHint = ''
@@ -11,7 +11,7 @@ window.__ModuleLoader__.load({
11
11
  ctx.effect(() => {
12
12
  let active = true
13
13
  let dispose
14
- import('/duet/assets/client/browser.mjs?v=0.1.4').then(module => {
14
+ import('/duet/assets/client/browser.mjs?v=0.1.5').then(module => {
15
15
  if (active) dispose = module.mountDuet(ctx)
16
16
  }).catch(error => console.warn('duet controls could not load:', error))
17
17
  return () => { active = false; dispose?.() }
@@ -366,7 +366,7 @@
366
366
  }
367
367
  $('openTutorial').onclick = async () => {
368
368
  try {
369
- const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.4');
369
+ const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.5');
370
370
  requestTutorial(localStorage);
371
371
  $('tutorialStatus').textContent = '请回到 DSH 页面继续教学。';
372
372
  } catch { $('tutorialStatus').textContent = '暂时无法打开教学,请允许浏览器存储后重试。'; }
@@ -375,11 +375,11 @@
375
375
  setInterval(() => { loadDuetConfig().catch(() => { $('duetConnection').textContent = '语音连接信息不可用'; }); }, 2000);
376
376
  void loadNotices();
377
377
  setInterval(loadNotices, 60000);
378
- import('/duet/assets/client/shortcuts.mjs?v=0.1.4').then(({mountShortcutSettings}) => {
378
+ import('/duet/assets/client/shortcuts.mjs?v=0.1.5').then(({mountShortcutSettings}) => {
379
379
  const dispose = mountShortcutSettings({speaker:$('speakerShortcut'),mic:$('micShortcut'),clearSpeaker:$('clearSpeakerShortcut'),clearMic:$('clearMicShortcut'),status:$('shortcutStatus')});
380
380
  window.addEventListener('pagehide', e => {if(!e.persisted)dispose()}, {once:true});
381
381
  }).catch(() => { $('shortcutStatus').textContent = '暂时无法加载快捷键设置,请刷新重试。'; });
382
- import('/duet/assets/client/microphone.mjs?v=0.1.4').then(({mountMicrophoneSettings}) => {
382
+ import('/duet/assets/client/microphone.mjs?v=0.1.5').then(({mountMicrophoneSettings}) => {
383
383
  const dispose = mountMicrophoneSettings({select:$('microphoneDevice'),refresh:$('refreshMicrophones'),status:$('microphoneStatus')});
384
384
  window.addEventListener('pagehide', dispose, {once:true});
385
385
  }).catch(() => { $('microphoneStatus').textContent = '暂时无法加载麦克风设置,请刷新重试。'; });
@@ -0,0 +1,40 @@
1
+ /** Use the same physical WebSocket base as DSH's own API gateway. */
2
+ export function voiceSocketUrl(params, globals = globalThis) {
3
+ const base = globals.__DSH_TRANSPORT__?.streamBaseUrl ?? globals.document.baseURI
4
+ const url = new URL('duplex-control/voice/ws', base)
5
+ if (!['http:', 'https:', 'ws:', 'wss:'].includes(url.protocol)) {
6
+ throw Error('voice_transport_unavailable')
7
+ }
8
+ url.protocol = ['https:', 'wss:'].includes(url.protocol) ? 'wss:' : 'ws:'
9
+ url.search = new URLSearchParams(params).toString()
10
+ url.hash = ''
11
+ return url.href
12
+ }
13
+
14
+ /** Desktop refuses custom-protocol popups; keep settings in the owned window. */
15
+ export function bindSettingsLink(link, globals = globalThis) {
16
+ if (globals.location.protocol !== 'dsh-app:') return () => {}
17
+ let dialog
18
+ const close = () => { dialog?.close(); dialog?.remove(); dialog = null }
19
+ const open = event => {
20
+ event.preventDefault()
21
+ if (dialog) return
22
+ const doc = link.ownerDocument
23
+ dialog = doc.createElement('dialog')
24
+ dialog.setAttribute('aria-label', 'duet 设置')
25
+ dialog.style.cssText = 'width:min(960px,calc(100vw - 40px));height:calc(100vh - 64px);max-height:900px;padding:0;border:1px solid #9aa8b8;border-radius:14px;background:Canvas;color:CanvasText;overflow:hidden'
26
+ const bar = doc.createElement('div')
27
+ bar.style.cssText = 'display:flex;align-items:center;justify-content:space-between;padding:10px 16px;font:14px system-ui'
28
+ const title = doc.createElement('strong'); title.textContent = 'duet 设置'
29
+ const button = doc.createElement('button'); button.textContent = '关闭设置'; button.onclick = close
30
+ bar.append(title, button)
31
+ const frame = doc.createElement('iframe')
32
+ frame.title = 'duet 设置'; frame.src = link.href
33
+ frame.style.cssText = 'display:block;width:100%;height:calc(100% - 48px);border:0'
34
+ dialog.append(bar, frame)
35
+ dialog.addEventListener('cancel', event => { event.preventDefault(); close() })
36
+ doc.body.append(dialog); dialog.showModal()
37
+ }
38
+ link.addEventListener('click', open)
39
+ return () => { link.removeEventListener('click', open); close() }
40
+ }
@@ -1,8 +1,8 @@
1
1
  /** DSH browser services plus existing voice connection; never opens a microphone. */
2
- import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.4'
3
- import { focusedSession } from './composer.mjs?v=0.1.4'
4
- import { requireWorkspace, workspaceIssue } from './workspaces.mjs?v=0.1.4'
5
- import { startComposerBridge } from './composer-bridge.mjs?v=0.1.4'
2
+ import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.5'
3
+ import { focusedSession } from './composer.mjs?v=0.1.5'
4
+ import { requireWorkspace, workspaceIssue } from './workspaces.mjs?v=0.1.5'
5
+ import { startComposerBridge } from './composer-bridge.mjs?v=0.1.5'
6
6
  export function tutorialAdapter(ctx, state, audio, pollReady, startBridge = startComposerBridge) {
7
7
  let narration
8
8
  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 './tutorial-request.mjs?v=0.1.4'
2
+ import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.1.5'
3
3
  export const TUTORIAL_KEY = 'dsh-duplex-tutorial-v1'
4
4
  export const QUESTION = '什么是语音交互?请用一句话简单解释,不使用工具。'
5
5
  export const INPUT = '用一句话介绍语音助手。'
@@ -12,6 +12,7 @@ const modules = {
12
12
  controls_layout: 'client/controls-layout',
13
13
  notice: 'client/notice',
14
14
  workspaces: 'client/workspaces',
15
+ transport: 'client/transport',
15
16
  }
16
17
  const aliases = {
17
18
  state: 'DuetState as VoiceState', audio: 'DuetAudio as VoiceAudio',
@@ -11,7 +11,8 @@ import {DEFAULT_DUET_URL, PUBLIC_TRIAL_AUTHORIZATION, isPublicTrialEndpoint} fro
11
11
 
12
12
  export function endpointHTTP(endpoint, path) {
13
13
  const url=new URL(endpoint)
14
- url.protocol=url.protocol==='wss:'?'https:':'http:'
14
+ if(!['http:','https:','ws:','wss:'].includes(url.protocol))throw Error('invalid_endpoint_protocol')
15
+ url.protocol=['wss:','https:'].includes(url.protocol)?'https:':'http:'
15
16
  url.pathname=url.pathname.replace(/\/ws\/?$/,'').replace(/\/$/,'')+path
16
17
  url.search=''
17
18
  return url.toString()
@@ -1,5 +1,5 @@
1
1
  /** Desired voice mode is independent of a temporarily suspended connection. */
2
- export const PLUGIN_VERSION = '0.1.4'
2
+ export const PLUGIN_VERSION = '0.1.5'
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 : ''
@@ -63,6 +63,8 @@ export class DuetState {
63
63
  this.changed(this)
64
64
  await this.retiring
65
65
  if (generation !== this.generation || this.mode === 'off' || this.suspended) return
66
+ // Remind on every new connection, while deduplicating its compatibility events.
67
+ this.recommendationShown = null
66
68
  try {
67
69
  this.connection = this.connect(this.mode, event => {
68
70
  if (generation !== this.generation) return