@codingame/monaco-vscode-chat-service-override 38.0.7 → 38.1.2
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/common.js +0 -53
- package/index.js +0 -3
- package/package.json +5 -5
- package/session.js +0 -3
- package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/missionControlAgentHostContribution.js +1 -1
- package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostActions.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostChatContribution.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.shared.contribution.js +6 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxSessionListController.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxSessionListController.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/editorCloudSandboxContribution.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/editorCloudSandboxContribution.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/missionControlEnvironmentActions.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/remoteAgentHost.contribution.js +7 -7
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/remoteAgentHostChatContribution.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewTitleControl.js +1 -1
- package/vscode/src/vs/platform/agentHost/browser/webPubSubRelayTransport.d.ts +0 -135
- package/vscode/src/vs/platform/agentHost/browser/webPubSubRelayTransport.js +0 -510
- package/vscode/src/vs/platform/agentHost/common/agentModelNotices.d.ts +0 -22
- package/vscode/src/vs/platform/agentHost/common/agentModelNotices.js +0 -21
- package/vscode/src/vs/platform/agentHost/common/cloudSandboxAgentHost.d.ts +0 -273
- package/vscode/src/vs/platform/agentHost/common/cloudSandboxAgentHost.js +0 -61
- package/vscode/src/vs/platform/agentHost/common/meta/agentModelMeta.d.ts +0 -7
- package/vscode/src/vs/platform/agentHost/common/meta/agentModelMeta.js +0 -17
- package/vscode/src/vs/platform/agentHost/common/meta/copilotd/cloudSandboxProjectMeta.d.ts +0 -12
- package/vscode/src/vs/platform/agentHost/common/meta/copilotd/cloudSandboxProjectMeta.js +0 -48
- package/vscode/src/vs/platform/agentHost/common/meta/vscode/agentModelEnsembleMeta.d.ts +0 -8
- package/vscode/src/vs/platform/agentHost/common/meta/vscode/agentModelEnsembleMeta.js +0 -11
- package/vscode/src/vs/platform/agentHost/common/meta/vscode/agentModelPricing.d.ts +0 -114
- package/vscode/src/vs/platform/agentHost/common/meta/vscode/agentModelPricing.js +0 -141
- package/vscode/src/vs/platform/agentHost/common/taskEventReplay.d.ts +0 -48
- package/vscode/src/vs/platform/agentHost/common/taskEventReplay.js +0 -238
- package/vscode/src/vs/platform/agentHost/common/webPubSub/chunking.d.ts +0 -102
- package/vscode/src/vs/platform/agentHost/common/webPubSub/chunking.js +0 -260
- package/vscode/src/vs/platform/agentHost/common/webPubSub/framing.d.ts +0 -102
- package/vscode/src/vs/platform/agentHost/common/webPubSub/framing.js +0 -115
- package/vscode/src/vs/platform/agentHost/common/webPubSub/groups.d.ts +0 -46
- package/vscode/src/vs/platform/agentHost/common/webPubSub/groups.js +0 -92
- package/vscode/src/vs/sessions/contrib/chat/browser/newSession.d.ts +0 -9
- package/vscode/src/vs/sessions/contrib/chat/browser/voiceBridge.contribution.d.ts +0 -14
- package/vscode/src/vs/sessions/contrib/chat/browser/voiceBridge.contribution.js +0 -385
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/cloudAutomationStore.d.ts +0 -67
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/cloudAutomationStore.js +0 -695
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/cloudSandboxSessionConfig.d.ts +0 -4
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/cloudSandboxSessionConfig.js +0 -39
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessions.contribution.d.ts +0 -1
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessions.contribution.js +0 -59
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsActions.d.ts +0 -1
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsActions.js +0 -83
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsChangesets.d.ts +0 -87
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsChangesets.js +0 -176
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsProvider.d.ts +0 -422
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsProvider.js +0 -2444
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/githubCloudAutomationStore.d.ts +0 -91
- package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/githubCloudAutomationStore.js +0 -620
- package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxAgentHost.contribution.d.ts +0 -1
- package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxAgentHost.contribution.js +0 -5
- package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxAgentHostContribution.d.ts +0 -46
- package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxAgentHostContribution.js +0 -321
- package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxSessionsProvider.d.ts +0 -104
- package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxSessionsProvider.js +0 -345
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoice.contribution.d.ts +0 -2
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoice.contribution.js +0 -611
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoiceSessionsPicker.d.ts +0 -20
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoiceSessionsPicker.js +0 -85
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoiceWidget.d.ts +0 -200
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoiceWidget.js +0 -981
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoiceWidgetBinding.d.ts +0 -24
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoiceWidgetBinding.js +0 -206
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoiceWindowService.d.ts +0 -65
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/agentsVoiceWindowService.js +0 -368
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/confirmationComponent.d.ts +0 -10
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/confirmationComponent.js +0 -57
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/feedbackDialog.d.ts +0 -33
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/feedbackDialog.js +0 -98
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/headerComponent.d.ts +0 -32
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/headerComponent.js +0 -186
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/onboardingComponent.d.ts +0 -12
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/onboardingComponent.js +0 -116
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/sessionListComponent.d.ts +0 -32
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/sessionListComponent.js +0 -226
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/statusRowsComponent.d.ts +0 -18
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/statusRowsComponent.js +0 -138
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/tokens.d.ts +0 -32
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/tokens.js +0 -29
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/transcriptComponent.d.ts +0 -13
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/transcriptComponent.js +0 -108
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/voiceBarComponent.d.ts +0 -13
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/components/voiceBarComponent.js +0 -63
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/media/voiceModeOnboarding.css +0 -252
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/transcriptsView/voiceTranscripts.contribution.d.ts +0 -1
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/transcriptsView/voiceTranscripts.contribution.js +0 -178
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/transcriptsView/voiceTranscriptsView.d.ts +0 -47
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/transcriptsView/voiceTranscriptsView.js +0 -322
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/voiceModeOnboarding.d.ts +0 -146
- package/vscode/src/vs/workbench/contrib/agentsVoice/browser/voiceModeOnboarding.js +0 -890
- package/vscode/src/vs/workbench/contrib/agentsVoice/common/voiceTranscriptStore.d.ts +0 -132
- package/vscode/src/vs/workbench/contrib/agentsVoice/common/voiceTranscriptStore.js +0 -237
- package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostLanguageModelProvider.d.ts +0 -120
- package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostLanguageModelProvider.js +0 -234
- package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsPicker.d.ts +0 -36
- package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsPicker.js +0 -164
- package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/repositoryPicker.d.ts +0 -21
- package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/repositoryPicker.js +0 -122
- package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup/chatSetupMicrosoftProbe.d.ts +0 -82
- package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup/chatSetupMicrosoftProbe.js +0 -213
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxAgentHostService.d.ts +0 -40
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxAgentHostService.js +0 -561
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxApiService.d.ts +0 -133
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxApiService.js +0 -1176
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxConnectionCustomization.d.ts +0 -17
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxConnectionCustomization.js +0 -76
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxCredentialRefresh.d.ts +0 -54
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxCredentialRefresh.js +0 -220
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxHistoryCache.d.ts +0 -21
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxHistoryCache.js +0 -184
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxLegacySessionPreparation.d.ts +0 -8
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxLegacySessionPreparation.js +0 -165
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxModels.d.ts +0 -43
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxModels.js +0 -162
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxReadOnlySessionHandler.d.ts +0 -40
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxReadOnlySessionHandler.js +0 -129
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxSessionContribution.d.ts +0 -166
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxSessionContribution.js +0 -838
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxSessionHandler.d.ts +0 -40
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxSessionHandler.js +0 -604
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxTelemetry.d.ts +0 -289
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxTelemetry.js +0 -497
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/missionControlCredentialSealing.d.ts +0 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/missionControlCredentialSealing.js +0 -41
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/missionControlEnvironmentService.d.ts +0 -73
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/missionControlEnvironmentService.js +0 -398
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/missionControlSharingService.d.ts +0 -45
- package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/missionControlSharingService.js +0 -296
- package/vscode/src/vs/workbench/contrib/chat/browser/speechToText/voiceCodeTranscriptionClient.d.ts +0 -63
- package/vscode/src/vs/workbench/contrib/chat/browser/speechToText/voiceCodeTranscriptionClient.js +0 -361
- package/vscode/src/vs/workbench/contrib/chat/browser/voiceClient/ttsPlaybackService.d.ts +0 -34
- package/vscode/src/vs/workbench/contrib/chat/browser/voiceClient/ttsPlaybackService.js +0 -198
- package/vscode/src/vs/workbench/contrib/chat/browser/voiceClient/voiceClientService.d.ts +0 -131
- package/vscode/src/vs/workbench/contrib/chat/browser/voiceClient/voiceClientService.js +0 -871
- package/vscode/src/vs/workbench/contrib/chat/browser/voiceInputMode/voiceInputMode.d.ts +0 -66
- package/vscode/src/vs/workbench/contrib/chat/browser/voiceInputMode/voiceInputMode.js +0 -297
- package/vscode/src/vs/workbench/contrib/chat/common/voicePlaybackService.d.ts +0 -31
- package/vscode/src/vs/workbench/contrib/chat/common/voicePlaybackService.js +0 -118
|
@@ -1,871 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
-
import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
4
|
-
import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
|
5
|
-
import { generateUuid } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uuid';
|
|
6
|
-
import { mainWindow } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/window';
|
|
7
|
-
import { Language } from '@codingame/monaco-vscode-api/vscode/vs/base/common/platform';
|
|
8
|
-
import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
|
|
9
|
-
import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
|
|
10
|
-
import { IProductService } from '@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service';
|
|
11
|
-
import { normalizeAgentsVoiceId, isVoiceCheckpointId } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/voiceClient/voiceClientService';
|
|
12
|
-
import '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
|
|
13
|
-
import { isTerminalCloseCode, voiceCloseCodeInfo } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/voiceClient/voiceCloseCodes';
|
|
14
|
-
import '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/extensions';
|
|
15
|
-
import { getVoiceWebSocketUrl } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/voiceClient/voiceEndpoint';
|
|
16
|
-
|
|
17
|
-
const PING_INTERVAL_MS = 25_000;
|
|
18
|
-
const PONG_TIMEOUT_MS = 10_000;
|
|
19
|
-
const FAST_RETRY_COUNT = 3;
|
|
20
|
-
const FAST_RETRY_DELAY_MS = 2_000;
|
|
21
|
-
const SLOW_RETRY_DELAY_MS = 10_000;
|
|
22
|
-
const MAX_RECONNECT_DURATION_MS = 60_000;
|
|
23
|
-
const TTS_SUPPORTED_LANGUAGE_BASES = ( new Set(["en", "de", "es", "fr", "it", "pt", "ja", "ko", "zh"]));
|
|
24
|
-
const ASR_SUPPORTED_LANGUAGE_BASES = ( new Set([
|
|
25
|
-
"ar",
|
|
26
|
-
"cs",
|
|
27
|
-
"da",
|
|
28
|
-
"de",
|
|
29
|
-
"en",
|
|
30
|
-
"es",
|
|
31
|
-
"fi",
|
|
32
|
-
"fr",
|
|
33
|
-
"hi",
|
|
34
|
-
"hu",
|
|
35
|
-
"id",
|
|
36
|
-
"it",
|
|
37
|
-
"ja",
|
|
38
|
-
"ko",
|
|
39
|
-
"nb",
|
|
40
|
-
"nl",
|
|
41
|
-
"pl",
|
|
42
|
-
"pt",
|
|
43
|
-
"ro",
|
|
44
|
-
"ru",
|
|
45
|
-
"sv",
|
|
46
|
-
"th",
|
|
47
|
-
"tr",
|
|
48
|
-
"vi",
|
|
49
|
-
"zh"
|
|
50
|
-
]));
|
|
51
|
-
const DEFAULT_LANGUAGE = "en-US";
|
|
52
|
-
function asOptionalString(value) {
|
|
53
|
-
return typeof value === "string" ? value : undefined;
|
|
54
|
-
}
|
|
55
|
-
function asOptionalNonEmptyString(value) {
|
|
56
|
-
const result = asOptionalString(value);
|
|
57
|
-
return result && result.length > 0 ? result : undefined;
|
|
58
|
-
}
|
|
59
|
-
function canonicalizeSupportedLanguage(value, supportedBases) {
|
|
60
|
-
const candidate = value?.trim();
|
|
61
|
-
if (!candidate || typeof Intl.getCanonicalLocales !== "function") {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
const canonical = Intl.getCanonicalLocales(candidate)[0];
|
|
66
|
-
return ( supportedBases.has(canonical.split("-")[0])) ? canonical : undefined;
|
|
67
|
-
} catch {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function resolveAutomaticVoiceLanguage(browserLanguage, displayLanguage) {
|
|
72
|
-
return canonicalizeSupportedLanguage(displayLanguage, ASR_SUPPORTED_LANGUAGE_BASES) ?? canonicalizeSupportedLanguage(browserLanguage, ASR_SUPPORTED_LANGUAGE_BASES) ?? DEFAULT_LANGUAGE;
|
|
73
|
-
}
|
|
74
|
-
function asTranscriptionStatus(value) {
|
|
75
|
-
return value === "partial" || value === "final" ? value : undefined;
|
|
76
|
-
}
|
|
77
|
-
function asTranscriptionRevision(value) {
|
|
78
|
-
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : undefined;
|
|
79
|
-
}
|
|
80
|
-
let VoiceClientService = class VoiceClientService extends Disposable {
|
|
81
|
-
get isConnected() {
|
|
82
|
-
return this._isConnected;
|
|
83
|
-
}
|
|
84
|
-
get isResuming() {
|
|
85
|
-
return this._isResuming;
|
|
86
|
-
}
|
|
87
|
-
get willReconnect() {
|
|
88
|
-
return this._reconnectTimer !== undefined;
|
|
89
|
-
}
|
|
90
|
-
get currentSessionId() {
|
|
91
|
-
return this._lastSessionId;
|
|
92
|
-
}
|
|
93
|
-
constructor(_configurationService, _logService, _productService) {
|
|
94
|
-
super();
|
|
95
|
-
this._configurationService = _configurationService;
|
|
96
|
-
this._logService = _logService;
|
|
97
|
-
this._productService = _productService;
|
|
98
|
-
this._reconnectAttempts = 0;
|
|
99
|
-
this._isConnected = false;
|
|
100
|
-
this._isResuming = false;
|
|
101
|
-
this._sessionStartedOnSocket = false;
|
|
102
|
-
this._lastSentById = ( new Map());
|
|
103
|
-
this._invalidatedSessionIds = ( new Set());
|
|
104
|
-
this._onTranscription = this._register(( new Emitter()));
|
|
105
|
-
this.onTranscription = this._onTranscription.event;
|
|
106
|
-
this._onAudioResponse = this._register(( new Emitter()));
|
|
107
|
-
this.onAudioResponse = this._onAudioResponse.event;
|
|
108
|
-
this._onBargeIn = this._register(( new Emitter()));
|
|
109
|
-
this.onBargeIn = this._onBargeIn.event;
|
|
110
|
-
this._onNarrationAck = this._register(( new Emitter()));
|
|
111
|
-
this.onNarrationAck = this._onNarrationAck.event;
|
|
112
|
-
this._onNarrationUnblocked = this._register(( new Emitter()));
|
|
113
|
-
this.onNarrationUnblocked = this._onNarrationUnblocked.event;
|
|
114
|
-
this._onNarrationInterrupted = this._register(( new Emitter()));
|
|
115
|
-
this.onNarrationInterrupted = this._onNarrationInterrupted.event;
|
|
116
|
-
this._onToolCall = this._register(( new Emitter()));
|
|
117
|
-
this.onToolCall = this._onToolCall.event;
|
|
118
|
-
this._onSpeechStarted = this._register(( new Emitter()));
|
|
119
|
-
this.onSpeechStarted = this._onSpeechStarted.event;
|
|
120
|
-
this._onSessionInit = this._register(( new Emitter()));
|
|
121
|
-
this.onSessionInit = this._onSessionInit.event;
|
|
122
|
-
this._onError = this._register(( new Emitter()));
|
|
123
|
-
this.onError = this._onError.event;
|
|
124
|
-
this._onDidChangeConnectionState = this._register(( new Emitter()));
|
|
125
|
-
this.onDidChangeConnectionState = this._onDidChangeConnectionState.event;
|
|
126
|
-
this._onFatalDisconnect = this._register(( new Emitter()));
|
|
127
|
-
this.onFatalDisconnect = this._onFatalDisconnect.event;
|
|
128
|
-
this._onConnectionIssue = this._register(( new Emitter()));
|
|
129
|
-
this.onConnectionIssue = this._onConnectionIssue.event;
|
|
130
|
-
this._onTurnAutoEnded = this._register(( new Emitter()));
|
|
131
|
-
this.onTurnAutoEnded = this._onTurnAutoEnded.event;
|
|
132
|
-
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
|
133
|
-
if (e.affectsConfiguration("agents.voice.turn.silenceMs") || e.affectsConfiguration("agents.voice.turn.stopPhrases") || e.affectsConfiguration("agents.voice.handsFree")) {
|
|
134
|
-
this._sendSetTurnConfig();
|
|
135
|
-
}
|
|
136
|
-
if (e.affectsConfiguration("agents.voice.voice")) {
|
|
137
|
-
this._sendSetVoice();
|
|
138
|
-
}
|
|
139
|
-
if (e.affectsConfiguration("agents.voice.language")) {
|
|
140
|
-
this._sendSetLanguage();
|
|
141
|
-
}
|
|
142
|
-
}));
|
|
143
|
-
}
|
|
144
|
-
_getVoice() {
|
|
145
|
-
return normalizeAgentsVoiceId(this._configurationService.getValue("agents.voice.voice"));
|
|
146
|
-
}
|
|
147
|
-
_sendSetVoice() {
|
|
148
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
149
|
-
this._ws.send(JSON.stringify({
|
|
150
|
-
type: "set_voice",
|
|
151
|
-
voice: this._getVoice()
|
|
152
|
-
}));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
_getLanguage() {
|
|
156
|
-
const configured = this._configurationService.getValue("agents.voice.language");
|
|
157
|
-
if (typeof configured === "string" && configured.trim().toLowerCase() !== "auto") {
|
|
158
|
-
const language = canonicalizeSupportedLanguage(configured, TTS_SUPPORTED_LANGUAGE_BASES);
|
|
159
|
-
if (language) {
|
|
160
|
-
return language;
|
|
161
|
-
}
|
|
162
|
-
this._logService.warn(
|
|
163
|
-
`[voice] Unsupported agents.voice.language value '${configured}', falling back to ${DEFAULT_LANGUAGE}`
|
|
164
|
-
);
|
|
165
|
-
return DEFAULT_LANGUAGE;
|
|
166
|
-
}
|
|
167
|
-
return resolveAutomaticVoiceLanguage(this._window?.navigator.language, Language.value());
|
|
168
|
-
}
|
|
169
|
-
_sendSetLanguage() {
|
|
170
|
-
if (this._ws?.readyState === WebSocket.OPEN && this._sessionStartedOnSocket) {
|
|
171
|
-
this._ws.send(JSON.stringify({
|
|
172
|
-
type: "set_language",
|
|
173
|
-
language: this._getLanguage()
|
|
174
|
-
}));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
_isExplicitlyConfigured(key) {
|
|
178
|
-
const inspected = this._configurationService.inspect(key);
|
|
179
|
-
return inspected.userValue !== undefined || inspected.userLocalValue !== undefined || inspected.userRemoteValue !== undefined || inspected.workspaceValue !== undefined || inspected.workspaceFolderValue !== undefined || inspected.applicationValue !== undefined;
|
|
180
|
-
}
|
|
181
|
-
_getTurnConfig() {
|
|
182
|
-
const cfg = this._configurationService;
|
|
183
|
-
const handsFree = cfg.getValue("agents.voice.handsFree") === true;
|
|
184
|
-
const silenceRaw = cfg.getValue("agents.voice.turn.silenceMs");
|
|
185
|
-
let silenceEnabled = typeof silenceRaw === "number" && silenceRaw > 0;
|
|
186
|
-
if (!handsFree && !this._isExplicitlyConfigured("agents.voice.turn.silenceMs")) {
|
|
187
|
-
silenceEnabled = false;
|
|
188
|
-
}
|
|
189
|
-
const silence_ms = silenceEnabled ? Math.round(silenceRaw) : 800;
|
|
190
|
-
const phrasesRaw = cfg.getValue("agents.voice.turn.stopPhrases");
|
|
191
|
-
const stop_phrases = Array.isArray(phrasesRaw) ? phrasesRaw.map(p => String(p).trim()).filter(p => p.length > 0) : [];
|
|
192
|
-
let phrasesEnabled = stop_phrases.length > 0;
|
|
193
|
-
if (!handsFree && !this._isExplicitlyConfigured("agents.voice.turn.stopPhrases")) {
|
|
194
|
-
phrasesEnabled = false;
|
|
195
|
-
}
|
|
196
|
-
const auto_end_mode = silenceEnabled && phrasesEnabled ? "both" : silenceEnabled ? "vad" : phrasesEnabled ? "phrase" : "off";
|
|
197
|
-
return {
|
|
198
|
-
auto_end_mode,
|
|
199
|
-
silence_ms,
|
|
200
|
-
stop_phrases: phrasesEnabled ? stop_phrases : [],
|
|
201
|
-
vad_gate_asr: true
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
_sendSetTurnConfig() {
|
|
205
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
206
|
-
this._ws.send(JSON.stringify({
|
|
207
|
-
type: "set_turn_config",
|
|
208
|
-
turn_config: this._getTurnConfig()
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
_getWsUrl() {
|
|
213
|
-
return getVoiceWebSocketUrl(this._configurationService, this._productService);
|
|
214
|
-
}
|
|
215
|
-
async connect(window, authToken) {
|
|
216
|
-
this._window = window;
|
|
217
|
-
this._authToken = authToken;
|
|
218
|
-
this._resetReconnectBudget();
|
|
219
|
-
this._connectWebSocket();
|
|
220
|
-
}
|
|
221
|
-
_connectWebSocket() {
|
|
222
|
-
const win = this._window;
|
|
223
|
-
if (!win) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
const baseUrl = this._getWsUrl();
|
|
227
|
-
if (!baseUrl) {
|
|
228
|
-
this._logService.error(
|
|
229
|
-
"[voice] No voice WebSocket URL configured (set voiceWsUrl in product.json or agents.voice.backendUrl in settings)"
|
|
230
|
-
);
|
|
231
|
-
this._onFatalDisconnect.fire({
|
|
232
|
-
code: 0,
|
|
233
|
-
reason: "",
|
|
234
|
-
kind: "fatal",
|
|
235
|
-
clientSide: true
|
|
236
|
-
});
|
|
237
|
-
this._cleanup();
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const url = this._authToken ? `${baseUrl}?token=${encodeURIComponent(this._authToken)}` : baseUrl;
|
|
241
|
-
const ws = new win.WebSocket(url);
|
|
242
|
-
this._ws = ws;
|
|
243
|
-
this._sessionStartedOnSocket = false;
|
|
244
|
-
ws.onopen = () => {
|
|
245
|
-
this._isResuming = !!this._lastSessionId;
|
|
246
|
-
this._sessionStartedOnSocket = false;
|
|
247
|
-
this._setConnected(true);
|
|
248
|
-
this._startPing();
|
|
249
|
-
};
|
|
250
|
-
ws.onmessage = evt => {
|
|
251
|
-
let msg;
|
|
252
|
-
try {
|
|
253
|
-
msg = JSON.parse(evt.data);
|
|
254
|
-
} catch {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
switch (msg.type) {
|
|
258
|
-
case "pong":
|
|
259
|
-
this._clearPongTimeout();
|
|
260
|
-
break;
|
|
261
|
-
case "session_init":
|
|
262
|
-
this._resetReconnectBudget();
|
|
263
|
-
this._lastSessionId = msg.session_id;
|
|
264
|
-
this._isResuming = false;
|
|
265
|
-
this._onSessionInit.fire({
|
|
266
|
-
sessionId: msg.session_id ?? ""
|
|
267
|
-
});
|
|
268
|
-
break;
|
|
269
|
-
case "session_resumed":
|
|
270
|
-
this._resetReconnectBudget();
|
|
271
|
-
this._lastSessionId = msg.session_id;
|
|
272
|
-
this._isResuming = false;
|
|
273
|
-
this._onSessionInit.fire({
|
|
274
|
-
sessionId: msg.session_id ?? ""
|
|
275
|
-
});
|
|
276
|
-
break;
|
|
277
|
-
case "speech_started":
|
|
278
|
-
this._onSpeechStarted.fire({
|
|
279
|
-
turnId: asOptionalString(msg.turn_id)
|
|
280
|
-
});
|
|
281
|
-
break;
|
|
282
|
-
case "barge_in":
|
|
283
|
-
this._onBargeIn.fire({
|
|
284
|
-
turnId: asOptionalString(msg.turn_id) ?? "",
|
|
285
|
-
interruptedTurnId: msg.interrupted_turn_id ?? ""
|
|
286
|
-
});
|
|
287
|
-
break;
|
|
288
|
-
case "narration_ack":
|
|
289
|
-
{
|
|
290
|
-
const disposition = msg.disposition === "busy" || msg.disposition === "invalid" || msg.disposition === "suppressed" ? msg.disposition : "accepted";
|
|
291
|
-
this._onNarrationAck.fire({
|
|
292
|
-
narrationId: msg.narration_id ?? "",
|
|
293
|
-
codingSessionId: msg.coding_session_id ?? "",
|
|
294
|
-
disposition,
|
|
295
|
-
reason: msg.reason
|
|
296
|
-
});
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
case "narration_unblocked":
|
|
300
|
-
this._onNarrationUnblocked.fire({
|
|
301
|
-
narrationId: msg.narration_id ?? "",
|
|
302
|
-
codingSessionId: msg.coding_session_id ?? ""
|
|
303
|
-
});
|
|
304
|
-
break;
|
|
305
|
-
case "narration_interrupted":
|
|
306
|
-
this._onNarrationInterrupted.fire({
|
|
307
|
-
narrationId: msg.narration_id ?? "",
|
|
308
|
-
codingSessionId: msg.coding_session_id ?? "",
|
|
309
|
-
...(typeof msg.retryable === "boolean" ? {
|
|
310
|
-
retryable: msg.retryable
|
|
311
|
-
} : {}),
|
|
312
|
-
...(msg.reason ? {
|
|
313
|
-
reason: msg.reason
|
|
314
|
-
} : {})
|
|
315
|
-
});
|
|
316
|
-
break;
|
|
317
|
-
case "transcription":
|
|
318
|
-
{
|
|
319
|
-
const status = msg.status === undefined ? "final" : asTranscriptionStatus(msg.status);
|
|
320
|
-
const turnId = msg.turn_id === undefined ? undefined : asOptionalNonEmptyString(msg.turn_id);
|
|
321
|
-
const revision = msg.revision === undefined ? undefined : asTranscriptionRevision(msg.revision);
|
|
322
|
-
if (!status || (msg.turn_id !== undefined && !turnId) || (msg.revision !== undefined && (!turnId || revision === undefined))) {
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
this._onTranscription.fire({
|
|
326
|
-
text: asOptionalString(msg.text) ?? "",
|
|
327
|
-
status,
|
|
328
|
-
committed: asOptionalString(msg.committed) ?? "",
|
|
329
|
-
turnId,
|
|
330
|
-
revision
|
|
331
|
-
});
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
case "audio_response":
|
|
335
|
-
{
|
|
336
|
-
const requestId = asOptionalString(msg.request_id);
|
|
337
|
-
const checkpointId = isVoiceCheckpointId(msg.checkpoint_id) ? msg.checkpoint_id : undefined;
|
|
338
|
-
const sequence = typeof msg.sequence === "number" && Number.isSafeInteger(msg.sequence) && msg.sequence > 0 ? msg.sequence : undefined;
|
|
339
|
-
const narrationKind = msg.narration_kind === "response" || msg.narration_kind === "confirmation" || msg.narration_kind === "checkpoint" ? msg.narration_kind : undefined;
|
|
340
|
-
const playbackId = asOptionalString(msg.playback_id);
|
|
341
|
-
if (narrationKind === "checkpoint") {
|
|
342
|
-
this._logService.info(
|
|
343
|
-
`[voice] checkpoint audio request=${requestId ?? "none"} stage=${checkpointId ?? "none"} sequence=${sequence ?? "none"} first=${msg.is_first_chunk === undefined ? true : Boolean(msg.is_first_chunk)} final=${Boolean(msg.is_final)}`
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
this._onAudioResponse.fire({
|
|
347
|
-
audio: msg.audio ?? "",
|
|
348
|
-
isFirstChunk: msg.is_first_chunk === undefined ? true : Boolean(msg.is_first_chunk),
|
|
349
|
-
isFinal: msg.is_final ?? false,
|
|
350
|
-
codingSessionId: msg.coding_session_id,
|
|
351
|
-
transcript: msg.transcript,
|
|
352
|
-
turnId: asOptionalString(msg.turn_id),
|
|
353
|
-
responseId: msg.narration_id ?? asOptionalString(msg.turn_id),
|
|
354
|
-
...(requestId ? {
|
|
355
|
-
requestId
|
|
356
|
-
} : {}),
|
|
357
|
-
...(checkpointId ? {
|
|
358
|
-
checkpointId
|
|
359
|
-
} : {}),
|
|
360
|
-
...(sequence !== undefined ? {
|
|
361
|
-
sequence
|
|
362
|
-
} : {}),
|
|
363
|
-
...(narrationKind ? {
|
|
364
|
-
narrationKind
|
|
365
|
-
} : {}),
|
|
366
|
-
...(playbackId ? {
|
|
367
|
-
playbackId
|
|
368
|
-
} : {})
|
|
369
|
-
});
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
case "tool_call":
|
|
373
|
-
this._onToolCall.fire({
|
|
374
|
-
callId: msg.call_id ?? "",
|
|
375
|
-
name: msg.name ?? "",
|
|
376
|
-
args: msg.args ?? {}
|
|
377
|
-
});
|
|
378
|
-
break;
|
|
379
|
-
case "turn_auto_ended":
|
|
380
|
-
{
|
|
381
|
-
const reason = msg.reason === "stop_phrase" ? "stop_phrase" : "vad_silence";
|
|
382
|
-
this._onTurnAutoEnded.fire({
|
|
383
|
-
reason,
|
|
384
|
-
turnId: asOptionalString(msg.turn_id) ?? ""
|
|
385
|
-
});
|
|
386
|
-
break;
|
|
387
|
-
}
|
|
388
|
-
case "error":
|
|
389
|
-
this._onError.fire(msg.detail ?? "Unknown error");
|
|
390
|
-
break;
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
ws.onerror = () => {
|
|
394
|
-
this._onError.fire("WebSocket error");
|
|
395
|
-
};
|
|
396
|
-
ws.onclose = evt => {
|
|
397
|
-
this._logService.trace(
|
|
398
|
-
`[voice] ws.onclose code=${evt.code} reason=${evt.reason ?? ""} wasClean=${evt.wasClean}`
|
|
399
|
-
);
|
|
400
|
-
if (this._ws === ws) {
|
|
401
|
-
if (isTerminalCloseCode(evt.code)) {
|
|
402
|
-
const kind = voiceCloseCodeInfo(evt.code)?.kind ?? "fatal";
|
|
403
|
-
this._logService.warn(
|
|
404
|
-
`[voice] terminal close ${evt.code} (${kind}): ${evt.reason}, not reconnecting`
|
|
405
|
-
);
|
|
406
|
-
this._onFatalDisconnect.fire({
|
|
407
|
-
code: evt.code,
|
|
408
|
-
reason: evt.reason ?? "",
|
|
409
|
-
kind
|
|
410
|
-
});
|
|
411
|
-
this._cleanup();
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
if (!this._reconnectStartedAt) {
|
|
415
|
-
this._reconnectStartedAt = Date.now();
|
|
416
|
-
}
|
|
417
|
-
const elapsed = Date.now() - this._reconnectStartedAt;
|
|
418
|
-
if (elapsed >= MAX_RECONNECT_DURATION_MS) {
|
|
419
|
-
this._logService.warn(
|
|
420
|
-
`[voice] reconnect budget of ${MAX_RECONNECT_DURATION_MS}ms exhausted, giving up`
|
|
421
|
-
);
|
|
422
|
-
this._onFatalDisconnect.fire({
|
|
423
|
-
code: evt.code,
|
|
424
|
-
reason: evt.reason ?? "",
|
|
425
|
-
kind: "fatal"
|
|
426
|
-
});
|
|
427
|
-
this._cleanup();
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
this._reconnectAttempts++;
|
|
431
|
-
this._stopPing();
|
|
432
|
-
this._ws = undefined;
|
|
433
|
-
const delay = this._reconnectAttempts <= FAST_RETRY_COUNT ? FAST_RETRY_DELAY_MS : SLOW_RETRY_DELAY_MS;
|
|
434
|
-
this._logService.warn(
|
|
435
|
-
`[voice] ws closed abnormally (code=${evt.code} reason=${evt.reason || "none"} wasClean=${evt.wasClean}); reconnecting in ${delay}ms (attempt ${this._reconnectAttempts})`
|
|
436
|
-
);
|
|
437
|
-
this._reconnectTimer = setTimeout(() => {
|
|
438
|
-
this._reconnectTimer = undefined;
|
|
439
|
-
this._connectWebSocket();
|
|
440
|
-
}, delay);
|
|
441
|
-
this._setConnected(false);
|
|
442
|
-
this._onConnectionIssue.fire({
|
|
443
|
-
code: evt.code,
|
|
444
|
-
reason: evt.reason ?? ""
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
disconnect() {
|
|
450
|
-
this._logService.trace("[voice] disconnect() called");
|
|
451
|
-
if (this._ws && this._ws.readyState < WebSocket.CLOSING) {
|
|
452
|
-
this._ws.close();
|
|
453
|
-
}
|
|
454
|
-
this._cleanup();
|
|
455
|
-
}
|
|
456
|
-
_cleanup() {
|
|
457
|
-
this._resetReconnectBudget();
|
|
458
|
-
this._stopPing();
|
|
459
|
-
if (this._reconnectTimer) {
|
|
460
|
-
clearTimeout(this._reconnectTimer);
|
|
461
|
-
this._reconnectTimer = undefined;
|
|
462
|
-
}
|
|
463
|
-
if (this._contextSendTimer) {
|
|
464
|
-
clearTimeout(this._contextSendTimer);
|
|
465
|
-
this._contextSendTimer = undefined;
|
|
466
|
-
}
|
|
467
|
-
this._pendingContext = undefined;
|
|
468
|
-
this._ws = undefined;
|
|
469
|
-
this._sessionStartedOnSocket = false;
|
|
470
|
-
this._window = undefined;
|
|
471
|
-
this._lastSessionId = undefined;
|
|
472
|
-
this._isResuming = false;
|
|
473
|
-
this._lastSentById.clear();
|
|
474
|
-
this._invalidatedSessionIds.clear();
|
|
475
|
-
this._setConnected(false);
|
|
476
|
-
}
|
|
477
|
-
_resetReconnectBudget() {
|
|
478
|
-
this._reconnectAttempts = 0;
|
|
479
|
-
this._reconnectStartedAt = undefined;
|
|
480
|
-
}
|
|
481
|
-
_startPing() {
|
|
482
|
-
this._stopPing();
|
|
483
|
-
const win = this._window ?? mainWindow;
|
|
484
|
-
this._pingTimer = win.setInterval(() => {
|
|
485
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
486
|
-
this._ws.send(JSON.stringify({
|
|
487
|
-
type: "ping"
|
|
488
|
-
}));
|
|
489
|
-
this._pongTimer = setTimeout(() => {
|
|
490
|
-
this._logService.warn("[voice] pong timeout — server unreachable, reconnecting");
|
|
491
|
-
this._ws?.close(4000, "pong timeout");
|
|
492
|
-
}, PONG_TIMEOUT_MS);
|
|
493
|
-
}
|
|
494
|
-
}, PING_INTERVAL_MS);
|
|
495
|
-
}
|
|
496
|
-
_stopPing() {
|
|
497
|
-
if (this._pingTimer) {
|
|
498
|
-
(this._window ?? mainWindow).clearInterval(this._pingTimer);
|
|
499
|
-
this._pingTimer = undefined;
|
|
500
|
-
}
|
|
501
|
-
this._clearPongTimeout();
|
|
502
|
-
}
|
|
503
|
-
_clearPongTimeout() {
|
|
504
|
-
if (this._pongTimer) {
|
|
505
|
-
clearTimeout(this._pongTimer);
|
|
506
|
-
this._pongTimer = undefined;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
_setConnected(connected) {
|
|
510
|
-
if (this._isConnected !== connected) {
|
|
511
|
-
this._isConnected = connected;
|
|
512
|
-
this._onDidChangeConnectionState.fire(connected);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
sendPttStart(turnId, options) {
|
|
516
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
517
|
-
this._ws.send(JSON.stringify({
|
|
518
|
-
type: "ptt_start",
|
|
519
|
-
turn_id: turnId,
|
|
520
|
-
has_active_session: options.hasActiveSession,
|
|
521
|
-
...(options.passive ? {
|
|
522
|
-
passive: true
|
|
523
|
-
} : {})
|
|
524
|
-
}));
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
sendPttAudioChunk(audio) {
|
|
528
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
529
|
-
this._ws.send(JSON.stringify({
|
|
530
|
-
type: "ptt_audio_chunk",
|
|
531
|
-
audio
|
|
532
|
-
}));
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
sendPttEnd() {
|
|
536
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
537
|
-
this._ws.send(JSON.stringify({
|
|
538
|
-
type: "ptt_end"
|
|
539
|
-
}));
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
sendPttDiagnostic(turnId, metrics) {
|
|
543
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
544
|
-
this._ws.send(JSON.stringify({
|
|
545
|
-
type: "ptt_diagnostic",
|
|
546
|
-
turn_id: turnId,
|
|
547
|
-
metrics
|
|
548
|
-
}));
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
sendSessionContext(context) {
|
|
552
|
-
if (!this._isConnected) {
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
this._pendingContext = context;
|
|
556
|
-
if (this._contextSendTimer) {
|
|
557
|
-
clearTimeout(this._contextSendTimer);
|
|
558
|
-
}
|
|
559
|
-
this._contextSendTimer = setTimeout(() => {
|
|
560
|
-
this._contextSendTimer = undefined;
|
|
561
|
-
const pending = this._pendingContext;
|
|
562
|
-
this._pendingContext = undefined;
|
|
563
|
-
if (pending && this._ws?.readyState === WebSocket.OPEN) {
|
|
564
|
-
this._sendDelta(pending);
|
|
565
|
-
}
|
|
566
|
-
}, 500);
|
|
567
|
-
}
|
|
568
|
-
flushSessionContext() {
|
|
569
|
-
if (!this._contextSendTimer) {
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
clearTimeout(this._contextSendTimer);
|
|
573
|
-
this._contextSendTimer = undefined;
|
|
574
|
-
const pending = this._pendingContext;
|
|
575
|
-
this._pendingContext = undefined;
|
|
576
|
-
if (pending && this._ws?.readyState === WebSocket.OPEN) {
|
|
577
|
-
this._sendDelta(pending);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
invalidateSessionCache(sessionId) {
|
|
581
|
-
this._invalidatedSessionIds.add(sessionId);
|
|
582
|
-
}
|
|
583
|
-
_sendDelta(context) {
|
|
584
|
-
const currentIds = ( new Set(context.sessions.map(s => s.id)));
|
|
585
|
-
const removes = [...( this._lastSentById.keys())].filter(id => !( currentIds.has(id)));
|
|
586
|
-
const upserts = [];
|
|
587
|
-
for (const session of context.sessions) {
|
|
588
|
-
const current = session;
|
|
589
|
-
const prev = this._lastSentById.get(session.id);
|
|
590
|
-
if (!prev) {
|
|
591
|
-
upserts.push(current);
|
|
592
|
-
} else {
|
|
593
|
-
const patch = {
|
|
594
|
-
id: session.id
|
|
595
|
-
};
|
|
596
|
-
let hasChanges = false;
|
|
597
|
-
if (( this._invalidatedSessionIds.has(session.id))) {
|
|
598
|
-
for (const key of ( Object.keys(current))) {
|
|
599
|
-
if (key !== "id") {
|
|
600
|
-
patch[key] = current[key] ?? null;
|
|
601
|
-
hasChanges = true;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
for (const key of ( Object.keys(prev))) {
|
|
605
|
-
if (key !== "id" && (!Object.prototype.hasOwnProperty.call(current, key) || current[key] === undefined)) {
|
|
606
|
-
patch[key] = null;
|
|
607
|
-
hasChanges = true;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
} else {
|
|
611
|
-
for (const key of ( Object.keys(current))) {
|
|
612
|
-
if (key === "id") {
|
|
613
|
-
continue;
|
|
614
|
-
}
|
|
615
|
-
if (stableStringify(current[key]) !== stableStringify(prev[key])) {
|
|
616
|
-
patch[key] = current[key];
|
|
617
|
-
hasChanges = true;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
for (const key of ( Object.keys(prev))) {
|
|
621
|
-
if (key === "id") {
|
|
622
|
-
continue;
|
|
623
|
-
}
|
|
624
|
-
if (!Object.prototype.hasOwnProperty.call(current, key) || current[key] === undefined) {
|
|
625
|
-
patch[key] = null;
|
|
626
|
-
hasChanges = true;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
if (!Object.prototype.hasOwnProperty.call(patch, "agent_state")) {
|
|
631
|
-
if (Object.prototype.hasOwnProperty.call(patch, "agent_state_detail")) {
|
|
632
|
-
delete patch.agent_state_detail;
|
|
633
|
-
}
|
|
634
|
-
if (Object.prototype.hasOwnProperty.call(patch, "last_response_summary")) {
|
|
635
|
-
delete patch.last_response_summary;
|
|
636
|
-
}
|
|
637
|
-
hasChanges = ( ( Object.keys(patch)).some(k => k !== "id"));
|
|
638
|
-
}
|
|
639
|
-
if (hasChanges) {
|
|
640
|
-
upserts.push(patch);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
if (upserts.length === 0 && removes.length === 0) {
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
for (const session of context.sessions) {
|
|
648
|
-
const obj = {};
|
|
649
|
-
for (const [k, v] of Object.entries(session)) {
|
|
650
|
-
if (v !== undefined) {
|
|
651
|
-
obj[k] = v;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
this._lastSentById.set(session.id, obj);
|
|
655
|
-
this._invalidatedSessionIds.delete(session.id);
|
|
656
|
-
}
|
|
657
|
-
for (const id of removes) {
|
|
658
|
-
this._lastSentById.delete(id);
|
|
659
|
-
this._invalidatedSessionIds.delete(id);
|
|
660
|
-
}
|
|
661
|
-
this._ws.send(JSON.stringify({
|
|
662
|
-
type: "session_context",
|
|
663
|
-
mode: "delta",
|
|
664
|
-
upserts,
|
|
665
|
-
removes
|
|
666
|
-
}));
|
|
667
|
-
this._logService.trace(`[voice] _sendDelta upserts=[${upserts.map(
|
|
668
|
-
u => `${String(u.id).slice(-8)}:${u.agent_state ?? "(no-state)"}${Object.prototype.hasOwnProperty.call(u, "agent_state_detail") ? "+detail" : ""}${Object.prototype.hasOwnProperty.call(u, "last_response_summary") && u.last_response_summary ? "+summary" : ""}`
|
|
669
|
-
).join(", ")}] removes=${removes.length}`);
|
|
670
|
-
}
|
|
671
|
-
_seedTracking(context) {
|
|
672
|
-
this._lastSentById.clear();
|
|
673
|
-
this._invalidatedSessionIds.clear();
|
|
674
|
-
for (const session of context.sessions) {
|
|
675
|
-
const obj = {};
|
|
676
|
-
for (const [k, v] of Object.entries(session)) {
|
|
677
|
-
if (v !== undefined) {
|
|
678
|
-
obj[k] = v;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
this._lastSentById.set(session.id, obj);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
sendToolResult(callId, result) {
|
|
685
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
686
|
-
this._ws.send(JSON.stringify({
|
|
687
|
-
type: "tool_result",
|
|
688
|
-
call_id: callId,
|
|
689
|
-
result
|
|
690
|
-
}));
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
sendNarrationPlaybackComplete(codingSessionId, narrationId, playbackId) {
|
|
694
|
-
if (this._ws?.readyState === WebSocket.OPEN && this._sessionStartedOnSocket) {
|
|
695
|
-
this._ws.send(JSON.stringify({
|
|
696
|
-
type: "narration_playback_complete",
|
|
697
|
-
coding_session_id: codingSessionId,
|
|
698
|
-
narration_id: narrationId,
|
|
699
|
-
playback_id: playbackId
|
|
700
|
-
}));
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
requestNarration(
|
|
704
|
-
codingSessionId,
|
|
705
|
-
kind,
|
|
706
|
-
text,
|
|
707
|
-
narrationId,
|
|
708
|
-
checkpoint,
|
|
709
|
-
confirmationType,
|
|
710
|
-
pending
|
|
711
|
-
) {
|
|
712
|
-
if (this._ws?.readyState === WebSocket.OPEN && this._sessionStartedOnSocket) {
|
|
713
|
-
const id = narrationId ?? generateUuid();
|
|
714
|
-
this._ws.send(JSON.stringify({
|
|
715
|
-
type: "request_narration",
|
|
716
|
-
coding_session_id: codingSessionId,
|
|
717
|
-
kind,
|
|
718
|
-
text,
|
|
719
|
-
narration_id: id,
|
|
720
|
-
...(checkpoint ? {
|
|
721
|
-
request_id: checkpoint.requestId,
|
|
722
|
-
checkpoint_id: checkpoint.checkpointId,
|
|
723
|
-
sequence: checkpoint.sequence
|
|
724
|
-
} : {}),
|
|
725
|
-
...(kind === "confirmation" && confirmationType ? {
|
|
726
|
-
confirmation_type: confirmationType
|
|
727
|
-
} : {}),
|
|
728
|
-
...(pending ? {
|
|
729
|
-
pending_id: pending.pendingId
|
|
730
|
-
} : {})
|
|
731
|
-
}));
|
|
732
|
-
this._logService.trace(
|
|
733
|
-
`[voice] request_narration kind=${kind} id=${codingSessionId.slice(-32)} narration_id=${id.slice(0, 8)}${narrationId ? " (retry)" : ""}`
|
|
734
|
-
);
|
|
735
|
-
if (checkpoint) {
|
|
736
|
-
this._logService.info(
|
|
737
|
-
`[voice] checkpoint sent request=${checkpoint.requestId} stage=${checkpoint.checkpointId} sequence=${checkpoint.sequence}`
|
|
738
|
-
);
|
|
739
|
-
}
|
|
740
|
-
return id;
|
|
741
|
-
}
|
|
742
|
-
return undefined;
|
|
743
|
-
}
|
|
744
|
-
sendSessionStateChange(sessionId, newState, _label, detail, lastResponseSummary) {
|
|
745
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
746
|
-
const payload = {
|
|
747
|
-
type: "session_state_change",
|
|
748
|
-
session_id: sessionId,
|
|
749
|
-
new_state: newState
|
|
750
|
-
};
|
|
751
|
-
if (detail) {
|
|
752
|
-
payload.detail = detail;
|
|
753
|
-
}
|
|
754
|
-
if (lastResponseSummary) {
|
|
755
|
-
payload.last_response_summary = lastResponseSummary;
|
|
756
|
-
}
|
|
757
|
-
this._ws.send(JSON.stringify(payload));
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
stopSpeaking() {}
|
|
761
|
-
sendStartSession(context, machineId, priorTimeline, turnConfigOverride, voiceInstructions) {
|
|
762
|
-
if (this._ws?.readyState === WebSocket.OPEN) {
|
|
763
|
-
const sessionContext = {
|
|
764
|
-
...context,
|
|
765
|
-
display_locale: this._getLanguage()
|
|
766
|
-
};
|
|
767
|
-
this._seedTracking(sessionContext);
|
|
768
|
-
const payload = {
|
|
769
|
-
type: "start_session",
|
|
770
|
-
session_context: sessionContext,
|
|
771
|
-
machine_id: machineId,
|
|
772
|
-
turn_config: turnConfigOverride ?? this._getTurnConfig(),
|
|
773
|
-
voice: this._getVoice(),
|
|
774
|
-
auto_narrate: false
|
|
775
|
-
};
|
|
776
|
-
if (priorTimeline && priorTimeline.length > 0) {
|
|
777
|
-
payload.prior_timeline = priorTimeline;
|
|
778
|
-
}
|
|
779
|
-
if (voiceInstructions) {
|
|
780
|
-
payload.voice_instructions = voiceInstructions;
|
|
781
|
-
}
|
|
782
|
-
this._ws.send(JSON.stringify(payload));
|
|
783
|
-
this._sessionStartedOnSocket = true;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
sendResumeSession(context, machineId, voiceInstructions) {
|
|
787
|
-
if (this._ws?.readyState === WebSocket.OPEN && this._lastSessionId) {
|
|
788
|
-
const sessionContext = {
|
|
789
|
-
...context,
|
|
790
|
-
display_locale: this._getLanguage()
|
|
791
|
-
};
|
|
792
|
-
this._seedTracking(sessionContext);
|
|
793
|
-
const payload = {
|
|
794
|
-
type: "resume_session",
|
|
795
|
-
session_id: this._lastSessionId,
|
|
796
|
-
session_context: sessionContext,
|
|
797
|
-
machine_id: machineId,
|
|
798
|
-
turn_config: this._getTurnConfig(),
|
|
799
|
-
voice: this._getVoice(),
|
|
800
|
-
auto_narrate: false
|
|
801
|
-
};
|
|
802
|
-
if (voiceInstructions) {
|
|
803
|
-
payload.voice_instructions = voiceInstructions;
|
|
804
|
-
}
|
|
805
|
-
this._ws.send(JSON.stringify(payload));
|
|
806
|
-
this._sessionStartedOnSocket = true;
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
async submitFeedback(payload) {
|
|
810
|
-
const httpUrl = this._getWsUrl().replace("wss://", "https://").replace("ws://", "http://").replace(/\/realtime\/voice$/, "/feedback");
|
|
811
|
-
const headers = {
|
|
812
|
-
"Content-Type": "application/json"
|
|
813
|
-
};
|
|
814
|
-
if (this._authToken) {
|
|
815
|
-
headers["Authorization"] = `Bearer ${this._authToken}`;
|
|
816
|
-
}
|
|
817
|
-
try {
|
|
818
|
-
const response = await fetch(httpUrl, {
|
|
819
|
-
method: "POST",
|
|
820
|
-
headers,
|
|
821
|
-
body: JSON.stringify({
|
|
822
|
-
feedback_text: payload.feedbackText,
|
|
823
|
-
machine_id: payload.machineId,
|
|
824
|
-
user_id: payload.userId,
|
|
825
|
-
session_id: payload.sessionId,
|
|
826
|
-
submission_id: payload.submissionId,
|
|
827
|
-
transcript_history: payload.transcriptHistory.map(t => ({
|
|
828
|
-
role: t.role,
|
|
829
|
-
text: t.text,
|
|
830
|
-
timestamp: t.timestamp
|
|
831
|
-
})),
|
|
832
|
-
client_session_state: payload.clientSessionState,
|
|
833
|
-
client_environment: payload.clientEnvironment,
|
|
834
|
-
timestamp: payload.timestamp
|
|
835
|
-
})
|
|
836
|
-
});
|
|
837
|
-
if (!response.ok) {
|
|
838
|
-
const text = await response.text();
|
|
839
|
-
return {
|
|
840
|
-
ok: false,
|
|
841
|
-
error: `HTTP ${response.status}: ${text}`
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
return {
|
|
845
|
-
ok: true
|
|
846
|
-
};
|
|
847
|
-
} catch (err) {
|
|
848
|
-
return {
|
|
849
|
-
ok: false,
|
|
850
|
-
error: String(err)
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
dispose() {
|
|
855
|
-
this.disconnect();
|
|
856
|
-
super.dispose();
|
|
857
|
-
}
|
|
858
|
-
};
|
|
859
|
-
VoiceClientService = ( __decorate([( __param(0, IConfigurationService)), ( __param(1, ILogService)), ( __param(2, IProductService))], VoiceClientService));
|
|
860
|
-
function stableStringify(value) {
|
|
861
|
-
if (value === null || typeof value !== "object") {
|
|
862
|
-
return JSON.stringify(value);
|
|
863
|
-
}
|
|
864
|
-
if (Array.isArray(value)) {
|
|
865
|
-
return "[" + value.map(stableStringify).join(",") + "]";
|
|
866
|
-
}
|
|
867
|
-
const keys = ( Object.keys(value)).sort();
|
|
868
|
-
return "{" + keys.map(k => JSON.stringify(k) + ":" + stableStringify(value[k])).join(",") + "}";
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
export { VoiceClientService, resolveAutomaticVoiceLanguage };
|