@goodandready/dsh-voice 0.9.50 โ†’ 0.9.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/client.js +200 -16
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -309,6 +309,42 @@ tag.setAttribute('data-dsh-plugin', 'dsh-voice')
309
309
  tag.dataset.pluginCss = cssId
310
310
  document.head.appendChild(tag)
311
311
  }
312
+ const DESIGN_TOKENS = {
313
+ surface: {
314
+ cardBg: 'var(--dsw-alias-bg-layer-3)',
315
+ elevatedBg: 'var(--dsw-alias-bg-layer-2)',
316
+ border: 'var(--dsw-alias-border-l2)',
317
+ },
318
+ text: {
319
+ primary: 'var(--dsw-alias-label-primary)',
320
+ secondary: 'var(--dsw-alias-label-secondary)',
321
+ tertiary: 'var(--dsw-alias-label-tertiary)',
322
+ brand: 'var(--dsw-alias-brand-text)',
323
+ },
324
+ state: {
325
+ success: 'var(--dsw-alias-state-success-primary)',
326
+ warning: 'var(--dsw-alias-state-warning-primary)',
327
+ danger: 'var(--dsw-alias-state-error-primary)',
328
+ },
329
+ radius: {
330
+ sm: '6px',
331
+ md: '8px',
332
+ lg: '12px',
333
+ pill: '999px',
334
+ },
335
+ space: {
336
+ xs: '4px',
337
+ sm: '8px',
338
+ md: '12px',
339
+ lg: '16px',
340
+ },
341
+ font: {
342
+ xs: '11px',
343
+ sm: '12px',
344
+ md: '13px',
345
+ lg: '15px',
346
+ },
347
+ }
312
348
  const apiClient = {
313
349
  getTokenHeaders() {
314
350
  return typeof window !== 'undefined' && window.__dshVoiceToken
@@ -429,6 +465,58 @@ return this.props?.children || null
429
465
  }
430
466
  const VoiceErrorBoundary = createErrorBoundary('voice')
431
467
  const ErrorBoundary = VoiceErrorBoundary
468
+ function UiActionButton(props) {
469
+ const variant = props.variant === 'primary' ? 'cb-btn cb-btn-primary' : 'cb-btn'
470
+ const cls = props.className ? (variant + ' ' + props.className) : variant
471
+ const baseStyle = props.size === 'sm'
472
+ ? { fontSize: DESIGN_TOKENS.font.sm, padding: DESIGN_TOKENS.space.xs + ' ' + DESIGN_TOKENS.space.sm }
473
+ : undefined
474
+ return React.createElement(
475
+ 'button',
476
+ {
477
+ type: 'button',
478
+ className: cls,
479
+ disabled: !!props.disabled,
480
+ title: props.title,
481
+ style: baseStyle && props.style ? Object.assign({}, baseStyle, props.style) : (props.style || baseStyle),
482
+ onClick: props.onClick,
483
+ },
484
+ props.children,
485
+ )
486
+ }
487
+ function UiStatusBadge(props) {
488
+ const kind = props.status === 'ok'
489
+ ? 'cb-badge cb-badge-ok'
490
+ : (props.status === 'warn' ? 'cb-badge cb-badge-warn' : (props.status === 'err' ? 'cb-badge cb-badge-err' : 'cb-badge'))
491
+ return React.createElement('span', { className: kind, title: props.title }, props.children)
492
+ }
493
+ function UiSectionCard(props) {
494
+ return React.createElement(
495
+ 'div',
496
+ { className: 'cb-section-card', style: props.style },
497
+ props.title ? React.createElement(
498
+ 'div',
499
+ { className: 'cb-section-title' },
500
+ React.createElement('span', null, (props.icon ? props.icon + ' ' : '') + props.title),
501
+ props.actions || null,
502
+ ) : null,
503
+ props.description ? React.createElement('div', { className: 'cb-section-desc' }, props.description) : null,
504
+ props.children,
505
+ )
506
+ }
507
+ function UiCheckToggle(props) {
508
+ return React.createElement(
509
+ 'label',
510
+ { className: 'cb-check-label' },
511
+ React.createElement('input', {
512
+ type: 'checkbox',
513
+ checked: !!props.checked,
514
+ disabled: !!props.disabled,
515
+ onChange: (e) => props.onChange && props.onChange(e.target.checked, e),
516
+ }),
517
+ props.label,
518
+ )
519
+ }
432
520
  const voice = {
433
521
  phase: 'idle', // idle | recording | processing | pending | error
434
522
  mode: 'dictation', // dictation | message
@@ -2765,6 +2853,93 @@ if (typeof offDock === 'function') offDock()
2765
2853
  }
2766
2854
  }, 'dsh-voice: composer slots')
2767
2855
  }
