@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
package/vscode/src/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxApiService.js
DELETED
|
@@ -1,1176 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
-
import { Limiter, raceCancellationError, timeout } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
|
|
4
|
-
import { CancellationToken } from '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
|
|
5
|
-
import { toErrorMessage } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errorMessage';
|
|
6
|
-
import { CancellationError, isCancellationError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
|
|
7
|
-
import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
|
8
|
-
import { isObject } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types';
|
|
9
|
-
import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
10
|
-
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
|
|
11
|
-
import { StopWatch } from '@codingame/monaco-vscode-api/vscode/vs/base/common/stopwatch';
|
|
12
|
-
import { mark, clearMarks } from '@codingame/monaco-vscode-api/vscode/vs/base/common/performance';
|
|
13
|
-
import { getGitHubRequestId, sanitizeConnectionDiagnosticText } from '@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/connectionDiagnostics';
|
|
14
|
-
import { CLOUD_SANDBOX_ON_DEMAND_ENVIRONMENT_ID, CloudSandboxRequestError, CloudSandboxAuthenticationRequiredError, CloudSandboxNetworkError, CLOUD_SANDBOX_AGENT_SLUG } from '../../../../../platform/agentHost/common/cloudSandboxAgentHost.js';
|
|
15
|
-
import { TaskEventReplayError, parseTaskEventsResponse, replayTaskAhpEvents } from '../../../../../platform/agentHost/common/taskEventReplay.js';
|
|
16
|
-
import '@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/state/sessionState';
|
|
17
|
-
import { createPricingMetaFromBilling, normalizeCAPIBilling } from '../../../../../platform/agentHost/common/meta/vscode/agentModelPricing.js';
|
|
18
|
-
import { COPILOT_INTEGRATION_ID } from '@codingame/monaco-vscode-api/vscode/vs/platform/endpoint/common/licenseAgreement';
|
|
19
|
-
import { deriveGitHubEndpoints, GITHUB_DOT_COM_COPILOT_API_BASE_URI } from '@codingame/monaco-vscode-api/vscode/vs/platform/github/common/githubEndpoints';
|
|
20
|
-
import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
|
|
21
|
-
import { IProductService } from '@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service';
|
|
22
|
-
import { asText } from '@codingame/monaco-vscode-api/vscode/vs/platform/request/common/request';
|
|
23
|
-
import { IRequestService } from '@codingame/monaco-vscode-api/vscode/vs/platform/request/common/request.service';
|
|
24
|
-
import { IAuthenticationService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/authentication/common/authentication.service';
|
|
25
|
-
import { requestOutcomeForStatus } from './cloudSandboxTelemetry.js';
|
|
26
|
-
import { ICloudSandboxTelemetryService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/browser/remoteAgentHost/cloudSandboxTelemetry.service';
|
|
27
|
-
import { CloudSandboxHistoryCache } from './cloudSandboxHistoryCache.js';
|
|
28
|
-
import { SessionStatus } from '@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/state/protocol/channels-session/state';
|
|
29
|
-
|
|
30
|
-
const LOG_PREFIX = "[CloudSandboxApi]";
|
|
31
|
-
function taskSessionStatus(state, logService) {
|
|
32
|
-
switch (state) {
|
|
33
|
-
case "queued":
|
|
34
|
-
case "in_progress":
|
|
35
|
-
return SessionStatus.InProgress;
|
|
36
|
-
case "waiting_for_user":
|
|
37
|
-
return SessionStatus.InputNeeded;
|
|
38
|
-
case "idle":
|
|
39
|
-
case "completed":
|
|
40
|
-
return SessionStatus.Idle;
|
|
41
|
-
case "failed":
|
|
42
|
-
case "timed_out":
|
|
43
|
-
case "cancelled":
|
|
44
|
-
return SessionStatus.Error;
|
|
45
|
-
case undefined:
|
|
46
|
-
return undefined;
|
|
47
|
-
default:
|
|
48
|
-
logService.warn(
|
|
49
|
-
`${LOG_PREFIX} Unrecognized session activity state; leaving its status unknown.`
|
|
50
|
-
);
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const GITHUB_DOT_COM_API_BASE_URI = deriveGitHubEndpoints(undefined).apiBaseUri;
|
|
55
|
-
const REQUEST_TIMEOUT_MS = 10_000;
|
|
56
|
-
const CONNECTION_REQUEST_TIMEOUT_MS = 30_000;
|
|
57
|
-
const DISCOVERY_TIMEOUT_MS = 30_000;
|
|
58
|
-
const CREATE_TIMEOUT_MS = 60_000;
|
|
59
|
-
const DEFAULT_WAKING_RETRY_AFTER_SECONDS = 5;
|
|
60
|
-
const DIAGNOSTIC_RESPONSE_HEADERS = ["x-github-request-id", "x-request-id", "x-sweagentd-retry", "retry-after"];
|
|
61
|
-
const DISCOVERY_TASK_SCAN_LIMIT = 100;
|
|
62
|
-
const DISCOVERY_TASK_PAGE_LIMIT = 10;
|
|
63
|
-
const DISCOVERY_TASK_FETCH_CONCURRENCY = 5;
|
|
64
|
-
const DISCOVERY_OVERLAP_MS = 60_000;
|
|
65
|
-
const STALLED_SESSION_GRACE_MS = 60 * 60_000;
|
|
66
|
-
const HTTP_TOO_MANY_REQUESTS = 429;
|
|
67
|
-
const RATE_LIMIT_MAX_RETRIES = 3;
|
|
68
|
-
const RATE_LIMIT_BASE_DELAY_MS = 1_000;
|
|
69
|
-
const RATE_LIMIT_MAX_BACKOFF_MS = 8_000;
|
|
70
|
-
const RATE_LIMIT_WAIT_BUDGET_MS = 15_000;
|
|
71
|
-
const FALLBACK_SCOPES = ["read:user", "user:email", "repo", "workflow"];
|
|
72
|
-
let CloudSandboxApiService = class CloudSandboxApiService extends Disposable {
|
|
73
|
-
constructor(
|
|
74
|
-
_requestService,
|
|
75
|
-
_authenticationService,
|
|
76
|
-
_productService,
|
|
77
|
-
_logService,
|
|
78
|
-
_telemetry
|
|
79
|
-
) {
|
|
80
|
-
super();
|
|
81
|
-
this._requestService = _requestService;
|
|
82
|
-
this._authenticationService = _authenticationService;
|
|
83
|
-
this._productService = _productService;
|
|
84
|
-
this._logService = _logService;
|
|
85
|
-
this._telemetry = _telemetry;
|
|
86
|
-
this._repositoryNames = ( new Map());
|
|
87
|
-
this._discoveredTasks = ( new Map());
|
|
88
|
-
this._discoveryGeneration = 0;
|
|
89
|
-
this._historyRequestId = 0;
|
|
90
|
-
this._historyCache = this._register(( new CloudSandboxHistoryCache()));
|
|
91
|
-
this._onDidChangeAccount = this._register(( new Emitter()));
|
|
92
|
-
this.onDidChangeAccount = this._onDidChangeAccount.event;
|
|
93
|
-
this._register(this._authenticationService.onDidChangeSessions(e => {
|
|
94
|
-
if (e.providerId === this._authenticationProviderId) {
|
|
95
|
-
void this._onAuthenticationChanged();
|
|
96
|
-
}
|
|
97
|
-
}));
|
|
98
|
-
this._register(this._authenticationService.onDidRegisterAuthenticationProvider(e => {
|
|
99
|
-
if (e.id === this._authenticationProviderId) {
|
|
100
|
-
void this._onAuthenticationChanged();
|
|
101
|
-
}
|
|
102
|
-
}));
|
|
103
|
-
this._register(this._authenticationService.onDidUnregisterAuthenticationProvider(e => {
|
|
104
|
-
if (e.id === this._authenticationProviderId) {
|
|
105
|
-
void this._onAuthenticationChanged();
|
|
106
|
-
}
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
get _authenticationProviderId() {
|
|
110
|
-
return this._productService.defaultChatAgent?.provider?.default?.id ?? "github";
|
|
111
|
-
}
|
|
112
|
-
async getAccountKey() {
|
|
113
|
-
const generation = this._discoveryGeneration;
|
|
114
|
-
const session = await this._resolveGitHubSession();
|
|
115
|
-
if (generation !== this._discoveryGeneration) {
|
|
116
|
-
throw ( new CancellationError());
|
|
117
|
-
}
|
|
118
|
-
return session ? JSON.stringify([this._authenticationProviderId, session.account.id]) : undefined;
|
|
119
|
-
}
|
|
120
|
-
async _onAuthenticationChanged() {
|
|
121
|
-
this.clearSessionHistory();
|
|
122
|
-
const generation = ++this._discoveryGeneration;
|
|
123
|
-
this._discoverySince = undefined;
|
|
124
|
-
this._discoveredTasks.clear();
|
|
125
|
-
this._repositoryNames.clear();
|
|
126
|
-
try {
|
|
127
|
-
const accountKey = await this.getAccountKey();
|
|
128
|
-
if (generation === this._discoveryGeneration && !this._store.isDisposed) {
|
|
129
|
-
this._onDidChangeAccount.fire(accountKey);
|
|
130
|
-
}
|
|
131
|
-
} catch (error) {
|
|
132
|
-
if (!isCancellationError(error)) {
|
|
133
|
-
this._logService.warn(
|
|
134
|
-
`${LOG_PREFIX} Resolving discovery account failed: ${toErrorMessage(error)}`
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
async connect(request, token) {
|
|
140
|
-
return this._connectRequest("connect", request.environmentId, token, {
|
|
141
|
-
...(request.sessionId && {
|
|
142
|
-
session_id: request.sessionId
|
|
143
|
-
})
|
|
144
|
-
}, request.onRequest);
|
|
145
|
-
}
|
|
146
|
-
async reconnect(request, clientId, token) {
|
|
147
|
-
const result = await this._connectRequest("reconnect", request.environmentId, token, {
|
|
148
|
-
client_id: clientId,
|
|
149
|
-
...(request.sessionId && {
|
|
150
|
-
session_id: request.sessionId
|
|
151
|
-
})
|
|
152
|
-
}, request.onRequest);
|
|
153
|
-
if (result.kind === "token" && result.token.client_id !== clientId) {
|
|
154
|
-
throw ( new Error("Cloud sandbox reconnect returned credentials for a different client"));
|
|
155
|
-
}
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
|
-
async getEnvironment(environmentId, token) {
|
|
159
|
-
const context = await this._sendEnvironment("get", environmentId, token);
|
|
160
|
-
if (!isSuccess(context)) {
|
|
161
|
-
await this._throwForStatus("get", context);
|
|
162
|
-
}
|
|
163
|
-
const environment = await this._readJson(context);
|
|
164
|
-
if (!environment?.status) {
|
|
165
|
-
throw ( new Error("Mission Control get returned an incomplete environment response"));
|
|
166
|
-
}
|
|
167
|
-
this._logService.trace(
|
|
168
|
-
`${LOG_PREFIX} Environment ${environmentId}: status=${environment.status}, ahp=${environment.capabilities?.ahp_version ?? "unknown"}`
|
|
169
|
-
);
|
|
170
|
-
return environment;
|
|
171
|
-
}
|
|
172
|
-
getCachedEnvironments() {
|
|
173
|
-
return this._environments?.generation === this._discoveryGeneration && Date.now() - this._environments.fetchedAt < 60_000 ? this._environments.values : undefined;
|
|
174
|
-
}
|
|
175
|
-
async listEnvironments(token, options) {
|
|
176
|
-
const generation = this._discoveryGeneration;
|
|
177
|
-
const cached = this.getCachedEnvironments();
|
|
178
|
-
if (!options?.refresh && cached) {
|
|
179
|
-
return cached;
|
|
180
|
-
}
|
|
181
|
-
const context = await this._request(
|
|
182
|
-
`${GITHUB_DOT_COM_COPILOT_API_BASE_URI}/agents/environments`,
|
|
183
|
-
"mc.environmentClient.list",
|
|
184
|
-
"listEnvironments",
|
|
185
|
-
{
|
|
186
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
187
|
-
},
|
|
188
|
-
token
|
|
189
|
-
);
|
|
190
|
-
if (!isSuccess(context)) {
|
|
191
|
-
await this._throwForStatus("list environments", context);
|
|
192
|
-
}
|
|
193
|
-
const response = await this._readJson(context);
|
|
194
|
-
if (!Array.isArray(response)) {
|
|
195
|
-
throw ( new Error("Mission Control returned invalid environment discovery metadata"));
|
|
196
|
-
}
|
|
197
|
-
const values = [];
|
|
198
|
-
for (const value of response) {
|
|
199
|
-
if (!isObject(value)) {
|
|
200
|
-
this._logService.warn("Ignoring malformed Mission Control environment metadata");
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
const environment = value;
|
|
204
|
-
if (typeof environment.id !== "string" || !/^[A-Za-z0-9_-]+$/.test(environment.id) || typeof environment.name !== "string" || !environment.name.trim() || typeof environment.kind !== "string" || typeof environment.status !== "string" || !environment.status) {
|
|
205
|
-
this._logService.warn("Ignoring incomplete Mission Control environment metadata");
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
values.push({
|
|
209
|
-
id: environment.id,
|
|
210
|
-
name: environment.name,
|
|
211
|
-
kind: environment.kind,
|
|
212
|
-
status: environment.status
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
if (generation !== this._discoveryGeneration) {
|
|
216
|
-
throw ( new CancellationError());
|
|
217
|
-
}
|
|
218
|
-
this._environments = {
|
|
219
|
-
generation,
|
|
220
|
-
fetchedAt: Date.now(),
|
|
221
|
-
values
|
|
222
|
-
};
|
|
223
|
-
return values;
|
|
224
|
-
}
|
|
225
|
-
async listSessions(token, options) {
|
|
226
|
-
const generation = this._discoveryGeneration;
|
|
227
|
-
const since = options?.incremental ? this._discoverySince : undefined;
|
|
228
|
-
const tasks = ( new Map());
|
|
229
|
-
const cache = ( new Map(this._discoveredTasks));
|
|
230
|
-
let truncated = false;
|
|
231
|
-
let checkpoint;
|
|
232
|
-
let latestUpdate;
|
|
233
|
-
for (const {
|
|
234
|
-
withRepository,
|
|
235
|
-
archived
|
|
236
|
-
} of [{
|
|
237
|
-
withRepository: true,
|
|
238
|
-
archived: false
|
|
239
|
-
}, {
|
|
240
|
-
withRepository: false,
|
|
241
|
-
archived: false
|
|
242
|
-
}, {
|
|
243
|
-
withRepository: true,
|
|
244
|
-
archived: true
|
|
245
|
-
}, {
|
|
246
|
-
withRepository: false,
|
|
247
|
-
archived: true
|
|
248
|
-
}]) {
|
|
249
|
-
for (let page = 1; page <= DISCOVERY_TASK_PAGE_LIMIT; page++) {
|
|
250
|
-
if (token.isCancellationRequested) {
|
|
251
|
-
throw ( new CancellationError());
|
|
252
|
-
}
|
|
253
|
-
const query = {
|
|
254
|
-
per_page: String(DISCOVERY_TASK_SCAN_LIMIT),
|
|
255
|
-
page: String(page),
|
|
256
|
-
sort: "updated_at",
|
|
257
|
-
direction: "desc",
|
|
258
|
-
with_repo: String(withRepository),
|
|
259
|
-
is_archived: String(archived),
|
|
260
|
-
...(since ? {
|
|
261
|
-
since,
|
|
262
|
-
include_environment_kinds: "managed-sandbox"
|
|
263
|
-
} : {})
|
|
264
|
-
};
|
|
265
|
-
try {
|
|
266
|
-
const context = await this._sendTask(`${this._tasksBaseUrl()}/tasks${toQuery(query)}`, "list", token);
|
|
267
|
-
const response = await this._readJson(context);
|
|
268
|
-
if (!Array.isArray(response?.tasks)) {
|
|
269
|
-
throw ( new Error("listTasks returned no tasks array"));
|
|
270
|
-
}
|
|
271
|
-
const date = context.res.headers?.date;
|
|
272
|
-
const serverTime = typeof date === "string" ? Date.parse(date) : Number.NaN;
|
|
273
|
-
if (!Number.isNaN(serverTime)) {
|
|
274
|
-
checkpoint = Math.min(checkpoint ?? serverTime, serverTime);
|
|
275
|
-
}
|
|
276
|
-
for (const task of response.tasks) {
|
|
277
|
-
tasks.set(task.id, {
|
|
278
|
-
...task,
|
|
279
|
-
hasRepository: withRepository
|
|
280
|
-
});
|
|
281
|
-
const updatedAt = task.updated_at ? Date.parse(task.updated_at) : Number.NaN;
|
|
282
|
-
if (!Number.isNaN(updatedAt)) {
|
|
283
|
-
latestUpdate = Math.max(latestUpdate ?? updatedAt, updatedAt);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (!hasNextLink(context.res.headers?.link)) {
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
if (page === DISCOVERY_TASK_PAGE_LIMIT) {
|
|
290
|
-
truncated = true;
|
|
291
|
-
}
|
|
292
|
-
} catch (error) {
|
|
293
|
-
if (isCancellationError(error) || token.isCancellationRequested) {
|
|
294
|
-
throw ( new CancellationError());
|
|
295
|
-
}
|
|
296
|
-
if (tasks.size === 0) {
|
|
297
|
-
return {
|
|
298
|
-
kind: "failed",
|
|
299
|
-
reason: `listTasks failed: ${toErrorMessage(error)}`
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
this._logService.warn(
|
|
303
|
-
`${LOG_PREFIX} Discovery page ${page} (with_repo=${withRepository}) failed: ${toErrorMessage(error)}`
|
|
304
|
-
);
|
|
305
|
-
truncated = true;
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
const scannedTaskIds = ( new Set(( tasks.keys())));
|
|
311
|
-
if (since) {
|
|
312
|
-
for (const [id, cached] of cache) {
|
|
313
|
-
if (!( tasks.has(id)) && (cached.needsRefresh || !cached.session || cached.unstartedSince !== undefined || (cached.repositoryId !== undefined && !cached.session.repoName))) {
|
|
314
|
-
tasks.set(id, cached.summary);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
const discoveryTime = checkpoint ?? Date.now();
|
|
319
|
-
const removedTaskIds = [];
|
|
320
|
-
const sandboxTasks = [];
|
|
321
|
-
for (const task of ( tasks.values())) {
|
|
322
|
-
if (isCloudSandboxTask(task)) {
|
|
323
|
-
sandboxTasks.push(task);
|
|
324
|
-
} else {
|
|
325
|
-
if (( cache.has(task.id)) || isCloudSandboxTask(task)) {
|
|
326
|
-
removedTaskIds.push(task.id);
|
|
327
|
-
}
|
|
328
|
-
cache.delete(task.id);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
let unresolved = 0;
|
|
332
|
-
const limiter = ( new Limiter(DISCOVERY_TASK_FETCH_CONCURRENCY));
|
|
333
|
-
let discovered;
|
|
334
|
-
try {
|
|
335
|
-
discovered = await Promise.all(sandboxTasks.map(task => limiter.queue(async () => {
|
|
336
|
-
try {
|
|
337
|
-
if (token.isCancellationRequested) {
|
|
338
|
-
throw ( new CancellationError());
|
|
339
|
-
}
|
|
340
|
-
let cached = cache.get(task.id);
|
|
341
|
-
if (cached?.needsRefresh || !cached?.session || !task.updated_at || task.updated_at !== cached.summary.updated_at || task.archived_at !== cached.summary.archived_at || task.hasRepository !== cached.summary.hasRepository) {
|
|
342
|
-
const context = await this._sendTask(
|
|
343
|
-
`${this._tasksBaseUrl()}/tasks/${encodeURIComponent(task.id)}`,
|
|
344
|
-
"get",
|
|
345
|
-
token
|
|
346
|
-
);
|
|
347
|
-
const full = await this._readJson(context);
|
|
348
|
-
if (!full) {
|
|
349
|
-
throw ( new Error("getTask returned no task"));
|
|
350
|
-
}
|
|
351
|
-
const binding = getTaskEnvironmentBinding(full);
|
|
352
|
-
if (!binding && cached?.session) {
|
|
353
|
-
removedTaskIds.push(task.id);
|
|
354
|
-
}
|
|
355
|
-
const status = binding ? taskSessionStatus(
|
|
356
|
-
full.sessions?.find(session => session.id === binding.sessionId)?.state ?? full.state ?? task.state,
|
|
357
|
-
this._logService
|
|
358
|
-
) : undefined;
|
|
359
|
-
const eventType = full.event_type || task.event_type;
|
|
360
|
-
const repositoryId = [full.repository?.id, task.repository?.id].find(id => id !== undefined && id > 0);
|
|
361
|
-
cached = {
|
|
362
|
-
summary: task,
|
|
363
|
-
repositoryId,
|
|
364
|
-
unstartedSince: getUnstartedSessionCreatedAt(full),
|
|
365
|
-
session: binding ? {
|
|
366
|
-
...binding,
|
|
367
|
-
taskId: task.id,
|
|
368
|
-
...(eventType ? {
|
|
369
|
-
eventType
|
|
370
|
-
} : {}),
|
|
371
|
-
name: full.name ?? task.name ?? `Sandbox ${task.id}`,
|
|
372
|
-
hasRepository: task.hasRepository || repositoryId !== undefined,
|
|
373
|
-
updatedAt: full.updated_at ?? task.updated_at,
|
|
374
|
-
...(status !== undefined ? {
|
|
375
|
-
status
|
|
376
|
-
} : {}),
|
|
377
|
-
...(full.archived_at ? {
|
|
378
|
-
isArchived: true
|
|
379
|
-
} : {})
|
|
380
|
-
} : undefined
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
if (cached.unstartedSince !== undefined && discoveryTime - cached.unstartedSince >= STALLED_SESSION_GRACE_MS) {
|
|
384
|
-
cache.set(task.id, cached);
|
|
385
|
-
if (!truncated || ( scannedTaskIds.has(task.id))) {
|
|
386
|
-
removedTaskIds.push(task.id);
|
|
387
|
-
this._logService.trace(
|
|
388
|
-
`${LOG_PREFIX} Hiding stalled queued sandbox task ${task.id} with no AHP resource.`
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
return undefined;
|
|
392
|
-
}
|
|
393
|
-
if (cached.session && cached.repositoryId !== undefined && !cached.session.repoName) {
|
|
394
|
-
const repoName = await this._resolveRepositoryName(cached.repositoryId, token);
|
|
395
|
-
cached = {
|
|
396
|
-
...cached,
|
|
397
|
-
session: {
|
|
398
|
-
...cached.session,
|
|
399
|
-
repoName
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
cache.set(task.id, cached);
|
|
404
|
-
return cached.session;
|
|
405
|
-
} catch (error) {
|
|
406
|
-
if (isCancellationError(error) || token.isCancellationRequested) {
|
|
407
|
-
throw ( new CancellationError());
|
|
408
|
-
}
|
|
409
|
-
this._logService.warn(
|
|
410
|
-
`${LOG_PREFIX} Discovery getTask ${task.id} failed: ${toErrorMessage(error)}`
|
|
411
|
-
);
|
|
412
|
-
cache.set(task.id, {
|
|
413
|
-
...cache.get(task.id),
|
|
414
|
-
summary: task,
|
|
415
|
-
needsRefresh: true
|
|
416
|
-
});
|
|
417
|
-
unresolved++;
|
|
418
|
-
return undefined;
|
|
419
|
-
}
|
|
420
|
-
})));
|
|
421
|
-
} finally {
|
|
422
|
-
limiter.dispose();
|
|
423
|
-
}
|
|
424
|
-
if (token.isCancellationRequested) {
|
|
425
|
-
throw ( new CancellationError());
|
|
426
|
-
}
|
|
427
|
-
if (generation !== this._discoveryGeneration) {
|
|
428
|
-
return {
|
|
429
|
-
kind: "failed",
|
|
430
|
-
reason: "Sandbox discovery was invalidated while listing sessions"
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
const partial = unresolved > 0 || truncated;
|
|
434
|
-
if (!partial) {
|
|
435
|
-
const nextCheckpoint = checkpoint ?? latestUpdate;
|
|
436
|
-
if (nextCheckpoint !== undefined) {
|
|
437
|
-
this._discoverySince = ( new Date(nextCheckpoint - DISCOVERY_OVERLAP_MS)).toISOString();
|
|
438
|
-
}
|
|
439
|
-
if (!since) {
|
|
440
|
-
for (const id of ( cache.keys())) {
|
|
441
|
-
if (!( scannedTaskIds.has(id))) {
|
|
442
|
-
cache.delete(id);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
this._discoveredTasks.clear();
|
|
448
|
-
for (const [id, cached] of cache) {
|
|
449
|
-
this._discoveredTasks.set(id, cached);
|
|
450
|
-
}
|
|
451
|
-
const sessions = discovered.filter(session => session !== undefined);
|
|
452
|
-
const unnamed = sessions.filter(session => !session.repoName).length;
|
|
453
|
-
this._logService.info(
|
|
454
|
-
`${LOG_PREFIX} ${since ? "Incremental discovery" : "Discovery"} found ${sessions.length} sandbox session(s) from ${sandboxTasks.length} sandbox task(s) out of ${scannedTaskIds.size} scanned${truncated ? " (scan truncated)" : ""}${unresolved > 0 ? `; ${unresolved} unresolved` : ""}${unnamed > 0 ? `; ${unnamed} without a repository name (they group under "Unknown")` : ""}.`
|
|
455
|
-
);
|
|
456
|
-
for (const session of sessions) {
|
|
457
|
-
this._logService.debug(`${LOG_PREFIX} Discovered sandbox session ${JSON.stringify({
|
|
458
|
-
taskId: session.taskId,
|
|
459
|
-
sessionId: session.sessionId,
|
|
460
|
-
environmentId: session.environmentId,
|
|
461
|
-
name: session.name,
|
|
462
|
-
repoName: session.repoName,
|
|
463
|
-
updatedAt: session.updatedAt,
|
|
464
|
-
status: session.status
|
|
465
|
-
})}`);
|
|
466
|
-
}
|
|
467
|
-
if (partial) {
|
|
468
|
-
return {
|
|
469
|
-
kind: "partial",
|
|
470
|
-
sessions,
|
|
471
|
-
removedTaskIds
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
return since ? {
|
|
475
|
-
kind: "incremental",
|
|
476
|
-
sessions,
|
|
477
|
-
removedTaskIds
|
|
478
|
-
} : {
|
|
479
|
-
kind: "complete",
|
|
480
|
-
sessions
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
async createSession(request, token) {
|
|
484
|
-
const startedAt = Date.now();
|
|
485
|
-
try {
|
|
486
|
-
const created = await this._createSession(request, token);
|
|
487
|
-
this._telemetry.reportProvisioningOutcome(
|
|
488
|
-
token.isCancellationRequested ? "cancelled" : "success",
|
|
489
|
-
Math.max(0, Date.now() - startedAt)
|
|
490
|
-
);
|
|
491
|
-
return created;
|
|
492
|
-
} catch (error) {
|
|
493
|
-
this._telemetry.reportProvisioningOutcome(
|
|
494
|
-
isCancellationError(error) || token.isCancellationRequested ? "cancelled" : "failure",
|
|
495
|
-
Math.max(0, Date.now() - startedAt)
|
|
496
|
-
);
|
|
497
|
-
throw error;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
async _createSession(request, token) {
|
|
501
|
-
const repository = parseNwo(request.repoNwo);
|
|
502
|
-
if (request.repoNwo !== undefined && !repository) {
|
|
503
|
-
throw ( new Error(( localize(13249, "The sandbox repository must be specified as owner/name."))));
|
|
504
|
-
}
|
|
505
|
-
const context = await this._request(`${this._tasksBaseUrl()}/tasks`, "mc.taskClient.create", "createTask", {
|
|
506
|
-
"Accept": "application/json",
|
|
507
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
508
|
-
}, token, CREATE_TIMEOUT_MS, session => ({
|
|
509
|
-
environment_id: CLOUD_SANDBOX_ON_DEMAND_ENVIRONMENT_ID,
|
|
510
|
-
prompt: request.prompt,
|
|
511
|
-
...(repository ? {
|
|
512
|
-
repositories: [repository]
|
|
513
|
-
} : {
|
|
514
|
-
compute: {
|
|
515
|
-
scope: session.account.label
|
|
516
|
-
}
|
|
517
|
-
})
|
|
518
|
-
}));
|
|
519
|
-
if (!isSuccess(context)) {
|
|
520
|
-
const failureBody = (await asText(context).catch(() => "")) ?? "";
|
|
521
|
-
this._logService.error(
|
|
522
|
-
`${LOG_PREFIX} Task create failed. ${this._describeResponse(context, failureBody)}`
|
|
523
|
-
);
|
|
524
|
-
const orphanedTaskId = this._taskIdFromFailure(failureBody);
|
|
525
|
-
if (orphanedTaskId) {
|
|
526
|
-
await this._deleteTaskBestEffort(orphanedTaskId);
|
|
527
|
-
} else {
|
|
528
|
-
this._logService.warn(
|
|
529
|
-
`${LOG_PREFIX} Task create failed (HTTP ${context.res.statusCode ?? "unknown"}) without reporting a task id. Mission Control may have recorded a task before failing; such a task is orphaned and can only be removed server-side.`
|
|
530
|
-
);
|
|
531
|
-
}
|
|
532
|
-
await this._throwForStatus("task create", context, failureBody);
|
|
533
|
-
}
|
|
534
|
-
const task = await this._readJson(context);
|
|
535
|
-
const taskId = task?.id;
|
|
536
|
-
if (!taskId) {
|
|
537
|
-
throw ( new CloudSandboxRequestError(context.res.statusCode, "Mission Control task create returned no task id"));
|
|
538
|
-
}
|
|
539
|
-
const binding = task && getTaskEnvironmentBinding(task);
|
|
540
|
-
if (!binding) {
|
|
541
|
-
await this._deleteTaskBestEffort(taskId);
|
|
542
|
-
throw ( new CloudSandboxRequestError(
|
|
543
|
-
context.res.statusCode,
|
|
544
|
-
`Mission Control bound no sandbox session to task ${taskId}`
|
|
545
|
-
));
|
|
546
|
-
}
|
|
547
|
-
this._logService.info(
|
|
548
|
-
`${LOG_PREFIX} Provisioned sandbox task ${taskId} (session ${binding.sessionId}) on environment ${binding.environmentId}.`
|
|
549
|
-
);
|
|
550
|
-
return {
|
|
551
|
-
taskId,
|
|
552
|
-
sessionId: binding.sessionId,
|
|
553
|
-
environmentId: binding.environmentId
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
async deleteTask(taskId, token) {
|
|
557
|
-
const context = await this._request(
|
|
558
|
-
`${this._tasksBaseUrl()}/tasks/${encodeURIComponent(taskId)}`,
|
|
559
|
-
"mc.taskClient.delete",
|
|
560
|
-
"deleteTask",
|
|
561
|
-
{
|
|
562
|
-
"Accept": "application/json",
|
|
563
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
564
|
-
},
|
|
565
|
-
token,
|
|
566
|
-
REQUEST_TIMEOUT_MS,
|
|
567
|
-
undefined,
|
|
568
|
-
"DELETE"
|
|
569
|
-
);
|
|
570
|
-
if (!isSuccess(context) && context.res.statusCode !== 404) {
|
|
571
|
-
await this._throwForStatus("task delete", context);
|
|
572
|
-
}
|
|
573
|
-
this._discoveredTasks.delete(taskId);
|
|
574
|
-
this.clearSessionHistory(taskId);
|
|
575
|
-
this._discoveryGeneration++;
|
|
576
|
-
}
|
|
577
|
-
async renameTask(taskId, title, token) {
|
|
578
|
-
const context = await this._request(
|
|
579
|
-
`${this._tasksBaseUrl()}/tasks/${encodeURIComponent(taskId)}`,
|
|
580
|
-
"mc.taskClient.update",
|
|
581
|
-
"renameTask",
|
|
582
|
-
{
|
|
583
|
-
"Accept": "application/json",
|
|
584
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
585
|
-
},
|
|
586
|
-
token,
|
|
587
|
-
REQUEST_TIMEOUT_MS,
|
|
588
|
-
{
|
|
589
|
-
name: title
|
|
590
|
-
},
|
|
591
|
-
"PATCH"
|
|
592
|
-
);
|
|
593
|
-
if (!isSuccess(context)) {
|
|
594
|
-
await this._throwForStatus("task rename", context);
|
|
595
|
-
}
|
|
596
|
-
this.invalidateSessionHistory(taskId);
|
|
597
|
-
const cached = this._discoveredTasks.get(taskId);
|
|
598
|
-
if (cached) {
|
|
599
|
-
this._discoveredTasks.set(taskId, {
|
|
600
|
-
...cached,
|
|
601
|
-
summary: {
|
|
602
|
-
...cached.summary,
|
|
603
|
-
name: title
|
|
604
|
-
},
|
|
605
|
-
session: cached.session ? {
|
|
606
|
-
...cached.session,
|
|
607
|
-
name: title
|
|
608
|
-
} : undefined,
|
|
609
|
-
needsRefresh: true
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
this._discoveryGeneration++;
|
|
613
|
-
}
|
|
614
|
-
async setTaskArchived(taskId, archived, token) {
|
|
615
|
-
const action = archived ? "archive" : "unarchive";
|
|
616
|
-
const context = await this._request(
|
|
617
|
-
`${this._tasksBaseUrl()}/tasks/${encodeURIComponent(taskId)}/${action}`,
|
|
618
|
-
`mc.taskClient.${action}`,
|
|
619
|
-
archived ? "archiveTask" : "unarchiveTask",
|
|
620
|
-
{
|
|
621
|
-
"Accept": "application/json",
|
|
622
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
623
|
-
},
|
|
624
|
-
token,
|
|
625
|
-
REQUEST_TIMEOUT_MS,
|
|
626
|
-
undefined,
|
|
627
|
-
"POST"
|
|
628
|
-
);
|
|
629
|
-
if (!isSuccess(context)) {
|
|
630
|
-
await this._throwForStatus(`task ${action}`, context);
|
|
631
|
-
}
|
|
632
|
-
this._discoveredTasks.delete(taskId);
|
|
633
|
-
this.invalidateSessionHistory(taskId);
|
|
634
|
-
this._discoveryGeneration++;
|
|
635
|
-
}
|
|
636
|
-
async _deleteTaskBestEffort(taskId) {
|
|
637
|
-
try {
|
|
638
|
-
await this.deleteTask(taskId, CancellationToken.None);
|
|
639
|
-
this._logService.info(`${LOG_PREFIX} Cleaned up unusable sandbox task ${taskId}.`);
|
|
640
|
-
} catch (error) {
|
|
641
|
-
this._logService.warn(
|
|
642
|
-
`${LOG_PREFIX} Could not clean up sandbox task ${taskId}: ${toErrorMessage(error)}. It remains and can only be removed server-side.`
|
|
643
|
-
);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
async getSessionHistory(taskId, token, diagnosticId, onCachedHistory, canCacheHistory) {
|
|
647
|
-
const watch = StopWatch.create(false);
|
|
648
|
-
return this._historyCache.load(taskId, token, async sharedToken => {
|
|
649
|
-
try {
|
|
650
|
-
const authentication = await raceCancellationError(this._resolveGitHubSession(), sharedToken);
|
|
651
|
-
if (!authentication?.accessToken) {
|
|
652
|
-
throw ( new CloudSandboxAuthenticationRequiredError());
|
|
653
|
-
}
|
|
654
|
-
return {
|
|
655
|
-
account: JSON.stringify([
|
|
656
|
-
this._tasksBaseUrl(),
|
|
657
|
-
this._authenticationProviderId,
|
|
658
|
-
authentication.account.id
|
|
659
|
-
]),
|
|
660
|
-
fetch: requestToken => this._fetchSessionHistory(taskId, requestToken, authentication, watch, diagnosticId)
|
|
661
|
-
};
|
|
662
|
-
} catch (error) {
|
|
663
|
-
this._logService.info(
|
|
664
|
-
`${LOG_PREFIX} historyAuthentication traceId=${diagnosticId ?? "standalone"} ${isCancellationError(error) ? "cancelled" : "failed"} durationMs=${watch.elapsed()}`
|
|
665
|
-
);
|
|
666
|
-
throw error;
|
|
667
|
-
}
|
|
668
|
-
}, onCachedHistory && (history => {
|
|
669
|
-
this._logService.info(
|
|
670
|
-
`${LOG_PREFIX} historyCacheHit traceId=${diagnosticId ?? "standalone"} elapsedMs=${watch.elapsed()}`
|
|
671
|
-
);
|
|
672
|
-
onCachedHistory(history);
|
|
673
|
-
}), canCacheHistory);
|
|
674
|
-
}
|
|
675
|
-
invalidateSessionHistory(taskId, preserveCached = false) {
|
|
676
|
-
this._historyCache.invalidate(taskId, false, preserveCached);
|
|
677
|
-
}
|
|
678
|
-
clearSessionHistory(taskId) {
|
|
679
|
-
if (taskId !== undefined) {
|
|
680
|
-
this._historyCache.invalidate(taskId, true);
|
|
681
|
-
} else {
|
|
682
|
-
this._historyCache.clear();
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
async _fetchSessionHistory(taskId, token, authentication, watch, diagnosticId) {
|
|
686
|
-
const loadId = ++this._historyRequestId;
|
|
687
|
-
const traceId = diagnosticId ?? `history-${loadId}`;
|
|
688
|
-
const marks = [];
|
|
689
|
-
const logTiming = (event, details = "") => {
|
|
690
|
-
const name = `code/cloudSandbox/${traceId}/history-${loadId}/${event}`;
|
|
691
|
-
marks.push(name);
|
|
692
|
-
mark(name);
|
|
693
|
-
this._logService.info(
|
|
694
|
-
`${LOG_PREFIX} historyTiming loadId=${loadId} traceId=${traceId} ${event}${details ? ` ${details}` : ""} totalMs=${watch.elapsed()}`
|
|
695
|
-
);
|
|
696
|
-
};
|
|
697
|
-
let phase = "authentication";
|
|
698
|
-
let phaseStarted = 0;
|
|
699
|
-
logTiming("authenticated", `authenticationMs=${watch.elapsed()}`);
|
|
700
|
-
try {
|
|
701
|
-
const url = `${this._tasksBaseUrl()}/tasks/${encodeURIComponent(taskId)}/events`;
|
|
702
|
-
const context = await this._request(url, "mc.taskClient.events", "getTaskEvents", {
|
|
703
|
-
"Accept": "application/vnd.github.ahp+json",
|
|
704
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
705
|
-
}, token, DISCOVERY_TIMEOUT_MS, undefined, undefined, () => {
|
|
706
|
-
phaseStarted = watch.elapsed();
|
|
707
|
-
logTiming("requestIssued", `authenticationMs=${phaseStarted}`);
|
|
708
|
-
phase = "request";
|
|
709
|
-
}, {
|
|
710
|
-
diagnosticId: `${traceId}/history-${loadId}`,
|
|
711
|
-
authentication
|
|
712
|
-
});
|
|
713
|
-
if (token.isCancellationRequested) {
|
|
714
|
-
throw ( new CancellationError());
|
|
715
|
-
}
|
|
716
|
-
const responseReceived = watch.elapsed();
|
|
717
|
-
const requestMs = responseReceived - phaseStarted;
|
|
718
|
-
const requestId = getGitHubRequestId(context.res.headers["x-github-request-id"]);
|
|
719
|
-
logTiming(
|
|
720
|
-
"responseReceived",
|
|
721
|
-
`requestMs=${requestMs} status=${context.res.statusCode ?? "unknown"} responseHeadersMs=${context.timings?.responseHeadersMs ?? "unavailable"} downloadMs=${context.timings?.responseBodyMs ?? "unavailable"} decodedBodyBytes=${context.timings?.decodedBodyBytes ?? "unavailable"} requestId=${requestId ?? "unavailable"}`
|
|
722
|
-
);
|
|
723
|
-
phase = "responseBody";
|
|
724
|
-
phaseStarted = responseReceived;
|
|
725
|
-
if (!isSuccess(context)) {
|
|
726
|
-
if ([401, 403, 404].includes(context.res.statusCode ?? 0)) {
|
|
727
|
-
this.invalidateSessionHistory(taskId);
|
|
728
|
-
}
|
|
729
|
-
await this._throwForStatus("task events", context);
|
|
730
|
-
}
|
|
731
|
-
const body = await this._readJson(context);
|
|
732
|
-
if (token.isCancellationRequested) {
|
|
733
|
-
throw ( new CancellationError());
|
|
734
|
-
}
|
|
735
|
-
const bodyRead = watch.elapsed();
|
|
736
|
-
const bodyReadAndParseMs = bodyRead - phaseStarted;
|
|
737
|
-
logTiming("bodyRead", `bodyReadAndParseMs=${bodyReadAndParseMs}`);
|
|
738
|
-
if (body === undefined) {
|
|
739
|
-
throw ( new TaskEventReplayError("Task AHP history response was empty or not JSON."));
|
|
740
|
-
}
|
|
741
|
-
phase = "replay";
|
|
742
|
-
phaseStarted = bodyRead;
|
|
743
|
-
const events = parseTaskEventsResponse(body);
|
|
744
|
-
const history = replayTaskAhpEvents(events);
|
|
745
|
-
logTiming(
|
|
746
|
-
"completed",
|
|
747
|
-
`apiMs=${requestMs + bodyReadAndParseMs} replayMs=${watch.elapsed() - phaseStarted} events=${events.length} sessions=${history?.sessions.length ?? 0} truncated=${history?.truncated ?? false}`
|
|
748
|
-
);
|
|
749
|
-
return history;
|
|
750
|
-
} catch (error) {
|
|
751
|
-
logTiming(
|
|
752
|
-
isCancellationError(error) || token.isCancellationRequested ? "cancelled" : "failed",
|
|
753
|
-
`phase=${phase} phaseMs=${watch.elapsed() - phaseStarted}`
|
|
754
|
-
);
|
|
755
|
-
throw error;
|
|
756
|
-
} finally {
|
|
757
|
-
for (const name of marks) {
|
|
758
|
-
clearMarks(name);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
_resolveRepositoryName(repositoryId, token) {
|
|
763
|
-
const cached = this._repositoryNames.get(repositoryId);
|
|
764
|
-
if (cached) {
|
|
765
|
-
return cached;
|
|
766
|
-
}
|
|
767
|
-
const pending = (async () => {
|
|
768
|
-
try {
|
|
769
|
-
const url = `${GITHUB_DOT_COM_API_BASE_URI}/repositories/${repositoryId}`;
|
|
770
|
-
const context = await this._retryWhileRateLimited(
|
|
771
|
-
"repository get",
|
|
772
|
-
token,
|
|
773
|
-
() => this._request(url, "mc.repositoryClient.get", "getRepository", {
|
|
774
|
-
"Accept": "application/vnd.github.v3+json"
|
|
775
|
-
}, token, DISCOVERY_TIMEOUT_MS)
|
|
776
|
-
);
|
|
777
|
-
if (!isSuccess(context)) {
|
|
778
|
-
throw ( new CloudSandboxRequestError(context.res.statusCode, `HTTP ${context.res.statusCode ?? "none"}`));
|
|
779
|
-
}
|
|
780
|
-
const body = await this._readJson(context);
|
|
781
|
-
return body?.full_name;
|
|
782
|
-
} catch (error) {
|
|
783
|
-
this._logService.warn(
|
|
784
|
-
`${LOG_PREFIX} Repository ${repositoryId} lookup failed: ${toErrorMessage(error)}`
|
|
785
|
-
);
|
|
786
|
-
return undefined;
|
|
787
|
-
}
|
|
788
|
-
})();
|
|
789
|
-
this._repositoryNames.set(repositoryId, pending);
|
|
790
|
-
pending.then(name => {
|
|
791
|
-
if (!name && this._repositoryNames.get(repositoryId) === pending) {
|
|
792
|
-
this._repositoryNames.delete(repositoryId);
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
return pending;
|
|
796
|
-
}
|
|
797
|
-
async _connectRequest(action, environmentId, token, searchParams, onRequest) {
|
|
798
|
-
const watch = StopWatch.create(false);
|
|
799
|
-
const context = await this._sendEnvironment(action, environmentId, token, searchParams, onRequest);
|
|
800
|
-
if (context.res.statusCode === 202) {
|
|
801
|
-
onRequest?.("waking");
|
|
802
|
-
const retryAfterSeconds = parseRetryAfter(context.res.headers?.["retry-after"]);
|
|
803
|
-
this._logService.debug(
|
|
804
|
-
`${LOG_PREFIX} ${action}: environment waking, retry after ${retryAfterSeconds}s`
|
|
805
|
-
);
|
|
806
|
-
return {
|
|
807
|
-
kind: "waking",
|
|
808
|
-
waking: {
|
|
809
|
-
retryAfterSeconds
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
if (!isSuccess(context)) {
|
|
814
|
-
const requestId = getGitHubRequestId(context.res.headers["x-github-request-id"]);
|
|
815
|
-
const retryAfter = retryAfterSeconds(context.res.headers["retry-after"]);
|
|
816
|
-
const status = context.res.statusCode;
|
|
817
|
-
const responseError = await this._readJson(context);
|
|
818
|
-
const detail = typeof responseError?.message === "string" ? sanitizeConnectionDiagnosticText(responseError.message) : undefined;
|
|
819
|
-
this._logService.error(`${LOG_PREFIX} ${action} failed: method=GET host=${( new URL(GITHUB_DOT_COM_COPILOT_API_BASE_URI)).host} environmentId=${environmentId} sessionId=${searchParams.session_id ?? "none"} clientId=${searchParams.client_id ?? "none"} status=${status ?? "unknown"} requestId=${requestId ?? "unavailable"} durationMs=${watch.elapsed()} retryAfterSeconds=${retryAfter ?? "none"}${detail ? ` message=${detail}` : ""}`);
|
|
820
|
-
throw ( new CloudSandboxRequestError(
|
|
821
|
-
status,
|
|
822
|
-
`Mission Control ${action} failed: HTTP ${status ?? "unknown"}${requestId ? ` (requestId=${requestId})` : ""}`,
|
|
823
|
-
retryAfter
|
|
824
|
-
));
|
|
825
|
-
}
|
|
826
|
-
const clientToken = await this._readJson(context);
|
|
827
|
-
if (!clientToken?.access_token || !clientToken?.wps_endpoint || !clientToken?.client_id || !clientToken?.groups) {
|
|
828
|
-
throw ( new Error(`Mission Control ${action} returned an incomplete token response`));
|
|
829
|
-
}
|
|
830
|
-
return {
|
|
831
|
-
kind: "token",
|
|
832
|
-
token: clientToken
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
async _sendEnvironment(action, environmentId, token, searchParams, onRequest) {
|
|
836
|
-
const path = action === "get" ? "" : `/${action}`;
|
|
837
|
-
const url = `${GITHUB_DOT_COM_COPILOT_API_BASE_URI}/agents/environments/${encodeURIComponent(environmentId)}${path}${toQuery(searchParams)}`;
|
|
838
|
-
return this._request(
|
|
839
|
-
url,
|
|
840
|
-
`mc.environmentClient.${action}`,
|
|
841
|
-
action === "get" ? "getEnvironment" : action,
|
|
842
|
-
{
|
|
843
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
844
|
-
},
|
|
845
|
-
token,
|
|
846
|
-
action === "get" ? REQUEST_TIMEOUT_MS : CONNECTION_REQUEST_TIMEOUT_MS,
|
|
847
|
-
undefined,
|
|
848
|
-
undefined,
|
|
849
|
-
onRequest
|
|
850
|
-
);
|
|
851
|
-
}
|
|
852
|
-
async _sendTask(url, action, token) {
|
|
853
|
-
const context = await this._retryWhileRateLimited(`task ${action}`, token, () => this._request(
|
|
854
|
-
url,
|
|
855
|
-
`mc.taskClient.${action}`,
|
|
856
|
-
action === "list" ? "listTasks" : "getTask",
|
|
857
|
-
{
|
|
858
|
-
"Accept": "application/json",
|
|
859
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
860
|
-
},
|
|
861
|
-
token,
|
|
862
|
-
DISCOVERY_TIMEOUT_MS
|
|
863
|
-
));
|
|
864
|
-
if (!isSuccess(context)) {
|
|
865
|
-
await this._throwForStatus(`task ${action}`, context);
|
|
866
|
-
}
|
|
867
|
-
return context;
|
|
868
|
-
}
|
|
869
|
-
async _retryWhileRateLimited(action, token, send) {
|
|
870
|
-
let waited = 0;
|
|
871
|
-
for (let attempt = 0; ; attempt++) {
|
|
872
|
-
const context = await send();
|
|
873
|
-
if (context.res.statusCode !== HTTP_TOO_MANY_REQUESTS || attempt >= RATE_LIMIT_MAX_RETRIES || token.isCancellationRequested) {
|
|
874
|
-
return context;
|
|
875
|
-
}
|
|
876
|
-
const delay = rateLimitDelay(context.res.headers?.["retry-after"], attempt);
|
|
877
|
-
if (waited + delay > RATE_LIMIT_WAIT_BUDGET_MS) {
|
|
878
|
-
this._logService.warn(
|
|
879
|
-
`${LOG_PREFIX} ${action} was rate limited and asks for another ${delay}ms, beyond what is left of its ${RATE_LIMIT_WAIT_BUDGET_MS}ms budget; giving up so the pass stays bounded. A later pass retries it.`
|
|
880
|
-
);
|
|
881
|
-
return context;
|
|
882
|
-
}
|
|
883
|
-
await asText(context).catch(() => undefined);
|
|
884
|
-
this._logService.warn(
|
|
885
|
-
`${LOG_PREFIX} ${action} was rate limited; retrying in ${delay}ms (attempt ${attempt + 1} of ${RATE_LIMIT_MAX_RETRIES}).`
|
|
886
|
-
);
|
|
887
|
-
await timeout(delay, token);
|
|
888
|
-
waited += delay;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
async _request(
|
|
892
|
-
url,
|
|
893
|
-
callSite,
|
|
894
|
-
action,
|
|
895
|
-
headers,
|
|
896
|
-
token,
|
|
897
|
-
timeoutMs = REQUEST_TIMEOUT_MS,
|
|
898
|
-
body,
|
|
899
|
-
method,
|
|
900
|
-
onRequest,
|
|
901
|
-
diagnostics
|
|
902
|
-
) {
|
|
903
|
-
const session = diagnostics?.authentication ?? (await this._resolveGitHubSession());
|
|
904
|
-
if (!session?.accessToken) {
|
|
905
|
-
throw ( new CloudSandboxAuthenticationRequiredError());
|
|
906
|
-
}
|
|
907
|
-
const accessToken = session.accessToken;
|
|
908
|
-
const started = Date.now();
|
|
909
|
-
const requestMethod = method ?? (body === undefined ? "GET" : "POST");
|
|
910
|
-
try {
|
|
911
|
-
if (token.isCancellationRequested) {
|
|
912
|
-
throw ( new CancellationError());
|
|
913
|
-
}
|
|
914
|
-
onRequest?.("issued");
|
|
915
|
-
const context = await this._requestService.request({
|
|
916
|
-
type: requestMethod,
|
|
917
|
-
url,
|
|
918
|
-
headers: {
|
|
919
|
-
...headers,
|
|
920
|
-
...(body === undefined ? undefined : {
|
|
921
|
-
["Content-Type"]: "application/json"
|
|
922
|
-
}),
|
|
923
|
-
["Authorization"]: `Bearer ${accessToken}`
|
|
924
|
-
},
|
|
925
|
-
...(body === undefined ? undefined : {
|
|
926
|
-
data: JSON.stringify(typeof body === "function" ? body(session) : body)
|
|
927
|
-
}),
|
|
928
|
-
timeout: timeoutMs,
|
|
929
|
-
callSite,
|
|
930
|
-
...(diagnostics ? {
|
|
931
|
-
diagnosticId: diagnostics.diagnosticId
|
|
932
|
-
} : {})
|
|
933
|
-
}, token).catch(error => {
|
|
934
|
-
if ((action === "connect" || action === "reconnect") && !isCancellationError(error) && !token.isCancellationRequested) {
|
|
935
|
-
throw ( new CloudSandboxNetworkError(toErrorMessage(error), {
|
|
936
|
-
cause: error
|
|
937
|
-
}));
|
|
938
|
-
}
|
|
939
|
-
throw error;
|
|
940
|
-
});
|
|
941
|
-
this._telemetry.reportRequest(action, requestOutcomeForStatus(context.res.statusCode));
|
|
942
|
-
this._logService.trace(
|
|
943
|
-
`${LOG_PREFIX} ${action} -> HTTP ${context.res.statusCode ?? "none"} in ${Date.now() - started}ms (budget ${timeoutMs}ms)${context.res.headers?.["retry-after"] ? `, Retry-After: ${context.res.headers["retry-after"]}` : ""}`
|
|
944
|
-
);
|
|
945
|
-
return context;
|
|
946
|
-
} catch (error) {
|
|
947
|
-
const cancellationError = isCancellationError(error) ? error : token.isCancellationRequested ? ( new CancellationError()) : undefined;
|
|
948
|
-
if (cancellationError) {
|
|
949
|
-
this._logService.trace(
|
|
950
|
-
`${LOG_PREFIX} ${action} -> cancelled after ${Date.now() - started}ms (budget ${timeoutMs}ms)`
|
|
951
|
-
);
|
|
952
|
-
} else {
|
|
953
|
-
this._telemetry.reportRequest(action, "networkError");
|
|
954
|
-
this._logService.trace(
|
|
955
|
-
`${LOG_PREFIX} ${action} -> failed after ${Date.now() - started}ms (budget ${timeoutMs}ms)`
|
|
956
|
-
);
|
|
957
|
-
this._logService.error(`${LOG_PREFIX} ${requestMethod} ${url} failed: ${toErrorMessage(error)}`);
|
|
958
|
-
}
|
|
959
|
-
throw cancellationError ?? error;
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
_tasksBaseUrl() {
|
|
963
|
-
return `${GITHUB_DOT_COM_COPILOT_API_BASE_URI}/agents`;
|
|
964
|
-
}
|
|
965
|
-
async listModels(token) {
|
|
966
|
-
const context = await this._request(`${this._tasksBaseUrl()}/swe/models`, "mc.models.list", "listModels", {
|
|
967
|
-
"Accept": "application/json",
|
|
968
|
-
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID
|
|
969
|
-
}, token, DISCOVERY_TIMEOUT_MS);
|
|
970
|
-
if (!isSuccess(context)) {
|
|
971
|
-
await this._throwForStatus("model catalog", context);
|
|
972
|
-
}
|
|
973
|
-
const catalog = await this._readJson(context);
|
|
974
|
-
if (!catalog || !Array.isArray(catalog.data) || (catalog.default_model !== undefined && typeof catalog.default_model !== "string")) {
|
|
975
|
-
throw ( new Error("Mission Control returned an invalid model catalog."));
|
|
976
|
-
}
|
|
977
|
-
const models = [];
|
|
978
|
-
for (const model of catalog.data) {
|
|
979
|
-
const efforts = model?.capabilities?.supports?.reasoning_effort;
|
|
980
|
-
if (!model || typeof model.id !== "string" || !model.id || typeof model.name !== "string" || (efforts !== undefined && (!Array.isArray(efforts) || !efforts.every(value => typeof value === "string")))) {
|
|
981
|
-
throw ( new Error("Mission Control returned invalid model metadata."));
|
|
982
|
-
}
|
|
983
|
-
if (model.model_picker_enabled === false || model.policy?.state === "disabled") {
|
|
984
|
-
continue;
|
|
985
|
-
}
|
|
986
|
-
models.push({
|
|
987
|
-
id: model.id,
|
|
988
|
-
name: model.name,
|
|
989
|
-
provider: "copilot",
|
|
990
|
-
maxContextWindow: model.capabilities?.limits?.max_context_window_tokens,
|
|
991
|
-
maxPromptTokens: model.capabilities?.limits?.max_prompt_tokens,
|
|
992
|
-
maxOutputTokens: model.capabilities?.limits?.max_output_tokens,
|
|
993
|
-
supportsVision: model.capabilities?.supports?.vision,
|
|
994
|
-
_meta: createPricingMetaFromBilling(
|
|
995
|
-
normalizeCAPIBilling(model.billing),
|
|
996
|
-
model.model_picker_price_category,
|
|
997
|
-
model.model_picker_category
|
|
998
|
-
),
|
|
999
|
-
...(efforts?.length ? {
|
|
1000
|
-
configSchema: {
|
|
1001
|
-
type: "object",
|
|
1002
|
-
properties: {
|
|
1003
|
-
reasoningEffort: {
|
|
1004
|
-
type: "string",
|
|
1005
|
-
title: ( localize(13250, "Reasoning Effort")),
|
|
1006
|
-
enum: [...efforts]
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
} : {})
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1013
|
-
return {
|
|
1014
|
-
models,
|
|
1015
|
-
defaultModel: catalog.default_model
|
|
1016
|
-
};
|
|
1017
|
-
}
|
|
1018
|
-
async _readJson(context) {
|
|
1019
|
-
const body = await asText(context);
|
|
1020
|
-
if (!body) {
|
|
1021
|
-
return undefined;
|
|
1022
|
-
}
|
|
1023
|
-
try {
|
|
1024
|
-
return JSON.parse(body);
|
|
1025
|
-
} catch {
|
|
1026
|
-
return undefined;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
async _throwForStatus(action, context, prereadBody) {
|
|
1030
|
-
const body = prereadBody ?? (await asText(context).catch(() => ""));
|
|
1031
|
-
const status = context.res.statusCode;
|
|
1032
|
-
throw ( new CloudSandboxRequestError(
|
|
1033
|
-
status,
|
|
1034
|
-
`Mission Control ${action} failed: HTTP ${status ?? "unknown"} - ${(body ?? "").slice(0, 200)}`,
|
|
1035
|
-
retryAfterSeconds(context.res.headers?.["retry-after"])
|
|
1036
|
-
));
|
|
1037
|
-
}
|
|
1038
|
-
_describeResponse(context, body) {
|
|
1039
|
-
const headers = context.res.headers ?? {};
|
|
1040
|
-
const parts = [`HTTP ${context.res.statusCode ?? "none"}`];
|
|
1041
|
-
for (const name of DIAGNOSTIC_RESPONSE_HEADERS) {
|
|
1042
|
-
const value = headers[name];
|
|
1043
|
-
if (value !== undefined) {
|
|
1044
|
-
parts.push(`${name}: ${Array.isArray(value) ? value.join(", ") : value}`);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
parts.push(`body: ${body || "<empty>"}`);
|
|
1048
|
-
return parts.join(" | ");
|
|
1049
|
-
}
|
|
1050
|
-
_taskIdFromFailure(body) {
|
|
1051
|
-
if (!body) {
|
|
1052
|
-
return undefined;
|
|
1053
|
-
}
|
|
1054
|
-
try {
|
|
1055
|
-
const parsed = JSON.parse(body);
|
|
1056
|
-
for (const candidate of [parsed?.id, parsed?.task_id]) {
|
|
1057
|
-
if (typeof candidate === "string" && candidate.length > 0) {
|
|
1058
|
-
return candidate;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
} catch {}
|
|
1062
|
-
return undefined;
|
|
1063
|
-
}
|
|
1064
|
-
async _resolveGitHubSession() {
|
|
1065
|
-
const providerId = this._authenticationProviderId;
|
|
1066
|
-
const scopes = this._productService.defaultChatAgent?.providerScopes?.[0] ?? FALLBACK_SCOPES;
|
|
1067
|
-
let exact;
|
|
1068
|
-
try {
|
|
1069
|
-
exact = await this._authenticationService.getSessions(providerId, [...scopes], undefined, true);
|
|
1070
|
-
} catch (error) {
|
|
1071
|
-
this._logService.warn(
|
|
1072
|
-
`${LOG_PREFIX} getSessions('${providerId}') failed: ${toErrorMessage(error)}`
|
|
1073
|
-
);
|
|
1074
|
-
throw ( new CloudSandboxAuthenticationRequiredError());
|
|
1075
|
-
}
|
|
1076
|
-
if (exact.length > 0) {
|
|
1077
|
-
return exact[0];
|
|
1078
|
-
}
|
|
1079
|
-
const all = await this._authenticationService.getSessions(providerId, undefined, undefined, true);
|
|
1080
|
-
const required = ( new Set(scopes));
|
|
1081
|
-
let best;
|
|
1082
|
-
for (const session of all) {
|
|
1083
|
-
const granted = ( new Set(session.scopes));
|
|
1084
|
-
if ([...required].every(scope => ( granted.has(scope)))) {
|
|
1085
|
-
const extra = granted.size - required.size;
|
|
1086
|
-
if (!best || extra < best.extra) {
|
|
1087
|
-
best = {
|
|
1088
|
-
session,
|
|
1089
|
-
extra
|
|
1090
|
-
};
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
if (!best) {
|
|
1095
|
-
this._logService.warn(
|
|
1096
|
-
`${LOG_PREFIX} No '${providerId}' session with scopes [${scopes.join(", ")}]`
|
|
1097
|
-
);
|
|
1098
|
-
}
|
|
1099
|
-
return best?.session;
|
|
1100
|
-
}
|
|
1101
|
-
};
|
|
1102
|
-
CloudSandboxApiService = ( __decorate([( __param(0, IRequestService)), ( __param(1, IAuthenticationService)), ( __param(2, IProductService)), ( __param(3, ILogService)), ( __param(4, ICloudSandboxTelemetryService))], CloudSandboxApiService));
|
|
1103
|
-
function isSuccess(context) {
|
|
1104
|
-
const status = context.res.statusCode ?? 0;
|
|
1105
|
-
return status >= 200 && status < 300;
|
|
1106
|
-
}
|
|
1107
|
-
function toQuery(searchParams) {
|
|
1108
|
-
if (!searchParams) {
|
|
1109
|
-
return "";
|
|
1110
|
-
}
|
|
1111
|
-
const search = ( ( new URLSearchParams(searchParams)).toString());
|
|
1112
|
-
return search ? `?${search}` : "";
|
|
1113
|
-
}
|
|
1114
|
-
function retryAfterSeconds(value) {
|
|
1115
|
-
const raw = (Array.isArray(value) ? value[0] : value)?.trim();
|
|
1116
|
-
if (raw) {
|
|
1117
|
-
const seconds = Number(raw);
|
|
1118
|
-
if (Number.isSafeInteger(seconds) && seconds >= 0) {
|
|
1119
|
-
return seconds;
|
|
1120
|
-
}
|
|
1121
|
-
const date = Number.isNaN(seconds) ? Date.parse(raw) : NaN;
|
|
1122
|
-
if (Number.isFinite(date)) {
|
|
1123
|
-
return Math.max(0, (date - Date.now()) / 1000);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
return undefined;
|
|
1127
|
-
}
|
|
1128
|
-
function parseRetryAfter(value) {
|
|
1129
|
-
return retryAfterSeconds(value) ?? DEFAULT_WAKING_RETRY_AFTER_SECONDS;
|
|
1130
|
-
}
|
|
1131
|
-
function rateLimitDelay(retryAfter, attempt) {
|
|
1132
|
-
const seconds = retryAfterSeconds(retryAfter);
|
|
1133
|
-
return seconds !== undefined ? seconds * 1000 : Math.min(RATE_LIMIT_BASE_DELAY_MS * Math.pow(2, attempt), RATE_LIMIT_MAX_BACKOFF_MS);
|
|
1134
|
-
}
|
|
1135
|
-
function isCloudSandboxTask(task) {
|
|
1136
|
-
const isCloudCodingAgent = task.agent_collaborators?.some(c => c.slug === CLOUD_SANDBOX_AGENT_SLUG) ?? false;
|
|
1137
|
-
return isCloudCodingAgent && task.compute?.provider === "sandboxes";
|
|
1138
|
-
}
|
|
1139
|
-
function hasNextLink(value) {
|
|
1140
|
-
const raw = Array.isArray(value) ? value.join(",") : value;
|
|
1141
|
-
return raw ? /rel="?next"?/.test(raw) : false;
|
|
1142
|
-
}
|
|
1143
|
-
function parseNwo(nwo) {
|
|
1144
|
-
const separator = nwo?.indexOf("/") ?? -1;
|
|
1145
|
-
if (!nwo || separator <= 0 || separator === nwo.length - 1) {
|
|
1146
|
-
return undefined;
|
|
1147
|
-
}
|
|
1148
|
-
return {
|
|
1149
|
-
owner: nwo.slice(0, separator),
|
|
1150
|
-
name: nwo.slice(separator + 1)
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
function getTaskEnvironmentBinding(task) {
|
|
1154
|
-
for (const session of task.sessions ?? []) {
|
|
1155
|
-
if (session.environment_id && session.environment_id.length > 0 && session.id.length > 0) {
|
|
1156
|
-
return {
|
|
1157
|
-
environmentId: session.environment_id,
|
|
1158
|
-
sessionId: session.id
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
return undefined;
|
|
1163
|
-
}
|
|
1164
|
-
function getUnstartedSessionCreatedAt(task) {
|
|
1165
|
-
if (task.name !== "New remote session" || task.state !== "queued" || task.sessions?.length !== 1) {
|
|
1166
|
-
return undefined;
|
|
1167
|
-
}
|
|
1168
|
-
const session = task.sessions[0];
|
|
1169
|
-
if (session.state !== "queued" || session.ahp_resource_uri || !session.created_at || session.updated_at !== session.created_at) {
|
|
1170
|
-
return undefined;
|
|
1171
|
-
}
|
|
1172
|
-
const createdAt = Date.parse(session.created_at);
|
|
1173
|
-
return Number.isFinite(createdAt) ? createdAt : undefined;
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
export { CloudSandboxApiService };
|