@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
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
17
|
import { Agent, AgentService, AIVariableContribution } from '@theia/ai-core/lib/common';
|
|
18
|
-
import { bindContributionProvider } from '@theia/core';
|
|
18
|
+
import { bindContributionProvider, ResourceResolver } from '@theia/core';
|
|
19
19
|
import { FrontendApplicationContribution, PreferenceContribution } from '@theia/core/lib/browser';
|
|
20
20
|
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
21
21
|
import {
|
|
@@ -25,27 +25,27 @@ import {
|
|
|
25
25
|
ChatRequestParser,
|
|
26
26
|
ChatRequestParserImpl,
|
|
27
27
|
ChatService,
|
|
28
|
-
DefaultChatAgentId
|
|
29
28
|
} from '../common';
|
|
30
29
|
import { ChatAgentsVariableContribution } from '../common/chat-agents-variable-contribution';
|
|
31
|
-
import { CommandChatAgent } from '../common/command-chat-agents';
|
|
32
30
|
import { CustomChatAgent } from '../common/custom-chat-agent';
|
|
33
|
-
import { OrchestratorChatAgent, OrchestratorChatAgentId } from '../common/orchestrator-chat-agent';
|
|
34
31
|
import { DefaultResponseContentFactory, DefaultResponseContentMatcherProvider, ResponseContentMatcherProvider } from '../common/response-content-matcher';
|
|
35
|
-
import { UniversalChatAgent } from '../common/universal-chat-agent';
|
|
36
32
|
import { aiChatPreferences } from './ai-chat-preferences';
|
|
33
|
+
import { ChangeSetElementArgs, ChangeSetFileElement, ChangeSetFileElementFactory } from './change-set-file-element';
|
|
37
34
|
import { AICustomAgentsFrontendApplicationContribution } from './custom-agent-frontend-application-contribution';
|
|
38
35
|
import { FrontendChatServiceImpl } from './frontend-chat-service';
|
|
39
36
|
import { CustomAgentFactory } from './custom-agent-factory';
|
|
40
|
-
import {
|
|
37
|
+
import { ChatToolRequestService } from '../common/chat-tool-request-service';
|
|
38
|
+
import { ChangeSetFileResourceResolver } from './change-set-file-resource';
|
|
39
|
+
import { ChangeSetFileService } from './change-set-file-service';
|
|
41
40
|
|
|
42
41
|
export default new ContainerModule(bind => {
|
|
43
42
|
bindContributionProvider(bind, Agent);
|
|
44
43
|
bindContributionProvider(bind, ChatAgent);
|
|
45
44
|
|
|
45
|
+
bind(ChatToolRequestService).toSelf().inSingletonScope();
|
|
46
|
+
|
|
46
47
|
bind(ChatAgentServiceImpl).toSelf().inSingletonScope();
|
|
47
48
|
bind(ChatAgentService).toService(ChatAgentServiceImpl);
|
|
48
|
-
bind(DefaultChatAgentId).toConstantValue({ id: OrchestratorChatAgentId });
|
|
49
49
|
|
|
50
50
|
bindContributionProvider(bind, ResponseContentMatcherProvider);
|
|
51
51
|
bind(DefaultResponseContentMatcherProvider).toSelf().inSingletonScope();
|
|
@@ -60,22 +60,6 @@ export default new ContainerModule(bind => {
|
|
|
60
60
|
bind(FrontendChatServiceImpl).toSelf().inSingletonScope();
|
|
61
61
|
bind(ChatService).toService(FrontendChatServiceImpl);
|
|
62
62
|
|
|
63
|
-
bind(OrchestratorChatAgent).toSelf().inSingletonScope();
|
|
64
|
-
bind(Agent).toService(OrchestratorChatAgent);
|
|
65
|
-
bind(ChatAgent).toService(OrchestratorChatAgent);
|
|
66
|
-
|
|
67
|
-
bind(O1ChatAgent).toSelf().inSingletonScope();
|
|
68
|
-
bind(Agent).toService(O1ChatAgent);
|
|
69
|
-
bind(ChatAgent).toService(O1ChatAgent);
|
|
70
|
-
|
|
71
|
-
bind(UniversalChatAgent).toSelf().inSingletonScope();
|
|
72
|
-
bind(Agent).toService(UniversalChatAgent);
|
|
73
|
-
bind(ChatAgent).toService(UniversalChatAgent);
|
|
74
|
-
|
|
75
|
-
bind(CommandChatAgent).toSelf().inSingletonScope();
|
|
76
|
-
bind(Agent).toService(CommandChatAgent);
|
|
77
|
-
bind(ChatAgent).toService(CommandChatAgent);
|
|
78
|
-
|
|
79
63
|
bind(PreferenceContribution).toConstantValue({ schema: aiChatPreferences });
|
|
80
64
|
|
|
81
65
|
bind(CustomChatAgent).toSelf();
|
|
@@ -95,4 +79,14 @@ export default new ContainerModule(bind => {
|
|
|
95
79
|
return agent;
|
|
96
80
|
});
|
|
97
81
|
bind(FrontendApplicationContribution).to(AICustomAgentsFrontendApplicationContribution).inSingletonScope();
|
|
82
|
+
|
|
83
|
+
bind(ChangeSetFileService).toSelf().inSingletonScope();
|
|
84
|
+
bind(ChangeSetFileElementFactory).toFactory(ctx => (args: ChangeSetElementArgs) => {
|
|
85
|
+
const container = ctx.container.createChild();
|
|
86
|
+
container.bind(ChangeSetElementArgs).toConstantValue(args);
|
|
87
|
+
container.bind(ChangeSetFileElement).toSelf().inSingletonScope();
|
|
88
|
+
return container.get(ChangeSetFileElement);
|
|
89
|
+
});
|
|
90
|
+
bind(ChangeSetFileResourceResolver).toSelf().inSingletonScope();
|
|
91
|
+
bind(ResourceResolver).toService(ChangeSetFileResourceResolver);
|
|
98
92
|
});
|
|
@@ -0,0 +1,137 @@
|
|
|
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 { URI } from '@theia/core';
|
|
18
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
19
|
+
import { ChangeSetElement, ChangeSetImpl } from '../common';
|
|
20
|
+
import { createChangeSetFileUri } from './change-set-file-resource';
|
|
21
|
+
import { ChangeSetFileService } from './change-set-file-service';
|
|
22
|
+
|
|
23
|
+
export const ChangeSetFileElementFactory = Symbol('ChangeSetFileElementFactory');
|
|
24
|
+
export type ChangeSetFileElementFactory = (elementProps: ChangeSetElementArgs) => ChangeSetFileElement;
|
|
25
|
+
|
|
26
|
+
export const ChangeSetElementArgs = Symbol('ChangeSetElementArgs');
|
|
27
|
+
export interface ChangeSetElementArgs extends Partial<ChangeSetElement> {
|
|
28
|
+
/** The URI of the element, expected to be unique within the same change set. */
|
|
29
|
+
uri: URI;
|
|
30
|
+
/** The change set containing this element. */
|
|
31
|
+
changeSet: ChangeSetImpl;
|
|
32
|
+
/** The id of the chat session containing this change set element. */
|
|
33
|
+
chatSessionId: string;
|
|
34
|
+
/**
|
|
35
|
+
* The state of the file after the changes have been applied.
|
|
36
|
+
* If `undefined`, there is no change.
|
|
37
|
+
*/
|
|
38
|
+
targetState?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
@injectable()
|
|
42
|
+
export class ChangeSetFileElement implements ChangeSetElement {
|
|
43
|
+
|
|
44
|
+
@inject(ChangeSetElementArgs)
|
|
45
|
+
protected readonly elementProps: ChangeSetElementArgs;
|
|
46
|
+
|
|
47
|
+
@inject(ChangeSetFileService)
|
|
48
|
+
protected readonly changeSetFileService: ChangeSetFileService;
|
|
49
|
+
|
|
50
|
+
protected _state: 'pending' | 'applied' | 'discarded' | undefined;
|
|
51
|
+
|
|
52
|
+
protected originalContent: string | undefined;
|
|
53
|
+
|
|
54
|
+
@postConstruct()
|
|
55
|
+
init(): void {
|
|
56
|
+
this.obtainOriginalContent();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected async obtainOriginalContent(): Promise<void> {
|
|
60
|
+
this.originalContent = await this.changeSetFileService.read(this.uri);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get uri(): URI {
|
|
64
|
+
return this.elementProps.uri;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get changedUri(): URI {
|
|
68
|
+
return createChangeSetFileUri(this.elementProps.chatSessionId, this.uri);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get name(): string {
|
|
72
|
+
return this.elementProps.name ?? this.changeSetFileService.getName(this.uri);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get icon(): string | undefined {
|
|
76
|
+
return this.elementProps.icon ?? this.changeSetFileService.getIcon(this.uri);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get additionalInfo(): string | undefined {
|
|
80
|
+
return this.changeSetFileService.getAdditionalInfo(this.uri);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get state(): 'pending' | 'applied' | 'discarded' | undefined {
|
|
84
|
+
return this._state ?? this.elementProps.state;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected set state(value: 'pending' | 'applied' | 'discarded' | undefined) {
|
|
88
|
+
this._state = value;
|
|
89
|
+
this.elementProps.changeSet.notifyChange();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get type(): 'add' | 'modify' | 'delete' | undefined {
|
|
93
|
+
return this.elementProps.type;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get data(): { [key: string]: unknown; } | undefined {
|
|
97
|
+
return this.elementProps.data;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
get targetState(): string {
|
|
101
|
+
return this.elementProps.targetState ?? '';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async open(): Promise<void> {
|
|
105
|
+
this.changeSetFileService.open(this);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async openChange(): Promise<void> {
|
|
109
|
+
this.changeSetFileService.openDiff(
|
|
110
|
+
this.uri,
|
|
111
|
+
this.changedUri
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async accept(contents?: string): Promise<void> {
|
|
116
|
+
this.state = 'applied';
|
|
117
|
+
if (this.type === 'delete') {
|
|
118
|
+
await this.changeSetFileService.delete(this.uri);
|
|
119
|
+
this.state = 'applied';
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
await this.changeSetFileService.write(this.uri, contents !== undefined ? contents : this.targetState);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async discard(): Promise<void> {
|
|
127
|
+
this.state = 'discarded';
|
|
128
|
+
if (this.type === 'add') {
|
|
129
|
+
await this.changeSetFileService.delete(this.uri);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (this.originalContent) {
|
|
133
|
+
await this.changeSetFileService.write(this.uri, this.originalContent);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 { Resource, ResourceResolver, ResourceSaveOptions, URI } from '@theia/core';
|
|
18
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { ChatService } from '../common';
|
|
20
|
+
import { ChangeSetFileElement } from './change-set-file-element';
|
|
21
|
+
|
|
22
|
+
export const CHANGE_SET_FILE_RESOURCE_SCHEME = 'changeset-file';
|
|
23
|
+
const QUERY = 'uri=';
|
|
24
|
+
|
|
25
|
+
export function createChangeSetFileUri(chatSessionId: string, elementUri: URI): URI {
|
|
26
|
+
return new URI(CHANGE_SET_FILE_RESOURCE_SCHEME + '://' + chatSessionId + '/' + elementUri.path).withQuery(QUERY + encodeURIComponent(elementUri.path.toString()));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A file resource within a chat's change set can be resolved with the following URI:
|
|
31
|
+
* changeset-file:/<chat-session-id>?uri=<element-uri-without-scheme>
|
|
32
|
+
*/
|
|
33
|
+
@injectable()
|
|
34
|
+
export class ChangeSetFileResourceResolver implements ResourceResolver {
|
|
35
|
+
|
|
36
|
+
@inject(ChatService)
|
|
37
|
+
protected readonly chatService: ChatService;
|
|
38
|
+
|
|
39
|
+
async resolve(uri: URI): Promise<Resource> {
|
|
40
|
+
if (uri.scheme !== CHANGE_SET_FILE_RESOURCE_SCHEME) {
|
|
41
|
+
throw new Error('The given uri is not a change set file uri: ' + uri);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const chatSessionId = uri.authority;
|
|
45
|
+
const session = this.chatService.getSession(chatSessionId);
|
|
46
|
+
if (!session) {
|
|
47
|
+
throw new Error('Chat session not found: ' + chatSessionId);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const changeSet = session.model.changeSet;
|
|
51
|
+
if (!changeSet) {
|
|
52
|
+
throw new Error('Chat session has no change set: ' + chatSessionId);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const fileUri = decodeURIComponent(uri.query.toString().replace(QUERY, ''));
|
|
56
|
+
const element = changeSet.getElements().find(e => e.uri.path.toString() === fileUri);
|
|
57
|
+
if (!(element instanceof ChangeSetFileElement)) {
|
|
58
|
+
throw new Error('Change set element not found: ' + fileUri);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
uri,
|
|
63
|
+
readOnly: false,
|
|
64
|
+
initiallyDirty: true,
|
|
65
|
+
readContents: async () => element.targetState ?? '',
|
|
66
|
+
saveContents: async (content: string, options?: ResourceSaveOptions): Promise<void> => {
|
|
67
|
+
element.accept(content);
|
|
68
|
+
},
|
|
69
|
+
dispose: () => { }
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
@@ -0,0 +1,136 @@
|
|
|
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 { ILogger, UNTITLED_SCHEME, URI } from '@theia/core';
|
|
18
|
+
import { DiffUris, LabelProvider, OpenerService, open } from '@theia/core/lib/browser';
|
|
19
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import { EditorManager } from '@theia/editor/lib/browser';
|
|
21
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
22
|
+
import { MonacoWorkspace } from '@theia/monaco/lib/browser/monaco-workspace';
|
|
23
|
+
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
|
24
|
+
import { ChangeSetFileElement } from './change-set-file-element';
|
|
25
|
+
|
|
26
|
+
@injectable()
|
|
27
|
+
export class ChangeSetFileService {
|
|
28
|
+
@inject(ILogger)
|
|
29
|
+
protected readonly logger: ILogger;
|
|
30
|
+
|
|
31
|
+
@inject(WorkspaceService)
|
|
32
|
+
protected readonly wsService: WorkspaceService;
|
|
33
|
+
|
|
34
|
+
@inject(LabelProvider)
|
|
35
|
+
protected readonly labelProvider: LabelProvider;
|
|
36
|
+
|
|
37
|
+
@inject(OpenerService)
|
|
38
|
+
protected readonly openerService: OpenerService;
|
|
39
|
+
|
|
40
|
+
@inject(EditorManager)
|
|
41
|
+
protected readonly editorManager: EditorManager;
|
|
42
|
+
|
|
43
|
+
@inject(MonacoWorkspace)
|
|
44
|
+
protected readonly monacoWorkspace: MonacoWorkspace;
|
|
45
|
+
|
|
46
|
+
@inject(FileService)
|
|
47
|
+
protected readonly fileService: FileService;
|
|
48
|
+
|
|
49
|
+
async read(uri: URI): Promise<string | undefined> {
|
|
50
|
+
const exists = await this.fileService.exists(uri);
|
|
51
|
+
if (!exists) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const document = this.monacoWorkspace.getTextDocument(uri.toString());
|
|
56
|
+
if (document) {
|
|
57
|
+
return document.getText();
|
|
58
|
+
}
|
|
59
|
+
return (await this.fileService.readFile(uri)).value.toString();
|
|
60
|
+
} catch (error) {
|
|
61
|
+
this.logger.error('Failed to read original content of change set file element.', error);
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getName(uri: URI): string {
|
|
67
|
+
return this.labelProvider.getName(uri);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getIcon(uri: URI): string | undefined {
|
|
71
|
+
return this.labelProvider.getIcon(uri);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getAdditionalInfo(uri: URI): string | undefined {
|
|
75
|
+
const wsUri = this.wsService.getWorkspaceRootUri(uri);
|
|
76
|
+
if (wsUri) {
|
|
77
|
+
const wsRelative = wsUri.relative(uri);
|
|
78
|
+
if (wsRelative?.hasDir) {
|
|
79
|
+
return `${wsRelative.dir.toString()}`;
|
|
80
|
+
}
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
return this.labelProvider.getLongName(uri.parent);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async open(element: ChangeSetFileElement): Promise<void> {
|
|
87
|
+
const exists = await this.fileService.exists(element.uri);
|
|
88
|
+
if (exists) {
|
|
89
|
+
await open(this.openerService, element.uri);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
await this.editorManager.open(element.changedUri, {
|
|
93
|
+
mode: 'reveal'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async openDiff(originalUri: URI, suggestedUri: URI): Promise<void> {
|
|
98
|
+
const exists = await this.fileService.exists(originalUri);
|
|
99
|
+
const openedUri = exists ? originalUri : originalUri.withScheme(UNTITLED_SCHEME);
|
|
100
|
+
// Currently we don't have a great way to show the suggestions in a diff editor with accept/reject buttons
|
|
101
|
+
// So we just use plain diffs with the suggestions as original and the current state as modified, so users can apply changes in their current state
|
|
102
|
+
// But this leads to wrong colors and wrong label (revert change instead of accept change)
|
|
103
|
+
const diffUri = DiffUris.encode(openedUri, suggestedUri,
|
|
104
|
+
`AI Changes: ${this.labelProvider.getName(originalUri)}`,
|
|
105
|
+
);
|
|
106
|
+
open(this.openerService, diffUri);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async delete(uri: URI): Promise<void> {
|
|
110
|
+
const exists = await this.fileService.exists(uri);
|
|
111
|
+
if (exists) {
|
|
112
|
+
await this.fileService.delete(uri);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async write(uri: URI, targetState: string): Promise<void> {
|
|
117
|
+
const exists = await this.fileService.exists(uri);
|
|
118
|
+
if (!exists) {
|
|
119
|
+
await this.fileService.create(uri, targetState);
|
|
120
|
+
}
|
|
121
|
+
await this.doWrite(uri, targetState);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
protected async doWrite(uri: URI, text: string): Promise<void> {
|
|
125
|
+
const document = this.monacoWorkspace.getTextDocument(uri.toString());
|
|
126
|
+
if (document) {
|
|
127
|
+
await this.monacoWorkspace.applyBackgroundEdit(document, [{
|
|
128
|
+
range: document.textEditorModel.getFullModelRange(),
|
|
129
|
+
text
|
|
130
|
+
}], (editor, wasDirty) => editor === undefined || !wasDirty);
|
|
131
|
+
} else {
|
|
132
|
+
await this.fileService.write(uri, text);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
}
|
|
@@ -19,6 +19,9 @@ import { ChatAgent, ChatServiceImpl, ParsedChatRequest } from '../common';
|
|
|
19
19
|
import { PreferenceService } from '@theia/core/lib/browser';
|
|
20
20
|
import { DEFAULT_CHAT_AGENT_PREF } from './ai-chat-preferences';
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Customizes the ChatServiceImpl to consider preference based default chat agent
|
|
24
|
+
*/
|
|
22
25
|
@injectable()
|
|
23
26
|
export class FrontendChatServiceImpl extends ChatServiceImpl {
|
|
24
27
|
|
|
@@ -27,32 +30,13 @@ export class FrontendChatServiceImpl extends ChatServiceImpl {
|
|
|
27
30
|
|
|
28
31
|
protected override getAgent(parsedRequest: ParsedChatRequest): ChatAgent | undefined {
|
|
29
32
|
const agentPart = this.getMentionedAgent(parsedRequest);
|
|
30
|
-
if (agentPart) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const configuredDefaultChatAgent = this.getConfiguredDefaultChatAgent();
|
|
35
|
-
if (configuredDefaultChatAgent) {
|
|
36
|
-
return configuredDefaultChatAgent;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (this.defaultChatAgentId) {
|
|
40
|
-
const defaultAgent = this.chatAgentService.getAgent(this.defaultChatAgentId.id);
|
|
41
|
-
// the default agent could be disabled
|
|
42
|
-
if (defaultAgent) {
|
|
43
|
-
return defaultAgent;
|
|
33
|
+
if (!agentPart) {
|
|
34
|
+
const configuredDefaultChatAgent = this.getConfiguredDefaultChatAgent();
|
|
35
|
+
if (configuredDefaultChatAgent) {
|
|
36
|
+
return configuredDefaultChatAgent;
|
|
44
37
|
}
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
// check whether "Universal" is available
|
|
48
|
-
const universalAgent = this.chatAgentService.getAgent('Universal');
|
|
49
|
-
if (universalAgent) {
|
|
50
|
-
return universalAgent;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.logger.warn('No default chat agent is configured or available and the "Universal" Chat Agent is unavailable too. Falling back to first registered agent.');
|
|
54
|
-
|
|
55
|
-
return this.chatAgentService.getAgents()[0] ?? undefined;
|
|
39
|
+
return super.getAgent(parsedRequest);
|
|
56
40
|
}
|
|
57
41
|
|
|
58
42
|
protected getConfiguredDefaultChatAgent(): ChatAgent | undefined {
|
|
@@ -38,12 +38,11 @@ import {
|
|
|
38
38
|
LanguageModelStreamResponsePart,
|
|
39
39
|
MessageActor,
|
|
40
40
|
} from '@theia/ai-core/lib/common';
|
|
41
|
-
import { CancellationToken,
|
|
41
|
+
import { CancellationToken, ContributionProvider, ILogger, isArray } from '@theia/core';
|
|
42
42
|
import { inject, injectable, named, postConstruct, unmanaged } from '@theia/core/shared/inversify';
|
|
43
43
|
import { ChatAgentService } from './chat-agent-service';
|
|
44
44
|
import {
|
|
45
45
|
ChatModel,
|
|
46
|
-
ChatRequestModel,
|
|
47
46
|
ChatRequestModelImpl,
|
|
48
47
|
ChatResponseContent,
|
|
49
48
|
ErrorChatResponseContentImpl,
|
|
@@ -53,6 +52,7 @@ import {
|
|
|
53
52
|
import { findFirstMatch, parseContents } from './parse-contents';
|
|
54
53
|
import { DefaultResponseContentFactory, ResponseContentMatcher, ResponseContentMatcherProvider } from './response-content-matcher';
|
|
55
54
|
import { ChatHistoryEntry } from './chat-history-entry';
|
|
55
|
+
import { ChatToolRequestService } from './chat-tool-request-service';
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* A conversation consists of a sequence of ChatMessages.
|
|
@@ -123,10 +123,12 @@ export abstract class AbstractChatAgent {
|
|
|
123
123
|
@inject(LanguageModelRegistry) protected languageModelRegistry: LanguageModelRegistry;
|
|
124
124
|
@inject(ILogger) protected logger: ILogger;
|
|
125
125
|
@inject(CommunicationRecordingService) protected recordingService: CommunicationRecordingService;
|
|
126
|
+
@inject(ChatToolRequestService) protected chatToolRequestService: ChatToolRequestService;
|
|
126
127
|
@inject(PromptService) protected promptService: PromptService;
|
|
127
128
|
|
|
128
129
|
@inject(ContributionProvider) @named(ResponseContentMatcherProvider)
|
|
129
130
|
protected contentMatcherProviders: ContributionProvider<ResponseContentMatcherProvider>;
|
|
131
|
+
protected additionalToolRequests: ToolRequest[] = [];
|
|
130
132
|
protected contentMatchers: ResponseContentMatcher[] = [];
|
|
131
133
|
|
|
132
134
|
@inject(DefaultResponseContentFactory)
|
|
@@ -171,7 +173,6 @@ export abstract class AbstractChatAgent {
|
|
|
171
173
|
);
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
const tools: Map<string, ToolRequest> = new Map();
|
|
175
176
|
if (systemMessageDescription) {
|
|
176
177
|
const systemMsg: ChatMessage = {
|
|
177
178
|
actor: 'system',
|
|
@@ -180,24 +181,20 @@ export abstract class AbstractChatAgent {
|
|
|
180
181
|
};
|
|
181
182
|
// insert system message at the beginning of the request messages
|
|
182
183
|
messages.unshift(systemMsg);
|
|
183
|
-
systemMessageDescription.functionDescriptions?.forEach((tool, id) => {
|
|
184
|
-
tools.set(id, tool);
|
|
185
|
-
});
|
|
186
184
|
}
|
|
187
|
-
this.getTools(request)?.forEach(tool => tools.set(tool.id, tool));
|
|
188
185
|
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
const systemMessageToolRequests = systemMessageDescription?.functionDescriptions?.values();
|
|
187
|
+
const tools = [
|
|
188
|
+
...this.chatToolRequestService.getChatToolRequests(request),
|
|
189
|
+
...this.chatToolRequestService.toChatToolRequests(systemMessageToolRequests ? Array.from(systemMessageToolRequests) : [], request),
|
|
190
|
+
...this.chatToolRequestService.toChatToolRequests(this.additionalToolRequests, request)
|
|
191
|
+
];
|
|
195
192
|
|
|
196
193
|
const languageModelResponse = await this.callLlm(
|
|
197
194
|
languageModel,
|
|
198
195
|
messages,
|
|
199
|
-
tools.
|
|
200
|
-
cancellationToken
|
|
196
|
+
tools.length > 0 ? tools : undefined,
|
|
197
|
+
request.response.cancellationToken
|
|
201
198
|
);
|
|
202
199
|
await this.addContentsToResponse(languageModelResponse, request);
|
|
203
200
|
await this.onResponseComplete(request);
|
|
@@ -265,15 +262,6 @@ export abstract class AbstractChatAgent {
|
|
|
265
262
|
return requestMessages;
|
|
266
263
|
}
|
|
267
264
|
|
|
268
|
-
/**
|
|
269
|
-
* @returns the list of tools used by this agent, or undefined if none is needed.
|
|
270
|
-
*/
|
|
271
|
-
protected getTools(request: ChatRequestModel): ToolRequest[] | undefined {
|
|
272
|
-
return request.message.toolRequests.size > 0
|
|
273
|
-
? [...request.message.toolRequests.values()]
|
|
274
|
-
: undefined;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
265
|
protected async callLlm(
|
|
278
266
|
languageModel: LanguageModel,
|
|
279
267
|
messages: ChatMessage[],
|