2856
+ function cloneSettingsObj(obj) {
2857
+ if (!obj || typeof obj !== 'object') return obj
2858
+ if (typeof structuredClone === 'function') {
2859
+ try { return structuredClone(obj) } catch (_) {}
2860
+ }
2861
+ try { return JSON.parse(JSON.stringify(obj)) } catch (_) { return Object.assign({}, obj) }
2862
+ }
2863
+ function validateSettingsDraft(draft) {
2864
+ const errors = {}
2865
+ if (!draft || typeof draft !== 'object') return { isValid: true, errors }
2866
+ if (draft.historyLimit !== undefined && (Number.isNaN(Number(draft.historyLimit)) || Number(draft.historyLimit) < 0)) {
2867
+ errors.historyLimit = 'historyLimit must be >= 0'
2868
+ }
2869
+ if (draft.noiseGateDb !== undefined && (Number.isNaN(Number(draft.noiseGateDb)) || Number(draft.noiseGateDb) > 0 || Number(draft.noiseGateDb) < -100)) {
2870
+ errors.noiseGateDb = 'noiseGateDb must be between -100 and 0'
2871
+ }
2872
+ if (draft.dictation && draft.dictation.vadSilenceMs !== undefined && Number(draft.dictation.vadSilenceMs) < 0) {
2873
+ errors['dictation.vadSilenceMs'] = 'vadSilenceMs must be >= 0'
2874
+ }
2875
+ return { isValid: Object.keys(errors).length === 0, errors }
2876
+ }
2877
+ function isSettingsDraftDirty(savedConfig, draftConfig) {
2878
+ if (!savedConfig || !draftConfig) return false
2879
+ try {
2880
+ return JSON.stringify(savedConfig) !== JSON.stringify(draftConfig)
2881
+ } catch (_) {
2882
+ return true
2883
+ }
2884
+ }
2885
+ function createSettingsDraftStore(initialSaved = null) {
2886
+ let savedConfig = initialSaved ? cloneSettingsObj(initialSaved) : null
2887
+ let draftConfig = initialSaved ? cloneSettingsObj(initialSaved) : null
2888
+ const listeners = new Set()
2889
+ const notify = () => { for (const fn of listeners) { try { fn() } catch (_) {} } }
2890
+ return {
2891
+ getState() {
2892
+ const { isValid, errors } = validateSettingsDraft(draftConfig)
2893
+ return {
2894
+ savedConfig,
2895
+ draftConfig,
2896
+ isDirty: isSettingsDraftDirty(savedConfig, draftConfig),
2897
+ isValid,
2898
+ errors,
2899
+ }
2900
+ },
2901
+ setSavedConfig(cfg) {
2902
+ savedConfig = cfg ? cloneSettingsObj(cfg) : null
2903
+ if (draftConfig === null && savedConfig !== null) {
2904
+ draftConfig = cloneSettingsObj(savedConfig)
2905
+ }
2906
+ notify()
2907
+ },
2908
+ patchDraft(key, val) {
2909
+ draftConfig = Object.assign({}, draftConfig || {}, { [key]: val })
2910
+ notify()
2911
+ return draftConfig
2912
+ },
2913
+ patchNestedDraft(mode, key, val) {
2914
+ const next = Object.assign({}, draftConfig || {})
2915
+ next[mode] = Object.assign({}, next[mode] || {}, { [key]: val })
2916
+ draftConfig = next
2917
+ notify()
2918
+ return draftConfig
2919
+ },
2920
+ reset() {
2921
+ draftConfig = savedConfig ? cloneSettingsObj(savedConfig) : null
2922
+ notify()
2923
+ return draftConfig
2924
+ },
2925
+ async commit(saveFn) {
2926
+ const st = this.getState()
2927
+ if (!st.isValid) {
2928
+ throw new Error(Object.values(st.errors)[0] || 'Invalid settings draft')
2929
+ }
2930
+ const prevSaved = savedConfig ? cloneSettingsObj(savedConfig) : null
2931
+ const nextSaved = await saveFn(cloneSettingsObj(draftConfig))
2932
+ savedConfig = cloneSettingsObj(nextSaved || draftConfig)
2933
+ draftConfig = cloneSettingsObj(savedConfig)
2934
+ notify()
2935
+ return { savedConfig, prevSaved }
2936
+ },
2937
+ subscribe(fn) {
2938
+ listeners.add(fn)
2939
+ return () => listeners.delete(fn)
2940
+ },
2941
+ }
2942
+ }
2768
2943
  const BUILTIN = [
2769
2944
  'browser', 'browser-webgpu', 'deepgram', 'groq', 'hf', 'local-whisper', 'sensevoice',
2770
2945
  'openai', 'siliconflow', 'deepinfra', 'fireworks', 'mistral', 'openrouter',
@@ -3821,28 +3996,27 @@ const whisperRunning = props.whisperRunning
3821
3996
  const providerCount = props.providerCount
3822
3997
  const onRefresh = props.onRefresh
3823
3998
  const onOpenWizard = props.onOpenWizard
3824
- return h('div', { className: 'cb-section-card' },
3825
- h('div', { className: 'cb-section-title' },
3826
- h('span', null, t('statusTitle')),
3827
- h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center' } },
3828
- onOpenWizard ? h('button', {
3829
- type: 'button', className: 'cb-btn cb-btn-primary', style: { fontSize: '12px', padding: '4px 10px' },
3999
+ return h(UiSectionCard, {
4000
+ title: t('statusTitle'),
4001
+ actions: h('div', { style: { display: 'flex', gap: DESIGN_TOKENS.space.sm, alignItems: 'center' } },
4002
+ onOpenWizard ? h(UiActionButton, {
4003
+ variant: 'primary', size: 'sm',
3830
4004
  onClick: onOpenWizard,
3831
4005
  }, 'โœจ ' + t('wizardBtnLaunch')) : null,
3832
- h('button', {
3833
- type: 'button', className: 'cb-btn', style: { fontSize: '12px', padding: '4px 8px' },
4006
+ h(UiActionButton, {
4007
+ size: 'sm',
3834
4008
  onClick: onRefresh,
3835
4009
  }, '๐Ÿ”„ ' + t('refreshStats')),
3836
4010
  ),
3837
- ),
3838
- h('div', { className: 'cb-row', style: { alignItems: 'center', gap: '12px', flexWrap: 'wrap' } },
3839
- h('span', { className: 'cb-badge ' + (hostOnline ? 'cb-badge-ok' : 'cb-badge-err') },
4011
+ },
4012
+ h('div', { className: 'cb-row', style: { alignItems: 'center', gap: DESIGN_TOKENS.space.md, flexWrap: 'wrap' } },
4013
+ h(UiStatusBadge, { status: hostOnline ? 'ok' : 'err' },
3840
4014
  hostOnline ? (`โœ“ ${t('hostOnline')} (${statusLatency} ${t('msShort')})`) : (`โœ— ${t('hostOffline')}`)
3841
4015
  ),
3842
- h('span', { className: 'cb-badge ' + (whisperRunning ? 'cb-badge-ok' : 'cb-badge-warn') },
4016
+ h(UiStatusBadge, { status: whisperRunning ? 'ok' : 'warn' },
3843
4017
  whisperRunning ? (`โœ“ ${t('whisperReady')}`) : (`ยท ${t('whisperStopped')}`)
3844
4018
  ),
3845
- h('span', { className: 'cb-badge' }, `${providerCount} ${t('providersAvailable')}`),
4019
+ h(UiStatusBadge, { status: 'neutral' }, `${providerCount} ${t('providersAvailable')}`),
3846
4020
  ),
3847
4021
  )
3848
4022
  }
@@ -3996,16 +4170,25 @@ try { return structuredClone(obj) } catch (e) { /* fallback */ }
3996
4170
  }
3997
4171
  try { return JSON.parse(JSON.stringify(obj)) } catch (e) { return Object.assign({}, obj) }
3998
4172
  }
3999
- const setTop = (key, val) => {
4173
+ const draftValidation = validateSettingsDraft(draft)
4174
+ const isDirty = isSettingsDraftDirty(serverConfig || value, draft)
4175
+ const isValid = draftValidation.isValid
4176
+ const patchDraft = (key, val) => {
4000
4177
  setDraft((d) => Object.assign({}, d || {}, { [key]: val }))
4001
4178
  }
4002
- const setIn = (mode, key, val) => {
4179
+ const patchNestedDraft = (mode, key, val) => {
4003
4180
  setDraft((d) => {
4004
4181
  const next = Object.assign({}, d || {})
4005
4182
  next[mode] = Object.assign({}, next[mode] || {}, { [key]: val })
4006
4183
  return next
4007
4184
  })
4008
4185
  }
4186
+ const resetDraft = () => {
4187
+ setDraft(deepClone(serverConfig || value))
4188
+ setErr('')
4189
+ }
4190
+ const setTop = patchDraft
4191
+ const setIn = patchNestedDraft
4009
4192
  const textField = (key, label, hint) => h('div', { className: 'cb-field' },
4010
4193
  h('label', null, label),
4011
4194
  h('input', {
@@ -4434,7 +4617,8 @@ onCheck: checkUpdater,
4434
4617
  onUpdateNow: onUpdateNow,
4435
4618
  }),
4436
4619
  h('div', { className: 'cb-row' },
4437
- h('button', { type: 'button', className: 'cb-btn cb-btn-primary', disabled: !writable, onClick: save }, t('save')),
4620
+ h(UiActionButton, { variant: 'primary', disabled: !writable || !isValid, onClick: save }, t('save')),
4621
+ isDirty ? h(UiActionButton, { disabled: !writable, onClick: resetDraft }, t('cancel')) : null,
4438
4622
  saved ? h('span', { className: 'dvs-ok' }, t('saved')) : null,
4439
4623
  err ? h('span', { className: 'dvs-bad' }, err) : null,
4440
4624
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-voice",
3
- "version": "0.9.50",
3
+ "version": "0.9.51",
4
4
  "description": "Voice input for DeepSeek Harness: dictation chunked by pauses and voice messages, each with its own provider fallback chain (Deepgram, Groq, HuggingFace, local whisper.cpp, plus any OpenAI-compatible API of your own).",
5
5
  "license": "MIT",
6
6
  "type": "module",