tabby-ai-assistant 1.0.4 → 1.0.6

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 (117) hide show
  1. package/dist/components/chat/ai-sidebar.component.d.ts +147 -0
  2. package/dist/components/chat/chat-interface.component.d.ts +38 -6
  3. package/dist/components/settings/general-settings.component.d.ts +6 -3
  4. package/dist/components/settings/provider-config.component.d.ts +25 -12
  5. package/dist/components/terminal/command-preview.component.d.ts +38 -0
  6. package/dist/index-full.d.ts +8 -0
  7. package/dist/index-minimal.d.ts +3 -0
  8. package/dist/index.d.ts +7 -3
  9. package/dist/index.js +1 -2
  10. package/dist/providers/tabby/ai-config.provider.d.ts +57 -5
  11. package/dist/providers/tabby/ai-hotkey.provider.d.ts +8 -14
  12. package/dist/providers/tabby/ai-toolbar-button.provider.d.ts +8 -9
  13. package/dist/services/chat/ai-sidebar.service.d.ts +89 -0
  14. package/dist/services/chat/chat-history.service.d.ts +78 -0
  15. package/dist/services/chat/chat-session.service.d.ts +57 -2
  16. package/dist/services/context/compaction.d.ts +90 -0
  17. package/dist/services/context/manager.d.ts +69 -0
  18. package/dist/services/context/memory.d.ts +116 -0
  19. package/dist/services/context/token-budget.d.ts +105 -0
  20. package/dist/services/core/ai-assistant.service.d.ts +40 -1
  21. package/dist/services/core/checkpoint.service.d.ts +130 -0
  22. package/dist/services/platform/escape-sequence.service.d.ts +132 -0
  23. package/dist/services/platform/platform-detection.service.d.ts +146 -0
  24. package/dist/services/providers/anthropic-provider.service.d.ts +5 -0
  25. package/dist/services/providers/base-provider.service.d.ts +6 -1
  26. package/dist/services/providers/glm-provider.service.d.ts +5 -0
  27. package/dist/services/providers/minimax-provider.service.d.ts +10 -1
  28. package/dist/services/providers/ollama-provider.service.d.ts +76 -0
  29. package/dist/services/providers/openai-compatible.service.d.ts +5 -0
  30. package/dist/services/providers/openai-provider.service.d.ts +5 -0
  31. package/dist/services/providers/vllm-provider.service.d.ts +82 -0
  32. package/dist/services/terminal/buffer-analyzer.service.d.ts +128 -0
  33. package/dist/services/terminal/terminal-manager.service.d.ts +185 -0
  34. package/dist/services/terminal/terminal-tools.service.d.ts +79 -0
  35. package/dist/types/ai.types.d.ts +92 -0
  36. package/dist/types/provider.types.d.ts +1 -1
  37. package/package.json +7 -10
  38. package/src/components/chat/ai-sidebar.component.ts +945 -0
  39. package/src/components/chat/chat-input.component.html +9 -24
  40. package/src/components/chat/chat-input.component.scss +3 -2
  41. package/src/components/chat/chat-interface.component.html +77 -69
  42. package/src/components/chat/chat-interface.component.scss +54 -4
  43. package/src/components/chat/chat-interface.component.ts +250 -34
  44. package/src/components/chat/chat-settings.component.scss +4 -4
  45. package/src/components/chat/chat-settings.component.ts +22 -11
  46. package/src/components/common/error-message.component.html +15 -0
  47. package/src/components/common/error-message.component.scss +77 -0
  48. package/src/components/common/error-message.component.ts +2 -96
  49. package/src/components/common/loading-spinner.component.html +4 -0
  50. package/src/components/common/loading-spinner.component.scss +57 -0
  51. package/src/components/common/loading-spinner.component.ts +2 -63
  52. package/src/components/security/consent-dialog.component.html +22 -0
  53. package/src/components/security/consent-dialog.component.scss +34 -0
  54. package/src/components/security/consent-dialog.component.ts +2 -55
  55. package/src/components/security/password-prompt.component.html +19 -0
  56. package/src/components/security/password-prompt.component.scss +30 -0
  57. package/src/components/security/password-prompt.component.ts +2 -54
  58. package/src/components/security/risk-confirm-dialog.component.html +8 -12
  59. package/src/components/security/risk-confirm-dialog.component.scss +8 -5
  60. package/src/components/security/risk-confirm-dialog.component.ts +6 -6
  61. package/src/components/settings/ai-settings-tab.component.html +16 -20
  62. package/src/components/settings/ai-settings-tab.component.scss +8 -5
  63. package/src/components/settings/ai-settings-tab.component.ts +12 -12
  64. package/src/components/settings/general-settings.component.html +8 -17
  65. package/src/components/settings/general-settings.component.scss +6 -3
  66. package/src/components/settings/general-settings.component.ts +62 -22
  67. package/src/components/settings/provider-config.component.html +19 -39
  68. package/src/components/settings/provider-config.component.scss +182 -39
  69. package/src/components/settings/provider-config.component.ts +119 -7
  70. package/src/components/settings/security-settings.component.scss +1 -1
  71. package/src/components/terminal/ai-toolbar-button.component.html +8 -0
  72. package/src/components/terminal/ai-toolbar-button.component.scss +20 -0
  73. package/src/components/terminal/ai-toolbar-button.component.ts +2 -30
  74. package/src/components/terminal/command-preview.component.html +61 -0
  75. package/src/components/terminal/command-preview.component.scss +72 -0
  76. package/src/components/terminal/command-preview.component.ts +127 -140
  77. package/src/components/terminal/command-suggestion.component.html +23 -0
  78. package/src/components/terminal/command-suggestion.component.scss +55 -0
  79. package/src/components/terminal/command-suggestion.component.ts +2 -77
  80. package/src/index-minimal.ts +32 -0
  81. package/src/index.ts +94 -11
  82. package/src/index.ts.backup +165 -0
  83. package/src/providers/tabby/ai-config.provider.ts +60 -51
  84. package/src/providers/tabby/ai-hotkey.provider.ts +23 -39
  85. package/src/providers/tabby/ai-settings-tab.provider.ts +2 -2
  86. package/src/providers/tabby/ai-toolbar-button.provider.ts +29 -24
  87. package/src/services/chat/ai-sidebar.service.ts +258 -0
  88. package/src/services/chat/chat-history.service.ts +308 -0
  89. package/src/services/chat/chat-history.service.ts.backup +239 -0
  90. package/src/services/chat/chat-session.service.ts +276 -3
  91. package/src/services/context/compaction.ts +483 -0
  92. package/src/services/context/manager.ts +442 -0
  93. package/src/services/context/memory.ts +519 -0
  94. package/src/services/context/token-budget.ts +422 -0
  95. package/src/services/core/ai-assistant.service.ts +280 -5
  96. package/src/services/core/ai-provider-manager.service.ts +2 -2
  97. package/src/services/core/checkpoint.service.ts +619 -0
  98. package/src/services/platform/escape-sequence.service.ts +499 -0
  99. package/src/services/platform/platform-detection.service.ts +494 -0
  100. package/src/services/providers/anthropic-provider.service.ts +28 -1
  101. package/src/services/providers/base-provider.service.ts +7 -1
  102. package/src/services/providers/glm-provider.service.ts +28 -1
  103. package/src/services/providers/minimax-provider.service.ts +209 -11
  104. package/src/services/providers/ollama-provider.service.ts +445 -0
  105. package/src/services/providers/openai-compatible.service.ts +9 -0
  106. package/src/services/providers/openai-provider.service.ts +9 -0
  107. package/src/services/providers/vllm-provider.service.ts +463 -0
  108. package/src/services/security/risk-assessment.service.ts +6 -2
  109. package/src/services/terminal/buffer-analyzer.service.ts +594 -0
  110. package/src/services/terminal/terminal-manager.service.ts +748 -0
  111. package/src/services/terminal/terminal-tools.service.ts +441 -0
  112. package/src/styles/ai-assistant.scss +78 -6
  113. package/src/types/ai.types.ts +144 -0
  114. package/src/types/provider.types.ts +1 -1
  115. package/src/utils/encryption.utils.ts +18 -8
  116. package/tsconfig.json +9 -9
  117. package/webpack.config.js +28 -6
