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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 热键服务
|
|
3
|
+
* 管理全局热键注册和处理
|
|
4
|
+
*/
|
|
5
|
+
export declare class HotkeyService {
|
|
6
|
+
private hotkeyPressed$;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* 注册热键
|
|
10
|
+
*/
|
|
11
|
+
registerHotkey(key: string, callback: () => void): void;
|
|
12
|
+
/**
|
|
13
|
+
* 取消注册热键
|
|
14
|
+
*/
|
|
15
|
+
unregisterHotkey(key: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* 订阅热键按下事件
|
|
18
|
+
*/
|
|
19
|
+
onHotkeyPressed(): any;
|
|
20
|
+
/**
|
|
21
|
+
* 触发热键事件
|
|
22
|
+
*/
|
|
23
|
+
triggerHotkey(key: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* 检查热键是否已注册
|
|
26
|
+
*/
|
|
27
|
+
isHotkeyRegistered(key: string): boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { TerminalContext, TerminalError, CommandResult, SystemInfo, ProcessInfo } from '../../types/terminal.types';
|
|
3
|
+
import { LoggerService } from '../core/logger.service';
|
|
4
|
+
export declare class TerminalContextService {
|
|
5
|
+
private logger;
|
|
6
|
+
private currentContext;
|
|
7
|
+
private contextChange$;
|
|
8
|
+
private errorDetected$;
|
|
9
|
+
private commandExecuted$;
|
|
10
|
+
constructor(logger: LoggerService);
|
|
11
|
+
private initializeContext;
|
|
12
|
+
/**
|
|
13
|
+
* 获取当前终端上下文
|
|
14
|
+
*/
|
|
15
|
+
getCurrentContext(): TerminalContext | null;
|
|
16
|
+
/**
|
|
17
|
+
* 订阅上下文变化
|
|
18
|
+
*/
|
|
19
|
+
onContextChange(): Observable<TerminalContext>;
|
|
20
|
+
/**
|
|
21
|
+
* 订阅错误检测
|
|
22
|
+
*/
|
|
23
|
+
onError(): Observable<TerminalError>;
|
|
24
|
+
/**
|
|
25
|
+
* 订阅命令执行
|
|
26
|
+
*/
|
|
27
|
+
onCommandExecuted(): Observable<CommandResult>;
|
|
28
|
+
/**
|
|
29
|
+
* 更新当前命令
|
|
30
|
+
*/
|
|
31
|
+
updateCurrentCommand(command: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* 设置命令执行结果
|
|
34
|
+
*/
|
|
35
|
+
setCommandResult(result: CommandResult): void;
|
|
36
|
+
/**
|
|
37
|
+
* 设置运行状态
|
|
38
|
+
*/
|
|
39
|
+
setRunningStatus(isRunning: boolean, process?: ProcessInfo): void;
|
|
40
|
+
/**
|
|
41
|
+
* 更改当前工作目录
|
|
42
|
+
*/
|
|
43
|
+
changeDirectory(path: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* 检测错误并生成分析
|
|
46
|
+
*/
|
|
47
|
+
private analyzeError;
|
|
48
|
+
/**
|
|
49
|
+
* 生成错误修复建议
|
|
50
|
+
*/
|
|
51
|
+
private generateSuggestions;
|
|
52
|
+
/**
|
|
53
|
+
* 获取当前会话信息
|
|
54
|
+
*/
|
|
55
|
+
private getCurrentSession;
|
|
56
|
+
/**
|
|
57
|
+
* 获取系统信息
|
|
58
|
+
*/
|
|
59
|
+
private getSystemInfo;
|
|
60
|
+
/**
|
|
61
|
+
* 获取系统信息 - 公共接口
|
|
62
|
+
*/
|
|
63
|
+
getSystemInfoPublic(): SystemInfo | null;
|
|
64
|
+
/**
|
|
65
|
+
* 检测项目信息
|
|
66
|
+
*/
|
|
67
|
+
private detectProjectInfo;
|
|
68
|
+
/**
|
|
69
|
+
* 检测当前Shell
|
|
70
|
+
*/
|
|
71
|
+
private detectShell;
|
|
72
|
+
/**
|
|
73
|
+
* 生成会话ID
|
|
74
|
+
*/
|
|
75
|
+
private generateSessionId;
|
|
76
|
+
/**
|
|
77
|
+
* 获取环境变量
|
|
78
|
+
*/
|
|
79
|
+
getEnvironmentVariables(): Record<string, string>;
|
|
80
|
+
/**
|
|
81
|
+
* 获取当前工作目录
|
|
82
|
+
*/
|
|
83
|
+
getCurrentDirectory(): string;
|
|
84
|
+
/**
|
|
85
|
+
* 获取最近命令历史
|
|
86
|
+
*/
|
|
87
|
+
getRecentCommands(): string[];
|
|
88
|
+
/**
|
|
89
|
+
* 获取项目信息
|
|
90
|
+
*/
|
|
91
|
+
getProjectInfo(): any;
|
|
92
|
+
/**
|
|
93
|
+
* 检查是否有错误
|
|
94
|
+
*/
|
|
95
|
+
hasError(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* 获取最后一条错误
|
|
98
|
+
*/
|
|
99
|
+
getLastError(): TerminalError | null;
|
|
100
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
export declare enum MessageRole {
|
|
5
|
+
USER = "user",
|
|
6
|
+
ASSISTANT = "assistant",
|
|
7
|
+
SYSTEM = "system"
|
|
8
|
+
}
|
|
9
|
+
export interface ChatMessage {
|
|
10
|
+
id: string;
|
|
11
|
+
role: MessageRole;
|
|
12
|
+
content: string;
|
|
13
|
+
timestamp: Date;
|
|
14
|
+
metadata?: Record<string, any>;
|
|
15
|
+
}
|
|
16
|
+
export interface ChatRequest {
|
|
17
|
+
messages: ChatMessage[];
|
|
18
|
+
systemPrompt?: string;
|
|
19
|
+
maxTokens?: number;
|
|
20
|
+
temperature?: number;
|
|
21
|
+
stream?: boolean;
|
|
22
|
+
model?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ChatResponse {
|
|
25
|
+
message: ChatMessage;
|
|
26
|
+
usage?: {
|
|
27
|
+
promptTokens: number;
|
|
28
|
+
completionTokens: number;
|
|
29
|
+
totalTokens: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface CommandRequest {
|
|
33
|
+
naturalLanguage: string;
|
|
34
|
+
context?: {
|
|
35
|
+
currentDirectory?: string;
|
|
36
|
+
operatingSystem?: string;
|
|
37
|
+
shell?: string;
|
|
38
|
+
environment?: Record<string, string>;
|
|
39
|
+
};
|
|
40
|
+
constraints?: {
|
|
41
|
+
maxLength?: number;
|
|
42
|
+
allowedCommands?: string[];
|
|
43
|
+
forbiddenCommands?: string[];
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface CommandResponse {
|
|
47
|
+
command: string;
|
|
48
|
+
explanation: string;
|
|
49
|
+
confidence: number;
|
|
50
|
+
alternatives?: {
|
|
51
|
+
command: string;
|
|
52
|
+
explanation: string;
|
|
53
|
+
confidence: number;
|
|
54
|
+
}[];
|
|
55
|
+
}
|
|
56
|
+
export interface ExplainRequest {
|
|
57
|
+
command: string;
|
|
58
|
+
context?: {
|
|
59
|
+
currentDirectory?: string;
|
|
60
|
+
operatingSystem?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export interface ExplainResponse {
|
|
64
|
+
explanation: string;
|
|
65
|
+
breakdown: {
|
|
66
|
+
part: string;
|
|
67
|
+
description: string;
|
|
68
|
+
}[];
|
|
69
|
+
examples?: string[];
|
|
70
|
+
}
|
|
71
|
+
export interface AnalysisRequest {
|
|
72
|
+
output: string;
|
|
73
|
+
command: string;
|
|
74
|
+
exitCode?: number;
|
|
75
|
+
context?: {
|
|
76
|
+
timestamp?: Date;
|
|
77
|
+
workingDirectory?: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export interface AnalysisResponse {
|
|
81
|
+
summary: string;
|
|
82
|
+
insights: string[];
|
|
83
|
+
issues?: {
|
|
84
|
+
severity: 'warning' | 'error' | 'info';
|
|
85
|
+
message: string;
|
|
86
|
+
suggestion?: string;
|
|
87
|
+
}[];
|
|
88
|
+
success: boolean;
|
|
89
|
+
}
|
|
90
|
+
export declare enum ProviderCapability {
|
|
91
|
+
CHAT = "chat",
|
|
92
|
+
COMMAND_GENERATION = "command_generation",
|
|
93
|
+
COMMAND_EXPLANATION = "command_explanation",
|
|
94
|
+
REASONING = "reasoning",
|
|
95
|
+
FUNCTION_CALL = "function_call",
|
|
96
|
+
STREAMING = "streaming"
|
|
97
|
+
}
|
|
98
|
+
export declare enum HealthStatus {
|
|
99
|
+
HEALTHY = "healthy",
|
|
100
|
+
DEGRADED = "degraded",
|
|
101
|
+
UNHEALTHY = "unhealthy"
|
|
102
|
+
}
|
|
103
|
+
export interface ValidationResult {
|
|
104
|
+
valid: boolean;
|
|
105
|
+
errors?: string[];
|
|
106
|
+
warnings?: string[];
|
|
107
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI提供商相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
import { ProviderCapability, HealthStatus, ValidationResult } from './ai.types';
|
|
5
|
+
import { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse } from './ai.types';
|
|
6
|
+
export { ProviderCapability, HealthStatus, ValidationResult };
|
|
7
|
+
export { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse };
|
|
8
|
+
export interface AuthConfig {
|
|
9
|
+
type: 'apiKey' | 'bearer' | 'basic' | 'oauth';
|
|
10
|
+
credentials: Record<string, string>;
|
|
11
|
+
requiresEncryption?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ProviderConfig {
|
|
14
|
+
name: string;
|
|
15
|
+
displayName: string;
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
baseURL?: string;
|
|
18
|
+
model?: string;
|
|
19
|
+
maxTokens?: number;
|
|
20
|
+
temperature?: number;
|
|
21
|
+
timeout?: number;
|
|
22
|
+
retries?: number;
|
|
23
|
+
authConfig?: AuthConfig;
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface ProviderInfo {
|
|
27
|
+
name: string;
|
|
28
|
+
displayName: string;
|
|
29
|
+
version: string;
|
|
30
|
+
description: string;
|
|
31
|
+
capabilities: ProviderCapability[];
|
|
32
|
+
authConfig: AuthConfig;
|
|
33
|
+
supportedModels: string[];
|
|
34
|
+
pricing?: {
|
|
35
|
+
type: 'free' | 'paid' | 'freemium';
|
|
36
|
+
currency: string;
|
|
37
|
+
unit: string;
|
|
38
|
+
costPerUnit?: number;
|
|
39
|
+
};
|
|
40
|
+
documentation?: string;
|
|
41
|
+
}
|
|
42
|
+
export declare abstract class BaseAiProvider {
|
|
43
|
+
abstract readonly name: string;
|
|
44
|
+
abstract readonly displayName: string;
|
|
45
|
+
abstract readonly capabilities: ProviderCapability[];
|
|
46
|
+
abstract readonly authConfig: AuthConfig;
|
|
47
|
+
protected config: ProviderConfig | null;
|
|
48
|
+
/**
|
|
49
|
+
* 配置提供商
|
|
50
|
+
*/
|
|
51
|
+
abstract configure(config: ProviderConfig): void;
|
|
52
|
+
/**
|
|
53
|
+
* 聊天功能
|
|
54
|
+
*/
|
|
55
|
+
abstract chat(request: ChatRequest): Promise<ChatResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* 生成命令
|
|
58
|
+
*/
|
|
59
|
+
abstract generateCommand(request: CommandRequest): Promise<CommandResponse>;
|
|
60
|
+
/**
|
|
61
|
+
* 解释命令
|
|
62
|
+
*/
|
|
63
|
+
abstract explainCommand(request: ExplainRequest): Promise<ExplainResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* 分析结果
|
|
66
|
+
*/
|
|
67
|
+
abstract analyzeResult(request: AnalysisRequest): Promise<AnalysisResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* 健康检查
|
|
70
|
+
*/
|
|
71
|
+
abstract healthCheck(): Promise<HealthStatus>;
|
|
72
|
+
/**
|
|
73
|
+
* 验证配置
|
|
74
|
+
*/
|
|
75
|
+
abstract validateConfig(): ValidationResult;
|
|
76
|
+
/**
|
|
77
|
+
* 获取提供商信息
|
|
78
|
+
*/
|
|
79
|
+
getInfo(): ProviderInfo;
|
|
80
|
+
/**
|
|
81
|
+
* 检查是否支持指定能力
|
|
82
|
+
*/
|
|
83
|
+
supportsCapability(capability: ProviderCapability): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* 获取当前配置
|
|
86
|
+
*/
|
|
87
|
+
getConfig(): ProviderConfig | null;
|
|
88
|
+
}
|
|
89
|
+
export interface ProviderManager {
|
|
90
|
+
registerProvider(provider: BaseAiProvider): void;
|
|
91
|
+
unregisterProvider(name: string): void;
|
|
92
|
+
getProvider(name: string): BaseAiProvider | undefined;
|
|
93
|
+
getAllProviders(): BaseAiProvider[];
|
|
94
|
+
getActiveProvider(): BaseAiProvider | undefined;
|
|
95
|
+
setActiveProvider(name: string): boolean;
|
|
96
|
+
getProviderInfo(name: string): ProviderInfo | undefined;
|
|
97
|
+
getAllProviderInfo(): ProviderInfo[];
|
|
98
|
+
}
|
|
99
|
+
export interface ProviderEvent {
|
|
100
|
+
type: 'connected' | 'disconnected' | 'error' | 'config_changed' | 'health_changed';
|
|
101
|
+
provider: string;
|
|
102
|
+
timestamp: Date;
|
|
103
|
+
data?: any;
|
|
104
|
+
}
|
|
105
|
+
export type ProviderEventListener = (event: ProviderEvent) => void;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 安全相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
export declare enum RiskLevel {
|
|
5
|
+
LOW = "low",
|
|
6
|
+
MEDIUM = "medium",
|
|
7
|
+
HIGH = "high",
|
|
8
|
+
CRITICAL = "critical"
|
|
9
|
+
}
|
|
10
|
+
export interface RiskAssessment {
|
|
11
|
+
level: RiskLevel;
|
|
12
|
+
score: number;
|
|
13
|
+
reasons: string[];
|
|
14
|
+
patterns: {
|
|
15
|
+
pattern: string;
|
|
16
|
+
match: string;
|
|
17
|
+
severity: RiskLevel;
|
|
18
|
+
}[];
|
|
19
|
+
suggestions?: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface ValidationResult {
|
|
22
|
+
approved: boolean;
|
|
23
|
+
riskLevel: RiskLevel;
|
|
24
|
+
skipConfirmation?: boolean;
|
|
25
|
+
reason?: string;
|
|
26
|
+
timestamp?: Date;
|
|
27
|
+
}
|
|
28
|
+
export interface StoredConsent {
|
|
29
|
+
commandHash: string;
|
|
30
|
+
riskLevel: RiskLevel;
|
|
31
|
+
timestamp: number;
|
|
32
|
+
expiry: number;
|
|
33
|
+
userId?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface PasswordValidationResult {
|
|
36
|
+
valid: boolean;
|
|
37
|
+
attempts: number;
|
|
38
|
+
locked: boolean;
|
|
39
|
+
lockExpiry?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface SecurityConfig {
|
|
42
|
+
enablePasswordProtection: boolean;
|
|
43
|
+
passwordHash?: string;
|
|
44
|
+
consentExpiryDays: number;
|
|
45
|
+
maxConsentAge: number;
|
|
46
|
+
enableRiskAssessment: boolean;
|
|
47
|
+
autoApproveLowRisk: boolean;
|
|
48
|
+
promptForMediumRisk: boolean;
|
|
49
|
+
requirePasswordForHighRisk: boolean;
|
|
50
|
+
dangerousPatterns: string[];
|
|
51
|
+
allowedCommands: string[];
|
|
52
|
+
forbiddenCommands: string[];
|
|
53
|
+
}
|
|
54
|
+
export interface SecurityEvent {
|
|
55
|
+
type: 'risk_assessed' | 'consent_given' | 'consent_rejected' | 'password_verified' | 'password_failed' | 'command_blocked' | 'command_allowed';
|
|
56
|
+
timestamp: Date;
|
|
57
|
+
command?: string;
|
|
58
|
+
riskLevel?: RiskLevel;
|
|
59
|
+
details?: Record<string, any>;
|
|
60
|
+
}
|
|
61
|
+
export interface SecurityStats {
|
|
62
|
+
totalCommandsEvaluated: number;
|
|
63
|
+
totalCommandsBlocked: number;
|
|
64
|
+
totalConsentsGiven: number;
|
|
65
|
+
totalConsentsRejected: number;
|
|
66
|
+
totalPasswordAttempts: number;
|
|
67
|
+
failedPasswordAttempts: number;
|
|
68
|
+
averageRiskScore: number;
|
|
69
|
+
riskLevelDistribution: {
|
|
70
|
+
low: number;
|
|
71
|
+
medium: number;
|
|
72
|
+
high: number;
|
|
73
|
+
critical: number;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface PasswordPolicy {
|
|
77
|
+
minLength: number;
|
|
78
|
+
maxLength: number;
|
|
79
|
+
requireUppercase: boolean;
|
|
80
|
+
requireLowercase: boolean;
|
|
81
|
+
requireNumbers: boolean;
|
|
82
|
+
requireSpecialChars: boolean;
|
|
83
|
+
prohibitCommonPasswords: boolean;
|
|
84
|
+
prohibitReuse: number;
|
|
85
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 终端相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
export interface TerminalSession {
|
|
5
|
+
sessionId: string;
|
|
6
|
+
pid?: number;
|
|
7
|
+
cwd: string;
|
|
8
|
+
shell: string;
|
|
9
|
+
user?: string;
|
|
10
|
+
hostname?: string;
|
|
11
|
+
environment: Record<string, string>;
|
|
12
|
+
startTime: Date;
|
|
13
|
+
lastActivity: Date;
|
|
14
|
+
}
|
|
15
|
+
export interface TerminalContext {
|
|
16
|
+
session: TerminalSession;
|
|
17
|
+
currentCommand?: string;
|
|
18
|
+
lastCommand?: string;
|
|
19
|
+
lastOutput?: string;
|
|
20
|
+
lastError?: string;
|
|
21
|
+
exitCode?: number;
|
|
22
|
+
isRunning: boolean;
|
|
23
|
+
runningProcess?: ProcessInfo;
|
|
24
|
+
recentCommands: string[];
|
|
25
|
+
systemInfo: SystemInfo;
|
|
26
|
+
projectInfo?: ProjectInfo;
|
|
27
|
+
}
|
|
28
|
+
export interface ProcessInfo {
|
|
29
|
+
pid: number;
|
|
30
|
+
name: string;
|
|
31
|
+
status: 'running' | 'sleeping' | 'stopped' | 'zombie';
|
|
32
|
+
cpu?: number;
|
|
33
|
+
memory?: number;
|
|
34
|
+
startTime?: Date;
|
|
35
|
+
command: string;
|
|
36
|
+
}
|
|
37
|
+
export interface SystemInfo {
|
|
38
|
+
platform: 'win32' | 'linux' | 'darwin' | 'freebsd' | 'sunos' | 'browser';
|
|
39
|
+
arch: string;
|
|
40
|
+
type: string;
|
|
41
|
+
release: string;
|
|
42
|
+
version?: string;
|
|
43
|
+
cpus: number;
|
|
44
|
+
totalMemory: number;
|
|
45
|
+
availableMemory?: number;
|
|
46
|
+
nodeVersion?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ProjectInfo {
|
|
49
|
+
type?: 'git' | 'npm' | 'yarn' | 'maven' | 'gradle' | 'pip' | 'cargo' | 'go' | 'rust';
|
|
50
|
+
root: string;
|
|
51
|
+
name?: string;
|
|
52
|
+
version?: string;
|
|
53
|
+
dependencies?: string[];
|
|
54
|
+
scripts?: Record<string, string>;
|
|
55
|
+
description?: string;
|
|
56
|
+
language?: string;
|
|
57
|
+
framework?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface TerminalError {
|
|
60
|
+
type: 'command_not_found' | 'permission_denied' | 'file_not_found' | 'syntax_error' | 'runtime_error' | 'network_error' | 'unknown';
|
|
61
|
+
message: string;
|
|
62
|
+
command?: string;
|
|
63
|
+
exitCode?: number;
|
|
64
|
+
stack?: string;
|
|
65
|
+
suggestions?: string[];
|
|
66
|
+
timestamp: Date;
|
|
67
|
+
}
|
|
68
|
+
export interface BufferContent {
|
|
69
|
+
content: string;
|
|
70
|
+
cursorPosition: number;
|
|
71
|
+
selectionStart?: number;
|
|
72
|
+
selectionEnd?: number;
|
|
73
|
+
}
|
|
74
|
+
export interface CommandResult {
|
|
75
|
+
command: string;
|
|
76
|
+
exitCode: number;
|
|
77
|
+
stdout: string;
|
|
78
|
+
stderr: string;
|
|
79
|
+
duration: number;
|
|
80
|
+
timestamp: Date;
|
|
81
|
+
success: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface HistoryEntry {
|
|
84
|
+
command: string;
|
|
85
|
+
timestamp: Date;
|
|
86
|
+
exitCode?: number;
|
|
87
|
+
duration?: number;
|
|
88
|
+
cwd?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface EnvironmentChange {
|
|
91
|
+
key: string;
|
|
92
|
+
oldValue?: string;
|
|
93
|
+
newValue: string;
|
|
94
|
+
timestamp: Date;
|
|
95
|
+
}
|
|
96
|
+
export interface TerminalTheme {
|
|
97
|
+
name: string;
|
|
98
|
+
foreground: string;
|
|
99
|
+
background: string;
|
|
100
|
+
colors: string[];
|
|
101
|
+
cursor: string;
|
|
102
|
+
}
|
|
103
|
+
export interface FileSystemState {
|
|
104
|
+
currentPath: string;
|
|
105
|
+
files: FileInfo[];
|
|
106
|
+
permissions: Record<string, string>;
|
|
107
|
+
}
|
|
108
|
+
export interface FileInfo {
|
|
109
|
+
name: string;
|
|
110
|
+
path: string;
|
|
111
|
+
type: 'file' | 'directory' | 'symlink' | 'device' | 'pipe' | 'socket';
|
|
112
|
+
size: number;
|
|
113
|
+
modified: Date;
|
|
114
|
+
permissions: string;
|
|
115
|
+
owner?: string;
|
|
116
|
+
group?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface Hotkey {
|
|
119
|
+
key: string;
|
|
120
|
+
description: string;
|
|
121
|
+
action: string;
|
|
122
|
+
scope?: 'global' | 'terminal' | 'chat';
|
|
123
|
+
}
|
|
124
|
+
export interface TerminalCapability {
|
|
125
|
+
name: string;
|
|
126
|
+
supported: boolean;
|
|
127
|
+
version?: string;
|
|
128
|
+
}
|
|
129
|
+
export interface ClipboardContent {
|
|
130
|
+
text: string;
|
|
131
|
+
type: 'plain' | 'rich' | 'image' | 'file';
|
|
132
|
+
timestamp: Date;
|
|
133
|
+
}
|
|
134
|
+
export interface AutoCompleteCandidate {
|
|
135
|
+
value: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
type: 'command' | 'file' | 'directory' | 'variable' | 'function';
|
|
138
|
+
icon?: string;
|
|
139
|
+
}
|
|
140
|
+
export interface TerminalNotification {
|
|
141
|
+
type: 'warning' | 'info' | 'error' | 'success';
|
|
142
|
+
title: string;
|
|
143
|
+
message: string;
|
|
144
|
+
timestamp: Date;
|
|
145
|
+
persistent?: boolean;
|
|
146
|
+
actions?: {
|
|
147
|
+
label: string;
|
|
148
|
+
action: () => void;
|
|
149
|
+
}[];
|
|
150
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成随机密钥
|
|
3
|
+
*/
|
|
4
|
+
export declare function generateKey(): string;
|
|
5
|
+
/**
|
|
6
|
+
* 生成随机初始化向量
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateIV(): string;
|
|
9
|
+
/**
|
|
10
|
+
* 使用AES加密字符串
|
|
11
|
+
*/
|
|
12
|
+
export declare function encrypt(text: string, key: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* 使用AES解密字符串
|
|
15
|
+
*/
|
|
16
|
+
export declare function decrypt(encryptedText: string, key: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* 使用PBKDF2派生密钥
|
|
19
|
+
*/
|
|
20
|
+
export declare function deriveKey(password: string, salt: string, iterations?: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* 生成加密盐值
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateSalt(): string;
|
|
25
|
+
/**
|
|
26
|
+
* 安全的哈希函数
|
|
27
|
+
*/
|
|
28
|
+
export declare function hash(text: string, salt?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* 验证哈希值
|
|
31
|
+
*/
|
|
32
|
+
export declare function verifyHash(text: string, hashValue: string, salt?: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* 加密对象
|
|
35
|
+
*/
|
|
36
|
+
export declare function encryptObject(obj: any, key: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* 解密对象
|
|
39
|
+
*/
|
|
40
|
+
export declare function decryptObject<T>(encryptedText: string, key: string): T;
|
|
41
|
+
/**
|
|
42
|
+
* 生成令牌
|
|
43
|
+
*/
|
|
44
|
+
export declare function generateToken(length?: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* Base64编码
|
|
47
|
+
*/
|
|
48
|
+
export declare function base64Encode(text: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Base64解码
|
|
51
|
+
*/
|
|
52
|
+
export declare function base64Decode(encodedText: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* 安全地比较两个字符串(防止时序攻击)
|
|
55
|
+
*/
|
|
56
|
+
export declare function secureCompare(a: string, b: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 清除敏感数据
|
|
59
|
+
*/
|
|
60
|
+
export declare function clearSensitiveData(obj: any): void;
|
|
61
|
+
/**
|
|
62
|
+
* 生成加密的配置对象
|
|
63
|
+
*/
|
|
64
|
+
export declare function createSecureConfig(data: any, masterPassword: string): {
|
|
65
|
+
encrypted: string;
|
|
66
|
+
salt: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* 解密配置对象
|
|
70
|
+
*/
|
|
71
|
+
export declare function parseSecureConfig(encryptedData: string, salt: string, masterPassword: string): any;
|
|
72
|
+
/**
|
|
73
|
+
* 检查密码强度并生成哈希
|
|
74
|
+
*/
|
|
75
|
+
export declare function hashPassword(password: string, salt?: string): {
|
|
76
|
+
hash: string;
|
|
77
|
+
salt: string;
|
|
78
|
+
valid: boolean;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* 验证密码
|
|
82
|
+
*/
|
|
83
|
+
export declare function verifyPassword(password: string, hash: string, salt: string): boolean;
|