@theia/ai-chat-ui 1.72.1 → 1.72.3

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 (34) hide show
  1. package/lib/browser/ai-chat-ui-frontend-module.d.ts.map +1 -1
  2. package/lib/browser/ai-chat-ui-frontend-module.js +4 -0
  3. package/lib/browser/ai-chat-ui-frontend-module.js.map +1 -1
  4. package/lib/browser/chat-response-renderer/delegation-tool-renderer.d.ts +8 -1
  5. package/lib/browser/chat-response-renderer/delegation-tool-renderer.d.ts.map +1 -1
  6. package/lib/browser/chat-response-renderer/delegation-tool-renderer.js +30 -1
  7. package/lib/browser/chat-response-renderer/delegation-tool-renderer.js.map +1 -1
  8. package/lib/browser/chat-response-renderer/tool-confirmation.d.ts +15 -1
  9. package/lib/browser/chat-response-renderer/tool-confirmation.d.ts.map +1 -1
  10. package/lib/browser/chat-response-renderer/tool-confirmation.js +60 -17
  11. package/lib/browser/chat-response-renderer/tool-confirmation.js.map +1 -1
  12. package/lib/browser/chat-response-renderer/toolcall-part-renderer.d.ts +8 -1
  13. package/lib/browser/chat-response-renderer/toolcall-part-renderer.d.ts.map +1 -1
  14. package/lib/browser/chat-response-renderer/toolcall-part-renderer.js +31 -5
  15. package/lib/browser/chat-response-renderer/toolcall-part-renderer.js.map +1 -1
  16. package/lib/browser/chat-response-renderer/toolcall-part-renderer.spec.js +102 -0
  17. package/lib/browser/chat-response-renderer/toolcall-part-renderer.spec.js.map +1 -1
  18. package/lib/browser/chat-view-widget.d.ts +1 -0
  19. package/lib/browser/chat-view-widget.d.ts.map +1 -1
  20. package/lib/browser/chat-view-widget.js +3 -0
  21. package/lib/browser/chat-view-widget.js.map +1 -1
  22. package/lib/browser/tool-confirmation-keybinding-contribution.d.ts +25 -0
  23. package/lib/browser/tool-confirmation-keybinding-contribution.d.ts.map +1 -0
  24. package/lib/browser/tool-confirmation-keybinding-contribution.js +106 -0
  25. package/lib/browser/tool-confirmation-keybinding-contribution.js.map +1 -0
  26. package/package.json +12 -12
  27. package/src/browser/ai-chat-ui-frontend-module.ts +5 -0
  28. package/src/browser/chat-response-renderer/delegation-tool-renderer.tsx +34 -3
  29. package/src/browser/chat-response-renderer/tool-confirmation.tsx +122 -30
  30. package/src/browser/chat-response-renderer/toolcall-part-renderer.spec.ts +127 -0
  31. package/src/browser/chat-response-renderer/toolcall-part-renderer.tsx +51 -6
  32. package/src/browser/chat-view-widget.tsx +4 -0
  33. package/src/browser/style/index.css +9 -0
  34. package/src/browser/tool-confirmation-keybinding-contribution.ts +104 -0
