dsh-duet 0.1.5 → 0.1.6
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 +2 -2
- package/src/client/audio.mjs +1 -1
- package/src/client/browser.mjs +24 -22
- package/src/client/composer-bridge.mjs +1 -1
- package/src/client/connection-hint.mjs +1 -1
- package/src/client/entry.js +1 -1
- package/src/client/feedback.mjs +3 -1
- package/src/client/identity.mjs +50 -0
- package/src/client/rpc.mjs +17 -3
- package/src/client/settings.html +39 -42
- package/src/client/tutorial-adapter.mjs +6 -7
- package/src/client/tutorial.mjs +1 -1
- package/src/client/workspaces.mjs +11 -0
- package/src/host/assets.mjs +1 -0
- package/src/host/feedback-files.mjs +14 -7
- package/src/host/plugin.mjs +32 -8
- package/src/host/proxy.mjs +3 -1
- package/src/host/settings.mjs +2 -2
- package/src/shared/identity.mjs +8 -0
- package/src/shared/state.mjs +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-duet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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 && node tests/browser/desktop-settings.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 && node tests/browser/desktop-identity.mjs",
|
|
26
26
|
"test:host": "node tests/host/isolated-host.mjs",
|
|
27
27
|
"prepack": "npm run check"
|
|
28
28
|
},
|
package/src/client/audio.mjs
CHANGED
package/src/client/browser.mjs
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.
|
|
2
|
-
import { DuetAudio } from './audio.mjs?v=0.1.
|
|
3
|
-
import { HarnessRPCExecutor } from './rpc.mjs?v=0.1.
|
|
4
|
-
import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.1.
|
|
5
|
-
import { startComposerBridge } from './composer-bridge.mjs?v=0.1.
|
|
6
|
-
import { mountTutorial } from './tutorial.mjs?v=0.1.
|
|
7
|
-
import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.1.
|
|
8
|
-
import { mountRating } from './feedback.mjs?v=0.1.
|
|
9
|
-
import { createAudioUploadConsent } from './consent.mjs?v=0.1.
|
|
10
|
-
import { bindDuetShortcuts } from './shortcuts.mjs?v=0.1.
|
|
11
|
-
import { nativeInteractions } from './interactions.mjs?v=0.1.
|
|
12
|
-
import { mountConnectionHint } from './connection-hint.mjs?v=0.1.
|
|
13
|
-
import { mountControlsLayout } from './controls-layout.mjs?v=0.1.
|
|
14
|
-
import { mountNotice } from './notice.mjs?v=0.1.
|
|
15
|
-
import { workspaceIssue, requireWorkspace, browserSessionCatalog } from './workspaces.mjs?v=0.1.
|
|
16
|
-
import { voiceSocketUrl, bindSettingsLink } from './transport.mjs?v=0.1.
|
|
1
|
+
import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.6'
|
|
2
|
+
import { DuetAudio } from './audio.mjs?v=0.1.6'
|
|
3
|
+
import { HarnessRPCExecutor, rpcNavigationSession } from './rpc.mjs?v=0.1.6'
|
|
4
|
+
import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.1.6'
|
|
5
|
+
import { startComposerBridge } from './composer-bridge.mjs?v=0.1.6'
|
|
6
|
+
import { mountTutorial } from './tutorial.mjs?v=0.1.6'
|
|
7
|
+
import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.1.6'
|
|
8
|
+
import { mountRating } from './feedback.mjs?v=0.1.6'
|
|
9
|
+
import { createAudioUploadConsent } from './consent.mjs?v=0.1.6'
|
|
10
|
+
import { bindDuetShortcuts } from './shortcuts.mjs?v=0.1.6'
|
|
11
|
+
import { nativeInteractions } from './interactions.mjs?v=0.1.6'
|
|
12
|
+
import { mountConnectionHint } from './connection-hint.mjs?v=0.1.6'
|
|
13
|
+
import { mountControlsLayout } from './controls-layout.mjs?v=0.1.6'
|
|
14
|
+
import { mountNotice } from './notice.mjs?v=0.1.6'
|
|
15
|
+
import { workspaceIssue, requireWorkspace, browserSessionCatalog, sessionCreationPayload } from './workspaces.mjs?v=0.1.6'
|
|
16
|
+
import { voiceSocketUrl, bindSettingsLink } from './transport.mjs?v=0.1.6'
|
|
17
|
+
import { identityFetch, identityVoiceProtocols } from './identity.mjs?v=0.1.6'
|
|
17
18
|
|
|
18
19
|
export function mountDuet(ctx) {
|
|
19
20
|
const pageId = crypto.randomUUID()
|
|
@@ -91,9 +92,9 @@ export function mountDuet(ctx) {
|
|
|
91
92
|
(await interactions(request, signal)) ?? composer.execute(request, signal), rows =>
|
|
92
93
|
browserSessionCatalog(ctx, rows).map(row => ({ ...row, active: row.session_id === focusedSession(ctx) })), {
|
|
93
94
|
id: connectionTraceId,
|
|
95
|
+
creationPayload: payload => sessionCreationPayload(ctx, payload),
|
|
94
96
|
completed: async (request, body, signal) => {
|
|
95
|
-
const id = request
|
|
96
|
-
: request.path.endsWith('/fork') ? body.session?.session_id : null
|
|
97
|
+
const id = rpcNavigationSession(request, body)
|
|
97
98
|
if (id) await openLocalSession(ctx, id, signal)
|
|
98
99
|
},
|
|
99
100
|
})
|
|
@@ -123,17 +124,17 @@ export function mountDuet(ctx) {
|
|
|
123
124
|
}
|
|
124
125
|
const open = async () => {
|
|
125
126
|
if (closed) return
|
|
126
|
-
//
|
|
127
|
+
// Refresh Desktop-compatible feedback before the WS handshake.
|
|
127
128
|
const configTimer = setTimeout(() => opening.abort(Error('voice_start_timeout')), 10000)
|
|
128
129
|
let identity
|
|
129
|
-
try { identity = await
|
|
130
|
+
try { identity = await identityFetch('/duplex-control/api/voice/config', {credentials:'same-origin',cache:'no-store',signal:opening.signal}) }
|
|
130
131
|
finally { clearTimeout(configTimer) }
|
|
131
132
|
if(!identity.ok)throw Error('voice_config_unavailable')
|
|
132
133
|
requireWorkspace(ctx)
|
|
133
134
|
if(closed)return
|
|
134
135
|
if (mode === 'online') stopBridge = startComposerBridge(ctx, connectionTraceId)
|
|
135
136
|
report({ event: 'browser.connection_start', page_binding: 'connection_owner_v1' })
|
|
136
|
-
ws = new WebSocket(voiceSocketUrl({ mode, plugin_version: PLUGIN_VERSION, client_trace_id: connectionTraceId, page_id: pageId }))
|
|
137
|
+
ws = new WebSocket(voiceSocketUrl({ mode, plugin_version: PLUGIN_VERSION, client_trace_id: connectionTraceId, page_id: pageId }), identityVoiceProtocols())
|
|
137
138
|
ws.onopen = () => {
|
|
138
139
|
send({ type: 'session.update' })
|
|
139
140
|
if (mode === 'online') stopComposer = observeComposer(ctx, composer, send)
|
|
@@ -302,7 +303,8 @@ export function mountDuet(ctx) {
|
|
|
302
303
|
|
|
303
304
|
const api = async (path, signal) => {
|
|
304
305
|
const response = await fetch(`/duplex-control/api/${path}`, { cache: 'no-store',
|
|
305
|
-
signal, headers: { 'X-Duet-Native-Interactions': '1'
|
|
306
|
+
signal, headers: { 'X-Duet-Native-Interactions': '1',
|
|
307
|
+
...(path === 'sessions' ? { 'X-Duet-Catalog-Scope': 'page' } : {}) } })
|
|
306
308
|
if (!response.ok) throw Object.assign(new Error('harness_unavailable'), {status:response.status})
|
|
307
309
|
return response.json()
|
|
308
310
|
}
|
|
@@ -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.
|
|
2
|
+
import { focusedSession as currentSession } from './composer.mjs?v=0.1.6'
|
|
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.
|
|
2
|
+
import {normalizeGuidance} from '../shared/connection-guidance.mjs?v=0.1.6'
|
|
3
3
|
export function mountConnectionHint(controls, { duration = 8000, onShown = ()=>{} } = {}) {
|
|
4
4
|
const hint = document.createElement('div')
|
|
5
5
|
hint.dataset.duetConnectionHint = ''
|
package/src/client/entry.js
CHANGED
|
@@ -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.
|
|
14
|
+
import('/duet/assets/client/browser.mjs?v=0.1.6').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?.() }
|
package/src/client/feedback.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** Optional, explicit rating; never opens voice or submits without a user click. */
|
|
2
|
+
import { identityFetch } from './identity.mjs?v=0.1.6'
|
|
3
|
+
|
|
2
4
|
export function mountRating(anchor, sessionTicket) {
|
|
3
5
|
if(!sessionTicket)return null
|
|
4
6
|
const panel=document.createElement('section')
|
|
@@ -34,7 +36,7 @@ export function mountRating(anchor, sessionTicket) {
|
|
|
34
36
|
requestController=new AbortController()
|
|
35
37
|
requestTimeout=setTimeout(()=>requestController.abort(),15000)
|
|
36
38
|
try {
|
|
37
|
-
const r=await
|
|
39
|
+
const r=await identityFetch('/duplex-control/api/feedback',{method:'POST',credentials:'same-origin',
|
|
38
40
|
headers:{'Content-Type':'application/json','X-Duplex-Settings':'1'},signal:requestController.signal,
|
|
39
41
|
body:JSON.stringify({kind:'rating',request_id:requestId,session_ticket:sessionTicket,rating})})
|
|
40
42
|
const result=await r.json()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { IDENTITY_HEADER, IDENTITY_TRANSPORT_HEADER, IDENTITY_TRANSPORT, IDENTITY_STORAGE,
|
|
2
|
+
VOICE_PROTOCOL, IDENTITY_PROTOCOL_PREFIX, validIdentityToken } from '../shared/identity.mjs?v=0.1.6'
|
|
3
|
+
|
|
4
|
+
/** Desktop strips plugin cookies. Keep the Host-signed value in its origin storage. */
|
|
5
|
+
export function createIdentityClient(globals = globalThis) {
|
|
6
|
+
const desktop = () => globals.location?.protocol === 'dsh-app:'
|
|
7
|
+
const read = () => {
|
|
8
|
+
const token = globals.localStorage.getItem(IDENTITY_STORAGE)
|
|
9
|
+
return validIdentityToken(token) ? token : null
|
|
10
|
+
}
|
|
11
|
+
async function fetchIdentity(path, options = {}) {
|
|
12
|
+
if (!desktop()) return globals.fetch(path, options)
|
|
13
|
+
if (!['/duplex-control/api/voice/config', '/duplex-control/api/feedback'].includes(path)) {
|
|
14
|
+
return globals.fetch(path, options)
|
|
15
|
+
}
|
|
16
|
+
const config = path.endsWith('/voice/config') && (!options.method || options.method === 'GET')
|
|
17
|
+
const request = async () => {
|
|
18
|
+
const headers = new Headers(options.headers)
|
|
19
|
+
const token = read()
|
|
20
|
+
if (token) headers.set(IDENTITY_HEADER, token)
|
|
21
|
+
headers.set(IDENTITY_TRANSPORT_HEADER, IDENTITY_TRANSPORT)
|
|
22
|
+
const response = await globals.fetch(path, {...options, headers, credentials:'same-origin', cache:'no-store'})
|
|
23
|
+
if (config && response.ok) {
|
|
24
|
+
const payload = await response.clone().json()
|
|
25
|
+
if (payload.feedback_enabled) {
|
|
26
|
+
if (!validIdentityToken(payload.feedback_identity)) throw Error('feedback_identity_unavailable')
|
|
27
|
+
globals.localStorage.setItem(IDENTITY_STORAGE, payload.feedback_identity)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return response
|
|
31
|
+
}
|
|
32
|
+
// Re-read storage inside the shared lock: concurrent page/iframe bootstrap
|
|
33
|
+
// must reuse the first issued identity instead of overwriting each other.
|
|
34
|
+
if (config) {
|
|
35
|
+
if (!globals.navigator?.locks) throw Error('feedback_identity_lock_unavailable')
|
|
36
|
+
return globals.navigator.locks.request(IDENTITY_STORAGE, {signal:options.signal}, request)
|
|
37
|
+
}
|
|
38
|
+
return request()
|
|
39
|
+
}
|
|
40
|
+
function voiceProtocols() {
|
|
41
|
+
if (!desktop()) return []
|
|
42
|
+
const token = read()
|
|
43
|
+
return token ? [VOICE_PROTOCOL, IDENTITY_PROTOCOL_PREFIX + token] : []
|
|
44
|
+
}
|
|
45
|
+
return {fetch:fetchIdentity, voiceProtocols}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const client = createIdentityClient()
|
|
49
|
+
export const identityFetch = client.fetch
|
|
50
|
+
export const identityVoiceProtocols = client.voiceProtocols
|
package/src/client/rpc.mjs
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
import { orderSessionCatalog, readWorkspaceView } from '../shared/catalog.mjs'
|
|
3
3
|
const MAX_BYTES = 256_000
|
|
4
4
|
const READ = /^\/api\/(?:health|sessions|jobs|results|interactions|composer\/focused|sessions\/[A-Za-z0-9_-]+\/composer)$/
|
|
5
|
-
const WRITE = /^\/api\/(?:sessions\/[A-Za-z0-9_-]+\/(?:composer\/submit|activate|rename|fork)|interactions\/(?:(?:question|approval)(?::|%3[Aa]))?[A-Za-z0-9_-]+\/respond)$/
|
|
5
|
+
const WRITE = /^\/api\/(?:sessions|sessions\/[A-Za-z0-9_-]+\/(?:composer\/submit|activate|rename|fork)|interactions\/(?:(?:question|approval)(?::|%3[Aa]))?[A-Za-z0-9_-]+\/respond)$/
|
|
6
|
+
|
|
7
|
+
// Navigate only the connection-owning page after a successful mutation.
|
|
8
|
+
export function rpcNavigationSession(request, body) {
|
|
9
|
+
if (request.method !== 'POST') return null
|
|
10
|
+
if (/^\/api\/sessions\/[A-Za-z0-9_-]+\/activate$/.test(request.path)) return body.active_session_id
|
|
11
|
+
if (request.path === '/api/sessions' || /^\/api\/sessions\/[A-Za-z0-9_-]+\/fork$/.test(request.path)) return body.session?.session_id
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
6
14
|
|
|
7
15
|
export function validateRPC(request) {
|
|
8
16
|
if (request.type !== 'harness.rpc.request' || !/^[a-f0-9]{32}$/.test(request.request_id || '')
|
|
@@ -63,6 +71,11 @@ export class HarnessRPCExecutor {
|
|
|
63
71
|
const timer = setTimeout(() => controller.abort(), 12_000)
|
|
64
72
|
const envelope = { type: 'harness.rpc.response', connection_id: request.connection_id, request_id: request.request_id }
|
|
65
73
|
try {
|
|
74
|
+
let payload = request.payload ?? {}
|
|
75
|
+
if (request.method === 'POST' && request.path === '/api/sessions' && this.binding.creationPayload) {
|
|
76
|
+
try { payload = this.binding.creationPayload(payload) }
|
|
77
|
+
catch (error) { return { ...envelope, status: 409, body: { error_code: error.code || error.message || 'workspace_selection_required' } } }
|
|
78
|
+
}
|
|
66
79
|
if (this.localComposer) {
|
|
67
80
|
try {
|
|
68
81
|
const body = await this.localComposer(request, controller.signal)
|
|
@@ -78,7 +91,7 @@ export class HarnessRPCExecutor {
|
|
|
78
91
|
headers: { 'Content-Type': 'application/json', 'X-Duplex-Control-Client': 'realtime-client-rpc-v1',
|
|
79
92
|
'X-Duet-Native-Interactions': '1',
|
|
80
93
|
...(this.binding.id ? { 'X-Duet-Browser-Client': this.binding.id } : {}) },
|
|
81
|
-
...(request.method !== 'GET' ? { body: JSON.stringify(
|
|
94
|
+
...(request.method !== 'GET' ? { body: JSON.stringify(payload) } : {}),
|
|
82
95
|
})
|
|
83
96
|
const text = await response.text()
|
|
84
97
|
if (new TextEncoder().encode(text).length > MAX_BYTES - 512) throw new Error('harness_rpc_response_too_large')
|
|
@@ -86,7 +99,8 @@ export class HarnessRPCExecutor {
|
|
|
86
99
|
if (!body || typeof body !== 'object' || Array.isArray(body)) throw new Error('invalid_harness_rpc_body')
|
|
87
100
|
controller.signal.throwIfAborted()
|
|
88
101
|
if (response.ok && this.binding.completed) await this.binding.completed(request, body, controller.signal)
|
|
89
|
-
if (response.status === 200 && request.path === '/api/sessions' && Array.isArray(body.sessions)) {
|
|
102
|
+
if (response.status === 200 && request.method === 'GET' && request.path === '/api/sessions' && Array.isArray(body.sessions)) {
|
|
103
|
+
body.duet_rpc_capabilities = ['create_session_v1']
|
|
90
104
|
// Both startup prompt and nth_N resolution read this same browser-local
|
|
91
105
|
// order, including manual drag order; archived rows cannot consume ranks.
|
|
92
106
|
body.sessions = this.catalogOrder(body.sessions)
|
package/src/client/settings.html
CHANGED
|
@@ -70,13 +70,13 @@
|
|
|
70
70
|
<h1>duet<span id="duetMark" style="color:#ed9b35">.</span></h1>
|
|
71
71
|
<div class="sub">用声音控制dsh,让工作变得更自由。</div>
|
|
72
72
|
<div class="connection" id="connectionStatus">
|
|
73
|
-
<div><div class="connection-title" id="connectionTitle"
|
|
73
|
+
<div><div class="connection-title" id="connectionTitle">正在读取连接状态</div><div class="connection-detail" id="connectionDetail"></div></div>
|
|
74
74
|
</div>
|
|
75
75
|
<section class="panel" style="margin-bottom:18px">
|
|
76
76
|
<h2>连接概览</h2>
|
|
77
77
|
<p class="section-note">选择一种语音模式,点击当前模式即可关闭。</p>
|
|
78
78
|
<div class="cards">
|
|
79
|
-
<div class="metric"><small>当前模式</small><strong id="duetConnection"
|
|
79
|
+
<div class="metric"><small>当前模式</small><strong id="duetConnection">读取中</strong></div>
|
|
80
80
|
<div class="metric"><small>服务配置</small><strong id="authState">检查中</strong></div>
|
|
81
81
|
<div class="metric"><small>插件版本</small><strong id="pluginVersion">检查中</strong></div>
|
|
82
82
|
<div class="metric"><small>双工模型</small><strong id="duplexModel" style="font-size:16px;overflow-wrap:anywhere">检查中</strong></div>
|
|
@@ -151,7 +151,8 @@
|
|
|
151
151
|
</div>
|
|
152
152
|
<footer><span>duet / DeepSeek Harness</span></footer>
|
|
153
153
|
</main>
|
|
154
|
-
<script>
|
|
154
|
+
<script type="module">
|
|
155
|
+
import { identityFetch } from '/duet/assets/client/identity.mjs?v=0.1.6';
|
|
155
156
|
const base = "/duplex-control/api";
|
|
156
157
|
let debugEnabled = false, settingsRevision = null, feedbackSubmitting = false;
|
|
157
158
|
const composerChannel = typeof BroadcastChannel === "undefined" ? null : new BroadcastChannel("dsh-duplex-control-v1");
|
|
@@ -160,7 +161,7 @@
|
|
|
160
161
|
const $ = id => document.getElementById(id);
|
|
161
162
|
const escapeHtml = value => String(value ?? "").replace(/[&<>"']/g, c => ({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));
|
|
162
163
|
async function api(path, options = {}) {
|
|
163
|
-
const response = await
|
|
164
|
+
const response = await identityFetch(base + path, {headers:{"Content-Type":"application/json"}, ...options});
|
|
164
165
|
const payload = await response.json();
|
|
165
166
|
if (!response.ok) throw new Error(payload.detail || `HTTP ${response.status}`);
|
|
166
167
|
return payload;
|
|
@@ -199,36 +200,32 @@
|
|
|
199
200
|
if (overwrite) $("composerDraft").value = composer.draft;
|
|
200
201
|
$("composerMeta").textContent = `${composer.session_id} · ${composer.phase} · revision ${composer.draft_revision}`;
|
|
201
202
|
}
|
|
202
|
-
function
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
async function loadConnectionStatus() {
|
|
203
|
+
function showConnectionStatus(config) {
|
|
204
|
+
const connection = config.connection || {};
|
|
206
205
|
const card = $("connectionStatus");
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
} else {
|
|
222
|
-
card.classList.add("connected");
|
|
223
|
-
$("connectionTitle").textContent = "DSH 主页面已连接";
|
|
224
|
-
$("connectionDetail").textContent = debugEnabled ? `焦点一致:${sessionLabel(health.active_session_id)} · 最近心跳 ${age?.toFixed(1)} 秒前` : `插件 ${health.plugin_version} · 主页面连接正常`;
|
|
225
|
-
}
|
|
226
|
-
} catch (error) {
|
|
227
|
-
card.className = "connection disconnected";
|
|
228
|
-
$("connectionTitle").textContent = "duet 暂时不可用";
|
|
229
|
-
$("connectionDetail").textContent = debugEnabled ? error.message : '暂时无法连接,请稍后重试。';
|
|
206
|
+
card.className = "connection";
|
|
207
|
+
if (connection.online || connection.tts_only) {
|
|
208
|
+
card.classList.add("connected");
|
|
209
|
+
$("connectionTitle").textContent = "语音已连接";
|
|
210
|
+
const mode = connection.online ? '交互模式' : '播报模式';
|
|
211
|
+
$("connectionDetail").textContent = `${mode} · 插件 ${config.plugin_version || '—'}`;
|
|
212
|
+
} else if (connection.connecting) {
|
|
213
|
+
card.classList.add("mismatch");
|
|
214
|
+
$("connectionTitle").textContent = "语音正在连接";
|
|
215
|
+
$("connectionDetail").textContent = "正在连接语音服务,请稍候。";
|
|
216
|
+
} else {
|
|
217
|
+
card.classList.add("disconnected");
|
|
218
|
+
$("connectionTitle").textContent = "语音未开启";
|
|
219
|
+
$("connectionDetail").textContent = "请回到 DSH 页面开启语音模式。";
|
|
230
220
|
}
|
|
231
221
|
}
|
|
222
|
+
function showConnectionUnavailable() {
|
|
223
|
+
$("connectionStatus").className = "connection disconnected";
|
|
224
|
+
$("connectionTitle").textContent = "语音连接信息不可用";
|
|
225
|
+
$("connectionDetail").textContent = "暂时无法读取连接状态,请稍后重试。";
|
|
226
|
+
$('duetConnection').textContent = '语音连接信息不可用';
|
|
227
|
+
$('duetMark').style.color = '#ed9b35';
|
|
228
|
+
}
|
|
232
229
|
async function loadSessions() {
|
|
233
230
|
const sessions = (await api("/sessions")).sessions;
|
|
234
231
|
sessionLabels.clear();
|
|
@@ -291,9 +288,13 @@
|
|
|
291
288
|
catch (error) { showMessage(error.message, true); }
|
|
292
289
|
};
|
|
293
290
|
$("refresh").onclick = async () => Promise.all([loadSessions(), loadJobs()]);
|
|
294
|
-
async function refresh() { try { await Promise.all([loadSessions(), loadJobs()
|
|
291
|
+
async function refresh() { try { await Promise.all([loadSessions(), loadJobs()]); } catch (error) { showMessage(error.message, true); } }
|
|
295
292
|
async function loadDuetConfig(fill = false) {
|
|
296
293
|
const config = await api('/voice/config');
|
|
294
|
+
showConnectionStatus(config);
|
|
295
|
+
const c = config.connection || {};
|
|
296
|
+
$('duetMark').style.color = c.online || c.tts_only ? '#7fd6a6' : '#ed9b35';
|
|
297
|
+
$('duetConnection').textContent = c.online ? '交互模式' : c.tts_only ? '播报模式' : c.connecting ? '正在连接' : '未开启';
|
|
297
298
|
const info = await api('/voice/service-info').catch(() => ({status:'unavailable'}));
|
|
298
299
|
$('duplexModel').textContent = info.status === 'ok' ? info.models.duplex : '暂不可用';
|
|
299
300
|
$('ttsModel').textContent = info.status === 'ok' ? info.models.tts : '暂不可用';
|
|
@@ -303,9 +304,6 @@
|
|
|
303
304
|
settingsRevision = config.revision;
|
|
304
305
|
$('backendUrl').value = config.backend_url || '';
|
|
305
306
|
}
|
|
306
|
-
const c = config.connection || {};
|
|
307
|
-
$('duetMark').style.color = c.online || c.tts_only ? '#7fd6a6' : '#ed9b35';
|
|
308
|
-
$('duetConnection').textContent = c.online ? '交互模式' : c.tts_only ? '播报模式' : c.connecting ? '正在连接' : '未开启';
|
|
309
307
|
$('authState').textContent = config.backend_url ? '已配置' : '待配置';
|
|
310
308
|
$('pluginVersion').textContent = config.plugin_version || '—';
|
|
311
309
|
$('saveDuet').disabled = false;
|
|
@@ -361,25 +359,24 @@
|
|
|
361
359
|
await refresh();
|
|
362
360
|
composerRequest('composer/get').then(composer => showComposer(composer)).catch(() => {});
|
|
363
361
|
setInterval(() => { void refresh(); }, 2000);
|
|
364
|
-
}
|
|
365
|
-
await loadConnectionStatus();
|
|
362
|
+
}
|
|
366
363
|
}
|
|
367
364
|
$('openTutorial').onclick = async () => {
|
|
368
365
|
try {
|
|
369
|
-
const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.
|
|
366
|
+
const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.6');
|
|
370
367
|
requestTutorial(localStorage);
|
|
371
368
|
$('tutorialStatus').textContent = '请回到 DSH 页面继续教学。';
|
|
372
369
|
} catch { $('tutorialStatus').textContent = '暂时无法打开教学,请允许浏览器存储后重试。'; }
|
|
373
370
|
};
|
|
374
|
-
initialize().catch(error => { $('settingsMessage').textContent = debugEnabled ? `配置读取失败:${error.message}` : '暂时无法加载设置,请刷新重试。'; });
|
|
375
|
-
setInterval(() => { loadDuetConfig().catch(
|
|
371
|
+
initialize().catch(error => { showConnectionUnavailable(); $('settingsMessage').textContent = debugEnabled ? `配置读取失败:${error.message}` : '暂时无法加载设置,请刷新重试。'; });
|
|
372
|
+
setInterval(() => { loadDuetConfig().catch(showConnectionUnavailable); }, 2000);
|
|
376
373
|
void loadNotices();
|
|
377
374
|
setInterval(loadNotices, 60000);
|
|
378
|
-
import('/duet/assets/client/shortcuts.mjs?v=0.1.
|
|
375
|
+
import('/duet/assets/client/shortcuts.mjs?v=0.1.6').then(({mountShortcutSettings}) => {
|
|
379
376
|
const dispose = mountShortcutSettings({speaker:$('speakerShortcut'),mic:$('micShortcut'),clearSpeaker:$('clearSpeakerShortcut'),clearMic:$('clearMicShortcut'),status:$('shortcutStatus')});
|
|
380
377
|
window.addEventListener('pagehide', e => {if(!e.persisted)dispose()}, {once:true});
|
|
381
378
|
}).catch(() => { $('shortcutStatus').textContent = '暂时无法加载快捷键设置,请刷新重试。'; });
|
|
382
|
-
import('/duet/assets/client/microphone.mjs?v=0.1.
|
|
379
|
+
import('/duet/assets/client/microphone.mjs?v=0.1.6').then(({mountMicrophoneSettings}) => {
|
|
383
380
|
const dispose = mountMicrophoneSettings({select:$('microphoneDevice'),refresh:$('refreshMicrophones'),status:$('microphoneStatus')});
|
|
384
381
|
window.addEventListener('pagehide', dispose, {once:true});
|
|
385
382
|
}).catch(() => { $('microphoneStatus').textContent = '暂时无法加载麦克风设置,请刷新重试。'; });
|
|
@@ -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.
|
|
3
|
-
import { focusedSession } from './composer.mjs?v=0.1.
|
|
4
|
-
import {
|
|
5
|
-
import { startComposerBridge } from './composer-bridge.mjs?v=0.1.
|
|
2
|
+
import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.6'
|
|
3
|
+
import { focusedSession } from './composer.mjs?v=0.1.6'
|
|
4
|
+
import { sessionCreationPayload, workspaceIssue } from './workspaces.mjs?v=0.1.6'
|
|
5
|
+
import { startComposerBridge } from './composer-bridge.mjs?v=0.1.6'
|
|
6
6
|
export function tutorialAdapter(ctx, state, audio, pollReady, startBridge = startComposerBridge) {
|
|
7
7
|
let narration
|
|
8
8
|
const completed = new Map()
|
|
@@ -44,9 +44,8 @@ export function tutorialAdapter(ctx, state, audio, pollReady, startBridge = star
|
|
|
44
44
|
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)}},
|
|
45
45
|
unlock:()=>audio.prepare(),
|
|
46
46
|
async create(name,signal){
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const d=await api('sessions',signal,'POST',{name,...(cwd?{cwd}:{})});return d.session.session_id
|
|
47
|
+
const payload=sessionCreationPayload(ctx,{name})
|
|
48
|
+
const d=await api('sessions',signal,'POST',payload);return d.session.session_id
|
|
50
49
|
},
|
|
51
50
|
async focus(id,signal){
|
|
52
51
|
await api(`sessions/${encodeURIComponent(id)}/activate`,signal,'POST',{})
|
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.1.
|
|
2
|
+
import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.1.6'
|
|
3
3
|
export const TUTORIAL_KEY = 'dsh-duplex-tutorial-v1'
|
|
4
4
|
export const QUESTION = '什么是语音交互?请用一句话简单解释,不使用工具。'
|
|
5
5
|
export const INPUT = '用一句话介绍语音助手。'
|
|
@@ -14,6 +14,17 @@ export function requireWorkspace(ctx) {
|
|
|
14
14
|
if (issue) throw Error(issue)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/** Resolve at command time from this page, not the host's global focus/cwd. */
|
|
18
|
+
export function sessionCreationPayload(ctx, payload = {}) {
|
|
19
|
+
requireWorkspace(ctx)
|
|
20
|
+
const current = focusedSession(ctx)
|
|
21
|
+
const items = ctx.workspaces.list.getSnapshot().items
|
|
22
|
+
const workspace = items.find(item => item.sessionIds?.includes(current))
|
|
23
|
+
?? (!current && items.length === 1 ? items[0] : null)
|
|
24
|
+
if (!workspace?.workspaceId) throw Object.assign(new Error('workspace_selection_required'), { code: 'workspace_selection_required' })
|
|
25
|
+
return { name: payload.name, workspace_id: workspace.workspaceId }
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
export function browserSessionCatalog(ctx, rows) {
|
|
18
29
|
const snapshot = ctx.sessions.list.getSnapshot()
|
|
19
30
|
const active = focusedSession(ctx)
|
package/src/host/assets.mjs
CHANGED
|
@@ -13,6 +13,7 @@ const modules = {
|
|
|
13
13
|
notice: 'client/notice',
|
|
14
14
|
workspaces: 'client/workspaces',
|
|
15
15
|
transport: 'client/transport',
|
|
16
|
+
identity: 'client/identity', identity_protocol: 'shared/identity',
|
|
16
17
|
}
|
|
17
18
|
const aliases = {
|
|
18
19
|
state: 'DuetState as VoiceState', audio: 'DuetAudio as VoiceAudio',
|
|
@@ -3,6 +3,7 @@ import {createHmac,randomBytes,timingSafeEqual} from 'node:crypto'
|
|
|
3
3
|
import {existsSync,mkdirSync,readFileSync,openSync,writeFileSync,fsyncSync,closeSync,linkSync,unlinkSync} from 'node:fs'
|
|
4
4
|
import {dirname} from 'node:path'
|
|
5
5
|
import {defaultStateFile} from './storage-paths.mjs'
|
|
6
|
+
import {IDENTITY_HEADER, IDENTITY_PROTOCOL_PREFIX, validIdentityToken} from '../shared/identity.mjs'
|
|
6
7
|
|
|
7
8
|
const COOKIE='duplex_feedback_user'
|
|
8
9
|
export class RemoteFeedback {
|
|
@@ -25,21 +26,27 @@ export class RemoteFeedback {
|
|
|
25
26
|
this.key=key;return key
|
|
26
27
|
}
|
|
27
28
|
sign(id){return createHmac('sha256',this.identityKey()).update(id).digest('hex')}
|
|
28
|
-
|
|
29
|
+
identityToken(req){
|
|
30
|
+
const header=req.headers?.[IDENTITY_HEADER.toLowerCase()]
|
|
31
|
+
const protocols=String(req.headers?.['sec-websocket-protocol']||'').split(',').map(x=>x.trim()).filter(x=>x.startsWith(IDENTITY_PROTOCOL_PREFIX))
|
|
32
|
+
if(protocols.length>1)throw Error('feedback_identity_unavailable')
|
|
29
33
|
const cookie=String(req.headers?.cookie||'').split(';').map(x=>x.trim()).find(x=>x.startsWith(COOKIE+'='))?.slice(COOKIE.length+1)
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
const token=header??(protocols.length?protocols[0].slice(IDENTITY_PROTOCOL_PREFIX.length):cookie)
|
|
35
|
+
if(!validIdentityToken(token))throw Error('feedback_identity_unavailable')
|
|
36
|
+
const [id,mac]=token.split('.')
|
|
32
37
|
if(!timingSafeEqual(Buffer.from(this.sign(id)),Buffer.from(mac)))throw Error('feedback_identity_unavailable')
|
|
33
|
-
return
|
|
38
|
+
return token
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
userId(req){return 'anon_'+this.identityToken(req).split('.')[0]}
|
|
41
|
+
ensureCredential(req,res){
|
|
42
|
+
try{return this.identityToken(req)}catch{}
|
|
37
43
|
const id=randomBytes(16).toString('hex'),signed=id+'.'+this.sign(id)
|
|
38
44
|
// Same-origin HttpOnly cookie; identity is pseudonymous browser, not account.
|
|
39
45
|
const secure=req.socket?.encrypted||req.headers['x-forwarded-proto']==='https'
|
|
40
46
|
res.setHeader('Set-Cookie',`${COOKIE}=${signed}; Path=/duplex-control; HttpOnly; SameSite=Strict; Max-Age=31536000${secure?'; Secure':''}`)
|
|
41
|
-
return
|
|
47
|
+
return signed
|
|
42
48
|
}
|
|
49
|
+
ensureIdentity(req,res){return 'anon_'+this.ensureCredential(req,res).split('.')[0]}
|
|
43
50
|
async insert(record,{config:connectionConfig}={}){
|
|
44
51
|
const config=connectionConfig||await this.getConfig(),url=new URL(config.endpoints.online)
|
|
45
52
|
url.protocol=url.protocol==='wss:'?'https:':'http:'
|
package/src/host/plugin.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { readFile } from 'node:fs/promises'
|
|
|
4
4
|
import { randomUUID } from 'node:crypto'
|
|
5
5
|
import { registerDuetProxy, duetConfig } from './proxy.mjs'
|
|
6
6
|
import { DuetSettings, settingsWriteAllowed } from './settings.mjs'
|
|
7
|
+
import { IDENTITY_TRANSPORT_HEADER, IDENTITY_TRANSPORT } from '../shared/identity.mjs'
|
|
7
8
|
import { ServiceNotices } from './notices.mjs'
|
|
8
9
|
import { ServiceInfo } from './service-info.mjs'
|
|
9
10
|
import { DuetTrace } from './trace.mjs'
|
|
@@ -485,9 +486,18 @@ export function apply(ctx, options = {}) {
|
|
|
485
486
|
completeJob(job, event)
|
|
486
487
|
})
|
|
487
488
|
|
|
489
|
+
const identityWriteAllowed = req => {
|
|
490
|
+
if(settingsWriteAllowed(req))return true
|
|
491
|
+
// Desktop strips Origin after enforcing dsh-app://app in its bridge.
|
|
492
|
+
// Never infer a trusted bridge from an absent header alone.
|
|
493
|
+
if(req.headers.origin!==undefined || req.headers[IDENTITY_TRANSPORT_HEADER.toLowerCase()]!==IDENTITY_TRANSPORT)return false
|
|
494
|
+
try {feedback.user(req);return settingsWriteAllowed(req,{verifiedLocalIdentity:true})} catch {return false}
|
|
495
|
+
}
|
|
488
496
|
const handleApi = async (req, res, pathname) => {
|
|
489
497
|
if(req.method==='POST' && pathname===`${ROUTE}/api/feedback`){
|
|
490
|
-
|
|
498
|
+
const rejection = ctx.connection.requestRejection(req)
|
|
499
|
+
if(rejection){sendError(res,rejection,'请先打开并登录 DSH 主页面');return}
|
|
500
|
+
if(!identityWriteAllowed(req)){sendError(res,403,'same-origin feedback request required');return}
|
|
491
501
|
try {sendJson(res,201,await feedback.submit(req,await readJson(req)))}
|
|
492
502
|
catch(error){
|
|
493
503
|
const code=String(error.message||'')
|
|
@@ -509,12 +519,17 @@ export function apply(ctx, options = {}) {
|
|
|
509
519
|
return
|
|
510
520
|
}
|
|
511
521
|
if (req.method === 'GET' && pathname === `${ROUTE}/api/voice/config`) {
|
|
512
|
-
|
|
513
|
-
|
|
522
|
+
let identity
|
|
523
|
+
try {
|
|
524
|
+
if(req.headers[IDENTITY_TRANSPORT_HEADER.toLowerCase()]===IDENTITY_TRANSPORT)identity=feedbackStore?.ensureCredential?.(req,res)
|
|
525
|
+
else feedbackStore?.ensureIdentity?.(req,res)
|
|
526
|
+
} catch {sendJson(res,503,{error_code:'feedback_identity_unavailable'});return}
|
|
527
|
+
sendJson(res, 200, { ...settings.public(), plugin_version: PLUGIN_VERSION, feedback_enabled: feedback.enabled,
|
|
528
|
+
...(identity?{feedback_identity:identity}:{}), connection: duetProxy?.snapshot?.() || { online: 0, tts_only: 0 } })
|
|
514
529
|
return
|
|
515
530
|
}
|
|
516
531
|
if (req.method === 'PUT' && pathname === `${ROUTE}/api/voice/config`) {
|
|
517
|
-
if (!
|
|
532
|
+
if (!identityWriteAllowed(req)) { sendError(res, 403, 'same-origin settings request required'); return }
|
|
518
533
|
try {
|
|
519
534
|
const result = await settings.save(await readJson(req))
|
|
520
535
|
Object.assign(voice, settings.effective())
|
|
@@ -779,7 +794,10 @@ export function apply(ctx, options = {}) {
|
|
|
779
794
|
return
|
|
780
795
|
}
|
|
781
796
|
if (req.method === 'GET' && pathname === `${ROUTE}/api/sessions`) {
|
|
782
|
-
|
|
797
|
+
// A page owns its focus. Do not remove blank sessions using host focus
|
|
798
|
+
// before that page can select its own current blank session.
|
|
799
|
+
const pageCatalog = browserOwner(req) || req.headers['x-duet-catalog-scope'] === 'page'
|
|
800
|
+
sendJson(res, 200, { sessions: await listSessions({forCatalog:!pageCatalog}) })
|
|
783
801
|
return
|
|
784
802
|
}
|
|
785
803
|
const composer = pathname.match(new RegExp(`^${ROUTE}/api/sessions/([^/]+)/composer$`))
|
|
@@ -905,11 +923,17 @@ export function apply(ctx, options = {}) {
|
|
|
905
923
|
if (req.method === 'POST' && pathname === `${ROUTE}/api/sessions`) {
|
|
906
924
|
const body = await readJson(req)
|
|
907
925
|
const name = String(body.name || '').trim()
|
|
908
|
-
const cwd = String(body.cwd ||
|
|
926
|
+
const cwd = String(body.cwd || '').trim()
|
|
909
927
|
// Current DSH only enables the blank-session composer for a session
|
|
910
928
|
// owned by a registered workspace. cwd alone creates an orphan session.
|
|
911
|
-
let workspaceId
|
|
912
|
-
if (
|
|
929
|
+
let workspaceId = typeof body.workspace_id === 'string' ? body.workspace_id.trim() : ''
|
|
930
|
+
if (workspaceId) {
|
|
931
|
+
if (!(ctx.workspaceRegistry.list?.() || []).some(workspace => workspace.id === workspaceId)) {
|
|
932
|
+
throw codedError('workspace_not_found', 'Selected workspace is no longer available', 409)
|
|
933
|
+
}
|
|
934
|
+
} else if (!cwd || browserOwner(req)) {
|
|
935
|
+
throw codedError('workspace_selection_required', 'Select a workspace before creating a session', 409)
|
|
936
|
+
} else if (typeof ctx.workspaceController.create === 'function') {
|
|
913
937
|
const resolved = await ctx.workspaceController.create({ path: cwd })
|
|
914
938
|
workspaceId = resolved.workspace?.workspaceId
|
|
915
939
|
if (typeof workspaceId !== 'string' || !workspaceId) {
|
package/src/host/proxy.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { PLUGIN_VERSION } from '../shared/state.mjs'
|
|
|
5
5
|
import { duetEnv } from './environment.mjs'
|
|
6
6
|
import { EndpointDiscovery, connectEndpoint } from './endpoint-discovery.mjs'
|
|
7
7
|
import {sessionMetadata} from './session-metadata.mjs'
|
|
8
|
+
import {VOICE_PROTOCOL} from '../shared/identity.mjs'
|
|
8
9
|
import { DEFAULT_DUET_URL, publicServiceAuthorization } from './service-defaults.mjs'
|
|
9
10
|
export { DEFAULT_DUET_URL } from './service-defaults.mjs'
|
|
10
11
|
const require = createRequire(import.meta.url)
|
|
@@ -55,7 +56,8 @@ export function registerDuetProxy(ctx, config = duetConfig(), feedback = null, c
|
|
|
55
56
|
if (!['ws:', 'wss:'].includes(url.protocol) || url.username || url.password || url.hash) throw new Error('invalid_voice_endpoint')
|
|
56
57
|
}
|
|
57
58
|
const { WebSocket, WebSocketServer } = require('ws')
|
|
58
|
-
const server = new WebSocketServer({ noServer: true, maxPayload: 1_000_000
|
|
59
|
+
const server = new WebSocketServer({ noServer: true, maxPayload: 1_000_000,
|
|
60
|
+
handleProtocols: protocols => protocols.has(VOICE_PROTOCOL) ? VOICE_PROTOCOL : false })
|
|
59
61
|
const connections = new Map()
|
|
60
62
|
const stop = ctx.webServer.registerUpgrade({
|
|
61
63
|
path: '/duplex-control/voice/ws',
|
package/src/host/settings.mjs
CHANGED
|
@@ -94,10 +94,10 @@ export class DuetSettings {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export function settingsWriteAllowed(req) {
|
|
97
|
+
export function settingsWriteAllowed(req, { verifiedLocalIdentity = false } = {}) {
|
|
98
98
|
try {
|
|
99
99
|
return req.headers['x-duplex-settings'] === '1'
|
|
100
|
-
&& new URL(req.headers.origin).host === req.headers.host
|
|
100
|
+
&& ((req.headers.origin === undefined && verifiedLocalIdentity) || new URL(req.headers.origin).host === req.headers.host)
|
|
101
101
|
&& String(req.headers['content-type'] || '').startsWith('application/json')
|
|
102
102
|
} catch { return false }
|
|
103
103
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Anonymous identity transport, independent of DSH authentication. */
|
|
2
|
+
export const IDENTITY_HEADER = 'X-Duet-Identity'
|
|
3
|
+
export const IDENTITY_TRANSPORT_HEADER = 'X-Duet-Identity-Transport'
|
|
4
|
+
export const IDENTITY_TRANSPORT = 'local-v1'
|
|
5
|
+
export const IDENTITY_STORAGE = 'dsh-duet.feedback-identity.v1'
|
|
6
|
+
export const VOICE_PROTOCOL = 'duet-voice-v1'
|
|
7
|
+
export const IDENTITY_PROTOCOL_PREFIX = 'duet-identity.'
|
|
8
|
+
export const validIdentityToken = value => typeof value === 'string' && /^[a-f0-9]{32}\.[a-f0-9]{64}$/.test(value)
|
package/src/shared/state.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Desired voice mode is independent of a temporarily suspended connection. */
|
|
2
|
-
export const PLUGIN_VERSION = '0.1.
|
|
2
|
+
export const PLUGIN_VERSION = '0.1.6'
|
|
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 : ''
|