@theia/ai-chat 1.56.0 → 1.57.0-next.136
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/README.md +2 -1
- package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-chat-frontend-module.js +14 -17
- package/lib/browser/ai-chat-frontend-module.js.map +1 -1
- package/lib/browser/change-set-file-element.d.ts +44 -0
- package/lib/browser/change-set-file-element.d.ts.map +1 -0
- package/lib/browser/change-set-file-element.js +113 -0
- package/lib/browser/change-set-file-element.js.map +1 -0
- package/lib/browser/change-set-file-resource.d.ts +13 -0
- package/lib/browser/change-set-file-resource.d.ts.map +1 -0
- package/lib/browser/change-set-file-resource.js +73 -0
- package/lib/browser/change-set-file-resource.js.map +1 -0
- package/lib/browser/change-set-file-service.d.ts +26 -0
- package/lib/browser/change-set-file-service.d.ts.map +1 -0
- package/lib/browser/change-set-file-service.js +139 -0
- package/lib/browser/change-set-file-service.js.map +1 -0
- package/lib/browser/frontend-chat-service.d.ts +3 -0
- package/lib/browser/frontend-chat-service.d.ts.map +1 -1
- package/lib/browser/frontend-chat-service.js +8 -20
- package/lib/browser/frontend-chat-service.js.map +1 -1
- package/lib/common/chat-agents.d.ts +4 -5
- package/lib/common/chat-agents.d.ts.map +1 -1
- package/lib/common/chat-agents.js +14 -21
- package/lib/common/chat-agents.js.map +1 -1
- package/lib/common/chat-model.d.ts +117 -7
- package/lib/common/chat-model.d.ts.map +1 -1
- package/lib/common/chat-model.js +124 -8
- package/lib/common/chat-model.js.map +1 -1
- package/lib/common/chat-service.d.ts +17 -0
- package/lib/common/chat-service.d.ts.map +1 -1
- package/lib/common/chat-service.js +34 -2
- package/lib/common/chat-service.js.map +1 -1
- package/lib/common/chat-tool-request-service.d.ts +17 -0
- package/lib/common/chat-tool-request-service.d.ts.map +1 -0
- package/lib/common/chat-tool-request-service.js +52 -0
- package/lib/common/chat-tool-request-service.js.map +1 -0
- package/lib/common/index.d.ts +0 -3
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +0 -3
- package/lib/common/index.js.map +1 -1
- package/package.json +10 -8
- package/src/browser/ai-chat-frontend-module.ts +17 -23
- package/src/browser/change-set-file-element.ts +137 -0
- package/src/browser/change-set-file-resource.ts +74 -0
- package/src/browser/change-set-file-service.ts +136 -0
- package/src/browser/frontend-chat-service.ts +8 -24
- package/src/common/chat-agents.ts +12 -24
- package/src/common/chat-model.ts +236 -14
- package/src/common/chat-service.ts +40 -1
- package/src/common/chat-tool-request-service.ts +59 -0
- package/src/common/index.ts +0 -3
- package/lib/common/command-chat-agents.d.ts +0 -33
- package/lib/common/command-chat-agents.d.ts.map +0 -1
- package/lib/common/command-chat-agents.js +0 -329
- package/lib/common/command-chat-agents.js.map +0 -1
- package/lib/common/o1-chat-agent.d.ts +0 -13
- package/lib/common/o1-chat-agent.d.ts.map +0 -1
- package/lib/common/o1-chat-agent.js +0 -45
- package/lib/common/o1-chat-agent.js.map +0 -1
- package/lib/common/orchestrator-chat-agent.d.ts +0 -22
- package/lib/common/orchestrator-chat-agent.d.ts.map +0 -1
- package/lib/common/orchestrator-chat-agent.js +0 -167
- package/lib/common/orchestrator-chat-agent.js.map +0 -1
- package/lib/common/universal-chat-agent.d.ts +0 -16
- package/lib/common/universal-chat-agent.d.ts.map +0 -1
- package/lib/common/universal-chat-agent.js +0 -109
- package/lib/common/universal-chat-agent.js.map +0 -1
- package/src/common/command-chat-agents.ts +0 -354
- package/src/common/o1-chat-agent.ts +0 -51
- package/src/common/orchestrator-chat-agent.ts +0 -179
- package/src/common/universal-chat-agent.ts +0 -117
package/src/common/chat-model.ts
CHANGED
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
*--------------------------------------------------------------------------------------------*/
|
|
20
20
|
// Partially copied from https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/workbench/contrib/chat/common/chatModel.ts
|
|
21
21
|
|
|
22
|
-
import { Command, Emitter, Event, generateUuid, URI } from '@theia/core';
|
|
22
|
+
import { CancellationToken, CancellationTokenSource, Command, Disposable, Emitter, Event, generateUuid, URI } from '@theia/core';
|
|
23
23
|
import { MarkdownString, MarkdownStringImpl } from '@theia/core/lib/common/markdown-rendering';
|
|
24
24
|
import { Position } from '@theia/core/shared/vscode-languageserver-protocol';
|
|
25
25
|
import { ChatAgentLocation } from './chat-agents';
|
|
26
|
-
import { ParsedChatRequest } from './parsed-chat-request';
|
|
26
|
+
import { ParsedChatRequest, ParsedChatRequestVariablePart } from './parsed-chat-request';
|
|
27
|
+
import { ResolvedAIVariable } from '@theia/ai-core';
|
|
27
28
|
|
|
28
29
|
/**********************
|
|
29
30
|
* INTERFACES AND TYPE GUARDS
|
|
@@ -32,7 +33,11 @@ import { ParsedChatRequest } from './parsed-chat-request';
|
|
|
32
33
|
export type ChatChangeEvent =
|
|
33
34
|
| ChatAddRequestEvent
|
|
34
35
|
| ChatAddResponseEvent
|
|
35
|
-
| ChatRemoveRequestEvent
|
|
36
|
+
| ChatRemoveRequestEvent
|
|
37
|
+
| ChatSetChangeSetEvent
|
|
38
|
+
| ChatSetChangeDeleteEvent
|
|
39
|
+
| ChatUpdateChangeSetEvent
|
|
40
|
+
| ChatRemoveChangeSetEvent;
|
|
36
41
|
|
|
37
42
|
export interface ChatAddRequestEvent {
|
|
38
43
|
kind: 'addRequest';
|
|
@@ -44,6 +49,31 @@ export interface ChatAddResponseEvent {
|
|
|
44
49
|
response: ChatResponseModel;
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
export interface ChatSetChangeSetEvent {
|
|
53
|
+
kind: 'setChangeSet';
|
|
54
|
+
changeSet: ChangeSet;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ChatSetChangeDeleteEvent {
|
|
58
|
+
kind: 'deleteChangeSet';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface ChatUpdateChangeSetEvent {
|
|
62
|
+
kind: 'updateChangeSet';
|
|
63
|
+
changeSet: ChangeSet;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ChatRemoveChangeSetEvent {
|
|
67
|
+
kind: 'removeChangeSet';
|
|
68
|
+
changeSet: ChangeSet;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export namespace ChatChangeEvent {
|
|
72
|
+
export function isChangeSetEvent(event: ChatChangeEvent): event is ChatSetChangeSetEvent | ChatUpdateChangeSetEvent | ChatRemoveChangeSetEvent {
|
|
73
|
+
return event.kind === 'setChangeSet' || event.kind === 'deleteChangeSet' || event.kind === 'removeChangeSet' || event.kind === 'updateChangeSet';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
47
77
|
export type ChatRequestRemovalReason = 'removal' | 'resend' | 'adoption';
|
|
48
78
|
|
|
49
79
|
export interface ChatRemoveRequestEvent {
|
|
@@ -57,10 +87,33 @@ export interface ChatModel {
|
|
|
57
87
|
readonly onDidChange: Event<ChatChangeEvent>;
|
|
58
88
|
readonly id: string;
|
|
59
89
|
readonly location: ChatAgentLocation;
|
|
90
|
+
readonly changeSet?: ChangeSet;
|
|
60
91
|
getRequests(): ChatRequestModel[];
|
|
61
92
|
isEmpty(): boolean;
|
|
62
93
|
}
|
|
63
94
|
|
|
95
|
+
export interface ChangeSet {
|
|
96
|
+
readonly title: string;
|
|
97
|
+
getElements(): ChangeSetElement[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface ChangeSetElement {
|
|
101
|
+
readonly uri: URI;
|
|
102
|
+
|
|
103
|
+
readonly name?: string;
|
|
104
|
+
readonly icon?: string;
|
|
105
|
+
readonly additionalInfo?: string;
|
|
106
|
+
|
|
107
|
+
readonly state?: 'pending' | 'applied' | 'discarded';
|
|
108
|
+
readonly type?: 'add' | 'modify' | 'delete';
|
|
109
|
+
readonly data?: { [key: string]: unknown };
|
|
110
|
+
|
|
111
|
+
open?(): Promise<void>;
|
|
112
|
+
openChange?(): Promise<void>;
|
|
113
|
+
accept?(): Promise<void>;
|
|
114
|
+
discard?(): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
|
|
64
117
|
export interface ChatRequest {
|
|
65
118
|
readonly text: string;
|
|
66
119
|
readonly displayText?: string;
|
|
@@ -76,6 +129,32 @@ export interface ChatRequestModel {
|
|
|
76
129
|
readonly data?: { [key: string]: unknown };
|
|
77
130
|
}
|
|
78
131
|
|
|
132
|
+
export namespace ChatRequestModel {
|
|
133
|
+
export function is(request: unknown): request is ChatRequestModel {
|
|
134
|
+
return !!(
|
|
135
|
+
request &&
|
|
136
|
+
typeof request === 'object' &&
|
|
137
|
+
'id' in request &&
|
|
138
|
+
typeof (request as { id: unknown }).id === 'string' &&
|
|
139
|
+
'session' in request &&
|
|
140
|
+
'request' in request &&
|
|
141
|
+
'response' in request &&
|
|
142
|
+
'message' in request
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
export function isInProgress(request: ChatRequestModel | undefined): boolean {
|
|
146
|
+
if (!request) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const response = request.response;
|
|
150
|
+
return !(
|
|
151
|
+
response.isComplete ||
|
|
152
|
+
response.isCanceled ||
|
|
153
|
+
response.isError
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
79
158
|
export interface ChatProgressMessage {
|
|
80
159
|
kind: 'progressMessage';
|
|
81
160
|
id: string;
|
|
@@ -321,18 +400,59 @@ export interface ChatResponse {
|
|
|
321
400
|
asString(): string;
|
|
322
401
|
}
|
|
323
402
|
|
|
403
|
+
/**
|
|
404
|
+
* The ChatResponseModel wraps the actual ChatResponse with additional information like the current state, progress messages, a unique id etc.
|
|
405
|
+
*/
|
|
324
406
|
export interface ChatResponseModel {
|
|
407
|
+
/**
|
|
408
|
+
* Use this to be notified for any change in the response model
|
|
409
|
+
*/
|
|
325
410
|
readonly onDidChange: Event<void>;
|
|
411
|
+
/**
|
|
412
|
+
* The unique identifier of the response model
|
|
413
|
+
*/
|
|
326
414
|
readonly id: string;
|
|
415
|
+
/**
|
|
416
|
+
* The unique identifier of the request model this response is associated with
|
|
417
|
+
*/
|
|
327
418
|
readonly requestId: string;
|
|
419
|
+
/**
|
|
420
|
+
* In case there are progress messages, then they will be stored here
|
|
421
|
+
*/
|
|
328
422
|
readonly progressMessages: ChatProgressMessage[];
|
|
423
|
+
/**
|
|
424
|
+
* The actual response content
|
|
425
|
+
*/
|
|
329
426
|
readonly response: ChatResponse;
|
|
427
|
+
/**
|
|
428
|
+
* Indicates whether this response is complete. No further changes are expected if 'true'.
|
|
429
|
+
*/
|
|
330
430
|
readonly isComplete: boolean;
|
|
431
|
+
/**
|
|
432
|
+
* Indicates whether this response is canceled. No further changes are expected if 'true'.
|
|
433
|
+
*/
|
|
331
434
|
readonly isCanceled: boolean;
|
|
435
|
+
/**
|
|
436
|
+
* Some agents might need to wait for user input to continue. This flag indicates that.
|
|
437
|
+
*/
|
|
332
438
|
readonly isWaitingForInput: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Indicates whether an error occurred when processing the response. No further changes are expected if 'true'.
|
|
441
|
+
*/
|
|
333
442
|
readonly isError: boolean;
|
|
443
|
+
/**
|
|
444
|
+
* The agent who produced the response content, if there is one.
|
|
445
|
+
*/
|
|
334
446
|
readonly agentId?: string
|
|
447
|
+
/**
|
|
448
|
+
* An optional error object that caused the response to be in an error state.
|
|
449
|
+
*/
|
|
335
450
|
readonly errorObject?: Error;
|
|
451
|
+
/**
|
|
452
|
+
* Some functionality might want to store some data associated with the response.
|
|
453
|
+
* This can be used to store and retrieve such data.
|
|
454
|
+
*/
|
|
455
|
+
readonly data: { [key: string]: unknown };
|
|
336
456
|
}
|
|
337
457
|
|
|
338
458
|
/**********************
|
|
@@ -345,6 +465,8 @@ export class ChatModelImpl implements ChatModel {
|
|
|
345
465
|
|
|
346
466
|
protected _requests: ChatRequestModelImpl[];
|
|
347
467
|
protected _id: string;
|
|
468
|
+
protected _changeSetListener?: Disposable;
|
|
469
|
+
protected _changeSet?: ChangeSetImpl;
|
|
348
470
|
|
|
349
471
|
constructor(public readonly location = ChatAgentLocation.Panel) {
|
|
350
472
|
// TODO accept serialized data as a parameter to restore a previously saved ChatModel
|
|
@@ -356,12 +478,52 @@ export class ChatModelImpl implements ChatModel {
|
|
|
356
478
|
return this._requests;
|
|
357
479
|
}
|
|
358
480
|
|
|
481
|
+
getRequest(id: string): ChatRequestModelImpl | undefined {
|
|
482
|
+
return this._requests.find(request => request.id === id);
|
|
483
|
+
}
|
|
484
|
+
|
|
359
485
|
get id(): string {
|
|
360
486
|
return this._id;
|
|
361
487
|
}
|
|
362
488
|
|
|
363
|
-
|
|
364
|
-
|
|
489
|
+
get changeSet(): ChangeSetImpl | undefined {
|
|
490
|
+
return this._changeSet;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
setChangeSet(changeSet: ChangeSetImpl | undefined): void {
|
|
494
|
+
this._changeSet = changeSet;
|
|
495
|
+
if (this._changeSet === undefined) {
|
|
496
|
+
this._changeSetListener?.dispose();
|
|
497
|
+
this._onDidChangeEmitter.fire({
|
|
498
|
+
kind: 'deleteChangeSet',
|
|
499
|
+
});
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
this._onDidChangeEmitter.fire({
|
|
503
|
+
kind: 'setChangeSet',
|
|
504
|
+
changeSet: this._changeSet,
|
|
505
|
+
});
|
|
506
|
+
this._changeSetListener = this._changeSet.onDidChange(() => {
|
|
507
|
+
this._onDidChangeEmitter.fire({
|
|
508
|
+
kind: 'updateChangeSet',
|
|
509
|
+
changeSet: this._changeSet!,
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
removeChangeSet(): void {
|
|
515
|
+
if (this._changeSet) {
|
|
516
|
+
const oldChangeSet = this._changeSet;
|
|
517
|
+
this._changeSet = undefined;
|
|
518
|
+
this._onDidChangeEmitter.fire({
|
|
519
|
+
kind: 'removeChangeSet',
|
|
520
|
+
changeSet: oldChangeSet,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
addRequest(parsedChatRequest: ParsedChatRequest, agentId?: string, context: ResolvedAIVariable[] = []): ChatRequestModelImpl {
|
|
526
|
+
const requestModel = new ChatRequestModelImpl(this, parsedChatRequest, agentId, context);
|
|
365
527
|
this._requests.push(requestModel);
|
|
366
528
|
this._onDidChangeEmitter.fire({
|
|
367
529
|
kind: 'addRequest',
|
|
@@ -375,21 +537,72 @@ export class ChatModelImpl implements ChatModel {
|
|
|
375
537
|
}
|
|
376
538
|
}
|
|
377
539
|
|
|
540
|
+
export class ChangeSetImpl implements ChangeSet {
|
|
541
|
+
protected readonly _onDidChangeEmitter = new Emitter<void>();
|
|
542
|
+
onDidChange: Event<void> = this._onDidChangeEmitter.event;
|
|
543
|
+
|
|
544
|
+
protected _elements: ChangeSetElement[] = [];
|
|
545
|
+
|
|
546
|
+
constructor(public readonly title: string, elements: ChangeSetElement[] = []) {
|
|
547
|
+
this.addElements(elements);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
getElements(): ChangeSetElement[] {
|
|
551
|
+
return this._elements;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
addElement(element: ChangeSetElement): void {
|
|
555
|
+
this.addElements([element]);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
addElements(elements: ChangeSetElement[]): void {
|
|
559
|
+
this._elements.push(...elements);
|
|
560
|
+
this.notifyChange();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
replaceElement(element: ChangeSetElement): boolean {
|
|
564
|
+
const index = this._elements.findIndex(e => e.uri.toString() === element.uri.toString());
|
|
565
|
+
if (index < 0) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
this._elements[index] = element;
|
|
569
|
+
this.notifyChange();
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
addOrReplaceElement(element: ChangeSetElement): void {
|
|
574
|
+
if (!this.replaceElement(element)) {
|
|
575
|
+
this.addElement(element);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
removeElement(index: number): void {
|
|
580
|
+
this._elements.splice(index, 1);
|
|
581
|
+
this.notifyChange();
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
notifyChange(): void {
|
|
585
|
+
this._onDidChangeEmitter.fire();
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
378
589
|
export class ChatRequestModelImpl implements ChatRequestModel {
|
|
379
590
|
protected readonly _id: string;
|
|
380
|
-
protected _session:
|
|
591
|
+
protected _session: ChatModelImpl;
|
|
381
592
|
protected _request: ChatRequest;
|
|
382
593
|
protected _response: ChatResponseModelImpl;
|
|
594
|
+
protected _context: ResolvedAIVariable[];
|
|
383
595
|
protected _agentId?: string;
|
|
384
596
|
protected _data: { [key: string]: unknown };
|
|
385
597
|
|
|
386
|
-
constructor(session:
|
|
387
|
-
data: { [key: string]: unknown } = {}) {
|
|
598
|
+
constructor(session: ChatModelImpl, public readonly message: ParsedChatRequest, agentId?: string,
|
|
599
|
+
context: ResolvedAIVariable[] = [], data: { [key: string]: unknown } = {}) {
|
|
388
600
|
// TODO accept serialized data as a parameter to restore a previously saved ChatRequestModel
|
|
389
601
|
this._request = message.request;
|
|
390
602
|
this._id = generateUuid();
|
|
391
603
|
this._session = session;
|
|
392
604
|
this._response = new ChatResponseModelImpl(this._id, agentId);
|
|
605
|
+
this._context = context.concat(message.parts.filter(part => part.kind === 'var').map(part => (part as ParsedChatRequestVariablePart).resolution));
|
|
393
606
|
this._agentId = agentId;
|
|
394
607
|
this._data = data;
|
|
395
608
|
}
|
|
@@ -410,7 +623,7 @@ export class ChatRequestModelImpl implements ChatRequestModel {
|
|
|
410
623
|
return this._id;
|
|
411
624
|
}
|
|
412
625
|
|
|
413
|
-
get session():
|
|
626
|
+
get session(): ChatModelImpl {
|
|
414
627
|
return this._session;
|
|
415
628
|
}
|
|
416
629
|
|
|
@@ -425,6 +638,10 @@ export class ChatRequestModelImpl implements ChatRequestModel {
|
|
|
425
638
|
get agentId(): string | undefined {
|
|
426
639
|
return this._agentId;
|
|
427
640
|
}
|
|
641
|
+
|
|
642
|
+
cancel(): void {
|
|
643
|
+
this.response.cancel();
|
|
644
|
+
}
|
|
428
645
|
}
|
|
429
646
|
|
|
430
647
|
export class ErrorChatResponseContentImpl implements ErrorChatResponseContent {
|
|
@@ -750,16 +967,18 @@ class ChatResponseModelImpl implements ChatResponseModel {
|
|
|
750
967
|
protected readonly _onDidChangeEmitter = new Emitter<void>();
|
|
751
968
|
onDidChange: Event<void> = this._onDidChangeEmitter.event;
|
|
752
969
|
|
|
970
|
+
data = {};
|
|
971
|
+
|
|
753
972
|
protected _id: string;
|
|
754
973
|
protected _requestId: string;
|
|
755
974
|
protected _progressMessages: ChatProgressMessage[];
|
|
756
975
|
protected _response: ChatResponseImpl;
|
|
757
976
|
protected _isComplete: boolean;
|
|
758
|
-
protected _isCanceled: boolean;
|
|
759
977
|
protected _isWaitingForInput: boolean;
|
|
760
978
|
protected _agentId?: string;
|
|
761
979
|
protected _isError: boolean;
|
|
762
980
|
protected _errorObject: Error | undefined;
|
|
981
|
+
protected _cancellationToken: CancellationTokenSource;
|
|
763
982
|
|
|
764
983
|
constructor(requestId: string, agentId?: string) {
|
|
765
984
|
// TODO accept serialized data as a parameter to restore a previously saved ChatResponseModel
|
|
@@ -770,9 +989,9 @@ class ChatResponseModelImpl implements ChatResponseModel {
|
|
|
770
989
|
response.onDidChange(() => this._onDidChangeEmitter.fire());
|
|
771
990
|
this._response = response;
|
|
772
991
|
this._isComplete = false;
|
|
773
|
-
this._isCanceled = false;
|
|
774
992
|
this._isWaitingForInput = false;
|
|
775
993
|
this._agentId = agentId;
|
|
994
|
+
this._cancellationToken = new CancellationTokenSource();
|
|
776
995
|
}
|
|
777
996
|
|
|
778
997
|
get id(): string {
|
|
@@ -827,7 +1046,7 @@ class ChatResponseModelImpl implements ChatResponseModel {
|
|
|
827
1046
|
}
|
|
828
1047
|
|
|
829
1048
|
get isCanceled(): boolean {
|
|
830
|
-
return this.
|
|
1049
|
+
return this._cancellationToken.token.isCancellationRequested;
|
|
831
1050
|
}
|
|
832
1051
|
|
|
833
1052
|
get isWaitingForInput(): boolean {
|
|
@@ -849,12 +1068,16 @@ class ChatResponseModelImpl implements ChatResponseModel {
|
|
|
849
1068
|
}
|
|
850
1069
|
|
|
851
1070
|
cancel(): void {
|
|
1071
|
+
this._cancellationToken.cancel();
|
|
852
1072
|
this._isComplete = true;
|
|
853
|
-
this._isCanceled = true;
|
|
854
1073
|
this._isWaitingForInput = false;
|
|
855
1074
|
this._onDidChangeEmitter.fire();
|
|
856
1075
|
}
|
|
857
1076
|
|
|
1077
|
+
get cancellationToken(): CancellationToken {
|
|
1078
|
+
return this._cancellationToken.token;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
858
1081
|
waitForInput(): void {
|
|
859
1082
|
this._isWaitingForInput = true;
|
|
860
1083
|
this._onDidChangeEmitter.fire();
|
|
@@ -867,7 +1090,6 @@ class ChatResponseModelImpl implements ChatResponseModel {
|
|
|
867
1090
|
|
|
868
1091
|
error(error: Error): void {
|
|
869
1092
|
this._isComplete = true;
|
|
870
|
-
this._isCanceled = false;
|
|
871
1093
|
this._isWaitingForInput = false;
|
|
872
1094
|
this._isError = true;
|
|
873
1095
|
this._errorObject = error;
|
|
@@ -67,11 +67,22 @@ export interface SessionOptions {
|
|
|
67
67
|
focus?: boolean;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* The default chat agent to invoke
|
|
72
|
+
*/
|
|
70
73
|
export const DefaultChatAgentId = Symbol('DefaultChatAgentId');
|
|
71
74
|
export interface DefaultChatAgentId {
|
|
72
75
|
id: string;
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
/**
|
|
79
|
+
* In case no fitting chat agent is available, this one will be used (if it is itself available)
|
|
80
|
+
*/
|
|
81
|
+
export const FallbackChatAgentId = Symbol('FallbackChatAgentId');
|
|
82
|
+
export interface FallbackChatAgentId {
|
|
83
|
+
id: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
75
86
|
export const ChatService = Symbol('ChatService');
|
|
76
87
|
export interface ChatService {
|
|
77
88
|
onActiveSessionChanged: Event<ActiveSessionChangedEvent>
|
|
@@ -86,6 +97,11 @@ export interface ChatService {
|
|
|
86
97
|
sessionId: string,
|
|
87
98
|
request: ChatRequest
|
|
88
99
|
): Promise<ChatRequestInvocation | undefined>;
|
|
100
|
+
|
|
101
|
+
deleteChangeSet(sessionId: string): void;
|
|
102
|
+
deleteChangeSetElement(sessionId: string, index: number): void;
|
|
103
|
+
|
|
104
|
+
cancelRequest(sessionId: string, requestId: string): Promise<void>;
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
interface ChatSessionInternal extends ChatSession {
|
|
@@ -103,6 +119,9 @@ export class ChatServiceImpl implements ChatService {
|
|
|
103
119
|
@inject(DefaultChatAgentId) @optional()
|
|
104
120
|
protected defaultChatAgentId: DefaultChatAgentId | undefined;
|
|
105
121
|
|
|
122
|
+
@inject(FallbackChatAgentId) @optional()
|
|
123
|
+
protected fallbackChatAgentId: FallbackChatAgentId | undefined;
|
|
124
|
+
|
|
106
125
|
@inject(ChatRequestParser)
|
|
107
126
|
protected chatRequestParser: ChatRequestParser;
|
|
108
127
|
|
|
@@ -219,18 +238,38 @@ export class ChatServiceImpl implements ChatService {
|
|
|
219
238
|
return invocation;
|
|
220
239
|
}
|
|
221
240
|
|
|
241
|
+
async cancelRequest(sessionId: string, requestId: string): Promise<void> {
|
|
242
|
+
return this.getSession(sessionId)?.model.getRequest(requestId)?.response.cancel();
|
|
243
|
+
}
|
|
244
|
+
|
|
222
245
|
protected getAgent(parsedRequest: ParsedChatRequest): ChatAgent | undefined {
|
|
223
246
|
const agentPart = this.getMentionedAgent(parsedRequest);
|
|
224
247
|
if (agentPart) {
|
|
225
248
|
return this.chatAgentService.getAgent(agentPart.agentId);
|
|
226
249
|
}
|
|
250
|
+
let chatAgent = undefined;
|
|
227
251
|
if (this.defaultChatAgentId) {
|
|
228
|
-
|
|
252
|
+
chatAgent = this.chatAgentService.getAgent(this.defaultChatAgentId.id);
|
|
253
|
+
}
|
|
254
|
+
if (!chatAgent && this.fallbackChatAgentId) {
|
|
255
|
+
chatAgent = this.chatAgentService.getAgent(this.fallbackChatAgentId.id);
|
|
229
256
|
}
|
|
257
|
+
if (chatAgent) {
|
|
258
|
+
return chatAgent;
|
|
259
|
+
}
|
|
260
|
+
this.logger.warn('Neither the default chat agent nor the fallback chat agent are configured or available. Falling back to the first registered agent');
|
|
230
261
|
return this.chatAgentService.getAgents()[0] ?? undefined;
|
|
231
262
|
}
|
|
232
263
|
|
|
233
264
|
protected getMentionedAgent(parsedRequest: ParsedChatRequest): ParsedChatRequestAgentPart | undefined {
|
|
234
265
|
return parsedRequest.parts.find(p => p instanceof ParsedChatRequestAgentPart) as ParsedChatRequestAgentPart | undefined;
|
|
235
266
|
}
|
|
267
|
+
|
|
268
|
+
deleteChangeSet(sessionId: string): void {
|
|
269
|
+
this.getSession(sessionId)?.model.setChangeSet(undefined);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
deleteChangeSetElement(sessionId: string, index: number): void {
|
|
273
|
+
this.getSession(sessionId)?.model.changeSet?.removeElement(index);
|
|
274
|
+
}
|
|
236
275
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ToolRequest } from '@theia/ai-core';
|
|
18
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { ChatRequestModelImpl } from './chat-model';
|
|
20
|
+
|
|
21
|
+
export interface ChatToolRequest extends ToolRequest {
|
|
22
|
+
handler: (
|
|
23
|
+
arg_string: string,
|
|
24
|
+
context: ChatRequestModelImpl,
|
|
25
|
+
) => Promise<unknown>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Wraps tool requests in a chat context.
|
|
30
|
+
*
|
|
31
|
+
* This service extracts tool requests from a given chat request model and wraps their
|
|
32
|
+
* handler functions to provide additional context, such as the chat request model.
|
|
33
|
+
*/
|
|
34
|
+
@injectable()
|
|
35
|
+
export class ChatToolRequestService {
|
|
36
|
+
|
|
37
|
+
getChatToolRequests(request: ChatRequestModelImpl): ChatToolRequest[] {
|
|
38
|
+
const toolRequests = request.message.toolRequests.size > 0 ? [...request.message.toolRequests.values()] : undefined;
|
|
39
|
+
if (!toolRequests) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return this.toChatToolRequests(toolRequests, request);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
toChatToolRequests(toolRequests: ToolRequest[] | undefined, request: ChatRequestModelImpl): ChatToolRequest[] {
|
|
46
|
+
if (!toolRequests) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
return toolRequests.map(toolRequest => this.toChatToolRequest(toolRequest, request));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected toChatToolRequest(toolRequest: ToolRequest, request: ChatRequestModelImpl): ChatToolRequest {
|
|
53
|
+
return {
|
|
54
|
+
...toolRequest,
|
|
55
|
+
handler: async (arg_string: string) => toolRequest.handler(arg_string, request)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
package/src/common/index.ts
CHANGED
|
@@ -19,8 +19,5 @@ export * from './chat-model';
|
|
|
19
19
|
export * from './chat-model-util';
|
|
20
20
|
export * from './chat-request-parser';
|
|
21
21
|
export * from './chat-service';
|
|
22
|
-
export * from './command-chat-agents';
|
|
23
22
|
export * from './custom-chat-agent';
|
|
24
23
|
export * from './parsed-chat-request';
|
|
25
|
-
export * from './orchestrator-chat-agent';
|
|
26
|
-
export * from './universal-chat-agent';
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AbstractTextToModelParsingChatAgent, ChatAgent, SystemMessageDescription } from './chat-agents';
|
|
2
|
-
import { PromptTemplate, AgentSpecificVariables } from '@theia/ai-core';
|
|
3
|
-
import { ChatRequestModelImpl, ChatResponseContent } from './chat-model';
|
|
4
|
-
import { CommandRegistry, MessageService } from '@theia/core';
|
|
5
|
-
export declare const commandTemplate: PromptTemplate;
|
|
6
|
-
interface ParsedCommand {
|
|
7
|
-
type: 'theia-command' | 'custom-handler' | 'no-command';
|
|
8
|
-
commandId: string;
|
|
9
|
-
arguments?: string[];
|
|
10
|
-
message?: string;
|
|
11
|
-
}
|
|
12
|
-
export declare class CommandChatAgent extends AbstractTextToModelParsingChatAgent<ParsedCommand> implements ChatAgent {
|
|
13
|
-
protected commandRegistry: CommandRegistry;
|
|
14
|
-
protected messageService: MessageService;
|
|
15
|
-
readonly name: string;
|
|
16
|
-
readonly description: string;
|
|
17
|
-
readonly variables: string[];
|
|
18
|
-
readonly promptTemplates: PromptTemplate[];
|
|
19
|
-
readonly functions: string[];
|
|
20
|
-
readonly agentSpecificVariables: AgentSpecificVariables[];
|
|
21
|
-
constructor();
|
|
22
|
-
protected getSystemMessageDescription(): Promise<SystemMessageDescription | undefined>;
|
|
23
|
-
/**
|
|
24
|
-
* @param text the text received from the language model
|
|
25
|
-
* @returns the parsed command if the text contained a valid command.
|
|
26
|
-
* If there was no json in the text, return a no-command response.
|
|
27
|
-
*/
|
|
28
|
-
protected parseTextResponse(text: string): Promise<ParsedCommand>;
|
|
29
|
-
protected createResponseContent(parsedCommand: ParsedCommand, request: ChatRequestModelImpl): ChatResponseContent;
|
|
30
|
-
protected commandCallback(...commandArgs: unknown[]): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
export {};
|
|
33
|
-
//# sourceMappingURL=command-chat-agents.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-chat-agents.d.ts","sourceRoot":"","sources":["../../src/common/command-chat-agents.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,mCAAmC,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EACH,cAAc,EACd,sBAAsB,EACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,oBAAoB,EACpB,mBAAmB,EAKtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,eAAe,EACf,cAAc,EAEjB,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,eAAe,EAAE,cA8M5B,CAAC;AAEH,UAAU,aAAa;IACnB,IAAI,EAAE,eAAe,GAAG,gBAAgB,GAAG,YAAY,CAAA;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBACa,gBAAiB,SAAQ,mCAAmC,CAAC,aAAa,CAAE,YAAW,SAAS;IAEzG,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAE3C,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,eAAe,EAAE,cAAc,EAAE,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,CAAC;;cAqB1C,2BAA2B,IAAI,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC;IAc5F;;;;OAIG;cACa,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAUvE,SAAS,CAAC,qBAAqB,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,oBAAoB,GAAG,mBAAmB;cAqCjG,eAAe,CAAC,GAAG,WAAW,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAI5E"}
|