@theia/ai-terminal 1.62.0-next.3 → 1.63.0-next.0
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/lib/browser/ai-terminal-agent.d.ts +2 -8
- package/lib/browser/ai-terminal-agent.d.ts.map +1 -1
- package/lib/browser/ai-terminal-agent.js +3 -16
- package/lib/browser/ai-terminal-agent.js.map +1 -1
- package/lib/browser/ai-terminal-prompt-template.d.ts +2 -6
- package/lib/browser/ai-terminal-prompt-template.d.ts.map +1 -1
- package/lib/browser/ai-terminal-prompt-template.js +10 -9
- package/lib/browser/ai-terminal-prompt-template.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/ai-terminal-agent.ts +4 -17
- package/src/browser/ai-terminal-prompt-template.ts +10 -8
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Agent,
|
|
1
|
+
import { Agent, LanguageModelRegistry, LanguageModelRequirement, PromptService } from '@theia/ai-core/lib/common';
|
|
2
2
|
import { LanguageModelService } from '@theia/ai-core/lib/browser';
|
|
3
3
|
import { ILogger } from '@theia/core';
|
|
4
4
|
export declare class AiTerminalAgent implements Agent {
|
|
5
|
-
protected recordingService: CommunicationRecordingService;
|
|
6
5
|
id: string;
|
|
7
6
|
name: string;
|
|
8
7
|
description: string;
|
|
@@ -13,12 +12,7 @@ export declare class AiTerminalAgent implements Agent {
|
|
|
13
12
|
usedInPrompt: boolean;
|
|
14
13
|
description: string;
|
|
15
14
|
}[];
|
|
16
|
-
|
|
17
|
-
id: string;
|
|
18
|
-
name: string;
|
|
19
|
-
description: string;
|
|
20
|
-
template: string;
|
|
21
|
-
}[];
|
|
15
|
+
prompts: import("@theia/ai-core/lib/common").PromptVariantSet[];
|
|
22
16
|
languageModelRequirements: LanguageModelRequirement[];
|
|
23
17
|
protected languageModelRegistry: LanguageModelRegistry;
|
|
24
18
|
protected promptService: PromptService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-terminal-agent.d.ts","sourceRoot":"","sources":["../../src/browser/ai-terminal-agent.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,KAAK,
|
|
1
|
+
{"version":3,"file":"ai-terminal-agent.d.ts","sourceRoot":"","sources":["../../src/browser/ai-terminal-agent.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,KAAK,EAGL,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EAEhB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAgB,OAAO,EAAO,MAAM,aAAa,CAAC;AAWzD,qBACa,eAAgB,YAAW,KAAK;IAEzC,EAAE,SAAwB;IAC1B,IAAI,SAAwB;IAC5B,WAAW,SAEqI;IAChJ,SAAS,UAAM;IACf,SAAS,UAAM;IACf,sBAAsB;;;;QAKpB;IACF,OAAO,yDAAmB;IAC1B,yBAAyB,EAAE,wBAAwB,EAAE,CAKnD;IAGF,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAGvD,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IAGvC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAG1B,SAAS,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;IAE/C,WAAW,CACb,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,sBAAsB,EAAE,MAAM,EAAE,GACjC,OAAO,CAAC,MAAM,EAAE,CAAC;CA+EvB"}
|
|
@@ -42,7 +42,7 @@ let AiTerminalAgent = class AiTerminalAgent {
|
|
|
42
42
|
{ name: 'cwd', usedInPrompt: true, description: 'The current working directory.' },
|
|
43
43
|
{ name: 'recentTerminalContents', usedInPrompt: true, description: 'The last 0 to 50 recent lines visible in the terminal.' }
|
|
44
44
|
];
|
|
45
|
-
this.
|
|
45
|
+
this.prompts = ai_terminal_prompt_template_1.terminalPrompts;
|
|
46
46
|
this.languageModelRequirements = [
|
|
47
47
|
{
|
|
48
48
|
purpose: 'suggest-terminal-commands',
|
|
@@ -65,8 +65,8 @@ let AiTerminalAgent = class AiTerminalAgent {
|
|
|
65
65
|
cwd,
|
|
66
66
|
recentTerminalContents
|
|
67
67
|
};
|
|
68
|
-
const systemMessage = await this.promptService.
|
|
69
|
-
const request = await this.promptService.
|
|
68
|
+
const systemMessage = await this.promptService.getResolvedPromptFragment('terminal-system', parameters).then(p => p === null || p === void 0 ? void 0 : p.text);
|
|
69
|
+
const request = await this.promptService.getResolvedPromptFragment('terminal-user', parameters).then(p => p === null || p === void 0 ? void 0 : p.text);
|
|
70
70
|
if (!systemMessage || !request) {
|
|
71
71
|
this.logger.error('The prompt service didn\'t return prompts for the AI Terminal Agent.');
|
|
72
72
|
return [];
|
|
@@ -99,26 +99,17 @@ let AiTerminalAgent = class AiTerminalAgent {
|
|
|
99
99
|
requestId,
|
|
100
100
|
sessionId
|
|
101
101
|
};
|
|
102
|
-
this.recordingService.recordRequest({
|
|
103
|
-
agentId: this.id,
|
|
104
|
-
sessionId,
|
|
105
|
-
requestId,
|
|
106
|
-
request: llmRequest.messages
|
|
107
|
-
});
|
|
108
102
|
try {
|
|
109
103
|
const result = await this.languageModelService.sendRequest(lm, llmRequest);
|
|
110
104
|
if ((0, common_1.isLanguageModelParsedResponse)(result)) {
|
|
111
105
|
// model returned structured output
|
|
112
106
|
const parsedResult = Commands.safeParse(result.parsed);
|
|
113
107
|
if (parsedResult.success) {
|
|
114
|
-
this.recordingService.recordResponse({ agentId: this.id, sessionId, requestId, response: [{ actor: 'ai', text: result.content, type: 'text' }] });
|
|
115
108
|
return parsedResult.data.commands;
|
|
116
109
|
}
|
|
117
110
|
}
|
|
118
111
|
// fall back to agent-based parsing of result
|
|
119
112
|
const jsonResult = await (0, common_1.getJsonOfResponse)(result);
|
|
120
|
-
const responseTextFromJSON = JSON.stringify(jsonResult);
|
|
121
|
-
this.recordingService.recordResponse({ agentId: this.id, sessionId, requestId, response: [{ actor: 'ai', text: responseTextFromJSON, type: 'text' }] });
|
|
122
113
|
const parsedJsonResult = Commands.safeParse(jsonResult);
|
|
123
114
|
if (parsedJsonResult.success) {
|
|
124
115
|
return parsedJsonResult.data.commands;
|
|
@@ -132,10 +123,6 @@ let AiTerminalAgent = class AiTerminalAgent {
|
|
|
132
123
|
}
|
|
133
124
|
};
|
|
134
125
|
exports.AiTerminalAgent = AiTerminalAgent;
|
|
135
|
-
tslib_1.__decorate([
|
|
136
|
-
(0, inversify_1.inject)(common_1.CommunicationRecordingService),
|
|
137
|
-
tslib_1.__metadata("design:type", Object)
|
|
138
|
-
], AiTerminalAgent.prototype, "recordingService", void 0);
|
|
139
126
|
tslib_1.__decorate([
|
|
140
127
|
(0, inversify_1.inject)(common_1.LanguageModelRegistry),
|
|
141
128
|
tslib_1.__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-terminal-agent.js","sourceRoot":"","sources":["../../src/browser/ai-terminal-agent.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,
|
|
1
|
+
{"version":3,"file":"ai-terminal-agent.js","sourceRoot":"","sources":["../../src/browser/ai-terminal-agent.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,sDAQmC;AACnC,wDAAkE;AAClE,sCAAyD;AACzD,+EAAgE;AAChE,4DAAkE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|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
name: string;
|
|
4
|
-
description: string;
|
|
5
|
-
template: string;
|
|
6
|
-
}[];
|
|
1
|
+
import { PromptVariantSet } from '@theia/ai-core';
|
|
2
|
+
export declare const terminalPrompts: PromptVariantSet[];
|
|
7
3
|
//# sourceMappingURL=ai-terminal-prompt-template.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-terminal-prompt-template.d.ts","sourceRoot":"","sources":["../../src/browser/ai-terminal-prompt-template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai-terminal-prompt-template.d.ts","sourceRoot":"","sources":["../../src/browser/ai-terminal-prompt-template.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,eAAO,MAAM,eAAe,EAAE,gBAAgB,EAkE7C,CAAC"}
|
|
@@ -10,14 +10,13 @@
|
|
|
10
10
|
// SPDX-License-Identifier: MIT
|
|
11
11
|
// *****************************************************************************
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
14
|
-
|
|
15
|
-
exports.terminalPromptTemplates = [
|
|
13
|
+
exports.terminalPrompts = void 0;
|
|
14
|
+
exports.terminalPrompts = [
|
|
16
15
|
{
|
|
17
16
|
id: 'terminal-system',
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
defaultVariant: {
|
|
18
|
+
id: 'terminal-system-default',
|
|
19
|
+
template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
|
|
21
20
|
Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
22
21
|
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
23
22
|
# Instructions
|
|
@@ -61,12 +60,13 @@ nothing to commit, working tree clean
|
|
|
61
60
|
}
|
|
62
61
|
\`\`\`
|
|
63
62
|
`
|
|
63
|
+
}
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
id: 'terminal-user',
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
defaultVariant: {
|
|
68
|
+
id: 'terminal-user-default',
|
|
69
|
+
template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
|
|
70
70
|
Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
71
71
|
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
72
72
|
user-request: {{userRequest}}
|
|
@@ -75,6 +75,7 @@ cwd: {{cwd}}
|
|
|
75
75
|
recent-terminal-contents:
|
|
76
76
|
{{recentTerminalContents}}
|
|
77
77
|
`
|
|
78
|
+
}
|
|
78
79
|
}
|
|
79
80
|
];
|
|
80
81
|
//# sourceMappingURL=ai-terminal-prompt-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-terminal-prompt-template.js","sourceRoot":"","sources":["../../src/browser/ai-terminal-prompt-template.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,+CAA+C;AAC/C,mEAAmE;AACnE,sCAAsC;AACtC,EAAE;AACF,+BAA+B;AAC/B,gFAAgF;;;
|
|
1
|
+
{"version":3,"file":"ai-terminal-prompt-template.js","sourceRoot":"","sources":["../../src/browser/ai-terminal-prompt-template.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,+CAA+C;AAC/C,mEAAmE;AACnE,sCAAsC;AACtC,EAAE;AACF,+BAA+B;AAC/B,gFAAgF;;;AAInE,QAAA,eAAe,GAAuB;IACjD;QACE,EAAE,EAAE,iBAAiB;QACrB,cAAc,EAAE;YACd,EAAE,EAAE,yBAAyB;YAC7B,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Cf;SACI;KACF;IACD;QACE,EAAE,EAAE,eAAe;QACnB,cAAc,EAAE;YACd,EAAE,EAAE,uBAAuB;YAC3B,QAAQ,EAAE;;;;;;;;CAQf;SACI;KACF;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/ai-terminal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.63.0-next.0+c02e6a4f5",
|
|
4
4
|
"description": "Theia - AI Terminal Extension",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/ai-chat": "1.
|
|
7
|
-
"@theia/ai-core": "1.
|
|
8
|
-
"@theia/core": "1.
|
|
9
|
-
"@theia/terminal": "1.
|
|
6
|
+
"@theia/ai-chat": "1.63.0-next.0+c02e6a4f5",
|
|
7
|
+
"@theia/ai-core": "1.63.0-next.0+c02e6a4f5",
|
|
8
|
+
"@theia/core": "1.63.0-next.0+c02e6a4f5",
|
|
9
|
+
"@theia/terminal": "1.63.0-next.0+c02e6a4f5",
|
|
10
10
|
"zod": "^3.23.8",
|
|
11
11
|
"zod-to-json-schema": "^3.23.2"
|
|
12
12
|
},
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"watch": "theiaext watch"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@theia/ext-scripts": "1.
|
|
46
|
+
"@theia/ext-scripts": "1.62.0"
|
|
47
47
|
},
|
|
48
48
|
"nyc": {
|
|
49
49
|
"extends": "../../configs/nyc.json"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "c02e6a4f58728b4067cbd267d598550192abb249"
|
|
52
52
|
}
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
18
|
Agent,
|
|
19
|
-
CommunicationRecordingService,
|
|
20
19
|
getJsonOfResponse,
|
|
21
20
|
isLanguageModelParsedResponse,
|
|
22
21
|
LanguageModelRegistry,
|
|
@@ -26,7 +25,7 @@ import {
|
|
|
26
25
|
} from '@theia/ai-core/lib/common';
|
|
27
26
|
import { LanguageModelService } from '@theia/ai-core/lib/browser';
|
|
28
27
|
import { generateUuid, ILogger, nls } from '@theia/core';
|
|
29
|
-
import {
|
|
28
|
+
import { terminalPrompts } from './ai-terminal-prompt-template';
|
|
30
29
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
31
30
|
import { z } from 'zod';
|
|
32
31
|
import zodToJsonSchema from 'zod-to-json-schema';
|
|
@@ -38,8 +37,6 @@ type Commands = z.infer<typeof Commands>;
|
|
|
38
37
|
|
|
39
38
|
@injectable()
|
|
40
39
|
export class AiTerminalAgent implements Agent {
|
|
41
|
-
@inject(CommunicationRecordingService)
|
|
42
|
-
protected recordingService: CommunicationRecordingService;
|
|
43
40
|
|
|
44
41
|
id = 'Terminal Assistant';
|
|
45
42
|
name = 'Terminal Assistant';
|
|
@@ -54,7 +51,7 @@ export class AiTerminalAgent implements Agent {
|
|
|
54
51
|
{ name: 'cwd', usedInPrompt: true, description: 'The current working directory.' },
|
|
55
52
|
{ name: 'recentTerminalContents', usedInPrompt: true, description: 'The last 0 to 50 recent lines visible in the terminal.' }
|
|
56
53
|
];
|
|
57
|
-
|
|
54
|
+
prompts = terminalPrompts;
|
|
58
55
|
languageModelRequirements: LanguageModelRequirement[] = [
|
|
59
56
|
{
|
|
60
57
|
purpose: 'suggest-terminal-commands',
|
|
@@ -96,8 +93,8 @@ export class AiTerminalAgent implements Agent {
|
|
|
96
93
|
recentTerminalContents
|
|
97
94
|
};
|
|
98
95
|
|
|
99
|
-
const systemMessage = await this.promptService.
|
|
100
|
-
const request = await this.promptService.
|
|
96
|
+
const systemMessage = await this.promptService.getResolvedPromptFragment('terminal-system', parameters).then(p => p?.text);
|
|
97
|
+
const request = await this.promptService.getResolvedPromptFragment('terminal-user', parameters).then(p => p?.text);
|
|
101
98
|
if (!systemMessage || !request) {
|
|
102
99
|
this.logger.error('The prompt service didn\'t return prompts for the AI Terminal Agent.');
|
|
103
100
|
return [];
|
|
@@ -132,13 +129,6 @@ export class AiTerminalAgent implements Agent {
|
|
|
132
129
|
sessionId
|
|
133
130
|
};
|
|
134
131
|
|
|
135
|
-
this.recordingService.recordRequest({
|
|
136
|
-
agentId: this.id,
|
|
137
|
-
sessionId,
|
|
138
|
-
requestId,
|
|
139
|
-
request: llmRequest.messages
|
|
140
|
-
});
|
|
141
|
-
|
|
142
132
|
try {
|
|
143
133
|
const result = await this.languageModelService.sendRequest(lm, llmRequest);
|
|
144
134
|
|
|
@@ -146,15 +136,12 @@ export class AiTerminalAgent implements Agent {
|
|
|
146
136
|
// model returned structured output
|
|
147
137
|
const parsedResult = Commands.safeParse(result.parsed);
|
|
148
138
|
if (parsedResult.success) {
|
|
149
|
-
this.recordingService.recordResponse({ agentId: this.id, sessionId, requestId, response: [{ actor: 'ai', text: result.content, type: 'text' }] });
|
|
150
139
|
return parsedResult.data.commands;
|
|
151
140
|
}
|
|
152
141
|
}
|
|
153
142
|
|
|
154
143
|
// fall back to agent-based parsing of result
|
|
155
144
|
const jsonResult = await getJsonOfResponse(result);
|
|
156
|
-
const responseTextFromJSON = JSON.stringify(jsonResult);
|
|
157
|
-
this.recordingService.recordResponse({ agentId: this.id, sessionId, requestId, response: [{ actor: 'ai', text: responseTextFromJSON, type: 'text' }] });
|
|
158
145
|
const parsedJsonResult = Commands.safeParse(jsonResult);
|
|
159
146
|
if (parsedJsonResult.success) {
|
|
160
147
|
return parsedJsonResult.data.commands;
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
// SPDX-License-Identifier: MIT
|
|
10
10
|
// *****************************************************************************
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { PromptVariantSet } from '@theia/ai-core';
|
|
13
13
|
|
|
14
|
-
export const
|
|
14
|
+
export const terminalPrompts: PromptVariantSet[] = [
|
|
15
15
|
{
|
|
16
16
|
id: 'terminal-system',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
defaultVariant: {
|
|
18
|
+
id: 'terminal-system-default',
|
|
19
|
+
template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
|
|
20
20
|
Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
21
21
|
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
22
22
|
# Instructions
|
|
@@ -60,12 +60,13 @@ nothing to commit, working tree clean
|
|
|
60
60
|
}
|
|
61
61
|
\`\`\`
|
|
62
62
|
`
|
|
63
|
+
}
|
|
63
64
|
},
|
|
64
65
|
{
|
|
65
66
|
id: 'terminal-user',
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
defaultVariant: {
|
|
68
|
+
id: 'terminal-user-default',
|
|
69
|
+
template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
|
|
69
70
|
Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
70
71
|
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
71
72
|
user-request: {{userRequest}}
|
|
@@ -74,5 +75,6 @@ cwd: {{cwd}}
|
|
|
74
75
|
recent-terminal-contents:
|
|
75
76
|
{{recentTerminalContents}}
|
|
76
77
|
`
|
|
78
|
+
}
|
|
77
79
|
}
|
|
78
80
|
];
|