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.
Files changed (134) hide show
  1. package/README.md +232 -0
  2. package/dist/components/chat/chat-input.component.d.ts +65 -0
  3. package/dist/components/chat/chat-interface.component.d.ts +71 -0
  4. package/dist/components/chat/chat-message.component.d.ts +53 -0
  5. package/dist/components/chat/chat-settings.component.d.ts +62 -0
  6. package/dist/components/common/error-message.component.d.ts +11 -0
  7. package/dist/components/common/loading-spinner.component.d.ts +4 -0
  8. package/dist/components/security/consent-dialog.component.d.ts +11 -0
  9. package/dist/components/security/password-prompt.component.d.ts +10 -0
  10. package/dist/components/security/risk-confirm-dialog.component.d.ts +36 -0
  11. package/dist/components/settings/ai-settings-tab.component.d.ts +72 -0
  12. package/dist/components/settings/general-settings.component.d.ts +60 -0
  13. package/dist/components/settings/provider-config.component.d.ts +182 -0
  14. package/dist/components/settings/security-settings.component.d.ts +23 -0
  15. package/dist/components/terminal/ai-toolbar-button.component.d.ts +10 -0
  16. package/dist/components/terminal/command-preview.component.d.ts +15 -0
  17. package/dist/components/terminal/command-suggestion.component.d.ts +16 -0
  18. package/dist/index.d.ts +8 -0
  19. package/dist/index.js +2 -0
  20. package/dist/index.js.LICENSE.txt +18 -0
  21. package/dist/main.d.ts +8 -0
  22. package/dist/providers/tabby/ai-config.provider.d.ts +18 -0
  23. package/dist/providers/tabby/ai-hotkey.provider.d.ts +21 -0
  24. package/dist/providers/tabby/ai-settings-tab.provider.d.ts +11 -0
  25. package/dist/providers/tabby/ai-toolbar-button.provider.d.ts +17 -0
  26. package/dist/services/chat/chat-history.service.d.ts +67 -0
  27. package/dist/services/chat/chat-session.service.d.ts +58 -0
  28. package/dist/services/chat/command-generator.service.d.ts +49 -0
  29. package/dist/services/core/ai-assistant.service.d.ts +88 -0
  30. package/dist/services/core/ai-provider-manager.service.d.ts +119 -0
  31. package/dist/services/core/config-provider.service.d.ts +137 -0
  32. package/dist/services/core/logger.service.d.ts +21 -0
  33. package/dist/services/providers/anthropic-provider.service.d.ts +39 -0
  34. package/dist/services/providers/base-provider.service.d.ts +137 -0
  35. package/dist/services/providers/glm-provider.service.d.ts +91 -0
  36. package/dist/services/providers/minimax-provider.service.d.ts +93 -0
  37. package/dist/services/providers/openai-compatible.service.d.ts +39 -0
  38. package/dist/services/providers/openai-provider.service.d.ts +38 -0
  39. package/dist/services/security/consent-manager.service.d.ts +65 -0
  40. package/dist/services/security/password-manager.service.d.ts +67 -0
  41. package/dist/services/security/risk-assessment.service.d.ts +65 -0
  42. package/dist/services/security/security-validator.service.d.ts +36 -0
  43. package/dist/services/terminal/command-analyzer.service.d.ts +20 -0
  44. package/dist/services/terminal/context-menu.service.d.ts +24 -0
  45. package/dist/services/terminal/hotkey.service.d.ts +28 -0
  46. package/dist/services/terminal/terminal-context.service.d.ts +100 -0
  47. package/dist/types/ai.types.d.ts +107 -0
  48. package/dist/types/provider.types.d.ts +105 -0
  49. package/dist/types/security.types.d.ts +85 -0
  50. package/dist/types/terminal.types.d.ts +150 -0
  51. package/dist/utils/encryption.utils.d.ts +83 -0
  52. package/dist/utils/formatting.utils.d.ts +106 -0
  53. package/dist/utils/validation.utils.d.ts +83 -0
  54. package/integration-test-output.txt +50 -0
  55. package/integration-tests/api-integration.test.ts +183 -0
  56. package/jest.config.js +47 -0
  57. package/package.json +73 -0
  58. package/setup-jest.ts +37 -0
  59. package/src/components/chat/chat-input.component.html +61 -0
  60. package/src/components/chat/chat-input.component.scss +183 -0
  61. package/src/components/chat/chat-input.component.ts +149 -0
  62. package/src/components/chat/chat-interface.component.html +119 -0
  63. package/src/components/chat/chat-interface.component.scss +354 -0
  64. package/src/components/chat/chat-interface.component.ts +224 -0
  65. package/src/components/chat/chat-message.component.html +65 -0
  66. package/src/components/chat/chat-message.component.scss +178 -0
  67. package/src/components/chat/chat-message.component.ts +93 -0
  68. package/src/components/chat/chat-settings.component.html +132 -0
  69. package/src/components/chat/chat-settings.component.scss +172 -0
  70. package/src/components/chat/chat-settings.component.ts +168 -0
  71. package/src/components/common/error-message.component.ts +124 -0
  72. package/src/components/common/loading-spinner.component.ts +72 -0
  73. package/src/components/security/consent-dialog.component.ts +77 -0
  74. package/src/components/security/password-prompt.component.ts +79 -0
  75. package/src/components/security/risk-confirm-dialog.component.html +87 -0
  76. package/src/components/security/risk-confirm-dialog.component.scss +360 -0
  77. package/src/components/security/risk-confirm-dialog.component.ts +96 -0
  78. package/src/components/settings/ai-settings-tab.component.html +140 -0
  79. package/src/components/settings/ai-settings-tab.component.scss +371 -0
  80. package/src/components/settings/ai-settings-tab.component.ts +193 -0
  81. package/src/components/settings/general-settings.component.html +103 -0
  82. package/src/components/settings/general-settings.component.scss +285 -0
  83. package/src/components/settings/general-settings.component.ts +123 -0
  84. package/src/components/settings/provider-config.component.html +95 -0
  85. package/src/components/settings/provider-config.component.scss +60 -0
  86. package/src/components/settings/provider-config.component.ts +206 -0
  87. package/src/components/settings/security-settings.component.html +51 -0
  88. package/src/components/settings/security-settings.component.scss +66 -0
  89. package/src/components/settings/security-settings.component.ts +71 -0
  90. package/src/components/terminal/ai-toolbar-button.component.ts +49 -0
  91. package/src/components/terminal/command-preview.component.ts +185 -0
  92. package/src/components/terminal/command-suggestion.component.ts +128 -0
  93. package/src/index.ts +163 -0
  94. package/src/main.ts +16 -0
  95. package/src/providers/tabby/ai-config.provider.ts +70 -0
  96. package/src/providers/tabby/ai-hotkey.provider.ts +55 -0
  97. package/src/providers/tabby/ai-settings-tab.provider.ts +18 -0
  98. package/src/providers/tabby/ai-toolbar-button.provider.ts +49 -0
  99. package/src/services/chat/chat-history.service.ts +239 -0
  100. package/src/services/chat/chat-session.service.spec.ts +249 -0
  101. package/src/services/chat/chat-session.service.ts +180 -0
  102. package/src/services/chat/command-generator.service.ts +301 -0
  103. package/src/services/core/ai-assistant.service.ts +334 -0
  104. package/src/services/core/ai-provider-manager.service.ts +314 -0
  105. package/src/services/core/config-provider.service.ts +347 -0
  106. package/src/services/core/logger.service.ts +104 -0
  107. package/src/services/providers/anthropic-provider.service.ts +373 -0
  108. package/src/services/providers/base-provider.service.ts +369 -0
  109. package/src/services/providers/glm-provider.service.ts +467 -0
  110. package/src/services/providers/minimax-provider.service.ts +427 -0
  111. package/src/services/providers/openai-compatible.service.ts +394 -0
  112. package/src/services/providers/openai-provider.service.ts +376 -0
  113. package/src/services/security/consent-manager.service.ts +332 -0
  114. package/src/services/security/password-manager.service.ts +188 -0
  115. package/src/services/security/risk-assessment.service.ts +340 -0
  116. package/src/services/security/security-validator.service.ts +143 -0
  117. package/src/services/terminal/command-analyzer.service.ts +43 -0
  118. package/src/services/terminal/context-menu.service.ts +45 -0
  119. package/src/services/terminal/hotkey.service.ts +53 -0
  120. package/src/services/terminal/terminal-context.service.ts +317 -0
  121. package/src/styles/ai-assistant.scss +449 -0
  122. package/src/types/ai.types.ts +133 -0
  123. package/src/types/provider.types.ts +147 -0
  124. package/src/types/security.types.ts +103 -0
  125. package/src/types/terminal.types.ts +186 -0
  126. package/src/utils/encryption.utils.spec.ts +250 -0
  127. package/src/utils/encryption.utils.ts +271 -0
  128. package/src/utils/formatting.utils.ts +359 -0
  129. package/src/utils/validation.utils.spec.ts +225 -0
  130. package/src/utils/validation.utils.ts +314 -0
  131. package/tsconfig.json +45 -0
  132. package/webpack-docker.config.js +42 -0
  133. package/webpack.config.js +59 -0
  134. package/webpack.config.js.backup +57 -0
