forked from dirac-run/dirac
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencode_refactor_sendRequest
More file actions
575 lines (513 loc) · 34 KB
/
opencode_refactor_sendRequest
File metadata and controls
575 lines (513 loc) · 34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
diff --git a/src/vs/sessions/contrib/copilotChatSessions/browser/copilotChatSessionsProvider.ts b/src/vs/sessions/contrib/copilotChatSessions/browser/copilotChatSessionsProvider.ts
index 9990b803d50..e0ad9d0b785 100644
--- a/src/vs/sessions/contrib/copilotChatSessions/browser/copilotChatSessionsProvider.ts
+++ b/src/vs/sessions/contrib/copilotChatSessions/browser/copilotChatSessionsProvider.ts
@@ -1193,7 +1193,7 @@ export class CopilotChatSessionsProvider extends Disposable implements ISessions
}
// Send request
- const result = await this.chatService.sendRequest(session.resource, query, sendOptions);
+ const result = await this.chatService.sendRequest({ sessionResource: session.resource, message: query, options: sendOptions });
if (result.kind === 'rejected') {
throw new Error(`[DefaultCopilotProvider] sendRequest rejected: ${result.reason}`);
}
diff --git a/src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts b/src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts
index 226abe28731..f172ae46a0a 100644
--- a/src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts
+++ b/src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts
@@ -463,7 +463,7 @@ export class RemoteAgentHostSessionsProvider extends Disposable implements ISess
// Send request through the chat service, which delegates to the
// AgentHostSessionHandler content provider for turn handling
- const result = await this._chatService.sendRequest(session.resource, query, sendOptions);
+ const result = await this._chatService.sendRequest({ sessionResource: session.resource, message: query, options: sendOptions });
if (result.kind === 'rejected') {
throw new Error(`[RemoteAgentHost] sendRequest rejected: ${result.reason}`);
}
diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.ts b/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.ts
index 1f5732b9cd6..621526add7d 100644
--- a/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.ts
+++ b/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.ts
@@ -504,11 +504,15 @@ export class CreateRemoteAgentJobAction {
);
await chatService.removeRequest(sessionResource, addedRequest.id);
- const sendResult = await chatService.sendRequest(sessionResource, userPrompt, {
- agentIdSilent: continuationTargetType,
- attachedContext: attachedContext.asArray(),
- userSelectedModelId: widget.input.currentLanguageModel,
- ...widget.getModeRequestOptions()
+ const sendResult = await chatService.sendRequest({
+ sessionResource,
+ message: userPrompt,
+ options: {
+ agentIdSilent: continuationTargetType,
+ attachedContext: attachedContext.asArray(),
+ userSelectedModelId: widget.input.currentLanguageModel,
+ ...widget.getModeRequestOptions()
+ }
});
if (ChatSendResult.isSent(sendResult)) {
diff --git a/src/vs/workbench/contrib/chat/browser/aiCustomization/customizationCreatorService.ts b/src/vs/workbench/contrib/chat/browser/aiCustomization/customizationCreatorService.ts
index cec5c423ff0..46638749807 100644
--- a/src/vs/workbench/contrib/chat/browser/aiCustomization/customizationCreatorService.ts
+++ b/src/vs/workbench/contrib/chat/browser/aiCustomization/customizationCreatorService.ts
@@ -78,18 +78,22 @@ export class CustomizationCreatorService {
return;
}
- await this.chatService.sendRequest(sessionResource, userMessage, {
- modeInfo: {
- kind: ChatModeKind.Agent,
- isBuiltin: false,
- modeId: 'custom',
- applyCodeBlockSuggestionId: undefined,
- modeInstructions: {
- name: 'customization-creator',
- content: systemInstructions,
- toolReferences: [],
+ await this.chatService.sendRequest({
+ sessionResource,
+ message: userMessage,
+ options: {
+ modeInfo: {
+ kind: ChatModeKind.Agent,
+ isBuiltin: false,
+ modeId: 'custom',
+ applyCodeBlockSuggestionId: undefined,
+ modeInstructions: {
+ name: 'customization-creator',
+ content: systemInstructions,
+ toolReferences: [],
+ },
},
- },
+ }
});
}
diff --git a/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts b/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts
index edb32b33b3d..78281beae50 100644
--- a/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts
+++ b/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts
@@ -563,7 +563,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
attachedContext = [promptFile, ...(attachedContext ?? [])];
}
- const result = await chatService.sendRequest(resource, chatOptions.prompt, { agentIdSilent: type, attachedContext });
+ const result = await chatService.sendRequest({ sessionResource: resource, message: chatOptions.prompt, options: { agentIdSilent: type, attachedContext } });
if (result.kind === 'queued') {
await result.deferred;
} else if (result.kind === 'sent') {
@@ -1375,7 +1375,7 @@ async function openChatSession(accessor: ServicesAccessor, openOptions: NewChatS
if (promptFile) {
attachedContext = [promptFile, ...(attachedContext ?? [])];
}
- await chatService.sendRequest(resource, chatSendOptions.prompt, { agentIdSilent: openOptions.type, attachedContext });
+ await chatService.sendRequest({ sessionResource: resource, message: chatSendOptions.prompt, options: { agentIdSilent: openOptions.type, attachedContext } });
} catch (e) {
logService.error(`Failed to send initial request to '${openOptions.type}' chat session with contextOptions: ${JSON.stringify(chatSendOptions)}`, e);
}
diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatConfirmationContentPart.ts b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatConfirmationContentPart.ts
index e7e7ba79921..f8de8b4d7b1 100644
--- a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatConfirmationContentPart.ts
+++ b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatConfirmationContentPart.ts
@@ -54,7 +54,7 @@ export class ChatConfirmationContentPart extends Disposable implements IChatCont
options.location = widget?.location;
Object.assign(options, widget?.getModeRequestOptions());
- const result = await this.chatService.sendRequest(element.sessionResource, prompt, options);
+ const result = await this.chatService.sendRequest({ sessionResource: element.sessionResource, message: prompt, options });
if (ChatSendResult.isSent(result)) {
confirmation.isUsed = true;
confirmationWidget.setShowButtons(false);
diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatErrorConfirmationPart.ts b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatErrorConfirmationPart.ts
index fe4903eff3b..4b21c91f1e1 100644
--- a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatErrorConfirmationPart.ts
+++ b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatErrorConfirmationPart.ts
@@ -60,7 +60,7 @@ export class ChatErrorConfirmationContentPart extends Disposable implements ICha
options.userSelectedModelId = widget?.input.currentLanguageModel;
Object.assign(options, widget?.getModeRequestOptions());
this.chatAccessibilityService.acceptRequest(element.sessionResource);
- await chatService.sendRequest(element.sessionResource, prompt, options);
+ await chatService.sendRequest({ sessionResource: element.sessionResource, message: prompt, options });
}));
});
}
diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownDecorationsRenderer.ts b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownDecorationsRenderer.ts
index 560e9ecf849..9b72f673d56 100644
--- a/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownDecorationsRenderer.ts
+++ b/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownDecorationsRenderer.ts
@@ -186,13 +186,16 @@ export class ChatMarkdownDecorationsRenderer {
return;
}
- this.chatService.sendRequest(widget.viewModel!.sessionResource, agent.metadata.sampleRequest ?? '',
- {
+ this.chatService.sendRequest({
+ sessionResource: widget.viewModel!.sessionResource,
+ message: agent.metadata.sampleRequest ?? '',
+ options: {
location: widget.location,
agentId: agent.id,
userSelectedModelId: widget.input.currentLanguageModel,
modeInfo: widget.input.currentModeInfo
- });
+ }
+ });
}));
} else {
container = this.renderResourceWidget(nameWithLeader, undefined, store);
@@ -223,12 +226,16 @@ export class ChatMarkdownDecorationsRenderer {
}
const command = agent.slashCommands.find(c => c.name === args.command);
- this.chatService.sendRequest(widget.viewModel!.sessionResource, command?.sampleRequest ?? '', {
- location: widget.location,
- agentId: agent.id,
- slashCommand: args.command,
- userSelectedModelId: widget.input.currentLanguageModel,
- modeInfo: widget.input.currentModeInfo
+ this.chatService.sendRequest({
+ sessionResource: widget.viewModel!.sessionResource,
+ message: command?.sampleRequest ?? '',
+ options: {
+ location: widget.location,
+ agentId: agent.id,
+ slashCommand: args.command,
+ userSelectedModelId: widget.input.currentLanguageModel,
+ modeInfo: widget.input.currentModeInfo
+ }
});
}));
diff --git a/src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts b/src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts
index 7689707940f..73c3dfe298a 100644
--- a/src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts
+++ b/src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts
@@ -2413,19 +2413,22 @@ export class ChatWidget extends Disposable implements IChatWidget {
const resolvedImageVariables = await this._resolveDirectoryImageAttachments(requestInputs.attachedContext.asArray());
const submittedSessionResource = this.viewModel.sessionResource;
- const result = await this.chatService.sendRequest(this.viewModel.sessionResource, requestInputs.input, {
- userSelectedModelId: this.input.currentLanguageModel,
- location: this.location,
- locationData: this._location.resolveData?.(),
- parserContext: { selectedAgent: this._lastSelectedAgent, mode: this.input.currentModeKind, attachmentCapabilities: this._lastSelectedAgent?.capabilities ?? this.attachmentCapabilities },
- attachedContext: requestInputs.attachedContext.asArray(),
- resolvedVariables: resolvedImageVariables,
- noCommandDetection: options?.noCommandDetection,
- ...this.getModeRequestOptions(),
- modeInfo: this.input.currentModeInfo,
- agentIdSilent: this._lockedAgent?.id,
- queue: options?.queue,
-
+ const result = await this.chatService.sendRequest({
+ sessionResource: this.viewModel.sessionResource,
+ message: requestInputs.input,
+ options: {
+ userSelectedModelId: this.input.currentLanguageModel,
+ location: this.location,
+ locationData: this._location.resolveData?.(),
+ parserContext: { selectedAgent: this._lastSelectedAgent, mode: this.input.currentModeKind, attachmentCapabilities: this._lastSelectedAgent?.capabilities ?? this.attachmentCapabilities },
+ attachedContext: requestInputs.attachedContext.asArray(),
+ resolvedVariables: resolvedImageVariables,
+ noCommandDetection: options?.noCommandDetection,
+ ...this.getModeRequestOptions(),
+ modeInfo: this.input.currentModeInfo,
+ agentIdSilent: this._lockedAgent?.id,
+ queue: options?.queue,
+ }
});
if (ChatSendResult.isRejected(result)) {
diff --git a/src/vs/workbench/contrib/chat/common/chatService/chatService.ts b/src/vs/workbench/contrib/chat/common/chatService/chatService.ts
index 2fd59394973..a1a7523939f 100644
--- a/src/vs/workbench/contrib/chat/common/chatService/chatService.ts
+++ b/src/vs/workbench/contrib/chat/common/chatService/chatService.ts
@@ -1402,6 +1402,12 @@ export type IChatModelReference = IReference<IChatModel>;
export const IChatService = createDecorator<IChatService>('IChatService');
+export interface IChatSendRequestParams {
+ readonly sessionResource: URI;
+ readonly message: string;
+ readonly options?: IChatSendRequestOptions;
+}
+
export interface IChatService {
_serviceBrand: undefined;
transferredSessionResource: URI | undefined;
@@ -1461,7 +1467,7 @@ export interface IChatService {
* Sends a chat request for the given session.
* @returns A result indicating whether the request was sent, queued, or rejected.
*/
- sendRequest(sessionResource: URI, message: string, options?: IChatSendRequestOptions): Promise<ChatSendResult>;
+ sendRequest(params: IChatSendRequestParams): Promise<ChatSendResult>;
getSessionTitle(sessionResource: URI): string | undefined;
setSessionTitle(sessionResource: URI, title: string): void;
diff --git a/src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts b/src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts
index 387af583779..9380e750484 100644
--- a/src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts
+++ b/src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts
@@ -41,7 +41,7 @@ import { ChatModel, ChatRequestModel, ChatRequestRemovalReason, IChatModel, ICha
import { ChatModelStore, IStartSessionProps } from '../model/chatModelStore.js';
import { chatAgentLeader, ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart, ChatRequestTextPart, chatSubcommandLeader, getPromptText, IParsedChatRequest } from '../requestParser/chatParserTypes.js';
import { ChatRequestParser } from '../requestParser/chatRequestParser.js';
-import { ChatMcpServersStarting, ChatPendingRequestChangeClassification, ChatPendingRequestChangeEvent, ChatPendingRequestChangeEventName, ChatRequestQueueKind, ChatSendResult, ChatSendResultQueued, ChatSendResultSent, ChatStopCancellationNoopClassification, ChatStopCancellationNoopEvent, ChatStopCancellationNoopEventName, IChatCompleteResponse, IChatDetail, IChatFollowup, IChatModelReference, IChatProgress, IChatQuestionAnswers, IChatSendRequestOptions, IChatSendRequestResponseState, IChatService, IChatSessionContext, IChatSessionStartOptions, IChatUserActionEvent, ResponseModelState } from './chatService.js';
+import { ChatMcpServersStarting, ChatPendingRequestChangeClassification, ChatPendingRequestChangeEvent, ChatPendingRequestChangeEventName, ChatRequestQueueKind, ChatSendResult, ChatSendResultQueued, ChatSendResultSent, ChatStopCancellationNoopClassification, ChatStopCancellationNoopEvent, ChatStopCancellationNoopEventName, IChatCompleteResponse, IChatDetail, IChatFollowup, IChatModelReference, IChatProgress, IChatQuestionAnswers, IChatSendRequestOptions, IChatSendRequestParams, IChatSendRequestResponseState, IChatService, IChatSessionContext, IChatSessionStartOptions, IChatUserActionEvent, ResponseModelState } from './chatService.js';
import { ChatRequestTelemetry, ChatServiceTelemetry } from './chatServiceTelemetry.js';
import { IChatSessionsService, localChatSessionType } from '../chatSessionsService.js';
import { ChatSessionStore, IChatSessionEntryMetadata } from '../model/chatSessionStore.js';
@@ -885,7 +885,8 @@ export class ChatService extends Disposable implements IChatService {
return { kind: 'queued', deferred: deferred.p };
}
- async sendRequest(sessionResource: URI, request: string, options?: IChatSendRequestOptions): Promise<ChatSendResult> {
+ async sendRequest(params: IChatSendRequestParams): Promise<ChatSendResult> {
+ let { sessionResource, message: request, options } = params;
this.trace('sendRequest', `sessionResource: ${sessionResource.toString()}, message: ${request.substring(0, 20)}${request.length > 20 ? '[...]' : ''}}`);
@@ -1743,9 +1744,13 @@ export class ChatService extends Disposable implements IChatService {
// Re-send remaining queued requests
for (const pending of pendingRequests) {
- void this.sendRequest(targetResource, pending.request.message.text, {
- ...pending.sendOptions,
- queue: pending.kind,
+ void this.sendRequest({
+ sessionResource: targetResource,
+ message: pending.request.message.text,
+ options: {
+ ...pending.sendOptions,
+ queue: pending.kind,
+ }
});
}
}
diff --git a/src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts b/src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts
index afa76442175..b8ab1967e7a 100644
--- a/src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts
+++ b/src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts
@@ -285,7 +285,7 @@ suite('ChatService', () => {
const modelRef = testDisposables.add(startSessionModel(testService));
const model = modelRef.object;
- const response = await testService.sendRequest(model.sessionResource, `@${chatAgentWithUsedContextId} test request`);
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: `@${chatAgentWithUsedContextId} test request` });
ChatSendResult.assertSent(response);
await response.data.responseCompletePromise;
@@ -311,21 +311,21 @@ suite('ChatService', () => {
const model = modelRef.object;
// Send a request to default agent
- const response = await testService.sendRequest(model.sessionResource, `test request`, { agentId: 'defaultAgent' });
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: `test request`, options: { agentId: 'defaultAgent' } });
ChatSendResult.assertSent(response);
await response.data.responseCompletePromise;
assert.strictEqual(model.getRequests().length, 1);
assert.strictEqual(model.getRequests()[0].response?.result?.metadata?.historyLength, 0);
// Send a request to agent2- it can't see the default agent's message
- const response2 = await testService.sendRequest(model.sessionResource, `test request`, { agentId: 'agent2' });
+ const response2 = await testService.sendRequest({ sessionResource: model.sessionResource, message: `test request`, options: { agentId: 'agent2' } });
ChatSendResult.assertSent(response2);
await response2.data.responseCompletePromise;
assert.strictEqual(model.getRequests().length, 2);
assert.strictEqual(model.getRequests()[1].response?.result?.metadata?.historyLength, 0);
// Send a request to defaultAgent - the default agent can see agent2's message
- const response3 = await testService.sendRequest(model.sessionResource, `test request`, { agentId: 'defaultAgent' });
+ const response3 = await testService.sendRequest({ sessionResource: model.sessionResource, message: `test request`, options: { agentId: 'defaultAgent' } });
ChatSendResult.assertSent(response3);
await response3.data.responseCompletePromise;
assert.strictEqual(model.getRequests().length, 3);
@@ -343,12 +343,12 @@ suite('ChatService', () => {
await assertSnapshot(toSnapshotExportData(model));
- const response = await testService.sendRequest(model.sessionResource, `@${chatAgentWithUsedContextId} test request`);
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: `@${chatAgentWithUsedContextId} test request` });
ChatSendResult.assertSent(response);
await response.data.responseCompletePromise;
assert.strictEqual(model.getRequests().length, 1);
- const response2 = await testService.sendRequest(model.sessionResource, `test request 2`);
+ const response2 = await testService.sendRequest({ sessionResource: model.sessionResource, message: `test request 2` });
ChatSendResult.assertSent(response2);
await response2.data.responseCompletePromise;
assert.strictEqual(model.getRequests().length, 2);
@@ -368,7 +368,7 @@ suite('ChatService', () => {
const chatModel1 = chatModel1Ref.object;
assert.strictEqual(chatModel1.getRequests().length, 0);
- const response = await testService.sendRequest(chatModel1.sessionResource, `@${chatAgentWithUsedContextId} test request`);
+ const response = await testService.sendRequest({ sessionResource: chatModel1.sessionResource, message: `@${chatAgentWithUsedContextId} test request` });
ChatSendResult.assertSent(response);
await response.data.responseCompletePromise;
@@ -399,7 +399,38 @@ suite('ChatService', () => {
const chatModel1 = chatModel1Ref.object;
assert.strictEqual(chatModel1.getRequests().length, 0);
- const response = await testService.sendRequest(chatModel1.sessionResource, `@${chatAgentWithUsedContextId} test request`);
+ const response = await testService.sendRequest({ sessionResource: chatModel1.sessionResource, message: `@${chatAgentWithUsedContextId} test request` });
+ ChatSendResult.assertSent(response);
+
+ await response.data.responseCompletePromise;
+
+ serializedChatData = JSON.parse(JSON.stringify(chatModel1));
+ }
+
+ // try deserializing the state into a new service
+
+ const testService2 = createChatService();
+
+ const chatModel2Ref = testService2.loadSessionFromData(serializedChatData);
+ assert(chatModel2Ref);
+ testDisposables.add(chatModel2Ref);
+ const chatModel2 = chatModel2Ref.object;
+
+ await assertSnapshot(toSnapshotExportData(chatModel2));
+ });
+
+ test('can deserialize with response', async () => {
+ let serializedChatData: ISerializableChatData;
+ testDisposables.add(chatAgentService.registerAgentImplementation(chatAgentWithMarkdownId, chatAgentWithMarkdown));
+
+ {
+ const testService = createChatService();
+
+ const chatModel1Ref = testDisposables.add(startSessionModel(testService));
+ const chatModel1 = chatModel1Ref.object;
+ assert.strictEqual(chatModel1.getRequests().length, 0);
+
+ const response = await testService.sendRequest({ sessionResource: chatModel1.sessionResource, message: `@${chatAgentWithUsedContextId} test request` });
ChatSendResult.assertSent(response);
await response.data.responseCompletePromise;
@@ -462,16 +493,20 @@ suite('ChatService', () => {
const model = modelRef.object;
// Start a request that will wait
- const response = await testService.sendRequest(model.sessionResource, 'first request', { agentId: 'slowAgent' });
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'first request', options: { agentId: 'slowAgent' } });
ChatSendResult.assertSent(response);
// Wait for the agent to start processing
await requestStarted.p;
// Queue a steering message while the first request is still in progress
- const steeringResponse = await testService.sendRequest(model.sessionResource, 'steering message', {
- agentId: 'slowAgent',
- queue: ChatRequestQueueKind.Steering
+ const steeringResponse = await testService.sendRequest({
+ sessionResource: model.sessionResource,
+ message: 'steering message',
+ options: {
+ agentId: 'slowAgent',
+ queue: ChatRequestQueueKind.Steering
+ }
});
assert.strictEqual(steeringResponse.kind, 'queued');
@@ -507,16 +542,16 @@ suite('ChatService', () => {
const model = modelRef.object;
// Start a request that will wait
- const response = await testService.sendRequest(model.sessionResource, 'first request', { agentId: 'slowAgent' });
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'first request', options: { agentId: 'slowAgent' } });
ChatSendResult.assertSent(response);
// Wait for the agent to start processing
await requestStarted.p;
// Queue 3 steering messages while the first request is in progress
- const steering1 = await testService.sendRequest(model.sessionResource, 'steering1', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Steering });
- const steering2 = await testService.sendRequest(model.sessionResource, 'steering2', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Steering });
- const steering3 = await testService.sendRequest(model.sessionResource, 'steering3', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Steering });
+ const steering1 = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'steering1', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Steering } });
+ const steering2 = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'steering2', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Steering } });
+ const steering3 = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'steering3', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Steering } });
assert.ok(ChatSendResult.isQueued(steering1));
assert.ok(ChatSendResult.isQueued(steering2));
assert.ok(ChatSendResult.isQueued(steering3));
@@ -559,7 +594,7 @@ suite('ChatService', () => {
const model = modelRef.object;
// Disabled hooks are reported for every request, but the hint should only be shown once per workspace.
- const response = await testService.sendRequest(model.sessionResource, 'test request');
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'test request' });
ChatSendResult.assertSent(response);
await response.data.responseCompletePromise;
@@ -574,7 +609,7 @@ suite('ChatService', () => {
assert.ok(hasHookHint, 'Response should contain the disabledClaudeHooks hint');
// Sending another request should NOT show the hint again (shown only once per workspace)
- const response2 = await testService.sendRequest(model.sessionResource, 'second request');
+ const response2 = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'second request' });
ChatSendResult.assertSent(response2);
await response2.data.responseCompletePromise;
@@ -607,7 +642,7 @@ suite('ChatService', () => {
const modelRef = testDisposables.add(startSessionModel(testService));
const model = modelRef.object;
- const response = await testService.sendRequest(model.sessionResource, 'first request');
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'first request' });
ChatSendResult.assertSent(response);
await response.data.responseCompletePromise;
@@ -653,7 +688,7 @@ suite('ChatService', () => {
const modelRef = testDisposables.add(startSessionModel(testService));
const model = modelRef.object;
- const response = await testService.sendRequest(model.sessionResource, 'test request', { agentId: 'slowAgent' });
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'test request', options: { agentId: 'slowAgent' } });
ChatSendResult.assertSent(response);
await requestStarted.p;
@@ -687,7 +722,7 @@ suite('ChatService', () => {
const modelRef = testDisposables.add(startSessionModel(testService));
const model = modelRef.object;
- const response = await testService.sendRequest(model.sessionResource, 'test request', { agentId: 'hangingAgent' });
+ const response = await testService.sendRequest({ sessionResource: model.sessionResource, message: 'test request', options: { agentId: 'hangingAgent' } });
ChatSendResult.assertSent(response);
await requestStarted.p;
@@ -727,12 +762,12 @@ suite('ChatService', () => {
const source = sourceRef.object;
// Start a blocking request on source
- const response = await testService.sendRequest(source.sessionResource, 'first request', { agentId: 'slowAgent' });
+ const response = await testService.sendRequest({ sessionResource: source.sessionResource, message: 'first request', options: { agentId: 'slowAgent' } });
ChatSendResult.assertSent(response);
await requestStarted.p;
// Queue a request while the first is in progress
- const queued = await testService.sendRequest(source.sessionResource, 'queued request', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued });
+ const queued = await testService.sendRequest({ sessionResource: source.sessionResource, message: 'queued request', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued } });
assert.ok(ChatSendResult.isQueued(queued));
// Remove the queued request from source
@@ -743,7 +778,7 @@ suite('ChatService', () => {
// Re-send it on a new target session through the normal queue path
const targetRef = testDisposables.add(startSessionModel(testService));
const target = targetRef.object;
- const resent = await testService.sendRequest(target.sessionResource, 'queued request', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued, pauseQueue: true });
+ const resent = await testService.sendRequest({ sessionResource: target.sessionResource, message: 'queued request', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued, pauseQueue: true } });
assert.ok(ChatSendResult.isQueued(resent));
assert.strictEqual(target.getPendingRequests().length, 1);
@@ -794,14 +829,14 @@ suite('ChatService', () => {
const source = sourceRef.object;
// Step 1: Send request 1 (blocks on firstRequestGate)
- const response1 = await testService.sendRequest(source.sessionResource, 'request-1', { agentId: 'slowAgent' });
+ const response1 = await testService.sendRequest({ sessionResource: source.sessionResource, message: 'request-1', options: { agentId: 'slowAgent' } });
ChatSendResult.assertSent(response1);
await firstRequestStarted.p;
// Step 2: Queue 3 more requests while request 1 is in progress
- const q1 = await testService.sendRequest(source.sessionResource, 'queued-1', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued });
- const q2 = await testService.sendRequest(source.sessionResource, 'queued-2', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued });
- const q3 = await testService.sendRequest(source.sessionResource, 'queued-3', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued });
+ const q1 = await testService.sendRequest({ sessionResource: source.sessionResource, message: 'queued-1', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued } });
+ const q2 = await testService.sendRequest({ sessionResource: source.sessionResource, message: 'queued-2', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued } });
+ const q3 = await testService.sendRequest({ sessionResource: source.sessionResource, message: 'queued-3', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued } });
assert.ok(ChatSendResult.isQueued(q1));
assert.ok(ChatSendResult.isQueued(q2));
assert.ok(ChatSendResult.isQueued(q3));
@@ -835,9 +870,9 @@ suite('ChatService', () => {
assert.strictEqual(source.getPendingRequests().length, 0);
// Re-send ALL 3 on the target through the normal queue path
- const resent1 = await testService.sendRequest(target.sessionResource, 'queued-1', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued, pauseQueue: true });
- const resent2 = await testService.sendRequest(target.sessionResource, 'queued-2', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued, pauseQueue: true });
- const resent3 = await testService.sendRequest(target.sessionResource, 'queued-3', { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued, pauseQueue: true });
+ const resent1 = await testService.sendRequest({ sessionResource: target.sessionResource, message: 'queued-1', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued, pauseQueue: true } });
+ const resent2 = await testService.sendRequest({ sessionResource: target.sessionResource, message: 'queued-2', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued, pauseQueue: true } });
+ const resent3 = await testService.sendRequest({ sessionResource: target.sessionResource, message: 'queued-3', options: { agentId: 'slowAgent', queue: ChatRequestQueueKind.Queued, pauseQueue: true } });
assert.ok(ChatSendResult.isQueued(resent1));
assert.ok(ChatSendResult.isQueued(resent2));
assert.ok(ChatSendResult.isQueued(resent3));
@@ -928,7 +963,7 @@ suite('ChatService', () => {
testDisposables.add(untitledRef);
// Send a request - this triggers the untitled → real session conversion
- const response = await testService.sendRequest(untitledResource, 'hello', { agentId: remoteScheme });
+ const response = await testService.sendRequest({ sessionResource: untitledResource, message: 'hello', options: { agentId: remoteScheme } });
ChatSendResult.assertSent(response);
await response.data.responseCompletePromise;
@@ -973,3 +1008,4 @@ function toSnapshotExportData(model: IChatModel) {
})
};
}
+
diff --git a/src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts b/src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts
index 07e106b2c43..2447ef913e8 100644
--- a/src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts
+++ b/src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts
@@ -8,7 +8,7 @@ import { Emitter, Event } from '../../../../../../base/common/event.js';
import { ResourceMap } from '../../../../../../base/common/map.js';
import { ISettableObservable, observableValue } from '../../../../../../base/common/observable.js';
import { URI } from '../../../../../../base/common/uri.js';
-import { ChatRequestQueueKind, ChatSendResult, IChatDetail, IChatModelReference, IChatProgress, IChatSendRequestOptions, IChatService, IChatSessionContext, IChatSessionStartOptions, IChatUserActionEvent } from '../../../common/chatService/chatService.js';
+import { ChatRequestQueueKind, ChatSendResult, IChatDetail, IChatModelReference, IChatProgress, IChatSendRequestOptions, IChatSendRequestParams, IChatService, IChatSessionContext, IChatSessionStartOptions, IChatUserActionEvent } from '../../../common/chatService/chatService.js';
import { ChatAgentLocation } from '../../../common/constants.js';
import { IChatModel, IChatRequestModel, IExportableChatData, ISerializableChatData } from '../../../common/model/chatModel.js';
@@ -112,7 +112,7 @@ export class MockChatService implements IChatService {
appendProgress(_request: IChatRequestModel, _progress: IChatProgress): void { }
- sendRequest(_sessionResource: URI, _message: string): Promise<ChatSendResult> {
+ sendRequest(_params: IChatSendRequestParams): Promise<ChatSendResult> {
throw new Error('Method not implemented.');
}