@codingame/monaco-vscode-chat-cloud-service-override 0.0.0-stage → 38.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/common.d.ts +2 -0
  2. package/common.js +29 -0
  3. package/index.d.ts +3 -0
  4. package/index.js +9 -0
  5. package/package.json +52 -3
  6. package/session.d.ts +3 -0
  7. package/session.js +11 -0
  8. package/vscode/src/vs/sessions/contrib/chat/browser/newSession.d.ts +9 -0
  9. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/cloudAutomationStore.d.ts +67 -0
  10. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/cloudAutomationStore.js +695 -0
  11. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/cloudSandboxSessionConfig.d.ts +4 -0
  12. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/cloudSandboxSessionConfig.js +39 -0
  13. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessions.contribution.d.ts +1 -0
  14. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessions.contribution.js +59 -0
  15. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsActions.d.ts +1 -0
  16. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsActions.js +83 -0
  17. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsChangesets.d.ts +87 -0
  18. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsChangesets.js +176 -0
  19. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsProvider.d.ts +422 -0
  20. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsProvider.js +2444 -0
  21. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/githubCloudAutomationStore.d.ts +91 -0
  22. package/vscode/src/vs/sessions/contrib/providers/copilotChatSessions/browser/githubCloudAutomationStore.js +620 -0
  23. package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxAgentHost.contribution.d.ts +1 -0
  24. package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxAgentHost.contribution.js +5 -0
  25. package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxAgentHostContribution.d.ts +46 -0
  26. package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxAgentHostContribution.js +321 -0
  27. package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxSessionsProvider.d.ts +104 -0
  28. package/vscode/src/vs/sessions/contrib/providers/remoteAgentHost/browser/cloudSandboxSessionsProvider.js +345 -0
  29. package/README.md +0 -3
