@theia/ai-chat 1.69.0-next.35 → 1.69.0-next.43
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.
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { MaybePromise, ProgressService, URI, Event } from '@theia/core';
|
|
2
2
|
import { ChatAgent, ChatService, ChatSession } from '../common';
|
|
3
|
-
import { PreferenceService } from '@theia/core/lib/common';
|
|
4
3
|
import { AgentService, PromptService, ResolvedPromptFragment } from '@theia/ai-core';
|
|
5
|
-
import { ChangeSetFileElementFactory } from './change-set-file-element';
|
|
6
4
|
export interface SummaryMetadata {
|
|
7
5
|
id?: string;
|
|
8
6
|
label: string;
|
|
@@ -29,14 +27,11 @@ export declare class TaskContextService {
|
|
|
29
27
|
protected readonly promptService: PromptService;
|
|
30
28
|
protected readonly storageService: TaskContextStorageService;
|
|
31
29
|
protected readonly progressService: ProgressService;
|
|
32
|
-
protected readonly preferenceService: PreferenceService;
|
|
33
|
-
protected readonly fileChangeFactory: ChangeSetFileElementFactory;
|
|
34
30
|
get onDidChange(): Event<void>;
|
|
35
31
|
getAll(): Array<Summary>;
|
|
36
32
|
getSummary(sessionIdOrFilePath: string): Promise<string>;
|
|
37
33
|
/** Returns an ID that can be used to refer to the summary in the future. */
|
|
38
34
|
summarize(session: ChatSession, promptId?: string, agent?: ChatAgent, override?: boolean): Promise<string>;
|
|
39
|
-
update(session: ChatSession, promptId?: string, agent?: ChatAgent, override?: boolean): Promise<string>;
|
|
40
35
|
protected getLlmSummary(session: ChatSession, prompt: ResolvedPromptFragment | undefined, agent?: ChatAgent): Promise<string>;
|
|
41
36
|
protected getSystemPrompt(session: ChatSession, promptId?: string): Promise<ResolvedPromptFragment | undefined>;
|
|
42
37
|
hasSummary(chatSession: ChatSession): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-context-service.d.ts","sourceRoot":"","sources":["../../src/browser/task-context-service.ts"],"names":[],"mappings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,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAC7C,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACpC,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,yBAAyB,CAAC;IACvE,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAE7E,IAAI,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC,CAE7B;IAED,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC;IAIlB,UAAU,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAc9D,4EAA4E;IACtE,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,EAAE,QAAQ,UAAO,GAAG,OAAO,CAAC,MAAM,CAAC;cAsC7F,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,sBAAsB,GAAG,SAAS,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;cAsBnH,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,GAAE,MAAuC,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAKrJ,UAAU,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO;IAI7C,SAAS,CAAC,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,GAAG,SAAS;IAI7E,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAKxC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
|
@@ -20,13 +20,10 @@ const tslib_1 = require("tslib");
|
|
|
20
20
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
21
|
const core_1 = require("@theia/core");
|
|
22
22
|
const common_1 = require("../common");
|
|
23
|
-
const common_2 = require("@theia/core/lib/common");
|
|
24
23
|
const chat_session_summary_agent_1 = require("../common/chat-session-summary-agent");
|
|
25
24
|
const promise_util_1 = require("@theia/core/lib/common/promise-util");
|
|
26
25
|
const ai_core_1 = require("@theia/ai-core");
|
|
27
26
|
const chat_session_summary_agent_prompt_1 = require("../common/chat-session-summary-agent-prompt");
|
|
28
|
-
const change_set_file_element_1 = require("./change-set-file-element");
|
|
29
|
-
const yaml = require("js-yaml");
|
|
30
27
|
exports.TaskContextStorageService = Symbol('TaskContextStorageService');
|
|
31
28
|
let TaskContextService = class TaskContextService {
|
|
32
29
|
constructor() {
|
|
@@ -97,89 +94,6 @@ let TaskContextService = class TaskContextService {
|
|
|
97
94
|
this.pendingSummaries.delete(session.id);
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
|
-
async update(session, promptId, agent, override = true) {
|
|
101
|
-
// Get the existing summary for the session
|
|
102
|
-
const existingSummary = this.getSummaryForSession(session);
|
|
103
|
-
if (!existingSummary) {
|
|
104
|
-
// If no summary exists, create one instead
|
|
105
|
-
// TODO: Maybe we could also look into the task context folder and ask for the existing ones with an additional menu to create a new one?
|
|
106
|
-
return this.summarize(session, promptId, agent, override);
|
|
107
|
-
}
|
|
108
|
-
const progress = await this.progressService.showProgress({
|
|
109
|
-
text: core_1.nls.localize('theia/ai/chat/taskContextService/updatingProgressMessage', 'Updating: {0}', session.title || session.id),
|
|
110
|
-
options: { location: 'ai-chat' }
|
|
111
|
-
});
|
|
112
|
-
try {
|
|
113
|
-
const prompt = await this.getSystemPrompt(session, promptId);
|
|
114
|
-
if (!prompt) {
|
|
115
|
-
return '';
|
|
116
|
-
}
|
|
117
|
-
// Get the task context file path
|
|
118
|
-
const taskContextStorageDirectory = this.preferenceService.get(
|
|
119
|
-
// preference key is defined in TASK_CONTEXT_STORAGE_DIRECTORY_PREF in @theia/ai-ide
|
|
120
|
-
'ai-features.promptTemplates.taskContextStorageDirectory', '.prompts/task-contexts');
|
|
121
|
-
const taskContextFileVariable = session.model.context.getVariables().find(variableReq => variableReq.variable.id === 'file-provider' &&
|
|
122
|
-
typeof variableReq.arg === 'string' &&
|
|
123
|
-
(variableReq.arg.startsWith(taskContextStorageDirectory)));
|
|
124
|
-
// Check if we have a document path to update
|
|
125
|
-
if (taskContextFileVariable && typeof taskContextFileVariable.arg === 'string') {
|
|
126
|
-
// Set document path in prompt template
|
|
127
|
-
const documentPath = taskContextFileVariable.arg;
|
|
128
|
-
// Modify prompt to include the document path and content
|
|
129
|
-
prompt.text = prompt.text + '\nThe document to update is: ' + documentPath + '\n\n## Current Document Content\n\n' + existingSummary.summary;
|
|
130
|
-
// Get updated document content from LLM
|
|
131
|
-
const updatedDocumentContent = await this.getLlmSummary(session, prompt, agent);
|
|
132
|
-
if (existingSummary.uri) {
|
|
133
|
-
// updated document metadata shall be updated.
|
|
134
|
-
// otherwise, frontmatter won't be set
|
|
135
|
-
const frontmatter = {
|
|
136
|
-
sessionId: existingSummary.sessionId,
|
|
137
|
-
date: new Date().toISOString(),
|
|
138
|
-
label: existingSummary.label,
|
|
139
|
-
};
|
|
140
|
-
const content = yaml.dump(frontmatter).trim() + `${core_1.EOL}---${core_1.EOL}` + updatedDocumentContent;
|
|
141
|
-
session.model.changeSet.addElements(this.fileChangeFactory({
|
|
142
|
-
uri: existingSummary.uri,
|
|
143
|
-
type: 'modify',
|
|
144
|
-
state: 'pending',
|
|
145
|
-
targetState: content,
|
|
146
|
-
requestId: session.model.id, // not a request id, as no changeRequest made yet.
|
|
147
|
-
chatSessionId: session.id
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
const updatedSummary = {
|
|
152
|
-
...existingSummary,
|
|
153
|
-
summary: updatedDocumentContent
|
|
154
|
-
};
|
|
155
|
-
// Store the updated summary
|
|
156
|
-
await this.storageService.store(updatedSummary);
|
|
157
|
-
}
|
|
158
|
-
return existingSummary.id;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
// Fall back to standard update if no document path is found
|
|
162
|
-
const updatedSummaryText = await this.getLlmSummary(session, prompt, agent);
|
|
163
|
-
const updatedSummary = {
|
|
164
|
-
...existingSummary,
|
|
165
|
-
summary: updatedSummaryText
|
|
166
|
-
};
|
|
167
|
-
await this.storageService.store(updatedSummary);
|
|
168
|
-
return updatedSummary.id;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
const errorSummary = {
|
|
173
|
-
...existingSummary,
|
|
174
|
-
summary: `Summary update failed: ${err instanceof Error ? err.message : typeof err === 'string' ? err : 'Unknown error'}`
|
|
175
|
-
};
|
|
176
|
-
await this.storageService.store(errorSummary);
|
|
177
|
-
throw err;
|
|
178
|
-
}
|
|
179
|
-
finally {
|
|
180
|
-
progress.cancel();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
97
|
async getLlmSummary(session, prompt, agent) {
|
|
184
98
|
if (!prompt) {
|
|
185
99
|
return '';
|
|
@@ -241,14 +155,6 @@ tslib_1.__decorate([
|
|
|
241
155
|
(0, inversify_1.inject)(core_1.ProgressService),
|
|
242
156
|
tslib_1.__metadata("design:type", core_1.ProgressService)
|
|
243
157
|
], TaskContextService.prototype, "progressService", void 0);
|
|
244
|
-
tslib_1.__decorate([
|
|
245
|
-
(0, inversify_1.inject)(common_2.PreferenceService),
|
|
246
|
-
tslib_1.__metadata("design:type", Object)
|
|
247
|
-
], TaskContextService.prototype, "preferenceService", void 0);
|
|
248
|
-
tslib_1.__decorate([
|
|
249
|
-
(0, inversify_1.inject)(change_set_file_element_1.ChangeSetFileElementFactory),
|
|
250
|
-
tslib_1.__metadata("design:type", Function)
|
|
251
|
-
], TaskContextService.prototype, "fileChangeFactory", void 0);
|
|
252
158
|
exports.TaskContextService = TaskContextService = tslib_1.__decorate([
|
|
253
159
|
(0, inversify_1.injectable)()
|
|
254
160
|
], TaskContextService);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-context-service.js","sourceRoot":"","sources":["../../src/browser/task-context-service.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,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,4DAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"task-context-service.js","sourceRoot":"","sources":["../../src/browser/task-context-service.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,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,4DAAkE;AAClE,sCAA2F;AAC3F,sCAAyJ;AAEzJ,qFAA+E;AAC/E,sEAA+D;AAC/D,4CAAqF;AACrF,mGAA0F;AAc7E,QAAA,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAWtE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAAxB;QAEO,qBAAgB,GAAG,IAAI,GAAG,EAA4B,CAAC;IAgHrE,CAAC;IAxGG,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC;IAC3C,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,mBAA2B;QACxC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QACpE,IAAI,QAAQ,EAAE,CAAC;YAAC,OAAO,QAAQ,CAAC,OAAO,CAAC;QAAC,CAAC;QAC1C,MAAM,OAAO,GAAG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Aa,CAAC;;yDAAiD;AACjB;IAArD,IAAA,kBAAM,EAAC,iCAAyB,CAAC;;0DAA8D;AACpD;IAA3C,IAAA,kBAAM,EAAC,sBAAe,CAAC;sCAAqC,sBAAe;2DAAC;6BARpE,kBAAkB;IAD9B,IAAA,sBAAU,GAAE;GACA,kBAAkB,CAkH9B"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/ai-chat",
|
|
3
|
-
"version": "1.69.0-next.
|
|
3
|
+
"version": "1.69.0-next.43+79f6eac6a",
|
|
4
4
|
"description": "Theia - AI Chat Extension",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/ai-core": "1.69.0-next.
|
|
7
|
-
"@theia/core": "1.69.0-next.
|
|
8
|
-
"@theia/editor": "1.69.0-next.
|
|
9
|
-
"@theia/file-search": "1.69.0-next.
|
|
10
|
-
"@theia/filesystem": "1.69.0-next.
|
|
11
|
-
"@theia/monaco": "1.69.0-next.
|
|
6
|
+
"@theia/ai-core": "1.69.0-next.43+79f6eac6a",
|
|
7
|
+
"@theia/core": "1.69.0-next.43+79f6eac6a",
|
|
8
|
+
"@theia/editor": "1.69.0-next.43+79f6eac6a",
|
|
9
|
+
"@theia/file-search": "1.69.0-next.43+79f6eac6a",
|
|
10
|
+
"@theia/filesystem": "1.69.0-next.43+79f6eac6a",
|
|
11
|
+
"@theia/monaco": "1.69.0-next.43+79f6eac6a",
|
|
12
12
|
"@theia/monaco-editor-core": "1.96.302",
|
|
13
|
-
"@theia/workspace": "1.69.0-next.
|
|
13
|
+
"@theia/workspace": "1.69.0-next.43+79f6eac6a",
|
|
14
14
|
"js-yaml": "^4.1.0",
|
|
15
15
|
"tslib": "^2.6.2"
|
|
16
16
|
},
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"nyc": {
|
|
55
55
|
"extends": "../../configs/nyc.json"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "79f6eac6a1a85e9b3e2bddd1b6d1ebf33785ac34"
|
|
58
58
|
}
|
|
@@ -15,15 +15,13 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
17
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
import { MaybePromise, ProgressService, URI, generateUuid, Event,
|
|
18
|
+
import { MaybePromise, ProgressService, URI, generateUuid, Event, nls } from '@theia/core';
|
|
19
19
|
import { ChatAgent, ChatAgentLocation, ChatService, ChatSession, MutableChatModel, MutableChatRequestModel, ParsedChatRequestTextPart } from '../common';
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
import { ChatSessionSummaryAgent } from '../common/chat-session-summary-agent';
|
|
22
22
|
import { Deferred } from '@theia/core/lib/common/promise-util';
|
|
23
23
|
import { AgentService, PromptService, ResolvedPromptFragment } from '@theia/ai-core';
|
|
24
24
|
import { CHAT_SESSION_SUMMARY_PROMPT } from '../common/chat-session-summary-agent-prompt';
|
|
25
|
-
import { ChangeSetFileElementFactory } from './change-set-file-element';
|
|
26
|
-
import * as yaml from 'js-yaml';
|
|
27
25
|
|
|
28
26
|
export interface SummaryMetadata {
|
|
29
27
|
id?: string;
|
|
@@ -57,9 +55,6 @@ export class TaskContextService {
|
|
|
57
55
|
@inject(PromptService) protected readonly promptService: PromptService;
|
|
58
56
|
@inject(TaskContextStorageService) protected readonly storageService: TaskContextStorageService;
|
|
59
57
|
@inject(ProgressService) protected readonly progressService: ProgressService;
|
|
60
|
-
@inject(PreferenceService) protected readonly preferenceService: PreferenceService;
|
|
61
|
-
@inject(ChangeSetFileElementFactory)
|
|
62
|
-
protected readonly fileChangeFactory: ChangeSetFileElementFactory;
|
|
63
58
|
|
|
64
59
|
get onDidChange(): Event<void> {
|
|
65
60
|
return this.storageService.onDidChange;
|
|
@@ -122,96 +117,6 @@ export class TaskContextService {
|
|
|
122
117
|
}
|
|
123
118
|
}
|
|
124
119
|
|
|
125
|
-
async update(session: ChatSession, promptId?: string, agent?: ChatAgent, override = true): Promise<string> {
|
|
126
|
-
// Get the existing summary for the session
|
|
127
|
-
const existingSummary = this.getSummaryForSession(session);
|
|
128
|
-
if (!existingSummary) {
|
|
129
|
-
// If no summary exists, create one instead
|
|
130
|
-
// TODO: Maybe we could also look into the task context folder and ask for the existing ones with an additional menu to create a new one?
|
|
131
|
-
return this.summarize(session, promptId, agent, override);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const progress = await this.progressService.showProgress({
|
|
135
|
-
text: nls.localize('theia/ai/chat/taskContextService/updatingProgressMessage', 'Updating: {0}', session.title || session.id),
|
|
136
|
-
options: { location: 'ai-chat' }
|
|
137
|
-
});
|
|
138
|
-
try {
|
|
139
|
-
const prompt = await this.getSystemPrompt(session, promptId);
|
|
140
|
-
if (!prompt) {
|
|
141
|
-
return '';
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Get the task context file path
|
|
145
|
-
const taskContextStorageDirectory = this.preferenceService.get(
|
|
146
|
-
// preference key is defined in TASK_CONTEXT_STORAGE_DIRECTORY_PREF in @theia/ai-ide
|
|
147
|
-
'ai-features.promptTemplates.taskContextStorageDirectory',
|
|
148
|
-
'.prompts/task-contexts'
|
|
149
|
-
);
|
|
150
|
-
const taskContextFileVariable = session.model.context.getVariables().find(variableReq => variableReq.variable.id === 'file-provider' &&
|
|
151
|
-
typeof variableReq.arg === 'string' &&
|
|
152
|
-
(variableReq.arg.startsWith(taskContextStorageDirectory)));
|
|
153
|
-
|
|
154
|
-
// Check if we have a document path to update
|
|
155
|
-
if (taskContextFileVariable && typeof taskContextFileVariable.arg === 'string') {
|
|
156
|
-
// Set document path in prompt template
|
|
157
|
-
const documentPath = taskContextFileVariable.arg;
|
|
158
|
-
|
|
159
|
-
// Modify prompt to include the document path and content
|
|
160
|
-
prompt.text = prompt.text + '\nThe document to update is: ' + documentPath + '\n\n## Current Document Content\n\n' + existingSummary.summary;
|
|
161
|
-
|
|
162
|
-
// Get updated document content from LLM
|
|
163
|
-
const updatedDocumentContent = await this.getLlmSummary(session, prompt, agent);
|
|
164
|
-
|
|
165
|
-
if (existingSummary.uri) {
|
|
166
|
-
// updated document metadata shall be updated.
|
|
167
|
-
// otherwise, frontmatter won't be set
|
|
168
|
-
const frontmatter = {
|
|
169
|
-
sessionId: existingSummary.sessionId,
|
|
170
|
-
date: new Date().toISOString(),
|
|
171
|
-
label: existingSummary.label,
|
|
172
|
-
};
|
|
173
|
-
const content = yaml.dump(frontmatter).trim() + `${EOL}---${EOL}` + updatedDocumentContent;
|
|
174
|
-
|
|
175
|
-
session.model.changeSet.addElements(this.fileChangeFactory({
|
|
176
|
-
uri: existingSummary.uri,
|
|
177
|
-
type: 'modify',
|
|
178
|
-
state: 'pending',
|
|
179
|
-
targetState: content,
|
|
180
|
-
requestId: session.model.id, // not a request id, as no changeRequest made yet.
|
|
181
|
-
chatSessionId: session.id
|
|
182
|
-
}));
|
|
183
|
-
} else {
|
|
184
|
-
const updatedSummary: Summary = {
|
|
185
|
-
...existingSummary,
|
|
186
|
-
summary: updatedDocumentContent
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// Store the updated summary
|
|
190
|
-
await this.storageService.store(updatedSummary);
|
|
191
|
-
}
|
|
192
|
-
return existingSummary.id;
|
|
193
|
-
} else {
|
|
194
|
-
// Fall back to standard update if no document path is found
|
|
195
|
-
const updatedSummaryText = await this.getLlmSummary(session, prompt, agent);
|
|
196
|
-
const updatedSummary: Summary = {
|
|
197
|
-
...existingSummary,
|
|
198
|
-
summary: updatedSummaryText
|
|
199
|
-
};
|
|
200
|
-
await this.storageService.store(updatedSummary);
|
|
201
|
-
return updatedSummary.id;
|
|
202
|
-
}
|
|
203
|
-
} catch (err) {
|
|
204
|
-
const errorSummary: Summary = {
|
|
205
|
-
...existingSummary,
|
|
206
|
-
summary: `Summary update failed: ${err instanceof Error ? err.message : typeof err === 'string' ? err : 'Unknown error'}`
|
|
207
|
-
};
|
|
208
|
-
await this.storageService.store(errorSummary);
|
|
209
|
-
throw err;
|
|
210
|
-
} finally {
|
|
211
|
-
progress.cancel();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
120
|
protected async getLlmSummary(session: ChatSession, prompt: ResolvedPromptFragment | undefined, agent?: ChatAgent): Promise<string> {
|
|
216
121
|
if (!prompt) { return ''; }
|
|
217
122
|
agent = agent || this.agentService.getAgents().find<ChatAgent>((candidate): candidate is ChatAgent =>
|