@theia/ai-chat 1.65.0-next.6 → 1.65.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.
Files changed (75) hide show
  1. package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -1
  2. package/lib/browser/ai-chat-frontend-module.js +5 -4
  3. package/lib/browser/ai-chat-frontend-module.js.map +1 -1
  4. package/lib/browser/change-set-file-element.d.ts +2 -2
  5. package/lib/browser/change-set-file-element.d.ts.map +1 -1
  6. package/lib/browser/change-set-file-element.js +6 -6
  7. package/lib/browser/change-set-file-element.js.map +1 -1
  8. package/lib/browser/{chat-tool-preferences.d.ts → chat-tool-preference-bindings.d.ts} +3 -23
  9. package/lib/browser/chat-tool-preference-bindings.d.ts.map +1 -0
  10. package/lib/browser/chat-tool-preference-bindings.js +122 -0
  11. package/lib/browser/chat-tool-preference-bindings.js.map +1 -0
  12. package/lib/browser/chat-tool-request-service.d.ts +2 -1
  13. package/lib/browser/chat-tool-request-service.d.ts.map +1 -1
  14. package/lib/browser/chat-tool-request-service.js +4 -3
  15. package/lib/browser/chat-tool-request-service.js.map +1 -1
  16. package/lib/browser/delegation-response-content.d.ts +1 -3
  17. package/lib/browser/delegation-response-content.d.ts.map +1 -1
  18. package/lib/browser/delegation-response-content.js +2 -14
  19. package/lib/browser/delegation-response-content.js.map +1 -1
  20. package/lib/browser/frontend-chat-service.d.ts +1 -1
  21. package/lib/browser/frontend-chat-service.d.ts.map +1 -1
  22. package/lib/browser/frontend-chat-service.js +3 -3
  23. package/lib/browser/frontend-chat-service.js.map +1 -1
  24. package/lib/browser/task-context-service.d.ts +1 -1
  25. package/lib/browser/task-context-service.d.ts.map +1 -1
  26. package/lib/browser/task-context-service.js +2 -2
  27. package/lib/browser/task-context-service.js.map +1 -1
  28. package/lib/{browser → common}/ai-chat-preferences.d.ts +1 -1
  29. package/lib/common/ai-chat-preferences.d.ts.map +1 -0
  30. package/lib/{browser → common}/ai-chat-preferences.js +1 -2
  31. package/lib/common/ai-chat-preferences.js.map +1 -0
  32. package/lib/common/chat-agents.d.ts +4 -0
  33. package/lib/common/chat-agents.d.ts.map +1 -1
  34. package/lib/common/chat-agents.js +36 -4
  35. package/lib/common/chat-agents.js.map +1 -1
  36. package/lib/common/chat-model.d.ts +1 -0
  37. package/lib/common/chat-model.d.ts.map +1 -1
  38. package/lib/common/chat-model.js +12 -0
  39. package/lib/common/chat-model.js.map +1 -1
  40. package/lib/common/chat-service.d.ts +5 -5
  41. package/lib/common/chat-service.d.ts.map +1 -1
  42. package/lib/common/chat-service.js +12 -9
  43. package/lib/common/chat-service.js.map +1 -1
  44. package/lib/common/chat-session-summary-agent.d.ts +0 -1
  45. package/lib/common/chat-session-summary-agent.d.ts.map +1 -1
  46. package/lib/common/chat-session-summary-agent.js +0 -1
  47. package/lib/common/chat-session-summary-agent.js.map +1 -1
  48. package/lib/common/chat-tool-preferences.d.ts +23 -0
  49. package/lib/common/chat-tool-preferences.d.ts.map +1 -0
  50. package/lib/common/chat-tool-preferences.js +68 -0
  51. package/lib/common/chat-tool-preferences.js.map +1 -0
  52. package/lib/node/ai-chat-backend-module.d.ts +4 -0
  53. package/lib/node/ai-chat-backend-module.d.ts.map +1 -0
  54. package/lib/node/ai-chat-backend-module.js +26 -0
  55. package/lib/node/ai-chat-backend-module.js.map +1 -0
  56. package/package.json +12 -12
  57. package/src/browser/ai-chat-frontend-module.ts +5 -4
  58. package/src/browser/change-set-file-element.ts +2 -2
  59. package/src/browser/{chat-tool-preferences.ts → chat-tool-preference-bindings.ts} +3 -64
  60. package/src/browser/chat-tool-request-service.ts +2 -1
  61. package/src/browser/delegation-response-content.ts +4 -19
  62. package/src/browser/frontend-chat-service.ts +2 -2
  63. package/src/browser/task-context-service.ts +1 -1
  64. package/src/{browser → common}/ai-chat-preferences.ts +2 -4
  65. package/src/common/chat-agents.ts +37 -4
  66. package/src/common/chat-model.ts +14 -0
  67. package/src/common/chat-service.ts +17 -10
  68. package/src/common/chat-session-summary-agent.ts +0 -1
  69. package/src/common/chat-tool-preferences.ts +83 -0
  70. package/src/node/ai-chat-backend-module.ts +25 -0
  71. package/lib/browser/ai-chat-preferences.d.ts.map +0 -1
  72. package/lib/browser/ai-chat-preferences.js.map +0 -1
  73. package/lib/browser/chat-tool-preferences.d.ts.map +0 -1
  74. package/lib/browser/chat-tool-preferences.js +0 -170
  75. package/lib/browser/chat-tool-preferences.js.map +0 -1