@@ -0,0 +1,137 @@
1
+ import { BaseAiProvider as IBaseAiProvider, ProviderConfig, AuthConfig, ProviderCapability, HealthStatus, ValidationResult } from '../../types/provider.types';
2
+ import { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse } from '../../types/ai.types';
3
+ import { LoggerService } from '../core/logger.service';
4
+ /**
5
+ * 基础AI提供商抽象类
6
+ * 所有AI提供商都应该继承此类
7
+ */
8
+ export declare abstract class BaseAiProvider extends IBaseAiProvider {
9
+ protected logger: LoggerService;
10
+ abstract readonly name: string;
11
+ abstract readonly displayName: string;
12
+ abstract readonly capabilities: ProviderCapability[];
13
+ abstract readonly authConfig: AuthConfig;
14
+ protected config: ProviderConfig | null;
15
+ protected isInitialized: boolean;
16
+ protected lastHealthCheck: {
17
+ status: HealthStatus;
18
+ timestamp: Date;
19
+ } | null;
20
+ constructor(logger: LoggerService);
21
+ /**
22
+ * 配置提供商
23
+ */
24
+ configure(config: ProviderConfig): void;
25
+ /**
26
+ * 聊天功能 - 必须由子类实现
27
+ */
28
+ abstract chat(request: ChatRequest): Promise<ChatResponse>;
29
+ /**
30
+ * 生成命令 - 必须由子类实现
31
+ */
32
+ abstract generateCommand(request: CommandRequest): Promise<CommandResponse>;
33
+ /**
34
+ * 解释命令 - 必须由子类实现
35
+ */
36
+ abstract explainCommand(request: ExplainRequest): Promise<ExplainResponse>;
37
+ /**
38
+ * 分析结果 - 必须由子类实现
39
+ */
40
+ abstract analyzeResult(request: AnalysisRequest): Promise<AnalysisResponse>;
41
+ /**
42
+ * 健康检查 - 默认实现,子类可以重写
43
+ */
44
+ healthCheck(): Promise<HealthStatus>;
45
+ /**
46
+ * 验证配置 - 默认实现,子类可以重写
47
+ */
48
+ validateConfig(): ValidationResult;
49
+ /**
50
+ * 检查是否支持指定能力
51
+ */
52
+ supportsCapability(capability: ProviderCapability): boolean;
53
+ /**
54
+ * 获取提供商信息
55
+ */
56
+ getInfo(): any;
57
+ /**
58
+ * 获取当前配置
59
+ */
60
+ getConfig(): ProviderConfig | null;
61
+ /**
62
+ * 检查是否已配置
63
+ */
64
+ isConfigured(): boolean;
65
+ /**
66
+ * 检查是否启用
67
+ */
68
+ isEnabled(): boolean;
69
+ /**
70
+ * 获取认证头
71
+ */
72
+ protected getAuthHeaders(): Record<string, string>;
73
+ /**
74
+ * 获取请求超时时间
75
+ */
76
+ protected getTimeout(): number;
77
+ /**
78
+ * 获取重试次数
79
+ */
80
+ protected getRetries(): number;
81
+ /**
82
+ * 执行重试逻辑
83
+ */
84
+ protected withRetry<T>(operation: () => Promise<T>): Promise<T>;
85
+ /**
86
+ * 记录请求
87
+ */
88
+ protected logRequest(request: any): void;
89
+ /**
90
+ * 记录响应
91
+ */
92
+ protected logResponse(response: any): void;
93
+ /**
94
+ * 记录错误
95
+ */
96
+ protected logError(error: any, context?: any): void;
97
+ /**
98
+ * 清理请求数据(移除敏感信息)
99
+ */
100
+ protected sanitizeRequest(request: any): any;
101
+ /**
102
+ * 清理响应数据
103
+ */
104
+ protected sanitizeResponse(response: any): any;
105
+ /**
106
+ * 获取基础URL
107
+ */
108
+ protected getBaseURL(): string;
109
+ /**
110
+ * 获取默认基础URL - 子类必须实现
111
+ */
112
+ protected abstract getDefaultBaseURL(): string;
113
+ /**
114
+ * 获取默认模型 - 子类可以重写
115
+ */
116
+ protected getDefaultModel(): string;
117
+ /**
118
+ * 转换聊天消息格式 - 子类可以重写
119
+ */
120
+ protected transformMessages(messages: any[]): any[];
121
+ /**
122
+ * 转换响应格式 - 子类可以重写
123
+ */
124
+ protected transformResponse(response: any): ChatResponse;
125
+ /**
126
+ * 生成唯一ID
127
+ */
128
+ protected generateId(): string;
129
+ /**
130
+ * 检查响应是否成功
131
+ */
132
+ protected isSuccessfulResponse(response: any): boolean;
133
+ /**
134
+ * 提取错误信息
135
+ */
136
+ protected extractError(response: any): string;
137
+ }
@@ -0,0 +1,91 @@
1
+ import { BaseAiProvider } from './base-provider.service';
2
+ import { ProviderCapability, HealthStatus, ValidationResult } from '../../types/provider.types';
3
+ import { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse } from '../../types/ai.types';
4
+ import { LoggerService } from '../core/logger.service';
5
+ /**
6
+ * GLM (ChatGLM) AI提供商
7
+ * 基于Anthropic兼容API格式
8
+ */
9
+ export declare class GlmProviderService extends BaseAiProvider {
10
+ readonly name = "glm";
11
+ readonly displayName = "GLM (ChatGLM-4.6)";
12
+ readonly capabilities: ProviderCapability[];
13
+ readonly authConfig: {
14
+ type: "bearer";
15
+ credentials: {
16
+ apiKey: string;
17
+ };
18
+ };
19
+ private client;
20
+ constructor(logger: LoggerService);
21
+ /**
22
+ * 配置提供商
23
+ */
24
+ configure(config: any): void;
25
+ /**
26
+ * 初始化HTTP客户端
27
+ */
28
+ private initializeClient;
29
+ /**
30
+ * 聊天功能
31
+ */
32
+ chat(request: ChatRequest): Promise<ChatResponse>;
33
+ /**
34
+ * 生成命令
35
+ */
36
+ generateCommand(request: CommandRequest): Promise<CommandResponse>;
37
+ /**
38
+ * 解释命令
39
+ */
40
+ explainCommand(request: ExplainRequest): Promise<ExplainResponse>;
41
+ /**
42
+ * 分析结果
43
+ */
44
+ analyzeResult(request: AnalysisRequest): Promise<AnalysisResponse>;
45
+ /**
46
+ * 健康检查
47
+ */
48
+ healthCheck(): Promise<HealthStatus>;
49
+ /**
50
+ * 验证配置
51
+ */
52
+ validateConfig(): ValidationResult;
53
+ /**
54
+ * 获取默认基础URL
55
+ * GLM提供与Anthropic兼容的API端点
56
+ */
57
+ protected getDefaultBaseURL(): string;
58
+ /**
59
+ * 转换消息格式(Anthropic兼容)
60
+ */
61
+ protected transformMessages(messages: any[]): any[];
62
+ /**
63
+ * 转换聊天响应
64
+ */
65
+ private transformChatResponse;
66
+ /**
67
+ * 构建命令生成提示
68
+ */
69
+ private buildCommandPrompt;
70
+ /**
71
+ * 构建命令解释提示
72
+ */
73
+ private buildExplainPrompt;
74
+ /**
75
+ * 构建结果分析提示
76
+ */
77
+ private buildAnalysisPrompt;
78
+ /**
79
+ * 解析命令响应
80
+ */
81
+ private parseCommandResponse;
82
+ /**
83
+ * 解析解释响应
84
+ */
85
+ private parseExplainResponse;
86
+ /**
87
+ * 解析分析响应
88
+ */
89
+ private parseAnalysisResponse;
90
+ private getDefaultSystemPrompt;
91
+ }
@@ -0,0 +1,93 @@
1
+ import { BaseAiProvider } from './base-provider.service';
2
+ import { ProviderCapability, HealthStatus, ValidationResult } from '../../types/provider.types';
3
+ import { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse } from '../../types/ai.types';
4
+ import { LoggerService } from '../core/logger.service';
5
+ /**
6
+ * Minimax AI提供商
7
+ * 基于Anthropic Claude API,完全兼容Anthropic格式
8
+ */
9
+ export declare class MinimaxProviderService extends BaseAiProvider {
10
+ readonly name = "minimax";
11
+ readonly displayName = "Minimax (MiniMax-M2)";
12
+ readonly capabilities: ProviderCapability[];
13
+ readonly authConfig: {
14
+ type: "bearer";
15
+ credentials: {
16
+ apiKey: string;
17
+ };
18
+ };
19
+ private client;
20
+ constructor(logger: LoggerService);
21
+ /**
22
+ * 配置提供商
23
+ */
24
+ configure(config: any): void;
25
+ /**
26
+ * 初始化Anthropic客户端
27
+ */
28
+ private initializeClient;
29
+ /**
30
+ * 聊天功能
31
+ */
32
+ chat(request: ChatRequest): Promise<ChatResponse>;
33
+ /**
34
+ * 生成命令
35
+ */
36
+ generateCommand(request: CommandRequest): Promise<CommandResponse>;
37
+ /**
38
+ * 解释命令
39
+ */
40
+ explainCommand(request: ExplainRequest): Promise<ExplainResponse>;
41
+ /**
42
+ * 分析结果
43
+ */
44
+ analyzeResult(request: AnalysisRequest): Promise<AnalysisResponse>;
45
+ /**
46
+ * 健康检查
47
+ */
48
+ healthCheck(): Promise<HealthStatus>;
49
+ /**
50
+ * 验证配置
51
+ */
52
+ validateConfig(): ValidationResult;
53
+ /**
54
+ * 获取默认基础URL
55
+ */
56
+ protected getDefaultBaseURL(): string;
57
+ /**
58
+ * 转换消息格式
59
+ */
60
+ protected transformMessages(messages: any[]): any[];
61
+ /**
62
+ * 转换聊天响应
63
+ */
64
+ private transformChatResponse;
65
+ /**
66
+ * 构建命令生成提示
67
+ */
68
+ private buildCommandPrompt;
69
+ /**
70
+ * 构建命令解释提示
71
+ */
72
+ private buildExplainPrompt;
73
+ /**
74
+ * 构建结果分析提示
75
+ */
76
+ private buildAnalysisPrompt;
77
+ /**
78
+ * 解析命令响应
79
+ */
80
+ private parseCommandResponse;
81
+ /**
82
+ * 解析解释响应
83
+ */
84
+ private parseExplainResponse;
85
+ /**
86
+ * 解析分析响应
87
+ */
88
+ private parseAnalysisResponse;
89
+ /**
90
+ * 获取默认系统提示
91
+ */
92
+ private getDefaultSystemPrompt;
93
+ }
@@ -0,0 +1,39 @@
1
+ import { BaseAiProvider } from './base-provider.service';
2
+ import { ProviderCapability, HealthStatus, ValidationResult } from '../../types/provider.types';
3
+ import { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse } from '../../types/ai.types';
4
+ import { LoggerService } from '../core/logger.service';
5
+ /**
6
+ * OpenAI兼容AI提供商
7
+ * 支持LocalAI、Ollama、OpenRouter等OpenAI API兼容服务
8
+ */
9
+ export declare class OpenAiCompatibleProviderService extends BaseAiProvider {
10
+ readonly name = "openai-compatible";
11
+ readonly displayName = "OpenAI Compatible";
12
+ readonly capabilities: ProviderCapability[];
13
+ readonly authConfig: {
14
+ type: "bearer";
15
+ credentials: {
16
+ apiKey: string;
17
+ };
18
+ };
19
+ private client;
20
+ private supportedModels;
21
+ constructor(logger: LoggerService);
22
+ configure(config: any): void;
23
+ private initializeClient;
24
+ chat(request: ChatRequest): Promise<ChatResponse>;
25
+ generateCommand(request: CommandRequest): Promise<CommandResponse>;
26
+ explainCommand(request: ExplainRequest): Promise<ExplainResponse>;
27
+ analyzeResult(request: AnalysisRequest): Promise<AnalysisResponse>;
28
+ healthCheck(): Promise<HealthStatus>;
29
+ validateConfig(): ValidationResult;
30
+ protected getDefaultBaseURL(): string;
31
+ protected transformMessages(messages: any[]): any[];
32
+ private transformChatResponse;
33
+ private buildCommandPrompt;
34
+ private buildExplainPrompt;
35
+ private buildAnalysisPrompt;
36
+ private parseCommandResponse;
37
+ private parseExplainResponse;
38
+ private parseAnalysisResponse;
39
+ }
@@ -0,0 +1,38 @@
1
+ import { BaseAiProvider } from './base-provider.service';
2
+ import { ProviderCapability, HealthStatus, ValidationResult } from '../../types/provider.types';
3
+ import { ChatRequest, ChatResponse, CommandRequest, CommandResponse, ExplainRequest, ExplainResponse, AnalysisRequest, AnalysisResponse } from '../../types/ai.types';
4
+ import { LoggerService } from '../core/logger.service';
5
+ /**
6
+ * OpenAI AI提供商
7
+ * 基于OpenAI API格式
8
+ */
9
+ export declare class OpenAiProviderService extends BaseAiProvider {
10
+ readonly name = "openai";
11
+ readonly displayName = "OpenAI (GPT-4)";
12
+ readonly capabilities: ProviderCapability[];
13
+ readonly authConfig: {
14
+ type: "bearer";
15
+ credentials: {
16
+ apiKey: string;
17
+ };
18
+ };
19
+ private client;
20
+ constructor(logger: LoggerService);
21
+ configure(config: any): void;
22
+ private initializeClient;
23
+ chat(request: ChatRequest): Promise<ChatResponse>;
24
+ generateCommand(request: CommandRequest): Promise<CommandResponse>;
25
+ explainCommand(request: ExplainRequest): Promise<ExplainResponse>;
26
+ analyzeResult(request: AnalysisRequest): Promise<AnalysisResponse>;
27
+ healthCheck(): Promise<HealthStatus>;
28
+ validateConfig(): ValidationResult;
29
+ protected getDefaultBaseURL(): string;
30
+ protected transformMessages(messages: any[]): any[];
31
+ private transformChatResponse;
32
+ private buildCommandPrompt;
33
+ private buildExplainPrompt;
34
+ private buildAnalysisPrompt;
35
+ private parseCommandResponse;
36
+ private parseExplainResponse;
37
+ private parseAnalysisResponse;
38
+ }
@@ -0,0 +1,65 @@
1
+ import { RiskLevel } from '../../types/security.types';
2
+ import { LoggerService } from '../core/logger.service';
3
+ export declare class ConsentManagerService {
4
+ private logger;
5
+ private readonly CONSENT_KEY_PREFIX;
6
+ private readonly DEFAULT_EXPIRY;
7
+ constructor(logger: LoggerService);
8
+ /**
9
+ * 存储用户同意
10
+ */
11
+ storeConsent(command: string, riskLevel: RiskLevel): Promise<void>;
12
+ /**
13
+ * 检查是否有用户同意
14
+ */
15
+ hasConsent(command: string, riskLevel: RiskLevel): Promise<boolean>;
16
+ /**
17
+ * 请求用户同意
18
+ */
19
+ requestConsent(command: string, explanation: string, riskLevel: RiskLevel): Promise<boolean>;
20
+ /**
21
+ * 清除所有同意
22
+ */
23
+ clearAllConsents(): Promise<void>;
24
+ /**
25
+ * 获取所有同意数量
26
+ */
27
+ getActiveConsentsCount(): Promise<number>;
28
+ /**
29
+ * 获取总验证次数
30
+ */
31
+ getTotalValidations(): Promise<number>;
32
+ /**
33
+ * 获取同意统计
34
+ */
35
+ getConsentStats(): Promise<{
36
+ total: number;
37
+ byLevel: {
38
+ [key in RiskLevel]: number;
39
+ };
40
+ expired: number;
41
+ }>;
42
+ /**
43
+ * 清理过期的同意
44
+ */
45
+ cleanupExpiredConsents(): Promise<number>;
46
+ /**
47
+ * 获取风险级别文本
48
+ */
49
+ private getRiskLevelText;
50
+ /**
51
+ * 对命令进行哈希
52
+ */
53
+ private hashCommand;
54
+ /**
55
+ * 导出同意数据
56
+ */
57
+ exportConsents(): string;
58
+ /**
59
+ * 导入同意数据
60
+ */
61
+ importConsents(data: string): Promise<{
62
+ imported: number;
63
+ skipped: number;
64
+ }>;
65
+ }
@@ -0,0 +1,67 @@
1
+ import { PasswordValidationResult } from '../../types/security.types';
2
+ import { LoggerService } from '../core/logger.service';
3
+ export declare class PasswordManagerService {
4
+ private logger;
5
+ private readonly STORAGE_KEY;
6
+ private readonly MAX_ATTEMPTS;
7
+ private readonly LOCKOUT_TIME;
8
+ private attempts;
9
+ private lockoutUntil;
10
+ constructor(logger: LoggerService);
11
+ /**
12
+ * 设置密码
13
+ */
14
+ setPassword(password: string): void;
15
+ /**
16
+ * 验证密码
17
+ */
18
+ requestPassword(): Promise<boolean>;
19
+ /**
20
+ * 检查是否有密码保护
21
+ */
22
+ hasPassword(): boolean;
23
+ /**
24
+ * 清除密码
25
+ */
26
+ clearPassword(): void;
27
+ /**
28
+ * 验证密码是否正确
29
+ */
30
+ private verifyPassword;
31
+ /**
32
+ * 哈希密码
33
+ */
34
+ private hashPassword;
35
+ /**
36
+ * 检查是否被锁定
37
+ */
38
+ private isLocked;
39
+ /**
40
+ * 获取剩余锁定时间
41
+ */
42
+ private getRemainingLockoutTime;
43
+ /**
44
+ * 重置尝试次数
45
+ */
46
+ private resetAttempts;
47
+ /**
48
+ * 保存状态
49
+ */
50
+ private saveState;
51
+ /**
52
+ * 加载状态
53
+ */
54
+ private loadState;
55
+ /**
56
+ * 获取验证结果
57
+ */
58
+ getValidationResult(): PasswordValidationResult;
59
+ /**
60
+ * 获取总尝试次数
61
+ */
62
+ getTotalAttempts(): number;
63
+ /**
64
+ * 获取失败次数
65
+ */
66
+ getFailedAttempts(): number;
67
+ }
@@ -0,0 +1,65 @@
1
+ import { RiskLevel, RiskAssessment } from '../../types/security.types';
2
+ import { LoggerService } from '../core/logger.service';
3
+ /**
4
+ * 风险评估服务
5
+ * 负责评估终端命令的安全风险级别
6
+ */
7
+ export declare class RiskAssessmentService {
8
+ private logger;
9
+ private readonly DANGEROUS_PATTERNS;
10
+ private readonly SYSTEM_COMMANDS;
11
+ private readonly NETWORK_COMMANDS;
12
+ private readonly READONLY_COMMANDS;
13
+ constructor(logger: LoggerService);
14
+ /**
15
+ * 评估命令风险
16
+ */
17
+ assessRisk(command: string): Promise<RiskLevel>;
18
+ /**
19
+ * 执行详细的风险评估
20
+ */
21
+ performAssessment(command: string): Promise<RiskAssessment>;
22
+ /**
23
+ * 检查命令中是否包含指定命令
24
+ */
25
+ private hasCommand;
26
+ /**
27
+ * 检查是否仅包含只读命令
28
+ */
29
+ private hasOnlyReadonlyCommands;
30
+ /**
31
+ * 检查是否是参数或路径
32
+ */
33
+ private isArgumentOrPath;
34
+ /**
35
+ * 计算风险分数
36
+ */
37
+ private calculateRiskScore;
38
+ /**
39
+ * 生成安全建议
40
+ */
41
+ private generateSuggestions;
42
+ /**
43
+ * 获取风险级别对应的数值
44
+ */
45
+ private getSeverityLevel;
46
+ /**
47
+ * 检查是否为危险命令
48
+ */
49
+ isDangerous(command: string): Promise<boolean>;
50
+ /**
51
+ * 获取风险级别描述
52
+ */
53
+ getRiskLevelDescription(level: RiskLevel): string;
54
+ /**
55
+ * 获取风险级别颜色
56
+ */
57
+ getRiskLevelColor(level: RiskLevel): string;
58
+ /**
59
+ * 批量评估多个命令
60
+ */
61
+ assessMultiple(commands: string[]): Promise<{
62
+ command: string;
63
+ level: RiskLevel;
64
+ }[]>;
65
+ }
@@ -0,0 +1,36 @@
1
+ import { RiskLevel, ValidationResult } from '../../types/security.types';
2
+ import { RiskAssessmentService } from './risk-assessment.service';
3
+ import { ConsentManagerService } from './consent-manager.service';
4
+ import { PasswordManagerService } from './password-manager.service';
5
+ import { LoggerService } from '../core/logger.service';
6
+ export declare class SecurityValidatorService {
7
+ private riskAssessment;
8
+ private consentManager;
9
+ private passwordManager;
10
+ private logger;
11
+ constructor(riskAssessment: RiskAssessmentService, consentManager: ConsentManagerService, passwordManager: PasswordManagerService, logger: LoggerService);
12
+ /**
13
+ * 验证并确认命令执行
14
+ */
15
+ validateAndConfirm(command: string, explanation: string, _context?: any): Promise<ValidationResult>;
16
+ /**
17
+ * 检查命令是否安全
18
+ */
19
+ isCommandSafe(command: string): Promise<boolean>;
20
+ /**
21
+ * 获取风险级别
22
+ */
23
+ getRiskLevel(command: string): Promise<RiskLevel>;
24
+ /**
25
+ * 检查是否需要确认
26
+ */
27
+ requiresConfirmation(command: string): Promise<boolean>;
28
+ /**
29
+ * 清除所有用户同意
30
+ */
31
+ clearAllConsents(): Promise<void>;
32
+ /**
33
+ * 获取安全统计
34
+ */
35
+ getSecurityStats(): Promise<any>;
36
+ }
@@ -0,0 +1,20 @@
1
+ import { Observable } from 'rxjs';
2
+ /**
3
+ * 命令分析服务
4
+ * 分析终端命令并提供智能建议
5
+ */
6
+ export declare class CommandAnalyzerService {
7
+ constructor();
8
+ /**
9
+ * 分析命令
10
+ */
11
+ analyzeCommand(command: string): Observable<any>;
12
+ /**
13
+ * 获取命令历史
14
+ */
15
+ getCommandHistory(): string[];
16
+ /**
17
+ * 解析命令参数
18
+ */
19
+ parseCommand(command: string): any;
20
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 上下文菜单服务
3
+ * 管理终端上下文菜单
4
+ */
5
+ export declare class ContextMenuService {
6
+ private menuItemSelected$;
7
+ constructor();
8
+ /**
9
+ * 显示上下文菜单
10
+ */
11
+ showMenu(x: number, y: number, items: any[]): void;
12
+ /**
13
+ * 隐藏上下文菜单
14
+ */
15
+ hideMenu(): void;
16
+ /**
17
+ * 订阅菜单项选择事件
18
+ */
19
+ onMenuItemSelected(): any;
20
+ /**
21
+ * 触发菜单项选择
22
+ */
23
+ selectMenuItem(item: any): void;
24
+ }