dsh-duet 0.1.6 → 0.1.7

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.6",
3
+ "version": "0.1.7",
4
4
  "description": "duet(二重奏):只用语音就能操作 DSH,边听边说、随时插话的全双工语音助手。",
5
5
  "keywords": [
6
6
  "dsh-plugin",
@@ -1,4 +1,4 @@
1
- import { microphoneConstraints } from './microphone.mjs?v=0.1.6'
1
+ import { microphoneConstraints } from './microphone.mjs?v=0.1.7'
2
2
 
3
3
  /** Browser-owned microphone and PCM playback. No microphone is requested in tts_only. */
4
4
  export class DuetAudio {
@@ -1,20 +1,22 @@
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'
1
+ import { DuetState, PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.7'
2
+ import { DuetAudio } from './audio.mjs?v=0.1.7'
3
+ import { HarnessRPCExecutor, rpcNavigationSession } from './rpc.mjs?v=0.1.7'
4
+ import { composerAccess, observeComposer, focusedSession, openLocalSession } from './composer.mjs?v=0.1.7'
5
+ import { startComposerBridge } from './composer-bridge.mjs?v=0.1.7'
6
+ import { mountTutorial } from './tutorial.mjs?v=0.1.7'
7
+ import { tutorialAdapter } from './tutorial-adapter.mjs?v=0.1.7'
8
+ import { mountRating } from './feedback.mjs?v=0.1.7'
9
+ import { createAudioUploadConsent } from './consent.mjs?v=0.1.7'
10
+ import { bindDuetShortcuts } from './shortcuts.mjs?v=0.1.7'
11
+ import { nativeInteractions } from './interactions.mjs?v=0.1.7'
12
+ import { mountConnectionHint } from './connection-hint.mjs?v=0.1.7'
13
+ import { mountControlsLayout } from './controls-layout.mjs?v=0.1.7'
14
+ import { mountNotice } from './notice.mjs?v=0.1.7'
15
+ import { workspaceIssue, requireWorkspace, browserSessionCatalog, sessionCreationPayload } from './workspaces.mjs?v=0.1.7'
16
+ import { voiceSocketUrl, bindSettingsLink } from './transport.mjs?v=0.1.7'
17
+ import { identityFetch, identityVoiceProtocols } from './identity.mjs?v=0.1.7'
18
+ import { sessionLabel } from '../shared/catalog.mjs?v=0.1.7'
19
+ import { resultNotification } from '../shared/result-notification.mjs?v=0.1.7'
18
20
 
19
21
  export function mountDuet(ctx) {
20
22
  const pageId = crypto.randomUUID()
@@ -86,7 +88,7 @@ export function mountDuet(ctx) {
86
88
  if (ws.bufferedAmount > 1_000_000) { receive({ type: 'error', code: 'voice_backpressure' }); return }
87
89
  ws.send(message instanceof ArrayBuffer ? message : JSON.stringify(message))
88
90
  }
89
- const composer = composerAccess(ctx, id => labels.get(id) || id)
91
+ const composer = composerAccess(ctx, id => sessionLabel(labels.get(id), id))
90
92
  const interactions = nativeInteractions(ctx)
91
93
  const rpc = new HarnessRPCExecutor(send, fetch, report, async (request, signal) =>
92
94
  (await interactions(request, signal)) ?? composer.execute(request, signal), rows =>
@@ -327,18 +329,13 @@ export function mountDuet(ctx) {
327
329
  const id = focusedSession(ctx)
328
330
  const scope = id ? ctx.sessions.scope(id) : undefined
329
331
  if (scope) {
330
- try { composer = { session_name: labels.get(id) || id, text: ctx.conversation.input.for(scope).state.getSnapshot().draft } } catch { /* Session input is still mounting; do not invent an empty draft. */ }
332
+ try { composer = { session_name: sessionLabel(labels.get(id), id), text: ctx.conversation.input.for(scope).state.getSnapshot().draft } } catch { /* Session input is still mounting; do not invent an empty draft. */ }
331
333
  }
332
334
  state.update({
333
335
  hidden: document.visibilityState !== 'visible',
334
336
  running: catalog.sessions.some(s => s.running),
335
337
  state: { focused_session_id: id || null, ...(composer ? { composer_state: composer } : {}), sessions: catalog.sessions.map(s => ({ session_id: s.session_id, session_name: s.label, running: s.running })) },
336
- results: bootstrap ? [] : completed.results.map(job => ({
337
- type: 'external_message', message_id: `harness_${job.id}`,
338
- source: { session_id: job.session_id, session_name: labels.get(job.session_id) || job.session_id,
339
- job_id: job.id, status: job.status === 'succeeded' ? 'completed' : 'failed' },
340
- text: (job.status === 'succeeded' ? job.result : (job.error || job.result)) || '未返回结果。',
341
- })),
338
+ results: bootstrap ? [] : completed.results.map(job => resultNotification(job, labels.get(job.session_id))),
342
339
  })
343
340
  resultEpoch = health.focus_epoch
344
341
  cursor = bootstrap ? completed.current_cursor : completed.next_cursor
@@ -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.6'
2
+ import { focusedSession as currentSession } from './composer.mjs?v=0.1.7'
3
3
 
4
4
  export function startComposerBridge(ctx, clientId, fetchImpl = fetch) {
5
5
  const focusedSession = () => currentSession(ctx)
@@ -1,4 +1,5 @@
1
1
  /** Browser-owned drafts: bounded snapshots and explicit overwrite/CAS edit policies. */
2
+ import { sessionLabel } from '../shared/catalog.mjs'
2
3
  const fail = code => { const error = new Error(code); error.code = code; throw error }
3
4
  const hash = async text => [...new Uint8Array(await crypto.subtle.digest('SHA-256',
4
5
  new TextEncoder().encode(text)))].map(v => v.toString(16).padStart(2, '0')).join('')
@@ -26,7 +27,7 @@ export async function openLocalSession(ctx, id, signal) {
26
27
  }
27
28
  }
28
29
 
29
- export function composerAccess(ctx, label = id => id) {
30
+ export function composerAccess(ctx, label = () => '') {
30
31
  const focused = () => focusedSession(ctx)
31
32
  const inputFor = id => {
32
33
  const scope = id && ctx.sessions.scope(id)
@@ -40,7 +41,7 @@ export function composerAccess(ctx, label = id => id) {
40
41
  const digest = await hash(before.draft)
41
42
  const live = input.state.getSnapshot()
42
43
  if (stable && (live.draft !== before.draft || live.draftRev !== before.draftRev || live.phase !== before.phase)) fail('draft_conflict')
43
- return { session_id: id, session_name: label(id), text: before.draft,
44
+ return { session_id: id, session_name: sessionLabel(label(id), id), text: before.draft,
44
45
  revision: before.draftRev, hash: digest, phase: before.phase }
45
46
  }
46
47
  const read = async () => {
@@ -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.6'
2
+ import {normalizeGuidance} from '../shared/connection-guidance.mjs?v=0.1.7'
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.6').then(module => {
14
+ import('/duet/assets/client/browser.mjs?v=0.1.7').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?.() }
@@ -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.1.6'
2
+ import { identityFetch } from './identity.mjs?v=0.1.7'
3
3
 
4
4
  export function mountRating(anchor, sessionTicket) {
5
5
  if(!sessionTicket)return null
@@ -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.1.6'
2
+ VOICE_PROTOCOL, IDENTITY_PROTOCOL_PREFIX, validIdentityToken } from '../shared/identity.mjs?v=0.1.7'
3
3
 
4
4
  /** Desktop strips plugin cookies. Keep the Host-signed value in its origin storage. */
5
5
  export function createIdentityClient(globals = globalThis) {
@@ -152,7 +152,7 @@
152
152
  <footer><span>duet / DeepSeek Harness</span></footer>
153
153
  </main>
154
154
  <script type="module">
155
- import { identityFetch } from '/duet/assets/client/identity.mjs?v=0.1.6';
155
+ import { identityFetch } from '/duet/assets/client/identity.mjs?v=0.1.7';
156
156
  const base = "/duplex-control/api";
157
157
  let debugEnabled = false, settingsRevision = null, feedbackSubmitting = false;
158
158
  const composerChannel = typeof BroadcastChannel === "undefined" ? null : new BroadcastChannel("dsh-duplex-control-v1");
@@ -363,7 +363,7 @@
363
363
  }
364
364
  $('openTutorial').onclick = async () => {
365
365
  try {
366
- const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.6');
366
+ const {requestTutorial} = await import('/duet/assets/client/tutorial-request.mjs?v=0.1.7');
367
367
  requestTutorial(localStorage);
368
368
  $('tutorialStatus').textContent = '请回到 DSH 页面继续教学。';
369
369
  } catch { $('tutorialStatus').textContent = '暂时无法打开教学,请允许浏览器存储后重试。'; }
@@ -372,11 +372,11 @@
372
372
  setInterval(() => { loadDuetConfig().catch(showConnectionUnavailable); }, 2000);
373
373
  void loadNotices();
374
374
  setInterval(loadNotices, 60000);
375
- import('/duet/assets/client/shortcuts.mjs?v=0.1.6').then(({mountShortcutSettings}) => {
375
+ import('/duet/assets/client/shortcuts.mjs?v=0.1.7').then(({mountShortcutSettings}) => {
376
376
  const dispose = mountShortcutSettings({speaker:$('speakerShortcut'),mic:$('micShortcut'),clearSpeaker:$('clearSpeakerShortcut'),clearMic:$('clearMicShortcut'),status:$('shortcutStatus')});
377
377
  window.addEventListener('pagehide', e => {if(!e.persisted)dispose()}, {once:true});
378
378
  }).catch(() => { $('shortcutStatus').textContent = '暂时无法加载快捷键设置,请刷新重试。'; });
379
- import('/duet/assets/client/microphone.mjs?v=0.1.6').then(({mountMicrophoneSettings}) => {
379
+ import('/duet/assets/client/microphone.mjs?v=0.1.7').then(({mountMicrophoneSettings}) => {
380
380
  const dispose = mountMicrophoneSettings({select:$('microphoneDevice'),refresh:$('refreshMicrophones'),status:$('microphoneStatus')});
381
381
  window.addEventListener('pagehide', dispose, {once:true});
382
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.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'
2
+ import { PLUGIN_VERSION } from '../shared/state.mjs?v=0.1.7'
3
+ import { focusedSession } from './composer.mjs?v=0.1.7'
4
+ import { sessionCreationPayload, workspaceIssue } from './workspaces.mjs?v=0.1.7'
5
+ import { startComposerBridge } from './composer-bridge.mjs?v=0.1.7'
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.6'
2
+ import {consumeTutorialRequest} from './tutorial-request.mjs?v=0.1.7'
3
3
  export const TUTORIAL_KEY = 'dsh-duplex-tutorial-v1'
4
4
  export const QUESTION = '什么是语音交互?请用一句话简单解释,不使用工具。'
5
5
  export const INPUT = '用一句话介绍语音助手。'
@@ -1,5 +1,5 @@
1
1
  /** Workspace readiness and browser-local session ordering shared by all voice paths. */
2
- import { orderSessionCatalog, readWorkspaceView } from '../shared/catalog.mjs'
2
+ import { orderSessionCatalog, readWorkspaceView, sessionLabel } from '../shared/catalog.mjs'
3
3
  import { focusedSession } from './composer.mjs'
4
4
 
5
5
  export function workspaceIssue(ctx) {
@@ -31,6 +31,7 @@ export function browserSessionCatalog(ctx, rows) {
31
31
  const archived = new Set(ctx.workspaces?.list?.getSnapshot().archivedSessionIds || [])
32
32
  return orderSessionCatalog(rows.filter(row => !archived.has(row.session_id)).map(row => ({
33
33
  ...row, active: row.session_id === active,
34
+ label: sessionLabel(row.label, row.session_id),
34
35
  updated_at: snapshot.byId?.[row.session_id]?.updatedAt ?? row.updated_at,
35
36
  })), readWorkspaceView())
36
37
  }
@@ -1,6 +1,7 @@
1
1
  /** Explicit public asset inventory. Host code and configuration are never served. */
2
2
  const modules = {
3
3
  state: 'shared/state', catalog: 'shared/catalog',
4
+ result_notification: 'shared/result-notification',
4
5
  connection_guidance: 'shared/connection-guidance',
5
6
  audio: 'client/audio', microphone: 'client/microphone', shortcuts: 'client/shortcuts',
6
7
  browser: 'client/browser', rpc: 'client/rpc', composer: 'client/composer',
@@ -11,7 +11,7 @@ import { DuetTrace } from './trace.mjs'
11
11
  import { FeedbackService } from './feedback-store.mjs'
12
12
  import { RemoteFeedback } from './feedback-files.mjs'
13
13
  import { PLUGIN_VERSION } from '../shared/state.mjs'
14
- import { buildSessionCatalog } from '../shared/catalog.mjs'
14
+ import { buildSessionCatalog, sessionLabel } from '../shared/catalog.mjs'
15
15
  import { publicAsset } from './assets.mjs'
16
16
  import { duetEnv } from './environment.mjs'
17
17
  import { EndpointDiscovery } from './endpoint-discovery.mjs'
@@ -945,7 +945,7 @@ export function apply(ctx, options = {}) {
945
945
  if (name) {
946
946
  await ctx.sessionController.rename({ sessionId: created.sessionId, title: name })
947
947
  }
948
- sendJson(res, 201, { session: { session_id: created.sessionId, label: name || created.sessionId, active: true } })
948
+ sendJson(res, 201, { session: { session_id: created.sessionId, label: sessionLabel(name, created.sessionId), active: true } })
949
949
  return
950
950
  }
951
951
 
@@ -6,6 +6,8 @@ import { duetEnv } from './environment.mjs'
6
6
  import { EndpointDiscovery, connectEndpoint } from './endpoint-discovery.mjs'
7
7
  import {sessionMetadata} from './session-metadata.mjs'
8
8
  import {VOICE_PROTOCOL} from '../shared/identity.mjs'
9
+ import { broadcastText } from '../shared/result-notification.mjs'
10
+ import { sessionLabel } from '../shared/catalog.mjs'
9
11
  import { DEFAULT_DUET_URL, publicServiceAuthorization } from './service-defaults.mjs'
10
12
  export { DEFAULT_DUET_URL } from './service-defaults.mjs'
11
13
  const require = createRequire(import.meta.url)
@@ -34,8 +36,7 @@ export function duetConfig(env = process.env) {
34
36
  export function externalWithState(message, _state) {
35
37
  if (message.type !== 'external_message' || typeof message.text !== 'string') throw new Error('invalid_external_message')
36
38
  // Keep authoritative result metadata separate from result text and UI state.
37
- const text = message.text
38
- if (text.length > 8000) throw new Error('external_message_too_large')
39
+ const text = broadcastText(message.text)
39
40
  const source = message.source
40
41
  if (source !== undefined) {
41
42
  const limits = { session_id: 256, session_name: 512, job_id: 256, status: 16 }
@@ -45,7 +46,7 @@ export function externalWithState(message, _state) {
45
46
  !['completed', 'failed'].includes(source.status)) throw new Error('invalid_external_message_source')
46
47
  }
47
48
  return { type: 'external_message', message_id: message.message_id, text,
48
- ...(source === undefined ? {} : { source: { ...source } }) }
49
+ ...(source === undefined ? {} : { source: { ...source, session_name: sessionLabel(source.session_name, source.session_id) } }) }
49
50
  }
50
51
 
51
52
  export function registerDuetProxy(ctx, config = duetConfig(), feedback = null, canUseVoice = () => true, discovery = new EndpointDiscovery(() => config)) {
@@ -1,13 +1,12 @@
1
1
  /** Public trial connection details distributed with the plugin. */
2
- export const DEFAULT_DUET_URL = 'ws://duet-router.1781574661016173.ap-southeast-1.pai-eas.aliyuncs.com/ws?protocol=realtime_v2'
2
+ export const DEFAULT_DUET_URL = 'wss://duet-router-acc.router.dsh-duet.com/ws?protocol=realtime_v2'
3
3
  export const PUBLIC_TRIAL_AUTHORIZATION = "ZTZhZWI4YzA3ODcyZWI2NzZhZjU4MDk3NGE3NGUxODQ2MjgxYWVjYQ=="
4
4
 
5
- export const PUBLIC_TRIAL_GATEWAY_URL = 'ws://duet-router-acc.gw-bmmaj5gve68z3gw34o.ap-southeast-1.pai-eas.aliyuncs.com/ws?protocol=realtime_v2'
6
5
  export const PUBLIC_TRIAL_ACCELERATOR_URL = 'ws://47.117.104.188/ws?protocol=realtime_v2'
7
6
 
8
7
  export function isPublicTrialEndpoint(value) {
9
8
  const url = new URL(value)
10
- return [DEFAULT_DUET_URL, PUBLIC_TRIAL_GATEWAY_URL, PUBLIC_TRIAL_ACCELERATOR_URL].some(value => {
9
+ return [DEFAULT_DUET_URL, PUBLIC_TRIAL_ACCELERATOR_URL].some(value => {
11
10
  const expected = new URL(value)
12
11
  return url.origin === expected.origin && url.pathname === expected.pathname && !url.username && !url.password
13
12
  })
@@ -0,0 +1,25 @@
1
+ /** Retired addresses are migration inputs only, never connection/auth targets. */
2
+ import { writeFileSync, renameSync, unlinkSync } from 'node:fs'
3
+ import { randomUUID } from 'node:crypto'
4
+ import { DEFAULT_DUET_URL } from './service-defaults.mjs'
5
+
6
+ export function migrateRetiredSettings(data, path) {
7
+ if (!data || typeof data !== 'object' || Array.isArray(data)) return data
8
+ let url
9
+ try { url = new URL(data.backend_url) } catch { return data }
10
+ const retired = [
11
+ 'duet-router.1781574661016173.ap-southeast-1.pai-eas.aliyuncs.com',
12
+ 'duet-router-acc.gw-bmmaj5gve68z3gw34o.ap-southeast-1.pai-eas.aliyuncs.com',
13
+ ]
14
+ if (!retired.includes(url.hostname) || !['ws:', 'wss:', 'http:', 'https:'].includes(url.protocol)
15
+ || url.port || url.username || url.password || url.hash || !['/', '/ws'].includes(url.pathname)
16
+ || [...url.searchParams].some(([k,v]) => k !== 'protocol' || v !== 'realtime_v2')) return data
17
+ const next = { backend_url: DEFAULT_DUET_URL }
18
+ const temp = `${path}.${randomUUID()}.tmp`
19
+ try {
20
+ writeFileSync(temp, JSON.stringify(next) + '\n', { mode: 0o600, flag: 'wx' })
21
+ renameSync(temp, path)
22
+ } catch { /* Read-only storage must not prevent using the current default. */ }
23
+ finally { try { unlinkSync(temp) } catch {} }
24
+ return next
25
+ }
@@ -6,6 +6,7 @@ import { defaultStateFile } from './storage-paths.mjs'
6
6
  import { randomUUID } from 'node:crypto'
7
7
  import { duetEnv } from './environment.mjs'
8
8
  import { publicServiceAuthorization, isPublicTrialEndpoint } from './service-defaults.mjs'
9
+ import { migrateRetiredSettings } from './settings-migration.mjs'
9
10
 
10
11
  export function normalizeBackendURL(value) {
11
12
  if (typeof value !== 'string' || value.length > 2048) throw new Error('invalid_backend_url')
@@ -38,7 +39,7 @@ export class DuetSettings {
38
39
  this.writing = false
39
40
  try {
40
41
  const data = JSON.parse(readFileSync(this.path, 'utf8'))
41
- this.saved = this.validate(data)
42
+ this.saved = this.validate(migrateRetiredSettings(data, this.path))
42
43
  } catch (error) { if (error.code !== 'ENOENT') throw new Error('invalid_voice_settings_file') }
43
44
  }
44
45
 
@@ -1,6 +1,11 @@
1
1
  /** Mirror DSH workspace order, never the global activity-sorted search list. */
2
2
  export const WORKSPACE_VIEW_KEY = 'dsh.workspace.view.v5'
3
3
 
4
+ export function sessionLabel(name, id) {
5
+ const text = typeof name === 'string' ? name.trim() : ''
6
+ return text && text !== id ? text : '未命名会话'
7
+ }
8
+
4
9
  export function readWorkspaceView() {
5
10
  try { return JSON.parse(globalThis.localStorage?.getItem(WORKSPACE_VIEW_KEY) || '{}') || {} }
6
11
  catch { return {} }
@@ -54,7 +59,7 @@ export function buildSessionCatalog(items, {workspaces = [], archivedIds = [], a
54
59
  const item = byId.get(id)
55
60
  if (!item) return
56
61
  byId.delete(id)
57
- result.push({session_id:id, label:item.projections?.values?.title || id,
62
+ result.push({session_id:id, label:sessionLabel(item.projections?.values?.title, id),
58
63
  active:id === activeId, running:item.running, updated_at:item.updatedAt,
59
64
  cwd:item.cwd || '', workspace_id:workspaceId, archived:false,
60
65
  blank:!!item.blank, origin:item.origin})
@@ -0,0 +1,19 @@
1
+ import { sessionLabel } from './catalog.mjs'
2
+
3
+ export const MAX_RESULT_TEXT_LENGTH = 8000
4
+ export const LONG_RESULT_NOTICE = '这条任务消息内容较长,请在 DSH 会话中查看完整内容。'
5
+
6
+ /** Never truncate code into a misleading summary. The full result stays in DSH. */
7
+ export function broadcastText(text) {
8
+ if (typeof text !== 'string') throw Error('invalid_external_message')
9
+ return text.length > MAX_RESULT_TEXT_LENGTH ? LONG_RESULT_NOTICE : text
10
+ }
11
+
12
+ export function resultNotification(job, name) {
13
+ return {
14
+ type: 'external_message', message_id: `harness_${job.id}`,
15
+ source: { session_id: job.session_id, session_name: sessionLabel(name, job.session_id),
16
+ job_id: job.id, status: job.status === 'succeeded' ? 'completed' : 'failed' },
17
+ text: broadcastText((job.status === 'succeeded' ? job.result : (job.error || job.result)) || '未返回结果。'),
18
+ }
19
+ }
@@ -1,5 +1,5 @@
1
1
  /** Desired voice mode is independent of a temporarily suspended connection. */
2
- export const PLUGIN_VERSION = '0.1.6'
2
+ export const PLUGIN_VERSION = '0.1.7'
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 : ''
@@ -89,10 +89,10 @@ export class DuetState {
89
89
  this.pending.delete(event.message_id)
90
90
  this.sent.delete(event.message_id)
91
91
  this.flush()
92
- } else if (event.type === 'error') {
92
+ } else if (event.type === 'error' || (event.type === 'warning' && event.warning?.code === 'malformed_dense_action')) {
93
93
  // A rejected model action is not a dead transport. Never execute/retry it,
94
94
  // but leave the user able to clarify instead of closing their microphone.
95
- if (event.code === 'malformed_dense_action') {
95
+ if ((event.code || event.warning?.code) === 'malformed_dense_action') {
96
96
  this.notice('这次操作指令格式有误,未执行。语音仍已连接,请重新说明。')
97
97
  } else this.fail(event.code, event)
98
98
  }