@@ -26,6 +26,8 @@ export interface ChatRequest {
26
26
  temperature?: number;
27
27
  stream?: boolean;
28
28
  model?: string;
29
+ tools?: any[]; // 工具定义列表
30
+ enableTools?: boolean; // 是否启用工具调用
29
31
  }
30
32
 
31
33
  // 聊天响应
@@ -131,3 +133,145 @@ export interface ValidationResult {
131
133
  errors?: string[];
132
134
  warnings?: string[];
133
135
  }
136
+
137
+ // ============================================================================
138
+ // 上下文工程相关类型定义
139
+ // ============================================================================
140
+
141
+ // API消息接口(支持压缩标记)
142
+ export interface ApiMessage {
143
+ role: 'user' | 'assistant' | 'system';
144
+ content: string | ContentBlock[];
145
+ ts: number; // 时间戳(毫秒)
146
+
147
+ // 压缩相关元数据
148
+ isSummary?: boolean; // 是否为摘要消息
149
+ condenseId?: string; // 摘要ID
150
+ condenseParent?: string; // 被哪个摘要压缩
151
+
152
+ // 截断相关元数据
153
+ isTruncationMarker?: boolean; // 是否为截断标记
154
+ truncationId?: string; // 截断ID
155
+ truncationParent?: string; // 被哪个截断隐藏
156
+ }
157
+
158
+ // 内容块类型(用于支持工具调用)
159
+ export interface ContentBlock {
160
+ type: 'text' | 'tool_use' | 'tool_result';
161
+ text?: string;
162
+ id?: string;
163
+ name?: string;
164
+ input?: Record<string, any>;
165
+ tool_use_id?: string;
166
+ content?: string;
167
+ }
168
+
169
+ // Token使用统计
170
+ export interface TokenUsage {
171
+ input: number; // 输入token数
172
+ output: number; // 输出token数
173
+ cacheRead: number; // 缓存读取token数
174
+ cacheWrite: number; // 缓存写入token数
175
+ }
176
+
177
+ // 会话状态
178
+ export interface SessionState {
179
+ id: string;
180
+ messages: ApiMessage[];
181
+ tokens: TokenUsage;
182
+ createdAt: number; // 创建时间戳(毫秒)
183
+ updatedAt: number; // 更新时间戳(毫秒)
184
+ checkpoints: string[]; // 检查点ID列表
185
+ }
186
+
187
+ // 上下文管理配置
188
+ export interface ContextConfig {
189
+ maxContextTokens: number; // 最大上下文窗口大小
190
+ reservedOutputTokens: number; // 输出预留token数
191
+ compactThreshold: number; // 压缩触发阈值 (0-1)
192
+ pruneThreshold: number; // 裁剪触发阈值 (0-1)
193
+ messagesToKeep: number; // 保留的最近消息数
194
+ bufferPercentage: number; // 安全缓冲区百分比
195
+ }
196
+
197
+ // 默认配置
198
+ export const DEFAULT_CONTEXT_CONFIG: ContextConfig = {
199
+ maxContextTokens: 200000,
200
+ reservedOutputTokens: 16000,
201
+ compactThreshold: 0.85,
202
+ pruneThreshold: 0.70,
203
+ messagesToKeep: 3,
204
+ bufferPercentage: 0.10
205
+ };
206
+
207
+ // 压缩结果
208
+ export interface CompactionResult {
209
+ success: boolean;
210
+ messages: ApiMessage[];
211
+ summary?: string;
212
+ condenseId?: string;
213
+ tokensSaved: number;
214
+ cost: number; // API调用成本
215
+ error?: string;
216
+ }
217
+
218
+ // 裁剪结果
219
+ export interface PruneResult {
220
+ pruned: boolean;
221
+ tokensSaved: number;
222
+ partsCompacted: number;
223
+ }
224
+
225
+ // 截断结果
226
+ export interface TruncationResult {
227
+ messages: ApiMessage[];
228
+ truncationId: string;
229
+ messagesRemoved: number;
230
+ }
231
+
232
+ // 扩展现有 ChatMessage,添加压缩标记支持
233
+ export interface ExtendedChatMessage extends ChatMessage {
234
+ // 压缩相关元数据(可选)
235
+ isSummary?: boolean; // 是否为摘要消息
236
+ condenseId?: string; // 摘要ID
237
+ condenseParent?: string; // 被哪个摘要压缩
238
+
239
+ // 截断相关元数据(可选)
240
+ isTruncationMarker?: boolean; // 是否为截断标记
241
+ truncationId?: string; // 截断ID
242
+ truncationParent?: string; // 被哪个截断隐藏
243
+
244
+ // Token使用统计(可选)
245
+ tokenUsage?: TokenUsage;
246
+ }
247
+
248
+ // 检查点接口
249
+ export interface Checkpoint {
250
+ id: string;
251
+ sessionId: string;
252
+ messages: ApiMessage[];
253
+ summary: string;
254
+ createdAt: number; // 时间戳(毫秒)
255
+ tokenUsage: TokenUsage;
256
+ }
257
+
258
+ // ============================================================================
259
+ // 流式响应相关类型定义
260
+ // ============================================================================
261
+
262
+ // 流式事件类型
263
+ export interface StreamEvent {
264
+ type: 'text_delta' | 'tool_use_start' | 'tool_use_delta' | 'tool_use_end' | 'message_end' | 'error';
265
+ // 文本增量
266
+ textDelta?: string;
267
+ // 工具调用(完整时才有)
268
+ toolCall?: {
269
+ id: string;
270
+ name: string;
271
+ input: any;
272
+ };
273
+ // 错误信息
274
+ error?: string;
275
+ // 最终消息(message_end 时)
276
+ message?: ChatMessage;
277
+ }
@@ -11,7 +11,7 @@ export { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequ
11
11
 
12
12
  // 认证配置
13
13
  export interface AuthConfig {
14
- type: 'apiKey' | 'bearer' | 'basic' | 'oauth';
14
+ type: 'apiKey' | 'bearer' | 'basic' | 'oauth' | 'none';
15
15
  credentials: Record<string, string>;
16
16
  requiresEncryption?: boolean;
17
17
  }
@@ -26,12 +26,15 @@ export function generateIV(): string {
26
26
  * 使用AES加密字符串
27
27
  */
28
28
  export function encrypt(text: string, key: string): string {
29
- if (!text || !key) {
29
+ if (text === null || text === undefined || key === null || key === undefined) {
30
30
  throw new Error('文本和密钥不能为空');
31
31
  }
32
32
 
33
33
  try {
34
- const encrypted = CryptoJS.AES.encrypt(text, key);
34
+ // 确保输入是字符串
35
+ const strText = String(text);
36
+ const strKey = String(key);
37
+ const encrypted = CryptoJS.AES.encrypt(strText, strKey);
35
38
  return encrypted.toString();
36
39
  } catch (error) {
37
40
  throw new Error(`加密失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -42,12 +45,15 @@ export function encrypt(text: string, key: string): string {
42
45
  * 使用AES解密字符串
43
46
  */
44
47
  export function decrypt(encryptedText: string, key: string): string {
45
- if (!encryptedText || !key) {
48
+ if (encryptedText === null || encryptedText === undefined || key === null || key === undefined) {
46
49
  throw new Error('加密文本和密钥不能为空');
47
50
  }
48
51
 
49
52
  try {
50
- const decrypted = CryptoJS.AES.decrypt(encryptedText, key);
53
+ // 确保输入是字符串
54
+ const strEncryptedText = String(encryptedText);
55
+ const strKey = String(key);
56
+ const decrypted = CryptoJS.AES.decrypt(strEncryptedText, strKey);
51
57
  return decrypted.toString(CryptoJS.enc.Utf8);
52
58
  } catch (error) {
53
59
  throw new Error(`解密失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -151,12 +157,14 @@ export function generateToken(length: number = 32): string {
151
157
  * Base64编码
152
158
  */
153
159
  export function base64Encode(text: string): string {
154
- if (!text) {
160
+ if (text === null || text === undefined) {
155
161
  throw new Error('文本不能为空');
156
162
  }
157
163
 
158
164
  try {
159
- return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text));
165
+ // 确保输入是字符串
166
+ const str = String(text);
167
+ return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(str));
160
168
  } catch (error) {
161
169
  throw new Error(`Base64编码失败: ${error instanceof Error ? error.message : String(error)}`);
162
170
  }
@@ -166,12 +174,14 @@ export function base64Encode(text: string): string {
166
174
  * Base64解码
167
175
  */
168
176
  export function base64Decode(encodedText: string): string {
169
- if (!encodedText) {
177
+ if (encodedText === null || encodedText === undefined) {
170
178
  throw new Error('编码文本不能为空');
171
179
  }
172
180
 
173
181
  try {
174
- return CryptoJS.enc.Base64.parse(encodedText).toString(CryptoJS.enc.Utf8);
182
+ // 确保输入是字符串
183
+ const str = String(encodedText);
184
+ return CryptoJS.enc.Base64.parse(str).toString(CryptoJS.enc.Utf8);
175
185
  } catch (error) {
176
186
  throw new Error(`Base64解码失败: ${error instanceof Error ? error.message : String(error)}`);
177
187
  }
package/tsconfig.json CHANGED
@@ -6,20 +6,20 @@
6
6
  "declaration": true,
7
7
  "outDir": "./dist",
8
8
  "rootDir": "./src",
9
- "strict": false,
9
+ "strict": true,
10
10
  "esModuleInterop": true,
11
11
  "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": false,
12
+ "forceConsistentCasingInFileNames": true,
13
13
  "noImplicitAny": false,
14
- "noImplicitReturns": false,
15
- "noImplicitThis": false,
14
+ "noImplicitReturns": true,
15
+ "noImplicitThis": true,
16
16
  "noUnusedLocals": false,
17
17
  "noUnusedParameters": false,
18
- "strictNullChecks": false,
19
- "strictFunctionTypes": false,
20
- "strictBindCallApply": false,
21
- "strictPropertyInitialization": false,
22
- "noFallthroughCasesInSwitch": false,
18
+ "strictNullChecks": true,
19
+ "strictFunctionTypes": true,
20
+ "strictBindCallApply": true,
21
+ "strictPropertyInitialization": true,
22
+ "noFallthroughCasesInSwitch": true,
23
23
  "moduleResolution": "node",
24
24
  "experimentalDecorators": true,
25
25
  "emitDecoratorMetadata": true,
package/webpack.config.js CHANGED
@@ -2,14 +2,14 @@ const path = require('path');
2
2
  const webpack = require('webpack');
3
3
 
4
4
  module.exports = {
5
- mode: 'production',
5
+ target: 'node',
6
+ mode: 'development',
7
+ devtool: 'eval-source-map',
6
8
  entry: './src/index.ts',
7
9
  output: {
8
10
  path: path.resolve(__dirname, 'dist'),
9
11
  filename: 'index.js',
10
- library: 'AiAssistantModule',
11
12
  libraryTarget: 'commonjs2',
12
- libraryExport: 'default',
13
13
  devtoolModuleFilenameTemplate: 'webpack-tabby-ai-assistant:///[resource-path]',
14
14
  },
15
15
  resolve: {
@@ -36,8 +36,30 @@ module.exports = {
36
36
  exclude: /node_modules/
37
37
  },
38
38
  {
39
- test: /\.(html|css|scss)$/,
40
- use: ['raw-loader']
39
+ test: /\.html$/,
40
+ use: {
41
+ loader: 'raw-loader',
42
+ options: {
43
+ esModule: false
44
+ }
45
+ }
46
+ },
47
+ {
48
+ test: /\.scss$/,
49
+ use: [
50
+ 'to-string-loader',
51
+ 'css-loader',
52
+ 'sass-loader',
53
+ ],
54
+ },
55
+ {
56
+ test: /\.css$/,
57
+ use: {
58
+ loader: 'raw-loader',
59
+ options: {
60
+ esModule: false
61
+ }
62
+ }
41
63
  }
42
64
  ]
43
65
  },
@@ -53,7 +75,7 @@ module.exports = {
53
75
  ],
54
76
  plugins: [
55
77
  new webpack.DefinePlugin({
56
- 'process.env.NODE_ENV': JSON.stringify('production')
78
+ 'process.env.NODE_ENV': JSON.stringify('development')
57
79
  })
58
80
  ]
59
81
  };