@@ -0,0 +1,104 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 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 { Command, CommandContribution, CommandRegistry } from '@theia/core';
18
+ import { ApplicationShell, KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
19
+ import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
20
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
21
+ import { PendingToolConfirmation, PendingToolConfirmationTracker } from '@theia/ai-chat/lib/browser/pending-tool-confirmation-tracker';
22
+ import { ChatViewWidget } from './chat-view-widget';
23
+
24
+ export const HAS_PENDING_TOOL_CONFIRMATION_CONTEXT_KEY = 'theiaAi.hasPendingToolConfirmation';
25
+
26
+ /**
27
+ * Only fire the approve/deny shortcuts while the chat view is focused, so e.g. `Ctrl+Enter` in an
28
+ * editor is never shadowed by a confirmation pending in some background chat.
29
+ */
30
+ const CHAT_VIEW_FOCUS_WHEN = '(chatInputFocus || chatResponseFocus)';
31
+
32
+ export const APPROVE_LATEST_TOOL_CONFIRMATION_COMMAND = Command.toLocalizedCommand({
33
+ id: 'theia.ai.chat.approveLatestToolConfirmation',
34
+ label: 'Approve Latest Tool Confirmation'
35
+ }, 'theia/ai/chat-ui/toolconfirmation/approveLatest');
36
+
37
+ export const DENY_LATEST_TOOL_CONFIRMATION_COMMAND = Command.toLocalizedCommand({
38
+ id: 'theia.ai.chat.denyLatestToolConfirmation',
39
+ label: 'Deny Latest Tool Confirmation'
40
+ }, 'theia/ai/chat-ui/toolconfirmation/denyLatest');
41
+
42
+ @injectable()
43
+ export class ToolConfirmationKeybindingContribution implements CommandContribution, KeybindingContribution {
44
+
45
+ @inject(PendingToolConfirmationTracker)
46
+ protected readonly pendingTracker: PendingToolConfirmationTracker;
47
+
48
+ @inject(ContextKeyService)
49
+ protected readonly contextKeyService: ContextKeyService;
50
+
51
+ @inject(ApplicationShell)
52
+ protected readonly shell: ApplicationShell;
53
+
54
+ protected hasPendingKey: ContextKey<boolean>;
55
+
56
+ @postConstruct()
57
+ protected init(): void {
58
+ this.hasPendingKey = this.contextKeyService.createKey<boolean>(HAS_PENDING_TOOL_CONFIRMATION_CONTEXT_KEY, false);
59
+ this.pendingTracker.onChanged(() => this.hasPendingKey.set(this.pendingTracker.hasPending()));
60
+ }
61
+
62
+ registerCommands(commands: CommandRegistry): void {
63
+ commands.registerCommand(APPROVE_LATEST_TOOL_CONFIRMATION_COMMAND, {
64
+ isEnabled: () => this.hasPendingInActiveChat(),
65
+ execute: () => this.getLatestInActiveChat()?.allow()
66
+ });
67
+ commands.registerCommand(DENY_LATEST_TOOL_CONFIRMATION_COMMAND, {
68
+ isEnabled: () => this.hasPendingInActiveChat(),
69
+ execute: () => this.getLatestInActiveChat()?.deny()
70
+ });
71
+ }
72
+
73
+ registerKeybindings(keybindings: KeybindingRegistry): void {
74
+ keybindings.registerKeybinding({
75
+ command: APPROVE_LATEST_TOOL_CONFIRMATION_COMMAND.id,
76
+ keybinding: 'ctrlcmd+enter',
77
+ when: `${HAS_PENDING_TOOL_CONFIRMATION_CONTEXT_KEY} && ${CHAT_VIEW_FOCUS_WHEN}`
78
+ });
79
+ keybindings.registerKeybinding({
80
+ command: DENY_LATEST_TOOL_CONFIRMATION_COMMAND.id,
81
+ keybinding: 'ctrlcmd+shift+backspace',
82
+ when: `${HAS_PENDING_TOOL_CONFIRMATION_CONTEXT_KEY} && ${CHAT_VIEW_FOCUS_WHEN}`
83
+ });
84
+ }
85
+
86
+ /**
87
+ * The id of the chat the user is currently interacting with, or `undefined` if no chat view is
88
+ * focused. Used to target the shortcuts at the visible confirmation rather than the globally
89
+ * newest one.
90
+ */
91
+ protected getActiveChatId(): string | undefined {
92
+ return ChatViewWidget.findActive(this.shell)?.sessionId;
93
+ }
94
+
95
+ protected hasPendingInActiveChat(): boolean {
96
+ const chatId = this.getActiveChatId();
97
+ return chatId !== undefined && this.pendingTracker.hasPending(chatId);
98
+ }
99
+
100
+ protected getLatestInActiveChat(): PendingToolConfirmation | undefined {
101
+ const chatId = this.getActiveChatId();
102
+ return chatId === undefined ? undefined : this.pendingTracker.getLatest(chatId);
103
+ }
104
+ }