dsh-duet 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/assets/avatar/desktop/companion.mjs +3 -3
- package/assets/avatar/desktop/manifest.json +1 -1
- package/desktop/bin/darwin-arm64/duet-avatar.app/Contents/MacOS/duet-avatar +0 -0
- package/desktop/bin/darwin-arm64/manifest.json +3 -3
- package/desktop/bin/win32-x64/duet-avatar.exe +0 -0
- package/desktop/bin/win32-x64/manifest.json +3 -3
- package/package.json +2 -2
- package/src/avatar/companion.mjs +5 -3
- package/src/client/agent-tasks.mjs +116 -18
- package/src/client/audio.mjs +1 -1
- package/src/client/avatar.mjs +15 -2
- package/src/client/browser.mjs +24 -24
- package/src/client/composer-bridge.mjs +1 -1
- package/src/client/connection-hint.mjs +1 -1
- package/src/client/entry.js +2 -2
- package/src/client/feedback.mjs +1 -1
- package/src/client/identity.mjs +1 -1
- package/src/client/interactions.mjs +5 -4
- package/src/client/notice.mjs +30 -9
- package/src/client/settings.html +5 -4
- package/src/client/sidebar-layout.mjs +26 -0
- package/src/client/tutorial-adapter.mjs +5 -5
- package/src/client/tutorial.mjs +1 -1
- package/src/client/work-mode.mjs +1 -1
- package/src/host/agent-connection.mjs +6 -1
- package/src/host/assets.mjs +1 -0
- package/src/host/auth.mjs +13 -0
- package/src/host/avatar.mjs +32 -13
- package/src/host/plugin.mjs +18 -15
- package/src/host/proxy.mjs +3 -2
- package/src/host/sync-feed.mjs +3 -2
- package/src/shared/state.mjs +29 -4
package/src/client/browser.mjs
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.3.
|
|
2
|
-
import { DuetAudio, AUDIO_STOP_PROTOCOL } from './audio.mjs?v=0.3.
|
|
3
|
-
import { HarnessRPCExecutor, rpcNavigationSession } from './rpc.mjs?v=0.3.
|
|
4
|
-
import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.3.
|
|
5
|
-
import { startComposerBridge } from './composer-bridge.mjs?v=0.3.
|
|
6
|
-
import { mountTutorial } from './tutorial.mjs?v=0.3.
|
|
1
|
+
import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.3.3'
|
|
2
|
+
import { DuetAudio, AUDIO_STOP_PROTOCOL } from './audio.mjs?v=0.3.3'
|
|
3
|
+
import { HarnessRPCExecutor, rpcNavigationSession } from './rpc.mjs?v=0.3.3'
|
|
4
|
+
import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.3.3'
|
|
5
|
+
import { startComposerBridge } from './composer-bridge.mjs?v=0.3.3'
|
|
6
|
+
import { mountTutorial } from './tutorial.mjs?v=0.3.3'
|
|
7
7
|
import { mountAvatarTasks } from './avatar-tasks.mjs'
|
|
8
|
-
import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.3.
|
|
9
|
-
import { mountRating } from './feedback.mjs?v=0.3.
|
|
10
|
-
import { createAudioUploadConsent } from './consent.mjs?v=0.3.
|
|
11
|
-
import { bindDuetShortcuts } from './shortcuts.mjs?v=0.3.
|
|
12
|
-
import { nativeInteractions } from './interactions.mjs?v=0.3.
|
|
13
|
-
import { mountConnectionHint } from './connection-hint.mjs?v=0.3.
|
|
14
|
-
import { mountControlsLayout } from './controls-layout.mjs?v=0.3.
|
|
15
|
-
import { mountNotice } from './notice.mjs?v=0.3.
|
|
16
|
-
import { browserSessionCatalog, sessionCreationPayload } from './workspaces.mjs?v=0.3.
|
|
8
|
+
import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.3.3'
|
|
9
|
+
import { mountRating } from './feedback.mjs?v=0.3.3'
|
|
10
|
+
import { createAudioUploadConsent } from './consent.mjs?v=0.3.3'
|
|
11
|
+
import { bindDuetShortcuts } from './shortcuts.mjs?v=0.3.3'
|
|
12
|
+
import { nativeInteractions } from './interactions.mjs?v=0.3.3'
|
|
13
|
+
import { mountConnectionHint } from './connection-hint.mjs?v=0.3.3'
|
|
14
|
+
import { mountControlsLayout } from './controls-layout.mjs?v=0.3.3'
|
|
15
|
+
import { mountNotice } from './notice.mjs?v=0.3.3'
|
|
16
|
+
import { browserSessionCatalog, sessionCreationPayload } from './workspaces.mjs?v=0.3.3'
|
|
17
17
|
import { workModeOnboarding } from './work-mode.mjs'
|
|
18
18
|
import { agentEntryNavigation } from './agent-entry.mjs'
|
|
19
19
|
import { workModeIssue, noteTaskVisit } from '../shared/work-mode.mjs'
|
|
20
|
-
import { voiceSocketUrl, bindSettingsLink } from './transport.mjs?v=0.3.
|
|
21
|
-
import { identityFetch, identityVoiceProtocols } from './identity.mjs?v=0.3.
|
|
22
|
-
import { sessionLabel } from '../shared/catalog.mjs?v=0.3.
|
|
23
|
-
import { resultNotification } from '../shared/result-notification.mjs?v=0.3.
|
|
24
|
-
import { HarnessSync } from './harness-sync.mjs?v=0.3.
|
|
25
|
-
import { LocalSync } from './local-sync.mjs?v=0.3.
|
|
26
|
-
import { diagnosticPayload } from '../shared/diagnostics.mjs?v=0.3.
|
|
20
|
+
import { voiceSocketUrl, bindSettingsLink } from './transport.mjs?v=0.3.3'
|
|
21
|
+
import { identityFetch, identityVoiceProtocols } from './identity.mjs?v=0.3.3'
|
|
22
|
+
import { sessionLabel } from '../shared/catalog.mjs?v=0.3.3'
|
|
23
|
+
import { resultNotification } from '../shared/result-notification.mjs?v=0.3.3'
|
|
24
|
+
import { HarnessSync } from './harness-sync.mjs?v=0.3.3'
|
|
25
|
+
import { LocalSync } from './local-sync.mjs?v=0.3.3'
|
|
26
|
+
import { diagnosticPayload } from '../shared/diagnostics.mjs?v=0.3.3'
|
|
27
27
|
import { mountAvatar } from './avatar.mjs'
|
|
28
28
|
import { mountAvatarSurfaces } from './avatar-surfaces.mjs'
|
|
29
29
|
import { audioUnlockPanel } from '../shared/avatar-ui.mjs'
|
|
@@ -59,10 +59,10 @@ export function mountDuet(ctx) {
|
|
|
59
59
|
const pageError = event => diagnostic({ event: 'browser.error', message: String(event.message || event.reason?.message || event.reason), stack: event.error?.stack || event.reason?.stack })
|
|
60
60
|
window.addEventListener('error', pageError)
|
|
61
61
|
window.addEventListener('unhandledrejection', pageError)
|
|
62
|
-
const notice = (text, { upgrade = false,
|
|
62
|
+
const notice = (text, { upgrade = false, ...details } = {}) => {
|
|
63
63
|
connectionHint?.dismiss()
|
|
64
64
|
if (upgrade) { ratingPanel?.dispose(); ratingPanel = null }
|
|
65
|
-
notices.show(text, { upgrade,
|
|
65
|
+
notices.show(text, { upgrade, ...details })
|
|
66
66
|
}
|
|
67
67
|
const draw = state => {
|
|
68
68
|
if (pollGeneration !== state.generation) {
|
|
@@ -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.3.
|
|
2
|
+
import { focusedSession as currentSession } from './composer.mjs?v=0.3.3'
|
|
3
3
|
|
|
4
4
|
export function startComposerBridge(ctx, clientId, fetchImpl = fetch, feed = null, onWrite = () => {}) {
|
|
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.3.
|
|
2
|
+
import {normalizeGuidance} from '../shared/connection-guidance.mjs?v=0.3.3'
|
|
3
3
|
import {AGENT_WORKSPACE_NOTICE,agentEntryReminder} from '../shared/work-mode.mjs'
|
|
4
4
|
export function mountConnectionHint(controls, { duration = 8000, onShown = ()=>{}, onSettings = ()=>{} } = {}) {
|
|
5
5
|
const hint = document.createElement('div')
|
package/src/client/entry.js
CHANGED
|
@@ -10,7 +10,7 @@ window.__ModuleLoader__.load({
|
|
|
10
10
|
function apply(ctx) {
|
|
11
11
|
ctx.effect(() => {
|
|
12
12
|
let active=true,dispose
|
|
13
|
-
import('/duet/assets/client/agent-tool-views.mjs?v=0.3.
|
|
13
|
+
import('/duet/assets/client/agent-tool-views.mjs?v=0.3.3').then(module=>{
|
|
14
14
|
if(active&&ctx.slots&&typeof require==='function')dispose=module.mountAgentToolViews(ctx,require('react'))
|
|
15
15
|
}).catch(error=>console.warn('duet task cards could not load:',error))
|
|
16
16
|
return ()=>{active=false;dispose?.()}
|
|
@@ -20,7 +20,7 @@ window.__ModuleLoader__.load({
|
|
|
20
20
|
ctx.effect(() => {
|
|
21
21
|
let active = true
|
|
22
22
|
let dispose
|
|
23
|
-
import('/duet/assets/client/browser.mjs?v=0.3.
|
|
23
|
+
import('/duet/assets/client/browser.mjs?v=0.3.3').then(module => {
|
|
24
24
|
if (active) dispose = module.mountDuet(ctx)
|
|
25
25
|
}).catch(error => {
|
|
26
26
|
console.warn('duet controls could not load:', error)
|
package/src/client/feedback.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Optional, explicit rating; never opens voice or submits without a user click. */
|
|
2
|
-
import { identityFetch } from './identity.mjs?v=0.3.
|
|
2
|
+
import { identityFetch } from './identity.mjs?v=0.3.3'
|
|
3
3
|
|
|
4
4
|
export function mountRating(anchor, sessionTicket, {origin='page'} = {}) {
|
|
5
5
|
if(!sessionTicket)return null
|
package/src/client/identity.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IDENTITY_HEADER, IDENTITY_TRANSPORT_HEADER, IDENTITY_TRANSPORT, IDENTITY_STORAGE,
|
|
2
|
-
VOICE_PROTOCOL, IDENTITY_PROTOCOL_PREFIX, validIdentityToken } from '../shared/identity.mjs?v=0.3.
|
|
2
|
+
VOICE_PROTOCOL, IDENTITY_PROTOCOL_PREFIX, validIdentityToken } from '../shared/identity.mjs?v=0.3.3'
|
|
3
3
|
|
|
4
4
|
/** Desktop strips plugin cookies. Keep the Host-signed value in its origin storage. */
|
|
5
5
|
export function createIdentityClient(globals = globalThis) {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/** Use the same pending objects as DSH's clickable question/approval cards. */
|
|
2
2
|
export function nativeInteractions(ctx) {
|
|
3
3
|
const firstSeen = new Map()
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const pendingStore = ctx.uiSession.pendingInteractions
|
|
5
|
+
const store = pendingStore ?? ctx.uiSession.sessionStatus
|
|
6
|
+
const pending = () => pendingStore
|
|
7
|
+
? [...store.getSnapshot().values()]
|
|
8
|
+
: [...store.getSnapshot().values()].map(row => row.pendingInteraction).filter(Boolean)
|
|
7
9
|
const publicValue = value => {
|
|
8
10
|
if (!firstSeen.has(value.key)) firstSeen.set(value.key, Date.now() / 1000)
|
|
9
11
|
if (firstSeen.size > 512) firstSeen.delete(firstSeen.keys().next().value)
|
|
@@ -38,7 +40,6 @@ export function nativeInteractions(ctx) {
|
|
|
38
40
|
return { ok: true, interaction_id: value.key }
|
|
39
41
|
}
|
|
40
42
|
execute.snapshot = snapshot
|
|
41
|
-
const store = ctx.uiSession.sessionStatus ?? ctx.uiSession.pendingInteractions
|
|
42
43
|
execute.supportsSync = typeof store.subscribe === 'function'
|
|
43
44
|
execute.subscribe = fn => store.subscribe?.(fn) ?? (() => {})
|
|
44
45
|
return execute
|
package/src/client/notice.mjs
CHANGED
|
@@ -26,30 +26,51 @@ export function mountNotice(anchor) {
|
|
|
26
26
|
const observer = new ResizeObserver(position)
|
|
27
27
|
observer.observe(panel)
|
|
28
28
|
return {
|
|
29
|
-
show(text, {upgrade = false, releaseNotes} = {}) {
|
|
29
|
+
show(text, {upgrade = false, releaseNotes, releases = [], currentVersion, targetVersion} = {}) {
|
|
30
30
|
if (disposed) return
|
|
31
31
|
clearTimeout(timer); panel.textContent = text; panel.hidden = false
|
|
32
32
|
if (upgrade) {
|
|
33
33
|
panel.textContent = ''
|
|
34
|
-
const heading=document.createElement('strong');heading.textContent='
|
|
34
|
+
const heading=document.createElement('strong');heading.textContent='duet 有新版本';heading.style.cssText='display:block;font-size:16px;margin-bottom:8px'
|
|
35
35
|
const message=document.createElement('p');message.textContent=text;message.style.cssText='margin:0 0 12px'
|
|
36
36
|
panel.append(heading,message)
|
|
37
|
-
if(
|
|
37
|
+
if(currentVersion&&targetVersion){
|
|
38
|
+
const range=document.createElement('div');range.dataset.duetVersionRange=''
|
|
39
|
+
range.style.cssText='display:flex;align-items:center;gap:10px;margin:0 0 14px;font-size:12px'
|
|
40
|
+
for(const [index,text] of [`v${currentVersion}`,'→',`v${targetVersion}`].entries()){
|
|
41
|
+
const badge=document.createElement('span');badge.textContent=text
|
|
42
|
+
if(index!==1)badge.style.cssText=`padding:3px 10px;border-radius:20px;background:${index===2?'#d1eaff':'#ffffffa8'};font-weight:${index===2?600:400}`
|
|
43
|
+
range.append(badge)
|
|
44
|
+
}
|
|
45
|
+
panel.append(range)
|
|
46
|
+
}
|
|
47
|
+
if(releases.length){
|
|
48
|
+
const label=document.createElement('strong');label.textContent=`更新内容 · ${currentVersion} → ${targetVersion}`;label.style.fontSize='12px'
|
|
49
|
+
const list=document.createElement('div');list.dataset.duetReleaseHistory=''
|
|
50
|
+
for(const release of releases){
|
|
51
|
+
const section=document.createElement('section'),version=document.createElement('strong'),notes=document.createElement('p')
|
|
52
|
+
version.textContent=`v${release.version}`;notes.textContent=release.notes
|
|
53
|
+
notes.style.cssText='white-space:pre-wrap;margin:4px 0 0'
|
|
54
|
+
section.style.cssText='margin:8px 0;padding:10px 12px;border-radius:8px;background:#ffffffa8'
|
|
55
|
+
section.append(version,notes);list.append(section)
|
|
56
|
+
}
|
|
57
|
+
panel.append(label,list)
|
|
58
|
+
}else if(typeof releaseNotes==='string' && releaseNotes.trim()){
|
|
38
59
|
const label=document.createElement('strong');label.textContent='更新内容';label.style.fontSize='12px'
|
|
39
60
|
const notes=document.createElement('p');notes.dataset.duetReleaseNotes='';notes.textContent=releaseNotes.slice(0,1000).trim()
|
|
40
61
|
notes.style.cssText='white-space:pre-wrap;margin:6px 0 14px;padding:10px 12px;border-radius:8px;background:#ffffffa8'
|
|
41
62
|
panel.append(label,notes)
|
|
42
63
|
}
|
|
43
64
|
const help = document.createElement('details'), title = document.createElement('summary')
|
|
65
|
+
help.open=true
|
|
44
66
|
help.style.cssText='border-top:1px solid #a5d8f4;padding-top:10px'
|
|
45
67
|
title.style.cssText='cursor:pointer;font-weight:600'
|
|
46
68
|
title.textContent = '如何升级'; help.append(title)
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
help.append(before, command, after); panel.append(help)
|
|
69
|
+
const steps=document.createElement('ol');steps.style.cssText='margin:10px 0;padding-left:20px'
|
|
70
|
+
for(const text of ['在 DSH 的「插件」页面卸载 duet。','点击「添加插件」,输入 dsh-duet 并安装。','安装完成后,如果插件不可用,可能需要重启 DSH 哦']){
|
|
71
|
+
const step=document.createElement('li');step.textContent=text;step.style.margin='6px 0';steps.append(step)
|
|
72
|
+
}
|
|
73
|
+
help.append(steps); panel.append(help)
|
|
53
74
|
help.addEventListener('toggle', position)
|
|
54
75
|
const actions=document.createElement('div');actions.style.cssText='display:flex;justify-content:flex-end;margin-top:14px'
|
|
55
76
|
const close = document.createElement('button'); close.type = 'button'; close.textContent = '知道了'; close.onclick = hide
|
package/src/client/settings.html
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
input[type=checkbox]::after{content:'';position:absolute;width:14px;height:14px;top:2px;left:2px;border-radius:50%;background:#e5eee8;transition:transform .15s}
|
|
36
36
|
input[type=checkbox]:checked{background:#80b294;border-color:#80b294}input[type=checkbox]:checked::after{transform:translateX(14px)}
|
|
37
37
|
.row{display:flex;gap:10px;margin-top:10px;align-items:center}.row input{flex:1;min-width:0}.row button{flex-shrink:0}
|
|
38
|
+
#debugTools .row{flex-wrap:wrap}
|
|
38
39
|
.connection{display:flex;align-items:center;gap:10px;margin:0 0 18px;padding:14px 18px;border:1px solid var(--line);border-radius:14px;background:#142119}
|
|
39
40
|
.connection-title{font-size:13px;font-weight:600}.connection-detail{font-size:12px;color:var(--muted);overflow-wrap:anywhere}
|
|
40
41
|
.cards{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:18px 24px;margin:16px 0 20px}
|
|
@@ -252,7 +253,7 @@
|
|
|
252
253
|
if(enabled||await avatarConfirm.ask())avatarSave({enabled});
|
|
253
254
|
};
|
|
254
255
|
window.addEventListener('pagehide',()=>{avatarConfirm.dispose();avatarChannel?.close();window.removeEventListener('storage',avatarStorage);},{once:true});
|
|
255
|
-
import { identityFetch } from '/duet/assets/client/identity.mjs?v=0.3.
|
|
256
|
+
import { identityFetch } from '/duet/assets/client/identity.mjs?v=0.3.3';
|
|
256
257
|
import { mountWorkMode, workModeOnboarding } from '/duet/assets/client/work-mode.mjs';
|
|
257
258
|
const modePreview=workModeOnboarding(undefined,{preview:true});
|
|
258
259
|
let previewRequested=new URL(location.href).searchParams.get('preview')==='work-mode';
|
|
@@ -502,7 +503,7 @@
|
|
|
502
503
|
}
|
|
503
504
|
$('openTutorial').onclick = async () => {
|
|
504
505
|
try {
|
|
505
|
-
const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.3.
|
|
506
|
+
const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.3.3');
|
|
506
507
|
requestTutorial(localStorage);
|
|
507
508
|
$('tutorialStatus').textContent = '请回到 DSH 页面继续教学。';
|
|
508
509
|
} catch { $('tutorialStatus').textContent = '暂时无法打开教学,请允许浏览器存储后重试。'; }
|
|
@@ -511,11 +512,11 @@
|
|
|
511
512
|
setInterval(() => { loadDuetConfig().catch(showConnectionUnavailable); }, 2000);
|
|
512
513
|
void loadNotices();
|
|
513
514
|
setInterval(loadNotices, 60000);
|
|
514
|
-
import('/duet/assets/client/shortcuts.mjs?v=0.3.
|
|
515
|
+
import('/duet/assets/client/shortcuts.mjs?v=0.3.3').then(({mountShortcutSettings}) => {
|
|
515
516
|
const dispose = mountShortcutSettings({speaker:$('speakerShortcut'),mic:$('micShortcut'),clearSpeaker:$('clearSpeakerShortcut'),clearMic:$('clearMicShortcut'),status:$('shortcutStatus')});
|
|
516
517
|
window.addEventListener('pagehide', e => {if(!e.persisted)dispose()}, {once:true});
|
|
517
518
|
}).catch(() => { $('shortcutStatus').textContent = '暂时无法加载快捷键设置,请刷新重试。'; });
|
|
518
|
-
import('/duet/assets/client/microphone.mjs?v=0.3.
|
|
519
|
+
import('/duet/assets/client/microphone.mjs?v=0.3.3').then(({mountMicrophoneSettings}) => {
|
|
519
520
|
const dispose = mountMicrophoneSettings({select:$('microphoneDevice'),refresh:$('refreshMicrophones'),status:$('microphoneStatus')});
|
|
520
521
|
window.addEventListener('pagehide', dispose, {once:true});
|
|
521
522
|
}).catch(() => { $('microphoneStatus').textContent = '暂时无法加载麦克风设置,请刷新重试。'; });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Resolve the sidebar without depending on DSH's generated CSS class names. */
|
|
2
|
+
export function sidebarElement(controls) {
|
|
3
|
+
if (!controls?.isConnected) return null
|
|
4
|
+
let fallback=null
|
|
5
|
+
for(let node=controls;node&&node!==document.body;node=node.parentElement){
|
|
6
|
+
const r=node.getBoundingClientRect()
|
|
7
|
+
if(!r.width||!r.height||r.width>Math.min(600,innerWidth*.75))continue
|
|
8
|
+
fallback=node
|
|
9
|
+
if(node.matches('aside,[role="complementary"]')||node.querySelector('[data-slot="sidebar.workspaces"]'))return node
|
|
10
|
+
}
|
|
11
|
+
return fallback
|
|
12
|
+
}
|
|
13
|
+
export const sidebarBounds=controls=>sidebarElement(controls)?.getBoundingClientRect()??null
|
|
14
|
+
|
|
15
|
+
/** A mask fades pixels; clipping also prevents the hidden area from taking clicks. */
|
|
16
|
+
export function clipToSidebar(node,bounds){
|
|
17
|
+
node.style.clipPath='';node.style.maskImage='';node.style.webkitMaskImage=''
|
|
18
|
+
if(!bounds)return
|
|
19
|
+
const r=node.getBoundingClientRect(),right=Math.max(0,r.right-bounds.right),left=Math.max(0,bounds.left-r.left)
|
|
20
|
+
node.style.clipPath=`inset(-4px ${right}px -4px ${left}px)`
|
|
21
|
+
if(right>0){
|
|
22
|
+
const end=Math.max(0,r.width-right),start=Math.max(left,end-24)
|
|
23
|
+
const mask=`linear-gradient(to right,#000 ${start}px,transparent ${end}px)`
|
|
24
|
+
node.style.maskImage=mask;node.style.webkitMaskImage=mask
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** DSH browser services plus existing voice connection; never opens a microphone. */
|
|
2
|
-
import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.3.
|
|
3
|
-
import { focusedSession } from './composer.mjs?v=0.3.
|
|
4
|
-
import { sessionCreationPayload, workspaceIssue } from './workspaces.mjs?v=0.3.
|
|
5
|
-
import { startComposerBridge } from './composer-bridge.mjs?v=0.3.
|
|
6
|
-
import { identityFetch } from './identity.mjs?v=0.3.
|
|
2
|
+
import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.3.3'
|
|
3
|
+
import { focusedSession } from './composer.mjs?v=0.3.3'
|
|
4
|
+
import { sessionCreationPayload, workspaceIssue } from './workspaces.mjs?v=0.3.3'
|
|
5
|
+
import { startComposerBridge } from './composer-bridge.mjs?v=0.3.3'
|
|
6
|
+
import { identityFetch } from './identity.mjs?v=0.3.3'
|
|
7
7
|
export function tutorialAdapter(ctx, state, audio, pollReady, startBridge = startComposerBridge) {
|
|
8
8
|
let narration
|
|
9
9
|
const completed = new Map()
|
package/src/client/tutorial.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Opt-in walkthrough. All writes are limited to sessions created by this run. */
|
|
2
|
-
import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.3.
|
|
2
|
+
import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.3.3'
|
|
3
3
|
export const TUTORIAL_KEY = 'dsh-duplex-tutorial-v1'
|
|
4
4
|
export const QUESTION = '什么是语音交互?请用一句话简单解释,不使用工具。'
|
|
5
5
|
export const INPUT = '用一句话介绍语音助手。'
|
package/src/client/work-mode.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WORK_MODES, AGENT_PERMISSION_TEXT, AGENT_WORKSPACE_NOTICE, workModeIssue, TASK_STATES, taskModelLabel } from '../shared/work-mode.mjs'
|
|
2
|
-
import { identityFetch } from './identity.mjs?v=0.3.
|
|
2
|
+
import { identityFetch } from './identity.mjs?v=0.3.3'
|
|
3
3
|
|
|
4
4
|
const styles = `
|
|
5
5
|
.dt-work{--ink:light-dark(#20392d,#e3eee7);--muted:light-dark(#53695c,#a7b9ae);--edge:light-dark(#cbd7cf,#3b4a40);--surface:light-dark(#fff,#191f1d);--tint:light-dark(#eef7f0,#203329);--accent:light-dark(#236548,#b3e9cb);color:var(--ink);font:normal 14px/1.5 system-ui,sans-serif;text-align:start;display:grid;gap:16px;container-type:inline-size}
|
|
@@ -74,7 +74,12 @@ export class AgentConnection {
|
|
|
74
74
|
const rows=this.source.taskRows().map(row=>{
|
|
75
75
|
// Local notification identity; never send native ticket metadata upstream.
|
|
76
76
|
const ticket=this.source.runtime?.store?.tickets?.get?.(row.session_id?.replace(/^worker-/,''))
|
|
77
|
-
|
|
77
|
+
const run=ticket?.assignments?.at(-1)
|
|
78
|
+
// Actual executor progress, not model selection metadata. Only project
|
|
79
|
+
// the latest assignment: an older run must not look like current work.
|
|
80
|
+
const progress=ticket?.attention?.question || run?.report?.summary || ticket?.ended?.reason
|
|
81
|
+
return {...row,...(ticket?.attention?.id?{attention_id:ticket.attention.id}:{}),
|
|
82
|
+
...(typeof progress==='string'&&progress.trim()?{progress:progress.slice(0,4000)}:{})}
|
|
78
83
|
})
|
|
79
84
|
const key=r=>r.task_id+':'+r.run_id
|
|
80
85
|
for(const r of rows)if(r.run_id && !r.finished_at && this.previousFinished?.has(key(r)))
|
package/src/host/assets.mjs
CHANGED
|
@@ -26,6 +26,7 @@ const modules = {
|
|
|
26
26
|
avatar_menu: 'shared/avatar-menu', avatar_menu_ui: 'shared/avatar-menu-ui',
|
|
27
27
|
avatar_tasks: 'client/avatar-tasks',
|
|
28
28
|
agent_tasks: 'client/agent-tasks',
|
|
29
|
+
sidebar_layout: 'client/sidebar-layout',
|
|
29
30
|
agent_entry: 'client/agent-entry',
|
|
30
31
|
agent_tool_views: 'client/agent-tool-views',
|
|
31
32
|
avatar_surface: 'shared/avatar-surface', avatar_surfaces: 'client/avatar-surfaces',
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** DSH 0.2.3 admits routes before dispatch; older hosts validate the request here. */
|
|
2
|
+
export function requestRejection(ctx, req, peer) {
|
|
3
|
+
if (peer) return peer.principal?.kind === 'owner' && !peer.signal?.aborted ? null : 403
|
|
4
|
+
const connection = ctx.connection
|
|
5
|
+
if (typeof connection?.admit === 'function') {
|
|
6
|
+
const admission = connection.admit(req)
|
|
7
|
+
if (admission?.rejection) return admission.rejection
|
|
8
|
+
const admitted = admission?.peer
|
|
9
|
+
return admitted?.principal?.kind === 'owner' && !admitted.signal?.aborted ? null : 403
|
|
10
|
+
}
|
|
11
|
+
if (typeof connection?.requestRejection === 'function') return connection.requestRejection(req)
|
|
12
|
+
return 503
|
|
13
|
+
}
|
package/src/host/avatar.mjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { requestRejection } from './auth.mjs'
|
|
1
2
|
import { WebSocketServer } from 'ws'
|
|
2
3
|
import { spawn } from 'node:child_process'
|
|
3
4
|
import { accessSync, constants } from 'node:fs'
|
|
4
5
|
import { fileURLToPath } from 'node:url'
|
|
5
6
|
import { randomBytes, timingSafeEqual } from 'node:crypto'
|
|
7
|
+
import {mkdtempSync,rm} from 'node:fs'
|
|
8
|
+
import {tmpdir} from 'node:os'
|
|
9
|
+
import {join} from 'node:path'
|
|
6
10
|
import { AVATAR_SIZES, avatarSize, avatarFrame, avatarInputEffect, AvatarHeartbeat } from '../shared/avatar.mjs'
|
|
7
11
|
import { AVATAR_UI_PROTOCOL, avatarSurface, avatarSurfaceAction } from '../shared/avatar-surface.mjs'
|
|
8
12
|
import {verifyDesktopAssets,desktopAssetsPath} from './avatar-assets.mjs'
|
|
@@ -20,7 +24,7 @@ export function sameSecret(a, b) {
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
/** Private, loopback-only IPC. The companion never receives DSH/server credentials. */
|
|
23
|
-
export async function launchAvatar({onCommand,onExit,signal,size,ownerKind='browser'}, {spawnImpl=spawn, binary=avatarBinary(), env=process.env, assets=desktopAssetsPath}={}) {
|
|
27
|
+
export async function launchAvatar({onCommand,onExit,signal,size,ownerKind='browser'}, {spawnImpl=spawn, binary=avatarBinary(), env=process.env, assets=desktopAssetsPath,platform=process.platform}={}) {
|
|
24
28
|
if(!binary)throw Error('desktop_platform_unsupported')
|
|
25
29
|
if(process.platform==='linux'&&!env.DISPLAY&&!env.WAYLAND_DISPLAY)throw Error('desktop_display_unavailable')
|
|
26
30
|
try{accessSync(binary,constants.X_OK)}catch{throw Error('desktop_helper_missing')}
|
|
@@ -29,14 +33,21 @@ export async function launchAvatar({onCommand,onExit,signal,size,ownerKind='brow
|
|
|
29
33
|
const ipc=new WebSocketServer({host:'127.0.0.1',port:0,maxPayload:2048,
|
|
30
34
|
verifyClient:({req})=>sameSecret(req.headers['sec-websocket-protocol'],`duet-avatar-${token}`)})
|
|
31
35
|
await new Promise((resolve,reject)=>{ipc.once('listening',resolve);ipc.once('error',reject)})
|
|
32
|
-
let child,peer,closed=false,ready=false,timeout,killTimer,abort
|
|
36
|
+
let child,peer,closed=false,ready=false,timeout,killTimer,abort,userData,visibility=null
|
|
37
|
+
const isRunning=()=>child&&child.exitCode===null&&child.signalCode==null
|
|
38
|
+
const cleanupData=()=>{if(userData){const path=userData;userData=null;rm(path,{recursive:true,force:true,maxRetries:10,retryDelay:200},()=>{})}}
|
|
39
|
+
const closeIPC=()=>{for(const ws of ipc.clients)ws.terminate();ipc.close()}
|
|
33
40
|
const stop=()=>{
|
|
34
41
|
if(closed)return
|
|
35
42
|
closed=true;clearTimeout(timeout)
|
|
36
43
|
signal?.removeEventListener('abort',abort)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
if(isRunning()){
|
|
45
|
+
// Let the renderer close WebView2 normally before forcing the native tree down.
|
|
46
|
+
// The Windows helper owns a kill-on-close Job Object for its descendants.
|
|
47
|
+
killTimer=setTimeout(()=>{closeIPC();if(isRunning())child.kill('SIGKILL')},2000);killTimer.unref()
|
|
48
|
+
if(peer?.readyState===1){try{peer.send(JSON.stringify({type:'shutdown'}))}catch{closeIPC();child.kill()}}
|
|
49
|
+
else {closeIPC();if(!peer)child.kill()}
|
|
50
|
+
}else {closeIPC();cleanupData()}
|
|
40
51
|
}
|
|
41
52
|
const initialized=new Promise((resolve,reject)=>{
|
|
42
53
|
const fail=code=>{if(closed)return;stop();if(!ready)reject(Error(code));else onExit(code)}
|
|
@@ -47,9 +58,15 @@ export async function launchAvatar({onCommand,onExit,signal,size,ownerKind='brow
|
|
|
47
58
|
if(peer){ws.close(1008);return}peer=ws
|
|
48
59
|
ws.on('error',()=>{})
|
|
49
60
|
ws.on('message',raw=>{
|
|
61
|
+
if(closed)return
|
|
50
62
|
try{
|
|
51
63
|
const msg=JSON.parse(raw)
|
|
52
|
-
if(msg.type==='ready'&&!ready){
|
|
64
|
+
if(msg.type==='ready'&&!ready){
|
|
65
|
+
if(msg.protocol!==AVATAR_UI_PROTOCOL){fail('desktop_helper_upgrade_required');return}
|
|
66
|
+
if(typeof msg.window_visible==='boolean')visibility={visible:msg.window_visible,fullscreenSuppressed:msg.fullscreen_suppressed===true}
|
|
67
|
+
if(visibility&&!visibility.visible&&!visibility.fullscreenSuppressed){fail('desktop_renderer_failed');return}
|
|
68
|
+
ready=true;clearTimeout(timeout);resolve()
|
|
69
|
+
}
|
|
53
70
|
else if(ready&&msg.type==='surface_action')onCommand(avatarSurfaceAction(msg))
|
|
54
71
|
else if(ready&&msg.type==='menu_action')onCommand(avatarMenuAction(msg))
|
|
55
72
|
else if(ready&&msg.type==='avatar_geometry')onCommand({type:'avatar_geometry',position:avatarGeometry(msg.position)})
|
|
@@ -66,26 +83,28 @@ export async function launchAvatar({onCommand,onExit,signal,size,ownerKind='brow
|
|
|
66
83
|
try{
|
|
67
84
|
// No shell, user-supplied executable, detached daemon, inherited credentials, or CLI token.
|
|
68
85
|
const safeEnv=Object.fromEntries(['PATH','HOME','USERPROFILE','LOCALAPPDATA','APPDATA','SYSTEMROOT','WINDIR','TEMP','TMP','TMPDIR','DISPLAY','WAYLAND_DISPLAY','XDG_RUNTIME_DIR','DBUS_SESSION_BUS_ADDRESS','LANG','LC_ALL'].filter(k=>env[k]).map(k=>[k,env[k]]))
|
|
69
|
-
|
|
86
|
+
if(platform==='win32')userData=mkdtempSync(join(tmpdir(),'dsh-duet-webview-'))
|
|
87
|
+
child=spawnImpl(binary,[],{stdio:'ignore',windowsHide:false,env:{...safeEnv,
|
|
88
|
+
...(userData?{DUET_AVATAR_USER_DATA:userData}:{}),
|
|
70
89
|
DUET_AVATAR_ASSETS:assetsPath,DUET_AVATAR_IPC:`ws://127.0.0.1:${ipc.address().port}`,DUET_AVATAR_TOKEN:token,DUET_AVATAR_SIZE:avatarSize(size),
|
|
71
90
|
DUET_AVATAR_OWNER_KIND:['desktop','chrome','edge','firefox','safari','browser'].includes(ownerKind)?ownerKind:'browser'}})
|
|
72
|
-
child.once('error',()=>fail('desktop_launch_failed'))
|
|
73
|
-
child.once('exit',code=>{clearTimeout(killTimer);fail(code===78?'desktop_webview2_missing':'desktop_closed')})
|
|
91
|
+
child.once('error',()=>{cleanupData();fail('desktop_launch_failed')})
|
|
92
|
+
child.once('exit',code=>{clearTimeout(killTimer);closeIPC();cleanupData();fail(code===78?'desktop_webview2_missing':'desktop_closed')})
|
|
74
93
|
timeout=setTimeout(()=>fail('desktop_start_timeout'),20000);timeout.unref()
|
|
75
|
-
}catch{fail('desktop_launch_failed')}
|
|
94
|
+
}catch{cleanupData();fail('desktop_launch_failed')}
|
|
76
95
|
})
|
|
77
96
|
await initialized
|
|
78
|
-
return {close:stop,send(frame){if(peer?.readyState===1&&peer.bufferedAmount<16000)peer.send(JSON.stringify(frame))}}
|
|
97
|
+
return {visibility,close:stop,send(frame){if(peer?.readyState===1&&peer.bufferedAmount<16000)peer.send(JSON.stringify(frame))}}
|
|
79
98
|
}
|
|
80
99
|
|
|
81
100
|
/** Exactly one owning DSH page per Host; other pages cannot drive its companion. */
|
|
82
101
|
export function registerAvatarHost(ctx, {launch=launchAvatar}={}) {
|
|
83
102
|
const server=new WebSocketServer({noServer:true,maxPayload:65536}),clients=new Set()
|
|
84
103
|
let owner=null,closed=false
|
|
85
|
-
const unregister=ctx.webServer.registerUpgrade({path:'/duet/avatar/ws',handler(req,socket,head){
|
|
104
|
+
const unregister=ctx.webServer.registerUpgrade({path:'/duet/avatar/ws',handler(req,socket,head,peer){
|
|
86
105
|
let allowed=!req.headers.origin
|
|
87
106
|
try{if(req.headers.origin)allowed=new URL(req.headers.origin).host===req.headers.host}catch{}
|
|
88
|
-
if(closed||!allowed||
|
|
107
|
+
if(closed||!allowed||requestRejection(ctx,req,peer)||clients.size>=8){socket.end('HTTP/1.1 403 Forbidden\r\nConnection: close\r\n\r\n');return}
|
|
89
108
|
server.handleUpgrade(req,socket,head,ws=>{
|
|
90
109
|
clients.add(ws);let helper,starting=false,ended=false,frames=0,second=Date.now(),alive=Date.now()
|
|
91
110
|
const lifetime=new AbortController()
|
package/src/host/plugin.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** duet Host entry: session operations, authenticated settings, and client assets. */
|
|
2
2
|
|
|
3
|
+
import { requestRejection } from './auth.mjs'
|
|
3
4
|
import { readFile, mkdir, realpath } from 'node:fs/promises'
|
|
4
5
|
import { homedir } from 'node:os'
|
|
5
6
|
import { join } from 'node:path'
|
|
@@ -583,9 +584,9 @@ export function apply(ctx, options = {}) {
|
|
|
583
584
|
return () => syncFeed.close()
|
|
584
585
|
})
|
|
585
586
|
|
|
586
|
-
const handleApi = async (req, res, pathname) => {
|
|
587
|
+
const handleApi = async (req, res, pathname, peer) => {
|
|
587
588
|
if(pathname===`${ROUTE}/api/voices`){
|
|
588
|
-
const rejection=
|
|
589
|
+
const rejection=requestRejection(ctx, req, peer)
|
|
589
590
|
if(rejection){sendError(res,rejection,'DSH connection required');return}
|
|
590
591
|
try {
|
|
591
592
|
if(req.method==='GET'){sendJson(res,200,await voices.refreshAvailability());return}
|
|
@@ -596,14 +597,14 @@ export function apply(ctx, options = {}) {
|
|
|
596
597
|
return
|
|
597
598
|
}
|
|
598
599
|
if(req.method==='POST'&&pathname===`${ROUTE}/api/avatar/activity`){
|
|
599
|
-
const rejection=
|
|
600
|
+
const rejection=requestRejection(ctx, req, peer)
|
|
600
601
|
if(rejection){sendError(res,rejection,'DSH connection required');return}
|
|
601
602
|
if(!identityWriteAllowed(req)){sendError(res,403,'same-origin activity request required');return}
|
|
602
603
|
try{const value=await readJson(req);if(JSON.stringify(value).length>4096){sendError(res,413,'activity too large');return}sendJson(res,202,await avatarActivity.enqueue(value,feedback.user(req)))}
|
|
603
604
|
catch{sendError(res,400,'invalid_avatar_activity')}return
|
|
604
605
|
}
|
|
605
606
|
if (req.method === 'POST' && pathname === `${ROUTE}/api/duet/nickname`) {
|
|
606
|
-
const rejection =
|
|
607
|
+
const rejection = requestRejection(ctx, req, peer)
|
|
607
608
|
if (rejection) { sendError(res, rejection, '请先打开并登录 DSH 主页面'); return }
|
|
608
609
|
const boundRPC = req.headers['x-duplex-control-client'] === 'realtime-client-rpc-v1' && browserOwner(req)
|
|
609
610
|
if (!identityWriteAllowed(req) && !boundRPC) { sendError(res, 403, 'same-origin nickname request required'); return }
|
|
@@ -623,7 +624,7 @@ export function apply(ctx, options = {}) {
|
|
|
623
624
|
return
|
|
624
625
|
}
|
|
625
626
|
if(req.method==='POST' && pathname===`${ROUTE}/api/feedback`){
|
|
626
|
-
const rejection =
|
|
627
|
+
const rejection = requestRejection(ctx, req, peer)
|
|
627
628
|
if(rejection){sendError(res,rejection,'请先打开并登录 DSH 主页面');return}
|
|
628
629
|
if(!identityWriteAllowed(req)){sendError(res,403,'same-origin feedback request required');return}
|
|
629
630
|
try {sendJson(res,201,await feedback.submit(req,await readJson(req)))}
|
|
@@ -636,7 +637,7 @@ export function apply(ctx, options = {}) {
|
|
|
636
637
|
return
|
|
637
638
|
}
|
|
638
639
|
if (req.method === 'POST' && pathname === `${ROUTE}/api/voice/diagnostic`) {
|
|
639
|
-
const rejection =
|
|
640
|
+
const rejection = requestRejection(ctx, req, peer)
|
|
640
641
|
if (rejection) { sendError(res, rejection, 'DSH connection required'); return }
|
|
641
642
|
if (!identityWriteAllowed(req)) { sendError(res, 403, 'same-origin diagnostic request required'); return }
|
|
642
643
|
const body = await readJson(req)
|
|
@@ -653,7 +654,7 @@ export function apply(ctx, options = {}) {
|
|
|
653
654
|
return
|
|
654
655
|
}
|
|
655
656
|
if (req.method === 'POST' && pathname === `${ROUTE}/api/voice/dedicated-workspace`) {
|
|
656
|
-
const rejection=
|
|
657
|
+
const rejection=requestRejection(ctx, req, peer)
|
|
657
658
|
if(rejection || !identityWriteAllowed(req)){sendError(res,rejection||403,'DSH connection required');return}
|
|
658
659
|
if(await workPolicy.get()==='direct_only'){sendError(res,403,'agent_mode_disabled');return}
|
|
659
660
|
try {
|
|
@@ -671,7 +672,7 @@ export function apply(ctx, options = {}) {
|
|
|
671
672
|
return
|
|
672
673
|
}
|
|
673
674
|
if(req.method==='GET' && pathname===`${ROUTE}/api/voice/agent-tasks`){
|
|
674
|
-
const rejection=
|
|
675
|
+
const rejection=requestRejection(ctx, req, peer)
|
|
675
676
|
if(rejection){sendError(res,rejection,'DSH connection required');return}
|
|
676
677
|
const policy=effectiveWorkPolicy(settings.public(),await workPolicy.get())
|
|
677
678
|
if(policy.work_mode!=='agent'||policy.agent_permission_version!==1){sendJson(res,200,{rows:[]});return}
|
|
@@ -1271,7 +1272,7 @@ export function apply(ctx, options = {}) {
|
|
|
1271
1272
|
}
|
|
1272
1273
|
if (req.method === 'GET' && [ `${ROUTE}/api/results`, `${ROUTE}/api/results/wait` ].includes(pathname)) {
|
|
1273
1274
|
if (pathname.endsWith('/wait')) {
|
|
1274
|
-
const rejection =
|
|
1275
|
+
const rejection = requestRejection(ctx, req, peer)
|
|
1275
1276
|
if (rejection) { sendError(res, rejection, '请先打开并登录 DSH 主页面'); return }
|
|
1276
1277
|
}
|
|
1277
1278
|
const url = new URL(req.url || '/', 'http://localhost')
|
|
@@ -1311,16 +1312,18 @@ export function apply(ctx, options = {}) {
|
|
|
1311
1312
|
sendError(res, 404, 'not found')
|
|
1312
1313
|
}
|
|
1313
1314
|
|
|
1314
|
-
const handler = async (req, res) => {
|
|
1315
|
+
const handler = async (req, res, peer) => {
|
|
1315
1316
|
const pathname = new URL(req.url || '/', 'http://localhost').pathname
|
|
1316
1317
|
try {
|
|
1318
|
+
const rejection = requestRejection(ctx, req, peer)
|
|
1319
|
+
if (rejection) { sendError(res, rejection, '请先打开并登录 DSH 主页面'); return }
|
|
1317
1320
|
if ([PAGE_ROUTE, `${PAGE_ROUTE}/`, ROUTE, `${ROUTE}/`, `${ROUTE}/api/voice/config`, `${ROUTE}/api/voice/work-options`, `${ROUTE}/api/voice/service-info`, `${ROUTE}/api/voice/diagnostic`, `${ROUTE}/api/announcements`].includes(pathname)) {
|
|
1318
|
-
const rejection =
|
|
1321
|
+
const rejection = requestRejection(ctx, req, peer)
|
|
1319
1322
|
if (rejection) { sendError(res, rejection, '请先打开并登录 DSH 主页面'); return }
|
|
1320
1323
|
}
|
|
1321
1324
|
const tutorialAudio = pathname.match(/^\/duplex-control\/tutorial-audio\/(modes_broadcast|modes_interaction|broadcast|input|edit|clear|reinput|send|switch)\.wav$/)
|
|
1322
1325
|
if (req.method === 'GET' && tutorialAudio) {
|
|
1323
|
-
const rejection =
|
|
1326
|
+
const rejection = requestRejection(ctx, req, peer)
|
|
1324
1327
|
if (rejection) { sendError(res, rejection, '请先打开并登录 DSH 主页面'); return }
|
|
1325
1328
|
const body = await readFile(new URL(`../../assets/tutorial-audio/${tutorialAudio[1]}.wav`, import.meta.url))
|
|
1326
1329
|
res.writeHead(200, { 'content-type': 'audio/wav', 'cache-control': 'private, max-age=3600', 'content-length': body.length })
|
|
@@ -1353,7 +1356,7 @@ export function apply(ctx, options = {}) {
|
|
|
1353
1356
|
res.end(body)
|
|
1354
1357
|
return
|
|
1355
1358
|
}
|
|
1356
|
-
await handleApi(req, res, pathname)
|
|
1359
|
+
await handleApi(req, res, pathname, peer)
|
|
1357
1360
|
} catch (error) {
|
|
1358
1361
|
audit.event('host.api_error', { method: req.method, path: pathname, message: error.message, stack: error.stack })
|
|
1359
1362
|
const status = Number.isInteger(error?.status) ? error.status : 500
|
|
@@ -1364,6 +1367,6 @@ export function apply(ctx, options = {}) {
|
|
|
1364
1367
|
}
|
|
1365
1368
|
}
|
|
1366
1369
|
|
|
1367
|
-
ctx.effect(() => ctx.webServer.register({ kind: 'prefix', path: ROUTE, handler }))
|
|
1368
|
-
ctx.effect(() => ctx.webServer.register({ kind: 'prefix', path: PAGE_ROUTE, handler }))
|
|
1370
|
+
ctx.effect(() => ctx.webServer.register({ kind: 'prefix', path: ROUTE, auth: 'required', handler }))
|
|
1371
|
+
ctx.effect(() => ctx.webServer.register({ kind: 'prefix', path: PAGE_ROUTE, auth: 'required', handler }))
|
|
1369
1372
|
}
|
package/src/host/proxy.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { requestRejection } from './auth.mjs'
|
|
1
2
|
/** Same-origin voice relay; endpoint and compatibility policy belong to the DSH host. */
|
|
2
3
|
import { createRequire } from 'node:module'
|
|
3
4
|
import { DuetTrace } from './trace.mjs'
|
|
@@ -69,8 +70,8 @@ export function registerDuetProxy(ctx, config = duetConfig(), feedback = null, c
|
|
|
69
70
|
acquireHostDiagnostics(ctx.webServer, config.diagnosticOptions)
|
|
70
71
|
const stop = ctx.webServer.registerUpgrade({
|
|
71
72
|
path: '/duplex-control/voice/ws',
|
|
72
|
-
handler(req, socket, head) {
|
|
73
|
-
const rejection =
|
|
73
|
+
handler(req, socket, head, peer) {
|
|
74
|
+
const rejection = requestRejection(ctx, req, peer)
|
|
74
75
|
if (rejection) { socket.end(`HTTP/1.1 ${rejection} Forbidden\r\nConnection: close\r\n\r\n`); return }
|
|
75
76
|
// No browser-selected target URLs and no cross-origin drive-by microphone sessions.
|
|
76
77
|
const origin = req.headers.origin
|
package/src/host/sync-feed.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { requestRejection } from './auth.mjs'
|
|
1
2
|
import { WebSocketServer } from 'ws'
|
|
2
3
|
|
|
3
4
|
/** Authenticated local event stream. No timers that query DSH state. */
|
|
@@ -6,10 +7,10 @@ export function registerSyncFeed(ctx, { snapshot, touch, commands }) {
|
|
|
6
7
|
const clients = new Set()
|
|
7
8
|
const unregister = ctx.webServer.registerUpgrade({
|
|
8
9
|
path: '/duplex-control/sync/ws',
|
|
9
|
-
handler(req, socket, head) {
|
|
10
|
+
handler(req, socket, head, peer) {
|
|
10
11
|
let allowed = !req.headers.origin
|
|
11
12
|
try { if (req.headers.origin) allowed = new URL(req.headers.origin).host === req.headers.host } catch {}
|
|
12
|
-
if (!allowed ||
|
|
13
|
+
if (!allowed || requestRejection(ctx, req, peer) || clients.size >= 64) {
|
|
13
14
|
socket.end('HTTP/1.1 403 Forbidden\r\nConnection: close\r\n\r\n'); return
|
|
14
15
|
}
|
|
15
16
|
server.handleUpgrade(req, socket, head, ws => {
|