tabby-ai-assistant 1.0.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.
- package/README.md +232 -0
- package/dist/components/chat/chat-input.component.d.ts +65 -0
- package/dist/components/chat/chat-interface.component.d.ts +71 -0
- package/dist/components/chat/chat-message.component.d.ts +53 -0
- package/dist/components/chat/chat-settings.component.d.ts +62 -0
- package/dist/components/common/error-message.component.d.ts +11 -0
- package/dist/components/common/loading-spinner.component.d.ts +4 -0
- package/dist/components/security/consent-dialog.component.d.ts +11 -0
- package/dist/components/security/password-prompt.component.d.ts +10 -0
- package/dist/components/security/risk-confirm-dialog.component.d.ts +36 -0
- package/dist/components/settings/ai-settings-tab.component.d.ts +72 -0
- package/dist/components/settings/general-settings.component.d.ts +60 -0
- package/dist/components/settings/provider-config.component.d.ts +182 -0
- package/dist/components/settings/security-settings.component.d.ts +23 -0
- package/dist/components/terminal/ai-toolbar-button.component.d.ts +10 -0
- package/dist/components/terminal/command-preview.component.d.ts +15 -0
- package/dist/components/terminal/command-suggestion.component.d.ts +16 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +18 -0
- package/dist/main.d.ts +8 -0
- package/dist/providers/tabby/ai-config.provider.d.ts +18 -0
- package/dist/providers/tabby/ai-hotkey.provider.d.ts +21 -0
- package/dist/providers/tabby/ai-settings-tab.provider.d.ts +11 -0
- package/dist/providers/tabby/ai-toolbar-button.provider.d.ts +17 -0
- package/dist/services/chat/chat-history.service.d.ts +67 -0
- package/dist/services/chat/chat-session.service.d.ts +58 -0
- package/dist/services/chat/command-generator.service.d.ts +49 -0
- package/dist/services/core/ai-assistant.service.d.ts +88 -0
- package/dist/services/core/ai-provider-manager.service.d.ts +119 -0
- package/dist/services/core/config-provider.service.d.ts +137 -0
- package/dist/services/core/logger.service.d.ts +21 -0
- package/dist/services/providers/anthropic-provider.service.d.ts +39 -0
- package/dist/services/providers/base-provider.service.d.ts +137 -0
- package/dist/services/providers/glm-provider.service.d.ts +91 -0
- package/dist/services/providers/minimax-provider.service.d.ts +93 -0
- package/dist/services/providers/openai-compatible.service.d.ts +39 -0
- package/dist/services/providers/openai-provider.service.d.ts +38 -0
- package/dist/services/security/consent-manager.service.d.ts +65 -0
- package/dist/services/security/password-manager.service.d.ts +67 -0
- package/dist/services/security/risk-assessment.service.d.ts +65 -0
- package/dist/services/security/security-validator.service.d.ts +36 -0
- package/dist/services/terminal/command-analyzer.service.d.ts +20 -0
- package/dist/services/terminal/context-menu.service.d.ts +24 -0
- package/dist/services/terminal/hotkey.service.d.ts +28 -0
- package/dist/services/terminal/terminal-context.service.d.ts +100 -0
- package/dist/types/ai.types.d.ts +107 -0
- package/dist/types/provider.types.d.ts +105 -0
- package/dist/types/security.types.d.ts +85 -0
- package/dist/types/terminal.types.d.ts +150 -0
- package/dist/utils/encryption.utils.d.ts +83 -0
- package/dist/utils/formatting.utils.d.ts +106 -0
- package/dist/utils/validation.utils.d.ts +83 -0
- package/integration-test-output.txt +50 -0
- package/integration-tests/api-integration.test.ts +183 -0
- package/jest.config.js +47 -0
- package/package.json +73 -0
- package/setup-jest.ts +37 -0
- package/src/components/chat/chat-input.component.html +61 -0
- package/src/components/chat/chat-input.component.scss +183 -0
- package/src/components/chat/chat-input.component.ts +149 -0
- package/src/components/chat/chat-interface.component.html +119 -0
- package/src/components/chat/chat-interface.component.scss +354 -0
- package/src/components/chat/chat-interface.component.ts +224 -0
- package/src/components/chat/chat-message.component.html +65 -0
- package/src/components/chat/chat-message.component.scss +178 -0
- package/src/components/chat/chat-message.component.ts +93 -0
- package/src/components/chat/chat-settings.component.html +132 -0
- package/src/components/chat/chat-settings.component.scss +172 -0
- package/src/components/chat/chat-settings.component.ts +168 -0
- package/src/components/common/error-message.component.ts +124 -0
- package/src/components/common/loading-spinner.component.ts +72 -0
- package/src/components/security/consent-dialog.component.ts +77 -0
- package/src/components/security/password-prompt.component.ts +79 -0
- package/src/components/security/risk-confirm-dialog.component.html +87 -0
- package/src/components/security/risk-confirm-dialog.component.scss +360 -0
- package/src/components/security/risk-confirm-dialog.component.ts +96 -0
- package/src/components/settings/ai-settings-tab.component.html +140 -0
- package/src/components/settings/ai-settings-tab.component.scss +371 -0
- package/src/components/settings/ai-settings-tab.component.ts +193 -0
- package/src/components/settings/general-settings.component.html +103 -0
- package/src/components/settings/general-settings.component.scss +285 -0
- package/src/components/settings/general-settings.component.ts +123 -0
- package/src/components/settings/provider-config.component.html +95 -0
- package/src/components/settings/provider-config.component.scss +60 -0
- package/src/components/settings/provider-config.component.ts +206 -0
- package/src/components/settings/security-settings.component.html +51 -0
- package/src/components/settings/security-settings.component.scss +66 -0
- package/src/components/settings/security-settings.component.ts +71 -0
- package/src/components/terminal/ai-toolbar-button.component.ts +49 -0
- package/src/components/terminal/command-preview.component.ts +185 -0
- package/src/components/terminal/command-suggestion.component.ts +128 -0
- package/src/index.ts +163 -0
- package/src/main.ts +16 -0
- package/src/providers/tabby/ai-config.provider.ts +70 -0
- package/src/providers/tabby/ai-hotkey.provider.ts +55 -0
- package/src/providers/tabby/ai-settings-tab.provider.ts +18 -0
- package/src/providers/tabby/ai-toolbar-button.provider.ts +49 -0
- package/src/services/chat/chat-history.service.ts +239 -0
- package/src/services/chat/chat-session.service.spec.ts +249 -0
- package/src/services/chat/chat-session.service.ts +180 -0
- package/src/services/chat/command-generator.service.ts +301 -0
- package/src/services/core/ai-assistant.service.ts +334 -0
- package/src/services/core/ai-provider-manager.service.ts +314 -0
- package/src/services/core/config-provider.service.ts +347 -0
- package/src/services/core/logger.service.ts +104 -0
- package/src/services/providers/anthropic-provider.service.ts +373 -0
- package/src/services/providers/base-provider.service.ts +369 -0
- package/src/services/providers/glm-provider.service.ts +467 -0
- package/src/services/providers/minimax-provider.service.ts +427 -0
- package/src/services/providers/openai-compatible.service.ts +394 -0
- package/src/services/providers/openai-provider.service.ts +376 -0
- package/src/services/security/consent-manager.service.ts +332 -0
- package/src/services/security/password-manager.service.ts +188 -0
- package/src/services/security/risk-assessment.service.ts +340 -0
- package/src/services/security/security-validator.service.ts +143 -0
- package/src/services/terminal/command-analyzer.service.ts +43 -0
- package/src/services/terminal/context-menu.service.ts +45 -0
- package/src/services/terminal/hotkey.service.ts +53 -0
- package/src/services/terminal/terminal-context.service.ts +317 -0
- package/src/styles/ai-assistant.scss +449 -0
- package/src/types/ai.types.ts +133 -0
- package/src/types/provider.types.ts +147 -0
- package/src/types/security.types.ts +103 -0
- package/src/types/terminal.types.ts +186 -0
- package/src/utils/encryption.utils.spec.ts +250 -0
- package/src/utils/encryption.utils.ts +271 -0
- package/src/utils/formatting.utils.ts +359 -0
- package/src/utils/validation.utils.spec.ts +225 -0
- package/src/utils/validation.utils.ts +314 -0
- package/tsconfig.json +45 -0
- package/webpack-docker.config.js +42 -0
- package/webpack.config.js +59 -0
- package/webpack.config.js.backup +57 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tabby AI Assistant 全局样式
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// 主题颜色
|
|
6
|
+
:root {
|
|
7
|
+
--ai-primary: #007bff;
|
|
8
|
+
--ai-secondary: #6c757d;
|
|
9
|
+
--ai-success: #28a745;
|
|
10
|
+
--ai-warning: #ffc107;
|
|
11
|
+
--ai-danger: #dc3545;
|
|
12
|
+
--ai-info: #17a2b8;
|
|
13
|
+
--ai-light: #f8f9fa;
|
|
14
|
+
--ai-dark: #343a40;
|
|
15
|
+
|
|
16
|
+
// 风险级别颜色
|
|
17
|
+
--ai-risk-low: #28a745;
|
|
18
|
+
--ai-risk-medium: #ffc107;
|
|
19
|
+
--ai-risk-high: #fd7e14;
|
|
20
|
+
--ai-risk-critical: #dc3545;
|
|
21
|
+
|
|
22
|
+
// 聊天消息颜色
|
|
23
|
+
--ai-user-message: #e3f2fd;
|
|
24
|
+
--ai-assistant-message: #f5f5f5;
|
|
25
|
+
--ai-system-message: #fff3cd;
|
|
26
|
+
|
|
27
|
+
// 背景和边框
|
|
28
|
+
--ai-bg-primary: #ffffff;
|
|
29
|
+
--ai-bg-secondary: #f8f9fa;
|
|
30
|
+
--ai-border: #dee2e6;
|
|
31
|
+
--ai-border-radius: 0.375rem;
|
|
32
|
+
--ai-box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 深色主题
|
|
36
|
+
.dark-theme {
|
|
37
|
+
--ai-primary: #4dabf7;
|
|
38
|
+
--ai-secondary: #adb5bd;
|
|
39
|
+
--ai-success: #51cf66;
|
|
40
|
+
--ai-warning: #fcc419;
|
|
41
|
+
--ai-danger: #ff6b6b;
|
|
42
|
+
--ai-info: #22b8cf;
|
|
43
|
+
--ai-light: #343a40;
|
|
44
|
+
--ai-dark: #f8f9fa;
|
|
45
|
+
|
|
46
|
+
--ai-risk-low: #51cf66;
|
|
47
|
+
--ai-risk-medium: #fcc419;
|
|
48
|
+
--ai-risk-high: #ff922b;
|
|
49
|
+
--ai-risk-critical: #ff6b6b;
|
|
50
|
+
|
|
51
|
+
--ai-user-message: #1e3a5f;
|
|
52
|
+
--ai-assistant-message: #2d3748;
|
|
53
|
+
--ai-system-message: #3a3a3a;
|
|
54
|
+
|
|
55
|
+
--ai-bg-primary: #1a1a1a;
|
|
56
|
+
--ai-bg-secondary: #2d2d2d;
|
|
57
|
+
--ai-border: #4a4a4a;
|
|
58
|
+
--ai-box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.3);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 通用样式
|
|
62
|
+
.ai-assistant {
|
|
63
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
64
|
+
font-size: 14px;
|
|
65
|
+
line-height: 1.5;
|
|
66
|
+
color: var(--ai-dark);
|
|
67
|
+
background-color: var(--ai-bg-primary);
|
|
68
|
+
|
|
69
|
+
* {
|
|
70
|
+
box-sizing: border-box;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 容器
|
|
75
|
+
.ai-container {
|
|
76
|
+
width: 100%;
|
|
77
|
+
height: 100%;
|
|
78
|
+
display: flex;
|
|
79
|
+
flex-direction: column;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 头部
|
|
84
|
+
.ai-header {
|
|
85
|
+
padding: 1rem;
|
|
86
|
+
background-color: var(--ai-bg-secondary);
|
|
87
|
+
border-bottom: 1px solid var(--ai-border);
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
justify-content: space-between;
|
|
91
|
+
|
|
92
|
+
.ai-title {
|
|
93
|
+
font-size: 1.125rem;
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
margin: 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.ai-provider-selector {
|
|
99
|
+
display: flex;
|
|
100
|
+
align-items: center;
|
|
101
|
+
gap: 0.5rem;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 内容区域
|
|
106
|
+
.ai-content {
|
|
107
|
+
flex: 1;
|
|
108
|
+
overflow-y: auto;
|
|
109
|
+
padding: 1rem;
|
|
110
|
+
display: flex;
|
|
111
|
+
flex-direction: column;
|
|
112
|
+
gap: 1rem;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 消息
|
|
116
|
+
.ai-message {
|
|
117
|
+
padding: 0.75rem 1rem;
|
|
118
|
+
border-radius: var(--ai-border-radius);
|
|
119
|
+
box-shadow: var(--ai-box-shadow);
|
|
120
|
+
max-width: 85%;
|
|
121
|
+
|
|
122
|
+
&.user {
|
|
123
|
+
align-self: flex-end;
|
|
124
|
+
background-color: var(--ai-user-message);
|
|
125
|
+
border: 1px solid var(--ai-primary);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
&.assistant {
|
|
129
|
+
align-self: flex-start;
|
|
130
|
+
background-color: var(--ai-assistant-message);
|
|
131
|
+
border: 1px solid var(--ai-border);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
&.system {
|
|
135
|
+
align-self: center;
|
|
136
|
+
background-color: var(--ai-system-message);
|
|
137
|
+
border: 1px solid var(--ai-warning);
|
|
138
|
+
font-style: italic;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.message-header {
|
|
142
|
+
font-size: 0.875rem;
|
|
143
|
+
font-weight: 600;
|
|
144
|
+
margin-bottom: 0.5rem;
|
|
145
|
+
opacity: 0.8;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.message-content {
|
|
149
|
+
word-wrap: break-word;
|
|
150
|
+
white-space: pre-wrap;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.message-timestamp {
|
|
154
|
+
font-size: 0.75rem;
|
|
155
|
+
opacity: 0.6;
|
|
156
|
+
margin-top: 0.5rem;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 输入框
|
|
161
|
+
.ai-input-container {
|
|
162
|
+
padding: 1rem;
|
|
163
|
+
background-color: var(--ai-bg-secondary);
|
|
164
|
+
border-top: 1px solid var(--ai-border);
|
|
165
|
+
display: flex;
|
|
166
|
+
gap: 0.5rem;
|
|
167
|
+
align-items: flex-end;
|
|
168
|
+
|
|
169
|
+
.ai-textarea {
|
|
170
|
+
flex: 1;
|
|
171
|
+
min-height: 60px;
|
|
172
|
+
max-height: 200px;
|
|
173
|
+
padding: 0.75rem;
|
|
174
|
+
border: 1px solid var(--ai-border);
|
|
175
|
+
border-radius: var(--ai-border-radius);
|
|
176
|
+
resize: vertical;
|
|
177
|
+
font-family: inherit;
|
|
178
|
+
font-size: 14px;
|
|
179
|
+
line-height: 1.5;
|
|
180
|
+
background-color: var(--ai-bg-primary);
|
|
181
|
+
color: var(--ai-dark);
|
|
182
|
+
|
|
183
|
+
&:focus {
|
|
184
|
+
outline: none;
|
|
185
|
+
border-color: var(--ai-primary);
|
|
186
|
+
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.ai-button {
|
|
191
|
+
padding: 0.75rem 1.5rem;
|
|
192
|
+
border: none;
|
|
193
|
+
border-radius: var(--ai-border-radius);
|
|
194
|
+
background-color: var(--ai-primary);
|
|
195
|
+
color: white;
|
|
196
|
+
font-weight: 500;
|
|
197
|
+
cursor: pointer;
|
|
198
|
+
transition: background-color 0.15s ease-in-out;
|
|
199
|
+
|
|
200
|
+
&:hover {
|
|
201
|
+
background-color: darken(#007bff, 7.5%);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
&:disabled {
|
|
205
|
+
opacity: 0.6;
|
|
206
|
+
cursor: not-allowed;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
&.secondary {
|
|
210
|
+
background-color: var(--ai-secondary);
|
|
211
|
+
|
|
212
|
+
&:hover {
|
|
213
|
+
background-color: darken(#6c757d, 7.5%);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
&.danger {
|
|
218
|
+
background-color: var(--ai-danger);
|
|
219
|
+
|
|
220
|
+
&:hover {
|
|
221
|
+
background-color: darken(#dc3545, 7.5%);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 命令预览
|
|
228
|
+
.ai-command-preview {
|
|
229
|
+
padding: 1rem;
|
|
230
|
+
background-color: var(--ai-bg-secondary);
|
|
231
|
+
border: 1px solid var(--ai-border);
|
|
232
|
+
border-radius: var(--ai-border-radius);
|
|
233
|
+
margin-bottom: 1rem;
|
|
234
|
+
|
|
235
|
+
.command {
|
|
236
|
+
font-family: 'Courier New', Courier, monospace;
|
|
237
|
+
font-size: 0.875rem;
|
|
238
|
+
background-color: var(--ai-bg-primary);
|
|
239
|
+
padding: 0.5rem;
|
|
240
|
+
border-radius: 0.25rem;
|
|
241
|
+
margin: 0.5rem 0;
|
|
242
|
+
word-break: break-all;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.explanation {
|
|
246
|
+
margin: 0.5rem 0;
|
|
247
|
+
opacity: 0.9;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.confidence {
|
|
251
|
+
font-size: 0.875rem;
|
|
252
|
+
color: var(--ai-info);
|
|
253
|
+
margin-top: 0.5rem;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 风险指示器
|
|
258
|
+
.ai-risk-indicator {
|
|
259
|
+
display: inline-flex;
|
|
260
|
+
align-items: center;
|
|
261
|
+
gap: 0.375rem;
|
|
262
|
+
padding: 0.25rem 0.75rem;
|
|
263
|
+
border-radius: 1rem;
|
|
264
|
+
font-size: 0.875rem;
|
|
265
|
+
font-weight: 500;
|
|
266
|
+
|
|
267
|
+
&.low {
|
|
268
|
+
background-color: rgba(40, 167, 69, 0.1);
|
|
269
|
+
color: var(--ai-risk-low);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
&.medium {
|
|
273
|
+
background-color: rgba(255, 193, 7, 0.1);
|
|
274
|
+
color: var(--ai-risk-medium);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
&.high {
|
|
278
|
+
background-color: rgba(253, 126, 20, 0.1);
|
|
279
|
+
color: var(--ai-risk-high);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
&.critical {
|
|
283
|
+
background-color: rgba(220, 53, 69, 0.1);
|
|
284
|
+
color: var(--ai-risk-critical);
|
|
285
|
+
animation: pulse 2s infinite;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.risk-dot {
|
|
289
|
+
width: 8px;
|
|
290
|
+
height: 8px;
|
|
291
|
+
border-radius: 50%;
|
|
292
|
+
background-color: currentColor;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
@keyframes pulse {
|
|
297
|
+
0%, 100% {
|
|
298
|
+
opacity: 1;
|
|
299
|
+
}
|
|
300
|
+
50% {
|
|
301
|
+
opacity: 0.5;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// 设置表单
|
|
306
|
+
.ai-settings {
|
|
307
|
+
.settings-section {
|
|
308
|
+
margin-bottom: 2rem;
|
|
309
|
+
|
|
310
|
+
h3 {
|
|
311
|
+
font-size: 1.125rem;
|
|
312
|
+
font-weight: 600;
|
|
313
|
+
margin-bottom: 1rem;
|
|
314
|
+
padding-bottom: 0.5rem;
|
|
315
|
+
border-bottom: 1px solid var(--ai-border);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.form-group {
|
|
319
|
+
margin-bottom: 1rem;
|
|
320
|
+
|
|
321
|
+
label {
|
|
322
|
+
display: block;
|
|
323
|
+
font-weight: 500;
|
|
324
|
+
margin-bottom: 0.5rem;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.form-control {
|
|
328
|
+
width: 100%;
|
|
329
|
+
padding: 0.5rem;
|
|
330
|
+
border: 1px solid var(--ai-border);
|
|
331
|
+
border-radius: var(--ai-border-radius);
|
|
332
|
+
background-color: var(--ai-bg-primary);
|
|
333
|
+
color: var(--ai-dark);
|
|
334
|
+
|
|
335
|
+
&:focus {
|
|
336
|
+
outline: none;
|
|
337
|
+
border-color: var(--ai-primary);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.form-text {
|
|
342
|
+
font-size: 0.875rem;
|
|
343
|
+
opacity: 0.8;
|
|
344
|
+
margin-top: 0.25rem;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.form-check {
|
|
349
|
+
display: flex;
|
|
350
|
+
align-items: center;
|
|
351
|
+
gap: 0.5rem;
|
|
352
|
+
margin-bottom: 0.5rem;
|
|
353
|
+
|
|
354
|
+
input[type="checkbox"] {
|
|
355
|
+
width: 1rem;
|
|
356
|
+
height: 1rem;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
label {
|
|
360
|
+
margin: 0;
|
|
361
|
+
cursor: pointer;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// 加载动画
|
|
368
|
+
.ai-loading {
|
|
369
|
+
display: inline-flex;
|
|
370
|
+
align-items: center;
|
|
371
|
+
gap: 0.5rem;
|
|
372
|
+
|
|
373
|
+
.spinner {
|
|
374
|
+
width: 16px;
|
|
375
|
+
height: 16px;
|
|
376
|
+
border: 2px solid var(--ai-border);
|
|
377
|
+
border-top-color: var(--ai-primary);
|
|
378
|
+
border-radius: 50%;
|
|
379
|
+
animation: spin 0.8s linear infinite;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
@keyframes spin {
|
|
384
|
+
to {
|
|
385
|
+
transform: rotate(360deg);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// 错误消息
|
|
390
|
+
.ai-error {
|
|
391
|
+
padding: 0.75rem;
|
|
392
|
+
background-color: rgba(220, 53, 69, 0.1);
|
|
393
|
+
border: 1px solid var(--ai-danger);
|
|
394
|
+
border-radius: var(--ai-border-radius);
|
|
395
|
+
color: var(--ai-danger);
|
|
396
|
+
margin: 0.5rem 0;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// 成功消息
|
|
400
|
+
.ai-success {
|
|
401
|
+
padding: 0.75rem;
|
|
402
|
+
background-color: rgba(40, 167, 69, 0.1);
|
|
403
|
+
border: 1px solid var(--ai-success);
|
|
404
|
+
border-radius: var(--ai-border-radius);
|
|
405
|
+
color: var(--ai-success);
|
|
406
|
+
margin: 0.5rem 0;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// 工具提示
|
|
410
|
+
.ai-tooltip {
|
|
411
|
+
position: relative;
|
|
412
|
+
display: inline-block;
|
|
413
|
+
|
|
414
|
+
&:hover::after {
|
|
415
|
+
content: attr(data-tooltip);
|
|
416
|
+
position: absolute;
|
|
417
|
+
bottom: 100%;
|
|
418
|
+
left: 50%;
|
|
419
|
+
transform: translateX(-50%);
|
|
420
|
+
padding: 0.5rem;
|
|
421
|
+
background-color: var(--ai-dark);
|
|
422
|
+
color: var(--ai-light);
|
|
423
|
+
border-radius: var(--ai-border-radius);
|
|
424
|
+
font-size: 0.875rem;
|
|
425
|
+
white-space: nowrap;
|
|
426
|
+
z-index: 1000;
|
|
427
|
+
opacity: 0;
|
|
428
|
+
animation: fadeIn 0.2s ease-in-out forwards;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
@keyframes fadeIn {
|
|
433
|
+
to {
|
|
434
|
+
opacity: 1;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// 响应式设计
|
|
439
|
+
@media (max-width: 768px) {
|
|
440
|
+
.ai-message {
|
|
441
|
+
max-width: 95%;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
.ai-header {
|
|
445
|
+
flex-direction: column;
|
|
446
|
+
align-items: flex-start;
|
|
447
|
+
gap: 0.5rem;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// 消息角色
|
|
6
|
+
export enum MessageRole {
|
|
7
|
+
USER = 'user',
|
|
8
|
+
ASSISTANT = 'assistant',
|
|
9
|
+
SYSTEM = 'system'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 聊天消息
|
|
13
|
+
export interface ChatMessage {
|
|
14
|
+
id: string;
|
|
15
|
+
role: MessageRole;
|
|
16
|
+
content: string;
|
|
17
|
+
timestamp: Date;
|
|
18
|
+
metadata?: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 聊天请求
|
|
22
|
+
export interface ChatRequest {
|
|
23
|
+
messages: ChatMessage[];
|
|
24
|
+
systemPrompt?: string;
|
|
25
|
+
maxTokens?: number;
|
|
26
|
+
temperature?: number;
|
|
27
|
+
stream?: boolean;
|
|
28
|
+
model?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 聊天响应
|
|
32
|
+
export interface ChatResponse {
|
|
33
|
+
message: ChatMessage;
|
|
34
|
+
usage?: {
|
|
35
|
+
promptTokens: number;
|
|
36
|
+
completionTokens: number;
|
|
37
|
+
totalTokens: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 命令请求
|
|
42
|
+
export interface CommandRequest {
|
|
43
|
+
naturalLanguage: string;
|
|
44
|
+
context?: {
|
|
45
|
+
currentDirectory?: string;
|
|
46
|
+
operatingSystem?: string;
|
|
47
|
+
shell?: string;
|
|
48
|
+
environment?: Record<string, string>;
|
|
49
|
+
};
|
|
50
|
+
constraints?: {
|
|
51
|
+
maxLength?: number;
|
|
52
|
+
allowedCommands?: string[];
|
|
53
|
+
forbiddenCommands?: string[];
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 命令响应
|
|
58
|
+
export interface CommandResponse {
|
|
59
|
+
command: string;
|
|
60
|
+
explanation: string;
|
|
61
|
+
confidence: number; // 0-1
|
|
62
|
+
alternatives?: {
|
|
63
|
+
command: string;
|
|
64
|
+
explanation: string;
|
|
65
|
+
confidence: number;
|
|
66
|
+
}[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 解释请求
|
|
70
|
+
export interface ExplainRequest {
|
|
71
|
+
command: string;
|
|
72
|
+
context?: {
|
|
73
|
+
currentDirectory?: string;
|
|
74
|
+
operatingSystem?: string;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 解释响应
|
|
79
|
+
export interface ExplainResponse {
|
|
80
|
+
explanation: string;
|
|
81
|
+
breakdown: {
|
|
82
|
+
part: string;
|
|
83
|
+
description: string;
|
|
84
|
+
}[];
|
|
85
|
+
examples?: string[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 分析请求
|
|
89
|
+
export interface AnalysisRequest {
|
|
90
|
+
output: string;
|
|
91
|
+
command: string;
|
|
92
|
+
exitCode?: number;
|
|
93
|
+
context?: {
|
|
94
|
+
timestamp?: Date;
|
|
95
|
+
workingDirectory?: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 分析响应
|
|
100
|
+
export interface AnalysisResponse {
|
|
101
|
+
summary: string;
|
|
102
|
+
insights: string[];
|
|
103
|
+
issues?: {
|
|
104
|
+
severity: 'warning' | 'error' | 'info';
|
|
105
|
+
message: string;
|
|
106
|
+
suggestion?: string;
|
|
107
|
+
}[];
|
|
108
|
+
success: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 提供商能力
|
|
112
|
+
export enum ProviderCapability {
|
|
113
|
+
CHAT = 'chat',
|
|
114
|
+
COMMAND_GENERATION = 'command_generation',
|
|
115
|
+
COMMAND_EXPLANATION = 'command_explanation',
|
|
116
|
+
REASONING = 'reasoning',
|
|
117
|
+
FUNCTION_CALL = 'function_call',
|
|
118
|
+
STREAMING = 'streaming'
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 健康状态
|
|
122
|
+
export enum HealthStatus {
|
|
123
|
+
HEALTHY = 'healthy',
|
|
124
|
+
DEGRADED = 'degraded',
|
|
125
|
+
UNHEALTHY = 'unhealthy'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 验证结果
|
|
129
|
+
export interface ValidationResult {
|
|
130
|
+
valid: boolean;
|
|
131
|
+
errors?: string[];
|
|
132
|
+
warnings?: string[];
|
|
133
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI提供商相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ProviderCapability, HealthStatus, ValidationResult } from './ai.types';
|
|
6
|
+
import { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse } from './ai.types';
|
|
7
|
+
|
|
8
|
+
// 重新导出相关类型
|
|
9
|
+
export { ProviderCapability, HealthStatus, ValidationResult };
|
|
10
|
+
export { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse };
|
|
11
|
+
|
|
12
|
+
// 认证配置
|
|
13
|
+
export interface AuthConfig {
|
|
14
|
+
type: 'apiKey' | 'bearer' | 'basic' | 'oauth';
|
|
15
|
+
credentials: Record<string, string>;
|
|
16
|
+
requiresEncryption?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 提供商配置
|
|
20
|
+
export interface ProviderConfig {
|
|
21
|
+
name: string;
|
|
22
|
+
displayName: string;
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
baseURL?: string;
|
|
25
|
+
model?: string;
|
|
26
|
+
maxTokens?: number;
|
|
27
|
+
temperature?: number;
|
|
28
|
+
timeout?: number;
|
|
29
|
+
retries?: number;
|
|
30
|
+
authConfig?: AuthConfig;
|
|
31
|
+
enabled?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 提供商信息
|
|
35
|
+
export interface ProviderInfo {
|
|
36
|
+
name: string;
|
|
37
|
+
displayName: string;
|
|
38
|
+
version: string;
|
|
39
|
+
description: string;
|
|
40
|
+
capabilities: ProviderCapability[];
|
|
41
|
+
authConfig: AuthConfig;
|
|
42
|
+
supportedModels: string[];
|
|
43
|
+
pricing?: {
|
|
44
|
+
type: 'free' | 'paid' | 'freemium';
|
|
45
|
+
currency: string;
|
|
46
|
+
unit: string;
|
|
47
|
+
costPerUnit?: number;
|
|
48
|
+
};
|
|
49
|
+
documentation?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 基础AI提供商接口
|
|
53
|
+
export abstract class BaseAiProvider {
|
|
54
|
+
abstract readonly name: string;
|
|
55
|
+
abstract readonly displayName: string;
|
|
56
|
+
abstract readonly capabilities: ProviderCapability[];
|
|
57
|
+
abstract readonly authConfig: AuthConfig;
|
|
58
|
+
|
|
59
|
+
protected config: ProviderConfig | null = null;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 配置提供商
|
|
63
|
+
*/
|
|
64
|
+
abstract configure(config: ProviderConfig): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 聊天功能
|
|
68
|
+
*/
|
|
69
|
+
abstract chat(request: ChatRequest): Promise<ChatResponse>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 生成命令
|
|
73
|
+
*/
|
|
74
|
+
abstract generateCommand(request: CommandRequest): Promise<CommandResponse>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 解释命令
|
|
78
|
+
*/
|
|
79
|
+
abstract explainCommand(request: ExplainRequest): Promise<ExplainResponse>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 分析结果
|
|
83
|
+
*/
|
|
84
|
+
abstract analyzeResult(request: AnalysisRequest): Promise<AnalysisResponse>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 健康检查
|
|
88
|
+
*/
|
|
89
|
+
abstract healthCheck(): Promise<HealthStatus>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 验证配置
|
|
93
|
+
*/
|
|
94
|
+
abstract validateConfig(): ValidationResult;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 获取提供商信息
|
|
98
|
+
*/
|
|
99
|
+
getInfo(): ProviderInfo {
|
|
100
|
+
return {
|
|
101
|
+
name: this.name,
|
|
102
|
+
displayName: this.displayName,
|
|
103
|
+
version: '1.0.0',
|
|
104
|
+
description: `${this.displayName} AI Provider`,
|
|
105
|
+
capabilities: this.capabilities,
|
|
106
|
+
authConfig: this.authConfig,
|
|
107
|
+
supportedModels: this.config?.model ? [this.config.model] : []
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 检查是否支持指定能力
|
|
113
|
+
*/
|
|
114
|
+
supportsCapability(capability: ProviderCapability): boolean {
|
|
115
|
+
return this.capabilities.includes(capability);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 获取当前配置
|
|
120
|
+
*/
|
|
121
|
+
getConfig(): ProviderConfig | null {
|
|
122
|
+
return this.config;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 提供商管理器
|
|
127
|
+
export interface ProviderManager {
|
|
128
|
+
registerProvider(provider: BaseAiProvider): void;
|
|
129
|
+
unregisterProvider(name: string): void;
|
|
130
|
+
getProvider(name: string): BaseAiProvider | undefined;
|
|
131
|
+
getAllProviders(): BaseAiProvider[];
|
|
132
|
+
getActiveProvider(): BaseAiProvider | undefined;
|
|
133
|
+
setActiveProvider(name: string): boolean;
|
|
134
|
+
getProviderInfo(name: string): ProviderInfo | undefined;
|
|
135
|
+
getAllProviderInfo(): ProviderInfo[];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 提供商事件
|
|
139
|
+
export interface ProviderEvent {
|
|
140
|
+
type: 'connected' | 'disconnected' | 'error' | 'config_changed' | 'health_changed';
|
|
141
|
+
provider: string;
|
|
142
|
+
timestamp: Date;
|
|
143
|
+
data?: any;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 提供商事件监听器
|
|
147
|
+
export type ProviderEventListener = (event: ProviderEvent) => void;
|