@@ -62,6 +62,7 @@ import {
62
62
  ThinkingChatResponseContentImpl,
63
63
  ToolCallChatResponseContentImpl,
64
64
  ErrorChatResponseContent,
65
+ InformationalChatResponseContent,
65
66
  } from './chat-model';
66
67
  import { ChatToolRequest, ChatToolRequestService } from './chat-tool-request-service';
67
68
  import { parseContents } from './parse-contents';
@@ -278,7 +279,22 @@ export abstract class AbstractChatAgent implements ChatAgent {
278
279
 
279
280
  if (request.response.isComplete || includeResponseInProgress) {
280
281
  const responseMessages: LanguageModelMessage[] = request.response.response.content
281
- .filter(c => !ErrorChatResponseContent.is(c))
282
+ .filter(c => {
283
+ // we do not send errors or informational content
284
+ if (ErrorChatResponseContent.is(c) || InformationalChatResponseContent.is(c)) {
285
+ return false;
286
+ }
287
+ // content even has an own converter, definitely include it
288
+ if (ChatResponseContent.hasToLanguageModelMessage(c)) {
289
+ return true;
290
+ }
291
+ // make sure content did not indicate to be excluded by returning undefined in asString
292
+ if (ChatResponseContent.hasAsString(c) && c.asString() === undefined) {
293
+ return false;
294
+ }
295
+ // include the rest
296
+ return true;
297
+ })
282
298
  .flatMap(c => {
283
299
  if (ChatResponseContent.hasToLanguageModelMessage(c)) {
284
300
  return c.toLanguageModelMessage();
@@ -287,8 +303,8 @@ export abstract class AbstractChatAgent implements ChatAgent {
287
303
  return {
288
304
  actor: 'ai',
289
305
  type: 'text',
290
- text: c.asString?.() ?? c.asDisplayString?.() ?? '',
291
- } as TextMessage;
306
+ text: c.asString?.() || c.asDisplayString?.() || '',
307
+ } satisfies TextMessage;
292
308
  });
293
309
  messages.push(...responseMessages);
294
310
  }
@@ -298,6 +314,22 @@ export abstract class AbstractChatAgent implements ChatAgent {
298
314
  return requestMessages;
299
315
  }
300
316
 
317
+ /**
318
+ * Deduplicate tools by name (falling back to id) while preserving the first occurrence and order.
319
+ */
320
+ protected deduplicateTools(toolRequests: ChatToolRequest[]): ChatToolRequest[] {
321
+ const seen = new Set<string>();
322
+ const deduped: ChatToolRequest[] = [];
323
+ for (const tool of toolRequests) {
324
+ const key = tool.name ?? tool.id;
325
+ if (!seen.has(key)) {
326
+ seen.add(key);
327
+ deduped.push(tool);
328
+ }
329
+ }
330
+ return deduped;
331
+ }
332
+
301
333
  protected async sendLlmRequest(
302
334
  request: MutableChatRequestModel,
303
335
  messages: LanguageModelMessage[],
@@ -306,7 +338,8 @@ export abstract class AbstractChatAgent implements ChatAgent {
306
338
  ): Promise<LanguageModelResponse> {
307
339
  const agentSettings = this.getLlmSettings();
308
340
  const settings = { ...agentSettings, ...request.session.settings };
309
- const tools = toolRequests.length > 0 ? toolRequests : undefined;
341
+ const dedupedTools = this.deduplicateTools(toolRequests);
342
+ const tools = dedupedTools.length > 0 ? dedupedTools : undefined;
310
343
  return this.languageModelService.sendRequest(
311
344
  languageModel,
312
345
  {
@@ -394,6 +394,7 @@ export interface ToolCallChatResponseContent extends Required<ChatResponseConten
394
394
  confirmed: Promise<boolean>;
395
395
  confirm(): void;
396
396
  deny(): void;
397
+ cancelConfirmation(reason?: unknown): void;
397
398
  }
398
399
 
399
400
  export interface ThinkingChatResponseContent
@@ -1905,6 +1906,19 @@ export class MutableChatResponseModel implements ChatResponseModel {
1905
1906
  this._cancellationToken.cancel();
1906
1907
  this._isComplete = true;
1907
1908
  this._isWaitingForInput = false;
1909
+
1910
+ // Ensure any pending tool confirmations are canceled when the chat is canceled
1911
+ try {
1912
+ const content = this._response.content;
1913
+ for (const item of content) {
1914
+ if (ToolCallChatResponseContent.is(item)) {
1915
+ item.cancelConfirmation(new Error('Chat request canceled'));
1916
+ }
1917
+ }
1918
+ } catch (e) {
1919
+ // best-effort: ignore errors while canceling confirmations
1920
+ }
1921
+
1908
1922
  this._onDidChangeEmitter.fire();
1909
1923
  }
1910
1924
 
@@ -139,6 +139,8 @@ export interface ChatService {
139
139
  deleteChangeSetElement(sessionId: string, uri: URI): void;
140
140
 
141
141
  cancelRequest(sessionId: string, requestId: string): Promise<void>;
142
+
143
+ getAgent(parsedRequest: ParsedChatRequest, session: ChatSession): ChatAgent | undefined;
142
144
  }
143
145
 
144
146
  interface ChatSessionInternal extends ChatSession {
@@ -233,10 +235,13 @@ export class ChatServiceImpl implements ChatService {
233
235
  return undefined;
234
236
  }
235
237
 
238
+ this.cancelIncompleteRequests(session);
239
+
236
240
  const resolutionContext: ChatSessionContext = { model: session.model };
237
241
  const resolvedContext = await this.resolveChatContext(request.variables ?? session.model.context.getVariables(), resolutionContext);
238
242
  const parsedRequest = await this.chatRequestParser.parseChatRequest(request, session.model.location, resolvedContext);
239
243
  const agent = this.getAgent(parsedRequest, session);
244
+ session.pinnedAgent = agent;
240
245
 
241
246
  if (agent === undefined) {
242
247
  const error = 'No ChatAgents available to handle request!';
@@ -274,6 +279,14 @@ export class ChatServiceImpl implements ChatService {
274
279
  return invocation;
275
280
  }
276
281
 
282
+ protected cancelIncompleteRequests(session: ChatSessionInternal): void {
283
+ for (const pastRequest of session.model.getRequests()) {
284
+ if (!pastRequest.response.isComplete) {
285
+ pastRequest.cancel();
286
+ }
287
+ }
288
+ }
289
+
277
290
  protected updateSessionMetadata(session: ChatSessionInternal, request: MutableChatRequestModel): void {
278
291
  session.lastInteraction = new Date();
279
292
  if (session.title) {
@@ -312,13 +325,13 @@ export class ChatServiceImpl implements ChatService {
312
325
  return this.getSession(sessionId)?.model.getRequest(requestId)?.response.cancel();
313
326
  }
314
327
 
315
- protected getAgent(parsedRequest: ParsedChatRequest, session: ChatSession): ChatAgent | undefined {
328
+ getAgent(parsedRequest: ParsedChatRequest, session: ChatSession): ChatAgent | undefined {
316
329
  const agent = this.initialAgentSelection(parsedRequest);
317
330
  if (!this.isPinChatAgentEnabled()) {
318
331
  return agent;
319
332
  }
320
333
 
321
- return this.handlePinnedAgent(parsedRequest, session, agent);
334
+ return this.getPinnedAgent(parsedRequest, session, agent);
322
335
  }
323
336
 
324
337
  /**
@@ -330,16 +343,12 @@ export class ChatServiceImpl implements ChatService {
330
343
  }
331
344
 
332
345
  /**
333
- * Handle pinned agent by:
334
- * - checking if an agent is pinned, and use it if no other agent is mentioned
335
- * - pinning the current agent
346
+ * Check if an agent is pinned, and use it if no other agent is mentioned.
336
347
  */
337
- protected handlePinnedAgent(parsedRequest: ParsedChatRequest, session: ChatSession, agent: ChatAgent | undefined): ChatAgent | undefined {
348
+ protected getPinnedAgent(parsedRequest: ParsedChatRequest, session: ChatSession, agent: ChatAgent | undefined): ChatAgent | undefined {
338
349
  const mentionedAgentPart = this.getMentionedAgent(parsedRequest);
339
350
  const mentionedAgent = mentionedAgentPart ? this.chatAgentService.getAgent(mentionedAgentPart.agentId) : undefined;
340
351
  if (mentionedAgent) {
341
- // If an agent is explicitly mentioned, it becomes the new pinned agent
342
- session.pinnedAgent = mentionedAgent;
343
352
  return mentionedAgent;
344
353
  } else if (session.pinnedAgent) {
345
354
  // If we have a valid pinned agent, use it (pinned agent may become stale
@@ -349,8 +358,6 @@ export class ChatServiceImpl implements ChatService {
349
358
  return pinnedAgent;
350
359
  }
351
360
  }
352
- // Otherwise, override the pinned agent and return the suggested one
353
- session.pinnedAgent = agent;
354
361
  return agent;
355
362
  }
356
363
 
@@ -28,7 +28,6 @@ export class ChatSessionSummaryAgent extends AbstractStreamParsingChatAgent impl
28
28
  id = ChatSessionSummaryAgent.ID;
29
29
  name = 'Chat Session Summary';
30
30
  override description = 'Agent for generating chat session summaries.';
31
- override variables = [];
32
31
  override prompts: PromptVariantSet[] = [CHAT_SESSION_SUMMARY_PROMPT];
33
32
  protected readonly defaultLanguageModelPurpose = 'chat-session-summary';
34
33
  languageModelRequirements: LanguageModelRequirement[] = [{
@@ -0,0 +1,83 @@
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 { AI_CORE_PREFERENCES_TITLE } from '@theia/ai-core/lib/common/ai-core-preferences';
18
+ import { nls } from '@theia/core';
19
+ import {
20
+ createPreferenceProxy,
21
+ PreferenceContribution,
22
+ PreferenceProxy,
23
+ PreferenceSchema,
24
+ PreferenceService,
25
+ } from '@theia/core/lib/common/preferences';
26
+ import { interfaces } from '@theia/core/shared/inversify';
27
+
28
+ export type ChatToolPreferences = PreferenceProxy<ChatToolConfiguration>;
29
+
30
+ export const ChatToolPreferenceContribution = Symbol('ChatToolPreferenceContribution');
31
+ export const ChatToolPreferences = Symbol('ChatToolPreferences');
32
+
33
+ export function createChatToolPreferences(preferences: PreferenceService, schema: PreferenceSchema = chatToolPreferences): ChatToolPreferences {
34
+ return createPreferenceProxy(preferences, schema);
35
+ }
36
+
37
+ export function bindChatToolPreferences(bind: interfaces.Bind): void {
38
+ bind(ChatToolPreferences).toDynamicValue((ctx: interfaces.Context) => {
39
+ const preferences = ctx.container.get<PreferenceService>(PreferenceService);
40
+ const contribution = ctx.container.get<PreferenceContribution>(ChatToolPreferenceContribution);
41
+ return createChatToolPreferences(preferences, contribution.schema);
42
+ }).inSingletonScope();
43
+ bind(ChatToolPreferenceContribution).toConstantValue({ schema: chatToolPreferences });
44
+ bind(PreferenceContribution).toService(ChatToolPreferenceContribution);
45
+ }
46
+
47
+ /**
48
+ * Enum for tool confirmation modes
49
+ */
50
+ export enum ToolConfirmationMode {
51
+ ALWAYS_ALLOW = 'always_allow',
52
+ CONFIRM = 'confirm',
53
+ DISABLED = 'disabled'
54
+ }
55
+
56
+ export const TOOL_CONFIRMATION_PREFERENCE = 'ai-features.chat.toolConfirmation';
57
+
58
+ export const chatToolPreferences: PreferenceSchema = {
59
+ properties: {
60
+ [TOOL_CONFIRMATION_PREFERENCE]: {
61
+ type: 'object',
62
+ additionalProperties: {
63
+ type: 'string',
64
+ enum: [ToolConfirmationMode.ALWAYS_ALLOW, ToolConfirmationMode.CONFIRM, ToolConfirmationMode.DISABLED],
65
+ enumDescriptions: [
66
+ nls.localize('theia/ai/chat/toolConfirmation/yolo/description', 'Execute tools automatically without confirmation'),
67
+ nls.localize('theia/ai/chat/toolConfirmation/confirm/description', 'Ask for confirmation before executing tools'),
68
+ nls.localize('theia/ai/chat/toolConfirmation/disabled/description', 'Disable tool execution')
69
+ ]
70
+ },
71
+ default: {},
72
+ description: nls.localize('theia/ai/chat/toolConfirmation/description',
73
+ 'Configure confirmation behavior for different tools. Key is the tool ID, value is the confirmation mode.' +
74
+ 'Use "*" as the key to set a global default for all tools.'),
75
+ title: AI_CORE_PREFERENCES_TITLE,
76
+ }
77
+ }
78
+ };
79
+
80
+ export interface ChatToolConfiguration {
81
+ [TOOL_CONFIRMATION_PREFERENCE]: { [toolId: string]: ToolConfirmationMode };
82
+ }
83
+
@@ -0,0 +1,25 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2025 STMicroelectronics and others
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 { PreferenceContribution } from '@theia/core';
18
+ import { ContainerModule } from '@theia/core/shared/inversify';
19
+ import { aiChatPreferences } from '../common/ai-chat-preferences';
20
+ import { chatToolPreferences } from '../common/chat-tool-preferences';
21
+
22
+ export default new ContainerModule(bind => {
23
+ bind(PreferenceContribution).toConstantValue({ schema: aiChatPreferences });
24
+ bind(PreferenceContribution).toConstantValue({ schema: chatToolPreferences });
25
+ });
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai-chat-preferences.d.ts","sourceRoot":"","sources":["../../src/browser/ai-chat-preferences.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAE/F,eAAO,MAAM,uBAAuB,sCAAsC,CAAC;AAC3E,eAAO,MAAM,mBAAmB,kCAAkC,CAAC;AAEnE,eAAO,MAAM,iBAAiB,EAAE,gBAmB/B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai-chat-preferences.js","sourceRoot":"","sources":["../../src/browser/ai-chat-preferences.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,wFAA2F;AAC3F,sCAAkC;AAGrB,QAAA,uBAAuB,GAAG,mCAAmC,CAAC;AAC9D,QAAA,mBAAmB,GAAG,+BAA+B,CAAC;AAEtD,QAAA,iBAAiB,GAAqB;IAC/C,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,+BAAuB,CAAC,EAAE;YACvB,IAAI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hC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAGpD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAa;IAEvF;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,oBAAoB;IAezE;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,IAAI;IAqBrE;;OAEG;IACH,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAS5F;;OAEG;IACH,qBAAqB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ5C;;OAEG;IACH,0BAA0B,IAAI;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAA;KAAE;IAIxE,gCAAgC,IAAI,IAAI;CAQ3C"}
@@ -1,170 +0,0 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2025 EclipseSource GmbH.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ToolConfirmationManager = exports.bindChatToolPreferences = exports.createChatToolPreferences = exports.ChatToolPreferences = exports.ChatToolPreferenceContribution = exports.chatToolPreferences = exports.TOOL_CONFIRMATION_PREFERENCE = exports.ToolConfirmationMode = void 0;
19
- const tslib_1 = require("tslib");
20
- const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
21
- const core_1 = require("@theia/core");
22
- const inversify_1 = require("@theia/core/shared/inversify");
23
- const preferences_1 = require("@theia/core/lib/browser/preferences");
24
- /**
25
- * Enum for tool confirmation modes
26
- */
27
- var ToolConfirmationMode;
28
- (function (ToolConfirmationMode) {
29
- ToolConfirmationMode["ALWAYS_ALLOW"] = "always_allow";
30
- ToolConfirmationMode["CONFIRM"] = "confirm";
31
- ToolConfirmationMode["DISABLED"] = "disabled";
32
- })(ToolConfirmationMode || (exports.ToolConfirmationMode = ToolConfirmationMode = {}));
33
- exports.TOOL_CONFIRMATION_PREFERENCE = 'ai-features.chat.toolConfirmation';
34
- exports.chatToolPreferences = {
35
- type: 'object',
36
- properties: {
37
- [exports.TOOL_CONFIRMATION_PREFERENCE]: {
38
- type: 'object',
39
- additionalProperties: {
40
- type: 'string',
41
- enum: [ToolConfirmationMode.ALWAYS_ALLOW, ToolConfirmationMode.CONFIRM, ToolConfirmationMode.DISABLED],
42
- enumDescriptions: [
43
- core_1.nls.localize('theia/ai/chat/toolConfirmation/yolo/description', 'Execute tools automatically without confirmation'),
44
- core_1.nls.localize('theia/ai/chat/toolConfirmation/confirm/description', 'Ask for confirmation before executing tools'),
45
- core_1.nls.localize('theia/ai/chat/toolConfirmation/disabled/description', 'Disable tool execution')
46
- ]
47
- },
48
- default: {},
49
- description: core_1.nls.localize('theia/ai/chat/toolConfirmation/description', 'Configure confirmation behavior for different tools. Key is the tool ID, value is the confirmation mode.' +
50
- 'Use "*" as the key to set a global default for all tools.'),
51
- title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
52
- }
53
- }
54
- };
55
- exports.ChatToolPreferenceContribution = Symbol('ChatToolPreferenceContribution');
56
- exports.ChatToolPreferences = Symbol('ChatToolPreferences');
57
- function createChatToolPreferences(preferences, schema = exports.chatToolPreferences) {
58
- return (0, preferences_1.createPreferenceProxy)(preferences, schema);
59
- }
60
- exports.createChatToolPreferences = createChatToolPreferences;
61
- function bindChatToolPreferences(bind) {
62
- bind(exports.ChatToolPreferences).toDynamicValue((ctx) => {
63
- const preferences = ctx.container.get(preferences_1.PreferenceService);
64
- const contribution = ctx.container.get(exports.ChatToolPreferenceContribution);
65
- return createChatToolPreferences(preferences, contribution.schema);
66
- }).inSingletonScope();
67
- bind(exports.ChatToolPreferenceContribution).toConstantValue({ schema: exports.chatToolPreferences });
68
- bind(preferences_1.PreferenceContribution).toService(exports.ChatToolPreferenceContribution);
69
- }
70
- exports.bindChatToolPreferences = bindChatToolPreferences;
71
- /**
72
- * Utility class to manage tool confirmation settings
73
- */
74
- let ToolConfirmationManager = class ToolConfirmationManager {
75
- constructor() {
76
- // In-memory session overrides (not persisted), per chat
77
- this.sessionOverrides = new Map();
78
- }
79
- /**
80
- * Get the confirmation mode for a specific tool, considering session overrides first (per chat)
81
- */
82
- getConfirmationMode(toolId, chatId) {
83
- const chatMap = this.sessionOverrides.get(chatId);
84
- if (chatMap && chatMap.has(toolId)) {
85
- return chatMap.get(toolId);
86
- }
87
- const toolConfirmation = this.preferences[exports.TOOL_CONFIRMATION_PREFERENCE];
88
- if (toolConfirmation[toolId]) {
89
- return toolConfirmation[toolId];
90
- }
91
- if (toolConfirmation['*']) {
92
- return toolConfirmation['*'];
93
- }
94
- return ToolConfirmationMode.ALWAYS_ALLOW; // Default to Always Allow
95
- }
96
- /**
97
- * Set the confirmation mode for a specific tool (persisted)
98
- */
99
- setConfirmationMode(toolId, mode) {
100
- const current = this.preferences[exports.TOOL_CONFIRMATION_PREFERENCE] || {};
101
- // Determine the global default (star entry), or fallback to schema default
102
- let starMode = current['*'];
103
- if (starMode === undefined) {
104
- starMode = ToolConfirmationMode.ALWAYS_ALLOW;
105
- }
106
- if (mode === starMode) {
107
- // Remove the toolId entry if it exists
108
- if (toolId in current) {
109
- const { [toolId]: _, ...rest } = current;
110
- this.preferenceService.updateValue(exports.TOOL_CONFIRMATION_PREFERENCE, rest);
111
- }
112
- // else, nothing to update
113
- }
114
- else {
115
- // Set or update the toolId entry
116
- const updated = { ...current, [toolId]: mode };
117
- this.preferenceService.updateValue(exports.TOOL_CONFIRMATION_PREFERENCE, updated);
118
- }
119
- }
120
- /**
121
- * Set the confirmation mode for a specific tool for this session only (not persisted, per chat)
122
- */
123
- setSessionConfirmationMode(toolId, mode, chatId) {
124
- let chatMap = this.sessionOverrides.get(chatId);
125
- if (!chatMap) {
126
- chatMap = new Map();
127
- this.sessionOverrides.set(chatId, chatMap);
128
- }
129
- chatMap.set(toolId, mode);
130
- }
131
- /**
132
- * Clear all session overrides for a specific chat, or all if no chatId is given
133
- */
134
- clearSessionOverrides(chatId) {
135
- if (chatId) {
136
- this.sessionOverrides.delete(chatId);
137
- }
138
- else {
139
- this.sessionOverrides.clear();
140
- }
141
- }
142
- /**
143
- * Get all tool confirmation settings
144
- */
145
- getAllConfirmationSettings() {
146
- return this.preferences[exports.TOOL_CONFIRMATION_PREFERENCE] || {};
147
- }
148
- resetAllConfirmationModeSettings() {
149
- const current = this.preferences[exports.TOOL_CONFIRMATION_PREFERENCE] || {};
150
- if ('*' in current) {
151
- this.preferenceService.updateValue(exports.TOOL_CONFIRMATION_PREFERENCE, { '*': current['*'] });
152
- }
153
- else {
154
- this.preferenceService.updateValue(exports.TOOL_CONFIRMATION_PREFERENCE, {});
155
- }
156
- }
157
- };
158
- exports.ToolConfirmationManager = ToolConfirmationManager;
159
- tslib_1.__decorate([
160
- (0, inversify_1.inject)(exports.ChatToolPreferences),
161
- tslib_1.__metadata("design:type", Object)
162
- ], ToolConfirmationManager.prototype, "preferences", void 0);
163
- tslib_1.__decorate([
164
- (0, inversify_1.inject)(preferences_1.PreferenceService),
165
- tslib_1.__metadata("design:type", Object)
166
- ], ToolConfirmationManager.prototype, "preferenceService", void 0);
167
- exports.ToolConfirmationManager = ToolConfirmationManager = tslib_1.__decorate([
168
- (0, inversify_1.injectable)()
169
- ], ToolConfirmationManager);
170
- //# sourceMappingURL=chat-tool-preferences.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chat-tool-preferences.js","sourceRoot":"","sources":["../../src/browser/chat-tool-preferences.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,wFAA2F;AAC3F,sCAAkC;AAClC,4DAA8E;AAC9E,qEAM6C;AAE7C;;GAEG;AACH,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC5B,qDAA6B,CAAA;IAC7B,2CAAmB,CAAA;IACnB,6CAAqB,CAAA;AACzB,CAAC,EAJW,oBAAoB,oCAApB,oBAAoB,QAI/B;AAEY,QAAA,4BAA4B,GAAG,mCAAmC,CAAC;AAEnE,QAAA,mBAAmB,GAAqB;IACjD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,oCAA4B,CAAC,EAAE;YAC5B,IAAI,EAAE,QAAQ;YACd,oBAAoB,EAAE;gBAClB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,oBAAoB,CAAC,YAAY,EAAE,oBAAoB,CAAC,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC;gBACtG,gBAAgB,EAAE;oBACd,UAAG,CAAC,QAAQ,CAAC,iDAAiD,EAAE,kDAAkD,CAAC;oBACnH,UAAG,CAAC,QAAQ,CAAC,oDAAoD,EAAE,6CAA6C,CAAC;oBACjH,UAAG,CAAC,QAAQ,CAAC,qDAAqD,EAAE,wBAAwB,CAAC;iBAChG;aACJ;YACD,OAAO,EAAE,EAAE;YACX,W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