Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/** Setting the banner writes when a voice chip is picked. */
const
VOICE_SETTING
=
'agents.voice.voice'
;
/** Setting that controls the language Voice Mode speaks. */
const
VOICE_LANGUAGE_SETTING
=
'agents.voice.language'
;
/** Where the first link sends anyone who wants to change their mind later. */
const
VOICE_SETTINGS_COMMAND
=
'agentsVoice.openSettings'
;
type
VoiceModeOnboardingAction
=
'shown'
|
'selectVoice'
|
'previewVoice'
|
'selectMicrophone'
|
'openSettings'
|
'openInstructions'
|
'close'
|
'escape'
;
type
VoiceModeOnboardingActionClassification
=
{
:
{
:
'PublicNonPersonalData'
;
:
'FeatureInsight'
;
:
'The action taken in the Voice Mode onboarding card.'
}
;
:
{
:
'PublicNonPersonalData'
;
:
'FeatureInsight'
;
:
'Whether the card appeared automatically on first use or was opened manually.'
}
;
:
'meganrogge'
;
:
'Tracks engagement with the Voice Mode onboarding card.'
;
}
;
type
VoiceModeOnboardingActionEvent
=
{
:
;
:
'automatic'
|
'manual'
;
}
;
/**
* The voices Voice Mode actually speaks with (mirrors the `agents.voice.voice`
* enum). Each one ships a short pre-recorded sample rendered with that exact
* model voice, so the preview a user hears in the banner is what they get in a
* real conversation.
*/
interface
IVoiceModeVoice
{
readonly
:
string
;
readonly
:
string
;
readonly
:
string
;
/** This voice's waveform texture. See {@link IWave}. */
readonly
:
readonly
[
]
;
}
/**
* One sine component of a waveform texture. A voice's signature is a handful of
* these summed together, which is what gives each voice a recognisably
* different trace rather than four copies of the same ripple.
*/
interface
IWave
{
readonly
:
number
;
readonly
:
number
;
readonly
:
number
;
readonly
:
number
;
}
const
VOICES
:
readonly
[
]
=
[
{
:
'birch_neutral'
,
:
'maya_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.birch'
,
"Birch (Default)"
)
,
// Flowing mid-range: even spread, gentle drift.
:
[
{
:
1.0
,
:
0.42
,
:
0.42
,
:
0.0
}
,
{
:
1.7
,
:
0.26
,
:
-
0.31
,
:
1.1
}
,
{
:
2.6
,
:
0.19
,
:
0.24
,
:
2.4
}
,
{
:
4.1
,
:
0.13
,
:
-
0.18
,
:
0.7
}
,
]
,
}
,
{
:
'harper_neutral'
,
:
'victoria_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.harper'
,
"Harper"
)
,
// Bright and quick: higher frequencies, tighter ripple.
:
[
{
:
1.4
,
:
0.38
,
:
0.52
,
:
0.0
}
,
{
:
2.3
,
:
0.27
,
:
-
0.38
,
:
1.1
}
,
{
:
3.6
,
:
0.21
,
:
0.30
,
:
2.4
}
,
{
:
5.2
,
:
0.14
,
:
-
0.22
,
:
0.7
}
,
]
,
}
,
{
:
'oak_neutral'
,
:
'kevin_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.oak'
,
"Oak"
)
,
// Low and broad: long swells with little high-frequency detail.
:
[
{
:
0.7
,
:
0.48
,
:
0.30
,
:
0.4
}
,
{
:
1.2
,
:
0.28
,
:
-
0.22
,
:
1.7
}
,
{
:
2.0
,
:
0.16
,
:
0.18
,
:
0.9
}
,
{
:
3.1
,
:
0.09
,
:
-
0.14
,
:
2.2
}
,
]
,
}
,
{
:
'junho_neutral'
,
:
'daniel_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.junho'
,
"Junho"
)
,
// Steady and measured: slow drift, calm regular crests.
:
[
{
:
0.9
,
:
0.44
,
:
0.24
,
:
1.3
}
,
{
:
1.5
,
:
0.30
,
:
-
0.18
,
:
0.2
}
,
{
:
2.4
,
:
0.14
,
:
0.15
,
:
2.0
}
,
{
:
3.4
,
:
0.10
,
:
-
0.12
,
:
1.5
}
,
]
,
}
,
]
;
/**
* A language Voice Mode speaks natively, and the single voice its backend uses
* for that language. Choosing between voices is an English-only affordance, so
* for these languages the card previews this one voice rather than the four
* English options.
*/
interface
ILocalizedVoice
{
readonly
:
string
;
readonly
:
string
;
}
const
LOCALIZED_VOICES
:
<
<
string
,
>>
=
{
:
{
:
'de_marc_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.marc'
,
"Marc"
)
}
,
:
{
:
'es-ES_maria_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.maria'
,
"Maria"
)
}
,
:
{
:
'fr_david_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.david'
,
"David"
)
}
,
:
{
:
'it_eva_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.eva'
,
"Eva"
)
}
,
:
{
:
'ja_aruha_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.aruha'
,
"Aruha"
)
}
,
:
{
:
'ko_jiyon_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.jiyon'
,
"Jiyon"
)
}
,
:
{
:
'pt-BR_gil_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.gil'
,
"Gil"
)
}
,
:
{
:
'zh_wuzhi_neutral'
,
:
localize
(
'voiceMode.onboarding.voice.wuzhi'
,
"Wuzhi"
)
}
,
}
;
/**
* The native voice for a spoken language, or `undefined` when the language has
* no native voice and the card should fall back to the English voice chooser.
*/
function
localizedVoiceForLanguage
(
:
string
)
:
|
undefined
{
try
{
const
=
.
getCanonicalLocales
(
.
trim
(
)
)
[
0
]
;
const
=
?.
split
(
'-'
)
[
0
]
.
toLowerCase
(
)
;
return
?
LOCALIZED_VOICES
[
]
:
undefined
;
}
catch
{
return
undefined
;
}
}
/**
* The trace before anyone has chosen: the four signatures averaged component by
* component, so it belongs to no voice in particular rather than quietly being
* the first one in the list. The declared phases all sit within a couple of
* radians of each other, so a plain mean lands between them rather than on the
* far side of the circle.
*/
const
RESTING_SIGNATURE
:
readonly
[
]
=
VOICES
[
0
]
.
.
map
(
(
,
)
=>
{
const
=
VOICES
.
map
(
=>
.
[
]
)
;
const
mean
=
(
pick
:
(
:
)
=>
number
)
=>
.
reduce
(
(
,
)
=>
+
pick
(
)
,
0
)
/
.
;
return
{
:
mean
(
=>
.
)
,
:
mean
(
=>
.
)
,
:
mean
(
=>
.
)
,
:
mean
(
=>
.
)
,
}
;
}
)
;
/**
* How long the dominant component takes to complete one cycle, matching the
* `chat-voice-input-mode-wave` keyframe the toolbar waveform idles on. Same
* instrument, same tempo.
*/
const
IDLE_CYCLE_SECONDS
=
2.6
;
/**
* Scales every declared `speed` so the resting trace cycles at
* {@link IDLE_CYCLE_SECONDS}. The signatures are written as a *relative* set -
* component 1 drifts against component 0, and so on - which makes them
* readable, but taken literally the dominant component turns once every ~17
* seconds. That is roughly 1px of movement per bar per second: technically
* animating, visibly frozen. Derived rather than hardcoded so editing a
* signature cannot silently put the trace back to sleep.
*/
/** Amplitude with nothing playing: present, but clearly at rest. */
const
IDLE_GAIN
=
0.5
;
/**
* Extra amplitude at peak loudness. Matched to the dictation card's waveform so
* the trace clearly swells with the voice being previewed rather than only
* nudging - the card's job is to let you hear (and see) each voice, and a trace
* that answers the sample reads as responding to it.
*/
const
SPEAKING_GAIN
=
0.45
;
/**
* How much of the travelling motion is always present, versus driven by the
* sample. At rest the trace drifts slowly - alive, not frozen - and it flows in
* earnest only while a voice plays, so the movement itself reads as a response to
* the voice you just picked rather than idle decoration.
*/
const
IDLE_MOTION
=
0.2
;
/** Additional travelling speed at peak loudness, on top of {@link IDLE_MOTION}. */
const
SPEAKING_MOTION
=
0.8
;
/**
* How quickly the band chases the audio, per {@link REFERENCE_FRAME_SECONDS}.
* Low and slow reads as smooth.
*/
const
LEVEL_EASING
=
0.08
;
/**
* How quickly the trace morphs from one voice's signature to another, per
* {@link REFERENCE_FRAME_SECONDS}.
*/
const
SIGNATURE_EASING
=
0.06
;
/**
* The frame duration the eased constants above are tuned against (60fps). Easing
* and the phase advance are scaled by the real elapsed time each frame so the
* motion runs at the same real-time pace whether frames arrive on time or stutter
* - which they do while a sample plays and the per-frame analyser read competes
* for the main thread. Scaling by real time (rather than a fixed per-frame step)
* is what keeps the trace moving at full speed under that load instead of stalling.
*/
const
REFERENCE_FRAME_SECONDS
=
1
/
60
;
/**
* Bar metrics, taken from Voice Mode's own waveform in `voiceInputMode.css`,
* which states the rule directly: *bars are strokes, not shapes* - they carry
* the same visual weight as the codicon glyphs beside them so the waveform
* never reads as bolder than the mic. Same 1px stroke and 2px gap here, just
* many more of them.
*/
const
BAR_WIDTH
=
1
;
const
BAR_GAP
=
2
;
/** Shortest a bar ever gets: a dot, so a resting bar keeps its round cap. */
const
BAR_MIN
=
1
;
/** A signature component with an incrementally accumulated animation phase. */
type
MutableWave
=
{
:
number
;
:
number
;
:
number
;
:
number
;
:
number
}
;
function
cloneSignature
(
:
readonly
[
]
)
:
[
]
{
return
.
map
(
=>
(
{
...
,
:
0
}
)
)
;
}
/**
* Convert a per-{@link REFERENCE_FRAME_SECONDS} easing constant into the fraction
* to ease by across `dt` seconds, so the morph settles at the same real-time rate
* regardless of frame rate. Reduces to the raw constant when `dt` is exactly one
* reference frame.
*/
function
easingFactor
(
:
number
,
:
number
)
:
number
{
return
1
-
.
pow
(
1
-
,
/
REFERENCE_FRAME_SECONDS
)
;
}
/**
* Ease a signature towards a target in place. Morphing the numbers rather than
* swapping them is what makes a voice change read as the trace *becoming* the
* new voice instead of cutting to it.
*
* `phase` eases with the rest: it is a static offset per component (the motion
* comes from the accumulated `oscillation`), so leaving it behind would strand
* every voice on whichever phases the trace happened to start with. Every declared
* phase sits within a radian or two of its neighbours, well inside half a turn, so
* easing straight to the target is also the shortest way round the circle.
*
* `oscillation` is deliberately left untouched: it is where the component is in its
* cycle, not part of the target texture, so it keeps flowing across the morph.
*/
function
easeSignature
(
:
[
]
,
:
readonly
[
]
,
:
number
)
:
void
{
for
(
let
=
0
;
<
.
&&
<
.
;
++
)
{
[
]
.
+=
(
[
]
.
-
[
]
.
)
*
;
[
]
.
+=
(
[
]
.
-
[
]
.
)
*
;
[
]
.
+=
(
[
]
.
-
[
]
.
)
*
;
[
]
.
+=
(
[
]
.
-
[
]
.
)
*
;
}
}
/**
* Advance each component's accumulated animation phase by the current speed over
* `dt` seconds, wrapping to keep it bounded over long sessions. Because this only
* ever adds to `oscillation`, changing `speed` mid-morph bends the motion smoothly
* instead of teleporting it.
*/
function
advanceOscillation
(
:
readonly
[
]
,
:
number
)
:
void
{
const
=
2
*
.
PI
;
for
(
const
of
)
{
.
=
(
.
+
.
*
WAVE_TEMPO
*
)
%
;
}
}
/**
* Draw the row of bars. Heights are symmetric about the centre line and follow
* a centre-peak silhouette so the trace reads as one instrument rather than a
* strip of unrelated levels.
*/
function
drawBars
(
:
,
:
number
,
:
number
,
:
readonly
[
]
,
:
number
,
)
:
void
{
const
=
BAR_WIDTH
+
BAR_GAP
;
const
=
.
max
(
1
,
.
floor
(
/
)
)
;
// Centre the row: whatever does not divide evenly becomes even margins
// rather than a ragged right edge.
const
=
(
-
(
*
-
BAR_GAP
)
)
/
2
;
const
=
/
2
;
const
=
/
2
;
for
(
let
=
0
;
<
;
++
)
{
const
=
>
1
?
/
(
-
1
)
:
0
;
const
=
bandFraction
(
,
)
*
;
const
=
.
max
(
BAR_MIN
/
2
,
.
min
(
,
*
)
)
;
.
beginPath
(
)
;
.
roundRect
(
+
*
,
-
,
BAR_WIDTH
,
*
2
,
BAR_WIDTH
/
2
)
;
.
fill
(
)
;
}
}
/**
* Half-height of the band at `position` (0..1 across the strip), as a fraction
* of the available half-height.
*
* Each component contributes an already-positive, cusp-free curve. Summing raw
* sines and taking their magnitude would put a sharp corner at every zero
* crossing - that is what makes an ASCII waveform look like it is snapping up
* and down rather than flowing.
*/
function
bandFraction
(
:
number
,
:
readonly
[
]
)
:
number
{
let
=
0
;
let
=
0
;
for
(
const
of
)
{
const
=
*
.
*
.
PI
*
2
+
.
+
.
;
+=
(
0.5
+
0.5
*
.
sin
(
)
)
*
.
;
+=
.
;
}
if
(
===
0
)
{
return
0
;
}
// Centre-peak silhouette: tallest in the middle and tapering to the ends, so
// the row reads as one instrument rather than a strip cut off at both edges.
const
=
.
sin
(
.
PI
*
.
min
(
1
,
.
max
(
0
,
)
)
)
;
return
(
/
)
*
(
0.35
+
0.65
*
)
;
}
/** What the animator needs to know each frame, supplied by the banner. */
interface
IWaveformSource
{
/** Loudness of the voice being previewed, `0` when silent. */
getLevel
(
)
:
number
;
/** The signature the trace should be easing towards. */
getSignature
(
)
:
readonly
[
]
;
}
/**
* Draws the animated waveform. Owns a single canvas, a `ResizeObserver` and an
* animation-frame loop; disposing stops both. Honors reduced motion by painting
* a single static frame instead of animating.
*/
class
VoiceModeOnboardingAnimator
extends
Disposable
{
private
readonly
:
;
private
readonly
=
this
.
_register
(
new
MutableDisposable<IDisposable>
(
)
)
;
private
=
0
;
private
=
0
;
private
=
false
;
private
=
false
;
private
=
0
;
/** Timestamp of the previous frame, for the elapsed-time each draw eases over. */
private
:
number
|
undefined
;
private
readonly
:
[
]
;
/**
* The stroke colour, taken from the canvas's own computed `color` so CSS
* owns the tier and theme overrides work for free - the same `currentColor`
* arrangement the toolbar waveform uses. Cached rather than read per frame:
* `getComputedStyle` inside the animation loop forces a style recalculation
* on every tick.
*/
private
=
''
;
constructor
(
private
readonly
:
,
private
readonly
:
,
private
readonly
:
,
@IThemeService
private
readonly
:
,
@IAccessibilityService
private
readonly
:
,
)
{
super
(
)
;
const
=
.
getContext
(
'2d'
)
;
if
(
!
)
{
throw
new
Error
(
'Failed to create the Voice Mode onboarding canvas context'
)
;
}
this
.
=
;
this
.
=
cloneSignature
(
this
.
.
getSignature
(
)
)
;
const
=
.
getWindow
(
)
;
const
=
new
targetWindow
.
ResizeObserver
(
(
)
=>
this
.
resize
(
)
)
;
.
observe
(
)
;
this
.
_register
(
toDisposable
(
(
)
=>
.
disconnect
(
)
)
)
;
this
.
_register
(
this
.
.
onDidColorThemeChange
(
(
)
=>
{
this
.
readStroke
(
)
;
this
.
draw
(
.
.
now
(
)
)
;
}
)
)
;
this
.
_register
(
this
.
.
onDidChangeReducedMotion
(
(
)
=>
this
.
updateMotion
(
)
)
)
;
this
.
_register
(
toDisposable
(
(
)
=>
this
.
stop
(
)
)
)
;
this
.
readStroke
(
)
;
this
.
resize
(
)
;
this
.
updateMotion
(
)
;
}
private
readStroke
(
)
:
void
{
this
.
=
.
getWindow
(
this
.
)
.
getComputedStyle
(
this
.
)
.
;
}
private
updateMotion
(
)
:
void
{
if
(
this
.
||
this
.
.
isMotionReduced
(
)
)
{
this
.
stop
(
)
;
this
.
draw
(
.
getWindow
(
this
.
)
.
.
now
(
)
)
;
}
else
{
this
.
start
(
)
;
}
}
/**
* Pause while the card is put away for higher-precedence content, so an
* invisible introduction is not still painting every frame.
*/
setSuspended
(
:
boolean
)
:
void
{
if
(
this
.
===
)
{
return
;
}
this
.
=
;
this
.
updateMotion
(
)
;
}
private
start
(
)
:
void
{
if
(
this
.
)
{
return
;
}
this
.
=
true
;
const
=
.
getWindow
(
this
.
)
;
const
tick
=
(
:
number
)
=>
{
if
(
!
this
.
)
{
return
;
}
this
.
draw
(
)
;
this
.
.
=
.
scheduleAtNextAnimationFrame
(
,
(
)
=>
tick
(
.
.
now
(
)
)
)
;
}
;
this
.
.
=
.
scheduleAtNextAnimationFrame
(
,
(
)
=>
tick
(
.
.
now
(
)
)
)
;
}
private
stop
(
)
:
void
{
this
.
=
false
;
this
.
.
clear
(
)
;
}
private
resize
(
)
:
void
{
const
=
.
getWindow
(
this
.
)
;
const
=
.
||
1
;
this
.
=
this
.
.
;
this
.
=
this
.
.
;
if
(
!
this
.
||
!
this
.
)
{
return
;
}
this
.
.
=
this
.
*
;
this
.
.
=
this
.
*
;
this
.
.
setTransform
(
,
0
,
0
,
,
0
,
0
)
;
this
.
draw
(
.
.
now
(
)
)
;
}
private
draw
(
:
number
)
:
void
{
if
(
!
this
.
||
!
this
.
)
{
return
;
}
// Real time elapsed since the previous frame. Both the easing and the phase
// advance scale by this, so the trace keeps its real-time speed whether
// frames arrive at 60fps or drop while a sample plays - rather than slowing
// down under the extra load. A big gap (a hitch, or a backgrounded tab that
// paused the loop) simply advances the trace to where it should be: the
// phase is periodic and the easing factor stays bounded, so there is no
// lurch to guard against.
const
=
this
.
===
undefined
?
0
:
.
max
(
0
,
(
-
this
.
)
*
0.001
)
;
this
.
=
;
// Idle, the waveform drifts gently; while a voice plays it flows and swells
// with that voice. Both the level and the shape are eased so the ribbon
// glides rather than snapping between frames.
this
.
+=
(
this
.
.
getLevel
(
)
-
this
.
)
*
easingFactor
(
LEVEL_EASING
,
)
;
easeSignature
(
this
.
,
this
.
.
getSignature
(
)
,
easingFactor
(
SIGNATURE_EASING
,
)
)
;
// Drive the travelling motion from the sample: nearly still at rest, flowing
// while a voice plays, so the movement reads as a response to the previewed
/**
* Plays the pre-recorded voice samples that ship next to this file. One element
* is reused for every preview so picking a second voice cuts the first one off.
*/
class
VoiceSamplePlayer
extends
Disposable
{
private
readonly
=
this
.
_register
(
new
MutableDisposable<DisposableStore>
(
)
)
;
/** Reused across previews: a media element source can only be created once
* per element, so the element, context and analyser are all long-lived. */
private
:
|
undefined
;
private
:
|
undefined
;
private
:
<
>
|
undefined
;
private
readonly
=
this
.
_register
(
new
Emitter<string|undefined>
(
)
)
;
/** Fires with the voice currently being heard, or `undefined` once it stops. */
readonly
=
this
.
.
;
private
:
string
|
undefined
;
get
playingVoice
(
)
:
string
|
undefined
{
return
this
.
;
}
constructor
(
private
readonly
:
,
private
readonly
:
(
(
)
=>
)
|
undefined
,
@ILogService
private
readonly
:
,
)
{
super
(
)
;
this
.
_register
(
toDisposable
(
(
)
=>
this
.
stop
(
)
)
)
;
}
/**
* Current loudness of the sample being played, `0` when silent. The waveform
* reads this so it moves to the voice the user is actually hearing.
*/
getLevel
(
)
:
number
{
if
(
!
this
.
||
!
this
.
||
!
this
.
)
{
return
0
;
}
this
.
.
getByteTimeDomainData
(
this
.
)
;
let
=
0
;
for
(
const
of
this
.
)
{
const
=
(
-
128
)
/
128
;
+=
*
;
}
// RMS, scaled so ordinary speech lands near 1 rather than a fraction.
/**
* Build the audio element and, best-effort, the analyser graph feeding the
* waveform. Analysis is a nicety: if the Web Audio graph cannot be created
* the sample still plays, the waveform just keeps its idle motion.
*/
/** Allows tests to provide a deterministic media element. */
readonly
?
:
(
)
=>
;
/** Allows tests to provide a deterministic spoken language. */
readonly
?
:
string
;
}
/** A rendered voice option, with the strings its play state swaps between. */
interface
IVoiceElement
{
readonly
:
;
readonly
:
string
;
readonly
:
string
;
}
/**
* The first-run Voice Mode card: what Voice Mode is, that it costs nothing, the
* voices it can speak with, and the mic as the alternative for anyone who would
* rather not be spoken to at all.
*
* Clicking a voice both plays it and adopts it, so there is nothing to confirm
* afterwards. The leading icon carries that story: play before the click,
* animating bars while it speaks, then a check once it is yours.
*/
export
class
VoiceModeOnboardingBanner
extends
ChatInputNoticeWidget
implements
IChatInputOnboardingBanner
{
private
readonly
:
;
private
:
|
undefined
;
private
readonly
:
;
private
readonly
=
this
.
_register
(
new
MutableDisposable<DisposableStore>
(
)
)
;
private
:
[
]
=
[
]
;
private
:
|
undefined
;
private
readonly
=
new
Map<string, IVoiceElement>
(
)
;
/** Where the voice chips live, so they can be re-rendered on a language change. */
private
:
|
undefined
;
/** Listeners for the current set of voice chips, cleared when they re-render. */
private
readonly
=
this
.
_register
(
new
DisposableStore
(
)
)
;
/** The native voice for the spoken language, when one exists. */
private
:
|
undefined
;
/** The voice being auditioned, and the one that will be committed. */
private
:
|
undefined
;
constructor
(
:
,
@ICommandService
private
readonly
:
,
@IConfigurationService
private
readonly
:
,
@IContextViewService
private
readonly
:
,
@IInstantiationService
:
,
@ILogService
private
readonly
:
,
@IStorageService
private
readonly
:
,
@ITelemetryService
private
readonly
:
,
)
{
super
(
{
:
.
,
:
.
,
:
'voice-mode-onboarding-banner'
,
:
localize
(
'voiceMode.onboarding.region'
,
"Voice Mode introduction"
)
,
:
localize
(
'voiceMode.onboarding.regionDescription'
,
"Choose how your agent speaks to you. Adjust settings anytime."
/**
* The voices as real buttons - border, hover lift, pressed feedback -
* because bare text gave no sign it could be clicked at all. In a language
* Voice Mode speaks natively there is only one voice, so the card previews
* that voice instead of offering the English chooser.
*
* Re-entrant: clears any previously rendered chips so the card can rebuild
* them when the spoken language changes.
*/
private
renderVoices
(
)
:
void
{
const
=
this
.
;
if
(
!
)
{
return
;
}
this
.
.
clear
(
)
;
this
.
.
clear
(
)
;
.
clearNode
(
)
;
const
=
localize
(
'voiceMode.onboarding.voices'
,
"Agent Voice:"
)
;
const
=
.
append
(
,
.
$
(
'.voice-mode-onboarding-voices-label'
)
)
;
.
=
;
if
(
this
.
)
{
this
.
renderLocalizedVoice
(
,
,
this
.
)
;
return
;
}
const
=
.
append
(
,
.
$
(
'.voice-mode-onboarding-voices'
)
)
;
.
setAttribute
(
'role'
,
'radiogroup'
)
;
.
setAttribute
(
'aria-label'
,
)
;
for
(
const
of
VOICES
)
{
const
=
.
append
(
,
.
$
(
'.voice-mode-onboarding-voice'
)
)
;
.
setAttribute
(
'role'
,
'radio'
)
;
const
=
localize
(
'voiceMode.onboarding.voice.ariaLabel'
,
"{0}. Hear this voice and use it for every conversation."
,
.
)
;
.
setAttribute
(
'aria-label'
,
)
;
this
.
appendVoiceIcon
(
)
;
const
=
.
append
(
,
.
$
(
'span.voice-mode-onboarding-voice-label'
)
)
;
.
=
.
;
this
.
.
set
(
.
,
{
:
,
:
.
,
}
)
;
this
.
.
add
(
.
addDisposableListener
(
,
.
.
CLICK
,
(
)
=>
this
.
selectVoice
(
)
)
)
;
this
.
.
add
(
.
addDisposableListener
(
,
.
.
KEY_DOWN
,
=>
this
.
handleOptionKey
(
,
)
)
)
;
}
this
.
updateSelection
(
)
;
}
/**
* The spoken language changed, so swap the chips: the four English voices
* for a native language's single voice, or back again. Nothing is carried
* over - a voice chosen for the old language means nothing for the new one.
*/
private
updateForLanguage
(
)
:
void
{
const
=
localizedVoiceForLanguage
(
this
.
resolveSpokenLanguage
(
)
)
;
if
(
?.
===
this
.
?.
)
{
return
;
}
const
=
this
.
?
.
isAncestorOfActiveElement
(
this
.
)
:
false
;
this
.
.
stop
(
)
;
this
.
=
;
this
.
=
undefined
;
this
.
renderVoices
(
)
;
if
(
)
{
this
.
.
values
(
)
.
next
(
)
.
?.
.
focus
(
)
;
}
}
/**
* The single native voice for the spoken language, as a preview button:
* there is nothing to choose, so it only ever plays and stops.
*/
private
renderLocalizedVoice
(
:
,
:
string
,
:
)
:
void
{
const
=
.
append
(
,
.
$
(
'.voice-mode-onboarding-voices'
)
)
;
.
setAttribute
(
'aria-label'
,
)
;
const
=
.
append
(
,
.
$
(
'.voice-mode-onboarding-voice'
)
)
;
.
setAttribute
(
'role'
,
'button'
)
;
.
=
0
;
const
=
localize
(
'voiceMode.onboarding.voice.previewAriaLabel'
,
"{0}. Hear how your agent will sound."
,
.
)
;
.
setAttribute
(
'aria-label'
,
)
;
this
.
appendVoiceIcon
(
)
;
const
=
.
append
(
,
.
$
(
'span.voice-mode-onboarding-voice-label'
)
)
;
.
=
.
;
this
.
.
set
(
.
,
{
:
,
:
.
,
}
)
;
this
.
.
add
(
.
addDisposableListener
(
,
.
.
CLICK
,
(
)
=>
this
.
previewLocalizedVoice
(
)
)
)
;
this
.
.
add
(
.
addDisposableListener
(
,
.
.
KEY_DOWN
,
=>
{
const
=
new
StandardKeyboardEvent
(
)
;
if
(
.
equals
(
.
)
||
.
equals
(
.
)
)
{
.
preventDefault
(
)
;
this
.
previewLocalizedVoice
(
)
;
}
}
)
)
;
}
/**
* The icon is the affordance: it says "this will speak" before the click,
* animating bars while it speaks, then a check once a voice is chosen.
*/
// A radiogroup is a single tab stop: the arrow keys move between the
// options (selecting as they go, as a radio group should) rather than Tab
// walking through every one of them.
const
=
.
equals
(
.
)
||
.
equals
(
.
)
;
const
=
.
equals
(
.
)
||
.
equals
(
.
)
;
if
(
||
)
{
.
preventDefault
(
)
;
const
=
VOICES
.
indexOf
(
)
;
const
=
VOICES
[
(
+
(
?
1
:
VOICES
.
-
1
)
)
%
VOICES
.
]
;
this
.
selectVoice
(
)
;
this
.
.
get
(
.
)
?.
.
focus
(
)
;
}
}
/**
* One short paragraph: what Voice Mode does, and where to change its
* settings or instructions.
*
* `[[...]]` marks each clause that becomes a link, so translators can place
* it naturally in the sentence instead of receiving a fixed phrase
* concatenated onto the end.
*/
'Preserve the double square brackets: they mark the text that becomes a link. Keep both links, in this order - the first opens Voice Mode settings, the second opens the voice.md customization file.'
,
]
,
}
,
"Choose how your agent speaks to you. Adjust [[settings]] or [[how it's written]] anytime."
)
;
.
append
(
,
renderFormattedText
(
,
{
:
{
callback
:
=>
{
const
=
===
'0'
?
VOICE_SETTINGS_COMMAND
:
CONFIGURE_VOICE_INSTRUCTIONS_ACTION_ID
;
this
.
logAction
(
===
'0'
?
'openSettings'
:
'openInstructions'
)
;
this
.
.
executeCommand
(
)
.
catch
(
=>
this
.
.
error
(
`[voice] Failed to run ${commandId}: ${error}`
)
)
;
}
,
:
this
.
,
}
,
}
,
.
$
(
'span'
)
)
)
;
// `renderFormattedText` gives each anchor a click listener and nothing
// else, so make them real controls: reachable by Tab and operable by
// Enter or Space like any other button. The renderer owns this DOM, so a
// selector is the only handle on it - same as the empty-editor hint.
// eslint-disable-next-line no-restricted-syntax
for
(
const
of
.
querySelectorAll
(
'a'
)
)
{
.
=
0
;
.
setAttribute
(
'role'
,
'button'
)
;
this
.
_register
(
.
addDisposableListener
(
,
.
.
KEY_DOWN
,
=>
{
const
=
new
StandardKeyboardEvent
(
)
;
if
(
.
equals
(
.
)
||
.
equals
(
.
)
)
{
.
preventDefault
(
)
;
.
click
(
)
;
}
}
)
)
;
}
}
/**
* Dismissal is always available and never gated: a disabled close would trap
* someone in the card. Choosing a voice already commits it, so this is only
* ever "I am done here" - and closing is what hands the session back.
*/
private
renderClose
(
)
:
void
{
this
.
addDismissAction
(
{
:
'voice-mode-onboarding-close'
,
:
localize
(
'voiceMode.onboarding.close'
,
"Close the introduction"
)
,
onActivate
:
(
)
=>
this
.
finish
(
)
,
}
)
;
}
/**
* Stops the sample and the waveform while the card is put away for a
* notification, so an invisible introduction is not still playing audio or
* painting every frame.
*/
setVisible
(
:
boolean
)
:
void
{
super
.
setVisible
(
)
;
this
.
?.
setSuspended
(
!
)
;
if
(
!
)
{
this
.
.
stop
(
)
;
}
}
private
selectVoice
(
:
)
:
void
{
if
(
this
.
.
===
.
)
{
this
.
.
stop
(
)
;
status
(
localize
(
'voiceMode.onboarding.voice.previewStopped'
,
"{0} preview stopped."
,
.
)
)
;
return
;
}
this
.
logAction
(
'selectVoice'
)
;
this
.
=
;
this
.
updateSelection
(
)
;
this
.
.
play
(
.
,
.
)
;
status
(
localize
(
'voiceMode.onboarding.voice.selected'
,
"{0} selected."
,
.
)
)
;
this
.
.
updateValue
(
VOICE_SETTING
,
.
,
.
USER
)
.
catch
(
=>
this
.
.
error
(
`[voice] Failed to persist the Voice Mode voice: ${error}`
)
)
;
}
/**
* The localized voice is not a choice - it is the only voice for the
* language - so previewing it just plays and stops, and never persists.
*/
private
previewLocalizedVoice
(
:
)
:
void
{
if
(
this
.
.
===
.
)
{
this
.
.
stop
(
)
;
status
(
localize
(
'voiceMode.onboarding.voice.localizedStopped'
,
"{0} preview stopped."
,
.
)
)
;
return
;
}
this
.
logAction
(
'previewVoice'
)
;
this
.
.
play
(
.
)
;
status
(
localize
(
'voiceMode.onboarding.voice.localizedPlaying'
,
"Playing {0} preview."
,
.
)
)
;
}
/**
* The spoken language, mirroring the resolution the voice client uses: an
* explicit test override, then the configured language (unless `auto`), then
* the window's language.
*/
private
resolveSpokenLanguage
(
)
:
string
{
if
(
this
.
.
)
{
return
this
.
.
;
}
const
=
this
.
.
getValue<string>
(
VOICE_LANGUAGE_SETTING
)
?.
trim
(
)
;
if
(
&&
.
toLowerCase
(
)
!==
'auto'
)
{
return
;
}
return
.
getWindow
(
this
.
)
.
.
;
}
private
updateSelection
(
)
:
void
{
for
(
const
[
,
]
of
this
.
)
{
const
=
===
this
.
?.
;
.
.
.
toggle
(
'selected'
,
)
;
.
.
setAttribute
(
'aria-checked'
,
String
(
)
)
;
}
this
.
updateTabStop
(
)
;
}
/**
* Keeps a single tab stop on the group: the chosen voice, or the first one
* when nothing has been chosen yet.
*/