@@ -0,0 +1,345 @@
1
+
2
+ import { Sequencer, raceCancellationError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
3
+ import { CancellationError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
4
+ import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
5
+ import { isEqual } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
6
+ import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
7
+ import { AgentSession } from '@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/agent';
8
+ import { CLOUD_SANDBOX_AGENT_PROVIDER, CLOUD_SANDBOX_SESSION_SCHEME, CloudSandboxAutoConnectOnOpenSettingId, CloudSandboxRequestError, isRetryableCloudSandboxError } from '@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/cloudSandboxAgentHost';
9
+ import { StorageScope, StorageTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage';
10
+ import { RemoteAgentHostSessionsProvider } from '@codingame/monaco-vscode-api/vscode/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider';
11
+ import { validateSessionConfigWrite } from '@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/sessionConfigProperties';
12
+ import { RemoteAgentHostConnectionStatus } from '@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/remoteAgentHostService';
13
+ import { readSessionWorkspaceless } from '@codingame/monaco-vscode-api/vscode/vs/platform/agentHost/common/state/sessionState';
14
+ import { derived } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/observables/derived';
15
+ import { constObservable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/observables/constObservable';
16
+
17
+ class CloudSandboxSessionsProvider extends RemoteAgentHostSessionsProvider {
18
+ constructor() {
19
+ super(...arguments);
20
+ this._configurationUnavailable = derived(
21
+ this,
22
+ reader => !RemoteAgentHostConnectionStatus.isConnected(this.connectionStatus.read(reader)) || this.authenticationPending.read(reader) || this.passiveRelay.read(reader)
23
+ );
24
+ this.supportsWorkspaceSelection = false;
25
+ this._archiveSequencer = ( new Sequencer());
26
+ this._withheldSessions = ( new Set());
27
+ this._provisionalSessions = ( new Map());
28
+ this._pendingSessionTitles = ( new Map());
29
+ }
30
+ get supportsOfflineDrafts() {
31
+ return true;
32
+ }
33
+ get environment() {
34
+ return {
35
+ id: "cloud",
36
+ label: ( localize(5144, "Cloud"))
37
+ };
38
+ }
39
+ get automations() {
40
+ return undefined;
41
+ }
42
+ _adoptCachedSessionMeta(meta) {
43
+ const adopted = super._adoptCachedSessionMeta(meta);
44
+ return adopted?.session.scheme === CLOUD_SANDBOX_AGENT_PROVIDER && adopted.provider === CLOUD_SANDBOX_AGENT_PROVIDER ? {
45
+ ...adopted,
46
+ session: adopted.session.with({
47
+ scheme: CLOUD_SANDBOX_SESSION_SCHEME
48
+ })
49
+ } : adopted;
50
+ }
51
+ static {
52
+ this.PROVISIONAL_GRACE_MS = 2 * 60_000;
53
+ }
54
+ async resolveInitialSessionConfig(sessionId, values, token) {
55
+ const rawId = this._sessionKeyFromChatId(sessionId);
56
+ const connection = this.connection;
57
+ if (!connection || !rawId || !( this._sessionCache.has(rawId))) {
58
+ throw ( new Error(( localize(5145, "The sandbox connection is unavailable. Your prompt was not sent."))));
59
+ }
60
+ const config = await raceCancellationError(connection.resolveSessionConfig({
61
+ provider: CLOUD_SANDBOX_AGENT_PROVIDER,
62
+ config: values
63
+ }), token);
64
+ for (const [key, value] of Object.entries(values)) {
65
+ validateSessionConfigWrite(config.schema, config.values, key, value, true);
66
+ if (config.values[key] !== value) {
67
+ throw ( new Error(( localize(
68
+ 5146,
69
+ "The sandbox could not apply the selected {0}. Your prompt was not sent.",
70
+ key
71
+ ))));
72
+ }
73
+ }
74
+ return {
75
+ ...values
76
+ };
77
+ }
78
+ _adapterOptions() {
79
+ return {
80
+ ...super._adapterOptions(),
81
+ preserveStatusWhenDisconnected: true,
82
+ useSessionTitleForDefaultChat: true,
83
+ isSessionTitlePlaceholder: (title, session) => session.scheme === CLOUD_SANDBOX_SESSION_SCHEME && title === AgentSession.id(session),
84
+ externalSessionState: (resource, store) => {
85
+ const key = this._localSessionStorageKey(AgentSession.id(resource));
86
+ store.add(this._chatService.onDidAcceptRequest((
87
+ {
88
+ chatSessionResource
89
+ }
90
+ ) => {
91
+ if (isEqual(resource, chatSessionResource.with({
92
+ fragment: ""
93
+ }))) {
94
+ this._storageService.store(key, true, StorageScope.PROFILE, StorageTarget.MACHINE);
95
+ }
96
+ }));
97
+ return constObservable(false);
98
+ }
99
+ };
100
+ }
101
+ _localSessionStorageKey(rawId) {
102
+ return `sessions.cloudSandbox.localSession.${this.id}.${rawId}`;
103
+ }
104
+ updateAdapter(adapter, meta) {
105
+ const changed = super.updateAdapter(adapter, meta);
106
+ const sessionKey = ( meta.session.toString());
107
+ this._provisionalSessions.delete(sessionKey);
108
+ const title = this._pendingSessionTitles.get(sessionKey);
109
+ if (title !== undefined && this.connection) {
110
+ this._pendingSessionTitles.delete(sessionKey);
111
+ void super.renameSession(adapter.sessionId, title).catch(error => {
112
+ this._logService.error(
113
+ `[CloudSandboxSessionsProvider] Failed to apply initial title for ${sessionKey}`,
114
+ error
115
+ );
116
+ });
117
+ return true;
118
+ }
119
+ return changed;
120
+ }
121
+ _onBackendSessionRemoved(rawId) {
122
+ super._onBackendSessionRemoved(rawId);
123
+ this._pendingSessionTitles.delete(rawId);
124
+ }
125
+ async prepareSessionForOpen() {
126
+ if (this._baseConfigurationService.getValue(CloudSandboxAutoConnectOnOpenSettingId) === true && !this.connection && RemoteAgentHostConnectionStatus.isDisconnected(this.connectionStatus.get())) {
127
+ void this.connect().catch(error => {
128
+ this._logService.warn(
129
+ "[CloudSandboxSessionsProvider] Background connection on open failed",
130
+ error
131
+ );
132
+ });
133
+ }
134
+ }
135
+ isSessionConfigResolving(sessionId) {
136
+ const resolving = super.isSessionConfigResolving(sessionId);
137
+ return derived(
138
+ this,
139
+ reader => this._configurationUnavailable.read(reader) || resolving.read(reader)
140
+ );
141
+ }
142
+ async setSessionConfigValue(sessionId, property, value) {
143
+ this._assertConfigurationAvailable();
144
+ await super.setSessionConfigValue(sessionId, property, value);
145
+ }
146
+ async replaceSessionConfig(sessionId, values) {
147
+ this._assertConfigurationAvailable();
148
+ await super.replaceSessionConfig(sessionId, values);
149
+ }
150
+ _assertConfigurationAvailable() {
151
+ if (this.passiveRelay.get()) {
152
+ throw ( new Error(( localize(5147, "This connection is read-only. Session settings cannot be changed."))));
153
+ }
154
+ if (this._configurationUnavailable.get()) {
155
+ throw ( new Error(( localize(5148, "Connect to the environment before changing session settings."))));
156
+ }
157
+ }
158
+ _resolveArchivedState(sessionKey, isArchived) {
159
+ return this._taskArchiveHandler?.sessionKey === sessionKey ? this._sessionCache.get(sessionKey)?.isArchived.get() ?? isArchived : super._resolveArchivedState(sessionKey, isArchived);
160
+ }
161
+ setTaskArchiveHandler(rawId, setArchived) {
162
+ this._taskArchiveHandler = {
163
+ sessionKey: ( AgentSession.uri(CLOUD_SANDBOX_SESSION_SCHEME, rawId).toString()),
164
+ setArchived
165
+ };
166
+ }
167
+ setTaskRenameHandler(rawId, rename) {
168
+ this._taskRenameHandler = {
169
+ sessionKey: ( AgentSession.uri(CLOUD_SANDBOX_SESSION_SCHEME, rawId).toString()),
170
+ rename
171
+ };
172
+ }
173
+ setInitialSessionTitle(sessionId, title) {
174
+ return this._renameSession(sessionId, title, true);
175
+ }
176
+ renameSession(sessionId, title) {
177
+ return this._renameSession(sessionId, title, false);
178
+ }
179
+ async _renameSession(sessionId, title, initial) {
180
+ const sessionKey = this._sessionKeyFromChatId(sessionId);
181
+ const session = sessionKey ? this._sessionCache.get(sessionKey) : undefined;
182
+ if (!session || !sessionKey) {
183
+ throw ( new Error(( localize(5149, "Sandbox session not found."))));
184
+ }
185
+ const handler = this._taskRenameHandler;
186
+ if (handler?.sessionKey !== sessionKey) {
187
+ if (!this.connection && !( this._provisionalSessions.has(sessionKey))) {
188
+ throw ( new Error(( localize(5150, "Connect to the environment to rename this session."))));
189
+ }
190
+ } else {
191
+ try {
192
+ await handler.rename(title);
193
+ } catch (error) {
194
+ if (!initial || !(error instanceof CloudSandboxRequestError) || !isRetryableCloudSandboxError(error)) {
195
+ throw error;
196
+ }
197
+ this._logService.warn(
198
+ `[CloudSandboxSessionsProvider] Failed to synchronize initial task title for ${sessionKey}; continuing with the first turn`,
199
+ error
200
+ );
201
+ }
202
+ if (this._store.isDisposed || this._sessionCache.get(sessionKey) !== session) {
203
+ throw ( new CancellationError());
204
+ }
205
+ }
206
+ if (( this._provisionalSessions.has(sessionKey))) {
207
+ this._pendingSessionTitles.set(sessionKey, title);
208
+ } else if (this.connection) {
209
+ return super.renameSession(sessionId, title);
210
+ }
211
+ session.setTitleFromUser(title);
212
+ this._onDidChangeSessions.fire({
213
+ added: [],
214
+ removed: [],
215
+ changed: [session]
216
+ });
217
+ }
218
+ async archiveSession(sessionId) {
219
+ await this._archiveSequencer.queue(() => this._setArchived(sessionId, true));
220
+ }
221
+ async unarchiveSession(sessionId) {
222
+ await this._archiveSequencer.queue(() => this._setArchived(sessionId, false));
223
+ }
224
+ async _setArchived(sessionId, isArchived) {
225
+ if (this._store.isDisposed) {
226
+ throw ( new CancellationError());
227
+ }
228
+ const sessionKey = this._sessionKeyFromChatId(sessionId);
229
+ const session = sessionKey ? this._sessionCache.get(sessionKey) : undefined;
230
+ if (!session || !sessionKey) {
231
+ throw ( new Error(( localize(5149, "Sandbox session not found."))));
232
+ }
233
+ const handler = this._taskArchiveHandler;
234
+ if (handler?.sessionKey !== sessionKey) {
235
+ if (!this.connection) {
236
+ throw ( new Error(( localize(5151, "Connect to the environment to change this session's archive state."))));
237
+ }
238
+ return isArchived ? super.archiveSession(sessionId) : super.unarchiveSession(sessionId);
239
+ }
240
+ await handler.setArchived(isArchived);
241
+ if (this._store.isDisposed || this._sessionCache.get(sessionKey) !== session) {
242
+ throw ( new CancellationError());
243
+ }
244
+ this.setSessionArchived(AgentSession.id(session.backendUri), isArchived);
245
+ }
246
+ setSessionArchived(rawId, archived) {
247
+ const session = this._sessionCache.get(( AgentSession.uri(CLOUD_SANDBOX_SESSION_SCHEME, rawId).toString()));
248
+ if (!session) {
249
+ throw ( new Error(( localize(5149, "Sandbox session not found."))));
250
+ }
251
+ if (session.isArchived.get() === archived) {
252
+ return;
253
+ }
254
+ session.isArchived.set(archived, undefined);
255
+ this._onDidChangeSessions.fire({
256
+ added: [],
257
+ removed: [],
258
+ changed: [session]
259
+ });
260
+ }
261
+ seedProvisionalSession(rawMeta) {
262
+ const meta = this._adoptSessionMeta(rawMeta);
263
+ const rawId = AgentSession.id(meta.session);
264
+ this._storageService.store(
265
+ this._localSessionStorageKey(rawId),
266
+ true,
267
+ StorageScope.PROFILE,
268
+ StorageTarget.MACHINE
269
+ );
270
+ if (( this._sessionCache.has(( meta.session.toString())))) {
271
+ return;
272
+ }
273
+ const adapter = this.createAdapter(meta);
274
+ adapter.updateDiscoveryMetadata(meta, readSessionWorkspaceless(meta._meta) || undefined);
275
+ this._sessionCache.set(( meta.session.toString()), adapter);
276
+ this._withheldSessions.add(( meta.session.toString()));
277
+ this._provisionalSessions.set(( meta.session.toString()), undefined);
278
+ }
279
+ publishWithheldSession(rawId, options) {
280
+ if (!this._withheldSessions.delete(( AgentSession.uri(CLOUD_SANDBOX_SESSION_SCHEME, rawId).toString()))) {
281
+ return;
282
+ }
283
+ const session = this.getCachedSession(rawId);
284
+ if (session && options?.announce !== false) {
285
+ this._onDidChangeSessions.fire({
286
+ added: [session],
287
+ removed: [],
288
+ changed: []
289
+ });
290
+ }
291
+ }
292
+ getCachedSession(rawId) {
293
+ return this._sessionCache.get(( AgentSession.uri(CLOUD_SANDBOX_SESSION_SCHEME, rawId).toString()));
294
+ }
295
+ getSessionModifiedTime(rawId) {
296
+ return this.getCachedSession(rawId)?.updatedAt.get().getTime();
297
+ }
298
+ removeDeletedSession(rawId) {
299
+ const cached = this.getCachedSession(rawId);
300
+ const key = cached ? this._sessionKeyFromChatId(cached.sessionId) : undefined;
301
+ const session = key ? this._removeCachedSession(key) : undefined;
302
+ const taskKey = ( AgentSession.uri(CLOUD_SANDBOX_SESSION_SCHEME, rawId).toString());
303
+ this._withheldSessions.delete(taskKey);
304
+ this._provisionalSessions.delete(taskKey);
305
+ this._pendingSessionTitles.delete(taskKey);
306
+ if (session) {
307
+ this._onDidChangeSessions.fire({
308
+ added: [],
309
+ removed: [session],
310
+ changed: []
311
+ });
312
+ session.dispose();
313
+ }
314
+ }
315
+ getSessions() {
316
+ const sessions = super.getSessions();
317
+ return this._withheldSessions.size === 0 ? sessions : sessions.filter(session => !( this._withheldSessions.has(this._sessionKeyFromChatId(session.sessionId) ?? "")));
318
+ }
319
+ _isSessionEvictable(rawId) {
320
+ if (!( this._provisionalSessions.has(rawId))) {
321
+ return true;
322
+ }
323
+ const deadline = this._provisionalSessions.get(rawId);
324
+ if (deadline === undefined || Date.now() < deadline) {
325
+ return false;
326
+ }
327
+ this._provisionalSessions.delete(rawId);
328
+ this._pendingSessionTitles.delete(rawId);
329
+ return true;
330
+ }
331
+ _onHostListedSessions(rawIds) {
332
+ if (this._provisionalSessions.size === 0) {
333
+ return;
334
+ }
335
+ for (const [rawId, deadline] of [...this._provisionalSessions]) {
336
+ if (( rawIds.has(rawId))) {
337
+ this._provisionalSessions.delete(rawId);
338
+ } else if (deadline === undefined) {
339
+ this._provisionalSessions.set(rawId, Date.now() + CloudSandboxSessionsProvider.PROVISIONAL_GRACE_MS);
340
+ }
341
+ }
342
+ }
343
+ }
344
+
345
+ export { CloudSandboxSessionsProvider };
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.