tabby-ai-assistant 1.0.13 → 1.0.16
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/.editorconfig +18 -0
- package/README.md +40 -10
- package/dist/index.js +1 -1
- package/package.json +5 -3
- package/src/components/chat/ai-sidebar.component.scss +220 -9
- package/src/components/chat/ai-sidebar.component.ts +379 -29
- package/src/components/chat/chat-input.component.ts +36 -4
- package/src/components/chat/chat-interface.component.ts +225 -5
- package/src/components/chat/chat-message.component.ts +6 -1
- package/src/components/settings/context-settings.component.ts +91 -91
- package/src/components/terminal/ai-toolbar-button.component.ts +4 -2
- package/src/components/terminal/command-suggestion.component.ts +148 -6
- package/src/index.ts +81 -19
- package/src/providers/tabby/ai-toolbar-button.provider.ts +7 -3
- package/src/services/chat/ai-sidebar.service.ts +448 -410
- package/src/services/chat/chat-session.service.ts +36 -12
- package/src/services/context/compaction.ts +110 -134
- package/src/services/context/manager.ts +27 -7
- package/src/services/context/memory.ts +17 -33
- package/src/services/context/summary.service.ts +136 -0
- package/src/services/core/ai-assistant.service.ts +1060 -37
- package/src/services/core/ai-provider-manager.service.ts +154 -25
- package/src/services/core/checkpoint.service.ts +218 -18
- package/src/services/core/toast.service.ts +106 -106
- package/src/services/providers/anthropic-provider.service.ts +126 -30
- package/src/services/providers/base-provider.service.ts +90 -7
- package/src/services/providers/glm-provider.service.ts +151 -38
- package/src/services/providers/minimax-provider.service.ts +55 -40
- package/src/services/providers/ollama-provider.service.ts +117 -28
- package/src/services/providers/openai-compatible.service.ts +164 -34
- package/src/services/providers/openai-provider.service.ts +169 -34
- package/src/services/providers/vllm-provider.service.ts +116 -28
- package/src/services/terminal/terminal-context.service.ts +265 -5
- package/src/services/terminal/terminal-manager.service.ts +845 -748
- package/src/services/terminal/terminal-tools.service.ts +612 -441
- package/src/types/ai.types.ts +156 -3
- package/src/utils/cost.utils.ts +249 -0
- package/src/utils/validation.utils.ts +306 -2
- package/dist/index.js.LICENSE.txt +0 -18
- package/src/services/terminal/command-analyzer.service.ts +0 -43
- package/src/services/terminal/context-menu.service.ts +0 -45
- package/src/services/terminal/hotkey.service.ts +0 -53
package/src/index.ts
CHANGED
|
@@ -43,9 +43,6 @@ import { CommandGeneratorService } from './services/chat/command-generator.servi
|
|
|
43
43
|
import { AiSidebarService } from './services/chat/ai-sidebar.service';
|
|
44
44
|
|
|
45
45
|
// Terminal Services
|
|
46
|
-
import { CommandAnalyzerService } from './services/terminal/command-analyzer.service';
|
|
47
|
-
import { ContextMenuService } from './services/terminal/context-menu.service';
|
|
48
|
-
import { HotkeyService } from './services/terminal/hotkey.service';
|
|
49
46
|
import { TerminalManagerService } from './services/terminal/terminal-manager.service';
|
|
50
47
|
|
|
51
48
|
// Context Engineering Services
|
|
@@ -136,9 +133,6 @@ import { AiHotkeyProvider } from './providers/tabby/ai-hotkey.provider';
|
|
|
136
133
|
AiSidebarService,
|
|
137
134
|
|
|
138
135
|
// Terminal Services
|
|
139
|
-
CommandAnalyzerService,
|
|
140
|
-
ContextMenuService,
|
|
141
|
-
HotkeyService,
|
|
142
136
|
TerminalManagerService,
|
|
143
137
|
|
|
144
138
|
// Context Engineering Services
|
|
@@ -210,6 +204,7 @@ export default class AiAssistantModule {
|
|
|
210
204
|
private config: ConfigService,
|
|
211
205
|
private aiService: AiAssistantService,
|
|
212
206
|
private sidebarService: AiSidebarService,
|
|
207
|
+
private terminalManager: TerminalManagerService,
|
|
213
208
|
hotkeys: HotkeysService
|
|
214
209
|
) {
|
|
215
210
|
console.log('[AiAssistantModule] Module initialized');
|
|
@@ -230,21 +225,88 @@ export default class AiAssistantModule {
|
|
|
230
225
|
|
|
231
226
|
// 订阅热键事件
|
|
232
227
|
hotkeys.hotkey$.subscribe(hotkey => {
|
|
233
|
-
|
|
234
|
-
this.sidebarService.toggle();
|
|
235
|
-
} else if (hotkey === 'ai-command-generation') {
|
|
236
|
-
// 打开侧边栏并聚焦输入
|
|
237
|
-
if (!this.sidebarService.sidebarVisible) {
|
|
238
|
-
this.sidebarService.show();
|
|
239
|
-
}
|
|
240
|
-
} else if (hotkey === 'ai-explain-command') {
|
|
241
|
-
// 打开侧边栏
|
|
242
|
-
if (!this.sidebarService.sidebarVisible) {
|
|
243
|
-
this.sidebarService.show();
|
|
244
|
-
}
|
|
245
|
-
}
|
|
228
|
+
this.handleHotkey(hotkey);
|
|
246
229
|
});
|
|
247
230
|
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 处理热键事件
|
|
234
|
+
*/
|
|
235
|
+
private handleHotkey(hotkey: string): void {
|
|
236
|
+
switch (hotkey) {
|
|
237
|
+
case 'ai-assistant-toggle':
|
|
238
|
+
this.sidebarService.toggle();
|
|
239
|
+
break;
|
|
240
|
+
|
|
241
|
+
case 'ai-command-generation':
|
|
242
|
+
this.handleCommandGeneration();
|
|
243
|
+
break;
|
|
244
|
+
|
|
245
|
+
case 'ai-explain-command':
|
|
246
|
+
this.handleExplainCommand();
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 处理命令生成快捷键 (Ctrl+Shift+G)
|
|
253
|
+
* 1. 尝试获取选中文本
|
|
254
|
+
* 2. 尝试获取最后一条命令
|
|
255
|
+
* 3. 获取终端上下文
|
|
256
|
+
* 4. 构建提示并发送
|
|
257
|
+
*/
|
|
258
|
+
private handleCommandGeneration(): void {
|
|
259
|
+
// 1. 尝试获取选中文本
|
|
260
|
+
const selectedText = this.terminalManager.getSelectedText();
|
|
261
|
+
|
|
262
|
+
// 2. 尝试获取最后一条命令
|
|
263
|
+
const lastCommand = this.terminalManager.getLastCommand();
|
|
264
|
+
|
|
265
|
+
// 3. 获取终端上下文
|
|
266
|
+
const context = this.terminalManager.getRecentContext();
|
|
267
|
+
|
|
268
|
+
// 4. 构建提示
|
|
269
|
+
let prompt: string;
|
|
270
|
+
if (selectedText) {
|
|
271
|
+
prompt = `请帮我优化或改进这个命令:\n\`\`\`\n${selectedText}\n\`\`\``;
|
|
272
|
+
} else if (lastCommand) {
|
|
273
|
+
prompt = `基于当前终端状态,请帮我生成下一步需要的命令。\n\n最近执行的命令: ${lastCommand}\n\n终端上下文:\n\`\`\`\n${context}\n\`\`\``;
|
|
274
|
+
} else {
|
|
275
|
+
prompt = `请根据当前终端状态帮我生成需要的命令。\n\n终端上下文:\n\`\`\`\n${context}\n\`\`\``;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// 5. 发送消息(自动发送)
|
|
279
|
+
this.sidebarService.sendPresetMessage(prompt, true);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 处理命令解释快捷键 (Ctrl+Shift+E)
|
|
284
|
+
* 1. 尝试获取选中文本
|
|
285
|
+
* 2. 尝试获取最后一条命令
|
|
286
|
+
* 3. 构建提示并发送
|
|
287
|
+
*/
|
|
288
|
+
private handleExplainCommand(): void {
|
|
289
|
+
// 1. 尝试获取选中文本
|
|
290
|
+
const selectedText = this.terminalManager.getSelectedText();
|
|
291
|
+
|
|
292
|
+
// 2. 尝试获取最后一条命令
|
|
293
|
+
const lastCommand = this.terminalManager.getLastCommand();
|
|
294
|
+
|
|
295
|
+
// 3. 构建提示
|
|
296
|
+
let prompt: string;
|
|
297
|
+
if (selectedText) {
|
|
298
|
+
prompt = `请详细解释这个命令的作用和每个参数的含义:\n\`\`\`\n${selectedText}\n\`\`\``;
|
|
299
|
+
} else if (lastCommand) {
|
|
300
|
+
prompt = `请详细解释这个命令的作用和每个参数的含义:\n\`\`\`\n${lastCommand}\n\`\`\``;
|
|
301
|
+
} else {
|
|
302
|
+
// 读取更多上下文让用户选择
|
|
303
|
+
const context = this.terminalManager.getRecentContext();
|
|
304
|
+
prompt = `请解释最近的终端输出内容:\n\`\`\`\n${context}\n\`\`\``;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// 4. 发送消息(自动发送)
|
|
308
|
+
this.sidebarService.sendPresetMessage(prompt, true);
|
|
309
|
+
}
|
|
248
310
|
}
|
|
249
311
|
|
|
250
312
|
export const forRoot = (): typeof AiAssistantModule => {
|
|
@@ -45,10 +45,14 @@ export class AiToolbarButtonProvider extends ToolbarButtonProvider {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* 打开设置页面
|
|
48
|
+
* 注意:设置页面通过 Tabby 设置菜单访问,用户可手动导航到"AI 助手"设置
|
|
48
49
|
*/
|
|
49
50
|
private openSettings(): void {
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
|
|
51
|
+
// 提示用户通过 Tabby 设置访问
|
|
52
|
+
// 设置标签页 ID 为 'ai-assistant'
|
|
53
|
+
this.app.openNewTab({
|
|
54
|
+
type: 'settings' as any,
|
|
55
|
+
inputs: { focusSection: 'ai-assistant' }
|
|
56
|
+
});
|
|
53
57
|
}
|
|
54
58
|
}
|